Skip to content

Commit 3c52a3b

Browse files
committed
Pass the pointers array in directly, no need to iterate them all every time
1 parent f7a374b commit 3c52a3b

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ The following changes took place in the Pointer class:
5555
* Calling `setPollAlways()` would cause the `'pointerdown'` event to fire multiple times. Fix #4541 (thanks @Neyromantik)
5656
* The pointer events were intermittently not registered, causing `pointerup` to often fail. Fix #4538 (thanks @paulsymphony)
5757
* Due to a regression in 3.16 the drag events were not performing as fast as before, causing drags to feel lagged. Fix #4500 (thanks @aliblong)
58+
* Over and Out events should now work for any pointer in multi-touch environments, not just the first touch pointer registered.
5859

59-
TODO: No need to iterate pointers in `update` any more, can pass in from manager handler.
6060

6161
### New Features
6262

src/input/InputManager.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,16 @@ var InputManager = new Class({
291291
*/
292292
this._tempSkip = false;
293293

294+
/**
295+
* An internal private array that avoids needing to create a new array on every DOM mouse event.
296+
*
297+
* @name Phaser.Input.InputManager#mousePointerContainer
298+
* @type {Phaser.Input.Pointer[]}
299+
* @private
300+
* @since 3.18.0
301+
*/
302+
this.mousePointerContainer = [ this.mousePointer ];
303+
294304
game.events.once(GameEvents.BOOT, this.boot, this);
295305
},
296306

@@ -678,13 +688,12 @@ var InputManager = new Class({
678688
* @method Phaser.Input.InputManager#updateInputPlugins
679689
* @since 3.16.0
680690
*
681-
* @param {number} time - The time value from the most recent Game step. Typically a high-resolution timer value, or Date.now().
682-
* @param {number} delta - The delta value since the last frame. This is smoothed to avoid delta spikes by the TimeStep class.
691+
* @param {integer} type - The type of event to process.
692+
* @param {Phaser.Input.Pointer[]} pointers - An array of Pointers on which the event occurred.
683693
*/
684-
updateInputPlugins: function (type, time)
694+
updateInputPlugins: function (type, pointers)
685695
{
686696
var scenes = this.game.scene.getScenes(true, true);
687-
var delta = this.game.loop.delta;
688697

689698
this._tempSkip = false;
690699

@@ -694,7 +703,7 @@ var InputManager = new Class({
694703

695704
if (scene.sys.input)
696705
{
697-
var capture = scene.sys.input.update(type, time, delta);
706+
var capture = scene.sys.input.update(type, pointers);
698707

699708
if ((capture && this.globalTopOnly) || this._tempSkip)
700709
{
@@ -723,7 +732,7 @@ var InputManager = new Class({
723732
pointer.updateMotion();
724733
});
725734

726-
this.updateInputPlugins(CONST.TOUCH_START, event.timeStamp);
735+
this.updateInputPlugins(CONST.TOUCH_START, event.timeStamp, changed);
727736
},
728737

729738
/**
@@ -744,7 +753,7 @@ var InputManager = new Class({
744753
pointer.updateMotion();
745754
});
746755

747-
this.updateInputPlugins(CONST.TOUCH_MOVE, event.timeStamp);
756+
this.updateInputPlugins(CONST.TOUCH_MOVE, event.timeStamp, changed);
748757
},
749758

750759
/**
@@ -765,7 +774,7 @@ var InputManager = new Class({
765774
pointer.updateMotion();
766775
});
767776

768-
this.updateInputPlugins(CONST.TOUCH_END, event.timeStamp);
777+
this.updateInputPlugins(CONST.TOUCH_END, event.timeStamp, changed);
769778
},
770779

771780
/**
@@ -786,7 +795,7 @@ var InputManager = new Class({
786795
pointer.updateMotion();
787796
});
788797

789-
this.updateInputPlugins(CONST.TOUCH_CANCEL, event.timeStamp);
798+
this.updateInputPlugins(CONST.TOUCH_CANCEL, event.timeStamp, changed);
790799
},
791800

792801
/**
@@ -804,7 +813,7 @@ var InputManager = new Class({
804813

805814
this.mousePointer.updateMotion();
806815

807-
this.updateInputPlugins(CONST.MOUSE_DOWN, event.timeStamp);
816+
this.updateInputPlugins(CONST.MOUSE_DOWN, event.timeStamp, this.mousePointerContainer);
808817
},
809818

810819
/**
@@ -822,7 +831,7 @@ var InputManager = new Class({
822831

823832
this.mousePointer.updateMotion();
824833

825-
this.updateInputPlugins(CONST.MOUSE_MOVE, event.timeStamp);
834+
this.updateInputPlugins(CONST.MOUSE_MOVE, event.timeStamp, this.mousePointerContainer);
826835
},
827836

828837
/**
@@ -840,7 +849,7 @@ var InputManager = new Class({
840849

841850
this.mousePointer.updateMotion();
842851

843-
this.updateInputPlugins(CONST.MOUSE_UP, event.timeStamp);
852+
this.updateInputPlugins(CONST.MOUSE_UP, event.timeStamp, this.mousePointerContainer);
844853
},
845854

846855
/**

src/input/InputPlugin.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,21 +630,19 @@ var InputPlugin = new Class({
630630
* @fires Phaser.Input.Events#UPDATE
631631
* @since 3.0.0
632632
*
633-
* @param {integer} type - The type of input event to process.
633+
* @param {integer} type - The type of event to process.
634+
* @param {Phaser.Input.Pointer[]} pointers - An array of Pointers on which the event occurred.
634635
*
635636
* @return {boolean} `true` if this Scene has captured the input events from all other Scenes, otherwise `false`.
636637
*/
637-
update: function (type)
638+
update: function (type, pointers)
638639
{
639640
if (!this.isActive())
640641
{
641642
return false;
642643
}
643644

644-
var manager = this.manager;
645-
646-
var pointers = manager.pointers;
647-
var pointersTotal = manager.pointersTotal;
645+
var pointersTotal = pointers.length;
648646
var captured = false;
649647

650648
for (var i = 0; i < pointersTotal; i++)

0 commit comments

Comments
 (0)