Isle
Loading...
Searching...
No Matches
mxdsaction.cpp
Go to the documentation of this file.
1#include "mxdsaction.h"
2
3#include "mxmisc.h"
4#include "mxtimer.h"
5#include "mxutilities.h"
6
7#include <assert.h>
8#include <float.h>
9#include <limits.h>
10
12
13// GLOBAL: LEGO1 0x10101410
14// GLOBAL: BETA10 0x10201f5c
15MxU16 g_sep = TWOCC(',', ' ');
16
17// FUNCTION: LEGO1 0x100ad810
18// FUNCTION: BETA10 0x1012afd0
20{
21 m_type = e_action;
22 m_flags = MxDSAction::c_enabled;
23 m_extraLength = 0;
24 m_extraData = NULL;
25 m_startTime = INT_MIN;
26 m_duration = INT_MIN;
27 m_loopCount = -1;
28 m_location.Fill(FLT_MAX);
29 m_direction.Fill(FLT_MAX);
30 m_up.Fill(FLT_MAX);
31 m_unk0x84 = NULL;
32 m_unk0x88 = 0;
33 m_origin = NULL;
34 m_unk0x90 = INT_MIN;
35}
36
37// FUNCTION: LEGO1 0x100ad940
38// FUNCTION: BETA10 0x1012bc50
40{
41 return m_duration;
42}
43
44// FUNCTION: LEGO1 0x100ad950
45// FUNCTION: BETA10 0x1012bc90
47{
48 m_duration = p_duration;
49}
50
51// FUNCTION: LEGO1 0x100ad960
52// FUNCTION: BETA10 0x1012bcc0
54{
55 return m_objectId == p_objectId;
56}
57
58// FUNCTION: LEGO1 0x100ada40
59// FUNCTION: BETA10 0x1012bdf0
61{
62 m_unk0x90 = p_unk0x90;
63}
64
65// FUNCTION: LEGO1 0x100ada50
66// FUNCTION: BETA10 0x1012be20
68{
69 return m_unk0x90;
70}
71
72// FUNCTION: LEGO1 0x100ada80
73// FUNCTION: BETA10 0x1012b144
75{
76 delete[] m_extraData;
77}
78
79// FUNCTION: LEGO1 0x100adaf0
80// FUNCTION: BETA10 0x1012b1c7
82{
83 m_objectId = p_dsAction.m_objectId;
84 m_flags = p_dsAction.m_flags;
85 m_startTime = p_dsAction.m_startTime;
86 m_duration = p_dsAction.m_duration;
87 m_loopCount = p_dsAction.m_loopCount;
88 m_location = p_dsAction.m_location;
89 m_direction = p_dsAction.m_direction;
90 m_up = p_dsAction.m_up;
91 AppendExtra(p_dsAction.m_extraLength, p_dsAction.m_extraData);
92 m_unk0x84 = p_dsAction.m_unk0x84;
93 m_unk0x88 = p_dsAction.m_unk0x88;
94 m_origin = p_dsAction.m_origin;
95 m_unk0x90 = p_dsAction.m_unk0x90;
96}
97
98// FUNCTION: BETA10 0x1012b2b3
100{
101 CopyFrom(p_dsAction);
102}
103
104// FUNCTION: LEGO1 0x100adbd0
105// FUNCTION: BETA10 0x1012b355
107{
108 return MxDSObject::VTable0x14();
109}
110
111// FUNCTION: LEGO1 0x100adbe0
112// FUNCTION: BETA10 0x1012b373
114{
116 size += sizeof(m_flags);
117 size += sizeof(m_startTime);
118 size += sizeof(m_duration);
119 size += sizeof(m_loopCount);
120 size += sizeof(double) * 3; // m_location
121 size += sizeof(double) * 3; // m_direction
122 size += sizeof(double) * 3; // m_up
123 size += sizeof(m_extraLength);
124 size += m_extraLength;
125
127
128 return size;
129}
130
131// FUNCTION: LEGO1 0x100adc10
132// FUNCTION: BETA10 0x1012b3d9
134{
135 if (this == &p_dsAction) {
136 return *this;
137 }
138
139 MxDSObject::operator=(p_dsAction);
140 CopyFrom(p_dsAction);
141 return *this;
142}
143
144// FUNCTION: LEGO1 0x100adc40
145// FUNCTION: BETA10 0x1012b420
147{
148 MxDSAction* clone = new MxDSAction();
149
150 if (clone) {
151 *clone = *this;
152 }
153
154 return clone;
155}
156
157// FUNCTION: LEGO1 0x100adcd0
158// FUNCTION: BETA10 0x1012b4ca
160{
161 return Timer()->GetTime() - m_unk0x90;
162}
163
164// FUNCTION: LEGO1 0x100add00
165// FUNCTION: BETA10 0x1012b4f5
167{
168 if (p_dsAction.GetStartTime() != INT_MIN) {
169 m_startTime = p_dsAction.GetStartTime();
170 }
171
172 if (p_dsAction.GetDuration() != INT_MIN) {
173 m_duration = p_dsAction.GetDuration();
174 }
175
176 if (p_dsAction.GetLoopCount() != -1) {
177 m_loopCount = p_dsAction.GetLoopCount();
178 }
179
180 if (p_dsAction.GetLocation()[0] != FLT_MAX) {
181 m_location[0] = p_dsAction.GetLocation()[0];
182 }
183 if (p_dsAction.GetLocation()[1] != FLT_MAX) {
184 m_location[1] = p_dsAction.GetLocation()[1];
185 }
186 if (p_dsAction.GetLocation()[2] != FLT_MAX) {
187 m_location[2] = p_dsAction.GetLocation()[2];
188 }
189
190 if (p_dsAction.GetDirection()[0] != FLT_MAX) {
191 m_direction[0] = p_dsAction.GetDirection()[0];
192 }
193 if (p_dsAction.GetDirection()[1] != FLT_MAX) {
194 m_direction[1] = p_dsAction.GetDirection()[1];
195 }
196 if (p_dsAction.GetDirection()[2] != FLT_MAX) {
197 m_direction[2] = p_dsAction.GetUp()[2]; // This is correct
198 }
199
200 if (p_dsAction.GetUp()[0] != FLT_MAX) {
201 m_up[0] = p_dsAction.GetUp()[0];
202 }
203 if (p_dsAction.GetUp()[1] != FLT_MAX) {
204 m_up[1] = p_dsAction.GetUp()[1];
205 }
206 if (p_dsAction.GetUp()[2] != FLT_MAX) {
207 m_up[2] = p_dsAction.GetUp()[2];
208 }
209
210 MxU16 extraLength;
211 char* extraData;
212 p_dsAction.GetExtra(extraLength, extraData);
213
214 if (extraLength && extraData) {
215 if (!m_extraData || !strncmp("XXX", m_extraData, 3)) {
216 delete[] m_extraData;
217 m_extraLength = 0;
218 AppendExtra(extraLength, extraData);
219 }
220 }
221}
222
223// FUNCTION: LEGO1 0x100ade60
224// FUNCTION: BETA10 0x1012b8a9
225void MxDSAction::AppendExtra(MxU16 p_extraLength, const char* p_extraData)
226{
227 if (m_extraData == p_extraData) {
228 return;
229 }
230
231 if (p_extraData) {
232 if (m_extraLength) {
233 char* newExtra = new char[p_extraLength + m_extraLength + sizeof(g_sep)];
234 assert(newExtra);
235 memcpy(newExtra, m_extraData, m_extraLength);
236 memcpy(&newExtra[m_extraLength], &g_sep, sizeof(g_sep));
237 memcpy(&newExtra[m_extraLength + sizeof(g_sep)], p_extraData, p_extraLength);
238
239 m_extraLength += p_extraLength + sizeof(g_sep);
240 delete[] m_extraData;
241 m_extraData = newExtra;
242 }
243 else {
244 m_extraData = new char[p_extraLength];
245
246 if (m_extraData) {
247 m_extraLength = p_extraLength;
248 memcpy(m_extraData, p_extraData, p_extraLength);
249 }
250 else {
251 assert(0);
252 }
253 }
254 }
255}
256
257// FUNCTION: LEGO1 0x100adf70
258// FUNCTION: BETA10 0x1012ba6a
259void MxDSAction::Deserialize(MxU8*& p_source, MxS16 p_flags)
260{
261 MxDSObject::Deserialize(p_source, p_flags);
262
263 // clang-format off
264 m_flags = *( MxU32*) p_source; p_source += sizeof(m_flags);
265 m_startTime = *(MxLong*) p_source; p_source += sizeof(m_startTime);
266 m_duration = *(MxLong*) p_source; p_source += sizeof(m_duration);
267 m_loopCount = *( MxS32*) p_source; p_source += sizeof(m_loopCount);
268 m_location[0] = *(double*) p_source; p_source += sizeof(double);
269 m_location[1] = *(double*) p_source; p_source += sizeof(double);
270 m_location[2] = *(double*) p_source; p_source += sizeof(double);
271 m_direction[0] = *(double*) p_source; p_source += sizeof(double);
272 m_direction[1] = *(double*) p_source; p_source += sizeof(double);
273 m_direction[2] = *(double*) p_source; p_source += sizeof(double);
274 m_up[0] = *(double*) p_source; p_source += sizeof(double);
275 m_up[1] = *(double*) p_source; p_source += sizeof(double);
276 m_up[2] = *(double*) p_source; p_source += sizeof(double);
277
278 MxU16 extraLength = *( MxU16*) p_source; p_source += sizeof(extraLength);
279 // clang-format on
280
281 if (extraLength) {
282 AppendExtra(extraLength, (char*) p_source);
283 p_source += extraLength;
284 }
285}
[AI] Represents an action deserialized from SI chunks, holding key animation or script parameters suc...
Definition: mxdsaction.h:17
undefined4 VTable0x14() override
[AI] Unknown virtual placeholder, possibly for additional interfaces.
Definition: mxdsaction.cpp:106
virtual void SetDuration(MxLong p_duration)
[AI] Sets the duration of this action in ticks or time units.
Definition: mxdsaction.cpp:46
MxU32 GetSizeOnDisk() override
[AI] Serializes the size on disk of this action (all fields + extra data length)
Definition: mxdsaction.cpp:113
undefined4 m_unk0x88
[AI] 4 bytes at 0x88; usage not known.
Definition: mxdsaction.h:340
MxDSAction & operator=(MxDSAction &p_dsAction)
[AI] Assignment operator: deep-copy from a different MxDSAction, including base class data and extra ...
Definition: mxdsaction.cpp:133
MxLong GetStartTime() const
[AI] Gets the nominal start time for the action, as loaded or scheduled.
Definition: mxdsaction.h:198
virtual MxBool HasId(MxU32 p_objectId)
[AI] Checks if this action contains/was created for a specific SI object id.
Definition: mxdsaction.cpp:53
char * m_extraData
[AI] Opaque extra data for custom or extended behavior.
Definition: mxdsaction.h:325
void CopyFrom(MxDSAction &p_dsAction)
[AI] Copies all properties from another MxDSAction (deep copy, including extra data string)
Definition: mxdsaction.cpp:81
void GetExtra(MxU16 &p_extraLength, char *&p_extraData)
[AI] Retrieves the extra data and its length for this action.
Definition: mxdsaction.h:168
void Deserialize(MxU8 *&p_source, MxS16 p_unk0x24) override
[AI] Deserializes this action's data from a binary buffer.
Definition: mxdsaction.cpp:259
Mx3DPointFloat m_up
[AI] "Up" vector for this action.
Definition: mxdsaction.h:320
MxS32 GetLoopCount()
[AI] Returns the loop count for this action.
Definition: mxdsaction.h:203
virtual void SetUnknown90(MxLong p_unk0x90)
[AI] Set unknown value at offset 0x90, used as baseline in GetElapsedTime.
Definition: mxdsaction.cpp:60
MxDSAction()
[AI] Default constructor.
Definition: mxdsaction.cpp:19
virtual MxLong GetUnknown90()
[AI] Gets the unknown value at offset 0x90, likely a start timestamp.
Definition: mxdsaction.cpp:67
MxS32 m_loopCount
[AI] Number of times to repeat the action, or -1 for infinite/not-set.
Definition: mxdsaction.h:305
MxU32 m_flags
[AI] Bitfield for flags (enabled, looping, etc).
Definition: mxdsaction.h:290
Mx3DPointFloat m_location
[AI] Location in 3D world or local space (x, y, z).
Definition: mxdsaction.h:310
const Vector3 & GetLocation()
[AI] Gets the location vector for this action (world or local space).
Definition: mxdsaction.h:215
MxCore * m_origin
[AI] Pointer to an "origin" MxCore object, for spatial/ownership reference.
Definition: mxdsaction.h:345
void AppendExtra(MxU16 p_extraLength, const char *p_extraData)
[AI] Concatenates or stores extra data associated with this action, robust for multi-part actions.
Definition: mxdsaction.cpp:225
const Vector3 & GetUp()
[AI] Gets the up vector for this action (global or local).
Definition: mxdsaction.h:225
MxU16 m_extraLength
[AI] Length of extra data in bytes.
Definition: mxdsaction.h:330
const Vector3 & GetDirection()
[AI] Gets the direction vector (typically forward vector) for this action.
Definition: mxdsaction.h:220
virtual MxLong GetDuration()
[AI] Gets the duration for which this action is intended to run.
Definition: mxdsaction.cpp:39
MxLong m_duration
[AI] The duration to run the action, or INT_MIN for undefined.
Definition: mxdsaction.h:300
virtual MxLong GetElapsedTime()
[AI] Gets elapsed time for this action since the last time field 0x90 was set.
Definition: mxdsaction.cpp:159
MxCore * m_unk0x84
[AI] Pointer to an auxiliary MxCore object, purpose unknown.
Definition: mxdsaction.h:335
MxLong m_startTime
[AI] Time at which the action is meant to start, or INT_MIN for unset.
Definition: mxdsaction.h:295
virtual MxDSAction * Clone()
[AI] Clones (deep-copies) this action and returns a new pointer.
Definition: mxdsaction.cpp:146
virtual void MergeFrom(MxDSAction &p_dsAction)
[AI] Copies/merges properties from another action.
Definition: mxdsaction.cpp:166
@ c_enabled
[AI] Action is currently enabled [AI]
Definition: mxdsaction.h:25
MxU32 m_sizeOnDisk
[AI] The size of this action's fields on disk, not counting ancestor size.
Definition: mxdsaction.h:285
MxLong m_unk0x90
[AI] Unknown field, appears to store a timestamp for GetElapsedTime logics.
Definition: mxdsaction.h:350
~MxDSAction() override
[AI] Destructor.
Definition: mxdsaction.cpp:74
Mx3DPointFloat m_direction
[AI] "Forward" direction vector for this action.
Definition: mxdsaction.h:315
[AI] Base class for any object deserialized from an SI (script/data) file in the LEGO Island engine.
Definition: mxdsobject.h:44
MxDSObject & operator=(MxDSObject &p_dsObject)
[AI] Assignment operator.
Definition: mxdsobject.cpp:65
virtual MxU32 GetSizeOnDisk()
[AI] Calculates serialized size of this object on disk (for buffer allocation).
Definition: mxdsobject.cpp:129
MxU32 m_objectId
[AI] Numeric id (unique per file or context, often -1). [AI]
Definition: mxdsobject.h:170
virtual void Deserialize(MxU8 *&p_source, MxS16 p_unk0x24)
[AI] Initializes this object from serialized (memory buffer) data.
Definition: mxdsobject.cpp:159
virtual undefined4 VTable0x14()
[AI] Placeholder for early vtable slot (purpose unknown, may be used for RTTI).
Definition: mxdsobject.cpp:121
MxLong GetTime()
Returns the current timer value in ms, depending on running state.
Definition: mxtimer.h:50
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
unsigned int undefined4
Definition: decomp.h:28
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
MxU16 g_sep
Definition: mxdsaction.cpp:15
MxTimer * Timer()
[AI] Returns the global simulation timer.
Definition: mxmisc.cpp:33
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
#define TWOCC(a, b)
[AI] Macro to compose a 16-bit code from two 8-bit characters (e.g., for type IDs).
Definition: mxtypes.h:151
int MxLong
[AI]
Definition: mxtypes.h:83
signed short MxS16
[AI]
Definition: mxtypes.h:26
unsigned char MxU8
[AI]
Definition: mxtypes.h:8
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned short MxU16
[AI]
Definition: mxtypes.h:20
unsigned int MxU32
[AI]
Definition: mxtypes.h:32