diff --git a/src/main/java/com/jozufozu/flywheel/api/event/BeginFrameEvent.java b/src/main/java/com/jozufozu/flywheel/api/event/BeginFrameEvent.java index dd1014bb8..5f0bfe6ae 100644 --- a/src/main/java/com/jozufozu/flywheel/api/event/BeginFrameEvent.java +++ b/src/main/java/com/jozufozu/flywheel/api/event/BeginFrameEvent.java @@ -12,7 +12,7 @@ public final class BeginFrameEvent extends Event { this.context = context; } - public RenderContext getContext() { + public RenderContext context() { return context; } } diff --git a/src/main/java/com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent.java b/src/main/java/com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent.java index 7ebabaa67..da5d07ac2 100644 --- a/src/main/java/com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent.java +++ b/src/main/java/com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent.java @@ -24,11 +24,11 @@ public final class EndClientResourceReloadEvent extends Event implements IModBus this.error = error; } - public Minecraft getMinecraft() { + public Minecraft minecraft() { return minecraft; } - public ResourceManager getResourceManager() { + public ResourceManager resourceManager() { return resourceManager; } @@ -36,7 +36,7 @@ public final class EndClientResourceReloadEvent extends Event implements IModBus return initialReload; } - public Optional getError() { + public Optional error() { return error; } } diff --git a/src/main/java/com/jozufozu/flywheel/api/event/ReloadLevelRendererEvent.java b/src/main/java/com/jozufozu/flywheel/api/event/ReloadLevelRendererEvent.java index dd6c55d55..7ae09cd11 100644 --- a/src/main/java/com/jozufozu/flywheel/api/event/ReloadLevelRendererEvent.java +++ b/src/main/java/com/jozufozu/flywheel/api/event/ReloadLevelRendererEvent.java @@ -17,7 +17,7 @@ public final class ReloadLevelRendererEvent extends Event { } @Nullable - public ClientLevel getLevel() { + public ClientLevel level() { return level; } } diff --git a/src/main/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java b/src/main/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java index 5c0234b33..c67b285d6 100644 --- a/src/main/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java +++ b/src/main/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java @@ -21,31 +21,31 @@ public final class RenderStageEvent extends Event { this.stage = stage; } - public RenderContext getContext() { + public RenderContext context() { return context; } - public RenderStage getStage() { + public RenderStage stage() { return stage; } - public ClientLevel getLevel() { + public ClientLevel level() { return context.level(); } - public PoseStack getStack() { + public PoseStack stack() { return context.stack(); } - public Matrix4f getViewProjection() { + public Matrix4f viewProjection() { return context.viewProjection(); } - public RenderBuffers getBuffers() { + public RenderBuffers buffers() { return context.buffers(); } - public Camera getCamera() { + public Camera camera() { return context.camera(); } diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/Effect.java b/src/main/java/com/jozufozu/flywheel/api/visual/Effect.java index 611fbabb1..47827bae7 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visual/Effect.java +++ b/src/main/java/com/jozufozu/flywheel/api/visual/Effect.java @@ -2,7 +2,17 @@ package com.jozufozu.flywheel.api.visual; import com.jozufozu.flywheel.api.visualization.VisualizationContext; -// TODO: Consider adding LevelAccessor getter +/** + * An effect is not attached to any formal game object, but allows you to hook into + * flywheel's systems to render things. They're closely analogous to particles but + * without any built in support for networking. + */ public interface Effect { + /** + * Create a visual that will be keyed by this effect object. + * + * @param ctx The visualization context. + * @return An arbitrary EffectVisual. + */ EffectVisual visualize(VisualizationContext ctx); } diff --git a/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java b/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java index 513fed7d7..302959cbf 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java @@ -71,7 +71,8 @@ public final class BackendManagerImpl { } public static void onEndClientResourceReload(EndClientResourceReloadEvent event) { - if (event.getError().isPresent()) { + if (event.error() + .isPresent()) { return; } @@ -82,7 +83,7 @@ public final class BackendManagerImpl { public static void onReloadLevelRenderer(ReloadLevelRendererEvent event) { chooseBackend(); - ClientLevel level = event.getLevel(); + ClientLevel level = event.level(); if (level != null) { VisualizationManagerImpl.reset(level); } diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java index 2d704ffaf..f7a74fee2 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java @@ -36,23 +36,25 @@ public final class VisualizationEventHandler { } public static void onBeginFrame(BeginFrameEvent event) { - ClientLevel level = event.getContext().level(); + ClientLevel level = event.context() + .level(); VisualizationManagerImpl manager = VisualizationManagerImpl.get(level); if (manager == null) { return; } - manager.beginFrame(event.getContext()); + manager.beginFrame(event.context()); } public static void onRenderStage(RenderStageEvent event) { - ClientLevel level = event.getContext().level(); + ClientLevel level = event.context() + .level(); VisualizationManagerImpl manager = VisualizationManagerImpl.get(level); if (manager == null) { return; } - manager.renderStage(event.getContext(), event.getStage()); + manager.renderStage(event.context(), event.stage()); } public static void onEntityJoinLevel(EntityJoinLevelEvent event) { diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java index ca1c773a1..3c9649e2a 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java @@ -167,8 +167,7 @@ public class LitVisualStorage { } } - // Breaking this into 2 separate cases allows us to avoid the sync overhead in the common case. - // TODO: is it faster to only use the synced variant to avoid virtual dispatches? + // Breaking this into 2 separate cases allows us to avoid the overhead of atomics in the common case. sealed interface Updater { void updateLight(long updateId); diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/ColoredLitInstance.java b/src/main/java/com/jozufozu/flywheel/lib/instance/ColoredLitInstance.java index 702219e89..be535c9a3 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/ColoredLitInstance.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/ColoredLitInstance.java @@ -12,8 +12,7 @@ public abstract class ColoredLitInstance extends AbstractInstance implements Fla public byte b = (byte) 0xFF; public byte a = (byte) 0xFF; - public byte blockLight; - public byte skyLight; + public int packedLight; public int overlay = OverlayTexture.NO_OVERLAY; @@ -58,22 +57,16 @@ public abstract class ColoredLitInstance extends AbstractInstance implements Fla } @Override - public ColoredLitInstance setBlockLight(int blockLight) { - this.blockLight = (byte) blockLight; - return this; + public ColoredLitInstance light(int blockLight, int skyLight) { + return light(LightTexture.pack(blockLight, skyLight)); } @Override - public ColoredLitInstance setSkyLight(int skyLight) { - this.skyLight = (byte) skyLight; + public ColoredLitInstance light(int packedLight) { + this.packedLight = packedLight; return this; } - @Override - public int getPackedLight() { - return LightTexture.pack(blockLight, skyLight); - } - public ColoredLitInstance setOverlay(int overlay) { this.overlay = overlay; return this; diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/FlatLit.java b/src/main/java/com/jozufozu/flywheel/lib/instance/FlatLit.java index 01a77c9ea..bf8f0774f 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/FlatLit.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/FlatLit.java @@ -2,38 +2,25 @@ package com.jozufozu.flywheel.lib.instance; import com.jozufozu.flywheel.api.instance.Instance; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.LightLayer; +import net.minecraft.client.renderer.LightTexture; /** * An interface that implementors of {@link Instance} should also implement * if they wish to make use of Flywheel's provided light update methods. - *

- * This only covers flat lighting, smooth lighting is still TODO. */ public interface FlatLit extends Instance { /** - * @param blockLight An integer in the range [0, 15] representing the - * amount of block light this instance should receive. - * @return {@code this} + * Set the block and sky light values for this instance. + * @param blockLight Block light value + * @param skyLight Sky light value + * @return {@code this} for chaining */ - FlatLit setBlockLight(int blockLight); + FlatLit light(int blockLight, int skyLight); /** - * @param skyLight An integer in the range [0, 15] representing the - * amount of sky light this instance should receive. - * @return {@code this} + * Set the packed light value for this instance. + * @param packedLight Packed block and sky light per {@link LightTexture#pack(int, int)} + * @return {@code this} for chaining */ - FlatLit setSkyLight(int skyLight); - - default FlatLit setLight(int blockLight, int skyLight) { - return setBlockLight(blockLight).setSkyLight(skyLight); - } - - default FlatLit updateLight(BlockAndTintGetter level, BlockPos pos) { - return setLight(level.getBrightness(LightLayer.BLOCK, pos), level.getBrightness(LightLayer.SKY, pos)); - } - - int getPackedLight(); + FlatLit light(int packedLight); } diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java b/src/main/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java index 9b8ae298d..b7bcb16be 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java @@ -26,8 +26,8 @@ public final class InstanceTypes { MemoryUtil.memPutByte(ptr + 3, instance.a); MemoryUtil.memPutShort(ptr + 4, (short) (instance.overlay & 0xFFFF)); MemoryUtil.memPutShort(ptr + 6, (short) (instance.overlay >> 16 & 0xFFFF)); - MemoryUtil.memPutShort(ptr + 8, (short) (Byte.toUnsignedInt(instance.blockLight) << 4)); - MemoryUtil.memPutShort(ptr + 10, (short) (Byte.toUnsignedInt(instance.skyLight) << 4)); + MemoryUtil.memPutShort(ptr + 8, (short) (instance.packedLight & 0xFFFF)); + MemoryUtil.memPutShort(ptr + 10, (short) (instance.packedLight >> 16 & 0xFFFF)); MatrixMath.writeUnsafe(instance.model, ptr + 12); MatrixMath.writeUnsafe(instance.normal, ptr + 76); }) @@ -51,8 +51,8 @@ public final class InstanceTypes { MemoryUtil.memPutByte(ptr + 3, instance.a); MemoryUtil.memPutShort(ptr + 4, (short) (instance.overlay & 0xFFFF)); MemoryUtil.memPutShort(ptr + 6, (short) (instance.overlay >> 16 & 0xFFFF)); - MemoryUtil.memPutShort(ptr + 8, (short) (Byte.toUnsignedInt(instance.blockLight) << 4)); - MemoryUtil.memPutShort(ptr + 10, (short) (Byte.toUnsignedInt(instance.skyLight) << 4)); + MemoryUtil.memPutShort(ptr + 8, (short) (instance.packedLight & 0xFFFF)); + MemoryUtil.memPutShort(ptr + 10, (short) (instance.packedLight >> 16 & 0xFFFF)); MemoryUtil.memPutFloat(ptr + 12, instance.posX); MemoryUtil.memPutFloat(ptr + 16, instance.posY); MemoryUtil.memPutFloat(ptr + 20, instance.posZ); diff --git a/src/main/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBufferer.java b/src/main/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBufferer.java index 148a10d12..de638d654 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBufferer.java +++ b/src/main/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBufferer.java @@ -147,7 +147,6 @@ final class BakedModelBufferer { { for (int layerIndex = 0; layerIndex < CHUNK_LAYER_AMOUNT; layerIndex++) { var renderType = CHUNK_LAYERS[layerIndex]; - // FIXME: We leak the memory owned by the BufferBuilder here. var buffer = new BufferBuilder(renderType.bufferSize()); emitters[layerIndex] = new MeshEmitter(buffer, renderType); } diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractVisual.java b/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractVisual.java index 3bf4e3d38..234444986 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractVisual.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractVisual.java @@ -61,8 +61,8 @@ public abstract class AbstractVisual implements Visual { continue; } - instance.setLight(block, sky); - instance.handle() + instance.light(block, sky) + .handle() .setChanged(); } } @@ -73,7 +73,7 @@ public abstract class AbstractVisual implements Visual { protected void relight(int block, int sky, Stream instances) { instances.filter(Objects::nonNull) - .forEach(instance -> instance.setLight(block, sky) + .forEach(instance -> instance.light(block, sky) .handle() .setChanged()); } @@ -87,7 +87,7 @@ public abstract class AbstractVisual implements Visual { if (instance == null) { continue; } - instance.setLight(block, sky) + instance.light(block, sky) .handle() .setChanged(); } diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/components/FireComponent.java b/src/main/java/com/jozufozu/flywheel/lib/visual/components/FireComponent.java index 7ea47f044..be919e41f 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/components/FireComponent.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/components/FireComponent.java @@ -56,7 +56,7 @@ public class FireComponent implements EntityComponent { TransformedInstance instance = context.instancerProvider() .instancer(InstanceTypes.TRANSFORMED, model) .createInstance(); - instance.setBlockLight(LightTexture.block(LightTexture.FULL_BLOCK)); + instance.light(LightTexture.FULL_BLOCK); instance.setChanged(); return instance; } diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/components/HitboxComponent.java b/src/main/java/com/jozufozu/flywheel/lib/visual/components/HitboxComponent.java index 455f0c75a..4503002f9 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/components/HitboxComponent.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/components/HitboxComponent.java @@ -70,7 +70,7 @@ public class HitboxComponent implements EntityComponent { TransformedInstance instance = context.instancerProvider() .instancer(InstanceTypes.TRANSFORMED, model) .createInstance(); - instance.setBlockLight(LightTexture.block(LightTexture.FULL_BLOCK)); + instance.light(LightTexture.FULL_BLOCK); instance.setChanged(); return instance; } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java b/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java index c6ad5479c..0c526f113 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java @@ -21,6 +21,7 @@ import com.jozufozu.flywheel.lib.model.Models; import com.jozufozu.flywheel.lib.task.ForEachPlan; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.LightTexture; import net.minecraft.core.Vec3i; import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; @@ -271,8 +272,7 @@ public class ExampleEffect implements Effect { .instancer(InstanceTypes.TRANSFORMED, Models.block(Blocks.SHROOMLIGHT.defaultBlockState())) .createInstance(); - instance.setBlockLight(15) - .setSkyLight(15); + instance.light(LightTexture.FULL_BRIGHT); } public void _delete() {