Add Check for State Changes During Grid Update

This commit is contained in:
Marty Oehme 2018-07-08 19:32:43 +02:00
parent 9fb67d0194
commit 1146c7d265
2 changed files with 8 additions and 4 deletions

View file

@ -56,7 +56,7 @@ class App {
void update() { void update() {
// print("updating"); // print("updating");
grid.update(); if(!grid.update()) running = false;
} }
void render([num interp]) { void render([num interp]) {

View file

@ -143,7 +143,8 @@ class Grid {
return grid; return grid;
} }
void update() { bool update() {
bool stateChanges = false;
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
// DEFAULTS TO CONWAY GAME OF LIFE RANGE OF ONE // DEFAULTS TO CONWAY GAME OF LIFE RANGE OF ONE
@ -152,11 +153,14 @@ class Grid {
} }
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
// DEFAULTS TO CONWAY GAME OF LIFE RANGE OF ONE Cell c = map[y][x];
map[y][x].advanceState(); if(c.state != c.nextState) stateChanges = true;
c.advanceState();
if (!_dirty && map[y][x].dirty) _dirty = true; if (!_dirty && map[y][x].dirty) _dirty = true;
} }
} }
return stateChanges;
} }
int getSurroundingNeighbors(int x, int y, int range) { int getSurroundingNeighbors(int x, int y, int range) {