mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 16:06:28 +01:00
Ready for 0.1.1 (finally)
- Might have bumped the version too early. - Fix crash rendering breaking overlay after reloading resource packs.
This commit is contained in:
parent
ef46e5acbf
commit
c6b0996b8a
7 changed files with 103 additions and 13 deletions
|
@ -161,6 +161,5 @@ curseforge {
|
||||||
changelog = file('changelog.txt')
|
changelog = file('changelog.txt')
|
||||||
releaseType = project.curse_type
|
releaseType = project.curse_type
|
||||||
mainArtifact jar
|
mainArtifact jar
|
||||||
addArtifact sourcesJar
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
New
|
New
|
||||||
- Flywheel driven chest and bell rendering, ~20x performance improvement in contrived cases
|
- Flywheel driven chest and bell rendering, ~20x performance improvement in contrived cases
|
||||||
Fixes
|
Fixes
|
||||||
- Fix potential crash related to rendering breaking overlay
|
- Fix crash rendering breaking overlay after reloading resource packs
|
||||||
Technical/API
|
Technical/API
|
||||||
- Deprecate instance registration functions in favor of builders
|
- Deprecate instance registration functions in favor of builders
|
||||||
- Refactor breaking overlay renderer to be cleaner and more contained
|
- Refactor breaking overlay renderer to be cleaner and more contained
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
|
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
|
||||||
|
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||||
import com.jozufozu.flywheel.backend.loading.Shader;
|
import com.jozufozu.flywheel.backend.loading.Shader;
|
||||||
import com.jozufozu.flywheel.backend.loading.ShaderLoadingException;
|
import com.jozufozu.flywheel.backend.loading.ShaderLoadingException;
|
||||||
|
@ -98,7 +99,9 @@ public class ShaderSources implements ISelectiveResourceReloadListener {
|
||||||
|
|
||||||
ClientWorld world = Minecraft.getInstance().world;
|
ClientWorld world = Minecraft.getInstance().world;
|
||||||
if (Backend.isFlywheelWorld(world)) {
|
if (Backend.isFlywheelWorld(world)) {
|
||||||
|
// TODO: looks like it might be good to have another event here
|
||||||
InstancedRenderDispatcher.loadAllInWorld(world);
|
InstancedRenderDispatcher.loadAllInWorld(world);
|
||||||
|
CrumblingRenderer.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,14 @@ import com.jozufozu.flywheel.util.WeakHashSet;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
import net.minecraft.inventory.container.PlayerContainer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.vector.Matrix4f;
|
import net.minecraft.util.math.vector.Matrix4f;
|
||||||
import net.minecraft.util.math.vector.Vector3i;
|
import net.minecraft.util.math.vector.Vector3i;
|
||||||
|
|
||||||
|
// TODO: 0.2 block atlas should not be a special case
|
||||||
public class MaterialManager<P extends WorldProgram> {
|
public class MaterialManager<P extends WorldProgram> {
|
||||||
|
|
||||||
public static int MAX_ORIGIN_DISTANCE = 100;
|
public static int MAX_ORIGIN_DISTANCE = 100;
|
||||||
|
@ -103,6 +105,7 @@ public class MaterialManager<P extends WorldProgram> {
|
||||||
atlasMaterials.clear();
|
atlasMaterials.clear();
|
||||||
atlasRenderers.clear();
|
atlasRenderers.clear();
|
||||||
materials.clear();
|
materials.clear();
|
||||||
|
renderers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.backend.instancing;
|
package com.jozufozu.flywheel.core.crumbling;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
||||||
import static org.lwjgl.opengl.GL11.glBindTexture;
|
import static org.lwjgl.opengl.GL11.glBindTexture;
|
||||||
|
@ -11,11 +11,12 @@ import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
|
||||||
import com.jozufozu.flywheel.core.Contexts;
|
import com.jozufozu.flywheel.core.Contexts;
|
||||||
import com.jozufozu.flywheel.core.crumbling.CrumblingInstanceManager;
|
|
||||||
import com.jozufozu.flywheel.core.crumbling.CrumblingMaterialManager;
|
|
||||||
import com.jozufozu.flywheel.core.crumbling.CrumblingProgram;
|
|
||||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||||
|
import com.jozufozu.flywheel.util.Lazy;
|
||||||
|
import com.jozufozu.flywheel.util.Pair;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
@ -29,7 +30,6 @@ import net.minecraft.client.renderer.texture.Texture;
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
import net.minecraft.client.world.ClientWorld;
|
import net.minecraft.client.world.ClientWorld;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.LazyValue;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.vector.Matrix4f;
|
import net.minecraft.util.math.vector.Matrix4f;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
@ -44,8 +44,15 @@ import net.minecraftforge.fml.common.Mod;
|
||||||
@Mod.EventBusSubscriber(Dist.CLIENT)
|
@Mod.EventBusSubscriber(Dist.CLIENT)
|
||||||
public class CrumblingRenderer {
|
public class CrumblingRenderer {
|
||||||
|
|
||||||
private static final LazyValue<MaterialManager<CrumblingProgram>> materialManager = new LazyValue<>(() -> new CrumblingMaterialManager(Contexts.CRUMBLING));
|
private static final Lazy<State> STATE;
|
||||||
private static final LazyValue<InstanceManager<TileEntity>> manager = new LazyValue<>(() -> new CrumblingInstanceManager(materialManager.getValue()));
|
private static final Lazy.KillSwitch<State> INVALIDATOR;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Pair<Lazy<State>, Lazy.KillSwitch<State>> state = Lazy.ofKillable(State::new, State::kill);
|
||||||
|
|
||||||
|
STATE = state.getFirst();
|
||||||
|
INVALIDATOR = state.getSecond();
|
||||||
|
}
|
||||||
|
|
||||||
private static final RenderType crumblingLayer = ModelBakery.BLOCK_DESTRUCTION_RENDER_LAYERS.get(0);
|
private static final RenderType crumblingLayer = ModelBakery.BLOCK_DESTRUCTION_RENDER_LAYERS.get(0);
|
||||||
|
|
||||||
|
@ -57,12 +64,14 @@ public class CrumblingRenderer {
|
||||||
|
|
||||||
if (activeStages.isEmpty()) return;
|
if (activeStages.isEmpty()) return;
|
||||||
|
|
||||||
InstanceManager<TileEntity> renderer = manager.getValue();
|
State state = STATE.get();
|
||||||
|
|
||||||
|
InstanceManager<TileEntity> renderer = state.instanceManager;
|
||||||
|
|
||||||
TextureManager textureManager = Minecraft.getInstance().textureManager;
|
TextureManager textureManager = Minecraft.getInstance().textureManager;
|
||||||
ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
|
ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
|
||||||
|
|
||||||
MaterialManager<CrumblingProgram> materials = materialManager.getValue();
|
MaterialManager<CrumblingProgram> materials = state.materialManager;
|
||||||
crumblingLayer.startDrawing();
|
crumblingLayer.startDrawing();
|
||||||
|
|
||||||
for (Int2ObjectMap.Entry<List<TileEntity>> stage : activeStages.int2ObjectEntrySet()) {
|
for (Int2ObjectMap.Entry<List<TileEntity>> stage : activeStages.int2ObjectEntrySet()) {
|
||||||
|
@ -124,7 +133,26 @@ public class CrumblingRenderer {
|
||||||
ClientWorld world = event.getWorld();
|
ClientWorld world = event.getWorld();
|
||||||
if (Backend.getInstance()
|
if (Backend.getInstance()
|
||||||
.canUseInstancing() && world != null) {
|
.canUseInstancing() && world != null) {
|
||||||
materialManager.getValue().delete();
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reset() {
|
||||||
|
INVALIDATOR.killValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class State {
|
||||||
|
private final MaterialManager<CrumblingProgram> materialManager;
|
||||||
|
private final InstanceManager<TileEntity> instanceManager;
|
||||||
|
|
||||||
|
private State() {
|
||||||
|
materialManager = new CrumblingMaterialManager(Contexts.CRUMBLING);
|
||||||
|
instanceManager = new CrumblingInstanceManager(materialManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void kill() {
|
||||||
|
materialManager.delete();
|
||||||
|
instanceManager.invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.OptifineHandler;
|
import com.jozufozu.flywheel.backend.OptifineHandler;
|
||||||
import com.jozufozu.flywheel.backend.instancing.CrumblingRenderer;
|
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||||
|
|
57
src/main/java/com/jozufozu/flywheel/util/Lazy.java
Normal file
57
src/main/java/com/jozufozu/flywheel/util/Lazy.java
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package com.jozufozu.flywheel.util;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.util.NonNullSupplier;
|
||||||
|
|
||||||
|
public class Lazy<T> {
|
||||||
|
|
||||||
|
private final NonNullSupplier<T> supplier;
|
||||||
|
|
||||||
|
private T value;
|
||||||
|
|
||||||
|
public Lazy(NonNullSupplier<T> supplier) {
|
||||||
|
this.supplier = supplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public T get() {
|
||||||
|
if (value == null) {
|
||||||
|
value = supplier.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an external facing API safe way of invalidating lazy values.
|
||||||
|
*/
|
||||||
|
public static <T> Pair<Lazy<T>, KillSwitch<T>> ofKillable(NonNullSupplier<T> factory, Consumer<T> destructor) {
|
||||||
|
Lazy<T> lazy = new Lazy<>(factory);
|
||||||
|
|
||||||
|
KillSwitch<T> killSwitch = new KillSwitch<>(lazy, destructor);
|
||||||
|
|
||||||
|
return Pair.of(lazy, killSwitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class KillSwitch<T> {
|
||||||
|
|
||||||
|
private final Lazy<T> lazy;
|
||||||
|
private final Consumer<T> finalizer;
|
||||||
|
|
||||||
|
private KillSwitch(Lazy<T> lazy, Consumer<T> finalizer) {
|
||||||
|
this.lazy = lazy;
|
||||||
|
this.finalizer = finalizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void killValue() {
|
||||||
|
if (lazy.value != null) {
|
||||||
|
finalizer.accept(lazy.value);
|
||||||
|
lazy.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue