Fix Reset & Step not working on first click

Rendering dirty flags were not updated accordingly, so the updates happened but were not pushed to be rendered. Added and moved additional dirty flag setters.
This commit is contained in:
Marty Oehme 2018-07-07 21:43:24 +02:00
parent 2d2365e606
commit c5b62e6c9f
3 changed files with 10 additions and 4 deletions

View File

@ -44,6 +44,7 @@ class AppComponent implements OnInit {
}
void onResetClicked() {
engine.running = false;
engine.reset();
}

View File

@ -24,12 +24,13 @@ class App {
App(this.canvas) {
_elapsed.start();
grid.startingPattern();
grid.addPattern(amount: 15, dispersal: 5);
}
void reset() {
grid = new Grid(100, 100);
running = false;
// grid = new Grid(100, 100);
// running = false;
grid.reset();
}
void process(num now) {

View File

@ -89,6 +89,10 @@ class Grid {
if (y < map.length && x < map[y].length) map[y][x].state = state;
}
bool getCellState(int x, int y) {
if (y < map.length && x < map[y].length) return map[y][x].state;
}
List<List<Cell>> _buildGrid(int w, int h) {
print("grid being created");
List<List<Cell>> grid = new List(h);
@ -133,13 +137,13 @@ class Grid {
for (int x = 0; x < w; x++) {
// DEFAULTS TO CONWAY GAME OF LIFE RANGE OF ONE
map[y][x].update(getSurroundingNeighbors(x, y, 1));
if (!_dirty && map[y][x].dirty) _dirty = true;
}
}
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
// DEFAULTS TO CONWAY GAME OF LIFE RANGE OF ONE
map[y][x].advanceState();
if (!_dirty && map[y][x].dirty) _dirty = true;
}
}
}