fix for reduced resource consumption that backfired on fast devices

This commit is contained in:
Gavin McDonald
2019-02-12 23:38:55 +00:00
parent c65a06a4ae
commit d893e6c003
4 changed files with 3799 additions and 20 deletions

28
package-lock.json generated
View File

@@ -2309,12 +2309,14 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@@ -2329,17 +2331,20 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@@ -2456,7 +2461,8 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@@ -2468,6 +2474,7 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@@ -2482,6 +2489,7 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@@ -2489,12 +2497,14 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@@ -2513,6 +2523,7 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@@ -2593,7 +2604,8 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@@ -2605,6 +2617,7 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@@ -2726,6 +2739,7 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",

File diff suppressed because one or more lines are too long

View File

@@ -3,6 +3,9 @@ import FPS from './fps.js';
const ONE_SECOND = 1000; const ONE_SECOND = 1000;
const PRESS_RIPPLE = ONE_SECOND / 3; const PRESS_RIPPLE = ONE_SECOND / 3;
const INTERACTION_WINDOW = 100;
const IDLE_DRAW_DELAY = 100;
const DEFAULTS = { const DEFAULTS = {
board: Tessellate.BOARD_STYLES.HEX, board: Tessellate.BOARD_STYLES.HEX,
style: Tessellate.DRAW_STYLES.FILL, style: Tessellate.DRAW_STYLES.FILL,
@@ -275,6 +278,7 @@ class Demo {
0, // tiles 0, // tiles
0, // pips 0, // pips
0, // mines 0, // mines
0, // drawDelay
]; ];
Tessellate.Shapes.background(context, height, width, { Tessellate.Shapes.background(context, height, width, {
@@ -303,15 +307,13 @@ class Demo {
Tessellate.TILES[cell.tileStyle][cell.drawStyle](context, scale, pixelPoint.getX(), pixelPoint.getY(), cell); Tessellate.TILES[cell.tileStyle][cell.drawStyle](context, scale, pixelPoint.getX(), pixelPoint.getY(), cell);
}); });
// Tessellate.funky.forEach(this.mines, cell => { const drawDelay = moved || this.ripples.length || (now - interacted) < INTERACTION_WINDOW ? 0 : IDLE_DRAW_DELAY;
// this.counts[2] += 1;
// const pixelPoint = this.tessellate.tileToPixel(cell); this.counts[3] = drawDelay;
// Tessellate.Shapes.mine(context, scale, pixelPoint.getX(), pixelPoint.getY());
// });
this.fps.frame(now, lastNow, this.counts); this.fps.frame(now, lastNow, this.counts);
return interacted || moved || this.ripples.length ? 0 : 100; return drawDelay;
} }
} }

View File

@@ -93,6 +93,8 @@ export class Tessellate {
'remap', 'remap',
].map(method => {this[method] = this[method].bind(this)}); ].map(method => {this[method] = this[method].bind(this)});
this.interacted = Date.now();
this.checkSettings(settings); this.checkSettings(settings);
this.sketch = new Sketch({ this.sketch = new Sketch({
@@ -152,7 +154,7 @@ export class Tessellate {
const tile = this.cartographer.pixelToTile(point); const tile = this.cartographer.pixelToTile(point);
const mapTile = this.cartographer.teleport(tile); const mapTile = this.cartographer.teleport(tile);
this.interacted = true; this.interacted = Date.now();
this.settings.tap({ this.settings.tap({
event, event,
@@ -169,6 +171,7 @@ export class Tessellate {
const mapTile = this.cartographer.teleport(tile); const mapTile = this.cartographer.teleport(tile);
this.interacted = true; this.interacted = true;
this.interacted = Date.now();
let tap = { let tap = {
event, event,
@@ -187,6 +190,7 @@ export class Tessellate {
const mapTile = this.cartographer.teleport(tile); const mapTile = this.cartographer.teleport(tile);
this.interacted = true; this.interacted = true;
this.interacted = Date.now();
this.settings.pressStart({ this.settings.pressStart({
event, event,
@@ -202,6 +206,7 @@ export class Tessellate {
const mapTile = this.cartographer.teleport(tile); const mapTile = this.cartographer.teleport(tile);
this.interacted = true; this.interacted = true;
this.interacted = Date.now();
this.settings.press({ this.settings.press({
event, event,
@@ -212,10 +217,12 @@ export class Tessellate {
} }
move (event) { move (event) {
this.interacted = Date.now();
return this.cartographer.move(event); return this.cartographer.move(event);
} }
zoom (event) { zoom (event) {
this.interacted = Date.now();
this.cartographer.zoom(event); this.cartographer.zoom(event);
} }
@@ -231,9 +238,9 @@ export class Tessellate {
this.lastLocation = this.lastLocation || {}; this.lastLocation = this.lastLocation || {};
const currentLocation = utils.extend({ const currentLocation = utils.extend({
scale: this.cartographer.getScale(),
originX: this.cartographer.getOriginX(), originX: this.cartographer.getOriginX(),
originY: this.cartographer.getOriginY(), originY: this.cartographer.getOriginY(),
scaleOrig: this.cartographer.getScale(),
}, corners); }, corners);
const changed = funky.reduce(currentLocation, (same, val, key) => same || this.lastLocation[key] !== val, false); const changed = funky.reduce(currentLocation, (same, val, key) => same || this.lastLocation[key] !== val, false);
@@ -266,9 +273,6 @@ export class Tessellate {
lowerRightY: height lowerRightY: height
}; };
const interacted = this.interacted;
this.interacted = false;
const moved = this.newLocation(corners); const moved = this.newLocation(corners);
this.locationSets = moved ? this.getLocationSets(corners) : this.locationSets; this.locationSets = moved ? this.getLocationSets(corners) : this.locationSets;
@@ -281,8 +285,8 @@ export class Tessellate {
lastNow: context.lastUTC, lastNow: context.lastUTC,
now: context.utc, now: context.utc,
interacted,
moved, moved,
interacted: this.interacted,
locationSets: this.locationSets, locationSets: this.locationSets,
}); });
} }