From f9e5d332965fa78784962774894e37e632bdbddd Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:12:48 -0800 Subject: [PATCH] Automated nullability - Remove most NotNull annotations - Automatically generate missing package-info.java files which contain annotations to establish that everything is not null by default - Remove CurseForge integration from build script - Fix some other formatting --- .gitignore | 2 + build.gradle | 19 +- gradle.properties | 15 +- gradle/package-infos.gradle | 70 +++++ .../jozufozu/flywheel/api/backend/Engine.java | 4 +- .../flywheel/api/context/Context.java | 4 +- .../flywheel/api/vertex/VertexList.java | 2 +- .../compile/component/IndirectComponent.java | 289 +++++++++--------- .../backend/compile/core/Compilation.java | 2 - .../backend/compile/core/Compile.java | 13 +- .../backend/compile/core/CompilerStats.java | 2 - .../compile/core/FailedCompilation.java | 4 - .../backend/compile/package-info.java | 6 - .../engine/indirect/IndirectDrawManager.java | 3 - .../engine/indirect/StagingBuffer.java | 2 - .../backend/engine/instancing/DrawCall.java | 10 +- .../backend/engine/instancing/EboCache.java | 2 - .../engine/instancing/InstancedCrumbling.java | 3 - .../instancing/InstancedDrawManager.java | 3 - .../backend/gl/buffer/GlBufferType.java | 2 +- .../flywheel/backend/glsl/ShaderSources.java | 5 +- .../flywheel/backend/glsl/SourceFile.java | 2 - .../flywheel/backend/glsl/SourceLines.java | 10 +- .../backend/glsl/error/ErrorBuilder.java | 2 - .../backend/glsl/generate/GlslBuilder.java | 34 +-- .../backend/glsl/generate/GlslSwitch.java | 23 +- .../glsl/generate/GlslUniformBlock.java | 32 +- .../flywheel/backend/glsl/package-info.java | 6 - .../backend/glsl/parse/ShaderStruct.java | 1 - .../flywheel/backend/glsl/span/Span.java | 4 +- .../backend/glsl/span/StringSpan.java | 2 +- .../impl/task/ParallelTaskExecutor.java | 3 +- .../impl/visualization/FrameContext.java | 2 - .../storage/VisualUpdatePlan.java | 3 - .../jozufozu/flywheel/lib/box/MutableBox.java | 2 +- .../flywheel/lib/model/ModelUtil.java | 2 +- .../lib/model/baked/PartialModel.java | 3 - .../lib/task/functional/package-info.java | 8 + .../flywheel/lib/util/ResourceUtil.java | 3 - .../visual/SimpleBlockEntityVisualizer.java | 4 +- .../lib/visual/SimpleEntityVisualizer.java | 4 +- .../flywheel/vanilla/MinecartVisual.java | 2 +- src/main/resources/META-INF/mods.toml | 1 - .../backend/glsl/MockShaderSources.java | 2 - .../flywheel/backend/glsl/TestBase.java | 5 - .../backend/glsl/TestErrorMessages.java | 2 - 46 files changed, 297 insertions(+), 327 deletions(-) create mode 100644 gradle/package-infos.gradle delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/compile/package-info.java delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/glsl/package-info.java diff --git a/.gitignore b/.gitignore index 8b80aec20..88fc08b84 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,6 @@ local.properties # PDT-specific .buildpath +# Other mcmodsrepo +src/*/generatedPackageInfos/ diff --git a/build.gradle b/build.gradle index 65b7f7cfe..9446108f3 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,6 @@ plugins { id 'net.minecraftforge.gradle' version "${forgegradle_version}" id 'org.parchmentmc.librarian.forgegradle' version "${librarian_version}" id 'org.spongepowered.mixin' version "${mixingradle_version}" - id 'com.matthewprenger.cursegradle' version "${cursegradle_version}" } jarJar.enable() @@ -166,6 +165,8 @@ tasks.named('processResources', ProcessResources).configure { } } +apply from: rootProject.file('gradle/package-infos.gradle') + void addLicense(jarTask) { jarTask.from('LICENSE.md') { rename '(.*)\\.(.*)', '$1_' + archivesBaseName + '.$2' @@ -230,19 +231,3 @@ publishing { } } } - -tasks.curseforge.enabled = !dev && project.hasProperty('jozu_curseforge_key') - -curseforge { - if (project.hasProperty('jozu_curseforge_key')) { - apiKey = project.jozu_curseforge_key - } - - project { - id = project.projectId - changelog = file('changelog.txt') - releaseType = project.curse_type - mainArtifact jar - addGameVersion '1.20.1' - } -} diff --git a/gradle.properties b/gradle.properties index 43ea1cc3d..878a41fce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,11 +5,11 @@ org.gradle.daemon = false mod_version = 1.0.0-alpha artifact_minecraft_version = 1.20.1 minecraft_version = 1.20.1 -forge_version=47.2.19 +forge_version = 47.2.19 # Version ranges for the mods.toml -minecraft_version_range=[1.20.1,1.20.3) -forge_version_range=[47,) -loader_version_range=[47,) +minecraft_version_range = [1.20.1,1.20.2) +forge_version_range = [47,) +loader_version_range = [47,) # build dependency versions forgegradle_version = [6.0.16,6.2) @@ -18,10 +18,3 @@ mixin_version = 0.8.5 librarian_version = 1.+ cursegradle_version = 1.4.0 parchment_version = 2023.09.03 - -# curseforge info -projectId = 486392 -curse_type = release - -# github info -github_project = Jozufozu/Flywheel diff --git a/gradle/package-infos.gradle b/gradle/package-infos.gradle new file mode 100644 index 000000000..b6877b240 --- /dev/null +++ b/gradle/package-infos.gradle @@ -0,0 +1,70 @@ +// Adapted from https://github.com/FabricMC/fabric/blob/31787236d242247e0b6c4ae806b1cfaa7042a62c/gradle/package-info.gradle, which is licensed under Apache 2.0. + +import java.nio.file.Files + +setupGeneratePackageInfos(sourceSets.main) + +def setupGeneratePackageInfos(SourceSet sourceSet) { + // We have to capture the source set name for the lazy string literals, + // otherwise it'll just be whatever the last source set is in the list. + def sourceSetName = sourceSet.name + def taskName = sourceSet.getTaskName('generate', 'PackageInfos') + def task = tasks.register(taskName, GeneratePackageInfosTask) { + group = 'flywheel' + description = "Generates package-info files for $sourceSetName packages." + + // Only apply to default source directory since we also add the generated + // sources to the source set. + sourceRoot = file("src/$sourceSetName/java") + outputDir = file("src/$sourceSetName/generatedPackageInfos") + } + sourceSet.java.srcDir task + + def cleanTask = tasks.register(sourceSet.getTaskName('clean', 'PackageInfos'), Delete) { + group = 'flywheel' + delete file("src/$sourceSetName/generatedPackageInfos") + } + clean.dependsOn cleanTask +} + +class GeneratePackageInfosTask extends DefaultTask { + @SkipWhenEmpty + @InputDirectory + final DirectoryProperty sourceRoot = project.objects.directoryProperty() + + @OutputDirectory + final DirectoryProperty outputDir = project.objects.directoryProperty() + + @TaskAction + def run() { + def output = outputDir.get().asFile.toPath() + output.deleteDir() + def root = sourceRoot.get().asFile.toPath() + + root.eachDirRecurse { + def containsJava = Files.list(it).any { + Files.isRegularFile(it) && it.fileName.toString().endsWith('.java') + } + + if (containsJava && Files.notExists(it.resolve('package-info.java'))) { + def relativePath = root.relativize(it) + def target = output.resolve(relativePath) + Files.createDirectories(target) + + target.resolve('package-info.java').withWriter { + def packageName = relativePath.toString().replace(File.separator, '.') + it.write("""@ParametersAreNonnullByDefault + |@FieldsAreNonnullByDefault + |@MethodsReturnNonnullByDefault + |package $packageName; + | + |import javax.annotation.ParametersAreNonnullByDefault; + | + |import net.minecraft.FieldsAreNonnullByDefault; + |import net.minecraft.MethodsReturnNonnullByDefault; + |""".stripMargin()) + } + } + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java b/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java index 78c1f5c52..3e9b7bd59 100644 --- a/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java +++ b/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java @@ -2,8 +2,6 @@ package com.jozufozu.flywheel.api.backend; import java.util.List; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.api.event.RenderContext; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; @@ -67,6 +65,6 @@ public interface Engine extends InstancerProvider { * @param pos The position of the block. * @param instances The instances associated with the BE at this position. */ - record CrumblingBlock(int progress, BlockPos pos, List<@NotNull Instance> instances) { + record CrumblingBlock(int progress, BlockPos pos, List instances) { } } diff --git a/src/main/java/com/jozufozu/flywheel/api/context/Context.java b/src/main/java/com/jozufozu/flywheel/api/context/Context.java index b66b008d0..7e448e596 100644 --- a/src/main/java/com/jozufozu/flywheel/api/context/Context.java +++ b/src/main/java/com/jozufozu/flywheel/api/context/Context.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.api.context; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.api.registry.Registry; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.impl.RegistryImpl; @@ -11,7 +9,7 @@ import net.minecraft.resources.ResourceLocation; public interface Context { static Registry REGISTRY = RegistryImpl.create(); - void onProgramLink(@NotNull GlProgram program); + void onProgramLink(GlProgram program); ResourceLocation vertexShader(); diff --git a/src/main/java/com/jozufozu/flywheel/api/vertex/VertexList.java b/src/main/java/com/jozufozu/flywheel/api/vertex/VertexList.java index a3eb9e3ff..f844ad5b3 100644 --- a/src/main/java/com/jozufozu/flywheel/api/vertex/VertexList.java +++ b/src/main/java/com/jozufozu/flywheel/api/vertex/VertexList.java @@ -44,7 +44,7 @@ public interface VertexList { return dest.set(x(i), y(i), z(i)); } - default Vector3f getNormal(int i, Vector3f dest) { + default Vector3f getNormal(int i, Vector3f dest) { return dest.set(normalX(i), normalY(i), normalZ(i)); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java index 8cc4b090a..7d7e31ccf 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java @@ -6,8 +6,6 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.layout.FloatRepr; @@ -126,152 +124,38 @@ public class IndirectComponent implements SourceComponent { throw new IllegalArgumentException("Unknown type " + type); } - private static GlslExpr unpackMatrix(String name, GlslStruct packed, MatrixElementType matrix) { - var repr = matrix.repr(); - - int rows = matrix.rows(); - int columns = matrix.columns(); - - List args = new ArrayList<>(); - - for (int i = 0; i < columns; i++) { - args.add(unpackFloatVector(name + "_" + i, repr, packed, rows)); - } - - return GlslExpr.call("mat" + columns + "x" + rows, args); - } - private static GlslExpr unpackScalar(String fieldName, GlslStruct packed, ScalarElementType scalar) { var repr = scalar.repr(); - if (repr instanceof FloatRepr floatRepr) { - return unpackFloatScalar(fieldName, floatRepr, packed); - } else if (repr instanceof IntegerRepr intRepr) { + if (repr instanceof IntegerRepr intRepr) { return unpackIntScalar(fieldName, intRepr, packed); } else if (repr instanceof UnsignedIntegerRepr unsignedIntegerRepr) { return unpackUnsignedScalar(fieldName, unsignedIntegerRepr, packed); + } else if (repr instanceof FloatRepr floatRepr) { + return unpackFloatScalar(fieldName, floatRepr, packed); } throw new IllegalArgumentException("Unknown repr " + repr); } - private static GlslExpr unpackVector(String fieldName, GlslStruct packed, VectorElementType vector) { - var repr = vector.repr(); - - int size = vector.size(); - - if (repr instanceof FloatRepr floatRepr) { - return unpackFloatVector(fieldName, floatRepr, packed, size); - } else if (repr instanceof IntegerRepr intRepr) { - return unpackIntVector(fieldName, intRepr, packed, size); - } else if (repr instanceof UnsignedIntegerRepr unsignedIntegerRepr) { - return unpackUnsignedVector(fieldName, unsignedIntegerRepr, packed, size); - } - - throw new IllegalArgumentException("Unknown repr " + repr); - } - - private static GlslExpr unpackFloatVector(String fieldName, FloatRepr floatRepr, GlslStruct packed, int size) { - return switch (floatRepr) { - case NORMALIZED_BYTE -> unpackBuiltin(fieldName, packed, size, "unpackSnorm4x8"); - case NORMALIZED_UNSIGNED_BYTE -> unpackBuiltin(fieldName, packed, size, "unpackUnorm4x8"); - case NORMALIZED_SHORT -> unpackBuiltin(fieldName, packed, size, "unpackSnorm2x16"); - case NORMALIZED_UNSIGNED_SHORT -> unpackBuiltin(fieldName, packed, size, "unpackUnorm2x16"); - case NORMALIZED_INT -> unpack(fieldName, packed, size, "int", "vec" + size, e -> e.div(2147483647f) - .clamp(-1, 1)); - case NORMALIZED_UNSIGNED_INT -> - unpack(fieldName, packed, size, "uint", "vec" + size, e -> e.div(4294967295f)); - case BYTE -> unpackByteBacked(fieldName, packed, size, "vec" + size, e -> e.cast("int") - .cast("float")); - case UNSIGNED_BYTE -> unpackByteBacked(fieldName, packed, size, "vec" + size, e -> e.cast("float")); - case SHORT -> unpackShortBacked(fieldName, packed, size, "vec" + size, e -> e.cast("int") - .cast("float")); - case UNSIGNED_SHORT -> unpackShortBacked(fieldName, packed, size, "vec" + size, e -> e.cast("float")); - case INT -> unpack(fieldName, packed, size, "int", "vec" + size, e -> e.cast("float")); - case UNSIGNED_INT -> unpack(fieldName, packed, size, "float", "vec" + size, e -> e.cast("float")); - case FLOAT -> unpack(fieldName, packed, size, "float", "vec" + size); + private static GlslExpr unpackIntScalar(String fieldName, IntegerRepr intRepr, GlslStruct packed) { + return switch (intRepr) { + case BYTE -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFF) + .cast("int")); + case SHORT -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFFFF) + .cast("int")); + case INT -> unpackScalar(fieldName, packed, "int"); }; } - private static GlslExpr unpackUnsignedVector(String fieldName, UnsignedIntegerRepr unsignedIntegerRepr, GlslStruct packed, int size) { - return switch (unsignedIntegerRepr) { - case UNSIGNED_BYTE -> unpackByteBacked(fieldName, packed, size, "uvec" + size, e -> e.cast("uint")); - case UNSIGNED_SHORT -> unpackShortBacked(fieldName, packed, size, "uvec" + size, e -> e.cast("uint")); - case UNSIGNED_INT -> unpack(fieldName, packed, size, "uint", "uvec" + size); - }; - } - - private static GlslExpr unpackIntVector(String fieldName, IntegerRepr repr, GlslStruct packed, int size) { + private static GlslExpr unpackUnsignedScalar(String fieldName, UnsignedIntegerRepr repr, GlslStruct packed) { return switch (repr) { - case BYTE -> unpackByteBacked(fieldName, packed, size, "ivec" + size, e -> e.cast("int")); - case SHORT -> unpackShortBacked(fieldName, packed, size, "ivec" + size, e -> e.cast("int")); - case INT -> unpack(fieldName, packed, size, "int", "ivec" + size); + case UNSIGNED_BYTE -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFF)); + case UNSIGNED_SHORT -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFFFF)); + case UNSIGNED_INT -> unpackScalar(fieldName, packed, "uint"); }; } - @NotNull - private static GlslExpr unpack(String fieldName, GlslStruct packed, int size, String backingType, String outType) { - return unpack(fieldName, packed, size, backingType, outType, Function.identity()); - } - - @NotNull - private static GlslExpr unpack(String fieldName, GlslStruct packed, int size, String backingType, String outType, Function perElement) { - List args = new ArrayList<>(); - for (int i = 0; i < size; i++) { - var name = fieldName + "_" + i; - packed.addField(backingType, name); - args.add(UNPACKING_VARIABLE.access(name) - .transform(perElement)); - } - return GlslExpr.call(outType, args); - } - - @NotNull - private static GlslExpr unpackBuiltin(String fieldName, GlslStruct packed, int size, String func) { - packed.addField("uint", fieldName); - GlslExpr expr = UNPACKING_VARIABLE.access(fieldName) - .callFunction(func); - return switch (size) { - case 2 -> expr.swizzle("xy"); - case 3 -> expr.swizzle("xyz"); - case 4 -> expr; - default -> throw new IllegalArgumentException("Invalid vector size " + size); - }; - } - - @NotNull - private static GlslExpr unpackByteBacked(String fieldName, GlslStruct packed, int size, String outType, Function perElement) { - packed.addField("uint", fieldName); - List args = new ArrayList<>(); - for (int i = 0; i < size; i++) { - int bitPos = i * 8; - var element = UNPACKING_VARIABLE.access(fieldName) - .and(0xFF << bitPos) - .rsh(bitPos); - args.add(perElement.apply(element)); - } - return GlslExpr.call(outType + size, args); - } - - @NotNull - private static GlslExpr unpackShortBacked(String fieldName, GlslStruct packed, int size, String outType, Function perElement) { - List args = new ArrayList<>(); - for (int i = 0; i < size; i++) { - int unpackField = i / 2; - int bitPos = (i % 2) * 16; - var name = fieldName + "_" + unpackField; - if (bitPos == 0) { - // First time we're seeing this field, add it to the struct. - packed.addField("uint", name); - } - var element = UNPACKING_VARIABLE.access(name) - .and(0xFFFF << bitPos) - .rsh(bitPos); - args.add(perElement.apply(element)); - } - return GlslExpr.call(outType, args); - } - private static GlslExpr unpackFloatScalar(String fieldName, FloatRepr repr, GlslStruct packed) { return switch (repr) { case BYTE -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFF) @@ -303,24 +187,6 @@ public class IndirectComponent implements SourceComponent { }; } - private static GlslExpr unpackUnsignedScalar(String fieldName, UnsignedIntegerRepr repr, GlslStruct packed) { - return switch (repr) { - case UNSIGNED_BYTE -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFF)); - case UNSIGNED_SHORT -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFFFF)); - case UNSIGNED_INT -> unpackScalar(fieldName, packed, "uint"); - }; - } - - private static GlslExpr unpackIntScalar(String fieldName, IntegerRepr intRepr, GlslStruct packed) { - return switch (intRepr) { - case BYTE -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFF) - .cast("int")); - case SHORT -> unpackScalar(fieldName, packed, "uint", e -> e.and(0xFFFF) - .cast("int")); - case INT -> unpackScalar(fieldName, packed, "int"); - }; - } - private static GlslExpr unpackScalar(String fieldName, GlslStruct packed, String packedType) { return unpackScalar(fieldName, packed, packedType, Function.identity()); } @@ -329,4 +195,131 @@ public class IndirectComponent implements SourceComponent { packed.addField(packedType, fieldName); return perElement.apply(UNPACKING_VARIABLE.access(fieldName)); } + + private static GlslExpr unpackVector(String fieldName, GlslStruct packed, VectorElementType vector) { + var repr = vector.repr(); + + int size = vector.size(); + + if (repr instanceof IntegerRepr intRepr) { + return unpackIntVector(fieldName, intRepr, packed, size); + } else if (repr instanceof UnsignedIntegerRepr unsignedIntegerRepr) { + return unpackUnsignedVector(fieldName, unsignedIntegerRepr, packed, size); + } else if (repr instanceof FloatRepr floatRepr) { + return unpackFloatVector(fieldName, floatRepr, packed, size); + } + + throw new IllegalArgumentException("Unknown repr " + repr); + } + + private static GlslExpr unpackIntVector(String fieldName, IntegerRepr repr, GlslStruct packed, int size) { + return switch (repr) { + case BYTE -> unpackByteBacked(fieldName, packed, size, "ivec" + size, e -> e.cast("int")); + case SHORT -> unpackShortBacked(fieldName, packed, size, "ivec" + size, e -> e.cast("int")); + case INT -> unpack(fieldName, packed, size, "int", "ivec" + size); + }; + } + + private static GlslExpr unpackUnsignedVector(String fieldName, UnsignedIntegerRepr unsignedIntegerRepr, GlslStruct packed, int size) { + return switch (unsignedIntegerRepr) { + case UNSIGNED_BYTE -> unpackByteBacked(fieldName, packed, size, "uvec" + size, e -> e.cast("uint")); + case UNSIGNED_SHORT -> unpackShortBacked(fieldName, packed, size, "uvec" + size, e -> e.cast("uint")); + case UNSIGNED_INT -> unpack(fieldName, packed, size, "uint", "uvec" + size); + }; + } + + private static GlslExpr unpackFloatVector(String fieldName, FloatRepr floatRepr, GlslStruct packed, int size) { + return switch (floatRepr) { + case NORMALIZED_BYTE -> unpackBuiltin(fieldName, packed, size, "unpackSnorm4x8"); + case NORMALIZED_UNSIGNED_BYTE -> unpackBuiltin(fieldName, packed, size, "unpackUnorm4x8"); + case NORMALIZED_SHORT -> unpackBuiltin(fieldName, packed, size, "unpackSnorm2x16"); + case NORMALIZED_UNSIGNED_SHORT -> unpackBuiltin(fieldName, packed, size, "unpackUnorm2x16"); + case NORMALIZED_INT -> unpack(fieldName, packed, size, "int", "vec" + size, e -> e.div(2147483647f) + .clamp(-1, 1)); + case NORMALIZED_UNSIGNED_INT -> + unpack(fieldName, packed, size, "uint", "vec" + size, e -> e.div(4294967295f)); + case BYTE -> unpackByteBacked(fieldName, packed, size, "vec" + size, e -> e.cast("int") + .cast("float")); + case UNSIGNED_BYTE -> unpackByteBacked(fieldName, packed, size, "vec" + size, e -> e.cast("float")); + case SHORT -> unpackShortBacked(fieldName, packed, size, "vec" + size, e -> e.cast("int") + .cast("float")); + case UNSIGNED_SHORT -> unpackShortBacked(fieldName, packed, size, "vec" + size, e -> e.cast("float")); + case INT -> unpack(fieldName, packed, size, "int", "vec" + size, e -> e.cast("float")); + case UNSIGNED_INT -> unpack(fieldName, packed, size, "float", "vec" + size, e -> e.cast("float")); + case FLOAT -> unpack(fieldName, packed, size, "float", "vec" + size); + }; + } + + private static GlslExpr unpackByteBacked(String fieldName, GlslStruct packed, int size, String outType, Function perElement) { + packed.addField("uint", fieldName); + List args = new ArrayList<>(); + for (int i = 0; i < size; i++) { + int bitPos = i * 8; + var element = UNPACKING_VARIABLE.access(fieldName) + .and(0xFF << bitPos) + .rsh(bitPos); + args.add(perElement.apply(element)); + } + return GlslExpr.call(outType + size, args); + } + + private static GlslExpr unpackShortBacked(String fieldName, GlslStruct packed, int size, String outType, Function perElement) { + List args = new ArrayList<>(); + for (int i = 0; i < size; i++) { + int unpackField = i / 2; + int bitPos = (i % 2) * 16; + var name = fieldName + "_" + unpackField; + if (bitPos == 0) { + // First time we're seeing this field, add it to the struct. + packed.addField("uint", name); + } + var element = UNPACKING_VARIABLE.access(name) + .and(0xFFFF << bitPos) + .rsh(bitPos); + args.add(perElement.apply(element)); + } + return GlslExpr.call(outType, args); + } + + private static GlslExpr unpack(String fieldName, GlslStruct packed, int size, String backingType, String outType) { + return unpack(fieldName, packed, size, backingType, outType, Function.identity()); + } + + private static GlslExpr unpack(String fieldName, GlslStruct packed, int size, String backingType, String outType, Function perElement) { + List args = new ArrayList<>(); + for (int i = 0; i < size; i++) { + var name = fieldName + "_" + i; + packed.addField(backingType, name); + args.add(UNPACKING_VARIABLE.access(name) + .transform(perElement)); + } + return GlslExpr.call(outType, args); + } + + private static GlslExpr unpackBuiltin(String fieldName, GlslStruct packed, int size, String func) { + packed.addField("uint", fieldName); + GlslExpr expr = UNPACKING_VARIABLE.access(fieldName) + .callFunction(func); + return switch (size) { + case 2 -> expr.swizzle("xy"); + case 3 -> expr.swizzle("xyz"); + case 4 -> expr; + default -> throw new IllegalArgumentException("Invalid vector size " + size); + }; + } + + private static GlslExpr unpackMatrix(String name, GlslStruct packed, MatrixElementType matrix) { + var repr = matrix.repr(); + + int rows = matrix.rows(); + int columns = matrix.columns(); + + List args = new ArrayList<>(); + + for (int i = 0; i < columns; i++) { + args.add(unpackFloatVector(name + "_" + i, repr, packed, rows)); + } + + return GlslExpr.call("mat" + columns + "x" + rows, args); + } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java index 756396e60..9bed55fc5 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java @@ -5,7 +5,6 @@ import java.io.FileWriter; import java.util.ArrayList; import java.util.List; -import org.jetbrains.annotations.NotNull; import org.lwjgl.opengl.GL20; import com.jozufozu.flywheel.backend.compile.FlwPrograms; @@ -33,7 +32,6 @@ public class Compilation { private final StringBuilder fullSource = new StringBuilder(); private int generatedLines = 0; - @NotNull public ShaderResult compile(ShaderType shaderType, String name) { int handle = GL20.glCreateShader(shaderType.glEnum); var source = fullSource.toString(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compile.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compile.java index 6c68e5031..3dc7d8c63 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compile.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compile.java @@ -10,7 +10,6 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; @@ -98,7 +97,7 @@ public class Compile { public static class ShaderCompiler { private final GlslVersion glslVersion; private final ShaderType shaderType; - private final List> fetchers = new ArrayList<>(); + private final List> fetchers = new ArrayList<>(); private Consumer compilationCallbacks = $ -> { }; private Function nameMapper = Object::toString; @@ -113,25 +112,25 @@ public class Compile { return this; } - public ShaderCompiler with(BiFunction fetch) { + public ShaderCompiler with(BiFunction fetch) { fetchers.add(fetch); return this; } - public ShaderCompiler withComponents(Collection components) { + public ShaderCompiler withComponents(Collection<@Nullable SourceComponent> components) { components.forEach(this::withComponent); return this; } - public ShaderCompiler withComponent(SourceComponent component) { + public ShaderCompiler withComponent(@Nullable SourceComponent component) { return withComponent($ -> component); } - public ShaderCompiler withComponent(Function sourceFetcher) { + public ShaderCompiler withComponent(Function sourceFetcher) { return with((key, $) -> sourceFetcher.apply(key)); } - public ShaderCompiler withResource(Function sourceFetcher) { + public ShaderCompiler withResource(Function sourceFetcher) { return with((key, loader) -> loader.find(sourceFetcher.apply(key))); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java index 1e71b3973..8af2b0f76 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.jetbrains.annotations.NotNull; import org.slf4j.Marker; import org.slf4j.MarkerFactory; @@ -71,7 +70,6 @@ public class CompilerStats { .collect(Collectors.joining("\n")); } - @NotNull private String linkErrors() { return String.join("\n", programErrors); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java index a73483d45..a8c2c44da 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java @@ -8,8 +8,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.glsl.SourceFile; import com.jozufozu.flywheel.backend.glsl.SourceLines; @@ -49,7 +47,6 @@ public class FailedCompilation { .collect(Collectors.joining("\n")); } - @NotNull private Stream errorStream() { return errorLog.lines() .mapMulti(this::interpretLine); @@ -142,7 +139,6 @@ public class FailedCompilation { .note("This generally indicates a bug in Flywheel, not your shader code."); } - @NotNull private static ErrorLevel parseErrorLevel(String level) { return switch (level.toLowerCase(Locale.ROOT)) { case "error" -> ErrorLevel.ERROR; diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/compile/package-info.java deleted file mode 100644 index 4b1ce0738..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -@MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -package com.jozufozu.flywheel.backend.compile; - -import javax.annotation.ParametersAreNonnullByDefault; - -import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java index cd7c75795..b3985fdfa 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java @@ -11,8 +11,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.api.backend.Engine; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; @@ -158,7 +156,6 @@ public class IndirectDrawManager extends InstancerStorage> block.free(); } - @NotNull private static Map, Int2ObjectMap, InstanceHandleImpl>>>> doCrumblingSort(List crumblingBlocks) { Map, Int2ObjectMap, InstanceHandleImpl>>>> byType = new HashMap<>(); for (Engine.CrumblingBlock block : crumblingBlocks) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/StagingBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/StagingBuffer.java index 0611b0166..a419c6fb1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/StagingBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/StagingBuffer.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.backend.engine.indirect; import java.util.function.LongConsumer; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL45; import org.lwjgl.opengl.GL45C; @@ -227,7 +226,6 @@ public class StagingBuffer { FlwMemoryTracker._freeCPUMemory(capacity); } - @NotNull private MemoryBlock getScratch(long size) { if (scratch == null) { scratch = MemoryBlock.malloc(size); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/DrawCall.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/DrawCall.java index 42aeb17bf..af0f59552 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/DrawCall.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/DrawCall.java @@ -74,14 +74,14 @@ public class DrawCall { } public void delete() { - if (vao != null) { - vao.delete(); - vao = null; - } + if (vao != null) { + vao.delete(); + vao = null; + } if (vaoScratch != null) { vaoScratch.delete(); vaoScratch = null; } - } + } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/EboCache.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/EboCache.java index 6b4b21abb..94d53984f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/EboCache.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/EboCache.java @@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.engine.instancing; import java.util.ArrayList; import java.util.List; -import org.jetbrains.annotations.NotNull; import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.api.model.IndexSequence; @@ -55,7 +54,6 @@ public class EboCache { } private record Entry(int ebo, int gpuSize) { - @NotNull private static Entry create(IndexSequence provider, int indexCount) { int byteSize = indexCount * GlNumericType.UINT.byteWidth(); var ebo = Buffer.IMPL.create(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedCrumbling.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedCrumbling.java index e82f5301c..e8623af5c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedCrumbling.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedCrumbling.java @@ -5,8 +5,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.api.backend.Engine; import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.backend.compile.InstancingPrograms; @@ -74,7 +72,6 @@ public class InstancedCrumbling { } } - @NotNull private static Map>> doCrumblingSort(List instances) { Map>> out = new HashMap<>(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java index a0ea3f517..1afcb82fa 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java @@ -5,8 +5,6 @@ import java.util.EnumMap; import java.util.Iterator; import java.util.Map; -import org.jetbrains.annotations.NotNull; - import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ListMultimap; @@ -108,7 +106,6 @@ public class InstancedDrawManager extends InstancerStorage return drawCalls.isEmpty(); } - @NotNull @Override public Iterator>> iterator() { return drawCalls.asMap() diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java index cd013b576..7e87f1767 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java @@ -53,7 +53,7 @@ public enum GlBufferType { }; } - public void bind(int buffer) { + public void bind(int buffer) { GlStateTracker.bindBuffer(this, buffer); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/ShaderSources.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/ShaderSources.java index da73b7632..9b7e26c7f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/ShaderSources.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/ShaderSources.java @@ -9,7 +9,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.VisibleForTesting; import net.minecraft.resources.ResourceLocation; @@ -40,7 +39,6 @@ public class ShaderSources { cache.putAll(preloadCache); } - @NotNull public LoadResult find(ResourceLocation location) { if (findStack.contains(location)) { // Make a copy of the find stack with the offending location added on top to show the full path. @@ -57,7 +55,6 @@ public class ShaderSources { return out; } - @NotNull private LoadResult _find(ResourceLocation location) { // Can't use computeIfAbsent because mutual recursion causes ConcurrentModificationExceptions var out = cache.get(location); @@ -68,7 +65,7 @@ public class ShaderSources { return out; } - @NotNull + @VisibleForTesting protected LoadResult load(ResourceLocation loc) { return manager.getResource(loc.withPrefix(SHADER_DIR)) .map(resource -> { diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/SourceFile.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/SourceFile.java index 2485af853..cda77ffd6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/SourceFile.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/SourceFile.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; @@ -229,7 +228,6 @@ public class SourceFile implements SourceComponent { return System.identityHashCode(this); } - @NotNull private static String generateFinalSource(ImmutableList imports, SourceLines source) { var out = new StringBuilder(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/SourceLines.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/SourceLines.java index 474852274..2964ca880 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/SourceLines.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/SourceLines.java @@ -3,8 +3,6 @@ package com.jozufozu.flywheel.backend.glsl; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.jetbrains.annotations.NotNull; - import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.backend.glsl.span.CharPos; @@ -14,8 +12,7 @@ import it.unimi.dsi.fastutil.ints.IntLists; import net.minecraft.resources.ResourceLocation; public class SourceLines implements CharSequence { - - private static final Pattern newLine = Pattern.compile("(\\r\\n|\\r|\\n)"); + private static final Pattern NEW_LINE = Pattern.compile("(\\r\\n|\\r|\\n)"); public final ResourceLocation name; /** @@ -88,7 +85,7 @@ public class SourceLines implements CharSequence { IntList l = new IntArrayList(); l.add(0); // first line is always at position 0 - Matcher matcher = newLine.matcher(source); + Matcher matcher = NEW_LINE.matcher(source); while (matcher.find()) { l.add(matcher.end()); @@ -116,16 +113,17 @@ public class SourceLines implements CharSequence { return raw; } - @NotNull @Override public CharSequence subSequence(int start, int end) { return raw.subSequence(start, end); } + @Override public char charAt(int i) { return raw.charAt(i); } + @Override public int length() { return raw.length(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/error/ErrorBuilder.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/error/ErrorBuilder.java index ed8596265..84b93258b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/error/ErrorBuilder.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/error/ErrorBuilder.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.VisibleForTesting; @@ -148,7 +147,6 @@ public class ErrorBuilder { return lineStream.collect(Collectors.joining("\n")); } - @NotNull private Stream getLineStream() { int maxMargin = calculateMargin(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslBuilder.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslBuilder.java index 5d6257a38..c9503c648 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslBuilder.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslBuilder.java @@ -17,28 +17,28 @@ public class GlslBuilder { public GlslStruct struct() { return add(new GlslStruct()); - } + } - public GlslFn function() { - return add(new GlslFn()); - } + public GlslFn function() { + return add(new GlslFn()); + } - public GlslVertexInput vertexInput() { - return add(new GlslVertexInput()); - } + public GlslVertexInput vertexInput() { + return add(new GlslVertexInput()); + } - public GlslUniformBlock uniformBlock() { - return add(new GlslUniformBlock()); - } + public GlslUniformBlock uniformBlock() { + return add(new GlslUniformBlock()); + } - public T add(T element) { - elements.add(element); - return element; - } + public T add(T element) { + elements.add(element); + return element; + } - public void blankLine() { - elements.add(Separators.BLANK_LINE); - } + public void blankLine() { + elements.add(Separators.BLANK_LINE); + } public void _addRaw(String sourceString) { elements.add(() -> sourceString); diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslSwitch.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslSwitch.java index 1e97684a2..ee8379007 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslSwitch.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslSwitch.java @@ -4,13 +4,10 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.lib.util.Pair; import com.jozufozu.flywheel.lib.util.StringUtil; public class GlslSwitch implements GlslStmt { - private final GlslExpr on; private final List> cases = new ArrayList<>(); @@ -44,16 +41,15 @@ public class GlslSwitch implements GlslStmt { }""".formatted(on.prettyPrint(), formatCases()); } - @NotNull - private String formatCases() { - var cases = this.cases.stream() - .map(GlslSwitch::prettyPrintCase) - .collect(Collectors.joining("\n")); - if (defaultCase != null) { - cases += "\ndefault:\n" + StringUtil.indent(defaultCase.prettyPrint(), 4); - } - return cases; - } + private String formatCases() { + var cases = this.cases.stream() + .map(GlslSwitch::prettyPrintCase) + .collect(Collectors.joining("\n")); + if (defaultCase != null) { + cases += "\ndefault:\n" + StringUtil.indent(defaultCase.prettyPrint(), 4); + } + return cases; + } private static String prettyPrintCase(Pair p) { var variant = p.first() @@ -64,5 +60,4 @@ public class GlslSwitch implements GlslStmt { case %s: %s""".formatted(variant, StringUtil.indent(block, 4)); } - } diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslUniformBlock.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslUniformBlock.java index a5917c466..e6f62c194 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslUniformBlock.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/generate/GlslUniformBlock.java @@ -8,36 +8,36 @@ import com.jozufozu.flywheel.lib.util.Pair; import com.jozufozu.flywheel.lib.util.StringUtil; public class GlslUniformBlock implements GlslBuilder.Declaration { - private String qualifier; + private String qualifier; private String name; private final List> members = new ArrayList<>(); - @Override - public String prettyPrint() { + @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")); - } + 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; - } + public GlslUniformBlock layout(String qualifier) { + this.qualifier = qualifier; + return this; + } public GlslUniformBlock name(String name) { this.name = name; return this; } - public GlslUniformBlock member(String typeName, String variableName) { - members.add(Pair.of(typeName, variableName)); + public GlslUniformBlock member(String typeName, String variableName) { + members.add(Pair.of(typeName, variableName)); return this; - } + } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/package-info.java deleted file mode 100644 index 2729fb3ed..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -@MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -package com.jozufozu.flywheel.backend.glsl; - -import javax.annotation.ParametersAreNonnullByDefault; - -import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/parse/ShaderStruct.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/parse/ShaderStruct.java index 9047af3a5..541298591 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/parse/ShaderStruct.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/parse/ShaderStruct.java @@ -9,7 +9,6 @@ import com.jozufozu.flywheel.backend.glsl.SourceLines; import com.jozufozu.flywheel.backend.glsl.span.Span; public class ShaderStruct { - // https://regexr.com/61rpe public static final Pattern PATTERN = Pattern.compile("struct\\s+([\\w_]*)\\s*\\{(.*?)}\\s*([\\w_]*)?\\s*;\\s", Pattern.DOTALL); diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/span/Span.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/span/Span.java index b0da73a77..9a2e7a7ff 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/span/Span.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/span/Span.java @@ -2,8 +2,6 @@ package com.jozufozu.flywheel.backend.glsl.span; import java.util.regex.Matcher; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.backend.glsl.SourceFile; import com.jozufozu.flywheel.backend.glsl.SourceLines; @@ -125,7 +123,7 @@ public abstract class Span implements CharSequence, Comparable { } @Override - public int compareTo(@NotNull Span o) { + public int compareTo(Span o) { return Integer.compareUnsigned(startIndex(), o.startIndex()); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/glsl/span/StringSpan.java b/src/main/java/com/jozufozu/flywheel/backend/glsl/span/StringSpan.java index 25cb5e1a9..7c797f5d6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/glsl/span/StringSpan.java +++ b/src/main/java/com/jozufozu/flywheel/backend/glsl/span/StringSpan.java @@ -10,7 +10,7 @@ public class StringSpan extends Span { @Override public Span subSpan(int from, int to) { - return new StringSpan(in, start.pos() + from, start.pos() + to); + return new StringSpan(in, start.pos() + from, start.pos() + to); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/impl/task/ParallelTaskExecutor.java b/src/main/java/com/jozufozu/flywheel/impl/task/ParallelTaskExecutor.java index b49014680..81a9e76bf 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/task/ParallelTaskExecutor.java +++ b/src/main/java/com/jozufozu/flywheel/impl/task/ParallelTaskExecutor.java @@ -9,7 +9,6 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BooleanSupplier; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import com.jozufozu.flywheel.Flywheel; @@ -106,7 +105,7 @@ public class ParallelTaskExecutor implements TaskExecutor { } @Override - public void execute(@NotNull Runnable task) { + public void execute(Runnable task) { if (!running.get()) { throw new IllegalStateException("Executor is stopped"); } diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/FrameContext.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/FrameContext.java index bf8945e4e..7da4537ed 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/FrameContext.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/FrameContext.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.impl.visualization; -import org.jetbrains.annotations.NotNull; import org.joml.FrustumIntersection; import org.joml.Matrix4f; @@ -9,7 +8,6 @@ import com.jozufozu.flywheel.api.event.RenderContext; import net.minecraft.core.Vec3i; public record FrameContext(double cameraX, double cameraY, double cameraZ, FrustumIntersection frustum, float partialTick) { - @NotNull public static FrameContext create(RenderContext context, Vec3i renderOrigin) { var cameraPos = context.camera() .getPosition(); diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/VisualUpdatePlan.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/VisualUpdatePlan.java index ff27e0427..3fe67ae97 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/VisualUpdatePlan.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/VisualUpdatePlan.java @@ -3,8 +3,6 @@ package com.jozufozu.flywheel.impl.visualization.storage; import java.util.List; import java.util.function.Supplier; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.api.task.Plan; import com.jozufozu.flywheel.api.task.TaskExecutor; import com.jozufozu.flywheel.lib.task.NestedPlan; @@ -13,7 +11,6 @@ import com.jozufozu.flywheel.lib.task.UnitPlan; public class VisualUpdatePlan implements SimplyComposedPlan { private final Supplier>> initializer; - @NotNull private Plan plan = UnitPlan.of(); private boolean initialized = false; private boolean needsSimplify = true; diff --git a/src/main/java/com/jozufozu/flywheel/lib/box/MutableBox.java b/src/main/java/com/jozufozu/flywheel/lib/box/MutableBox.java index 71c0dc116..9b471d3c1 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/box/MutableBox.java +++ b/src/main/java/com/jozufozu/flywheel/lib/box/MutableBox.java @@ -205,7 +205,7 @@ public class MutableBox implements Box { maxZ = Math.min(this.maxZ, other.getMaxZ()); } - public void fixMinMax() { + public void fixMinMax() { int minX = Math.min(this.minX, this.maxX); int minY = Math.min(this.minY, this.maxY); int minZ = Math.min(this.minZ, this.maxZ); diff --git a/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java b/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java index b1d22edcf..b3d0dcfb9 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java @@ -12,8 +12,8 @@ import com.dreizak.miniball.highdim.Miniball; import com.dreizak.miniball.model.PointSet; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.api.model.Mesh; -import com.jozufozu.flywheel.api.vertex.VertexView; import com.jozufozu.flywheel.api.vertex.VertexList; +import com.jozufozu.flywheel.api.vertex.VertexView; import com.jozufozu.flywheel.api.vertex.VertexViewProviderRegistry; import com.jozufozu.flywheel.lib.material.Materials; import com.jozufozu.flywheel.lib.memory.MemoryBlock; diff --git a/src/main/java/com/jozufozu/flywheel/lib/model/baked/PartialModel.java b/src/main/java/com/jozufozu/flywheel/lib/model/baked/PartialModel.java index f6e1b055a..c8fc27a0c 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/model/baked/PartialModel.java +++ b/src/main/java/com/jozufozu/flywheel/lib/model/baked/PartialModel.java @@ -3,8 +3,6 @@ package com.jozufozu.flywheel.lib.model.baked; import java.util.ArrayList; import java.util.List; -import org.jetbrains.annotations.NotNull; - import net.minecraft.client.resources.model.BakedModel; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.client.event.ModelEvent; @@ -51,7 +49,6 @@ public class PartialModel { } } - @NotNull public String getName() { return getLocation() .toString(); diff --git a/src/main/java/com/jozufozu/flywheel/lib/task/functional/package-info.java b/src/main/java/com/jozufozu/flywheel/lib/task/functional/package-info.java index 6551c466a..7a47118c8 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/task/functional/package-info.java +++ b/src/main/java/com/jozufozu/flywheel/lib/task/functional/package-info.java @@ -5,4 +5,12 @@ * interface, but do not need to create additional closure objects to translate when the consumer wishes to ignore * the context object. */ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault package com.jozufozu.flywheel.lib.task.functional; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.FieldsAreNonnullByDefault; +import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/lib/util/ResourceUtil.java b/src/main/java/com/jozufozu/flywheel/lib/util/ResourceUtil.java index 265587e4c..6ab2e76f7 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/util/ResourceUtil.java +++ b/src/main/java/com/jozufozu/flywheel/lib/util/ResourceUtil.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.lib.util; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.Flywheel; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -55,7 +53,6 @@ public final class ResourceUtil { } } - @NotNull public static String toDebugFileNameNoExtension(ResourceLocation resourceLocation) { var stringLoc = resourceLocation.toString(); return stringLoc.substring(0, stringLoc.lastIndexOf('.')) diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleBlockEntityVisualizer.java b/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleBlockEntityVisualizer.java index 24e01cfdf..644f53cf9 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleBlockEntityVisualizer.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleBlockEntityVisualizer.java @@ -3,8 +3,6 @@ package com.jozufozu.flywheel.lib.visual; import java.util.Objects; import java.util.function.Predicate; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.api.visual.BlockEntityVisual; import com.jozufozu.flywheel.api.visualization.BlockEntityVisualizer; import com.jozufozu.flywheel.api.visualization.VisualizationContext; @@ -45,7 +43,7 @@ public class SimpleBlockEntityVisualizer implements Block @FunctionalInterface public interface Factory { - @NotNull BlockEntityVisual create(VisualizationContext ctx, T blockEntity); + BlockEntityVisual create(VisualizationContext ctx, T blockEntity); } /** diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleEntityVisualizer.java b/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleEntityVisualizer.java index 483f307ef..038e13abb 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleEntityVisualizer.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleEntityVisualizer.java @@ -3,8 +3,6 @@ package com.jozufozu.flywheel.lib.visual; import java.util.Objects; import java.util.function.Predicate; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.api.visual.EntityVisual; import com.jozufozu.flywheel.api.visualization.EntityVisualizer; import com.jozufozu.flywheel.api.visualization.VisualizationContext; @@ -45,7 +43,7 @@ public class SimpleEntityVisualizer implements EntityVisualize @FunctionalInterface public interface Factory { - @NotNull EntityVisual create(VisualizationContext ctx, T entity); + EntityVisual create(VisualizationContext ctx, T entity); } /** diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java index 45606dfcf..efdb1c9b2 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java @@ -70,7 +70,7 @@ public class MinecartVisual extends AbstractEntityVi return null; } - return instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.block(blockState), RenderStage.AFTER_ENTITIES) + return instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.block(blockState), RenderStage.AFTER_ENTITIES) .createInstance(); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index b1acd1093..5d3bde9cc 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -5,7 +5,6 @@ license = "MIT" [[mods]] modId = "flywheel" -# The Implementation-Version property in the jar's MANIFEST.MF file will be used as the mod version at runtime version = "${mod_version}" displayName = "Flywheel" logoFile = "logo.png" diff --git a/src/test/java/com/jozufozu/flywheel/backend/glsl/MockShaderSources.java b/src/test/java/com/jozufozu/flywheel/backend/glsl/MockShaderSources.java index db4966b99..19d660ddd 100644 --- a/src/test/java/com/jozufozu/flywheel/backend/glsl/MockShaderSources.java +++ b/src/test/java/com/jozufozu/flywheel/backend/glsl/MockShaderSources.java @@ -4,7 +4,6 @@ import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Map; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import net.minecraft.resources.ResourceLocation; @@ -21,7 +20,6 @@ public class MockShaderSources extends ShaderSources { sources.put(loc, source); } - @NotNull @Override protected LoadResult load(ResourceLocation loc) { var maybeFound = sources.get(loc); diff --git a/src/test/java/com/jozufozu/flywheel/backend/glsl/TestBase.java b/src/test/java/com/jozufozu/flywheel/backend/glsl/TestBase.java index 9b487ef46..beebdad43 100644 --- a/src/test/java/com/jozufozu/flywheel/backend/glsl/TestBase.java +++ b/src/test/java/com/jozufozu/flywheel/backend/glsl/TestBase.java @@ -6,8 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.List; -import org.jetbrains.annotations.NotNull; - import com.jozufozu.flywheel.Flywheel; import net.minecraft.resources.ResourceLocation; @@ -22,7 +20,6 @@ public class TestBase { return list.get(0); } - @NotNull public static E findAndAssertError(Class clazz, MockShaderSources sources, ResourceLocation loc) { var result = sources.find(loc); var failure = assertInstanceOf(LoadResult.Failure.class, result); @@ -40,13 +37,11 @@ public class TestBase { return assertInstanceOf(finalErrType, pair.second()); } - @NotNull public static SourceFile findAndAssertSuccess(MockShaderSources sources, ResourceLocation loc) { var result = sources.find(loc); return assertSuccessAndUnwrap(loc, result); } - @NotNull public static SourceFile assertSuccessAndUnwrap(ResourceLocation expectedName, LoadResult result) { assertInstanceOf(LoadResult.Success.class, result); diff --git a/src/test/java/com/jozufozu/flywheel/backend/glsl/TestErrorMessages.java b/src/test/java/com/jozufozu/flywheel/backend/glsl/TestErrorMessages.java index 642bde3ff..58059a7f9 100644 --- a/src/test/java/com/jozufozu/flywheel/backend/glsl/TestErrorMessages.java +++ b/src/test/java/com/jozufozu/flywheel/backend/glsl/TestErrorMessages.java @@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.glsl; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -62,7 +61,6 @@ public class TestErrorMessages extends TestBase { assertEquals(expected.trim(), message.trim()); } - @NotNull public static ErrorBuilder assertErrorAndGetMessage(MockShaderSources sources, ResourceLocation loc) { var result = sources.find(loc); var failure = assertInstanceOf(LoadResult.Failure.class, result);