mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-27 21:37:56 +01:00
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:
parent
47b110c48c
commit
7b3bab6647
90 changed files with 346 additions and 311 deletions
|
@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx3G
|
|||
org.gradle.daemon = false
|
||||
|
||||
# mod version info
|
||||
mod_version = 0.3.0
|
||||
mod_version = 0.4.0
|
||||
mc_update_version = 1.18
|
||||
minecraft_version = 1.18
|
||||
forge_version = 38.0.15
|
||||
|
|
|
@ -13,9 +13,10 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.lwjgl.opengl.GL;
|
||||
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.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.api.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialSpec;
|
||||
import com.jozufozu.flywheel.config.FlwConfig;
|
||||
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
||||
|
||||
|
@ -41,7 +42,7 @@ public class Backend {
|
|||
private boolean instancedArrays;
|
||||
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, ProgramSpec> programSpecRegistry = new HashMap<>();
|
||||
|
||||
|
@ -82,7 +83,7 @@ public class Backend {
|
|||
/**
|
||||
* Register a shader context.
|
||||
*/
|
||||
public <C extends IShaderContext<?>> C register(C spec) {
|
||||
public <C extends ShaderContext<?>> C register(C spec) {
|
||||
contexts.add(spec);
|
||||
return spec;
|
||||
}
|
||||
|
@ -97,8 +98,7 @@ public class Backend {
|
|||
}
|
||||
materialRegistry.put(name, spec);
|
||||
|
||||
log.debug("registered material '" + name + "' with vertex size " + spec.getModelFormat()
|
||||
.getStride() + " and instance size " + spec.getInstanceType().format().getStride());
|
||||
log.debug("registered material '" + name + "' with instance size " + spec.getInstanceType().format().getStride());
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ public class Backend {
|
|||
return programSpecRegistry.values();
|
||||
}
|
||||
|
||||
public Collection<IShaderContext<?>> allContexts() {
|
||||
public Collection<ShaderContext<?>> allContexts() {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ public class Backend {
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ public class Backend {
|
|||
public void _clearContexts() {
|
||||
GameStateRegistry.clear();
|
||||
programSpecRegistry.clear();
|
||||
contexts.forEach(IShaderContext::delete);
|
||||
contexts.forEach(ShaderContext::delete);
|
||||
contexts.clear();
|
||||
materialRegistry.clear();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -78,7 +78,7 @@ public class Loader implements ResourceManagerReloadListener {
|
|||
|
||||
Resolver.INSTANCE.resolve(sources);
|
||||
|
||||
for (IShaderContext<?> context : backend.allContexts()) {
|
||||
for (ShaderContext<?> context : backend.allContexts()) {
|
||||
context.load();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.state;
|
||||
package com.jozufozu.flywheel.backend;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
|||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public interface IShaderContext<P extends GlProgram> {
|
||||
public interface ShaderContext<P extends GlProgram> {
|
||||
|
||||
default P getProgram(ResourceLocation loc) {
|
||||
return this.getProgramSupplier(loc)
|
|
@ -1,11 +1,11 @@
|
|||
package com.jozufozu.flywheel.backend.instancing;
|
||||
package com.jozufozu.flywheel.backend.api;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* 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.
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
@ -32,7 +32,22 @@ public interface Instancer<D extends InstanceData> {
|
|||
*/
|
||||
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();
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
package com.jozufozu.flywheel.backend.material;
|
||||
package com.jozufozu.flywheel.backend.api;
|
||||
|
||||
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.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.RenderUtil;
|
||||
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.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
Instancer<D> model(Object key, Supplier<IModel> modelSupplier);
|
||||
Instancer<D> model(Object key, Supplier<Model> modelSupplier);
|
||||
|
||||
default Instancer<D> getModel(PartialModel partial, BlockState referenceState) {
|
||||
return model(partial, () -> new BlockModel(partial.get(), referenceState));
|
|
@ -1,6 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.material;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
package com.jozufozu.flywheel.backend.api;
|
||||
|
||||
public interface MaterialGroup {
|
||||
/**
|
|
@ -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.core.Vec3i;
|
|
@ -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 net.minecraft.resources.ResourceLocation;
|
||||
|
@ -11,13 +9,11 @@ public class MaterialSpec<D extends InstanceData> {
|
|||
public final ResourceLocation name;
|
||||
|
||||
private final ResourceLocation programSpec;
|
||||
private final VertexFormat modelFormat;
|
||||
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.programSpec = programSpec;
|
||||
this.modelFormat = modelFormat;
|
||||
this.instanceType = type;
|
||||
}
|
||||
|
||||
|
@ -25,10 +21,6 @@ public class MaterialSpec<D extends InstanceData> {
|
|||
return programSpec;
|
||||
}
|
||||
|
||||
public VertexFormat getModelFormat() {
|
||||
return modelFormat;
|
||||
}
|
||||
|
||||
public StructType<D> getInstanceType() {
|
||||
return instanceType;
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.instancing;
|
||||
package com.jozufozu.flywheel.backend.api.instance;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
|
@ -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;
|
||||
|
||||
/**
|
|
@ -1,5 +1,5 @@
|
|||
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||
package com.jozufozu.flywheel.backend.material;
|
||||
package com.jozufozu.flywheel.backend.api.instance;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||
package com.jozufozu.flywheel.backend.state;
|
||||
package com.jozufozu.flywheel.backend.api;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
|
@ -3,10 +3,13 @@ package com.jozufozu.flywheel.backend.instancing;
|
|||
import java.util.Arrays;
|
||||
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.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.materials.IFlatLight;
|
||||
import com.jozufozu.flywheel.light.ILightUpdateListener;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.materials.FlatLit;
|
||||
import com.jozufozu.flywheel.light.LightListener;
|
||||
import com.jozufozu.flywheel.light.ImmutableBox;
|
||||
import com.jozufozu.flywheel.light.LightProvider;
|
||||
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.
|
||||
* 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;
|
||||
public final Level world;
|
||||
|
@ -84,19 +87,19 @@ public abstract class AbstractInstance implements IInstance, ILightUpdateListene
|
|||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected void relight(int block, int sky, IFlatLight<?>... models) {
|
||||
protected void relight(int block, int sky, FlatLit<?>... 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)
|
||||
.setSkyLight(sky));
|
||||
}
|
||||
|
|
|
@ -3,19 +3,20 @@ package com.jozufozu.flywheel.backend.instancing;
|
|||
import java.util.ArrayList;
|
||||
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.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 IModel modelData;
|
||||
protected final Model modelData;
|
||||
protected final ArrayList<D> data = new ArrayList<>();
|
||||
|
||||
boolean anyToRemove;
|
||||
boolean anyToUpdate;
|
||||
protected boolean anyToRemove;
|
||||
|
||||
public AbstractInstancer(StructType<D> type, IModel modelData) {
|
||||
protected AbstractInstancer(StructType<D> type, Model modelData) {
|
||||
this.type = type;
|
||||
this.modelData = modelData;
|
||||
}
|
||||
|
@ -25,9 +26,7 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
|
|||
*/
|
||||
@Override
|
||||
public D createInstance() {
|
||||
D data = type.create();
|
||||
data.owner = this;
|
||||
return _add(data);
|
||||
return _add(type.create());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,24 +37,17 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
|
|||
*/
|
||||
@Override
|
||||
public void stealInstance(D inOther) {
|
||||
if (inOther.owner == this) return;
|
||||
if (inOther.getOwner() == this) return;
|
||||
|
||||
inOther.delete();
|
||||
// sike, we want to keep it, changing the owner reference will still delete it in the other
|
||||
inOther.removed = false;
|
||||
// Changing the owner reference will delete it in the other instancer
|
||||
inOther.getOwner()
|
||||
.notifyRemoval();
|
||||
_add(inOther);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty(InstanceData instanceData) {
|
||||
anyToUpdate = true;
|
||||
instanceData.dirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markRemoval(InstanceData instanceData) {
|
||||
public void notifyRemoval() {
|
||||
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++) {
|
||||
D element = data.get(i);
|
||||
if (element.dirty) {
|
||||
if (element.checkDirtyAndClear()) {
|
||||
dirtySet.set(i);
|
||||
|
||||
element.dirty = false;
|
||||
}
|
||||
}
|
||||
return dirtySet;
|
||||
|
@ -88,7 +78,7 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
|
|||
final BitSet removeSet = new BitSet(oldSize);
|
||||
for (int i = 0; i < oldSize; i++) {
|
||||
final D element = this.data.get(i);
|
||||
if (element.removed || element.owner != this) {
|
||||
if (element.isRemoved() || element.getOwner() != this) {
|
||||
removeSet.set(i);
|
||||
removeCount++;
|
||||
}
|
||||
|
@ -103,22 +93,22 @@ public class AbstractInstancer<D extends InstanceData> implements Instancer<D> {
|
|||
if (i != j) {
|
||||
D element = data.get(i);
|
||||
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)
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
private D _add(D instanceData) {
|
||||
instanceData.owner = this;
|
||||
instanceData.setOwner(this);
|
||||
|
||||
instanceData.dirty = true;
|
||||
anyToUpdate = true;
|
||||
instanceData.markDirty();
|
||||
synchronized (data) {
|
||||
data.add(instanceData);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package com.jozufozu.flywheel.backend.instancing;
|
||||
|
||||
import com.jozufozu.flywheel.backend.api.MaterialManager;
|
||||
|
||||
public interface Engine extends RenderDispatcher, MaterialManager {
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,8 +9,10 @@ import java.util.Set;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine;
|
||||
import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
|
||||
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.mojang.math.Vector3f;
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
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.tile.TileInstanceManager;
|
||||
import com.jozufozu.flywheel.backend.material.Engine;
|
||||
import com.jozufozu.flywheel.backend.material.batching.BatchingEngine;
|
||||
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine;
|
||||
import com.jozufozu.flywheel.backend.instancing.batching.BatchingEngine;
|
||||
import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
|
||||
import com.jozufozu.flywheel.core.Contexts;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||
|
|
|
@ -5,11 +5,12 @@ import java.util.Map;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
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.IEntityInstanceFactory;
|
||||
import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory;
|
||||
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.Object2BooleanMap;
|
||||
|
@ -34,11 +35,11 @@ public class InstancedRenderRegistry {
|
|||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
|
|
@ -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 net.minecraft.client.Camera;
|
||||
|
@ -10,8 +9,8 @@ public interface RenderDispatcher {
|
|||
/**
|
||||
* Render every model for every material.
|
||||
*
|
||||
* @param layer Which of the 3 {@link RenderLayer render layers} is being drawn?
|
||||
* @param viewProjection How do we get from camera space to clip space?
|
||||
* @param event Context for rendering.
|
||||
* @param buffers The buffer source for which batched rendering should happen.
|
||||
*/
|
||||
void render(RenderLayerEvent event, MultiBufferSource buffers);
|
||||
|
|
@ -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.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.CPUInstancer;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.instancing.Instancer;
|
||||
import com.jozufozu.flywheel.backend.material.Material;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.api.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.api.Instancer;
|
||||
import com.jozufozu.flywheel.backend.api.Material;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialSpec;
|
||||
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.VertexConsumer;
|
||||
|
||||
|
@ -26,7 +25,7 @@ public class BatchedMaterial<D extends InstanceData> implements Material<D> {
|
|||
}
|
||||
|
||||
@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()));
|
||||
}
|
||||
|
|
@ -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.Map;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.api.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialSpec;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
|
|
@ -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.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jozufozu.flywheel.backend.material.Engine;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.state.RenderLayer;
|
||||
import com.jozufozu.flywheel.backend.instancing.Engine;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.RenderLayer;
|
||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
||||
|
||||
import net.minecraft.client.Camera;
|
|
@ -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.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.VertexConsumer;
|
||||
|
||||
|
@ -10,13 +12,18 @@ public class CPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
|||
|
||||
private final BatchingTransformer<D> renderer;
|
||||
|
||||
public CPUInstancer(StructType<D> type, IModel modelData) {
|
||||
public CPUInstancer(StructType<D> type, Model modelData) {
|
||||
super(type, modelData);
|
||||
|
||||
renderer = type.asBatched()
|
||||
.getTransformer(modelData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDirty() {
|
||||
// noop
|
||||
}
|
||||
|
||||
public void drawAll(PoseStack stack, VertexConsumer buffer) {
|
||||
if (renderer == null) {
|
||||
return;
|
||||
|
@ -34,6 +41,6 @@ public class CPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
|||
removeDeletedInstances();
|
||||
}
|
||||
|
||||
anyToRemove = anyToUpdate = false;
|
||||
anyToRemove = false;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||
package com.jozufozu.flywheel.backend.material.batching;
|
||||
package com.jozufozu.flywheel.backend.instancing.batching;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
package com.jozufozu.flywheel.backend.instancing.entity;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
|
||||
import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
|
||||
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.ILightUpdateListener;
|
||||
import com.jozufozu.flywheel.light.IMovingListener;
|
||||
import com.jozufozu.flywheel.light.LightListener;
|
||||
import com.jozufozu.flywheel.light.MovingListener;
|
||||
import com.jozufozu.flywheel.light.LightProvider;
|
||||
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.
|
||||
*/
|
||||
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 GridAlignedBB bounds;
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.Backend;
|
|||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||
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.world.entity.Entity;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.backend.instancing;
|
||||
package com.jozufozu.flywheel.backend.instancing.instancing;
|
||||
|
||||
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.MappedBuffer;
|
||||
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.ModelAllocator;
|
||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
||||
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;
|
||||
|
||||
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 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);
|
||||
this.modelAllocator = modelAllocator;
|
||||
this.instanceFormat = type.format();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDirty() {
|
||||
anyToUpdate = true;
|
||||
}
|
||||
|
||||
public void render() {
|
||||
if (invalid()) return;
|
||||
|
|
@ -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.function.Supplier;
|
||||
|
@ -6,14 +6,14 @@ import java.util.function.Supplier;
|
|||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.jozufozu.flywheel.backend.RenderWork;
|
||||
import com.jozufozu.flywheel.backend.instancing.GPUInstancer;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.instancing.Instancer;
|
||||
import com.jozufozu.flywheel.backend.material.Material;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.api.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.api.Instancer;
|
||||
import com.jozufozu.flywheel.backend.api.Material;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.model.ModelPool;
|
||||
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.
|
||||
|
@ -28,7 +28,7 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
|
|||
public InstancedMaterial(MaterialSpec<D> spec) {
|
||||
this.type = spec.getInstanceType();
|
||||
|
||||
modelPool = new ModelPool(spec.getModelFormat(), 64);
|
||||
modelPool = new ModelPool(Formats.UNLIT_MODEL, 64);
|
||||
this.models = CacheBuilder.newBuilder()
|
||||
.removalListener(notification -> {
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
public Instancer<D> model(Object key, Supplier<IModel> modelSupplier) {
|
||||
public Instancer<D> model(Object key, Supplier<Model> modelSupplier) {
|
||||
try {
|
||||
return models.get(key, () -> new GPUInstancer<>(type, modelSupplier.get(), modelPool));
|
||||
} catch (ExecutionException e) {
|
|
@ -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.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.api.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialSpec;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.util.TextureBinder;
|
||||
import com.mojang.math.Matrix4f;
|
|
@ -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.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.GPUInstancer;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.mojang.math.Matrix4f;
|
||||
|
|
@ -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.HashMap;
|
||||
|
@ -10,9 +10,9 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
|
||||
import com.jozufozu.flywheel.backend.material.Engine;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.state.RenderLayer;
|
||||
import com.jozufozu.flywheel.backend.instancing.Engine;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.RenderLayer;
|
||||
import com.jozufozu.flywheel.core.WorldContext;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
|
@ -1,5 +1,5 @@
|
|||
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||
package com.jozufozu.flywheel.backend.material.instancing;
|
||||
package com.jozufozu.flywheel.backend.instancing.instancing;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
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;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.jozufozu.flywheel.backend.instancing.tile;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
|
||||
import com.jozufozu.flywheel.backend.material.Material;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
|
||||
import com.jozufozu.flywheel.backend.api.Material;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
||||
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.Backend;
|
|||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||
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.world.level.BlockGetter;
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package com.jozufozu.flywheel.backend.material;
|
||||
|
||||
public interface Engine extends RenderDispatcher, MaterialManager {
|
||||
}
|
|
@ -3,14 +3,14 @@ package com.jozufozu.flywheel.backend.model;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
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;
|
||||
|
||||
public class ArrayModelRenderer extends ModelRenderer {
|
||||
|
||||
protected GlVertexArray vao;
|
||||
|
||||
public ArrayModelRenderer(Supplier<IModel> model) {
|
||||
public ArrayModelRenderer(Supplier<Model> model) {
|
||||
super(model);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public class ArrayModelRenderer extends ModelRenderer {
|
|||
@Override
|
||||
protected void init() {
|
||||
initialized = true;
|
||||
IModel model = modelSupplier.get();
|
||||
Model model = modelSupplier.get();
|
||||
|
||||
if (model.empty()) return;
|
||||
|
||||
|
|
|
@ -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.MappedBuffer;
|
||||
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.util.AttribUtil;
|
||||
|
||||
public class BufferedModel implements IBufferedModel {
|
||||
|
||||
protected final IModel model;
|
||||
protected final Model model;
|
||||
protected final GlPrimitive primitiveMode;
|
||||
protected GlBuffer vbo;
|
||||
protected boolean deleted;
|
||||
|
||||
public BufferedModel(GlPrimitive primitiveMode, IModel model) {
|
||||
public BufferedModel(GlPrimitive primitiveMode, Model model) {
|
||||
this.model = model;
|
||||
this.primitiveMode = primitiveMode;
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
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 static final ImmediateAllocator INSTANCE = new ImmediateAllocator();
|
||||
|
||||
@Override
|
||||
public IBufferedModel alloc(IModel model, Callback allocationCallback) {
|
||||
public IBufferedModel alloc(Model model, Callback allocationCallback) {
|
||||
IndexedModel out = new IndexedModel(model);
|
||||
allocationCallback.onAlloc(out);
|
||||
return out;
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL20;
|
|||
import org.lwjgl.opengl.GL31;
|
||||
|
||||
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.
|
||||
|
@ -15,7 +15,7 @@ public class IndexedModel extends BufferedModel {
|
|||
|
||||
protected ElementBuffer ebo;
|
||||
|
||||
public IndexedModel(IModel model) {
|
||||
public IndexedModel(Model model) {
|
||||
super(GlPrimitive.TRIANGLES, model);
|
||||
|
||||
this.ebo = model.createEBO();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jozufozu.flywheel.backend.model;
|
||||
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
|
||||
public interface ModelAllocator {
|
||||
/**
|
||||
|
@ -9,7 +9,7 @@ public interface ModelAllocator {
|
|||
* @param model The model to allocate.
|
||||
* @return A handle to the allocated model.
|
||||
*/
|
||||
IBufferedModel alloc(IModel model, Callback allocationCallback);
|
||||
IBufferedModel alloc(Model model, Callback allocationCallback);
|
||||
|
||||
@FunctionalInterface
|
||||
interface Callback {
|
||||
|
|
|
@ -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.MappedBuffer;
|
||||
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.util.AttribUtil;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class ModelPool implements ModelAllocator {
|
|||
* @return A handle to the allocated model.
|
||||
*/
|
||||
@Override
|
||||
public PooledModel alloc(IModel model, Callback callback) {
|
||||
public PooledModel alloc(Model model, Callback callback) {
|
||||
PooledModel bufferedModel = new PooledModel(model, vertices);
|
||||
bufferedModel.callback = callback;
|
||||
vertices += model.vertexCount();
|
||||
|
@ -158,12 +158,12 @@ public class ModelPool implements ModelAllocator {
|
|||
private final ElementBuffer ebo;
|
||||
private Callback callback;
|
||||
|
||||
private final IModel model;
|
||||
private final Model model;
|
||||
private int first;
|
||||
|
||||
private boolean remove;
|
||||
|
||||
public PooledModel(IModel model, int first) {
|
||||
public PooledModel(Model model, int first) {
|
||||
this.model = model;
|
||||
this.first = first;
|
||||
ebo = model.createEBO();
|
||||
|
|
|
@ -2,16 +2,16 @@ package com.jozufozu.flywheel.backend.model;
|
|||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.jozufozu.flywheel.core.model.IModel;
|
||||
import com.jozufozu.flywheel.core.model.Model;
|
||||
|
||||
public class ModelRenderer {
|
||||
|
||||
protected Supplier<IModel> modelSupplier;
|
||||
protected Supplier<Model> modelSupplier;
|
||||
protected IBufferedModel model;
|
||||
|
||||
protected boolean initialized;
|
||||
|
||||
public ModelRenderer(Supplier<IModel> modelSupplier) {
|
||||
public ModelRenderer(Supplier<Model> modelSupplier) {
|
||||
this.modelSupplier = modelSupplier;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class ModelRenderer {
|
|||
|
||||
protected void init() {
|
||||
initialized = true;
|
||||
IModel model = modelSupplier.get();
|
||||
Model model = modelSupplier.get();
|
||||
|
||||
if (model.empty()) return;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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.spec.ProgramSpec;
|
||||
|
||||
|
@ -8,8 +8,8 @@ import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
|||
* The main interface for compiling usable shaders from program specs.
|
||||
* @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);
|
||||
|
||||
}
|
|
@ -9,14 +9,14 @@ import com.jozufozu.flywheel.backend.source.FileResolution;
|
|||
import com.jozufozu.flywheel.backend.source.SourceFile;
|
||||
import com.jozufozu.flywheel.core.shader.ExtensibleGlProgram;
|
||||
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.spec.ProgramSpec;
|
||||
import com.jozufozu.flywheel.core.shader.spec.ProgramState;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -29,14 +29,14 @@ public class WorldShaderPipeline<P extends WorldProgram> implements IShaderPipel
|
|||
this.header = header;
|
||||
}
|
||||
|
||||
public IMultiProgram<P> compile(ProgramSpec spec) {
|
||||
public ContextAwareProgram<P> compile(ProgramSpec spec) {
|
||||
|
||||
SourceFile file = spec.getSource().getFile();
|
||||
|
||||
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)
|
||||
.setMainSource(file);
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
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> {
|
||||
|
||||
BatchingTransformer<S> getTransformer(IModel model);
|
||||
BatchingTransformer<S> getTransformer(Model model);
|
||||
|
||||
@Override
|
||||
default Batched<S> asBatched() {
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.jozufozu.flywheel.core;
|
|||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
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.WorldShaderPipeline;
|
||||
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 worldBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.WORLD, ".glsl"));
|
||||
|
||||
IShaderPipeline<CrumblingProgram> crumblingPipeline = new WorldShaderPipeline<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins);
|
||||
IShaderPipeline<WorldProgram> worldPipeline = new WorldShaderPipeline<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins);
|
||||
ShaderPipeline<CrumblingProgram> crumblingPipeline = new WorldShaderPipeline<>(CrumblingProgram::new, InstancingTemplate.INSTANCE, crumblingBuiltins);
|
||||
ShaderPipeline<WorldProgram> worldPipeline = new WorldShaderPipeline<>(WorldProgram::new, InstancingTemplate.INSTANCE, worldBuiltins);
|
||||
|
||||
CRUMBLING = backend.register(WorldContext.builder(backend, Names.CRUMBLING).build(crumblingPipeline));
|
||||
WORLD = backend.register(WorldContext.builder(backend, Names.WORLD).build(worldPipeline));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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.core.materials.model.ModelData;
|
||||
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<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<ModelData> TRANSFORMED = new MaterialSpec<>(Names.MODEL, Programs.TRANSFORMED, Formats.UNLIT_MODEL, TRANSFORMED_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, TRANSFORMED_TYPE);
|
||||
|
||||
public static void flwInit(GatherContextEvent event) {
|
||||
event.getBackend()
|
||||
|
|
|
@ -6,24 +6,24 @@ import java.util.function.Supplier;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.IShaderContext;
|
||||
import com.jozufozu.flywheel.backend.material.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline;
|
||||
import com.jozufozu.flywheel.core.shader.IMultiProgram;
|
||||
import com.jozufozu.flywheel.backend.ShaderContext;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialSpec;
|
||||
import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline;
|
||||
import com.jozufozu.flywheel.core.shader.ContextAwareProgram;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
||||
|
||||
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;
|
||||
protected final Map<ResourceLocation, IMultiProgram<P>> programs = new HashMap<>();
|
||||
protected final Map<ResourceLocation, ContextAwareProgram<P>> programs = new HashMap<>();
|
||||
protected final ResourceLocation name;
|
||||
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.name = name;
|
||||
this.specStream = specStream;
|
||||
|
@ -61,7 +61,7 @@ public class WorldContext<P extends WorldProgram> implements IShaderContext<P> {
|
|||
@Override
|
||||
public void delete() {
|
||||
programs.values()
|
||||
.forEach(IMultiProgram::delete);
|
||||
.forEach(ContextAwareProgram::delete);
|
||||
programs.clear();
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class WorldContext<P extends WorldProgram> implements IShaderContext<P> {
|
|||
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) {
|
||||
specStream = () -> backend.allMaterials()
|
||||
.stream()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.jozufozu.flywheel.core.crumbling;
|
||||
|
||||
import com.jozufozu.flywheel.backend.material.instancing.InstancedMaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine;
|
||||
import com.jozufozu.flywheel.backend.material.instancing.InstancedMaterialRenderer;
|
||||
import com.jozufozu.flywheel.backend.instancing.instancing.InstancedMaterialGroup;
|
||||
import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
|
||||
import com.jozufozu.flywheel.backend.instancing.instancing.InstancedMaterialRenderer;
|
||||
import com.jozufozu.flywheel.core.atlas.AtlasInfo;
|
||||
import com.jozufozu.flywheel.core.atlas.SheetData;
|
||||
import com.jozufozu.flywheel.util.RenderTextures;
|
||||
|
@ -11,7 +11,6 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||
import com.mojang.math.Matrix4f;
|
||||
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class CrumblingGroup<P extends CrumblingProgram> extends InstancedMaterialGroup<P> {
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.jozufozu.flywheel.core.crumbling;
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.SortedSet;
|
|||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
|
||||
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.event.ReloadRenderersEvent;
|
||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
||||
|
|
|
@ -5,8 +5,8 @@ import java.util.function.Consumer;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.instancing.Instancer;
|
||||
import com.jozufozu.flywheel.backend.api.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.api.Instancer;
|
||||
|
||||
public class ConditionalInstance<D extends InstanceData> {
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.instancing.Instancer;
|
||||
import com.jozufozu.flywheel.backend.api.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.api.Instancer;
|
||||
|
||||
public class GroupInstance<D extends InstanceData> extends AbstractCollection<D> {
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ import java.util.Optional;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.instancing.Instancer;
|
||||
import com.jozufozu.flywheel.backend.api.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.api.Instancer;
|
||||
|
||||
public class SelectInstance<D extends InstanceData> {
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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 skyLight;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
|
@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
|||
*
|
||||
* @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
|
||||
* amount of block light this instance should receive.
|
|
@ -1,10 +1,10 @@
|
|||
package com.jozufozu.flywheel.core.materials.model;
|
||||
|
||||
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 ModelTransformer(IModel model) {
|
||||
public ModelTransformer(Model model) {
|
||||
|
||||
|
||||
//model.buffer();
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.struct.StructWriter;
|
|||
import com.jozufozu.flywheel.backend.struct.Writeable;
|
||||
import com.jozufozu.flywheel.core.Formats;
|
||||
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> {
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class ModelType implements Writeable<ModelData>, Batched<ModelData> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BatchingTransformer<ModelData> getTransformer(IModel model) {
|
||||
public BatchingTransformer<ModelData> getTransformer(Model model) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.struct.StructWriter;
|
|||
import com.jozufozu.flywheel.backend.struct.Writeable;
|
||||
import com.jozufozu.flywheel.core.Formats;
|
||||
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> {
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class OrientedType implements Writeable<OrientedData>, Batched<OrientedDa
|
|||
}
|
||||
|
||||
@Override
|
||||
public BatchingTransformer<OrientedData> getTransformer(IModel model) {
|
||||
public BatchingTransformer<OrientedData> getTransformer(Model model) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import net.minecraft.client.resources.model.BakedModel;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
|
||||
public class BakedModelModel implements IModel {
|
||||
public class BakedModelModel implements Model {
|
||||
// DOWN, UP, NORTH, SOUTH, WEST, EAST, null
|
||||
private static final Direction[] dirs;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
/**
|
||||
* A model of a single block.
|
||||
*/
|
||||
public class BlockModel implements IModel {
|
||||
public class BlockModel implements Model {
|
||||
private static final PoseStack IDENTITY = new PoseStack();
|
||||
|
||||
private final BufferBuilderReader reader;
|
||||
|
|
|
@ -25,7 +25,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer;
|
|||
* assert model.size() == final - initial;
|
||||
* }</pre>
|
||||
*/
|
||||
public interface IModel {
|
||||
public interface Model {
|
||||
|
||||
/**
|
||||
* A name uniquely identifying this model.
|
|
@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
|||
import com.jozufozu.flywheel.core.Formats;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
|
||||
public class ModelPart implements IModel {
|
||||
public class ModelPart implements Model {
|
||||
|
||||
private final List<PartBuilder.CuboidBuilder> cuboids;
|
||||
private int vertices;
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraft.client.renderer.RenderType;
|
|||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
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 String name;
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
|||
*
|
||||
* @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.
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.jozufozu.flywheel.backend.ShaderContext;
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
||||
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
|
||||
* 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
|
||||
* {@link com.jozufozu.flywheel.backend.ShaderContext ShaderContext}.
|
||||
* {@link ShaderContext ShaderContext}.
|
||||
*/
|
||||
public class ExtensibleGlProgram extends GlProgram {
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
|||
import com.jozufozu.flywheel.core.shader.spec.IGameStateCondition;
|
||||
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 P fallback;
|
||||
|
@ -55,7 +55,7 @@ public class GameStateProgram<P extends GlProgram> implements IMultiProgram<P> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public IMultiProgram<P> build() {
|
||||
public ContextAwareProgram<P> build() {
|
||||
return new GameStateProgram<>(ImmutableList.copyOf(variants), fallback);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.event;
|
|||
|
||||
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.vertex.PoseStack;
|
||||
import com.mojang.math.Matrix4f;
|
||||
|
|
|
@ -1,23 +1,16 @@
|
|||
package com.jozufozu.flywheel.light;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
|
||||
/**
|
||||
* Wraps a world and minimally lowers the interface.
|
||||
*/
|
||||
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 BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
|
||||
|
||||
public BasicProvider(BlockAndTintGetter reader) {
|
||||
this.reader = reader;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jozufozu.flywheel.light;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ICoordinateConsumer {
|
||||
public interface CoordinateConsumer {
|
||||
void consume(int x, int y, int z);
|
||||
}
|
|
@ -385,7 +385,7 @@ public class GridAlignedBB implements ImmutableBox {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void forEachContained(ICoordinateConsumer func) {
|
||||
public void forEachContained(CoordinateConsumer func) {
|
||||
if (empty()) return;
|
||||
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
default void forEachContained(ICoordinateConsumer func) {
|
||||
default void forEachContained(CoordinateConsumer func) {
|
||||
if (empty()) return;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.light;
|
|||
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
|
||||
public interface ILightUpdateListener {
|
||||
public interface LightListener {
|
||||
|
||||
ImmutableBox getVolume();
|
||||
|
|
@ -25,12 +25,12 @@ public class LightUpdater {
|
|||
|
||||
private final LightProvider provider;
|
||||
|
||||
private final WeakHashSet<IMovingListener> movingListeners = new WeakHashSet<>();
|
||||
private final WeakContainmentMultiMap<ILightUpdateListener> sections = new WeakContainmentMultiMap<>();
|
||||
private final WeakContainmentMultiMap<ILightUpdateListener> chunks = new WeakContainmentMultiMap<>();
|
||||
private final WeakHashSet<MovingListener> movingListeners = new WeakHashSet<>();
|
||||
private final WeakContainmentMultiMap<LightListener> sections = new WeakContainmentMultiMap<>();
|
||||
private final WeakContainmentMultiMap<LightListener> chunks = new WeakContainmentMultiMap<>();
|
||||
|
||||
public LightUpdater(BlockAndTintGetter world) {
|
||||
provider = BasicProvider.get(world);
|
||||
provider = new BasicProvider(world);
|
||||
}
|
||||
|
||||
public LightProvider getProvider() {
|
||||
|
@ -38,7 +38,7 @@ public class LightUpdater {
|
|||
}
|
||||
|
||||
public void tick() {
|
||||
for (IMovingListener listener : movingListeners) {
|
||||
for (MovingListener listener : movingListeners) {
|
||||
if (listener.update(provider)) {
|
||||
addListener(listener);
|
||||
}
|
||||
|
@ -47,12 +47,12 @@ public class LightUpdater {
|
|||
|
||||
/**
|
||||
* Add a listener.
|
||||
|
||||
*
|
||||
* @param listener The object that wants to receive light update notifications.
|
||||
*/
|
||||
public void addListener(ILightUpdateListener listener) {
|
||||
if (listener instanceof IMovingListener)
|
||||
movingListeners.add(((IMovingListener) listener));
|
||||
public void addListener(LightListener listener) {
|
||||
if (listener instanceof MovingListener)
|
||||
movingListeners.add(((MovingListener) listener));
|
||||
|
||||
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.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 sectionPos A long representing the section position where light changed.
|
||||
*/
|
||||
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;
|
||||
|
||||
|
@ -99,26 +99,26 @@ public class LightUpdater {
|
|||
|
||||
ImmutableBox chunkBox = GridAlignedBB.from(SectionPos.of(sectionPos));
|
||||
|
||||
for (ILightUpdateListener listener : set) {
|
||||
for (LightListener listener : set) {
|
||||
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.
|
||||
*
|
||||
*/
|
||||
public void onLightPacket(int chunkX, int 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;
|
||||
|
||||
set.removeIf(l -> l.status().shouldRemove());
|
||||
|
||||
for (ILightUpdateListener listener : set) {
|
||||
for (LightListener listener : set) {
|
||||
listener.onLightPacket(provider, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class LightUpdater {
|
|||
}
|
||||
|
||||
public Stream<ImmutableBox> getAllBoxes() {
|
||||
return chunks.stream().map(ILightUpdateListener::getVolume);
|
||||
return chunks.stream().map(LightListener::getVolume);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.lwjgl.system.MemoryUtil;
|
|||
import net.minecraft.core.BlockPos;
|
||||
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 ByteBuffer lightData;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package com.jozufozu.flywheel.light;
|
||||
|
||||
public interface IMovingListener extends ILightUpdateListener {
|
||||
public interface MovingListener extends LightListener {
|
||||
boolean update(LightProvider provider);
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
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.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
||||
import com.jozufozu.flywheel.core.model.ModelPart;
|
||||
|
|
|
@ -4,9 +4,9 @@ import java.util.Calendar;
|
|||
|
||||
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.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
||||
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.jozufozu.flywheel.vanilla;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
|
||||
import com.jozufozu.flywheel.backend.api.instance.IDynamicInstance;
|
||||
import com.jozufozu.flywheel.backend.api.instance.ITickableInstance;
|
||||
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.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.util.AnimationTickHolder;
|
||||
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
|
||||
|
@ -153,7 +153,7 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
|
|||
.createInstance();
|
||||
}
|
||||
|
||||
private IModel getBodyModel() {
|
||||
private Model getBodyModel() {
|
||||
int y = -3;
|
||||
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()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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.material.MaterialManager;
|
||||
import com.jozufozu.flywheel.backend.api.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
||||
import com.jozufozu.flywheel.core.model.ModelPart;
|
||||
|
|
Loading…
Reference in a new issue