Move Simulation Accesses to Simulation Class
Everything has been refactored away from engine, which now only controls updating & rendering within a specific timestep. (As well as stepping forward by calling a single update) Everything regarding grids, patterns and cells has been moved into the simulation and the Services have been updated to reflect that.
This commit is contained in:
parent
32a3676d95
commit
8db9cd6ff1
5 changed files with 33 additions and 63 deletions
|
|
@ -2,35 +2,42 @@ import 'dart:html' as html;
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:rules_of_living/service/engine_service.dart';
|
||||
import 'package:rules_of_living/src/Simulation.dart';
|
||||
|
||||
class SimulationService {
|
||||
final EngineService _engine;
|
||||
// DEFAULT VALUES
|
||||
static final int DEFAULT_GRID_SIZE = 50;
|
||||
|
||||
SimulationService(this._engine);
|
||||
final EngineService _engine;
|
||||
final Simulation _sim = Simulation(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE);
|
||||
|
||||
SimulationService(this._engine) {
|
||||
_engine.simulation = _sim;
|
||||
_sim.addRandomPattern(amount: 15, dispersal: 5);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_engine.reset();
|
||||
_sim.reset();
|
||||
}
|
||||
|
||||
void addRandomPattern() {
|
||||
_engine.addRandomPattern();
|
||||
_sim.addRandomPattern();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_engine.clear();
|
||||
_sim.reset();
|
||||
}
|
||||
|
||||
Point<int> get gridSize => _sim.gridSize;
|
||||
void set gridSize(Point<int> size) {
|
||||
_engine.engine.gridSize = size;
|
||||
_sim.gridSize = size;
|
||||
}
|
||||
|
||||
Point<int> get gridSize => _engine.engine.gridSize;
|
||||
|
||||
//TODO split into RenderService when rendering is decoupled from engine.
|
||||
html.CanvasElement get canvas => _engine.engine.canvas;
|
||||
void set canvas(html.CanvasElement canvas) => _engine.engine.canvas = canvas;
|
||||
|
||||
void toggleGrid() {
|
||||
_engine.engine.toggleEdgeRendering();
|
||||
_sim.renderEdges = !_sim.renderEdges;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue