mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 20:11:35 +01:00
No more compartments in Flywheel.
It never really needed them in the first place.
This commit is contained in:
parent
322496f3b4
commit
c9718b0a1b
2 changed files with 33 additions and 45 deletions
|
@ -1,7 +1,12 @@
|
||||||
package com.simibubi.create.foundation.render.backend;
|
package com.simibubi.create.foundation.render.backend;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
|
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||||
|
import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||||
|
|
||||||
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.vector.Matrix3f;
|
import net.minecraft.util.math.vector.Matrix3f;
|
||||||
import net.minecraft.util.math.vector.Matrix4f;
|
import net.minecraft.util.math.vector.Matrix4f;
|
||||||
|
|
||||||
|
@ -71,4 +76,16 @@ public class RenderUtil {
|
||||||
model.a33,
|
model.a33,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Supplier<MatrixStack> rotateToFace(Direction facing) {
|
||||||
|
return () -> {
|
||||||
|
MatrixStack stack = new MatrixStack();
|
||||||
|
MatrixStacker.of(stack)
|
||||||
|
.centre()
|
||||||
|
.rotateY(AngleHelper.horizontalAngle(facing))
|
||||||
|
.rotateX(AngleHelper.verticalAngle(facing))
|
||||||
|
.unCentre();
|
||||||
|
return stack;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.simibubi.create.foundation.render.backend.instancing;
|
package com.simibubi.create.foundation.render.backend.instancing;
|
||||||
|
|
||||||
import static com.simibubi.create.foundation.render.Compartment.PARTIAL;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -14,16 +10,14 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||||
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.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.simibubi.create.foundation.render.Compartment;
|
|
||||||
import com.simibubi.create.foundation.render.SuperByteBufferCache;
|
import com.simibubi.create.foundation.render.SuperByteBufferCache;
|
||||||
import com.simibubi.create.foundation.render.backend.Backend;
|
import com.simibubi.create.foundation.render.backend.Backend;
|
||||||
import com.simibubi.create.foundation.render.backend.FastRenderDispatcher;
|
import com.simibubi.create.foundation.render.backend.FastRenderDispatcher;
|
||||||
|
import com.simibubi.create.foundation.render.backend.RenderUtil;
|
||||||
import com.simibubi.create.foundation.render.backend.core.PartialModel;
|
import com.simibubi.create.foundation.render.backend.core.PartialModel;
|
||||||
import com.simibubi.create.foundation.render.backend.gl.BasicProgram;
|
import com.simibubi.create.foundation.render.backend.gl.BasicProgram;
|
||||||
import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec;
|
import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec;
|
||||||
import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback;
|
import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback;
|
||||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
|
||||||
import com.simibubi.create.foundation.utility.MatrixStacker;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -37,7 +31,7 @@ import net.minecraft.util.math.vector.Matrix4f;
|
||||||
public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel<?>> {
|
public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel<?>> {
|
||||||
|
|
||||||
protected final InstancedTileRenderer<?> renderer;
|
protected final InstancedTileRenderer<?> renderer;
|
||||||
protected final Map<Compartment<?>, Cache<Object, MODEL>> models;
|
protected final Cache<Object, MODEL> models;
|
||||||
protected final ModelFactory<MODEL> factory;
|
protected final ModelFactory<MODEL> factory;
|
||||||
protected final ProgramSpec<P> programSpec;
|
protected final ProgramSpec<P> programSpec;
|
||||||
protected final Predicate<RenderType> layerPredicate;
|
protected final Predicate<RenderType> layerPredicate;
|
||||||
|
@ -51,13 +45,12 @@ public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel
|
||||||
|
|
||||||
public RenderMaterial(InstancedTileRenderer<?> renderer, ProgramSpec<P> programSpec, ModelFactory<MODEL> factory, Predicate<RenderType> layerPredicate) {
|
public RenderMaterial(InstancedTileRenderer<?> renderer, ProgramSpec<P> programSpec, ModelFactory<MODEL> factory, Predicate<RenderType> layerPredicate) {
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
this.models = new HashMap<>();
|
this.models = CacheBuilder.newBuilder()
|
||||||
|
.removalListener(notification -> ((InstancedModel<?>) notification.getValue()).delete())
|
||||||
|
.build();
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.programSpec = programSpec;
|
this.programSpec = programSpec;
|
||||||
this.layerPredicate = layerPredicate;
|
this.layerPredicate = layerPredicate;
|
||||||
registerCompartment(Compartment.PARTIAL);
|
|
||||||
registerCompartment(Compartment.DIRECTIONAL_PARTIAL);
|
|
||||||
registerCompartment(Compartment.GENERIC_TILE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canRenderInLayer(RenderType layer) {
|
public boolean canRenderInLayer(RenderType layer) {
|
||||||
|
@ -75,15 +68,11 @@ public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel
|
||||||
if (setup != null) setup.call(program);
|
if (setup != null) setup.call(program);
|
||||||
|
|
||||||
makeRenderCalls();
|
makeRenderCalls();
|
||||||
teardown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void teardown() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
runOnAll(InstancedModel::delete);
|
//runOnAll(InstancedModel::delete);
|
||||||
models.values().forEach(Cache::invalidateAll);
|
models.invalidateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void makeRenderCalls() {
|
protected void makeRenderCalls() {
|
||||||
|
@ -91,38 +80,31 @@ public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runOnAll(Consumer<MODEL> f) {
|
public void runOnAll(Consumer<MODEL> f) {
|
||||||
for (Cache<Object, MODEL> cache : models.values()) {
|
for (MODEL model : models.asMap().values()) {
|
||||||
for (MODEL model : cache.asMap().values()) {
|
f.accept(model);
|
||||||
f.accept(model);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCompartment(Compartment<?> instance) {
|
|
||||||
models.put(instance, CacheBuilder.newBuilder().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public MODEL getModel(PartialModel partial, BlockState referenceState) {
|
public MODEL getModel(PartialModel partial, BlockState referenceState) {
|
||||||
return get(PARTIAL, partial, () -> buildModel(partial.get(), referenceState));
|
return get(partial, () -> buildModel(partial.get(), referenceState));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MODEL getModel(PartialModel partial, BlockState referenceState, Direction dir) {
|
public MODEL getModel(PartialModel partial, BlockState referenceState, Direction dir) {
|
||||||
return getModel(partial, referenceState, dir, rotateToFace(dir));
|
return getModel(partial, referenceState, dir, RenderUtil.rotateToFace(dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MODEL getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier<MatrixStack> modelTransform) {
|
public MODEL getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier<MatrixStack> modelTransform) {
|
||||||
return get(Compartment.DIRECTIONAL_PARTIAL, Pair.of(dir, partial),
|
return get(Pair.of(dir, partial),
|
||||||
() -> buildModel(partial.get(), referenceState, modelTransform.get()));
|
() -> buildModel(partial.get(), referenceState, modelTransform.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MODEL getModel(BlockState toRender) {
|
public MODEL getModel(BlockState toRender) {
|
||||||
return get(Compartment.GENERIC_TILE, toRender, () -> buildModel(toRender));
|
return get(toRender, () -> buildModel(toRender));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> MODEL get(Compartment<T> compartment, T key, Supplier<MODEL> supplier) {
|
public MODEL get(Object key, Supplier<MODEL> supplier) {
|
||||||
Cache<Object, MODEL> compartmentCache = models.get(compartment);
|
|
||||||
try {
|
try {
|
||||||
return compartmentCache.get(key, supplier::get);
|
return models.get(key, supplier::get);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
@ -144,15 +126,4 @@ public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel
|
||||||
return factory.makeModel(renderer, builder);
|
return factory.makeModel(renderer, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Supplier<MatrixStack> rotateToFace(Direction facing) {
|
|
||||||
return () -> {
|
|
||||||
MatrixStack stack = new MatrixStack();
|
|
||||||
MatrixStacker.of(stack)
|
|
||||||
.centre()
|
|
||||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
|
||||||
.rotateX(AngleHelper.verticalAngle(facing))
|
|
||||||
.unCentre();
|
|
||||||
return stack;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue