diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/BackendConfig.java b/common/src/backend/java/dev/engine_room/flywheel/backend/BackendConfig.java index 779ab2f9c..b61b3bef5 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/BackendConfig.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/BackendConfig.java @@ -3,7 +3,7 @@ import dev.engine_room.flywheel.backend.compile.LightSmoothness; public interface BackendConfig { - BackendConfig INSTANCE = FlwBackendXplat.INSTANCE.getConfig(); + BackendConfig INSTANCE = FlwBackend.config(); /** * How smooth/accurate our flw_light impl is. diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/FlwBackend.java b/common/src/backend/java/dev/engine_room/flywheel/backend/FlwBackend.java index a51878268..6e1dac124 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/FlwBackend.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/FlwBackend.java @@ -1,5 +1,6 @@ package dev.engine_room.flywheel.backend; +import org.jetbrains.annotations.UnknownNullability; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,11 +8,18 @@ public final class FlwBackend { public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/backend"); + @UnknownNullability + private static BackendConfig config; private FlwBackend() { } - public static void init() { + public static BackendConfig config() { + return config; + } + + public static void init(BackendConfig config) { + FlwBackend.config = config; Backends.init(); } } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplat.java b/common/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplat.java index 8cd216c59..6acb2832a 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplat.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplat.java @@ -9,6 +9,4 @@ public interface FlwBackendXplat { FlwBackendXplat INSTANCE = DependencyInjection.load(FlwBackendXplat.class, "dev.engine_room.flywheel.backend.FlwBackendXplatImpl"); int getLightEmission(BlockState state, BlockGetter level, BlockPos pos); - - BackendConfig getConfig(); } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/BufferTextureInstanceComponent.java b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/BufferTextureInstanceComponent.java index 9a6a02012..262f051b8 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/BufferTextureInstanceComponent.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/BufferTextureInstanceComponent.java @@ -44,7 +44,9 @@ protected void generateUnpacking(GlslBuilder builder) { fnBody.ret(GlslExpr.call(STRUCT_NAME, unpackArgs)); - builder._addRaw("uniform usamplerBuffer _flw_instances;"); + builder.uniform() + .type("usamplerBuffer") + .name("_flw_instances"); builder.blankLine(); builder.function() .signature(FnSignature.create() diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/InstanceStructComponent.java b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/InstanceStructComponent.java index 76d56e755..ec875e095 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/InstanceStructComponent.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/InstanceStructComponent.java @@ -34,7 +34,7 @@ public String source() { var builder = new GlslBuilder(); var instance = builder.struct(); - instance.setName(STRUCT_NAME); + instance.name(STRUCT_NAME); for (var element : layout.elements()) { instance.addField(LayoutInterpreter.typeName(element.type()), element.name()); } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/SsboInstanceComponent.java b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/SsboInstanceComponent.java index c8902b2d4..2b7df8af8 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/SsboInstanceComponent.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/component/SsboInstanceComponent.java @@ -43,7 +43,7 @@ protected void generateUnpacking(GlslBuilder builder) { fnBody.ret(GlslExpr.call(STRUCT_NAME, unpackArgs)); - builder._addRaw("layout(std430, binding = " + BufferBindings.INSTANCE + ") restrict readonly buffer InstanceBuffer {\n" + builder._raw("layout(std430, binding = " + BufferBindings.INSTANCE + ") restrict readonly buffer InstanceBuffer {\n" + " uint _flw_instances[];\n" + "};"); builder.blankLine(); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/DrawManager.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/DrawManager.java index 993046659..19bdfeae1 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/DrawManager.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/DrawManager.java @@ -8,6 +8,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; +import com.mojang.datafixers.util.Pair; + import dev.engine_room.flywheel.api.backend.Engine; import dev.engine_room.flywheel.api.instance.Instance; import dev.engine_room.flywheel.api.instance.InstanceType; @@ -16,7 +18,6 @@ import dev.engine_room.flywheel.backend.FlwBackend; import dev.engine_room.flywheel.backend.engine.embed.Environment; import dev.engine_room.flywheel.backend.engine.embed.EnvironmentStorage; -import dev.engine_room.flywheel.lib.util.Pair; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.client.resources.model.ModelBakery; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectDrawManager.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectDrawManager.java index cb029600e..e19999b5c 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectDrawManager.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectDrawManager.java @@ -219,8 +219,8 @@ public void renderCrumbling(List crumblingBlocks) { TextureBinder.bind(ModelBakery.BREAKING_LOCATIONS.get(progressEntry.getIntKey())); for (var instanceHandlePair : progressEntry.getValue()) { - IndirectInstancer instancer = instanceHandlePair.first(); - int instanceIndex = instanceHandlePair.second().index; + IndirectInstancer instancer = instanceHandlePair.getFirst(); + int instanceIndex = instanceHandlePair.getSecond().index; for (IndirectDraw draw : instancer.draws()) { // Transform the material to be suited for crumbling. diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDrawManager.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDrawManager.java index f7c55d43f..400dae79c 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDrawManager.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDrawManager.java @@ -180,8 +180,8 @@ public void renderCrumbling(List crumblingBlocks) { TextureBinder.bind(ModelBakery.BREAKING_LOCATIONS.get(progressEntry.getIntKey())); for (var instanceHandlePair : progressEntry.getValue()) { - InstancedInstancer instancer = instanceHandlePair.first(); - var index = instanceHandlePair.second().index; + InstancedInstancer instancer = instanceHandlePair.getFirst(); + var index = instanceHandlePair.getSecond().index; program.setInt("_flw_baseInstance", index); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArrayDSA.java b/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArrayDSA.java index 4dca28b58..a3c67b0d2 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArrayDSA.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArrayDSA.java @@ -1,5 +1,6 @@ package dev.engine_room.flywheel.backend.gl.array; +import java.util.Arrays; import java.util.BitSet; import java.util.List; @@ -7,13 +8,13 @@ import org.lwjgl.system.Checks; import dev.engine_room.flywheel.backend.gl.GlCompat; -import dev.engine_room.flywheel.lib.util.FlwUtil; +import net.minecraft.Util; public class GlVertexArrayDSA extends GlVertexArray { public static final boolean SUPPORTED = isSupported(); private final BitSet attributeEnabled = new BitSet(MAX_ATTRIBS); private final VertexAttribute[] attributes = new VertexAttribute[MAX_ATTRIBS]; - private final int[] attributeBindings = FlwUtil.initArray(MAX_ATTRIBS, -1); + private final int[] attributeBindings = Util.make(new int[MAX_ATTRIBS], a -> Arrays.fill(a, -1)); private final int[] bindingBuffers = new int[MAX_ATTRIB_BINDINGS]; private final long[] bindingOffsets = new long[MAX_ATTRIB_BINDINGS]; private final int[] bindingStrides = new int[MAX_ATTRIB_BINDINGS]; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArrayGL3.java b/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArrayGL3.java index bdf048ff4..785b17fca 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArrayGL3.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArrayGL3.java @@ -1,5 +1,6 @@ package dev.engine_room.flywheel.backend.gl.array; +import java.util.Arrays; import java.util.BitSet; import java.util.List; @@ -12,13 +13,13 @@ import dev.engine_room.flywheel.backend.gl.GlCompat; import dev.engine_room.flywheel.backend.gl.buffer.GlBufferType; -import dev.engine_room.flywheel.lib.util.FlwUtil; +import net.minecraft.Util; public abstract class GlVertexArrayGL3 extends GlVertexArray { private final BitSet attributeDirty = new BitSet(MAX_ATTRIBS); private final int[] attributeOffsets = new int[MAX_ATTRIBS]; private final VertexAttribute[] attributes = new VertexAttribute[MAX_ATTRIBS]; - private final int[] attributeBindings = FlwUtil.initArray(MAX_ATTRIBS, -1); + private final int[] attributeBindings = Util.make(new int[MAX_ATTRIBS], a -> Arrays.fill(a, -1)); private final int[] bindingBuffers = new int[MAX_ATTRIB_BINDINGS]; private final long[] bindingOffsets = new long[MAX_ATTRIB_BINDINGS]; private final int[] bindingStrides = new int[MAX_ATTRIB_BINDINGS]; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArraySeparateAttributes.java b/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArraySeparateAttributes.java index a7bdbf978..6488ea03d 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArraySeparateAttributes.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/gl/array/GlVertexArraySeparateAttributes.java @@ -1,5 +1,6 @@ package dev.engine_room.flywheel.backend.gl.array; +import java.util.Arrays; import java.util.BitSet; import java.util.List; @@ -9,13 +10,13 @@ import dev.engine_room.flywheel.backend.gl.GlCompat; import dev.engine_room.flywheel.backend.gl.GlStateTracker; import dev.engine_room.flywheel.backend.gl.buffer.GlBufferType; -import dev.engine_room.flywheel.lib.util.FlwUtil; +import net.minecraft.Util; public class GlVertexArraySeparateAttributes extends GlVertexArray { public static final boolean SUPPORTED = isSupported(); private final BitSet attributeEnabled = new BitSet(MAX_ATTRIBS); private final VertexAttribute[] attributes = new VertexAttribute[MAX_ATTRIBS]; - private final int[] attributeBindings = FlwUtil.initArray(MAX_ATTRIBS, -1); + private final int[] attributeBindings = Util.make(new int[MAX_ATTRIBS], a -> Arrays.fill(a, -1)); private final int[] bindingBuffers = new int[MAX_ATTRIB_BINDINGS]; private final long[] bindingOffsets = new long[MAX_ATTRIB_BINDINGS]; private final int[] bindingStrides = new int[MAX_ATTRIB_BINDINGS]; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/LoadError.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/LoadError.java index 0cfd3058b..5d4347ad4 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/LoadError.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/LoadError.java @@ -5,9 +5,10 @@ import java.util.List; import java.util.stream.Collectors; +import com.mojang.datafixers.util.Pair; + import dev.engine_room.flywheel.backend.glsl.error.ErrorBuilder; import dev.engine_room.flywheel.backend.glsl.span.Span; -import dev.engine_room.flywheel.lib.util.Pair; import net.minecraft.ResourceLocationException; import net.minecraft.resources.ResourceLocation; @@ -38,9 +39,9 @@ public ErrorBuilder generateMessage() { .pointAtFile(location); for (var innerError : innerErrors) { - var err = innerError.second() + var err = innerError.getSecond() .generateMessage(); - out.pointAt(innerError.first()) + out.pointAt(innerError.getFirst()) .nested(err); } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/SourceFile.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/SourceFile.java index 020b85692..1f9646c56 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/SourceFile.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/SourceFile.java @@ -4,13 +4,13 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Optional; import java.util.Set; import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.util.Pair; import dev.engine_room.flywheel.backend.glsl.parse.Import; import dev.engine_room.flywheel.backend.glsl.parse.ShaderField; @@ -18,7 +18,6 @@ import dev.engine_room.flywheel.backend.glsl.parse.ShaderStruct; import dev.engine_room.flywheel.backend.glsl.span.Span; import dev.engine_room.flywheel.backend.glsl.span.StringSpan; -import dev.engine_room.flywheel.lib.util.Pair; import dev.engine_room.flywheel.lib.util.ResourceUtil; import net.minecraft.ResourceLocationException; import net.minecraft.resources.ResourceLocation; @@ -172,44 +171,48 @@ public Span getLineSpanMatching(int line, @Nullable String match) { * @param name The name of the struct to find. * @return null if no definition matches the name. */ - public Optional findStructByName(String name) { + @Nullable + public ShaderStruct findStruct(String name) { ShaderStruct struct = structs.get(name); if (struct != null) { - return Optional.of(struct); + return struct; } for (var include : included) { - var external = include.structs.get(name); + var external = include.findStruct(name); if (external != null) { - return Optional.of(external); + return external; } } - return Optional.empty(); + return null; } /** * Search this file and recursively search all imports to find a function definition matching the given name. * * @param name The name of the function to find. - * @return Optional#empty() if no definition matches the name. + * @return null if no definition matches the name. */ - public Optional findFunction(String name) { - ShaderFunction local = functions.get(name); + @Nullable + public ShaderFunction findFunction(String name) { + ShaderFunction function = functions.get(name); - if (local != null) return Optional.of(local); + if (function != null) { + return function; + } for (var include : included) { - var external = include.functions.get(name); + var external = include.findFunction(name); if (external != null) { - return Optional.of(external); + return external; } } - return Optional.empty(); + return null; } @Override diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/SourceLines.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/SourceLines.java index ebc40e19e..934c40865 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/SourceLines.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/SourceLines.java @@ -128,10 +128,6 @@ public int length() { return raw.length(); } - public int lineStartCol(int spanLine) { - return 0; - } - public int lineWidth(int spanLine) { return lines.get(spanLine) .length(); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/ErrorBuilder.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/ErrorBuilder.java index f4e5fe023..b23a05954 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/ErrorBuilder.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/ErrorBuilder.java @@ -29,7 +29,6 @@ public class ErrorBuilder { private final List lines = new ArrayList<>(); private ErrorBuilder() { - } public static ErrorBuilder create() { diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/ErrorLine.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/ErrorLine.java index d2622ffcd..3e7811a04 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/ErrorLine.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/ErrorLine.java @@ -1,7 +1,6 @@ package dev.engine_room.flywheel.backend.glsl.error.lines; public interface ErrorLine { - default int neededMargin() { return left().length(); } @@ -17,6 +16,7 @@ default String build() { default String left() { return ""; } + default String right() { return ""; } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/FileLine.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/FileLine.java index e9f77a090..d7571cec8 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/FileLine.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/FileLine.java @@ -1,7 +1,6 @@ package dev.engine_room.flywheel.backend.glsl.error.lines; public record FileLine(String fileName) implements ErrorLine { - @Override public String left() { return "-"; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/HeaderLine.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/HeaderLine.java index dc4f24703..d6af1f811 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/HeaderLine.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/HeaderLine.java @@ -1,7 +1,6 @@ package dev.engine_room.flywheel.backend.glsl.error.lines; public record HeaderLine(String level, CharSequence message) implements ErrorLine { - @Override public int neededMargin() { return -1; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/SourceLine.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/SourceLine.java index 8015f5abe..96a2c7a93 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/SourceLine.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/SourceLine.java @@ -1,7 +1,6 @@ package dev.engine_room.flywheel.backend.glsl.error.lines; public record SourceLine(String number, String line) implements ErrorLine { - public static SourceLine numbered(int number, String line) { return new SourceLine(Integer.toString(number), line); } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/SpanHighlightLine.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/SpanHighlightLine.java index 1d1e41a72..1fe6c1b28 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/SpanHighlightLine.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/SpanHighlightLine.java @@ -7,11 +7,6 @@ public SpanHighlightLine(int firstCol, int lastCol) { line = generateUnderline(firstCol, lastCol); } - @Override - public String left() { - return ""; - } - @Override public String right() { return line; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/TextLine.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/TextLine.java index e957106db..5880d8566 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/TextLine.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/error/lines/TextLine.java @@ -1,7 +1,6 @@ package dev.engine_room.flywheel.backend.glsl.error.lines; public record TextLine(String msg) implements ErrorLine { - @Override public String build() { return msg; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/FnSignature.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/FnSignature.java index dcfea176c..6dd81ff65 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/FnSignature.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/FnSignature.java @@ -3,12 +3,12 @@ import java.util.Collection; import java.util.stream.Collectors; -import com.google.common.collect.ImmutableList; +import org.jetbrains.annotations.Nullable; -import dev.engine_room.flywheel.lib.util.Pair; +import com.google.common.collect.ImmutableList; +import com.mojang.datafixers.util.Pair; public record FnSignature(String returnType, String name, ImmutableList> args) { - public static Builder create() { return new Builder(); } @@ -26,7 +26,7 @@ public static FnSignature ofVoid(String name) { public Collection createArgExpressions() { return args.stream() - .map(Pair::second) + .map(Pair::getSecond) .map(GlslExpr::variable) .collect(Collectors.toList()); } @@ -37,18 +37,20 @@ public boolean isVoid() { public String fullDeclaration() { return returnType + ' ' + name + '(' + args.stream() - .map(p -> p.first() + ' ' + p.second()) + .map(p -> p.getFirst() + ' ' + p.getSecond()) .collect(Collectors.joining(", ")) + ')'; } public String signatureDeclaration() { return returnType + ' ' + name + '(' + args.stream() - .map(Pair::first) + .map(Pair::getFirst) .collect(Collectors.joining(", ")) + ')'; } public static class Builder { + @Nullable private String returnType; + @Nullable private String name; private final ImmutableList.Builder> args = ImmutableList.builder(); @@ -77,5 +79,4 @@ public FnSignature build() { return new FnSignature(returnType, name, args.build()); } } - } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslBuilder.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslBuilder.java index 74f95b389..ba28d74ab 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslBuilder.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslBuilder.java @@ -19,29 +19,33 @@ public GlslStruct struct() { return add(new GlslStruct()); } - public GlslFn function() { - return add(new GlslFn()); - } - public GlslVertexInput vertexInput() { return add(new GlslVertexInput()); } + public GlslUniform uniform() { + return add(new GlslUniform()); + } + public GlslUniformBlock uniformBlock() { return add(new GlslUniformBlock()); } - public T add(T element) { - elements.add(element); - return element; + public GlslFn function() { + return add(new GlslFn()); } public void blankLine() { - elements.add(Separators.BLANK_LINE); + add(Separators.BLANK_LINE); + } + + public void _raw(String sourceString) { + add(new Raw(sourceString)); } - public void _addRaw(String sourceString) { - elements.add(() -> sourceString); + public T add(T element) { + elements.add(element); + return element; } public String build() { @@ -54,6 +58,20 @@ public interface Declaration { String prettyPrint(); } + public record Define(String name, String value) implements Declaration { + @Override + public String prettyPrint() { + return "#define " + name + " " + value; + } + } + + public record Undef(String name) implements Declaration { + @Override + public String prettyPrint() { + return "#undef " + name; + } + } + public enum Separators implements Declaration { BLANK_LINE(""), ; @@ -70,18 +88,10 @@ public String prettyPrint() { } } - public record Define(String name, String value) implements Declaration { - @Override - public String prettyPrint() { - return "#define " + name + " " + value; - } - } - - public record Undef(String name) implements Declaration { + public record Raw(String sourceString) implements Declaration { @Override public String prettyPrint() { - return "#undef " + name; + return sourceString; } } - } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslExpr.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslExpr.java index c9f15ea73..0d4d36b86 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslExpr.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslExpr.java @@ -8,7 +8,6 @@ import com.google.common.collect.ImmutableList; public interface GlslExpr { - /** * Create a glsl variable with the given name. * @@ -129,7 +128,6 @@ record Variable(String name) implements GlslExpr { public String prettyPrint() { return name; } - } record FunctionCall(String name, Collection args) implements GlslExpr { @@ -144,7 +142,6 @@ public String prettyPrint() { .collect(Collectors.joining(", ")); return name + "(" + args + ")"; } - } record FunctionCall0(String name) implements GlslExpr { @@ -152,7 +149,6 @@ record FunctionCall0(String name) implements GlslExpr { public String prettyPrint() { return name + "()"; } - } record Swizzle(GlslExpr target, String selection) implements GlslExpr { @@ -160,7 +156,6 @@ record Swizzle(GlslExpr target, String selection) implements GlslExpr { public String prettyPrint() { return target.prettyPrint() + "." + selection; } - } record Access(GlslExpr target, String argName) implements GlslExpr { @@ -168,7 +163,6 @@ record Access(GlslExpr target, String argName) implements GlslExpr { public String prettyPrint() { return target.prettyPrint() + "." + argName; } - } record Clamp(GlslExpr value, GlslExpr from, GlslExpr to) implements GlslExpr { diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslFn.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslFn.java index cd6bbea68..f56735a52 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslFn.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslFn.java @@ -5,24 +5,25 @@ import dev.engine_room.flywheel.lib.util.StringUtil; public class GlslFn implements GlslBuilder.Declaration { - private GlslBlock body = new GlslBlock(); private FnSignature signature; + private GlslBlock body = new GlslBlock(); public GlslFn signature(FnSignature signature) { this.signature = signature; return this; } - public GlslFn body(Consumer f) { - f.accept(body); + public GlslFn body(GlslBlock block) { + body = block; return this; } - public GlslFn body(GlslBlock block) { - body = block; + public GlslFn body(Consumer f) { + f.accept(body); return this; } + @Override public String prettyPrint() { return """ %s { diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslStruct.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslStruct.java index 5da578f56..f60c514d2 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslStruct.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslStruct.java @@ -4,15 +4,15 @@ import java.util.List; import java.util.stream.Collectors; -import dev.engine_room.flywheel.lib.util.Pair; +import com.mojang.datafixers.util.Pair; + import dev.engine_room.flywheel.lib.util.StringUtil; public class GlslStruct implements GlslBuilder.Declaration { - - private final List> fields = new ArrayList<>(); private String name; + private final List> fields = new ArrayList<>(); - public GlslStruct setName(String name) { + public GlslStruct name(String name) { this.name = name; return this; } @@ -22,12 +22,6 @@ public GlslStruct addField(String type, String name) { return this; } - private String buildFields() { - return fields.stream() - .map(p -> p.first() + ' ' + p.second() + ';') - .collect(Collectors.joining("\n")); - } - @Override public String prettyPrint() { return """ @@ -35,4 +29,10 @@ public String prettyPrint() { %s };""".formatted(name, StringUtil.indent(buildFields(), 4)); } + + private String buildFields() { + return fields.stream() + .map(p -> p.getFirst() + ' ' + p.getSecond() + ';') + .collect(Collectors.joining("\n")); + } } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslSwitch.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslSwitch.java index 37ef474b8..5112165cb 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslSwitch.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslSwitch.java @@ -4,13 +4,17 @@ import java.util.List; import java.util.stream.Collectors; -import dev.engine_room.flywheel.lib.util.Pair; +import org.jetbrains.annotations.Nullable; + +import com.mojang.datafixers.util.Pair; + import dev.engine_room.flywheel.lib.util.StringUtil; public class GlslSwitch implements GlslStmt { private final GlslExpr on; private final List> cases = new ArrayList<>(); + @Nullable private GlslBlock defaultCase = null; private GlslSwitch(GlslExpr on) { @@ -52,9 +56,9 @@ private String formatCases() { } private static String prettyPrintCase(Pair p) { - var variant = p.first() + var variant = p.getFirst() .prettyPrint(); - var block = p.second() + var block = p.getSecond() .prettyPrint(); return """ case %s: diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslUniform.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslUniform.java new file mode 100644 index 000000000..bc87770b6 --- /dev/null +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslUniform.java @@ -0,0 +1,21 @@ +package dev.engine_room.flywheel.backend.glsl.generate; + +public class GlslUniform implements GlslBuilder.Declaration { + private String type; + private String name; + + public GlslUniform type(String typeName) { + type = typeName; + return this; + } + + public GlslUniform name(String name) { + this.name = name; + return this; + } + + @Override + public String prettyPrint() { + return "uniform " + type + " " + name + ";"; + } +} diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslUniformBlock.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslUniformBlock.java index 011cfe822..f1edcbebc 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslUniformBlock.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslUniformBlock.java @@ -4,7 +4,8 @@ import java.util.List; import java.util.stream.Collectors; -import dev.engine_room.flywheel.lib.util.Pair; +import com.mojang.datafixers.util.Pair; + import dev.engine_room.flywheel.lib.util.StringUtil; public class GlslUniformBlock implements GlslBuilder.Declaration { @@ -12,20 +13,6 @@ public class GlslUniformBlock implements GlslBuilder.Declaration { private String name; private final List> members = new ArrayList<>(); - @Override - public String prettyPrint() { - return """ - layout(%s) uniform %s { - %s - };""".formatted(qualifier, name, StringUtil.indent(formatMembers(), 4)); - } - - private String formatMembers() { - return members.stream() - .map(p -> p.first() + " " + p.second() + ";") - .collect(Collectors.joining("\n")); - } - public GlslUniformBlock layout(String qualifier) { this.qualifier = qualifier; return this; @@ -40,4 +27,18 @@ public GlslUniformBlock member(String typeName, String variableName) { members.add(Pair.of(typeName, variableName)); return this; } + + @Override + public String prettyPrint() { + return """ + layout(%s) uniform %s { + %s + };""".formatted(qualifier, name, StringUtil.indent(formatMembers(), 4)); + } + + private String formatMembers() { + return members.stream() + .map(p -> p.getFirst() + " " + p.getSecond() + ";") + .collect(Collectors.joining("\n")); + } } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslVertexInput.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslVertexInput.java index c33f11c12..9763026b4 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslVertexInput.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/generate/GlslVertexInput.java @@ -1,7 +1,6 @@ package dev.engine_room.flywheel.backend.glsl.generate; public class GlslVertexInput implements GlslBuilder.Declaration { - private int binding; private String type; private String name; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/Import.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/Import.java index 159009b21..006338c6f 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/Import.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/Import.java @@ -12,17 +12,17 @@ public record Import(Span self, Span file) { public static final Pattern PATTERN = Pattern.compile("^\\s*#\\s*include\\s+\"(.*)\"", Pattern.MULTILINE); /** - * Scan the source for {@code #use "..."} directives. + * Scan the source for {@code #include "..."} directives. * Records the contents of the directive into an {@link Import} object, and marks the directive for elision. */ public static ImmutableList parseImports(SourceLines source) { - Matcher uses = PATTERN.matcher(source); + Matcher matcher = PATTERN.matcher(source); var imports = ImmutableList.builder(); - while (uses.find()) { - Span use = Span.fromMatcher(source, uses); - Span file = Span.fromMatcher(source, uses, 1); + while (matcher.find()) { + Span use = Span.fromMatcher(source, matcher); + Span file = Span.fromMatcher(source, matcher, 1); imports.add(new Import(use, file)); } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderField.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderField.java index 5ed22b77a..3f7871d43 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderField.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderField.java @@ -13,17 +13,19 @@ public class ShaderField { public static final Pattern PATTERN = Pattern.compile("layout\\s*\\(location\\s*=\\s*(\\d+)\\)\\s+(in|out)\\s+([\\w\\d]+)\\s+" + "([\\w\\d]+)"); + public final Span self; public final Span location; - public final @Nullable Decoration decoration; + public final Span qualifierSpan; + @Nullable + public final Qualifier qualifier; public final Span type; public final Span name; - public final Span self; - public ShaderField(Span self, Span location, Span inOut, Span type, Span name) { + public ShaderField(Span self, Span location, Span qualifier, Span type, Span name) { this.self = self; - this.location = location; - this.decoration = Decoration.fromSpan(inOut); + this.qualifierSpan = qualifier; + this.qualifier = Qualifier.fromSpan(qualifier); this.type = type; this.name = name; } @@ -48,14 +50,14 @@ public static ImmutableMap parseFields(SourceLines source) return fields.build(); } - public enum Decoration { + public enum Qualifier { IN, OUT, FLAT, ; @Nullable - public static Decoration fromSpan(Span span) { + public static Qualifier fromSpan(Span span) { return switch (span.toString()) { case "in" -> IN; case "out" -> OUT; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderFunction.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderFunction.java index 5d6c06bbf..4ddec0e01 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderFunction.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderFunction.java @@ -17,17 +17,16 @@ public class ShaderFunction { // https://regexr.com/60n3d public static final Pattern PATTERN = Pattern.compile("(\\w+)\\s+(\\w+)\\s*\\(([\\w,\\s]*)\\)\\s*\\{"); + public static final Pattern ARGUMENT_PATTERN = Pattern.compile("(?:(inout|in|out) )?(\\w+)\\s+(\\w+)"); + public static final Pattern ASSIGNMENT_PATTERN = Pattern.compile("(\\w+)\\s*="); - public static final Pattern argument = Pattern.compile("(?:(inout|in|out) )?(\\w+)\\s+(\\w+)"); - public static final Pattern assignment = Pattern.compile("(\\w+)\\s*="); public final Span self; + public final Span type; + public final Span name; + public final Span args; + public final Span body; - private final Span type; - private final Span name; - private final Span args; - private final Span body; - - private final ImmutableList parameters; + public final ImmutableList parameters; public ShaderFunction(Span self, Span type, Span name, Span args, Span body) { this.self = self; @@ -95,22 +94,6 @@ private static int findEndOfBlock(CharSequence source, int start) { return -1; } - public Span getType() { - return type; - } - - public Span getName() { - return name; - } - - public Span getArgs() { - return args; - } - - public Span getBody() { - return body; - } - public String call(String... args) { return name + "(" + String.join(", ", args) + ")"; } @@ -119,18 +102,10 @@ public Span getParameterType(int index) { return parameters.get(index).type; } - public ImmutableList getParameters() { - return parameters; - } - - public String returnTypeName() { - return type.get(); - } - protected ImmutableList parseArguments() { if (args.isErr() || args.isEmpty()) return ImmutableList.of(); - Matcher arguments = argument.matcher(args.get()); + Matcher arguments = ARGUMENT_PATTERN.matcher(args.get()); ImmutableList.Builder builder = ImmutableList.builder(); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderStruct.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderStruct.java index d1af3342e..3b4a7fe7a 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderStruct.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderStruct.java @@ -13,19 +13,20 @@ public class ShaderStruct { // https://regexr.com/61rpe public static final Pattern PATTERN = Pattern.compile("struct\\s+([\\w_]*)\\s*\\{(.*?)}\\s*([\\w_]*)?\\s*;\\s", Pattern.DOTALL); + public final Span self; public final Span name; public final Span body; - public final Span self; public final Span variableName; - private final ImmutableList fields; - private final ImmutableMap fields2Types; + public final ImmutableList fields; + public final ImmutableMap fields2Types; public ShaderStruct(Span self, Span name, Span body, Span variableName) { this.self = self; this.name = name; this.body = body; this.variableName = variableName; + this.fields = parseFields(); this.fields2Types = createTypeLookup(); } @@ -51,29 +52,8 @@ public static ImmutableMap parseStructs(SourceLines source return structs.build(); } - public Span getName() { - return name; - } - - public Span getBody() { - return body; - } - - public ImmutableList getFields() { - return fields; - } - - private ImmutableMap createTypeLookup() { - ImmutableMap.Builder lookup = ImmutableMap.builder(); - for (StructField field : fields) { - lookup.put(field.name.get(), field.type); - } - - return lookup.build(); - } - private ImmutableList parseFields() { - Matcher matcher = StructField.fieldPattern.matcher(body); + Matcher matcher = StructField.PATTERN.matcher(body); ImmutableList.Builder fields = ImmutableList.builder(); @@ -88,6 +68,15 @@ private ImmutableList parseFields() { return fields.build(); } + private ImmutableMap createTypeLookup() { + ImmutableMap.Builder lookup = ImmutableMap.builder(); + for (StructField field : fields) { + lookup.put(field.name.get(), field.type); + } + + return lookup.build(); + } + @Override public String toString() { return "struct " + name; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderVariable.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderVariable.java index 707c92830..6eee86538 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderVariable.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/ShaderVariable.java @@ -1,21 +1,23 @@ package dev.engine_room.flywheel.backend.glsl.parse; +import org.jetbrains.annotations.Nullable; + import dev.engine_room.flywheel.backend.glsl.span.Span; public class ShaderVariable { - + public final Span self; public final Span qualifierSpan; + @Nullable + public final Qualifier qualifier; public final Span type; public final Span name; - public final Qualifier qualifier; - public final Span self; public ShaderVariable(Span self, Span qualifier, Span type, Span name) { this.self = self; this.qualifierSpan = qualifier; + this.qualifier = Qualifier.fromSpan(qualifierSpan); this.type = type; this.name = name; - this.qualifier = Qualifier.fromSpan(qualifierSpan); } @Override @@ -27,9 +29,9 @@ public enum Qualifier { NONE, IN, OUT, - INOUT, - ERROR; + INOUT; + @Nullable public static Qualifier fromSpan(Span s) { String span = s.toString(); @@ -38,7 +40,7 @@ public static Qualifier fromSpan(Span s) { case "in" -> IN; case "inout" -> INOUT; case "out" -> OUT; - default -> ERROR; + default -> null; }; } } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/StructField.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/StructField.java index b0b3f7448..016494607 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/StructField.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/parse/StructField.java @@ -5,11 +5,11 @@ import dev.engine_room.flywheel.backend.glsl.span.Span; public class StructField { - public static final Pattern fieldPattern = Pattern.compile("(\\S+)\\s*(\\S+);"); - public final Span self; + public static final Pattern PATTERN = Pattern.compile("(\\S+)\\s*(\\S+);"); - public Span type; - public Span name; + public final Span self; + public final Span type; + public final Span name; public StructField(Span self, Span type, Span name) { this.self = self; @@ -17,14 +17,6 @@ public StructField(Span self, Span type, Span name) { this.name = name; } - public Span getType() { - return type; - } - - public Span getName() { - return name; - } - @Override public String toString() { return type + " " + name; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/span/StringSpan.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/span/StringSpan.java index 547ffbb0c..75d50165b 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/span/StringSpan.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/span/StringSpan.java @@ -3,7 +3,6 @@ import dev.engine_room.flywheel.backend.glsl.SourceLines; public class StringSpan extends Span { - public StringSpan(SourceLines in, int start, int end) { super(in, start, end); } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelCache.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelCache.java deleted file mode 100644 index 2b99cde80..000000000 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelCache.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.engine_room.flywheel.lib.model; - -import java.util.function.Function; - -import dev.engine_room.flywheel.api.model.Model; - -public final class ModelCache extends ResourceReloadCache { - public ModelCache(Function factory) { - super(factory); - } -} diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelHolder.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelHolder.java deleted file mode 100644 index 7e838bf70..000000000 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelHolder.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.engine_room.flywheel.lib.model; - -import java.util.function.Supplier; - -import dev.engine_room.flywheel.api.model.Model; - -public final class ModelHolder extends ResourceReloadHolder { - public ModelHolder(Supplier factory) { - super(factory); - } -} diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java index 93a4849a5..9e0e3a813 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java @@ -9,6 +9,7 @@ import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder; import dev.engine_room.flywheel.lib.model.baked.PartialModel; import dev.engine_room.flywheel.lib.transform.TransformStack; +import dev.engine_room.flywheel.lib.util.ResourceReloadCache; import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.BlockState; @@ -19,11 +20,11 @@ * method with the same parameters will return the same object. */ public final class Models { - private static final ModelCache BLOCK_STATE = new ModelCache<>(it -> BlockModelBuilder.create(it) + private static final ResourceReloadCache BLOCK_STATE = new ResourceReloadCache<>(it -> BlockModelBuilder.create(it) .build()); - private static final ModelCache PARTIAL = new ModelCache<>(it -> BakedModelBuilder.create(it.get()) + private static final ResourceReloadCache PARTIAL = new ResourceReloadCache<>(it -> BakedModelBuilder.create(it.get()) .build()); - private static final ModelCache> TRANSFORMED_PARTIAL = new ModelCache<>(TransformedPartial::create); + private static final ResourceReloadCache, Model> TRANSFORMED_PARTIAL = new ResourceReloadCache<>(TransformedPartial::create); private Models() { } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/MeshTree.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/MeshTree.java index f9d0bd38c..98c10fc0c 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/MeshTree.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/MeshTree.java @@ -10,8 +10,8 @@ import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.lib.internal.FlwLibLink; import dev.engine_room.flywheel.lib.memory.MemoryBlock; -import dev.engine_room.flywheel.lib.model.ResourceReloadCache; import dev.engine_room.flywheel.lib.model.SimpleQuadMesh; +import dev.engine_room.flywheel.lib.util.ResourceReloadCache; import dev.engine_room.flywheel.lib.vertex.PosTexNormalVertexView; import dev.engine_room.flywheel.lib.vertex.VertexView; import net.minecraft.client.Minecraft; diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelTrees.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelTrees.java index 7c87c6275..7b9599f82 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelTrees.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelTrees.java @@ -10,9 +10,9 @@ import dev.engine_room.flywheel.api.material.Material; import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.lib.model.ResourceReloadCache; import dev.engine_room.flywheel.lib.model.RetexturedMesh; import dev.engine_room.flywheel.lib.model.SingleMeshModel; +import dev.engine_room.flywheel.lib.util.ResourceReloadCache; import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.renderer.texture.TextureAtlasSprite; diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/util/FlwUtil.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/FlwUtil.java deleted file mode 100644 index c00d10d97..000000000 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/util/FlwUtil.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.engine_room.flywheel.lib.util; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Set; -import java.util.WeakHashMap; - -public final class FlwUtil { - private FlwUtil() { - } - - public static int[] initArray(int size, int fill) { - var out = new int[size]; - Arrays.fill(out, fill); - return out; - } - - public static Set createWeakHashSet() { - return Collections.newSetFromMap(new WeakHashMap<>()); - } -} diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/util/Pair.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/Pair.java deleted file mode 100644 index a54e9e297..000000000 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/util/Pair.java +++ /dev/null @@ -1,36 +0,0 @@ -package dev.engine_room.flywheel.lib.util; - -import java.util.Objects; - -public record Pair(F first, S second) { - public static Pair of(F first, S second) { - return new Pair<>(first, second); - } - - public Pair swap() { - return Pair.of(second, first); - } - - public Pair copy() { - return Pair.of(first, second); - } - - @Override - public boolean equals(final Object obj) { - if (obj == this) return true; - if (obj instanceof final Pair other) { - return Objects.equals(first, other.first) && Objects.equals(second, other.second); - } - return false; - } - - @Override - public int hashCode() { - return (Objects.hashCode(first) * 31) ^ Objects.hashCode(second); - } - - @Override - public String toString() { - return "(" + first + ", " + second + ")"; - } -} diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ResourceReloadCache.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadCache.java similarity index 72% rename from common/src/lib/java/dev/engine_room/flywheel/lib/model/ResourceReloadCache.java rename to common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadCache.java index 363cf61b2..dcacb38d3 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ResourceReloadCache.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadCache.java @@ -1,16 +1,16 @@ -package dev.engine_room.flywheel.lib.model; +package dev.engine_room.flywheel.lib.util; +import java.util.Collections; import java.util.Map; import java.util.Set; +import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import org.jetbrains.annotations.ApiStatus; -import dev.engine_room.flywheel.lib.util.FlwUtil; - -public class ResourceReloadCache implements Function { - private static final Set> ALL = FlwUtil.createWeakHashSet(); +public final class ResourceReloadCache implements Function { + private static final Set> ALL = Collections.newSetFromMap(new WeakHashMap<>()); private final Function factory; private final Map map = new ConcurrentHashMap<>(); diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ResourceReloadHolder.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadHolder.java similarity index 76% rename from common/src/lib/java/dev/engine_room/flywheel/lib/model/ResourceReloadHolder.java rename to common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadHolder.java index dd00c5e2a..9ff36d40c 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ResourceReloadHolder.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadHolder.java @@ -1,15 +1,15 @@ -package dev.engine_room.flywheel.lib.model; +package dev.engine_room.flywheel.lib.util; +import java.util.Collections; import java.util.Set; +import java.util.WeakHashMap; import java.util.function.Supplier; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import dev.engine_room.flywheel.lib.util.FlwUtil; - -public class ResourceReloadHolder implements Supplier { - private static final Set> ALL = FlwUtil.createWeakHashSet(); +public final class ResourceReloadHolder implements Supplier { + private static final Set> ALL = Collections.newSetFromMap(new WeakHashMap<>()); private final Supplier factory; @Nullable private volatile T obj; diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceUtil.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceUtil.java index 9eb0f1419..8aca2b9be 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceUtil.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceUtil.java @@ -53,10 +53,11 @@ public static ResourceLocation readFlywheelDefault(StringReader reader) throws C } } + /** + * Same as {@link ResourceLocation#toDebugFileName()}, but also removes the file extension. + */ public static String toDebugFileNameNoExtension(ResourceLocation resourceLocation) { - var stringLoc = resourceLocation.toString(); - return stringLoc.substring(0, stringLoc.lastIndexOf('.')) - .replace('/', '_') - .replace(':', '_'); + var stringLoc = resourceLocation.toDebugFileName(); + return stringLoc.substring(0, stringLoc.lastIndexOf('.')); } } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/util/StringUtil.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/StringUtil.java index 93364d43a..6cf5bfcbd 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/util/StringUtil.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/util/StringUtil.java @@ -57,12 +57,6 @@ public static String formatAddress(long address) { return "0x" + Long.toHexString(address); } - public static String args(String functionName, Object... args) { - return functionName + '(' + Arrays.stream(args) - .map(Object::toString) - .collect(Collectors.joining(", ")) + ')'; - } - public static String trimPrefix(String s, String prefix) { if (s.startsWith(prefix)) { return s.substring(prefix.length()); diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/util/Unit.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/Unit.java deleted file mode 100644 index 2544e4286..000000000 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/util/Unit.java +++ /dev/null @@ -1,5 +0,0 @@ -package dev.engine_room.flywheel.lib.util; - -public enum Unit { - INSTANCE; -} diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/FireComponent.java b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/FireComponent.java index 13d60a58d..0e0cb8301 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/FireComponent.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/FireComponent.java @@ -15,9 +15,9 @@ import dev.engine_room.flywheel.lib.instance.TransformedInstance; import dev.engine_room.flywheel.lib.material.Materials; import dev.engine_room.flywheel.lib.material.SimpleMaterial; -import dev.engine_room.flywheel.lib.model.ModelCache; import dev.engine_room.flywheel.lib.model.QuadMesh; import dev.engine_room.flywheel.lib.model.SingleMeshModel; +import dev.engine_room.flywheel.lib.util.ResourceReloadCache; import dev.engine_room.flywheel.lib.visual.util.SmartRecycler; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -36,7 +36,7 @@ public final class FireComponent implements EntityComponent { // Parameterize by the material instead of the sprite // because Material#sprite is a surprisingly heavy operation // and because sprites are invalidated after a resource reload. - private static final ModelCache FIRE_MODELS = new ModelCache<>(texture -> { + private static final ResourceReloadCache FIRE_MODELS = new ResourceReloadCache<>(texture -> { return new SingleMeshModel(new FireMesh(texture.sprite()), FIRE_MATERIAL); }); diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/FlwConfig.java b/common/src/main/java/dev/engine_room/flywheel/impl/FlwConfig.java index ba661d25c..760711c0f 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/FlwConfig.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/FlwConfig.java @@ -1,6 +1,7 @@ package dev.engine_room.flywheel.impl; import dev.engine_room.flywheel.api.backend.Backend; +import dev.engine_room.flywheel.backend.BackendConfig; public interface FlwConfig { FlwConfig INSTANCE = FlwImplXplat.INSTANCE.getConfig(); @@ -10,4 +11,6 @@ public interface FlwConfig { boolean limitUpdates(); int workerThreads(); + + BackendConfig backendConfig(); } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/FlwImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/FlwImpl.java index d1eafb15e..2b33206ac 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/FlwImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/FlwImpl.java @@ -35,7 +35,7 @@ public static void init() { StandardMaterialShaders.init(); // backend - FlwBackend.init(); + FlwBackend.init(FlwConfig.INSTANCE.backendConfig()); // vanilla VanillaVisuals.init(); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/LightSmoothnessArgument.java b/common/src/main/java/dev/engine_room/flywheel/impl/LightSmoothnessArgument.java similarity index 93% rename from common/src/backend/java/dev/engine_room/flywheel/backend/LightSmoothnessArgument.java rename to common/src/main/java/dev/engine_room/flywheel/impl/LightSmoothnessArgument.java index 871184d5d..da04731c5 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/LightSmoothnessArgument.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/LightSmoothnessArgument.java @@ -1,4 +1,4 @@ -package dev.engine_room.flywheel.backend; +package dev.engine_room.flywheel.impl; import dev.engine_room.flywheel.backend.compile.LightSmoothness; import net.minecraft.commands.arguments.StringRepresentableArgument; diff --git a/common/src/test/java/dev/engine_room/flywheel/backend/glsl/TestBase.java b/common/src/test/java/dev/engine_room/flywheel/backend/glsl/TestBase.java index fe6be7887..5c159daf8 100644 --- a/common/src/test/java/dev/engine_room/flywheel/backend/glsl/TestBase.java +++ b/common/src/test/java/dev/engine_room/flywheel/backend/glsl/TestBase.java @@ -30,10 +30,10 @@ static E assertSimpleNestedErrorsToDepth(Class finalErr var pair = assertSingletonList(includeError.innerErrors()); for (int i = 1; i < depth; i++) { - includeError = assertInstanceOf(LoadError.IncludeError.class, pair.second()); + includeError = assertInstanceOf(LoadError.IncludeError.class, pair.getSecond()); pair = assertSingletonList(includeError.innerErrors()); } - return assertInstanceOf(finalErrType, pair.second()); + return assertInstanceOf(finalErrType, pair.getSecond()); } public static SourceFile findAndAssertSuccess(MockShaderSources sources, ResourceLocation loc) { diff --git a/common/src/test/java/dev/engine_room/flywheel/backend/glsl/TestShaderSourceLoading.java b/common/src/test/java/dev/engine_room/flywheel/backend/glsl/TestShaderSourceLoading.java index 51bcccf91..3acf1ba2d 100644 --- a/common/src/test/java/dev/engine_room/flywheel/backend/glsl/TestShaderSourceLoading.java +++ b/common/src/test/java/dev/engine_room/flywheel/backend/glsl/TestShaderSourceLoading.java @@ -129,11 +129,11 @@ void testSelfInclude() { var shouldBeRecursiveIncludePair = assertSingletonList(aErr.innerErrors()); - var circularDependency = assertInstanceOf(LoadError.CircularDependency.class, shouldBeRecursiveIncludePair.second()); + var circularDependency = assertInstanceOf(LoadError.CircularDependency.class, shouldBeRecursiveIncludePair.getSecond()); assertEquals(ImmutableList.of(FLW_A, FLW_A), circularDependency.stack()); assertEquals(FLW_A, circularDependency.offender()); - assertEquals(FLW_A.toString(), shouldBeRecursiveIncludePair.first() + assertEquals(FLW_A.toString(), shouldBeRecursiveIncludePair.getFirst() .toString()); } diff --git a/common/src/test/java/dev/engine_room/flywheel/impl/task/PlanExecutionTest.java b/common/src/test/java/dev/engine_room/flywheel/impl/task/PlanExecutionTest.java index 90991fbd8..9a967baac 100644 --- a/common/src/test/java/dev/engine_room/flywheel/impl/task/PlanExecutionTest.java +++ b/common/src/test/java/dev/engine_room/flywheel/impl/task/PlanExecutionTest.java @@ -21,8 +21,8 @@ import dev.engine_room.flywheel.lib.task.Synchronizer; import dev.engine_room.flywheel.lib.task.UnitPlan; import dev.engine_room.flywheel.lib.task.functional.RunnableWithContext; -import dev.engine_room.flywheel.lib.util.Unit; import it.unimi.dsi.fastutil.ints.IntArrayList; +import net.minecraft.util.Unit; class PlanExecutionTest { protected static ParallelTaskExecutor EXECUTOR; diff --git a/common/src/test/java/dev/engine_room/flywheel/lib/task/PlanCompositionTest.java b/common/src/test/java/dev/engine_room/flywheel/lib/task/PlanCompositionTest.java index 2569b5848..d35b7ac26 100644 --- a/common/src/test/java/dev/engine_room/flywheel/lib/task/PlanCompositionTest.java +++ b/common/src/test/java/dev/engine_room/flywheel/lib/task/PlanCompositionTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import dev.engine_room.flywheel.api.task.Plan; -import dev.engine_room.flywheel.lib.util.Unit; +import net.minecraft.util.Unit; public class PlanCompositionTest { public static final Plan SIMPLE = SimplePlan.of(() -> { diff --git a/fabric/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java b/fabric/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java index 23a08243e..661f58bc7 100644 --- a/fabric/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java +++ b/fabric/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java @@ -1,22 +1,12 @@ package dev.engine_room.flywheel.backend; -import org.jetbrains.annotations.UnknownNullability; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.state.BlockState; public class FlwBackendXplatImpl implements FlwBackendXplat { - @UnknownNullability - public static BackendConfig CONFIG; - @Override public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) { return state.getLightEmission(); } - - @Override - public BackendConfig getConfig() { - return CONFIG; - } } diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java index aa04433b5..cf51ddf48 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java @@ -16,7 +16,6 @@ import dev.engine_room.flywheel.api.backend.BackendManager; import dev.engine_room.flywheel.backend.BackendConfig; import dev.engine_room.flywheel.backend.FlwBackend; -import dev.engine_room.flywheel.backend.FlwBackendXplatImpl; import dev.engine_room.flywheel.backend.compile.LightSmoothness; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.ResourceLocationException; @@ -39,16 +38,14 @@ public class FabricFlwConfig implements FlwConfig { private final File file; - public final FabricBackendConfig backendConfig = new FabricBackendConfig(); - public Backend backend = BackendManager.defaultBackend(); public boolean limitUpdates = LIMIT_UPDATES_DEFAULT; public int workerThreads = WORKER_THREADS_DEFAULT; + public final FabricBackendConfig backendConfig = new FabricBackendConfig(); + public FabricFlwConfig(File file) { this.file = file; - - FlwBackendXplatImpl.CONFIG = backendConfig; } @Override @@ -66,6 +63,11 @@ public int workerThreads() { return workerThreads; } + @Override + public BackendConfig backendConfig() { + return backendConfig; + } + public void load() { if (file.exists()) { try (FileReader reader = new FileReader(file)) { @@ -177,7 +179,7 @@ public JsonObject toJson() { object.addProperty("backend", Backend.REGISTRY.getIdOrThrow(backend).toString()); object.addProperty("limitUpdates", limitUpdates); object.addProperty("workerThreads", workerThreads); - object.add("flw_backend", backendConfig.toJson()); + object.add("flw_backends", backendConfig.toJson()); return object; } diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java index 6bf004116..72ff04be9 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java @@ -8,7 +8,6 @@ import dev.engine_room.flywheel.api.backend.Backend; import dev.engine_room.flywheel.api.backend.BackendManager; -import dev.engine_room.flywheel.backend.LightSmoothnessArgument; import dev.engine_room.flywheel.backend.compile.LightSmoothness; import dev.engine_room.flywheel.backend.engine.uniform.DebugMode; import dev.engine_room.flywheel.backend.engine.uniform.FrameUniforms; diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java index 4e33b3145..50d5129a9 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java @@ -5,13 +5,12 @@ import dev.engine_room.flywheel.api.Flywheel; import dev.engine_room.flywheel.api.event.EndClientResourceReloadCallback; import dev.engine_room.flywheel.api.event.ReloadLevelRendererCallback; -import dev.engine_room.flywheel.backend.LightSmoothnessArgument; import dev.engine_room.flywheel.backend.compile.FlwProgramsReloader; import dev.engine_room.flywheel.backend.engine.uniform.Uniforms; import dev.engine_room.flywheel.impl.visualization.VisualizationEventHandler; -import dev.engine_room.flywheel.lib.model.ResourceReloadCache; -import dev.engine_room.flywheel.lib.model.ResourceReloadHolder; import dev.engine_room.flywheel.lib.model.baked.PartialModelEventHandler; +import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.ResourceReloadHolder; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents; diff --git a/forge/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java b/forge/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java index c8eb18fb7..f49549f3e 100644 --- a/forge/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java +++ b/forge/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java @@ -1,22 +1,12 @@ package dev.engine_room.flywheel.backend; -import org.jetbrains.annotations.UnknownNullability; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.state.BlockState; public class FlwBackendXplatImpl implements FlwBackendXplat { - @UnknownNullability - public static BackendConfig CONFIG; - @Override public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) { return state.getLightEmission(level, pos); } - - @Override - public BackendConfig getConfig() { - return CONFIG; - } } diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java b/forge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java index 870680a66..ee46048d5 100644 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java +++ b/forge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java @@ -6,7 +6,6 @@ import dev.engine_room.flywheel.api.backend.Backend; import dev.engine_room.flywheel.api.backend.BackendManager; -import dev.engine_room.flywheel.backend.LightSmoothnessArgument; import dev.engine_room.flywheel.backend.compile.LightSmoothness; import dev.engine_room.flywheel.backend.engine.uniform.DebugMode; import dev.engine_room.flywheel.backend.engine.uniform.FrameUniforms; diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java b/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java index 11acf03f8..205db0497 100644 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java +++ b/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java @@ -6,14 +6,13 @@ import dev.engine_room.flywheel.api.Flywheel; import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent; import dev.engine_room.flywheel.api.event.ReloadLevelRendererEvent; -import dev.engine_room.flywheel.backend.LightSmoothnessArgument; import dev.engine_room.flywheel.backend.compile.FlwProgramsReloader; import dev.engine_room.flywheel.backend.engine.uniform.Uniforms; import dev.engine_room.flywheel.impl.visualization.VisualizationEventHandler; -import dev.engine_room.flywheel.lib.model.ResourceReloadCache; -import dev.engine_room.flywheel.lib.model.ResourceReloadHolder; import dev.engine_room.flywheel.lib.model.baked.PartialModelEventHandler; import dev.engine_room.flywheel.lib.util.LevelAttached; +import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.ResourceReloadHolder; import net.minecraft.client.Minecraft; import net.minecraft.commands.synchronization.ArgumentTypeInfos; import net.minecraftforge.api.distmarker.Dist; diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java b/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java index b19ae9fea..dbf03d087 100644 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java +++ b/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java @@ -6,7 +6,6 @@ import dev.engine_room.flywheel.api.backend.Backend; import dev.engine_room.flywheel.api.backend.BackendManager; import dev.engine_room.flywheel.backend.BackendConfig; -import dev.engine_room.flywheel.backend.FlwBackendXplatImpl; import dev.engine_room.flywheel.backend.compile.LightSmoothness; import net.minecraft.ResourceLocationException; import net.minecraft.resources.ResourceLocation; @@ -24,8 +23,6 @@ private ForgeFlwConfig() { Pair clientPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); this.client = clientPair.getLeft(); clientSpec = clientPair.getRight(); - - FlwBackendXplatImpl.CONFIG = client.backendConfig; } @Override @@ -68,6 +65,11 @@ public int workerThreads() { return client.workerThreads.get(); } + @Override + public BackendConfig backendConfig() { + return client.backendConfig; + } + public void registerSpecs(ModLoadingContext context) { context.registerConfig(ModConfig.Type.CLIENT, clientSpec); } @@ -90,7 +92,7 @@ private ClientConfig(ForgeConfigSpec.Builder builder) { .defineInRange("workerThreads", -1, -1, Runtime.getRuntime() .availableProcessors()); - builder.comment("Config options for flywheel's build-in backends.") + builder.comment("Config options for Flywheel's built-in backends.") .push("flw_backends"); backendConfig = new ForgeBackendConfig(builder);