Skip to content

Commit f9cc2a9

Browse files
committed
Scene now sets a status flag for every state it goes through, allowing the manager to know when to allow updating and rendering
1 parent a5a1121 commit f9cc2a9

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

src/scene/SceneManager.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var CanvasInterpolation = require('../display/canvas/CanvasInterpolation');
22
var CanvasPool = require('../display/canvas/CanvasPool');
33
var Class = require('../utils/Class');
4-
var CONST = require('../const');
4+
var CONST = require('./const');
55
var GetValue = require('../utils/object/GetValue');
66
var NOOP = require('../utils/NOOP');
77
var Scene = require('./Scene');
@@ -230,6 +230,8 @@ var SceneManager = new Class({
230230
}
231231
else
232232
{
233+
scene.sys.settings.status = CONST.LOADING;
234+
233235
// Start the loader going as we have something in the queue
234236
loader.once('complete', this.loadComplete, this);
235237

@@ -295,7 +297,7 @@ var SceneManager = new Class({
295297
{
296298
var sys = this.scenes[i].sys;
297299

298-
if (sys.settings.active)
300+
if (sys.settings.status === CONST.RUNNING)
299301
{
300302
sys.step(time, delta);
301303
}
@@ -342,6 +344,8 @@ var SceneManager = new Class({
342344
{
343345
scene.create.call(scene, scene.sys.settings.data);
344346
}
347+
348+
scene.sys.settings.status = CONST.RUNNING;
345349
},
346350

347351
/**
@@ -781,6 +785,8 @@ var SceneManager = new Class({
781785

782786
if (loader.loadArray(scene.sys.settings.files))
783787
{
788+
scene.sys.settings.status = CONST.LOADING;
789+
784790
loader.once('complete', this.payloadComplete, this);
785791

786792
loader.start();

src/scene/Systems.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ var Systems = new Class({
4646

4747
init: function (game)
4848
{
49+
this.settings.status = CONST.INIT;
50+
4951
this.game = game;
5052

5153
this.canvas = game.canvas;
@@ -117,6 +119,8 @@ var Systems = new Class({
117119
{
118120
if (this.settings.active)
119121
{
122+
this.settings.status = CONST.PAUSED;
123+
120124
this.settings.active = false;
121125

122126
this.events.emit('pause', this);
@@ -127,6 +131,8 @@ var Systems = new Class({
127131
{
128132
if (!this.settings.active)
129133
{
134+
this.settings.status = CONST.RUNNING;
135+
130136
this.settings.active = true;
131137

132138
this.events.emit('resume', this);
@@ -135,6 +141,8 @@ var Systems = new Class({
135141

136142
sleep: function ()
137143
{
144+
this.settings.status = CONST.SLEEPING;
145+
138146
this.settings.active = false;
139147
this.settings.visible = false;
140148

@@ -143,6 +151,8 @@ var Systems = new Class({
143151

144152
wake: function ()
145153
{
154+
this.settings.status = CONST.RUNNING;
155+
146156
this.settings.active = true;
147157
this.settings.visible = true;
148158

@@ -151,12 +161,12 @@ var Systems = new Class({
151161

152162
isSleeping: function ()
153163
{
154-
return (!this.settings.active && !this.settings.visible);
164+
return (this.settings.status === CONST.SLEEPING);
155165
},
156166

157167
isActive: function ()
158168
{
159-
return this.settings.active;
169+
return (this.settings.status === CONST.RUNNING);
160170
},
161171

162172
isVisible: function ()
@@ -173,13 +183,20 @@ var Systems = new Class({
173183

174184
setActive: function (value)
175185
{
176-
this.settings.active = value;
177-
178-
return this;
186+
if (value)
187+
{
188+
return this.resume();
189+
}
190+
else
191+
{
192+
return this.pause();
193+
}
179194
},
180195

181196
start: function (data)
182197
{
198+
this.settings.status = CONST.START;
199+
183200
this.settings.data = data;
184201

185202
this.settings.active = true;
@@ -190,6 +207,8 @@ var Systems = new Class({
190207

191208
shutdown: function ()
192209
{
210+
this.settings.status = CONST.SHUTDOWN;
211+
193212
this.settings.active = false;
194213
this.settings.visible = false;
195214

@@ -198,6 +217,8 @@ var Systems = new Class({
198217

199218
destroy: function ()
200219
{
220+
this.settings.status = CONST.DESTROYED;
221+
201222
this.events.emit('destroy', this);
202223
}
203224

src/scene/const.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
module.exports = {
33

44
PENDING: 0,
5-
INSTALLED: 1,
6-
SHUTDOWN: 2
5+
INIT: 1,
6+
START: 2,
7+
LOADING: 3,
8+
RUNNING: 4,
9+
PAUSED: 5,
10+
SLEEPING: 6,
11+
SHUTDOWN: 7,
12+
DESTROYED: 8
713

814
};

0 commit comments

Comments
 (0)