Isle
Loading...
Searching...
No Matches
legoanimactor.cpp
Go to the documentation of this file.
1#include "legoanimactor.h"
2
3#include "anim/legoanim.h"
4#include "define.h"
6#include "legopathboundary.h"
7#include "legoworld.h"
8#include "misc.h"
9#include "mxutilities.h"
10
13
14// FUNCTION: LEGO1 0x1001bf80
15// FUNCTION: BETA10 0x1003dc10
16LegoAnimActorStruct::LegoAnimActorStruct(float p_unk0x00, LegoAnim* p_AnimTreePtr, LegoROI** p_roiMap, MxU32 p_numROIs)
17{
18 m_unk0x00 = p_unk0x00;
19 m_AnimTreePtr = p_AnimTreePtr;
20 m_roiMap = p_roiMap;
21 m_numROIs = p_numROIs;
22}
23
24// FUNCTION: LEGO1 0x1001c0a0
26{
27 for (MxU16 i = 0; i < m_unk0x10.size(); i++) {
28 delete m_unk0x10[i];
29 }
30}
31
32// FUNCTION: LEGO1 0x1001c130
33// FUNCTION: BETA10 0x1003df3a
35{
36 assert(m_AnimTreePtr);
37 return m_AnimTreePtr->GetDuration();
38}
39
40// FUNCTION: LEGO1 0x1001c140
41// FUNCTION: BETA10 0x1003dfe4
43{
44 for (MxS32 i = 0; i < m_animMaps.size(); i++) {
45 if (m_animMaps[i]) {
46 delete m_animMaps[i];
47 }
48 }
49}
50
51// FUNCTION: LEGO1 0x1001c1f0
52// FUNCTION: BETA10 0x1003f240
54{
55 float duration = (float) m_animMaps[m_curAnim]->m_AnimTreePtr->GetDuration();
56 p_und = m_actorTime - duration * ((MxS32) (m_actorTime / duration));
57 return SUCCESS;
58}
59
60// FUNCTION: LEGO1 0x1001c240
62{
63 float und;
64 LegoPathActor::VTable0x74(p_transform);
65
66 if (m_curAnim >= 0) {
67 FUN_1001c1f0(und);
68 FUN_1001c360(und, p_transform);
69 }
70}
71
72// FUNCTION: LEGO1 0x1001c290
73// FUNCTION: BETA10 0x1003e144
74void LegoAnimActor::Animate(float p_time)
75{
76 assert(m_roi);
77
78 if (m_lastTime == 0) {
79 m_lastTime = p_time - 1.0f;
80 }
81
83 if (m_curAnim >= 0) {
84 MxMatrix matrix(m_unk0xec);
85 float f;
86 FUN_1001c1f0(f);
87 FUN_1001c360(f, matrix);
88 }
89
90 m_lastTime = m_actorTime = p_time;
91 }
92 else {
94 }
95}
96
97// FUNCTION: LEGO1 0x1001c360
98// FUNCTION: BETA10 0x1003e2d3
100{
101 if (p_und >= 0) {
102 assert((m_curAnim >= 0) && (m_curAnim < m_animMaps.size()));
103
104 LegoROI** roiMap = m_animMaps[m_curAnim]->m_roiMap;
105 MxU32 numROIs = m_animMaps[m_curAnim]->m_numROIs;
106
107 if (!m_boundary->GetFlag0x10()) {
108 MxU32 i;
110
111 for (i = 0; i < numROIs; i++) {
112 LegoROI* roi = roiMap[i];
113
114 if (roi != NULL && m_roi != roi) {
115 roi->SetVisibility(FALSE);
116 }
117 }
118 }
119 else {
120 // name verified by BETA10 0x1003e407
121 LegoTreeNode* n = m_animMaps[m_curAnim]->m_AnimTreePtr->GetRoot();
122
123 assert(roiMap && n && m_roi && m_boundary);
124
126
127 for (MxU32 i = 0; i < numROIs; i++) {
128 LegoROI* roi = roiMap[i];
129
130 if (roi != NULL && m_roi != roi) {
131 roi->SetVisibility(TRUE);
132 }
133 }
134
135 for (MxS32 j = 0; j < n->GetNumChildren(); j++) {
136 LegoROI::FUN_100a8e80(n->GetChild(j), p_transform, p_und, roiMap);
137 }
138
139 if (m_cameraFlag) {
140 FUN_10010c30();
141 }
142 }
143
144 return SUCCESS;
145 }
146 else {
147 return FAILURE;
148 }
149}
150
151// FUNCTION: LEGO1 0x1001c450
152// FUNCTION: BETA10 0x1003e590
153MxResult LegoAnimActor::FUN_1001c450(LegoAnim* p_AnimTreePtr, float p_unk0x00, LegoROI** p_roiMap, MxU32 p_numROIs)
154{
155 // the capitalization of `p_AnimTreePtr` was taken from BETA10
156 assert(p_AnimTreePtr && p_roiMap);
157
158 LegoAnimActorStruct* laas = new LegoAnimActorStruct(p_unk0x00, p_AnimTreePtr, p_roiMap, p_numROIs);
159
160 for (vector<LegoAnimActorStruct*>::iterator it = m_animMaps.begin(); it != m_animMaps.end(); it++) {
161 if (p_unk0x00 < (*it)->m_unk0x00) {
162 m_animMaps.insert(it, laas);
164 return SUCCESS;
165 }
166 }
167
168 m_animMaps.push_back(laas);
170 return SUCCESS;
171}
172
173// FUNCTION: LEGO1 0x1001c800
174// FUNCTION: BETA10 0x1003e747
176{
177 for (MxU32 i = 0; i < m_animMaps.size(); i++) {
178 delete m_animMaps[i];
179 }
180
181 m_animMaps.clear();
182 m_curAnim = -1;
183}
184
185// FUNCTION: LEGO1 0x1001c870
186// FUNCTION: BETA10 0x1003e7e4
188{
189 if (p_worldSpeed < 0) {
190 m_worldSpeed = 0;
191 }
192 else {
193 m_worldSpeed = p_worldSpeed;
194 }
195
196 if (m_animMaps.size() > 0) {
197 m_curAnim = 0;
198
199 if (m_worldSpeed >= m_animMaps[m_animMaps.size() - 1]->m_unk0x00) {
200 m_curAnim = m_animMaps.size() - 1;
201 }
202 else {
203 for (MxU32 i = 0; i < m_animMaps.size(); i++) {
204 if (m_worldSpeed <= m_animMaps[i]->m_unk0x00) {
205 m_curAnim = i;
206 break;
207 }
208 }
209 }
210 }
211}
212
213// FUNCTION: LEGO1 0x1001c920
214// FUNCTION: BETA10 0x1003e914
215void LegoAnimActor::ParseAction(char* p_extra)
216{
218
219 LegoWorld* world = CurrentWorld();
220 char value[256];
221
222 if (world) {
223 if (KeyValueStringParse(value, g_strANIMATION, p_extra)) {
224 // name verified by BETA10 0x1003ea46
225 char* token = strtok(value, g_parseExtraTokens);
226
227 while (token) {
228 // name verified by BETA10 0x1003e9f5
229 LegoLocomotionAnimPresenter* p = (LegoLocomotionAnimPresenter*) world->Find("LegoAnimPresenter", token);
230
231 assert(p);
232
233 if (p != NULL) {
234 token = strtok(NULL, g_parseExtraTokens);
235
236 if (token) {
237 p->FUN_1006d680(this, atof(token));
238 }
239 }
240
241 token = strtok(NULL, g_parseExtraTokens);
242 }
243 }
244 }
245}
[AI] Path-based actor which supports skeletal/mesh animation via an animation tree and multiple anima...
Definition: legoanimactor.h:49
void ParseAction(char *p_extra) override
[AI] Handles extra action strings, looks for animation assignments and delegates to presenters (overr...
void SetWorldSpeed(MxFloat p_worldSpeed) override
[AI] Sets the current world speed and chooses which animation (from the animation map list) should be...
virtual void ClearMaps()
[AI] Deallocates all animation map structures and selects no animation; resets current animation inde...
vector< LegoAnimActorStruct * > m_animMaps
[AI] List of animation structures, each representing a valid animation for different speed/phase rang...
~LegoAnimActor() override
[AI] Destructor cleans up all animation map structures.
virtual MxResult FUN_1001c360(float p_und, Matrix4 &p_transform)
[AI] Applies the animation transform for the current animation at the given phase,...
virtual MxResult FUN_1001c450(LegoAnim *p_AnimTreePtr, float p_unk0x00, LegoROI **p_roiMap, MxU32 p_numROIs)
[AI] Adds a new animation mapping (LegoAnimActorStruct) with a tree, threshold, and mesh mapping.
MxS16 m_curAnim
[AI] Index of currently selected animation map (-1 if none active). [AI]
virtual MxResult FUN_1001c1f0(float &p_und)
[AI] Computes the animation phase offset within the current animation, adjusts for looping.
void Animate(float p_time) override
[AI] Performs per-frame update; applies the appropriate animation to mesh ROIs based on speed and sta...
void VTable0x74(Matrix4 &p_transform) override
[AI] Applies the current animation's transforms to the provided matrix, propagates to mesh hierarchie...
[AI] Root class for all node-based animation blending/structure.
Definition: legoanim.h:356
LegoTime GetDuration()
[AI] Duration (in time units) of the animation.
Definition: legoanim.h:361
void FUN_10010c30()
[AI] Updates the camera transformation when this entity is the camera target. Used after movement or ...
Definition: legoentity.cpp:192
MxBool m_cameraFlag
[AI] Set to TRUE if this entity is currently the camera target. [AI]
Definition: legoentity.h:218
MxFloat m_worldSpeed
[AI] World-relative speed (can affect animation/movement logic). [AI]
Definition: legoentity.h:212
LegoROI * m_roi
[AI] Pointer to this entity's currently assigned ROI (3D instance in the world). [AI]
Definition: legoentity.h:215
[AI] Specialized presenter class for handling locomotion animation playback and state in the LEGO Isl...
void FUN_1006d680(LegoAnimActor *p_actor, MxFloat p_value)
[AI] Binds a LegoAnimActor to the internal animation context and ROI mapping.
MxFloat m_actorTime
[AI] Animation time for current path segment. [AI]
virtual void Animate(float p_time)
[AI] Per-frame animation update.
LegoPathBoundary * m_boundary
[AI] Current boundary the actor is navigating on. [AI]
MxU32 m_actorState
[AI] State and flags bitfield for path following logic. [AI]
void ParseAction(char *p_extra) override
[AI] Parses a set of key-value action commands and configures path navigation and collision for this ...
virtual void VTable0x74(Matrix4 &p_transform)
[AI] Updates the ROI's transformation (typically matrix) with new values, applies world position/orie...
@ c_initial
[AI] Default state upon creation or reset. [AI]
Definition: legopathactor.h:37
MxMatrix m_unk0xec
[AI] World-to-local transformation matrix for this actor/ROI. [AI]
MxBool m_userNavFlag
[AI] TRUE if this actor is currently user/player controlled. [AI]
MxFloat m_lastTime
[AI] Time of last update (used for delta calculations). [AI]
[AI] Represents a Real-time Object Instance enriched with LEGO-specific functionality.
Definition: legoroi.h:43
static void FUN_100a8e80(LegoTreeNode *p_node, Matrix4 &p_matrix, LegoTime p_time, LegoROI **p_roiMap)
[AI] [Static] Recursively evaluates animation nodes, updating the transformation matrices and visibil...
Definition: legoroi.cpp:414
[AI] Represents a node within a general, N-ary tree structure.
Definition: legotree.h:44
LegoU32 GetNumChildren()
[AI] Returns the number of direct children of this node. [AI]
Definition: legotree.h:63
LegoTreeNode * GetChild(LegoU32 p_i)
[AI] Gets the child node at the specified index (no bounds checking).
Definition: legotree.h:72
LegoU32 GetFlag0x10()
Returns TRUE if the 'disabled' flag is not set, otherwise FALSE.
Definition: legowegedge.h:57
Represents the active 3D world, holding all entity, animation, sound, path, and ROI objects.
Definition: legoworld.h:49
MxCore * Find(const char *p_class, const char *p_name)
Finds an object of a given class and name in the world.
Definition: legoworld.cpp:573
4x4 Matrix class with virtual interface for manipulation and transformation.
Definition: matrix.h:24
[AI] Represents a 4x4 transformation matrix, specialized for the LEGO Island engine and derived from ...
Definition: mxmatrix.h:16
void SetVisibility(unsigned char p_visible)
[AI] Sets the visibility flag to the provided value.
Definition: roi.h:235
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
const char * g_strANIMATION
[AI] Keyword used for tagging animation properties, types, or script commands.
Definition: define.cpp:9
const char * g_parseExtraTokens
[AI] Delimiter tokens for parsing extra parameters in scripts or command strings.
Definition: define.cpp:141
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
Definition: legotypes.h:34
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
LegoWorld * CurrentWorld()
[AI] Accessor for the currently active LegoWorld instance. [AI]
Definition: misc.cpp:93
MxLong MxResult
[AI]
Definition: mxtypes.h:106
float MxFloat
[AI]
Definition: mxtypes.h:68
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned short MxU16
[AI]
Definition: mxtypes.h:20
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
MxBool KeyValueStringParse(char *, const char *, const char *)
Searches p_string for a key command and copies its associated value to p_output.
Definition: mxutilities.cpp:85
[AI] Holds per-animation instance data for a LegoAnimActor.
Definition: legoanimactor.h:13
float GetDuration()
[AI] Gets the length, in seconds, of the animation (delegates to anim tree).
LegoAnim * m_AnimTreePtr
[AI] Root of animation tree for this animation [AI]
Definition: legoanimactor.h:39
vector< undefined * > m_unk0x10
[AI] Holds per-instance temporary or auxiliary animation data [AI_SUGGESTED_NAME: tempAnimationData]
Definition: legoanimactor.h:42
~LegoAnimActorStruct()
[AI] Destructor: Deallocates dynamic vector data associated with the animation entry.