use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class SparseBooleanFieldFacet3D method getWorldEntries.
/**
* @return a <b>new</b> map with world-based position entries
*/
public Map<Vector3i, Boolean> getWorldEntries() {
Map<Vector3i, Boolean> result = Maps.newLinkedHashMap();
for (Entry<Vector3ic, Boolean> entry : relData.entrySet()) {
Vector3ic relPos = entry.getKey();
Vector3i worldPos = relativeToWorld(relPos.x(), relPos.y(), relPos.z());
result.put(worldPos, entry.getValue());
}
return result;
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class ChunkViewCoreImpl method setDirtyAround.
@Override
public void setDirtyAround(BlockRegionc region) {
BlockRegion tmp = new BlockRegion(region).expand(1, 1, 1);
for (Vector3ic pos : Chunks.toChunkRegion(tmp, tmp)) {
int px = pos.x() + offset.x;
int py = pos.y() + offset.y;
int pz = pos.z() + offset.z;
Chunk chunk = chunks[px + chunkRegion.getSizeX() * (pz + chunkRegion.getSizeZ() * py)];
if (chunk != null) {
chunk.setDirty(true);
}
}
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setBlocks.
@Override
public Map<Vector3ic, Block> setBlocks(Map<? extends Vector3ic, Block> blocks) {
/*
* Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
* command "showSCreen BenchmarkScreen".
*/
Set<BlockChange> changedBlocks = new HashSet<>();
Map<Vector3ic, Block> result = new HashMap<>(blocks.size());
Vector3i chunkPos = new Vector3i();
Vector3i relativePos = new Vector3i();
for (Map.Entry<? extends Vector3ic, Block> entry : blocks.entrySet()) {
Vector3ic worldPos = entry.getKey();
Chunks.toChunkPos(worldPos, chunkPos);
Chunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Block type = entry.getValue();
Chunks.toRelative(worldPos, relativePos);
Block oldBlockType = chunk.setBlock(relativePos, type);
if (oldBlockType != type) {
BlockChange oldChange = blockChanges.get(worldPos);
if (oldChange == null) {
blockChanges.put(new Vector3i(worldPos), new BlockChange(worldPos, oldBlockType, type));
} else {
oldChange.setTo(type);
}
setDirtyChunksNear(worldPos);
changedBlocks.add(new BlockChange(worldPos, oldBlockType, type));
}
result.put(worldPos, oldBlockType);
} else {
result.put(worldPos, null);
}
}
for (BlockChange change : changedBlocks) {
notifyBlockChanged(change.getPosition(), change.getTo(), change.getFrom());
}
return result;
}
use of org.joml.Vector3ic 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.Vector3ic 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