From b16d108e70d99478955f6c18b79022a26f5599ce Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 6 Jul 2018 15:00:01 +0200 Subject: [PATCH] Finally fix TimeStep --- lib/App.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/App.dart b/lib/App.dart index 5c57cc3..69447f8 100644 --- a/lib/App.dart +++ b/lib/App.dart @@ -6,13 +6,12 @@ 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; // Max Frame (i.e. Rendering) rate - does *not* impact game speed - final int _MS_PER_FRAME = 1000; + final int _MS_PER_FRAME = 1000 ~/ 2; // ms stuck in updateloop after which game will declare itself unresponsive final int SAFETY_TIMEOUT = 2000; @@ -27,13 +26,12 @@ class App { App(this.canvas) { this.map = this.grid.map; + _elapsed.start(); } void process(num now) { - _drawLag = now - lastNow; - lastNow = now; - - _updateLag += _drawLag; + _drawLag+= _elapsed.elapsedMilliseconds; + _updateLag += _elapsed.elapsedMilliseconds; _elapsed.reset(); while (_updateLag >= _MS_PER_STEP) { @@ -59,6 +57,7 @@ class App { void render([num interp]) { + print("rendering"); html.CanvasRenderingContext2D ctx = canvas.getContext('2d'); int brickW = (canvas.width ~/ map[0].length); int brickH = (canvas.height ~/ map.length);