Skip to content

Commit ce3bb7d

Browse files
committed
Implemented RTree spatial sort for the display list handling. Canvas Renderer updated to take advantage of it. Camera updated to extend BaseTransform + add extra properties. Array QuickSelect function added. Frame radius calculation added.
1 parent 0d9e25c commit ce3bb7d

14 files changed

Lines changed: 872 additions & 343 deletions

File tree

v3/dev-guide/IDEAS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ TODO
55

66
Upgrade to Webpack 2 final release
77
Stop the build script from _moving_ the build file into Examples, and just copy it :)
8+
Add in k-nearest neighbors search (KNN) for RBush
9+
Look at Bounds + SetBounds from EaselJS for Transforms that aren't Frame based
810

911
General
1012
-------
@@ -13,8 +15,6 @@ Add a Registry - a game level Data component, accessible from any State.
1315

1416
Look at adding events to the Data component, so you can be notified about changes to objects stored within it. Something like the way Freezer does it? https://github.com/arqex/freezer
1517

16-
Rename ParticleRenderer to BlitterBatch.
17-
1818

1919
Arcade Physics
2020
--------------

v3/src/camera/Camera.js

Lines changed: 15 additions & 280 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/**
2-
* @author Richard Davey <rich@photonstorm.com>
3-
* @copyright 2016 Photon Storm Ltd.
4-
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5-
*/
6-
7-
var Component = require('../components');
8-
var MATH_CONST = require('../math/const');
9-
var WrapAngle = require('../math/angle/Wrap');
101

11-
// Swap to extending a BaseTransform
12-
// var BaseTransform = require('');
2+
var BaseTransform = require('../components/BaseTransform');
133

144
/**
155
* A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view.
@@ -26,315 +16,60 @@ var WrapAngle = require('../math/angle/Wrap');
2616
*/
2717
var Camera = function (state, x, y, viewportWidth, viewportHeight)
2818
{
29-
/**
30-
* The State that this Camera belongs to. A Camera can only belong to one State, and a State only
31-
* has one Camera.
32-
* @property {Phaser.State} state
33-
*/
19+
console.log('Camera', viewportWidth, viewportHeight);
20+
3421
this.state = state;
3522

36-
this.viewportWidth = viewportWidth;
23+
BaseTransform.call(this, this, x, y);
3724

25+
this.viewportWidth = viewportWidth;
3826
this.viewportHeight = viewportHeight;
3927

40-
this.transform = new Component.Transform(this, x, y);
41-
42-
/**
43-
* The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World.
44-
* The Rectangle can be located anywhere in the world and updated as often as you like. If you don't wish the Camera to be bound
45-
* at all then set this to null. The values can be anything and are in World coordinates, with 0,0 being the top-left of the world.
46-
*
47-
* @property {Phaser.Rectangle} bounds - The Rectangle in which the Camera is bounded. Set to null to allow for movement anywhere.
48-
*/
49-
// this.bounds = new Phaser.Rectangle(x, y, width, height);
50-
51-
// this.bounds = new Phaser.Circle(x, y)
52-
53-
/**
54-
* @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not.
55-
*/
56-
this.atLimit = { x: false, y: false };
28+
this.transform.deleteTreeNode();
5729
};
5830

31+
Camera.prototype = Object.create(BaseTransform.prototype);
5932
Camera.prototype.constructor = Camera;
6033

61-
Camera.prototype = {
62-
63-
/**
64-
* Method called to ensure the camera doesn't venture outside of the game world.
65-
* Called automatically by Camera.update.
66-
*
67-
* @method Phaser.Camera#checkBounds
68-
* @protected
69-
*/
70-
checkBounds: function ()
71-
{
72-
this.atLimit.x = false;
73-
this.atLimit.y = false;
74-
75-
// var vx = this.view.x + this._shake.x;
76-
// var vw = this.view.right + this._shake.x;
77-
// var vy = this.view.y + this._shake.y;
78-
// var vh = this.view.bottom + this._shake.y;
79-
80-
var vx = this.x;
81-
var vw = this.x + this.viewportWidth;
82-
var vy = this.y;
83-
var vh = this.y + this.viewportHeight;
84-
85-
// Make sure we didn't go outside the cameras bounds
86-
if (vx <= this.bounds.x * this.scale.x)
87-
{
88-
this.atLimit.x = true;
89-
this.view.x = this.bounds.x * this.scale.x;
90-
91-
if (!this._shake.shakeBounds)
92-
{
93-
// The camera is up against the bounds, so reset the shake
94-
this._shake.x = 0;
95-
}
96-
}
97-
98-
if (vw >= this.bounds.right * this.scale.x)
99-
{
100-
this.atLimit.x = true;
101-
this.view.x = (this.bounds.right * this.scale.x) - this.width;
102-
103-
if (!this._shake.shakeBounds)
104-
{
105-
// The camera is up against the bounds, so reset the shake
106-
this._shake.x = 0;
107-
}
108-
}
109-
110-
if (vy <= this.bounds.top * this.scale.y)
111-
{
112-
this.atLimit.y = true;
113-
this.view.y = this.bounds.top * this.scale.y;
114-
115-
if (!this._shake.shakeBounds)
116-
{
117-
// The camera is up against the bounds, so reset the shake
118-
this._shake.y = 0;
119-
}
120-
}
121-
122-
if (vh >= this.bounds.bottom * this.scale.y)
123-
{
124-
this.atLimit.y = true;
125-
this.view.y = (this.bounds.bottom * this.scale.y) - this.height;
126-
127-
if (!this._shake.shakeBounds)
128-
{
129-
// The camera is up against the bounds, so reset the shake
130-
this._shake.y = 0;
131-
}
132-
}
133-
134-
}
135-
34+
Camera.prototype.render = function ()
35+
{
13636
};
13737

13838
Object.defineProperties(Camera.prototype, {
13939

140-
// Transform getters / setters
141-
142-
x: {
143-
144-
enumerable: true,
145-
146-
get: function ()
147-
{
148-
return this.transform._posX;
149-
},
150-
151-
set: function (value)
152-
{
153-
this.transform._posX = value;
154-
this.transform.dirty = true;
155-
}
156-
157-
},
158-
159-
y: {
160-
161-
enumerable: true,
162-
163-
get: function ()
164-
{
165-
return this.transform._posY;
166-
},
167-
168-
set: function (value)
169-
{
170-
this.transform._posY = value;
171-
this.transform.dirty = true;
172-
}
173-
174-
},
175-
17640
right: {
17741

17842
enumerable: true,
17943

18044
get: function ()
18145
{
182-
return this.transform._posX + (this.viewportWidth * this.transform._scaleX);
183-
}
184-
185-
},
186-
187-
bottom: {
188-
189-
enumerable: true,
190-
191-
get: function ()
192-
{
193-
return this.transform._posY + (this.viewportHeight * this.transform._scaleY);
194-
}
195-
196-
},
197-
198-
scale: {
199-
200-
enumerable: true,
201-
202-
get: function ()
203-
{
204-
return this.transform._scaleX;
205-
},
206-
207-
set: function (value)
208-
{
209-
this.transform._scaleX = value;
210-
this.transform._scaleY = value;
211-
this.transform.dirty = true;
212-
this.transform.updateCache();
213-
}
214-
215-
},
216-
217-
scaleX: {
218-
219-
enumerable: true,
220-
221-
get: function ()
222-
{
223-
return this.transform._scaleX;
46+
return this.transform._posX + this.viewportWidth;
22447
},
22548

22649
set: function (value)
22750
{
228-
this.transform._scaleX = value;
51+
this.transform._posX = value - this.viewportWidth;
22952
this.transform.dirty = true;
230-
this.transform.updateCache();
23153
}
23254

23355
},
23456

235-
scaleY: {
236-
237-
enumerable: true,
238-
239-
get: function ()
240-
{
241-
return this.transform._scaleY;
242-
},
243-
244-
set: function (value)
245-
{
246-
this.transform._scaleY = value;
247-
this.transform.dirty = true;
248-
this.transform.updateCache();
249-
}
250-
251-
},
252-
253-
pivotX: {
254-
255-
enumerable: true,
256-
257-
get: function ()
258-
{
259-
return this.transform._pivotX;
260-
},
261-
262-
set: function (value)
263-
{
264-
this.transform._pivotX = value;
265-
this.transform.dirty = true;
266-
this.transform.updateCache();
267-
}
268-
269-
},
270-
271-
pivotY: {
272-
273-
enumerable: true,
274-
275-
get: function ()
276-
{
277-
return this.transform._pivotY;
278-
},
279-
280-
set: function (value)
281-
{
282-
this.transform._pivotY = value;
283-
this.transform.dirty = true;
284-
this.transform.updateCache();
285-
}
286-
287-
},
288-
289-
angle: {
290-
291-
enumerable: true,
292-
293-
get: function ()
294-
{
295-
return WrapAngle(this.rotation * MATH_CONST.RAD_TO_DEG);
296-
},
297-
298-
set: function (value)
299-
{
300-
this.rotation = WrapAngle(value) * MATH_CONST.DEG_TO_RAD;
301-
}
302-
303-
},
304-
305-
rotation: {
57+
bottom: {
30658

30759
enumerable: true,
30860

30961
get: function ()
31062
{
311-
return this.transform._rotation;
63+
return this.transform._posY + this.viewportHeight;
31264
},
31365

31466
set: function (value)
31567
{
316-
if (this.transform._rotation === value)
317-
{
318-
return;
319-
}
320-
321-
this.transform._rotation = value;
68+
this.transform._posY = value - this.viewportHeight;
32269
this.transform.dirty = true;
323-
324-
if (this.transform._rotation % MATH_CONST.PI2)
325-
{
326-
this.transform.cache.sr = Math.sin(this.transform._rotation);
327-
this.transform.cache.cr = Math.cos(this.transform._rotation);
328-
this.transform.updateCache();
329-
this.transform.hasLocalRotation = true;
330-
}
331-
else
332-
{
333-
this.transform.hasLocalRotation = false;
334-
}
33570
}
33671

337-
},
72+
}
33873

33974
});
34075

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: '1f102830-e320-11e6-897c-f1a016edce8a'
2+
build: 'ec96c2b0-e379-11e6-ab53-298f7f57f45b'
33
};
44
module.exports = CHECKSUM;

v3/src/components/BaseTransform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ var Transform = require('./Transform');
1414
*
1515
* @class
1616
*/
17-
var BaseTransform = function (x, y)
17+
var BaseTransform = function (parent, x, y, scaleX, scaleY)
1818
{
19-
this.transform = new Transform(this, x, y);
19+
this.transform = new Transform(parent, x, y, scaleX, scaleY);
2020
};
2121

2222
BaseTransform.prototype.constructor = BaseTransform;

0 commit comments

Comments
 (0)