mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
No hacks here no sir
- Add VisualizationContext#withContext to formalize the way contexts are "pushed" - Also push a render origin so contexts have better control over visuals' positions - Make InstancerProvider NonExtendable
This commit is contained in:
parent
9a5bd0cac8
commit
b49e9f1d28
@ -1,7 +1,10 @@
|
|||||||
package com.jozufozu.flywheel.api.instance;
|
package com.jozufozu.flywheel.api.instance;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.model.Model;
|
import com.jozufozu.flywheel.api.model.Model;
|
||||||
|
|
||||||
|
@ApiStatus.NonExtendable
|
||||||
public interface InstancerProvider {
|
public interface InstancerProvider {
|
||||||
/**
|
/**
|
||||||
* Get an instancer for the given instance type rendering the given model.
|
* Get an instancer for the given instance type rendering the given model.
|
||||||
|
@ -2,6 +2,7 @@ package com.jozufozu.flywheel.api.visualization;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.context.Context;
|
||||||
import com.jozufozu.flywheel.api.instance.InstancerProvider;
|
import com.jozufozu.flywheel.api.instance.InstancerProvider;
|
||||||
|
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
@ -22,4 +23,14 @@ public interface VisualizationContext {
|
|||||||
* @return The origin of the renderer as a world position.
|
* @return The origin of the renderer as a world position.
|
||||||
*/
|
*/
|
||||||
Vec3i renderOrigin();
|
Vec3i renderOrigin();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link VisualizationContext} with the given {@link Context} and render origin.
|
||||||
|
*
|
||||||
|
* @param context The new context.
|
||||||
|
* @param renderOrigin The new render origin.
|
||||||
|
* @return A new {@link VisualizationContext} for use with child visuals.
|
||||||
|
*/
|
||||||
|
@ApiStatus.Experimental
|
||||||
|
VisualizationContext withContext(Context context, Vec3i renderOrigin);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.jozufozu.flywheel.impl.visualization;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.backend.Engine;
|
import com.jozufozu.flywheel.api.backend.Engine;
|
||||||
|
import com.jozufozu.flywheel.api.context.Context;
|
||||||
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.InstanceType;
|
||||||
@ -10,13 +11,13 @@ import com.jozufozu.flywheel.api.instance.Instancer;
|
|||||||
import com.jozufozu.flywheel.api.instance.InstancerProvider;
|
import com.jozufozu.flywheel.api.instance.InstancerProvider;
|
||||||
import com.jozufozu.flywheel.api.model.Model;
|
import com.jozufozu.flywheel.api.model.Model;
|
||||||
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
|
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
|
||||||
import com.jozufozu.flywheel.lib.context.Contexts;
|
|
||||||
|
|
||||||
public record InstancerProviderImpl(Engine engine,
|
public record InstancerProviderImpl(Engine engine,
|
||||||
|
Context context,
|
||||||
RenderStage renderStage) implements InstancerProvider, Supplier<VisualizationContext> {
|
RenderStage renderStage) implements InstancerProvider, Supplier<VisualizationContext> {
|
||||||
@Override
|
@Override
|
||||||
public <I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model) {
|
public <I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model) {
|
||||||
return engine.instancer(type, Contexts.DEFAULT, model, renderStage);
|
return engine.instancer(type, context, model, renderStage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jozufozu.flywheel.impl.visualization;
|
package com.jozufozu.flywheel.impl.visualization;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.context.Context;
|
||||||
import com.jozufozu.flywheel.api.instance.InstancerProvider;
|
import com.jozufozu.flywheel.api.instance.InstancerProvider;
|
||||||
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
|
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
|
||||||
|
|
||||||
@ -12,6 +13,10 @@ 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 {
|
@Override
|
||||||
|
public VisualizationContext withContext(Context context, Vec3i renderOrigin) {
|
||||||
|
var provider = new InstancerProviderImpl(instancerProvider.engine(), context, instancerProvider.renderStage());
|
||||||
|
return new VisualizationContextImpl(provider, renderOrigin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import com.jozufozu.flywheel.impl.visualization.manager.VisualManagerImpl;
|
|||||||
import com.jozufozu.flywheel.impl.visualization.ratelimit.BandedPrimeLimiter;
|
import com.jozufozu.flywheel.impl.visualization.ratelimit.BandedPrimeLimiter;
|
||||||
import com.jozufozu.flywheel.impl.visualization.ratelimit.DistanceUpdateLimiterImpl;
|
import com.jozufozu.flywheel.impl.visualization.ratelimit.DistanceUpdateLimiterImpl;
|
||||||
import com.jozufozu.flywheel.impl.visualization.ratelimit.NonLimiter;
|
import com.jozufozu.flywheel.impl.visualization.ratelimit.NonLimiter;
|
||||||
|
import com.jozufozu.flywheel.lib.context.Contexts;
|
||||||
import com.jozufozu.flywheel.lib.task.Flag;
|
import com.jozufozu.flywheel.lib.task.Flag;
|
||||||
import com.jozufozu.flywheel.lib.task.IfElsePlan;
|
import com.jozufozu.flywheel.lib.task.IfElsePlan;
|
||||||
import com.jozufozu.flywheel.lib.task.MapContextPlan;
|
import com.jozufozu.flywheel.lib.task.MapContextPlan;
|
||||||
@ -84,9 +85,9 @@ public class VisualizationManagerImpl implements VisualizationManager {
|
|||||||
.createEngine(level);
|
.createEngine(level);
|
||||||
taskExecutor = FlwTaskExecutor.get();
|
taskExecutor = FlwTaskExecutor.get();
|
||||||
|
|
||||||
var blockEntitiesStorage = new BlockEntityStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_BLOCK_ENTITIES));
|
var blockEntitiesStorage = new BlockEntityStorage(new InstancerProviderImpl(engine, Contexts.DEFAULT, RenderStage.AFTER_BLOCK_ENTITIES));
|
||||||
var entitiesStorage = new EntityStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_ENTITIES));
|
var entitiesStorage = new EntityStorage(new InstancerProviderImpl(engine, Contexts.DEFAULT, RenderStage.AFTER_ENTITIES));
|
||||||
var effectsStorage = new EffectStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_PARTICLES));
|
var effectsStorage = new EffectStorage(new InstancerProviderImpl(engine, Contexts.DEFAULT, RenderStage.AFTER_PARTICLES));
|
||||||
|
|
||||||
blockEntities = new VisualManagerImpl<>(blockEntitiesStorage);
|
blockEntities = new VisualManagerImpl<>(blockEntitiesStorage);
|
||||||
entities = new VisualManagerImpl<>(entitiesStorage);
|
entities = new VisualManagerImpl<>(entitiesStorage);
|
||||||
|
Loading…
Reference in New Issue
Block a user