Apply directly to the engine!

- Move Engine#intancer to DirectInstancerProvider interface
- InstancerProvider allows access to the DirectInstancerProvider it's
  wrapping. This is to allow mods to change the context or RenderStage
  if they need
- Mark new methods and interfaces as experimental
- Should we mark them for removal in version 2?
- Remove NonExtendable from some context interfaces
This commit is contained in:
Jozufozu 2024-02-17 11:36:43 -07:00
parent dcecc9672d
commit e5a0e35141
8 changed files with 54 additions and 29 deletions

View file

@ -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.
*
* <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 as well as hide the Context.</p>
*
* @return An instancer for the given instance type, model, and render stage.
* @see InstancerProvider
*/
<I extends Instance> Instancer<I> instancer(InstanceType<I> type, Context context, Model model, RenderStage stage);
}

View file

@ -3,14 +3,9 @@ package com.jozufozu.flywheel.api.backend;
import java.util.List; import java.util.List;
import com.jozufozu.flywheel.api.BackendImplemented; 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.RenderContext;
import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance; 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.Plan;
import com.jozufozu.flywheel.api.task.TaskExecutor; import com.jozufozu.flywheel.api.task.TaskExecutor;
@ -19,21 +14,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
@BackendImplemented @BackendImplemented
public interface Engine { public interface Engine extends DirectInstancerProvider {
/**
* 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, Context context, Model model, RenderStage stage);
/** /**
* Create a plan that will be executed every frame. * Create a plan that will be executed every frame.
* @return A new plan. * @return A new plan.

View file

@ -1,5 +1,8 @@
package com.jozufozu.flywheel.api.instance; 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; import com.jozufozu.flywheel.api.model.Model;
public interface InstancerProvider { public interface InstancerProvider {
@ -11,4 +14,17 @@ public interface InstancerProvider {
* @return An instancer for the given instance type rendering the given model. * @return An instancer for the given instance type rendering the given model.
*/ */
<I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model); <I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model);
/**
* Get the {@link DirectInstancerProvider} this provider is built on top of.
*
* <p>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 <em>and</em> nest visuals.</p>
* @return A DirectInstancerProvider.
*/
@ApiStatus.Experimental
DirectInstancerProvider _directProvider();
} }

View file

@ -1,11 +1,9 @@
package com.jozufozu.flywheel.api.visual; package com.jozufozu.flywheel.api.visual;
import org.jetbrains.annotations.ApiStatus;
import org.joml.FrustumIntersection; import org.joml.FrustumIntersection;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
@ApiStatus.NonExtendable
public interface VisualFrameContext { public interface VisualFrameContext {
Camera camera(); Camera camera();

View file

@ -1,8 +1,5 @@
package com.jozufozu.flywheel.api.visual; package com.jozufozu.flywheel.api.visual;
import org.jetbrains.annotations.ApiStatus;
@ApiStatus.NonExtendable
public interface VisualTickContext { public interface VisualTickContext {
// TODO: remove? // TODO: remove?
} }

View file

@ -1,7 +1,5 @@
package com.jozufozu.flywheel.api.visualization; package com.jozufozu.flywheel.api.visualization;
import org.jetbrains.annotations.ApiStatus;
import com.jozufozu.flywheel.api.instance.InstancerProvider; import com.jozufozu.flywheel.api.instance.InstancerProvider;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
@ -9,7 +7,6 @@ import net.minecraft.core.Vec3i;
/** /**
* A context object passed on visual creation. * A context object passed on visual creation.
*/ */
@ApiStatus.NonExtendable
public interface VisualizationContext { public interface VisualizationContext {
/** /**
* @return The {@link InstancerProvider} that the visual can use to get instancers to render models. * @return The {@link InstancerProvider} that the visual can use to get instancers to render models.

View file

@ -2,6 +2,7 @@ package com.jozufozu.flywheel.impl.visualization;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.jozufozu.flywheel.api.backend.DirectInstancerProvider;
import com.jozufozu.flywheel.api.backend.Engine; import com.jozufozu.flywheel.api.backend.Engine;
import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instance;
@ -19,6 +20,11 @@ public record InstancerProviderImpl(Engine engine,
return engine.instancer(type, Contexts.DEFAULT, model, renderStage); return engine.instancer(type, Contexts.DEFAULT, model, renderStage);
} }
@Override
public DirectInstancerProvider _directProvider() {
return engine;
}
@Override @Override
public VisualizationContext get() { public VisualizationContext get() {
return new VisualizationContextImpl(this, engine.renderOrigin()); return new VisualizationContextImpl(this, engine.renderOrigin());

View file

@ -12,6 +12,6 @@ import net.minecraft.core.Vec3i;
* @param renderOrigin The origin of the renderer as a world position. * @param renderOrigin The origin of the renderer as a world position.
* All models render as if this position is (0, 0, 0). * 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 { Vec3i renderOrigin) implements VisualizationContext {
} }