optimises march with bounds wip

This commit is contained in:
Francisco Dans 2015-10-06 16:55:29 +02:00
parent b3e504f672
commit 740f219157

View File

@ -16,6 +16,7 @@ function IsoRenderer (canvas, options) {
this.TILE_SIZE = 256; this.TILE_SIZE = 256;
this.contourValues = [1,2,4,8,10,16,32]; this.contourValues = [1,2,4,8,10,16,32];
this.lines = []; this.lines = [];
this.bounds = {n: 10000, s: 0, e: 0, w: 100000};
} }
torque.extend(IsoRenderer.prototype, torque.Event, { 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) { _renderTile: function(tile, key, frame_offset, sprites, shader, pos) {
if (!this._canvas) return; if (!this._canvas) return;
var ctx = this._ctx; if (tile.x.length > 0) {
this._gridData(tile); this._gridData(tile);
}
}, },
_gridData: function(tile){ _gridData: function(tile){
@ -95,6 +97,10 @@ torque.extend(IsoRenderer.prototype, torque.Event, {
var x = tile.x[i], y = tile.y[i]; 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]; 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){ _getPipe: function(cell, contour){
@ -536,9 +542,14 @@ torque.extend(IsoRenderer.prototype, torque.Event, {
for (var c = 0; c < contourValues.length; c++) { for (var c = 0; c < contourValues.length; c++) {
this.lines[c] = []; this.lines[c] = [];
var pointsTraveled = new Set(); 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 line = [];
var xy = march(0,0); var xy = march(pointerX, pointerY);
while(xy){ while(xy){
xy = march(xy.x, xy.y); xy = march(xy.x, xy.y);