Skip to content

Commit 991ab25

Browse files
committed
Broke the lists apart into DisplayList and UpdateList, as the vast majority of Game Objects don't ever need to have their preUpdate methods called as they are empty.
1 parent 5cb2dbc commit 991ab25

8 files changed

Lines changed: 145 additions & 42 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '4e841af0-60bf-11e7-a35c-4fb005842e0f'
2+
build: '451b4000-60cf-11e7-b7fc-4333a978f5a7'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/GameObject.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ var GameObject = new Class({
3535
this.renderFlags = 15;
3636
},
3737

38-
// To be overridden by custom Game Objects
39-
preUpdate: function ()
40-
{
41-
},
42-
4338
// Can be overridden by custom Game Objects, but provides default export functionality
4439
toJSON: function ()
4540
{

v3/src/gameobjects/group/Group.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ var Group = new Class({
6464
{
6565
if (visible === undefined) { visible = true; }
6666

67-
var child = this.state.sys.children.add(new this.classType(this.state, x, y, key, frame));
67+
var child = new this.classType(this.state, x, y, key, frame);
68+
69+
this.state.sys.displayList.add(child);
70+
71+
if (child.preUpdate)
72+
{
73+
this.state.sys.updateList.add(child);
74+
}
6875

6976
child.visible = visible;
7077

v3/src/plugins/GameObjectCreator.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ var GameObjectCreator = new Class({
2323
function GameObjectCreator (state)
2424
{
2525
this.state = state;
26-
27-
this.children = state.sys.children;
2826
},
2927

3028
bitmapText: function (config)

v3/src/plugins/GameObjectFactory.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,82 +24,88 @@ var GameObjectFactory = new Class({
2424
{
2525
this.state = state;
2626

27-
this.children = state.sys.children;
27+
this.displayList = state.sys.displayList;
28+
this.updateList = state.sys.updateList;
2829
},
2930

3031
bitmapText: function (x, y, font, text, size, align)
3132
{
32-
return this.children.add(StaticBitmapTextFactory(this.state, x, y, font, text, size, align));
33+
return this.displayList.add(StaticBitmapTextFactory(this.state, x, y, font, text, size, align));
3334
},
3435

3536
dynamicBitmapText: function (x, y, font, text, size, align)
3637
{
37-
return this.children.add(DynamicBitmapTextFactory(this.state, x, y, font, text, size, align));
38+
return this.displayList.add(DynamicBitmapTextFactory(this.state, x, y, font, text, size, align));
3839
},
3940

4041
blitter: function (x, y, key, frame)
4142
{
42-
return this.children.add(BlitterFactory(this.state, x, y, key, frame));
43+
return this.displayList.add(BlitterFactory(this.state, x, y, key, frame));
4344
},
4445

4546
effectLayer: function (x, y, width, height, effectName, fragmentShader)
4647
{
47-
return this.children.add(EffectLayerFactory(this.state, x, y, width, height, effectName, fragmentShader));
48+
return this.displayList.add(EffectLayerFactory(this.state, x, y, width, height, effectName, fragmentShader));
4849
},
4950

5051
graphics: function (config)
5152
{
52-
return this.children.add(GraphicsFactory(this.state, config));
53+
return this.displayList.add(GraphicsFactory(this.state, config));
5354
},
5455

55-
group: function (children, config)
56+
group: function (displayList, config)
5657
{
57-
return GroupFactory(this.state, children, config);
58+
return GroupFactory(this.state, displayList, config);
5859
},
5960

6061
image: function (x, y, key, frame)
6162
{
62-
return this.children.add(ImageFactory(this.state, x, y, key, frame));
63+
return this.displayList.add(ImageFactory(this.state, x, y, key, frame));
6364
},
6465

6566
mesh: function (x, y, vertices, uv, key, frame)
6667
{
67-
return this.children.add(MeshFactory(this.state, x, y, vertices, uv, key, frame));
68+
return this.displayList.add(MeshFactory(this.state, x, y, vertices, uv, key, frame));
6869
},
6970

7071
quad: function (x, y, key, frame)
7172
{
72-
return this.children.add(QuadFactory(this.state, x, y, key, frame));
73+
return this.displayList.add(QuadFactory(this.state, x, y, key, frame));
7374
},
7475

7576
renderPass: function (x, y, width, height, shaderName, fragmentShader)
7677
{
77-
return this.children.add(RenderPassFactory(this.state, x, y, width, height, shaderName, fragmentShader));
78+
return this.displayList.add(RenderPassFactory(this.state, x, y, width, height, shaderName, fragmentShader));
7879
},
7980

8081
sprite: function (x, y, key, frame)
8182
{
82-
return this.children.add(SpriteFactory(this.state, x, y, key, frame));
83+
var sprite = SpriteFactory(this.state, x, y, key, frame);
84+
85+
this.displayList.add(sprite);
86+
this.updateList.add(sprite);
87+
88+
return sprite;
8389
},
8490

8591
text: function (x, y, text, style)
8692
{
87-
return this.children.add(TextFactory(this.state, x, y, text, style));
93+
return this.displayList.add(TextFactory(this.state, x, y, text, style));
8894
},
8995

9096
tilemap: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
9197
{
92-
return this.children.add(DynamicTilemapFactory(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame));
98+
return this.displayList.add(DynamicTilemapFactory(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame));
9399
},
94100

95101
staticTilemap: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
96102
{
97-
return this.children.add(StaticTilemapFactory(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame));
98-
},
103+
return this.displayList.add(StaticTilemapFactory(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame));
104+
},
99105

100106
tileSprite: function (x, y, width, height, key, frame)
101107
{
102-
return this.children.add(TileSpriteFactory(this.state, x, y, width, height, key, frame));
108+
return this.displayList.add(TileSpriteFactory(this.state, x, y, width, height, key, frame));
103109
}
104110

105111
});

v3/src/plugins/UpdateList.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
var Class = require('../utils/Class');
2+
3+
var UpdateList = new Class({
4+
5+
initialize:
6+
7+
function UpdateList (state)
8+
{
9+
this.state = state;
10+
11+
this._active = [];
12+
this._pendingInsertion = [];
13+
this._pendingRemoval = [];
14+
},
15+
16+
add: function (child)
17+
{
18+
this._pendingInsertion.push(child);
19+
},
20+
21+
begin: function ()
22+
{
23+
var toRemove = this._pendingRemoval.length;
24+
var toInsert = this._pendingInsertion.length;
25+
26+
if (toRemove === 0 && toInsert === 0)
27+
{
28+
// Quick bail
29+
return;
30+
}
31+
32+
var i;
33+
var event;
34+
35+
// Delete old events
36+
for (i = 0; i < toRemove; i++)
37+
{
38+
event = this._pendingRemoval[i];
39+
40+
var index = this._active.indexOf(event);
41+
42+
if (index > -1)
43+
{
44+
this._active.splice(index, 1);
45+
}
46+
47+
// Pool them?
48+
// event.destroy();
49+
}
50+
51+
this._active = this._active.concat(this._pendingInsertion.splice(0));
52+
53+
// Clear the lists
54+
this._pendingRemoval.length = 0;
55+
this._pendingInsertion.length = 0;
56+
},
57+
58+
update: function (time, delta)
59+
{
60+
for (var i = 0; i < this._active.length; i++)
61+
{
62+
var gameObject = this._active[i];
63+
64+
gameObject.preUpdate.call(gameObject, time, delta);
65+
}
66+
},
67+
68+
// State that owns this Clock is shutting down
69+
shutdown: function ()
70+
{
71+
var i;
72+
73+
for (i = 0; i < this._pendingInsertion.length; i++)
74+
{
75+
this._pendingInsertion[i].destroy();
76+
}
77+
78+
for (i = 0; i < this._active.length; i++)
79+
{
80+
this._active[i].destroy();
81+
}
82+
83+
for (i = 0; i < this._pendingRemoval.length; i++)
84+
{
85+
this._pendingRemoval[i].destroy();
86+
}
87+
88+
this._active.length = 0;
89+
this._pendingRemoval.length = 0;
90+
this._pendingInsertion.length = 0;
91+
},
92+
93+
// Game level nuke
94+
destroy: function ()
95+
{
96+
this.shutdown();
97+
98+
this.state = undefined;
99+
}
100+
101+
});
102+
103+
module.exports = UpdateList;

v3/src/state/InjectionMap.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ var InjectionMap = {
2121
time: 'time',
2222
tweens: 'tweens',
2323

24-
children: 'children',
25-
color: 'color',
24+
displayList: 'children',
2625
data: 'data'
2726

2827
};

v3/src/state/Systems.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var Settings = require('./Settings');
1212
var StableSort = require('../utils/array/StableSort');
1313
var StateManager = require('../plugins/StateManager');
1414
var TweenManager = require('../tween/TweenManager');
15+
var UpdateList = require('../plugins/UpdateList');
1516

1617
var Systems = new Class({
1718

@@ -52,7 +53,8 @@ var Systems = new Class({
5253
this.tweens;
5354

5455
// State properties
55-
this.children;
56+
this.updateList;
57+
this.displayList;
5658
this.data;
5759
},
5860

@@ -72,7 +74,9 @@ var Systems = new Class({
7274

7375
// State specific properties (transform, data, children, etc)
7476

75-
this.children = new DisplayList(state);
77+
this.updateList = new UpdateList(state);
78+
this.displayList = new DisplayList(state);
79+
7680
this.data = new Data(state);
7781

7882
// State specific managers (Factory, Tweens, Loader, Physics, etc)
@@ -114,22 +118,13 @@ var Systems = new Class({
114118
return;
115119
}
116120

121+
this.updateList.begin();
117122
this.time.begin(time);
118-
119123
this.tweens.begin(time);
120124

121-
var list = this.children.list;
122-
123-
for (var i = 0; i < list.length; i++)
124-
{
125-
list[i].preUpdate(time, delta);
126-
}
127-
128-
// preUpdate TimerEvents
125+
this.updateList.update(time, delta);
129126
this.time.update(time, delta);
130-
131127
this.tweens.update(time, delta);
132-
133128
this.cameras.update(time, delta);
134129

135130
this.state.update.call(this.state, time, delta);

0 commit comments

Comments
 (0)