From 8c4a74179dfbdc6c3bfb3bde060f4642028ebec8 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Wed, 4 Aug 2021 01:47:36 -0400 Subject: [PATCH] Better Rates --- .../volmit/iris/engine/IrisWorldManager.java | 29 +++++++++++++++++-- .../volmit/iris/engine/object/IrisEntity.java | 20 +++++++++++-- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisWorldManager.java b/src/main/java/com/volmit/iris/engine/IrisWorldManager.java index b901c2e68..cdc53d6f0 100644 --- a/src/main/java/com/volmit/iris/engine/IrisWorldManager.java +++ b/src/main/java/com/volmit/iris/engine/IrisWorldManager.java @@ -60,6 +60,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager { private final ChronoLatch ecl; private int actuallySpawned = 0; private int cooldown = 0; + private List precount = new KList<>(); public IrisWorldManager() { super(null); @@ -71,13 +72,30 @@ public class IrisWorldManager extends EngineAssignedWorldManager { public IrisWorldManager(Engine engine) { super(engine); - cl = new ChronoLatch(1000); + cl = new ChronoLatch(3000); ecl = new ChronoLatch(250); chunkCooldowns = new KMap<>(); energy = 25; looper = new Looper() { @Override protected long loop() { + if(precount != null) + { + entityCount = 0; + for(Entity i : precount) + { + if(i instanceof LivingEntity) + { + if(!i.isDead()) + { + entityCount++; + } + } + } + + precount = null; + } + if(energy < 650) { if(ecl.flip()) @@ -120,7 +138,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager { } if (cl.flip()) { - J.s(() -> entityCount = getEngine().getWorld().realWorld().getEntities().size()); + J.s(() -> precount = getEngine().getWorld().realWorld().getEntities()); } int maxGroups = 1; @@ -346,6 +364,11 @@ public class IrisWorldManager extends EngineAssignedWorldManager { @Override public double getEntitySaturation() { - return (double) entityCount / (getEngine().getWorld().realWorld().getLoadedChunks().length + 1) * 1.665; + if(!getEngine().getWorld().hasRealWorld()) + { + return 1; + } + + return (double) entityCount / (getEngine().getWorld().realWorld().getLoadedChunks().length + 1) * 1.28; } } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEntity.java b/src/main/java/com/volmit/iris/engine/object/IrisEntity.java index a6688c7d3..08e592798 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEntity.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEntity.java @@ -90,7 +90,7 @@ public class IrisEntity extends IrisRegistrant { private boolean pickupItems = false; @Desc("Should this entity be removed when far away") - private boolean removable = true; + private boolean removable = false; @Desc("Entity helmet equipment") private IrisLoot helmet = null; @@ -266,11 +266,25 @@ public class IrisEntity extends IrisRegistrant { // Someone called spawn (worldedit maybe?) on a non server thread // Due to the structure of iris, we will call it sync and busy wait until it's done. AtomicReference ae = new AtomicReference<>(); - J.s(() -> ae.set(doSpawn(at))); + + try + { + J.s(() -> ae.set(doSpawn(at))); + } + + catch(Throwable e) + { + return null; + } PrecisionStopwatch p = PrecisionStopwatch.start(); while (ae.get() == null) { - J.sleep(3); + J.sleep(25); + + if(p.getMilliseconds() > 500) + { + return null; + } } return ae.get();