mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-02-04 17:24:59 +01:00
The name game
- Rename the light visuals to have distinct names - Rename SectionProperty -> SectionCollector because it isn't really a property
This commit is contained in:
parent
caa02f2666
commit
1ea94a859e
9 changed files with 53 additions and 50 deletions
|
@ -5,9 +5,9 @@ package dev.engine_room.flywheel.api.visual;
|
|||
*
|
||||
* <p>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}.</p>
|
||||
* {@link SectionCollector#sections}.</p>
|
||||
*/
|
||||
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.
|
||||
*
|
|
@ -4,7 +4,7 @@ import org.jetbrains.annotations.ApiStatus;
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package dev.engine_room.flywheel.api.visual;
|
|||
/**
|
||||
* A marker interface allowing visuals to request light data on the GPU for a set of sections.
|
||||
*
|
||||
* <p> Sections passed into {@link SectionProperty#lightSections} will have their light data handed to the
|
||||
* <p> Sections passed into {@link SectionCollector#sections} will have their light data handed to the
|
||||
* backend and queryable by {@code flw_light*} functions in shaders.
|
||||
* <br>
|
||||
* 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 {
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@ package dev.engine_room.flywheel.api.visual;
|
|||
*
|
||||
* @see DynamicVisual
|
||||
* @see TickableVisual
|
||||
* @see LitVisual
|
||||
* @see LightUpdatedVisual
|
||||
*/
|
||||
public interface Visual {
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,8 @@ import org.joml.FrustumIntersection;
|
|||
|
||||
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 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
* <ul>
|
||||
* <li>{@link DynamicVisual}</li>
|
||||
* <li>{@link TickableVisual}</li>
|
||||
* <li>{@link LightUpdatedVisual}</li>
|
||||
* <li>{@link ShaderLightVisual}</li>
|
||||
* </ul>
|
||||
* See the interfaces' documentation for more information about each one.
|
||||
*
|
||||
|
@ -33,13 +36,13 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
*
|
||||
* @param <T> The type of {@link BlockEntity}.
|
||||
*/
|
||||
public abstract class AbstractBlockEntityVisual<T extends BlockEntity> extends AbstractVisual implements BlockEntityVisual<T>, LitVisual {
|
||||
public abstract class AbstractBlockEntityVisual<T extends BlockEntity> extends AbstractVisual implements BlockEntityVisual<T>, 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 abstract class AbstractBlockEntityVisual<T extends BlockEntity> extends A
|
|||
}
|
||||
|
||||
@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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
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 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|||
/**
|
||||
* 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<LitVisual, LongSet> visuals2Sections = new WeakHashMap<>();
|
||||
private final Map<LightUpdatedVisual, LongSet> visuals2Sections = new WeakHashMap<>();
|
||||
private final Long2ObjectMap<List<Updater>> sections2Visuals = new Long2ObjectOpenHashMap<>();
|
||||
|
||||
private final Queue<MovedVisual> movedVisuals = new ConcurrentLinkedQueue<>();
|
||||
|
@ -90,14 +90,14 @@ public class LitVisualStorage {
|
|||
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 class LitVisualStorage {
|
|||
* @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 class LitVisualStorage {
|
|||
sectionsUpdatedThisFrame.clear();
|
||||
}
|
||||
|
||||
private static int indexOfUpdater(List<Updater> listeners, LitVisual visual) {
|
||||
private static int indexOfUpdater(List<Updater> listeners, LightUpdatedVisual visual) {
|
||||
for (int i = 0; i < listeners.size(); i++) {
|
||||
if (listeners.get(i)
|
||||
.visual() == visual) {
|
||||
|
@ -162,7 +162,7 @@ public class LitVisualStorage {
|
|||
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 @@ public class LitVisualStorage {
|
|||
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 class LitVisualStorage {
|
|||
|
||||
// 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 @@ public class LitVisualStorage {
|
|||
}
|
||||
}
|
||||
|
||||
private record MovedVisual(SectionPropertyImpl tracker, LitVisual visual) {
|
||||
private record MovedVisual(SectionCollectorImpl tracker, LightUpdatedVisual visual) {
|
||||
}
|
||||
}
|
|
@ -3,17 +3,17 @@ package dev.engine_room.flywheel.impl.visualization.storage;
|
|||
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<Runnable> listeners = new ArrayList<>(2);
|
||||
|
||||
@Override
|
||||
public void lightSections(LongSet sections) {
|
||||
public void sections(LongSet sections) {
|
||||
this.sections.clear();
|
||||
this.sections.addAll(sections);
|
||||
|
|
@ -4,13 +4,13 @@ import java.util.Map;
|
|||
|
||||
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<SmoothLitVisual, SectionPropertyImpl> visuals = new Reference2ObjectOpenHashMap<>();
|
||||
public class ShaderLightStorage {
|
||||
private final Map<ShaderLightVisual, SectionCollectorImpl> visuals = new Reference2ObjectOpenHashMap<>();
|
||||
|
||||
@Nullable
|
||||
private LongSet cachedSections;
|
||||
|
@ -31,12 +31,12 @@ public class SmoothLitVisualStorage {
|
|||
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);
|
||||
|
|
@ -10,9 +10,9 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
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<T> {
|
|||
protected final PlanMap<TickableVisual, TickableVisual.Context> tickableVisuals = new PlanMap<>();
|
||||
protected final List<SimpleDynamicVisual> simpleDynamicVisuals = new ArrayList<>();
|
||||
protected final List<SimpleTickableVisual> 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<T, Visual> visuals = new Reference2ObjectOpenHashMap<>();
|
||||
|
||||
|
@ -71,10 +71,10 @@ public abstract class Storage<T> {
|
|||
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 @@ public abstract class Storage<T> {
|
|||
}
|
||||
|
||||
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 @@ public abstract class Storage<T> {
|
|||
*/
|
||||
public abstract boolean willAccept(T obj);
|
||||
|
||||
public SmoothLitVisualStorage smoothLitStorage() {
|
||||
public ShaderLightStorage smoothLitStorage() {
|
||||
return smoothLitVisuals;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue