Finally fix TimeStep

This commit is contained in:
Marty Oehme 2018-07-06 15:00:01 +02:00
parent 12792a7897
commit b16d108e70
1 changed files with 5 additions and 6 deletions

View File

@ -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);