Revert "Listless no longer"

This reverts commit 22383fd5
This commit is contained in:
Jozufozu 2024-07-05 13:47:21 -07:00
parent 06a2788f9c
commit b2483def1d
11 changed files with 68 additions and 99 deletions

View file

@ -1,7 +1,5 @@
package dev.engine_room.flywheel.api.visual; package dev.engine_room.flywheel.api.visual;
import java.util.List;
import dev.engine_room.flywheel.api.visualization.VisualizationContext; import dev.engine_room.flywheel.api.visualization.VisualizationContext;
/** /**
@ -16,5 +14,5 @@ public interface Effect {
* @param ctx The visualization context. * @param ctx The visualization context.
* @return An arbitrary EffectVisual. * @return An arbitrary EffectVisual.
*/ */
List<EffectVisual<?>> visualize(VisualizationContext ctx, float partialTick); EffectVisual<?> visualize(VisualizationContext ctx, float partialTick);
} }

View file

@ -1,7 +1,5 @@
package dev.engine_room.flywheel.api.visualization; package dev.engine_room.flywheel.api.visualization;
import java.util.List;
import dev.engine_room.flywheel.api.visual.BlockEntityVisual; import dev.engine_room.flywheel.api.visual.BlockEntityVisual;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
@ -18,7 +16,7 @@ public interface BlockEntityVisualizer<T extends BlockEntity> {
* @param blockEntity The block entity to construct a visual for. * @param blockEntity The block entity to construct a visual for.
* @return The visual. * @return The visual.
*/ */
List<BlockEntityVisual<? super T>> createVisual(VisualizationContext ctx, T blockEntity, float partialTick); BlockEntityVisual<? super T> createVisual(VisualizationContext ctx, T blockEntity, float partialTick);
/** /**
* Checks if the given block entity should not be rendered with the vanilla {@link BlockEntityRenderer}. * Checks if the given block entity should not be rendered with the vanilla {@link BlockEntityRenderer}.

View file

@ -1,7 +1,5 @@
package dev.engine_room.flywheel.api.visualization; package dev.engine_room.flywheel.api.visualization;
import java.util.List;
import dev.engine_room.flywheel.api.visual.EntityVisual; import dev.engine_room.flywheel.api.visual.EntityVisual;
import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -18,7 +16,7 @@ public interface EntityVisualizer<T extends Entity> {
* @param entity The entity to construct a visual for. * @param entity The entity to construct a visual for.
* @return The visual. * @return The visual.
*/ */
List<EntityVisual<? super T>> createVisual(VisualizationContext ctx, T entity, float partialTick); EntityVisual<? super T> createVisual(VisualizationContext ctx, T entity, float partialTick);
/** /**
* Checks if the given entity should not render with the vanilla {@link EntityRenderer}. * Checks if the given entity should not render with the vanilla {@link EntityRenderer}.

View file

@ -1,6 +1,5 @@
package dev.engine_room.flywheel.lib.visual; package dev.engine_room.flywheel.lib.visual;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -24,8 +23,8 @@ public class SimpleBlockEntityVisualizer<T extends BlockEntity> implements Block
} }
@Override @Override
public List<BlockEntityVisual<? super T>> createVisual(VisualizationContext ctx, T blockEntity, float partialTick) { public BlockEntityVisual<? super T> createVisual(VisualizationContext ctx, T blockEntity, float partialTick) {
return List.of(visualFactory.create(ctx, blockEntity, partialTick)); return visualFactory.create(ctx, blockEntity, partialTick);
} }
@Override @Override

View file

@ -1,6 +1,5 @@
package dev.engine_room.flywheel.lib.visual; package dev.engine_room.flywheel.lib.visual;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -24,8 +23,8 @@ public class SimpleEntityVisualizer<T extends Entity> implements EntityVisualize
} }
@Override @Override
public List<EntityVisual<? super T>> createVisual(VisualizationContext ctx, T entity, float partialTick) { public EntityVisual<? super T> createVisual(VisualizationContext ctx, T entity, float partialTick) {
return List.of(visualFactory.create(ctx, entity, partialTick)); return visualFactory.create(ctx, entity, partialTick);
} }
@Override @Override

View file

@ -17,7 +17,6 @@ import dev.engine_room.flywheel.api.event.RenderStage;
import dev.engine_room.flywheel.api.instance.Instance; import dev.engine_room.flywheel.api.instance.Instance;
import dev.engine_room.flywheel.api.task.Plan; import dev.engine_room.flywheel.api.task.Plan;
import dev.engine_room.flywheel.api.task.TaskExecutor; import dev.engine_room.flywheel.api.task.TaskExecutor;
import dev.engine_room.flywheel.api.visual.BlockEntityVisual;
import dev.engine_room.flywheel.api.visual.DynamicVisual; import dev.engine_room.flywheel.api.visual.DynamicVisual;
import dev.engine_room.flywheel.api.visual.Effect; import dev.engine_room.flywheel.api.visual.Effect;
import dev.engine_room.flywheel.api.visual.TickableVisual; import dev.engine_room.flywheel.api.visual.TickableVisual;
@ -262,23 +261,21 @@ public class VisualizationManagerImpl implements VisualizationManager {
continue; continue;
} }
var visualList = blockEntities.getStorage() var visual = blockEntities.getStorage()
.visualAtPos(entry.getLongKey()); .visualAtPos(entry.getLongKey());
if (visualList == null || visualList.isEmpty()) { if (visual == null) {
// The block doesn't have a visual, this is probably the common case. // The block doesn't have a visual, this is probably the common case.
continue; continue;
} }
List<Instance> instances = new ArrayList<>(); List<Instance> instances = new ArrayList<>();
for (BlockEntityVisual<?> visual : visualList) { visual.collectCrumblingInstances(instance -> {
visual.collectCrumblingInstances(instance -> { if (instance != null) {
if (instance != null) { instances.add(instance);
instances.add(instance); }
} });
});
}
if (instances.isEmpty()) { if (instances.isEmpty()) {
// The visual doesn't want to render anything crumbling. // The visual doesn't want to render anything crumbling.

View file

@ -1,6 +1,5 @@
package dev.engine_room.flywheel.impl.visualization.manager; package dev.engine_room.flywheel.impl.visualization.manager;
import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -17,14 +16,14 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
public class BlockEntityStorage extends Storage<BlockEntity> { public class BlockEntityStorage extends Storage<BlockEntity> {
private final Long2ObjectMap<List<? extends BlockEntityVisual<?>>> posLookup = new Long2ObjectOpenHashMap<>(); private final Long2ObjectMap<BlockEntityVisual<?>> posLookup = new Long2ObjectOpenHashMap<>();
public BlockEntityStorage(Supplier<VisualizationContext> visualizationContextSupplier) { public BlockEntityStorage(Supplier<VisualizationContext> visualizationContextSupplier) {
super(visualizationContextSupplier); super(visualizationContextSupplier);
} }
@Nullable @Nullable
public List<? extends BlockEntityVisual<?>> visualAtPos(long pos) { public BlockEntityVisual<?> visualAtPos(long pos) {
return posLookup.get(pos); return posLookup.get(pos);
} }
@ -53,18 +52,19 @@ public class BlockEntityStorage extends Storage<BlockEntity> {
} }
@Override @Override
protected List<? extends BlockEntityVisual<?>> createRaw(BlockEntity obj, float partialTick) { @Nullable
protected BlockEntityVisual<?> createRaw(BlockEntity obj, float partialTick) {
var visualizer = VisualizationHelper.getVisualizer(obj); var visualizer = VisualizationHelper.getVisualizer(obj);
if (visualizer == null) { if (visualizer == null) {
return List.of(); return null;
} }
var visualList = visualizer.createVisual(visualizationContextSupplier.get(), obj, partialTick); var visual = visualizer.createVisual(visualizationContextSupplier.get(), obj, partialTick);
BlockPos blockPos = obj.getBlockPos(); BlockPos blockPos = obj.getBlockPos();
posLookup.put(blockPos.asLong(), visualList); posLookup.put(blockPos.asLong(), visual);
return visualList; return visual;
} }
@Override @Override

View file

@ -1,6 +1,5 @@
package dev.engine_room.flywheel.impl.visualization.manager; package dev.engine_room.flywheel.impl.visualization.manager;
import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import dev.engine_room.flywheel.api.visual.Effect; import dev.engine_room.flywheel.api.visual.Effect;
@ -14,7 +13,7 @@ public class EffectStorage extends Storage<Effect> {
} }
@Override @Override
protected List<? extends EffectVisual<?>> createRaw(Effect obj, float partialTick) { protected EffectVisual<?> createRaw(Effect obj, float partialTick) {
return obj.visualize(visualizationContextSupplier.get(), partialTick); return obj.visualize(visualizationContextSupplier.get(), partialTick);
} }

View file

@ -1,6 +1,5 @@
package dev.engine_room.flywheel.impl.visualization.manager; package dev.engine_room.flywheel.impl.visualization.manager;
import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import dev.engine_room.flywheel.api.visual.EntityVisual; import dev.engine_room.flywheel.api.visual.EntityVisual;
@ -16,10 +15,10 @@ public class EntityStorage extends Storage<Entity> {
} }
@Override @Override
protected List<? extends EntityVisual<?>> createRaw(Entity obj, float partialTick) { protected EntityVisual<?> createRaw(Entity obj, float partialTick) {
var visualizer = VisualizationHelper.getVisualizer(obj); var visualizer = VisualizationHelper.getVisualizer(obj);
if (visualizer == null) { if (visualizer == null) {
return List.of(); return null;
} }
return visualizer.createVisual(visualizationContextSupplier.get(), obj, partialTick); return visualizer.createVisual(visualizationContextSupplier.get(), obj, partialTick);

View file

@ -26,7 +26,8 @@ public class VisualManagerImpl<T, S extends Storage<T>> implements VisualManager
@Override @Override
public int getVisualCount() { public int getVisualCount() {
return getStorage().visualCount(); return getStorage().getAllVisuals()
.size();
} }
@Override @Override

View file

@ -1,10 +1,13 @@
package dev.engine_room.flywheel.impl.visualization.storage; package dev.engine_room.flywheel.impl.visualization.storage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;
import dev.engine_room.flywheel.api.task.Plan; import dev.engine_room.flywheel.api.task.Plan;
import dev.engine_room.flywheel.api.visual.DynamicVisual; import dev.engine_room.flywheel.api.visual.DynamicVisual;
import dev.engine_room.flywheel.api.visual.LitVisual; import dev.engine_room.flywheel.api.visual.LitVisual;
@ -26,50 +29,59 @@ public abstract class Storage<T> {
protected final List<SimpleTickableVisual> simpleTickableVisuals = new ArrayList<>(); protected final List<SimpleTickableVisual> simpleTickableVisuals = new ArrayList<>();
protected final LitVisualStorage litVisuals = new LitVisualStorage(); protected final LitVisualStorage litVisuals = new LitVisualStorage();
private final Map<T, List<? extends Visual>> visuals = new Reference2ObjectOpenHashMap<>(); private final Map<T, Visual> visuals = new Reference2ObjectOpenHashMap<>();
public Storage(Supplier<VisualizationContext> visualizationContextSupplier) { public Storage(Supplier<VisualizationContext> visualizationContextSupplier) {
this.visualizationContextSupplier = visualizationContextSupplier; this.visualizationContextSupplier = visualizationContextSupplier;
} }
public int visualCount() { public Collection<Visual> getAllVisuals() {
int out = 0; return visuals.values();
for (var visualList : visuals.values()) {
out += visualList.size();
}
return out;
} }
public void add(T obj, float partialTick) { public void add(T obj, float partialTick) {
var visualList = this.visuals.get(obj); Visual visual = visuals.get(obj);
if (visualList == null) { if (visual == null) {
create(obj, partialTick); create(obj, partialTick);
} }
} }
public void remove(T obj) { public void remove(T obj) {
var visualList = this.visuals.remove(obj); Visual visual = visuals.remove(obj);
if (visualList == null || visualList.isEmpty()) { if (visual == null) {
return; return;
} }
for (Visual visual : visualList) { if (visual instanceof TickableVisual tickable) {
remove(visual); if (visual instanceof SimpleTickableVisual simpleTickable) {
simpleTickableVisuals.remove(simpleTickable);
} else {
tickableVisuals.remove(tickable);
}
} }
if (visual instanceof DynamicVisual dynamic) {
if (visual instanceof SimpleDynamicVisual simpleDynamic) {
simpleDynamicVisuals.remove(simpleDynamic);
} else {
dynamicVisuals.remove(dynamic);
}
}
if (visual instanceof LitVisual lit) {
litVisuals.remove(lit);
}
visual.delete();
} }
public void update(T obj, float partialTick) { public void update(T obj, float partialTick) {
var visualList = visuals.get(obj); Visual visual = visuals.get(obj);
if (visualList == null || visualList.isEmpty()) { if (visual == null) {
return; return;
} }
for (Visual visual : visualList) { visual.update(partialTick);
visual.update(partialTick);
}
} }
public void recreateAll(float partialTick) { public void recreateAll(float partialTick) {
@ -78,17 +90,13 @@ public abstract class Storage<T> {
simpleTickableVisuals.clear(); simpleTickableVisuals.clear();
simpleDynamicVisuals.clear(); simpleDynamicVisuals.clear();
litVisuals.clear(); litVisuals.clear();
visuals.replaceAll((obj, visuals) -> { visuals.replaceAll((obj, visual) -> {
visuals.forEach(Visual::delete); visual.delete();
var out = createRaw(obj, partialTick); var out = createRaw(obj, partialTick);
if (out.isEmpty()) { if (out != null) {
return null; setup(out);
}
for (Visual visual : out) {
setup(visual);
} }
return out; return out;
@ -99,28 +107,22 @@ public abstract class Storage<T> {
tickableVisuals.clear(); tickableVisuals.clear();
dynamicVisuals.clear(); dynamicVisuals.clear();
litVisuals.clear(); litVisuals.clear();
for (var visualList : visuals.values()) { visuals.values()
for (Visual visual : visualList) { .forEach(Visual::delete);
visual.delete();
}
}
visuals.clear(); visuals.clear();
} }
private void create(T obj, float partialTick) { private void create(T obj, float partialTick) {
var visuals = createRaw(obj, partialTick); var visual = createRaw(obj, partialTick);
if (visuals.isEmpty()) { if (visual != null) {
return;
}
this.visuals.put(obj, visuals);
for (Visual visual : visuals) {
setup(visual); setup(visual);
visuals.put(obj, visual);
} }
} }
protected abstract List<? extends Visual> createRaw(T obj, float partialTick); @Nullable
protected abstract Visual createRaw(T obj, float partialTick);
public Plan<DynamicVisual.Context> framePlan() { public Plan<DynamicVisual.Context> framePlan() {
return NestedPlan.of(dynamicVisuals, litVisuals.plan(), ForEachPlan.of(() -> simpleDynamicVisuals, SimpleDynamicVisual::beginFrame)); return NestedPlan.of(dynamicVisuals, litVisuals.plan(), ForEachPlan.of(() -> simpleDynamicVisuals, SimpleDynamicVisual::beginFrame));
@ -156,27 +158,6 @@ public abstract class Storage<T> {
} }
} }
private void remove(Visual visual) {
if (visual instanceof TickableVisual tickable) {
if (visual instanceof SimpleTickableVisual simpleTickable) {
simpleTickableVisuals.remove(simpleTickable);
} else {
tickableVisuals.remove(tickable);
}
}
if (visual instanceof DynamicVisual dynamic) {
if (visual instanceof SimpleDynamicVisual simpleDynamic) {
simpleDynamicVisuals.remove(simpleDynamic);
} else {
dynamicVisuals.remove(dynamic);
}
}
if (visual instanceof LitVisual lit) {
litVisuals.remove(lit);
}
visual.delete();
}
/** /**
* Is the given object currently capable of being added? * Is the given object currently capable of being added?
* *