More stuff
This commit is contained in:
@@ -11,9 +11,8 @@ import net.minecraft.client.world.ClientWorld;
|
||||
public class VoxyClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
/*
|
||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
||||
dispatcher.register(WorldImportCommand.register());
|
||||
});*/
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class WorldImportWrapper {
|
||||
|
||||
private WorldImporter importer;
|
||||
private final ServiceThreadPool pool;
|
||||
private final WorldEngine world;
|
||||
|
||||
@@ -476,12 +476,18 @@ public class NodeManager {
|
||||
// childRequest
|
||||
// this is only valid if this node is an inner node
|
||||
|
||||
|
||||
Logger.error("UNFINISHED OPERATION TODO: FIXME2");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if ((childExistence&(1<<i))==0) continue;
|
||||
|
||||
long childPos = makeChildPos(pos, i);
|
||||
this.recurseRemoveNode(childPos);
|
||||
}
|
||||
|
||||
//Free geometry and related memory for this node
|
||||
|
||||
//TODO: DELETE GEOMETRY
|
||||
int geometry = this.nodeData.getNodeGeometry(nodeId);
|
||||
if (geometry != EMPTY_GEOMETRY_ID && geometry != NULL_GEOMETRY_ID)
|
||||
this.geometryManager.removeSection(geometry);
|
||||
|
||||
this.nodeData.free(nodeId);
|
||||
this.clearId(nodeId);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class MixinRenderSectionManager {
|
||||
//TODO: Am not quite sure if this is right
|
||||
var instance = VoxyCommon.getInstance();
|
||||
if (instance != null && VoxyConfig.CONFIG.ingestEnabled) {
|
||||
instance.getIngestService().enqueueIngest(this.level.getChunk(x, z));
|
||||
instance.getIngestService().enqueueIngest(this.level.getChunk(x, z), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
public class WorldImportCommand {
|
||||
/*
|
||||
|
||||
public static LiteralArgumentBuilder<FabricClientCommandSource> register() {
|
||||
return ClientCommandManager.literal("voxy").requires((ctx)-> VoxyCommon.getInstance() != null)
|
||||
.then(ClientCommandManager.literal("import")
|
||||
@@ -42,14 +42,16 @@ public class WorldImportCommand {
|
||||
.executes(WorldImportCommand::importZip))))
|
||||
.then(ClientCommandManager.literal("cancel")
|
||||
//.requires((ctx)->((IGetVoxelCore)MinecraftClient.getInstance().worldRenderer).getVoxelCore().importer.isImporterRunning())
|
||||
.executes((ctx)->{((IGetVoxelCore)MinecraftClient.getInstance().worldRenderer).getVoxelCore().importer.stopImporter(); return 0;}))
|
||||
.executes(WorldImportCommand::cancelImport))
|
||||
);
|
||||
}
|
||||
|
||||
private static boolean fileBasedImporter(File directory) {
|
||||
var instance = MinecraftClient.getInstance();
|
||||
var core = ((IGetVoxelCore)instance.worldRenderer).getVoxelCore();
|
||||
return core.importer.createWorldImporter(instance.player.clientWorld,
|
||||
var instance = VoxyCommon.getInstance();
|
||||
if (instance == null) {
|
||||
return false;
|
||||
}
|
||||
return instance.importWrapper.createWorldImporter(MinecraftClient.getInstance().player.clientWorld,
|
||||
(importer, up, done)->importer.importRegionDirectoryAsyncStart(directory, up, done));
|
||||
}
|
||||
|
||||
@@ -131,13 +133,21 @@ public class WorldImportCommand {
|
||||
innerDir = ctx.getArgument("innerPath", String.class);
|
||||
} catch (Exception e) {}
|
||||
|
||||
var instance = MinecraftClient.getInstance();
|
||||
var core = ((IGetVoxelCore)instance.worldRenderer).getVoxelCore();
|
||||
if (core == null) {
|
||||
var instance = VoxyCommon.getInstance();
|
||||
if (instance == null) {
|
||||
return 1;
|
||||
}
|
||||
String finalInnerDir = innerDir;
|
||||
return core.importer.createWorldImporter(instance.player.clientWorld,
|
||||
return instance.importWrapper.createWorldImporter(MinecraftClient.getInstance().player.clientWorld,
|
||||
(importer, up, done)->importer.importZippedRegionDirectoryAsyncStart(zip, finalInnerDir, up, done))?0:1;
|
||||
}*/
|
||||
}
|
||||
|
||||
private static int cancelImport(CommandContext<FabricClientCommandSource> fabricClientCommandSourceCommandContext) {
|
||||
var instance = VoxyCommon.getInstance();
|
||||
if (instance == null) {
|
||||
return 1;
|
||||
}
|
||||
instance.importWrapper.stopImporter();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -136,6 +136,7 @@ public class WorldConversionFactory {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
//TODO: replace .get with a raw enumeration
|
||||
int bId = pc[bStor.get(i++)];
|
||||
|
||||
byte light = lightSupplier.supply(x,y,z);
|
||||
|
||||
@@ -79,10 +79,12 @@ public class VoxelIngestService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void enqueueIngest(WorldChunk chunk) {
|
||||
public void enqueueIngest(WorldChunk chunk, boolean ignoreOnNullWorld) {
|
||||
var engine = ((IVoxyWorldGetter)chunk.getWorld()).getWorldEngine();
|
||||
if (engine == null) {
|
||||
Logger.error("Could not ingest chunk as does not have world engine");
|
||||
if (!ignoreOnNullWorld) {
|
||||
Logger.error("Could not ingest chunk as does not have world engine");
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.enqueueIngest(engine, chunk);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package me.cortex.voxy.commonImpl;
|
||||
|
||||
import me.cortex.voxy.client.core.WorldImportWrapper;
|
||||
import me.cortex.voxy.client.saver.ContextSelectionSystem;
|
||||
import me.cortex.voxy.common.Logger;
|
||||
import me.cortex.voxy.common.config.section.SectionStorage;
|
||||
import me.cortex.voxy.common.config.storage.StorageBackend;
|
||||
import me.cortex.voxy.common.thread.ServiceThreadPool;
|
||||
import me.cortex.voxy.common.util.MemoryBuffer;
|
||||
import me.cortex.voxy.common.world.WorldEngine;
|
||||
@@ -9,12 +12,16 @@ import me.cortex.voxy.common.world.service.SectionSavingService;
|
||||
import me.cortex.voxy.common.world.service.VoxelIngestService;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
//TODO: add thread access verification (I.E. only accessible on a single thread)
|
||||
public class VoxyInstance {
|
||||
private final ServiceThreadPool threadPool;
|
||||
private final SectionSavingService savingService;
|
||||
private final VoxelIngestService ingestService;
|
||||
private final Set<WorldEngine> activeWorlds = new HashSet<>();
|
||||
|
||||
public VoxyInstance(int threadCount) {
|
||||
this.threadPool = new ServiceThreadPool(threadCount);
|
||||
@@ -60,6 +67,13 @@ public class VoxyInstance {
|
||||
}
|
||||
}
|
||||
|
||||
private WorldEngine createWorld(SectionStorage storage) {
|
||||
var world = new WorldEngine(storage, 1024);
|
||||
world.setSaveCallback(this.savingService::enqueueSave);
|
||||
this.activeWorlds.add(world);
|
||||
return world;
|
||||
}
|
||||
|
||||
private static final ContextSelectionSystem SELECTOR = new ContextSelectionSystem();
|
||||
|
||||
public WorldEngine getOrMakeWorld(ClientWorld world) {
|
||||
@@ -68,8 +82,19 @@ public class VoxyInstance {
|
||||
vworld = new WorldEngine(SELECTOR.getBestSelectionOrCreate(world).createSectionStorageBackend(), 1024);
|
||||
vworld.setSaveCallback(this.savingService::enqueueSave);
|
||||
((IVoxyWorldSetter)world).setWorldEngine(vworld);
|
||||
this.importWrapper = new WorldImportWrapper(this.threadPool, vworld);
|
||||
}
|
||||
return vworld;
|
||||
}
|
||||
|
||||
|
||||
public WorldImportWrapper importWrapper;
|
||||
|
||||
public void stopWorld(WorldEngine world) {
|
||||
if (this.importWrapper != null) {
|
||||
this.importWrapper.stopImporter();
|
||||
}
|
||||
this.flush();
|
||||
world.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,11 @@ public class MixinFabricWorld {
|
||||
res.ifPresent(chunk -> {
|
||||
var voxyInstance = VoxyCommon.getInstance();
|
||||
if (voxyInstance != null) {
|
||||
voxyInstance.getIngestService().enqueueIngest((WorldChunk) chunk);
|
||||
try {
|
||||
voxyInstance.getIngestService().enqueueIngest((WorldChunk) chunk, true);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
return res;
|
||||
|
||||
@@ -4,6 +4,7 @@ import me.cortex.voxy.common.Logger;
|
||||
import me.cortex.voxy.common.world.WorldEngine;
|
||||
import me.cortex.voxy.commonImpl.IVoxyWorldGetter;
|
||||
import me.cortex.voxy.commonImpl.IVoxyWorldSetter;
|
||||
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
@@ -18,7 +19,9 @@ public class MixinWorld implements IVoxyWorldGetter, IVoxyWorldSetter {
|
||||
@Inject(method = "close", at = @At("HEAD"))
|
||||
private void closeVoxyWorld(CallbackInfo ci) {
|
||||
if (this.voxyWorld != null) {
|
||||
try {this.voxyWorld.shutdown();this.voxyWorld = null;} catch (Exception e) {
|
||||
//TODO: FIXME: DONT DO THIS, this is a hack to ensure everything is saved
|
||||
var instance = VoxyCommon.getInstance();
|
||||
try {instance.stopWorld(this.voxyWorld); this.voxyWorld = null;} catch (Exception e) {
|
||||
Logger.error("Failed to shutdown voxy world engine.", e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user