From c50e92fb19705ebc4a3fe49df5150c6dd71fcbb3 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 2 Oct 2018 14:55:39 +0200 Subject: [PATCH] Add simple stateChanges map into Simulation --- lib/src/Engine.dart | 3 ++- lib/src/Simulation.dart | 16 +++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/src/Engine.dart b/lib/src/Engine.dart index 84d52e8..9855d14 100644 --- a/lib/src/Engine.dart +++ b/lib/src/Engine.dart @@ -101,7 +101,8 @@ class Engine { /// directly, since it is automatically taken care of by the processing function. /// If simulation should be advanced manually one time, prefer using step(). void update() { - if (!_grid.update()) running = false; + // TODO: create hasUpdated/hasAdvanced method in simulation to abstract actual updating away + if (_grid.update().length != 0) running = false; } /// Advances Logic One Update diff --git a/lib/src/Simulation.dart b/lib/src/Simulation.dart index ca7bb71..e451bf0 100644 --- a/lib/src/Simulation.dart +++ b/lib/src/Simulation.dart @@ -125,19 +125,17 @@ class Simulation { return null; } - bool update() { - bool stateChanges = false; + Map update() { + Map stateChanges = Map(); for (int i = 0; i < map.length; i++) { math.Point p = map.toCoordinates(i); - map[i].update(getSurroundingNeighbors(p.x, p.y, 1)); + Cell el = map[i]; + el.update(getSurroundingNeighbors(p.x, p.y, 1)); + stateChanges[i] = el; } - // TODO when implementing changeSet we can remove this second loop and add to changeSet in the first - map.forEach((Cell el) { - if (el.state != el.nextState) stateChanges = true; - el.advanceState(); - }); - stateChanges ? _dirty = true : false; + stateChanges.forEach((_, el) => el.advanceState()); + stateChanges.length != 0 ? _dirty = true : false; return stateChanges; }