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
This commit is contained in:
PepperCode1 2024-05-12 16:01:08 -07:00 committed by Jozufozu
parent 6dff488f8c
commit 914ce0a7de
54 changed files with 147 additions and 188 deletions

View file

@ -2,17 +2,16 @@ package com.jozufozu.gradle.platform
import com.jozufozu.gradle.jarset.JarTaskSet import com.jozufozu.gradle.jarset.JarTaskSet
import net.fabricmc.loom.api.LoomGradleExtensionAPI 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.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.SourceSet
import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.jvm.tasks.Jar 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 org.gradle.language.jvm.tasks.ProcessResources
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty

View file

@ -19,7 +19,6 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.gradle.language.jvm.tasks.ProcessResources import org.gradle.language.jvm.tasks.ProcessResources
class SubprojectPlugin: Plugin<Project> { class SubprojectPlugin: Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
project.extensions.create("defaultPackageInfos", PackageInfosExtension::class.java, project) project.extensions.create("defaultPackageInfos", PackageInfosExtension::class.java, project)

View file

@ -4,8 +4,6 @@ import org.gradle.api.Action
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.file.FileCollection import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.SourceSet 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) { open class TransitiveSourceSetsExtension(private val project: Project) {
var compileClasspath: FileCollection? = null var compileClasspath: FileCollection? = null

View file

@ -1,13 +1,9 @@
package com.jozufozu.flywheel; package com.jozufozu.flywheel.api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public final class Flywheel { public final class Flywheel {
public static final String ID = "flywheel"; public static final String ID = "flywheel";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);
private Flywheel() { private Flywheel() {
} }

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend; 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.api.backend.Backend;
import com.jozufozu.flywheel.backend.compile.IndirectPrograms; import com.jozufozu.flywheel.backend.compile.IndirectPrograms;
import com.jozufozu.flywheel.backend.compile.InstancingPrograms; import com.jozufozu.flywheel.backend.compile.InstancingPrograms;

View file

@ -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();
}
}

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend;
import java.util.List; 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.FloatRepr;
import com.jozufozu.flywheel.api.layout.Layout; import com.jozufozu.flywheel.api.layout.Layout;
import com.jozufozu.flywheel.api.layout.LayoutBuilder; import com.jozufozu.flywheel.api.layout.LayoutBuilder;

View file

@ -7,7 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList; 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.api.instance.InstanceType;
import com.jozufozu.flywheel.backend.ShaderIndices; import com.jozufozu.flywheel.backend.ShaderIndices;
import com.jozufozu.flywheel.backend.compile.component.UberShaderComponent; import com.jozufozu.flywheel.backend.compile.component.UberShaderComponent;
@ -22,7 +22,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManager;
public final class FlwPrograms { 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_VERT = Flywheel.rl("internal/components_header.vert");
private static final ResourceLocation COMPONENTS_HEADER_FRAG = Flywheel.rl("internal/components_header.frag"); private static final ResourceLocation COMPONENTS_HEADER_FRAG = Flywheel.rl("internal/components_header.frag");

View file

@ -1,13 +1,12 @@
package com.jozufozu.flywheel.backend.compile; package com.jozufozu.flywheel.backend.compile;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.google.common.collect.ImmutableList; 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.api.instance.InstanceType;
import com.jozufozu.flywheel.backend.compile.component.InstanceStructComponent; import com.jozufozu.flywheel.backend.compile.component.InstanceStructComponent;
import com.jozufozu.flywheel.backend.compile.component.SsboInstanceComponent; import com.jozufozu.flywheel.backend.compile.component.SsboInstanceComponent;

View file

@ -1,6 +1,5 @@
package com.jozufozu.flywheel.backend.compile; package com.jozufozu.flywheel.backend.compile;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View file

@ -1,10 +1,9 @@
package com.jozufozu.flywheel.backend.compile; package com.jozufozu.flywheel.backend.compile;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; 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.InternalVertex;
import com.jozufozu.flywheel.backend.Samplers; import com.jozufozu.flywheel.backend.Samplers;
import com.jozufozu.flywheel.backend.compile.component.InstanceStructComponent; import com.jozufozu.flywheel.backend.compile.component.InstanceStructComponent;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.compile; 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.Samplers;
import com.jozufozu.flywheel.backend.compile.component.BufferTextureInstanceComponent; import com.jozufozu.flywheel.backend.compile.component.BufferTextureInstanceComponent;
import com.jozufozu.flywheel.backend.compile.component.SsboInstanceComponent; import com.jozufozu.flywheel.backend.compile.component.SsboInstanceComponent;

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.compile.component;
import java.util.ArrayList; 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.instance.InstanceType;
import com.jozufozu.flywheel.api.layout.Layout; import com.jozufozu.flywheel.api.layout.Layout;
import com.jozufozu.flywheel.backend.glsl.generate.FnSignature; import com.jozufozu.flywheel.backend.glsl.generate.FnSignature;

View file

@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.compile.component;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; 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.instance.InstanceType;
import com.jozufozu.flywheel.api.layout.Layout; import com.jozufozu.flywheel.api.layout.Layout;
import com.jozufozu.flywheel.backend.compile.LayoutInterpreter; import com.jozufozu.flywheel.backend.compile.LayoutInterpreter;

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.compile.component;
import java.util.ArrayList; 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.instance.InstanceType;
import com.jozufozu.flywheel.api.layout.Layout; import com.jozufozu.flywheel.api.layout.Layout;
import com.jozufozu.flywheel.backend.engine.indirect.IndirectBuffers; import com.jozufozu.flywheel.backend.engine.indirect.IndirectBuffers;

View file

@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.compile.component;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.Flywheel;
import com.jozufozu.flywheel.backend.glsl.SourceComponent; import com.jozufozu.flywheel.backend.glsl.SourceComponent;
public final class StringSubstitutionComponent implements SourceComponent { public final class StringSubstitutionComponent implements SourceComponent {

View file

@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; 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.compile.core.SourceLoader;
import com.jozufozu.flywheel.backend.glsl.SourceComponent; import com.jozufozu.flywheel.backend.glsl.SourceComponent;
import com.jozufozu.flywheel.backend.glsl.SourceFile; import com.jozufozu.flywheel.backend.glsl.SourceFile;

View file

@ -8,7 +8,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; 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.SourceFile;
import com.jozufozu.flywheel.backend.glsl.SourceLines; import com.jozufozu.flywheel.backend.glsl.SourceLines;
import com.jozufozu.flywheel.backend.glsl.error.ConsoleColors; import com.jozufozu.flywheel.backend.glsl.error.ConsoleColors;

View file

@ -8,13 +8,13 @@ import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.backend.Engine; import com.jozufozu.flywheel.api.backend.Engine;
import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.instance.InstanceType;
import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.instance.Instancer;
import com.jozufozu.flywheel.api.model.Model; 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.backend.engine.embed.Environment;
import com.jozufozu.flywheel.lib.util.Pair; import com.jozufozu.flywheel.lib.util.Pair;
@ -98,7 +98,7 @@ public abstract class DrawManager<N extends AbstractInstancer<?>> {
.forEach(f -> builder.append("\n\t") .forEach(f -> builder.append("\n\t")
.append(f.toString())); .append(f.toString()));
Flywheel.LOGGER.warn(builder.toString()); FlwBackend.LOGGER.warn(builder.toString());
return false; return false;
} }

View file

@ -147,7 +147,7 @@ public final class FrameUniforms extends UniformWriter {
} }
private static long writeTime(long ptr, RenderContext context) { 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 partialTick = context.partialTick();
float renderTicks = ticks + partialTick; float renderTicks = ticks + partialTick;
float renderSeconds = renderTicks / 20f; float renderSeconds = renderTicks / 20f;

View file

@ -12,7 +12,7 @@ import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.opengl.KHRShaderSubgroup; import org.lwjgl.opengl.KHRShaderSubgroup;
import org.lwjgl.system.MemoryStack; 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.compile.core.Compilation;
import com.jozufozu.flywheel.backend.glsl.GlslVersion; import com.jozufozu.flywheel.backend.glsl.GlslVersion;
import com.jozufozu.flywheel.lib.math.MoreMath; import com.jozufozu.flywheel.lib.math.MoreMath;
@ -26,7 +26,7 @@ public final class GlCompat {
caps = GL.getCapabilities(); caps = GL.getCapabilities();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// This happens with vulkanmod installed. // 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; caps = null;
} }
CAPABILITIES = caps; CAPABILITIES = caps;

View file

@ -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();
}

View file

@ -8,5 +8,5 @@ import net.minecraft.client.renderer.LevelRenderer;
@Mixin(LevelRenderer.class) @Mixin(LevelRenderer.class)
public interface LevelRendererAccessor { public interface LevelRendererAccessor {
@Accessor("ticks") @Accessor("ticks")
int flywheel$ticks(); int flywheel$getTicks();
} }

View file

@ -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();
}

View file

@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.engine.uniform.OptionsUniforms;
import net.minecraft.client.Options; import net.minecraft.client.Options;
@Mixin(Options.class) @Mixin(Options.class)
public class OptionsMixin { abstract class OptionsMixin {
@Inject(method = "load()V", at = @At("RETURN")) @Inject(method = "load()V", at = @At("RETURN"))
private void flywheel$onLoad(CallbackInfo ci) { private void flywheel$onLoad(CallbackInfo ci) {
OptionsUniforms.update((Options) (Object) this); OptionsUniforms.update((Options) (Object) this);

View file

@ -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();
}

View file

@ -6,12 +6,9 @@
"refmap": "backend-flywheel.refmap.json", "refmap": "backend-flywheel.refmap.json",
"client": [ "client": [
"AbstractClientPlayerAccessor", "AbstractClientPlayerAccessor",
"GameRendererAccessor",
"GlStateManagerMixin", "GlStateManagerMixin",
"LevelRendererAccessor", "LevelRendererAccessor",
"LightTextureAccessor",
"OptionsMixin", "OptionsMixin",
"OverlayTextureAccessor",
"RenderSystemMixin" "RenderSystemMixin"
], ],
"injectors": { "injectors": {

View file

@ -3,7 +3,7 @@ package com.jozufozu.flywheel.lib.instance;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import org.lwjgl.system.MemoryUtil; 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.instance.InstanceType;
import com.jozufozu.flywheel.api.layout.FloatRepr; import com.jozufozu.flywheel.api.layout.FloatRepr;
import com.jozufozu.flywheel.api.layout.IntegerRepr; import com.jozufozu.flywheel.api.layout.IntegerRepr;

View file

@ -1,5 +1,7 @@
package com.jozufozu.flywheel.lib.internal; package com.jozufozu.flywheel.lib.internal;
import org.slf4j.Logger;
import com.jozufozu.flywheel.api.internal.DependencyInjection; import com.jozufozu.flywheel.api.internal.DependencyInjection;
import com.jozufozu.flywheel.lib.transform.PoseTransformStack; import com.jozufozu.flywheel.lib.transform.PoseTransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
@ -7,5 +9,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
public interface FlwLibLink { public interface FlwLibLink {
FlwLibLink INSTANCE = DependencyInjection.load(FlwLibLink.class, "com.jozufozu.flywheel.impl.FlwLibLinkImpl"); FlwLibLink INSTANCE = DependencyInjection.load(FlwLibLink.class, "com.jozufozu.flywheel.impl.FlwLibLinkImpl");
Logger getLogger();
PoseTransformStack getPoseTransformStackOf(PoseStack stack); PoseTransformStack getPoseTransformStackOf(PoseStack stack);
} }

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.lib.material;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.Flywheel;
import com.jozufozu.flywheel.api.material.CutoutShader; import com.jozufozu.flywheel.api.material.CutoutShader;
public class CutoutShaders { public class CutoutShaders {

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.lib.material;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.Flywheel;
import com.jozufozu.flywheel.api.material.FogShader; import com.jozufozu.flywheel.api.material.FogShader;
public class FogShaders { public class FogShaders {

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.lib.material;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.Flywheel;
import com.jozufozu.flywheel.api.material.MaterialShaders; import com.jozufozu.flywheel.api.material.MaterialShaders;
public final class StandardMaterialShaders { public final class StandardMaterialShaders {

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.lib.memory;
import java.lang.ref.Cleaner; import java.lang.ref.Cleaner;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.lib.internal.FlwLibLink;
import com.jozufozu.flywheel.lib.util.StringUtil; import com.jozufozu.flywheel.lib.util.StringUtil;
class DebugMemoryBlockImpl extends AbstractMemoryBlockImpl { class DebugMemoryBlockImpl extends AbstractMemoryBlockImpl {
@ -91,7 +91,7 @@ class DebugMemoryBlockImpl extends AbstractMemoryBlockImpl {
builder.append("\n\t"); builder.append("\n\t");
builder.append(frame); builder.append(frame);
} }
Flywheel.LOGGER.warn(builder.toString()); FlwLibLink.INSTANCE.getLogger().warn(builder.toString());
FlwMemoryTracker.free(ptr); FlwMemoryTracker.free(ptr);
FlwMemoryTracker._freeCPUMemory(size); FlwMemoryTracker._freeCPUMemory(size);

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.lib.util; 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.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;

View file

@ -4,14 +4,11 @@ import java.lang.reflect.Field;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import org.jetbrains.annotations.ApiStatus; 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.jozufozu.flywheel.lib.internal.FlwLibXplat;
import com.mojang.logging.LogUtils;
public final class ShadersModHandler { public final class ShadersModHandler {
private static final Logger LOGGER = LogUtils.getLogger();
private static final String OPTIFINE_ROOT_PACKAGE = "net.optifine"; private static final String OPTIFINE_ROOT_PACKAGE = "net.optifine";
private static final boolean IS_IRIS_LOADED; 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 // OptiFine and Iris/Oculus are assumed to be mutually exclusive
if (IS_IRIS_LOADED) { if (IS_IRIS_LOADED) {
LOGGER.debug("Iris detected."); FlwLibLink.INSTANCE.getLogger().debug("Iris detected.");
INTERNAL_HANDLER = irisHandler; INTERNAL_HANDLER = irisHandler;
} else if (IS_OPTIFINE_INSTALLED) { } else if (IS_OPTIFINE_INSTALLED) {
LOGGER.debug("OptiFine detected."); FlwLibLink.INSTANCE.getLogger().debug("OptiFine detected.");
INTERNAL_HANDLER = new OptifineHandler(); INTERNAL_HANDLER = new OptifineHandler();
} else { } else {
LOGGER.debug("No shaders mod detected."); FlwLibLink.INSTANCE.getLogger().debug("No shaders mod detected.");
INTERNAL_HANDLER = new InternalHandler() {}; INTERNAL_HANDLER = new InternalHandler() {};
} }
} }

View file

@ -4,7 +4,6 @@ import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.instance.Instancer;
import com.jozufozu.flywheel.api.task.Plan; import com.jozufozu.flywheel.api.task.Plan;
import com.jozufozu.flywheel.api.visual.DynamicVisual; import com.jozufozu.flywheel.api.visual.DynamicVisual;
import com.jozufozu.flywheel.api.visual.TickableVisual;
import com.jozufozu.flywheel.lib.task.RunnablePlan; import com.jozufozu.flywheel.lib.task.RunnablePlan;
public interface SimpleDynamicVisual extends DynamicVisual { public interface SimpleDynamicVisual extends DynamicVisual {

View file

@ -3,7 +3,6 @@ package com.jozufozu.flywheel.lib.visual;
import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.instance.Instancer;
import com.jozufozu.flywheel.api.task.Plan; 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.api.visual.TickableVisual;
import com.jozufozu.flywheel.lib.task.RunnablePlan; import com.jozufozu.flywheel.lib.task.RunnablePlan;

View file

@ -1,21 +1,17 @@
package com.jozufozu.flywheel.impl; package com.jozufozu.flywheel.impl;
import org.jetbrains.annotations.Nullable; 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.api.backend.Backend;
import com.jozufozu.flywheel.backend.Backends; import com.jozufozu.flywheel.backend.Backends;
import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl; import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl;
import com.jozufozu.flywheel.lib.backend.SimpleBackend; import com.jozufozu.flywheel.lib.backend.SimpleBackend;
import com.mojang.logging.LogUtils;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public final class BackendManagerImpl { public final class BackendManagerImpl {
private static final Logger LOGGER = LogUtils.getLogger();
public static final Backend OFF_BACKEND = SimpleBackend.builder() public static final Backend OFF_BACKEND = SimpleBackend.builder()
.engineFactory(level -> { .engineFactory(level -> {
throw new UnsupportedOperationException("Cannot create engine when backend is off."); throw new UnsupportedOperationException("Cannot create engine when backend is off.");
@ -49,7 +45,7 @@ public final class BackendManagerImpl {
var actual = preferred.findFallback(); var actual = preferred.findFallback();
if (preferred != actual) { 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; backend = actual;

View file

@ -1,7 +1,10 @@
package com.jozufozu.flywheel.impl; package com.jozufozu.flywheel.impl;
import com.jozufozu.flywheel.backend.Backends; import org.slf4j.Logger;
import com.jozufozu.flywheel.backend.ShaderIndices; 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.IdRegistryImpl;
import com.jozufozu.flywheel.impl.registry.RegistryImpl; import com.jozufozu.flywheel.impl.registry.RegistryImpl;
import com.jozufozu.flywheel.lib.instance.InstanceTypes; import com.jozufozu.flywheel.lib.instance.InstanceTypes;
@ -11,8 +14,11 @@ import com.jozufozu.flywheel.lib.material.StandardMaterialShaders;
import com.jozufozu.flywheel.lib.util.ShadersModHandler; import com.jozufozu.flywheel.lib.util.ShadersModHandler;
import com.jozufozu.flywheel.vanilla.VanillaVisuals; import com.jozufozu.flywheel.vanilla.VanillaVisuals;
public final class FlywheelInit { public final class FlwImpl {
private FlywheelInit() { 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() { public static void init() {
@ -27,8 +33,7 @@ public final class FlywheelInit {
StandardMaterialShaders.init(); StandardMaterialShaders.init();
// backend // backend
ShaderIndices.init(); FlwBackend.init();
Backends.init();
// vanilla // vanilla
VanillaVisuals.init(); VanillaVisuals.init();

View file

@ -1,11 +1,18 @@
package com.jozufozu.flywheel.impl; package com.jozufozu.flywheel.impl;
import org.slf4j.Logger;
import com.jozufozu.flywheel.impl.extension.PoseStackExtension; import com.jozufozu.flywheel.impl.extension.PoseStackExtension;
import com.jozufozu.flywheel.lib.internal.FlwLibLink; import com.jozufozu.flywheel.lib.internal.FlwLibLink;
import com.jozufozu.flywheel.lib.transform.PoseTransformStack; import com.jozufozu.flywheel.lib.transform.PoseTransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
public class FlwLibLinkImpl implements FlwLibLink { public class FlwLibLinkImpl implements FlwLibLink {
@Override
public Logger getLogger() {
return FlwImpl.LOGGER;
}
@Override @Override
public PoseTransformStack getPoseTransformStackOf(PoseStack stack) { public PoseTransformStack getPoseTransformStackOf(PoseStack stack) {
return ((PoseStackExtension) stack).flywheel$transformStack(); return ((PoseStackExtension) stack).flywheel$transformStack();

View file

@ -20,12 +20,12 @@ abstract class ClientChunkCacheMixin {
@Final @Final
ClientLevel level; ClientLevel level;
@Inject(at = @At("HEAD"), method = "onLightUpdate") @Inject(method = "onLightUpdate", at = @At("HEAD"))
private void flywheel$onLightUpdate(LightLayer pType, SectionPos pPos, CallbackInfo ci) { private void flywheel$onLightUpdate(LightLayer layer, SectionPos pos, CallbackInfo ci) {
var manager = VisualizationManagerImpl.get(level); var manager = VisualizationManagerImpl.get(level);
if (manager != null) { if (manager != null) {
manager.enqueueLightUpdateSection(pPos.asLong()); manager.enqueueLightUpdateSection(pos.asLong());
} }
} }
} }

View file

@ -107,7 +107,7 @@ abstract class LevelRendererMixin {
flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN); 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)) @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) { private void flywheel$onStage$afterParticles$fabric(CallbackInfo ci) {
flywheel$dispatch(RenderStage.AFTER_PARTICLES); flywheel$dispatch(RenderStage.AFTER_PARTICLES);

View file

@ -9,19 +9,14 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import org.slf4j.Logger;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.task.TaskExecutor; import com.jozufozu.flywheel.api.task.TaskExecutor;
import com.mojang.logging.LogUtils; import com.jozufozu.flywheel.impl.FlwImpl;
import net.minecraft.util.Mth; 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://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 // https://stackoverflow.com/questions/29655531
public class ParallelTaskExecutor implements TaskExecutor { public class ParallelTaskExecutor implements TaskExecutor {
private static final Logger LOGGER = LogUtils.getLogger();
private final String name; private final String name;
private final int threadCount; private final int threadCount;
@ -70,7 +65,7 @@ public class ParallelTaskExecutor implements TaskExecutor {
threads.add(thread); threads.add(thread);
} }
LOGGER.info("Started {} worker threads", threads.size()); FlwImpl.LOGGER.info("Started {} worker threads", threads.size());
} }
public void stopWorkers() { public void stopWorkers() {
@ -82,7 +77,7 @@ public class ParallelTaskExecutor implements TaskExecutor {
throw new IllegalStateException("No threads are alive but the executor is in the RUNNING state"); 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 // Notify all worker threads to wake up, where they will then terminate
synchronized (taskNotifier) { synchronized (taskNotifier) {
@ -233,7 +228,7 @@ public class ParallelTaskExecutor implements TaskExecutor {
try { try {
task.run(); task.run();
} catch (Exception e) { } catch (Exception e) {
Flywheel.LOGGER.error("Error running task", e); FlwImpl.LOGGER.error("Error running task", e);
} finally { } finally {
waitGroup.done(); waitGroup.done();
} }
@ -243,7 +238,7 @@ public class ParallelTaskExecutor implements TaskExecutor {
try { try {
task.run(); task.run();
} catch (Exception e) { } catch (Exception e) {
Flywheel.LOGGER.error("Error running main thread task", e); FlwImpl.LOGGER.error("Error running main thread task", e);
} }
} }

View file

@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.List; import java.util.List;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.Flywheel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.compile; 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.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -4,7 +4,7 @@ import java.util.List;
import org.jetbrains.annotations.ApiStatus; 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.ResourceReloadListenerKeys;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;

View file

@ -11,7 +11,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.api.backend.Backend;
import com.jozufozu.flywheel.api.backend.BackendManager; import com.jozufozu.flywheel.api.backend.BackendManager;
@ -25,21 +24,21 @@ public class FabricFlwConfig implements FlwConfig {
.getConfigDir() .getConfigDir()
.resolve("flywheel.json"); .resolve("flywheel.json");
public static final FabricFlwConfig INSTANCE = new FabricFlwConfig(PATH.toFile()); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
protected 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_DEFAULT = -1;
public static final int WORKER_THREADS_MAX = Runtime.getRuntime() public static final int WORKER_THREADS_MAX = Runtime.getRuntime()
.availableProcessors(); .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 Backend backend = BackendManager.getDefaultBackend();
public boolean limitUpdates = LIMIT_UPDATES_DEFAULT; public boolean limitUpdates = LIMIT_UPDATES_DEFAULT;
public int workerThreads = WORKER_THREADS_DEFAULT; public int workerThreads = WORKER_THREADS_DEFAULT;
private final File file;
public FabricFlwConfig(File file) { public FabricFlwConfig(File file) {
this.file = file; this.file = file;
} }
@ -64,7 +63,7 @@ public class FabricFlwConfig implements FlwConfig {
try (FileReader reader = new FileReader(file)) { try (FileReader reader = new FileReader(file)) {
fromJson(JsonParser.parseReader(reader)); fromJson(JsonParser.parseReader(reader));
} catch (Exception e) { } 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. // In case we found an error in the config file, immediately save to fix it.
@ -75,12 +74,13 @@ public class FabricFlwConfig implements FlwConfig {
try (FileWriter writer = new FileWriter(file)) { try (FileWriter writer = new FileWriter(file)) {
GSON.toJson(toJson(), writer); GSON.toJson(toJson(), writer);
} catch (Exception e) { } 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) { public void fromJson(JsonElement json) {
if (!(json instanceof JsonObject object)) { if (!(json instanceof JsonObject object)) {
FlwImpl.CONFIG_LOGGER.warn("Config JSON must be an object");
backend = BackendManager.getDefaultBackend(); backend = BackendManager.getDefaultBackend();
limitUpdates = LIMIT_UPDATES_DEFAULT; limitUpdates = LIMIT_UPDATES_DEFAULT;
workerThreads = WORKER_THREADS_DEFAULT; workerThreads = WORKER_THREADS_DEFAULT;
@ -94,41 +94,42 @@ public class FabricFlwConfig implements FlwConfig {
private void readBackend(JsonObject object) { private void readBackend(JsonObject object) {
var backendJson = object.get("backend"); var backendJson = object.get("backend");
String msg = null;
String err = null;
if (backendJson instanceof JsonPrimitive primitive && primitive.isString()) { if (backendJson instanceof JsonPrimitive primitive && primitive.isString()) {
var backendString = primitive.getAsString(); var value = primitive.getAsString();
try { try {
this.backend = Backend.REGISTRY.getOrThrow(new ResourceLocation(backendString)); this.backend = Backend.REGISTRY.getOrThrow(new ResourceLocation(value));
return; return;
} catch (IllegalArgumentException e) {
err = "backend ID '" + backendString + "' is not registered";
} catch (ResourceLocationException e) { } 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) { } catch (Exception e) {
// Something else went wrong? This should be dead code. // Something else went wrong? This should be dead code.
err = "backend '" + backendString + "' is invalid"; msg = "'backend' value '" + value + "' is invalid";
} }
} else if (backendJson != null) { } 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. // Don't log an error if the field is missing.
if (err != null) { if (msg != null) {
Flywheel.LOGGER.warn(err); FlwImpl.CONFIG_LOGGER.warn(msg);
} }
backend = BackendManager.getDefaultBackend(); backend = BackendManager.getDefaultBackend();
} }
private void readLimitUpdates(JsonObject object) { private void readLimitUpdates(JsonObject object) {
var limitUpdatesJson = object.get("limitUpdates"); var limitUpdatesJson = object.get("limitUpdates");
if (limitUpdatesJson instanceof JsonPrimitive primitive && primitive.isBoolean()) { if (limitUpdatesJson instanceof JsonPrimitive primitive && primitive.isBoolean()) {
limitUpdates = primitive.getAsBoolean(); limitUpdates = primitive.getAsBoolean();
return; return;
} else if (limitUpdatesJson != null) { } 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; limitUpdates = LIMIT_UPDATES_DEFAULT;
} }
@ -136,18 +137,17 @@ public class FabricFlwConfig implements FlwConfig {
var workerThreadsJson = object.get("workerThreads"); var workerThreadsJson = object.get("workerThreads");
if (workerThreadsJson instanceof JsonPrimitive primitive && primitive.isNumber()) { if (workerThreadsJson instanceof JsonPrimitive primitive && primitive.isNumber()) {
int configuredValue = primitive.getAsInt(); int value = primitive.getAsInt();
int clamped = Mth.clamp(value, WORKER_THREADS_DEFAULT, WORKER_THREADS_MAX);
int clamped = Mth.clamp(configuredValue, WORKER_THREADS_DEFAULT, WORKER_THREADS_MAX); if (clamped != value) {
FlwImpl.CONFIG_LOGGER.warn("'workerThreads' value of {} is out of range, clamping to {}", value, clamped);
if (clamped != configuredValue) {
Flywheel.LOGGER.warn("workerThreads value of {} is out of range, clamping to {}", configuredValue, clamped);
} }
workerThreads = clamped; workerThreads = clamped;
return; return;
} else if (workerThreadsJson != null) { } 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; workerThreads = WORKER_THREADS_DEFAULT;
@ -155,9 +155,9 @@ public class FabricFlwConfig implements FlwConfig {
public JsonObject toJson() { public JsonObject toJson() {
JsonObject object = new JsonObject(); JsonObject object = new JsonObject();
object.addProperty("backend", Backend.REGISTRY.getIdOrThrow(backend).toString());
object.addProperty("limitUpdates", limitUpdates); object.addProperty("limitUpdates", limitUpdates);
object.addProperty("workerThreads", workerThreads); object.addProperty("workerThreads", workerThreads);
object.addProperty("backend", Backend.REGISTRY.getIdOrThrow(backend).toString());
return object; return object;
} }
} }

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.impl;
import org.jetbrains.annotations.UnknownNullability; 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.BeginFrameCallback;
import com.jozufozu.flywheel.api.event.EndClientResourceReloadCallback; import com.jozufozu.flywheel.api.event.EndClientResourceReloadCallback;
import com.jozufozu.flywheel.api.event.ReloadLevelRendererCallback; import com.jozufozu.flywheel.api.event.ReloadLevelRendererCallback;
@ -40,13 +40,7 @@ public final class FlywheelFabric implements ClientModInitializer {
setupLib(); setupLib();
setupBackend(); setupBackend();
FlywheelInit.init(); FlwImpl.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();
} }
private static void setupImpl() { private static void setupImpl() {

View file

@ -11,6 +11,8 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.api.event.EndClientResourceReloadCallback; 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.client.Minecraft;
import net.minecraft.server.packs.resources.ReloadableResourceManager; import net.minecraft.server.packs.resources.ReloadableResourceManager;
@ -21,6 +23,14 @@ abstract class MinecraftMixin {
@Final @Final
private ReloadableResourceManager resourceManager; private ReloadableResourceManager resourceManager;
@Inject(method = "<init>", 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")) @Inject(method = "method_24040", at = @At("HEAD"))
private void flywheel$onEndInitialResourceReload(Optional<Throwable> error, CallbackInfo ci) { private void flywheel$onEndInitialResourceReload(Optional<Throwable> error, CallbackInfo ci) {
EndClientResourceReloadCallback.EVENT.invoker() EndClientResourceReloadCallback.EVENT.invoker()

View file

@ -24,11 +24,9 @@ public final class FlwCommands {
} }
public static void registerClientCommands(RegisterClientCommandsEvent event) { public static void registerClientCommands(RegisterClientCommandsEvent event) {
ForgeFlwConfig config = ForgeFlwConfig.INSTANCE;
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal("flywheel"); LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal("flywheel");
ConfigValue<String> backendValue = config.client.backend; ConfigValue<String> backendValue = ForgeFlwConfig.INSTANCE.client.backend;
command.then(Commands.literal("backend") command.then(Commands.literal("backend")
.executes(context -> { .executes(context -> {
Backend backend = BackendManager.getBackend(); Backend backend = BackendManager.getBackend();
@ -58,7 +56,7 @@ public final class FlwCommands {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
}))); })));
BooleanValue limitUpdatesValue = config.client.limitUpdates; BooleanValue limitUpdatesValue = ForgeFlwConfig.INSTANCE.client.limitUpdates;
command.then(Commands.literal("limitUpdates") command.then(Commands.literal("limitUpdates")
.executes(context -> { .executes(context -> {
if (limitUpdatesValue.get()) { if (limitUpdatesValue.get()) {

View file

@ -3,7 +3,6 @@ package com.jozufozu.flywheel.impl;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import com.jozufozu.flywheel.lib.internal.FlwLibXplat; import com.jozufozu.flywheel.lib.internal.FlwLibXplat;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder; import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder;
@ -13,7 +12,6 @@ import com.jozufozu.flywheel.lib.model.baked.ForgeBlockModelBuilder;
import com.jozufozu.flywheel.lib.model.baked.ForgeMultiBlockModelBuilder; import com.jozufozu.flywheel.lib.model.baked.ForgeMultiBlockModelBuilder;
import com.jozufozu.flywheel.lib.model.baked.MultiBlockModelBuilder; import com.jozufozu.flywheel.lib.model.baked.MultiBlockModelBuilder;
import com.jozufozu.flywheel.lib.util.ShadersModHandler; import com.jozufozu.flywheel.lib.util.ShadersModHandler;
import com.mojang.logging.LogUtils;
import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -27,8 +25,6 @@ import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper; import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
public class FlwLibXplatImpl implements FlwLibXplat { public class FlwLibXplatImpl implements FlwLibXplat {
private static final Logger LOGGER = LogUtils.getLogger();
@Override @Override
public BlockRenderDispatcher createVanillaBlockRenderDispatcher() { public BlockRenderDispatcher createVanillaBlockRenderDispatcher() {
BlockRenderDispatcher defaultDispatcher = Minecraft.getInstance().getBlockRenderer(); BlockRenderDispatcher defaultDispatcher = Minecraft.getInstance().getBlockRenderer();
@ -40,7 +36,7 @@ public class FlwLibXplatImpl implements FlwLibXplat {
} }
ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "f_110900_"); ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "f_110900_");
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e); FlwImpl.LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e);
return defaultDispatcher; return defaultDispatcher;
} }
return dispatcher; return dispatcher;

View file

@ -3,7 +3,7 @@ package com.jozufozu.flywheel.impl;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.jetbrains.annotations.UnknownNullability; 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.BeginFrameEvent;
import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent;
import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent; import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent;
@ -33,7 +33,6 @@ import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent; import net.minecraftforge.registries.RegisterEvent;
@ -66,7 +65,7 @@ public final class FlywheelForge {
registerBackendEventListeners(forgeEventBus, modEventBus); registerBackendEventListeners(forgeEventBus, modEventBus);
CrashReportCallables.registerCrashCallable("Flywheel Backend", BackendManagerImpl::getBackendString); CrashReportCallables.registerCrashCallable("Flywheel Backend", BackendManagerImpl::getBackendString);
FlywheelInit.init(); FlwImpl.init();
} }
private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBus modEventBus) { private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBus modEventBus) {
@ -95,8 +94,6 @@ public final class FlywheelForge {
FlwDebugInfo.addDebugInfo(minecraft, e.getRight()); FlwDebugInfo.addDebugInfo(minecraft, e.getRight());
}); });
modEventBus.addListener((FMLLoadCompleteEvent e) -> FlywheelInit.freezeRegistries());
modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error().isPresent())); modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error().isPresent()));
modEventBus.addListener((FMLCommonSetupEvent e) -> { modEventBus.addListener((FMLCommonSetupEvent e) -> {

View file

@ -2,11 +2,9 @@ package com.jozufozu.flywheel.impl;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.api.backend.Backend;
import com.jozufozu.flywheel.api.backend.BackendManager; import com.jozufozu.flywheel.api.backend.BackendManager;
import com.mojang.logging.LogUtils;
import net.minecraft.ResourceLocationException; import net.minecraft.ResourceLocationException;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -15,7 +13,6 @@ import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.config.ModConfig;
public class ForgeFlwConfig implements FlwConfig { public class ForgeFlwConfig implements FlwConfig {
private static final Logger LOGGER = LogUtils.getLogger();
public static final ForgeFlwConfig INSTANCE = new ForgeFlwConfig(); public static final ForgeFlwConfig INSTANCE = new ForgeFlwConfig();
public final ClientConfig client; public final ClientConfig client;
@ -44,13 +41,13 @@ public class ForgeFlwConfig implements FlwConfig {
try { try {
backendId = new ResourceLocation(idStr); backendId = new ResourceLocation(idStr);
} catch (ResourceLocationException e) { } 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; return null;
} }
Backend backend = Backend.REGISTRY.get(backendId); Backend backend = Backend.REGISTRY.get(backendId);
if (backend == null) { 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; return null;
} }

View file

@ -2,15 +2,18 @@ package com.jozufozu.flywheel.impl.mixin;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent;
import com.jozufozu.flywheel.impl.FlwImpl;
import com.mojang.realmsclient.client.RealmsClient; import com.mojang.realmsclient.client.RealmsClient;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -25,6 +28,13 @@ abstract class MinecraftMixin {
@Final @Final
private ReloadableResourceManager resourceManager; private ReloadableResourceManager resourceManager;
// Inject at invoke cannot be used in constructors in vanilla Mixin, so use ModifyArg instead.
@ModifyArg(method = "<init>", 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")) @Inject(method = "lambda$new$5", at = @At("HEAD"))
private void flywheel$onEndInitialResourceReload(RealmsClient realmsClient, ReloadInstance reloadInstance, GameConfig gameConfig, Optional<Throwable> error, CallbackInfo ci) { private void flywheel$onEndInitialResourceReload(RealmsClient realmsClient, ReloadInstance reloadInstance, GameConfig gameConfig, Optional<Throwable> error, CallbackInfo ci) {
ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, true, error)); ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, true, error));