Skip to content

Commit 906e00c

Browse files
committed
Minor optimisation and clean up.
1 parent a41f62a commit 906e00c

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

src/tilemap/TilemapLayerGL.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,14 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
464464
// x/y - is cell location, normalized [0..width/height) in loop
465465
// xmax/ymax - remaining cells to render on column/row
466466
var tx, ty, x, y, xmax, ymax;
467+
var tileset = this._mc.tileset;
467468

468469
for (y = normStartY, ymax = bottom - top, ty = baseY; ymax >= 0; y++, ymax--, ty += th)
469470
{
470471
if (y >= height)
471472
{
472-
y -= height;
473+
// wrap around if coordinates go out of range 0..height
474+
y %= height;
473475
}
474476

475477
var row = this.layer.data[y];
@@ -478,7 +480,8 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
478480
{
479481
if (x >= width)
480482
{
481-
x -= width;
483+
// wrap around if coordinates go out of range 0..width
484+
x %= width;
482485
}
483486

484487
var tile = row[x];
@@ -487,23 +490,23 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
487490
if (!tile || tile.index < this._mc.tileset.firstgid || tile.index > this._mc.lastgid)
488491
{
489492
// skipping some tiles, add a degenerate marker into the batch list
490-
this._mc.tileset.addDegenerate(this.glBatch);
493+
tileset.addDegenerate(this.glBatch);
491494
continue;
492495
}
493496

494497
var index = tile.index;
495498

496-
this._mc.tileset.drawGl(this.glBatch, tx + offx, ty + offy, index, tile.alpha, tile.flippedVal);
499+
tileset.drawGl(this.glBatch, tx + offx, ty + offy, index, tile.alpha, tile.flippedVal);
497500
}
498501

499502
// at end of each row, add a degenerate marker into the batch drawing list
500-
this._mc.tileset.addDegenerate(this.glBatch);
503+
tileset.addDegenerate(this.glBatch);
501504
}
502505

503506
};
504507

505508
/**
506-
* Clear and render the entire canvas.
509+
* Render the entire visible region of the map.
507510
*
508511
* @method Phaser.TilemapLayerGL#renderFull
509512
* @private

src/tilemap/Tileset.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, prope
3939
*/
4040
this.firstgid = firstgid | 0;
4141

42-
/**
43-
* This is the ending index of the last tile index this Tileset can contain.
44-
* This is populated automatically by Phaser.TilemapParser.parseTiledJSON.
45-
* For a single tileset map it should be left as the default value.
46-
* @property {integer} lastgid
47-
*/
48-
this.lastgid = Infinity;
49-
5042
/**
5143
* The width of each tile (in pixels).
5244
* @property {integer} tileWidth
@@ -162,10 +154,10 @@ Phaser.Tileset.prototype = {
162154
},
163155

164156
/**
165-
* Sets the GL Batch data to draw a tile from this Tileset at the given coordinates
166-
* using a WebGL renderer.
157+
* Draws a tile from this Tileset at the given coordinates using a WebGL renderer.
167158
*
168159
* @method Phaser.Tileset#drawGl
160+
* @public
169161
* @param {Array} glBatch - A list of WebGL batch objects to draw later.
170162
* @param {number} x - The x coordinate to draw to.
171163
* @param {number} y - The y coordinate to draw to.
@@ -230,16 +222,16 @@ Phaser.Tileset.prototype = {
230222
},
231223

232224
/**
233-
* Adds a marker for the WebGL batch display to insert a degenerate
234-
* triangle (eg. at the end of each row of tiles)
225+
* Adds a marker for the WebGl batch display to insert a degenerate triangle (eg. at the end of each row of tiles)
235226
*
236227
* @method Phaser.Tileset#addDegenerate
237-
* @param {array} glBatch - The GL Batch data array.
228+
* @public
229+
* @param {[type]} glBatch [description]
238230
*/
239231
addDegenerate: function (glBatch) {
240232

241-
// Don't insert multiple degenerate markers in a row
242-
if (glBatch[glBatch.length - 1])
233+
// don't insert multiple degenerate markers in a row
234+
if (glBatch.length > 0 && glBatch[glBatch.length - 1])
243235
{
244236
glBatch.push(null);
245237
}

0 commit comments

Comments
 (0)