mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 23:47:09 +01:00
Fix crash on load when backend is off
- Closes #81 - Disabled crashing on error poll
This commit is contained in:
parent
92ad07c779
commit
123a548474
8 changed files with 50 additions and 33 deletions
|
@ -12,7 +12,6 @@ import com.jozufozu.flywheel.backend.Backend;
|
|||
import com.jozufozu.flywheel.backend.gl.GlFence;
|
||||
import com.jozufozu.flywheel.backend.gl.error.GlError;
|
||||
import com.jozufozu.flywheel.backend.gl.error.GlException;
|
||||
import com.jozufozu.flywheel.util.StringUtil;
|
||||
|
||||
public class PersistentGlBuffer extends GlBuffer implements Mappable {
|
||||
|
||||
|
@ -49,13 +48,6 @@ public class PersistentGlBuffer extends GlBuffer implements Mappable {
|
|||
|
||||
Backend.getInstance().compat.bufferStorage.bufferStorage(type, size, flags);
|
||||
|
||||
GlError error = GlError.poll();
|
||||
if (error != null) {
|
||||
// If this error is being thrown but everything seems fine,
|
||||
// GlError.poll() might be returning an error from something earlier.
|
||||
throw new GlException(error, StringUtil.args("bufferStorage", type, size, flags));
|
||||
}
|
||||
|
||||
ByteBuffer byteBuffer = GL30.glMapBufferRange(type.glEnum, 0, size, flags);
|
||||
|
||||
if (byteBuffer == null) {
|
||||
|
|
|
@ -5,8 +5,6 @@ import java.util.function.Supplier;
|
|||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
|
||||
|
@ -41,10 +39,10 @@ public enum GlError {
|
|||
}
|
||||
|
||||
public static void pollAndThrow(Supplier<String> context) {
|
||||
// TODO: build flag? to enable or disable this function
|
||||
GlError err = GlError.poll();
|
||||
if (err != null) {
|
||||
Flywheel.LOGGER.error("{}: {}", err.name(), context.get());
|
||||
}
|
||||
// This was a bad idea.
|
||||
// GlError err = GlError.poll();
|
||||
// if (err != null) {
|
||||
// Flywheel.LOGGER.error("{}: {}", err.name(), context.get());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,11 @@ public class InstancedRenderDispatcher {
|
|||
* @param te The tile whose instance you want to update.
|
||||
*/
|
||||
public static void enqueueUpdate(BlockEntity te) {
|
||||
if (te.hasLevel() && te.getLevel() instanceof ClientLevel)
|
||||
getTiles(te.getLevel()).queueUpdate(te);
|
||||
if (Backend.isOn() && te.hasLevel() && te.getLevel() instanceof ClientLevel) {
|
||||
instanceWorlds.get(te.getLevel())
|
||||
.getTileEntityInstanceManager()
|
||||
.queueUpdate(te);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,17 +41,29 @@ public class InstancedRenderDispatcher {
|
|||
* @param entity The entity whose instance you want to update.
|
||||
*/
|
||||
public static void enqueueUpdate(Entity entity) {
|
||||
getEntities(entity.level).queueUpdate(entity);
|
||||
if (Backend.isOn()) {
|
||||
instanceWorlds.get(entity.level)
|
||||
.getEntityInstanceManager()
|
||||
.queueUpdate(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public static InstanceManager<BlockEntity> getTiles(LevelAccessor world) {
|
||||
return instanceWorlds.get(world)
|
||||
.getTileEntityInstanceManager();
|
||||
if (Backend.isOn()) {
|
||||
return instanceWorlds.get(world)
|
||||
.getTileEntityInstanceManager();
|
||||
} else {
|
||||
throw new NullPointerException("Backend is off, cannot retrieve instance world.");
|
||||
}
|
||||
}
|
||||
|
||||
public static InstanceManager<Entity> getEntities(LevelAccessor world) {
|
||||
return instanceWorlds.get(world)
|
||||
.getEntityInstanceManager();
|
||||
if (Backend.isOn()) {
|
||||
return instanceWorlds.get(world)
|
||||
.getEntityInstanceManager();
|
||||
} else {
|
||||
throw new NullPointerException("Backend is off, cannot retrieve instance world.");
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -61,12 +76,15 @@ public class InstancedRenderDispatcher {
|
|||
ClientLevel world = mc.level;
|
||||
AnimationTickHolder.tick();
|
||||
|
||||
instanceWorlds.get(world).tick();
|
||||
if (Backend.isOn()) {
|
||||
instanceWorlds.get(world)
|
||||
.tick();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBeginFrame(BeginFrameEvent event) {
|
||||
if (Backend.isGameActive()) {
|
||||
if (Backend.isGameActive() && Backend.isOn()) {
|
||||
instanceWorlds.get(event.getWorld())
|
||||
.beginFrame(event);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.jozufozu.flywheel.event;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
@ -13,13 +14,13 @@ public class EntityWorldHandler {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void onEntityJoinWorld(EntityJoinWorldEvent event) {
|
||||
if (event.getWorld().isClientSide) InstancedRenderDispatcher.getEntities(event.getWorld())
|
||||
if (event.getWorld().isClientSide && Backend.isOn()) InstancedRenderDispatcher.getEntities(event.getWorld())
|
||||
.queueAdd(event.getEntity());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onEntityLeaveWorld(EntityLeaveWorldEvent event) {
|
||||
if (event.getWorld().isClientSide) InstancedRenderDispatcher.getEntities(event.getWorld())
|
||||
if (event.getWorld().isClientSide && Backend.isOn()) InstancedRenderDispatcher.getEntities(event.getWorld())
|
||||
.remove(event.getEntity());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ChunkRebuildHooksMixin {
|
|||
@Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true)
|
||||
private <E extends BlockEntity> void addAndFilterBEs(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> set, E be, CallbackInfo ci) {
|
||||
|
||||
if (Backend.isOn() && Backend.isFlywheelWorld(be.getLevel())) {
|
||||
if (Backend.canUseInstancing(be.getLevel())) {
|
||||
|
||||
InstancedRenderRegistry registry = InstancedRenderRegistry.getInstance();
|
||||
if (registry.canInstance(be.getType()))
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
|
@ -26,7 +27,9 @@ public class InstanceAddMixin {
|
|||
@Inject(method = "setBlockEntity",
|
||||
at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))
|
||||
private void tileAdded(BlockEntity be, CallbackInfo ci) {
|
||||
if (level.isClientSide) InstancedRenderDispatcher.getTiles(this.level)
|
||||
.add(be);
|
||||
if (level.isClientSide && Backend.isOn()) {
|
||||
InstancedRenderDispatcher.getTiles(this.level)
|
||||
.add(be);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
@ -23,8 +24,10 @@ public class InstanceRemoveMixin {
|
|||
|
||||
@Inject(at = @At("TAIL"), method = "setRemoved")
|
||||
private void removeInstance(CallbackInfo ci) {
|
||||
if (level instanceof ClientLevel) InstancedRenderDispatcher.getTiles(this.level)
|
||||
.remove((BlockEntity) (Object) this);
|
||||
if (level instanceof ClientLevel && Backend.isOn()) {
|
||||
InstancedRenderDispatcher.getTiles(this.level)
|
||||
.remove((BlockEntity) (Object) this);
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
|
|
|
@ -86,7 +86,9 @@ public class RenderHooksMixin {
|
|||
*/
|
||||
@Inject(at = @At("TAIL"), method = "setBlockDirty(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V")
|
||||
private void checkUpdate(BlockPos pos, BlockState lastState, BlockState newState, CallbackInfo ci) {
|
||||
InstancedRenderDispatcher.getTiles(level)
|
||||
.update(level.getBlockEntity(pos));
|
||||
if (Backend.isOn()) {
|
||||
InstancedRenderDispatcher.getTiles(level)
|
||||
.update(level.getBlockEntity(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue