From 8a8258e8b7e5e0be034677dbb21a525158a41ab8 Mon Sep 17 00:00:00 2001
From: Jozufozu
Date: Sun, 14 Jul 2024 17:13:53 -0700
Subject: [PATCH] The name game
- Rename the light visuals to have distinct names
- Rename SectionProperty -> SectionCollector because it isn't really a
property
---
...LitVisual.java => LightUpdatedVisual.java} | 4 +--
.../api/visual/SectionTrackedVisual.java | 8 +++---
...hLitVisual.java => ShaderLightVisual.java} | 4 +--
.../flywheel/api/visual/Visual.java | 2 +-
.../lib/visual/AbstractBlockEntityVisual.java | 15 ++++++-----
...lStorage.java => LightUpdatedStorage.java} | 24 ++++++++---------
...rtyImpl.java => SectionCollectorImpl.java} | 6 ++---
...alStorage.java => ShaderLightStorage.java} | 14 +++++-----
.../impl/visualization/storage/Storage.java | 26 +++++++++----------
9 files changed, 53 insertions(+), 50 deletions(-)
rename common/src/api/java/dev/engine_room/flywheel/api/visual/{LitVisual.java => LightUpdatedVisual.java} (89%)
rename common/src/api/java/dev/engine_room/flywheel/api/visual/{SmoothLitVisual.java => ShaderLightVisual.java} (69%)
rename common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/{LitVisualStorage.java => LightUpdatedStorage.java} (87%)
rename common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/{SectionPropertyImpl.java => SectionCollectorImpl.java} (72%)
rename common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/{SmoothLitVisualStorage.java => ShaderLightStorage.java} (67%)
diff --git a/common/src/api/java/dev/engine_room/flywheel/api/visual/LitVisual.java b/common/src/api/java/dev/engine_room/flywheel/api/visual/LightUpdatedVisual.java
similarity index 89%
rename from common/src/api/java/dev/engine_room/flywheel/api/visual/LitVisual.java
rename to common/src/api/java/dev/engine_room/flywheel/api/visual/LightUpdatedVisual.java
index bd01158cd..3ac56d93d 100644
--- a/common/src/api/java/dev/engine_room/flywheel/api/visual/LitVisual.java
+++ b/common/src/api/java/dev/engine_room/flywheel/api/visual/LightUpdatedVisual.java
@@ -5,9 +5,9 @@
*
* If your visual moves around in the level at all, you should use {@link TickableVisual} or {@link DynamicVisual},
* and poll for light yourself along with listening for updates. When your visual moves to a different section, call
- * {@link SectionProperty#lightSections}.
+ * {@link SectionCollector#sections}.
*/
-public non-sealed interface LitVisual extends SectionTrackedVisual {
+public non-sealed interface LightUpdatedVisual extends SectionTrackedVisual {
/**
* Called when a section this visual is contained in receives a light update.
*
diff --git a/common/src/api/java/dev/engine_room/flywheel/api/visual/SectionTrackedVisual.java b/common/src/api/java/dev/engine_room/flywheel/api/visual/SectionTrackedVisual.java
index 92bcca70d..725d4a4ed 100644
--- a/common/src/api/java/dev/engine_room/flywheel/api/visual/SectionTrackedVisual.java
+++ b/common/src/api/java/dev/engine_room/flywheel/api/visual/SectionTrackedVisual.java
@@ -4,7 +4,7 @@
import it.unimi.dsi.fastutil.longs.LongSet;
-public sealed interface SectionTrackedVisual extends Visual permits SmoothLitVisual, LitVisual {
+public sealed interface SectionTrackedVisual extends Visual permits ShaderLightVisual, LightUpdatedVisual {
/**
* Set the section property object.
*
@@ -14,13 +14,13 @@ public sealed interface SectionTrackedVisual extends Visual permits SmoothLitVis
*
* @param property The property.
*/
- void setSectionProperty(SectionProperty property);
+ void setSectionCollector(SectionCollector property);
@ApiStatus.NonExtendable
- interface SectionProperty {
+ interface SectionCollector {
/**
* Assign the set of sections this visual wants to track itself in.
*/
- void lightSections(LongSet sections);
+ void sections(LongSet sections);
}
}
diff --git a/common/src/api/java/dev/engine_room/flywheel/api/visual/SmoothLitVisual.java b/common/src/api/java/dev/engine_room/flywheel/api/visual/ShaderLightVisual.java
similarity index 69%
rename from common/src/api/java/dev/engine_room/flywheel/api/visual/SmoothLitVisual.java
rename to common/src/api/java/dev/engine_room/flywheel/api/visual/ShaderLightVisual.java
index 23b09d197..dcd4ed73d 100644
--- a/common/src/api/java/dev/engine_room/flywheel/api/visual/SmoothLitVisual.java
+++ b/common/src/api/java/dev/engine_room/flywheel/api/visual/ShaderLightVisual.java
@@ -3,12 +3,12 @@
/**
* A marker interface allowing visuals to request light data on the GPU for a set of sections.
*
- * Sections passed into {@link SectionProperty#lightSections} will have their light data handed to the
+ *
Sections passed into {@link SectionCollector#sections} will have their light data handed to the
* backend and queryable by {@code flw_light*} functions in shaders.
*
* Note that the queryable light data is shared across all visuals, so even if one specific visual does not
* request a given section, the data will be available if another visual does.
*/
-public non-sealed interface SmoothLitVisual extends SectionTrackedVisual {
+public non-sealed interface ShaderLightVisual extends SectionTrackedVisual {
}
diff --git a/common/src/api/java/dev/engine_room/flywheel/api/visual/Visual.java b/common/src/api/java/dev/engine_room/flywheel/api/visual/Visual.java
index 4aed57f59..60b42fd15 100644
--- a/common/src/api/java/dev/engine_room/flywheel/api/visual/Visual.java
+++ b/common/src/api/java/dev/engine_room/flywheel/api/visual/Visual.java
@@ -5,7 +5,7 @@
*
* @see DynamicVisual
* @see TickableVisual
- * @see LitVisual
+ * @see LightUpdatedVisual
*/
public interface Visual {
/**
diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/AbstractBlockEntityVisual.java b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/AbstractBlockEntityVisual.java
index 1aab4baa6..a3fafb59f 100644
--- a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/AbstractBlockEntityVisual.java
+++ b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/AbstractBlockEntityVisual.java
@@ -5,7 +5,8 @@
import dev.engine_room.flywheel.api.visual.BlockEntityVisual;
import dev.engine_room.flywheel.api.visual.DynamicVisual;
-import dev.engine_room.flywheel.api.visual.LitVisual;
+import dev.engine_room.flywheel.api.visual.LightUpdatedVisual;
+import dev.engine_room.flywheel.api.visual.ShaderLightVisual;
import dev.engine_room.flywheel.api.visual.TickableVisual;
import dev.engine_room.flywheel.api.visualization.VisualManager;
import dev.engine_room.flywheel.api.visualization.VisualizationContext;
@@ -25,6 +26,8 @@
*
* - {@link DynamicVisual}
* - {@link TickableVisual}
+ * - {@link LightUpdatedVisual}
+ * - {@link ShaderLightVisual}
*
* See the interfaces' documentation for more information about each one.
*
@@ -33,13 +36,13 @@
*
* @param The type of {@link BlockEntity}.
*/
-public abstract class AbstractBlockEntityVisual extends AbstractVisual implements BlockEntityVisual, LitVisual {
+public abstract class AbstractBlockEntityVisual extends AbstractVisual implements BlockEntityVisual, LightUpdatedVisual {
protected final T blockEntity;
protected final BlockPos pos;
protected final BlockPos visualPos;
protected final BlockState blockState;
@Nullable
- protected SectionProperty lightSections;
+ protected SectionCollector lightSections;
public AbstractBlockEntityVisual(VisualizationContext ctx, T blockEntity, float partialTick) {
super(ctx, blockEntity.getLevel(), partialTick);
@@ -50,9 +53,9 @@ public AbstractBlockEntityVisual(VisualizationContext ctx, T blockEntity, float
}
@Override
- public void setSectionProperty(SectionProperty property) {
- this.lightSections = property;
- lightSections.lightSections(LongSet.of(SectionPos.asLong(pos)));
+ public void setSectionCollector(SectionCollector sectionCollector) {
+ this.lightSections = sectionCollector;
+ lightSections.sections(LongSet.of(SectionPos.asLong(pos)));
}
/**
diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/LitVisualStorage.java b/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/LightUpdatedStorage.java
similarity index 87%
rename from common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/LitVisualStorage.java
rename to common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/LightUpdatedStorage.java
index c7cf7b916..d2df21868 100644
--- a/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/LitVisualStorage.java
+++ b/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/LightUpdatedStorage.java
@@ -10,7 +10,7 @@
import dev.engine_room.flywheel.api.task.Plan;
import dev.engine_room.flywheel.api.task.TaskExecutor;
import dev.engine_room.flywheel.api.visual.DynamicVisual;
-import dev.engine_room.flywheel.api.visual.LitVisual;
+import dev.engine_room.flywheel.api.visual.LightUpdatedVisual;
import dev.engine_room.flywheel.lib.task.Distribute;
import dev.engine_room.flywheel.lib.task.SimplyComposedPlan;
import dev.engine_room.flywheel.lib.task.Synchronizer;
@@ -24,11 +24,11 @@
/**
* Keeps track of what chunks/sections each listener is in, so we can update exactly what needs to be updated.
*/
-public class LitVisualStorage {
+public class LightUpdatedStorage {
private static final long NEVER_UPDATED = Long.MIN_VALUE;
private static final long INITIAL_UPDATE_ID = NEVER_UPDATED + 1;
- private final Map visuals2Sections = new WeakHashMap<>();
+ private final Map visuals2Sections = new WeakHashMap<>();
private final Long2ObjectMap> sections2Visuals = new Long2ObjectOpenHashMap<>();
private final Queue movedVisuals = new ConcurrentLinkedQueue<>();
@@ -90,14 +90,14 @@ public boolean isEmpty() {
return visuals2Sections.isEmpty();
}
- public void add(SectionPropertyImpl tracker, LitVisual visual) {
+ public void add(SectionCollectorImpl tracker, LightUpdatedVisual visual) {
var moved = new MovedVisual(tracker, visual);
tracker.addListener(() -> movedVisuals.add(moved));
updateTracking(tracker, visual);
}
- public void updateTracking(SectionPropertyImpl tracker, LitVisual visual) {
+ public void updateTracking(SectionCollectorImpl tracker, LightUpdatedVisual visual) {
if (tracker.sections.isEmpty()) {
// Add the visual to the map even if sections is empty, this way we can distinguish from deleted visuals
visuals2Sections.put(visual, LongSet.of());
@@ -129,7 +129,7 @@ public void enqueueLightUpdateSection(long section) {
* @param visual The visual to remove.
* @return {@code true} if the visual was removed, {@code false} otherwise.
*/
- public boolean remove(LitVisual visual) {
+ public boolean remove(LightUpdatedVisual visual) {
var sections = visuals2Sections.remove(visual);
if (sections == null) {
@@ -152,7 +152,7 @@ public void clear() {
sectionsUpdatedThisFrame.clear();
}
- private static int indexOfUpdater(List listeners, LitVisual visual) {
+ private static int indexOfUpdater(List listeners, LightUpdatedVisual visual) {
for (int i = 0; i < listeners.size(); i++) {
if (listeners.get(i)
.visual() == visual) {
@@ -162,7 +162,7 @@ private static int indexOfUpdater(List listeners, LitVisual visual) {
return -1;
}
- private static Updater createUpdater(LitVisual visual, int sectionCount) {
+ private static Updater createUpdater(LightUpdatedVisual visual, int sectionCount) {
if (sectionCount == 1) {
return new Updater.Simple(visual);
} else {
@@ -174,10 +174,10 @@ private static Updater createUpdater(LitVisual visual, int sectionCount) {
sealed interface Updater {
void updateLight(Context ctx);
- LitVisual visual();
+ LightUpdatedVisual visual();
// The visual is only in one section. In this case, we can just update the visual directly.
- record Simple(LitVisual visual) implements Updater {
+ record Simple(LightUpdatedVisual visual) implements Updater {
@Override
public void updateLight(Context ctx) {
visual.updateLight(ctx.partialTick);
@@ -186,7 +186,7 @@ public void updateLight(Context ctx) {
// The visual is in multiple sections. Here we need to make sure that the visual only gets updated once,
// even when multiple sections it was contained in are updated at the same time.
- record Synced(LitVisual visual, AtomicLong updateId) implements Updater {
+ record Synced(LightUpdatedVisual visual, AtomicLong updateId) implements Updater {
@Override
public void updateLight(Context ctx) {
// Different update ID means we won, so we can update the visual.
@@ -201,6 +201,6 @@ record Context(long updateId, float partialTick) {
}
}
- private record MovedVisual(SectionPropertyImpl tracker, LitVisual visual) {
+ private record MovedVisual(SectionCollectorImpl tracker, LightUpdatedVisual visual) {
}
}
diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SectionPropertyImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SectionCollectorImpl.java
similarity index 72%
rename from common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SectionPropertyImpl.java
rename to common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SectionCollectorImpl.java
index 88c5bf0d7..faa1d7b45 100644
--- a/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SectionPropertyImpl.java
+++ b/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SectionCollectorImpl.java
@@ -3,17 +3,17 @@
import java.util.ArrayList;
import java.util.List;
-import dev.engine_room.flywheel.api.visual.SmoothLitVisual;
+import dev.engine_room.flywheel.api.visual.SectionTrackedVisual;
import it.unimi.dsi.fastutil.longs.LongArraySet;
import it.unimi.dsi.fastutil.longs.LongSet;
-public class SectionPropertyImpl implements SmoothLitVisual.SectionProperty {
+public class SectionCollectorImpl implements SectionTrackedVisual.SectionCollector {
public final LongSet sections = new LongArraySet();
private final List listeners = new ArrayList<>(2);
@Override
- public void lightSections(LongSet sections) {
+ public void sections(LongSet sections) {
this.sections.clear();
this.sections.addAll(sections);
diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SmoothLitVisualStorage.java b/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/ShaderLightStorage.java
similarity index 67%
rename from common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SmoothLitVisualStorage.java
rename to common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/ShaderLightStorage.java
index dc6b0fbac..c51a55467 100644
--- a/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/SmoothLitVisualStorage.java
+++ b/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/ShaderLightStorage.java
@@ -4,13 +4,13 @@
import org.jetbrains.annotations.Nullable;
-import dev.engine_room.flywheel.api.visual.SmoothLitVisual;
+import dev.engine_room.flywheel.api.visual.ShaderLightVisual;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
-public class SmoothLitVisualStorage {
- private final Map visuals = new Reference2ObjectOpenHashMap<>();
+public class ShaderLightStorage {
+ private final Map visuals = new Reference2ObjectOpenHashMap<>();
@Nullable
private LongSet cachedSections;
@@ -31,12 +31,12 @@ public LongSet sections() {
return cachedSections;
}
- public void remove(SmoothLitVisual smoothLit) {
- visuals.remove(smoothLit);
+ public void remove(ShaderLightVisual visual) {
+ visuals.remove(visual);
}
- public void add(SectionPropertyImpl tracker, SmoothLitVisual smoothLit) {
- visuals.put(smoothLit, tracker);
+ public void add(SectionCollectorImpl tracker, ShaderLightVisual visual) {
+ visuals.put(visual, tracker);
tracker.addListener(this::markDirty);
diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/Storage.java b/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/Storage.java
index 3f8fab082..f219e9138 100644
--- a/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/Storage.java
+++ b/common/src/main/java/dev/engine_room/flywheel/impl/visualization/storage/Storage.java
@@ -10,9 +10,9 @@
import dev.engine_room.flywheel.api.task.Plan;
import dev.engine_room.flywheel.api.visual.DynamicVisual;
-import dev.engine_room.flywheel.api.visual.LitVisual;
+import dev.engine_room.flywheel.api.visual.LightUpdatedVisual;
import dev.engine_room.flywheel.api.visual.SectionTrackedVisual;
-import dev.engine_room.flywheel.api.visual.SmoothLitVisual;
+import dev.engine_room.flywheel.api.visual.ShaderLightVisual;
import dev.engine_room.flywheel.api.visual.TickableVisual;
import dev.engine_room.flywheel.api.visual.Visual;
import dev.engine_room.flywheel.api.visualization.VisualizationContext;
@@ -29,8 +29,8 @@ public abstract class Storage {
protected final PlanMap tickableVisuals = new PlanMap<>();
protected final List simpleDynamicVisuals = new ArrayList<>();
protected final List simpleTickableVisuals = new ArrayList<>();
- protected final LitVisualStorage litVisuals = new LitVisualStorage();
- protected final SmoothLitVisualStorage smoothLitVisuals = new SmoothLitVisualStorage();
+ protected final LightUpdatedStorage litVisuals = new LightUpdatedStorage();
+ protected final ShaderLightStorage smoothLitVisuals = new ShaderLightStorage();
private final Map visuals = new Reference2ObjectOpenHashMap<>();
@@ -71,10 +71,10 @@ public void remove(T obj) {
dynamicVisuals.remove(dynamic);
}
}
- if (visual instanceof LitVisual lit) {
+ if (visual instanceof LightUpdatedVisual lit) {
litVisuals.remove(lit);
}
- if (visual instanceof SmoothLitVisual smoothLit) {
+ if (visual instanceof ShaderLightVisual smoothLit) {
smoothLitVisuals.remove(smoothLit);
}
visual.delete();
@@ -161,17 +161,17 @@ private void setup(Visual visual) {
}
if (visual instanceof SectionTrackedVisual tracked) {
- SectionPropertyImpl sectionProperty = new SectionPropertyImpl();
+ SectionCollectorImpl sectionProperty = new SectionCollectorImpl();
// Give the visual a chance to fill in the property.
- tracked.setSectionProperty(sectionProperty);
+ tracked.setSectionCollector(sectionProperty);
- if (visual instanceof LitVisual lit) {
- litVisuals.add(sectionProperty, lit);
+ if (visual instanceof LightUpdatedVisual lightUpdated) {
+ litVisuals.add(sectionProperty, lightUpdated);
}
- if (visual instanceof SmoothLitVisual smoothLit) {
- smoothLitVisuals.add(sectionProperty, smoothLit);
+ if (visual instanceof ShaderLightVisual shaderLight) {
+ smoothLitVisuals.add(sectionProperty, shaderLight);
}
}
}
@@ -183,7 +183,7 @@ private void setup(Visual visual) {
*/
public abstract boolean willAccept(T obj);
- public SmoothLitVisualStorage smoothLitStorage() {
+ public ShaderLightStorage smoothLitStorage() {
return smoothLitVisuals;
}
}