Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.engine_room.flywheel.api.visualization;

import org.joml.Matrix3fc;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;

import dev.engine_room.flywheel.api.backend.BackendImplemented;
Expand All @@ -24,6 +25,11 @@ public interface VisualEmbedding extends VisualizationContext {
*/
void transforms(Matrix4fc pose, Matrix3fc normal);

/**
* Set the scene ID used for lighting in this embedding
*/
void setLightingInfo(Matrix4fc sceneMatrix, int scene, float skyLightScale);

/**
* Delete this embedding.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ private static Long2ObjectFunction<DataLayer> createFastBlockDataGetter(LayerLig
return null;
}

public void collectSection(long ptr, long section) {
collectSolidData(ptr, section);
collectLightData(ptr, section);
public void collectSection(long ptr, int scene, long section) {
collectSolidData(ptr, scene, section);
collectLightData(ptr, scene, section);
}

private void collectSolidData(long ptr, long section) {
private void collectSolidData(long ptr, int scene, long section) {
var blockPos = new BlockPos.MutableBlockPos();
int xMin = SectionPos.sectionToBlockCoord(SectionPos.x(section));
int yMin = SectionPos.sectionToBlockCoord(SectionPos.y(section));
Expand Down Expand Up @@ -127,7 +127,7 @@ private void collectSolidData(long ptr, long section) {
}
}

protected abstract void collectLightData(long ptr, long section);
protected abstract void collectLightData(long ptr, int scene, long section);

/**
* Write to the given section.
Expand Down Expand Up @@ -162,7 +162,7 @@ public Fast(LevelAccessor level, LayerLightEventListener skyLayerListener, Layer
}

@Override
protected void collectLightData(long ptr, long section) {
protected void collectLightData(long ptr, int scene, long section) {
collectCenter(ptr, section);

for (SectionEdge i : SectionEdge.VALUES) {
Expand Down Expand Up @@ -299,7 +299,7 @@ public Slow(LevelAccessor level, LayerLightEventListener skyLayerListener, Layer
}

@Override
protected void collectLightData(long ptr, long section) {
protected void collectLightData(long ptr, int scene, long section) {
var blockLayerListener = this.blockLayerListener;
var skyLayerListener = this.skyLayerListener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,55 @@
// Massive kudos to RogueLogix for figuring out this LUT scheme.
// First layer is Y, then X, then Z.
public final class LightLut {
public final Layer<Layer<IntLayer>> indices = new Layer<>();
public final Layer<Layer<Layer<IntLayer>>> indices = new Layer<>();

public void add(long position, int index) {
public void add(int scene, long position, int index) {
final var x = SectionPos.x(position);
final var y = SectionPos.y(position);
final var z = SectionPos.z(position);

indices.computeIfAbsent(y, Layer::new)
indices.computeIfAbsent(scene, Layer::new)
.computeIfAbsent(y, Layer::new)
.computeIfAbsent(x, IntLayer::new)
.set(z, index + 1);
}

public void prune() {
// Maybe this could be done better incrementally?
indices.prune((middle) -> middle.prune(IntLayer::prune));
indices.prune((scene) -> scene.prune((middle) -> middle.prune(IntLayer::prune)));
}

public void remove(long section) {
public void remove(int scene, long section) {
final var x = SectionPos.x(section);
final var y = SectionPos.y(section);
final var z = SectionPos.z(section);

var first = indices.get(y);
var first = indices.get(scene);

if (first == null) {
return;
}

var second = first.get(x);
var second = first.get(y);

if (second == null) {
return;
}

second.clear(z);
var third = second.get(x);

if (third == null) {
return;
}

third.clear(z);
}

public IntArrayList flatten() {
final var out = new IntArrayList();
indices.fillLut(out, (yIndices, lut) -> yIndices.fillLut(lut, IntLayer::fillLut));
this.indices.fillLut(out, (sceneIndices, lut1) -> sceneIndices.fillLut(lut1,
(yIndices, lut2) -> yIndices.fillLut(lut2, IntLayer::fillLut)
));
return out;
}

Expand Down
Loading