From 740f2191578dc380f68342e89396b1bc89ffd9ee Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Tue, 6 Oct 2015 16:55:29 +0200 Subject: [PATCH] optimises march with bounds wip --- lib/torque/renderer/iso.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/torque/renderer/iso.js b/lib/torque/renderer/iso.js index c0ddb37..0e19927 100644 --- a/lib/torque/renderer/iso.js +++ b/lib/torque/renderer/iso.js @@ -16,6 +16,7 @@ function IsoRenderer (canvas, options) { this.TILE_SIZE = 256; this.contourValues = [1,2,4,8,10,16,32]; this.lines = []; + this.bounds = {n: 10000, s: 0, e: 0, w: 100000}; } torque.extend(IsoRenderer.prototype, torque.Event, { @@ -76,8 +77,9 @@ torque.extend(IsoRenderer.prototype, torque.Event, { _renderTile: function(tile, key, frame_offset, sprites, shader, pos) { if (!this._canvas) return; - var ctx = this._ctx; - this._gridData(tile); + if (tile.x.length > 0) { + this._gridData(tile); + } }, _gridData: function(tile){ @@ -95,6 +97,10 @@ torque.extend(IsoRenderer.prototype, torque.Event, { var x = tile.x[i], y = tile.y[i]; this.globalGrid[baseIndex.y + (256 - y) / this.options.resolution -1][baseIndex.x + x/this.options.resolution] = tile.renderData[i]; } + if (tile.x < this.bounds.w) this.bounds.w = tile.x; + else if (tile.x > this.bounds.e) this.bounds.e = tile.x; + if (tile.y < this.bounds.n) this.bounds.n = tile.y; + else if (tile.y > this.bounds.s) this.bounds.s = tile.y; }, _getPipe: function(cell, contour){ @@ -536,9 +542,14 @@ torque.extend(IsoRenderer.prototype, torque.Event, { for (var c = 0; c < contourValues.length; c++) { this.lines[c] = []; var pointsTraveled = new Set(); - var pointerX = 0, pointerY = 0, x = 0, y = 0; + var pointerX = this.bounds.w, + pointerY = this.bounds.n, + x = 0, + y = 0, + limitX = this.bounds.e, + limitY = this.bounds.s; var line = []; - var xy = march(0,0); + var xy = march(pointerX, pointerY); while(xy){ xy = march(xy.x, xy.y);