Rename Simulation in Engine Object

This commit is contained in:
Unknown 2018-10-18 09:59:26 +02:00
parent bac65ef116
commit e16085153a

View file

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