From e5384c23dc4b761718f684e865f8aea863f70006 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sun, 12 May 2024 16:01:08 -0700 Subject: [PATCH] Fix registry freeze timing - Move registry freezing to right before start of initial resource reload - Also warn if Fabric config JSON is not an object - Move Flywheel.java to API - Remove Flywheel.LOGGER and others; add impl-specific and backend-specific loggers - Remove unused mixins - Organize imports --- .../gradle/platform/PlatformExtension.kt | 9 ++- .../gradle/subproject/SubprojectPlugin.kt | 1 - .../TransitiveSourceSetsExtension.kt | 2 - .../com/jozufozu/flywheel/api}/Flywheel.java | 6 +- .../jozufozu/flywheel/backend/Backends.java | 2 +- .../jozufozu/flywheel/backend/FlwBackend.java | 18 ++++++ .../flywheel/backend/InternalVertex.java | 2 +- .../flywheel/backend/compile/FlwPrograms.java | 4 +- .../backend/compile/IndirectPrograms.java | 3 +- .../backend/compile/InstancingPrograms.java | 1 - .../backend/compile/PipelineCompiler.java | 3 +- .../flywheel/backend/compile/Pipelines.java | 2 +- .../BufferTextureInstanceComponent.java | 2 +- .../component/InstanceStructComponent.java | 2 +- .../component/SsboInstanceComponent.java | 2 +- .../StringSubstitutionComponent.java | 2 +- .../component/UberShaderComponent.java | 2 +- .../compile/core/FailedCompilation.java | 2 +- .../flywheel/backend/engine/DrawManager.java | 4 +- .../backend/engine/uniform/FrameUniforms.java | 2 +- .../flywheel/backend/gl/GlCompat.java | 4 +- .../backend/mixin/GameRendererAccessor.java | 23 -------- .../backend/mixin/LevelRendererAccessor.java | 2 +- .../backend/mixin/LightTextureAccessor.java | 13 ----- .../flywheel/backend/mixin/OptionsMixin.java | 2 +- .../backend/mixin/OverlayTextureAccessor.java | 13 ----- .../resources/flywheel.backend.mixins.json | 3 - .../flywheel/lib/instance/InstanceTypes.java | 2 +- .../flywheel/lib/internal/FlwLibLink.java | 4 ++ .../flywheel/lib/material/CutoutShaders.java | 2 +- .../flywheel/lib/material/FogShaders.java | 2 +- .../lib/material/StandardMaterialShaders.java | 2 +- .../lib/memory/DebugMemoryBlockImpl.java | 4 +- .../flywheel/lib/util/ResourceUtil.java | 2 +- .../flywheel/lib/util/ShadersModHandler.java | 11 ++-- .../lib/visual/SimpleDynamicVisual.java | 1 - .../lib/visual/SimpleTickableVisual.java | 1 - .../flywheel/impl/BackendManagerImpl.java | 8 +-- .../impl/{FlywheelInit.java => FlwImpl.java} | 17 ++++-- .../flywheel/impl/FlwLibLinkImpl.java | 7 +++ .../impl/mixin/ClientChunkCacheMixin.java | 6 +- .../impl/mixin/LevelRendererMixin.java | 2 +- .../impl/task/ParallelTaskExecutor.java | 15 ++--- .../flywheel/backend/glsl/TestBase.java | 2 +- .../backend/compile/FlwProgramsReloader.java | 2 +- .../model/baked/PartialModelEventHandler.java | 2 +- .../flywheel/impl/FabricFlwConfig.java | 56 +++++++++---------- .../flywheel/impl/FlywheelFabric.java | 10 +--- .../flywheel/impl/mixin/MinecraftMixin.java | 10 ++++ .../jozufozu/flywheel/impl/FlwCommands.java | 6 +- .../flywheel/impl/FlwLibXplatImpl.java | 6 +- .../jozufozu/flywheel/impl/FlywheelForge.java | 7 +-- .../flywheel/impl/ForgeFlwConfig.java | 7 +-- .../flywheel/impl/mixin/MinecraftMixin.java | 10 ++++ 54 files changed, 147 insertions(+), 188 deletions(-) rename common/src/{lib/java/com/jozufozu/flywheel => api/java/com/jozufozu/flywheel/api}/Flywheel.java (61%) create mode 100644 common/src/backend/java/com/jozufozu/flywheel/backend/FlwBackend.java delete mode 100644 common/src/backend/java/com/jozufozu/flywheel/backend/mixin/GameRendererAccessor.java delete mode 100644 common/src/backend/java/com/jozufozu/flywheel/backend/mixin/LightTextureAccessor.java delete mode 100644 common/src/backend/java/com/jozufozu/flywheel/backend/mixin/OverlayTextureAccessor.java rename common/src/main/java/com/jozufozu/flywheel/impl/{FlywheelInit.java => FlwImpl.java} (69%) diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformExtension.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformExtension.kt index 2b5268a18..dec97abf7 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformExtension.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformExtension.kt @@ -2,17 +2,16 @@ package com.jozufozu.gradle.platform import com.jozufozu.gradle.jarset.JarTaskSet import net.fabricmc.loom.api.LoomGradleExtensionAPI -import net.fabricmc.loom.task.RemapJarTask -import net.fabricmc.loom.task.RemapSourcesJarTask import org.gradle.api.Project -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.jvm.tasks.Jar -import org.gradle.kotlin.dsl.* +import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.the +import org.gradle.kotlin.dsl.withType import org.gradle.language.jvm.tasks.ProcessResources import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt index b448b7e0d..d39d0d9b4 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt @@ -19,7 +19,6 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.kotlin.dsl.* import org.gradle.language.jvm.tasks.ProcessResources - class SubprojectPlugin: Plugin { override fun apply(project: Project) { project.extensions.create("defaultPackageInfos", PackageInfosExtension::class.java, project) diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsExtension.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsExtension.kt index e549cc158..9ebbe2dab 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsExtension.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsExtension.kt @@ -4,8 +4,6 @@ import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.file.FileCollection import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.SourceSetContainer -import org.gradle.kotlin.dsl.the open class TransitiveSourceSetsExtension(private val project: Project) { var compileClasspath: FileCollection? = null diff --git a/common/src/lib/java/com/jozufozu/flywheel/Flywheel.java b/common/src/api/java/com/jozufozu/flywheel/api/Flywheel.java similarity index 61% rename from common/src/lib/java/com/jozufozu/flywheel/Flywheel.java rename to common/src/api/java/com/jozufozu/flywheel/api/Flywheel.java index 857125674..f410e4ac2 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/Flywheel.java +++ b/common/src/api/java/com/jozufozu/flywheel/api/Flywheel.java @@ -1,13 +1,9 @@ -package com.jozufozu.flywheel; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +package com.jozufozu.flywheel.api; import net.minecraft.resources.ResourceLocation; public final class Flywheel { public static final String ID = "flywheel"; - public static final Logger LOGGER = LoggerFactory.getLogger(ID); private Flywheel() { } diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/Backends.java b/common/src/backend/java/com/jozufozu/flywheel/backend/Backends.java index fa0ce5ac2..73698e28b 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/Backends.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/Backends.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.backend.compile.IndirectPrograms; import com.jozufozu.flywheel.backend.compile.InstancingPrograms; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/FlwBackend.java b/common/src/backend/java/com/jozufozu/flywheel/backend/FlwBackend.java new file mode 100644 index 000000000..8f2f5cb19 --- /dev/null +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/FlwBackend.java @@ -0,0 +1,18 @@ +package com.jozufozu.flywheel.backend; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.jozufozu.flywheel.api.Flywheel; + +public final class FlwBackend { + public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/backend"); + + private FlwBackend() { + } + + public static void init() { + ShaderIndices.init(); + Backends.init(); + } +} diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/InternalVertex.java b/common/src/backend/java/com/jozufozu/flywheel/backend/InternalVertex.java index 8b6aa2cb3..bac7f639b 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/InternalVertex.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/InternalVertex.java @@ -2,7 +2,7 @@ import java.util.List; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.layout.FloatRepr; import com.jozufozu.flywheel.api.layout.Layout; import com.jozufozu.flywheel.api.layout.LayoutBuilder; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java index 2364ee4bb..cbe0b6877 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java @@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory; import com.google.common.collect.ImmutableList; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.backend.ShaderIndices; import com.jozufozu.flywheel.backend.compile.component.UberShaderComponent; @@ -22,7 +22,7 @@ import net.minecraft.server.packs.resources.ResourceManager; public final class FlwPrograms { - public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/shaders"); + public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/backend/shaders"); private static final ResourceLocation COMPONENTS_HEADER_VERT = Flywheel.rl("internal/components_header.vert"); private static final ResourceLocation COMPONENTS_HEADER_FRAG = Flywheel.rl("internal/components_header.frag"); diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java index 2dea078ab..1856776db 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java @@ -1,13 +1,12 @@ package com.jozufozu.flywheel.backend.compile; -import java.util.ArrayList; import java.util.List; import java.util.Map; import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.backend.compile.component.InstanceStructComponent; import com.jozufozu.flywheel.backend.compile.component.SsboInstanceComponent; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java index 0d9b3de7c..ea29fe109 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.backend.compile; -import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java index 09fbe049b..a964a8894 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java @@ -1,10 +1,9 @@ package com.jozufozu.flywheel.backend.compile; import java.util.Collection; -import java.util.Collections; import java.util.List; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.backend.InternalVertex; import com.jozufozu.flywheel.backend.Samplers; import com.jozufozu.flywheel.backend.compile.component.InstanceStructComponent; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/Pipelines.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/Pipelines.java index 29978c1de..238d5e58b 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/Pipelines.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/Pipelines.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.compile; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.backend.Samplers; import com.jozufozu.flywheel.backend.compile.component.BufferTextureInstanceComponent; import com.jozufozu.flywheel.backend.compile.component.SsboInstanceComponent; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/BufferTextureInstanceComponent.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/BufferTextureInstanceComponent.java index b2218cbb9..1de3b5249 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/BufferTextureInstanceComponent.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/BufferTextureInstanceComponent.java @@ -2,7 +2,7 @@ import java.util.ArrayList; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.layout.Layout; import com.jozufozu.flywheel.backend.glsl.generate.FnSignature; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/InstanceStructComponent.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/InstanceStructComponent.java index 3a78fdc7f..123de197a 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/InstanceStructComponent.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/InstanceStructComponent.java @@ -3,7 +3,7 @@ import java.util.Collection; import java.util.Collections; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.layout.Layout; import com.jozufozu.flywheel.backend.compile.LayoutInterpreter; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/SsboInstanceComponent.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/SsboInstanceComponent.java index a09e87ea7..f8244ffb1 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/SsboInstanceComponent.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/SsboInstanceComponent.java @@ -2,7 +2,7 @@ import java.util.ArrayList; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.layout.Layout; import com.jozufozu.flywheel.backend.engine.indirect.IndirectBuffers; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/StringSubstitutionComponent.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/StringSubstitutionComponent.java index 071865d80..58cbdb73b 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/StringSubstitutionComponent.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/StringSubstitutionComponent.java @@ -3,7 +3,7 @@ import java.util.Collection; import java.util.Map; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.backend.glsl.SourceComponent; public final class StringSubstitutionComponent implements SourceComponent { diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/UberShaderComponent.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/UberShaderComponent.java index e93c49af2..733b76776 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/UberShaderComponent.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/component/UberShaderComponent.java @@ -9,7 +9,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.backend.compile.core.SourceLoader; import com.jozufozu.flywheel.backend.glsl.SourceComponent; import com.jozufozu.flywheel.backend.glsl.SourceFile; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java index a8c2c44da..27dc28cb1 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java @@ -8,7 +8,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.backend.glsl.SourceFile; import com.jozufozu.flywheel.backend.glsl.SourceLines; import com.jozufozu.flywheel.backend.glsl.error.ConsoleColors; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/engine/DrawManager.java b/common/src/backend/java/com/jozufozu/flywheel/backend/engine/DrawManager.java index c003a9264..404155aab 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/engine/DrawManager.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/engine/DrawManager.java @@ -8,13 +8,13 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; -import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.backend.Engine; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.model.Model; +import com.jozufozu.flywheel.backend.FlwBackend; import com.jozufozu.flywheel.backend.engine.embed.Environment; import com.jozufozu.flywheel.lib.util.Pair; @@ -98,7 +98,7 @@ private static boolean checkAndWarnEmptyModel(Model model) { .forEach(f -> builder.append("\n\t") .append(f.toString())); - Flywheel.LOGGER.warn(builder.toString()); + FlwBackend.LOGGER.warn(builder.toString()); return false; } diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/engine/uniform/FrameUniforms.java b/common/src/backend/java/com/jozufozu/flywheel/backend/engine/uniform/FrameUniforms.java index 8cf6380ab..e4467ab8e 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/engine/uniform/FrameUniforms.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/engine/uniform/FrameUniforms.java @@ -147,7 +147,7 @@ private static long writeCamera(long ptr) { } private static long writeTime(long ptr, RenderContext context) { - int ticks = ((LevelRendererAccessor) context.renderer()).flywheel$ticks(); + int ticks = ((LevelRendererAccessor) context.renderer()).flywheel$getTicks(); float partialTick = context.partialTick(); float renderTicks = ticks + partialTick; float renderSeconds = renderTicks / 20f; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/gl/GlCompat.java b/common/src/backend/java/com/jozufozu/flywheel/backend/gl/GlCompat.java index ae11d94d0..e284d6975 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/gl/GlCompat.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/gl/GlCompat.java @@ -12,7 +12,7 @@ import org.lwjgl.opengl.KHRShaderSubgroup; import org.lwjgl.system.MemoryStack; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.backend.FlwBackend; import com.jozufozu.flywheel.backend.compile.core.Compilation; import com.jozufozu.flywheel.backend.glsl.GlslVersion; import com.jozufozu.flywheel.lib.math.MoreMath; @@ -26,7 +26,7 @@ public final class GlCompat { caps = GL.getCapabilities(); } catch (IllegalStateException e) { // This happens with vulkanmod installed. - Flywheel.LOGGER.warn("Failed to get GL capabilities, all flywheel backends will be disabled."); + FlwBackend.LOGGER.warn("Failed to get GL capabilities; default Flywheel backends will be disabled."); caps = null; } CAPABILITIES = caps; diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/GameRendererAccessor.java b/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/GameRendererAccessor.java deleted file mode 100644 index cf92578fb..000000000 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/GameRendererAccessor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.jozufozu.flywheel.backend.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; -import org.spongepowered.asm.mixin.gen.Invoker; - -import net.minecraft.client.Camera; -import net.minecraft.client.renderer.GameRenderer; - -@Mixin(GameRenderer.class) -public interface GameRendererAccessor { - @Invoker("getFov") - double flywheel$getFov(Camera pActiveRenderInfo, float pPartialTicks, boolean pUseFOVSetting); - - @Accessor("zoom") - float flywheel$getZoom(); - - @Accessor("zoomX") - float flywheel$getZoomX(); - - @Accessor("zoomY") - float flywheel$getZoomY(); -} diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/LevelRendererAccessor.java b/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/LevelRendererAccessor.java index 5ddc4a5ba..a22055f7b 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/LevelRendererAccessor.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/LevelRendererAccessor.java @@ -8,5 +8,5 @@ @Mixin(LevelRenderer.class) public interface LevelRendererAccessor { @Accessor("ticks") - int flywheel$ticks(); + int flywheel$getTicks(); } diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/LightTextureAccessor.java b/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/LightTextureAccessor.java deleted file mode 100644 index edda4df14..000000000 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/LightTextureAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jozufozu.flywheel.backend.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.texture.DynamicTexture; - -@Mixin(LightTexture.class) -public interface LightTextureAccessor { - @Accessor("lightTexture") - DynamicTexture flywheel$texture(); -} diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/OptionsMixin.java b/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/OptionsMixin.java index e14e279df..8543d8162 100644 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/OptionsMixin.java +++ b/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/OptionsMixin.java @@ -10,7 +10,7 @@ import net.minecraft.client.Options; @Mixin(Options.class) -public class OptionsMixin { +abstract class OptionsMixin { @Inject(method = "load()V", at = @At("RETURN")) private void flywheel$onLoad(CallbackInfo ci) { OptionsUniforms.update((Options) (Object) this); diff --git a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/OverlayTextureAccessor.java b/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/OverlayTextureAccessor.java deleted file mode 100644 index 0f5af0ca6..000000000 --- a/common/src/backend/java/com/jozufozu/flywheel/backend/mixin/OverlayTextureAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jozufozu.flywheel.backend.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.client.renderer.texture.OverlayTexture; - -@Mixin(OverlayTexture.class) -public interface OverlayTextureAccessor { - @Accessor("texture") - DynamicTexture flywheel$texture(); -} diff --git a/common/src/backend/resources/flywheel.backend.mixins.json b/common/src/backend/resources/flywheel.backend.mixins.json index 164b33dca..9aef02424 100644 --- a/common/src/backend/resources/flywheel.backend.mixins.json +++ b/common/src/backend/resources/flywheel.backend.mixins.json @@ -6,12 +6,9 @@ "refmap": "backend-flywheel.refmap.json", "client": [ "AbstractClientPlayerAccessor", - "GameRendererAccessor", "GlStateManagerMixin", "LevelRendererAccessor", - "LightTextureAccessor", "OptionsMixin", - "OverlayTextureAccessor", "RenderSystemMixin" ], "injectors": { diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java b/common/src/lib/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java index 2f6e8ce47..8a56570ff 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java @@ -3,7 +3,7 @@ import org.jetbrains.annotations.ApiStatus; import org.lwjgl.system.MemoryUtil; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.layout.FloatRepr; import com.jozufozu.flywheel.api.layout.IntegerRepr; diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/internal/FlwLibLink.java b/common/src/lib/java/com/jozufozu/flywheel/lib/internal/FlwLibLink.java index a12b696ba..cf30466a1 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/internal/FlwLibLink.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/internal/FlwLibLink.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.lib.internal; +import org.slf4j.Logger; + import com.jozufozu.flywheel.api.internal.DependencyInjection; import com.jozufozu.flywheel.lib.transform.PoseTransformStack; import com.mojang.blaze3d.vertex.PoseStack; @@ -7,5 +9,7 @@ public interface FlwLibLink { FlwLibLink INSTANCE = DependencyInjection.load(FlwLibLink.class, "com.jozufozu.flywheel.impl.FlwLibLinkImpl"); + Logger getLogger(); + PoseTransformStack getPoseTransformStackOf(PoseStack stack); } diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/material/CutoutShaders.java b/common/src/lib/java/com/jozufozu/flywheel/lib/material/CutoutShaders.java index 8ce015841..e5694e97d 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/material/CutoutShaders.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/material/CutoutShaders.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.ApiStatus; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.material.CutoutShader; public class CutoutShaders { diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/material/FogShaders.java b/common/src/lib/java/com/jozufozu/flywheel/lib/material/FogShaders.java index 9c23ae718..7f3630a4e 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/material/FogShaders.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/material/FogShaders.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.ApiStatus; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.material.FogShader; public class FogShaders { diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/material/StandardMaterialShaders.java b/common/src/lib/java/com/jozufozu/flywheel/lib/material/StandardMaterialShaders.java index bfea555bd..715c476b1 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/material/StandardMaterialShaders.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/material/StandardMaterialShaders.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.ApiStatus; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.material.MaterialShaders; public final class StandardMaterialShaders { diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/memory/DebugMemoryBlockImpl.java b/common/src/lib/java/com/jozufozu/flywheel/lib/memory/DebugMemoryBlockImpl.java index b91dc53a6..e10b2023a 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/memory/DebugMemoryBlockImpl.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/memory/DebugMemoryBlockImpl.java @@ -2,7 +2,7 @@ import java.lang.ref.Cleaner; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.lib.internal.FlwLibLink; import com.jozufozu.flywheel.lib.util.StringUtil; class DebugMemoryBlockImpl extends AbstractMemoryBlockImpl { @@ -91,7 +91,7 @@ public void run() { builder.append("\n\t"); builder.append(frame); } - Flywheel.LOGGER.warn(builder.toString()); + FlwLibLink.INSTANCE.getLogger().warn(builder.toString()); FlwMemoryTracker.free(ptr); FlwMemoryTracker._freeCPUMemory(size); diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/util/ResourceUtil.java b/common/src/lib/java/com/jozufozu/flywheel/lib/util/ResourceUtil.java index 6ab2e76f7..36be0853c 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/util/ResourceUtil.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/util/ResourceUtil.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.lib.util; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/util/ShadersModHandler.java b/common/src/lib/java/com/jozufozu/flywheel/lib/util/ShadersModHandler.java index cd451ac32..8ab564351 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/util/ShadersModHandler.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/util/ShadersModHandler.java @@ -4,14 +4,11 @@ import java.util.function.BooleanSupplier; import org.jetbrains.annotations.ApiStatus; -import org.slf4j.Logger; +import com.jozufozu.flywheel.lib.internal.FlwLibLink; import com.jozufozu.flywheel.lib.internal.FlwLibXplat; -import com.mojang.logging.LogUtils; public final class ShadersModHandler { - private static final Logger LOGGER = LogUtils.getLogger(); - private static final String OPTIFINE_ROOT_PACKAGE = "net.optifine"; private static final boolean IS_IRIS_LOADED; @@ -29,13 +26,13 @@ public final class ShadersModHandler { // OptiFine and Iris/Oculus are assumed to be mutually exclusive if (IS_IRIS_LOADED) { - LOGGER.debug("Iris detected."); + FlwLibLink.INSTANCE.getLogger().debug("Iris detected."); INTERNAL_HANDLER = irisHandler; } else if (IS_OPTIFINE_INSTALLED) { - LOGGER.debug("OptiFine detected."); + FlwLibLink.INSTANCE.getLogger().debug("OptiFine detected."); INTERNAL_HANDLER = new OptifineHandler(); } else { - LOGGER.debug("No shaders mod detected."); + FlwLibLink.INSTANCE.getLogger().debug("No shaders mod detected."); INTERNAL_HANDLER = new InternalHandler() {}; } } diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleDynamicVisual.java b/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleDynamicVisual.java index 1abd2749d..8f0b76dc1 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleDynamicVisual.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleDynamicVisual.java @@ -4,7 +4,6 @@ import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.task.Plan; import com.jozufozu.flywheel.api.visual.DynamicVisual; -import com.jozufozu.flywheel.api.visual.TickableVisual; import com.jozufozu.flywheel.lib.task.RunnablePlan; public interface SimpleDynamicVisual extends DynamicVisual { diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleTickableVisual.java b/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleTickableVisual.java index baf8246e9..ac9a2d658 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleTickableVisual.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleTickableVisual.java @@ -3,7 +3,6 @@ import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.task.Plan; -import com.jozufozu.flywheel.api.visual.DynamicVisual; import com.jozufozu.flywheel.api.visual.TickableVisual; import com.jozufozu.flywheel.lib.task.RunnablePlan; diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java b/common/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java index cd144716d..de7dbed89 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java @@ -1,21 +1,17 @@ package com.jozufozu.flywheel.impl; import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.backend.Backends; import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl; import com.jozufozu.flywheel.lib.backend.SimpleBackend; -import com.mojang.logging.LogUtils; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.resources.ResourceLocation; public final class BackendManagerImpl { - private static final Logger LOGGER = LogUtils.getLogger(); - public static final Backend OFF_BACKEND = SimpleBackend.builder() .engineFactory(level -> { throw new UnsupportedOperationException("Cannot create engine when backend is off."); @@ -49,7 +45,7 @@ private static void chooseBackend() { var actual = preferred.findFallback(); if (preferred != actual) { - LOGGER.warn("Flywheel backend fell back from '{}' to '{}'", Backend.REGISTRY.getIdOrThrow(preferred), Backend.REGISTRY.getIdOrThrow(actual)); + FlwImpl.LOGGER.warn("Flywheel backend fell back from '{}' to '{}'", Backend.REGISTRY.getIdOrThrow(preferred), Backend.REGISTRY.getIdOrThrow(actual)); } backend = actual; diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/FlywheelInit.java b/common/src/main/java/com/jozufozu/flywheel/impl/FlwImpl.java similarity index 69% rename from common/src/main/java/com/jozufozu/flywheel/impl/FlywheelInit.java rename to common/src/main/java/com/jozufozu/flywheel/impl/FlwImpl.java index a7a81f478..53df9d4e1 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/FlywheelInit.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/FlwImpl.java @@ -1,7 +1,10 @@ package com.jozufozu.flywheel.impl; -import com.jozufozu.flywheel.backend.Backends; -import com.jozufozu.flywheel.backend.ShaderIndices; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.jozufozu.flywheel.api.Flywheel; +import com.jozufozu.flywheel.backend.FlwBackend; import com.jozufozu.flywheel.impl.registry.IdRegistryImpl; import com.jozufozu.flywheel.impl.registry.RegistryImpl; import com.jozufozu.flywheel.lib.instance.InstanceTypes; @@ -11,8 +14,11 @@ import com.jozufozu.flywheel.lib.util.ShadersModHandler; import com.jozufozu.flywheel.vanilla.VanillaVisuals; -public final class FlywheelInit { - private FlywheelInit() { +public final class FlwImpl { + public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID); + public static final Logger CONFIG_LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/config"); + + private FlwImpl() { } public static void init() { @@ -27,8 +33,7 @@ public static void init() { StandardMaterialShaders.init(); // backend - ShaderIndices.init(); - Backends.init(); + FlwBackend.init(); // vanilla VanillaVisuals.init(); diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/FlwLibLinkImpl.java b/common/src/main/java/com/jozufozu/flywheel/impl/FlwLibLinkImpl.java index 346afd1d1..f49536065 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/FlwLibLinkImpl.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/FlwLibLinkImpl.java @@ -1,11 +1,18 @@ package com.jozufozu.flywheel.impl; +import org.slf4j.Logger; + import com.jozufozu.flywheel.impl.extension.PoseStackExtension; import com.jozufozu.flywheel.lib.internal.FlwLibLink; import com.jozufozu.flywheel.lib.transform.PoseTransformStack; import com.mojang.blaze3d.vertex.PoseStack; public class FlwLibLinkImpl implements FlwLibLink { + @Override + public Logger getLogger() { + return FlwImpl.LOGGER; + } + @Override public PoseTransformStack getPoseTransformStackOf(PoseStack stack) { return ((PoseStackExtension) stack).flywheel$transformStack(); diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientChunkCacheMixin.java b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientChunkCacheMixin.java index 6f032bd86..30532a337 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientChunkCacheMixin.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientChunkCacheMixin.java @@ -20,12 +20,12 @@ abstract class ClientChunkCacheMixin { @Final ClientLevel level; - @Inject(at = @At("HEAD"), method = "onLightUpdate") - private void flywheel$onLightUpdate(LightLayer pType, SectionPos pPos, CallbackInfo ci) { + @Inject(method = "onLightUpdate", at = @At("HEAD")) + private void flywheel$onLightUpdate(LightLayer layer, SectionPos pos, CallbackInfo ci) { var manager = VisualizationManagerImpl.get(level); if (manager != null) { - manager.enqueueLightUpdateSection(pPos.asLong()); + manager.enqueueLightUpdateSection(pos.asLong()); } } } diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java index 993c0dffb..d9afd8992 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java @@ -107,7 +107,7 @@ abstract class LevelRendererMixin { flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN); } - @Group(name = "onStage$afterParticles", min = 1) + @Group(name = "onStage$afterParticles", min = 2, max = 2) @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;F)V", shift = Shift.AFTER)) private void flywheel$onStage$afterParticles$fabric(CallbackInfo ci) { flywheel$dispatch(RenderStage.AFTER_PARTICLES); diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/task/ParallelTaskExecutor.java b/common/src/main/java/com/jozufozu/flywheel/impl/task/ParallelTaskExecutor.java index d16efb030..eb1e38282 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/task/ParallelTaskExecutor.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/task/ParallelTaskExecutor.java @@ -9,19 +9,14 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BooleanSupplier; -import org.slf4j.Logger; - -import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.task.TaskExecutor; -import com.mojang.logging.LogUtils; +import com.jozufozu.flywheel.impl.FlwImpl; import net.minecraft.util.Mth; // https://github.com/CaffeineMC/sodium-fabric/blob/5d364ed5ba63f9067fcf72a078ca310bff4db3e9/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuilder.java // https://stackoverflow.com/questions/29655531 public class ParallelTaskExecutor implements TaskExecutor { - private static final Logger LOGGER = LogUtils.getLogger(); - private final String name; private final int threadCount; @@ -70,7 +65,7 @@ public void startWorkers() { threads.add(thread); } - LOGGER.info("Started {} worker threads", threads.size()); + FlwImpl.LOGGER.info("Started {} worker threads", threads.size()); } public void stopWorkers() { @@ -82,7 +77,7 @@ public void stopWorkers() { throw new IllegalStateException("No threads are alive but the executor is in the RUNNING state"); } - LOGGER.info("Stopping worker threads"); + FlwImpl.LOGGER.info("Stopping worker threads"); // Notify all worker threads to wake up, where they will then terminate synchronized (taskNotifier) { @@ -233,7 +228,7 @@ private void processTask(Runnable task) { try { task.run(); } catch (Exception e) { - Flywheel.LOGGER.error("Error running task", e); + FlwImpl.LOGGER.error("Error running task", e); } finally { waitGroup.done(); } @@ -243,7 +238,7 @@ private void processMainThreadTask(Runnable task) { try { task.run(); } catch (Exception e) { - Flywheel.LOGGER.error("Error running main thread task", e); + FlwImpl.LOGGER.error("Error running main thread task", e); } } diff --git a/common/src/test/java/com/jozufozu/flywheel/backend/glsl/TestBase.java b/common/src/test/java/com/jozufozu/flywheel/backend/glsl/TestBase.java index beebdad43..1d74bdebb 100644 --- a/common/src/test/java/com/jozufozu/flywheel/backend/glsl/TestBase.java +++ b/common/src/test/java/com/jozufozu/flywheel/backend/glsl/TestBase.java @@ -6,7 +6,7 @@ import java.util.List; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import net.minecraft.resources.ResourceLocation; diff --git a/fabric/src/backend/java/com/jozufozu/flywheel/backend/compile/FlwProgramsReloader.java b/fabric/src/backend/java/com/jozufozu/flywheel/backend/compile/FlwProgramsReloader.java index a6fce9831..4d32525eb 100644 --- a/fabric/src/backend/java/com/jozufozu/flywheel/backend/compile/FlwProgramsReloader.java +++ b/fabric/src/backend/java/com/jozufozu/flywheel/backend/compile/FlwProgramsReloader.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.compile; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; import net.minecraft.resources.ResourceLocation; diff --git a/fabric/src/lib/java/com/jozufozu/flywheel/lib/model/baked/PartialModelEventHandler.java b/fabric/src/lib/java/com/jozufozu/flywheel/lib/model/baked/PartialModelEventHandler.java index ebab75af5..a1d80cbd0 100644 --- a/fabric/src/lib/java/com/jozufozu/flywheel/lib/model/baked/PartialModelEventHandler.java +++ b/fabric/src/lib/java/com/jozufozu/flywheel/lib/model/baked/PartialModelEventHandler.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.ApiStatus; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys; import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; diff --git a/fabric/src/main/java/com/jozufozu/flywheel/impl/FabricFlwConfig.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/FabricFlwConfig.java index f8ec8ff37..e147424f1 100644 --- a/fabric/src/main/java/com/jozufozu/flywheel/impl/FabricFlwConfig.java +++ b/fabric/src/main/java/com/jozufozu/flywheel/impl/FabricFlwConfig.java @@ -11,7 +11,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; -import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.api.backend.BackendManager; @@ -25,21 +24,21 @@ public class FabricFlwConfig implements FlwConfig { .getConfigDir() .resolve("flywheel.json"); - public static final FabricFlwConfig INSTANCE = new FabricFlwConfig(PATH.toFile()); - - protected static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + public static final boolean LIMIT_UPDATES_DEFAULT = true; public static final int WORKER_THREADS_DEFAULT = -1; public static final int WORKER_THREADS_MAX = Runtime.getRuntime() .availableProcessors(); - public static final boolean LIMIT_UPDATES_DEFAULT = true; + + public static final FabricFlwConfig INSTANCE = new FabricFlwConfig(PATH.toFile()); + + private final File file; public Backend backend = BackendManager.getDefaultBackend(); public boolean limitUpdates = LIMIT_UPDATES_DEFAULT; public int workerThreads = WORKER_THREADS_DEFAULT; - private final File file; - public FabricFlwConfig(File file) { this.file = file; } @@ -64,7 +63,7 @@ public void load() { try (FileReader reader = new FileReader(file)) { fromJson(JsonParser.parseReader(reader)); } catch (Exception e) { - Flywheel.LOGGER.error("Could not load config from file '{}'", file.getAbsolutePath(), e); + FlwImpl.CONFIG_LOGGER.warn("Could not load config from file '{}'", file.getAbsolutePath(), e); } } // In case we found an error in the config file, immediately save to fix it. @@ -75,12 +74,13 @@ public void save() { try (FileWriter writer = new FileWriter(file)) { GSON.toJson(toJson(), writer); } catch (Exception e) { - Flywheel.LOGGER.error("Could not save config to file '{}'", file.getAbsolutePath(), e); + FlwImpl.CONFIG_LOGGER.warn("Could not save config to file '{}'", file.getAbsolutePath(), e); } } public void fromJson(JsonElement json) { if (!(json instanceof JsonObject object)) { + FlwImpl.CONFIG_LOGGER.warn("Config JSON must be an object"); backend = BackendManager.getDefaultBackend(); limitUpdates = LIMIT_UPDATES_DEFAULT; workerThreads = WORKER_THREADS_DEFAULT; @@ -94,41 +94,42 @@ public void fromJson(JsonElement json) { private void readBackend(JsonObject object) { var backendJson = object.get("backend"); - - String err = null; + String msg = null; if (backendJson instanceof JsonPrimitive primitive && primitive.isString()) { - var backendString = primitive.getAsString(); + var value = primitive.getAsString(); try { - this.backend = Backend.REGISTRY.getOrThrow(new ResourceLocation(backendString)); + this.backend = Backend.REGISTRY.getOrThrow(new ResourceLocation(value)); return; - } catch (IllegalArgumentException e) { - err = "backend ID '" + backendString + "' is not registered"; } catch (ResourceLocationException e) { - err = "backend '" + backendString + "' is not a valid resource location"; + msg = "'backend' value '" + value + "' is not a valid resource location"; + } catch (IllegalArgumentException e) { + msg = "Backend with ID '" + value + "' is not registered"; } catch (Exception e) { // Something else went wrong? This should be dead code. - err = "backend '" + backendString + "' is invalid"; + msg = "'backend' value '" + value + "' is invalid"; } } else if (backendJson != null) { - err = "backend must be a string"; + msg = "'backend' value must be a string"; } // Don't log an error if the field is missing. - if (err != null) { - Flywheel.LOGGER.warn(err); + if (msg != null) { + FlwImpl.CONFIG_LOGGER.warn(msg); } backend = BackendManager.getDefaultBackend(); } private void readLimitUpdates(JsonObject object) { var limitUpdatesJson = object.get("limitUpdates"); + if (limitUpdatesJson instanceof JsonPrimitive primitive && primitive.isBoolean()) { limitUpdates = primitive.getAsBoolean(); return; } else if (limitUpdatesJson != null) { - Flywheel.LOGGER.warn("limitUpdates must be a boolean"); + FlwImpl.CONFIG_LOGGER.warn("'limitUpdates' value must be a boolean"); } + limitUpdates = LIMIT_UPDATES_DEFAULT; } @@ -136,18 +137,17 @@ private void readWorkerThreads(JsonObject object) { var workerThreadsJson = object.get("workerThreads"); if (workerThreadsJson instanceof JsonPrimitive primitive && primitive.isNumber()) { - int configuredValue = primitive.getAsInt(); - - int clamped = Mth.clamp(configuredValue, WORKER_THREADS_DEFAULT, WORKER_THREADS_MAX); + int value = primitive.getAsInt(); + int clamped = Mth.clamp(value, WORKER_THREADS_DEFAULT, WORKER_THREADS_MAX); - if (clamped != configuredValue) { - Flywheel.LOGGER.warn("workerThreads value of {} is out of range, clamping to {}", configuredValue, clamped); + if (clamped != value) { + FlwImpl.CONFIG_LOGGER.warn("'workerThreads' value of {} is out of range, clamping to {}", value, clamped); } workerThreads = clamped; return; } else if (workerThreadsJson != null) { - Flywheel.LOGGER.warn("workerThreads must be an integer"); + FlwImpl.CONFIG_LOGGER.warn("'workerThreads' value must be an integer"); } workerThreads = WORKER_THREADS_DEFAULT; @@ -155,9 +155,9 @@ private void readWorkerThreads(JsonObject object) { public JsonObject toJson() { JsonObject object = new JsonObject(); + object.addProperty("backend", Backend.REGISTRY.getIdOrThrow(backend).toString()); object.addProperty("limitUpdates", limitUpdates); object.addProperty("workerThreads", workerThreads); - object.addProperty("backend", Backend.REGISTRY.getIdOrThrow(backend).toString()); return object; } } diff --git a/fabric/src/main/java/com/jozufozu/flywheel/impl/FlywheelFabric.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/FlywheelFabric.java index e4f58f5d8..68857a7e1 100644 --- a/fabric/src/main/java/com/jozufozu/flywheel/impl/FlywheelFabric.java +++ b/fabric/src/main/java/com/jozufozu/flywheel/impl/FlywheelFabric.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.UnknownNullability; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.event.BeginFrameCallback; import com.jozufozu.flywheel.api.event.EndClientResourceReloadCallback; import com.jozufozu.flywheel.api.event.ReloadLevelRendererCallback; @@ -40,13 +40,7 @@ public void onInitializeClient() { setupLib(); setupBackend(); - FlywheelInit.init(); - - // FIXME: Registries cannot be frozen this early. - FlywheelInit.freezeRegistries(); - // Have to load the config after we freeze registries, - // so we can find third party backends. - FabricFlwConfig.INSTANCE.load(); + FlwImpl.init(); } private static void setupImpl() { diff --git a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java index c1ec8c809..0fed00bf7 100644 --- a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java +++ b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java @@ -11,6 +11,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.jozufozu.flywheel.api.event.EndClientResourceReloadCallback; +import com.jozufozu.flywheel.impl.FabricFlwConfig; +import com.jozufozu.flywheel.impl.FlwImpl; import net.minecraft.client.Minecraft; import net.minecraft.server.packs.resources.ReloadableResourceManager; @@ -21,6 +23,14 @@ abstract class MinecraftMixin { @Final private ReloadableResourceManager resourceManager; + @Inject(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/ReloadableResourceManager;createReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/server/packs/resources/ReloadInstance;")) + private void flywheel$onBeginInitialResourceReload(CallbackInfo ci) { + FlwImpl.freezeRegistries(); + // Load the config after we freeze registries, + // so we can find third party backends. + FabricFlwConfig.INSTANCE.load(); + } + @Inject(method = "method_24040", at = @At("HEAD")) private void flywheel$onEndInitialResourceReload(Optional error, CallbackInfo ci) { EndClientResourceReloadCallback.EVENT.invoker() diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwCommands.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwCommands.java index f8cdb2929..37795b40c 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwCommands.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwCommands.java @@ -24,11 +24,9 @@ private FlwCommands() { } public static void registerClientCommands(RegisterClientCommandsEvent event) { - ForgeFlwConfig config = ForgeFlwConfig.INSTANCE; - LiteralArgumentBuilder command = Commands.literal("flywheel"); - ConfigValue backendValue = config.client.backend; + ConfigValue backendValue = ForgeFlwConfig.INSTANCE.client.backend; command.then(Commands.literal("backend") .executes(context -> { Backend backend = BackendManager.getBackend(); @@ -58,7 +56,7 @@ public static void registerClientCommands(RegisterClientCommandsEvent event) { return Command.SINGLE_SUCCESS; }))); - BooleanValue limitUpdatesValue = config.client.limitUpdates; + BooleanValue limitUpdatesValue = ForgeFlwConfig.INSTANCE.client.limitUpdates; command.then(Commands.literal("limitUpdates") .executes(context -> { if (limitUpdatesValue.get()) { diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwLibXplatImpl.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwLibXplatImpl.java index 4dc57a159..ef50b33fc 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwLibXplatImpl.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwLibXplatImpl.java @@ -3,7 +3,6 @@ import java.lang.reflect.Field; import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; import com.jozufozu.flywheel.lib.internal.FlwLibXplat; import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder; @@ -13,7 +12,6 @@ import com.jozufozu.flywheel.lib.model.baked.ForgeMultiBlockModelBuilder; import com.jozufozu.flywheel.lib.model.baked.MultiBlockModelBuilder; import com.jozufozu.flywheel.lib.util.ShadersModHandler; -import com.mojang.logging.LogUtils; import net.irisshaders.iris.api.v0.IrisApi; import net.minecraft.client.Minecraft; @@ -27,8 +25,6 @@ import net.minecraftforge.fml.util.ObfuscationReflectionHelper; public class FlwLibXplatImpl implements FlwLibXplat { - private static final Logger LOGGER = LogUtils.getLogger(); - @Override public BlockRenderDispatcher createVanillaBlockRenderDispatcher() { BlockRenderDispatcher defaultDispatcher = Minecraft.getInstance().getBlockRenderer(); @@ -40,7 +36,7 @@ public BlockRenderDispatcher createVanillaBlockRenderDispatcher() { } ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "f_110900_"); } catch (Exception e) { - LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e); + FlwImpl.LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e); return defaultDispatcher; } return dispatcher; diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java index 7905f3709..03c06b4ec 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java @@ -3,7 +3,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.jetbrains.annotations.UnknownNullability; -import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.api.Flywheel; import com.jozufozu.flywheel.api.event.BeginFrameEvent; import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent; @@ -33,7 +33,6 @@ import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegisterEvent; @@ -66,7 +65,7 @@ private static void clientInit(IEventBus forgeEventBus, IEventBus modEventBus) { registerBackendEventListeners(forgeEventBus, modEventBus); CrashReportCallables.registerCrashCallable("Flywheel Backend", BackendManagerImpl::getBackendString); - FlywheelInit.init(); + FlwImpl.init(); } private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBus modEventBus) { @@ -95,8 +94,6 @@ private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBu FlwDebugInfo.addDebugInfo(minecraft, e.getRight()); }); - modEventBus.addListener((FMLLoadCompleteEvent e) -> FlywheelInit.freezeRegistries()); - modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error().isPresent())); modEventBus.addListener((FMLCommonSetupEvent e) -> { diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/ForgeFlwConfig.java b/forge/src/main/java/com/jozufozu/flywheel/impl/ForgeFlwConfig.java index 012bea791..fff51a309 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/ForgeFlwConfig.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/ForgeFlwConfig.java @@ -2,11 +2,9 @@ import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.api.backend.BackendManager; -import com.mojang.logging.LogUtils; import net.minecraft.ResourceLocationException; import net.minecraft.resources.ResourceLocation; @@ -15,7 +13,6 @@ import net.minecraftforge.fml.config.ModConfig; public class ForgeFlwConfig implements FlwConfig { - private static final Logger LOGGER = LogUtils.getLogger(); public static final ForgeFlwConfig INSTANCE = new ForgeFlwConfig(); public final ClientConfig client; @@ -44,13 +41,13 @@ private static Backend parseBackend(String idStr) { try { backendId = new ResourceLocation(idStr); } catch (ResourceLocationException e) { - LOGGER.warn("Config contains invalid backend ID '" + idStr + "'!"); + FlwImpl.CONFIG_LOGGER.warn("'backend' value '{}' is not a valid resource location", idStr); return null; } Backend backend = Backend.REGISTRY.get(backendId); if (backend == null) { - LOGGER.warn("Config contains non-existent backend with ID '" + backendId + "'!"); + FlwImpl.CONFIG_LOGGER.warn("Backend with ID '{}' is not registered", backendId); return null; } diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java index 38ad493bb..16874dbaf 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java @@ -2,15 +2,18 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; +import com.jozufozu.flywheel.impl.FlwImpl; import com.mojang.realmsclient.client.RealmsClient; import net.minecraft.client.Minecraft; @@ -25,6 +28,13 @@ abstract class MinecraftMixin { @Final private ReloadableResourceManager resourceManager; + // Inject at invoke cannot be used in constructors in vanilla Mixin, so use ModifyArg instead. + @ModifyArg(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/ReloadableResourceManager;createReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/server/packs/resources/ReloadInstance;"), index = 0) + private Executor flywheel$onBeginInitialResourceReload(Executor arg0) { + FlwImpl.freezeRegistries(); + return arg0; + } + @Inject(method = "lambda$new$5", at = @At("HEAD")) private void flywheel$onEndInitialResourceReload(RealmsClient realmsClient, ReloadInstance reloadInstance, GameConfig gameConfig, Optional error, CallbackInfo ci) { ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, true, error));