Search in sources :

Example 1 with BaseRegionLoader

use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.

the class Anvil method doGarbageCollection.

@Override
public void doGarbageCollection() {
    int limit = (int) (System.currentTimeMillis() - 50);
    for (Map.Entry<Long, BaseRegionLoader> entry : this.regions.entrySet()) {
        long index = entry.getKey();
        BaseRegionLoader region = entry.getValue();
        if (region.lastUsed <= limit) {
            try {
                region.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            this.regions.remove(index);
        }
    }
}
Also used : BaseRegionLoader(cn.nukkit.level.format.generic.BaseRegionLoader) IOException(java.io.IOException)

Example 2 with BaseRegionLoader

use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.

the class McRegion method loadChunk.

@Override
public BaseFullChunk loadChunk(long index, int chunkX, int chunkZ, boolean create) {
    int regionX = getRegionIndexX(chunkX);
    int regionZ = getRegionIndexZ(chunkZ);
    BaseRegionLoader region = this.loadRegion(regionX, regionZ);
    this.level.timings.syncChunkLoadDataTimer.startTiming();
    BaseFullChunk chunk;
    try {
        chunk = region.readChunk(chunkX - regionX * 32, chunkZ - regionZ * 32);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    if (chunk == null) {
        if (create) {
            chunk = this.getEmptyChunk(chunkX, chunkZ);
            putChunk(index, chunk);
        }
    } else {
        putChunk(index, chunk);
    }
    this.level.timings.syncChunkLoadDataTimer.stopTiming();
    return chunk;
}
Also used : BaseRegionLoader(cn.nukkit.level.format.generic.BaseRegionLoader) BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) IOException(java.io.IOException)

Example 3 with BaseRegionLoader

use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.

the class McRegion method loadRegion.

protected BaseRegionLoader loadRegion(int x, int z) {
    BaseRegionLoader tmp = lastRegion;
    if (tmp != null && x == tmp.getX() && z == tmp.getZ()) {
        return tmp;
    }
    long index = Level.chunkHash(x, z);
    BaseRegionLoader region = this.regions.get(index);
    if (region == null) {
        region = new RegionLoader(this, x, z);
        this.regions.put(index, region);
        return lastRegion = region;
    } else {
        return lastRegion = region;
    }
}
Also used : BaseRegionLoader(cn.nukkit.level.format.generic.BaseRegionLoader) BaseRegionLoader(cn.nukkit.level.format.generic.BaseRegionLoader)

Example 4 with BaseRegionLoader

use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.

the class Anvil method loadChunk.

@Override
public BaseFullChunk loadChunk(long index, int chunkX, int chunkZ, boolean create) {
    int regionX = getRegionIndexX(chunkX);
    int regionZ = getRegionIndexZ(chunkZ);
    BaseRegionLoader region = this.loadRegion(regionX, regionZ);
    this.level.timings.syncChunkLoadDataTimer.startTiming();
    BaseFullChunk chunk;
    try {
        chunk = region.readChunk(chunkX - regionX * 32, chunkZ - regionZ * 32);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    if (chunk == null) {
        if (create) {
            chunk = this.getEmptyChunk(chunkX, chunkZ);
            putChunk(index, chunk);
        }
    } else {
        putChunk(index, chunk);
    }
    this.level.timings.syncChunkLoadDataTimer.stopTiming();
    return chunk;
}
Also used : BaseRegionLoader(cn.nukkit.level.format.generic.BaseRegionLoader) BaseFullChunk(cn.nukkit.level.format.generic.BaseFullChunk) IOException(java.io.IOException)

Example 5 with BaseRegionLoader

use of cn.nukkit.level.format.generic.BaseRegionLoader in project Nukkit by Nukkit.

the class Anvil method loadRegion.

protected BaseRegionLoader loadRegion(int x, int z) {
    BaseRegionLoader tmp = lastRegion;
    if (tmp != null && x == tmp.getX() && z == tmp.getZ()) {
        return tmp;
    }
    long index = Level.chunkHash(x, z);
    BaseRegionLoader region = this.regions.get(index);
    if (region == null) {
        try {
            region = new RegionLoader(this, x, z);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        this.regions.put(index, region);
        return lastRegion = region;
    } else {
        return lastRegion = region;
    }
}
Also used : BaseRegionLoader(cn.nukkit.level.format.generic.BaseRegionLoader) IOException(java.io.IOException) BaseRegionLoader(cn.nukkit.level.format.generic.BaseRegionLoader)

Aggregations

BaseRegionLoader (cn.nukkit.level.format.generic.BaseRegionLoader)5 IOException (java.io.IOException)4 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)2