use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ChunkViewTest method testLocalToWorld.
@Test
public void testLocalToWorld() {
Chunk chunk = createChunk(1, 0, 1);
chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
Chunk[] chunks = new Chunk[] { createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2) };
ChunkViewCoreImpl chunkView = new ChunkViewCoreImpl(chunks, new BlockRegion(1, 0, 1).expand(1, 0, 1), new Vector3i(1, 1, 1), airBlock);
assertEquals(new Vector3i(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z), chunkView.toWorldPos(new Vector3i()));
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ChunkViewTest method testOffsetChunksWorldView.
@Test
public void testOffsetChunksWorldView() {
Chunk chunk = createChunk(1, 0, 1);
chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
Chunk[] chunks = new Chunk[] { createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2) };
ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, new BlockRegion(1, 0, 1).expand(1, 0, 1), new Vector3i(1, 0, 1), airBlock);
assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ChunkProcessingPipelineTest method multiRequirementsChunksExistsSuccess.
/**
* Imagine that we have task, which requires neighbors with same Z level. neighbors chunk already in chunk cache.
*/
@Test
void multiRequirementsChunksExistsSuccess() throws ExecutionException, InterruptedException, TimeoutException {
Vector3i positionToGenerate = new Vector3i(0, 0, 0);
Map<Vector3ic, Chunk> chunkCache = getNearChunkPositions(positionToGenerate).stream().filter(// remove central chunk.
(p) -> !p.equals(positionToGenerate)).map(this::createChunkAt).collect(Collectors.toMap((chunk) -> chunk.getPosition(new Vector3i()), Function.identity()));
pipeline = new ChunkProcessingPipeline(chunkCache::get, (o1, o2) -> 0);
pipeline.addStage(ChunkTaskProvider.createMulti("flat merging task", (chunks) -> chunks.stream().filter((c) -> c.getPosition().equals(positionToGenerate)).findFirst().get(), this::getNearChunkPositions));
Chunk chunk = createChunkAt(positionToGenerate);
Future<Chunk> chunkFuture = pipeline.invokeGeneratorTask(new Vector3i(0, 0, 0), () -> chunk);
Chunk chunkAfterProcessing = chunkFuture.get(1, TimeUnit.SECONDS);
Assertions.assertEquals(chunkAfterProcessing.getPosition(new Vector3i()), chunk.getPosition(new Vector3i()), "Chunk after processing must have equals position, probably pipeline lost you chunk");
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ChunkProcessingPipelineTest method simpleStopProcessingSuccess.
@Test
void simpleStopProcessingSuccess() {
pipeline = new ChunkProcessingPipeline((p) -> null, (o1, o2) -> 0);
Vector3i position = new Vector3i(0, 0, 0);
Chunk chunk = createChunkAt(position);
pipeline.addStage(ChunkTaskProvider.create("dummy long executing task", (c) -> {
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
}
return c;
}));
Future<Chunk> chunkFuture = pipeline.invokeGeneratorTask(position, () -> chunk);
pipeline.stopProcessingAt(position);
Assertions.assertThrows(CancellationException.class, () -> chunkFuture.get(1, TimeUnit.SECONDS), "chunkFuture must be cancelled, when processing stopped");
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class BulkLightPropagationTest method testAddAdjacentLights.
@Test
public void testAddAdjacentLights() {
StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
worldView.setBlockAt(new Vector3i(1, 0, 0), mediumLight);
worldView.setBlockAt(new Vector3i(0, 0, 0), mediumLight);
BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
propagator.process(new BlockChange(new Vector3i(1, 0, 0), air, mediumLight), new BlockChange(ZERO_VECTOR, air, mediumLight));
for (int i = 0; i < fullLight.getLuminance() + 1; ++i) {
for (Vector3ic pos : Diamond3iIterable.shell(new Vector3i(0, 0, 0), i).build()) {
long dist = Math.min(new Vector3i(0, 0, 0).gridDistance(pos), new Vector3i(1, 0, 0).gridDistance(pos));
byte expectedLuminance = (byte) Math.max(mediumLight.getLuminance() - dist, 0);
assertEquals(expectedLuminance, worldView.getValueAt(pos));
}
}
}
Aggregations