Add simple stateChanges map into Simulation

This commit is contained in:
Unknown 2018-10-02 14:55:39 +02:00
parent 9c37f87045
commit c50e92fb19
2 changed files with 9 additions and 10 deletions

View file

@ -101,7 +101,8 @@ class Engine {
/// directly, since it is automatically taken care of by the processing function. /// directly, since it is automatically taken care of by the processing function.
/// If simulation should be advanced manually one time, prefer using step(). /// If simulation should be advanced manually one time, prefer using step().
void update() { 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 /// Advances Logic One Update

View file

@ -125,19 +125,17 @@ class Simulation {
return null; return null;
} }
bool update() { Map<int, Cell> update() {
bool stateChanges = false; Map<int, Cell> stateChanges = Map();
for (int i = 0; i < map.length; i++) { for (int i = 0; i < map.length; i++) {
math.Point p = map.toCoordinates(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 stateChanges.forEach((_, el) => el.advanceState());
map.forEach((Cell el) { stateChanges.length != 0 ? _dirty = true : false;
if (el.state != el.nextState) stateChanges = true;
el.advanceState();
});
stateChanges ? _dirty = true : false;
return stateChanges; return stateChanges;
} }