Finally fix TimeStep
This commit is contained in:
parent
12792a7897
commit
b16d108e70
1 changed files with 5 additions and 6 deletions
11
lib/App.dart
11
lib/App.dart
|
@ -6,13 +6,12 @@ import 'package:rules_of_living/Grid.dart';
|
||||||
class App {
|
class App {
|
||||||
// Elapsed Time Counter - useful for Safety Timeout
|
// Elapsed Time Counter - useful for Safety Timeout
|
||||||
Stopwatch _elapsed = new Stopwatch();
|
Stopwatch _elapsed = new Stopwatch();
|
||||||
num lastNow = 0;
|
|
||||||
|
|
||||||
// Game Tick Rate - *does* impact game speed
|
// Game Tick Rate - *does* impact game speed
|
||||||
final int _MS_PER_STEP = 1000;
|
final int _MS_PER_STEP = 1000;
|
||||||
|
|
||||||
// Max Frame (i.e. Rendering) rate - does *not* impact game speed
|
// 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
|
// ms stuck in updateloop after which game will declare itself unresponsive
|
||||||
final int SAFETY_TIMEOUT = 2000;
|
final int SAFETY_TIMEOUT = 2000;
|
||||||
|
@ -27,13 +26,12 @@ class App {
|
||||||
|
|
||||||
App(this.canvas) {
|
App(this.canvas) {
|
||||||
this.map = this.grid.map;
|
this.map = this.grid.map;
|
||||||
|
_elapsed.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void process(num now) {
|
void process(num now) {
|
||||||
_drawLag = now - lastNow;
|
_drawLag+= _elapsed.elapsedMilliseconds;
|
||||||
lastNow = now;
|
_updateLag += _elapsed.elapsedMilliseconds;
|
||||||
|
|
||||||
_updateLag += _drawLag;
|
|
||||||
_elapsed.reset();
|
_elapsed.reset();
|
||||||
|
|
||||||
while (_updateLag >= _MS_PER_STEP) {
|
while (_updateLag >= _MS_PER_STEP) {
|
||||||
|
@ -59,6 +57,7 @@ class App {
|
||||||
|
|
||||||
|
|
||||||
void render([num interp]) {
|
void render([num interp]) {
|
||||||
|
print("rendering");
|
||||||
html.CanvasRenderingContext2D ctx = canvas.getContext('2d');
|
html.CanvasRenderingContext2D ctx = canvas.getContext('2d');
|
||||||
int brickW = (canvas.width ~/ map[0].length);
|
int brickW = (canvas.width ~/ map[0].length);
|
||||||
int brickH = (canvas.height ~/ map.length);
|
int brickH = (canvas.height ~/ map.length);
|
||||||
|
|
Loading…
Reference in a new issue