diff --git a/lib/App.dart b/lib/App.dart index 1705823..1c88062 100644 --- a/lib/App.dart +++ b/lib/App.dart @@ -6,15 +6,16 @@ import 'package:rules_of_living/Grid.dart'; class App { // Elapsed Time Counter - useful for Safety Timeout Stopwatch _elapsed = new Stopwatch(); + num lastNow = 0; // Game Tick Rate - *does* impact game speed - final int _MS_PER_STEP = 1000 ~/ 1; + final int _MS_PER_STEP = 1000; // Max Frame (i.e. Rendering) rate - does *not* impact game speed - final int _MS_PER_FRAME = 1000 ~/ 1; + final int _MS_PER_FRAME = 1000; // ms stuck in updateloop after which game will declare itself unresponsive - final int SAFETY_TIMEOUT = 1000; + final int SAFETY_TIMEOUT = 2000; num _updateLag = 0.0; num _drawLag = 0.0; @@ -22,18 +23,24 @@ class App { final html.CanvasElement canvas; final Grid grid = new Grid(20,20); - final List> map = new Grid(20, 20).map; + List> map; - App(this.canvas); + App(this.canvas) { + this.map = this.grid.map; + } void process(num now) { - _drawLag = now; + _drawLag = now - lastNow; + print(_drawLag); + lastNow = now; + _updateLag += _drawLag; _elapsed.reset(); while (_updateLag >= _MS_PER_STEP) { if (_elapsed.elapsedMilliseconds > SAFETY_TIMEOUT) { // TODO stub - give warning etc when this occurs + print("ERROR STUCK IN UPDATE LOOP"); break; } update(); @@ -47,6 +54,7 @@ class App { } void update() { + print("updating"); grid.update(); }