Skip to content

Commit c1c4aed

Browse files
authored
Merge pull request phaserjs#1 from photonstorm/master
keeping up with phaser
2 parents 4f8dd24 + f61b947 commit c1c4aed

57 files changed

Lines changed: 2846 additions & 703 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 103 additions & 12 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Extra special thanks to the following companies who's support makes Phaser possi
7777
* [Y8 Games](https://www.y8.com)
7878
* [Poki](https://developers.poki.com/)
7979

80-
![Sponsors](https://phaser.io/images/github/sponsors-2019-08.png "Awesome Sponsors")
80+
![Sponsors](https://phaser.io/images/github/sponsors-2019-12.png "Awesome Sponsors")
8181

8282
![Phaser Newsletter](https://phaser.io/images/github/div-newsletter.png "Phaser Newsletter")
8383

src/core/Game.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,12 +671,12 @@ var Game = new Class({
671671
*/
672672
runDestroy: function ()
673673
{
674+
this.scene.destroy();
675+
674676
this.events.emit(Events.DESTROY);
675677

676678
this.events.removeAllListeners();
677679

678-
this.scene.destroy();
679-
680680
if (this.renderer)
681681
{
682682
this.renderer.destroy();

src/core/TimeStep.js

Lines changed: 81 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,26 @@ var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
1515
// target: 60,
1616
// forceSetTimeOut: false,
1717
// deltaHistory: 10,
18-
// panicMax: 120
18+
// panicMax: 120,
19+
// smoothStep: true
1920
// }
2021

2122
// http://www.testufo.com/#test=animation-time-graph
2223

2324
/**
2425
* @classdesc
25-
* [description]
26+
* The core runner class that Phaser uses to handle the game loop. It can use either Request Animation Frame,
27+
* or SetTimeout, based on browser support and config settings, to create a continuous loop within the browser.
28+
*
29+
* Each time the loop fires, `TimeStep.step` is called and this is then passed onto the core Game update loop,
30+
* it is the core heartbeat of your game. It will fire as often as Request Animation Frame is capable of handling
31+
* on the target device.
32+
*
33+
* Note that there are lots of situations where a browser will stop updating your game. Such as if the player
34+
* switches tabs, or covers up the browser window with another application. In these cases, the 'heartbeat'
35+
* of your game will pause, and only resume when focus is returned to it by the player. There is no way to avoid
36+
* this situation, all you can do is use the visibility events the browser, and Phaser, provide to detect when
37+
* it has happened and then gracefully recover.
2638
*
2739
* @class TimeStep
2840
* @memberof Phaser.Core
@@ -49,7 +61,7 @@ var TimeStep = new Class({
4961
this.game = game;
5062

5163
/**
52-
* [description]
64+
* The Request Animation Frame DOM Event handler.
5365
*
5466
* @name Phaser.Core.TimeStep#raf
5567
* @type {Phaser.DOM.RequestAnimationFrame}
@@ -141,7 +153,8 @@ var TimeStep = new Class({
141153
this.actualFps = this.targetFps;
142154

143155
/**
144-
* [description]
156+
* The time at which the next fps rate update will take place.
157+
* When an fps update happens, the `framesThisSecond` value is reset.
145158
*
146159
* @name Phaser.Core.TimeStep#nextFpsUpdate
147160
* @type {integer}
@@ -338,6 +351,22 @@ var TimeStep = new Class({
338351
* @since 3.18.0
339352
*/
340353
this.now = 0;
354+
355+
/**
356+
* Apply smoothing to the delta value used within Phasers internal calculations?
357+
*
358+
* This can be changed in the Game Config via the `fps.smoothStep` property. The default is `true`.
359+
*
360+
* Smoothing helps settle down the delta values after browser tab switches, or other situations
361+
* which could cause significant delta spikes or dips. By default it has been enabled in Phaser 3
362+
* since the first version, but is now exposed under this property (and the corresponding game config
363+
* `smoothStep` value), to allow you to easily disable it, should you require.
364+
*
365+
* @name Phaser.Core.TimeStep#smoothStep
366+
* @type {boolean}
367+
* @since 3.22.0
368+
*/
369+
this.smoothStep = GetValue(config, 'smoothStep', true);
341370
},
342371

343372
/**
@@ -461,7 +490,7 @@ var TimeStep = new Class({
461490
step: function ()
462491
{
463492
// Because the timestamp passed in from raf represents the beginning of the main thread frame that we’re currently in,
464-
// not the actual time now. As we want to compare this time value against Event timeStamps and the like, we need a
493+
// not the actual time now, and as we want to compare this time value against Event timeStamps and the like, we need a
465494
// more accurate one:
466495

467496
var time = window.performance.now();
@@ -485,55 +514,59 @@ var TimeStep = new Class({
485514
// delta time (time is in ms)
486515
var dt = before;
487516

517+
// Delta Average
518+
var avg = before;
519+
488520
// When a browser switches tab, then comes back again, it takes around 10 frames before
489521
// the delta time settles down so we employ a 'cooling down' period before we start
490522
// trusting the delta values again, to avoid spikes flooding through our delta average
491523

492-
if (this._coolDown > 0 || !this.inFocus)
493-
{
494-
this._coolDown--;
495-
496-
dt = Math.min(dt, this._target);
497-
}
498-
499-
if (dt > this._min)
500-
{
501-
// Probably super bad start time or browser tab context loss,
502-
// so use the last 'sane' dt value
503-
504-
dt = history[idx];
505-
506-
// Clamp delta to min (in case history has become corrupted somehow)
507-
dt = Math.min(dt, this._min);
508-
}
509-
510-
// Smooth out the delta over the previous X frames
511-
512-
// add the delta to the smoothing array
513-
history[idx] = dt;
514-
515-
// adjusts the delta history array index based on the smoothing count
516-
// this stops the array growing beyond the size of deltaSmoothingMax
517-
this.deltaIndex++;
518-
519-
if (this.deltaIndex > max)
524+
if (this.smoothStep)
520525
{
521-
this.deltaIndex = 0;
526+
if (this._coolDown > 0 || !this.inFocus)
527+
{
528+
this._coolDown--;
529+
530+
dt = Math.min(dt, this._target);
531+
}
532+
533+
if (dt > this._min)
534+
{
535+
// Probably super bad start time or browser tab context loss,
536+
// so use the last 'sane' dt value
537+
538+
dt = history[idx];
539+
540+
// Clamp delta to min (in case history has become corrupted somehow)
541+
dt = Math.min(dt, this._min);
542+
}
543+
544+
// Smooth out the delta over the previous X frames
545+
546+
// add the delta to the smoothing array
547+
history[idx] = dt;
548+
549+
// adjusts the delta history array index based on the smoothing count
550+
// this stops the array growing beyond the size of deltaSmoothingMax
551+
this.deltaIndex++;
552+
553+
if (this.deltaIndex > max)
554+
{
555+
this.deltaIndex = 0;
556+
}
557+
558+
// Loop the history array, adding the delta values together
559+
avg = 0;
560+
561+
for (var i = 0; i < max; i++)
562+
{
563+
avg += history[i];
564+
}
565+
566+
// Then divide by the array length to get the average delta
567+
avg /= max;
522568
}
523569

524-
// Delta Average
525-
var avg = 0;
526-
527-
// Loop the history array, adding the delta values together
528-
529-
for (var i = 0; i < max; i++)
530-
{
531-
avg += history[i];
532-
}
533-
534-
// Then divide by the array length to get the average delta
535-
avg /= max;
536-
537570
// Set as the world delta value
538571
this.delta = avg;
539572

@@ -667,7 +700,7 @@ var TimeStep = new Class({
667700
* @method Phaser.Core.TimeStep#stop
668701
* @since 3.0.0
669702
*
670-
* @return {Phaser.Core.TimeStep} The TimeStep object.
703+
* @return {this} The TimeStep object.
671704
*/
672705
stop: function ()
673706
{

src/core/typedefs/FPSConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
* @property {boolean} [forceSetTimeOut=false] - Use setTimeout instead of requestAnimationFrame to run the game loop.
88
* @property {integer} [deltaHistory=10] - Calculate the average frame delta from this many consecutive frame intervals.
99
* @property {integer} [panicMax=120] - The amount of frames the time step counts before we trust the delta values again.
10+
* @property {boolean} [smoothStep=true] - Apply delta smoothing during the game update to help avoid spikes?
1011
*/

src/curves/Curve.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,24 +353,37 @@ var Curve = new Class({
353353
* @method Phaser.Curves.Curve#getSpacedPoints
354354
* @since 3.0.0
355355
*
356-
* @param {integer} [divisions] - [description]
356+
* @param {integer} [divisions] - The number of evenly spaced points from the curve to return. If falsy, step param will be used to calculate the number of points.
357+
* @param {number} [step] - Step between points. Used to calculate the number of points to return when divisions is falsy. Ignored if divisions is positive.
358+
* @param {(array|Phaser.Math.Vector2[])} [out] - An optional array to store the points in.
357359
*
358360
* @return {Phaser.Math.Vector2[]} [description]
359361
*/
360-
getSpacedPoints: function (divisions)
362+
getSpacedPoints: function (divisions, stepRate, out)
361363
{
362-
if (divisions === undefined) { divisions = this.defaultDivisions; }
364+
if (out === undefined) { out = []; }
363365

364-
var points = [];
366+
// If divisions is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead.
367+
if (!divisions)
368+
{
369+
if (!stepRate)
370+
{
371+
divisions = this.defaultDivisions;
372+
}
373+
else
374+
{
375+
divisions = this.getLength() / stepRate;
376+
}
377+
}
365378

366379
for (var d = 0; d <= divisions; d++)
367380
{
368381
var t = this.getUtoTmapping(d / divisions, null, divisions);
369382

370-
points.push(this.getPoint(t));
383+
out.push(this.getPoint(t));
371384
}
372385

373-
return points;
386+
return out;
374387
},
375388

376389
/**

src/curves/LineCurve.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,41 @@ var LineCurve = new Class({
194194
return tangent.normalize();
195195
},
196196

197+
// Override default Curve.getUtoTmapping
198+
199+
/**
200+
* [description]
201+
*
202+
* @method Phaser.Curves.Line#getUtoTmapping
203+
* @since 3.0.0
204+
*
205+
* @param {number} u - [description]
206+
* @param {integer} distance - [description]
207+
* @param {integer} [divisions] - [description]
208+
*
209+
* @return {number} [description]
210+
*/
211+
getUtoTmapping: function (u, distance, divisions)
212+
{
213+
var t;
214+
215+
if (distance)
216+
{
217+
var arcLengths = this.getLengths(divisions);
218+
var lineLength = arcLengths[arcLengths.length - 1];
219+
// Cannot overshoot the curve
220+
var targetLineLength = Math.min(distance, lineLength);
221+
222+
t = targetLineLength / lineLength;
223+
}
224+
else
225+
{
226+
t = u;
227+
}
228+
229+
return t;
230+
},
231+
197232
// Override default Curve.draw because this is better than calling getPoints on a line!
198233

199234
/**

src/gameobjects/GameObjectCreator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var GameObjectCreator = new Class({
6363
/**
6464
* A reference to the Scene Update List.
6565
*
66-
* @name Phaser.GameObjects.GameObjectCreator#updateList;
66+
* @name Phaser.GameObjects.GameObjectCreator#updateList
6767
* @type {Phaser.GameObjects.UpdateList}
6868
* @protected
6969
* @since 3.0.0

src/gameobjects/GameObjectFactory.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var GameObjectFactory = new Class({
6262
/**
6363
* A reference to the Scene Update List.
6464
*
65-
* @name Phaser.GameObjects.GameObjectFactory#updateList;
65+
* @name Phaser.GameObjects.GameObjectFactory#updateList
6666
* @type {Phaser.GameObjects.UpdateList}
6767
* @protected
6868
* @since 3.0.0
@@ -105,7 +105,7 @@ var GameObjectFactory = new Class({
105105

106106
/**
107107
* Adds an existing Game Object to this Scene.
108-
*
108+
*
109109
* If the Game Object renders, it will be added to the Display List.
110110
* If it has a `preUpdate` method, it will be added to the Update List.
111111
*
@@ -167,8 +167,19 @@ var GameObjectFactory = new Class({
167167

168168
});
169169

170-
// Static method called directly by the Game Object factory functions
171-
170+
/**
171+
* Static method called directly by the Game Object factory functions.
172+
* With this method you can register a custom GameObject factory in the GameObjectFactory,
173+
* providing a name (`factoryType`) and the constructor (`factoryFunction`) in order
174+
* to be called when you call to Phaser.Scene.add[ factoryType ] method.
175+
*
176+
* @method Phaser.GameObjects.GameObjectFactory.register
177+
* @static
178+
* @since 3.0.0
179+
*
180+
* @param {string} factoryType - The key of the factory that you will use to call to Phaser.Scene.add[ factoryType ] method.
181+
* @param {function} factoryFunction - The constructor function to be called when you invoke to the Phaser.Scene.add method.
182+
*/
172183
GameObjectFactory.register = function (factoryType, factoryFunction)
173184
{
174185
if (!GameObjectFactory.prototype.hasOwnProperty(factoryType))
@@ -177,6 +188,17 @@ GameObjectFactory.register = function (factoryType, factoryFunction)
177188
}
178189
};
179190

191+
/**
192+
* Static method called directly by the Game Object factory functions.
193+
* With this method you can remove a custom GameObject factory registered in the GameObjectFactory,
194+
* providing a its `factoryType`.
195+
*
196+
* @method Phaser.GameObjects.GameObjectFactory.remove
197+
* @static
198+
* @since 3.0.0
199+
*
200+
* @param {string} factoryType - The key of the factory that you want to remove from the GameObjectFactory.
201+
*/
180202
GameObjectFactory.remove = function (factoryType)
181203
{
182204
if (GameObjectFactory.prototype.hasOwnProperty(factoryType))

src/gameobjects/bitmaptext/ParseFromAtlas.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var ParseXMLBitmapFont = require('./ParseXMLBitmapFont');
2020
* @param {string} textureKey - The key of the BitmapFont's texture.
2121
* @param {string} frameKey - The key of the BitmapFont texture's frame.
2222
* @param {string} xmlKey - The key of the XML data of the font to parse.
23-
* @param {integer} xSpacing - The x-axis spacing to add between each letter.
24-
* @param {integer} ySpacing - The y-axis spacing to add to the line height.
23+
* @param {integer} [xSpacing] - The x-axis spacing to add between each letter.
24+
* @param {integer} [ySpacing] - The y-axis spacing to add to the line height.
2525
*
2626
* @return {boolean} Whether the parsing was successful or not.
2727
*/

0 commit comments

Comments
 (0)