use of io.xol.chunkstories.world.region.RegionImplementation in project chunkstories by Hugobros3.
the class WorldLogicThread method run.
public void run() {
// TODO
// Installs a custom SecurityManager
logger.info("Security manager: " + System.getSecurityManager());
while (!die.get()) {
// Dirty performance metric :]
// perfMetric();
// nanoCheckStep(20, "Loop was more than 20ms");
// Timings
fps = 1f / ((System.nanoTime() - lastTimeNs) / 1000f / 1000f / 1000f);
lastTimeNs = System.nanoTime();
this.getPluginsManager().fireEvent(new WorldTickEvent(world));
try {
world.tick();
} catch (Exception e) {
world.logger().error("Exception occured while ticking the world : ", e);
}
// Every second, unloads unused stuff
if (world.getTicksElapsed() % 60 == 0) {
// System.gc();
// Compresses pending chunk summaries
Iterator<RegionImplementation> loadedChunksHolders = world.getRegionsHolder().getLoadedRegions();
while (loadedChunksHolders.hasNext()) {
RegionImplementation region = loadedChunksHolders.next();
region.compressChangedChunks();
}
// Delete unused world data
world.unloadUselessData();
}
// nanoCheckStep(1, "unload");
gameLogicScheduler.runScheduledTasks();
// nanoCheckStep(1, "schedule");
// Game logic is 60 ticks/s
sync(getTargetFps());
}
waitForLogicFinish.signal();
}
use of io.xol.chunkstories.world.region.RegionImplementation in project chunkstories by Hugobros3.
the class RemotePlayerLoadingAgent method destroy.
public void destroy() {
try {
lock.lock();
for (int handle : this.usedChunksHandles) {
int[] pos = chunk(handle);
RegionImplementation region = player.getWorld().getRegionChunkCoordinates(pos[0], pos[1], pos[2]);
// assert region != null;
if (region != null) {
ChunkHolder holder = region.getChunkHolder(pos[0], pos[1], pos[2]);
// assert holder != null; // We can assert the chunk holder exists because at this point it MUST be held by this very loading agent !
if (holder != null) {
holder.unregisterUser(player);
continue;
}
}
player.getContext().logger().error("Error while disconnecting player: " + player + ", chunkholder at [" + pos[0] + ":" + pos[1] + ":" + pos[2] + "] wasn't loaded even thought it was part of that player's subscriptions list");
}
this.usedChunksHandles.clear();
for (int handle : this.usedRegionHandles) {
int[] pos = summary(handle);
Heightmap regionSummary = player.getWorld().getRegionsSummariesHolder().getHeightmap(pos[0], pos[1]);
// assert regionSummary != null; // We can assert the region summary exists because at this point it MUST be held by this very loading agent !
if (regionSummary != null)
regionSummary.unregisterUser(player);
else {
player.getContext().logger().error("Error while disconnecting player: " + player + ", region at [" + pos[0] + " :" + pos[1] + "] wasn't loaded even thought it was part of that player's subscriptions list");
}
}
this.usedRegionHandles.clear();
destroyed = true;
} catch (Exception e) {
player.getContext().logger().error("Error while disconnecting player: " + player + ", exception thrown while freeing his held world data.");
player.getContext().logger().error(e.getMessage());
} finally {
lock.unlock();
}
}
Aggregations