Skip to content

Commit ec5bd19

Browse files
committed
GameObject.willRender now takes a Camera as its only argument and uses it within the check. This has allowed me to remove 23 duplicate checks spread across the various Game Objects, all of which did the same thing, saving both KB and CPU time as the flags were being checked twice in most cases.
1 parent 1d697b1 commit ec5bd19

27 files changed

Lines changed: 57 additions & 99 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* `Camera.x` and `Camera.y` have been turned into getters / setters, mapped to the internal private values `_x` and `_y` respectively. This is so that setting the Camera viewport position directly will now update the new internal resolution calculation vars too.
1414
* `Camera.setScene` will now set the Cameras `resolution` property at the same time and update the internal viewport vars.
1515
* The `Cull Tiles` method used by the Dynamic Tilemap Layer has had a nice and significant optimization. It will now use the cull area dimensions to restrict the amount of tile iteration that takes place per layer, resulting in dramatic reductions in processing time on large layers, or multiple layers (thanks @tarsupin)
16+
* `GameObject.willRender` now takes a Camera as its only argument and uses it within the check. This has allowed me to remove 23 duplicate checks spread across the various Game Objects, all of which did the same thing, saving both KB and CPU time as the flags were being checked twice in most cases.
1617

1718
### Game Config Resolution Specific Bug Fixes
1819

src/gameobjects/GameObject.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,18 @@ var GameObject = new Class({
436436

437437
/**
438438
* Compares the renderMask with the renderFlags to see if this Game Object will render or not.
439+
* Also checks the Game Object against the given Cameras exclusion list.
439440
*
440441
* @method Phaser.GameObjects.GameObject#willRender
441442
* @since 3.0.0
443+
*
444+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to check against this Game Object.
442445
*
443446
* @return {boolean} True if the Game Object should be rendered, otherwise false.
444447
*/
445-
willRender: function ()
448+
willRender: function (camera)
446449
{
447-
return (GameObject.RENDER_MASK === this.renderFlags);
450+
return !(GameObject.RENDER_MASK !== this.renderFlags || (this.cameraFilter > 0 && (this.cameraFilter & camera.id)));
448451
},
449452

450453
/**

src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCanvasRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
2626
var text = src.text;
2727
var textLength = text.length;
2828

29-
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
29+
if (textLength === 0)
3030
{
3131
return;
3232
}

src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextWebGLRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, src, interpolationPerce
2727
var text = src.text;
2828
var textLength = text.length;
2929

30-
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
30+
if (textLength === 0)
3131
{
3232
return;
3333
}

src/gameobjects/bitmaptext/static/BitmapTextCanvasRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
2626
var text = src._text;
2727
var textLength = text.length;
2828

29-
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
29+
if (textLength === 0)
3030
{
3131
return;
3232
}

src/gameobjects/bitmaptext/static/BitmapTextWebGLRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
2727
var text = src._text;
2828
var textLength = text.length;
2929

30-
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
30+
if (textLength === 0)
3131
{
3232
return;
3333
}

src/gameobjects/blitter/BlitterCanvasRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var BlitterCanvasRenderer = function (renderer, src, interpolationPercentage, ca
2525
{
2626
var list = src.getRenderList();
2727

28-
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)) || list.length === 0)
28+
if (list.length === 0)
2929
{
3030
return;
3131
}

src/gameobjects/blitter/BlitterWebGLRenderer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ var Utils = require('../../renderer/webgl/Utils');
2424
*/
2525
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
2626
{
27-
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
27+
var list = src.getRenderList();
28+
29+
if (list.length === 0)
2830
{
2931
return;
3032
}
@@ -48,7 +50,6 @@ var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, cam
4850
cameraScrollY = 0;
4951
}
5052

51-
var list = src.getRenderList();
5253
var blitterX = src.x - cameraScrollX;
5354
var blitterY = src.y - cameraScrollY;
5455
var prevTextureSourceIndex = -1;

src/gameobjects/container/ContainerCanvasRenderer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ var GameObject = require('../GameObject');
2424
*/
2525
var ContainerCanvasRenderer = function (renderer, container, interpolationPercentage, camera, parentMatrix)
2626
{
27-
if (GameObject.RENDER_MASK !== container.renderFlags || (container.cameraFilter > 0 && (container.cameraFilter & camera._id)))
27+
var children = container.list;
28+
29+
if (children.length === 0)
2830
{
2931
return;
3032
}
3133

32-
var children = container.list;
3334
var transformMatrix = container.localTransform;
3435

3536
if (parentMatrix === undefined)
@@ -49,9 +50,9 @@ var ContainerCanvasRenderer = function (renderer, container, interpolationPercen
4950
var scrollFactorX = container.scrollFactorX;
5051
var scrollFactorY = container.scrollFactorY;
5152

52-
for (var index = 0; index < children.length; ++index)
53+
for (var i = 0; i < children.length; i++)
5354
{
54-
var child = children[index];
55+
var child = children[i];
5556
var childAlpha = child._alpha;
5657
var childScrollFactorX = child.scrollFactorX;
5758
var childScrollFactorY = child.scrollFactorY;

src/gameobjects/container/ContainerWebGLRenderer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ var GameObject = require('../GameObject');
2424
*/
2525
var ContainerWebGLRenderer = function (renderer, container, interpolationPercentage, camera, parentMatrix)
2626
{
27-
if (GameObject.RENDER_MASK !== container.renderFlags || (container.cameraFilter > 0 && (container.cameraFilter & camera._id)))
27+
var children = container.list;
28+
29+
if (children.length === 0)
2830
{
2931
return;
3032
}
3133

32-
var children = container.list;
3334
var transformMatrix = container.localTransform;
3435

3536
if (parentMatrix === undefined)
@@ -49,9 +50,9 @@ var ContainerWebGLRenderer = function (renderer, container, interpolationPercent
4950
var scrollFactorX = container.scrollFactorX;
5051
var scrollFactorY = container.scrollFactorY;
5152

52-
for (var index = 0; index < children.length; ++index)
53+
for (var i = 0; i < children.length; i++)
5354
{
54-
var child = children[index];
55+
var child = children[i];
5556
var childAlpha = child._alpha;
5657
var childScrollFactorX = child.scrollFactorX;
5758
var childScrollFactorY = child.scrollFactorY;

0 commit comments

Comments
 (0)