Skip to content

Commit 2405160

Browse files
committed
Added continuous polling feature to the Input Manager.
1 parent 8cefdae commit 2405160

4 files changed

Lines changed: 80 additions & 32 deletions

File tree

v3/src/camera/components/Cull.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ var Cull = function (renderableObjects)
55
return renderableObjects;
66
}
77

8-
var scrollX = this.scrollX;
9-
var scrollY = this.scrollY;
10-
var cameraW = this.width;
11-
var cameraH = this.height;
12-
var culledObjects = this.culledObjects;
13-
var length = renderableObjects.length;
148
var cameraMatrix = this.matrix.matrix;
159

1610
var mva = cameraMatrix[0];
@@ -28,6 +22,13 @@ var Cull = function (renderableObjects)
2822
return renderableObjects;
2923
}
3024

25+
var scrollX = this.scrollX;
26+
var scrollY = this.scrollY;
27+
var cameraW = this.width;
28+
var cameraH = this.height;
29+
var culledObjects = this.culledObjects;
30+
var length = renderableObjects.length;
31+
3132
determinant = 1 / determinant;
3233

3334
culledObjects.length = 0;

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: '612572f0-68ab-11e7-91cd-add8a0bdccbb'
2+
build: 'bed52b20-68b5-11e7-9844-9578aae7c468'
33
};
44
module.exports = CHECKSUM;

v3/src/input/components/HitTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var HitTest = function (tempMatrix, x, y, gameObjectArray, camera, output)
2020
var scrollX = camera.scrollX;
2121
var scrollY = camera.scrollY;
2222
var screenPoint = camera.cameraToScreen({ x: x, y: y });
23-
2423
var culled = camera.cull(gameObjectArray);
2524

2625
for (var i = 0; i < culled.length; i++)
@@ -31,6 +30,7 @@ var HitTest = function (tempMatrix, x, y, gameObjectArray, camera, output)
3130

3231
if (PointWithinGameObject(object, tpoint.x, tpoint.y))
3332
{
33+
// output.push({ gameObject: object, x: tpoint.x, y: tpoint.y });
3434
output.push(object);
3535
}
3636
}

v3/src/plugins/InputManager.js

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ var InputManager = new Class({
2121
this.keyboard = this.manager.keyboard;
2222
this.mouse = this.manager.mouse;
2323

24+
// How often should the pointer input be checked?
25+
// Time given in ms
26+
// Pointer will *always* be checked if it has been moved by the user.
27+
// This controls how often it will be polled if it hasn't been moved.
28+
// Set to 0 to poll constantly. Set to -1 to only poll on user movement.
29+
this.pollRate = -1;
30+
31+
this._pollTimer = 0;
32+
2433
this._size = 0;
2534

2635
// All interactive objects
@@ -83,41 +92,57 @@ var InputManager = new Class({
8392
this._pendingInsertion.length = 0;
8493
},
8594

95+
setPollAlways: function ()
96+
{
97+
this.pollRate = 0;
98+
this._pollTimer = 0;
99+
100+
return this;
101+
},
102+
103+
setPollOnMove: function ()
104+
{
105+
this.pollRate = -1;
106+
this._pollTimer = 0;
107+
108+
return this;
109+
},
110+
111+
setPoll: function (value)
112+
{
113+
this.pollRate = value;
114+
this._pollTimer = 0;
115+
116+
return this;
117+
},
118+
86119
update: function (time, delta)
87120
{
88121
if (this._size === 0)
89122
{
90123
return;
91124
}
92125

93-
// Has the pointer moved? If so we need to re-check the interactive objects per camera in this Scene
94-
if (this.manager.activePointer.dirty)
95-
{
96-
this.hitTestPointer(this.manager.activePointer);
126+
var runUpdate = (this.manager.activePointer.dirty || this.pollRate === 0);
97127

98-
this.processPointer(this.manager.activePointer);
99-
}
100-
},
101-
102-
// Has it been pressed down or released in this update?
103-
processPointer: function (pointer)
104-
{
105-
var i;
106-
var over = this._over;
107-
108-
if (pointer.justDown)
128+
if (this.pollRate > -1)
109129
{
110-
for (i = 0; i < over.length; i++)
130+
this._pollTimer -= delta;
131+
132+
if (this._pollTimer < 0)
111133
{
112-
this.events.dispatch(new InputEvent.DOWN(pointer, over[i]));
134+
runUpdate = true;
135+
136+
// Discard timer diff
137+
this._pollTimer = this.pollRate;
113138
}
114139
}
115-
else if (pointer.justUp)
140+
141+
if (runUpdate)
116142
{
117-
for (i = 0; i < over.length; i++)
118-
{
119-
this.events.dispatch(new InputEvent.UP(pointer, over[i]));
120-
}
143+
this.hitTestPointer(this.manager.activePointer);
144+
145+
this.processPointer(this.manager.activePointer);
121146
}
122147
},
123148

@@ -155,8 +180,8 @@ var InputManager = new Class({
155180
}
156181
}
157182

158-
this._over.forEach(function(item) {
159-
183+
this._over.forEach(function (item)
184+
{
160185
if (tested.indexOf(item) === -1)
161186
{
162187
justOut.push(item);
@@ -179,6 +204,28 @@ var InputManager = new Class({
179204
this._over = stillOver.concat(justOver);
180205
},
181206

207+
// Has it been pressed down or released in this update?
208+
processPointer: function (pointer)
209+
{
210+
var i;
211+
var over = this._over;
212+
213+
if (pointer.justDown)
214+
{
215+
for (i = 0; i < over.length; i++)
216+
{
217+
this.events.dispatch(new InputEvent.DOWN(pointer, over[i]));
218+
}
219+
}
220+
else if (pointer.justUp)
221+
{
222+
for (i = 0; i < over.length; i++)
223+
{
224+
this.events.dispatch(new InputEvent.UP(pointer, over[i]));
225+
}
226+
}
227+
},
228+
182229
add: function (child)
183230
{
184231
if (this._pendingInsertion.indexOf(child) === -1 && this._list.indexOf(child) === -1)

0 commit comments

Comments
 (0)