Animation.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. //============================================================================================
  2. // Spirenkov Maxim, 2004
  3. //============================================================================================
  4. // Animation service
  5. //============================================================================================
  6. // Animation
  7. //============================================================================================
  8. #include "Animation.h"
  9. #include "AnimationService.h"
  10. //============================================================================================
  11. Animation::Animation(AnxData & data, AnimationService & aserv, AnimationScene & ascene,
  12. const char * _name, const char * _cppFile, long _cppLine) : animation(data),
  13. service(aserv),
  14. scene(ascene),
  15. stages(_FL_),
  16. events(_FL_)
  17. {
  18. #ifndef _XBOX
  19. #ifndef NO_TOOLS
  20. isBlockControl = 0;
  21. #endif
  22. #endif
  23. isPause = 0;
  24. animation.SetAnimationExecuteEvent(Event, this);
  25. name = _name;
  26. refCounter = 1;
  27. timeEvent = null;
  28. updateStageIndex = -1;
  29. timeEventStep = 0.05f;
  30. currentHandler = -1;
  31. kSpeed = 1.0f;
  32. cppFile = _cppFile;
  33. cppLine = _cppLine;
  34. Pause(false);
  35. }
  36. Animation::~Animation()
  37. {
  38. scene.Delete(this);
  39. Assert(refCounter == 0);
  40. while(stages > 0)
  41. {
  42. IAniBlendStage * stage = stages[stages - 1].stage;
  43. UnregistryBlendStage(stage);
  44. RemoveAnimationFromBlendStage(stage);
  45. }
  46. EventHandler * evs = events.GetBuffer();
  47. long evsCount = events.Size();
  48. for(long i = 0; i < evsCount; i++)
  49. {
  50. if(!evs[i].listener) continue;
  51. RemoveAnimationFromListener(evs[i].listener);
  52. for(long j = i + 1; j < evsCount; j++)
  53. {
  54. if(evs[i].listener == evs[j].listener)
  55. {
  56. evs[j].listener = null;
  57. }
  58. }
  59. }
  60. events.Empty();
  61. service.ReleaseData(&animation.data);
  62. }
  63. //============================================================================================
  64. //Управление копиями
  65. //============================================================================================
  66. //Копировать интерфейс
  67. IAnimationTransform * Animation::Clone()
  68. {
  69. refCounter++;
  70. return this;
  71. }
  72. //Удалить интерфейс
  73. void Animation::Release()
  74. {
  75. refCounter--;
  76. if(refCounter <= 0)
  77. {
  78. delete this;
  79. }
  80. }
  81. //Удалить интерфейс принудительно
  82. void Animation::ForceRelease()
  83. {
  84. api->Trace("Animation -> Don't release animation (cpp: %s, %u)", cppFile, cppLine);
  85. refCounter = 1;
  86. Release();
  87. }
  88. //============================================================================================
  89. //Управление проигрыванием
  90. //============================================================================================
  91. //Начать проигрывание анимации с заданного нода
  92. bool Animation::Start(const char * nodeName, bool isInstant)
  93. {
  94. if(IsBlockControl()) return false;
  95. const char * nameId = null;
  96. if(nodeName)
  97. {
  98. nameId = animation.GetConstData().GetHeader().FindName(nodeName, AnxFndName::f_node);
  99. if(!nameId)
  100. {
  101. return false;
  102. }
  103. }
  104. if(!isInstant)
  105. {
  106. isPause &= ~pf_stopnode;
  107. scene.Command_Pause(this, isPause != 0);
  108. scene.Command_Start(this, nameId);
  109. }else{
  110. service.ThreadRemoveAnimationToUpdate(this);
  111. return animation.Start(nameId);
  112. }
  113. return true;
  114. }
  115. //Перейти на заданный нод с текущего
  116. bool Animation::Goto(const char * nodeName, float blendTime)
  117. {
  118. if(IsBlockControl()) return false;
  119. const char * nameId = animation.GetConstData().GetHeader().FindName(nodeName, AnxFndName::f_node);
  120. if(!nameId)
  121. {
  122. return false;
  123. }
  124. isPause &= ~pf_stopnode;
  125. scene.Command_Pause(this, isPause != 0);
  126. scene.Command_Goto(this, nameId, blendTime, -1);
  127. return true;
  128. }
  129. //Активировать линк
  130. bool Animation::ActivateLink(const char * command, bool forceApply)
  131. {
  132. if(IsBlockControl()) return false;
  133. if(animation.CurrentNodeIsStop())
  134. {
  135. api->Error("Animation <%s>: link not been activated, animation not on stop node!\n Link: %s", GetName(), command ? command : "<null>");
  136. return false;
  137. }
  138. if(string::IsEmpty(command))
  139. {
  140. api->Error("Animation <%s>: link not been activated, it name is empty!\n Link: %s", GetName(), command ? command : "<null>");
  141. return false;
  142. }
  143. const char * nameId = animation.GetConstData().GetHeader().FindName(command, AnxFndName::f_link);
  144. if(!nameId)
  145. {
  146. api->Error("Animation <%s>: link not been activated, link name is invalidate for this animation!\n Link: %s", GetName(), command ? command : "<null>");
  147. return false;
  148. }
  149. scene.Command_ActivateLink(this, nameId, forceApply);
  150. return animation.ActivateLink(nameId, false, true);
  151. }
  152. //Проверить, можно ли в текущий момент активировать линк
  153. bool Animation::IsCanActivateLink(const char * command)
  154. {
  155. if(IsBlockControl()) return false;
  156. if(animation.CurrentNodeIsStop())
  157. {
  158. return false;
  159. }
  160. const char * nameId = animation.GetConstData().GetHeader().FindName(command, AnxFndName::f_link);
  161. return animation.ActivateLink(nameId, false, true);
  162. }
  163. //Установить анимацию на паузу
  164. void Animation::Pause(bool isPause)
  165. {
  166. if(IsBlockControl()) return;
  167. if(isPause)
  168. {
  169. this->isPause |= pf_pause;
  170. }else{
  171. this->isPause &= ~pf_pause;
  172. }
  173. scene.Command_Pause(this, isPause);
  174. }
  175. //Анимацию на паузе или работает
  176. bool Animation::IsPause()
  177. {
  178. return (isPause & pf_pause) != 0;
  179. }
  180. //Являеться ли текущий нод стоповым
  181. bool Animation::CurrentNodeIsStop()
  182. {
  183. if(IsBlockControl()) return false;
  184. return animation.CurrentNodeIsStop();
  185. }
  186. //Установить скорость проигрывания анимации
  187. void Animation::SetPlaySpeed(float k)
  188. {
  189. if(IsBlockControl()) return;
  190. kSpeed = Clampf(k, 0.0f, 10.0f);
  191. }
  192. //Получить скорость проигрывания анимации
  193. float Animation::GetPlaySpeed()
  194. {
  195. return kSpeed;
  196. }
  197. //Обновить анимацию
  198. void Animation::UpdateAnimation(float dltTime)
  199. {
  200. // Assert(!isPause);
  201. if(animation.CurrentNodeIsStop())
  202. {
  203. animation.Update(0.0f);
  204. this->isPause |= pf_stopnode;
  205. scene.Command_Pause(this, isPause != 0);
  206. return;
  207. }
  208. dltTime *= kSpeed;
  209. if(dltTime <= 1e-35f)
  210. {
  211. return;
  212. }
  213. animation.Update(dltTime);
  214. }
  215. //Обновить стадии блендинга
  216. void Animation::UpdateStages(float dltTime)
  217. {
  218. // Assert(!isPause);
  219. dltTime *= kSpeed;
  220. if(dltTime <= 1e-35f)
  221. {
  222. return;
  223. }
  224. for(updateStageIndex = 0; updateStageIndex < stages; updateStageIndex++)
  225. {
  226. stages[updateStageIndex].stage->Update(dltTime);
  227. }
  228. }
  229. //Выбрать случайную позицию проигрывания
  230. void Animation::RandomizePosition()
  231. {
  232. scene.Command_RandomizePosition(this);
  233. }
  234. //Разослать события
  235. void Animation::SendEvents()
  236. {
  237. // Assert(!isPause);
  238. for(long i = 0; i < animation.events; i++)
  239. {
  240. AnxEvent & evt = *animation.events[i];
  241. //Ищим принимателей события
  242. const char * name = evt.name.ptr;
  243. for(currentHandler = 0; currentHandler < events; currentHandler++)
  244. {
  245. EventHandler & eh = events[currentHandler];
  246. if(eh.eventName == name)
  247. {
  248. (eh.listener->*eh.func)(this, name, evt.params.ptr, evt.numParams);
  249. }
  250. }
  251. }
  252. animation.events.Empty();
  253. }
  254. //============================================================================================
  255. //Утилитные функции
  256. //============================================================================================
  257. //Получить имя текущего нода
  258. const char * Animation::CurrentNode()
  259. {
  260. return animation.CurrentNode();
  261. }
  262. //Доступиться до константы типа string
  263. const char * Animation::GetConstString(const char * constName, const char * nodeName)
  264. {
  265. return animation.GetConstString(constName, nodeName);
  266. }
  267. //Доступиться до константы типа float
  268. float Animation::GetConstFloat(const char * constName, const char * nodeName)
  269. {
  270. return animation.GetConstFloat(constName, nodeName);
  271. }
  272. //Доступиться до константы типа blend
  273. float Animation::GetConstBlend(const char * constName)
  274. {
  275. return animation.GetConstBlend(constName);
  276. }
  277. //Получить имя анимации
  278. const char * Animation::GetName()
  279. {
  280. return name.c_str();
  281. }
  282. //Получить внутреннюю информацию графа
  283. bool Animation::GetNativeGraphInfo(GraphNativeAccessor & accessor) const
  284. {
  285. switch(accessor.GetType())
  286. {
  287. case agna_global:
  288. return SetNativeInfoGlobal((AGNA_GlobalInfo &)accessor);
  289. case agna_node_by_name:
  290. return SetNativeInfoNodeByName((AGNA_NodeInfo &)accessor);
  291. case agna_node_by_index:
  292. return SetNativeInfoNodeByIndex((AGNA_NodeInfo &)accessor);
  293. case agna_link:
  294. return SetNativeInfoLink((AGNA_LinkInfo &)accessor);
  295. case agna_clip:
  296. return SetNativeInfoClip((AGNA_ClipInfo &)accessor);
  297. case agna_event:
  298. return SetNativeInfoEvent((AGNA_EventInfo &)accessor);
  299. case agna_global_event:
  300. return SetNativeInfoEvent((AGNA_GlobalEventInfo &)accessor);
  301. case agna_get_frame:
  302. return SetNativeInfoCurrentFrameGet((AGNA_GetCurrentFrame &)accessor);
  303. case agna_set_frame:
  304. return SetNativeInfoCurrentFrameSet((AGNA_SetCurrentFrame &)accessor);
  305. case agna_get_number_of_frames:
  306. return SetNativeInfoNumberOfFrames((AGNA_GetNumberOfFrames &)accessor);
  307. case agna_is_bone_use_global_pos:
  308. return SetNativeInfoIsBoneUseGlobalPos((AGNA_IsBoneUseGlobalPos &)accessor);
  309. case agna_set_fps:
  310. return SetNativeInfoSetFPS((AGNA_SetFPS &)accessor);
  311. case agna_goto_nodeclip:
  312. return SetNativeGotoNodeClip((AGNA_GotoNodeClip &)accessor);
  313. case agna_pause:
  314. return SetNativePause((AGNA_AnimationPause &)accessor);
  315. case agna_block_control:
  316. return SetNativeBlockControl((AGNA_BlockControl &)accessor);
  317. };
  318. return false;
  319. }
  320. //============================================================================================
  321. //Доступ к костям анимации
  322. //============================================================================================
  323. //Получить количество костей в анимации
  324. long Animation::GetNumBones()
  325. {
  326. return animation.GetNumBones();
  327. }
  328. //Получить имя кости
  329. const char * Animation::GetBoneName(long index)
  330. {
  331. return animation.GetBoneName(index);
  332. }
  333. //Получить индекс родительской кости
  334. long Animation::GetBoneParent(long index)
  335. {
  336. return animation.GetBoneParent(index);
  337. }
  338. //Найти по имени кость
  339. long Animation::FindBone(const char * boneName, bool shortName)
  340. {
  341. return animation.FindBone(boneName, shortName);
  342. }
  343. //Найти по имени кость (короткое имя)
  344. long Animation::FindBoneUseHash(const char * boneName, dword hash)
  345. {
  346. return animation.FindBoneUseHash(boneName, (unsigned long)hash);
  347. }
  348. //Получить текущее в анимации сотояние кости
  349. void Animation::GetAnimationBone(long index, Quaternion & q, Vector & p)
  350. {
  351. animation.GetAnimationBone(index, q, p);
  352. }
  353. //Получить ориентацию кости с учётом блендеров, без иерархии
  354. const Quaternion & Animation::GetBoneRotate(long index)
  355. {
  356. return animation.GetBoneRotate(index);
  357. }
  358. //Получить позицию кости с учётом блендеров, без иерархии
  359. const Vector & Animation::GetBonePosition(long index)
  360. {
  361. return animation.GetBonePosition(index);
  362. }
  363. //Получить масштаб кости с учётом блендеров, без иерархии
  364. const Vector & Animation::GetBoneScale(long index)
  365. {
  366. return animation.GetBoneScale(index);
  367. }
  368. //Получить матрицу кости
  369. const Matrix & Animation::GetBoneMatrix(long index)
  370. {
  371. #ifdef DEBUG_PIX_ENABLE
  372. PIXBeginNamedEvent(0, "Ani-GetBoneMatrix");
  373. #endif
  374. synchroUpdate.Enter();
  375. //SyncroCode sc(synchroUpdate);
  376. #ifndef STOP_DEBUG
  377. if(!animation.IsBonesUpdated(index))
  378. {
  379. service.AddMissGetSingleBoneMatrix();
  380. }
  381. #endif
  382. const Matrix & mtx = animation.GetBoneMatrix(index);
  383. service.ThreadAddAnimationToUpdate(this);
  384. #ifdef DEBUG_PIX_ENABLE
  385. PIXEndNamedEvent();
  386. #endif
  387. synchroUpdate.Leave();
  388. return mtx;
  389. }
  390. //Получить массив матриц
  391. const Matrix * Animation::GetBoneMatrices()
  392. {
  393. #ifdef DEBUG_PIX_ENABLE
  394. PIXBeginNamedEvent(0, "Ani-GetBoneMatrices");
  395. #endif
  396. SyncroCode sc(synchroUpdate);
  397. #ifndef STOP_DEBUG
  398. if(!animation.IsAllBonesUpdated())
  399. {
  400. service.AddMissGetBoneMatrices();
  401. }
  402. #endif
  403. const Matrix * mtx = animation.GetBoneMatrices();
  404. service.ThreadAddAnimationToUpdate(this);
  405. #ifdef DEBUG_PIX_ENABLE
  406. PIXEndNamedEvent();
  407. #endif
  408. return mtx;
  409. }
  410. //Получить текущую дельту смещения
  411. void Animation::GetMovement(Vector & deltaPos)
  412. {
  413. animation.GetMovement(deltaPos);
  414. }
  415. //Зарегистрировать стадию блендинга скелета
  416. void Animation::RegistryBlendStage(IAniBlendStage * stage, long level)
  417. {
  418. service.ThreadRemoveAnimationToUpdate(this);
  419. animation.extMixer.Empty();
  420. UnregistryBlendStage(stage);
  421. BStage bs;
  422. bs.stage = stage;
  423. bs.level = level;
  424. for(long i = 0; i < stages; i++)
  425. {
  426. if(stages[i].level > level)
  427. {
  428. stages.Insert(bs, i);
  429. if(i < updateStageIndex)
  430. {
  431. updateStageIndex++;
  432. }
  433. break;
  434. }
  435. }
  436. if(i >= stages)
  437. {
  438. stages.Add(bs);
  439. }
  440. for(long i = 0; i < stages; i++)
  441. {
  442. animation.extMixer.Add(&stages[i]);
  443. }
  444. }
  445. //Освободить стадию блендинга
  446. void Animation::UnregistryBlendStage(IAniBlendStage * stage)
  447. {
  448. if(!stage) return;
  449. service.ThreadRemoveAnimationToUpdate(this);
  450. animation.extMixer.Empty();
  451. for(long i = 0; i < stages; i++)
  452. {
  453. if(stages[i].stage == stage)
  454. {
  455. stages.DelIndex(i);
  456. if(i <= updateStageIndex)
  457. {
  458. updateStageIndex--;
  459. }
  460. }
  461. }
  462. for(long i = 0; i < stages; i++)
  463. {
  464. animation.extMixer.Add(&stages[i]);
  465. }
  466. }
  467. //Проверить что блендер уже отрелижен
  468. void Animation::UnregistryBlendStageCheck(IAniBlendStage * stage)
  469. {
  470. service.ThreadRemoveAnimationToUpdate(this);
  471. for(long i = 0; i < stages; i++)
  472. {
  473. if(stages[i].stage == stage)
  474. {
  475. //Перед удалением BlendStage небыла вызванна UnregistryBlendStage
  476. //Если удалять в деструкторе, то вызов UnregistryBlendStage должен идти первым
  477. Assert(false);
  478. }
  479. }
  480. }
  481. //--------------------------------------------------------------------------------------------
  482. //Система сообщений
  483. //--------------------------------------------------------------------------------------------
  484. //Установить функцию обработчика на исполнение
  485. bool Animation::SetEventHandler(IAnimationListener * listener, AniEvent func, const char * eventName)
  486. {
  487. //Анализируем входные параметры
  488. if(!listener || !func) return false;
  489. if(!eventName || !eventName[0]) return false;
  490. //Преобразуем указатель в нативный
  491. eventName = animation.header.FindName(eventName, AnxFndName::f_event);
  492. //Ищим событие среди добавленных
  493. for(long i = 0; i < events; i++)
  494. {
  495. if(events[i].listener == listener)
  496. {
  497. if(events[i].func == func)
  498. {
  499. if(events[i].eventName == eventName)
  500. {
  501. return true;
  502. }
  503. }
  504. }
  505. }
  506. //Добавляем событие
  507. EventHandler & eh = events[events.Add()];
  508. eh.eventName = eventName;
  509. eh.listener = listener;
  510. eh.func = func;
  511. AddAnimationToListener(listener);
  512. return true;
  513. }
  514. //Удалить функцию обработчика
  515. void Animation::DelEventHandler(IAnimationListener * listener, AniEvent func, const char * eventName)
  516. {
  517. //Ищим событие среди добавленных
  518. for(long i = 0; i < events; i++)
  519. {
  520. if(events[i].listener == listener)
  521. {
  522. if(events[i].func == func)
  523. {
  524. // if(events[i].eventName == eventName)
  525. if(string::IsEqual(events[i].eventName,eventName))
  526. {
  527. events.DelIndex(i);
  528. if(i <= currentHandler) currentHandler--;
  529. return;
  530. }
  531. }
  532. }
  533. }
  534. }
  535. //Удалить все функции обработчика
  536. void Animation::DelAllEventHandlers(IAnimationListener * listener)
  537. {
  538. //Ищим событие среди добавленных
  539. for(long i = 0; i < events; i++)
  540. {
  541. if(events[i].listener == listener)
  542. {
  543. events.DelIndex(i);
  544. if(i <= currentHandler) currentHandler--;
  545. i = -1;
  546. }
  547. }
  548. if(timeEvent == listener)
  549. {
  550. SetTimeEventHandler(null, 0.0f);
  551. }
  552. }
  553. //Установить обработчик временных интервалов в анимации
  554. void Animation::SetTimeEventHandler(IAnimationListener * listener, float timeStep)
  555. {
  556. if(timeStep <= 0.0f) listener = null;
  557. timeEvent = listener;
  558. timeEventStep = timeStep;
  559. if(listener)
  560. {
  561. animation.SetTimeEvent(TimeEvent, this, timeEventStep);
  562. }else{
  563. animation.SetTimeEvent(null, null, 0.0f);
  564. }
  565. }
  566. //Получить шаг временных интервалов в анимации, если меньше 0, то неустановлен режим
  567. float Animation::GetTimeEventStep()
  568. {
  569. if(timeEvent)
  570. {
  571. return timeEventStep;
  572. }
  573. return -1.0f;
  574. }
  575. //Расчитать кости из вспомогательного потока
  576. void Animation::ThreadUpdateBones()
  577. {
  578. #ifdef DEBUG_PIX_ENABLE
  579. PIXBeginNamedEvent(0, "Ani-ThreadUpdateBones");
  580. #endif
  581. if(synchroUpdate.TryEnter())
  582. {
  583. #ifndef STOP_DEBUG
  584. if(!animation.IsAllBonesUpdated())
  585. {
  586. service.AddThreadUpdateBoneMatricesCounter();
  587. }
  588. #endif
  589. animation.GetBoneMatrices();
  590. synchroUpdate.Leave();
  591. }
  592. #ifdef DEBUG_PIX_ENABLE
  593. PIXEndNamedEvent();
  594. #endif
  595. }
  596. //Проверить не отписанный блендер и листенер
  597. void Animation::UnregistryCheck(IAniBlendStage * bs, IAnimationListener * lis)
  598. {
  599. for(long i = 0; i < stages; i++)
  600. {
  601. Assert(stages[i].stage != bs);
  602. }
  603. for(long i = 0; i < events; i++)
  604. {
  605. Assert(events[i].listener != lis);
  606. }
  607. }
  608. void __fastcall Animation::Event(void * pointer, AnxAnimation * ani, const char * eventName, const char ** params, dword numParams)
  609. {
  610. Animation * a = (Animation *)pointer;
  611. Assert(a);
  612. for(a->currentHandler = 0; a->currentHandler < a->events; a->currentHandler++)
  613. {
  614. EventHandler & eh = a->events[a->currentHandler];
  615. if(eh.eventName == eventName)
  616. {
  617. (eh.listener->*eh.func)(a, eventName, params, numParams);
  618. }
  619. }
  620. }
  621. void __fastcall Animation::TimeEvent(void * pointer, AnxAnimation * ani)
  622. {
  623. Animation * a = (Animation *)pointer;
  624. Assert(a);
  625. Assert(a->timeEvent);
  626. a->timeEvent->TimeEvent(a);
  627. }
  628. bool Animation::SetNativeInfoGlobal(AGNA_GlobalInfo & accessor) const
  629. {
  630. const AnxHeader & header = animation.header;
  631. accessor.numNodes = header.numNodes;
  632. accessor.numLinks = header.numLinks;
  633. accessor.numConstatns = header.numConsts;
  634. accessor.numEvents = header.numEvents;
  635. accessor.numClips = header.numClips;
  636. return true;
  637. }
  638. bool Animation::SetNativeInfoNodeByName(AGNA_NodeInfo & accessor) const
  639. {
  640. if(!accessor.name) return false;
  641. const AnxHeader & header = animation.header;
  642. for(dword i = 0; i < header.numNodes; i++)
  643. {
  644. if(string::IsEqual(header.nodes.ptr[i].name.ptr, accessor.name))
  645. {
  646. accessor.index = i;
  647. return SetNativeInfoNodeByIndex(accessor);
  648. }
  649. }
  650. return false;
  651. }
  652. bool Animation::SetNativeInfoNodeByIndex(AGNA_NodeInfo & accessor) const
  653. {
  654. const AnxHeader & header = animation.header;
  655. if(accessor.index >= header.numNodes)
  656. {
  657. return false;
  658. }
  659. AnxNode & node = header.nodes.ptr[accessor.index];
  660. accessor.name = node.name.ptr;
  661. accessor.numClips = node.numClips;
  662. accessor.numConsts = node.numConsts;
  663. accessor.numLinks = node.numLinks;
  664. accessor.defLink = node.defLink;
  665. accessor.isLoop = (node.flags & AnxNode::isLoop) != 0;
  666. accessor.isChange = (node.flags & AnxNode::isChange) != 0;
  667. return true;
  668. }
  669. bool Animation::SetNativeInfoLink(AGNA_LinkInfo & accessor) const
  670. {
  671. const AnxHeader & header = animation.header;
  672. if(accessor.nodeIndex >= header.numNodes)
  673. {
  674. return false;
  675. }
  676. AnxNode & node = header.nodes.ptr[accessor.nodeIndex];
  677. if(accessor.linkIndex >= node.numLinks)
  678. {
  679. return false;
  680. }
  681. AnxLink & link = node.links.ptr[accessor.linkIndex];
  682. accessor.command = link.name.ptr;
  683. Assert(link.toNode.ptr);
  684. accessor.to = link.toNode.ptr - header.nodes.ptr;
  685. Assert(accessor.to < header.numNodes);
  686. accessor.arange[0] = link.arange[0];
  687. accessor.arange[1] = link.arange[1];
  688. accessor.mrange[0] = link.mrange[0];
  689. accessor.mrange[1] = link.mrange[1];
  690. accessor.kBlendTime = link.kBlendTime;
  691. accessor.syncPos = link.syncPos;
  692. return true;
  693. }
  694. bool Animation::SetNativeInfoClip(AGNA_ClipInfo & accessor) const
  695. {
  696. const AnxHeader & header = animation.header;
  697. if(accessor.nodeIndex >= header.numNodes)
  698. {
  699. return false;
  700. }
  701. AnxNode & node = header.nodes.ptr[accessor.nodeIndex];
  702. if(accessor.clipIndex >= node.numClips)
  703. {
  704. return false;
  705. }
  706. AnxClip & clip = node.clips.ptr[accessor.clipIndex];
  707. accessor.numEvents = clip.numEvents;
  708. accessor.frames = clip.frames;
  709. accessor.fps = clip.fps;
  710. accessor.probability = clip.probability;
  711. return true;
  712. }
  713. bool Animation::SetNativeInfoEvent(AGNA_EventInfo & accessor) const
  714. {
  715. const AnxHeader & header = animation.header;
  716. if(accessor.nodeIndex >= header.numNodes)
  717. {
  718. return false;
  719. }
  720. AnxNode & node = header.nodes.ptr[accessor.nodeIndex];
  721. if(accessor.clipIndex >= node.numClips)
  722. {
  723. return false;
  724. }
  725. AnxClip & clip = node.clips.ptr[accessor.clipIndex];
  726. if(accessor.eventIndex >= clip.numEvents)
  727. {
  728. return false;
  729. }
  730. AnxEvent & evt = clip.events.ptr[accessor.eventIndex];
  731. accessor.name = evt.name.ptr;
  732. accessor.frame = evt.frame;
  733. accessor.params = evt.params.ptr;
  734. accessor.numParams = evt.numParams;
  735. return true;
  736. }
  737. bool Animation::SetNativeInfoEvent(AGNA_GlobalEventInfo & accessor) const
  738. {
  739. const AnxHeader & header = animation.header;
  740. if(accessor.eventIndex >= header.numEvents)
  741. {
  742. return false;
  743. }
  744. AnxEvent & evt = header.events.ptr[accessor.eventIndex];
  745. accessor.name = evt.name.ptr;
  746. accessor.frame = evt.frame;
  747. accessor.params = evt.params.ptr;
  748. accessor.numParams = evt.numParams;
  749. return true;
  750. }
  751. bool Animation::SetNativeInfoCurrentFrameGet(AGNA_GetCurrentFrame & accessor) const
  752. {
  753. #ifndef _XBOX
  754. AnxAnimation & ani = (AnxAnimation &)animation;
  755. if(ani.CurrentNode() != null)
  756. {
  757. ((AGNA_GetCurrentFrame &)accessor).currentFrame = ani.GetCurrentFrame();
  758. return true;
  759. }
  760. #endif
  761. return false;
  762. }
  763. bool Animation::SetNativeInfoCurrentFrameSet(AGNA_SetCurrentFrame & accessor) const
  764. {
  765. #ifndef _XBOX
  766. #ifndef NO_TOOLS
  767. scene.Command_ClearQueue(this);
  768. AnxAnimation & ani = (AnxAnimation &)animation;
  769. if(ani.CurrentNode() != null)
  770. {
  771. ani.SetCurrentFrame(((AGNA_SetCurrentFrame &)accessor).currentFrame);
  772. return true;
  773. }
  774. #endif
  775. #endif
  776. return false;
  777. }
  778. bool Animation::SetNativeInfoNumberOfFrames(AGNA_GetNumberOfFrames & accessor) const
  779. {
  780. #ifndef _XBOX
  781. #ifndef NO_TOOLS
  782. AnxAnimation & ani = (AnxAnimation &)animation;
  783. accessor.frames = ani.GetNumberOfFrames();
  784. return true;
  785. #endif
  786. #endif
  787. return false;
  788. }
  789. bool Animation::SetNativeInfoIsBoneUseGlobalPos(AGNA_IsBoneUseGlobalPos & accessor) const
  790. {
  791. #ifndef _XBOX
  792. #ifndef NO_TOOLS
  793. AnxAnimation & ani = (AnxAnimation &)animation;
  794. return ani.IsBoneUseGlobalPos(accessor.index);
  795. #endif
  796. #endif
  797. return false;
  798. }
  799. bool Animation::SetNativeInfoSetFPS(AGNA_SetFPS & accessor) const
  800. {
  801. #ifndef _XBOX
  802. #ifndef NO_TOOLS
  803. AnxAnimation & ani = (AnxAnimation &)animation;
  804. ani.SetFPS(accessor.fps);
  805. return true;
  806. #endif
  807. #endif
  808. return false;
  809. }
  810. bool Animation::SetNativeGotoNodeClip(AGNA_GotoNodeClip & accessor) const
  811. {
  812. #ifndef _XBOX
  813. #ifndef NO_TOOLS
  814. scene.Command_ClearQueue(this);
  815. if(!accessor.node)
  816. {
  817. AnxAnimation & ani = (AnxAnimation &)animation;
  818. return ani.Start(null, 0);
  819. }
  820. const char * nameId = animation.GetConstData().GetHeader().FindName(accessor.node, AnxFndName::f_node);
  821. if(nameId)
  822. {
  823. service.Editor_NoThread();
  824. AnxAnimation & ani = (AnxAnimation &)animation;
  825. return ani.Goto(nameId, accessor.blendTime, accessor.clipIndex);
  826. }
  827. #endif
  828. #endif
  829. return false;
  830. }
  831. bool Animation::SetNativePause(AGNA_AnimationPause & accessor) const
  832. {
  833. #ifndef _XBOX
  834. #ifndef NO_TOOLS
  835. scene.Command_ClearQueue(this);
  836. if(accessor.isAnimationPause)
  837. {
  838. ((Animation *)this)->isPause |= pf_pause;
  839. }else{
  840. ((Animation *)this)->isPause &= ~pf_pause;
  841. }
  842. scene.Command_Pause(((Animation *)this), accessor.isAnimationPause);
  843. return true;
  844. #endif
  845. #endif
  846. return false;
  847. }
  848. bool Animation::SetNativeBlockControl(AGNA_BlockControl & accessor) const
  849. {
  850. #ifndef _XBOX
  851. #ifndef NO_TOOLS
  852. scene.Command_ClearQueue(this);
  853. ((Animation *)this)->isBlockControl = (accessor.isBlockControl) ? 1 : 0;
  854. AnxAnimation & ani = (AnxAnimation &)animation;
  855. ani.BlockGraphLinks(accessor.isBlockControl);
  856. return true;
  857. #endif
  858. #endif
  859. return false;
  860. }
  861. __forceinline bool Animation::IsBlockControl() const
  862. {
  863. #ifndef _XBOX
  864. #ifndef NO_TOOLS
  865. return isBlockControl != 0;
  866. #endif
  867. #endif
  868. return false;
  869. }