Make Simulation dirty-flag public

This commit is contained in:
Unknown 2018-10-21 13:55:15 +02:00
parent 1f435617da
commit 66c273c783
1 changed files with 9 additions and 10 deletions

View File

@ -14,8 +14,7 @@ class Simulation {
RuleSet rules = GameOfLife();
bool _dirty = true;
bool get dirty => _dirty;
bool dirty = true;
bool _renderEdges = true;
bool get renderEdges => _renderEdges;
@ -38,8 +37,8 @@ class Simulation {
Grid<bool> reset([Grid<bool> map]) {
map ??= this.map;
_dirty = true;
map.setAll(0, List.filled(map.length, false));
// dirty = true;
// map.setAll(0, List.filled(map.length, false));
return map;
}
@ -61,7 +60,7 @@ class Simulation {
if (sanityCheck > 100 && sanityCheck > i * 3) break;
}
_dirty = true;
dirty = true;
}
void setCellState(int x, int y, bool state) {
@ -91,7 +90,7 @@ class Simulation {
void mergeStateChanges(Map<int, bool> stateChanges) {
stateChanges.forEach((i, el) => map[i] = el);
if (stateChanges.length != 0) _dirty = true;
if (stateChanges.length != 0) dirty = true;
}
Map<int, bool> calculateNextState(Grid<bool> oldState) {
@ -127,7 +126,7 @@ class Simulation {
void render(html.CanvasElement canvas, [num interp]) {
// only renders if any cells changed between renders
if (!_dirty) return;
if (!dirty) return;
html.CanvasRenderingContext2D ctx = canvas.getContext('2d');
int brickW = (canvas.width ~/ map.width);
@ -146,18 +145,18 @@ class Simulation {
ctx.setFillColorRgb(0, 0, 0);
ctx.fillRect(p.x * brickW, p.y * brickH, brickW, brickH);
}
_dirty = false;
dirty = false;
}
void set renderEdges(bool on) {
_renderEdges = on;
_dirty = true;
dirty = true;
}
void saveSnapshot() => _snapshot = Grid.from(map);
Grid<bool> loadSnapshot() {
map = Grid.from(_snapshot);
_dirty = true;
dirty = true;
return map;
}
}