Isle
Loading...
Searching...
No Matches
legomodelpresenter.cpp
Go to the documentation of this file.
2
4#include "anim/legoanim.h"
5#include "define.h"
7#include "legoentity.h"
9#include "legovideomanager.h"
10#include "legoworld.h"
11#include "misc.h"
12#include "misc/legocontainer.h"
13#include "misc/legotexture.h"
14#include "misc/version.h"
17#include "mxdssubscriber.h"
18#include "mxutilities.h"
19#include "realtime/realtime.h"
20#include "roi/legoroi.h"
21
23
24// GLOBAL: LEGO1 0x100f7ae0
26
27// FUNCTION: LEGO1 0x1007f660
28void LegoModelPresenter::configureLegoModelPresenter(MxS32 p_modelPresenterConfig)
29{
30 g_modelPresenterConfig = p_modelPresenterConfig;
31}
32
33// FUNCTION: LEGO1 0x1007f670
34void LegoModelPresenter::Destroy(MxBool p_fromDestructor)
35{
37 m_roi = NULL;
38 m_addedToView = FALSE;
40
41 if (!p_fromDestructor) {
43 }
44}
45
46// FUNCTION: LEGO1 0x1007f6b0
47// FUNCTION: BETA10 0x1009845e
48MxResult LegoModelPresenter::CreateROI(MxDSChunk* p_chunk)
49{
50 MxResult result = FAILURE;
51 LegoU32 numROIs;
52 Mx3DPointFloat vect;
53 LegoMemory storage(p_chunk->GetData());
54 LegoAnim anim;
55 LegoU32 version, textureInfoOffset, i, numTextures, skipTextures;
56 MxMatrix mat;
57 LegoChar* textureName = NULL;
58 LegoTexture* texture = NULL;
59 LegoTextureInfo* textureInfo = NULL;
61
62 if (m_roi) {
63 delete m_roi;
64 }
65 if (!(m_roi = new LegoROI(VideoManager()->GetRenderer()))) {
66 goto done;
67 }
68 if (storage.Read(&version, sizeof(version)) != SUCCESS) {
69 goto done;
70 }
71 if (version != MODEL_VERSION) {
72 goto done;
73 }
74 if (storage.Read(&textureInfoOffset, sizeof(textureInfoOffset)) != SUCCESS) {
75 goto done;
76 }
77
78 storage.SetPosition(textureInfoOffset);
79
80 if (storage.Read(&numTextures, sizeof(numTextures)) != SUCCESS) {
81 goto done;
82 }
83 if (storage.Read(&skipTextures, sizeof(skipTextures)) != SUCCESS) {
84 goto done;
85 }
86
87 for (i = 0; i < numTextures; i++) {
88 LegoU32 textureNameLength;
89
90 storage.Read(&textureNameLength, sizeof(textureNameLength));
91 textureName = new LegoChar[textureNameLength + 1];
92 storage.Read(textureName, textureNameLength);
93 textureName[textureNameLength] = '\0';
94
95 strlwr(textureName);
96
97 if (textureName[0] == '^') {
98 strcpy(textureName, textureName + 1);
99
101 texture = new LegoTexture();
102 if (texture->Read(&storage, hardwareMode) != SUCCESS) {
103 goto done;
104 }
105
106 LegoTexture* discardTexture = new LegoTexture();
107 if (discardTexture->Read(&storage, FALSE) != SUCCESS) {
108 goto done;
109 }
110 delete discardTexture;
111 }
112 else {
113 LegoTexture* discardTexture = new LegoTexture();
114 if (discardTexture->Read(&storage, FALSE) != SUCCESS) {
115 goto done;
116 }
117 delete discardTexture;
118
119 texture = new LegoTexture();
120 if (texture->Read(&storage, hardwareMode) != SUCCESS) {
121 goto done;
122 }
123 }
124 }
125 else {
126 texture = new LegoTexture();
127 if (texture->Read(&storage, hardwareMode) != SUCCESS) {
128 goto done;
129 }
130 }
131
132 if (!skipTextures) {
133 if (TextureContainer()->Get(textureName) == NULL) {
134 textureInfo = LegoTextureInfo::Create(textureName, texture);
135
136 if (textureInfo == NULL) {
137 goto done;
138 }
139
140 TextureContainer()->Add(textureName, textureInfo);
141 }
142
143 delete[] textureName;
144 textureName = NULL;
145 delete texture;
146 texture = NULL;
147 }
148 }
149
150 storage.SetPosition(8);
151
152 if (storage.Read(&numROIs, sizeof(numROIs)) != SUCCESS) {
153 goto done;
154 }
155 if (anim.Read(&storage, FALSE) != SUCCESS) {
156 goto done;
157 }
158 if (m_roi->Read(NULL, VideoManager()->GetRenderer(), GetViewLODListManager(), TextureContainer(), &storage) !=
159 SUCCESS) {
160 goto done;
161 }
162 if (m_roi->SetFrame(&anim, 0) != SUCCESS) {
163 goto done;
164 }
165
166 // Get scripted location, direction and up vectors
167
172 mat
173 );
175
176 result = SUCCESS;
177
178done:
179 if (textureName != NULL) {
180 delete[] textureName;
181 }
182 if (texture != NULL) {
183 delete texture;
184 }
185 if (result != SUCCESS) {
186 if (m_roi) {
187 delete m_roi;
188 m_roi = NULL;
189 }
190 }
191
192 return result;
193}
194
195// FUNCTION: LEGO1 0x1007ff70
196// FUNCTION: BETA10 0x10099061
198 MxDSChunk& p_chunk,
199 LegoEntity* p_entity,
200 MxBool p_roiVisible,
201 LegoWorld* p_world
202)
203{
204 MxResult result = SUCCESS;
205
206 ParseExtra();
207
208 if (m_roi == NULL && (result = CreateROI(&p_chunk)) == SUCCESS && p_entity != NULL) {
209 VideoManager()->Get3DManager()->Add(*m_roi);
210 VideoManager()->Get3DManager()->Moved(*m_roi);
211 }
212
213 if (m_roi != NULL) {
214 m_roi->SetVisibility(p_roiVisible);
215 }
216
217 if (p_entity != NULL) {
218 p_entity->SetROI(m_roi, TRUE, TRUE);
220 }
221 else {
222 p_world->GetROIList().push_back(m_roi);
223 }
224
225 return result;
226}
227
228// FUNCTION: LEGO1 0x10080050
229// FUNCTION: BETA10 0x100991c2
231{
232 if (m_compositePresenter != NULL && m_compositePresenter->IsA("LegoEntityPresenter") &&
234 return;
235 }
236
237 ParseExtra();
238
239 if (m_roi != NULL) {
240 if (m_compositePresenter && m_compositePresenter->IsA("LegoEntityPresenter")) {
241 ((LegoEntityPresenter*) m_compositePresenter)->GetInternalEntity()->SetROI(m_roi, m_addedToView, TRUE);
243 ->GetInternalEntity()
244 ->SetFlags(
245 ((LegoEntityPresenter*) m_compositePresenter)->GetInternalEntity()->GetFlags() &
246 ~LegoEntity::c_managerOwned
247 );
248 ((LegoEntityPresenter*) m_compositePresenter)->GetInternalEntity()->SetType(LegoEntity::e_actor);
249 }
250
251 ParseExtra();
253 EndAction();
254 }
255 else {
257
258 if (chunk != NULL && chunk->GetTime() <= m_action->GetElapsedTime()) {
259 chunk = m_subscriber->PopData();
260 MxResult result = CreateROI(chunk);
262
263 if (result == SUCCESS) {
264 VideoManager()->Get3DManager()->Add(*m_roi);
265 VideoManager()->Get3DManager()->Moved(*m_roi);
266
267 if (m_compositePresenter != NULL && m_compositePresenter->IsA("LegoEntityPresenter")) {
268 ((LegoEntityPresenter*) m_compositePresenter)->GetInternalEntity()->SetROI(m_roi, TRUE, TRUE);
270 ->GetInternalEntity()
271 ->SetFlags(
272 ((LegoEntityPresenter*) m_compositePresenter)->GetInternalEntity()->GetFlags() &
273 ~LegoEntity::c_managerOwned
274 );
275 }
276
277 ParseExtra();
279 }
280
281 EndAction();
282 }
283 }
284}
285
286// FUNCTION: LEGO1 0x100801b0
287// FUNCTION: BETA10 0x10099443
289{
290 MxU16 extraLength;
291 char* extraData;
292 m_action->GetExtra(extraLength, extraData);
293
294 if (extraLength) {
295 char extraCopy[1024], output[1024];
296 output[0] = '\0';
297 memcpy(extraCopy, extraData, extraLength);
298 extraCopy[extraLength] = '\0';
299
300 if (KeyValueStringParse(output, g_strAUTO_CREATE, extraCopy) != 0) {
301 char* token = strtok(output, g_parseExtraTokens);
302
303 if (m_roi == NULL) {
304 m_roi = CharacterManager()->GetActorROI(token, FALSE);
305 m_addedToView = FALSE;
306 }
307 }
308 else if (KeyValueStringParse(output, g_strDB_CREATE, extraCopy) != 0 && m_roi == NULL) {
309 LegoWorld* currentWorld = CurrentWorld();
310 list<LegoROI*>& roiList = currentWorld->GetROIList();
311
312 for (list<LegoROI*>::iterator it = roiList.begin(); it != roiList.end(); it++) {
313 if (!strcmpi((*it)->GetName(), output)) {
314 m_roi = *it;
315 roiList.erase(it);
316
317 m_addedToView = TRUE;
318 VideoManager()->Get3DManager()->Add(*m_roi);
319 VideoManager()->Get3DManager()->Moved(*m_roi);
320 break;
321 }
322 }
323 }
324 }
325}
BOOL Moved(ViewROI &rROI)
[AI] Notifies the manager that the ROI has moved and needs spatial update.
BOOL Add(ViewROI &rROI)
[AI] Adds a ViewROI (rendered object) to the scene.
[AI] Root class for all node-based animation blending/structure.
Definition: legoanim.h:356
virtual LegoResult Read(LegoStorage *p_storage, LegoS32 p_parseScene)
[AI] Loads model and animation data from storage, optionally including scene/camera animation.
Definition: legoanim.cpp:1038
LegoROI * GetActorROI(const char *p_name, MxBool p_createEntity)
[AI] Returns a LegoROI for the given character name, creating and registering the actor if necessary.
void Add(const char *p_name, T *p_value)
Add an element mapped to the given name, replacing existing item if present.
[AI] Presenter responsible for managing the lifecycle, location, and logic for a LegoEntity instance ...
[AI] Represents an entity that can be placed and managed in the LEGO Island world.
Definition: legoentity.h:16
virtual void SetROI(LegoROI *p_roi, MxBool p_bool1, MxBool p_bool2)
[AI] Assigns a 3D ROI (3D object instance) to this entity, controlling how it appears/acts in the wor...
Definition: legoentity.cpp:127
void ClearFlag(MxU8 p_flag)
[AI] Clears the given flag in the flags byte.
Definition: legoentity.h:179
@ e_actor
[AI] Standard character entity controlled by scripts or user [AI]
Definition: legoentity.h:20
@ c_managerOwned
[AI] Indicates this entity is managed/owned by an entity manager [AI]
Definition: legoentity.h:30
Implementation of LegoStorage for memory-backed buffers.
Definition: legostorage.h:317
[AI] Presenter class for managing 3D model (ROI) presentation and their relationship with entities in...
MxResult FUN_1007ff70(MxDSChunk &p_chunk, LegoEntity *p_entity, MxBool p_roiVisible, LegoWorld *p_world)
[AI] Loads or associates an ROI for presentation from a chunk, linking it to a LegoEntity or LegoWorl...
void ReadyTickle() override
[AI] Handles the tickle state when moving into the Ready state. If necessary, creates or assigns an R...
void Destroy() override
[AI] Destroys all resources and resets state. Calls base class destroy if not from destructor.
void ParseExtra() override
[AI] Parses and applies extra data from the action, for example to auto-create or DB-create an ROI ba...
[AI] Represents a Real-time Object Instance enriched with LEGO-specific functionality.
Definition: legoroi.h:43
LegoResult SetFrame(LegoAnim *p_anim, LegoTime p_time)
[AI] Sets the current animation frame for this ROI based on a parsed animation structure.
Definition: legoroi.cpp:471
LegoResult Read(OrientableROI *p_unk0xd4, Tgl::Renderer *p_renderer, ViewLODListManager *p_viewLODListManager, LegoTextureContainer *p_textureContainer, LegoStorage *p_storage)
[AI] Reads and initializes this ROI from a LEGO project resource stream, populating geometry,...
Definition: legoroi.cpp:108
[AI] Contains DirectDraw and Direct3DRM handles and metadata for a texture used in the LEGO Island re...
static LegoTextureInfo * Create(const char *p_name, LegoTexture *p_texture)
[AI] Creates a new LegoTextureInfo for a given logical name and loaded LegoTexture.
[AI] Represents a texture which wraps a LegoImage and provides loading/saving functionality.
Definition: legotexture.h:15
LegoResult Read(LegoStorage *p_storage, LegoU32 p_square)
[AI] Reads texture data from a LegoStorage.
Definition: legotexture.cpp:22
MxDirect3D * GetDirect3D()
[AI] Returns the active Direct3D wrapper (engine/utility) object.
Lego3DManager * Get3DManager()
[AI] Returns the Lego3DManager for this manager, which owns all 3D scene representations and view con...
Represents the active 3D world, holding all entity, animation, sound, path, and ROI objects.
Definition: legoworld.h:49
list< LegoROI * > & GetROIList()
Gets the list of all ROIs (Real-time Object Instances) in the world.
Definition: legoworld.h:301
[AI] Represents a 3D point with floating-point precision, inheriting from Vector3.
Definition: mxgeometry3d.h:14
BOOL GetHardwareMode()
[AI] Checks if the device is operating in hardware mode.
Definition: mxdirectxinfo.h:88
MxBool IsA(const char *p_name) const override
[AI] Runtime type checking for presenter class hierarchy, supporting parent/child class checks.
void Enter()
[AI] Acquires/gains entry to the critical section or mutex, blocking if not available.
void Leave()
[AI] Releases/leaves the critical section or mutex.
void GetExtra(MxU16 &p_extraLength, char *&p_extraData)
[AI] Retrieves the extra data and its length for this action.
Definition: mxdsaction.h:168
const Vector3 & GetLocation()
[AI] Gets the location vector for this action (world or local space).
Definition: mxdsaction.h:215
const Vector3 & GetUp()
[AI] Gets the up vector for this action (global or local).
Definition: mxdsaction.h:225
const Vector3 & GetDirection()
[AI] Gets the direction vector (typically forward vector) for this action.
Definition: mxdsaction.h:220
virtual MxLong GetElapsedTime()
[AI] Gets elapsed time for this action since the last time field 0x90 was set.
Definition: mxdsaction.cpp:159
[AI] Represents a chunk of data extracted from a stream (typically from a Mindscape/Mx SI file or str...
Definition: mxdschunk.h:38
MxLong GetTime()
[AI] Returns the time (timestamp or tick) associated with this chunk. [AI]
Definition: mxdschunk.h:102
MxU8 * GetData()
[AI] Returns a pointer to the start of the data payload. [AI]
Definition: mxdschunk.h:108
MxStreamChunk * PopData()
[AI] Pops the next available pending data chunk for consumption, moving it to the consumed list.
void FreeDataChunk(MxStreamChunk *p_chunk)
[AI] Frees (deletes) a data chunk if it's found in the consumed data list; also forcibly deletes sing...
MxStreamChunk * PeekData()
[AI] Returns but does not remove the first pending data chunk ("peek" operation).
MxAssignedDevice * AssignedDevice()
[AI] Returns the currently selected/active rendering device information for 3D output.
Definition: mxdirect3d.h:75
[AI] Represents a 4x4 transformation matrix, specialized for the LEGO Island engine and derived from ...
Definition: mxmatrix.h:16
MxDSSubscriber * m_subscriber
[AI] Subscriber that provides the stream data (e.g., audio/video chunks) for this presenter.
void ProgressTickleState(TickleState p_tickleState)
[AI] Helper for advancing the presenter's tickle state and updating transition history.
Definition: mxpresenter.h:72
MxDSAction * m_action
[AI] The associated action currently being presented by this presenter.
Definition: mxpresenter.h:211
MxS32 GetCurrentTickleState() const
[AI] Returns the current tickle state.
Definition: mxpresenter.h:160
@ e_ready
[AI] Prepared to start processing an action.
Definition: mxpresenter.h:25
@ e_starting
[AI] In the process of starting playback/presentation.
Definition: mxpresenter.h:26
MxCriticalSection m_criticalSection
[AI] Thread synchronization for presenter state and data.
Definition: mxpresenter.h:214
MxCompositePresenter * m_compositePresenter
[AI] Owner composite presenter, if any.
Definition: mxpresenter.h:217
[AI] Represents a streamable chunk of data, typically sourced from a media buffer and designed for no...
Definition: mxstreamchunk.h:19
void EndAction() override
Signals the end of the current playback action.
void Destroy() override
Destroys internal resources for the presenter.
void UpdateTransformationRelativeToParent(const Matrix4 &p_transform)
Calculates and updates the world transform relative to this object's parent, then calls UpdateWorldDa...
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_parseExtraTokens
[AI] Delimiter tokens for parsing extra parameters in scripts or command strings.
Definition: define.cpp:141
const char * g_strAUTO_CREATE
[AI] Used to signal that an object or feature should be automatically created/initialized on load.
Definition: define.cpp:17
const char * g_strDB_CREATE
[AI] Used to indicate an entry should be created for a resource in a data block (DB) at load time.
Definition: define.cpp:45
MxS32 g_modelPresenterConfig
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
unsigned long LegoU32
[AI] Unsigned 32-bit integer type for cross-platform compatibility.
Definition: legotypes.h:71
char LegoChar
[AI] Alias for char, for use in character/byte data and string handling.
Definition: legotypes.h:83
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
Definition: legotypes.h:34
long LegoS32
[AI] Signed 32-bit integer type for cross-platform compatibility.
Definition: legotypes.h:65
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
LegoVideoManager * VideoManager()
[AI] Accessor for the game's LegoVideoManager subsystem. Used for managing 3D/video hardware....
Definition: misc.cpp:29
LegoCharacterManager * CharacterManager()
[AI] Accessor for the character manager, which manages in-game characters/NPCs. [AI]
Definition: misc.cpp:101
ViewLODListManager * GetViewLODListManager()
[AI] Returns the global ViewLODListManager for view LOD (Level of Detail) resources....
Definition: misc.cpp:136
LegoWorld * CurrentWorld()
[AI] Accessor for the currently active LegoWorld instance. [AI]
Definition: misc.cpp:93
LegoTextureContainer * TextureContainer()
[AI] Accessor for the texture container used for global texture management. [AI]
Definition: misc.cpp:130
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned short MxU16
[AI]
Definition: mxtypes.h:20
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
void CalcLocalTransform(const Vector3 &p_posVec, const Vector3 &p_dirVec, const Vector3 &p_upVec, Matrix4 &p_outMatrix)
[AI] Computes a transformation matrix based on a position, direction, and up vector.
Definition: realtime.cpp:7
#define MODEL_VERSION
[AI] Represents the version number of the game model/resources.
Definition: version.h:9