extensions = new ArrayList<>();
public ExtensibleGlProgram(ResourceLocation name, int handle) {
super(name, handle);
@@ -32,7 +32,7 @@ public class ExtensibleGlProgram extends GlProgram {
public void bind() {
super.bind();
- extensions.forEach(IExtensionInstance::bind);
+ extensions.forEach(ExtensionInstance::bind);
}
@Override
@@ -42,7 +42,7 @@ public class ExtensibleGlProgram extends GlProgram {
.append(name)
.append('[');
- for (IExtensionInstance extension : extensions) {
+ for (ExtensionInstance extension : extensions) {
builder.append(extension)
.append('+');
}
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 12bc659ad..ce6ae31cd 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/GameStateProgram.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/GameStateProgram.java
@@ -5,22 +5,22 @@ import java.util.List;
import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
-import com.jozufozu.flywheel.core.shader.spec.IGameStateCondition;
+import com.jozufozu.flywheel.core.shader.spec.GameStateCondition;
import com.jozufozu.flywheel.util.Pair;
public class GameStateProgram implements ContextAwareProgram
{
- private final List> variants;
+ private final List> variants;
private final P fallback;
- protected GameStateProgram(List> variants, P fallback) {
+ protected GameStateProgram(List> variants, P fallback) {
this.variants = variants;
this.fallback = fallback;
}
@Override
public P get() {
- for (Pair variant : variants) {
+ for (Pair variant : variants) {
if (variant.first()
.isMet()) return variant.second();
}
@@ -30,7 +30,7 @@ public class GameStateProgram implements ContextAwareProgra
@Override
public void delete() {
- for (Pair variant : variants) {
+ for (Pair variant : variants) {
variant.second()
.delete();
}
@@ -44,13 +44,13 @@ public class GameStateProgram implements ContextAwareProgra
public static class Builder
{
private final P fallback;
- private final List> variants = new ArrayList<>();
+ private final List> variants = new ArrayList<>();
public Builder(P fallback) {
this.fallback = fallback;
}
- public Builder withVariant(IGameStateCondition condition, P program) {
+ public Builder
withVariant(GameStateCondition condition, P program) {
variants.add(Pair.of(condition, program));
return this;
}
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/extension/IExtensionInstance.java b/src/main/java/com/jozufozu/flywheel/core/shader/extension/ExtensionInstance.java
similarity index 87%
rename from src/main/java/com/jozufozu/flywheel/core/shader/extension/IExtensionInstance.java
rename to src/main/java/com/jozufozu/flywheel/core/shader/extension/ExtensionInstance.java
index d6c2e0f04..6499820c9 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/extension/IExtensionInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/extension/ExtensionInstance.java
@@ -2,7 +2,7 @@ package com.jozufozu.flywheel.core.shader.extension;
import net.minecraft.resources.ResourceLocation;
-public interface IExtensionInstance {
+public interface ExtensionInstance {
/**
* Bind the extra program state. It is recommended to grab the state information from global variables.
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/extension/UnitExtensionInstance.java b/src/main/java/com/jozufozu/flywheel/core/shader/extension/UnitExtensionInstance.java
index ac3dcc36e..70d1bff4b 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/extension/UnitExtensionInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/extension/UnitExtensionInstance.java
@@ -5,7 +5,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import net.minecraft.resources.ResourceLocation;
-public class UnitExtensionInstance implements IExtensionInstance {
+public class UnitExtensionInstance implements ExtensionInstance {
public static final ResourceLocation NAME = Flywheel.rl("unit");
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/extension/WorldFog.java b/src/main/java/com/jozufozu/flywheel/core/shader/extension/WorldFog.java
index b76c370eb..dd371debd 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/extension/WorldFog.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/extension/WorldFog.java
@@ -8,7 +8,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.resources.ResourceLocation;
-public class WorldFog implements IExtensionInstance {
+public class WorldFog implements ExtensionInstance {
public static final ResourceLocation NAME = Flywheel.rl("fog");
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/IGameStateProvider.java b/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/GameStateProvider.java
similarity index 60%
rename from src/main/java/com/jozufozu/flywheel/core/shader/gamestate/IGameStateProvider.java
rename to src/main/java/com/jozufozu/flywheel/core/shader/gamestate/GameStateProvider.java
index 8e472de72..a7f7fb0ba 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/IGameStateProvider.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/GameStateProvider.java
@@ -5,9 +5,9 @@ import com.mojang.serialization.Codec;
import net.minecraft.resources.ResourceLocation;
-public interface IGameStateProvider {
+public interface GameStateProvider {
- Codec CODEC = ResourceLocation.CODEC.xmap(GameStateRegistry::getStateProvider, IGameStateProvider::getID);
+ Codec CODEC = ResourceLocation.CODEC.xmap(GameStateRegistry::getStateProvider, GameStateProvider::getID);
ResourceLocation getID();
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/NormalDebugStateProvider.java b/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/NormalDebugStateProvider.java
index f7ddbbea0..01646f027 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/NormalDebugStateProvider.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/NormalDebugStateProvider.java
@@ -2,11 +2,11 @@ package com.jozufozu.flywheel.core.shader.gamestate;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.config.FlwConfig;
-import com.jozufozu.flywheel.core.shader.spec.IBooleanStateProvider;
+import com.jozufozu.flywheel.core.shader.spec.BooleanStateProvider;
import net.minecraft.resources.ResourceLocation;
-public class NormalDebugStateProvider implements IBooleanStateProvider {
+public class NormalDebugStateProvider implements BooleanStateProvider {
public static final NormalDebugStateProvider INSTANCE = new NormalDebugStateProvider();
public static final ResourceLocation NAME = Flywheel.rl("normal_debug");
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/BooleanGameStateCondition.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/BooleanGameStateCondition.java
index 6293ade94..9ff461f6b 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/BooleanGameStateCondition.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/BooleanGameStateCondition.java
@@ -1,22 +1,22 @@
package com.jozufozu.flywheel.core.shader.spec;
-import com.jozufozu.flywheel.core.shader.gamestate.IGameStateProvider;
+import com.jozufozu.flywheel.core.shader.gamestate.GameStateProvider;
import com.mojang.serialization.Codec;
import net.minecraft.resources.ResourceLocation;
-public class BooleanGameStateCondition implements IGameStateCondition {
+public class BooleanGameStateCondition implements GameStateCondition {
- public static final Codec BOOLEAN_SUGAR = IGameStateProvider.CODEC.xmap(gameContext -> {
- if (gameContext instanceof IBooleanStateProvider) {
- return new BooleanGameStateCondition(((IBooleanStateProvider) gameContext));
+ public static final Codec BOOLEAN_SUGAR = GameStateProvider.CODEC.xmap(gameContext -> {
+ if (gameContext instanceof BooleanStateProvider) {
+ return new BooleanGameStateCondition(((BooleanStateProvider) gameContext));
}
return null;
- }, IGameStateCondition::getStateProvider);
- protected final IBooleanStateProvider context;
+ }, GameStateCondition::getStateProvider);
+ protected final BooleanStateProvider context;
- public BooleanGameStateCondition(IBooleanStateProvider context) {
+ public BooleanGameStateCondition(BooleanStateProvider context) {
this.context = context;
}
@@ -26,7 +26,7 @@ public class BooleanGameStateCondition implements IGameStateCondition {
}
@Override
- public IGameStateProvider getStateProvider() {
+ public GameStateProvider getStateProvider() {
return context;
}
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/BooleanStateProvider.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/BooleanStateProvider.java
new file mode 100644
index 000000000..1cf0b1da2
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/BooleanStateProvider.java
@@ -0,0 +1,13 @@
+package com.jozufozu.flywheel.core.shader.spec;
+
+import com.jozufozu.flywheel.core.shader.gamestate.GameStateProvider;
+
+public interface BooleanStateProvider extends GameStateProvider {
+
+ boolean isTrue();
+
+ @Override
+ default Boolean getValue() {
+ return isTrue();
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/IGameStateCondition.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/GameStateCondition.java
similarity index 50%
rename from src/main/java/com/jozufozu/flywheel/core/shader/spec/IGameStateCondition.java
rename to src/main/java/com/jozufozu/flywheel/core/shader/spec/GameStateCondition.java
index 08fd87dc3..c8ad1e1cf 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/IGameStateCondition.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/GameStateCondition.java
@@ -1,14 +1,14 @@
package com.jozufozu.flywheel.core.shader.spec;
-import com.jozufozu.flywheel.core.shader.gamestate.IGameStateProvider;
+import com.jozufozu.flywheel.core.shader.gamestate.GameStateProvider;
import net.minecraft.resources.ResourceLocation;
-public interface IGameStateCondition {
+public interface GameStateCondition {
ResourceLocation getID();
- IGameStateProvider getStateProvider();
+ GameStateProvider getStateProvider();
boolean isMet();
}
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/IBooleanStateProvider.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/IBooleanStateProvider.java
deleted file mode 100644
index 1f1265724..000000000
--- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/IBooleanStateProvider.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.jozufozu.flywheel.core.shader.spec;
-
-import com.jozufozu.flywheel.core.shader.gamestate.IGameStateProvider;
-
-public interface IBooleanStateProvider extends IGameStateProvider {
-
- boolean isTrue();
-
- @Override
- default Boolean getValue() {
- return isTrue();
- }
-}
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramState.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramState.java
index e680c4e85..7f4fc7782 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramState.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramState.java
@@ -9,10 +9,10 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;
-public record ProgramState(IGameStateCondition context, List defines) {
+public record ProgramState(GameStateCondition context, List defines) {
// TODO: Use Codec.dispatch
- private static final Codec WHEN = Codec.either(BooleanGameStateCondition.BOOLEAN_SUGAR, SpecificValueCondition.CODEC)
+ private static final Codec WHEN = Codec.either(BooleanGameStateCondition.BOOLEAN_SUGAR, SpecificValueCondition.CODEC)
.flatXmap(either -> either.map(DataResult::success, DataResult::success), any -> {
if (any instanceof BooleanGameStateCondition) {
return DataResult.success(Either.left((BooleanGameStateCondition) any));
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/SpecificValueCondition.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/SpecificValueCondition.java
index 69e40a08d..fc530536e 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/SpecificValueCondition.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/SpecificValueCondition.java
@@ -1,22 +1,22 @@
package com.jozufozu.flywheel.core.shader.spec;
-import com.jozufozu.flywheel.core.shader.gamestate.IGameStateProvider;
+import com.jozufozu.flywheel.core.shader.gamestate.GameStateProvider;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.resources.ResourceLocation;
-public class SpecificValueCondition implements IGameStateCondition {
+public class SpecificValueCondition implements GameStateCondition {
- public static final Codec CODEC = RecordCodecBuilder.create(condition -> condition.group(IGameStateProvider.CODEC.fieldOf("provider")
+ public static final Codec CODEC = RecordCodecBuilder.create(condition -> condition.group(GameStateProvider.CODEC.fieldOf("provider")
.forGetter(SpecificValueCondition::getStateProvider), Codec.STRING.fieldOf("value")
.forGetter(SpecificValueCondition::getValue))
.apply(condition, SpecificValueCondition::new));
private final String required;
- private final IGameStateProvider context;
+ private final GameStateProvider context;
- public SpecificValueCondition(IGameStateProvider context, String required) {
+ public SpecificValueCondition(GameStateProvider context, String required) {
this.required = required;
this.context = context;
}
@@ -31,7 +31,7 @@ public class SpecificValueCondition implements IGameStateCondition {
}
@Override
- public IGameStateProvider getStateProvider() {
+ public GameStateProvider getStateProvider() {
return context;
}
diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertex.java b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertex.java
index eb77286fc..4a6664d0b 100644
--- a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertex.java
+++ b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertex.java
@@ -4,8 +4,8 @@ import java.nio.ByteBuffer;
import com.jozufozu.flywheel.api.vertex.VertexList;
import com.jozufozu.flywheel.api.vertex.VertexType;
-import com.jozufozu.flywheel.core.layout.CommonItems;
import com.jozufozu.flywheel.core.layout.BufferLayout;
+import com.jozufozu.flywheel.core.layout.CommonItems;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.datafixers.util.Pair;
diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertex.java b/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertex.java
index feb7ff348..85daec969 100644
--- a/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertex.java
+++ b/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertex.java
@@ -3,8 +3,8 @@ package com.jozufozu.flywheel.core.vertex;
import java.nio.ByteBuffer;
import com.jozufozu.flywheel.api.vertex.VertexType;
-import com.jozufozu.flywheel.core.layout.CommonItems;
import com.jozufozu.flywheel.core.layout.BufferLayout;
+import com.jozufozu.flywheel.core.layout.CommonItems;
public class PosTexNormalVertex implements VertexType {
diff --git a/src/main/java/com/jozufozu/flywheel/core/virtual/VirtualRenderWorld.java b/src/main/java/com/jozufozu/flywheel/core/virtual/VirtualRenderWorld.java
index bfd246988..a0687b992 100644
--- a/src/main/java/com/jozufozu/flywheel/core/virtual/VirtualRenderWorld.java
+++ b/src/main/java/com/jozufozu/flywheel/core/virtual/VirtualRenderWorld.java
@@ -43,7 +43,7 @@ import net.minecraft.world.ticks.LevelTickAccess;
public class VirtualRenderWorld extends Level implements FlywheelWorld {
public final Map blocksAdded = new HashMap<>();
- public final Map tesAdded = new HashMap<>();
+ public final Map besAdded = new HashMap<>();
public final Set spannedSections = new HashSet<>();
private final BlockPos.MutableBlockPos scratch = new BlockPos.MutableBlockPos();
@@ -85,9 +85,9 @@ public class VirtualRenderWorld extends Level implements FlywheelWorld {
lighter.runUpdates(Integer.MAX_VALUE, false, false);
}
- public void setTileEntities(Collection tileEntities) {
- tesAdded.clear();
- tileEntities.forEach(te -> tesAdded.put(te.getBlockPos(), te));
+ public void setBlockEntities(Collection blockEntities) {
+ besAdded.clear();
+ blockEntities.forEach(be -> besAdded.put(be.getBlockPos(), be));
}
public void clear() {
@@ -153,7 +153,7 @@ public class VirtualRenderWorld extends Level implements FlywheelWorld {
@Override
@Nullable
public BlockEntity getBlockEntity(BlockPos pos) {
- return tesAdded.get(pos);
+ return besAdded.get(pos);
}
@Override
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java
new file mode 100644
index 000000000..c9f086957
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java
@@ -0,0 +1,26 @@
+package com.jozufozu.flywheel.mixin;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstancingController;
+import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityTypeExtension;
+
+import net.minecraft.world.level.block.entity.BlockEntity;
+import net.minecraft.world.level.block.entity.BlockEntityType;
+
+@Mixin(BlockEntityType.class)
+public class BlockEntityTypeMixin implements BlockEntityTypeExtension {
+ @Unique
+ private BlockEntityInstancingController super T> flywheel$instancingController;
+
+ @Override
+ public BlockEntityInstancingController super T> flywheel$getInstancingController() {
+ return flywheel$instancingController;
+ }
+
+ @Override
+ public void flywheel$setInstancingController(BlockEntityInstancingController super T> instancingController) {
+ this.flywheel$instancingController = instancingController;
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
index a105affa3..5a67e78a2 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
@@ -9,8 +9,6 @@ import org.lwjgl.system.MemoryUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
-import com.jozufozu.flywheel.backend.instancing.SuperBufferSource;
-import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
import com.jozufozu.flywheel.backend.model.BufferBuilderHack;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.VertexFormat;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java
index 0e64a35ed..ed1a41e6e 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java
@@ -24,11 +24,9 @@ public class CancelEntityRenderMixin {
private Iterable filterEntities(ClientLevel world) {
Iterable entities = world.entitiesForRendering();
if (Backend.isOn()) {
-
ArrayList filtered = Lists.newArrayList(entities);
- InstancedRenderRegistry r = InstancedRenderRegistry.getInstance();
- filtered.removeIf(r::shouldSkipRender);
+ filtered.removeIf(InstancedRenderRegistry::shouldSkipRender);
return filtered;
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java
index 861fa7c06..a4accbe24 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/ChunkRebuildHooksMixin.java
@@ -22,14 +22,11 @@ public class ChunkRebuildHooksMixin {
@Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true)
private void addAndFilterBEs(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set set, E be, CallbackInfo ci) {
-
if (Backend.canUseInstancing(be.getLevel())) {
+ if (InstancedRenderRegistry.canInstance(be.getType()))
+ InstancedRenderDispatcher.getBlockEntities(be.getLevel()).queueAdd(be);
- InstancedRenderRegistry registry = InstancedRenderRegistry.getInstance();
- if (registry.canInstance(be.getType()))
- InstancedRenderDispatcher.getTiles(be.getLevel()).queueAdd(be);
-
- if (registry.shouldSkipRender(be))
+ if (InstancedRenderRegistry.shouldSkipRender(be))
ci.cancel();
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java
new file mode 100644
index 000000000..828232c4a
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java
@@ -0,0 +1,26 @@
+package com.jozufozu.flywheel.mixin;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+import com.jozufozu.flywheel.backend.instancing.entity.EntityInstancingController;
+import com.jozufozu.flywheel.backend.instancing.entity.EntityTypeExtension;
+
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EntityType;
+
+@Mixin(EntityType.class)
+public class EntityTypeMixin implements EntityTypeExtension {
+ @Unique
+ private EntityInstancingController super T> flywheel$instancingController;
+
+ @Override
+ public EntityInstancingController super T> flywheel$getInstancingController() {
+ return flywheel$instancingController;
+ }
+
+ @Override
+ public void flywheel$setInstancingController(EntityInstancingController super T> instancingController) {
+ this.flywheel$instancingController = instancingController;
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/InstanceAddMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/InstanceAddMixin.java
index 53137d485..b28fbfa84 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/InstanceAddMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/InstanceAddMixin.java
@@ -26,9 +26,9 @@ public class InstanceAddMixin {
@Inject(method = "setBlockEntity",
at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))
- private void tileAdded(BlockEntity be, CallbackInfo ci) {
+ private void blockEntityAdded(BlockEntity be, CallbackInfo ci) {
if (level.isClientSide && Backend.isOn()) {
- InstancedRenderDispatcher.getTiles(this.level)
+ InstancedRenderDispatcher.getBlockEntities(this.level)
.add(be);
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/InstanceRemoveMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/InstanceRemoveMixin.java
index 9a6862ddf..0ee0fd088 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/InstanceRemoveMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/InstanceRemoveMixin.java
@@ -25,18 +25,18 @@ public class InstanceRemoveMixin {
@Inject(at = @At("TAIL"), method = "setRemoved")
private void removeInstance(CallbackInfo ci) {
if (level instanceof ClientLevel && Backend.isOn()) {
- InstancedRenderDispatcher.getTiles(this.level)
+ InstancedRenderDispatcher.getBlockEntities(this.level)
.remove((BlockEntity) (Object) this);
}
}
// /**
// * Don't do this.
-// * It can cause infinite loops if an instance class tries to access another tile entity in its constructor.
+// * It can cause infinite loops if an instance class tries to access another block entity in its constructor.
// */
// @Inject(at = @At("TAIL"), method = "clearRemoved")
// private void addInstance(CallbackInfo ci) {
-// if (level.isClientSide) InstancedRenderDispatcher.getTiles(this.level)
+// if (level.isClientSide) InstancedRenderDispatcher.getBlockEntities(this.level)
// .add((BlockEntity) (Object) this);
// }
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java
index 5452c100e..a60ffd45d 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java
@@ -87,7 +87,7 @@ public class RenderHooksMixin {
@Inject(at = @At("TAIL"), method = "setBlockDirty(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V")
private void checkUpdate(BlockPos pos, BlockState lastState, BlockState newState, CallbackInfo ci) {
if (Backend.isOn()) {
- InstancedRenderDispatcher.getTiles(level)
+ InstancedRenderDispatcher.getBlockEntities(level)
.update(level.getBlockEntity(pos));
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java
index c66e41b63..0da987881 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java
@@ -1,11 +1,11 @@
package com.jozufozu.flywheel.vanilla;
import com.jozufozu.flywheel.api.MaterialManager;
-import com.jozufozu.flywheel.api.instance.IDynamicInstance;
-import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
+import com.jozufozu.flywheel.api.instance.DynamicInstance;
+import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
import com.jozufozu.flywheel.core.Materials;
-import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
+import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
@@ -14,14 +14,14 @@ import net.minecraft.client.renderer.blockentity.BellRenderer;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.entity.BellBlockEntity;
-public class BellInstance extends TileEntityInstance implements IDynamicInstance {
+public class BellInstance extends BlockEntityInstance implements DynamicInstance {
private final OrientedData bell;
private float lastRingTime = Float.NaN;
- public BellInstance(MaterialManager materialManager, BellBlockEntity tile) {
- super(materialManager, tile);
+ public BellInstance(MaterialManager materialManager, BellBlockEntity blockEntity) {
+ super(materialManager, blockEntity);
bell = createBellInstance()
.setPivot(0.5f, 0.75f, 0.5f)
@@ -30,15 +30,15 @@ public class BellInstance extends TileEntityInstance implements
@Override
public void beginFrame() {
- float ringTime = (float)tile.ticks + AnimationTickHolder.getPartialTicks();
+ float ringTime = (float)blockEntity.ticks + AnimationTickHolder.getPartialTicks();
if (ringTime == lastRingTime) return;
lastRingTime = ringTime;
- if (tile.shaking) {
+ if (blockEntity.shaking) {
float angle = Mth.sin(ringTime / (float) Math.PI) / (4.0F + ringTime / 3.0F);
- Vector3f ringAxis = tile.clickDirection.getCounterClockWise().step();
+ Vector3f ringAxis = blockEntity.clickDirection.getCounterClockWise().step();
bell.setRotation(ringAxis.rotation(angle));
} else {
@@ -59,7 +59,7 @@ public class BellInstance extends TileEntityInstance implements
private OrientedData createBellInstance() {
return materialManager.defaultCutout()
.material(Materials.ORIENTED)
- .model(tile.getType(), BellInstance::createBellModel)
+ .model(blockEntity.getType(), BellInstance::createBellModel)
.createInstance();
}
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java
index ab1acdebf..df834d326 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java
@@ -5,12 +5,12 @@ import java.util.Calendar;
import javax.annotation.Nonnull;
import com.jozufozu.flywheel.api.MaterialManager;
-import com.jozufozu.flywheel.api.instance.IDynamicInstance;
-import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
+import com.jozufozu.flywheel.api.instance.DynamicInstance;
+import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
import com.jozufozu.flywheel.core.Materials;
+import com.jozufozu.flywheel.core.hardcoded.ModelPart;
import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
-import com.jozufozu.flywheel.core.hardcoded.ModelPart;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
@@ -28,7 +28,7 @@ import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.state.properties.ChestType;
-public class ChestInstance extends TileEntityInstance implements IDynamicInstance {
+public class ChestInstance extends BlockEntityInstance implements DynamicInstance {
private final OrientedData body;
private final ModelData lid;
@@ -41,13 +41,13 @@ public class ChestInstance extends TileE
private float lastProgress = Float.NaN;
- public ChestInstance(MaterialManager materialManager, T tile) {
- super(materialManager, tile);
+ public ChestInstance(MaterialManager materialManager, T blockEntity) {
+ super(materialManager, blockEntity);
Block block = blockState.getBlock();
chestType = blockState.hasProperty(ChestBlock.TYPE) ? blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
- renderMaterial = Sheets.chooseMaterial(tile, chestType, isChristmas());
+ renderMaterial = Sheets.chooseMaterial(blockEntity, chestType, isChristmas());
body = baseInstance()
.setPosition(getInstancePosition());
@@ -63,7 +63,7 @@ public class ChestInstance extends TileE
DoubleBlockCombiner.NeighborCombineResult extends ChestBlockEntity> wrapper = chestBlock.combine(blockState, world, getWorldPosition(), true);
- this.lidProgress = wrapper.apply(ChestBlock.opennessCombiner(tile));
+ this.lidProgress = wrapper.apply(ChestBlock.opennessCombiner(blockEntity));
} else {
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java
index 4fe3116df..c4d06994a 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java
@@ -1,13 +1,13 @@
package com.jozufozu.flywheel.vanilla;
import com.jozufozu.flywheel.api.MaterialManager;
-import com.jozufozu.flywheel.api.instance.IDynamicInstance;
-import com.jozufozu.flywheel.api.instance.ITickableInstance;
+import com.jozufozu.flywheel.api.instance.DynamicInstance;
+import com.jozufozu.flywheel.api.instance.TickableInstance;
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
import com.jozufozu.flywheel.core.Materials;
+import com.jozufozu.flywheel.core.hardcoded.ModelPart;
import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.model.Model;
-import com.jozufozu.flywheel.core.hardcoded.ModelPart;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
import com.mojang.math.Vector3f;
@@ -21,7 +21,7 @@ import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
-public class MinecartInstance extends EntityInstance implements IDynamicInstance, ITickableInstance {
+public class MinecartInstance extends EntityInstance implements DynamicInstance, TickableInstance {
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png");
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java
index a64e5b0ec..167b2367a 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java
@@ -1,11 +1,11 @@
package com.jozufozu.flywheel.vanilla;
import com.jozufozu.flywheel.api.MaterialManager;
-import com.jozufozu.flywheel.api.instance.IDynamicInstance;
-import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
+import com.jozufozu.flywheel.api.instance.DynamicInstance;
+import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
import com.jozufozu.flywheel.core.Materials;
-import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
+import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
import com.mojang.math.Quaternion;
@@ -19,7 +19,7 @@ import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.ShulkerBoxBlock;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
-public class ShulkerBoxInstance extends TileEntityInstance implements IDynamicInstance {
+public class ShulkerBoxInstance extends BlockEntityInstance implements DynamicInstance {
private final TextureAtlasSprite texture;
@@ -29,10 +29,10 @@ public class ShulkerBoxInstance extends TileEntityInstance
Date: Tue, 4 Jan 2022 14:14:30 -0800
Subject: [PATCH 2/7] Document, annotate, and rename
- Add documentation for new InstancedRenderRegistry
- Annotate TypeExtensions with Nullable
- Add method for creating bulk instances
---
.../com/jozufozu/flywheel/api/Instancer.java | 10 ++
.../instancing/InstancedRenderRegistry.java | 170 +++++++++++++++---
.../BlockEntityInstancingController.java | 15 ++
.../blockentity/BlockEntityTypeExtension.java | 5 +-
.../entity/EntityInstancingController.java | 15 ++
.../entity/EntityTypeExtension.java | 5 +-
.../flywheel/mixin/BlockEntityTypeMixin.java | 5 +-
.../flywheel/mixin/EntityTypeMixin.java | 5 +-
8 files changed, 205 insertions(+), 25 deletions(-)
diff --git a/src/main/java/com/jozufozu/flywheel/api/Instancer.java b/src/main/java/com/jozufozu/flywheel/api/Instancer.java
index 8ea0c3f70..5b6ac1cb4 100644
--- a/src/main/java/com/jozufozu/flywheel/api/Instancer.java
+++ b/src/main/java/com/jozufozu/flywheel/api/Instancer.java
@@ -50,4 +50,14 @@ public interface Instancer {
*
*/
void notifyRemoval();
+
+ /**
+ * Populate arr with new instances of this model.
+ * @param arr An array to fill.
+ */
+ default void createInstances(D[] arr) {
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = createInstance();
+ }
+ }
}
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 87f43a90e..1946dabdb 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java
@@ -21,89 +21,177 @@ import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
+/**
+ * A utility class for registering and retrieving {@code InstancingController}s.
+ */
+@SuppressWarnings("unchecked")
public class InstancedRenderRegistry {
+ /**
+ * Checks if the given block entity type can be instanced.
+ * @param type The block entity type to check.
+ * @param The type of the block entity.
+ * @return {@code true} if the block entity type can be instanced.
+ */
public static boolean canInstance(BlockEntityType extends T> type) {
- return getBlockEntityController(type) != null;
+ return getController(type) != null;
}
+ /**
+ * Checks if the given entity type can be instanced.
+ * @param type The entity type to check.
+ * @param The type of the entity.
+ * @return {@code true} if the entity type can be instanced.
+ */
public static boolean canInstance(EntityType extends T> type) {
- return getEntityController(type) != null;
+ return getController(type) != null;
}
+ /**
+ * Creates an instance for the given block entity, if possible.
+ * @param materialManager The material manager to use.
+ * @param blockEntity The block entity to create an instance of.
+ * @param The type of the block entity.
+ * @return An instance of the block entity, or {@code null} if the block entity cannot be instanced.
+ */
@Nullable
public static BlockEntityInstance super T> createInstance(MaterialManager materialManager, T blockEntity) {
- BlockEntityInstancingController super T> controller = getBlockEntityController(getType(blockEntity));
+ BlockEntityInstancingController super T> controller = getController(getType(blockEntity));
if (controller == null) {
return null;
}
return controller.createInstance(materialManager, blockEntity);
}
+ /**
+ * Creates an instance for the given entity, if possible.
+ * @param materialManager The material manager to use.
+ * @param entity The entity to create an instance of.
+ * @param The type of the entity.
+ * @return An instance of the entity, or {@code null} if the entity cannot be instanced.
+ */
@Nullable
public static EntityInstance super T> createInstance(MaterialManager materialManager, T entity) {
- EntityInstancingController super T> controller = getEntityController(getType(entity));
+ EntityInstancingController super T> controller = getController(getType(entity));
if (controller == null) {
return null;
}
return controller.createInstance(materialManager, entity);
}
+ /**
+ * Checks if the given block entity is instanced and should not be rendered normally.
+ * @param blockEntity The block entity to check.
+ * @param The type of the block entity.
+ * @return {@code true} if the block entity is instanced and should not be rendered normally.
+ */
public static boolean shouldSkipRender(T blockEntity) {
- BlockEntityInstancingController super T> controller = getBlockEntityController(getType(blockEntity));
+ BlockEntityInstancingController super T> controller = getController(getType(blockEntity));
if (controller == null) {
return false;
}
return controller.shouldSkipRender(blockEntity);
}
+ /**
+ * Checks if the given entity is instanced and should not be rendered normally.
+ * @param entity The entity to check.
+ * @param The type of the entity.
+ * @return {@code true} if the entity is instanced and should not be rendered normally.
+ */
public static boolean shouldSkipRender(T entity) {
- EntityInstancingController super T> controller = getEntityController(getType(entity));
+ EntityInstancingController super T> controller = getController(getType(entity));
if (controller == null) {
return false;
}
return controller.shouldSkipRender(entity);
}
+ /**
+ * Get an object to configure the instancing controller for the given block entity type.
+ * @param type The block entity type to configure.
+ * @param The type of the block entity.
+ * @return The configuration object.
+ */
public static BlockEntityConfig configure(BlockEntityType type) {
return new BlockEntityConfig<>(type);
}
+ /**
+ * Get an object to configure the instancing controller for the given entity type.
+ * @param type The entity type to configure.
+ * @param The type of the entity.
+ * @return The configuration object.
+ */
public static EntityConfig configure(EntityType type) {
return new EntityConfig<>(type);
}
- @SuppressWarnings("unchecked")
+ /**
+ * Gets the instancing controller for the given block entity type, if one exists.
+ * @param type The block entity type to get the instancing controller for.
+ * @param The type of the block entity.
+ * @return The instancing controller for the given block entity type, or {@code null} if none exists.
+ */
@Nullable
- public static BlockEntityInstancingController super T> getBlockEntityController(BlockEntityType type) {
+ public static BlockEntityInstancingController super T> getController(BlockEntityType type) {
return ((BlockEntityTypeExtension) type).flywheel$getInstancingController();
}
- @SuppressWarnings("unchecked")
- public static void setBlockEntityController(BlockEntityType type, BlockEntityInstancingController super T> instancingController) {
- ((BlockEntityTypeExtension) type).flywheel$setInstancingController(instancingController);
- }
-
- @SuppressWarnings("unchecked")
+ /**
+ * Gets the instancing controller for the given entity type, if one exists.
+ * @param type The entity type to get the instancing controller for.
+ * @param The type of the entity.
+ * @return The instancing controller for the given entity type, or {@code null} if none exists.
+ */
@Nullable
- public static EntityInstancingController super T> getEntityController(EntityType type) {
+ public static EntityInstancingController super T> getController(EntityType type) {
return ((EntityTypeExtension) type).flywheel$getInstancingController();
}
- @SuppressWarnings("unchecked")
- public static void setEntityController(EntityType type, EntityInstancingController super T> instancingController) {
+ /**
+ * Sets the instancing controller for the given block entity type.
+ * @param type The block entity type to set the instancing controller for.
+ * @param instancingController The instancing controller to set.
+ * @param The type of the block entity.
+ */
+ public static void setController(BlockEntityType type, BlockEntityInstancingController super T> instancingController) {
+ ((BlockEntityTypeExtension) type).flywheel$setInstancingController(instancingController);
+ }
+
+ /**
+ * Sets the instancing controller for the given entity type.
+ * @param type The entity type to set the instancing controller for.
+ * @param instancingController The instancing controller to set.
+ * @param The type of the entity.
+ */
+ public static void setController(EntityType type, EntityInstancingController super T> instancingController) {
((EntityTypeExtension) type).flywheel$setInstancingController(instancingController);
}
- @SuppressWarnings("unchecked")
+ /**
+ * Gets the type of the given block entity.
+ * @param blockEntity The block entity to get the type of.
+ * @param The type of the block entity.
+ * @return The {@link BlockEntityType} associated with the given block entity.
+ */
public static BlockEntityType super T> getType(T blockEntity) {
return (BlockEntityType super T>) blockEntity.getType();
}
- @SuppressWarnings("unchecked")
+ /**
+ * Gets the type of the given entity.
+ * @param entity The entity to get the type of.
+ * @param The type of the entity.
+ * @return The {@link EntityType} associated with the given entity.
+ */
public static EntityType super T> getType(T entity) {
return (EntityType super T>) entity.getType();
}
+ /**
+ * An object to configure the instancing controller for a block entity.
+ * @param The type of the block entity.
+ */
public static class BlockEntityConfig {
protected BlockEntityType type;
protected BiFunction> instanceFactory;
@@ -113,32 +201,54 @@ public class InstancedRenderRegistry {
this.type = type;
}
+ /**
+ * Sets the instance factory for the block entity.
+ * @param instanceFactory The instance factory.
+ * @return {@code this}
+ */
public BlockEntityConfig factory(BiFunction> instanceFactory) {
this.instanceFactory = instanceFactory;
return this;
}
+ /**
+ * Sets a predicate to determine whether to skip rendering a block entity.
+ * @param skipRender The predicate.
+ * @return {@code this}
+ */
public BlockEntityConfig skipRender(Predicate skipRender) {
this.skipRender = skipRender;
return this;
}
+ /**
+ * Sets a predicate to always skip rendering for block entities of this type.
+ * @return {@code this}
+ */
public BlockEntityConfig alwaysSkipRender() {
this.skipRender = be -> true;
return this;
}
+ /**
+ * Constructs the block entity instancing controller, and sets it for the block entity type.
+ * @return The block entity instancing controller.
+ */
public SimpleBlockEntityInstancingController apply() {
Objects.requireNonNull(instanceFactory, "Instance factory cannot be null!");
if (skipRender == null) {
skipRender = be -> false;
}
SimpleBlockEntityInstancingController controller = new SimpleBlockEntityInstancingController<>(instanceFactory, skipRender);
- setBlockEntityController(type, controller);
+ setController(type, controller);
return controller;
}
}
+ /**
+ * An object to configure the instancing controller for an entity.
+ * @param The type of the entity.
+ */
public static class EntityConfig {
protected EntityType type;
protected BiFunction> instanceFactory;
@@ -148,28 +258,46 @@ public class InstancedRenderRegistry {
this.type = type;
}
+ /**
+ * Sets the instance factory for the entity.
+ * @param instanceFactory The instance factory.
+ * @return {@code this}
+ */
public EntityConfig factory(BiFunction> instanceFactory) {
this.instanceFactory = instanceFactory;
return this;
}
+ /**
+ * Sets a predicate to determine whether to skip rendering an entity.
+ * @param skipRender The predicate.
+ * @return {@code this}
+ */
public EntityConfig skipRender(Predicate skipRender) {
this.skipRender = skipRender;
return this;
}
+ /**
+ * Sets a predicate to always skip rendering for entities of this type.
+ * @return {@code this}
+ */
public EntityConfig alwaysSkipRender() {
this.skipRender = entity -> true;
return this;
}
+ /**
+ * Constructs the entity instancing controller, and sets it for the entity type.
+ * @return The entity instancing controller.
+ */
public SimpleEntityInstancingController apply() {
Objects.requireNonNull(instanceFactory, "Instance factory cannot be null!");
if (skipRender == null) {
skipRender = entity -> false;
}
SimpleEntityInstancingController controller = new SimpleEntityInstancingController<>(instanceFactory, skipRender);
- setEntityController(type, controller);
+ setController(type, controller);
return controller;
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstancingController.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstancingController.java
index d2af7e459..23bf0b318 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstancingController.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstancingController.java
@@ -4,8 +4,23 @@ import com.jozufozu.flywheel.api.MaterialManager;
import net.minecraft.world.level.block.entity.BlockEntity;
+/**
+ * An instancing controller that will be keyed to a block entity type.
+ * @param The type of block entity this controller is for.
+ */
public interface BlockEntityInstancingController {
+ /**
+ * Given a block entity and a material manager, constructs an instance for the block entity.
+ * @param materialManager The material manager to use.
+ * @param blockEntity The block entity to construct an instance for.
+ * @return The instance.
+ */
BlockEntityInstance super T> createInstance(MaterialManager materialManager, T blockEntity);
+ /**
+ * Checks if the given block entity should not be rendered normally.
+ * @param blockEntity The block entity to check.
+ * @return {@code true} if the block entity should not be rendered normally, {@code false} if it should.
+ */
boolean shouldSkipRender(T blockEntity);
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityTypeExtension.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityTypeExtension.java
index e21f03334..3ac1bbb7e 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityTypeExtension.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityTypeExtension.java
@@ -1,9 +1,12 @@
package com.jozufozu.flywheel.backend.instancing.blockentity;
+import javax.annotation.Nullable;
+
import net.minecraft.world.level.block.entity.BlockEntity;
public interface BlockEntityTypeExtension {
+ @Nullable
BlockEntityInstancingController super T> flywheel$getInstancingController();
- void flywheel$setInstancingController(BlockEntityInstancingController super T> instancingController);
+ void flywheel$setInstancingController(@Nullable BlockEntityInstancingController super T> instancingController);
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstancingController.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstancingController.java
index c835ca59e..740800f6b 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstancingController.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstancingController.java
@@ -4,8 +4,23 @@ import com.jozufozu.flywheel.api.MaterialManager;
import net.minecraft.world.entity.Entity;
+/**
+ * An instancing controller that will be keyed to an entity type.
+ * @param The entity type.
+ */
public interface EntityInstancingController {
+ /**
+ * Given an entity and a material manager, constructs an instance for the entity.
+ * @param materialManager The material manager to use.
+ * @param entity The entity to construct an instance for.
+ * @return The instance.
+ */
EntityInstance super T> createInstance(MaterialManager materialManager, T entity);
+ /**
+ * Checks if the given entity should not render normally.
+ * @param entity The entity to check.
+ * @return {@code true} if the entity should not render normally, {@code false} if it should.
+ */
boolean shouldSkipRender(T entity);
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityTypeExtension.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityTypeExtension.java
index cede41bbe..b01918acd 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityTypeExtension.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityTypeExtension.java
@@ -1,9 +1,12 @@
package com.jozufozu.flywheel.backend.instancing.entity;
+import javax.annotation.Nullable;
+
import net.minecraft.world.entity.Entity;
public interface EntityTypeExtension {
+ @Nullable
EntityInstancingController super T> flywheel$getInstancingController();
- void flywheel$setInstancingController(EntityInstancingController super T> instancingController);
+ void flywheel$setInstancingController(@Nullable EntityInstancingController super T> instancingController);
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java
index c9f086957..ba5b86e18 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java
@@ -1,5 +1,7 @@
package com.jozufozu.flywheel.mixin;
+import javax.annotation.Nullable;
+
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@@ -15,12 +17,13 @@ public class BlockEntityTypeMixin implements BlockEntityT
private BlockEntityInstancingController super T> flywheel$instancingController;
@Override
+ @Nullable
public BlockEntityInstancingController super T> flywheel$getInstancingController() {
return flywheel$instancingController;
}
@Override
- public void flywheel$setInstancingController(BlockEntityInstancingController super T> instancingController) {
+ public void flywheel$setInstancingController(@Nullable BlockEntityInstancingController super T> instancingController) {
this.flywheel$instancingController = instancingController;
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java
index 828232c4a..fdd14c9d2 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java
@@ -1,5 +1,7 @@
package com.jozufozu.flywheel.mixin;
+import javax.annotation.Nullable;
+
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@@ -15,12 +17,13 @@ public class EntityTypeMixin implements EntityTypeExtension
private EntityInstancingController super T> flywheel$instancingController;
@Override
+ @Nullable
public EntityInstancingController super T> flywheel$getInstancingController() {
return flywheel$instancingController;
}
@Override
- public void flywheel$setInstancingController(EntityInstancingController super T> instancingController) {
+ public void flywheel$setInstancingController(@Nullable EntityInstancingController super T> instancingController) {
this.flywheel$instancingController = instancingController;
}
}
From 8224e476194919a5d7b691ac498ce01322595e41 Mon Sep 17 00:00:00 2001
From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com>
Date: Tue, 4 Jan 2022 21:50:10 -0800
Subject: [PATCH 3/7] Add 0.5.0a and 0.5.1 to issue template
---
.github/ISSUE_TEMPLATE/bug_report.yml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index a48b1b1a6..2fc8897dc 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -59,6 +59,8 @@ body:
label: Mod Version
description: The version of the mod you were using when the bug occured
options:
+ - "0.5.1"
+ - "0.5.0a"
- "0.5.0"
- "0.4.2-rc"
- "0.4.1"
From e0342c4b785ef84481cc1750d7ea90a3a6e66888 Mon Sep 17 00:00:00 2001
From: Jozufozu
Date: Wed, 5 Jan 2022 11:44:52 -0800
Subject: [PATCH 4/7] Better state restore in InstancingEngine
- Attempt to fix optifine issues
- Replace with {@code}
---
.../flywheel/api/instance/DynamicInstance.java | 2 +-
.../flywheel/api/instance/TickableInstance.java | 2 +-
.../flywheel/backend/gl/GlVertexArray.java | 13 ++++++++++---
.../flywheel/backend/gl/buffer/GlBufferType.java | 8 ++++++++
.../backend/gl/versioned/GlVersioned.java | 2 +-
.../backend/instancing/AbstractInstance.java | 6 +++---
.../blockentity/BlockEntityInstance.java | 6 +++---
.../instancing/instancing/InstancingEngine.java | 10 +++++++---
.../flywheel/backend/source/SourceFile.java | 2 +-
.../jozufozu/flywheel/core/materials/FlatLit.java | 4 ++--
.../jozufozu/flywheel/core/model/WorldModel.java | 2 +-
.../flywheel/core/shader/spec/ProgramSpec.java | 4 ++--
.../flywheel/mixin/BufferUploaderAccessor.java | 15 +++++++++++++++
13 files changed, 55 insertions(+), 21 deletions(-)
diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java b/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java
index 14310c962..86e43e77b 100644
--- a/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java
@@ -30,7 +30,7 @@ public interface DynamicInstance extends Instance {
*
You might want to opt out of this if you want your animations to remain smooth
* even when far away from the camera. It is recommended to keep this as is, however.
*
- * @return true
if your instance should be slow ticked.
+ * @return {@code true} if your instance should be slow ticked.
*/
default boolean decreaseFramerateWithDistance() {
return true;
diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java b/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java
index efb2fedb1..488ba8697 100644
--- a/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java
@@ -38,7 +38,7 @@ public interface TickableInstance extends Instance {
*
You might want to opt out of this if you want your animations to remain smooth
* even when far away from the camera. It is recommended to keep this as is, however.
*
- * @return true
if your instance should be slow ticked.
+ * @return {@code true} if your instance should be slow ticked.
*/
default boolean decreaseTickRateWithDistance() {
return true;
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java b/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java
index 1ec315fa9..4f194e5d9 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GlVertexArray.java
@@ -12,10 +12,17 @@ public class GlVertexArray extends GlObject {
setHandle(GlStateManager._glGenVertexArrays());
}
+ public static void bind(int vao) {
+ GlStateManager._glBindVertexArray(vao);
+ BufferUploaderAccessor.flywheel$setLastVAO(vao);
+ }
+
public void bind() {
- int handle = handle();
- GlStateManager._glBindVertexArray(handle);
- BufferUploaderAccessor.flywheel$setLastVAO(handle);
+ bind(handle());
+ }
+
+ public static int getBoundVertexArray() {
+ return BufferUploaderAccessor.flywheel$getLastVAO();
}
public static void unbind() {
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java
index 53a0ab9ac..16f0c450a 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java
@@ -50,4 +50,12 @@ public enum GlBufferType {
case GL15C.GL_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$setLastVBO(0);
}
}
+
+ public int getBoundBuffer() {
+ return switch (this.glEnum) {
+ case GL15C.GL_ELEMENT_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$getLastEBO();
+ case GL15C.GL_ARRAY_BUFFER -> BufferUploaderAccessor.flywheel$getLastVBO();
+ default -> -1;
+ };
+ }
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlVersioned.java b/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlVersioned.java
index d019832b7..8615e9086 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlVersioned.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlVersioned.java
@@ -4,7 +4,7 @@ import org.lwjgl.opengl.GLCapabilities;
/**
* This interface should be implemented by enums such that the
- * last defined variant always returns true
.
+ * last defined variant always returns {@code true}
*/
public interface GlVersioned {
/**
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 1a2ebb781..6a3e67ba8 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java
@@ -65,13 +65,13 @@ public abstract class AbstractInstance implements Instance, LightListener {
* When an instance is reset, the instance is deleted and re-created.
*
*
- * Just before {@link #update()} would be called, shouldReset()
is checked.
- * If this function returns true
, then this instance will be {@link #remove removed},
+ * Just before {@link #update()} would be called, {@code shouldReset()} is checked.
+ * If this function returns {@code true}, then this instance will be {@link #remove removed},
* and another instance will be constructed to replace it. This allows for more sane resource
* acquisition compared to trying to update everything within the lifetime of an instance.
*
*
- * @return true
if this instance should be discarded and refreshed.
+ * @return {@code true} if this instance should be discarded and refreshed.
*/
public boolean shouldReset() {
return false;
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java
index 11925664f..ed4313063 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java
@@ -48,12 +48,12 @@ public abstract class BlockEntityInstance extends Abstrac
}
/**
- * Just before {@link #update()} would be called, shouldReset()
is checked.
- * If this function returns true
, then this instance will be {@link #remove removed},
+ * Just before {@link #update()} would be called, {@code shouldReset()} is checked.
+ * If this function returns {@code true}, then this instance will be {@link #remove removed},
* and another instance will be constructed to replace it. This allows for more sane resource
* acquisition compared to trying to update everything within the lifetime of an instance.
*
- * @return true
if this instance should be discarded and refreshed.
+ * @return {@code true} if this instance should be discarded and refreshed.
*/
public boolean shouldReset() {
return blockEntity.getBlockState() != blockState;
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java
index b14cf78e7..8f044c733 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java
@@ -79,6 +79,10 @@ public class InstancingEngine implements Engine {
*/
@Override
public void render(TaskEngine taskEngine, RenderLayerEvent event) {
+ int ebo = GlBufferType.ELEMENT_ARRAY_BUFFER.getBoundBuffer();
+ int vbo = GlBufferType.ARRAY_BUFFER.getBoundBuffer();
+ int vao = GlVertexArray.getBoundVertexArray();
+
double camX;
double camY;
double camZ;
@@ -99,9 +103,9 @@ public class InstancingEngine
implements Engine {
getGroupsToRender(event.getLayer()).forEach(group -> group.render(viewProjection, camX, camY, camZ));
- GlBufferType.ELEMENT_ARRAY_BUFFER.unbind();
- GlBufferType.ARRAY_BUFFER.unbind();
- GlVertexArray.unbind();
+ GlBufferType.ELEMENT_ARRAY_BUFFER.bind(ebo);
+ GlBufferType.ARRAY_BUFFER.bind(vbo);
+ GlVertexArray.bind(vao);
}
private Stream> getGroupsToRender(@Nullable RenderLayer layer) {
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java b/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java
index ab055553d..24a8d1836 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/SourceFile.java
@@ -217,7 +217,7 @@ public class SourceFile {
}
/**
- * Scan the source for #use "..."
directives.
+ * Scan the source for {@code #use "..."} directives.
* Records the contents of the directive into an {@link Import} object, and marks the directive for elision.
* @param elisions
*/
diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java b/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java
index 038a7250a..3829a1a84 100644
--- a/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java
+++ b/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java
@@ -14,14 +14,14 @@ public interface FlatLit> {
/**
* @param blockLight An integer in the range [0, 15] representing the
* amount of block light this instance should receive.
- * @return this
+ * @return {@code this}
*/
D setBlockLight(int blockLight);
/**
* @param skyLight An integer in the range [0, 15] representing the
* amount of sky light this instance should receive.
- * @return this
+ * @return {@code this}
*/
D setSkyLight(int skyLight);
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 b3e96aa7d..c350361c9 100644
--- a/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java
+++ b/src/main/java/com/jozufozu/flywheel/core/model/WorldModel.java
@@ -16,7 +16,7 @@ public class WorldModel implements Model {
private final String name;
/**
- * It is expected that renderWorld.getShade(...)
returns a constant.
+ * It is expected that {@code renderWorld.getShade(...)} returns a constant.
*/
public WorldModel(BlockAndTintGetter renderWorld, RenderType layer, Collection blocks, String name) {
reader = Formats.BLOCK.createReader(ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, blocks));
diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java
index 3716caef2..e293a2732 100644
--- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java
+++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramSpec.java
@@ -15,11 +15,11 @@ import net.minecraft.resources.ResourceLocation;
* An object describing a shader program that can be loaded by flywheel.
*
*
- * These are defined through json. All ProgramSpecs in assets/modid/flywheel/programs
are parsed and
+ * These are defined through json. All ProgramSpecs in {@code assets/modid/flywheel/programs} are parsed and
* processed. One ProgramSpec typically specifies one "material" that can be used in game to render things.
*
*
- * All shader source files in assets/modid/flywheel/shaders
are completely loaded and parsed into
+ * All shader source files in {@code assets/modid/flywheel/shaders} are completely loaded and parsed into
* {@link SourceFile SourceFiles}, but not compiled until one of them is
* referenced by a ProgramSpec.
*
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java
index 64b81bd2b..f7d609805 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/BufferUploaderAccessor.java
@@ -21,4 +21,19 @@ public interface BufferUploaderAccessor {
static void flywheel$setLastEBO(int id) {
throw new AssertionError();
}
+
+ @Accessor("lastIndexBufferObject")
+ static int flywheel$getLastEBO() {
+ throw new AssertionError();
+ }
+
+ @Accessor("lastVertexBufferObject")
+ static int flywheel$getLastVBO() {
+ throw new AssertionError();
+ }
+
+ @Accessor("lastVertexArrayObject")
+ static int flywheel$getLastVAO() {
+ throw new AssertionError();
+ }
}
From 5c4ff9ca2a6021880803ed4e796a79e77154cf7b Mon Sep 17 00:00:00 2001
From: Jozufozu
Date: Wed, 5 Jan 2022 22:01:03 -0800
Subject: [PATCH 5/7] Fix visual artifacts with contraptions while using
opfine.
I think the buffers from the shadow pass were bleeding into the color pass.
---
.../jozufozu/flywheel/backend/Backend.java | 8 +--
.../flywheel/backend/OptifineHandler.java | 25 +++++++
.../backend/instancing/InstanceWorld.java | 6 +-
.../flywheel/core/LastActiveCamera.java | 16 +++++
.../flywheel/event/BeginFrameEvent.java | 20 +++---
.../jozufozu/flywheel/mixin/CameraMixin.java | 21 ++++++
.../jozufozu/flywheel/mixin/FrustumMixin.java | 25 +++++++
...ooksMixin.java => LevelRendererMixin.java} | 4 +-
src/main/resources/flywheel.mixins.json | 66 ++++++++++---------
9 files changed, 138 insertions(+), 53 deletions(-)
create mode 100644 src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java
create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java
create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java
rename src/main/java/com/jozufozu/flywheel/mixin/{RenderHooksMixin.java => LevelRendererMixin.java} (95%)
diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java
index bffbddc46..2285f5684 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java
@@ -1,10 +1,6 @@
package com.jozufozu.flywheel.backend;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import javax.annotation.Nullable;
@@ -55,7 +51,7 @@ public class Backend {
* (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use.
*/
public String getBackendDescriptor() {
- return engine.getProperName();
+ return engine == null ? "" : engine.getProperName();
}
public FlwEngine getEngine() {
diff --git a/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java b/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java
index f003208fe..51e60eebe 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java
@@ -4,7 +4,11 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.util.Optional;
+import java.util.function.BooleanSupplier;
+
+import com.jozufozu.flywheel.util.Lazy;
import net.minecraft.client.Minecraft;
@@ -15,6 +19,23 @@ public class OptifineHandler {
private static Package optifine;
private static OptifineHandler handler;
+ private static final Lazy isShadowPass = Lazy.of(() -> {
+ try {
+ Class> ofShaders = Class.forName("net.optifine.shaders.Shaders");
+ Field field = ofShaders.getDeclaredField("isShadowPass");
+ field.setAccessible(true);
+ return () -> {
+ try {
+ return field.getBoolean(null);
+ } catch (IllegalAccessException ignored) {
+ return false;
+ }
+ };
+ } catch (Exception ignored) {
+ return () -> false;
+ }
+ });
+
public final boolean usingShaders;
public OptifineHandler(boolean usingShaders) {
@@ -40,6 +61,10 @@ public class OptifineHandler {
.orElse(false);
}
+ public static boolean isShadowPass() {
+ return isShadowPass.get().getAsBoolean();
+ }
+
public static void init() {
optifine = Package.getPackage(OPTIFINE_ROOT_PACKAGE);
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 1f4c7200c..8274a2e06 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java
@@ -90,12 +90,12 @@ public class InstanceWorld {
*
*/
public void beginFrame(BeginFrameEvent event) {
- engine.beginFrame(event.getInfo());
+ engine.beginFrame(event.getCamera());
taskEngine.syncPoint();
- blockEntityInstanceManager.beginFrame(taskEngine, event.getInfo());
- entityInstanceManager.beginFrame(taskEngine, event.getInfo());
+ blockEntityInstanceManager.beginFrame(taskEngine, event.getCamera());
+ entityInstanceManager.beginFrame(taskEngine, event.getCamera());
}
/**
diff --git a/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java b/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java
new file mode 100644
index 000000000..0d47d3c66
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java
@@ -0,0 +1,16 @@
+package com.jozufozu.flywheel.core;
+
+import net.minecraft.client.Camera;
+
+public class LastActiveCamera {
+
+ private static Camera camera;
+
+ public static void _setActiveCamera(Camera camera) {
+ LastActiveCamera.camera = camera;
+ }
+
+ public static Camera getActiveCamera() {
+ return camera;
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java b/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java
index 2db6271ee..db4d6fd1f 100644
--- a/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java
+++ b/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java
@@ -8,28 +8,28 @@ import net.minecraftforge.eventbus.api.Event;
public class BeginFrameEvent extends Event {
private final ClientLevel world;
- private final Camera info;
- private final Frustum clippingHelper;
+ private final Camera camera;
+ private final Frustum frustum;
- public BeginFrameEvent(ClientLevel world, Camera info, Frustum clippingHelper) {
+ public BeginFrameEvent(ClientLevel world, Camera camera, Frustum frustum) {
this.world = world;
- this.info = info;
- this.clippingHelper = clippingHelper;
+ this.camera = camera;
+ this.frustum = frustum;
}
public ClientLevel getWorld() {
return world;
}
- public Camera getInfo() {
- return info;
+ public Camera getCamera() {
+ return camera;
}
- public Frustum getClippingHelper() {
- return clippingHelper;
+ public Frustum getFrustum() {
+ return frustum;
}
public Vec3 getCameraPos() {
- return info.getPosition();
+ return camera.getPosition();
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java
new file mode 100644
index 000000000..52e6043ef
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java
@@ -0,0 +1,21 @@
+package com.jozufozu.flywheel.mixin;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import com.jozufozu.flywheel.core.LastActiveCamera;
+
+import net.minecraft.client.Camera;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.level.BlockGetter;
+
+@Mixin(Camera.class)
+public class CameraMixin {
+
+ @Inject(method = "setup", at = @At("TAIL"))
+ private void setup(BlockGetter level, Entity entity, boolean is3rdPerson, boolean isMirrored, float pt, CallbackInfo ci) {
+ LastActiveCamera._setActiveCamera((Camera)(Object) this);
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java
new file mode 100644
index 000000000..c0edf6bf0
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java
@@ -0,0 +1,25 @@
+package com.jozufozu.flywheel.mixin;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import com.jozufozu.flywheel.backend.OptifineHandler;
+import com.jozufozu.flywheel.core.LastActiveCamera;
+import com.jozufozu.flywheel.event.BeginFrameEvent;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.culling.Frustum;
+import net.minecraftforge.common.MinecraftForge;
+
+@Mixin(Frustum.class)
+public class FrustumMixin {
+
+ @Inject(method = "prepare", at = @At("TAIL"))
+ private void onPrepare(double x, double y, double z, CallbackInfo ci) {
+ if (OptifineHandler.isShadowPass()) {
+ MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(Minecraft.getInstance().level, LastActiveCamera.getActiveCamera(), (Frustum) (Object) this));
+ }
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java
similarity index 95%
rename from src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java
rename to src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java
index a60ffd45d..3dbe19701 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java
@@ -33,7 +33,7 @@ import net.minecraftforge.common.MinecraftForge;
@OnlyIn(Dist.CLIENT)
@Mixin(LevelRenderer.class)
-public class RenderHooksMixin {
+public class LevelRendererMixin {
@Shadow
private ClientLevel level;
@@ -52,7 +52,7 @@ public class RenderHooksMixin {
* layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects.
* This should probably be a forge event.
*/
- @Inject(at = @At("TAIL"), method = "renderChunkLayer")
+ @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ShaderInstance;clear()V"), method = "renderChunkLayer")
private void renderLayer(RenderType type, PoseStack stack, double camX, double camY, double camZ, Matrix4f p_172999_, CallbackInfo ci) {
RenderBuffers renderBuffers = this.renderBuffers;
diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json
index bcc9860ab..01959c480 100644
--- a/src/main/resources/flywheel.mixins.json
+++ b/src/main/resources/flywheel.mixins.json
@@ -1,34 +1,36 @@
{
- "required": true,
- "minVersion": "0.8",
- "package": "com.jozufozu.flywheel.mixin",
- "compatibilityLevel": "JAVA_17",
- "refmap": "flywheel.refmap.json",
- "client": [
- "BlockEntityTypeMixin",
- "BufferBuilderMixin",
- "BufferUploaderAccessor",
- "CancelEntityRenderMixin",
- "ChunkRebuildHooksMixin",
- "EntityTypeMixin",
- "FixFabulousDepthMixin",
- "InstanceAddMixin",
- "InstanceRemoveMixin",
- "LevelRendererAccessor",
- "PausedPartialTickAccessor",
- "RenderHooksMixin",
- "RenderTexturesMixin",
- "ShaderCloseMixin",
- "ShaderInstanceAccessor",
- "atlas.AtlasDataMixin",
- "atlas.SheetDataAccessor",
- "light.LightUpdateMixin",
- "light.NetworkLightUpdateMixin",
- "matrix.Matrix3fMixin",
- "matrix.Matrix4fMixin",
- "matrix.PoseStackMixin"
- ],
- "injectors": {
- "defaultRequire": 1
- }
+ "required": true,
+ "minVersion": "0.8",
+ "package": "com.jozufozu.flywheel.mixin",
+ "compatibilityLevel": "JAVA_17",
+ "refmap": "flywheel.refmap.json",
+ "client": [
+ "BlockEntityTypeMixin",
+ "BufferBuilderMixin",
+ "BufferUploaderAccessor",
+ "CameraMixin",
+ "CancelEntityRenderMixin",
+ "ChunkRebuildHooksMixin",
+ "EntityTypeMixin",
+ "FixFabulousDepthMixin",
+ "FrustumMixin",
+ "InstanceAddMixin",
+ "InstanceRemoveMixin",
+ "LevelRendererAccessor",
+ "LevelRendererMixin",
+ "PausedPartialTickAccessor",
+ "RenderTexturesMixin",
+ "ShaderCloseMixin",
+ "ShaderInstanceAccessor",
+ "atlas.AtlasDataMixin",
+ "atlas.SheetDataAccessor",
+ "light.LightUpdateMixin",
+ "light.NetworkLightUpdateMixin",
+ "matrix.Matrix3fMixin",
+ "matrix.Matrix4fMixin",
+ "matrix.PoseStackMixin"
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
}
From e4182a7f1eab9cd049962f3c81675f9144652f28 Mon Sep 17 00:00:00 2001
From: Jozufozu
Date: Thu, 6 Jan 2022 15:25:00 -0800
Subject: [PATCH 6/7] RenderLayers directly store DrawBuffers
- Inspired by pepper's BlockEntityTypeExtensions
- Document the batching engine internals.
---
.../jozufozu/flywheel/backend/Backend.java | 6 +-
.../instancing/BatchDrawingTracker.java | 83 +++++++++++++++++++
.../backend/instancing/DrawBuffer.java | 77 +++++++++++++++++
.../instancing/RenderTypeExtension.java | 25 ++++++
.../backend/instancing/SuperBufferSource.java | 79 ------------------
.../batching/BatchedMaterialGroup.java | 9 +-
.../instancing/batching/BatchingEngine.java | 12 ++-
.../backend/model/BufferBuilderExtension.java | 27 ++++++
.../backend/model/BufferBuilderHack.java | 16 ----
.../backend/model/DirectVertexConsumer.java | 2 +-
.../flywheel/core/LastActiveCamera.java | 5 ++
.../flywheel/mixin/BufferBuilderMixin.java | 6 +-
.../flywheel/mixin/RenderTypeMixin.java | 24 ++++++
src/main/resources/flywheel.mixins.json | 67 +++++++--------
14 files changed, 294 insertions(+), 144 deletions(-)
create mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/BatchDrawingTracker.java
create mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java
create mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/RenderTypeExtension.java
delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/SuperBufferSource.java
create mode 100644 src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderExtension.java
delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java
create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java
diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java
index 2285f5684..b365f2458 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java
@@ -1,6 +1,10 @@
package com.jozufozu.flywheel.backend;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import javax.annotation.Nullable;
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/BatchDrawingTracker.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/BatchDrawingTracker.java
new file mode 100644
index 000000000..ee1bee295
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/BatchDrawingTracker.java
@@ -0,0 +1,83 @@
+package com.jozufozu.flywheel.backend.instancing;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.jozufozu.flywheel.backend.model.BufferBuilderExtension;
+import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
+import com.mojang.blaze3d.vertex.BufferBuilder;
+
+import net.minecraft.client.renderer.RenderType;
+
+public class BatchDrawingTracker {
+
+ protected final Set activeTypes = new HashSet<>();
+ private final BufferBuilder scratch;
+
+ public BatchDrawingTracker() {
+ scratch = new BufferBuilder(8);
+
+ ((BufferBuilderExtension) scratch).flywheel$freeBuffer();
+ }
+
+ /**
+ * Get a direct vertex consumer for drawing the given number of vertices to the given RenderType.
+ * @param renderType The RenderType to draw to.
+ * @param vertexCount The number of vertices that will be drawn.
+ * @return A direct vertex consumer.
+ */
+ public DirectVertexConsumer getDirectConsumer(RenderType renderType, int vertexCount) {
+ activeTypes.add(renderType);
+ return RenderTypeExtension.getDrawBuffer(renderType)
+ .begin(vertexCount);
+ }
+
+ /**
+ * Draws all active DrawBuffers and reset them.
+ */
+ public void endBatch() {
+ // TODO: when/if this causes trouble with shaders, try to inject our BufferBuilders
+ // into the RenderBuffers from context.
+
+ for (RenderType renderType : activeTypes) {
+ _draw(renderType);
+ }
+
+ activeTypes.clear();
+ }
+
+ /**
+ * Draw and reset the DrawBuffer for the given RenderType.
+ * @param renderType The RenderType to draw.
+ */
+ public void endBatch(RenderType renderType) {
+ _draw(renderType);
+
+ activeTypes.remove(renderType);
+ }
+
+ /**
+ * Resets all DrawBuffers to 0 vertices.
+ */
+ public void clear() {
+ for (RenderType type : activeTypes) {
+ RenderTypeExtension.getDrawBuffer(type)
+ .reset();
+ }
+ activeTypes.clear();
+ }
+
+ private void _draw(RenderType renderType) {
+ DrawBuffer drawBuffer = RenderTypeExtension.getDrawBuffer(renderType);
+
+ BufferBuilderExtension scratch = (BufferBuilderExtension) this.scratch;
+ if (drawBuffer.hasVertices()) {
+ drawBuffer.inject(scratch);
+
+ renderType.end(this.scratch, 0, 0, 0);
+
+ drawBuffer.reset();
+ }
+ }
+
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java
new file mode 100644
index 000000000..4166c1e59
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java
@@ -0,0 +1,77 @@
+package com.jozufozu.flywheel.backend.instancing;
+
+import java.nio.ByteBuffer;
+
+import com.jozufozu.flywheel.backend.model.BufferBuilderExtension;
+import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
+import com.mojang.blaze3d.platform.MemoryTracker;
+import com.mojang.blaze3d.vertex.VertexFormat;
+
+import net.minecraft.client.renderer.RenderType;
+
+/**
+ * A byte buffer that can be used to draw vertices through a {@link DirectVertexConsumer}.
+ *
+ * The number of vertices needs to be known ahead of time.
+ */
+public class DrawBuffer {
+
+ private final RenderType parent;
+ private ByteBuffer backingBuffer;
+ private int expectedVertices;
+
+ public DrawBuffer(RenderType parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * Creates a direct vertex consumer that can be used to write vertices into this buffer.
+ * @param vertexCount The number of vertices to reserve memory for.
+ * @return A direct vertex consumer.
+ * @throws IllegalStateException If the buffer is already in use.
+ */
+ public DirectVertexConsumer begin(int vertexCount) {
+ if (expectedVertices != 0) {
+ throw new IllegalStateException("Already drawing");
+ }
+
+ this.expectedVertices = vertexCount;
+
+ VertexFormat format = parent.format();
+
+ int byteSize = format.getVertexSize() * vertexCount;
+
+ if (backingBuffer == null) {
+ backingBuffer = MemoryTracker.create(byteSize);
+ }
+ if (byteSize > backingBuffer.capacity()) {
+ backingBuffer = MemoryTracker.resize(backingBuffer, byteSize);
+ }
+
+ return new DirectVertexConsumer(backingBuffer, format, vertexCount);
+ }
+
+ /**
+ * Injects the backing buffer into the given builder and prepares it for rendering.
+ * @param bufferBuilder The buffer builder to inject into.
+ */
+ public void inject(BufferBuilderExtension bufferBuilder) {
+ bufferBuilder.flywheel$injectForRender(backingBuffer, parent.format(), expectedVertices);
+ }
+
+ /**
+ * @return {@code true} if the buffer has any vertices.
+ */
+ public boolean hasVertices() {
+ return expectedVertices > 0;
+ }
+
+ /**
+ * Reset the draw buffer to have no vertices.
+ *
+ * Does not clear the backing buffer.
+ */
+ public void reset() {
+ this.expectedVertices = 0;
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderTypeExtension.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderTypeExtension.java
new file mode 100644
index 000000000..d95ea68c1
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderTypeExtension.java
@@ -0,0 +1,25 @@
+package com.jozufozu.flywheel.backend.instancing;
+
+import net.minecraft.client.renderer.RenderType;
+
+/**
+ * Duck interface to make RenderType store a DrawBuffer.
+ *
+ * @see RenderType
+ */
+public interface RenderTypeExtension {
+
+ /**
+ * @return The DrawBuffer associated with this RenderType.
+ */
+ DrawBuffer flywheel$getDrawBuffer();
+
+ /**
+ * Helper function to cast a RenderType to a RenderTypeExtension and get its DrawBuffer.
+ * @param type The RenderType to get the DrawBuffer from.
+ * @return The DrawBuffer associated with the given RenderType.
+ */
+ static DrawBuffer getDrawBuffer(RenderType type) {
+ return ((RenderTypeExtension) type).flywheel$getDrawBuffer();
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/SuperBufferSource.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/SuperBufferSource.java
deleted file mode 100644
index 20984c03b..000000000
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/SuperBufferSource.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.jozufozu.flywheel.backend.instancing;
-
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.Map;
-
-import com.jozufozu.flywheel.backend.model.BufferBuilderHack;
-import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
-import com.mojang.blaze3d.platform.MemoryTracker;
-import com.mojang.blaze3d.vertex.BufferBuilder;
-import com.mojang.blaze3d.vertex.VertexFormat;
-
-import net.minecraft.client.renderer.RenderType;
-
-public class SuperBufferSource {
-
- protected final Map buffers = new HashMap<>();
- private final BufferBuilder scratch;
-
- public SuperBufferSource() {
- scratch = new BufferBuilder(8);
-
- ((BufferBuilderHack) scratch).flywheel$freeBuffer();
- }
-
- public DirectVertexConsumer getBuffer(RenderType renderType, int vertexCount) {
- return buffers.computeIfAbsent(renderType, DrawBuffer::new)
- .begin(vertexCount);
- }
-
- public void endBatch() {
- // TODO: when/if this causes trouble with shaders, try to inject our BufferBuilders
- // into the RenderBuffers from context.
-
- BufferBuilderHack hack = (BufferBuilderHack) scratch;
-
- for (Map.Entry entry : buffers.entrySet()) {
- DrawBuffer builder = entry.getValue();
-
- if (builder.expectedVertices > 0) {
- RenderType type = entry.getKey();
-
- hack.flywheel$hackBegin(builder.backingBuffer, type.format(), builder.expectedVertices);
-
- type.end(scratch, 0, 0, 0);
-
- builder.expectedVertices = 0;
- }
- }
- }
-
- private static class DrawBuffer {
-
- private final RenderType type;
- private ByteBuffer backingBuffer;
- private int expectedVertices;
-
- public DrawBuffer(RenderType type) {
- this.type = type;
- }
-
- public DirectVertexConsumer begin(int vertexCount) {
- this.expectedVertices = vertexCount;
-
- VertexFormat format = type.format();
-
- int byteSize = format.getVertexSize() * vertexCount;
-
- if (backingBuffer == null) {
- backingBuffer = MemoryTracker.create(byteSize);
- } if (byteSize > backingBuffer.capacity()) {
- backingBuffer = MemoryTracker.resize(backingBuffer, byteSize);
- }
-
- return new DirectVertexConsumer(backingBuffer, format, vertexCount);
- }
-
- }
-}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java
index 890dce0e1..032a03457 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java
@@ -7,7 +7,8 @@ import com.jozufozu.flywheel.api.InstanceData;
import com.jozufozu.flywheel.api.MaterialGroup;
import com.jozufozu.flywheel.api.struct.Batched;
import com.jozufozu.flywheel.api.struct.StructType;
-import com.jozufozu.flywheel.backend.instancing.SuperBufferSource;
+import com.jozufozu.flywheel.backend.OptifineHandler;
+import com.jozufozu.flywheel.backend.instancing.BatchDrawingTracker;
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
import com.mojang.blaze3d.vertex.PoseStack;
@@ -34,7 +35,7 @@ public class BatchedMaterialGroup implements MaterialGroup {
}
}
- public void render(PoseStack stack, SuperBufferSource source, TaskEngine pool) {
+ public void render(PoseStack stack, BatchDrawingTracker source, TaskEngine pool) {
int vertexCount = 0;
for (BatchedMaterial> material : materials.values()) {
@@ -44,14 +45,14 @@ public class BatchedMaterialGroup implements MaterialGroup {
}
}
- DirectVertexConsumer consumer = source.getBuffer(state, vertexCount);
+ DirectVertexConsumer consumer = source.getDirectConsumer(state, vertexCount);
// avoids rendering garbage, but doesn't fix the issue of some instances not being buffered
consumer.memSetZero();
for (BatchedMaterial> material : materials.values()) {
for (CPUInstancer> instancer : material.models.values()) {
- instancer.sbb.context.outputColorDiffuse = !consumer.hasOverlay();
+ instancer.sbb.context.outputColorDiffuse = !consumer.hasOverlay() && !OptifineHandler.usingShaders();
instancer.submitTasks(stack, pool, consumer);
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java
index ed1dd12cd..b08044d7b 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java
@@ -6,8 +6,8 @@ import java.util.Map;
import com.jozufozu.flywheel.api.MaterialGroup;
import com.jozufozu.flywheel.backend.RenderLayer;
+import com.jozufozu.flywheel.backend.instancing.BatchDrawingTracker;
import com.jozufozu.flywheel.backend.instancing.Engine;
-import com.jozufozu.flywheel.backend.instancing.SuperBufferSource;
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
import com.jozufozu.flywheel.event.RenderLayerEvent;
import com.mojang.blaze3d.platform.Lighting;
@@ -21,7 +21,7 @@ import net.minecraft.core.Vec3i;
public class BatchingEngine implements Engine {
private final Map> layers;
- private final SuperBufferSource superBufferSource = new SuperBufferSource();
+ private final BatchDrawingTracker batchTracker = new BatchDrawingTracker();
public BatchingEngine() {
this.layers = new EnumMap<>(RenderLayer.class);
@@ -43,14 +43,11 @@ public class BatchingEngine implements Engine {
@Override
public void render(TaskEngine taskEngine, RenderLayerEvent event) {
-
Map groups = layers.get(event.getLayer());
for (BatchedMaterialGroup group : groups.values()) {
- group.render(event.stack, superBufferSource, taskEngine);
+ group.render(event.stack, batchTracker, taskEngine);
}
- taskEngine.syncPoint();
-
// FIXME: this probably breaks some vanilla stuff but it works much better for flywheel
Matrix4f mat = new Matrix4f();
mat.setIdentity();
@@ -60,7 +57,8 @@ public class BatchingEngine implements Engine {
Lighting.setupLevel(mat);
}
- superBufferSource.endBatch();
+ taskEngine.syncPoint();
+ batchTracker.endBatch();
}
@Override
diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderExtension.java b/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderExtension.java
new file mode 100644
index 000000000..87d840792
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderExtension.java
@@ -0,0 +1,27 @@
+package com.jozufozu.flywheel.backend.model;
+
+import java.nio.ByteBuffer;
+
+import com.mojang.blaze3d.vertex.BufferBuilder;
+import com.mojang.blaze3d.vertex.VertexFormat;
+
+/**
+ * Duck interface used on {@link BufferBuilder} to provide lower level access to the backing memory.
+ *
+ * @see com.jozufozu.flywheel.mixin.BufferBuilderMixin
+ */
+public interface BufferBuilderExtension {
+
+ /**
+ * Frees the internal ByteBuffer, if it exists.
+ */
+ void flywheel$freeBuffer();
+
+ /**
+ * Prepares the BufferBuilder for drawing the contents of the given buffer.
+ * @param buffer The buffer to draw.
+ * @param format The format of the buffer.
+ * @param vertexCount The number of vertices in the buffer.
+ */
+ void flywheel$injectForRender(ByteBuffer buffer, VertexFormat format, int vertexCount);
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java b/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java
deleted file mode 100644
index 2fc98cf21..000000000
--- a/src/main/java/com/jozufozu/flywheel/backend/model/BufferBuilderHack.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.jozufozu.flywheel.backend.model;
-
-import java.nio.ByteBuffer;
-
-import com.mojang.blaze3d.vertex.BufferBuilder;
-import com.mojang.blaze3d.vertex.VertexFormat;
-
-/**
- * Duck interface used on {@link BufferBuilder} to provide lower level access to the backing memory.
- */
-public interface BufferBuilderHack {
-
- void flywheel$freeBuffer();
-
- void flywheel$hackBegin(ByteBuffer buffer, VertexFormat format, int vertexCount);
-}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/DirectVertexConsumer.java b/src/main/java/com/jozufozu/flywheel/backend/model/DirectVertexConsumer.java
index 8446fbfcc..3461e65e1 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/model/DirectVertexConsumer.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/model/DirectVertexConsumer.java
@@ -13,7 +13,7 @@ import com.mojang.blaze3d.vertex.VertexFormatElement;
/**
* An unsafe vertex consumer allowing for unchecked writes into a ByteBuffer.
*
- * @see BufferBuilderHack
+ * @see BufferBuilderExtension
*/
public class DirectVertexConsumer implements VertexConsumer {
public final VertexFormat format;
diff --git a/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java b/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java
index 0d47d3c66..60e36f463 100644
--- a/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java
+++ b/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java
@@ -2,6 +2,11 @@ package com.jozufozu.flywheel.core;
import net.minecraft.client.Camera;
+/**
+ * A class tracking which object last had {@link Camera#setup} called on it.
+ *
+ * @see com.jozufozu.flywheel.mixin.CameraMixin
+ */
public class LastActiveCamera {
private static Camera camera;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
index 5a67e78a2..6b13b9a92 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
@@ -9,13 +9,13 @@ import org.lwjgl.system.MemoryUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
-import com.jozufozu.flywheel.backend.model.BufferBuilderHack;
+import com.jozufozu.flywheel.backend.model.BufferBuilderExtension;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormatElement;
@Mixin(BufferBuilder.class)
-public abstract class BufferBuilderMixin implements BufferBuilderHack {
+public abstract class BufferBuilderMixin implements BufferBuilderExtension {
@Shadow
private ByteBuffer buffer;
@@ -50,7 +50,7 @@ public abstract class BufferBuilderMixin implements BufferBuilderHack {
}
@Override
- public void flywheel$hackBegin(@Nonnull ByteBuffer buffer, @Nonnull VertexFormat format, int vertexCount) {
+ public void flywheel$injectForRender(@Nonnull ByteBuffer buffer, @Nonnull VertexFormat format, int vertexCount) {
this.building = true;
this.mode = VertexFormat.Mode.QUADS;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java
new file mode 100644
index 000000000..c3a3d7b5d
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java
@@ -0,0 +1,24 @@
+package com.jozufozu.flywheel.mixin;
+
+import javax.annotation.Nonnull;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+import com.jozufozu.flywheel.backend.instancing.DrawBuffer;
+import com.jozufozu.flywheel.backend.instancing.RenderTypeExtension;
+
+import net.minecraft.client.renderer.RenderType;
+
+@Mixin(RenderType.class)
+public class RenderTypeMixin implements RenderTypeExtension {
+
+ @Unique
+ private final DrawBuffer flywheel$drawBuffer = new DrawBuffer((RenderType) (Object) this);
+
+ @Override
+ @Nonnull
+ public DrawBuffer flywheel$getDrawBuffer() {
+ return flywheel$drawBuffer;
+ }
+}
diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json
index 01959c480..54eb1247d 100644
--- a/src/main/resources/flywheel.mixins.json
+++ b/src/main/resources/flywheel.mixins.json
@@ -1,36 +1,37 @@
{
- "required": true,
- "minVersion": "0.8",
- "package": "com.jozufozu.flywheel.mixin",
- "compatibilityLevel": "JAVA_17",
- "refmap": "flywheel.refmap.json",
- "client": [
- "BlockEntityTypeMixin",
- "BufferBuilderMixin",
- "BufferUploaderAccessor",
- "CameraMixin",
- "CancelEntityRenderMixin",
- "ChunkRebuildHooksMixin",
- "EntityTypeMixin",
- "FixFabulousDepthMixin",
- "FrustumMixin",
- "InstanceAddMixin",
- "InstanceRemoveMixin",
- "LevelRendererAccessor",
- "LevelRendererMixin",
- "PausedPartialTickAccessor",
- "RenderTexturesMixin",
- "ShaderCloseMixin",
- "ShaderInstanceAccessor",
- "atlas.AtlasDataMixin",
- "atlas.SheetDataAccessor",
- "light.LightUpdateMixin",
- "light.NetworkLightUpdateMixin",
- "matrix.Matrix3fMixin",
- "matrix.Matrix4fMixin",
- "matrix.PoseStackMixin"
- ],
- "injectors": {
- "defaultRequire": 1
+ "required": true,
+ "minVersion": "0.8",
+ "package": "com.jozufozu.flywheel.mixin",
+ "compatibilityLevel": "JAVA_17",
+ "refmap": "flywheel.refmap.json",
+ "client": [
+ "BlockEntityTypeMixin",
+ "BufferBuilderMixin",
+ "BufferUploaderAccessor",
+ "CameraMixin",
+ "CancelEntityRenderMixin",
+ "ChunkRebuildHooksMixin",
+ "EntityTypeMixin",
+ "FixFabulousDepthMixin",
+ "FrustumMixin",
+ "InstanceAddMixin",
+ "InstanceRemoveMixin",
+ "LevelRendererAccessor",
+ "LevelRendererMixin",
+ "PausedPartialTickAccessor",
+ "RenderTexturesMixin",
+ "RenderTypeMixin",
+ "ShaderCloseMixin",
+ "ShaderInstanceAccessor",
+ "atlas.AtlasDataMixin",
+ "atlas.SheetDataAccessor",
+ "light.LightUpdateMixin",
+ "light.NetworkLightUpdateMixin",
+ "matrix.Matrix3fMixin",
+ "matrix.Matrix4fMixin",
+ "matrix.PoseStackMixin"
+ ],
+ "injectors": {
+ "defaultRequire": 1
}
}
From 01fb788fa3f6a1ada1f35073881f2bc7fc0bee5a Mon Sep 17 00:00:00 2001
From: Jozufozu
Date: Fri, 7 Jan 2022 11:50:01 -0800
Subject: [PATCH 7/7] Reduce merge conflicts with shader-sanity
---
.gitignore | 1 +
.../com/jozufozu/flywheel/backend/source/FileResolution.java | 2 +-
.../java/com/jozufozu/flywheel/backend/source/Resolver.java | 2 +-
.../com/jozufozu/flywheel/backend/source/ShaderSources.java | 2 +-
.../backend/source/{SourceHolder.java => SourceFinder.java} | 2 +-
5 files changed, 5 insertions(+), 4 deletions(-)
rename src/main/java/com/jozufozu/flywheel/backend/source/{SourceHolder.java => SourceFinder.java} (87%)
diff --git a/.gitignore b/.gitignore
index 0123b6707..fe6afb8ac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ run/
.gradle/
build/
gradle-app.setting
+out/
## IntelliJ IDEA
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/FileResolution.java b/src/main/java/com/jozufozu/flywheel/backend/source/FileResolution.java
index 5d2d221ef..648d9def7 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/FileResolution.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/FileResolution.java
@@ -62,7 +62,7 @@ public class FileResolution {
* Called after all files are loaded. If we can't find the file here, it doesn't exist.
*
*/
- void resolve(SourceHolder sources) {
+ void resolve(SourceFinder sources) {
try {
file = sources.findSource(fileLoc);
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/Resolver.java b/src/main/java/com/jozufozu/flywheel/backend/source/Resolver.java
index 4377d8496..202b7a94d 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/Resolver.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/Resolver.java
@@ -28,7 +28,7 @@ public class Resolver {
/**
* Try and resolve all referenced source files, printing errors if any aren't found.
*/
- public void resolve(SourceHolder sources) {
+ public void resolve(SourceFinder sources) {
for (FileResolution resolution : resolutions.values()) {
resolution.resolve(sources);
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/ShaderSources.java b/src/main/java/com/jozufozu/flywheel/backend/source/ShaderSources.java
index be9ab9dfb..03a2b8401 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/ShaderSources.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/ShaderSources.java
@@ -17,7 +17,7 @@ import net.minecraft.server.packs.resources.ResourceManager;
/**
* The main object for loading and parsing source files.
*/
-public class ShaderSources implements SourceHolder {
+public class ShaderSources implements SourceFinder {
public static final String SHADER_DIR = "flywheel/shaders/";
public static final ArrayList EXTENSIONS = Lists.newArrayList(".vert", ".vsh", ".frag", ".fsh", ".glsl");
diff --git a/src/main/java/com/jozufozu/flywheel/backend/source/SourceHolder.java b/src/main/java/com/jozufozu/flywheel/backend/source/SourceFinder.java
similarity index 87%
rename from src/main/java/com/jozufozu/flywheel/backend/source/SourceHolder.java
rename to src/main/java/com/jozufozu/flywheel/backend/source/SourceFinder.java
index 9d25cbaea..7dfa41ac3 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/source/SourceHolder.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/source/SourceFinder.java
@@ -6,7 +6,7 @@ import net.minecraft.resources.ResourceLocation;
* A minimal source file lookup function.
*/
@FunctionalInterface
-public interface SourceHolder {
+public interface SourceFinder {
SourceFile findSource(ResourceLocation name);
}