Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rendering): migrate chunk mesh generation Flux #4786

Merged
merged 75 commits into from
May 13, 2022
Merged
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
2723a05
refactor(rendering): rework chunk mesh generation with RXJava
pollend Jun 21, 2021
f0ac410
cleanup
pollend Jun 21, 2021
ca841b7
chore: replace with computation
pollend Jun 21, 2021
093921c
refactor(rendering): rework chunk mesh generation with RXJava Flowable
pollend Jun 23, 2021
7791254
update tessellator
pollend Jun 23, 2021
8016258
chore: cleanup
pollend Jun 25, 2021
dea7815
chore: cleanup
pollend Jun 26, 2021
9df6538
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Jun 27, 2021
a8e2d11
Merge branch 'develop' of github.com:MovingBlocks/Terasology into ref…
pollend Jun 27, 2021
5902bbd
chore: add info
pollend Jun 27, 2021
1456a7a
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' of git…
pollend Jun 27, 2021
9b04a71
chore: better handle processing chunks that are unloaded
pollend Jun 27, 2021
543a293
chore: replace with reactor
pollend Jul 3, 2021
2826532
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Jul 3, 2021
08cafdc
chore: batch process chunks
pollend Jul 4, 2021
0acab6b
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' of git…
pollend Jul 4, 2021
d088ace
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Jul 4, 2021
8c6e918
chore: minor cleanup
pollend Jul 4, 2021
3da70fc
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' of git…
pollend Jul 4, 2021
f53e6bc
chore: limit number of parallel rails
pollend Jul 4, 2021
587dc29
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Jul 5, 2021
8d4264f
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Aug 1, 2021
4a951a8
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Aug 7, 2021
0005fcd
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Aug 24, 2021
f2ba2d7
Merge branch 'develop' of github.com:MovingBlocks/Terasology into ref…
pollend Aug 28, 2021
b04e07e
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' of git…
pollend Aug 28, 2021
bad0581
Merge branch 'develop' of github.com:MovingBlocks/Terasology into ref…
pollend Aug 28, 2021
fef81c6
chore: remove duplicate reactor and scheulders
pollend Aug 29, 2021
cfc7d58
chore: update interfaces
pollend Aug 29, 2021
7cbdc32
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Sep 3, 2021
73085f8
chore: clean up RenderableWorldImpl
pollend Sep 3, 2021
a1e3ae1
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' of git…
pollend Sep 3, 2021
79f80f6
chore: remove ChunkTask
pollend Sep 3, 2021
262c677
Merge remote-tracking branch 'origin/develop' into refactor/migrate-c…
keturn Sep 5, 2021
bd783e6
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Sep 5, 2021
e15b975
chore: simplify consumer
pollend Sep 5, 2021
950acbe
handle emission error when submitting chunk for mesh
pollend Sep 6, 2021
e5069c7
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Oct 3, 2021
de2835d
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Nov 7, 2021
7072611
Merge branch 'develop' of github.com:MovingBlocks/Terasology into ref…
pollend Nov 20, 2021
60a63fe
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Nov 27, 2021
25e2983
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
pollend Dec 5, 2021
1bfcd3c
refactor: split out chunk work as a seperate helper class
pollend Dec 6, 2021
e7663be
chore: cleanup world renderer
pollend Dec 10, 2021
93fe4f8
Merge remote-tracking branch 'origin/develop' into refactor/migrate-c…
keturn Jan 19, 2022
4667639
fix(RenderableWorldImpl): update for ChunkMonitor change #4888
keturn Jan 19, 2022
90791df
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' into r…
keturn Jan 19, 2022
a15466b
chore(rendering.world): lint
keturn Jan 19, 2022
8e227a1
Merge pull request #4972 from MovingBlocks/refactor/split-chunk-proce…
keturn Jan 19, 2022
9562e86
test(ChunkMeshWorker): initial sketch of tests
keturn Jan 20, 2022
ff3b09c
refactor(Chunk): provide default implementations of methods where pos…
keturn Jan 20, 2022
130dfcd
refactor(ChunkMeshWorker): factor out the generateMesh method
keturn Jan 20, 2022
e032131
test(DummyChunk): stub implementation of Chunk
keturn Jan 20, 2022
e4c723a
test(ChunkMeshWorker): initial attempt at using reactor-test
keturn Jan 20, 2022
e9e32b7
test(ChunkMeshWorker): implement more tests
keturn Jan 22, 2022
cf27ab9
Merge remote-tracking branch 'origin/develop' into refactor/migrate-c…
keturn Jan 22, 2022
3f5a78f
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' into t…
keturn Jan 22, 2022
cf7710a
fix(ChunkMeshWorker): fix no-longer-processing test
keturn Jan 22, 2022
095e40d
refactor(ChunkMeshWorker): inline fluxNewMeshes
keturn Jan 22, 2022
72b0f67
refactor(Chunk): push dispose-old-mesh logic down in to Chunk.setMesh
keturn Jan 22, 2022
ca2f3be
refactor(ChunkMeshWorker): make worker function definitions more compact
keturn Feb 6, 2022
b41ebb1
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
keturn Feb 6, 2022
761a492
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
keturn Feb 18, 2022
430bafa
Merge remote-tracking branch 'origin/refactor/migrate-chunk-mesh-gene…
keturn Feb 18, 2022
972ee97
test(ChunkMeshWorker): remove some difficult to implement tests about…
keturn Feb 18, 2022
1f4ac45
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
jdrueckert Apr 3, 2022
6e534d7
Merge remote-tracking branch 'origin/develop' into refactor/migrate-c…
keturn May 3, 2022
4cc9ca1
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' into t…
keturn May 3, 2022
b313fb0
test(ChunkMeshWorker): make DummyChunk strings slightly more concise
keturn May 6, 2022
3db427f
test(ChunkMeshWorker): fix testMultipleChunks so the results are orde…
keturn May 6, 2022
d69eef8
test(ChunkMeshWorker): add some documentation
keturn May 7, 2022
a157225
Merge remote-tracking branch 'origin/develop' into refactor/migrate-c…
keturn May 7, 2022
f9c6475
Merge branch 'refactor/migrate-chunk-mesh-generation-flowable' into t…
keturn May 7, 2022
cfb307c
Merge pull request #4987 from MovingBlocks/test/chunkmeshworker
keturn May 7, 2022
4c296fe
Merge branch 'develop' into refactor/migrate-chunk-mesh-generation-fl…
keturn May 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: minor cleanup
  • Loading branch information
pollend committed Jul 4, 2021
commit 8c6e91860b91abfe58493edb6bacb59028905e8d
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.joml.Vector3i;
import org.joml.Vector3ic;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.config.Config;
Expand Down Expand Up @@ -40,7 +38,6 @@
import reactor.core.publisher.Sinks;
import reactor.core.scheduler.Schedulers;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -87,7 +84,7 @@ class RenderableWorldImpl implements RenderableWorld {
private int statIgnoredPhases;

private final Set<Vector3ic> chunkMeshProcessing = Sets.newConcurrentHashSet();
private Sinks.Many<Chunk> chunkMeshPublisher = Sinks.many().unicast().onBackpressureBuffer(Queues.newArrayBlockingQueue(100));
private Sinks.Many<Chunk> chunkMeshPublisher = Sinks.many().unicast().onBackpressureBuffer();

private static class ChunkMeshPayload {
Chunk chunk;
Expand Down Expand Up @@ -118,44 +115,38 @@ private static class ChunkMeshPayload {
new PriorityQueue<>(MAX_LOADABLE_CHUNKS, new ChunkBackToFrontComparator()));

chunkMeshPublisher.asFlux()
.distinct(Chunk::getPosition, () -> chunkMeshProcessing)
.doOnNext(k -> k.setDirty(false))
.bufferTimeout(100, Duration.ofMillis(100))
.parallel().runOn(Schedulers.boundedElastic())
.<Chunk>flatMap(chunks -> (Publisher<Chunk>) res -> {
chunks.sort(new ChunkFrontToBackComparator());
for (Chunk c : chunks) {
res.onNext(c);
}
})
.<Optional<ChunkMeshPayload>>map(c -> {
ChunkView chunkView = worldProvider.getLocalView(c.getPosition());
if (chunkView != null && chunkView.isValidView() && chunkMeshProcessing.remove(c.getPosition())) {
ChunkMesh newMesh = chunkTessellator.generateMesh(chunkView);
ChunkMonitor.fireChunkTessellated(new Vector3i(c.getPosition()), newMesh);
ChunkMeshPayload payload = new ChunkMeshPayload();
payload.chunk = c;
payload.mesh = newMesh;
return Optional.of(payload);
}
return Optional.empty();
}).sequential()
.publishOn(GameThread.main())
.subscribe(payload -> {
payload.ifPresent(result -> {
if (chunksInProximityOfCamera.contains(result.chunk)) {
result.mesh.generateVBOs();
result.mesh.discardData();
if (result.chunk.hasMesh()) {
result.chunk.getMesh().dispose();
}
result.chunk.setMesh(result.mesh);
.subscribeOn(Schedulers.newSingle("chunk reactor"))
.distinct(Chunk::getPosition, () -> chunkMeshProcessing)
.doOnNext(k -> k.setDirty(false))
.parallel().runOn(Schedulers.parallel())
.<Optional<ChunkMeshPayload>>map(c -> {
ChunkView chunkView = worldProvider.getLocalView(c.getPosition());
if (chunkView != null && chunkView.isValidView() && chunkMeshProcessing.remove(c.getPosition())) {
ChunkMesh newMesh = chunkTessellator.generateMesh(chunkView);
ChunkMonitor.fireChunkTessellated(new Vector3i(c.getPosition()), newMesh);
ChunkMeshPayload payload = new ChunkMeshPayload();
payload.chunk = c;
payload.mesh = newMesh;
return Optional.of(payload);
}
});
return Optional.empty();
}).filter(Optional::isPresent).sequential()
.publishOn(GameThread.main())
.subscribe(payload -> {
payload.ifPresent(result -> {
if (chunksInProximityOfCamera.contains(result.chunk)) {
result.mesh.generateVBOs();
result.mesh.discardData();
if (result.chunk.hasMesh()) {
result.chunk.getMesh().dispose();
}
result.chunk.setMesh(result.mesh);
}
});

}, throwable -> {
logger.error("Failed to build mesh {}", throwable);
});
}, throwable -> {
logger.error("Failed to build mesh {}", throwable);
});
}

@Override
Expand Down