mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-26 15:06:28 +01:00
Exit stage left
- InstancerProvider now has an implicit render stage based on the type of visual. - block entities: AFTER_BLOCK_ENTITIES - entities: AFTER_ENTITIES - effects: AFTER_PARTICLES - Engine no longer extends InstancerProvider and instead has the full interface that accepts a RenderStage. - I'm leaving in a few extra render stages for safe keeping.
This commit is contained in:
parent
a82e3f8dd5
commit
47fe905b79
11 changed files with 62 additions and 34 deletions
|
@ -6,7 +6,10 @@ import com.jozufozu.flywheel.api.BackendImplemented;
|
|||
import com.jozufozu.flywheel.api.event.RenderContext;
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.instance.Instance;
|
||||
import com.jozufozu.flywheel.api.instance.InstanceType;
|
||||
import com.jozufozu.flywheel.api.instance.Instancer;
|
||||
import com.jozufozu.flywheel.api.instance.InstancerProvider;
|
||||
import com.jozufozu.flywheel.api.model.Model;
|
||||
import com.jozufozu.flywheel.api.task.Plan;
|
||||
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
||||
|
||||
|
@ -15,7 +18,21 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Vec3i;
|
||||
|
||||
@BackendImplemented
|
||||
public interface Engine extends InstancerProvider {
|
||||
public interface Engine {
|
||||
/**
|
||||
* Get an instancer for the given instance type, model, and render stage.
|
||||
*
|
||||
* <p>Calling this method twice with the same arguments will return the same instancer.</p>
|
||||
*
|
||||
* <p>If you are writing a visual you should probably be using
|
||||
* {@link InstancerProvider#instancer(InstanceType, Model)}, which will decide the {@code RenderStage}
|
||||
* based on what type of visual is getting the instancer.</p>
|
||||
*
|
||||
* @return An instancer for the given instance type, model, and render stage.
|
||||
* @see InstancerProvider
|
||||
*/
|
||||
<I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model, RenderStage stage);
|
||||
|
||||
/**
|
||||
* Create a plan that will be executed every frame.
|
||||
* @return A new plan.
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package com.jozufozu.flywheel.api.instance;
|
||||
|
||||
import com.jozufozu.flywheel.api.BackendImplemented;
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.model.Model;
|
||||
|
||||
@BackendImplemented
|
||||
public interface InstancerProvider {
|
||||
/**
|
||||
* Get an instancer for the given instance type, model, and render stage.
|
||||
* <br>
|
||||
* Calling this method twice with the same arguments will return the same instancer.
|
||||
* Get an instancer for the given instance type rendering the given model.
|
||||
*
|
||||
* @return An instancer for the given instance type, model, and render stage.
|
||||
* <p>Calling this method twice with the same arguments will return the same instancer.</p>
|
||||
*
|
||||
* @return An instancer for the given instance type rendering the given model.
|
||||
*/
|
||||
<I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model, RenderStage stage);
|
||||
<I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.jozufozu.flywheel.impl.visualization;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.jozufozu.flywheel.api.backend.Engine;
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.instance.Instance;
|
||||
import com.jozufozu.flywheel.api.instance.InstanceType;
|
||||
import com.jozufozu.flywheel.api.instance.Instancer;
|
||||
import com.jozufozu.flywheel.api.instance.InstancerProvider;
|
||||
import com.jozufozu.flywheel.api.model.Model;
|
||||
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
|
||||
|
||||
public record InstancerProviderImpl(Engine engine,
|
||||
RenderStage renderStage) implements InstancerProvider, Supplier<VisualizationContext> {
|
||||
@Override
|
||||
public <I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model) {
|
||||
return engine.instancer(type, model, renderStage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisualizationContext get() {
|
||||
return new VisualizationContextImpl(this, engine.renderOrigin());
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package com.jozufozu.flywheel.impl.visualization;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -23,7 +22,6 @@ import com.jozufozu.flywheel.api.visual.TickableVisual;
|
|||
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
|
||||
import com.jozufozu.flywheel.api.visual.VisualTickContext;
|
||||
import com.jozufozu.flywheel.api.visualization.VisualManager;
|
||||
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
|
||||
import com.jozufozu.flywheel.api.visualization.VisualizationLevel;
|
||||
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
|
||||
import com.jozufozu.flywheel.config.FlwConfig;
|
||||
|
@ -86,11 +84,9 @@ public class VisualizationManagerImpl implements VisualizationManager {
|
|||
.createEngine(level);
|
||||
taskExecutor = FlwTaskExecutor.get();
|
||||
|
||||
Supplier<VisualizationContext> contextSupplier = () -> new VisualizationContextImpl(engine, engine.renderOrigin());
|
||||
|
||||
var blockEntitiesStorage = new BlockEntityStorage(contextSupplier);
|
||||
var entitiesStorage = new EntityStorage(contextSupplier);
|
||||
var effectsStorage = new EffectStorage(contextSupplier);
|
||||
var blockEntitiesStorage = new BlockEntityStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_BLOCK_ENTITIES));
|
||||
var entitiesStorage = new EntityStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_ENTITIES));
|
||||
var effectsStorage = new EffectStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_PARTICLES));
|
||||
|
||||
blockEntities = new VisualManagerImpl<>(blockEntitiesStorage);
|
||||
entities = new VisualManagerImpl<>(entitiesStorage);
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.jozufozu.flywheel.lib.visual;
|
|||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.material.Material;
|
||||
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
||||
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
|
||||
|
@ -54,7 +53,7 @@ public class FireComponent {
|
|||
|
||||
private TransformedInstance createInstance(net.minecraft.client.resources.model.Material texture) {
|
||||
TransformedInstance instance = context.instancerProvider()
|
||||
.instancer(InstanceTypes.TRANSFORMED, FIRE_MODELS.get(texture), RenderStage.AFTER_ENTITIES)
|
||||
.instancer(InstanceTypes.TRANSFORMED, FIRE_MODELS.get(texture))
|
||||
.createInstance();
|
||||
instance.setBlockLight(LightTexture.block(LightTexture.FULL_BLOCK));
|
||||
instance.setChanged();
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.jetbrains.annotations.Nullable;
|
|||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.material.Material;
|
||||
import com.jozufozu.flywheel.api.material.Transparency;
|
||||
import com.jozufozu.flywheel.api.material.WriteMask;
|
||||
|
@ -70,7 +69,7 @@ public class ShadowComponent {
|
|||
|
||||
private ShadowInstance createInstance() {
|
||||
return context.instancerProvider()
|
||||
.instancer(InstanceTypes.SHADOW, SHADOW_MODEL, RenderStage.AFTER_ENTITIES)
|
||||
.instancer(InstanceTypes.SHADOW, SHADOW_MODEL)
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.joml.AxisAngle4f;
|
|||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.instance.Instance;
|
||||
import com.jozufozu.flywheel.api.visual.DynamicVisual;
|
||||
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
|
||||
|
@ -50,7 +49,7 @@ public class BellVisual extends AbstractBlockEntityVisual<BellBlockEntity> imple
|
|||
}
|
||||
|
||||
private OrientedInstance createBellInstance() {
|
||||
return instancerProvider.instancer(InstanceTypes.ORIENTED, BELL_MODEL.get(), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
return instancerProvider.instancer(InstanceTypes.ORIENTED, BELL_MODEL.get())
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.function.Consumer;
|
|||
|
||||
import org.joml.Quaternionf;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.instance.Instance;
|
||||
import com.jozufozu.flywheel.api.visual.DynamicVisual;
|
||||
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
|
||||
|
@ -98,17 +97,17 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
|||
}
|
||||
|
||||
private OrientedInstance createBottomInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.ORIENTED, BOTTOM_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
return instancerProvider.instancer(InstanceTypes.ORIENTED, BOTTOM_MODELS.get(Pair.of(chestType, texture)))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
private TransformedInstance createLidInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(Pair.of(chestType, texture)))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
private TransformedInstance createLockInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LOCK_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LOCK_MODELS.get(Pair.of(chestType, texture)))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.jozufozu.flywheel.vanilla;
|
|||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.visual.DynamicVisual;
|
||||
import com.jozufozu.flywheel.api.visual.TickableVisual;
|
||||
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
|
||||
|
@ -70,7 +69,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
|||
}
|
||||
|
||||
private TransformedInstance createBodyInstance() {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, bodyModel.get(), RenderStage.AFTER_ENTITIES)
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, bodyModel.get())
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
@ -89,7 +88,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
|||
return null;
|
||||
}
|
||||
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.block(blockState), RenderStage.AFTER_ENTITIES)
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.block(blockState))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.function.Consumer;
|
|||
|
||||
import org.joml.Quaternionf;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.instance.Instance;
|
||||
import com.jozufozu.flywheel.api.visual.DynamicVisual;
|
||||
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
|
||||
|
@ -78,12 +77,12 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
|||
}
|
||||
|
||||
private TransformedInstance createBaseInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, BASE_MODELS.get(texture), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, BASE_MODELS.get(texture))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
private TransformedInstance createLidInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(texture), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(texture))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.List;
|
|||
import org.joml.Vector3f;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent;
|
||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||
import com.jozufozu.flywheel.api.task.Plan;
|
||||
import com.jozufozu.flywheel.api.visual.Effect;
|
||||
import com.jozufozu.flywheel.api.visual.EffectVisual;
|
||||
|
@ -273,7 +272,7 @@ public class ExampleEffect implements Effect {
|
|||
this.self = self;
|
||||
|
||||
instance = ctx.instancerProvider()
|
||||
.instancer(InstanceTypes.TRANSFORMED, Models.block(Blocks.SHROOMLIGHT.defaultBlockState()), RenderStage.AFTER_PARTICLES)
|
||||
.instancer(InstanceTypes.TRANSFORMED, Models.block(Blocks.SHROOMLIGHT.defaultBlockState()))
|
||||
.createInstance();
|
||||
|
||||
instance.setBlockLight(15)
|
||||
|
|
Loading…
Reference in a new issue