make canvas argument optional on instantiating engine

This commit is contained in:
Marty Oehme 2018-08-24 20:02:43 +02:00
parent 8d7575eaf7
commit 6c9179b833
2 changed files with 19 additions and 4 deletions

View file

@ -6,7 +6,7 @@ class Engine {
// Elapsed Time Counter - useful for Safety Timeout // Elapsed Time Counter - useful for Safety Timeout
Stopwatch _elapsed = new Stopwatch(); Stopwatch _elapsed = new Stopwatch();
// Game Tick Rate - *does* impact game speed // Game Tick Rate - *does* impact game speed TODO add configurable option
int _MS_PER_STEP = 1000 ~/ 3; int _MS_PER_STEP = 1000 ~/ 3;
// Max Frame (i.e. Rendering) rate - does *not* impact game speed // Max Frame (i.e. Rendering) rate - does *not* impact game speed
@ -15,14 +15,18 @@ class Engine {
// 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;
// Grid Size TODO add as configurable option
static final GRID_X = 100;
static final GRID_Y = 100;
num _updateLag = 0.0; num _updateLag = 0.0;
num _drawLag = 0.0; num _drawLag = 0.0;
final html.CanvasElement canvas; final html.CanvasElement canvas;
Grid _grid = new Grid(100, 100); Grid _grid = new Grid(GRID_X, GRID_Y);
bool _running = false; bool _running = false;
Engine(this.canvas) { Engine([this.canvas]) {
_elapsed.start(); _elapsed.start();
_grid.addPattern(amount: 15, dispersal: 5); _grid.addPattern(amount: 15, dispersal: 5);
} }
@ -59,7 +63,6 @@ class Engine {
} }
void update() { void update() {
// print("updating");
if (!_grid.update()) running = false; if (!_grid.update()) running = false;
} }

12
test/src/engine_test.dart Normal file
View file

@ -0,0 +1,12 @@
@TestOn('browser')
import 'dart:html';
import 'package:rules_of_living/src/Engine.dart';
import 'package:test/test.dart';
void main() {
test("Engine can be instantiated without canvas", () {
expect(Engine(), isNot(throwsA(anything)));
});
}