Skip to content

Commit 4e0a3e9

Browse files
committed
Getting ready for rewrite
1 parent b90109e commit 4e0a3e9

1 file changed

Lines changed: 41 additions & 38 deletions

File tree

src/dom/ScaleManager.js

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ var ScaleManager = new Class({
101101
orientationFallback: null,
102102
noMargins: false,
103103
scrollTo: null,
104-
forceMinimumDocumentHeight: false,
105104
canExpandParent: true,
106105
clickTrampoline: ''
107106
};
@@ -136,7 +135,7 @@ var ScaleManager = new Class({
136135

137136
this._updateThrottle = 0;
138137

139-
this._updateThrottleReset = 100;
138+
this._updateThrottleReset = 1000;
140139

141140
this._parentBounds = new Rectangle();
142141

@@ -147,13 +146,11 @@ var ScaleManager = new Class({
147146
this._lastReportedGameSize = new Rectangle();
148147

149148
this._booted = false;
150-
151-
game.events.once('boot', this.boot, this);
152149
},
153150

154-
boot: function ()
151+
preBoot: function ()
155152
{
156-
console.log('SM boot');
153+
console.log('%c preBoot ', 'background: #000; color: #ffff00');
157154

158155
// Configure device-dependent compatibility
159156

@@ -230,33 +227,32 @@ var ScaleManager = new Class({
230227
document.addEventListener('MSFullscreenError', this._fullScreenError, false);
231228
}
232229

230+
// Set-up the Bounds
231+
var isDesktop = os.desktop && (document.documentElement.clientWidth <= window.innerWidth) && (document.documentElement.clientHeight <= window.innerHeight);
232+
233+
console.log('isDesktop', isDesktop, os.desktop);
234+
235+
VisualBounds.init(isDesktop);
236+
LayoutBounds.init(isDesktop);
237+
233238
this.setupScale(game.config.width, game.config.height);
234239

235240
// Same as calling setGameSize:
236241
this._gameSize.setTo(0, 0, game.config.width, game.config.height);
237242

238-
game.events.once('ready', this.start, this);
243+
game.events.once('boot', this.boot, this);
239244
},
240245

241246
// Called once added to the DOM, not before
242-
start: function ()
247+
boot: function ()
243248
{
244-
console.log('SM.start', this.width, this.height);
249+
console.log('%c boot ', 'background: #000; color: #ffff00', this.width, this.height);
245250

246251
var game = this.game;
247-
var os = game.device.os;
248252
var compat = this.compatibility;
249253

250-
game.events.on('resume', this.gameResumed, this);
251-
252254
// Initialize core bounds
253255

254-
// Set-up the Bounds
255-
var isDesktop = os.desktop && (document.documentElement.clientWidth <= window.innerWidth) && (document.documentElement.clientHeight <= window.innerHeight);
256-
257-
VisualBounds.init(isDesktop);
258-
LayoutBounds.init(isDesktop);
259-
260256
GetOffset(game.canvas, this.offset);
261257

262258
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
@@ -277,11 +273,17 @@ var ScaleManager = new Class({
277273

278274
this.signalSizeChange();
279275

280-
// game.events.on('prestep', this.step, this);
276+
// Make sure to sync the parent bounds to the current local rect, or we'll expand forever
277+
this.getParentBounds(this._parentBounds);
278+
279+
game.events.on('resume', this.gameResumed, this);
280+
game.events.on('prestep', this.step, this);
281281
},
282282

283283
setupScale: function (width, height)
284284
{
285+
console.log('%c setupScale ', 'background: #000; color: #ffff00', width, height);
286+
285287
var target;
286288
var rect = new Rectangle();
287289

@@ -311,6 +313,8 @@ var ScaleManager = new Class({
311313
rect.width = VisualBounds.width;
312314
rect.height = VisualBounds.height;
313315

316+
console.log('parentIsWindow', VisualBounds.width, VisualBounds.height);
317+
314318
this.offset.set(0, 0);
315319
}
316320
else
@@ -360,15 +364,15 @@ var ScaleManager = new Class({
360364

361365
this.updateDimensions(newWidth, newHeight, false);
362366

363-
console.log('setupScale', this._gameSize);
364367
console.log('pn', this.parentNode);
365368
console.log('pw', this.parentIsWindow);
366369
console.log('pb', this._parentBounds);
370+
console.log('new size', newWidth, newHeight);
367371
},
368372

369373
setGameSize: function (width, height)
370374
{
371-
console.log('setGameSize', width, height);
375+
console.log('%c setGameSize ', 'background: #000; color: #ffff00', width, height);
372376

373377
this._gameSize.setTo(0, 0, width, height);
374378

@@ -468,6 +472,8 @@ var ScaleManager = new Class({
468472

469473
if (boundsChanged || orientationChanged)
470474
{
475+
console.log('%c bc ', 'background: #000; color: #ffff00', boundsChanged, bounds.width, prevWidth, bounds.height, prevHeight);
476+
471477
if (this.onResize)
472478
{
473479
this.onResize.call(this.onResizeContext, this, bounds);
@@ -476,6 +482,11 @@ var ScaleManager = new Class({
476482
this.updateLayout();
477483

478484
this.signalSizeChange();
485+
486+
// Make sure to sync the parent bounds to the current local rect, or we'll expand forever
487+
this.getParentBounds(this._parentBounds);
488+
489+
console.log('%c new bounds ', 'background: #000; color: #ffff00', this._parentBounds.width, this._parentBounds.height);
479490
}
480491

481492
// Next throttle, eg. 25, 50, 100, 200...
@@ -646,13 +657,6 @@ var ScaleManager = new Class({
646657

647658
this.scrollTop();
648659

649-
if (this.compatibility.forceMinimumDocumentHeight)
650-
{
651-
// (This came from older code, by why is it here?)
652-
// Set minimum height of content to new window height
653-
document.documentElement.style.minHeight = window.innerHeight + 'px';
654-
}
655-
656660
if (this.incorrectOrientation)
657661
{
658662
this.setMaximum();
@@ -704,7 +708,7 @@ var ScaleManager = new Class({
704708

705709
getParentBounds: function (bounds, parentNode)
706710
{
707-
console.log('getParentBounds');
711+
// console.log('%c getParentBounds ', 'background: #000; color: #ff00ff');
708712

709713
if (bounds === undefined) { bounds = new Rectangle(); }
710714
if (parentNode === undefined) { parentNode = this.boundingParent; }
@@ -715,7 +719,7 @@ var ScaleManager = new Class({
715719
if (!parentNode)
716720
{
717721
bounds.setTo(0, 0, visualBounds.width, visualBounds.height);
718-
console.log('b1');
722+
// console.log('b1', bounds);
719723
}
720724
else
721725
{
@@ -739,15 +743,15 @@ var ScaleManager = new Class({
739743
windowBounds = (wc.bottom === 'layout') ? layoutBounds : visualBounds;
740744
bounds.bottom = Math.min(bounds.bottom, windowBounds.height);
741745
}
742-
743-
console.log('b2');
744746
}
745747

746-
bounds.setTo(
747-
Math.round(bounds.x), Math.round(bounds.y),
748-
Math.round(bounds.width), Math.round(bounds.height));
748+
bounds.setTo(Math.round(bounds.x), Math.round(bounds.y), Math.round(bounds.width), Math.round(bounds.height));
749749

750-
console.log(bounds);
750+
// console.log(parentNode.offsetParent);
751+
// console.log(clientRect);
752+
// console.log(parentRect);
753+
// console.log(clientRect.left - parentRect.left, clientRect.top - parentRect.top, clientRect.width, clientRect.height);
754+
// console.log('gpb', bounds);
751755

752756
return bounds;
753757
},
@@ -893,6 +897,7 @@ var ScaleManager = new Class({
893897
{
894898
this._parentBounds.width = 0;
895899
this._parentBounds.height = 0;
900+
this._lastUpdate = 0;
896901
}
897902

898903
this._updateThrottle = this._updateThrottleReset;
@@ -1200,7 +1205,6 @@ var ScaleManager = new Class({
12001205
},
12011206
*/
12021207

1203-
/*
12041208
getInnerHeight: function ()
12051209
{
12061210
// Based on code by @tylerjpeterson
@@ -1236,7 +1240,6 @@ var ScaleManager = new Class({
12361240
return size.w;
12371241
}
12381242
},
1239-
*/
12401243

12411244
/**
12421245
* Destroys the ScaleManager.

0 commit comments

Comments
 (0)