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