LightsManager.destroy will now clear the lightPool array when destroyed, where-as previously it didn't.

This commit is contained in:
Richard Davey 2020-07-16 03:25:25 +01:00
parent 84968f502f
commit 1146e6f7a3

View file

@ -157,9 +157,9 @@ var LightsManager = new Class({
culledLights.length = 0; culledLights.length = 0;
for (var index = 0; index < length && culledLights.length < this.maxLights; index++) for (var i = 0; i < length && culledLights.length < this.maxLights; i++)
{ {
var light = lights[index]; var light = lights[i];
cameraMatrix.transformPoint(light.x, light.y, point); cameraMatrix.transformPoint(light.x, light.y, point);
@ -170,7 +170,7 @@ var LightsManager = new Class({
if (distance < light.radius + cameraRadius) if (distance < light.radius + cameraRadius)
{ {
culledLights.push(lights[index]); culledLights.push(lights[i]);
} }
} }
@ -197,9 +197,9 @@ var LightsManager = new Class({
var lights = this.lights; var lights = this.lights;
var length = lights.length; var length = lights.length;
for (var index = 0; index < length; ++index) for (var i = 0; i < length; i++)
{ {
callback(lights[index]); callback(lights[i]);
} }
return this; return this;
@ -268,21 +268,25 @@ var LightsManager = new Class({
*/ */
addLight: function (x, y, radius, rgb, intensity) addLight: function (x, y, radius, rgb, intensity)
{ {
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (radius === undefined) { radius = 100; }
if (rgb === undefined) { rgb = 0xffffff; }
if (intensity === undefined) { intensity = 1; }
var color = null; var color = null;
var light = null; var light = null;
x = (x === undefined) ? 0.0 : x;
y = (y === undefined) ? 0.0 : y;
rgb = (rgb === undefined) ? 0xffffff : rgb;
radius = (radius === undefined) ? 100.0 : radius;
intensity = (intensity === undefined) ? 1.0 : intensity;
color = Utils.getFloatsFromUintRGB(rgb); color = Utils.getFloatsFromUintRGB(rgb);
light = null; light = null;
if (this.lightPool.length > 0) var pool = this.lightPool;
if (pool.length > 0)
{ {
light = this.lightPool.pop(); light = pool.pop();
light.set(x, y, radius, color[0], color[1], color[2], intensity); light.set(x, y, radius, color[0], color[1], color[2], intensity);
} }
else else
@ -350,6 +354,8 @@ var LightsManager = new Class({
destroy: function () destroy: function ()
{ {
this.shutdown(); this.shutdown();
this.lightPool.length = 0;
} }
}); });