Make Simulation dirty-flag public
This commit is contained in:
parent
1f435617da
commit
66c273c783
1 changed files with 9 additions and 10 deletions
|
@ -14,8 +14,7 @@ class Simulation {
|
||||||
|
|
||||||
RuleSet rules = GameOfLife();
|
RuleSet rules = GameOfLife();
|
||||||
|
|
||||||
bool _dirty = true;
|
bool dirty = true;
|
||||||
bool get dirty => _dirty;
|
|
||||||
|
|
||||||
bool _renderEdges = true;
|
bool _renderEdges = true;
|
||||||
bool get renderEdges => _renderEdges;
|
bool get renderEdges => _renderEdges;
|
||||||
|
@ -38,8 +37,8 @@ class Simulation {
|
||||||
|
|
||||||
Grid<bool> reset([Grid<bool> map]) {
|
Grid<bool> reset([Grid<bool> map]) {
|
||||||
map ??= this.map;
|
map ??= this.map;
|
||||||
_dirty = true;
|
// dirty = true;
|
||||||
map.setAll(0, List.filled(map.length, false));
|
// map.setAll(0, List.filled(map.length, false));
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ class Simulation {
|
||||||
if (sanityCheck > 100 && sanityCheck > i * 3) break;
|
if (sanityCheck > 100 && sanityCheck > i * 3) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCellState(int x, int y, bool state) {
|
void setCellState(int x, int y, bool state) {
|
||||||
|
@ -91,7 +90,7 @@ class Simulation {
|
||||||
|
|
||||||
void mergeStateChanges(Map<int, bool> stateChanges) {
|
void mergeStateChanges(Map<int, bool> stateChanges) {
|
||||||
stateChanges.forEach((i, el) => map[i] = el);
|
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) {
|
Map<int, bool> calculateNextState(Grid<bool> oldState) {
|
||||||
|
@ -127,7 +126,7 @@ class Simulation {
|
||||||
|
|
||||||
void render(html.CanvasElement canvas, [num interp]) {
|
void render(html.CanvasElement canvas, [num interp]) {
|
||||||
// only renders if any cells changed between renders
|
// only renders if any cells changed between renders
|
||||||
if (!_dirty) return;
|
if (!dirty) return;
|
||||||
|
|
||||||
html.CanvasRenderingContext2D ctx = canvas.getContext('2d');
|
html.CanvasRenderingContext2D ctx = canvas.getContext('2d');
|
||||||
int brickW = (canvas.width ~/ map.width);
|
int brickW = (canvas.width ~/ map.width);
|
||||||
|
@ -146,18 +145,18 @@ class Simulation {
|
||||||
ctx.setFillColorRgb(0, 0, 0);
|
ctx.setFillColorRgb(0, 0, 0);
|
||||||
ctx.fillRect(p.x * brickW, p.y * brickH, brickW, brickH);
|
ctx.fillRect(p.x * brickW, p.y * brickH, brickW, brickH);
|
||||||
}
|
}
|
||||||
_dirty = false;
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set renderEdges(bool on) {
|
void set renderEdges(bool on) {
|
||||||
_renderEdges = on;
|
_renderEdges = on;
|
||||||
_dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveSnapshot() => _snapshot = Grid.from(map);
|
void saveSnapshot() => _snapshot = Grid.from(map);
|
||||||
Grid<bool> loadSnapshot() {
|
Grid<bool> loadSnapshot() {
|
||||||
map = Grid.from(_snapshot);
|
map = Grid.from(_snapshot);
|
||||||
_dirty = true;
|
dirty = true;
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue