Skip to content

Commit 7e93def

Browse files
committed
Moved functions into components and reworked the Update loop to make it cleaner and faster.
1 parent f84980c commit 7e93def

13 files changed

Lines changed: 280 additions & 135 deletions

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: '43c65050-3b1d-11e7-88f6-353b3d1c591c'
2+
build: 'c27e2550-3b57-11e7-9070-8d2076256d8f'
33
};
44
module.exports = CHECKSUM;

v3/src/tween/Tween.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var TWEEN_CONST = require('./const');
12

23
// A Tween is responsible for tweening one property of one target.
34
// If a target has many properties being tweened, then each unique property will be its own Tween object.
@@ -22,27 +23,25 @@ var Tween = function (manager, target, key)
2223
this.data = [];
2324

2425
// Current TweenData being processed
25-
this.tween;
26+
this.currentTweenData = null;
2627

2728
// if true then duration, delay, etc values are all frame totals
2829
this.useFrames = false;
2930

30-
// infinitely loop this tween?
31+
// infinitely loop this tween? Maybe a string? 'alternate', 'reverse', etc
32+
// When enabled it will play through
3133
this.loop = false;
3234

35+
// Time in ms/frames before the tween loops again if loop is true
36+
this.loopDelay = 0;
37+
3338
// Time in ms/frames before the 'onComplete' event fires
34-
this.onCompleteDelay = 0;
39+
this.completeDelay = 0;
3540

36-
// Changes the property to be this before starting the tween
37-
this.startAt;
41+
// delta countdown timer
42+
this.countdown = 0;
3843

39-
// 0 = Waiting to be added to the TweenManager
40-
// 1 = Paused (dev needs to invoke Tween.start)
41-
// 2 = Started, but waiting for delay to expire
42-
// 3 = Playing Forwards
43-
// 4 = Playing Backwards
44-
// 5 = Completed
45-
this.state = 0;
44+
this.state = TWEEN_CONST.PENDING_ADD;
4645

4746
this.paused = false;
4847

@@ -62,6 +61,7 @@ Tween.prototype = {
6261

6362
init: require('./components/Init'),
6463
loadValues: require('./components/LoadValues'),
64+
playNext: require('./components/PlayNext'),
6565
setCurrentTweenData: require('./components/SetCurrentTweenData'),
6666
setEventCallback: require('./components/SetEventCallback'),
6767
start: require('./components/Start'),

v3/src/tween/TweenBuilder.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,15 @@ var TweenBuilder = function (manager, config)
152152
var defaultYoyo = GetValue(config, 'yoyo', false);
153153
var defaultRepeat = GetAdvancedValue(config, 'repeat', 0);
154154
var defaultRepeatDelay = GetAdvancedValue(config, 'repeatDelay', 0);
155-
var defaultCompleteDelay = GetAdvancedValue(config, 'completeDelay', 0);
156-
var defaultLoop = GetValue(config, 'loop', false);
157155
var defaultDelay = GetAdvancedValue(config, 'delay', 0);
156+
var defaultHold = GetAdvancedValue(config, 'hold', 0);
157+
var defaultStartAt = GetAdvancedValue(config, 'startAt', null);
158+
159+
var useFrames = GetValue(config, 'useFrames', false);
160+
161+
var loop = GetValue(config, 'loop', false);
162+
var loopDelay = GetAdvancedValue(config, 'loopDelay', 0);
163+
var completeDelay = GetAdvancedValue(config, 'completeDelay', 0);
158164

159165
for (var p = 0; p < props.length; p++)
160166
{
@@ -176,25 +182,29 @@ var TweenBuilder = function (manager, config)
176182

177183
// Set Tween properties (TODO: Callbacks)
178184

179-
tween.completeDelay = GetAdvancedValue(value, 'completeDelay', defaultCompleteDelay);
180-
tween.loop = GetValue(value, 'loop', defaultLoop);
185+
tween.useFrames = useFrames;
186+
tween.loop = loop;
187+
tween.loopDelay = loopDelay;
188+
tween.completeDelay = completeDelay;
181189

182190
// Build the TweenData
183191
for (var i = 0; i < values.length; i++)
184192
{
185193
var value = values[i];
186194

187195
// Set TweenData properties
188-
var valueOp = GetValueOp(target, key, value);
189196

190-
var ease = GetEaseFunction(GetValue(value, 'ease', defaultEase));
191-
var duration = GetAdvancedValue(value, 'duration', defaultDuration);
192-
var yoyo = GetValue(value, 'yoyo', defaultYoyo);
193-
var repeat = GetAdvancedValue(value, 'repeat', defaultRepeat);
194-
var repeatDelay = GetAdvancedValue(value, 'repeatDelay', defaultRepeatDelay);
195-
var delay = GetAdvancedValue(value, 'delay', defaultDelay);
196-
197-
var tweenData = TweenData(valueOp, ease, duration, yoyo, repeat, delay, repeatDelay);
197+
var tweenData = TweenData(
198+
GetValueOp(target, key, value),
199+
GetEaseFunction(GetValue(value, 'ease', defaultEase)),
200+
GetAdvancedValue(value, 'delay', defaultDelay),
201+
GetAdvancedValue(value, 'duration', defaultDuration),
202+
GetAdvancedValue(value, 'hold', defaultHold),
203+
GetAdvancedValue(value, 'repeat', defaultRepeat),
204+
GetAdvancedValue(value, 'repeatDelay', defaultRepeatDelay),
205+
GetAdvancedValue(value, 'startAt', defaultStartAt),
206+
GetValue(value, 'yoyo', defaultYoyo)
207+
);
198208

199209
tweenData.prev = prev;
200210

@@ -208,8 +218,6 @@ var TweenBuilder = function (manager, config)
208218
prev = tweenData;
209219
}
210220

211-
tween.current = tween.data[0];
212-
213221
tweens.push(tween);
214222

215223
manager.queue(tween);

v3/src/tween/TweenData.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var TweenData = function (value, ease, duration, yoyo, repeat, delay, repeatDelay)
1+
var TweenData = function (value, ease, delay, duration, hold, repeat, repeatDelay, startAt, yoyo)
22
{
33
return {
44

@@ -20,27 +20,25 @@ var TweenData = function (value, ease, duration, yoyo, repeat, delay, repeatDela
2020
// time in ms/frames before tween will start
2121
delay: delay,
2222

23+
// time in ms/frames the tween will remain in its end state before either yoyo, repeat or complete
24+
hold: hold,
25+
2326
// time in ms/frames before repeat will start
2427
repeatDelay: repeatDelay,
2528

29+
// Changes the property to be this value before starting the tween
30+
startAt: startAt,
31+
2632
// between 0 and 1 showing completion of this TweenData
2733
progress: 0,
2834

2935
// delta counter
3036
elapsed: 0,
3137

32-
// delta countdown timer
33-
countdown: 0,
34-
3538
// how many repeats are left to run?
3639
repeatCounter: 0,
3740

38-
// 0 = Waiting for Start
39-
// 1 = Waiting for countdown to expire
40-
// 2 = Started, waiting for next render to Load Values
41-
// 3 = Playing Forward
42-
// 4 = Playing Backwards
43-
// 5 = Completed
41+
// TWEEN_CONST.CREATED
4442
state: 0,
4543

4644
// For chained TweenData these point to the prev and next references

v3/src/tween/TweenManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
var EventDispatcher = require('../events/EventDispatcher');
33
var TweenBuilder = require('./TweenBuilder');
4+
var TWEEN_CONST = require('./const');
45

56
var TweenManager = function (state)
67
{

v3/src/tween/components/Init.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
var TWEEN_CONST = require('../const');
2+
3+
// Return true if this Tween should be moved from the pending list to the active list
14
var Init = function ()
25
{
3-
this.state = 1;
6+
if (this.paused)
7+
{
8+
this.state = TWEEN_CONST.PAUSED;
49

5-
return (!this.paused);
10+
return false;
11+
}
12+
else
13+
{
14+
return true;
15+
}
616
};
717

818
module.exports = Init;

v3/src/tween/components/LoadValues.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var LoadValues = function ()
22
{
33
this.start = this.target[this.key];
44
this.current = this.start;
5-
this.end = this.tween.value();
5+
this.end = this.currentTweenData.value();
66
};
77

88
module.exports = LoadValues;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var TWEEN_CONST = require('../const');
2+
3+
var PlayNext = function ()
4+
{
5+
// This is the TweenData that has just completed playing
6+
var tweenData = this.currentTweenData;
7+
8+
if (tweenData.next)
9+
{
10+
this.setCurrentTweenData(tweenData.next);
11+
}
12+
else if (this.loop)
13+
{
14+
this.setCurrentTweenData(this.data[0]);
15+
16+
if (this.loopDelay > 0)
17+
{
18+
this.countdown = this.loopDelay;
19+
this.state = TWEEN_CONST.LOOP_DELAY;
20+
}
21+
}
22+
else if (this.completeDelay > 0)
23+
{
24+
this.countdown = this.completeDelay;
25+
this.state = TWEEN_CONST.COMPLETE_DELAY;
26+
}
27+
else
28+
{
29+
this.state = TWEEN_CONST.PENDING_REMOVE;
30+
}
31+
};
32+
33+
module.exports = PlayNext;
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
var SetCurrentTweenData = function (tween)
1+
var TWEEN_CONST = require('../const');
2+
3+
var SetCurrentTweenData = function (tweenData)
24
{
3-
tween.progress = 0;
4-
tween.elapsed = 0;
5+
tweenData.progress = 0;
6+
tweenData.elapsed = 0;
57

6-
tween.repeatCounter = (tween.repeat === -1) ? Number.MAX_SAFE_INTEGER : tween.repeat;
8+
tweenData.repeatCounter = (tweenData.repeat === -1) ? Number.MAX_SAFE_INTEGER : tweenData.repeat;
79

8-
if (tween.delay > 0)
10+
if (tweenData.delay > 0)
911
{
10-
tween.countdown = tween.delay;
11-
tween.state = 1;
12+
tweenData.elapsed = tweenData.delay;
13+
tweenData.state = TWEEN_CONST.DELAY;
1214
}
1315
else
1416
{
15-
tween.state = 2;
17+
tweenData.state = TWEEN_CONST.PENDING_RENDER;
1618
}
1719

18-
this.tween = tween;
20+
this.currentTweenData = tweenData;
1921
};
2022

2123
module.exports = SetCurrentTweenData;

v3/src/tween/components/Start.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
var TWEEN_CONST = require('../const');
2+
13
var Start = function ()
24
{
3-
if (this.state !== 1)
5+
if (this.state === TWEEN_CONST.ACTIVE)
46
{
57
return;
68
}
79

10+
this.state = TWEEN_CONST.ACTIVE;
11+
812
this.setCurrentTweenData(this.data[0]);
913
};
1014

0 commit comments

Comments
 (0)