Add simple stateChanges map into Simulation
This commit is contained in:
parent
9c37f87045
commit
c50e92fb19
2 changed files with 9 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -125,19 +125,17 @@ class Simulation {
|
|||
return null;
|
||||
}
|
||||
|
||||
bool update() {
|
||||
bool stateChanges = false;
|
||||
Map<int, Cell> update() {
|
||||
Map<int, Cell> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue