Skip to content

Commit 7cef0e4

Browse files
committed
Working through context issues.
1 parent 00ac451 commit 7cef0e4

7 files changed

Lines changed: 45 additions & 15 deletions

File tree

v3/src/boot/CreateRenderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var CreateRenderer = function (game)
8080
{
8181
game.renderer = new CanvasRenderer(game);
8282
game.context = game.renderer.gameContext;
83+
8384
// debug
8485
game.canvas.id = 'game';
8586
}

v3/src/boot/MainLoop.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var MainLoop = function (framerate)
2323
*/
2424
this.frameDelta = 0;
2525

26+
this.discardedTime = 0;
27+
2628
/**
2729
* The timestamp in milliseconds of the last time the main loop was run.
2830
* Used to compute the time elapsed between frames.
@@ -134,9 +136,11 @@ MainLoop.prototype = {
134136

135137
step: function (timestamp, active, renderer)
136138
{
139+
var len = active.length;
140+
137141
// Throttle the frame rate (if minFrameDelay is set to a non-zero value by
138142
// `MainLoop.setMaxAllowedFPS()`).
139-
if (active.length === 0 || timestamp < this.lastFrameTimeMs + this.minFrameDelay)
143+
if (len === 0 || timestamp < this.lastFrameTimeMs + this.minFrameDelay)
140144
{
141145
return;
142146
}
@@ -152,7 +156,7 @@ MainLoop.prototype = {
152156
// Run any updates that are not dependent on time in the simulation.
153157
// Here we'll need to run things like tween.update, input.update, etc.
154158

155-
for (var i = 0; i < active.length; i++)
159+
for (var i = 0; i < len; i++)
156160
{
157161
active[i].state.sys.begin(timestamp, this.frameDelta);
158162
}
@@ -178,7 +182,7 @@ MainLoop.prototype = {
178182

179183
while (this.frameDelta >= this.timestep)
180184
{
181-
for (var i = 0; i < active.length; i++)
185+
for (i = 0; i < len; i++)
182186
{
183187
active[i].state.sys.update(this.timestep, this.physicsStep);
184188
}
@@ -198,6 +202,7 @@ MainLoop.prototype = {
198202

199203
renderer.preRender();
200204

205+
// This uses active.length, in case state.update removed the state from the active list
201206
for (i = 0; i < active.length; i++)
202207
{
203208
active[i].state.sys.render(interpolation, renderer);
@@ -211,9 +216,9 @@ MainLoop.prototype = {
211216
// it's better than the alternative (the application would look like it
212217
// was running very quickly until the simulation caught up to real
213218
// time).
214-
var discardedTime = Math.round(this.resetFrameDelta());
219+
this.discardedTime = Math.round(this.resetFrameDelta());
215220

216-
console.warn('Main loop panicked, tab probably put in the background. Discarding ' + discardedTime + 'ms');
221+
// console.warn('Main loop panicked, tab probably put in the background. Discarding ' + discardedTime + 'ms');
217222
}
218223

219224
this.panic = false;

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: 'ec84a400-ed6e-11e6-b72e-61e1cba6b1dc'
2+
build: '539c39d0-ed76-11e6-b722-c929a207674e'
33
};
44
module.exports = CHECKSUM;

v3/src/events/EventBinding.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ EventBinding.prototype = {
229229
return;
230230
}
231231

232-
console.log('EventBinding.tidy');
233-
console.dir(this.active);
234-
235232
var added = 0;
236233

237234
var i = this.active.length - 1;

v3/src/renderer/canvas/CanvasRenderer.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ CanvasRenderer.prototype = {
144144
*/
145145
render: function (state, list, interpolationPercentage, camera)
146146
{
147+
if (window.d === 1)
148+
{
149+
console.log('render', state.sys.settings.key);
150+
}
151+
147152
var w = state.sys.width;
148153
var h = state.sys.height;
149154
var ctx = state.sys.context;
@@ -157,6 +162,11 @@ CanvasRenderer.prototype = {
157162

158163
if (scissor)
159164
{
165+
if (window.d === 1)
166+
{
167+
console.log('scissor');
168+
}
169+
160170
ctx.beginPath();
161171
ctx.rect(camera.x, camera.y, camera.width, camera.height);
162172
ctx.clip();
@@ -179,6 +189,11 @@ CanvasRenderer.prototype = {
179189

180190
if (settings.renderToTexture)
181191
{
192+
if (window.d === 1)
193+
{
194+
console.log('renderToTexture');
195+
}
196+
182197
if (settings.clearBeforeRender)
183198
{
184199
ctx.clearRect(0, 0, w, h);
@@ -197,20 +212,30 @@ CanvasRenderer.prototype = {
197212
{
198213
var child = list[c].gameObject;
199214

215+
if (window.d === 1)
216+
{
217+
console.log('render child', state.sys.settings.key, child.frame.cutWidth);
218+
}
219+
200220
child.renderCanvas(this, child, interpolationPercentage);
201221
}
202222

203223
// Reset the transform so going into the devs render function the context is ready for use
204224
ctx.setTransform(1, 0, 0, 1, 0, 0);
205225

206226
// Call the State.render function
207-
state.render(ctx, interpolationPercentage);
227+
state.render.call(state, ctx, interpolationPercentage);
208228

209229
// Blast it to the Game Canvas (if needed)
210230
if (settings.renderToTexture)
211231
{
212232
this.gameContext.drawImage(state.sys.canvas, 0, 0, w, h, settings.x, settings.y, w, h);
213233
}
234+
235+
if (window.d === 1)
236+
{
237+
console.log('render end', state.sys.settings.key);
238+
}
214239
},
215240

216241
postRender: function ()

v3/src/state/StateManager.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,17 @@ StateManager.prototype = {
332332

333333
getActiveStateIndex: function (state)
334334
{
335+
var index = -1;
336+
335337
for (var i = 0; i < this.active.length; i++)
336338
{
337339
if (this.active[i].state === state)
338340
{
339-
return this.active[i].index;
341+
index = this.active[i].index;
340342
}
341343
}
342344

343-
return -1;
345+
return index;
344346
},
345347

346348
isActive: function (key)
@@ -434,7 +436,7 @@ StateManager.prototype = {
434436

435437
if (state.preload)
436438
{
437-
state.preload.call(state, this.game);
439+
state.preload(this.game);
438440

439441
// Is the loader empty?
440442
if (loader.list.size === 0)
@@ -473,7 +475,7 @@ StateManager.prototype = {
473475
if (state.create)
474476
{
475477
console.log('startCreate.call', state.sys.settings.key);
476-
state.create.call(state);
478+
state.create();
477479
}
478480

479481
// Insert at the correct index, or it just all goes wrong :)

v3/src/state/Systems.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Systems.prototype = {
136136
// }
137137
}
138138

139-
this.state.update(timestep, physicsStep);
139+
this.state.update.call(this.state, timestep, physicsStep);
140140
},
141141

142142
render: function (interpolation, renderer)

0 commit comments

Comments
 (0)