Rename Simulation in Engine Object
This commit is contained in:
parent
bac65ef116
commit
e16085153a
1 changed files with 14 additions and 12 deletions
|
@ -32,11 +32,11 @@ class Engine {
|
|||
/// Grid Size
|
||||
///
|
||||
/// Number of cells on x coordinate and y coordinate. Can be set individually.
|
||||
Point get gridSize => Point<int>(_grid.w, _grid.h);
|
||||
Point get gridSize => Point<int>(_simulation.w, _simulation.h);
|
||||
void set gridSize(Point<int> value) {
|
||||
if (value.x <= 0 || value.y <= 0)
|
||||
throw ArgumentError("grid size must not be smaller than 1");
|
||||
_grid = Simulation(value.x, value.y);
|
||||
_simulation = Simulation(value.x, value.y);
|
||||
}
|
||||
|
||||
num _updateLag = 0.0;
|
||||
|
@ -48,14 +48,14 @@ class Engine {
|
|||
/// be used if no canvas was defined at engine creation and it should be
|
||||
/// rendered later.
|
||||
html.CanvasElement canvas;
|
||||
Simulation _grid;
|
||||
Simulation _simulation;
|
||||
bool running = false;
|
||||
|
||||
Engine([x = 100, y = 100, this.canvas]) {
|
||||
_grid = Simulation(x, y);
|
||||
_simulation = Simulation(x, y);
|
||||
|
||||
_elapsed.start();
|
||||
_grid.addPattern(amount: 15, dispersal: 5);
|
||||
_simulation.addPattern(amount: 15, dispersal: 5);
|
||||
html.window.animationFrame.then(animFrame);
|
||||
}
|
||||
|
||||
|
@ -65,12 +65,12 @@ class Engine {
|
|||
}
|
||||
|
||||
void reset() {
|
||||
_grid.reset();
|
||||
_simulation.reset();
|
||||
running = false;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_grid = new Simulation(gridSize.x, gridSize.y);
|
||||
_simulation = new Simulation(gridSize.x, gridSize.y);
|
||||
running = false;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ class Engine {
|
|||
/// If simulation should be advanced manually one time, prefer using step().
|
||||
void update() {
|
||||
// TODO: create hasUpdated/hasAdvanced method in simulation to abstract actual updating away
|
||||
if (_grid.update().length == 0) running = false;
|
||||
if (_simulation.update().length == 0) running = false;
|
||||
}
|
||||
|
||||
/// Advances Logic One Update
|
||||
|
@ -112,7 +112,7 @@ class Engine {
|
|||
/// (though this should usually not pose a problem).
|
||||
void step() {
|
||||
running = false;
|
||||
_grid.update();
|
||||
_simulation.update();
|
||||
}
|
||||
|
||||
/// Renders the Current Simulation State
|
||||
|
@ -121,14 +121,16 @@ class Engine {
|
|||
/// the internal engine processing. Does not do anything if no canvas is
|
||||
/// defined.
|
||||
void render([num interp]) {
|
||||
if (canvas != null) _grid.render(canvas, interp);
|
||||
if (canvas == null) return;
|
||||
|
||||
_simulation.render(canvas, interp);
|
||||
}
|
||||
|
||||
void addPattern({int amount, int dispersal}) {
|
||||
_grid.addPattern(amount: amount, dispersal: dispersal);
|
||||
_simulation.addPattern(amount: amount, dispersal: dispersal);
|
||||
}
|
||||
|
||||
void toggleEdgeRendering() {
|
||||
_grid.renderEdges = !_grid.renderEdges;
|
||||
_simulation.renderEdges = !_simulation.renderEdges;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue