mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-02-04 17:24:59 +01:00
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:
parent
2854e1f1dc
commit
29d4ec03c2
68 changed files with 257 additions and 317 deletions
|
@ -1,8 +1,8 @@
|
|||
package com.jozufozu.flywheel;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.OptifineHandler;
|
||||
import com.jozufozu.flywheel.core.Contexts;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.jozufozu.flywheel.core.StitchedSprite;
|
||||
import com.jozufozu.flywheel.core.compile.ProgramCompiler;
|
||||
|
@ -18,15 +18,14 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|||
public class FlywheelClient {
|
||||
|
||||
public static void clientInit() {
|
||||
CrashReportCallables.registerCrashCallable("Flywheel Backend", () ->
|
||||
Backend.getInstance().getBackendDescriptor());
|
||||
CrashReportCallables.registerCrashCallable("Flywheel Backend", Backend::getBackendDescriptor);
|
||||
|
||||
OptifineHandler.init();
|
||||
Backend.init();
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get()
|
||||
.getModEventBus();
|
||||
|
||||
modEventBus.addListener(Contexts::flwInit);
|
||||
modEventBus.addListener(Materials::flwInit);
|
||||
modEventBus.addListener(PartialModel::onModelRegistry);
|
||||
modEventBus.addListener(PartialModel::onModelBake);
|
||||
modEventBus.addListener(StitchedSprite::onTextureStitchPre);
|
||||
|
|
|
@ -1,19 +1,11 @@
|
|||
package com.jozufozu.flywheel.backend;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
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.InstanceData;
|
||||
import com.jozufozu.flywheel.api.struct.StructType;
|
||||
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
|
||||
import com.jozufozu.flywheel.config.FlwConfig;
|
||||
import com.jozufozu.flywheel.config.FlwEngine;
|
||||
|
@ -27,89 +19,39 @@ import net.minecraft.world.level.LevelAccessor;
|
|||
public class Backend {
|
||||
public static final Logger LOGGER = LogManager.getLogger(Backend.class);
|
||||
|
||||
protected static final Backend INSTANCE = new Backend();
|
||||
public static Backend getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
private static FlwEngine engine;
|
||||
|
||||
private FlwEngine engine;
|
||||
public static GlCompat compat;
|
||||
|
||||
public GLCapabilities capabilities;
|
||||
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();
|
||||
}
|
||||
private static final Loader loader = new Loader();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public String getBackendDescriptor() {
|
||||
public static String getBackendDescriptor() {
|
||||
return engine == null ? "" : engine.getProperName();
|
||||
}
|
||||
|
||||
public FlwEngine getEngine() {
|
||||
public static FlwEngine getEngine() {
|
||||
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
|
||||
public ProgramSpec getSpec(ResourceLocation name) {
|
||||
return programSpecRegistry.get(name);
|
||||
public static ProgramSpec getSpec(ResourceLocation name) {
|
||||
return loader.get(name);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
public static void refresh() {
|
||||
OptifineHandler.refresh();
|
||||
|
||||
capabilities = GL.createCapabilities();
|
||||
|
||||
compat = new GlCompat(capabilities);
|
||||
compat = new GlCompat();
|
||||
|
||||
engine = chooseEngine(compat);
|
||||
}
|
||||
|
||||
public Collection<StructType<?>> allMaterials() {
|
||||
return materialRegistry.values();
|
||||
}
|
||||
|
||||
public Collection<ProgramSpec> allPrograms() {
|
||||
return programSpecRegistry.values();
|
||||
}
|
||||
|
||||
public static boolean isOn() {
|
||||
return getInstance().engine != FlwEngine.OFF;
|
||||
return engine != FlwEngine.OFF;
|
||||
}
|
||||
|
||||
public static boolean canUseInstancing(@Nullable Level world) {
|
||||
|
@ -137,18 +79,6 @@ public class Backend {
|
|||
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) {
|
||||
FlwEngine preferredChoice = FlwConfig.get()
|
||||
.getEngine();
|
||||
|
@ -162,4 +92,12 @@ public class Backend {
|
|||
|
||||
return canUseEngine ? preferredChoice : FlwEngine.OFF;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
// noop
|
||||
}
|
||||
|
||||
private Backend() {
|
||||
throw new UnsupportedOperationException("Backend is a static class!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
package com.jozufozu.flywheel.backend;
|
||||
|
||||
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.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
import com.jozufozu.flywheel.backend.source.Resolver;
|
||||
import com.jozufozu.flywheel.backend.source.ShaderSources;
|
||||
import com.jozufozu.flywheel.core.GameStateRegistry;
|
||||
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
|
||||
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.util.ResourceUtil;
|
||||
import com.jozufozu.flywheel.util.StringUtil;
|
||||
|
@ -37,13 +42,11 @@ public class Loader implements ResourceManagerReloadListener {
|
|||
public static final String PROGRAM_DIR = "flywheel/programs/";
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
|
||||
private final Backend backend;
|
||||
private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
|
||||
|
||||
private boolean firstLoad = true;
|
||||
|
||||
public Loader(Backend backend) {
|
||||
this.backend = backend;
|
||||
|
||||
Loader() {
|
||||
// Can be null when running datagenerators due to the unfortunate time we call this
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
if (minecraft != null) {
|
||||
|
@ -54,15 +57,20 @@ public class Loader implements ResourceManagerReloadListener {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ProgramSpec get(ResourceLocation name) {
|
||||
return programSpecRegistry.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(ResourceManager manager) {
|
||||
backend.refresh();
|
||||
Backend.refresh();
|
||||
|
||||
backend._clearContexts();
|
||||
GameStateRegistry._clear();
|
||||
|
||||
Resolver.INSTANCE.invalidate();
|
||||
ModLoader.get()
|
||||
.postEvent(new GatherContextEvent(backend, firstLoad));
|
||||
.postEvent(new GatherContextEvent(firstLoad));
|
||||
|
||||
ShaderSources sources = new ShaderSources(manager);
|
||||
|
||||
|
@ -101,10 +109,21 @@ public class Loader implements ResourceManagerReloadListener {
|
|||
|
||||
spec.setName(specName);
|
||||
|
||||
backend.register(spec);
|
||||
register(spec);
|
||||
} catch (Exception 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public abstract class GlBuffer extends GlObject {
|
|||
* @return A buffer that will be persistent if the driver supports it.
|
||||
*/
|
||||
public static GlBuffer requestPersistent(GlBufferType type) {
|
||||
if (Backend.getInstance().compat.bufferStorageSupported()) {
|
||||
if (Backend.compat.bufferStorageSupported()) {
|
||||
return new PersistentGlBuffer(type);
|
||||
} else {
|
||||
return new MappedGlBuffer(type);
|
||||
|
|
|
@ -46,7 +46,7 @@ public class PersistentGlBuffer extends GlBuffer implements Mappable {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL20;
|
|||
|
||||
import com.jozufozu.flywheel.backend.gl.GlObject;
|
||||
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;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.nio.ByteBuffer;
|
|||
import java.util.Arrays;
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL20C;
|
||||
import org.lwjgl.opengl.GLCapabilities;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
|
@ -23,11 +24,11 @@ public class GlCompat {
|
|||
public final BufferStorage bufferStorage;
|
||||
public final boolean amd;
|
||||
|
||||
public GlCompat(GLCapabilities caps) {
|
||||
public GlCompat() {
|
||||
GLCapabilities caps = GL.createCapabilities();
|
||||
instancedArrays = getLatest(InstancedArrays.class, caps);
|
||||
bufferStorage = getLatest(BufferStorage.class, caps);
|
||||
|
||||
|
||||
if (Util.getPlatform() == Util.OS.WINDOWS) {
|
||||
String vendor = GL20C.glGetString(GL20C.GL_VENDOR);
|
||||
// vendor string I got was "ATI Technologies Inc."
|
||||
|
|
|
@ -39,8 +39,7 @@ public class InstanceWorld {
|
|||
this.taskEngine = new ParallelTaskEngine("Flywheel " + world.dimension().location());
|
||||
this.taskEngine.startWorkers();
|
||||
|
||||
FlwEngine engine = Backend.getInstance()
|
||||
.getEngine();
|
||||
FlwEngine engine = Backend.getEngine();
|
||||
|
||||
switch (engine) {
|
||||
case INSTANCING -> {
|
||||
|
|
|
@ -198,7 +198,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
|||
vao.bindAttributes(attributeBaseIndex, instanceFormat);
|
||||
|
||||
for (int i = 0; i < instanceFormat.getAttributeCount(); i++) {
|
||||
Backend.getInstance().compat.instancedArrays.vertexAttribDivisor(attributeBaseIndex + i, 1);
|
||||
Backend.compat.instancedArrays.vertexAttribDivisor(attributeBaseIndex + i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
|||
public InstancedMaterialGroup(InstancingEngine<P> owner, RenderType type) {
|
||||
this.owner = owner;
|
||||
this.type = type;
|
||||
if (Backend.getInstance().compat.onAMDWindows()) {
|
||||
if (Backend.compat.onAMDWindows()) {
|
||||
this.allocator = FallbackAllocator.INSTANCE;
|
||||
} else {
|
||||
this.allocator = new ModelPool(Formats.POS_TEX_NORMAL, 2048);
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package com.jozufozu.flywheel.core;
|
||||
|
||||
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.crumbling.CrumblingProgram;
|
||||
import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider;
|
||||
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.util.ResourceUtil;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.jozufozu.flywheel.backend;
|
||||
package com.jozufozu.flywheel.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jozufozu.flywheel.core.compile.ShaderConstants;
|
||||
import com.jozufozu.flywheel.core.shader.GameStateProvider;
|
||||
import com.jozufozu.flywheel.core.shader.ShaderConstants;
|
||||
import com.jozufozu.flywheel.core.shader.StateSnapshot;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -13,7 +13,7 @@ public class GameStateRegistry {
|
|||
|
||||
private static final Map<ResourceLocation, GameStateProvider> registeredStateProviders = new HashMap<>();
|
||||
|
||||
static void clear() {
|
||||
public static void _clear() {
|
||||
registeredStateProviders.clear();
|
||||
}
|
||||
|
|
@ -2,12 +2,10 @@ package com.jozufozu.flywheel.core;
|
|||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
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.ModelType;
|
||||
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
||||
import com.jozufozu.flywheel.core.materials.oriented.OrientedType;
|
||||
import com.jozufozu.flywheel.event.GatherContextEvent;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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<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 final ResourceLocation MODEL = Flywheel.rl("model");
|
||||
public static final ResourceLocation ORIENTED = Flywheel.rl("oriented");
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
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.shader.ShaderType;
|
||||
|
||||
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) {
|
||||
return "#version "
|
||||
+ version
|
||||
|
@ -13,4 +19,31 @@ public class CompileUtil {
|
|||
+ "#extension GL_ARB_conservative_depth : enable\n"
|
||||
+ 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import java.util.Objects;
|
|||
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlShader;
|
||||
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.ShaderConstants;
|
||||
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> {
|
||||
private final FileResolution header;
|
||||
|
@ -43,9 +45,23 @@ public class FragmentCompiler extends Memoizer<FragmentCompiler.Context, GlShade
|
|||
value.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the conditions under which a shader is compiled.
|
||||
*/
|
||||
public static final class Context {
|
||||
/**
|
||||
* The file to compile.
|
||||
*/
|
||||
private final SourceFile file;
|
||||
|
||||
/**
|
||||
* The shader constants to apply.
|
||||
*/
|
||||
private final StateSnapshot ctx;
|
||||
|
||||
/**
|
||||
* Alpha threshold below which fragments are discarded.
|
||||
*/
|
||||
private final float alphaDiscard;
|
||||
|
||||
public Context(SourceFile file, StateSnapshot ctx, float alphaDiscard) {
|
||||
|
|
|
@ -3,13 +3,13 @@ package com.jozufozu.flywheel.core.compile;
|
|||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.backend.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.backend.source.parse.StructField;
|
||||
import com.jozufozu.flywheel.backend.source.parse.Variable;
|
||||
import com.jozufozu.flywheel.backend.source.span.Span;
|
||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.core.source.parse.StructField;
|
||||
import com.jozufozu.flywheel.core.source.parse.Variable;
|
||||
import com.jozufozu.flywheel.core.source.span.Span;
|
||||
|
||||
public class FragmentTemplateData implements FragmentData {
|
||||
public final SourceFile file;
|
||||
|
|
|
@ -4,14 +4,15 @@ import java.util.Optional;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||
import com.jozufozu.flywheel.backend.source.ShaderLoadingException;
|
||||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.backend.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.backend.source.parse.StructField;
|
||||
import com.jozufozu.flywheel.backend.source.parse.Variable;
|
||||
import com.jozufozu.flywheel.backend.source.span.Span;
|
||||
import com.jozufozu.flywheel.core.source.FileIndex;
|
||||
import com.jozufozu.flywheel.core.source.ShaderLoadingException;
|
||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.core.source.parse.StructField;
|
||||
import com.jozufozu.flywheel.core.source.parse.Variable;
|
||||
import com.jozufozu.flywheel.core.source.span.Span;
|
||||
|
||||
public class InstancingTemplateData implements VertexData {
|
||||
|
||||
|
@ -83,7 +84,7 @@ public class InstancingTemplateData implements VertexData {
|
|||
.append("a_i_")
|
||||
.append(field.name)
|
||||
.append(";\n");
|
||||
attributeBinding += TypeHelper.getAttributeCount(field.type);
|
||||
attributeBinding += CompileUtil.getAttributeCount(field.type);
|
||||
}
|
||||
template.append(String.format("""
|
||||
out vec4 v2f_color;
|
||||
|
|
|
@ -4,11 +4,12 @@ import java.util.Optional;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||
import com.jozufozu.flywheel.backend.source.ShaderLoadingException;
|
||||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.backend.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.backend.source.parse.Variable;
|
||||
import com.jozufozu.flywheel.core.source.FileIndex;
|
||||
import com.jozufozu.flywheel.core.source.ShaderLoadingException;
|
||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.core.source.parse.Variable;
|
||||
|
||||
public class OneShotTemplateData implements VertexData {
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
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.source.FileResolution;
|
||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,8 +6,8 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.GameStateRegistry;
|
||||
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.StateSnapshot;
|
||||
|
||||
|
@ -15,7 +15,6 @@ import net.minecraft.resources.ResourceLocation;
|
|||
|
||||
/**
|
||||
* Represents the entire context of a program's usage.
|
||||
*
|
||||
*/
|
||||
public final class ProgramContext {
|
||||
/**
|
||||
|
@ -27,8 +26,7 @@ public final class ProgramContext {
|
|||
* @return A compilation context.
|
||||
*/
|
||||
public static ProgramContext create(ResourceLocation programName, VertexType vertexType, @Nullable RenderLayer layer) {
|
||||
ProgramSpec spec = Backend.getInstance()
|
||||
.getSpec(programName);
|
||||
ProgramSpec spec = Backend.getSpec(programName);
|
||||
|
||||
if (spec == null) {
|
||||
throw new NullPointerException("Cannot compile shader because '" + programName + "' is not recognized.");
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package com.jozufozu.flywheel.core.compile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
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.
|
||||
|
@ -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.
|
||||
* </p>
|
||||
*/
|
||||
public class Template<T> {
|
||||
|
||||
private final Map<SourceFile, T> metadata = new HashMap<>();
|
||||
public class Template<T> extends Memoizer<SourceFile, T> {
|
||||
|
||||
private final Function<SourceFile, T> reader;
|
||||
private final GLSLVersion glslVersion;
|
||||
|
@ -34,7 +30,7 @@ public class Template<T> {
|
|||
*/
|
||||
public T apply(SourceFile file) {
|
||||
// lazily read files, cache results
|
||||
return metadata.computeIfAbsent(file, reader);
|
||||
return super.get(file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,4 +40,13 @@ public class Template<T> {
|
|||
return glslVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T _create(SourceFile key) {
|
||||
return reader.apply(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _destroy(T value) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -5,9 +5,10 @@ import java.util.Objects;
|
|||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlShader;
|
||||
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.source.FileIndexImpl;
|
||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||
|
||||
public class VertexCompiler extends Memoizer<VertexCompiler.Context, GlShader> {
|
||||
private final Template<? extends VertexData> template;
|
||||
|
@ -55,8 +56,19 @@ public class VertexCompiler extends Memoizer<VertexCompiler.Context, GlShader> {
|
|||
}
|
||||
|
||||
public static class Context {
|
||||
/**
|
||||
* The file to compile.
|
||||
*/
|
||||
private final SourceFile file;
|
||||
|
||||
/**
|
||||
* The shader constants to apply.
|
||||
*/
|
||||
private final StateSnapshot ctx;
|
||||
|
||||
/**
|
||||
* The vertex type to use.
|
||||
*/
|
||||
private final VertexType vertexType;
|
||||
|
||||
public Context(SourceFile file, StateSnapshot ctx, VertexType vertexType) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.jozufozu.flywheel.core.compile;
|
||||
|
||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||
import com.jozufozu.flywheel.core.source.FileIndex;
|
||||
|
||||
public interface VertexData {
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package com.jozufozu.flywheel.core.shader;
|
||||
|
||||
import com.jozufozu.flywheel.core.compile.ShaderConstants;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public interface GameStateProvider {
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.jozufozu.flywheel.core.shader;
|
|||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.config.FlwConfig;
|
||||
import com.jozufozu.flywheel.core.compile.ShaderConstants;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.jozufozu.flywheel.core.shader;
|
||||
|
||||
import com.jozufozu.flywheel.backend.source.FileResolution;
|
||||
import com.jozufozu.flywheel.backend.source.Resolver;
|
||||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||
import com.jozufozu.flywheel.core.source.Resolver;
|
||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package com.jozufozu.flywheel.core.compile;
|
||||
package com.jozufozu.flywheel.core.shader;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A class for manipulating a list of {@code #define} directives.
|
||||
*
|
||||
* <p>Based loosely on code by jellysquid3.
|
||||
*/
|
||||
public class ShaderConstants {
|
||||
|
||||
|
||||
private final Map<String, String> definitions = new HashMap<>();
|
||||
|
||||
public ShaderConstants define(String def) {
|
|
@ -1,7 +1,6 @@
|
|||
package com.jozufozu.flywheel.core.shader;
|
||||
|
||||
import com.jozufozu.flywheel.backend.GameStateRegistry;
|
||||
import com.jozufozu.flywheel.core.compile.ShaderConstants;
|
||||
import com.jozufozu.flywheel.core.GameStateRegistry;
|
||||
|
||||
public record StateSnapshot(long ctx) {
|
||||
// TODO: is this needed?
|
||||
|
|
|
@ -2,15 +2,10 @@ package com.jozufozu.flywheel.core.shader;
|
|||
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class WorldFog implements ExtensionInstance {
|
||||
|
||||
public static final ResourceLocation NAME = Flywheel.rl("fog");
|
||||
public class WorldFog {
|
||||
|
||||
private final int uFogColor;
|
||||
private final int uFogRange;
|
||||
|
@ -20,14 +15,8 @@ public class WorldFog implements ExtensionInstance {
|
|||
this.uFogRange = program.getUniformLocation("uFogRange");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind() {
|
||||
GL20.glUniform2f(uFogRange, RenderSystem.getShaderFogStart(), RenderSystem.getShaderFogEnd());
|
||||
GL20.glUniform4fv(uFogColor, RenderSystem.getShaderFogColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation name() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.backend.source.span.Span;
|
||||
import com.jozufozu.flywheel.core.source.span.Span;
|
||||
|
||||
public interface FileIndex {
|
||||
/**
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.core.compile;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -6,9 +6,8 @@ import java.util.List;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.backend.source.error.ErrorBuilder;
|
||||
import com.jozufozu.flywheel.backend.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.core.source.error.ErrorBuilder;
|
||||
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
package com.jozufozu.flywheel.backend.source;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.source.error.ErrorBuilder;
|
||||
import com.jozufozu.flywheel.backend.source.span.Span;
|
||||
import com.jozufozu.flywheel.core.source.error.ErrorBuilder;
|
||||
import com.jozufozu.flywheel.core.source.span.Span;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
package com.jozufozu.flywheel.backend.source;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
public class ShaderLoadingException extends RuntimeException {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -10,13 +10,12 @@ import java.util.regex.Pattern;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.jozufozu.flywheel.backend.source.parse.Import;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.backend.source.span.ErrorSpan;
|
||||
import com.jozufozu.flywheel.backend.source.span.Span;
|
||||
import com.jozufozu.flywheel.backend.source.span.StringSpan;
|
||||
import com.jozufozu.flywheel.core.compile.FileIndex;
|
||||
import com.jozufozu.flywheel.core.source.parse.Import;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.core.source.span.ErrorSpan;
|
||||
import com.jozufozu.flywheel.core.source.span.Span;
|
||||
import com.jozufozu.flywheel.core.source.span.StringSpan;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
@ -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.Pattern;
|
||||
|
||||
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 it.unimi.dsi.fastutil.ints.IntArrayList;
|
|
@ -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.List;
|
||||
|
@ -7,16 +7,16 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.backend.source.SourceLines;
|
||||
import com.jozufozu.flywheel.backend.source.error.lines.ErrorLine;
|
||||
import com.jozufozu.flywheel.backend.source.error.lines.FileLine;
|
||||
import com.jozufozu.flywheel.backend.source.error.lines.HeaderLine;
|
||||
import com.jozufozu.flywheel.backend.source.error.lines.SourceLine;
|
||||
import com.jozufozu.flywheel.backend.source.error.lines.SpanHighlightLine;
|
||||
import com.jozufozu.flywheel.backend.source.error.lines.TextLine;
|
||||
import com.jozufozu.flywheel.backend.source.span.Span;
|
||||
import com.jozufozu.flywheel.core.compile.FileIndex;
|
||||
import com.jozufozu.flywheel.core.source.FileIndex;
|
||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.source.SourceLines;
|
||||
import com.jozufozu.flywheel.core.source.error.lines.ErrorLine;
|
||||
import com.jozufozu.flywheel.core.source.error.lines.FileLine;
|
||||
import com.jozufozu.flywheel.core.source.error.lines.HeaderLine;
|
||||
import com.jozufozu.flywheel.core.source.error.lines.SourceLine;
|
||||
import com.jozufozu.flywheel.core.source.error.lines.SpanHighlightLine;
|
||||
import com.jozufozu.flywheel.core.source.error.lines.TextLine;
|
||||
import com.jozufozu.flywheel.core.source.span.Span;
|
||||
import com.jozufozu.flywheel.util.FlwUtil;
|
||||
|
||||
public class ErrorBuilder {
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source.error;
|
||||
package com.jozufozu.flywheel.core.source.error;
|
||||
|
||||
public enum ErrorLevel {
|
||||
WARN("warn"),
|
|
@ -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.Optional;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.backend.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.backend.source.span.Span;
|
||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
|
||||
import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
|
||||
import com.jozufozu.flywheel.core.source.span.Span;
|
||||
import com.jozufozu.flywheel.util.FlwUtil;
|
||||
|
||||
public class ErrorReporter {
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source.error.lines;
|
||||
package com.jozufozu.flywheel.core.source.error.lines;
|
||||
|
||||
public enum Divider {
|
||||
BAR(" | "),
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source.error.lines;
|
||||
package com.jozufozu.flywheel.core.source.error.lines;
|
||||
|
||||
public interface ErrorLine {
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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 {
|
||||
private final String line;
|
|
@ -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 {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||
package com.jozufozu.flywheel.backend.source.span;
|
||||
package com.jozufozu.flywheel.core.source.error;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||
package com.jozufozu.flywheel.backend.source;
|
||||
package com.jozufozu.flywheel.core.source;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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.List;
|
||||
|
@ -6,11 +6,11 @@ import java.util.Optional;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.backend.source.FileResolution;
|
||||
import com.jozufozu.flywheel.backend.source.Resolver;
|
||||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.backend.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.backend.source.span.Span;
|
||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||
import com.jozufozu.flywheel.core.source.Resolver;
|
||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
|
||||
import com.jozufozu.flywheel.core.source.span.Span;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
|
@ -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.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 {
|
||||
|
|
@ -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.Pattern;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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 {
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package com.jozufozu.flywheel.backend.source.parse;
|
||||
package com.jozufozu.flywheel.core.source.parse;
|
||||
|
||||
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 static final Pattern fieldPattern = Pattern.compile("(\\S+)\\s*(\\S+);");
|
|
@ -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 {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package com.jozufozu.flywheel.backend.source.parse;
|
||||
package com.jozufozu.flywheel.core.source.parse;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.source.span;
|
||||
package com.jozufozu.flywheel.core.source.span;
|
||||
|
||||
/**
|
||||
* A position in a 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.
|
|
@ -1,8 +1,8 @@
|
|||
package com.jozufozu.flywheel.backend.source.span;
|
||||
package com.jozufozu.flywheel.core.source.span;
|
||||
|
||||
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}.
|
|
@ -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 {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||
package com.jozufozu.flywheel.backend.source.error;
|
||||
package com.jozufozu.flywheel.core.source.span;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
|
@ -24,8 +24,7 @@ public class ForgeEvents {
|
|||
|
||||
ArrayList<String> right = event.getRight();
|
||||
|
||||
String text = "Flywheel: " + Backend.getInstance()
|
||||
.getBackendDescriptor();
|
||||
String text = "Flywheel: " + Backend.getBackendDescriptor();
|
||||
if (right.size() < 10) {
|
||||
right.add("");
|
||||
right.add(text);
|
||||
|
|
|
@ -1,24 +1,16 @@
|
|||
package com.jozufozu.flywheel.event;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
public class GatherContextEvent extends Event implements IModBusEvent {
|
||||
|
||||
private final Backend backend;
|
||||
private final boolean firstLoad;
|
||||
|
||||
public GatherContextEvent(Backend backend, boolean firstLoad) {
|
||||
this.backend = backend;
|
||||
public GatherContextEvent(boolean firstLoad) {
|
||||
this.firstLoad = firstLoad;
|
||||
}
|
||||
|
||||
public Backend getBackend() {
|
||||
return backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true iff it is the first time the event is fired.
|
||||
*/
|
||||
|
|
|
@ -67,8 +67,7 @@ public class LevelRendererMixin {
|
|||
|
||||
@Inject(at = @At("TAIL"), method = "allChanged")
|
||||
private void refresh(CallbackInfo ci) {
|
||||
Backend.getInstance()
|
||||
.refresh();
|
||||
Backend.refresh();
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new ReloadRenderersEvent(level));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue