From 7b3bab66479cc2537432de6a741c8a0f889e884e Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Thu, 9 Dec 2021 00:42:27 -0800 Subject: [PATCH] Reorganize, rename, refactor, 0.4.0 - Move most user facing interfaces to flywheel.api package - Refactor InstanceData to have no package private classes - Remove 'I' prefix from many interfaces - ILightUpdateListener -> LightListener - IMultiProgram -> ContextAwareProgram - IFlatLight -> FlatLit - All materials use the same vertex format: UNLIT_MODEL --- gradle.properties | 2 +- .../jozufozu/flywheel/backend/Backend.java | 18 +++---- .../flywheel/backend/IFlywheelWorld.java | 13 ----- .../com/jozufozu/flywheel/backend/Loader.java | 2 +- .../backend/{state => }/RenderLayer.java | 2 +- ...IShaderContext.java => ShaderContext.java} | 2 +- .../FlywheelRendered.java} | 4 +- .../flywheel/backend/api/FlywheelWorld.java | 13 +++++ .../flywheel/backend/api/InstanceData.java | 41 +++++++++++++++ .../{instancing => api}/Instancer.java | 21 ++++++-- .../backend/{material => api}/Material.java | 10 ++-- .../{material => api}/MaterialGroup.java | 4 +- .../{material => api}/MaterialManager.java | 4 +- .../{material => api}/MaterialSpec.java | 12 +---- .../instance}/IDynamicInstance.java | 4 +- .../instance}/IInstance.java | 2 +- .../instance}/ITickableInstance.java | 4 +- .../instance}/package-info.java | 2 +- .../backend/{state => api}/package-info.java | 2 +- .../backend/instancing/AbstractInstance.java | 19 ++++--- .../backend/instancing/AbstractInstancer.java | 52 ++++++++----------- .../flywheel/backend/instancing/Engine.java | 6 +++ .../backend/instancing/InstanceData.java | 18 ------- .../backend/instancing/InstanceManager.java | 6 ++- .../backend/instancing/InstanceWorld.java | 7 +-- .../instancing/InstancedRenderRegistry.java | 7 +-- .../RenderDispatcher.java | 7 ++- .../batching/BatchedMaterial.java | 15 +++--- .../batching/BatchedMaterialGroup.java | 8 +-- .../batching/BatchingEngine.java | 8 +-- .../{ => batching}/CPUInstancer.java | 15 ++++-- .../batching/package-info.java | 2 +- .../instancing/entity/EntityInstance.java | 12 ++--- .../entity/EntityInstanceManager.java | 2 +- .../entity/IEntityInstanceFactory.java | 2 +- .../{ => instancing}/GPUInstancer.java | 15 ++++-- .../instancing/InstancedMaterial.java | 18 +++---- .../instancing/InstancedMaterialGroup.java | 8 +-- .../instancing/InstancedMaterialRenderer.java | 3 +- .../instancing/InstancingEngine.java | 8 +-- .../instancing/package-info.java | 2 +- .../instancing/tile/ITileInstanceFactory.java | 2 +- .../instancing/tile/TileEntityInstance.java | 8 +-- .../instancing/tile/TileInstanceManager.java | 2 +- .../flywheel/backend/material/Engine.java | 4 -- .../backend/model/ArrayModelRenderer.java | 6 +-- .../flywheel/backend/model/BufferedModel.java | 6 +-- .../backend/model/ImmediateAllocator.java | 4 +- .../flywheel/backend/model/IndexedModel.java | 4 +- .../backend/model/ModelAllocator.java | 4 +- .../flywheel/backend/model/ModelPool.java | 8 +-- .../flywheel/backend/model/ModelRenderer.java | 8 +-- ...haderPipeline.java => ShaderPipeline.java} | 6 +-- .../backend/pipeline/WorldShaderPipeline.java | 8 +-- .../flywheel/backend/struct/Batched.java | 4 +- .../com/jozufozu/flywheel/core/Contexts.java | 6 +-- .../com/jozufozu/flywheel/core/Materials.java | 6 +-- .../jozufozu/flywheel/core/WorldContext.java | 20 +++---- .../core/crumbling/CrumblingGroup.java | 7 ++- .../crumbling/CrumblingInstanceManager.java | 2 +- .../core/crumbling/CrumblingRenderer.java | 2 +- .../core/instancing/ConditionalInstance.java | 4 +- .../core/instancing/GroupInstance.java | 4 +- .../core/instancing/SelectInstance.java | 4 +- .../flywheel/core/materials/BasicData.java | 4 +- .../{IFlatLight.java => FlatLit.java} | 4 +- .../materials/model/ModelTransformer.java | 4 +- .../core/materials/model/ModelType.java | 4 +- .../core/materials/oriented/OrientedType.java | 4 +- .../flywheel/core/model/BakedModelModel.java | 2 +- .../flywheel/core/model/BlockModel.java | 2 +- .../core/model/{IModel.java => Model.java} | 2 +- .../flywheel/core/model/ModelPart.java | 2 +- .../flywheel/core/model/WorldModel.java | 2 +- ...iProgram.java => ContextAwareProgram.java} | 2 +- .../core/shader/ExtensibleGlProgram.java | 3 +- .../core/shader/GameStateProgram.java | 4 +- .../flywheel/event/RenderLayerEvent.java | 2 +- .../flywheel/light/BasicProvider.java | 15 ++---- ...eConsumer.java => CoordinateConsumer.java} | 2 +- .../flywheel/light/GridAlignedBB.java | 2 +- .../jozufozu/flywheel/light/ImmutableBox.java | 4 +- ...UpdateListener.java => LightListener.java} | 2 +- .../jozufozu/flywheel/light/LightUpdater.java | 34 ++++++------ .../jozufozu/flywheel/light/LightVolume.java | 2 +- ...ovingListener.java => MovingListener.java} | 2 +- .../flywheel/vanilla/BellInstance.java | 4 +- .../flywheel/vanilla/ChestInstance.java | 4 +- .../flywheel/vanilla/MinecartInstance.java | 10 ++-- .../flywheel/vanilla/ShulkerBoxInstance.java | 4 +- 90 files changed, 346 insertions(+), 311 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/IFlywheelWorld.java rename src/main/java/com/jozufozu/flywheel/backend/{state => }/RenderLayer.java (95%) rename src/main/java/com/jozufozu/flywheel/backend/{IShaderContext.java => ShaderContext.java} (90%) rename src/main/java/com/jozufozu/flywheel/backend/{instancing/IInstanceRendered.java => api/FlywheelRendered.java} (78%) create mode 100644 src/main/java/com/jozufozu/flywheel/backend/api/FlywheelWorld.java create mode 100644 src/main/java/com/jozufozu/flywheel/backend/api/InstanceData.java rename src/main/java/com/jozufozu/flywheel/backend/{instancing => api}/Instancer.java (73%) rename src/main/java/com/jozufozu/flywheel/backend/{material => api}/Material.java (79%) rename src/main/java/com/jozufozu/flywheel/backend/{material => api}/MaterialGroup.java (76%) rename src/main/java/com/jozufozu/flywheel/backend/{material => api}/MaterialManager.java (90%) rename src/main/java/com/jozufozu/flywheel/backend/{material => api}/MaterialSpec.java (61%) rename src/main/java/com/jozufozu/flywheel/backend/{instancing => api/instance}/IDynamicInstance.java (89%) rename src/main/java/com/jozufozu/flywheel/backend/{instancing => api/instance}/IInstance.java (66%) rename src/main/java/com/jozufozu/flywheel/backend/{instancing => api/instance}/ITickableInstance.java (90%) rename src/main/java/com/jozufozu/flywheel/backend/{material => api/instance}/package-info.java (76%) rename src/main/java/com/jozufozu/flywheel/backend/{state => api}/package-info.java (79%) create mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/Engine.java delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceData.java rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/RenderDispatcher.java (67%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/batching/BatchedMaterial.java (66%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/batching/BatchedMaterialGroup.java (84%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/batching/BatchingEngine.java (84%) rename src/main/java/com/jozufozu/flywheel/backend/instancing/{ => batching}/CPUInstancer.java (66%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/batching/package-info.java (74%) rename src/main/java/com/jozufozu/flywheel/backend/instancing/{ => instancing}/GPUInstancer.java (91%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/instancing/InstancedMaterial.java (78%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/instancing/InstancedMaterialGroup.java (90%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/instancing/InstancedMaterialRenderer.java (91%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/instancing/InstancingEngine.java (96%) rename src/main/java/com/jozufozu/flywheel/backend/{material => instancing}/instancing/package-info.java (73%) delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/material/Engine.java rename src/main/java/com/jozufozu/flywheel/backend/pipeline/{IShaderPipeline.java => ShaderPipeline.java} (64%) rename src/main/java/com/jozufozu/flywheel/core/materials/{IFlatLight.java => FlatLit.java} (85%) rename src/main/java/com/jozufozu/flywheel/core/model/{IModel.java => Model.java} (98%) rename src/main/java/com/jozufozu/flywheel/core/shader/{IMultiProgram.java => ContextAwareProgram.java} (87%) rename src/main/java/com/jozufozu/flywheel/light/{ICoordinateConsumer.java => CoordinateConsumer.java} (71%) rename src/main/java/com/jozufozu/flywheel/light/{ILightUpdateListener.java => LightListener.java} (94%) rename src/main/java/com/jozufozu/flywheel/light/{IMovingListener.java => MovingListener.java} (55%) diff --git a/gradle.properties b/gradle.properties index f267992ed..2ca2551c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx3G org.gradle.daemon = false # mod version info -mod_version = 0.3.0 +mod_version = 0.4.0 mc_update_version = 1.18 minecraft_version = 1.18 forge_version = 38.0.15 diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 927d9498f..aa8b8ad65 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -13,9 +13,10 @@ import org.apache.logging.log4j.Logger; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GLCapabilities; +import com.jozufozu.flywheel.backend.api.FlywheelWorld; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.material.MaterialSpec; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.MaterialSpec; import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; @@ -41,7 +42,7 @@ public class Backend { private boolean instancedArrays; private boolean enabled; - private final List> contexts = new ArrayList<>(); + private final List> contexts = new ArrayList<>(); private final Map> materialRegistry = new HashMap<>(); private final Map programSpecRegistry = new HashMap<>(); @@ -82,7 +83,7 @@ public class Backend { /** * Register a shader context. */ - public > C register(C spec) { + public > C register(C spec) { contexts.add(spec); return spec; } @@ -97,8 +98,7 @@ public class Backend { } materialRegistry.put(name, spec); - log.debug("registered material '" + name + "' with vertex size " + spec.getModelFormat() - .getStride() + " and instance size " + spec.getInstanceType().format().getStride()); + log.debug("registered material '" + name + "' with instance size " + spec.getInstanceType().format().getStride()); return spec; } @@ -151,7 +151,7 @@ public class Backend { return programSpecRegistry.values(); } - public Collection> allContexts() { + public Collection> allContexts() { return contexts; } @@ -163,7 +163,7 @@ public class Backend { if (!world.isClientSide()) return false; - if (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()) return true; + if (world instanceof FlywheelWorld && ((FlywheelWorld) world).supportsFlywheel()) return true; return world == Minecraft.getInstance().level; } @@ -182,7 +182,7 @@ public class Backend { public void _clearContexts() { GameStateRegistry.clear(); programSpecRegistry.clear(); - contexts.forEach(IShaderContext::delete); + contexts.forEach(ShaderContext::delete); contexts.clear(); materialRegistry.clear(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/IFlywheelWorld.java b/src/main/java/com/jozufozu/flywheel/backend/IFlywheelWorld.java deleted file mode 100644 index 52f1712ed..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/IFlywheelWorld.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jozufozu.flywheel.backend; - -/** - * A marker interface custom worlds can override to indicate - * that tiles inside the world should render with Flywheel. - * - * Minecraft.getInstance().world is special cased and will support Flywheel by default. - */ -public interface IFlywheelWorld { - default boolean supportsFlywheel() { - return true; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/Loader.java b/src/main/java/com/jozufozu/flywheel/backend/Loader.java index 491ec3f06..3d9d6b369 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Loader.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Loader.java @@ -78,7 +78,7 @@ public class Loader implements ResourceManagerReloadListener { Resolver.INSTANCE.resolve(sources); - for (IShaderContext context : backend.allContexts()) { + for (ShaderContext context : backend.allContexts()) { context.load(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java b/src/main/java/com/jozufozu/flywheel/backend/RenderLayer.java similarity index 95% rename from src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java rename to src/main/java/com/jozufozu/flywheel/backend/RenderLayer.java index 8594f1f00..615187b43 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/RenderLayer.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.state; +package com.jozufozu.flywheel.backend; import javax.annotation.Nullable; diff --git a/src/main/java/com/jozufozu/flywheel/backend/IShaderContext.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java similarity index 90% rename from src/main/java/com/jozufozu/flywheel/backend/IShaderContext.java rename to src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java index 0d24963f2..66585908e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/IShaderContext.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java @@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import net.minecraft.resources.ResourceLocation; -public interface IShaderContext

{ +public interface ShaderContext

{ default P getProgram(ResourceLocation loc) { return this.getProgramSupplier(loc) diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java b/src/main/java/com/jozufozu/flywheel/backend/api/FlywheelRendered.java similarity index 78% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java rename to src/main/java/com/jozufozu/flywheel/backend/api/FlywheelRendered.java index 50073b868..82e4f47b3 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/FlywheelRendered.java @@ -1,11 +1,11 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.api; import net.minecraft.world.level.Level; /** * Something (a BlockEntity or Entity) that can be rendered using the instancing API. */ -public interface IInstanceRendered { +public interface FlywheelRendered { /** * @return true if there are parts of the renderer that cannot be implemented with Flywheel. diff --git a/src/main/java/com/jozufozu/flywheel/backend/api/FlywheelWorld.java b/src/main/java/com/jozufozu/flywheel/backend/api/FlywheelWorld.java new file mode 100644 index 000000000..0254dddef --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/api/FlywheelWorld.java @@ -0,0 +1,13 @@ +package com.jozufozu.flywheel.backend.api; + +/** + * A marker interface custom worlds can override to indicate + * that tiles inside the world should render with Flywheel. + * + * {@link net.minecraft.client.Minecraft#level Minecraft#level} is special cased and will support Flywheel by default. + */ +public interface FlywheelWorld { + default boolean supportsFlywheel() { + return true; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/api/InstanceData.java b/src/main/java/com/jozufozu/flywheel/backend/api/InstanceData.java new file mode 100644 index 000000000..bc9b33a42 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/api/InstanceData.java @@ -0,0 +1,41 @@ +package com.jozufozu.flywheel.backend.api; + +public abstract class InstanceData { + + private Instancer owner; + + private boolean dirty; + private boolean removed; + + public final void markDirty() { + dirty = true; + owner.notifyDirty(); + } + + public final void delete() { + removed = true; + owner.notifyRemoval(); + } + + public final boolean checkDirtyAndClear() { + if (dirty) { + dirty = false; + return true; + } else { + return false; + } + } + + public final boolean isRemoved() { + return removed; + } + + public Instancer getOwner() { + return owner; + } + + public InstanceData setOwner(Instancer owner) { + this.owner = owner; + return this; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java b/src/main/java/com/jozufozu/flywheel/backend/api/Instancer.java similarity index 73% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java rename to src/main/java/com/jozufozu/flywheel/backend/api/Instancer.java index f83de1e53..2da26426b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/Instancer.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.api; /** * An instancer is how you interact with an instanced model. @@ -32,7 +32,22 @@ public interface Instancer { */ void stealInstance(D inOther); - void markDirty(InstanceData instanceData); + /** + * Notify the Instancer that some of its data needs updating. + * + *

+ * This might be ignored, depending on the implementation. For the GPUInstancer, this triggers a scan of all + * instances. + *

+ */ + void notifyDirty(); - void markRemoval(InstanceData instanceData); + /** + * Notify the Instances that some of its data should be removed. + * + *

+ * By the time the next frame is drawn, the instanceData passed will no longer be considered for rendering. + *

+ */ + void notifyRemoval(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/Material.java b/src/main/java/com/jozufozu/flywheel/backend/api/Material.java similarity index 79% rename from src/main/java/com/jozufozu/flywheel/backend/material/Material.java rename to src/main/java/com/jozufozu/flywheel/backend/api/Material.java index af1e2d609..f6a1ed011 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/Material.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/Material.java @@ -1,12 +1,10 @@ -package com.jozufozu.flywheel.backend.material; +package com.jozufozu.flywheel.backend.api; import java.util.function.Supplier; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.model.BlockModel; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.util.Pair; import com.jozufozu.flywheel.util.RenderUtil; import com.mojang.blaze3d.vertex.PoseStack; @@ -19,10 +17,10 @@ public interface Material { * Get an instancer for the given model. Calling this method twice with the same key will return the same instancer. * * @param key An object that uniquely identifies the model. - * @param modelSupplier A factory that creates the IModel that you want to render. + * @param modelSupplier A factory that creates the Model that you want to render. * @return An instancer for the given model, capable of rendering many copies for little cost. */ - Instancer model(Object key, Supplier modelSupplier); + Instancer model(Object key, Supplier modelSupplier); default Instancer getModel(PartialModel partial, BlockState referenceState) { return model(partial, () -> new BlockModel(partial.get(), referenceState)); diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/api/MaterialGroup.java similarity index 76% rename from src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java rename to src/main/java/com/jozufozu/flywheel/backend/api/MaterialGroup.java index 2e3bb81fe..9ffb32d52 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/MaterialGroup.java @@ -1,6 +1,4 @@ -package com.jozufozu.flywheel.backend.material; - -import com.jozufozu.flywheel.backend.instancing.InstanceData; +package com.jozufozu.flywheel.backend.api; public interface MaterialGroup { /** diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java b/src/main/java/com/jozufozu/flywheel/backend/api/MaterialManager.java similarity index 90% rename from src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java rename to src/main/java/com/jozufozu/flywheel/backend/api/MaterialManager.java index 14d907e59..c825b8c80 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/MaterialManager.java @@ -1,6 +1,6 @@ -package com.jozufozu.flywheel.backend.material; +package com.jozufozu.flywheel.backend.api; -import com.jozufozu.flywheel.backend.state.RenderLayer; +import com.jozufozu.flywheel.backend.RenderLayer; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.Vec3i; diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java b/src/main/java/com/jozufozu/flywheel/backend/api/MaterialSpec.java similarity index 61% rename from src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java rename to src/main/java/com/jozufozu/flywheel/backend/api/MaterialSpec.java index 733d98947..1350e8878 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/MaterialSpec.java @@ -1,7 +1,5 @@ -package com.jozufozu.flywheel.backend.material; +package com.jozufozu.flywheel.backend.api; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.struct.StructType; import net.minecraft.resources.ResourceLocation; @@ -11,13 +9,11 @@ public class MaterialSpec { public final ResourceLocation name; private final ResourceLocation programSpec; - private final VertexFormat modelFormat; private final StructType instanceType; - public MaterialSpec(ResourceLocation name, ResourceLocation programSpec, VertexFormat modelFormat, StructType type) { + public MaterialSpec(ResourceLocation name, ResourceLocation programSpec, StructType type) { this.name = name; this.programSpec = programSpec; - this.modelFormat = modelFormat; this.instanceType = type; } @@ -25,10 +21,6 @@ public class MaterialSpec { return programSpec; } - public VertexFormat getModelFormat() { - return modelFormat; - } - public StructType getInstanceType() { return instanceType; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IDynamicInstance.java b/src/main/java/com/jozufozu/flywheel/backend/api/instance/IDynamicInstance.java similarity index 89% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/IDynamicInstance.java rename to src/main/java/com/jozufozu/flywheel/backend/api/instance/IDynamicInstance.java index 5f598022a..c69d01994 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IDynamicInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/instance/IDynamicInstance.java @@ -1,5 +1,7 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.api.instance; +import com.jozufozu.flywheel.backend.api.Instancer; +import com.jozufozu.flywheel.backend.api.InstanceData; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; /** diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java b/src/main/java/com/jozufozu/flywheel/backend/api/instance/IInstance.java similarity index 66% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java rename to src/main/java/com/jozufozu/flywheel/backend/api/instance/IInstance.java index 9514740d8..7b088eab2 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/instance/IInstance.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.api.instance; import net.minecraft.core.BlockPos; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/ITickableInstance.java b/src/main/java/com/jozufozu/flywheel/backend/api/instance/ITickableInstance.java similarity index 90% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/ITickableInstance.java rename to src/main/java/com/jozufozu/flywheel/backend/api/instance/ITickableInstance.java index 0e97b5327..8e72e02ce 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/ITickableInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/instance/ITickableInstance.java @@ -1,5 +1,7 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.api.instance; +import com.jozufozu.flywheel.backend.api.Instancer; +import com.jozufozu.flywheel.backend.api.InstanceData; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; /** diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/api/instance/package-info.java similarity index 76% rename from src/main/java/com/jozufozu/flywheel/backend/material/package-info.java rename to src/main/java/com/jozufozu/flywheel/backend/api/instance/package-info.java index 6568fe53f..2374b554d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/package-info.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/instance/package-info.java @@ -1,5 +1,5 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -package com.jozufozu.flywheel.backend.material; +package com.jozufozu.flywheel.backend.api.instance; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/backend/state/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/api/package-info.java similarity index 79% rename from src/main/java/com/jozufozu/flywheel/backend/state/package-info.java rename to src/main/java/com/jozufozu/flywheel/backend/api/package-info.java index d769925d3..693e0fd2b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/state/package-info.java +++ b/src/main/java/com/jozufozu/flywheel/backend/api/package-info.java @@ -1,5 +1,5 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -package com.jozufozu.flywheel.backend.state; +package com.jozufozu.flywheel.backend.api; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java index 6d67ae02e..b17e238bd 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java @@ -3,10 +3,13 @@ package com.jozufozu.flywheel.backend.instancing; import java.util.Arrays; import java.util.stream.Stream; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.IInstance; +import com.jozufozu.flywheel.backend.api.instance.ITickableInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; -import com.jozufozu.flywheel.backend.material.MaterialManager; -import com.jozufozu.flywheel.core.materials.IFlatLight; -import com.jozufozu.flywheel.light.ILightUpdateListener; +import com.jozufozu.flywheel.backend.api.MaterialManager; +import com.jozufozu.flywheel.core.materials.FlatLit; +import com.jozufozu.flywheel.light.LightListener; import com.jozufozu.flywheel.light.ImmutableBox; import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.ListenerStatus; @@ -19,7 +22,7 @@ import net.minecraft.world.level.LightLayer; * A general interface providing information about any type of thing that could use Flywheel's instanced rendering. * Right now, that's only {@link TileInstanceManager}, but there could be an entity equivalent in the future. */ -public abstract class AbstractInstance implements IInstance, ILightUpdateListener { +public abstract class AbstractInstance implements IInstance, LightListener { protected final MaterialManager materialManager; public final Level world; @@ -84,19 +87,19 @@ public abstract class AbstractInstance implements IInstance, ILightUpdateListene updateLight(); } - protected void relight(BlockPos pos, IFlatLight... models) { + protected void relight(BlockPos pos, FlatLit... models) { relight(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos), models); } - protected > void relight(BlockPos pos, Stream models) { + protected > void relight(BlockPos pos, Stream models) { relight(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos), models); } - protected void relight(int block, int sky, IFlatLight... models) { + protected void relight(int block, int sky, FlatLit... models) { relight(block, sky, Arrays.stream(models)); } - protected > void relight(int block, int sky, Stream models) { + protected > void relight(int block, int sky, Stream models) { models.forEach(model -> model.setBlockLight(block) .setSkyLight(sky)); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java index c27178984..9fb667df6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java @@ -3,19 +3,20 @@ package com.jozufozu.flywheel.backend.instancing; import java.util.ArrayList; import java.util.BitSet; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.Instancer; import com.jozufozu.flywheel.backend.struct.StructType; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; -public class AbstractInstancer implements Instancer { +public abstract class AbstractInstancer implements Instancer { protected final StructType type; - protected final IModel modelData; + protected final Model modelData; protected final ArrayList data = new ArrayList<>(); - boolean anyToRemove; - boolean anyToUpdate; + protected boolean anyToRemove; - public AbstractInstancer(StructType type, IModel modelData) { + protected AbstractInstancer(StructType type, Model modelData) { this.type = type; this.modelData = modelData; } @@ -25,9 +26,7 @@ public class AbstractInstancer implements Instancer { */ @Override public D createInstance() { - D data = type.create(); - data.owner = this; - return _add(data); + return _add(type.create()); } /** @@ -38,24 +37,17 @@ public class AbstractInstancer implements Instancer { */ @Override public void stealInstance(D inOther) { - if (inOther.owner == this) return; + if (inOther.getOwner() == this) return; - inOther.delete(); - // sike, we want to keep it, changing the owner reference will still delete it in the other - inOther.removed = false; + // Changing the owner reference will delete it in the other instancer + inOther.getOwner() + .notifyRemoval(); _add(inOther); } @Override - public void markDirty(InstanceData instanceData) { - anyToUpdate = true; - instanceData.dirty = true; - } - - @Override - public void markRemoval(InstanceData instanceData) { + public void notifyRemoval() { anyToRemove = true; - instanceData.removed = true; } /** @@ -72,10 +64,8 @@ public class AbstractInstancer implements Instancer { for (int i = 0; i < size; i++) { D element = data.get(i); - if (element.dirty) { + if (element.checkDirtyAndClear()) { dirtySet.set(i); - - element.dirty = false; } } return dirtySet; @@ -88,7 +78,7 @@ public class AbstractInstancer implements Instancer { final BitSet removeSet = new BitSet(oldSize); for (int i = 0; i < oldSize; i++) { final D element = this.data.get(i); - if (element.removed || element.owner != this) { + if (element.isRemoved() || element.getOwner() != this) { removeSet.set(i); removeCount++; } @@ -103,22 +93,22 @@ public class AbstractInstancer implements Instancer { if (i != j) { D element = data.get(i); data.set(j, element); - element.dirty = true; + // Marking the data dirty marks us dirty too. + // Perhaps there will be some wasted cycles, but the JVM should be able to + // generate code that moves the repeated segment out of the loop. + element.markDirty(); } } - anyToUpdate = true; - data.subList(newSize, oldSize) .clear(); } private D _add(D instanceData) { - instanceData.owner = this; + instanceData.setOwner(this); - instanceData.dirty = true; - anyToUpdate = true; + instanceData.markDirty(); synchronized (data) { data.add(instanceData); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/Engine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/Engine.java new file mode 100644 index 000000000..430c7e841 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/Engine.java @@ -0,0 +1,6 @@ +package com.jozufozu.flywheel.backend.instancing; + +import com.jozufozu.flywheel.backend.api.MaterialManager; + +public interface Engine extends RenderDispatcher, MaterialManager { +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceData.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceData.java deleted file mode 100644 index 5379822de..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceData.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.jozufozu.flywheel.backend.instancing; - -public abstract class InstanceData { - - Instancer owner; - - boolean dirty; - boolean removed; - - public void markDirty() { - owner.markDirty(this); - } - - public void delete() { - owner.markRemoval(this); - } - -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java index 535357ff3..6e527f91a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -9,8 +9,10 @@ import java.util.Set; import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.material.MaterialManager; -import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.ITickableInstance; +import com.jozufozu.flywheel.backend.api.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine; import com.jozufozu.flywheel.light.LightUpdater; import com.mojang.math.Vector3f; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java index f35437895..404ac47c8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java @@ -1,10 +1,11 @@ package com.jozufozu.flywheel.backend.instancing; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.ITickableInstance; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstanceManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; -import com.jozufozu.flywheel.backend.material.Engine; -import com.jozufozu.flywheel.backend.material.batching.BatchingEngine; -import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine; +import com.jozufozu.flywheel.backend.instancing.batching.BatchingEngine; +import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine; import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.event.BeginFrameEvent; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java index cbafe6398..3beaac245 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java @@ -5,11 +5,12 @@ import java.util.Map; import javax.annotation.Nullable; import com.google.common.collect.Maps; +import com.jozufozu.flywheel.backend.api.FlywheelRendered; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; import com.jozufozu.flywheel.backend.instancing.entity.IEntityInstanceFactory; import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; @@ -34,11 +35,11 @@ public class InstancedRenderRegistry { } public boolean shouldSkipRender(T type) { - return _skipRender(type.getType()) || ((type instanceof IInstanceRendered) && !((IInstanceRendered) type).shouldRenderNormally()); + return _skipRender(type.getType()) || ((type instanceof FlywheelRendered) && !((FlywheelRendered) type).shouldRenderNormally()); } public boolean shouldSkipRender(T type) { - return _skipRender(type.getType()) || ((type instanceof IInstanceRendered) && !((IInstanceRendered) type).shouldRenderNormally()); + return _skipRender(type.getType()) || ((type instanceof FlywheelRendered) && !((FlywheelRendered) type).shouldRenderNormally()); } public boolean canInstance(BlockEntityType type) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/RenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderDispatcher.java similarity index 67% rename from src/main/java/com/jozufozu/flywheel/backend/material/RenderDispatcher.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/RenderDispatcher.java index a528d0f0f..fd4681dd1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/RenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderDispatcher.java @@ -1,6 +1,5 @@ -package com.jozufozu.flywheel.backend.material; +package com.jozufozu.flywheel.backend.instancing; -import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.event.RenderLayerEvent; import net.minecraft.client.Camera; @@ -10,8 +9,8 @@ public interface RenderDispatcher { /** * Render every model for every material. * - * @param layer Which of the 3 {@link RenderLayer render layers} is being drawn? - * @param viewProjection How do we get from camera space to clip space? + * @param event Context for rendering. + * @param buffers The buffer source for which batched rendering should happen. */ void render(RenderLayerEvent event, MultiBufferSource buffers); diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchedMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterial.java similarity index 66% rename from src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchedMaterial.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterial.java index 96a93766a..5956ea04f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchedMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterial.java @@ -1,16 +1,15 @@ -package com.jozufozu.flywheel.backend.material.batching; +package com.jozufozu.flywheel.backend.instancing.batching; import java.util.HashMap; import java.util.Map; import java.util.function.Supplier; -import com.jozufozu.flywheel.backend.instancing.CPUInstancer; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.Instancer; -import com.jozufozu.flywheel.backend.material.Material; -import com.jozufozu.flywheel.backend.material.MaterialSpec; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.Instancer; +import com.jozufozu.flywheel.backend.api.Material; +import com.jozufozu.flywheel.backend.api.MaterialSpec; import com.jozufozu.flywheel.backend.struct.StructType; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -26,7 +25,7 @@ public class BatchedMaterial implements Material { } @Override - public Instancer model(Object key, Supplier modelSupplier) { + public Instancer model(Object key, Supplier modelSupplier) { return models.computeIfAbsent(key, $ -> new CPUInstancer<>(type, modelSupplier.get())); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchedMaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java similarity index 84% rename from src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchedMaterialGroup.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java index b843897dd..0226aee2b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchedMaterialGroup.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java @@ -1,11 +1,11 @@ -package com.jozufozu.flywheel.backend.material.batching; +package com.jozufozu.flywheel.backend.instancing.batching; import java.util.HashMap; import java.util.Map; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.material.MaterialGroup; -import com.jozufozu.flywheel.backend.material.MaterialSpec; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.MaterialGroup; +import com.jozufozu.flywheel.backend.api.MaterialSpec; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java similarity index 84% rename from src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchingEngine.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java index c7d0d3354..f5dc0bd12 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/batching/BatchingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java @@ -1,12 +1,12 @@ -package com.jozufozu.flywheel.backend.material.batching; +package com.jozufozu.flywheel.backend.instancing.batching; import java.util.EnumMap; import java.util.HashMap; import java.util.Map; -import com.jozufozu.flywheel.backend.material.Engine; -import com.jozufozu.flywheel.backend.material.MaterialGroup; -import com.jozufozu.flywheel.backend.state.RenderLayer; +import com.jozufozu.flywheel.backend.instancing.Engine; +import com.jozufozu.flywheel.backend.api.MaterialGroup; +import com.jozufozu.flywheel.backend.RenderLayer; import com.jozufozu.flywheel.event.RenderLayerEvent; import net.minecraft.client.Camera; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/CPUInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java similarity index 66% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/CPUInstancer.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java index eadfa9db8..6bec6f210 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/CPUInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java @@ -1,8 +1,10 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.instancing.batching; +import com.jozufozu.flywheel.backend.instancing.AbstractInstancer; +import com.jozufozu.flywheel.backend.api.InstanceData; import com.jozufozu.flywheel.backend.struct.BatchingTransformer; import com.jozufozu.flywheel.backend.struct.StructType; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -10,13 +12,18 @@ public class CPUInstancer extends AbstractInstancer { private final BatchingTransformer renderer; - public CPUInstancer(StructType type, IModel modelData) { + public CPUInstancer(StructType type, Model modelData) { super(type, modelData); renderer = type.asBatched() .getTransformer(modelData); } + @Override + public void notifyDirty() { + // noop + } + public void drawAll(PoseStack stack, VertexConsumer buffer) { if (renderer == null) { return; @@ -34,6 +41,6 @@ public class CPUInstancer extends AbstractInstancer { removeDeletedInstances(); } - anyToRemove = anyToUpdate = false; + anyToRemove = false; } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/batching/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/package-info.java similarity index 74% rename from src/main/java/com/jozufozu/flywheel/backend/material/batching/package-info.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/batching/package-info.java index c9e565892..0a8a7db98 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/batching/package-info.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/package-info.java @@ -1,5 +1,5 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -package com.jozufozu.flywheel.backend.material.batching; +package com.jozufozu.flywheel.backend.instancing.batching; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java index 76970613f..ba4dd05cb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java @@ -1,13 +1,13 @@ package com.jozufozu.flywheel.backend.instancing.entity; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; -import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.ITickableInstance; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.ITickableInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ILightUpdateListener; -import com.jozufozu.flywheel.light.IMovingListener; +import com.jozufozu.flywheel.light.LightListener; +import com.jozufozu.flywheel.light.MovingListener; import com.jozufozu.flywheel.light.LightProvider; import com.mojang.math.Vector3f; @@ -34,7 +34,7 @@ import net.minecraft.world.phys.Vec3; * * @param The type of {@link Entity} your class is an instance of. */ -public abstract class EntityInstance extends AbstractInstance implements ILightUpdateListener, IMovingListener { +public abstract class EntityInstance extends AbstractInstance implements LightListener, MovingListener { protected final E entity; protected final GridAlignedBB bounds; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java index cb3759e5b..a9b2d87a8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java @@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java index 67d5a0257..07db1b55e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.instancing.entity; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import net.minecraft.world.entity.Entity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/GPUInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java similarity index 91% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/GPUInstancer.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java index 656741057..f4ec37828 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/GPUInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.instancing.instancing; import java.util.BitSet; @@ -9,11 +9,13 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.gl.error.GlError; +import com.jozufozu.flywheel.backend.instancing.AbstractInstancer; +import com.jozufozu.flywheel.backend.api.InstanceData; import com.jozufozu.flywheel.backend.model.IBufferedModel; import com.jozufozu.flywheel.backend.model.ModelAllocator; import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructWriter; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.util.AttribUtil; public class GPUInstancer extends AbstractInstancer { @@ -29,12 +31,19 @@ public class GPUInstancer extends AbstractInstancer { private boolean deleted; private boolean initialized; - public GPUInstancer(StructType type, IModel model, ModelAllocator modelAllocator) { + protected boolean anyToUpdate; + + public GPUInstancer(StructType type, Model model, ModelAllocator modelAllocator) { super(type, model); this.modelAllocator = modelAllocator; this.instanceFormat = type.format(); } + @Override + public void notifyDirty() { + anyToUpdate = true; + } + public void render() { if (invalid()) return; diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterial.java similarity index 78% rename from src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterial.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterial.java index c0704162f..335a1bbeb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterial.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.material.instancing; +package com.jozufozu.flywheel.backend.instancing.instancing; import java.util.concurrent.ExecutionException; import java.util.function.Supplier; @@ -6,14 +6,14 @@ import java.util.function.Supplier; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.jozufozu.flywheel.backend.RenderWork; -import com.jozufozu.flywheel.backend.instancing.GPUInstancer; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.Instancer; -import com.jozufozu.flywheel.backend.material.Material; -import com.jozufozu.flywheel.backend.material.MaterialSpec; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.Instancer; +import com.jozufozu.flywheel.backend.api.Material; +import com.jozufozu.flywheel.backend.api.MaterialSpec; import com.jozufozu.flywheel.backend.model.ModelPool; import com.jozufozu.flywheel.backend.struct.StructType; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.Formats; +import com.jozufozu.flywheel.core.model.Model; /** * A collection of Instancers that all have the same format. @@ -28,7 +28,7 @@ public class InstancedMaterial implements Material { public InstancedMaterial(MaterialSpec spec) { this.type = spec.getInstanceType(); - modelPool = new ModelPool(spec.getModelFormat(), 64); + modelPool = new ModelPool(Formats.UNLIT_MODEL, 64); this.models = CacheBuilder.newBuilder() .removalListener(notification -> { GPUInstancer instancer = (GPUInstancer) notification.getValue(); @@ -45,7 +45,7 @@ public class InstancedMaterial implements Material { * @return An instancer for the given model, capable of rendering many copies for little cost. */ @Override - public Instancer model(Object key, Supplier modelSupplier) { + public Instancer model(Object key, Supplier modelSupplier) { try { return models.get(key, () -> new GPUInstancer<>(type, modelSupplier.get(), modelPool)); } catch (ExecutionException e) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialGroup.java similarity index 90% rename from src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterialGroup.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialGroup.java index 5716034d0..31d604fdb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterialGroup.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialGroup.java @@ -1,12 +1,12 @@ -package com.jozufozu.flywheel.backend.material.instancing; +package com.jozufozu.flywheel.backend.instancing.instancing; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.material.MaterialGroup; -import com.jozufozu.flywheel.backend.material.MaterialSpec; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.MaterialGroup; +import com.jozufozu.flywheel.backend.api.MaterialSpec; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.util.TextureBinder; import com.mojang.math.Matrix4f; diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterialRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialRenderer.java similarity index 91% rename from src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterialRenderer.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialRenderer.java index ac8c64e16..9d52ea695 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancedMaterialRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialRenderer.java @@ -1,10 +1,9 @@ -package com.jozufozu.flywheel.backend.material.instancing; +package com.jozufozu.flywheel.backend.instancing.instancing; import java.util.Collection; import java.util.function.Consumer; import java.util.function.Supplier; -import com.jozufozu.flywheel.backend.instancing.GPUInstancer; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.mojang.math.Matrix4f; diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java similarity index 96% rename from src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancingEngine.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java index 05a8de155..142531319 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/InstancingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.material.instancing; +package com.jozufozu.flywheel.backend.instancing.instancing; import java.util.EnumMap; import java.util.HashMap; @@ -10,9 +10,9 @@ import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; -import com.jozufozu.flywheel.backend.material.Engine; -import com.jozufozu.flywheel.backend.material.MaterialGroup; -import com.jozufozu.flywheel.backend.state.RenderLayer; +import com.jozufozu.flywheel.backend.instancing.Engine; +import com.jozufozu.flywheel.backend.api.MaterialGroup; +import com.jozufozu.flywheel.backend.RenderLayer; import com.jozufozu.flywheel.core.WorldContext; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.event.RenderLayerEvent; diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/package-info.java similarity index 73% rename from src/main/java/com/jozufozu/flywheel/backend/material/instancing/package-info.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/package-info.java index 42283d047..740e8a1a2 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/instancing/package-info.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/package-info.java @@ -1,5 +1,5 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -package com.jozufozu.flywheel.backend.material.instancing; +package com.jozufozu.flywheel.backend.instancing.instancing; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/ITileInstanceFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/ITileInstanceFactory.java index 3f8cdd1b8..672198098 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/ITileInstanceFactory.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/ITileInstanceFactory.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.instancing.tile; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import net.minecraft.world.level.block.entity.BlockEntity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileEntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileEntityInstance.java index f79190e8f..29f8ec1d5 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileEntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileEntityInstance.java @@ -1,10 +1,10 @@ package com.jozufozu.flywheel.backend.instancing.tile; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; -import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.ITickableInstance; -import com.jozufozu.flywheel.backend.material.Material; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.ITickableInstance; +import com.jozufozu.flywheel.backend.api.Material; +import com.jozufozu.flywheel.backend.api.MaterialManager; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java index 234c2d7cb..edfcd5d71 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java @@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/Engine.java b/src/main/java/com/jozufozu/flywheel/backend/material/Engine.java deleted file mode 100644 index 215764bfb..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/material/Engine.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.jozufozu.flywheel.backend.material; - -public interface Engine extends RenderDispatcher, MaterialManager { -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ArrayModelRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/model/ArrayModelRenderer.java index 8ac9bc906..97cfc5da7 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/ArrayModelRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/ArrayModelRenderer.java @@ -3,14 +3,14 @@ package com.jozufozu.flywheel.backend.model; import java.util.function.Supplier; import com.jozufozu.flywheel.backend.gl.GlVertexArray; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.util.AttribUtil; public class ArrayModelRenderer extends ModelRenderer { protected GlVertexArray vao; - public ArrayModelRenderer(Supplier model) { + public ArrayModelRenderer(Supplier model) { super(model); } @@ -27,7 +27,7 @@ public class ArrayModelRenderer extends ModelRenderer { @Override protected void init() { initialized = true; - IModel model = modelSupplier.get(); + Model model = modelSupplier.get(); if (model.empty()) return; diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/BufferedModel.java b/src/main/java/com/jozufozu/flywheel/backend/model/BufferedModel.java index 7dfb48aef..da8b26bc5 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/BufferedModel.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/BufferedModel.java @@ -10,18 +10,18 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.core.model.VecBufferConsumer; import com.jozufozu.flywheel.util.AttribUtil; public class BufferedModel implements IBufferedModel { - protected final IModel model; + protected final Model model; protected final GlPrimitive primitiveMode; protected GlBuffer vbo; protected boolean deleted; - public BufferedModel(GlPrimitive primitiveMode, IModel model) { + public BufferedModel(GlPrimitive primitiveMode, Model model) { this.model = model; this.primitiveMode = primitiveMode; diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ImmediateAllocator.java b/src/main/java/com/jozufozu/flywheel/backend/model/ImmediateAllocator.java index 7da671ca0..e290549e4 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/ImmediateAllocator.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/ImmediateAllocator.java @@ -1,13 +1,13 @@ package com.jozufozu.flywheel.backend.model; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; public class ImmediateAllocator implements ModelAllocator { public static final ImmediateAllocator INSTANCE = new ImmediateAllocator(); @Override - public IBufferedModel alloc(IModel model, Callback allocationCallback) { + public IBufferedModel alloc(Model model, Callback allocationCallback) { IndexedModel out = new IndexedModel(model); allocationCallback.onAlloc(out); return out; diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java b/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java index 678a9f468..f22818d32 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/IndexedModel.java @@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL31; import com.jozufozu.flywheel.backend.gl.GlPrimitive; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; /** * An indexed triangle model. Just what the driver ordered. @@ -15,7 +15,7 @@ public class IndexedModel extends BufferedModel { protected ElementBuffer ebo; - public IndexedModel(IModel model) { + public IndexedModel(Model model) { super(GlPrimitive.TRIANGLES, model); this.ebo = model.createEBO(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ModelAllocator.java b/src/main/java/com/jozufozu/flywheel/backend/model/ModelAllocator.java index afa45904a..8756f9427 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/ModelAllocator.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/ModelAllocator.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.model; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; public interface ModelAllocator { /** @@ -9,7 +9,7 @@ public interface ModelAllocator { * @param model The model to allocate. * @return A handle to the allocated model. */ - IBufferedModel alloc(IModel model, Callback allocationCallback); + IBufferedModel alloc(Model model, Callback allocationCallback); @FunctionalInterface interface Callback { diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java b/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java index 3ad3bdba3..9c64c6469 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java @@ -11,7 +11,7 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.core.model.VecBufferConsumer; import com.jozufozu.flywheel.util.AttribUtil; @@ -49,7 +49,7 @@ public class ModelPool implements ModelAllocator { * @return A handle to the allocated model. */ @Override - public PooledModel alloc(IModel model, Callback callback) { + public PooledModel alloc(Model model, Callback callback) { PooledModel bufferedModel = new PooledModel(model, vertices); bufferedModel.callback = callback; vertices += model.vertexCount(); @@ -158,12 +158,12 @@ public class ModelPool implements ModelAllocator { private final ElementBuffer ebo; private Callback callback; - private final IModel model; + private final Model model; private int first; private boolean remove; - public PooledModel(IModel model, int first) { + public PooledModel(Model model, int first) { this.model = model; this.first = first; ebo = model.createEBO(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ModelRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/model/ModelRenderer.java index 72a11d601..b6802caad 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/ModelRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/ModelRenderer.java @@ -2,16 +2,16 @@ package com.jozufozu.flywheel.backend.model; import java.util.function.Supplier; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; public class ModelRenderer { - protected Supplier modelSupplier; + protected Supplier modelSupplier; protected IBufferedModel model; protected boolean initialized; - public ModelRenderer(Supplier modelSupplier) { + public ModelRenderer(Supplier modelSupplier) { this.modelSupplier = modelSupplier; } @@ -34,7 +34,7 @@ public class ModelRenderer { protected void init() { initialized = true; - IModel model = modelSupplier.get(); + Model model = modelSupplier.get(); if (model.empty()) return; diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/IShaderPipeline.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/ShaderPipeline.java similarity index 64% rename from src/main/java/com/jozufozu/flywheel/backend/pipeline/IShaderPipeline.java rename to src/main/java/com/jozufozu/flywheel/backend/pipeline/ShaderPipeline.java index 370281fcd..0caa59d57 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/IShaderPipeline.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/ShaderPipeline.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.pipeline; -import com.jozufozu.flywheel.core.shader.IMultiProgram; +import com.jozufozu.flywheel.core.shader.ContextAwareProgram; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; @@ -8,8 +8,8 @@ import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; * The main interface for compiling usable shaders from program specs. * @param

the type of the program that this pipeline compiles. */ -public interface IShaderPipeline

{ +public interface ShaderPipeline

{ - IMultiProgram

compile(ProgramSpec spec); + ContextAwareProgram

compile(ProgramSpec spec); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java index d961f0646..985a60ad7 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java @@ -9,14 +9,14 @@ import com.jozufozu.flywheel.backend.source.FileResolution; import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.shader.ExtensibleGlProgram; import com.jozufozu.flywheel.core.shader.GameStateProgram; -import com.jozufozu.flywheel.core.shader.IMultiProgram; +import com.jozufozu.flywheel.core.shader.ContextAwareProgram; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.core.shader.spec.ProgramState; import net.minecraft.resources.ResourceLocation; -public class WorldShaderPipeline

implements IShaderPipeline

{ +public class WorldShaderPipeline

implements ShaderPipeline

{ private final ExtensibleGlProgram.Factory

factory; @@ -29,14 +29,14 @@ public class WorldShaderPipeline

implements IShaderPipel this.header = header; } - public IMultiProgram

compile(ProgramSpec spec) { + public ContextAwareProgram

compile(ProgramSpec spec) { SourceFile file = spec.getSource().getFile(); return compile(spec.name, file, spec.getStates()); } - public IMultiProgram

compile(ResourceLocation name, SourceFile file, List variants) { + public ContextAwareProgram

compile(ResourceLocation name, SourceFile file, List variants) { WorldShader shader = new WorldShader(name, template, header) .setMainSource(file); diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/Batched.java b/src/main/java/com/jozufozu/flywheel/backend/struct/Batched.java index d3b1f6724..687dd933e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/Batched.java +++ b/src/main/java/com/jozufozu/flywheel/backend/struct/Batched.java @@ -1,10 +1,10 @@ package com.jozufozu.flywheel.backend.struct; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; public interface Batched extends StructType { - BatchingTransformer getTransformer(IModel model); + BatchingTransformer getTransformer(Model model); @Override default Batched asBatched() { diff --git a/src/main/java/com/jozufozu/flywheel/core/Contexts.java b/src/main/java/com/jozufozu/flywheel/core/Contexts.java index e1ee8b002..49821aaf9 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Contexts.java +++ b/src/main/java/com/jozufozu/flywheel/core/Contexts.java @@ -3,7 +3,7 @@ package com.jozufozu.flywheel.core; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.GameStateRegistry; -import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline; +import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline; import com.jozufozu.flywheel.backend.pipeline.InstancingTemplate; import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline; import com.jozufozu.flywheel.backend.source.FileResolution; @@ -32,8 +32,8 @@ public class Contexts { FileResolution crumblingBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.CRUMBLING, ".glsl")); FileResolution worldBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.WORLD, ".glsl")); - IShaderPipeline crumblingPipeline = new WorldShaderPipeline<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins); - IShaderPipeline worldPipeline = new WorldShaderPipeline<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins); + ShaderPipeline crumblingPipeline = new WorldShaderPipeline<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins); + ShaderPipeline worldPipeline = new WorldShaderPipeline<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins); CRUMBLING = backend.register(WorldContext.builder(backend, Names.CRUMBLING).build(crumblingPipeline)); WORLD = backend.register(WorldContext.builder(backend, Names.WORLD).build(worldPipeline)); diff --git a/src/main/java/com/jozufozu/flywheel/core/Materials.java b/src/main/java/com/jozufozu/flywheel/core/Materials.java index 2103fe812..b5efeee81 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Materials.java +++ b/src/main/java/com/jozufozu/flywheel/core/Materials.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.core; -import com.jozufozu.flywheel.backend.material.MaterialSpec; +import com.jozufozu.flywheel.backend.api.MaterialSpec; import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.model.ModelType; @@ -17,8 +17,8 @@ public class Materials { public static final StructType ORIENTED_TYPE = new OrientedType(); public static final StructType TRANSFORMED_TYPE = new ModelType(); - public static final MaterialSpec ORIENTED = new MaterialSpec<>(Names.ORIENTED, Programs.ORIENTED, Formats.UNLIT_MODEL, ORIENTED_TYPE); - public static final MaterialSpec TRANSFORMED = new MaterialSpec<>(Names.MODEL, Programs.TRANSFORMED, Formats.UNLIT_MODEL, TRANSFORMED_TYPE); + public static final MaterialSpec ORIENTED = new MaterialSpec<>(Names.ORIENTED, Programs.ORIENTED, ORIENTED_TYPE); + public static final MaterialSpec TRANSFORMED = new MaterialSpec<>(Names.MODEL, Programs.TRANSFORMED, TRANSFORMED_TYPE); public static void flwInit(GatherContextEvent event) { event.getBackend() diff --git a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java index 063d8d27a..170b9e10c 100644 --- a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java +++ b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java @@ -6,24 +6,24 @@ import java.util.function.Supplier; import java.util.stream.Stream; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.IShaderContext; -import com.jozufozu.flywheel.backend.material.MaterialSpec; -import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline; -import com.jozufozu.flywheel.core.shader.IMultiProgram; +import com.jozufozu.flywheel.backend.ShaderContext; +import com.jozufozu.flywheel.backend.api.MaterialSpec; +import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline; +import com.jozufozu.flywheel.core.shader.ContextAwareProgram; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import net.minecraft.resources.ResourceLocation; -public class WorldContext

implements IShaderContext

{ +public class WorldContext

implements ShaderContext

{ public final Backend backend; - protected final Map> programs = new HashMap<>(); + protected final Map> programs = new HashMap<>(); protected final ResourceLocation name; protected final Supplier> specStream; - public final IShaderPipeline

pipeline; + public final ShaderPipeline

pipeline; - public WorldContext(Backend backend, ResourceLocation name, Supplier> specStream, IShaderPipeline

pipeline) { + public WorldContext(Backend backend, ResourceLocation name, Supplier> specStream, ShaderPipeline

pipeline) { this.backend = backend; this.name = name; this.specStream = specStream; @@ -61,7 +61,7 @@ public class WorldContext

implements IShaderContext

{ @Override public void delete() { programs.values() - .forEach(IMultiProgram::delete); + .forEach(ContextAwareProgram::delete); programs.clear(); } @@ -84,7 +84,7 @@ public class WorldContext

implements IShaderContext

{ return this; } - public

WorldContext

build(IShaderPipeline

pipeline) { + public

WorldContext

build(ShaderPipeline

pipeline) { if (specStream == null) { specStream = () -> backend.allMaterials() .stream() diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java index c53db3b8a..a5093fbe5 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java @@ -1,8 +1,8 @@ package com.jozufozu.flywheel.core.crumbling; -import com.jozufozu.flywheel.backend.material.instancing.InstancedMaterialGroup; -import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine; -import com.jozufozu.flywheel.backend.material.instancing.InstancedMaterialRenderer; +import com.jozufozu.flywheel.backend.instancing.instancing.InstancedMaterialGroup; +import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine; +import com.jozufozu.flywheel.backend.instancing.instancing.InstancedMaterialRenderer; import com.jozufozu.flywheel.core.atlas.AtlasInfo; import com.jozufozu.flywheel.core.atlas.SheetData; import com.jozufozu.flywheel.util.RenderTextures; @@ -11,7 +11,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.math.Matrix4f; import net.minecraft.client.renderer.RenderType; -import net.minecraft.resources.ResourceLocation; public class CrumblingGroup

extends InstancedMaterialGroup

{ diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java index 75e75247c..57fde613b 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.core.crumbling; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import net.minecraft.core.BlockPos; diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java index 2844df589..f15d3ea91 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java @@ -7,7 +7,7 @@ import java.util.SortedSet; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.GlTextureUnit; import com.jozufozu.flywheel.backend.instancing.InstanceManager; -import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine; +import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine; import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.event.RenderLayerEvent; diff --git a/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java b/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java index 251b00db6..0aa08d052 100644 --- a/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java +++ b/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java @@ -5,8 +5,8 @@ import java.util.function.Consumer; import javax.annotation.Nullable; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.Instancer; public class ConditionalInstance { diff --git a/src/main/java/com/jozufozu/flywheel/core/instancing/GroupInstance.java b/src/main/java/com/jozufozu/flywheel/core/instancing/GroupInstance.java index c9084b6c0..8bcc6e078 100644 --- a/src/main/java/com/jozufozu/flywheel/core/instancing/GroupInstance.java +++ b/src/main/java/com/jozufozu/flywheel/core/instancing/GroupInstance.java @@ -5,8 +5,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.Instancer; public class GroupInstance extends AbstractCollection { diff --git a/src/main/java/com/jozufozu/flywheel/core/instancing/SelectInstance.java b/src/main/java/com/jozufozu/flywheel/core/instancing/SelectInstance.java index c865c4c0b..cc848b73a 100644 --- a/src/main/java/com/jozufozu/flywheel/core/instancing/SelectInstance.java +++ b/src/main/java/com/jozufozu/flywheel/core/instancing/SelectInstance.java @@ -6,8 +6,8 @@ import java.util.Optional; import javax.annotation.Nullable; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.api.InstanceData; +import com.jozufozu.flywheel.backend.api.Instancer; public class SelectInstance { diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java b/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java index eed1208bd..77512d886 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java @@ -1,8 +1,8 @@ package com.jozufozu.flywheel.core.materials; -import com.jozufozu.flywheel.backend.instancing.InstanceData; +import com.jozufozu.flywheel.backend.api.InstanceData; -public abstract class BasicData extends InstanceData implements IFlatLight { +public abstract class BasicData extends InstanceData implements FlatLit { public byte blockLight; public byte skyLight; diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/IFlatLight.java b/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java similarity index 85% rename from src/main/java/com/jozufozu/flywheel/core/materials/IFlatLight.java rename to src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java index 93c90dbea..d9d4b2010 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/IFlatLight.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.core.materials; -import com.jozufozu.flywheel.backend.instancing.InstanceData; +import com.jozufozu.flywheel.backend.api.InstanceData; /** * An interface that implementors of {@link InstanceData} should also implement @@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.instancing.InstanceData; * * @param The name of the class that implements this interface. */ -public interface IFlatLight> { +public interface FlatLit> { /** * @param blockLight An integer in the range [0, 15] representing the * amount of block light this instance should receive. diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelTransformer.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelTransformer.java index 941df358b..bfa0a1ac6 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelTransformer.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelTransformer.java @@ -1,10 +1,10 @@ package com.jozufozu.flywheel.core.materials.model; import com.jozufozu.flywheel.backend.struct.BatchingTransformer; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; public class ModelTransformer extends BatchingTransformer { - public ModelTransformer(IModel model) { + public ModelTransformer(Model model) { //model.buffer(); diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelType.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelType.java index 9074fdf50..ff99dc97b 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelType.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelType.java @@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.struct.StructWriter; import com.jozufozu.flywheel.backend.struct.Writeable; import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.materials.model.writer.UnsafeModelWriter; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; public class ModelType implements Writeable, Batched { @@ -28,7 +28,7 @@ public class ModelType implements Writeable, Batched { } @Override - public BatchingTransformer getTransformer(IModel model) { + public BatchingTransformer getTransformer(Model model) { return null; } } diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedType.java b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedType.java index 468bbb597..5019cd61d 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedType.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedType.java @@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.struct.StructWriter; import com.jozufozu.flywheel.backend.struct.Writeable; import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.materials.oriented.writer.UnsafeOrientedWriter; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; public class OrientedType implements Writeable, Batched { @@ -28,7 +28,7 @@ public class OrientedType implements Writeable, Batched getTransformer(IModel model) { + public BatchingTransformer getTransformer(Model model) { return null; } } diff --git a/src/main/java/com/jozufozu/flywheel/core/model/BakedModelModel.java b/src/main/java/com/jozufozu/flywheel/core/model/BakedModelModel.java index d9ea916ec..a972704fb 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/BakedModelModel.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/BakedModelModel.java @@ -23,7 +23,7 @@ import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.core.Vec3i; -public class BakedModelModel implements IModel { +public class BakedModelModel implements Model { // DOWN, UP, NORTH, SOUTH, WEST, EAST, null private static final Direction[] dirs; diff --git a/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java b/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java index efee04d5b..44d81c899 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java @@ -24,7 +24,7 @@ import net.minecraft.world.level.block.state.BlockState; /** * A model of a single block. */ -public class BlockModel implements IModel { +public class BlockModel implements Model { private static final PoseStack IDENTITY = new PoseStack(); private final BufferBuilderReader reader; diff --git a/src/main/java/com/jozufozu/flywheel/core/model/IModel.java b/src/main/java/com/jozufozu/flywheel/core/model/Model.java similarity index 98% rename from src/main/java/com/jozufozu/flywheel/core/model/IModel.java rename to src/main/java/com/jozufozu/flywheel/core/model/Model.java index 6db3d1135..fb8704742 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/IModel.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/Model.java @@ -25,7 +25,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer; * assert model.size() == final - initial; * } */ -public interface IModel { +public interface Model { /** * A name uniquely identifying this model. diff --git a/src/main/java/com/jozufozu/flywheel/core/model/ModelPart.java b/src/main/java/com/jozufozu/flywheel/core/model/ModelPart.java index 2ae657e2b..bf4498090 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelPart.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelPart.java @@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.core.Formats; import com.mojang.blaze3d.vertex.VertexConsumer; -public class ModelPart implements IModel { +public class ModelPart implements Model { private final List cuboids; private int vertices; diff --git a/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java b/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java index d62ef9c26..c9c355c05 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java @@ -13,7 +13,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; -public class WorldModel implements IModel { +public class WorldModel implements Model { private final BufferBuilderReader reader; private final String name; diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/IMultiProgram.java b/src/main/java/com/jozufozu/flywheel/core/shader/ContextAwareProgram.java similarity index 87% rename from src/main/java/com/jozufozu/flywheel/core/shader/IMultiProgram.java rename to src/main/java/com/jozufozu/flywheel/core/shader/ContextAwareProgram.java index 924a989a5..c10affa04 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/IMultiProgram.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/ContextAwareProgram.java @@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram; * * @param

*/ -public interface IMultiProgram

extends Supplier

{ +public interface ContextAwareProgram

extends Supplier

{ /** * Get the shader program most suited for the current game state. diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java b/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java index ac64b9aab..72f642020 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java @@ -5,6 +5,7 @@ import java.util.List; import javax.annotation.Nonnull; +import com.jozufozu.flywheel.backend.ShaderContext; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.core.shader.extension.IExtensionInstance; @@ -17,7 +18,7 @@ import net.minecraft.resources.ResourceLocation; * the caller using the program. This is used by some programs to implement the different fog modes. Other uses might * include binding extra textures to allow for blocks to have normal maps, for example. As the extensions are * per-program, this also allows for same extra specialization within a - * {@link com.jozufozu.flywheel.backend.ShaderContext ShaderContext}. + * {@link ShaderContext ShaderContext}. */ public class ExtensibleGlProgram extends GlProgram { diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/GameStateProgram.java b/src/main/java/com/jozufozu/flywheel/core/shader/GameStateProgram.java index 9b67fdf37..d0591c29d 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/GameStateProgram.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/GameStateProgram.java @@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.core.shader.spec.IGameStateCondition; import com.jozufozu.flywheel.util.Pair; -public class GameStateProgram

implements IMultiProgram

{ +public class GameStateProgram

implements ContextAwareProgram

{ private final List> variants; private final P fallback; @@ -55,7 +55,7 @@ public class GameStateProgram

implements IMultiProgram

{ return this; } - public IMultiProgram

build() { + public ContextAwareProgram

build() { return new GameStateProgram<>(ImmutableList.copyOf(variants), fallback); } } diff --git a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java index 2e1176738..f0d84bf31 100644 --- a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java +++ b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.event; import javax.annotation.Nullable; -import com.jozufozu.flywheel.backend.state.RenderLayer; +import com.jozufozu.flywheel.backend.RenderLayer; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; diff --git a/src/main/java/com/jozufozu/flywheel/light/BasicProvider.java b/src/main/java/com/jozufozu/flywheel/light/BasicProvider.java index 6ddc4d5fd..fb5d3b189 100644 --- a/src/main/java/com/jozufozu/flywheel/light/BasicProvider.java +++ b/src/main/java/com/jozufozu/flywheel/light/BasicProvider.java @@ -1,23 +1,16 @@ package com.jozufozu.flywheel.light; -import java.util.Map; -import java.util.WeakHashMap; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.LightLayer; +/** + * Wraps a world and minimally lowers the interface. + */ public class BasicProvider implements LightProvider { - private static final Map wrappers = new WeakHashMap<>(); - - public static BasicProvider get(BlockAndTintGetter world) { - return wrappers.computeIfAbsent(world, BasicProvider::new); - } - - private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); - private final BlockAndTintGetter reader; + private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); public BasicProvider(BlockAndTintGetter reader) { this.reader = reader; diff --git a/src/main/java/com/jozufozu/flywheel/light/ICoordinateConsumer.java b/src/main/java/com/jozufozu/flywheel/light/CoordinateConsumer.java similarity index 71% rename from src/main/java/com/jozufozu/flywheel/light/ICoordinateConsumer.java rename to src/main/java/com/jozufozu/flywheel/light/CoordinateConsumer.java index a4d77b32e..b6a64eb0d 100644 --- a/src/main/java/com/jozufozu/flywheel/light/ICoordinateConsumer.java +++ b/src/main/java/com/jozufozu/flywheel/light/CoordinateConsumer.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.light; @FunctionalInterface -public interface ICoordinateConsumer { +public interface CoordinateConsumer { void consume(int x, int y, int z); } diff --git a/src/main/java/com/jozufozu/flywheel/light/GridAlignedBB.java b/src/main/java/com/jozufozu/flywheel/light/GridAlignedBB.java index 1ccdf6a81..d84dd13a4 100644 --- a/src/main/java/com/jozufozu/flywheel/light/GridAlignedBB.java +++ b/src/main/java/com/jozufozu/flywheel/light/GridAlignedBB.java @@ -385,7 +385,7 @@ public class GridAlignedBB implements ImmutableBox { } @Override - public void forEachContained(ICoordinateConsumer func) { + public void forEachContained(CoordinateConsumer func) { if (empty()) return; for (int x = minX; x < maxX; x++) { diff --git a/src/main/java/com/jozufozu/flywheel/light/ImmutableBox.java b/src/main/java/com/jozufozu/flywheel/light/ImmutableBox.java index 935a521dc..a06cabb60 100644 --- a/src/main/java/com/jozufozu/flywheel/light/ImmutableBox.java +++ b/src/main/java/com/jozufozu/flywheel/light/ImmutableBox.java @@ -107,7 +107,7 @@ public interface ImmutableBox { return this.getMinX() < maxX && this.getMaxX() > minX && this.getMinY() < maxY && this.getMaxY() > minY && this.getMinZ() < maxZ && this.getMaxZ() > minZ; } - default void forEachContained(ICoordinateConsumer func) { + default void forEachContained(CoordinateConsumer func) { if (empty()) return; for (int x = getMinX(); x < getMaxX(); x++) { @@ -119,7 +119,7 @@ public interface ImmutableBox { } } - default AABB toAABB() { + default AABB toAABB() { return new AABB(getMinX(), getMinY(), getMinZ(), getMaxX(), getMaxY(), getMaxZ()); } diff --git a/src/main/java/com/jozufozu/flywheel/light/ILightUpdateListener.java b/src/main/java/com/jozufozu/flywheel/light/LightListener.java similarity index 94% rename from src/main/java/com/jozufozu/flywheel/light/ILightUpdateListener.java rename to src/main/java/com/jozufozu/flywheel/light/LightListener.java index dbb6bbfeb..9037d3b1f 100644 --- a/src/main/java/com/jozufozu/flywheel/light/ILightUpdateListener.java +++ b/src/main/java/com/jozufozu/flywheel/light/LightListener.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.light; import net.minecraft.world.level.LightLayer; -public interface ILightUpdateListener { +public interface LightListener { ImmutableBox getVolume(); diff --git a/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java b/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java index 44ac3575d..26404ab2a 100644 --- a/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java +++ b/src/main/java/com/jozufozu/flywheel/light/LightUpdater.java @@ -25,12 +25,12 @@ public class LightUpdater { private final LightProvider provider; - private final WeakHashSet movingListeners = new WeakHashSet<>(); - private final WeakContainmentMultiMap sections = new WeakContainmentMultiMap<>(); - private final WeakContainmentMultiMap chunks = new WeakContainmentMultiMap<>(); + private final WeakHashSet movingListeners = new WeakHashSet<>(); + private final WeakContainmentMultiMap sections = new WeakContainmentMultiMap<>(); + private final WeakContainmentMultiMap chunks = new WeakContainmentMultiMap<>(); public LightUpdater(BlockAndTintGetter world) { - provider = BasicProvider.get(world); + provider = new BasicProvider(world); } public LightProvider getProvider() { @@ -38,7 +38,7 @@ public class LightUpdater { } public void tick() { - for (IMovingListener listener : movingListeners) { + for (MovingListener listener : movingListeners) { if (listener.update(provider)) { addListener(listener); } @@ -47,12 +47,12 @@ public class LightUpdater { /** * Add a listener. - + * * @param listener The object that wants to receive light update notifications. */ - public void addListener(ILightUpdateListener listener) { - if (listener instanceof IMovingListener) - movingListeners.add(((IMovingListener) listener)); + public void addListener(LightListener listener) { + if (listener instanceof MovingListener) + movingListeners.add(((MovingListener) listener)); ImmutableBox box = listener.getVolume(); @@ -80,18 +80,18 @@ public class LightUpdater { } } - public void removeListener(ILightUpdateListener listener) { + public void removeListener(LightListener listener) { this.sections.remove(listener); this.chunks.remove(listener); } /** - * Dispatch light updates to all registered {@link ILightUpdateListener}s. + * Dispatch light updates to all registered {@link LightListener}s. * @param type The type of light that changed. * @param sectionPos A long representing the section position where light changed. */ public void onLightUpdate(LightLayer type, long sectionPos) { - Set set = sections.get(sectionPos); + Set set = sections.get(sectionPos); if (set == null || set.isEmpty()) return; @@ -99,26 +99,26 @@ public class LightUpdater { ImmutableBox chunkBox = GridAlignedBB.from(SectionPos.of(sectionPos)); - for (ILightUpdateListener listener : set) { + for (LightListener listener : set) { listener.onLightUpdate(provider, type, chunkBox); } } /** - * Dispatch light updates to all registered {@link ILightUpdateListener}s + * Dispatch light updates to all registered {@link LightListener}s * when the server sends lighting data for an entire chunk. * */ public void onLightPacket(int chunkX, int chunkZ) { long chunkPos = SectionPos.asLong(chunkX, 0, chunkZ); - Set set = chunks.get(chunkPos); + Set set = chunks.get(chunkPos); if (set == null || set.isEmpty()) return; set.removeIf(l -> l.status().shouldRemove()); - for (ILightUpdateListener listener : set) { + for (LightListener listener : set) { listener.onLightPacket(provider, chunkX, chunkZ); } } @@ -132,7 +132,7 @@ public class LightUpdater { } public Stream getAllBoxes() { - return chunks.stream().map(ILightUpdateListener::getVolume); + return chunks.stream().map(LightListener::getVolume); } public boolean isEmpty() { diff --git a/src/main/java/com/jozufozu/flywheel/light/LightVolume.java b/src/main/java/com/jozufozu/flywheel/light/LightVolume.java index 84c1d2083..27f40f070 100644 --- a/src/main/java/com/jozufozu/flywheel/light/LightVolume.java +++ b/src/main/java/com/jozufozu/flywheel/light/LightVolume.java @@ -7,7 +7,7 @@ import org.lwjgl.system.MemoryUtil; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LightLayer; -public class LightVolume implements ImmutableBox, ILightUpdateListener { +public class LightVolume implements ImmutableBox, LightListener { protected final GridAlignedBB box = new GridAlignedBB(); protected ByteBuffer lightData; diff --git a/src/main/java/com/jozufozu/flywheel/light/IMovingListener.java b/src/main/java/com/jozufozu/flywheel/light/MovingListener.java similarity index 55% rename from src/main/java/com/jozufozu/flywheel/light/IMovingListener.java rename to src/main/java/com/jozufozu/flywheel/light/MovingListener.java index 68ff331ed..388d6fdd7 100644 --- a/src/main/java/com/jozufozu/flywheel/light/IMovingListener.java +++ b/src/main/java/com/jozufozu/flywheel/light/MovingListener.java @@ -1,5 +1,5 @@ package com.jozufozu.flywheel.light; -public interface IMovingListener extends ILightUpdateListener { +public interface MovingListener extends LightListener { boolean update(LightProvider provider); } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java index 22d771e9a..c7750f528 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java @@ -1,8 +1,8 @@ package com.jozufozu.flywheel.vanilla; -import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; import com.jozufozu.flywheel.core.model.ModelPart; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java index 0302fae0b..9487aa072 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java @@ -4,9 +4,9 @@ import java.util.Calendar; import javax.annotation.Nonnull; -import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java index ad3346a30..d758c588f 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java @@ -1,12 +1,12 @@ package com.jozufozu.flywheel.vanilla; -import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.ITickableInstance; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.ITickableInstance; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.model.ModelData; -import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.core.model.ModelPart; import com.jozufozu.flywheel.util.AnimationTickHolder; import com.jozufozu.flywheel.util.transform.MatrixTransformStack; @@ -153,7 +153,7 @@ public class MinecartInstance extends EntityInstance .createInstance(); } - private IModel getBodyModel() { + private Model getBodyModel() { int y = -3; return ModelPart.builder("minecart", 64, 32) .cuboid().invertYZ().start(-10, -8, -y).size(20, 16, 2).textureOffset(0, 10).rotateZ((float) Math.PI).rotateX(((float)Math.PI / 2F)).endCuboid() diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java index 5e8fb230c..291a3c35a 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java @@ -1,8 +1,8 @@ package com.jozufozu.flywheel.vanilla; -import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; +import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.api.MaterialManager; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.model.ModelPart;