[Edge] Better handle world tick

This commit is contained in:
Sotr
2018-06-04 00:14:10 +08:00
parent 399671d50d
commit e526974792

View File

@@ -56,7 +56,7 @@ public class MixinMinecraftServer {
@Shadow public ServerConnection an() { return null; } @Shadow public ServerConnection an() { return null; }
@Shadow public CustomFunctionData aL() { return null; } @Shadow public CustomFunctionData aL() { return null; }
private final ExecutorCompletionService<Void> STAGE_WORLD_TICK = new ExecutorCompletionService<Void>(Executors.newFixedThreadPool(2, LogWrapper.STAGE_FACTORY)); private final ExecutorCompletionService<Void> STAGE_WORLD_TICK = new ExecutorCompletionService<Void>(Executors.newFixedThreadPool(1, LogWrapper.STAGE_FACTORY));
@Overwrite @Overwrite
public void D() throws InterruptedException { public void D() throws InterruptedException {
@@ -92,13 +92,12 @@ public class MixinMinecraftServer {
} }
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot
for (int i = 0; i < this.worlds.size(); ++i) { // CraftBukkit for (int i = 0; i < worlds.size(); ++i) { // CraftBukkit
WorldServer worldserver = this.worlds.get(i); WorldServer worldserver = worlds.get(i);
// TODO Fix this feature // TODO Fix this feature
// TileEntityHopper.skipHopperEvents = worldserver.paperConfig.disableHopperMoveEvents || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // TileEntityHopper.skipHopperEvents = worldserver.paperConfig.disableHopperMoveEvents || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0;
LogWrapper.silentTiming = true; Runnable tick = () -> {
STAGE_WORLD_TICK.submit(() -> {
try { try {
worldserver.doTick(); worldserver.doTick();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -111,31 +110,39 @@ public class MixinMinecraftServer {
worldserver.a(crashreport); worldserver.a(crashreport);
throw new ReportedException(crashreport); throw new ReportedException(crashreport);
} }
}, null); };
int size = worlds.size();
if (size > 1) {
LogWrapper.silentTiming = true;
STAGE_WORLD_TICK.submit(tick, null);
} else {
worldserver.timings.doTick.startTiming();
tick.run();
worldserver.timings.doTick.stopTiming();
}
STAGE_WORLD_TICK.submit(() -> {
try { try {
worldserver.tickEntities(); worldserver.timings.tickEntities.startTiming();
} catch (Throwable throwable1) { worlds.get(i + 1 < size ? i + 1 : 0).tickEntities();
worldserver.timings.tickEntities.stopTiming();
} catch (Throwable throwable) {
CrashReport crashreport; CrashReport crashreport;
try { try {
crashreport = CrashReport.a(throwable1, "Exception ticking world entities"); crashreport = CrashReport.a(throwable, "Exception ticking world entities");
} catch (Throwable t){ } catch (Throwable t){
throw new RuntimeException("Error generating crash report", t); throw new RuntimeException("Error generating crash report", t);
} }
worldserver.a(crashreport); worldserver.a(crashreport);
throw new ReportedException(crashreport); throw new ReportedException(crashreport);
} }
}, null);
if (size > 1) {
worldserver.timings.doTick.startTiming(); worldserver.timings.doTick.startTiming();
STAGE_WORLD_TICK.take(); // Block STAGE_WORLD_TICK.take();
worldserver.timings.doTick.stopTiming(); worldserver.timings.doTick.stopTiming();
worldserver.timings.tickEntities.startTiming();
STAGE_WORLD_TICK.take(); // Entity
LogWrapper.silentTiming = false; LogWrapper.silentTiming = false;
worldserver.timings.tickEntities.stopTiming(); }
worldserver.getTracker().updatePlayers(); worldserver.getTracker().updatePlayers();
worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions