Reorganize, rename, refactor, 0.4.0

- Move most user facing interfaces to flywheel.api package
 - Refactor InstanceData to have no package private classes
 - Remove 'I' prefix from many interfaces
 - ILightUpdateListener -> LightListener
 - IMultiProgram -> ContextAwareProgram
 - IFlatLight -> FlatLit
 - All materials use the same vertex format: UNLIT_MODEL
This commit is contained in:
Jozufozu 2021-12-09 00:42:27 -08:00
parent 47b110c48c
commit 7b3bab6647
90 changed files with 346 additions and 311 deletions

View file

@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx3G
org.gradle.daemon = false org.gradle.daemon = false
# mod version info # mod version info
mod_version = 0.3.0 mod_version = 0.4.0
mc_update_version = 1.18 mc_update_version = 1.18
minecraft_version = 1.18 minecraft_version = 1.18
forge_version = 38.0.15 forge_version = 38.0.15

View file

@ -13,9 +13,10 @@ import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.api.FlywheelWorld;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.material.MaterialSpec; import com.jozufozu.flywheel.backend.api.MaterialSpec;
import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
@ -41,7 +42,7 @@ public class Backend {
private boolean instancedArrays; private boolean instancedArrays;
private boolean enabled; private boolean enabled;
private final List<IShaderContext<?>> contexts = new ArrayList<>(); private final List<ShaderContext<?>> contexts = new ArrayList<>();
private final Map<ResourceLocation, MaterialSpec<?>> materialRegistry = new HashMap<>(); private final Map<ResourceLocation, MaterialSpec<?>> materialRegistry = new HashMap<>();
private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>(); private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
@ -82,7 +83,7 @@ public class Backend {
/** /**
* Register a shader context. * Register a shader context.
*/ */
public <C extends IShaderContext<?>> C register(C spec) { public <C extends ShaderContext<?>> C register(C spec) {
contexts.add(spec); contexts.add(spec);
return spec; return spec;
} }
@ -97,8 +98,7 @@ public class Backend {
} }
materialRegistry.put(name, spec); materialRegistry.put(name, spec);
log.debug("registered material '" + name + "' with vertex size " + spec.getModelFormat() log.debug("registered material '" + name + "' with instance size " + spec.getInstanceType().format().getStride());
.getStride() + " and instance size " + spec.getInstanceType().format().getStride());
return spec; return spec;
} }
@ -151,7 +151,7 @@ public class Backend {
return programSpecRegistry.values(); return programSpecRegistry.values();
} }
public Collection<IShaderContext<?>> allContexts() { public Collection<ShaderContext<?>> allContexts() {
return contexts; return contexts;
} }
@ -163,7 +163,7 @@ public class Backend {
if (!world.isClientSide()) return false; if (!world.isClientSide()) return false;
if (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()) return true; if (world instanceof FlywheelWorld && ((FlywheelWorld) world).supportsFlywheel()) return true;
return world == Minecraft.getInstance().level; return world == Minecraft.getInstance().level;
} }
@ -182,7 +182,7 @@ public class Backend {
public void _clearContexts() { public void _clearContexts() {
GameStateRegistry.clear(); GameStateRegistry.clear();
programSpecRegistry.clear(); programSpecRegistry.clear();
contexts.forEach(IShaderContext::delete); contexts.forEach(ShaderContext::delete);
contexts.clear(); contexts.clear();
materialRegistry.clear(); materialRegistry.clear();
} }

View file

@ -1,13 +0,0 @@
package com.jozufozu.flywheel.backend;
/**
* A marker interface custom worlds can override to indicate
* that tiles inside the world should render with Flywheel.
*
* <code>Minecraft.getInstance().world</code> is special cased and will support Flywheel by default.
*/
public interface IFlywheelWorld {
default boolean supportsFlywheel() {
return true;
}
}

View file

@ -78,7 +78,7 @@ public class Loader implements ResourceManagerReloadListener {
Resolver.INSTANCE.resolve(sources); Resolver.INSTANCE.resolve(sources);
for (IShaderContext<?> context : backend.allContexts()) { for (ShaderContext<?> context : backend.allContexts()) {
context.load(); context.load();
} }

View file

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

View file

@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public interface IShaderContext<P extends GlProgram> { public interface ShaderContext<P extends GlProgram> {
default P getProgram(ResourceLocation loc) { default P getProgram(ResourceLocation loc) {
return this.getProgramSupplier(loc) return this.getProgramSupplier(loc)

View file

@ -1,11 +1,11 @@
package com.jozufozu.flywheel.backend.instancing; package com.jozufozu.flywheel.backend.api;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
/** /**
* Something (a BlockEntity or Entity) that can be rendered using the instancing API. * Something (a BlockEntity or Entity) that can be rendered using the instancing API.
*/ */
public interface IInstanceRendered { public interface FlywheelRendered {
/** /**
* @return true if there are parts of the renderer that cannot be implemented with Flywheel. * @return true if there are parts of the renderer that cannot be implemented with Flywheel.

View file

@ -0,0 +1,13 @@
package com.jozufozu.flywheel.backend.api;
/**
* A marker interface custom worlds can override to indicate
* that tiles inside the world should render with Flywheel.
*
* {@link net.minecraft.client.Minecraft#level Minecraft#level} is special cased and will support Flywheel by default.
*/
public interface FlywheelWorld {
default boolean supportsFlywheel() {
return true;
}
}

View file

@ -0,0 +1,41 @@
package com.jozufozu.flywheel.backend.api;
public abstract class InstanceData {
private Instancer<?> owner;
private boolean dirty;
private boolean removed;
public final void markDirty() {
dirty = true;
owner.notifyDirty();
}
public final void delete() {
removed = true;
owner.notifyRemoval();
}
public final boolean checkDirtyAndClear() {
if (dirty) {
dirty = false;
return true;
} else {
return false;
}
}
public final boolean isRemoved() {
return removed;
}
public Instancer<?> getOwner() {
return owner;
}
public InstanceData setOwner(Instancer<?> owner) {
this.owner = owner;
return this;
}
}

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.instancing; package com.jozufozu.flywheel.backend.api;
/** /**
* An instancer is how you interact with an instanced model. * An instancer is how you interact with an instanced model.
@ -32,7 +32,22 @@ public interface Instancer<D extends InstanceData> {
*/ */
void stealInstance(D inOther); void stealInstance(D inOther);
void markDirty(InstanceData instanceData); /**
* Notify the Instancer that some of its data needs updating.
*
* <p>
* This might be ignored, depending on the implementation. For the GPUInstancer, this triggers a scan of all
* instances.
* </p>
*/
void notifyDirty();
void markRemoval(InstanceData instanceData); /**
* Notify the Instances that some of its data should be removed.
*
* <p>
* By the time the next frame is drawn, the instanceData passed will no longer be considered for rendering.
* </p>
*/
void notifyRemoval();
} }

View file

@ -1,12 +1,10 @@
package com.jozufozu.flywheel.backend.material; package com.jozufozu.flywheel.backend.api;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.instancing.Instancer;
import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.PartialModel;
import com.jozufozu.flywheel.core.model.BlockModel; import com.jozufozu.flywheel.core.model.BlockModel;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.util.Pair; import com.jozufozu.flywheel.util.Pair;
import com.jozufozu.flywheel.util.RenderUtil; import com.jozufozu.flywheel.util.RenderUtil;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
@ -19,10 +17,10 @@ public interface Material<D extends InstanceData> {
* Get an instancer for the given model. Calling this method twice with the same key will return the same instancer. * Get an instancer for the given model. Calling this method twice with the same key will return the same instancer.
* *
* @param key An object that uniquely identifies the model. * @param key An object that uniquely identifies the model.
* @param modelSupplier A factory that creates the IModel that you want to render. * @param modelSupplier A factory that creates the Model that you want to render.
* @return An instancer for the given model, capable of rendering many copies for little cost. * @return An instancer for the given model, capable of rendering many copies for little cost.
*/ */
Instancer<D> model(Object key, Supplier<IModel> modelSupplier); Instancer<D> model(Object key, Supplier<Model> modelSupplier);
default Instancer<D> getModel(PartialModel partial, BlockState referenceState) { default Instancer<D> getModel(PartialModel partial, BlockState referenceState) {
return model(partial, () -> new BlockModel(partial.get(), referenceState)); return model(partial, () -> new BlockModel(partial.get(), referenceState));

View file

@ -1,6 +1,4 @@
package com.jozufozu.flywheel.backend.material; package com.jozufozu.flywheel.backend.api;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
public interface MaterialGroup { public interface MaterialGroup {
/** /**

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.material; package com.jozufozu.flywheel.backend.api;
import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.backend.RenderLayer;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;

View file

@ -1,7 +1,5 @@
package com.jozufozu.flywheel.backend.material; package com.jozufozu.flywheel.backend.api;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructType;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -11,13 +9,11 @@ public class MaterialSpec<D extends InstanceData> {
public final ResourceLocation name; public final ResourceLocation name;
private final ResourceLocation programSpec; private final ResourceLocation programSpec;
private final VertexFormat modelFormat;
private final StructType<D> instanceType; private final StructType<D> instanceType;
public MaterialSpec(ResourceLocation name, ResourceLocation programSpec, VertexFormat modelFormat, StructType<D> type) { public MaterialSpec(ResourceLocation name, ResourceLocation programSpec, StructType<D> type) {
this.name = name; this.name = name;
this.programSpec = programSpec; this.programSpec = programSpec;
this.modelFormat = modelFormat;
this.instanceType = type; this.instanceType = type;
} }
@ -25,10 +21,6 @@ public class MaterialSpec<D extends InstanceData> {
return programSpec; return programSpec;
} }
public VertexFormat getModelFormat() {
return modelFormat;
}
public StructType<D> getInstanceType() { public StructType<D> getInstanceType() {
return instanceType; return instanceType;
} }

View file

@ -1,5 +1,7 @@
package com.jozufozu.flywheel.backend.instancing; package com.jozufozu.flywheel.backend.api.instance;
import com.jozufozu.flywheel.backend.api.Instancer;
import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
/** /**

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.instancing; package com.jozufozu.flywheel.backend.api.instance;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;

View file

@ -1,5 +1,7 @@
package com.jozufozu.flywheel.backend.instancing; package com.jozufozu.flywheel.backend.api.instance;
import com.jozufozu.flywheel.backend.api.Instancer;
import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
/** /**

View file

@ -1,5 +1,5 @@
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package com.jozufozu.flywheel.backend.material; package com.jozufozu.flywheel.backend.api.instance;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;

View file

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

View file

@ -3,10 +3,13 @@ package com.jozufozu.flywheel.backend.instancing;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.api.instance.IInstance;
import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import com.jozufozu.flywheel.core.materials.IFlatLight; import com.jozufozu.flywheel.core.materials.FlatLit;
import com.jozufozu.flywheel.light.ILightUpdateListener; import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.ImmutableBox; import com.jozufozu.flywheel.light.ImmutableBox;
import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.ListenerStatus; import com.jozufozu.flywheel.light.ListenerStatus;
@ -19,7 +22,7 @@ import net.minecraft.world.level.LightLayer;
* A general interface providing information about any type of thing that could use Flywheel's instanced rendering. * A general interface providing information about any type of thing that could use Flywheel's instanced rendering.
* Right now, that's only {@link TileInstanceManager}, but there could be an entity equivalent in the future. * Right now, that's only {@link TileInstanceManager}, but there could be an entity equivalent in the future.
*/ */
public abstract class AbstractInstance implements IInstance, ILightUpdateListener { public abstract class AbstractInstance implements IInstance, LightListener {
protected final MaterialManager materialManager; protected final MaterialManager materialManager;
public final Level world; public final Level world;
@ -84,19 +87,19 @@ public abstract class AbstractInstance implements IInstance, ILightUpdateListene
updateLight(); updateLight();
} }
protected void relight(BlockPos pos, IFlatLight<?>... models) { protected void relight(BlockPos pos, FlatLit<?>... models) {
relight(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos), models); relight(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos), models);
} }
protected <L extends IFlatLight<?>> void relight(BlockPos pos, Stream<L> models) { protected <L extends FlatLit<?>> void relight(BlockPos pos, Stream<L> models) {
relight(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos), models); relight(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos), models);
} }
protected void relight(int block, int sky, IFlatLight<?>... models) { protected void relight(int block, int sky, FlatLit<?>... models) {
relight(block, sky, Arrays.stream(models)); relight(block, sky, Arrays.stream(models));
} }
protected <L extends IFlatLight<?>> void relight(int block, int sky, Stream<L> models) { protected <L extends FlatLit<?>> void relight(int block, int sky, Stream<L> models) {
models.forEach(model -> model.setBlockLight(block) models.forEach(model -> model.setBlockLight(block)
.setSkyLight(sky)); .setSkyLight(sky));
} }

View file

@ -3,19 +3,20 @@ package com.jozufozu.flywheel.backend.instancing;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.api.Instancer;
import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructType;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
public class AbstractInstancer<D extends InstanceData> implements Instancer<D> { public abstract class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
protected final StructType<D> type; protected final StructType<D> type;
protected final IModel modelData; protected final Model modelData;
protected final ArrayList<D> data = new ArrayList<>(); protected final ArrayList<D> data = new ArrayList<>();
boolean anyToRemove; protected boolean anyToRemove;
boolean anyToUpdate;
public AbstractInstancer(StructType<D> type, IModel modelData) { protected AbstractInstancer(StructType<D> type, Model modelData) {
this.type = type; this.type = type;
this.modelData = modelData; this.modelData = modelData;
} }
@ -25,9 +26,7 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
*/ */
@Override @Override
public D createInstance() { public D createInstance() {
D data = type.create(); return _add(type.create());
data.owner = this;
return _add(data);
} }
/** /**
@ -38,24 +37,17 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
*/ */
@Override @Override
public void stealInstance(D inOther) { public void stealInstance(D inOther) {
if (inOther.owner == this) return; if (inOther.getOwner() == this) return;
inOther.delete(); // Changing the owner reference will delete it in the other instancer
// sike, we want to keep it, changing the owner reference will still delete it in the other inOther.getOwner()
inOther.removed = false; .notifyRemoval();
_add(inOther); _add(inOther);
} }
@Override @Override
public void markDirty(InstanceData instanceData) { public void notifyRemoval() {
anyToUpdate = true;
instanceData.dirty = true;
}
@Override
public void markRemoval(InstanceData instanceData) {
anyToRemove = true; anyToRemove = true;
instanceData.removed = true;
} }
/** /**
@ -72,10 +64,8 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
D element = data.get(i); D element = data.get(i);
if (element.dirty) { if (element.checkDirtyAndClear()) {
dirtySet.set(i); dirtySet.set(i);
element.dirty = false;
} }
} }
return dirtySet; return dirtySet;
@ -88,7 +78,7 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
final BitSet removeSet = new BitSet(oldSize); final BitSet removeSet = new BitSet(oldSize);
for (int i = 0; i < oldSize; i++) { for (int i = 0; i < oldSize; i++) {
final D element = this.data.get(i); final D element = this.data.get(i);
if (element.removed || element.owner != this) { if (element.isRemoved() || element.getOwner() != this) {
removeSet.set(i); removeSet.set(i);
removeCount++; removeCount++;
} }
@ -103,22 +93,22 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
if (i != j) { if (i != j) {
D element = data.get(i); D element = data.get(i);
data.set(j, element); data.set(j, element);
element.dirty = true; // Marking the data dirty marks us dirty too.
// Perhaps there will be some wasted cycles, but the JVM should be able to
// generate code that moves the repeated segment out of the loop.
element.markDirty();
} }
} }
anyToUpdate = true;
data.subList(newSize, oldSize) data.subList(newSize, oldSize)
.clear(); .clear();
} }
private D _add(D instanceData) { private D _add(D instanceData) {
instanceData.owner = this; instanceData.setOwner(this);
instanceData.dirty = true; instanceData.markDirty();
anyToUpdate = true;
synchronized (data) { synchronized (data) {
data.add(instanceData); data.add(instanceData);
} }

View file

@ -0,0 +1,6 @@
package com.jozufozu.flywheel.backend.instancing;
import com.jozufozu.flywheel.backend.api.MaterialManager;
public interface Engine extends RenderDispatcher, MaterialManager {
}

View file

@ -1,18 +0,0 @@
package com.jozufozu.flywheel.backend.instancing;
public abstract class InstanceData {
Instancer<?> owner;
boolean dirty;
boolean removed;
public void markDirty() {
owner.markDirty(this);
}
public void delete() {
owner.markRemoval(this);
}
}

View file

@ -9,8 +9,10 @@ import java.util.Set;
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.material.MaterialManager; import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine; import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
import com.jozufozu.flywheel.backend.api.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
import com.jozufozu.flywheel.light.LightUpdater; import com.jozufozu.flywheel.light.LightUpdater;
import com.mojang.math.Vector3f; import com.mojang.math.Vector3f;

View file

@ -1,10 +1,11 @@
package com.jozufozu.flywheel.backend.instancing; package com.jozufozu.flywheel.backend.instancing;
import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstanceManager; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstanceManager;
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
import com.jozufozu.flywheel.backend.material.Engine; import com.jozufozu.flywheel.backend.instancing.batching.BatchingEngine;
import com.jozufozu.flywheel.backend.material.batching.BatchingEngine; import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine;
import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.Contexts;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.BeginFrameEvent;

View file

@ -5,11 +5,12 @@ import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.jozufozu.flywheel.backend.api.FlywheelRendered;
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
import com.jozufozu.flywheel.backend.instancing.entity.IEntityInstanceFactory; import com.jozufozu.flywheel.backend.instancing.entity.IEntityInstanceFactory;
import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory; import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
@ -34,11 +35,11 @@ public class InstancedRenderRegistry {
} }
public <T extends BlockEntity> boolean shouldSkipRender(T type) { public <T extends BlockEntity> boolean shouldSkipRender(T type) {
return _skipRender(type.getType()) || ((type instanceof IInstanceRendered) && !((IInstanceRendered) type).shouldRenderNormally()); return _skipRender(type.getType()) || ((type instanceof FlywheelRendered) && !((FlywheelRendered) type).shouldRenderNormally());
} }
public <T extends Entity> boolean shouldSkipRender(T type) { public <T extends Entity> boolean shouldSkipRender(T type) {
return _skipRender(type.getType()) || ((type instanceof IInstanceRendered) && !((IInstanceRendered) type).shouldRenderNormally()); return _skipRender(type.getType()) || ((type instanceof FlywheelRendered) && !((FlywheelRendered) type).shouldRenderNormally());
} }
public <T extends BlockEntity> boolean canInstance(BlockEntityType<? extends T> type) { public <T extends BlockEntity> boolean canInstance(BlockEntityType<? extends T> type) {

View file

@ -1,6 +1,5 @@
package com.jozufozu.flywheel.backend.material; package com.jozufozu.flywheel.backend.instancing;
import com.jozufozu.flywheel.backend.state.RenderLayer;
import com.jozufozu.flywheel.event.RenderLayerEvent; import com.jozufozu.flywheel.event.RenderLayerEvent;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
@ -10,8 +9,8 @@ public interface RenderDispatcher {
/** /**
* Render every model for every material. * Render every model for every material.
* *
* @param layer Which of the 3 {@link RenderLayer render layers} is being drawn? * @param event Context for rendering.
* @param viewProjection How do we get from camera space to clip space? * @param buffers The buffer source for which batched rendering should happen.
*/ */
void render(RenderLayerEvent event, MultiBufferSource buffers); void render(RenderLayerEvent event, MultiBufferSource buffers);

View file

@ -1,16 +1,15 @@
package com.jozufozu.flywheel.backend.material.batching; package com.jozufozu.flywheel.backend.instancing.batching;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.jozufozu.flywheel.backend.instancing.CPUInstancer; import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.Instancer;
import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.backend.api.Material;
import com.jozufozu.flywheel.backend.material.Material; import com.jozufozu.flywheel.backend.api.MaterialSpec;
import com.jozufozu.flywheel.backend.material.MaterialSpec;
import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructType;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -26,7 +25,7 @@ public class BatchedMaterial<D extends InstanceData> implements Material<D> {
} }
@Override @Override
public Instancer<D> model(Object key, Supplier<IModel> modelSupplier) { public Instancer<D> model(Object key, Supplier<Model> modelSupplier) {
return models.computeIfAbsent(key, $ -> new CPUInstancer<>(type, modelSupplier.get())); return models.computeIfAbsent(key, $ -> new CPUInstancer<>(type, modelSupplier.get()));
} }

View file

@ -1,11 +1,11 @@
package com.jozufozu.flywheel.backend.material.batching; package com.jozufozu.flywheel.backend.instancing.batching;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.material.MaterialGroup; import com.jozufozu.flywheel.backend.api.MaterialGroup;
import com.jozufozu.flywheel.backend.material.MaterialSpec; import com.jozufozu.flywheel.backend.api.MaterialSpec;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;

View file

@ -1,12 +1,12 @@
package com.jozufozu.flywheel.backend.material.batching; package com.jozufozu.flywheel.backend.instancing.batching;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.jozufozu.flywheel.backend.material.Engine; import com.jozufozu.flywheel.backend.instancing.Engine;
import com.jozufozu.flywheel.backend.material.MaterialGroup; import com.jozufozu.flywheel.backend.api.MaterialGroup;
import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.backend.RenderLayer;
import com.jozufozu.flywheel.event.RenderLayerEvent; import com.jozufozu.flywheel.event.RenderLayerEvent;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;

View file

@ -1,8 +1,10 @@
package com.jozufozu.flywheel.backend.instancing; package com.jozufozu.flywheel.backend.instancing.batching;
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.struct.BatchingTransformer; import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructType;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -10,13 +12,18 @@ public class CPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
private final BatchingTransformer<D> renderer; private final BatchingTransformer<D> renderer;
public CPUInstancer(StructType<D> type, IModel modelData) { public CPUInstancer(StructType<D> type, Model modelData) {
super(type, modelData); super(type, modelData);
renderer = type.asBatched() renderer = type.asBatched()
.getTransformer(modelData); .getTransformer(modelData);
} }
@Override
public void notifyDirty() {
// noop
}
public void drawAll(PoseStack stack, VertexConsumer buffer) { public void drawAll(PoseStack stack, VertexConsumer buffer) {
if (renderer == null) { if (renderer == null) {
return; return;
@ -34,6 +41,6 @@ public class CPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
removeDeletedInstances(); removeDeletedInstances();
} }
anyToRemove = anyToUpdate = false; anyToRemove = false;
} }
} }

View file

@ -1,5 +1,5 @@
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package com.jozufozu.flywheel.backend.material.batching; package com.jozufozu.flywheel.backend.instancing.batching;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -1,13 +1,13 @@
package com.jozufozu.flywheel.backend.instancing.entity; package com.jozufozu.flywheel.backend.instancing.entity;
import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.ITickableInstance; import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.light.ILightUpdateListener; import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.IMovingListener; import com.jozufozu.flywheel.light.MovingListener;
import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightProvider;
import com.mojang.math.Vector3f; import com.mojang.math.Vector3f;
@ -34,7 +34,7 @@ import net.minecraft.world.phys.Vec3;
* *
* @param <E> The type of {@link Entity} your class is an instance of. * @param <E> The type of {@link Entity} your class is an instance of.
*/ */
public abstract class EntityInstance<E extends Entity> extends AbstractInstance implements ILightUpdateListener, IMovingListener { public abstract class EntityInstance<E extends Entity> extends AbstractInstance implements LightListener, MovingListener {
protected final E entity; protected final E entity;
protected final GridAlignedBB bounds; protected final GridAlignedBB bounds;

View file

@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstanceManager;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.instancing.entity; package com.jozufozu.flywheel.backend.instancing.entity;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.instancing; package com.jozufozu.flywheel.backend.instancing.instancing;
import java.util.BitSet; import java.util.BitSet;
@ -9,11 +9,13 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
import com.jozufozu.flywheel.backend.gl.error.GlError; import com.jozufozu.flywheel.backend.gl.error.GlError;
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.model.IBufferedModel; import com.jozufozu.flywheel.backend.model.IBufferedModel;
import com.jozufozu.flywheel.backend.model.ModelAllocator; import com.jozufozu.flywheel.backend.model.ModelAllocator;
import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructType;
import com.jozufozu.flywheel.backend.struct.StructWriter; import com.jozufozu.flywheel.backend.struct.StructWriter;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.util.AttribUtil; import com.jozufozu.flywheel.util.AttribUtil;
public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> { public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
@ -29,12 +31,19 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
private boolean deleted; private boolean deleted;
private boolean initialized; private boolean initialized;
public GPUInstancer(StructType<D> type, IModel model, ModelAllocator modelAllocator) { protected boolean anyToUpdate;
public GPUInstancer(StructType<D> type, Model model, ModelAllocator modelAllocator) {
super(type, model); super(type, model);
this.modelAllocator = modelAllocator; this.modelAllocator = modelAllocator;
this.instanceFormat = type.format(); this.instanceFormat = type.format();
} }
@Override
public void notifyDirty() {
anyToUpdate = true;
}
public void render() { public void render() {
if (invalid()) return; if (invalid()) return;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.material.instancing; package com.jozufozu.flywheel.backend.instancing.instancing;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -6,14 +6,14 @@ import java.util.function.Supplier;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.jozufozu.flywheel.backend.RenderWork; import com.jozufozu.flywheel.backend.RenderWork;
import com.jozufozu.flywheel.backend.instancing.GPUInstancer; import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.Instancer;
import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.backend.api.Material;
import com.jozufozu.flywheel.backend.material.Material; import com.jozufozu.flywheel.backend.api.MaterialSpec;
import com.jozufozu.flywheel.backend.material.MaterialSpec;
import com.jozufozu.flywheel.backend.model.ModelPool; import com.jozufozu.flywheel.backend.model.ModelPool;
import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructType;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.core.model.Model;
/** /**
* A collection of Instancers that all have the same format. * A collection of Instancers that all have the same format.
@ -28,7 +28,7 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
public InstancedMaterial(MaterialSpec<D> spec) { public InstancedMaterial(MaterialSpec<D> spec) {
this.type = spec.getInstanceType(); this.type = spec.getInstanceType();
modelPool = new ModelPool(spec.getModelFormat(), 64); modelPool = new ModelPool(Formats.UNLIT_MODEL, 64);
this.models = CacheBuilder.newBuilder() this.models = CacheBuilder.newBuilder()
.removalListener(notification -> { .removalListener(notification -> {
GPUInstancer<?> instancer = (GPUInstancer<?>) notification.getValue(); GPUInstancer<?> instancer = (GPUInstancer<?>) notification.getValue();
@ -45,7 +45,7 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
* @return An instancer for the given model, capable of rendering many copies for little cost. * @return An instancer for the given model, capable of rendering many copies for little cost.
*/ */
@Override @Override
public Instancer<D> model(Object key, Supplier<IModel> modelSupplier) { public Instancer<D> model(Object key, Supplier<Model> modelSupplier) {
try { try {
return models.get(key, () -> new GPUInstancer<>(type, modelSupplier.get(), modelPool)); return models.get(key, () -> new GPUInstancer<>(type, modelSupplier.get(), modelPool));
} catch (ExecutionException e) { } catch (ExecutionException e) {

View file

@ -1,12 +1,12 @@
package com.jozufozu.flywheel.backend.material.instancing; package com.jozufozu.flywheel.backend.instancing.instancing;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.material.MaterialGroup; import com.jozufozu.flywheel.backend.api.MaterialGroup;
import com.jozufozu.flywheel.backend.material.MaterialSpec; import com.jozufozu.flywheel.backend.api.MaterialSpec;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.util.TextureBinder; import com.jozufozu.flywheel.util.TextureBinder;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;

View file

@ -1,10 +1,9 @@
package com.jozufozu.flywheel.backend.material.instancing; package com.jozufozu.flywheel.backend.instancing.instancing;
import java.util.Collection; import java.util.Collection;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.jozufozu.flywheel.backend.instancing.GPUInstancer;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.material.instancing; package com.jozufozu.flywheel.backend.instancing.instancing;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
@ -10,9 +10,9 @@ import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.backend.gl.GlVertexArray;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
import com.jozufozu.flywheel.backend.material.Engine; import com.jozufozu.flywheel.backend.instancing.Engine;
import com.jozufozu.flywheel.backend.material.MaterialGroup; import com.jozufozu.flywheel.backend.api.MaterialGroup;
import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.backend.RenderLayer;
import com.jozufozu.flywheel.core.WorldContext; import com.jozufozu.flywheel.core.WorldContext;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.event.RenderLayerEvent; import com.jozufozu.flywheel.event.RenderLayerEvent;

View file

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

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.instancing.tile; package com.jozufozu.flywheel.backend.instancing.tile;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;

View file

@ -1,10 +1,10 @@
package com.jozufozu.flywheel.backend.instancing.tile; package com.jozufozu.flywheel.backend.instancing.tile;
import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.ITickableInstance; import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
import com.jozufozu.flywheel.backend.material.Material; import com.jozufozu.flywheel.backend.api.Material;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData; import com.jozufozu.flywheel.core.materials.oriented.OrientedData;

View file

@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstanceManager;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;

View file

@ -1,4 +0,0 @@
package com.jozufozu.flywheel.backend.material;
public interface Engine extends RenderDispatcher, MaterialManager {
}

View file

@ -3,14 +3,14 @@ package com.jozufozu.flywheel.backend.model;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.backend.gl.GlVertexArray;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.util.AttribUtil; import com.jozufozu.flywheel.util.AttribUtil;
public class ArrayModelRenderer extends ModelRenderer { public class ArrayModelRenderer extends ModelRenderer {
protected GlVertexArray vao; protected GlVertexArray vao;
public ArrayModelRenderer(Supplier<IModel> model) { public ArrayModelRenderer(Supplier<Model> model) {
super(model); super(model);
} }
@ -27,7 +27,7 @@ public class ArrayModelRenderer extends ModelRenderer {
@Override @Override
protected void init() { protected void init() {
initialized = true; initialized = true;
IModel model = modelSupplier.get(); Model model = modelSupplier.get();
if (model.empty()) return; if (model.empty()) return;

View file

@ -10,18 +10,18 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.model.VecBufferConsumer; import com.jozufozu.flywheel.core.model.VecBufferConsumer;
import com.jozufozu.flywheel.util.AttribUtil; import com.jozufozu.flywheel.util.AttribUtil;
public class BufferedModel implements IBufferedModel { public class BufferedModel implements IBufferedModel {
protected final IModel model; protected final Model model;
protected final GlPrimitive primitiveMode; protected final GlPrimitive primitiveMode;
protected GlBuffer vbo; protected GlBuffer vbo;
protected boolean deleted; protected boolean deleted;
public BufferedModel(GlPrimitive primitiveMode, IModel model) { public BufferedModel(GlPrimitive primitiveMode, Model model) {
this.model = model; this.model = model;
this.primitiveMode = primitiveMode; this.primitiveMode = primitiveMode;

View file

@ -1,13 +1,13 @@
package com.jozufozu.flywheel.backend.model; package com.jozufozu.flywheel.backend.model;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
public class ImmediateAllocator implements ModelAllocator { public class ImmediateAllocator implements ModelAllocator {
public static final ImmediateAllocator INSTANCE = new ImmediateAllocator(); public static final ImmediateAllocator INSTANCE = new ImmediateAllocator();
@Override @Override
public IBufferedModel alloc(IModel model, Callback allocationCallback) { public IBufferedModel alloc(Model model, Callback allocationCallback) {
IndexedModel out = new IndexedModel(model); IndexedModel out = new IndexedModel(model);
allocationCallback.onAlloc(out); allocationCallback.onAlloc(out);
return out; return out;

View file

@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL31; import org.lwjgl.opengl.GL31;
import com.jozufozu.flywheel.backend.gl.GlPrimitive; import com.jozufozu.flywheel.backend.gl.GlPrimitive;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
/** /**
* An indexed triangle model. Just what the driver ordered. * An indexed triangle model. Just what the driver ordered.
@ -15,7 +15,7 @@ public class IndexedModel extends BufferedModel {
protected ElementBuffer ebo; protected ElementBuffer ebo;
public IndexedModel(IModel model) { public IndexedModel(Model model) {
super(GlPrimitive.TRIANGLES, model); super(GlPrimitive.TRIANGLES, model);
this.ebo = model.createEBO(); this.ebo = model.createEBO();

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.model; package com.jozufozu.flywheel.backend.model;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
public interface ModelAllocator { public interface ModelAllocator {
/** /**
@ -9,7 +9,7 @@ public interface ModelAllocator {
* @param model The model to allocate. * @param model The model to allocate.
* @return A handle to the allocated model. * @return A handle to the allocated model.
*/ */
IBufferedModel alloc(IModel model, Callback allocationCallback); IBufferedModel alloc(Model model, Callback allocationCallback);
@FunctionalInterface @FunctionalInterface
interface Callback { interface Callback {

View file

@ -11,7 +11,7 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.model.VecBufferConsumer; import com.jozufozu.flywheel.core.model.VecBufferConsumer;
import com.jozufozu.flywheel.util.AttribUtil; import com.jozufozu.flywheel.util.AttribUtil;
@ -49,7 +49,7 @@ public class ModelPool implements ModelAllocator {
* @return A handle to the allocated model. * @return A handle to the allocated model.
*/ */
@Override @Override
public PooledModel alloc(IModel model, Callback callback) { public PooledModel alloc(Model model, Callback callback) {
PooledModel bufferedModel = new PooledModel(model, vertices); PooledModel bufferedModel = new PooledModel(model, vertices);
bufferedModel.callback = callback; bufferedModel.callback = callback;
vertices += model.vertexCount(); vertices += model.vertexCount();
@ -158,12 +158,12 @@ public class ModelPool implements ModelAllocator {
private final ElementBuffer ebo; private final ElementBuffer ebo;
private Callback callback; private Callback callback;
private final IModel model; private final Model model;
private int first; private int first;
private boolean remove; private boolean remove;
public PooledModel(IModel model, int first) { public PooledModel(Model model, int first) {
this.model = model; this.model = model;
this.first = first; this.first = first;
ebo = model.createEBO(); ebo = model.createEBO();

View file

@ -2,16 +2,16 @@ package com.jozufozu.flywheel.backend.model;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
public class ModelRenderer { public class ModelRenderer {
protected Supplier<IModel> modelSupplier; protected Supplier<Model> modelSupplier;
protected IBufferedModel model; protected IBufferedModel model;
protected boolean initialized; protected boolean initialized;
public ModelRenderer(Supplier<IModel> modelSupplier) { public ModelRenderer(Supplier<Model> modelSupplier) {
this.modelSupplier = modelSupplier; this.modelSupplier = modelSupplier;
} }
@ -34,7 +34,7 @@ public class ModelRenderer {
protected void init() { protected void init() {
initialized = true; initialized = true;
IModel model = modelSupplier.get(); Model model = modelSupplier.get();
if (model.empty()) return; if (model.empty()) return;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.backend.pipeline; package com.jozufozu.flywheel.backend.pipeline;
import com.jozufozu.flywheel.core.shader.IMultiProgram; import com.jozufozu.flywheel.core.shader.ContextAwareProgram;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
@ -8,8 +8,8 @@ import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
* The main interface for compiling usable shaders from program specs. * The main interface for compiling usable shaders from program specs.
* @param <P> the type of the program that this pipeline compiles. * @param <P> the type of the program that this pipeline compiles.
*/ */
public interface IShaderPipeline<P extends WorldProgram> { public interface ShaderPipeline<P extends WorldProgram> {
IMultiProgram<P> compile(ProgramSpec spec); ContextAwareProgram<P> compile(ProgramSpec spec);
} }

View file

@ -9,14 +9,14 @@ import com.jozufozu.flywheel.backend.source.FileResolution;
import com.jozufozu.flywheel.backend.source.SourceFile; import com.jozufozu.flywheel.backend.source.SourceFile;
import com.jozufozu.flywheel.core.shader.ExtensibleGlProgram; import com.jozufozu.flywheel.core.shader.ExtensibleGlProgram;
import com.jozufozu.flywheel.core.shader.GameStateProgram; import com.jozufozu.flywheel.core.shader.GameStateProgram;
import com.jozufozu.flywheel.core.shader.IMultiProgram; import com.jozufozu.flywheel.core.shader.ContextAwareProgram;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
import com.jozufozu.flywheel.core.shader.spec.ProgramState; import com.jozufozu.flywheel.core.shader.spec.ProgramState;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class WorldShaderPipeline<P extends WorldProgram> implements IShaderPipeline<P> { public class WorldShaderPipeline<P extends WorldProgram> implements ShaderPipeline<P> {
private final ExtensibleGlProgram.Factory<P> factory; private final ExtensibleGlProgram.Factory<P> factory;
@ -29,14 +29,14 @@ public class WorldShaderPipeline<P extends WorldProgram> implements IShaderPipel
this.header = header; this.header = header;
} }
public IMultiProgram<P> compile(ProgramSpec spec) { public ContextAwareProgram<P> compile(ProgramSpec spec) {
SourceFile file = spec.getSource().getFile(); SourceFile file = spec.getSource().getFile();
return compile(spec.name, file, spec.getStates()); return compile(spec.name, file, spec.getStates());
} }
public IMultiProgram<P> compile(ResourceLocation name, SourceFile file, List<ProgramState> variants) { public ContextAwareProgram<P> compile(ResourceLocation name, SourceFile file, List<ProgramState> variants) {
WorldShader shader = new WorldShader(name, template, header) WorldShader shader = new WorldShader(name, template, header)
.setMainSource(file); .setMainSource(file);

View file

@ -1,10 +1,10 @@
package com.jozufozu.flywheel.backend.struct; package com.jozufozu.flywheel.backend.struct;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
public interface Batched<S> extends StructType<S> { public interface Batched<S> extends StructType<S> {
BatchingTransformer<S> getTransformer(IModel model); BatchingTransformer<S> getTransformer(Model model);
@Override @Override
default Batched<S> asBatched() { default Batched<S> asBatched() {

View file

@ -3,7 +3,7 @@ package com.jozufozu.flywheel.core;
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.GameStateRegistry; import com.jozufozu.flywheel.backend.GameStateRegistry;
import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline; import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline;
import com.jozufozu.flywheel.backend.pipeline.InstancingTemplate; import com.jozufozu.flywheel.backend.pipeline.InstancingTemplate;
import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline; import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline;
import com.jozufozu.flywheel.backend.source.FileResolution; import com.jozufozu.flywheel.backend.source.FileResolution;
@ -32,8 +32,8 @@ public class Contexts {
FileResolution crumblingBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.CRUMBLING, ".glsl")); FileResolution crumblingBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.CRUMBLING, ".glsl"));
FileResolution worldBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.WORLD, ".glsl")); FileResolution worldBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.WORLD, ".glsl"));
IShaderPipeline<CrumblingProgram> crumblingPipeline = new WorldShaderPipeline<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins); ShaderPipeline<CrumblingProgram> crumblingPipeline = new WorldShaderPipeline<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins);
IShaderPipeline<WorldProgram> worldPipeline = new WorldShaderPipeline<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins); ShaderPipeline<WorldProgram> worldPipeline = new WorldShaderPipeline<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins);
CRUMBLING = backend.register(WorldContext.builder(backend, Names.CRUMBLING).build(crumblingPipeline)); CRUMBLING = backend.register(WorldContext.builder(backend, Names.CRUMBLING).build(crumblingPipeline));
WORLD = backend.register(WorldContext.builder(backend, Names.WORLD).build(worldPipeline)); WORLD = backend.register(WorldContext.builder(backend, Names.WORLD).build(worldPipeline));

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.core; package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.backend.material.MaterialSpec; import com.jozufozu.flywheel.backend.api.MaterialSpec;
import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructType;
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;
@ -17,8 +17,8 @@ public class Materials {
public static final StructType<OrientedData> ORIENTED_TYPE = new OrientedType(); public static final StructType<OrientedData> ORIENTED_TYPE = new OrientedType();
public static final StructType<ModelData> TRANSFORMED_TYPE = new ModelType(); public static final StructType<ModelData> TRANSFORMED_TYPE = new ModelType();
public static final MaterialSpec<OrientedData> ORIENTED = new MaterialSpec<>(Names.ORIENTED, Programs.ORIENTED, Formats.UNLIT_MODEL, ORIENTED_TYPE); public static final MaterialSpec<OrientedData> ORIENTED = new MaterialSpec<>(Names.ORIENTED, Programs.ORIENTED, ORIENTED_TYPE);
public static final MaterialSpec<ModelData> TRANSFORMED = new MaterialSpec<>(Names.MODEL, Programs.TRANSFORMED, Formats.UNLIT_MODEL, TRANSFORMED_TYPE); public static final MaterialSpec<ModelData> TRANSFORMED = new MaterialSpec<>(Names.MODEL, Programs.TRANSFORMED, TRANSFORMED_TYPE);
public static void flwInit(GatherContextEvent event) { public static void flwInit(GatherContextEvent event) {
event.getBackend() event.getBackend()

View file

@ -6,24 +6,24 @@ import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.IShaderContext; import com.jozufozu.flywheel.backend.ShaderContext;
import com.jozufozu.flywheel.backend.material.MaterialSpec; import com.jozufozu.flywheel.backend.api.MaterialSpec;
import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline; import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline;
import com.jozufozu.flywheel.core.shader.IMultiProgram; import com.jozufozu.flywheel.core.shader.ContextAwareProgram;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class WorldContext<P extends WorldProgram> implements IShaderContext<P> { public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
public final Backend backend; public final Backend backend;
protected final Map<ResourceLocation, IMultiProgram<P>> programs = new HashMap<>(); protected final Map<ResourceLocation, ContextAwareProgram<P>> programs = new HashMap<>();
protected final ResourceLocation name; protected final ResourceLocation name;
protected final Supplier<Stream<ResourceLocation>> specStream; protected final Supplier<Stream<ResourceLocation>> specStream;
public final IShaderPipeline<P> pipeline; public final ShaderPipeline<P> pipeline;
public WorldContext(Backend backend, ResourceLocation name, Supplier<Stream<ResourceLocation>> specStream, IShaderPipeline<P> pipeline) { public WorldContext(Backend backend, ResourceLocation name, Supplier<Stream<ResourceLocation>> specStream, ShaderPipeline<P> pipeline) {
this.backend = backend; this.backend = backend;
this.name = name; this.name = name;
this.specStream = specStream; this.specStream = specStream;
@ -61,7 +61,7 @@ public class WorldContext<P extends WorldProgram> implements IShaderContext<P> {
@Override @Override
public void delete() { public void delete() {
programs.values() programs.values()
.forEach(IMultiProgram::delete); .forEach(ContextAwareProgram::delete);
programs.clear(); programs.clear();
} }
@ -84,7 +84,7 @@ public class WorldContext<P extends WorldProgram> implements IShaderContext<P> {
return this; return this;
} }
public <P extends WorldProgram> WorldContext<P> build(IShaderPipeline<P> pipeline) { public <P extends WorldProgram> WorldContext<P> build(ShaderPipeline<P> pipeline) {
if (specStream == null) { if (specStream == null) {
specStream = () -> backend.allMaterials() specStream = () -> backend.allMaterials()
.stream() .stream()

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.core.crumbling; package com.jozufozu.flywheel.core.crumbling;
import com.jozufozu.flywheel.backend.material.instancing.InstancedMaterialGroup; import com.jozufozu.flywheel.backend.instancing.instancing.InstancedMaterialGroup;
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine; import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
import com.jozufozu.flywheel.backend.material.instancing.InstancedMaterialRenderer; import com.jozufozu.flywheel.backend.instancing.instancing.InstancedMaterialRenderer;
import com.jozufozu.flywheel.core.atlas.AtlasInfo; import com.jozufozu.flywheel.core.atlas.AtlasInfo;
import com.jozufozu.flywheel.core.atlas.SheetData; import com.jozufozu.flywheel.core.atlas.SheetData;
import com.jozufozu.flywheel.util.RenderTextures; import com.jozufozu.flywheel.util.RenderTextures;
@ -11,7 +11,6 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
public class CrumblingGroup<P extends CrumblingProgram> extends InstancedMaterialGroup<P> { public class CrumblingGroup<P extends CrumblingProgram> extends InstancedMaterialGroup<P> {

View file

@ -1,7 +1,7 @@
package com.jozufozu.flywheel.core.crumbling; package com.jozufozu.flywheel.core.crumbling;
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;

View file

@ -7,7 +7,7 @@ import java.util.SortedSet;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.GlTextureUnit; import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstanceManager;
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine; import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.Contexts;
import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent;
import com.jozufozu.flywheel.event.RenderLayerEvent; import com.jozufozu.flywheel.event.RenderLayerEvent;

View file

@ -5,8 +5,8 @@ import java.util.function.Consumer;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.backend.api.Instancer;
public class ConditionalInstance<D extends InstanceData> { public class ConditionalInstance<D extends InstanceData> {

View file

@ -5,8 +5,8 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.backend.api.Instancer;
public class GroupInstance<D extends InstanceData> extends AbstractCollection<D> { public class GroupInstance<D extends InstanceData> extends AbstractCollection<D> {

View file

@ -6,8 +6,8 @@ import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.InstanceData;
import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.backend.api.Instancer;
public class SelectInstance<D extends InstanceData> { public class SelectInstance<D extends InstanceData> {

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.core.materials; package com.jozufozu.flywheel.core.materials;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.InstanceData;
public abstract class BasicData extends InstanceData implements IFlatLight<BasicData> { public abstract class BasicData extends InstanceData implements FlatLit<BasicData> {
public byte blockLight; public byte blockLight;
public byte skyLight; public byte skyLight;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.core.materials; package com.jozufozu.flywheel.core.materials;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.api.InstanceData;
/** /**
* An interface that implementors of {@link InstanceData} should also implement * An interface that implementors of {@link InstanceData} should also implement
@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.instancing.InstanceData;
* *
* @param <D> The name of the class that implements this interface. * @param <D> The name of the class that implements this interface.
*/ */
public interface IFlatLight<D extends InstanceData & IFlatLight<D>> { public interface FlatLit<D extends InstanceData & FlatLit<D>> {
/** /**
* @param blockLight An integer in the range [0, 15] representing the * @param blockLight An integer in the range [0, 15] representing the
* amount of block light this instance should receive. * amount of block light this instance should receive.

View file

@ -1,10 +1,10 @@
package com.jozufozu.flywheel.core.materials.model; package com.jozufozu.flywheel.core.materials.model;
import com.jozufozu.flywheel.backend.struct.BatchingTransformer; import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
public class ModelTransformer extends BatchingTransformer<ModelData> { public class ModelTransformer extends BatchingTransformer<ModelData> {
public ModelTransformer(IModel model) { public ModelTransformer(Model model) {
//model.buffer(); //model.buffer();

View file

@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.struct.StructWriter;
import com.jozufozu.flywheel.backend.struct.Writeable; import com.jozufozu.flywheel.backend.struct.Writeable;
import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.core.materials.model.writer.UnsafeModelWriter; import com.jozufozu.flywheel.core.materials.model.writer.UnsafeModelWriter;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
public class ModelType implements Writeable<ModelData>, Batched<ModelData> { public class ModelType implements Writeable<ModelData>, Batched<ModelData> {
@ -28,7 +28,7 @@ public class ModelType implements Writeable<ModelData>, Batched<ModelData> {
} }
@Override @Override
public BatchingTransformer<ModelData> getTransformer(IModel model) { public BatchingTransformer<ModelData> getTransformer(Model model) {
return null; return null;
} }
} }

View file

@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.struct.StructWriter;
import com.jozufozu.flywheel.backend.struct.Writeable; import com.jozufozu.flywheel.backend.struct.Writeable;
import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.core.materials.oriented.writer.UnsafeOrientedWriter; import com.jozufozu.flywheel.core.materials.oriented.writer.UnsafeOrientedWriter;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
public class OrientedType implements Writeable<OrientedData>, Batched<OrientedData> { public class OrientedType implements Writeable<OrientedData>, Batched<OrientedData> {
@ -28,7 +28,7 @@ public class OrientedType implements Writeable<OrientedData>, Batched<OrientedDa
} }
@Override @Override
public BatchingTransformer<OrientedData> getTransformer(IModel model) { public BatchingTransformer<OrientedData> getTransformer(Model model) {
return null; return null;
} }
} }

View file

@ -23,7 +23,7 @@ import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
public class BakedModelModel implements IModel { public class BakedModelModel implements Model {
// DOWN, UP, NORTH, SOUTH, WEST, EAST, null // DOWN, UP, NORTH, SOUTH, WEST, EAST, null
private static final Direction[] dirs; private static final Direction[] dirs;

View file

@ -24,7 +24,7 @@ import net.minecraft.world.level.block.state.BlockState;
/** /**
* A model of a single block. * A model of a single block.
*/ */
public class BlockModel implements IModel { public class BlockModel implements Model {
private static final PoseStack IDENTITY = new PoseStack(); private static final PoseStack IDENTITY = new PoseStack();
private final BufferBuilderReader reader; private final BufferBuilderReader reader;

View file

@ -25,7 +25,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer;
* assert model.size() == final - initial; * assert model.size() == final - initial;
* }</pre> * }</pre>
*/ */
public interface IModel { public interface Model {
/** /**
* A name uniquely identifying this model. * A name uniquely identifying this model.

View file

@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.Formats;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
public class ModelPart implements IModel { public class ModelPart implements Model {
private final List<PartBuilder.CuboidBuilder> cuboids; private final List<PartBuilder.CuboidBuilder> cuboids;
private int vertices; private int vertices;

View file

@ -13,7 +13,7 @@ import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
public class WorldModel implements IModel { public class WorldModel implements Model {
private final BufferBuilderReader reader; private final BufferBuilderReader reader;
private final String name; private final String name;

View file

@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
* *
* @param <P> * @param <P>
*/ */
public interface IMultiProgram<P extends GlProgram> extends Supplier<P> { public interface ContextAwareProgram<P extends GlProgram> extends Supplier<P> {
/** /**
* Get the shader program most suited for the current game state. * Get the shader program most suited for the current game state.

View file

@ -5,6 +5,7 @@ import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.jozufozu.flywheel.backend.ShaderContext;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.core.shader.extension.IExtensionInstance; import com.jozufozu.flywheel.core.shader.extension.IExtensionInstance;
@ -17,7 +18,7 @@ import net.minecraft.resources.ResourceLocation;
* the caller using the program. This is used by some programs to implement the different fog modes. Other uses might * the caller using the program. This is used by some programs to implement the different fog modes. Other uses might
* include binding extra textures to allow for blocks to have normal maps, for example. As the extensions are * include binding extra textures to allow for blocks to have normal maps, for example. As the extensions are
* per-program, this also allows for same extra specialization within a * per-program, this also allows for same extra specialization within a
* {@link com.jozufozu.flywheel.backend.ShaderContext ShaderContext}. * {@link ShaderContext ShaderContext}.
*/ */
public class ExtensibleGlProgram extends GlProgram { public class ExtensibleGlProgram extends GlProgram {

View file

@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.core.shader.spec.IGameStateCondition; import com.jozufozu.flywheel.core.shader.spec.IGameStateCondition;
import com.jozufozu.flywheel.util.Pair; import com.jozufozu.flywheel.util.Pair;
public class GameStateProgram<P extends GlProgram> implements IMultiProgram<P> { public class GameStateProgram<P extends GlProgram> implements ContextAwareProgram<P> {
private final List<Pair<IGameStateCondition, P>> variants; private final List<Pair<IGameStateCondition, P>> variants;
private final P fallback; private final P fallback;
@ -55,7 +55,7 @@ public class GameStateProgram<P extends GlProgram> implements IMultiProgram<P> {
return this; return this;
} }
public IMultiProgram<P> build() { public ContextAwareProgram<P> build() {
return new GameStateProgram<>(ImmutableList.copyOf(variants), fallback); return new GameStateProgram<>(ImmutableList.copyOf(variants), fallback);
} }
} }

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.event;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.backend.RenderLayer;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;

View file

@ -1,23 +1,16 @@
package com.jozufozu.flywheel.light; package com.jozufozu.flywheel.light;
import java.util.Map;
import java.util.WeakHashMap;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.LightLayer;
/**
* Wraps a world and minimally lowers the interface.
*/
public class BasicProvider implements LightProvider { public class BasicProvider implements LightProvider {
private static final Map<BlockAndTintGetter, BasicProvider> wrappers = new WeakHashMap<>();
public static BasicProvider get(BlockAndTintGetter world) {
return wrappers.computeIfAbsent(world, BasicProvider::new);
}
private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
private final BlockAndTintGetter reader; private final BlockAndTintGetter reader;
private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
public BasicProvider(BlockAndTintGetter reader) { public BasicProvider(BlockAndTintGetter reader) {
this.reader = reader; this.reader = reader;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.light; package com.jozufozu.flywheel.light;
@FunctionalInterface @FunctionalInterface
public interface ICoordinateConsumer { public interface CoordinateConsumer {
void consume(int x, int y, int z); void consume(int x, int y, int z);
} }

View file

@ -385,7 +385,7 @@ public class GridAlignedBB implements ImmutableBox {
} }
@Override @Override
public void forEachContained(ICoordinateConsumer func) { public void forEachContained(CoordinateConsumer func) {
if (empty()) return; if (empty()) return;
for (int x = minX; x < maxX; x++) { for (int x = minX; x < maxX; x++) {

View file

@ -107,7 +107,7 @@ public interface ImmutableBox {
return this.getMinX() < maxX && this.getMaxX() > minX && this.getMinY() < maxY && this.getMaxY() > minY && this.getMinZ() < maxZ && this.getMaxZ() > minZ; return this.getMinX() < maxX && this.getMaxX() > minX && this.getMinY() < maxY && this.getMaxY() > minY && this.getMinZ() < maxZ && this.getMaxZ() > minZ;
} }
default void forEachContained(ICoordinateConsumer func) { default void forEachContained(CoordinateConsumer func) {
if (empty()) return; if (empty()) return;
for (int x = getMinX(); x < getMaxX(); x++) { for (int x = getMinX(); x < getMaxX(); x++) {
@ -119,7 +119,7 @@ public interface ImmutableBox {
} }
} }
default AABB toAABB() { default AABB toAABB() {
return new AABB(getMinX(), getMinY(), getMinZ(), getMaxX(), getMaxY(), getMaxZ()); return new AABB(getMinX(), getMinY(), getMinZ(), getMaxX(), getMaxY(), getMaxZ());
} }

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.light;
import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.LightLayer;
public interface ILightUpdateListener { public interface LightListener {
ImmutableBox getVolume(); ImmutableBox getVolume();

View file

@ -25,12 +25,12 @@ public class LightUpdater {
private final LightProvider provider; private final LightProvider provider;
private final WeakHashSet<IMovingListener> movingListeners = new WeakHashSet<>(); private final WeakHashSet<MovingListener> movingListeners = new WeakHashSet<>();
private final WeakContainmentMultiMap<ILightUpdateListener> sections = new WeakContainmentMultiMap<>(); private final WeakContainmentMultiMap<LightListener> sections = new WeakContainmentMultiMap<>();
private final WeakContainmentMultiMap<ILightUpdateListener> chunks = new WeakContainmentMultiMap<>(); private final WeakContainmentMultiMap<LightListener> chunks = new WeakContainmentMultiMap<>();
public LightUpdater(BlockAndTintGetter world) { public LightUpdater(BlockAndTintGetter world) {
provider = BasicProvider.get(world); provider = new BasicProvider(world);
} }
public LightProvider getProvider() { public LightProvider getProvider() {
@ -38,7 +38,7 @@ public class LightUpdater {
} }
public void tick() { public void tick() {
for (IMovingListener listener : movingListeners) { for (MovingListener listener : movingListeners) {
if (listener.update(provider)) { if (listener.update(provider)) {
addListener(listener); addListener(listener);
} }
@ -47,12 +47,12 @@ public class LightUpdater {
/** /**
* Add a listener. * Add a listener.
*
* @param listener The object that wants to receive light update notifications. * @param listener The object that wants to receive light update notifications.
*/ */
public void addListener(ILightUpdateListener listener) { public void addListener(LightListener listener) {
if (listener instanceof IMovingListener) if (listener instanceof MovingListener)
movingListeners.add(((IMovingListener) listener)); movingListeners.add(((MovingListener) listener));
ImmutableBox box = listener.getVolume(); ImmutableBox box = listener.getVolume();
@ -80,18 +80,18 @@ public class LightUpdater {
} }
} }
public void removeListener(ILightUpdateListener listener) { public void removeListener(LightListener listener) {
this.sections.remove(listener); this.sections.remove(listener);
this.chunks.remove(listener); this.chunks.remove(listener);
} }
/** /**
* Dispatch light updates to all registered {@link ILightUpdateListener}s. * Dispatch light updates to all registered {@link LightListener}s.
* @param type The type of light that changed. * @param type The type of light that changed.
* @param sectionPos A long representing the section position where light changed. * @param sectionPos A long representing the section position where light changed.
*/ */
public void onLightUpdate(LightLayer type, long sectionPos) { public void onLightUpdate(LightLayer type, long sectionPos) {
Set<ILightUpdateListener> set = sections.get(sectionPos); Set<LightListener> set = sections.get(sectionPos);
if (set == null || set.isEmpty()) return; if (set == null || set.isEmpty()) return;
@ -99,26 +99,26 @@ public class LightUpdater {
ImmutableBox chunkBox = GridAlignedBB.from(SectionPos.of(sectionPos)); ImmutableBox chunkBox = GridAlignedBB.from(SectionPos.of(sectionPos));
for (ILightUpdateListener listener : set) { for (LightListener listener : set) {
listener.onLightUpdate(provider, type, chunkBox); listener.onLightUpdate(provider, type, chunkBox);
} }
} }
/** /**
* Dispatch light updates to all registered {@link ILightUpdateListener}s * Dispatch light updates to all registered {@link LightListener}s
* when the server sends lighting data for an entire chunk. * when the server sends lighting data for an entire chunk.
* *
*/ */
public void onLightPacket(int chunkX, int chunkZ) { public void onLightPacket(int chunkX, int chunkZ) {
long chunkPos = SectionPos.asLong(chunkX, 0, chunkZ); long chunkPos = SectionPos.asLong(chunkX, 0, chunkZ);
Set<ILightUpdateListener> set = chunks.get(chunkPos); Set<LightListener> set = chunks.get(chunkPos);
if (set == null || set.isEmpty()) return; if (set == null || set.isEmpty()) return;
set.removeIf(l -> l.status().shouldRemove()); set.removeIf(l -> l.status().shouldRemove());
for (ILightUpdateListener listener : set) { for (LightListener listener : set) {
listener.onLightPacket(provider, chunkX, chunkZ); listener.onLightPacket(provider, chunkX, chunkZ);
} }
} }
@ -132,7 +132,7 @@ public class LightUpdater {
} }
public Stream<ImmutableBox> getAllBoxes() { public Stream<ImmutableBox> getAllBoxes() {
return chunks.stream().map(ILightUpdateListener::getVolume); return chunks.stream().map(LightListener::getVolume);
} }
public boolean isEmpty() { public boolean isEmpty() {

View file

@ -7,7 +7,7 @@ import org.lwjgl.system.MemoryUtil;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.LightLayer;
public class LightVolume implements ImmutableBox, ILightUpdateListener { public class LightVolume implements ImmutableBox, LightListener {
protected final GridAlignedBB box = new GridAlignedBB(); protected final GridAlignedBB box = new GridAlignedBB();
protected ByteBuffer lightData; protected ByteBuffer lightData;

View file

@ -1,5 +1,5 @@
package com.jozufozu.flywheel.light; package com.jozufozu.flywheel.light;
public interface IMovingListener extends ILightUpdateListener { public interface MovingListener extends LightListener {
boolean update(LightProvider provider); boolean update(LightProvider provider);
} }

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.vanilla; package com.jozufozu.flywheel.vanilla;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData; import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.core.model.ModelPart; import com.jozufozu.flywheel.core.model.ModelPart;

View file

@ -4,9 +4,9 @@ import java.util.Calendar;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData; import com.jozufozu.flywheel.core.materials.oriented.OrientedData;

View file

@ -1,12 +1,12 @@
package com.jozufozu.flywheel.vanilla; package com.jozufozu.flywheel.vanilla;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.ITickableInstance; import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.model.ModelPart; import com.jozufozu.flywheel.core.model.ModelPart;
import com.jozufozu.flywheel.util.AnimationTickHolder; import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack; import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
@ -153,7 +153,7 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
.createInstance(); .createInstance();
} }
private IModel getBodyModel() { private Model getBodyModel() {
int y = -3; int y = -3;
return ModelPart.builder("minecart", 64, 32) return ModelPart.builder("minecart", 64, 32)
.cuboid().invertYZ().start(-10, -8, -y).size(20, 16, 2).textureOffset(0, 10).rotateZ((float) Math.PI).rotateX(((float)Math.PI / 2F)).endCuboid() .cuboid().invertYZ().start(-10, -8, -y).size(20, 16, 2).textureOffset(0, 10).rotateZ((float) Math.PI).rotateX(((float)Math.PI / 2F)).endCuboid()

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.vanilla; package com.jozufozu.flywheel.vanilla;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.api.MaterialManager;
import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.model.ModelPart; import com.jozufozu.flywheel.core.model.ModelPart;