diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/DirectInstancerProvider.java b/src/main/java/com/jozufozu/flywheel/api/backend/DirectInstancerProvider.java new file mode 100644 index 000000000..1d8271e23 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/api/backend/DirectInstancerProvider.java @@ -0,0 +1,30 @@ +package com.jozufozu.flywheel.api.backend; + +import org.jetbrains.annotations.ApiStatus; + +import com.jozufozu.flywheel.api.BackendImplemented; +import com.jozufozu.flywheel.api.context.Context; +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; + +@BackendImplemented +@ApiStatus.Experimental +public interface DirectInstancerProvider { + /** + * Get an instancer for the given instance type, model, and render stage. + * + *
Calling this method twice with the same arguments will return the same instancer.
+ * + *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 as well as hide the Context.
+ * + * @return An instancer for the given instance type, model, and render stage. + * @see InstancerProvider + */ + Instancer instancer(InstanceType type, Context context, Model model, RenderStage stage); +} diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java b/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java index c43c21688..598881b90 100644 --- a/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java +++ b/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java @@ -3,14 +3,9 @@ package com.jozufozu.flywheel.api.backend; import java.util.List; import com.jozufozu.flywheel.api.BackendImplemented; -import com.jozufozu.flywheel.api.context.Context; 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; @@ -19,21 +14,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; @BackendImplemented -public interface Engine { - /** - * Get an instancer for the given instance type, model, and render stage. - * - *Calling this method twice with the same arguments will return the same instancer.
- * - *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.
- * - * @return An instancer for the given instance type, model, and render stage. - * @see InstancerProvider - */ - Instancer instancer(InstanceType type, Context context, Model model, RenderStage stage); - +public interface Engine extends DirectInstancerProvider { /** * Create a plan that will be executed every frame. * @return A new plan. diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java b/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java index cc3cbcc9a..74c975028 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java +++ b/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java @@ -1,5 +1,8 @@ package com.jozufozu.flywheel.api.instance; +import org.jetbrains.annotations.ApiStatus; + +import com.jozufozu.flywheel.api.backend.DirectInstancerProvider; import com.jozufozu.flywheel.api.model.Model; public interface InstancerProvider { @@ -11,4 +14,17 @@ public interface InstancerProvider { * @return An instancer for the given instance type rendering the given model. */ Instancer instancer(InstanceType type, Model model); + + /** + * Get the {@link DirectInstancerProvider} this provider is built on top of. + * + *The direct provider allows for explicit control over the + * {@link com.jozufozu.flywheel.api.context.Context Context} and + * {@link com.jozufozu.flywheel.api.event.RenderStage RenderStage}. + * Generally this is a safe operation, though compatibility issues basically guaranteed + * if you mess with the Context and nest visuals.
+ * @return A DirectInstancerProvider. + */ + @ApiStatus.Experimental + DirectInstancerProvider _directProvider(); } diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java b/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java index 84e5dff56..d2f4795d3 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java @@ -1,11 +1,9 @@ package com.jozufozu.flywheel.api.visual; -import org.jetbrains.annotations.ApiStatus; import org.joml.FrustumIntersection; import net.minecraft.client.Camera; -@ApiStatus.NonExtendable public interface VisualFrameContext { Camera camera(); diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java b/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java index b74294d23..a234c87a3 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java @@ -1,8 +1,5 @@ package com.jozufozu.flywheel.api.visual; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.NonExtendable public interface VisualTickContext { // TODO: remove? } diff --git a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java index b03b7609a..f8c116359 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.api.visualization; -import org.jetbrains.annotations.ApiStatus; - import com.jozufozu.flywheel.api.instance.InstancerProvider; import net.minecraft.core.Vec3i; @@ -9,7 +7,6 @@ import net.minecraft.core.Vec3i; /** * A context object passed on visual creation. */ -@ApiStatus.NonExtendable public interface VisualizationContext { /** * @return The {@link InstancerProvider} that the visual can use to get instancers to render models. diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/InstancerProviderImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/InstancerProviderImpl.java index c354427a1..8ff117ad6 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/InstancerProviderImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/InstancerProviderImpl.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.impl.visualization; import java.util.function.Supplier; +import com.jozufozu.flywheel.api.backend.DirectInstancerProvider; import com.jozufozu.flywheel.api.backend.Engine; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; @@ -19,6 +20,11 @@ public record InstancerProviderImpl(Engine engine, return engine.instancer(type, Contexts.DEFAULT, model, renderStage); } + @Override + public DirectInstancerProvider _directProvider() { + return engine; + } + @Override public VisualizationContext get() { return new VisualizationContextImpl(this, engine.renderOrigin()); diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationContextImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationContextImpl.java index eaf888a82..db750e34a 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationContextImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationContextImpl.java @@ -12,6 +12,6 @@ import net.minecraft.core.Vec3i; * @param renderOrigin The origin of the renderer as a world position. * All models render as if this position is (0, 0, 0). */ -public record VisualizationContextImpl(InstancerProvider instancerProvider, +public record VisualizationContextImpl(InstancerProviderImpl instancerProvider, Vec3i renderOrigin) implements VisualizationContext { }