Search in sources :

Example 1 with WorldTickEvent

use of io.xol.chunkstories.api.events.world.WorldTickEvent 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();
}
Also used : WorldTickEvent(io.xol.chunkstories.api.events.world.WorldTickEvent) RegionImplementation(io.xol.chunkstories.world.region.RegionImplementation)

Aggregations

WorldTickEvent (io.xol.chunkstories.api.events.world.WorldTickEvent)1 RegionImplementation (io.xol.chunkstories.world.region.RegionImplementation)1