Logging and checking
This commit is contained in:
@@ -73,6 +73,7 @@ public abstract class VoxyInstance {
|
|||||||
// note, the reference count should be separate from the number of active chunks to prevent many issues
|
// note, the reference count should be separate from the number of active chunks to prevent many issues
|
||||||
// a world is no longer active once it has no reference counts and no active chunks associated with it
|
// a world is no longer active once it has no reference counts and no active chunks associated with it
|
||||||
public WorldEngine getNullable(WorldIdentifier identifier) {
|
public WorldEngine getNullable(WorldIdentifier identifier) {
|
||||||
|
if (!this.isRunning) return null;
|
||||||
var cache = identifier.cachedEngineObject;
|
var cache = identifier.cachedEngineObject;
|
||||||
WorldEngine world;
|
WorldEngine world;
|
||||||
if (cache == null) {
|
if (cache == null) {
|
||||||
@@ -109,11 +110,21 @@ public abstract class VoxyInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WorldEngine getOrCreate(WorldIdentifier identifier) {
|
public WorldEngine getOrCreate(WorldIdentifier identifier) {
|
||||||
|
if (!this.isRunning) {
|
||||||
|
Logger.error("Tried getting world object on voxy instance but its not running");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
var world = this.getNullable(identifier);
|
var world = this.getNullable(identifier);
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
long stamp = this.activeWorldLock.writeLock();
|
long stamp = this.activeWorldLock.writeLock();
|
||||||
|
|
||||||
|
if (!this.isRunning) {
|
||||||
|
Logger.error("Tried getting world object on voxy instance but its not running");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
world = this.activeWorlds.get(identifier);
|
world = this.activeWorlds.get(identifier);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
//Create world here
|
//Create world here
|
||||||
@@ -128,10 +139,13 @@ public abstract class VoxyInstance {
|
|||||||
protected abstract SectionStorage createStorage(WorldIdentifier identifier);
|
protected abstract SectionStorage createStorage(WorldIdentifier identifier);
|
||||||
|
|
||||||
private WorldEngine createWorld(WorldIdentifier identifier) {
|
private WorldEngine createWorld(WorldIdentifier identifier) {
|
||||||
|
if (!this.isRunning) {
|
||||||
|
throw new IllegalStateException("Cannot create world while not running");
|
||||||
|
}
|
||||||
if (this.activeWorlds.containsKey(identifier)) {
|
if (this.activeWorlds.containsKey(identifier)) {
|
||||||
throw new IllegalStateException("Existing world with identifier");
|
throw new IllegalStateException("Existing world with identifier");
|
||||||
}
|
}
|
||||||
Logger.info("Creating new world engine: " + identifier.getLongHash());
|
Logger.info("Creating new world engine: " + identifier.getLongHash() + "@" + System.identityHashCode(this));
|
||||||
var world = new WorldEngine(this.createStorage(identifier), this);
|
var world = new WorldEngine(this.createStorage(identifier), this);
|
||||||
world.setSaveCallback(this.savingService::enqueueSave);
|
world.setSaveCallback(this.savingService::enqueueSave);
|
||||||
this.activeWorlds.put(identifier, world);
|
this.activeWorlds.put(identifier, world);
|
||||||
|
|||||||
Reference in New Issue
Block a user