Isle
Loading...
Searching...
No Matches
legopartpresenter.cpp
Go to the documentation of this file.
1#include "legopartpresenter.h"
2
3#include "legovideomanager.h"
4#include "misc.h"
6#include "misc/legostorage.h"
7#include "misc/legotexture.h"
9#include "mxdsaction.h"
10#include "mxdssubscriber.h"
12
16
17// GLOBAL: LEGO1 0x100f7aa0
19
20// GLOBAL: LEGO1 0x100f7aa4
22
23// FUNCTION: LEGO1 0x1007c990
24void LegoPartPresenter::configureLegoPartPresenter(MxS32 p_partPresenterConfig1, MxS32 p_partPresenterConfig2)
25{
26 g_partPresenterConfig1 = p_partPresenterConfig1;
27 g_partPresenterConfig2 = p_partPresenterConfig2;
28}
29
30// FUNCTION: LEGO1 0x1007c9b0
32{
34 return SUCCESS;
35}
36
37// FUNCTION: LEGO1 0x1007c9d0
38void LegoPartPresenter::Destroy(MxBool p_fromDestructor)
39{
42
43 if (m_parts) {
44 delete m_parts;
45 m_parts = NULL;
46 }
47 m_parts = NULL;
48
50 if (!p_fromDestructor) {
52 }
53}
54
55// FUNCTION: LEGO1 0x1007ca30
57{
58 MxResult result = FAILURE;
59 LegoU32 numROIs, numLODs;
60 LegoMemory storage(p_chunk.GetData());
61 LegoU32 textureInfoOffset, i, j, numTextures;
62 LegoU32 roiNameLength, roiInfoOffset, surplusLODs;
63 LegoLODList* lods;
64 LegoNamedPart* namedPart;
65 LegoChar* roiName = NULL;
66 LegoChar* textureName = NULL;
67 LegoTexture* texture = NULL;
68 LegoTextureInfo* textureInfo = NULL;
70
71 if (storage.Read(&textureInfoOffset, sizeof(textureInfoOffset)) != SUCCESS) {
72 goto done;
73 }
74 if (storage.SetPosition(textureInfoOffset) != SUCCESS) {
75 goto done;
76 }
77 if (storage.Read(&numTextures, sizeof(numTextures)) != SUCCESS) {
78 goto done;
79 }
80
81 for (i = 0; i < numTextures; i++) {
82 LegoU32 textureNameLength;
83
84 storage.Read(&textureNameLength, sizeof(textureNameLength));
85 textureName = new LegoChar[textureNameLength + 1];
86 storage.Read(textureName, textureNameLength);
87 textureName[textureNameLength] = '\0';
88
89 strlwr(textureName);
90
91 if (textureName[0] == '^') {
92 strcpy(textureName, textureName + 1);
93
95 texture = new LegoTexture();
96 if (texture->Read(&storage, hardwareMode) != SUCCESS) {
97 goto done;
98 }
99
100 LegoTexture* discardTexture = new LegoTexture();
101 if (discardTexture->Read(&storage, FALSE) != SUCCESS) {
102 goto done;
103 }
104 delete discardTexture;
105 }
106 else {
107 LegoTexture* discardTexture = new LegoTexture();
108 if (discardTexture->Read(&storage, FALSE) != SUCCESS) {
109 goto done;
110 }
111 delete discardTexture;
112
113 texture = new LegoTexture();
114 if (texture->Read(&storage, hardwareMode) != SUCCESS) {
115 goto done;
116 }
117 }
118 }
119 else {
120 texture = new LegoTexture();
121 if (texture->Read(&storage, hardwareMode) != SUCCESS) {
122 goto done;
123 }
124 }
125
126 if (TextureContainer()->Get(textureName) == NULL) {
127 textureInfo = LegoTextureInfo::Create(textureName, texture);
128
129 if (textureInfo == NULL) {
130 goto done;
131 }
132
133 TextureContainer()->Add(textureName, textureInfo);
134 }
135
136 delete[] textureName;
137 textureName = NULL;
138 delete texture;
139 texture = NULL;
140 }
141
142 if (storage.SetPosition(4) != SUCCESS) {
143 goto done;
144 }
145
146 m_parts = new LegoNamedPartList();
147
148 if (storage.Read(&numROIs, sizeof(numROIs)) != SUCCESS) {
149 goto done;
150 }
151
152 for (i = 0; i < numROIs; i++) {
153 if (storage.Read(&roiNameLength, sizeof(roiNameLength)) != SUCCESS) {
154 goto done;
155 }
156
157 roiName = new LegoChar[roiNameLength + 1];
158 if (storage.Read(roiName, roiNameLength) != SUCCESS) {
159 goto done;
160 }
161
162 roiName[roiNameLength] = '\0';
163 strlwr(roiName);
164
165 if (storage.Read(&numLODs, sizeof(numLODs)) != SUCCESS) {
166 goto done;
167 }
168 if (storage.Read(&roiInfoOffset, sizeof(roiInfoOffset)) != SUCCESS) {
169 goto done;
170 }
171
172 if (numLODs > g_partPresenterConfig2) {
173 surplusLODs = numLODs - g_partPresenterConfig2;
174 numLODs = g_partPresenterConfig2;
175 }
176 else {
177 surplusLODs = 0;
178 }
179
180 lods = new LegoLODList();
181
182 for (j = 0; j < numLODs; j++) {
183 LegoLOD* lod = new LegoLOD(VideoManager()->GetRenderer());
184
185 if (lod->Read(VideoManager()->GetRenderer(), TextureContainer(), &storage) != SUCCESS) {
186 goto done;
187 }
188
189 if (j == 0) {
190 if (surplusLODs != 0 && lod->GetUnknown0x08Test8()) {
191 numLODs++;
192 surplusLODs--;
193 }
194 }
195
196 lods->Append(lod);
197 }
198
199 storage.SetPosition(roiInfoOffset);
200
201 namedPart = new LegoNamedPart(roiName, lods);
202 m_parts->Append(namedPart);
203
204 delete[] roiName;
205 roiName = NULL;
206 }
207
208 result = SUCCESS;
209
210done:
211 if (roiName != NULL) {
212 delete[] roiName;
213 }
214 if (result != SUCCESS && m_parts != NULL) {
215 delete m_parts;
216 m_parts = NULL;
217 }
218
219 return result;
220}
221
222// FUNCTION: LEGO1 0x1007deb0
224{
226
227 if (chunk != NULL && chunk->GetTime() <= m_action->GetElapsedTime()) {
228 ParseExtra();
230
231 chunk = m_subscriber->PopData();
232 MxResult result = Read(*chunk);
234
235 if (result == SUCCESS) {
236 Store();
237 }
238
239 EndAction();
240 }
241}
242
243// FUNCTION: LEGO1 0x1007df20
245{
246 LegoNamedPartListCursor partCursor(m_parts);
247 LegoNamedPart* part;
248
249 while (partCursor.Next(part)) {
250 ViewLODList* lodList = GetViewLODListManager()->Lookup(part->GetName()->GetData());
251
252 if (lodList == NULL) {
253 lodList = GetViewLODListManager()->Create(part->GetName()->GetData(), part->GetList()->GetNumElements());
254
255 LegoLODListCursor lodCursor(part->GetList());
256 LegoLOD* lod;
257
258 while (lodCursor.First(lod)) {
259 lodCursor.Detach();
260 lodList->PushBack(lod);
261 }
262 }
263 else {
264 lodList->Release();
265 }
266 }
267
268 if (m_parts != NULL) {
269 delete m_parts;
270 }
271
272 m_parts = NULL;
273}
const T * PushBack(const T *)
[AI] Typed append.
Definition: lodlist.h:243
void Add(const char *p_name, T *p_value)
Add an element mapped to the given name, replacing existing item if present.
[AI] Cursor class for traversing a LegoLODList.
Definition: legolodlist.h:53
[AI] Manages a list of LOD (Level-of-Detail) objects used for efficient 3D rendering by trading detai...
Definition: legolodlist.h:27
[AI] Level-Of-Detail (LOD) object used for rendering and managing polygonal mesh data with LOD switch...
Definition: legolod.h:27
LegoResult Read(Tgl::Renderer *p_renderer, LegoTextureContainer *p_textureContainer, LegoStorage *p_storage)
[AI] Load LOD geometry and material info from storage, building Tgl::Mesh group(s).
Definition: legolod.cpp:56
Implementation of LegoStorage for memory-backed buffers.
Definition: legostorage.h:317
LegoResult Read(void *p_buffer, LegoU32 p_size) override
Reads bytes from memory buffer at current position.
Definition: legostorage.cpp:20
LegoResult SetPosition(LegoU32 p_position) override
Sets the current offset into the memory buffer.
Definition: legostorage.h:357
[AI] Cursor/iterator for traversing a LegoNamedPartList.
[AI] A list container for storing pointers to LegoNamedPart objects.
[AI] Encapsulates a named part within a LEGO object that contains a list of LODs (Levels of Detail).
Definition: legonamedpart.h:18
LegoLODList * GetList()
[AI] Accesses the list of LODs associated with this part.
Definition: legonamedpart.h:60
const MxString * GetName() const
[AI] Gets the name of this named part.
Definition: legonamedpart.h:54
[AI] Presents and loads Lego part definitions from SI chunks and manages their installation in ViewLO...
MxResult Read(MxDSChunk &p_chunk)
[AI] Reads Lego part and texture data from a MxDSChunk and builds internal part list.
MxResult AddToManager() override
[AI] Registers this presenter with the VideoManager.
void Destroy() override
[AI] Virtual destroy method called by framework.
void Store()
[AI] Transfers all loaded named Lego parts and LODs to the ViewLODListManager.
void ReadyTickle() override
[AI] Called when entering the Ready tickle state: loads and installs parts from the subscriber stream...
[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.
BOOL GetHardwareMode()
[AI] Checks if the device is operating in hardware mode.
Definition: mxdirectxinfo.h:88
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.
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
MxBool Next()
[AI]
void Detach()
[AI]
MxBool First(T &p_obj)
[AI]
void Append(T p_obj)
[AI]
Definition: mxlist.h:100
MxU32 GetNumElements()
[AI]
Definition: mxlist.h:118
virtual void RegisterPresenter(MxPresenter &p_presenter)
[AI] Register a new presenter for tickle management and playback coordination.
virtual void UnregisterPresenter(MxPresenter &p_presenter)
[AI] Remove a presenter from tickle and managed output lists.
void Destroy() override
[AI] Cleans up internal resources and resets the presenter to an uninitialized state.
void EndAction() override
[AI] Ends the media playback action, releasing all resources, notifying listeners if necessary.
MxDSSubscriber * m_subscriber
[AI] Subscriber that provides the stream data (e.g., audio/video chunks) for this presenter.
virtual void ParseExtra()
[AI] Parses additional data from the associated action for configuration or world interaction.
Definition: mxpresenter.cpp:80
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
@ 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
[AI] Represents a streamable chunk of data, typically sourced from a media buffer and designed for no...
Definition: mxstreamchunk.h:19
char * GetData() const
Returns a pointer to the internal character buffer.
Definition: mxstring.h:110
ViewLODList * Create(const ROIName &rROIName, int lodCount)
[AI] Creates and registers a new ViewLODList for a named ROI, with space for the specified number of ...
Definition: viewlodlist.cpp:67
ViewLODList * Lookup(const ROIName &) const
[AI] Looks up an existing ViewLODList by ROI name, incrementing its reference count.
[AI] Reference-counted list of Level-of-Detail (LOD) objects associated with a single ROI (Realtime O...
Definition: viewlodlist.h:30
int Release()
[AI] Decrements the reference count.
unsigned char GetUnknown0x08Test8()
[AI] Performs a bitwise AND (mask) with value 0xffffff08 on the internal flag, returning result as an...
Definition: viewlod.h:81
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
MxS32 g_partPresenterConfig1
MxS32 g_partPresenterConfig2
#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
ViewLODListManager * GetViewLODListManager()
[AI] Returns the global ViewLODListManager for view LOD (Level of Detail) resources....
Definition: misc.cpp:136
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