multithreading good
parent
d026feb525
commit
8d5a3efbdf
|
@ -136,7 +136,8 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
if (chunk == null) return false;
|
||||
// Otherwise save the chunk
|
||||
AtomicBoolean result = new AtomicBoolean(false);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
CompletableFuture.runAsync(() ->
|
||||
{
|
||||
result.set(this.save.saveChunk(chunk));
|
||||
this.chunks.remove(posHash);
|
||||
});
|
||||
|
@ -187,6 +188,8 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
public void unloadAllChunks()
|
||||
{
|
||||
LongList chunkPositions = new LongArrayList();
|
||||
CompletableFuture.runAsync(() ->
|
||||
{
|
||||
if (this.chunks != null)
|
||||
this.chunks.forEach((pos, chunk) ->
|
||||
{ // for every chunk in memory
|
||||
|
@ -194,6 +197,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
this.save.saveChunk(chunk); // save chunk
|
||||
});
|
||||
chunkPositions.forEach((LongConsumer) (pos -> this.chunks.remove(pos))); // remove all chunks
|
||||
});
|
||||
}
|
||||
|
||||
public long getSeed()
|
||||
|
@ -203,13 +207,8 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
|
||||
public void updateLoadedChunks(int chunkX, int chunkY, int chunkZ)
|
||||
{
|
||||
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
//Ginger.getInstance().threading.registerChunkThreadToWaitlist(new DynamicChunkLoader(chunkX, chunkY, chunkZ, this));
|
||||
|
||||
Long2ObjectMap<Chunk> chunksList = this.chunks;
|
||||
|
||||
//FIXME completable futures
|
||||
|
||||
CompletableFuture.runAsync(() ->
|
||||
{
|
||||
List<Chunk> toKeep = new ArrayList<>();
|
||||
// loop over rendered area, adding chunks that are needed
|
||||
for (int x = chunkX - this.renderBound; x < chunkX + this.renderBound; x++)
|
||||
|
@ -219,7 +218,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
|
||||
LongList toRemove = new LongArrayList();
|
||||
// check which loaded chunks are not neccesary
|
||||
chunksList.forEach((pos, chunk) ->
|
||||
chunks.forEach((pos, chunk) ->
|
||||
{
|
||||
if (!toKeep.contains(chunk))
|
||||
toRemove.add((long) pos);
|
||||
|
@ -227,7 +226,8 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
// unload unneccesary chunks from chunk array
|
||||
toRemove.forEach((LongConsumer) this::unloadChunk);
|
||||
|
||||
toKeep.forEach(chunk -> {
|
||||
toKeep.forEach(chunk ->
|
||||
{
|
||||
if (!chunk.isFullyGenerated())
|
||||
{
|
||||
this.populateChunk(chunk);
|
||||
|
@ -236,10 +236,9 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
boolean alreadyRendering = chunk.doRender(); // if it's already rendering then it's most likely in the map
|
||||
chunk.setRender(true);
|
||||
if (!alreadyRendering)
|
||||
chunksList.put(this.posHash(chunk.chunkX, chunk.chunkY, chunk.chunkZ), chunk);
|
||||
chunks.put(this.posHash(chunk.chunkX, chunk.chunkY, chunk.chunkZ), chunk);
|
||||
});
|
||||
});
|
||||
this.chunks = chunksList;
|
||||
|
||||
}
|
||||
|
||||
private static final class GenerationWorld implements BlockAccess, WorldGenConstants
|
||||
|
|
|
@ -11,7 +11,7 @@ public class CavesModifier implements WorldModifier, WorldGenConstants
|
|||
{
|
||||
private OctaveSimplexNoise caveNoise;
|
||||
private static final double THRESHOLD = 0.1;
|
||||
//
|
||||
|
||||
@Override
|
||||
public void initialize(long seed)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue