From 94fcdc06b41df09551e366bfa3f3483c2a4c5a91 Mon Sep 17 00:00:00 2001 From: Rybot666 Date: Mon, 29 Apr 2024 23:34:27 +0100 Subject: [PATCH 1/4] Remove sign and name tag buffering This commit also cleans up some unused code as a result of removing these features. If you still want either of these things, check out ImmediatelyFast. --- .../dev/tr7zw/exordium/ExordiumModBase.java | 29 +-- .../dev/tr7zw/exordium/NametagSettings.java | 12 -- .../java/dev/tr7zw/exordium/SignSettings.java | 17 -- .../dev/tr7zw/exordium/config/Config.java | 1 - .../exordium/config/ExordiumConfigScreen.java | 7 - .../exordium/mixin/EntityRendererMixin.java | 62 ------ .../exordium/mixin/GameRendererMixin.java | 6 - .../exordium/mixin/SignBlockEntityMixin.java | 56 ------ .../exordium/mixin/SignRendererMixin.java | 57 ------ ...dSateHolder.java => BlendStateHolder.java} | 2 +- .../exordium/util/BufferedComponent.java | 15 +- .../util/DelayedRenderCallManager.java | 54 +----- .../exordium/util/NametagScreenBuffer.java | 108 ----------- .../exordium/util/SignBufferRenderer.java | 180 ------------------ src/main/resources/exordium.mixins.json | 3 - 15 files changed, 25 insertions(+), 584 deletions(-) delete mode 100644 src/main/java/dev/tr7zw/exordium/NametagSettings.java delete mode 100644 src/main/java/dev/tr7zw/exordium/SignSettings.java delete mode 100644 src/main/java/dev/tr7zw/exordium/mixin/EntityRendererMixin.java delete mode 100644 src/main/java/dev/tr7zw/exordium/mixin/SignBlockEntityMixin.java delete mode 100644 src/main/java/dev/tr7zw/exordium/mixin/SignRendererMixin.java rename src/main/java/dev/tr7zw/exordium/util/{BlendSateHolder.java => BlendStateHolder.java} (95%) delete mode 100644 src/main/java/dev/tr7zw/exordium/util/NametagScreenBuffer.java delete mode 100644 src/main/java/dev/tr7zw/exordium/util/SignBufferRenderer.java diff --git a/src/main/java/dev/tr7zw/exordium/ExordiumModBase.java b/src/main/java/dev/tr7zw/exordium/ExordiumModBase.java index 3f08333..dee4a05 100644 --- a/src/main/java/dev/tr7zw/exordium/ExordiumModBase.java +++ b/src/main/java/dev/tr7zw/exordium/ExordiumModBase.java @@ -1,26 +1,23 @@ package dev.tr7zw.exordium; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; - -import dev.tr7zw.exordium.util.DelayedRenderCallManager; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; - import dev.tr7zw.exordium.config.Config; import dev.tr7zw.exordium.config.ConfigUpgrader; import dev.tr7zw.exordium.config.ExordiumConfigScreen; import dev.tr7zw.exordium.util.CustomShaderManager; -import dev.tr7zw.exordium.util.NametagScreenBuffer; +import dev.tr7zw.exordium.util.DelayedRenderCallManager; import net.minecraft.client.gui.screens.Screen; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; public abstract class ExordiumModBase { @@ -31,10 +28,7 @@ public abstract class ExordiumModBase { public Config config; private final File settingsFile = new File("config", "exordium.json"); private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - private NametagScreenBuffer nametagScreenBuffer; private RenderTarget temporaryScreenOverwrite = null; - public static SignSettings signSettings = new SignSettings(); - public static NametagSettings nametagSettings = new NametagSettings(); private final DelayedRenderCallManager delayedRenderCallManager = new DelayedRenderCallManager(); private final CustomShaderManager customShaderManager = new CustomShaderManager(); private final BufferManager bufferManager = new BufferManager(); @@ -72,13 +66,6 @@ public void writeConfig() { } } - public NametagScreenBuffer getNameTagScreenBuffer() { - if (nametagScreenBuffer == null) { - nametagScreenBuffer = new NametagScreenBuffer(1000 / config.targetFPSNameTags); - } - return nametagScreenBuffer; - } - public DelayedRenderCallManager getDelayedRenderCallManager() { return delayedRenderCallManager; } diff --git a/src/main/java/dev/tr7zw/exordium/NametagSettings.java b/src/main/java/dev/tr7zw/exordium/NametagSettings.java deleted file mode 100644 index d0796fe..0000000 --- a/src/main/java/dev/tr7zw/exordium/NametagSettings.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.tr7zw.exordium; - -public class NametagSettings { - - public final float bufferWidth = 4.5f; - public final float bufferHeight = 24; - public final float renderHeight = 16; - public final float scaleSize = 9; - - public final float heightscale = -0.12f; - -} diff --git a/src/main/java/dev/tr7zw/exordium/SignSettings.java b/src/main/java/dev/tr7zw/exordium/SignSettings.java deleted file mode 100644 index 27974db..0000000 --- a/src/main/java/dev/tr7zw/exordium/SignSettings.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.tr7zw.exordium; - -public class SignSettings { - - public final float bufferWidth = 366; - public final float bufferHeight = 366; - public final float renderWidth = 183; - public final float renderHeight = 183; - public final float scaleSize = 91; - - public final float offsetX = -63.1f; - public final float offsetY = -91.7f; - - public final float hangingOffsetZ = -0.3f; - public final float hangingOffsetY = 0f; - -} diff --git a/src/main/java/dev/tr7zw/exordium/config/Config.java b/src/main/java/dev/tr7zw/exordium/config/Config.java index ad81696..d23cfee 100644 --- a/src/main/java/dev/tr7zw/exordium/config/Config.java +++ b/src/main/java/dev/tr7zw/exordium/config/Config.java @@ -3,7 +3,6 @@ public class Config { public int configVersion = 2; - public boolean enableSignBuffering = true; public int targetFPSNameTags = 60; public boolean enableNametagScreenBuffering = false; public int pollRate = 60; diff --git a/src/main/java/dev/tr7zw/exordium/config/ExordiumConfigScreen.java b/src/main/java/dev/tr7zw/exordium/config/ExordiumConfigScreen.java index 4c700ef..ff79002 100644 --- a/src/main/java/dev/tr7zw/exordium/config/ExordiumConfigScreen.java +++ b/src/main/java/dev/tr7zw/exordium/config/ExordiumConfigScreen.java @@ -19,13 +19,6 @@ public void initialize() { Config config = ExordiumModBase.instance.config; List> options = new ArrayList<>(); - options.add(getOnOffOption("text.exordium.enableSignBuffering", () -> config.enableSignBuffering, - (b) -> config.enableSignBuffering = b)); - - options.add(getOnOffOption("text.exordium.enableNametagScreenBuffering", - () -> config.enableNametagScreenBuffering, (b) -> config.enableNametagScreenBuffering = b)); - options.add(getIntOption("text.exordium.targetFPSNameTags", 30, 80, () -> config.targetFPSNameTags, - (v) -> config.targetFPSNameTags = v)); options.add(getIntOption("text.exordium.pollRate", 20, 240, () -> config.pollRate, (v) -> config.pollRate = v)); addSettings(options, config.chatSettings, "chat", false); diff --git a/src/main/java/dev/tr7zw/exordium/mixin/EntityRendererMixin.java b/src/main/java/dev/tr7zw/exordium/mixin/EntityRendererMixin.java deleted file mode 100644 index 24f51dd..0000000 --- a/src/main/java/dev/tr7zw/exordium/mixin/EntityRendererMixin.java +++ /dev/null @@ -1,62 +0,0 @@ -package dev.tr7zw.exordium.mixin; - -import org.joml.Matrix4f; -import org.joml.Vector3f; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; - -import dev.tr7zw.exordium.ExordiumModBase; -import dev.tr7zw.exordium.util.NametagScreenBuffer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.entity.EntityRenderDispatcher; -import net.minecraft.client.renderer.entity.EntityRenderer; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.Entity; - -@Mixin(value = EntityRenderer.class) -public class EntityRendererMixin { - - @Shadow - protected EntityRenderDispatcher entityRenderDispatcher; - @Shadow - private Font font; - - @Inject(method = "renderNameTag", at = @At("HEAD"), cancellable = true) - protected void renderNameTag(Entity entity, Component component, PoseStack tmpPoseStack, - MultiBufferSource unusedBuffer, int i, float f2, CallbackInfo ci) { - NametagScreenBuffer buffer = null; - ExordiumModBase inst = ExordiumModBase.instance; - if (inst.config.enableNametagScreenBuffering) { - buffer = inst.getNameTagScreenBuffer(); - if (!entity.isDiscrete() && !buffer.acceptsData()) { - ci.cancel(); // the buffer is not ready, so the last frame will be used instead - return; - } - Matrix4f matrix4f = new Matrix4f(tmpPoseStack.last().pose()); - float f = entity.getBbHeight() + 0.5F; - matrix4f.translate(new Vector3f(0.0f, f, 0.0f)); - matrix4f.rotate(this.entityRenderDispatcher.cameraOrientation()); - matrix4f.scale(-0.025F, -0.025F, 0.025F); - ExordiumModBase.instance.getDelayedRenderCallManager().addNametagRenderCall(() -> { - // partial copy of the method to remove the "behind walls" part - MultiBufferSource.BufferSource bufferSource = MultiBufferSource - .immediate(Tesselator.getInstance().getBuilder()); - float h = (-font.width(component) / 2); - float g = (Minecraft.getInstance()).options.getBackgroundOpacity(0.25F); - int k = (int) (g * 255.0F) << 24; - font.drawInBatch(component, h, 0, -1, false, matrix4f, bufferSource, Font.DisplayMode.NORMAL, k, i); - bufferSource.endBatch(); - - }); - ci.cancel(); - } - } -} diff --git a/src/main/java/dev/tr7zw/exordium/mixin/GameRendererMixin.java b/src/main/java/dev/tr7zw/exordium/mixin/GameRendererMixin.java index 8b551d8..4da918f 100644 --- a/src/main/java/dev/tr7zw/exordium/mixin/GameRendererMixin.java +++ b/src/main/java/dev/tr7zw/exordium/mixin/GameRendererMixin.java @@ -20,14 +20,8 @@ @Mixin(value = GameRenderer.class, priority = 500) // needs to be lower to cancel Architectury for REI public abstract class GameRendererMixin { - @Inject(method = "render(FJZ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getWindow()Lcom/mojang/blaze3d/platform/Window;", ordinal = 0, shift = Shift.AFTER)) - public void postWorldRender(float tickDelta, long startTime, boolean tick, CallbackInfo ci) { - ExordiumModBase.instance.getDelayedRenderCallManager().execRenderCalls(); - } - @Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GameRenderer;resetProjectionMatrix(Lorg/joml/Matrix4f;)V")) public void renderLevel(GameRenderer gr, Matrix4f matrix4f, float f, long l) { - ExordiumModBase.instance.getDelayedRenderCallManager().setProjectionMatrix(matrix4f); resetProjectionMatrix(matrix4f); } diff --git a/src/main/java/dev/tr7zw/exordium/mixin/SignBlockEntityMixin.java b/src/main/java/dev/tr7zw/exordium/mixin/SignBlockEntityMixin.java deleted file mode 100644 index 0962577..0000000 --- a/src/main/java/dev/tr7zw/exordium/mixin/SignBlockEntityMixin.java +++ /dev/null @@ -1,56 +0,0 @@ -package dev.tr7zw.exordium.mixin; - -import org.spongepowered.asm.mixin.Mixin; - -import com.mojang.blaze3d.vertex.PoseStack; - -import dev.tr7zw.exordium.access.SignBufferHolder; -import dev.tr7zw.exordium.util.SignBufferRenderer; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.network.chat.Component; -import net.minecraft.world.level.block.entity.HangingSignBlockEntity; -import net.minecraft.world.level.block.entity.SignBlockEntity; -import net.minecraft.world.level.block.entity.SignText; - -@Mixin(SignBlockEntity.class) -public class SignBlockEntityMixin implements SignBufferHolder { - - private SignBufferRenderer cachedBufferRenderer = null; - private SignText front; - private SignText back; - private int currentLight = -1; - - @Override - public boolean renderBuffered(PoseStack poseStack, MultiBufferSource multiBufferSource, boolean renderFront, - int light) { - SignBlockEntity sign = (SignBlockEntity) (Object) this; - if ((renderFront && isSignEmpty(sign.getFrontText())) || (!renderFront && isSignEmpty(sign.getBackText()))) { - return true; // empty sign, nothing to do - } - if (cachedBufferRenderer == null || currentLight != light || (renderFront && (sign.getFrontText() != front)) - || (!renderFront && (sign.getBackText() != back))) { - if (cachedBufferRenderer == null) { - cachedBufferRenderer = new SignBufferRenderer(sign, light); - } - cachedBufferRenderer.refreshImage(sign, light, renderFront); - currentLight = light; - if (renderFront) { - front = sign.getFrontText(); - } else { - back = sign.getBackText(); - } - } - cachedBufferRenderer.render(poseStack, light, ((Object) this) instanceof HangingSignBlockEntity, renderFront); - return true; - } - - private boolean isSignEmpty(SignText text) { - for (int i = 0; i < 4; i++) { - Component line = text.getMessage(i, false); - if (!line.getString().isBlank()) - return false; - } - return true; - } - -} diff --git a/src/main/java/dev/tr7zw/exordium/mixin/SignRendererMixin.java b/src/main/java/dev/tr7zw/exordium/mixin/SignRendererMixin.java deleted file mode 100644 index eab02eb..0000000 --- a/src/main/java/dev/tr7zw/exordium/mixin/SignRendererMixin.java +++ /dev/null @@ -1,57 +0,0 @@ -package dev.tr7zw.exordium.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.mojang.blaze3d.vertex.PoseStack; - -import dev.tr7zw.exordium.ExordiumModBase; -import dev.tr7zw.exordium.access.SignBufferHolder; -import net.minecraft.client.model.Model; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.blockentity.SignRenderer; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.SignBlock; -import net.minecraft.world.level.block.entity.SignBlockEntity; -import net.minecraft.world.level.block.entity.SignText; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.WoodType; -import net.minecraft.world.phys.Vec3; - -@Mixin(SignRenderer.class) -public abstract class SignRendererMixin { - - private SignBlockEntity renderingSign; - - @Inject(method = "renderSignWithText", at = @At("HEAD")) - void renderSignWithText(SignBlockEntity signEntity, PoseStack poseStack, MultiBufferSource buffer, int packedLight, - int packedOverlay, BlockState state, SignBlock signBlock, WoodType woodType, Model model, - CallbackInfo info) { - this.renderingSign = signEntity; - } - - @Inject(method = "renderSignText", at = @At("HEAD"), cancellable = true) - public void render(BlockPos pos, SignText text, PoseStack poseStack, MultiBufferSource buffer, int packedLight, - int lineHeight, int maxWidth, boolean isFrontText, CallbackInfo info) { - if (!ExordiumModBase.instance.config.enableSignBuffering || renderingSign == null) { - return; - } - poseStack.pushPose(); - translateSignText(poseStack, isFrontText, getTextOffset()); - boolean cancel = ((SignBufferHolder) renderingSign).renderBuffered(poseStack, buffer, isFrontText, packedLight); - poseStack.popPose(); - if (cancel) { - info.cancel(); - } - } - - @Shadow - abstract Vec3 getTextOffset(); - - @Shadow - abstract void translateSignText(PoseStack poseStack, boolean isFrontText, Vec3 offset); - -} diff --git a/src/main/java/dev/tr7zw/exordium/util/BlendSateHolder.java b/src/main/java/dev/tr7zw/exordium/util/BlendStateHolder.java similarity index 95% rename from src/main/java/dev/tr7zw/exordium/util/BlendSateHolder.java rename to src/main/java/dev/tr7zw/exordium/util/BlendStateHolder.java index 24d57a1..13fb4f8 100644 --- a/src/main/java/dev/tr7zw/exordium/util/BlendSateHolder.java +++ b/src/main/java/dev/tr7zw/exordium/util/BlendStateHolder.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.platform.GlStateManager; -public class BlendSateHolder { +public class BlendStateHolder { private boolean blendStateFetched = false; private int srcRgb = 1; diff --git a/src/main/java/dev/tr7zw/exordium/util/BufferedComponent.java b/src/main/java/dev/tr7zw/exordium/util/BufferedComponent.java index 63b7473..9a3c995 100644 --- a/src/main/java/dev/tr7zw/exordium/util/BufferedComponent.java +++ b/src/main/java/dev/tr7zw/exordium/util/BufferedComponent.java @@ -25,7 +25,7 @@ public abstract class BufferedComponent { private int reloadCount = 0; private boolean isRendering = false; private boolean forceBlending = false; - private BlendSateHolder blendSateHolder = new BlendSateHolder(); + private BlendStateHolder blendStateHolder = new BlendStateHolder(); public static Model getModel() { return model; @@ -60,8 +60,9 @@ public boolean render() { if (!settings.get().enabled) { return false; } - if (!blendSateHolder.isBlendStateFetched()) { // the intended blendstate is not know. Skip the buffer logic, let - // it render normally, then grab the expected state + if (!blendStateHolder.isBlendStateFetched()) { // the intended blendstate is not know. Skip the buffer logic, + // let + // it render normally, then grab the expected state return false; } int screenWidth = minecraft.getWindow().getGuiScaledWidth(); @@ -82,7 +83,7 @@ public boolean render() { if (!updateFrame) { // renderTextureOverlay(guiTarget.getColorTextureId()); ExordiumModBase.instance.getDelayedRenderCallManager().addBufferedComponent(this); - blendSateHolder.apply(); + blendStateHolder.apply(); return true; } guiTarget.setClearColor(0, 0, 0, 0); @@ -104,9 +105,9 @@ protected boolean shouldForceRender() { } public void renderEnd() { - if (!blendSateHolder.isBlendStateFetched()) { + if (!blendStateHolder.isBlendStateFetched()) { // capture the expected blend state - blendSateHolder.fetch(); + blendStateHolder.fetch(); } if (!isRendering) { return; @@ -122,7 +123,7 @@ public void renderEnd() { } // renderTextureOverlay(guiTarget.getColorTextureId()); ExordiumModBase.instance.getDelayedRenderCallManager().addBufferedComponent(this); - blendSateHolder.apply(); + blendStateHolder.apply(); } private void renderTextureOverlay(int textureid) { diff --git a/src/main/java/dev/tr7zw/exordium/util/DelayedRenderCallManager.java b/src/main/java/dev/tr7zw/exordium/util/DelayedRenderCallManager.java index e7b407e..3ff3854 100644 --- a/src/main/java/dev/tr7zw/exordium/util/DelayedRenderCallManager.java +++ b/src/main/java/dev/tr7zw/exordium/util/DelayedRenderCallManager.java @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.List; -import org.joml.Matrix4f; - import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; @@ -19,65 +17,30 @@ * */ public class DelayedRenderCallManager { - - private List renderCalls = new ArrayList<>(); - private List nametagRenderCalls = new ArrayList<>(); - private List componentRenderCalls = new ArrayList<>(); - private Matrix4f usedProjectionMatrix = new Matrix4f(); - private final int maxTexturesPerDraw = 8; - private BlendSateHolder blendSateHolder = new BlendSateHolder(); - - public void setProjectionMatrix(Matrix4f mat) { - this.usedProjectionMatrix = mat; - } - - public void addRenderCall(Runnable run) { - renderCalls.add(run); - } - - public void addNametagRenderCall(Runnable run) { - nametagRenderCalls.add(run); - } + private static final int MAX_TEXTURES_PER_DRAW = 8; + private final List componentRenderCalls = new ArrayList<>(); + private final BlendStateHolder blendStateHolder = new BlendStateHolder(); public void addBufferedComponent(BufferedComponent component) { this.componentRenderCalls.add(component); } - public void execRenderCalls() { - for (Runnable run : renderCalls) { - run.run(); - } - renderCalls.clear(); - if (!nametagRenderCalls.isEmpty()) { - Matrix4f backupProjectionMatrix = RenderSystem.getProjectionMatrix(); - NametagScreenBuffer buffer = ExordiumModBase.instance.getNameTagScreenBuffer(); - buffer.bind(); - RenderSystem.setProjectionMatrix(usedProjectionMatrix, RenderSystem.getVertexSorting()); - for (Runnable run : nametagRenderCalls) { - run.run(); - } - buffer.bindEnd(); - nametagRenderCalls.clear(); - RenderSystem.setProjectionMatrix(backupProjectionMatrix, RenderSystem.getVertexSorting()); - } - } - public void renderComponents() { - blendSateHolder.fetch(); + blendStateHolder.fetch(); CustomShaderManager shaderManager = ExordiumModBase.instance.getCustomShaderManager(); RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - RenderSystem.setShader(() -> shaderManager.getPositionMultiTexShader()); + RenderSystem.setShader(shaderManager::getPositionMultiTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); Model model = BufferedComponent.getModel(); int textureId = 0; for (BufferedComponent component : componentRenderCalls) { RenderSystem.setShaderTexture(textureId, component.getTextureId()); textureId++; - if (textureId == maxTexturesPerDraw) { - shaderManager.getPositionMultiTexTextureCountUniform().set(maxTexturesPerDraw); + if (textureId == MAX_TEXTURES_PER_DRAW) { + shaderManager.getPositionMultiTexTextureCountUniform().set(MAX_TEXTURES_PER_DRAW); model.draw(RenderSystem.getModelViewMatrix()); textureId = 0; } @@ -89,8 +52,7 @@ public void renderComponents() { RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - blendSateHolder.apply(); + blendStateHolder.apply(); componentRenderCalls.clear(); } - } diff --git a/src/main/java/dev/tr7zw/exordium/util/NametagScreenBuffer.java b/src/main/java/dev/tr7zw/exordium/util/NametagScreenBuffer.java deleted file mode 100644 index aed6358..0000000 --- a/src/main/java/dev/tr7zw/exordium/util/NametagScreenBuffer.java +++ /dev/null @@ -1,108 +0,0 @@ -package dev.tr7zw.exordium.util; - -import com.mojang.blaze3d.pipeline.RenderTarget; -import com.mojang.blaze3d.pipeline.TextureTarget; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; - -import dev.tr7zw.exordium.ExordiumModBase; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GameRenderer; - -// TODO: Bit of a spaghetti logic. Should be cleaned up at some point -public class NametagScreenBuffer { - - private static final Minecraft minecraft = Minecraft.getInstance(); - private RenderTarget guiTarget = new TextureTarget(100, 100, true, false); - private boolean needsNewData = true; - private int requestedNewData = 0; - private long nextFrame = System.currentTimeMillis(); - - public NametagScreenBuffer(int cacheTime) { - reset(cacheTime); - } - - /** - * Prepares the buffer for a new frame if the old one is too old or the size - * changed. - * - * @param cacheTime - */ - private void reset(int cacheTime) { - guiTarget.setClearColor(0, 0, 0, 0); - guiTarget.clear(false); - nextFrame = System.currentTimeMillis() + cacheTime; - } - - /** - * @return true if ready for rendering - */ - public boolean bind() { - reset(1000 / ExordiumModBase.instance.config.targetFPSNameTags); - guiTarget.bindWrite(false); - - ExordiumModBase.instance.setTemporaryScreenOverwrite(guiTarget); - return true; - } - - public boolean acceptsData() { - return needsNewData; - } - - private void updateNeeds() { - boolean forceRender = false; - if (guiTarget.width != minecraft.getWindow().getWidth() - || guiTarget.height != minecraft.getWindow().getHeight()) { - guiTarget.resize(minecraft.getWindow().getWidth(), minecraft.getWindow().getHeight(), true); - forceRender = true; - } - needsNewData = forceRender || System.currentTimeMillis() > nextFrame; - if (needsNewData) { - requestedNewData++; - } else { - requestedNewData = 0; - } - } - - public void bindEnd() { - ExordiumModBase.instance.setTemporaryScreenOverwrite(null); - guiTarget.unbindWrite(); - Minecraft.getInstance().getMainRenderTarget().bindWrite(true); - needsNewData = false; - } - - public void renderOverlay() { - if (needsNewData && requestedNewData >= 2) - return; - int screenWidth = minecraft.getWindow().getGuiScaledWidth(); - int screenHeight = minecraft.getWindow().getGuiScaledHeight(); - renderTextureOverlay(guiTarget.getColorTextureId(), screenWidth, screenHeight); - updateNeeds(); - } - - private void renderTextureOverlay(int textureid, int screenWidth, int screenHeight) { - RenderSystem.disableDepthTest(); - RenderSystem.depthMask(false); - RenderSystem.enableBlend(); - RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, textureid); - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder bufferbuilder = tesselator.getBuilder(); - bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - bufferbuilder.vertex(0.0D, screenHeight, -90.0D).uv(0.0F, 0.0F).endVertex(); // 1 - bufferbuilder.vertex(screenWidth, screenHeight, -90.0D).uv(1.0F, 0.0F).endVertex(); // 2 - bufferbuilder.vertex(screenWidth, 0.0D, -90.0D).uv(1.0F, 1.0F).endVertex(); // 3 - bufferbuilder.vertex(0.0D, 0.0D, -90.0D).uv(0.0F, 1.0F).endVertex(); // 4 - tesselator.end(); -// RenderSystem.depthMask(true); -// RenderSystem.enableDepthTest(); - - } - -} diff --git a/src/main/java/dev/tr7zw/exordium/util/SignBufferRenderer.java b/src/main/java/dev/tr7zw/exordium/util/SignBufferRenderer.java deleted file mode 100644 index 0920dd4..0000000 --- a/src/main/java/dev/tr7zw/exordium/util/SignBufferRenderer.java +++ /dev/null @@ -1,180 +0,0 @@ -package dev.tr7zw.exordium.util; - -import java.lang.ref.Cleaner; -import java.util.List; - -import dev.tr7zw.exordium.ExordiumModBase; -import org.joml.Matrix3f; -import org.joml.Matrix4f; -import org.joml.Vector3f; - -import com.mojang.blaze3d.pipeline.RenderTarget; -import com.mojang.blaze3d.pipeline.TextureTarget; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.util.FastColor; -import net.minecraft.util.FormattedCharSequence; -import net.minecraft.world.item.DyeColor; -import net.minecraft.world.level.block.entity.SignBlockEntity; -import net.minecraft.world.level.block.entity.SignText; -import net.minecraft.world.phys.Vec3; - -public class SignBufferRenderer { - - private static final Cleaner cleaner = Cleaner.create(); - private static final Minecraft minecraft = Minecraft.getInstance(); - private static Model model = null; - private RenderTarget frontTexture; - private RenderTarget backtTexture; - - public SignBufferRenderer(SignBlockEntity arg, int light) { - frontTexture = new TextureTarget((int) ExordiumModBase.signSettings.bufferWidth, - (int) ExordiumModBase.signSettings.bufferHeight, false, false); - frontTexture.setClearColor(0, 0, 0, 0); - frontTexture.clear(false); - cleaner.register(this, new State(frontTexture)); - backtTexture = new TextureTarget((int) ExordiumModBase.signSettings.bufferWidth, - (int) ExordiumModBase.signSettings.bufferHeight, false, false); - backtTexture.setClearColor(0, 0, 0, 0); - backtTexture.clear(false); - cleaner.register(this, new State(backtTexture)); - if (model == null) - initializeModel(); - // restore renderlogic - Minecraft.getInstance().getMainRenderTarget().bindWrite(true); - } - - public void refreshImage(SignBlockEntity arg, int light, boolean front) { - ExordiumModBase.instance.getDelayedRenderCallManager().addRenderCall(() -> { - if (front) { - frontTexture.bindWrite(false); - frontTexture.clear(false); - renderSignToBuffer(arg.getFrontText(), frontTexture, light); - } else { - backtTexture.bindWrite(false); - backtTexture.clear(false); - renderSignToBuffer(arg.getBackText(), backtTexture, light); - } - }); - } - - private static void initializeModel() { - float height = (int) ExordiumModBase.signSettings.renderHeight; - float width = (int) ExordiumModBase.signSettings.renderWidth; - - Vector3f[] modelData = new Vector3f[] { new Vector3f(0.0f, height, 0.01F), new Vector3f(width, height, 0.01F), - new Vector3f(width, 0.0f, 0.01F), new Vector3f(0.0f, 0.0f, 0.01F), }; - Model.Vector2f[] uvData = new Model.Vector2f[] { new Model.Vector2f(0.0f, 0.0f), new Model.Vector2f(1.0f, 0.0f), - new Model.Vector2f(1.0f, 1.0f), new Model.Vector2f(0.0f, 1.0f), }; - model = new Model(modelData, uvData); - } - - Vec3 getTextOffset(float f) { - return new Vec3(0.0D, (0.5F * f), (0.07F * f)); - } - - public void render(PoseStack poseStack, int light, boolean hangingSign, boolean front) { -// poseStack.pushPose(); -// float scale = hangingSign ? 1.0F : 0.6666667F; -// float g = 0.015625F * scale; -// Vec3 vec3 = getTextOffset(scale); -// poseStack.translate(vec3.x, vec3.y, vec3.z); -// poseStack.scale(g, -g, g); - poseStack.translate(ExordiumModBase.signSettings.offsetX, - ExordiumModBase.signSettings.offsetY + (hangingSign ? ExordiumModBase.signSettings.hangingOffsetY : 0), - hangingSign ? ExordiumModBase.signSettings.hangingOffsetZ : 0); - RenderSystem.depthMask(true); - RenderSystem.enableDepthTest(); - RenderSystem.enableBlend(); - RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, front ? frontTexture.getColorTextureId() : backtTexture.getColorTextureId()); - Matrix4f pose = poseStack.last().pose(); - - model.draw(pose); // TODO: is light required here, since it's baked into the texture? - -// poseStack.popPose(); - } - - private void renderSignToBuffer(SignText text, RenderTarget texture, int light) { - MultiBufferSource.BufferSource bufferSource = MultiBufferSource - .immediate(Tesselator.getInstance().getBuilder()); - texture.bindWrite(false); - // cache the current render state - Matrix4f tmp = RenderSystem.getProjectionMatrix(); - // set the renderstate to identity matrices -// RenderSystem.disableCull(); - RenderSystem.setProjectionMatrix(new Matrix4f(), RenderSystem.getVertexSorting()); - float scale = 1 / ExordiumModBase.signSettings.scaleSize; - // matrix used for the text - Matrix4f matrix4f = new Matrix4f().m00(scale).m11(-scale).m22(scale).m33(1);// Matrix4f.createScaleMatrix(scale, - // -scale, scale); - int n; - boolean bl; - int o; - int l = getDarkColor(text); - FormattedCharSequence[] formattedCharSequences = text - .getRenderMessages(Minecraft.getInstance().isTextFilteringEnabled(), arg2 -> { - List list = minecraft.font.split(arg2, 90); - return list.isEmpty() ? FormattedCharSequence.EMPTY : list.get(0); - }); - if (text.hasGlowingText()) { - n = text.getColor().getTextColor(); - bl = true;// isOutlineVisible(arg, n); - o = 15728880; - } else { - n = l; - bl = false; - o = light; - } - for (int p = 0; p < 4; p++) { - FormattedCharSequence formattedCharSequence = formattedCharSequences[p]; - float q = (-minecraft.font.width(formattedCharSequence) / 2); - if (bl) { - minecraft.font.drawInBatch8xOutline(formattedCharSequence, -28 + q, (p * 10 - 20), n, l, matrix4f, - bufferSource, o); - } else { - minecraft.font.drawInBatch(formattedCharSequence, (-28 + q), (p * 10 - 20), n, false, matrix4f, - bufferSource, Font.DisplayMode.NORMAL, 0, o); - } - } - bufferSource.endBatch(); // force clear the vertex consumer - // restore renderlogic - Minecraft.getInstance().getMainRenderTarget().bindWrite(true); - RenderSystem.setProjectionMatrix(tmp, RenderSystem.getVertexSorting()); - } - - private static int getDarkColor(SignText text) { - int i = text.getColor().getTextColor(); - if (i == DyeColor.BLACK.getTextColor() && text.hasGlowingText()) - return -988212; - int j = (int) (FastColor.ARGB32.red(i) * 0.4D); - int k = (int) (FastColor.ARGB32.green(i) * 0.4D); - int l = (int) (FastColor.ARGB32.blue(i) * 0.4D); - return FastColor.ARGB32.color(0, j, k, l); - } - - static class State implements Runnable { - - private RenderTarget cleanableRenderTarget; - - State(RenderTarget guiTarget) { - this.cleanableRenderTarget = guiTarget; - } - - public void run() { - RenderSystem.recordRenderCall(() -> { - cleanableRenderTarget.destroyBuffers(); - }); - } - } - -} diff --git a/src/main/resources/exordium.mixins.json b/src/main/resources/exordium.mixins.json index 846e63e..7cdf6b5 100644 --- a/src/main/resources/exordium.mixins.json +++ b/src/main/resources/exordium.mixins.json @@ -10,7 +10,6 @@ "client": [ "ChatComponentMixin", "CrosshairMixin", - "EntityRendererMixin", "GameRendererMixin", "GlStateManagerMixin", "GuiDebugOverlayMixin", @@ -21,8 +20,6 @@ "MinecraftMixin", "PlayerTabOverlayMixin", "ScoreboardMixin", - "SignBlockEntityMixin", - "SignRendererMixin", "VignetteMixin" ], "injectors": { From c021ac5216fcb7b8e162efb06496c3579e96c776 Mon Sep 17 00:00:00 2001 From: Rybot666 Date: Mon, 29 Apr 2024 23:36:47 +0100 Subject: [PATCH 2/4] Remove unused translations --- .../resources/assets/exordium/lang/en_us.json | 6 ------ .../resources/assets/exordium/lang/it_it.json | 17 ----------------- .../resources/assets/exordium/lang/pt_br.json | 12 ------------ .../resources/assets/exordium/lang/pt_pt.json | 12 ------------ .../resources/assets/exordium/lang/ru_ru.json | 6 ------ .../resources/assets/exordium/lang/zh_cn.json | 6 ------ 6 files changed, 59 deletions(-) delete mode 100644 src/main/resources/assets/exordium/lang/it_it.json delete mode 100644 src/main/resources/assets/exordium/lang/pt_br.json delete mode 100644 src/main/resources/assets/exordium/lang/pt_pt.json diff --git a/src/main/resources/assets/exordium/lang/en_us.json b/src/main/resources/assets/exordium/lang/en_us.json index 48926bb..0fff551 100644 --- a/src/main/resources/assets/exordium/lang/en_us.json +++ b/src/main/resources/assets/exordium/lang/en_us.json @@ -1,11 +1,5 @@ { "text.exordium.title": "Exordium", - "text.exordium.enableSignBuffering": "Sign Buffering", - "text.exordium.enableSignBuffering.tooltip": "Enable/Disable buffering sign text", - "text.exordium.enableNametagScreenBuffering": "Enable Nametag Buffering", - "text.exordium.enableNametagScreenBuffering.tooltip": "Enable/Disable buffering nametags on the screen", - "text.exordium.targetFPSNameTags": "Framerate Nametags", - "text.exordium.targetFPSNameTags.tooltip": "The target framerate for nametags on the screen", "text.exordium.setting.chat.enabled": "Buffer Chat", "text.exordium.setting.chat.enabled.tooltip": "Enable/Disable buffering the chat overlay", "text.exordium.setting.chat.fps": "Buffer Chat Max. FPS", diff --git a/src/main/resources/assets/exordium/lang/it_it.json b/src/main/resources/assets/exordium/lang/it_it.json deleted file mode 100644 index 15b9483..0000000 --- a/src/main/resources/assets/exordium/lang/it_it.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "text.exordium.title": "Exordium", - "text.exordium.enableGui": "Abilita Gui", - "text.exordium.enableGui.tooltip": "Abilita/Disabilita il buffering della Gui/hud in gioco", - "text.exordium.targetFramerateGui": "Framerate Gui", - "text.exordium.targetFramerateGui.tooltip": "L'obbiettivo di framerate per la Gui/hud in gioco", - "text.exordium.enableSignBuffering": "Buffering dei cartelli", - "text.exordium.enableSignBuffering.tooltip": "Abilita/Disabilita il buffering del testo dei cartelli", - "text.exordium.enableNametagScreenBuffering": "Abilita il Buffering delle Nametag", - "text.exordium.enableNametagScreenBuffering.tooltip": "Abilita/Disabilita il Buffering delle nametag sullo schermo", - "text.exordium.targetFPSNameTags": "Framerate nametag", - "text.exordium.targetFPSNameTags.tooltip": "L'obbiettivo di framerate delle nametag sullo schermo", - "text.exordium.enabledGuiAnimationSpeedup": "Accelerazione durente animazioni della Gui", - "text.exordium.enabledGuiAnimationSpeedup.tooltip": "Abilita/Disabilita accelerazione durente animazioni della Gui", - "text.exordium.targetFPSIngameGuiAnimated": "Framerate animazioni della Gui", - "text.exordium.targetFPSIngameGuiAnimated.tooltip": "L'obbiettivo di framerate per le animazioni della Gui" -} diff --git a/src/main/resources/assets/exordium/lang/pt_br.json b/src/main/resources/assets/exordium/lang/pt_br.json deleted file mode 100644 index 08c260b..0000000 --- a/src/main/resources/assets/exordium/lang/pt_br.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "text.exordium.title": "Exordium", - "text.exordium.enableGui": "Mod Ativo no Gui", - "text.exordium.targetFramerateGui": "FPS do Gui", - "text.exordium.targetFramerateScreen": "FPS das Telas", - "text.exordium.enableScreen": "Mod Ativo nas Telas", - "text.exordium.enableSignBuffering": "Buffering nas Placas de Texto", - "text.exordium.enableNametagScreenBuffering": "Ativar Nametag Buffering", - "text.exordium.targetFPSNameTags": "FPS das Nametags", - "text.exordium.enabledGuiAnimationSpeedup": "Animações do GUI Mais Rápidas", - "text.exordium.targetFPSIngameGuiAnimated": "FPS das Animações do Gui" -} diff --git a/src/main/resources/assets/exordium/lang/pt_pt.json b/src/main/resources/assets/exordium/lang/pt_pt.json deleted file mode 100644 index 08c260b..0000000 --- a/src/main/resources/assets/exordium/lang/pt_pt.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "text.exordium.title": "Exordium", - "text.exordium.enableGui": "Mod Ativo no Gui", - "text.exordium.targetFramerateGui": "FPS do Gui", - "text.exordium.targetFramerateScreen": "FPS das Telas", - "text.exordium.enableScreen": "Mod Ativo nas Telas", - "text.exordium.enableSignBuffering": "Buffering nas Placas de Texto", - "text.exordium.enableNametagScreenBuffering": "Ativar Nametag Buffering", - "text.exordium.targetFPSNameTags": "FPS das Nametags", - "text.exordium.enabledGuiAnimationSpeedup": "Animações do GUI Mais Rápidas", - "text.exordium.targetFPSIngameGuiAnimated": "FPS das Animações do Gui" -} diff --git a/src/main/resources/assets/exordium/lang/ru_ru.json b/src/main/resources/assets/exordium/lang/ru_ru.json index 8eed50e..d50b099 100644 --- a/src/main/resources/assets/exordium/lang/ru_ru.json +++ b/src/main/resources/assets/exordium/lang/ru_ru.json @@ -1,11 +1,5 @@ { "text.exordium.title": "Настройки Exordium", - "text.exordium.enableSignBuffering": "Буфер табличек", - "text.exordium.enableSignBuffering.tooltip": "Переключить использование отдельного буфера для текста на табличках.", - "text.exordium.enableNametagScreenBuffering": "Буфер имён", - "text.exordium.enableNametagScreenBuffering.tooltip": "Переключить использование отдельного буфера для имён на экране.", - "text.exordium.targetFPSNameTags": "FPS буфера имён", - "text.exordium.targetFPSNameTags.tooltip": "Предельная частота обновления буфера имён.", "text.exordium.setting.chat.enabled": "Буфер чата", "text.exordium.setting.chat.enabled.tooltip": "Переключить использование отдельного буфера для чата.", "text.exordium.setting.chat.fps": "FPS буфера чата", diff --git a/src/main/resources/assets/exordium/lang/zh_cn.json b/src/main/resources/assets/exordium/lang/zh_cn.json index dcf65fd..8ad77a5 100644 --- a/src/main/resources/assets/exordium/lang/zh_cn.json +++ b/src/main/resources/assets/exordium/lang/zh_cn.json @@ -1,11 +1,5 @@ { "text.exordium.title": "Exordium", - "text.exordium.enableSignBuffering": "告示牌文本缓冲", - "text.exordium.enableSignBuffering.tooltip": "启用/禁用告示牌文本缓冲", - "text.exordium.enableNametagScreenBuffering": "命名标签缓冲", - "text.exordium.enableNametagScreenBuffering.tooltip": "启用或禁用屏幕内命名标签缓冲", - "text.exordium.targetFPSNameTags": "命名标签最大帧率", - "text.exordium.targetFPSNameTags.tooltip": "屏幕内命名标签的目标帧率", "text.exordium.setting.chat.enabled": "聊天栏缓冲", "text.exordium.setting.chat.enabled.tooltip": "启用/禁用聊天栏叠加层缓冲", "text.exordium.setting.chat.fps": "聊天栏最大帧率", From c696d850aaf52f8a043860c79671234676f3df44 Mon Sep 17 00:00:00 2001 From: Rybot666 Date: Mon, 29 Apr 2024 23:43:35 +0100 Subject: [PATCH 3/4] Add myself to fabric.mod.json --- src/main/resources/fabric.mod.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4d3af8b..aed8759 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -5,7 +5,8 @@ "name": "Exordium", "description": "Render the ingame gui on its own FPS limiter", "authors": [ - "tr7zw" + "tr7zw", + "katietheqt" ], "contact": { "homepage": "https://github.com/tr7zw", From d357bb90aacbdb9c12a059a0148a3d03b2934aea Mon Sep 17 00:00:00 2001 From: Rybot666 Date: Mon, 29 Apr 2024 23:50:55 +0100 Subject: [PATCH 4/4] Forgot two variables --- src/main/java/dev/tr7zw/exordium/config/Config.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/dev/tr7zw/exordium/config/Config.java b/src/main/java/dev/tr7zw/exordium/config/Config.java index d23cfee..f12259c 100644 --- a/src/main/java/dev/tr7zw/exordium/config/Config.java +++ b/src/main/java/dev/tr7zw/exordium/config/Config.java @@ -3,8 +3,6 @@ public class Config { public int configVersion = 2; - public int targetFPSNameTags = 60; - public boolean enableNametagScreenBuffering = false; public int pollRate = 60; public ComponentSettings chatSettings = new ComponentSettings(true, 20); public ComponentSettings debugScreenSettings = new ComponentSettings(true, 10);