AdvancedAnimSheet.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // AdvancedAnimSheet.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "W3dViewDoc.h"
  23. #include "AdvancedAnimSheet.h"
  24. #include "AssetMgr.h"
  25. #include "HAnim.h"
  26. #include "HTree.h"
  27. #include "Utils.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. // QSort comparison function for HAnimClass pointers.
  34. // Will compare their names.
  35. static int anim_name_compare (const void *arg1, const void *arg2)
  36. {
  37. ASSERT(arg1 != NULL);
  38. ASSERT(arg2 != NULL);
  39. HAnimClass *a1 = *(HAnimClass**)arg1;
  40. HAnimClass *a2 = *(HAnimClass**)arg2;
  41. return _stricmp( a1->Get_Name(), a2->Get_Name() );
  42. }
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CAdvancedAnimSheet
  45. IMPLEMENT_DYNAMIC(CAdvancedAnimSheet, CPropertySheet)
  46. CAdvancedAnimSheet::CAdvancedAnimSheet(CWnd* pParentWnd, UINT iSelectPage)
  47. : CPropertySheet("Advanced Animation", pParentWnd, iSelectPage),
  48. m_MixingPage(this),
  49. m_ReportPage(this),
  50. AnimsValid(false),
  51. AnimCount(0)
  52. {
  53. // Blank out the array of animation pointers.
  54. ZeroMemory(Anims, sizeof(Anims));
  55. // Add the property pages into this property sheet.
  56. AddPage(&m_MixingPage);
  57. AddPage(&m_ReportPage);
  58. }
  59. CAdvancedAnimSheet::~CAdvancedAnimSheet()
  60. {
  61. if (AnimsValid)
  62. {
  63. for (int i = 0; i < AnimCount; i++)
  64. {
  65. MEMBER_RELEASE(Anims[i]);
  66. }
  67. AnimsValid = false;
  68. AnimCount = 0;
  69. }
  70. }
  71. BEGIN_MESSAGE_MAP(CAdvancedAnimSheet, CPropertySheet)
  72. //{{AFX_MSG_MAP(CAdvancedAnimSheet)
  73. // NOTE - the ClassWizard will add and remove mapping macros here.
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CAdvancedAnimSheet message handlers
  78. int CAdvancedAnimSheet::GetAnimCount (void)
  79. {
  80. if (AnimsValid)
  81. return AnimCount;
  82. LoadAnims();
  83. if (AnimsValid)
  84. return AnimCount;
  85. else
  86. return 0;
  87. }
  88. HAnimClass ** CAdvancedAnimSheet::GetAnims (void)
  89. {
  90. if (AnimsValid)
  91. return Anims;
  92. LoadAnims();
  93. // Return the array regardless of validity. If the entries are
  94. // invalid, they'll all be NULL, but the array itself is cool.
  95. return Anims;
  96. }
  97. void CAdvancedAnimSheet::LoadAnims (void)
  98. {
  99. // Get the current render object and it's HTree. If it doesn't have
  100. // an HTree, then it's not animating and we're not interested.
  101. RenderObjClass *robj = ::GetCurrentDocument()->GetDisplayedObject();
  102. if (robj == NULL)
  103. return;
  104. const HTreeClass *htree = robj->Get_HTree();
  105. if (htree == NULL)
  106. return;
  107. const char *htree_name = htree->Get_Name();
  108. /*
  109. ** Figure out which animations apply to the current object, and
  110. ** add each one to the array of animations which we will later sort.
  111. */
  112. // Get an iterator from the asset manager that we can
  113. // use to enumerate the currently loaded assets
  114. AssetIterator *pAnimEnum = WW3DAssetManager::Get_Instance()->Create_HAnim_Iterator();
  115. ASSERT(pAnimEnum != NULL);
  116. if (pAnimEnum)
  117. {
  118. // Loop through all the animations in the manager
  119. for (pAnimEnum->First(); pAnimEnum->Is_Done() == FALSE; pAnimEnum->Next())
  120. {
  121. LPCTSTR pszAnimName = pAnimEnum->Current_Item_Name();
  122. // Get an instance of the animation object
  123. HAnimClass *pHierarchyAnim = WW3DAssetManager::Get_Instance()->Get_HAnim(pszAnimName);
  124. ASSERT(pHierarchyAnim != NULL);
  125. if (pHierarchyAnim)
  126. {
  127. // Does this animation apply to the current model's HTree?
  128. if (stricmp(htree_name, pHierarchyAnim->Get_HName()) == 0)
  129. {
  130. // Add this Anims pointer to the array.
  131. if (AnimCount < MAX_REPORT_ANIMS)
  132. {
  133. MEMBER_ADD(Anims[AnimCount], pHierarchyAnim);
  134. AnimCount++;
  135. }
  136. else
  137. {
  138. char msg[256];
  139. sprintf(msg, "Error: Only %d animations are supported in this report. "
  140. " There are more than that loaded...", MAX_REPORT_ANIMS);
  141. MessageBox(msg, "Too Many Animations");
  142. break;
  143. }
  144. }
  145. // Release our hold on this animation.
  146. MEMBER_RELEASE(pHierarchyAnim);
  147. }
  148. }
  149. // Free the object
  150. delete pAnimEnum;
  151. pAnimEnum = NULL;
  152. }
  153. /*
  154. ** Sort the array of animations in alphabetical order.
  155. */
  156. qsort(Anims, AnimCount, sizeof(HAnimClass*), anim_name_compare);
  157. AnimsValid = true;
  158. }