Skip to content

Commit

Permalink
An original thought
Browse files Browse the repository at this point in the history
- Require embeddings to specify an origin coordinate on creation
  • Loading branch information
Jozufozu committed Jul 27, 2024
1 parent b8f6bf8 commit cdc6824
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

import dev.engine_room.flywheel.api.backend.BackendImplemented;

/**
* A visualization context that can apply a transformation to instances created through its instancer provider.
*
* <p>This is intended to be used for large meta-visuals that may be composed of many block entities or entities.
* Invoking a visualizer with a VisualEmbedding will create a "subvisual". The parent visual is responsible for managing
* the lifecycle of subvisuals: deleting them, and optionally invoking their frame and tick plans. Subvisuals exist in
* the real world from their perspective, and in general visuals should not care if they are within a VisualEmbedding.
* However, if a visual wants to check it can use {@code instanceof VisualEmbedding} on its VisualizationContext.</p>
*/
@BackendImplemented
public interface VisualEmbedding extends VisualizationContext {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,23 @@ public interface VisualizationContext {
/**
* All models render as if this position is (0, 0, 0).
*
* <p>For a Visual to appear in the correct position in the world,
* it must render at its actual world position minus this renderOrigin.
* <br>i.e. {@code be.getBlockPos() - visualizationContext.renderOrigin()}</p>
*
* <p>This exists to prevent floating point precision issues
* when the camera is far away from the level's origin.</p>
*
* @return The origin of the renderer as a level position.
*/
Vec3i renderOrigin();

VisualEmbedding createEmbedding();
/**
* Create a new embedding to compose visuals.
*
* @param renderOrigin The renderOrigin the embedding will appear to have.
* @return The embedding.
* @see VisualEmbedding
*/
VisualEmbedding createEmbedding(Vec3i renderOrigin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public Vec3i renderOrigin() {
}

@Override
public VisualEmbedding createEmbedding() {
var out = new EmbeddedEnvironment(EngineImpl.this, visualType);
public VisualEmbedding createEmbedding(Vec3i renderOrigin) {
var out = new EmbeddedEnvironment(EngineImpl.this, visualType, renderOrigin);
environmentStorage.track(out);
return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class EmbeddedEnvironment implements VisualEmbedding, Environment {
private final EngineImpl engine;
private final VisualType visualType;
private final Vec3i renderOrigin;
@Nullable
private final EmbeddedEnvironment parent;
private final InstancerProvider instancerProvider;
Expand All @@ -32,9 +33,10 @@ public class EmbeddedEnvironment implements VisualEmbedding, Environment {

private boolean deleted = false;

public EmbeddedEnvironment(EngineImpl engine, VisualType visualType, @Nullable EmbeddedEnvironment parent) {
public EmbeddedEnvironment(EngineImpl engine, VisualType visualType, Vec3i renderOrigin, @Nullable EmbeddedEnvironment parent) {
this.engine = engine;
this.visualType = visualType;
this.renderOrigin = renderOrigin;
this.parent = parent;

instancerProvider = new InstancerProvider() {
Expand All @@ -46,8 +48,8 @@ public <I extends Instance> Instancer<I> instancer(InstanceType<I> type, Model m
};
}

public EmbeddedEnvironment(EngineImpl engine, VisualType visualType) {
this(engine, visualType, null);
public EmbeddedEnvironment(EngineImpl engine, VisualType visualType, Vec3i renderOrigin) {
this(engine, visualType, renderOrigin, null);
}

@Override
Expand All @@ -63,12 +65,12 @@ public InstancerProvider instancerProvider() {

@Override
public Vec3i renderOrigin() {
return Vec3i.ZERO;
return renderOrigin;
}

@Override
public VisualEmbedding createEmbedding() {
var out = new EmbeddedEnvironment(engine, visualType, this);
public VisualEmbedding createEmbedding(Vec3i renderOrigin) {
var out = new EmbeddedEnvironment(engine, visualType, renderOrigin, this);
engine.environmentStorage()
.track(out);
return out;
Expand Down

0 comments on commit cdc6824

Please sign in to comment.