Reorganize and simplify

- StructTypes no longer need to be registered
 - Move backend.source to core.source
 - Move GameStateRegistry to core
 - Backend is static again
 - Loader maintains state internally
This commit is contained in:
Jozufozu 2022-01-12 21:25:03 -08:00
parent 2854e1f1dc
commit 29d4ec03c2
68 changed files with 257 additions and 317 deletions

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel; package com.jozufozu.flywheel;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.OptifineHandler;
import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.Contexts;
import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.PartialModel;
import com.jozufozu.flywheel.core.StitchedSprite; import com.jozufozu.flywheel.core.StitchedSprite;
import com.jozufozu.flywheel.core.compile.ProgramCompiler; import com.jozufozu.flywheel.core.compile.ProgramCompiler;
@ -18,15 +18,14 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
public class FlywheelClient { public class FlywheelClient {
public static void clientInit() { public static void clientInit() {
CrashReportCallables.registerCrashCallable("Flywheel Backend", () -> CrashReportCallables.registerCrashCallable("Flywheel Backend", Backend::getBackendDescriptor);
Backend.getInstance().getBackendDescriptor());
OptifineHandler.init();
Backend.init(); Backend.init();
IEventBus modEventBus = FMLJavaModLoadingContext.get() IEventBus modEventBus = FMLJavaModLoadingContext.get()
.getModEventBus(); .getModEventBus();
modEventBus.addListener(Contexts::flwInit); modEventBus.addListener(Contexts::flwInit);
modEventBus.addListener(Materials::flwInit);
modEventBus.addListener(PartialModel::onModelRegistry); modEventBus.addListener(PartialModel::onModelRegistry);
modEventBus.addListener(PartialModel::onModelBake); modEventBus.addListener(PartialModel::onModelBake);
modEventBus.addListener(StitchedSprite::onTextureStitchPre); modEventBus.addListener(StitchedSprite::onTextureStitchPre);

View file

@ -1,19 +1,11 @@
package com.jozufozu.flywheel.backend; package com.jozufozu.flywheel.backend;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.api.FlywheelWorld; import com.jozufozu.flywheel.api.FlywheelWorld;
import com.jozufozu.flywheel.api.InstanceData;
import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.config.FlwEngine; import com.jozufozu.flywheel.config.FlwEngine;
@ -27,89 +19,39 @@ import net.minecraft.world.level.LevelAccessor;
public class Backend { public class Backend {
public static final Logger LOGGER = LogManager.getLogger(Backend.class); public static final Logger LOGGER = LogManager.getLogger(Backend.class);
protected static final Backend INSTANCE = new Backend(); private static FlwEngine engine;
public static Backend getInstance() {
return INSTANCE;
}
private FlwEngine engine; public static GlCompat compat;
public GLCapabilities capabilities; private static final Loader loader = new Loader();
public GlCompat compat;
public final Loader loader;
private final Map<ResourceLocation, StructType<?>> materialRegistry = new HashMap<>();
private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
protected Backend() {
loader = new Loader(this);
OptifineHandler.init();
}
/** /**
* Get a string describing the Flywheel backend. When there are eventually multiple backends * Get a string describing the Flywheel backend. When there are eventually multiple backends
* (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use. * (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use.
*/ */
public String getBackendDescriptor() { public static String getBackendDescriptor() {
return engine == null ? "" : engine.getProperName(); return engine == null ? "" : engine.getProperName();
} }
public FlwEngine getEngine() { public static FlwEngine getEngine() {
return engine; return engine;
} }
/**
* Register a shader program.
*/
public ProgramSpec register(ProgramSpec spec) {
ResourceLocation name = spec.name;
if (programSpecRegistry.containsKey(name)) {
throw new IllegalStateException("Program spec '" + name + "' already registered.");
}
programSpecRegistry.put(name, spec);
return spec;
}
/**
* Register an instancing material.
*/
public <D extends InstanceData> StructType<D> register(ResourceLocation name, StructType<D> spec) {
if (materialRegistry.containsKey(name)) {
throw new IllegalStateException("Material spec '" + name + "' already registered.");
}
materialRegistry.put(name, spec);
LOGGER.debug("registered material '" + name + "' with instance size " + spec.getLayout().getStride());
return spec;
}
@Nullable @Nullable
public ProgramSpec getSpec(ResourceLocation name) { public static ProgramSpec getSpec(ResourceLocation name) {
return programSpecRegistry.get(name); return loader.get(name);
} }
public void refresh() { public static void refresh() {
OptifineHandler.refresh(); OptifineHandler.refresh();
capabilities = GL.createCapabilities(); compat = new GlCompat();
compat = new GlCompat(capabilities);
engine = chooseEngine(compat); engine = chooseEngine(compat);
} }
public Collection<StructType<?>> allMaterials() {
return materialRegistry.values();
}
public Collection<ProgramSpec> allPrograms() {
return programSpecRegistry.values();
}
public static boolean isOn() { public static boolean isOn() {
return getInstance().engine != FlwEngine.OFF; return engine != FlwEngine.OFF;
} }
public static boolean canUseInstancing(@Nullable Level world) { public static boolean canUseInstancing(@Nullable Level world) {
@ -137,18 +79,6 @@ public class Backend {
RenderWork.enqueue(Minecraft.getInstance().levelRenderer::allChanged); RenderWork.enqueue(Minecraft.getInstance().levelRenderer::allChanged);
} }
/**
* INTERNAL USE ONLY
*/
void _clearContexts() {
GameStateRegistry.clear();
programSpecRegistry.clear();
materialRegistry.clear();
}
public static void init() {
}
private static FlwEngine chooseEngine(GlCompat compat) { private static FlwEngine chooseEngine(GlCompat compat) {
FlwEngine preferredChoice = FlwConfig.get() FlwEngine preferredChoice = FlwConfig.get()
.getEngine(); .getEngine();
@ -162,4 +92,12 @@ public class Backend {
return canUseEngine ? preferredChoice : FlwEngine.OFF; return canUseEngine ? preferredChoice : FlwEngine.OFF;
} }
public static void init() {
// noop
}
private Backend() {
throw new UnsupportedOperationException("Backend is a static class!");
}
} }

View file

@ -1,15 +1,20 @@
package com.jozufozu.flywheel.backend; package com.jozufozu.flywheel.backend;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.backend.source.Resolver; import com.jozufozu.flywheel.core.GameStateRegistry;
import com.jozufozu.flywheel.backend.source.ShaderSources;
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer; import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
import com.jozufozu.flywheel.core.shader.ProgramSpec; import com.jozufozu.flywheel.core.shader.ProgramSpec;
import com.jozufozu.flywheel.core.source.Resolver;
import com.jozufozu.flywheel.core.source.ShaderSources;
import com.jozufozu.flywheel.event.GatherContextEvent; import com.jozufozu.flywheel.event.GatherContextEvent;
import com.jozufozu.flywheel.util.ResourceUtil; import com.jozufozu.flywheel.util.ResourceUtil;
import com.jozufozu.flywheel.util.StringUtil; import com.jozufozu.flywheel.util.StringUtil;
@ -37,13 +42,11 @@ public class Loader implements ResourceManagerReloadListener {
public static final String PROGRAM_DIR = "flywheel/programs/"; public static final String PROGRAM_DIR = "flywheel/programs/";
private static final Gson GSON = new GsonBuilder().create(); private static final Gson GSON = new GsonBuilder().create();
private final Backend backend; private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
private boolean firstLoad = true; private boolean firstLoad = true;
public Loader(Backend backend) { Loader() {
this.backend = backend;
// Can be null when running datagenerators due to the unfortunate time we call this // Can be null when running datagenerators due to the unfortunate time we call this
Minecraft minecraft = Minecraft.getInstance(); Minecraft minecraft = Minecraft.getInstance();
if (minecraft != null) { if (minecraft != null) {
@ -54,15 +57,20 @@ public class Loader implements ResourceManagerReloadListener {
} }
} }
@Nullable
public ProgramSpec get(ResourceLocation name) {
return programSpecRegistry.get(name);
}
@Override @Override
public void onResourceManagerReload(ResourceManager manager) { public void onResourceManagerReload(ResourceManager manager) {
backend.refresh(); Backend.refresh();
backend._clearContexts(); GameStateRegistry._clear();
Resolver.INSTANCE.invalidate(); Resolver.INSTANCE.invalidate();
ModLoader.get() ModLoader.get()
.postEvent(new GatherContextEvent(backend, firstLoad)); .postEvent(new GatherContextEvent(firstLoad));
ShaderSources sources = new ShaderSources(manager); ShaderSources sources = new ShaderSources(manager);
@ -101,10 +109,21 @@ public class Loader implements ResourceManagerReloadListener {
spec.setName(specName); spec.setName(specName);
backend.register(spec); register(spec);
} catch (Exception e) { } catch (Exception e) {
Backend.LOGGER.error(e); Backend.LOGGER.error(e);
} }
} }
} }
/**
* Register a shader program.
*/
private void register(ProgramSpec spec) {
ResourceLocation name = spec.name;
if (programSpecRegistry.containsKey(name)) {
throw new IllegalStateException("Program spec '" + name + "' already registered.");
}
programSpecRegistry.put(name, spec);
}
} }

View file

@ -21,7 +21,7 @@ public abstract class GlBuffer extends GlObject {
* @return A buffer that will be persistent if the driver supports it. * @return A buffer that will be persistent if the driver supports it.
*/ */
public static GlBuffer requestPersistent(GlBufferType type) { public static GlBuffer requestPersistent(GlBufferType type) {
if (Backend.getInstance().compat.bufferStorageSupported()) { if (Backend.compat.bufferStorageSupported()) {
return new PersistentGlBuffer(type); return new PersistentGlBuffer(type);
} else { } else {
return new MappedGlBuffer(type); return new MappedGlBuffer(type);

View file

@ -46,7 +46,7 @@ public class PersistentGlBuffer extends GlBuffer implements Mappable {
fence.clear(); fence.clear();
Backend.getInstance().compat.bufferStorage.bufferStorage(type, size, flags); Backend.compat.bufferStorage.bufferStorage(type, size, flags);
ByteBuffer byteBuffer = GL30.glMapBufferRange(type.glEnum, 0, size, flags); ByteBuffer byteBuffer = GL30.glMapBufferRange(type.glEnum, 0, size, flags);

View file

@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL20;
import com.jozufozu.flywheel.backend.gl.GlObject; import com.jozufozu.flywheel.backend.gl.GlObject;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.jozufozu.flywheel.backend.source.ShaderLoadingException; import com.jozufozu.flywheel.core.source.ShaderLoadingException;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -4,6 +4,7 @@ import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import org.lwjgl.PointerBuffer; import org.lwjgl.PointerBuffer;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryStack;
@ -23,11 +24,11 @@ public class GlCompat {
public final BufferStorage bufferStorage; public final BufferStorage bufferStorage;
public final boolean amd; public final boolean amd;
public GlCompat(GLCapabilities caps) { public GlCompat() {
GLCapabilities caps = GL.createCapabilities();
instancedArrays = getLatest(InstancedArrays.class, caps); instancedArrays = getLatest(InstancedArrays.class, caps);
bufferStorage = getLatest(BufferStorage.class, caps); bufferStorage = getLatest(BufferStorage.class, caps);
if (Util.getPlatform() == Util.OS.WINDOWS) { if (Util.getPlatform() == Util.OS.WINDOWS) {
String vendor = GL20C.glGetString(GL20C.GL_VENDOR); String vendor = GL20C.glGetString(GL20C.GL_VENDOR);
// vendor string I got was "ATI Technologies Inc." // vendor string I got was "ATI Technologies Inc."

View file

@ -39,8 +39,7 @@ public class InstanceWorld {
this.taskEngine = new ParallelTaskEngine("Flywheel " + world.dimension().location()); this.taskEngine = new ParallelTaskEngine("Flywheel " + world.dimension().location());
this.taskEngine.startWorkers(); this.taskEngine.startWorkers();
FlwEngine engine = Backend.getInstance() FlwEngine engine = Backend.getEngine();
.getEngine();
switch (engine) { switch (engine) {
case INSTANCING -> { case INSTANCING -> {

View file

@ -198,7 +198,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
vao.bindAttributes(attributeBaseIndex, instanceFormat); vao.bindAttributes(attributeBaseIndex, instanceFormat);
for (int i = 0; i < instanceFormat.getAttributeCount(); i++) { for (int i = 0; i < instanceFormat.getAttributeCount(); i++) {
Backend.getInstance().compat.instancedArrays.vertexAttribDivisor(attributeBaseIndex + i, 1); Backend.compat.instancedArrays.vertexAttribDivisor(attributeBaseIndex + i, 1);
} }
} }
} }

View file

@ -37,7 +37,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
public InstancedMaterialGroup(InstancingEngine<P> owner, RenderType type) { public InstancedMaterialGroup(InstancingEngine<P> owner, RenderType type) {
this.owner = owner; this.owner = owner;
this.type = type; this.type = type;
if (Backend.getInstance().compat.onAMDWindows()) { if (Backend.compat.onAMDWindows()) {
this.allocator = FallbackAllocator.INSTANCE; this.allocator = FallbackAllocator.INSTANCE;
} else { } else {
this.allocator = new ModelPool(Formats.POS_TEX_NORMAL, 2048); this.allocator = new ModelPool(Formats.POS_TEX_NORMAL, 2048);

View file

@ -1,13 +1,12 @@
package com.jozufozu.flywheel.core; package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.GameStateRegistry;
import com.jozufozu.flywheel.backend.source.FileResolution;
import com.jozufozu.flywheel.backend.source.Resolver;
import com.jozufozu.flywheel.core.compile.ProgramCompiler; import com.jozufozu.flywheel.core.compile.ProgramCompiler;
import com.jozufozu.flywheel.core.crumbling.CrumblingProgram; import com.jozufozu.flywheel.core.crumbling.CrumblingProgram;
import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider; import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.core.source.Resolver;
import com.jozufozu.flywheel.event.GatherContextEvent; import com.jozufozu.flywheel.event.GatherContextEvent;
import com.jozufozu.flywheel.util.ResourceUtil; import com.jozufozu.flywheel.util.ResourceUtil;

View file

@ -1,10 +1,10 @@
package com.jozufozu.flywheel.backend; package com.jozufozu.flywheel.core;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.jozufozu.flywheel.core.compile.ShaderConstants;
import com.jozufozu.flywheel.core.shader.GameStateProvider; import com.jozufozu.flywheel.core.shader.GameStateProvider;
import com.jozufozu.flywheel.core.shader.ShaderConstants;
import com.jozufozu.flywheel.core.shader.StateSnapshot; import com.jozufozu.flywheel.core.shader.StateSnapshot;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -13,7 +13,7 @@ public class GameStateRegistry {
private static final Map<ResourceLocation, GameStateProvider> registeredStateProviders = new HashMap<>(); private static final Map<ResourceLocation, GameStateProvider> registeredStateProviders = new HashMap<>();
static void clear() { public static void _clear() {
registeredStateProviders.clear(); registeredStateProviders.clear();
} }

View file

@ -2,12 +2,10 @@ package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.materials.model.ModelType; import com.jozufozu.flywheel.core.materials.model.ModelType;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData; import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.core.materials.oriented.OrientedType; import com.jozufozu.flywheel.core.materials.oriented.OrientedType;
import com.jozufozu.flywheel.event.GatherContextEvent;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
@ -19,12 +17,6 @@ public class Materials {
public static final StructType<OrientedData> ORIENTED = new OrientedType(); public static final StructType<OrientedData> ORIENTED = new OrientedType();
public static final StructType<ModelData> TRANSFORMED = new ModelType(); public static final StructType<ModelData> TRANSFORMED = new ModelType();
public static void flwInit(GatherContextEvent event) {
Backend backend = event.getBackend();
backend.register(Names.ORIENTED, ORIENTED);
backend.register(Names.MODEL, TRANSFORMED);
}
public static class Names { public static class Names {
public static final ResourceLocation MODEL = Flywheel.rl("model"); public static final ResourceLocation MODEL = Flywheel.rl("model");
public static final ResourceLocation ORIENTED = Flywheel.rl("oriented"); public static final ResourceLocation ORIENTED = Flywheel.rl("oriented");

View file

@ -1,10 +1,16 @@
package com.jozufozu.flywheel.core.compile; package com.jozufozu.flywheel.core.compile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.jozufozu.flywheel.backend.gl.GLSLVersion; import com.jozufozu.flywheel.backend.gl.GLSLVersion;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType; import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
public class CompileUtil { public class CompileUtil {
public static final Pattern vecType = Pattern.compile("^[biud]?vec([234])$");
public static final Pattern matType = Pattern.compile("^mat([234])(?:x([234]))?$");
protected static String generateHeader(GLSLVersion version, ShaderType type) { protected static String generateHeader(GLSLVersion version, ShaderType type) {
return "#version " return "#version "
+ version + version
@ -13,4 +19,31 @@ public class CompileUtil {
+ "#extension GL_ARB_conservative_depth : enable\n" + "#extension GL_ARB_conservative_depth : enable\n"
+ type.getDefineStatement(); + type.getDefineStatement();
} }
public static int getElementCount(String type) {
Matcher vec = vecType.matcher(type);
if (vec.find()) return Integer.parseInt(vec.group(1));
Matcher mat = matType.matcher(type);
if (mat.find()) {
int n = Integer.parseInt(mat.group(1));
String m = mat.group(2);
if (m != null) return Integer.parseInt(m) * n;
return n;
}
return 1;
}
public static int getAttributeCount(CharSequence type) {
Matcher mat = matType.matcher(type);
if (mat.find()) {
return Integer.parseInt(mat.group(1));
}
return 1;
}
} }

View file

@ -4,9 +4,11 @@ import java.util.Objects;
import com.jozufozu.flywheel.backend.gl.shader.GlShader; import com.jozufozu.flywheel.backend.gl.shader.GlShader;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType; import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.source.FileResolution; import com.jozufozu.flywheel.core.shader.ShaderConstants;
import com.jozufozu.flywheel.backend.source.SourceFile;
import com.jozufozu.flywheel.core.shader.StateSnapshot; import com.jozufozu.flywheel.core.shader.StateSnapshot;
import com.jozufozu.flywheel.core.source.FileIndexImpl;
import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.core.source.SourceFile;
public class FragmentCompiler extends Memoizer<FragmentCompiler.Context, GlShader> { public class FragmentCompiler extends Memoizer<FragmentCompiler.Context, GlShader> {
private final FileResolution header; private final FileResolution header;
@ -43,9 +45,23 @@ public class FragmentCompiler extends Memoizer<FragmentCompiler.Context, GlShade
value.delete(); value.delete();
} }
/**
* Represents the conditions under which a shader is compiled.
*/
public static final class Context { public static final class Context {
/**
* The file to compile.
*/
private final SourceFile file; private final SourceFile file;
/**
* The shader constants to apply.
*/
private final StateSnapshot ctx; private final StateSnapshot ctx;
/**
* Alpha threshold below which fragments are discarded.
*/
private final float alphaDiscard; private final float alphaDiscard;
public Context(SourceFile file, StateSnapshot ctx, float alphaDiscard) { public Context(SourceFile file, StateSnapshot ctx, float alphaDiscard) {

View file

@ -3,13 +3,13 @@ package com.jozufozu.flywheel.core.compile;
import java.util.Optional; import java.util.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.backend.source.error.ErrorReporter; import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct; import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
import com.jozufozu.flywheel.backend.source.parse.StructField; import com.jozufozu.flywheel.core.source.parse.StructField;
import com.jozufozu.flywheel.backend.source.parse.Variable; import com.jozufozu.flywheel.core.source.parse.Variable;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
public class FragmentTemplateData implements FragmentData { public class FragmentTemplateData implements FragmentData {
public final SourceFile file; public final SourceFile file;

View file

@ -4,14 +4,15 @@ import java.util.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.backend.source.ShaderLoadingException; import com.jozufozu.flywheel.core.source.FileIndex;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.ShaderLoadingException;
import com.jozufozu.flywheel.backend.source.error.ErrorReporter; import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct; import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
import com.jozufozu.flywheel.backend.source.parse.StructField; import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
import com.jozufozu.flywheel.backend.source.parse.Variable; import com.jozufozu.flywheel.core.source.parse.StructField;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.parse.Variable;
import com.jozufozu.flywheel.core.source.span.Span;
public class InstancingTemplateData implements VertexData { public class InstancingTemplateData implements VertexData {
@ -83,7 +84,7 @@ public class InstancingTemplateData implements VertexData {
.append("a_i_") .append("a_i_")
.append(field.name) .append(field.name)
.append(";\n"); .append(";\n");
attributeBinding += TypeHelper.getAttributeCount(field.type); attributeBinding += CompileUtil.getAttributeCount(field.type);
} }
template.append(String.format(""" template.append(String.format("""
out vec4 v2f_color; out vec4 v2f_color;

View file

@ -4,11 +4,12 @@ import java.util.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.backend.source.ShaderLoadingException; import com.jozufozu.flywheel.core.source.FileIndex;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.ShaderLoadingException;
import com.jozufozu.flywheel.backend.source.error.ErrorReporter; import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.backend.source.parse.Variable; import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
import com.jozufozu.flywheel.core.source.parse.Variable;
public class OneShotTemplateData implements VertexData { public class OneShotTemplateData implements VertexData {

View file

@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.source.FileResolution;
import com.jozufozu.flywheel.core.Templates; import com.jozufozu.flywheel.core.Templates;
import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent;
/** /**

View file

@ -6,8 +6,8 @@ import javax.annotation.Nullable;
import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.GameStateRegistry;
import com.jozufozu.flywheel.backend.RenderLayer; import com.jozufozu.flywheel.backend.RenderLayer;
import com.jozufozu.flywheel.core.GameStateRegistry;
import com.jozufozu.flywheel.core.shader.ProgramSpec; import com.jozufozu.flywheel.core.shader.ProgramSpec;
import com.jozufozu.flywheel.core.shader.StateSnapshot; import com.jozufozu.flywheel.core.shader.StateSnapshot;
@ -15,7 +15,6 @@ import net.minecraft.resources.ResourceLocation;
/** /**
* Represents the entire context of a program's usage. * Represents the entire context of a program's usage.
*
*/ */
public final class ProgramContext { public final class ProgramContext {
/** /**
@ -27,8 +26,7 @@ public final class ProgramContext {
* @return A compilation context. * @return A compilation context.
*/ */
public static ProgramContext create(ResourceLocation programName, VertexType vertexType, @Nullable RenderLayer layer) { public static ProgramContext create(ResourceLocation programName, VertexType vertexType, @Nullable RenderLayer layer) {
ProgramSpec spec = Backend.getInstance() ProgramSpec spec = Backend.getSpec(programName);
.getSpec(programName);
if (spec == null) { if (spec == null) {
throw new NullPointerException("Cannot compile shader because '" + programName + "' is not recognized."); throw new NullPointerException("Cannot compile shader because '" + programName + "' is not recognized.");

View file

@ -1,11 +1,9 @@
package com.jozufozu.flywheel.core.compile; package com.jozufozu.flywheel.core.compile;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import com.jozufozu.flywheel.backend.gl.GLSLVersion; import com.jozufozu.flywheel.backend.gl.GLSLVersion;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
/** /**
* A class that generates glsl glue code given a SourceFile. * A class that generates glsl glue code given a SourceFile.
@ -15,9 +13,7 @@ import com.jozufozu.flywheel.backend.source.SourceFile;
* metadata to generate shader code that OpenGL can use to call into our shader programs. * metadata to generate shader code that OpenGL can use to call into our shader programs.
* </p> * </p>
*/ */
public class Template<T> { public class Template<T> extends Memoizer<SourceFile, T> {
private final Map<SourceFile, T> metadata = new HashMap<>();
private final Function<SourceFile, T> reader; private final Function<SourceFile, T> reader;
private final GLSLVersion glslVersion; private final GLSLVersion glslVersion;
@ -34,7 +30,7 @@ public class Template<T> {
*/ */
public T apply(SourceFile file) { public T apply(SourceFile file) {
// lazily read files, cache results // lazily read files, cache results
return metadata.computeIfAbsent(file, reader); return super.get(file);
} }
/** /**
@ -44,4 +40,13 @@ public class Template<T> {
return glslVersion; return glslVersion;
} }
@Override
protected T _create(SourceFile key) {
return reader.apply(key);
}
@Override
protected void _destroy(T value) {
// noop
}
} }

View file

@ -1,37 +0,0 @@
package com.jozufozu.flywheel.core.compile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TypeHelper {
public static final Pattern vecType = Pattern.compile("^[biud]?vec([234])$");
public static final Pattern matType = Pattern.compile("^mat([234])(?:x([234]))?$");
public static int getElementCount(String type) {
Matcher vec = vecType.matcher(type);
if (vec.find()) return Integer.parseInt(vec.group(1));
Matcher mat = matType.matcher(type);
if (mat.find()) {
int n = Integer.parseInt(mat.group(1));
String m = mat.group(2);
if (m != null) return Integer.parseInt(m) * n;
return n;
}
return 1;
}
public static int getAttributeCount(CharSequence type) {
Matcher mat = matType.matcher(type);
if (mat.find()) {
return Integer.parseInt(mat.group(1));
}
return 1;
}
}

View file

@ -5,9 +5,10 @@ import java.util.Objects;
import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.backend.gl.shader.GlShader; import com.jozufozu.flywheel.backend.gl.shader.GlShader;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType; import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.source.FileResolution;
import com.jozufozu.flywheel.backend.source.SourceFile;
import com.jozufozu.flywheel.core.shader.StateSnapshot; import com.jozufozu.flywheel.core.shader.StateSnapshot;
import com.jozufozu.flywheel.core.source.FileIndexImpl;
import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.core.source.SourceFile;
public class VertexCompiler extends Memoizer<VertexCompiler.Context, GlShader> { public class VertexCompiler extends Memoizer<VertexCompiler.Context, GlShader> {
private final Template<? extends VertexData> template; private final Template<? extends VertexData> template;
@ -55,8 +56,19 @@ public class VertexCompiler extends Memoizer<VertexCompiler.Context, GlShader> {
} }
public static class Context { public static class Context {
/**
* The file to compile.
*/
private final SourceFile file; private final SourceFile file;
/**
* The shader constants to apply.
*/
private final StateSnapshot ctx; private final StateSnapshot ctx;
/**
* The vertex type to use.
*/
private final VertexType vertexType; private final VertexType vertexType;
public Context(SourceFile file, StateSnapshot ctx, VertexType vertexType) { public Context(SourceFile file, StateSnapshot ctx, VertexType vertexType) {

View file

@ -1,6 +1,7 @@
package com.jozufozu.flywheel.core.compile; package com.jozufozu.flywheel.core.compile;
import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.core.source.FileIndex;
public interface VertexData { public interface VertexData {
/** /**

View file

@ -1,13 +0,0 @@
package com.jozufozu.flywheel.core.shader;
import net.minecraft.resources.ResourceLocation;
public interface ExtensionInstance {
/**
* Bind the extra program state. It is recommended to grab the state information from global variables.
*/
void bind();
ResourceLocation name();
}

View file

@ -1,7 +1,5 @@
package com.jozufozu.flywheel.core.shader; package com.jozufozu.flywheel.core.shader;
import com.jozufozu.flywheel.core.compile.ShaderConstants;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public interface GameStateProvider { public interface GameStateProvider {

View file

@ -2,7 +2,6 @@ package com.jozufozu.flywheel.core.shader;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.core.compile.ShaderConstants;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.core.shader; package com.jozufozu.flywheel.core.shader;
import com.jozufozu.flywheel.backend.source.FileResolution; import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.backend.source.Resolver; import com.jozufozu.flywheel.core.source.Resolver;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;

View file

@ -1,12 +1,16 @@
package com.jozufozu.flywheel.core.compile; package com.jozufozu.flywheel.core.shader;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* A class for manipulating a list of {@code #define} directives.
*
* <p>Based loosely on code by jellysquid3.
*/
public class ShaderConstants { public class ShaderConstants {
private final Map<String, String> definitions = new HashMap<>(); private final Map<String, String> definitions = new HashMap<>();
public ShaderConstants define(String def) { public ShaderConstants define(String def) {

View file

@ -1,7 +1,6 @@
package com.jozufozu.flywheel.core.shader; package com.jozufozu.flywheel.core.shader;
import com.jozufozu.flywheel.backend.GameStateRegistry; import com.jozufozu.flywheel.core.GameStateRegistry;
import com.jozufozu.flywheel.core.compile.ShaderConstants;
public record StateSnapshot(long ctx) { public record StateSnapshot(long ctx) {
// TODO: is this needed? // TODO: is this needed?

View file

@ -2,15 +2,10 @@ package com.jozufozu.flywheel.core.shader;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.resources.ResourceLocation; public class WorldFog {
public class WorldFog implements ExtensionInstance {
public static final ResourceLocation NAME = Flywheel.rl("fog");
private final int uFogColor; private final int uFogColor;
private final int uFogRange; private final int uFogRange;
@ -20,14 +15,8 @@ public class WorldFog implements ExtensionInstance {
this.uFogRange = program.getUniformLocation("uFogRange"); this.uFogRange = program.getUniformLocation("uFogRange");
} }
@Override
public void bind() { public void bind() {
GL20.glUniform2f(uFogRange, RenderSystem.getShaderFogStart(), RenderSystem.getShaderFogEnd()); GL20.glUniform2f(uFogRange, RenderSystem.getShaderFogStart(), RenderSystem.getShaderFogEnd());
GL20.glUniform4fv(uFogColor, RenderSystem.getShaderFogColor()); GL20.glUniform4fv(uFogColor, RenderSystem.getShaderFogColor());
} }
@Override
public ResourceLocation name() {
return NAME;
}
} }

View file

@ -1,7 +1,6 @@
package com.jozufozu.flywheel.core.compile; package com.jozufozu.flywheel.core.source;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.span.Span;
import com.jozufozu.flywheel.backend.source.span.Span;
public interface FileIndex { public interface FileIndex {
/** /**

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.core.compile; package com.jozufozu.flywheel.core.source;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -6,9 +6,8 @@ import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.error.ErrorBuilder;
import com.jozufozu.flywheel.backend.source.error.ErrorBuilder; import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.backend.source.error.ErrorReporter;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -1,12 +1,12 @@
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.source.error.ErrorBuilder; import com.jozufozu.flywheel.core.source.error.ErrorBuilder;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -1,12 +1,12 @@
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder; import com.google.common.collect.MultimapBuilder;
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct; import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
public class ShaderLoadingException extends RuntimeException { public class ShaderLoadingException extends RuntimeException {

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -10,13 +10,12 @@ import java.util.regex.Pattern;
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.backend.source.parse.Import; import com.jozufozu.flywheel.core.source.parse.Import;
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct; import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
import com.jozufozu.flywheel.backend.source.span.ErrorSpan; import com.jozufozu.flywheel.core.source.span.ErrorSpan;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
import com.jozufozu.flywheel.backend.source.span.StringSpan; import com.jozufozu.flywheel.core.source.span.StringSpan;
import com.jozufozu.flywheel.core.compile.FileIndex;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View file

@ -1,10 +1,10 @@
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.backend.source.span.CharPos; import com.jozufozu.flywheel.core.source.span.CharPos;
import com.jozufozu.flywheel.util.StringUtil; import com.jozufozu.flywheel.util.StringUtil;
import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrayList;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error; package com.jozufozu.flywheel.core.source.error;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -7,16 +7,16 @@ import java.util.regex.Pattern;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.FileIndex;
import com.jozufozu.flywheel.backend.source.SourceLines; import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.backend.source.error.lines.ErrorLine; import com.jozufozu.flywheel.core.source.SourceLines;
import com.jozufozu.flywheel.backend.source.error.lines.FileLine; import com.jozufozu.flywheel.core.source.error.lines.ErrorLine;
import com.jozufozu.flywheel.backend.source.error.lines.HeaderLine; import com.jozufozu.flywheel.core.source.error.lines.FileLine;
import com.jozufozu.flywheel.backend.source.error.lines.SourceLine; import com.jozufozu.flywheel.core.source.error.lines.HeaderLine;
import com.jozufozu.flywheel.backend.source.error.lines.SpanHighlightLine; import com.jozufozu.flywheel.core.source.error.lines.SourceLine;
import com.jozufozu.flywheel.backend.source.error.lines.TextLine; import com.jozufozu.flywheel.core.source.error.lines.SpanHighlightLine;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.error.lines.TextLine;
import com.jozufozu.flywheel.core.compile.FileIndex; import com.jozufozu.flywheel.core.source.span.Span;
import com.jozufozu.flywheel.util.FlwUtil; import com.jozufozu.flywheel.util.FlwUtil;
public class ErrorBuilder { public class ErrorBuilder {

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error; package com.jozufozu.flywheel.core.source.error;
public enum ErrorLevel { public enum ErrorLevel {
WARN("warn"), WARN("warn"),

View file

@ -1,14 +1,14 @@
package com.jozufozu.flywheel.backend.source.error; package com.jozufozu.flywheel.core.source.error;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct; import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
import com.jozufozu.flywheel.util.FlwUtil; import com.jozufozu.flywheel.util.FlwUtil;
public class ErrorReporter { public class ErrorReporter {

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error.lines; package com.jozufozu.flywheel.core.source.error.lines;
public enum Divider { public enum Divider {
BAR(" | "), BAR(" | "),

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error.lines; package com.jozufozu.flywheel.core.source.error.lines;
public interface ErrorLine { public interface ErrorLine {

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error.lines; package com.jozufozu.flywheel.core.source.error.lines;
public record FileLine(String fileName) implements ErrorLine { public record FileLine(String fileName) implements ErrorLine {

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error.lines; package com.jozufozu.flywheel.core.source.error.lines;
public record HeaderLine(String level, CharSequence message) implements ErrorLine { public record HeaderLine(String level, CharSequence message) implements ErrorLine {

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error.lines; package com.jozufozu.flywheel.core.source.error.lines;
public record SourceLine(String number, String line) implements ErrorLine { public record SourceLine(String number, String line) implements ErrorLine {

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error.lines; package com.jozufozu.flywheel.core.source.error.lines;
public class SpanHighlightLine implements ErrorLine { public class SpanHighlightLine implements ErrorLine {
private final String line; private final String line;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.error.lines; package com.jozufozu.flywheel.core.source.error.lines;
public record TextLine(String msg) implements ErrorLine { public record TextLine(String msg) implements ErrorLine {

View file

@ -1,5 +1,5 @@
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package com.jozufozu.flywheel.backend.source.span; package com.jozufozu.flywheel.core.source.error;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -1,5 +1,5 @@
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package com.jozufozu.flywheel.backend.source; package com.jozufozu.flywheel.core.source;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.source.parse; package com.jozufozu.flywheel.core.source.parse;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
public abstract class AbstractShaderElement { public abstract class AbstractShaderElement {

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.parse; package com.jozufozu.flywheel.core.source.parse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -6,11 +6,11 @@ import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.source.FileResolution; import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.backend.source.Resolver; import com.jozufozu.flywheel.core.source.Resolver;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.backend.source.error.ErrorReporter; import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -1,11 +1,11 @@
package com.jozufozu.flywheel.backend.source.parse; package com.jozufozu.flywheel.core.source.parse;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
public class ShaderFunction extends AbstractShaderElement { public class ShaderFunction extends AbstractShaderElement {

View file

@ -1,11 +1,11 @@
package com.jozufozu.flywheel.backend.source.parse; package com.jozufozu.flywheel.core.source.parse;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
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.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
public class ShaderStruct extends AbstractShaderElement { public class ShaderStruct extends AbstractShaderElement {

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.backend.source.parse; package com.jozufozu.flywheel.core.source.parse;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
public class StructField extends AbstractShaderElement { public class StructField extends AbstractShaderElement {
public static final Pattern fieldPattern = Pattern.compile("(\\S+)\\s*(\\S+);"); public static final Pattern fieldPattern = Pattern.compile("(\\S+)\\s*(\\S+);");

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.source.parse; package com.jozufozu.flywheel.core.source.parse;
import com.jozufozu.flywheel.backend.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
public class Variable extends AbstractShaderElement { public class Variable extends AbstractShaderElement {

View file

@ -1,6 +1,6 @@
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault @MethodsReturnNonnullByDefault
package com.jozufozu.flywheel.backend.source.parse; package com.jozufozu.flywheel.core.source.parse;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.source.span; package com.jozufozu.flywheel.core.source.span;
/** /**
* A position in a file. * A position in a file.

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.source.span; package com.jozufozu.flywheel.core.source.span;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
/** /**
* Represents a (syntactically) malformed segment of code. * Represents a (syntactically) malformed segment of code.

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.backend.source.span; package com.jozufozu.flywheel.core.source.span;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
/** /**
* A segment of code in a {@link SourceFile}. * A segment of code in a {@link SourceFile}.

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.source.span; package com.jozufozu.flywheel.core.source.span;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
public class StringSpan extends Span { public class StringSpan extends Span {

View file

@ -1,5 +1,5 @@
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package com.jozufozu.flywheel.backend.source.error; package com.jozufozu.flywheel.core.source.span;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -24,8 +24,7 @@ public class ForgeEvents {
ArrayList<String> right = event.getRight(); ArrayList<String> right = event.getRight();
String text = "Flywheel: " + Backend.getInstance() String text = "Flywheel: " + Backend.getBackendDescriptor();
.getBackendDescriptor();
if (right.size() < 10) { if (right.size() < 10) {
right.add(""); right.add("");
right.add(text); right.add(text);

View file

@ -1,24 +1,16 @@
package com.jozufozu.flywheel.event; package com.jozufozu.flywheel.event;
import com.jozufozu.flywheel.backend.Backend;
import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.event.IModBusEvent; import net.minecraftforge.fml.event.IModBusEvent;
public class GatherContextEvent extends Event implements IModBusEvent { public class GatherContextEvent extends Event implements IModBusEvent {
private final Backend backend;
private final boolean firstLoad; private final boolean firstLoad;
public GatherContextEvent(Backend backend, boolean firstLoad) { public GatherContextEvent(boolean firstLoad) {
this.backend = backend;
this.firstLoad = firstLoad; this.firstLoad = firstLoad;
} }
public Backend getBackend() {
return backend;
}
/** /**
* @return true iff it is the first time the event is fired. * @return true iff it is the first time the event is fired.
*/ */

View file

@ -67,8 +67,7 @@ public class LevelRendererMixin {
@Inject(at = @At("TAIL"), method = "allChanged") @Inject(at = @At("TAIL"), method = "allChanged")
private void refresh(CallbackInfo ci) { private void refresh(CallbackInfo ci) {
Backend.getInstance() Backend.refresh();
.refresh();
MinecraftForge.EVENT_BUS.post(new ReloadRenderersEvent(level)); MinecraftForge.EVENT_BUS.post(new ReloadRenderersEvent(level));
} }