Small Optimization
EnergonRelics/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-08-20 21:21:35 -04:00
parent c484e6d78a
commit c095f7da28
1 changed files with 14 additions and 4 deletions

View File

@ -47,6 +47,8 @@ public class EnergyTicker {
NetworkComponent.getInstance((ServerWorld) world).clearCache(); NetworkComponent.getInstance((ServerWorld) world).clearCache();
world.getProfiler().push("startTick");
List<EnergyTickable> started = new ArrayList<>(); List<EnergyTickable> started = new ArrayList<>();
List<EnergyTickable> temp = new ArrayList<>(scheduled); List<EnergyTickable> temp = new ArrayList<>(scheduled);
@ -54,7 +56,7 @@ public class EnergyTicker {
while (!temp.isEmpty()) { while (!temp.isEmpty()) {
for (EnergyTickable tickable : temp) { for (EnergyTickable tickable : temp) {
if (!started.contains(tickable)) { if (!started.contains(tickable)) {
world.getProfiler().push(() -> tickable.getID() + " startTick"); world.getProfiler().push(tickable::getID);
temp2.addAll(tickable.startTick()); temp2.addAll(tickable.startTick());
started.add(tickable); started.add(tickable);
@ -62,8 +64,10 @@ public class EnergyTicker {
world.getProfiler().pop(); world.getProfiler().pop();
} }
} }
temp.clear();
temp.addAll(temp2); List<EnergyTickable> temp3 = temp;
temp = temp2;
temp2 = temp3;
temp2.clear(); temp2.clear();
} }
@ -73,8 +77,12 @@ public class EnergyTicker {
Collections.shuffle(started, world.random); Collections.shuffle(started, world.random);
world.getProfiler().pop(); world.getProfiler().pop();
world.getProfiler().pop();
world.getProfiler().push("logicTick");
for (EnergyTickable tickable : started) { for (EnergyTickable tickable : started) {
world.getProfiler().push(() -> tickable.getID() + " logicTick"); world.getProfiler().push(tickable::getID);
tickable.logicTick(); tickable.logicTick();
@ -82,6 +90,8 @@ public class EnergyTicker {
} }
world.getProfiler().pop(); world.getProfiler().pop();
world.getProfiler().pop();
} }
scheduled.clear(); scheduled.clear();