Skip to content

Commit 5f6ea15

Browse files
committed
Clean-up and comments.
1 parent 263238b commit 5f6ea15

1 file changed

Lines changed: 20 additions & 49 deletions

File tree

src/pixi/extras/Tilemap.js

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ PIXI.Tilemap = function(texture, mapwidth, mapheight, tilewidth, tileheight, lay
2323
this.mapWide = mapwidth;
2424
this.mapHigh = mapheight;
2525

26-
// precalculate the width of the source texture in entire tile units
27-
this.texTilesWide = Math.ceil(this.texture.width / this.tileWide);
28-
this.texTilesHigh = Math.ceil(this.texture.height / this.tileHigh);
29-
3026
// TODO: switch here to create DisplayObjectContainer at correct size for the render mode
3127
this.width = this.mapWide * this.tileWide;
3228
this.height = this.mapHigh * this.tileHigh;
@@ -60,18 +56,29 @@ PIXI.Tilemap = function(texture, mapwidth, mapheight, tilewidth, tileheight, lay
6056
*/
6157
this.blendMode = PIXI.blendModes.NORMAL;
6258

63-
// calculate size of map
64-
var mapSize = mapwidth * mapheight * 16;
59+
/**
60+
* The size of a single data element in the batch drawing.
61+
* Each tile requires two triangles, each specified as:
62+
* float left, bottom, right, top - screen coordinates
63+
* float u, v, wide, high - source texture coordinates
64+
*
65+
* @type {Number}
66+
*/
67+
this.batchDataElement = 16;
68+
69+
// calculate total batch data size
70+
var dataSize = mapwidth * mapheight * this.batchDataElement;
6571

6672
// create buffer data for the webgl rendering of this tile
67-
this.buffer = new PIXI.Float32Array( mapSize );
73+
this.buffer = new PIXI.Float32Array( dataSize );
6874
};
6975

7076

71-
// constructor
77+
// constructor, this class extends PIXI.DisplayObjectContainer
7278
PIXI.Tilemap.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
7379
PIXI.Tilemap.prototype.constructor = PIXI.Tilemap;
7480

81+
// unused methods overridden to prevent default behaviour
7582
PIXI.Tilemap.prototype.update = function() {};
7683
PIXI.Tilemap.prototype.postUpdate = function() {};
7784

@@ -85,6 +92,7 @@ PIXI.Tilemap.prototype._renderWebGL = function(renderSession)
8592
return;
8693
}
8794

95+
// stop current render session batch drawing
8896
renderSession.spriteBatch.stop();
8997

9098
if (!this._vertexBuffer)
@@ -96,6 +104,7 @@ PIXI.Tilemap.prototype._renderWebGL = function(renderSession)
96104

97105
this._renderWholeTilemap(renderSession);
98106

107+
// restart batch drawing now that this Tile layer has been rendered
99108
renderSession.spriteBatch.start();
100109
};
101110

@@ -118,44 +127,6 @@ PIXI.Tilemap.prototype._initWebGL = function(renderSession)
118127
};
119128

120129

121-
PIXI.Tilemap.prototype.makeProjection = function(_width, _height)
122-
{
123-
// project coordinates into a 2x2 number range, starting at (-1, 1)
124-
var m = new PIXI.Float32Array(9);
125-
m[0] = 2 / _width;
126-
m[1] = 0;
127-
m[2] = 0;
128-
129-
m[3] = 0;
130-
m[4] = -2 / _height;
131-
m[5] = 0;
132-
133-
m[6] = -1;
134-
m[7] = 1;
135-
m[8] = 1;
136-
return m;
137-
};
138-
139-
140-
/*
141-
PIXI.Tilemap.prototype.makeTransform = function(_x, _y, _angleInRadians, _scaleX, _scaleY)
142-
{
143-
var c = Math.cos( _angleInRadians );
144-
var s = Math.sin( _angleInRadians );
145-
var m = new Float32Array(9);
146-
m[0] = c * _scaleX;
147-
m[1] = -s * _scaleY;
148-
m[2] = 0;
149-
m[3] = s * _scaleX;
150-
m[4] = c * _scaleY;
151-
m[5] = 0;
152-
m[6] = _x;
153-
m[7] = _y;
154-
m[8] = 1;
155-
return m;
156-
};
157-
*/
158-
159130
PIXI.Tilemap.prototype._renderBatch = function( renderSession )
160131
{
161132
if ( this.glBatch )
@@ -203,6 +174,7 @@ PIXI.Tilemap.prototype._renderBatch = function( renderSession )
203174
{
204175
// insert a degenerate triangle when null is found in the list of batch objects
205176
degenerate = true;
177+
// skip to end of loop, degenerate will be inserted when no more null objects are found
206178
continue;
207179
}
208180

@@ -228,7 +200,7 @@ PIXI.Tilemap.prototype._renderBatch = function( renderSession )
228200
buffer[ c + 2 ] = buffer[ c + 6 ] = uvl;
229201
buffer[ c + 3 ] = buffer[ c + 7 ] = uvt;
230202

231-
// advance the buffer index
203+
// advance the buffer index for one single degenerate triangle
232204
c += 8;
233205
degenerate = false;
234206
}
@@ -249,6 +221,7 @@ PIXI.Tilemap.prototype._renderBatch = function( renderSession )
249221
c += 16;
250222
}
251223

224+
// if there's anything to draw...
252225
if ( c > 0 )
253226
{
254227
var shader = renderSession.shaderManager.tilemapShader;
@@ -265,8 +238,6 @@ PIXI.Tilemap.prototype._renderBatch = function( renderSession )
265238
}
266239
};
267240

268-
// gl.uniformMatrix3fv( shader.uProjectionMatrix, false, this.makeProjection(this.game.width, this.game.height) );
269-
// gl.uniform1i( shader.uImageSampler, 0 );
270241

271242
/**
272243
* render the entire tilemap using a fast webgl batched tile render

0 commit comments

Comments
 (0)