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