AnimationClip.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. #include "Base.h"
  2. #include "AnimationClip.h"
  3. #include "Animation.h"
  4. #include "AnimationTarget.h"
  5. #include "Game.h"
  6. #include "Quaternion.h"
  7. #include "ScriptController.h"
  8. namespace gameplay
  9. {
  10. AnimationClip::AnimationClip(const char* id, Animation* animation, unsigned long startTime, unsigned long endTime)
  11. : _id(id), _animation(animation), _startTime(startTime), _endTime(endTime), _duration(_endTime - _startTime),
  12. _stateBits(0x00), _repeatCount(1.0f), _loopBlendTime(0), _activeDuration(_duration * _repeatCount), _speed(1.0f), _timeStarted(0),
  13. _elapsedTime(0), _crossFadeToClip(NULL), _crossFadeOutElapsed(0), _crossFadeOutDuration(0), _blendWeight(1.0f),
  14. _beginListeners(NULL), _endListeners(NULL), _listeners(NULL), _listenerItr(NULL), _scriptListeners(NULL)
  15. {
  16. GP_ASSERT(_animation);
  17. GP_ASSERT(0 <= startTime && startTime <= _animation->_duration && 0 <= endTime && endTime <= _animation->_duration);
  18. for (size_t i = 0, count = _animation->_channels.size(); i < count; i++)
  19. {
  20. GP_ASSERT(_animation->_channels[i]);
  21. GP_ASSERT(_animation->_channels[i]->getCurve());
  22. _values.push_back(new AnimationValue(_animation->_channels[i]->getCurve()->getComponentCount()));
  23. }
  24. }
  25. AnimationClip::~AnimationClip()
  26. {
  27. std::vector<AnimationValue*>::iterator valueIter = _values.begin();
  28. while (valueIter != _values.end())
  29. {
  30. SAFE_DELETE(*valueIter);
  31. valueIter++;
  32. }
  33. _values.clear();
  34. SAFE_RELEASE(_crossFadeToClip);
  35. SAFE_DELETE(_beginListeners);
  36. SAFE_DELETE(_endListeners);
  37. if (_scriptListeners)
  38. {
  39. for (size_t i = 0; i < _scriptListeners->size(); i++)
  40. {
  41. SAFE_DELETE((*_scriptListeners)[i]);
  42. }
  43. SAFE_DELETE(_scriptListeners);
  44. }
  45. if (_listeners)
  46. {
  47. *_listenerItr = _listeners->begin();
  48. while (*_listenerItr != _listeners->end())
  49. {
  50. ListenerEvent* lEvt = **_listenerItr;
  51. SAFE_DELETE(lEvt);
  52. ++*_listenerItr;
  53. }
  54. SAFE_DELETE(_listeners);
  55. }
  56. SAFE_DELETE(_listenerItr);
  57. }
  58. AnimationClip::ListenerEvent::ListenerEvent(Listener* listener, unsigned long eventTime)
  59. {
  60. _listener = listener;
  61. _eventTime = eventTime;
  62. }
  63. AnimationClip::ListenerEvent::~ListenerEvent()
  64. {
  65. }
  66. const char* AnimationClip::getId() const
  67. {
  68. return _id.c_str();
  69. }
  70. Animation* AnimationClip::getAnimation() const
  71. {
  72. return _animation;
  73. }
  74. unsigned long AnimationClip::getStartTime() const
  75. {
  76. return _startTime;
  77. }
  78. unsigned long AnimationClip::getEndTime() const
  79. {
  80. return _endTime;
  81. }
  82. float AnimationClip::getElapsedTime() const
  83. {
  84. return _elapsedTime;
  85. }
  86. void AnimationClip::setRepeatCount(float repeatCount)
  87. {
  88. GP_ASSERT(repeatCount == REPEAT_INDEFINITE || repeatCount > 0.0f);
  89. _repeatCount = repeatCount;
  90. if (repeatCount == REPEAT_INDEFINITE)
  91. {
  92. _activeDuration = _duration + _loopBlendTime;
  93. }
  94. else
  95. {
  96. _activeDuration = _duration * _repeatCount;
  97. if (repeatCount > 1.0f && _loopBlendTime > 0.0f)
  98. _activeDuration += std::ceil(repeatCount - 1.0f) * _loopBlendTime;
  99. }
  100. }
  101. float AnimationClip::getRepeatCount() const
  102. {
  103. return _repeatCount;
  104. }
  105. void AnimationClip::setActiveDuration(unsigned long duration)
  106. {
  107. GP_ASSERT(duration > 0.0f);
  108. if (duration == REPEAT_INDEFINITE)
  109. {
  110. _activeDuration = _duration + _loopBlendTime;
  111. }
  112. else
  113. {
  114. _activeDuration = duration;
  115. _repeatCount = (float)_activeDuration / (float)_duration;
  116. }
  117. }
  118. unsigned long AnimationClip::getActiveDuration() const
  119. {
  120. if (_repeatCount == REPEAT_INDEFINITE)
  121. return REPEAT_INDEFINITE;
  122. return _activeDuration;
  123. }
  124. unsigned long AnimationClip::getDuration() const
  125. {
  126. return _duration;
  127. }
  128. void AnimationClip::setSpeed(float speed)
  129. {
  130. _speed = speed;
  131. }
  132. float AnimationClip::getSpeed() const
  133. {
  134. return _speed;
  135. }
  136. void AnimationClip::setBlendWeight(float blendWeight)
  137. {
  138. _blendWeight = blendWeight;
  139. }
  140. float AnimationClip::getBlendWeight() const
  141. {
  142. return _blendWeight;
  143. }
  144. void AnimationClip::setLoopBlendTime(float loopBlendTime)
  145. {
  146. _loopBlendTime = loopBlendTime;
  147. if (_loopBlendTime < 0.0f)
  148. _loopBlendTime = 0.0f;
  149. }
  150. float AnimationClip::getLoopBlendTime() const
  151. {
  152. return _loopBlendTime;
  153. }
  154. bool AnimationClip::isPlaying() const
  155. {
  156. return (isClipStateBitSet(CLIP_IS_PLAYING_BIT) && !isClipStateBitSet(CLIP_IS_PAUSED_BIT));
  157. }
  158. void AnimationClip::play()
  159. {
  160. if (isClipStateBitSet(CLIP_IS_PLAYING_BIT))
  161. {
  162. // If paused, reset the bit and return.
  163. if (isClipStateBitSet(CLIP_IS_PAUSED_BIT))
  164. {
  165. resetClipStateBit(CLIP_IS_PAUSED_BIT);
  166. return;
  167. }
  168. // If the clip is set to be removed, reset the flag.
  169. if (isClipStateBitSet(CLIP_IS_MARKED_FOR_REMOVAL_BIT))
  170. resetClipStateBit(CLIP_IS_MARKED_FOR_REMOVAL_BIT);
  171. // Set the state bit to restart.
  172. setClipStateBit(CLIP_IS_RESTARTED_BIT);
  173. }
  174. else
  175. {
  176. setClipStateBit(CLIP_IS_PLAYING_BIT);
  177. GP_ASSERT(_animation);
  178. GP_ASSERT(_animation->_controller);
  179. _animation->_controller->schedule(this);
  180. }
  181. _timeStarted = Game::getGameTime();
  182. }
  183. void AnimationClip::stop()
  184. {
  185. if (isClipStateBitSet(CLIP_IS_PLAYING_BIT))
  186. {
  187. // Reset the restarted and paused bits.
  188. resetClipStateBit(CLIP_IS_RESTARTED_BIT);
  189. resetClipStateBit(CLIP_IS_PAUSED_BIT);
  190. // Mark the clip to removed from the AnimationController.
  191. setClipStateBit(CLIP_IS_MARKED_FOR_REMOVAL_BIT);
  192. }
  193. }
  194. void AnimationClip::pause()
  195. {
  196. if (isClipStateBitSet(CLIP_IS_PLAYING_BIT) && !isClipStateBitSet(CLIP_IS_MARKED_FOR_REMOVAL_BIT))
  197. {
  198. setClipStateBit(CLIP_IS_PAUSED_BIT);
  199. }
  200. }
  201. void AnimationClip::crossFade(AnimationClip* clip, unsigned long duration)
  202. {
  203. GP_ASSERT(clip);
  204. // Check if the given clip is fading into this clip.
  205. // We should reset the clip from fading out, and this one from fading in
  206. // in order to start the crossfade back the other way.
  207. if (clip->isClipStateBitSet(CLIP_IS_FADING_OUT_BIT) && clip->_crossFadeToClip == this)
  208. {
  209. clip->resetClipStateBit(CLIP_IS_FADING_OUT_BIT);
  210. clip->_crossFadeToClip->resetClipStateBit(CLIP_IS_FADING_IN_BIT);
  211. SAFE_RELEASE(clip->_crossFadeToClip);
  212. }
  213. // If I already have a clip I'm fading to and it's not the same as the given clip release it.
  214. // Assign the new clip and increase it's ref count.
  215. if (_crossFadeToClip)
  216. {
  217. SAFE_RELEASE(_crossFadeToClip);
  218. }
  219. // Set and initialize the crossfade clip
  220. _crossFadeToClip = clip;
  221. _crossFadeToClip->addRef();
  222. _crossFadeToClip->setClipStateBit(CLIP_IS_FADING_IN_BIT);
  223. _crossFadeToClip->_blendWeight = 0.0f;
  224. // Set and initialize this clip to fade out
  225. setClipStateBit(CLIP_IS_FADING_OUT_STARTED_BIT);
  226. setClipStateBit(CLIP_IS_FADING_OUT_BIT);
  227. _crossFadeOutElapsed = 0.0f;
  228. _crossFadeOutDuration = duration;
  229. // If this clip is currently not playing, we should start playing it.
  230. if (!isClipStateBitSet(CLIP_IS_PLAYING_BIT))
  231. play();
  232. // Start playing the cross fade clip.
  233. _crossFadeToClip->play();
  234. }
  235. void AnimationClip::addListener(AnimationClip::Listener* listener, unsigned long eventTime)
  236. {
  237. GP_ASSERT(listener);
  238. GP_ASSERT(eventTime < _activeDuration);
  239. ListenerEvent* listenerEvent = new ListenerEvent(listener, eventTime);
  240. if (!_listeners)
  241. {
  242. _listeners = new std::list<ListenerEvent*>;
  243. _listeners->push_front(listenerEvent);
  244. _listenerItr = new std::list<ListenerEvent*>::iterator;
  245. if (isClipStateBitSet(CLIP_IS_PLAYING_BIT))
  246. *_listenerItr = _listeners->begin();
  247. }
  248. else
  249. {
  250. for (std::list<ListenerEvent*>::iterator itr = _listeners->begin(); itr != _listeners->end(); itr++)
  251. {
  252. GP_ASSERT(*itr);
  253. if (eventTime < (*itr)->_eventTime)
  254. {
  255. itr = _listeners->insert(itr, listenerEvent);
  256. // If playing, update the iterator if we need to.
  257. // otherwise, it will just be set the next time the clip gets played.
  258. if (isClipStateBitSet(CLIP_IS_PLAYING_BIT))
  259. {
  260. float currentTime = fmodf(_elapsedTime, (float)_duration);
  261. GP_ASSERT(**_listenerItr || *_listenerItr == _listeners->end());
  262. if ((_speed >= 0.0f && currentTime < eventTime && (*_listenerItr == _listeners->end() || eventTime < (**_listenerItr)->_eventTime)) ||
  263. (_speed <= 0 && currentTime > eventTime && (*_listenerItr == _listeners->begin() || eventTime > (**_listenerItr)->_eventTime)))
  264. *_listenerItr = itr;
  265. }
  266. return;
  267. }
  268. }
  269. _listeners->push_back(listenerEvent);
  270. }
  271. }
  272. void AnimationClip::addBeginListener(AnimationClip::Listener* listener)
  273. {
  274. if (!_beginListeners)
  275. _beginListeners = new std::vector<Listener*>;
  276. GP_ASSERT(listener);
  277. _beginListeners->push_back(listener);
  278. }
  279. void AnimationClip::addEndListener(AnimationClip::Listener* listener)
  280. {
  281. if (!_endListeners)
  282. _endListeners = new std::vector<Listener*>;
  283. GP_ASSERT(listener);
  284. _endListeners->push_back(listener);
  285. }
  286. void AnimationClip::addBeginListener(const char* function)
  287. {
  288. if (!_scriptListeners)
  289. _scriptListeners = new std::vector<ScriptListener*>;
  290. ScriptListener* listener = new ScriptListener(function);
  291. _scriptListeners->push_back(listener);
  292. addBeginListener(listener);
  293. }
  294. void AnimationClip::addEndListener(const char* function)
  295. {
  296. if (!_scriptListeners)
  297. _scriptListeners = new std::vector<ScriptListener*>;
  298. ScriptListener* listener = new ScriptListener(function);
  299. _scriptListeners->push_back(listener);
  300. addEndListener(listener);
  301. }
  302. void AnimationClip::addListener(const char* function, unsigned long eventTime)
  303. {
  304. if (!_scriptListeners)
  305. _scriptListeners = new std::vector<ScriptListener*>;
  306. ScriptListener* listener = new ScriptListener(function);
  307. _scriptListeners->push_back(listener);
  308. addListener(listener, eventTime);
  309. }
  310. bool AnimationClip::update(float elapsedTime)
  311. {
  312. if (isClipStateBitSet(CLIP_IS_PAUSED_BIT))
  313. {
  314. return false;
  315. }
  316. if (isClipStateBitSet(CLIP_IS_MARKED_FOR_REMOVAL_BIT))
  317. {
  318. // If the marked for removal bit is set, it means stop() was called on the AnimationClip at some point
  319. // after the last update call. Reset the flag, and return true so the AnimationClip is removed from the
  320. // running clips on the AnimationController.
  321. onEnd();
  322. return true;
  323. }
  324. if (!isClipStateBitSet(CLIP_IS_STARTED_BIT))
  325. {
  326. // Clip is just starting
  327. onBegin();
  328. }
  329. else
  330. {
  331. // Clip was already running
  332. _elapsedTime += elapsedTime * _speed;
  333. if (_repeatCount == REPEAT_INDEFINITE && _elapsedTime <= 0)
  334. {
  335. // Elapsed time is moving backwards, so wrap it back around the end when it falls below zero
  336. _elapsedTime = _activeDuration + _elapsedTime;
  337. // TODO: account for _loopBlendTime
  338. }
  339. }
  340. // Current time within a loop of the clip
  341. float currentTime = 0.0f;
  342. // Check to see if clip is complete.
  343. if (_repeatCount != REPEAT_INDEFINITE && ((_speed >= 0.0f && _elapsedTime >= _activeDuration) || (_speed <= 0.0f && _elapsedTime <= 0.0f)))
  344. {
  345. // We finished our active duration (including repeats), so clamp to our end value.
  346. resetClipStateBit(CLIP_IS_STARTED_BIT);
  347. // Ensure we end off at the endpoints of our clip (-speed==0, +speed==_duration)
  348. currentTime = _speed < 0.0f ? 0.0f : _duration;
  349. }
  350. else
  351. {
  352. // If _duration == 0, we have a "pose". Just set currentTime to 0.
  353. if (_duration == 0)
  354. {
  355. currentTime = 0.0f;
  356. }
  357. else
  358. {
  359. // Animation is running normally.
  360. currentTime = fmodf(_elapsedTime, _duration + _loopBlendTime);
  361. }
  362. }
  363. // Notify any listeners of Animation events.
  364. if (_listeners)
  365. {
  366. GP_ASSERT(_listenerItr);
  367. if (_speed >= 0.0f)
  368. {
  369. while (*_listenerItr != _listeners->end() && _elapsedTime >= (long) (**_listenerItr)->_eventTime)
  370. {
  371. GP_ASSERT(_listenerItr);
  372. GP_ASSERT(**_listenerItr);
  373. GP_ASSERT((**_listenerItr)->_listener);
  374. (**_listenerItr)->_listener->animationEvent(this, Listener::TIME);
  375. ++*_listenerItr;
  376. }
  377. }
  378. else
  379. {
  380. while (*_listenerItr != _listeners->begin() && _elapsedTime <= (long) (**_listenerItr)->_eventTime)
  381. {
  382. GP_ASSERT(_listenerItr);
  383. GP_ASSERT(**_listenerItr);
  384. GP_ASSERT((**_listenerItr)->_listener);
  385. (**_listenerItr)->_listener->animationEvent(this, Listener::TIME);
  386. --*_listenerItr;
  387. }
  388. }
  389. }
  390. // Add back in start time, and divide by the total animation's duration to get the actual percentage complete
  391. GP_ASSERT(_animation);
  392. // Compute percentage complete for the current loop (prevent a divide by zero if _duration==0).
  393. // Note that we don't use (currentTime/(_duration+_loopBlendTime)). That's because we want a
  394. // % value that is outside the 0-1 range for loop smoothing/blending purposes.
  395. float percentComplete = _duration == 0 ? 1 : currentTime / (float)_duration;
  396. if (_loopBlendTime == 0.0f)
  397. percentComplete = MATH_CLAMP(percentComplete, 0.0f, 1.0f);
  398. // If we're cross fading, compute blend weights
  399. if (isClipStateBitSet(CLIP_IS_FADING_OUT_BIT))
  400. {
  401. GP_ASSERT(_crossFadeToClip);
  402. GP_ASSERT(_crossFadeOutDuration > 0);
  403. if (isClipStateBitSet(CLIP_IS_FADING_OUT_STARTED_BIT)) // Calculate elapsed time since the fade out begin.
  404. {
  405. GP_ASSERT(_crossFadeToClip);
  406. _crossFadeOutElapsed = (Game::getGameTime() - _crossFadeToClip->_timeStarted) * fabs(_speed);
  407. resetClipStateBit(CLIP_IS_FADING_OUT_STARTED_BIT);
  408. }
  409. else
  410. {
  411. // continue tracking elapsed time.
  412. _crossFadeOutElapsed += elapsedTime * fabs(_speed);
  413. }
  414. if (_crossFadeOutElapsed < _crossFadeOutDuration)
  415. {
  416. // Calculate this clip's blend weight.
  417. float tempBlendWeight = ((float)_crossFadeOutDuration - _crossFadeOutElapsed) / (float)_crossFadeOutDuration;
  418. // If this clip is fading in, adjust the crossfade clip's weight to be a percentage of your current blend weight
  419. if (isClipStateBitSet(CLIP_IS_FADING_IN_BIT))
  420. {
  421. _crossFadeToClip->_blendWeight = (1.0f - tempBlendWeight) * _blendWeight;
  422. _blendWeight -= _crossFadeToClip->_blendWeight;
  423. }
  424. else
  425. {
  426. // Just set the blend weight.
  427. _crossFadeToClip->_blendWeight = (1.0f - tempBlendWeight);
  428. _blendWeight = tempBlendWeight;
  429. }
  430. }
  431. else
  432. {
  433. // Fade is done.
  434. _crossFadeToClip->_blendWeight = 1.0f;
  435. _blendWeight = 0.0f;
  436. resetClipStateBit(CLIP_IS_STARTED_BIT);
  437. resetClipStateBit(CLIP_IS_FADING_OUT_BIT);
  438. _crossFadeToClip->resetClipStateBit(CLIP_IS_FADING_IN_BIT);
  439. SAFE_RELEASE(_crossFadeToClip);
  440. }
  441. }
  442. // Evaluate this clip.
  443. Animation::Channel* channel = NULL;
  444. AnimationValue* value = NULL;
  445. AnimationTarget* target = NULL;
  446. size_t channelCount = _animation->_channels.size();
  447. float percentageStart = (float)_startTime / (float)_animation->_duration;
  448. float percentageEnd = (float)_endTime / (float)_animation->_duration;
  449. float percentageBlend = (float)_loopBlendTime / (float)_animation->_duration;
  450. for (size_t i = 0; i < channelCount; i++)
  451. {
  452. channel = _animation->_channels[i];
  453. GP_ASSERT(channel);
  454. target = channel->_target;
  455. GP_ASSERT(target);
  456. value = _values[i];
  457. GP_ASSERT(value);
  458. // Evaluate the point on Curve
  459. GP_ASSERT(channel->getCurve());
  460. channel->getCurve()->evaluate(percentComplete, percentageStart, percentageEnd, percentageBlend, value->_value);
  461. // Set the animation value on the target property.
  462. target->setAnimationPropertyValue(channel->_propertyId, value, _blendWeight);
  463. }
  464. // When ended. Probably should move to it's own method so we can call it when the clip is ended early.
  465. if (isClipStateBitSet(CLIP_IS_MARKED_FOR_REMOVAL_BIT) || !isClipStateBitSet(CLIP_IS_STARTED_BIT))
  466. {
  467. onEnd();
  468. return true;
  469. }
  470. return false;
  471. }
  472. void AnimationClip::onBegin()
  473. {
  474. addRef();
  475. // Initialize animation to play.
  476. setClipStateBit(CLIP_IS_STARTED_BIT);
  477. if (_speed >= 0)
  478. {
  479. _elapsedTime = (Game::getGameTime() - _timeStarted) * _speed;
  480. if (_listeners)
  481. *_listenerItr = _listeners->begin();
  482. }
  483. else
  484. {
  485. _elapsedTime = _activeDuration + (Game::getGameTime() - _timeStarted) * _speed;
  486. if (_listeners)
  487. *_listenerItr = _listeners->end();
  488. }
  489. // Notify begin listeners if any.
  490. if (_beginListeners)
  491. {
  492. std::vector<Listener*>::iterator listener = _beginListeners->begin();
  493. while (listener != _beginListeners->end())
  494. {
  495. GP_ASSERT(*listener);
  496. (*listener)->animationEvent(this, Listener::BEGIN);
  497. listener++;
  498. }
  499. }
  500. release();
  501. }
  502. void AnimationClip::onEnd()
  503. {
  504. addRef();
  505. _blendWeight = 1.0f;
  506. resetClipStateBit(CLIP_ALL_BITS);
  507. // Notify end listeners if any.
  508. if (_endListeners)
  509. {
  510. std::vector<Listener*>::iterator listener = _endListeners->begin();
  511. while (listener != _endListeners->end())
  512. {
  513. GP_ASSERT(*listener);
  514. (*listener)->animationEvent(this, Listener::END);
  515. listener++;
  516. }
  517. }
  518. release();
  519. }
  520. bool AnimationClip::isClipStateBitSet(unsigned char bit) const
  521. {
  522. return (_stateBits & bit) == bit;
  523. }
  524. void AnimationClip::setClipStateBit(unsigned char bit)
  525. {
  526. _stateBits |= bit;
  527. }
  528. void AnimationClip::resetClipStateBit(unsigned char bit)
  529. {
  530. _stateBits &= ~bit;
  531. }
  532. AnimationClip* AnimationClip::clone(Animation* animation) const
  533. {
  534. // Don't clone the elapsed time, listeners or crossfade information.
  535. AnimationClip* newClip = new AnimationClip(getId(), animation, getStartTime(), getEndTime());
  536. newClip->setSpeed(getSpeed());
  537. newClip->setRepeatCount(getRepeatCount());
  538. newClip->setBlendWeight(getBlendWeight());
  539. size_t size = _values.size();
  540. newClip->_values.resize(size, NULL);
  541. for (size_t i = 0; i < size; ++i)
  542. {
  543. if (newClip->_values[i] == NULL)
  544. {
  545. newClip->_values[i] = new AnimationValue(*_values[i]);
  546. }
  547. else
  548. {
  549. *newClip->_values[i] = *_values[i];
  550. }
  551. }
  552. return newClip;
  553. }
  554. AnimationClip::ScriptListener::ScriptListener(const std::string& function)
  555. {
  556. // Store the function name.
  557. this->function = Game::getInstance()->getScriptController()->loadUrl(function.c_str());
  558. }
  559. void AnimationClip::ScriptListener::animationEvent(AnimationClip* clip, EventType type)
  560. {
  561. Game::getInstance()->getScriptController()->executeFunction<void>(function.c_str(), "<AnimationClip>[AnimationClip::Listener::EventType]", clip, type);
  562. }
  563. }