From 7c5e02d2e8a37531335d2a7a1f9633362445f258 Mon Sep 17 00:00:00 2001
From: Jozufozu
Date: Sun, 26 Sep 2021 19:40:53 -0700
Subject: [PATCH] UNTESTED - Replace ATs
- Matrices use #store
- Accessor for pausedPartialTick
---
build.gradle | 2 +-
.../backend/gl/buffer/MappedBuffer.java | 7 +++++
.../flywheel/backend/gl/buffer/VecBuffer.java | 10 ++++++
.../flywheel/backend/gl/shader/GlProgram.java | 10 +++++-
.../core/materials/model/ModelData.java | 15 ++++++---
.../mixin/PausedPartialTickAccessor.java | 13 ++++++++
.../flywheel/util/AnimationTickHolder.java | 4 ++-
.../jozufozu/flywheel/util/RenderUtil.java | 15 ---------
.../resources/META-INF/accesstransformer.cfg | 31 -------------------
src/main/resources/flywheel.mixins.json | 3 +-
10 files changed, 56 insertions(+), 54 deletions(-)
create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/PausedPartialTickAccessor.java
delete mode 100644 src/main/resources/META-INF/accesstransformer.cfg
diff --git a/build.gradle b/build.gradle
index 46343283f..685a645e2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -33,7 +33,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(16)
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
mappings channel: 'official', version: "${minecraft_version}"
- accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
+ //accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
runs {
client {
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java
index 0fa839915..60c5e85f8 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java
@@ -1,6 +1,7 @@
package com.jozufozu.flywheel.backend.gl.buffer;
import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
import org.lwjgl.opengl.GL15;
import org.lwjgl.system.MemoryUtil;
@@ -48,6 +49,12 @@ public abstract class MappedBuffer extends VecBuffer implements AutoCloseable {
return this;
}
+ public MappedBuffer put(FloatBuffer floats) {
+ checkAndMap();
+ super.put(floats);
+ return this;
+ }
+
public int position() {
checkAndMap();
return super.position();
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java
index 76fcfcccb..96171c80b 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java
@@ -3,6 +3,7 @@ package com.jozufozu.flywheel.backend.gl.buffer;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
public class VecBuffer {
@@ -48,6 +49,15 @@ public class VecBuffer {
return this;
}
+ public VecBuffer put(FloatBuffer floats) {
+
+ int remainingBytes = floats.remaining() * 4;
+ internal.asFloatBuffer().put(floats);
+ internal.position(internal.position() + remainingBytes);
+
+ return this;
+ }
+
public int position() {
return internal.position();
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java
index 692002529..eade29843 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java
@@ -6,6 +6,11 @@ import static org.lwjgl.opengl.GL20.glUniform1i;
import static org.lwjgl.opengl.GL20.glUniformMatrix4fv;
import static org.lwjgl.opengl.GL20.glUseProgram;
+import java.nio.FloatBuffer;
+
+import org.lwjgl.system.MemoryStack;
+import org.lwjgl.system.MemoryUtil;
+
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.GlObject;
import com.jozufozu.flywheel.util.RenderUtil;
@@ -65,7 +70,10 @@ public abstract class GlProgram extends GlObject {
}
protected static void uploadMatrixUniform(int uniform, Matrix4f mat) {
- glUniformMatrix4fv(uniform, false, RenderUtil.writeMatrix(mat));
+ FloatBuffer floatBuffer = MemoryStack.stackGet()
+ .mallocFloat(16);
+ mat.store(floatBuffer);
+ glUniformMatrix4fv(uniform, false, floatBuffer);
}
@Override
diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelData.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelData.java
index ff225c0ea..8b36c186e 100644
--- a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelData.java
+++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelData.java
@@ -1,5 +1,7 @@
package com.jozufozu.flywheel.core.materials.model;
+import java.nio.FloatBuffer;
+
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.core.materials.BasicData;
import com.jozufozu.flywheel.util.RenderUtil;
@@ -8,10 +10,14 @@ import com.mojang.blaze3d.vertex.PoseStack;
public class ModelData extends BasicData {
private static final float[] empty = new float[25];
- public float[] matrices = empty;
+ public final float[] matrices = empty.clone();
+ private final FloatBuffer buf = FloatBuffer.wrap(matrices);
public ModelData setTransform(PoseStack stack) {
- matrices = RenderUtil.writeMatrixStack(stack);
+ this.buf.reset();
+
+ stack.last().pose().store(this.buf);
+ stack.last().normal().store(this.buf);
markDirty();
return this;
}
@@ -24,7 +30,8 @@ public class ModelData extends BasicData {
*
*/
public ModelData setEmptyTransform() {
- matrices = empty;
+ this.buf.reset();
+ this.buf.put(empty);
markDirty();
return this;
}
@@ -32,6 +39,6 @@ public class ModelData extends BasicData {
@Override
public void write(VecBuffer buf) {
super.write(buf);
- buf.putFloatArray(matrices);
+ buf.put(this.buf);
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/PausedPartialTickAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/PausedPartialTickAccessor.java
new file mode 100644
index 000000000..550f6d4ab
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/mixin/PausedPartialTickAccessor.java
@@ -0,0 +1,13 @@
+package com.jozufozu.flywheel.mixin;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+import net.minecraft.client.Minecraft;
+
+@Mixin(Minecraft.class)
+public interface PausedPartialTickAccessor {
+
+ @Accessor("pausePartialTick")
+ float getPausePartialTick();
+}
diff --git a/src/main/java/com/jozufozu/flywheel/util/AnimationTickHolder.java b/src/main/java/com/jozufozu/flywheel/util/AnimationTickHolder.java
index d5143f3a2..0a8374f42 100644
--- a/src/main/java/com/jozufozu/flywheel/util/AnimationTickHolder.java
+++ b/src/main/java/com/jozufozu/flywheel/util/AnimationTickHolder.java
@@ -1,5 +1,7 @@
package com.jozufozu.flywheel.util;
+import com.jozufozu.flywheel.mixin.PausedPartialTickAccessor;
+
import net.minecraft.client.Minecraft;
public class AnimationTickHolder {
@@ -35,6 +37,6 @@ public class AnimationTickHolder {
public static float getPartialTicks() {
Minecraft mc = Minecraft.getInstance();
- return (mc.isPaused() ? mc.pausePartialTick : mc.getFrameTime());
+ return (mc.isPaused() ? ((PausedPartialTickAccessor) mc).getPausePartialTick() : mc.getFrameTime());
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java b/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java
index 857207939..7a06724ab 100644
--- a/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java
+++ b/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java
@@ -42,21 +42,6 @@ public class RenderUtil {
return Math.sqrt(lengthSqr(x, y, z));
}
- public static float[] writeMatrixStack(PoseStack stack) {
- return writeMatrixStack(stack.last()
- .pose(), stack.last()
- .normal());
- }
-
- // GPUs want matrices in column major order.
- public static float[] writeMatrixStack(Matrix4f model, Matrix3f normal) {
- return new float[]{model.m00, model.m10, model.m20, model.m30, model.m01, model.m11, model.m21, model.m31, model.m02, model.m12, model.m22, model.m32, model.m03, model.m13, model.m23, model.m33, normal.m00, normal.m10, normal.m20, normal.m01, normal.m11, normal.m21, normal.m02, normal.m12, normal.m22,};
- }
-
- public static float[] writeMatrix(Matrix4f model) {
- return new float[]{model.m00, model.m10, model.m20, model.m30, model.m01, model.m11, model.m21, model.m31, model.m02, model.m12, model.m22, model.m32, model.m03, model.m13, model.m23, model.m33,};
- }
-
public static Supplier rotateToFace(Direction facing) {
return () -> {
PoseStack stack = new PoseStack();
diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg
deleted file mode 100644
index d4a263750..000000000
--- a/src/main/resources/META-INF/accesstransformer.cfg
+++ /dev/null
@@ -1,31 +0,0 @@
-
-# Don't jitter when game is paused
-public net.minecraft.client.Minecraft f_91013_ #renderPartialTicksPaused
-
-# For uploading matrices as vertex attributes.
-public com.mojang.math.Matrix3f f_8134_ #a00
-public com.mojang.math.Matrix3f f_8135_ #a01
-public com.mojang.math.Matrix3f f_8136_ #a02
-public com.mojang.math.Matrix3f f_8137_ #a10
-public com.mojang.math.Matrix3f f_8138_ #a11
-public com.mojang.math.Matrix3f f_8139_ #a12
-public com.mojang.math.Matrix3f f_8140_ #a20
-public com.mojang.math.Matrix3f f_8141_ #a21
-public com.mojang.math.Matrix3f f_8142_ #a22
-
-public com.mojang.math.Matrix4f f_27603_ #a00
-public com.mojang.math.Matrix4f f_27604_ #a01
-public com.mojang.math.Matrix4f f_27605_ #a02
-public com.mojang.math.Matrix4f f_27606_ #a03
-public com.mojang.math.Matrix4f f_27607_ #a10
-public com.mojang.math.Matrix4f f_27608_ #a11
-public com.mojang.math.Matrix4f f_27609_ #a12
-public com.mojang.math.Matrix4f f_27610_ #a13
-public com.mojang.math.Matrix4f f_27611_ #a20
-public com.mojang.math.Matrix4f f_27612_ #a21
-public com.mojang.math.Matrix4f f_27613_ #a22
-public com.mojang.math.Matrix4f f_27614_ #a23
-public com.mojang.math.Matrix4f f_27615_ #a30
-public com.mojang.math.Matrix4f f_27616_ #a31
-public com.mojang.math.Matrix4f f_27617_ #a32
-public com.mojang.math.Matrix4f f_27618_ #a33
diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json
index 30a4c08bb..b9cf08632 100644
--- a/src/main/resources/flywheel.mixins.json
+++ b/src/main/resources/flywheel.mixins.json
@@ -17,7 +17,8 @@
"LevelRendererAccessor",
"InstanceAddMixin",
"InstanceRemoveMixin",
- "LeakChunkStorageArrayMixin"
+ "LeakChunkStorageArrayMixin",
+ "PausedPartialTickAccessor"
],
"injectors": {
"defaultRequire": 1