Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
hanim.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(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
19/* $Header: /Commando/Code/ww3d2/hanim.h 3 12/13/01 7:01p Patrick $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando / G 3D Library *
25 * *
26 * $Archive:: /Commando/Code/ww3d2/hanim.h $*
27 * *
28 * Author:: Greg_h *
29 * *
30 * $Modtime:: 12/13/01 6:54p $*
31 * *
32 * $Revision:: 3 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef HANIM_H
44#define HANIM_H
45
46#include "always.h"
47#include "quat.h"
48#include "refcount.h"
49#include "w3d_file.h"
50#include "hash.h"
51#include "mempool.h"
52#include <refcount.h>
53#include <slist.h>
54#include <vector.h>
55
56struct NodeMotionStruct;
58class BitChannelClass;
59class HTreeClass;
60class ChunkLoadClass;
61class ChunkSaveClass;
62class HTreeClass;
63
64
65
66#define EMBEDDED_SOUND_BONE_INDEX_NOT_SET -1
67/**********************************************************************************
68
69 HAnimClass
70
71 This is the base class for all animation formats used in W3D. It
72 contains the virtual interface that all animations must support.
73
74**********************************************************************************/
76{
77public:
78 enum
79 {
80 CLASSID_UNKNOWNANIM = 0xFFFFFFFF,
82 CLASSID_LASTANIM = 0x0000FFFF
83 };
84
87 virtual ~HAnimClass(void) { }
88
89 virtual const char * Get_Name(void) const = 0;
90 virtual const char * Get_HName(void) const = 0;
91
92 virtual const char * Get_Key( void ) { return Get_Name(); }
93
94 virtual int Get_Num_Frames(void) = 0;
95 virtual float Get_Frame_Rate() = 0;
96 virtual float Get_Total_Time() = 0;
97
98// virtual Vector3 Get_Translation(int pividx,float frame) = 0;
99// virtual Quaternion Get_Orientation(int pividx,float frame) = 0;
100 // Jani: Changed to pass in reference of destination to avoid copying
101 virtual void Get_Translation(int pividx,float frame) {} // todo: remove
102 virtual void Get_Orientation(int pividx,float frame) {} // todo: remove
103 virtual void Get_Translation(Vector3& translation, int pividx,float frame) const = 0;
104 virtual void Get_Orientation(Quaternion& orientation, int pividx,float frame) const = 0;
105 virtual void Get_Transform(Matrix3D&, int pividx, float frame) const = 0;
106 virtual bool Get_Visibility(int pividx,float frame) = 0;
107
108 virtual int Get_Num_Pivots(void) const = 0;
109 virtual bool Is_Node_Motion_Present(int pividx) = 0;
110
111 // Methods that test the presence of a certain motion channel.
112 virtual bool Has_X_Translation (int pividx) { return true; }
113 virtual bool Has_Y_Translation (int pividx) { return true; }
114 virtual bool Has_Z_Translation (int pividx) { return true; }
115 virtual bool Has_Rotation (int pividx) { return true; }
116 virtual bool Has_Visibility (int pividx) { return true; }
117 virtual int Class_ID(void) const { return CLASSID_UNKNOWNANIM; }
118
119 // Animated sound-triggering support
120 virtual bool Has_Embedded_Sounds (void) const { if (EmbeddedSoundBoneIndex < 0) return false; return true;}
121 virtual void Set_Embedded_Sound_Bone_Index (int bone) { EmbeddedSoundBoneIndex = bone; }
123
124protected:
126};
127
128
129/*
130** The PivotMapClass is used by the HAnimComboDataClass (sometimes) to keep track of animation
131** weights per-pivot point.
132*/
134
135class PivotMapClass : public DynamicVectorClass<float>, public RefCountClass
136{
137public:
138 virtual NamedPivotMapClass * As_Named_Pivot_Map() { return 0; }
139};
140
141
142/*
143** The NamedPivotMapClass allows us to create HAnimComboDataClass objects with pivot maps without
144** having to have the HAnim available. Later, when an HAnim is retrieved from the asset manager,
145** the pivot map can be updated to produce the correct map.
146*/
148{
149public:
151
152 virtual NamedPivotMapClass * As_Named_Pivot_Map() { return this; }
153
154 // add a name & weight to the arrays
155 void Add(const char *Name, float Weight);
156
157 // configure the base pivot map using the specified tree
158 void Update_Pivot_Map(const HTreeClass *Tree);
159
160private:
161
162 // This info is packaged into a struct to minimize DynamicVectorClass overhead
163 struct WeightInfoStruct {
164 WeightInfoStruct() : Name(0) {}
165 ~WeightInfoStruct() { if(Name) delete [] Name; }
166
167 char *Name;
168 float Weight;
169
170 // operators required for the DynamicVectorClass
171 WeightInfoStruct & operator = (WeightInfoStruct const &that);
172 bool operator == (WeightInfoStruct const &that) const { return &that == this; }
173 bool operator != (WeightInfoStruct const &that) const { return &that != this; }
174 };
175
177};
178
179
180/*
181** The HAnimComboDataClass is used by the new HAnimComboClass to allow for a mix of shared/unshared data
182** which will allow us to have the anim combo refer to data whereever we wish to put it.
183*/
184class HAnimComboDataClass : public AutoPoolClass<HAnimComboDataClass,256> {
185 public:
186 HAnimComboDataClass(bool shared = false);
189
190 void Copy(const HAnimComboDataClass *);
191
192 void Clear(void);
193 void Set_HAnim(HAnimClass *motion);
194 void Give_HAnim(HAnimClass *motion) { if(HAnim) HAnim->Release_Ref(); HAnim = motion; } // used for giving this object the reference
195
196 void Set_Frame(float frame) { PrevFrame = Frame; Frame = frame; }
197 void Set_Prev_Frame(float frame) { PrevFrame = frame; }
198 void Set_Weight(float weight) { Weight = weight; }
199 void Set_Pivot_Map(PivotMapClass *map);
200
201
202 HAnimClass * Peek_HAnim(void) const { return HAnim; } // note: does not add reference
203 HAnimClass * Get_HAnim(void) const { if(HAnim) HAnim->Add_Ref(); return HAnim; } // note: does not add reference
204 float Get_Frame(void) const { return Frame; }
205 float Get_Prev_Frame(void) const { return PrevFrame; }
206 float Get_Weight(void) const { return Weight; }
207 PivotMapClass * Peek_Pivot_Map(void) const { return PivotMap; }
208 PivotMapClass * Get_Pivot_Map(void) const { if(PivotMap) PivotMap->Add_Ref(); return PivotMap; }
209 bool Is_Shared(void) const { return Shared; }
210
211 void Build_Active_Pivot_Map(void);
212
213 private:
214
215 HAnimClass *HAnim;
216 float Frame;
217 float PrevFrame;
218 float Weight;
219 PivotMapClass * PivotMap;
220 bool Shared; // this is set to false when the HAnimCombo allocates it
221};
222
223/*
224** defines a combination of animations for blending/mixing
225*/
227
228public:
229
230 HAnimComboClass(void);
231 HAnimComboClass( int num_animations ); // allocates specified number of channels and sets then all to not-shared
232 ~HAnimComboClass(void);
233
234 void Clear( void ); // zeros all data
235
236 void Reset( void ); // empties the dynamic vector
237
238 bool Normalize_Weights(void); // Normalizes all weights (returns true if succeeded)
239 int Get_Num_Anims( void ) { return HAnimComboData.Count(); }
240
241 void Set_Motion( int indx, HAnimClass *motion );
242 HAnimClass *Get_Motion( int indx );
243 HAnimClass *Peek_Motion( int indx );
244
245 void Set_Frame( int indx, float frame );
246 void Set_Prev_Frame( int indx, float frame );
247 float Get_Frame( int indx );
248 float Get_Prev_Frame( int indx );
249
250 void Set_Weight( int indx, float weight );
251 float Get_Weight( int indx );
252
253 void Set_Pivot_Weight_Map( int indx, PivotMapClass * map );
256
257
258 // add an entry to the dynamic vector
259 void Append_Anim_Combo_Data(HAnimComboDataClass * AnimComboData);
260
261 // remove an entry from the vector
262 void Remove_Anim_Combo_Data(HAnimComboDataClass * AnimComboData);
263
264 // retrieve a specific combo data
266
267protected:
268
270
271};
272
273#endif
DynamicVectorClass(unsigned size=0, float const *array=0)
Definition Vector.H:587
virtual void Get_Translation(Vector3 &translation, int pividx, float frame) const =0
virtual void Get_Orientation(int pividx, float frame)
Definition hanim.h:102
virtual void Get_Orientation(Quaternion &orientation, int pividx, float frame) const =0
virtual int Get_Num_Frames(void)=0
virtual float Get_Frame_Rate()=0
virtual const char * Get_Name(void) const =0
virtual bool Has_Z_Translation(int pividx)
Definition hanim.h:114
virtual bool Is_Node_Motion_Present(int pividx)=0
HAnimClass(void)
Definition hanim.h:85
virtual ~HAnimClass(void)
Definition hanim.h:87
int EmbeddedSoundBoneIndex
Definition hanim.h:125
virtual int Class_ID(void) const
Definition hanim.h:117
virtual bool Has_Y_Translation(int pividx)
Definition hanim.h:113
virtual void Get_Translation(int pividx, float frame)
Definition hanim.h:101
virtual bool Has_Embedded_Sounds(void) const
Definition hanim.h:120
virtual void Get_Transform(Matrix3D &, int pividx, float frame) const =0
virtual bool Has_Visibility(int pividx)
Definition hanim.h:116
virtual float Get_Total_Time()=0
virtual int Get_Embedded_Sound_Bone_Index()
Definition hanim.h:122
@ CLASSID_UNKNOWNANIM
Definition hanim.h:80
@ CLASSID_LASTANIM
Definition hanim.h:82
@ CLASSID_HRAWANIM
Definition hanim.h:81
virtual const char * Get_HName(void) const =0
virtual bool Get_Visibility(int pividx, float frame)=0
virtual const char * Get_Key(void)
Definition hanim.h:92
virtual bool Has_Rotation(int pividx)
Definition hanim.h:115
virtual int Get_Num_Pivots(void) const =0
virtual void Set_Embedded_Sound_Bone_Index(int bone)
Definition hanim.h:121
virtual bool Has_X_Translation(int pividx)
Definition hanim.h:112
void Append_Anim_Combo_Data(HAnimComboDataClass *AnimComboData)
Definition hanim.cpp:458
DynamicVectorClass< HAnimComboDataClass * > HAnimComboData
Definition hanim.h:269
float Get_Prev_Frame(int indx)
Definition hanim.cpp:410
float Get_Frame(int indx)
Definition hanim.cpp:394
void Set_Weight(int indx, float weight)
Definition hanim.cpp:418
float Get_Weight(int indx)
Definition hanim.cpp:426
void Set_Pivot_Weight_Map(int indx, PivotMapClass *map)
Definition hanim.cpp:434
HAnimClass * Get_Motion(int indx)
Definition hanim.cpp:364
HAnimClass * Peek_Motion(int indx)
Definition hanim.cpp:377
void Remove_Anim_Combo_Data(HAnimComboDataClass *AnimComboData)
Definition hanim.cpp:463
PivotMapClass * Peek_Pivot_Weight_Map(int indx)
Definition hanim.cpp:450
void Set_Frame(int indx, float frame)
Definition hanim.cpp:386
HAnimComboClass(void)
Definition hanim.cpp:231
void Set_Prev_Frame(int indx, float frame)
Definition hanim.cpp:402
HAnimComboDataClass * Peek_Anim_Combo_Data(int index)
Definition hanim.h:265
PivotMapClass * Get_Pivot_Weight_Map(int indx)
Definition hanim.cpp:442
void Reset(void)
Definition hanim.cpp:260
void Clear(void)
Definition hanim.cpp:250
bool Normalize_Weights(void)
Definition hanim.cpp:272
void Set_Motion(int indx, HAnimClass *motion)
Definition hanim.cpp:356
int Get_Num_Anims(void)
Definition hanim.h:239
~HAnimComboClass(void)
Definition hanim.cpp:244
float Get_Prev_Frame(void) const
Definition hanim.h:205
void Set_Weight(float weight)
Definition hanim.h:198
void Copy(const HAnimComboDataClass *)
Definition hanim.cpp:127
void Set_Frame(float frame)
Definition hanim.h:196
PivotMapClass * Peek_Pivot_Map(void) const
Definition hanim.h:207
HAnimClass * Peek_HAnim(void) const
Definition hanim.h:202
~HAnimComboDataClass(void)
Definition hanim.cpp:144
void Set_HAnim(HAnimClass *motion)
Definition hanim.cpp:172
void Build_Active_Pivot_Map(void)
Definition hanim.cpp:199
HAnimClass * Get_HAnim(void) const
Definition hanim.h:203
void Clear(void)
Definition hanim.cpp:152
PivotMapClass * Get_Pivot_Map(void) const
Definition hanim.h:208
bool Is_Shared(void) const
Definition hanim.h:209
void Set_Pivot_Map(PivotMapClass *map)
Definition hanim.cpp:184
void Set_Prev_Frame(float frame)
Definition hanim.h:197
float Get_Frame(void) const
Definition hanim.h:204
HAnimComboDataClass(bool shared=false)
Definition hanim.cpp:112
void Give_HAnim(HAnimClass *motion)
Definition hanim.h:194
float Get_Weight(void) const
Definition hanim.h:206
HashableClass(void)
Definition hash.h:57
void Add(const char *Name, float Weight)
Definition hanim.cpp:73
void Update_Pivot_Map(const HTreeClass *Tree)
Definition hanim.cpp:83
~NamedPivotMapClass(void)
Definition hanim.cpp:59
virtual NamedPivotMapClass * As_Named_Pivot_Map()
Definition hanim.h:152
virtual NamedPivotMapClass * As_Named_Pivot_Map()
Definition hanim.h:138
void Add_Ref(void) const
Definition refcount.cpp:171
RefCountClass(void)
Definition refcount.h:108
#define EMBEDDED_SOUND_BONE_INDEX_NOT_SET
Definition hanim.h:66