Compare commits

...

3 Commits

Author SHA1 Message Date
Jozufozu
593784d614 Unbuffers your data
- Fix null check in BakedModelBufferer
2024-02-18 17:05:17 -06:00
Jozufozu
b49e9f1d28 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
2024-02-18 15:27:41 -06:00
Jozufozu
9a5bd0cac8 Revert "Apply directly to the engine!"
This reverts commit f3a88c25d5.
2024-02-18 14:05:24 -06:00
10 changed files with 55 additions and 59 deletions

View File

@ -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);
}

View File

@ -3,9 +3,14 @@ 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;
@ -14,7 +19,21 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
@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.
* @return A new plan.

View File

@ -2,9 +2,9 @@ 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;
@ApiStatus.NonExtendable
public interface InstancerProvider {
/**
* 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.
*/
<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,9 +1,11 @@
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();

View File

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

View File

@ -1,5 +1,8 @@
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 net.minecraft.core.Vec3i;
@ -7,6 +10,7 @@ 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.
@ -19,4 +23,14 @@ public interface VisualizationContext {
* @return The origin of the renderer as a world position.
*/
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);
}

View File

@ -2,8 +2,8 @@ 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.context.Context;
import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance;
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.model.Model;
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.context.Contexts;
public record InstancerProviderImpl(Engine engine,
Context context,
RenderStage renderStage) implements InstancerProvider, Supplier<VisualizationContext> {
@Override
public <I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model model) {
return engine.instancer(type, Contexts.DEFAULT, model, renderStage);
}
@Override
public DirectInstancerProvider _directProvider() {
return engine;
return engine.instancer(type, context, model, renderStage);
}
@Override

View File

@ -1,5 +1,6 @@
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.visualization.VisualizationContext;
@ -12,6 +13,10 @@ 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(InstancerProviderImpl instancerProvider,
Vec3i renderOrigin) implements VisualizationContext {
public record VisualizationContextImpl(InstancerProviderImpl instancerProvider, 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);
}
}

View File

@ -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.DistanceUpdateLimiterImpl;
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.IfElsePlan;
import com.jozufozu.flywheel.lib.task.MapContextPlan;
@ -84,9 +85,9 @@ public class VisualizationManagerImpl implements VisualizationManager {
.createEngine(level);
taskExecutor = FlwTaskExecutor.get();
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));
var blockEntitiesStorage = new BlockEntityStorage(new InstancerProviderImpl(engine, Contexts.DEFAULT, RenderStage.AFTER_BLOCK_ENTITIES));
var entitiesStorage = new EntityStorage(new InstancerProviderImpl(engine, Contexts.DEFAULT, RenderStage.AFTER_ENTITIES));
var effectsStorage = new EffectStorage(new InstancerProviderImpl(engine, Contexts.DEFAULT, RenderStage.AFTER_PARTICLES));
blockEntities = new VisualManagerImpl<>(blockEntitiesStorage);
entities = new VisualManagerImpl<>(entitiesStorage);

View File

@ -238,7 +238,7 @@ public final class BakedModelBufferer {
shadedData.release();
}
RenderedBuffer unshadedData = unshadedBuffer.endOrDiscardIfEmpty();
if (unshadedBuffer != null) {
if (unshadedData != null) {
resultConsumer.accept(renderType, false, unshadedData);
unshadedData.release();
}