Skip to content

Commit 718859b

Browse files
committed
Moved the depth sorting functions into the DisplayList class, as it's really the one responsible for it, not System.
1 parent 98ae800 commit 718859b

6 files changed

Lines changed: 46 additions & 26 deletions

File tree

src/actions/GridAlign.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
var AlignIn = require('../display/align/in/QuickSet');
22
var CONST = require('../display/align/const');
33
var GetValue = require('../utils/object/GetValue');
4+
var NOOP = require('../utils/NOOP');
45
var Zone = require('../gameobjects/zone/Zone');
56

6-
var tempZone = new Zone({ sys: { sortChildrenFlag: false }}, 0, 0, 1, 1);
7+
var tempZone = new Zone({ sys: { queueDepthSort: NOOP }}, 0, 0, 1, 1);
78

89
/**
910
* [description]

src/gameobjects/GameObject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ var GameObject = new Class({
121121
this.body = null;
122122

123123
// Tell the Scene to re-sort the children
124-
this.scene.sys.sortChildrenFlag = true;
124+
this.scene.sys.queueDepthSort();
125125
},
126126

127127
/**
@@ -294,7 +294,7 @@ var GameObject = new Class({
294294
}
295295

296296
// Tell the Scene to re-sort the children
297-
this.scene.sys.sortChildrenFlag = true;
297+
this.scene.sys.queueDepthSort();
298298

299299
this.active = false;
300300
this.visible = false;

src/gameobjects/components/Depth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var Depth = {
1414

1515
set: function (value)
1616
{
17-
this.scene.sys.sortChildrenFlag = true;
17+
this.scene.sys.queueDepthSort();
1818
this._depth = value;
1919
}
2020

src/gameobjects/components/Transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ var Transform = {
180180

181181
set: function (value)
182182
{
183-
this.scene.sys.sortChildrenFlag = true;
183+
this.scene.sys.queueDepthSort();
184184
this._depth = value;
185185
}
186186

src/scene/local/Systems.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ var Systems = new Class({
2929
this.config = config;
3030
this.settings = Settings.create(config);
3131

32-
this.sortChildrenFlag = false;
33-
3432
// Set by the GlobalSceneManager
3533
this.canvas;
3634
this.context;
@@ -157,37 +155,23 @@ var Systems = new Class({
157155
return;
158156
}
159157

160-
// inlined to avoid branching
161-
if (this.sortChildrenFlag)
162-
{
163-
StableSort.inplace(this.displayList.list, this.sortZ);
158+
var displayList = this.displayList;
164159

165-
this.sortChildrenFlag = false;
166-
}
160+
displayList.process();
167161

168-
this.cameras.render(renderer, this.displayList, interpolation);
162+
this.cameras.render(renderer, displayList, interpolation);
169163
},
170164

171165
// Force a sort of the display list on the next render
172166
queueDepthSort: function ()
173167
{
174-
this.sortChildrenFlag = true;
168+
this.displayList.queueDepthSort();
175169
},
176170

177171
// Immediately sorts the display list if the flag is set
178172
depthSort: function ()
179173
{
180-
if (this.sortChildrenFlag)
181-
{
182-
StableSort.inplace(this.displayList.list, this.sortZ);
183-
184-
this.sortChildrenFlag = false;
185-
}
186-
},
187-
188-
sortZ: function (childA, childB)
189-
{
190-
return childA._depth - childB._depth;
174+
this.displayList.depthSort();
191175
},
192176

193177
// A paused Scene still renders, it just doesn't run ANY of its update handlers or systems

src/scene/plugins/DisplayList.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Class = require('../../utils/Class');
2+
var StableSort = require('../../utils/array/StableSort');
23

34
var DisplayList = new Class({
45

@@ -13,9 +14,43 @@ var DisplayList = new Class({
1314
// The equivalent of the old `Sprite.children` array.
1415
this.list = [];
1516

17+
this.sortChildrenFlag = false;
18+
1619
this.position = 0;
1720
},
1821

22+
process: function ()
23+
{
24+
if (this.sortChildrenFlag)
25+
{
26+
StableSort.inplace(this.list, this.sortZ);
27+
28+
this.sortChildrenFlag = false;
29+
}
30+
},
31+
32+
sortZ: function (childA, childB)
33+
{
34+
return childA._depth - childB._depth;
35+
},
36+
37+
// Force a sort of the display list on the next call to process
38+
queueDepthSort: function ()
39+
{
40+
this.sortChildrenFlag = true;
41+
},
42+
43+
// Immediately sorts the display list if the flag is set
44+
depthSort: function ()
45+
{
46+
if (this.sortChildrenFlag)
47+
{
48+
StableSort.inplace(this.list, this.sortZ);
49+
50+
this.sortChildrenFlag = false;
51+
}
52+
},
53+
1954
add: function (child)
2055
{
2156
// Is child already in this display list?

0 commit comments

Comments
 (0)