Preliminary Move of Renderr
NON-WORKING STATE. interim commit.
This commit is contained in:
parent
d79aceeebf
commit
d80e149dbc
3 changed files with 53 additions and 46 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:html' as html;
|
||||
|
||||
import 'package:rules_of_living/src/Renderer.dart';
|
||||
import 'package:rules_of_living/src/Simulation.dart';
|
||||
|
||||
class Engine {
|
||||
|
|
@ -37,7 +38,12 @@ class Engine {
|
|||
/// be used if no canvas was defined at engine creation and it should be
|
||||
/// rendered later.
|
||||
html.CanvasElement canvas;
|
||||
|
||||
Simulation _simulation;
|
||||
Map<int, bool> _lastSimulationUpdate = {};
|
||||
|
||||
Renderer _renderer;
|
||||
|
||||
bool running = false;
|
||||
|
||||
Engine() {
|
||||
|
|
@ -70,6 +76,7 @@ class Engine {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO Should be renamed to something more intention revealing like hasReachedUpdateTimestepThreshold
|
||||
bool _shouldUpdate(int updateLag, int elapsed, int timeOut) {
|
||||
if (updateLag < _MS_PER_STEP) return false;
|
||||
if (elapsed > timeOut) throw StackOverflowError;
|
||||
|
|
@ -85,10 +92,10 @@ class Engine {
|
|||
void update() {
|
||||
if (_simulation == null) return;
|
||||
|
||||
Map<int, bool> simulationUpdate = _simulation.update();
|
||||
_simulation.mergeStateChanges(simulationUpdate);
|
||||
_lastSimulationUpdate = _simulation.update();
|
||||
_simulation.mergeStateChanges(_lastSimulationUpdate);
|
||||
|
||||
if (simulationUpdate.length == 0) running = false;
|
||||
if (_lastSimulationUpdate.length == 0) running = false;
|
||||
}
|
||||
|
||||
/// Advances Logic One Update
|
||||
|
|
@ -107,9 +114,9 @@ class Engine {
|
|||
/// the internal engine processing. Does not do anything if no canvas is
|
||||
/// defined.
|
||||
void render([num interp]) {
|
||||
if (canvas == null || _simulation == null) return;
|
||||
if (canvas == null || _renderer == null) return;
|
||||
|
||||
_simulation.render(canvas, interp);
|
||||
_renderer.render(canvas, _lastSimulationUpdate);
|
||||
}
|
||||
|
||||
void set simulation(Simulation value) => _simulation = value;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue