1. Sequence
Action sequences. When the operation performed in the order parameter, the total duration of operation of each of the operation and long.
1.1 member variables
* _Actions FiniteTimeAction [ 2 ]; a float _split; // first time in a proportion of action of Sequence int _last;
1.2 create method
Four kinds:
createWithTwoActions (FiniteTimeAction * actionOne, FiniteTimeAction * actionTwo) with two action // create the Create (FiniteTimeAction * action1, ...) // create a lot of action, call the following method createWithVariableList (FiniteTimeAction * action1, va_list args) the Create ( const Vector <FiniteTimeAction *> & arrayOfActions) // Vector container for storing the action as a parameter
createWithTwoActions:
Call initWithTwoActions method, the time of action and two as Sequence of duration, and two action retain ().
createWithVariableList:
Call createWithTwoActions method, the first parameter is an action parameter action, the second parameter is a variable length parameter action va_list args stored. When only one action, a second parameter is createWithTwoActions ExtraAction.
Sequence* Sequence::createWithVariableList(FiniteTimeAction *action1, va_list args) { FiniteTimeAction *now; FiniteTimeAction *prev = action1; bool bOneAction = true; while (action1) { now = va_arg(args, FiniteTimeAction*); if (now) { prev = createWithTwoActions(prev, now); bOneAction = false; } else { // If only one action is added to Sequence, make up a Sequence by adding a simplest finite time action. if (bOneAction) { prev = createWithTwoActions(prev, ExtraAction::create()); } break; } } return ((Sequence*)prev); }
create:
Use Vector storage action, calling the init method to create Sequence recursively.
s1 = a1 + a2 s2 = a3 + s1 s3 = a4 + s2 s4 = a5 + s3 ... Sequence finally obtained is a combination and sequence of action.
1.3 start with target
runAction when calling.
if (_duration > FLT_EPSILON) _split = _actions[0]->getDuration() > FLT_EPSILON ? _actions[0]->getDuration() / _duration : 0;
ActionInterval::startWithTarget(target);
_last = -1;
_duration and duration of action greater than the accuracy value FLT_EPSILON, an action of the first set time and total time series is commercially _split, representative of the proportion of time in the first action sequence.
_last action index is performed when the last sequence of update, 0 or 1, -1 yet update.
1.4 update
In short, update to be performed by the current progress to determine what action, first calculate the action of this progress. If this is the first implementation of the second action, we first have to complete the implementation of the first action update. Next, the execution of the action update, save the subscript after the execution of the execution, judge for the next frame.
Sequence execution and update startWithTarget Sequence recursive nested therein. Recursive exit condition is found == _last && _actions [found] -> isDone (), which is the last action execution completed.
. 1 void Sequence :: Update ( a float T) 2 { . 3 int found = 0 ; // this action index . 4 a float new_t = 0.0f ; // current action schedule . 5 . 6 IF (T <_split) // executing a first an action . 7 { . 8 // action [0] . 9 found = 0 ; // change the subscript 10 IF (_split =! 0 ) // time of the first action is not set to 0 . 11 T = new_t / _split; // calculating a first action schedule 12 is the else 13 is new_t = . 1 ; // time of the first action is set to 0, the completion of the first action 14 15 } 16 the else // executing a second two action . 17 { 18 is // action [. 1] . 19 found = . 1 ; // change the index 20 is IF (_split == . 1 ) // second time 0, the action 21 is new_t = . 1 ; // complete the second Action 22 the else 23 is new_t = (T-_split) / ( . 1 - _split); // calculate the second action schedule 24 } 25 26 is IF (found == . 1 ) // executing the second the Action 27 { 28 IF (== _last - . 1 ) // if the last update fails to perform a Action 29 { 30 // . Action [0] Skipped WAS, IT execute 31 is _actions [ 0 ] -> startWithTarget (_target); // initialize the first Action 32 IF (! (sendUpdateEventToScript ( 1.0f, _Actions [ 0 ]))) 33 is _actions [ 0 ] -> Update ( 1.0f ); // directly to complete the first Action 34 is _actions [ 0 ] -> STOP (); 35 } 36 the else IF (_last == 0 ) // last update is performed first Action, this second update execution, perform a completion of the first instructions 37 [ { 38 is // Switching to 1. Action Action of 0. the STOP 39 IF (! (sendUpdateEventToScript ( 1.0 F , _actions [ 0 ]))) 40 _actions [0 ] -> Update ( 1.0f ); // make the first implementation of the completion 41 is _actions [ 0 ] -> STOP (); 42 is } 43 is } 44 is the else IF (found == 0 && _last == . 1 ) // Basic does not occur in the 45 { 46 is // Reverse MODE? 47 // FIXME:. not contemplate the Bug When the this case does _last == -. 1, found = 0 and in "Reverse MODE" 48 // Operating since the require IT a Will Action to know IF AN hack IS ON Reverse the MODE or not. 49 // "step" should be overridden, and the "reverseMode" value propagated to inner Sequences. 50 if (!(sendUpdateEventToScript(0, _actions[1]))) 51 _actions[1]->update(0); 52 _actions[1]->stop(); 53 } 54 // Last action found and it is done. 55 if( found == _last && _actions[found]->isDone() ) 56 { 57 return; 58 } 59 60 if(Found = _last!) // normally perform a new action 61 is { 62 is _actions [found] -> startWithTarget (_target); // new initialization action 63 is } 64 IF (! (SendUpdateEventToScript (new_t, _actions [found])) ) 65 _actions [found] -> Update (new_t); // perform 66 _last = found; // Action recording the subscript performed 67 }