mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
Compare commits
3 Commits
913a0d47b5
...
593784d614
Author | SHA1 | Date | |
---|---|---|---|
|
593784d614 | ||
|
b49e9f1d28 | ||
|
9a5bd0cac8 |
@ -1,30 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -3,9 +3,14 @@ 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;
|
||||||
|
|
||||||
@ -14,7 +19,21 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
|
|
||||||
@BackendImplemented
|
@BackendImplemented
|
||||||
public interface Engine extends DirectInstancerProvider {
|
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, 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.
|
||||||
|
@ -2,9 +2,9 @@ package com.jozufozu.flywheel.api.instance;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
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;
|
||||||
|
|
||||||
|
@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.
|
||||||
@ -14,17 +14,4 @@ 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();
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
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();
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
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?
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.jozufozu.flywheel.api.visualization;
|
package com.jozufozu.flywheel.api.visualization;
|
||||||
|
|
||||||
|
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;
|
||||||
@ -7,6 +10,7 @@ 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.
|
||||||
@ -19,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);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ 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.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;
|
||||||
@ -11,18 +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
|
|
||||||
public DirectInstancerProvider _directProvider() {
|
|
||||||
return engine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(InstancerProviderImpl 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);
|
||||||
|
@ -238,7 +238,7 @@ public final class BakedModelBufferer {
|
|||||||
shadedData.release();
|
shadedData.release();
|
||||||
}
|
}
|
||||||
RenderedBuffer unshadedData = unshadedBuffer.endOrDiscardIfEmpty();
|
RenderedBuffer unshadedData = unshadedBuffer.endOrDiscardIfEmpty();
|
||||||
if (unshadedBuffer != null) {
|
if (unshadedData != null) {
|
||||||
resultConsumer.accept(renderType, false, unshadedData);
|
resultConsumer.accept(renderType, false, unshadedData);
|
||||||
unshadedData.release();
|
unshadedData.release();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user