From 2fc2e2e38d0789d6e59f44f08cd01ef77271ab52 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Wed, 3 Dec 2025 10:53:44 -0800 Subject: [PATCH] Fix some small things * Bump nhlib dep due to crash when Iris is disabled * Use jabel for tests * use joml isIdentity * remove Integer usage --- build.gradle.kts | 5 +++++ dependencies.gradle | 3 ++- .../gtnewhorizons/angelica/AngelicaMod.java | 2 +- .../angelica/glsm/DisplayListManager.java | 2 +- .../recording/CommandBufferProcessor.java | 16 +++------------ .../glsm/recording/CompiledDisplayList.java | 18 ++++++++--------- .../glsm/GLSM_DisplayList_Batching_Test.java | 4 ++-- ..._DisplayList_TransformCollapsing_Test.java | 20 +++++++++---------- .../RecordingDataStructuresTest.java | 5 +++-- 9 files changed, 36 insertions(+), 39 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 19114a9bf..1fc6fbd6d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,11 @@ plugins { minecraft { extraRunJvmArguments.add("-Dangelica.enableTestBlocks=true") extraRunJvmArguments.add("-Dangelica.dumpClass=true") +/* extraRunJvmArguments.addAll( + "-Dlegacy.debugClassLoading=true", + "-Dlegacy.debugClassLoadingFiner=true", + "-Dlegacy.debugClassLoadingSave=true")*/ + //extraRunJvmArguments.add("-Dangelica.redirectorLogspam=true") } diff --git a/dependencies.gradle b/dependencies.gradle index bb0bc2149..b66bfcad0 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -58,7 +58,7 @@ dependencies { // Iris Shaders compileOnly('org.jetbrains:annotations:26.0.2') - api("com.github.GTNewHorizons:GTNHLib:0.8.18:dev") + api("com.github.GTNewHorizons:GTNHLib:0.8.19:dev") shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0 shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-4.g6b42bca") { exclude module: "antlr4" // we only want to shadow the runtime module @@ -114,6 +114,7 @@ dependencies { testImplementation('org.junit.jupiter:junit-jupiter') testImplementation("org.mockito:mockito-core:3.+") testImplementation("org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209") + testAnnotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:1.0.1") compileOnly("mega:fluidlogged-mc1.7.10:0.1.2") } diff --git a/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java b/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java index 36ec511c5..d6fb745c0 100644 --- a/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java +++ b/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java @@ -18,7 +18,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; name = "Angelica", version = Tags.VERSION, dependencies = """ - required-after:gtnhlib@[0.8.18,);\ + required-after:gtnhlib@[0.8.19,);\ before:lwjgl3ify@[1.5.3,);\ after:hodgepodge@[2.4.4,);\ after:CodeChickenCore@[1.2.0,);\ diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/DisplayListManager.java b/src/main/java/com/gtnewhorizons/angelica/glsm/DisplayListManager.java index 11db348c0..8cc4ac34d 100644 --- a/src/main/java/com/gtnewhorizons/angelica/glsm/DisplayListManager.java +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/DisplayListManager.java @@ -101,7 +101,7 @@ public class DisplayListManager { return currentRenderingList != -1; } - static boolean isIdentity(Matrix4f m) { + public static boolean isIdentity(Matrix4f m) { return (m.properties() & Matrix4f.PROPERTY_IDENTITY) != 0; } diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferProcessor.java b/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferProcessor.java index dc2a61523..a3834f370 100644 --- a/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferProcessor.java +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferProcessor.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.angelica.glsm.recording; +import com.gtnewhorizons.angelica.glsm.DisplayListManager; import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -255,17 +256,6 @@ public final class CommandBufferProcessor { } } - /** - * Check if a matrix is identity (within epsilon). - */ - public static boolean isIdentity(Matrix4f m) { - final float eps = 1e-6f; - return Math.abs(m.m00() - 1) < eps && Math.abs(m.m01()) < eps && Math.abs(m.m02()) < eps && Math.abs(m.m03()) < eps - && Math.abs(m.m10()) < eps && Math.abs(m.m11() - 1) < eps && Math.abs(m.m12()) < eps && Math.abs(m.m13()) < eps - && Math.abs(m.m20()) < eps && Math.abs(m.m21()) < eps && Math.abs(m.m22() - 1) < eps && Math.abs(m.m23()) < eps - && Math.abs(m.m30()) < eps && Math.abs(m.m31()) < eps && Math.abs(m.m32()) < eps && Math.abs(m.m33() - 1) < eps; - } - /** * Lightweight transform optimizer for buffer-to-buffer processing. * Tracks accumulated MODELVIEW transform and emits MultMatrix commands when needed. @@ -316,7 +306,7 @@ public final class CommandBufferProcessor { } public boolean isIdentity() { - return CommandBufferProcessor.isIdentity(accumulated); + return DisplayListManager.isIdentity(accumulated); } public void markAbsoluteMatrix() { @@ -340,7 +330,7 @@ public final class CommandBufferProcessor { return; } - if (CommandBufferProcessor.isIdentity(lastEmitted)) { + if (DisplayListManager.isIdentity(lastEmitted)) { out.writeMultMatrix(GL11.GL_MODELVIEW, target); } else { final Matrix4f delta = new Matrix4f(lastEmitted).invert().mul(target); diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CompiledDisplayList.java b/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CompiledDisplayList.java index e1024d638..f3a95336e 100644 --- a/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CompiledDisplayList.java +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CompiledDisplayList.java @@ -2,12 +2,12 @@ package com.gtnewhorizons.angelica.glsm.recording; import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer; import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memAddress; import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memFree; @@ -96,8 +96,8 @@ public final class CompiledDisplayList { * Get counts of each command type in the buffer. * Used for testing to verify optimization results. */ - public Map getCommandCounts() { - Map counts = new HashMap<>(); + public Int2IntMap getCommandCounts() { + Int2IntMap counts = new Int2IntOpenHashMap(); if (commandBuffer == null || commandBuffer.limit() == 0) { return counts; } @@ -105,7 +105,7 @@ public final class CompiledDisplayList { long end = ptr + commandBuffer.limit(); while (ptr < end) { int cmd = memGetInt(ptr); - counts.merge(cmd, 1, Integer::sum); + counts.mergeInt(cmd, 1, Integer::sum); ptr += getCommandSize(cmd, ptr); } return counts; @@ -115,8 +115,8 @@ public final class CompiledDisplayList { * Get the sequence of command opcodes in order. * Used for testing to verify command ordering. */ - public List getCommandOpcodes() { - List opcodes = new ArrayList<>(); + public IntList getCommandOpcodes() { + IntList opcodes = new IntArrayList(); if (commandBuffer == null || commandBuffer.limit() == 0) { return opcodes; } diff --git a/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_Batching_Test.java b/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_Batching_Test.java index d22e0116a..1a35d2449 100644 --- a/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_Batching_Test.java +++ b/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_Batching_Test.java @@ -58,8 +58,8 @@ class GLSM_DisplayList_Batching_Test { private Set getUniqueVBOs(DisplayListCommand[] commands) { Set vbos = new HashSet<>(); for (DisplayListCommand cmd : commands) { - if (cmd instanceof DrawRangeCmd) { - vbos.add(((DrawRangeCmd) cmd).sharedVbo()); + if (cmd instanceof DrawRangeCmd rangeCmd) { + vbos.add(rangeCmd.sharedVbo()); } } return vbos; diff --git a/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_TransformCollapsing_Test.java b/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_TransformCollapsing_Test.java index 33c4139a0..bfec809e0 100644 --- a/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_TransformCollapsing_Test.java +++ b/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_TransformCollapsing_Test.java @@ -3,6 +3,8 @@ package com.gtnewhorizons.angelica.glsm; import com.gtnewhorizons.angelica.AngelicaExtension; import com.gtnewhorizons.angelica.glsm.recording.CompiledDisplayList; import com.gtnewhorizons.angelica.glsm.recording.GLCommand; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.IntList; import org.joml.Matrix4f; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -11,8 +13,6 @@ import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import java.nio.FloatBuffer; -import java.util.List; -import java.util.Map; import static org.junit.jupiter.api.Assertions.*; @@ -68,7 +68,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList); assertNotNull(compiled, "Display list should be compiled"); - Map counts = compiled.getCommandCounts(); + Int2IntMap counts = compiled.getCommandCounts(); int multMatrixCount = counts.getOrDefault(GLCommand.MULT_MATRIX, 0); int individualTransformCount = counts.getOrDefault(GLCommand.TRANSLATE, 0) + counts.getOrDefault(GLCommand.ROTATE, 0) @@ -122,7 +122,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { // Verify optimization: should have Push, Pop, and collapsed MultMatrix commands CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList); - Map counts = compiled.getCommandCounts(); + Int2IntMap counts = compiled.getCommandCounts(); int pushCount = counts.getOrDefault(GLCommand.PUSH_MATRIX, 0); int popCount = counts.getOrDefault(GLCommand.POP_MATRIX, 0); @@ -217,7 +217,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { // Verify optimization: MultMatrix should be emitted before CallList CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList); - List opcodes = compiled.getCommandOpcodes(); + IntList opcodes = compiled.getCommandOpcodes(); // Find positions of MultMatrix and CallList int multMatrixIndex = opcodes.indexOf(GLCommand.MULT_MATRIX); @@ -268,7 +268,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { GLStateManager.glEndList(); CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList); - Map counts = compiled.getCommandCounts(); + Int2IntMap counts = compiled.getCommandCounts(); int multMatrixCount = counts.getOrDefault(GLCommand.MULT_MATRIX, 0); @@ -356,7 +356,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { // Verify optimization: should collapse to 1 MultMatrix CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList); - Map counts = compiled.getCommandCounts(); + Int2IntMap counts = compiled.getCommandCounts(); int multMatrixCount = counts.getOrDefault(GLCommand.MULT_MATRIX, 0); @@ -416,7 +416,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList); assertNotNull(compiled, "Display list should be compiled"); - List opcodes = compiled.getCommandOpcodes(); + IntList opcodes = compiled.getCommandOpcodes(); // Find indices of key commands int pushIndex = opcodes.indexOf(GLCommand.PUSH_MATRIX); @@ -467,7 +467,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { GLStateManager.glEndList(); CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList); - List opcodes = compiled.getCommandOpcodes(); + IntList opcodes = compiled.getCommandOpcodes(); int pushIndex = opcodes.indexOf(GLCommand.PUSH_MATRIX); int popIndex = opcodes.indexOf(GLCommand.POP_MATRIX); @@ -507,7 +507,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList); assertNotNull(compiled, "Display list should be compiled"); - Map counts = compiled.getCommandCounts(); + Int2IntMap counts = compiled.getCommandCounts(); int loadMatrixCount = counts.getOrDefault(GLCommand.LOAD_MATRIX, 0); assertEquals(1, loadMatrixCount, diff --git a/src/test/java/com/gtnewhorizons/angelica/glsm/recording/RecordingDataStructuresTest.java b/src/test/java/com/gtnewhorizons/angelica/glsm/recording/RecordingDataStructuresTest.java index 1aba9e61d..3e9e4282b 100644 --- a/src/test/java/com/gtnewhorizons/angelica/glsm/recording/RecordingDataStructuresTest.java +++ b/src/test/java/com/gtnewhorizons/angelica/glsm/recording/RecordingDataStructuresTest.java @@ -9,10 +9,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.lwjgl.opengl.GL11; +import it.unimi.dsi.fastutil.ints.Int2IntMap; + import java.nio.ByteBuffer; import java.util.Arrays; import java.util.List; -import java.util.Map; import static org.junit.jupiter.api.Assertions.*; @@ -72,7 +73,7 @@ class RecordingDataStructuresTest { assertNotNull(compiled.getCommandBuffer(), "Command buffer should not be null"); // Get command counts to verify structure - Map counts = compiled.getCommandCounts(); + Int2IntMap counts = compiled.getCommandCounts(); // Should have PushMatrix and PopMatrix assertEquals(1, counts.getOrDefault(GLCommand.PUSH_MATRIX, 0), "Should have 1 PushMatrix");