Improve chunk readiness checking in SectorSimulationSystem
Convert the chunk readiness checking to use anyMatch, which allows the
check to short-circuit, almost always leading to fewer checks when at
least one chunk is loaded.
Also remove the unnecessary worldProvider field.
import org.terasology.logic.delay.PeriodicActionTriggeredEvent;
import org.terasology.registry.In;
import org.terasology.world.WorldComponent;
-import org.terasology.world.WorldProvider;
import org.terasology.world.chunks.ChunkProvider;
import org.terasology.world.chunks.event.BeforeChunkUnload;
import org.terasology.world.chunks.event.OnChunkLoaded;
@In
private EntityManager entityManager;
- @In
- private WorldProvider worldProvider;
-
@In
private DelayManager delayManager;
@@ -144,14 +140,13 @@ public void processPeriodicSectorEvent(PeriodicActionTriggeredEvent event, Entit
if (event.getActionId().equals(SECTOR_SIMULATION_ACTION)) {
float delta = simulationDelta(entity);
- long readyChunks = SectorUtil.getWatchedChunks(entity).stream()
- .filter(chunkProvider::isChunkReady)
- .count();
+ boolean anyChunksReady = SectorUtil.getWatchedChunks(entity).stream()
+ .anyMatch(chunkProvider::isChunkReady);
- if (readyChunks == 0) {
- entity.send(new SectorSimulationEvent(delta));
- } else {
+ if (anyChunksReady) {
sendLoadedSectorUpdateEvent(entity, delta);
+ } else {
+ entity.send(new SectorSimulationEvent(delta));
}
}
}
