Isle
Loading...
Searching...
No Matches
modeldb.cpp
Go to the documentation of this file.
1#include "modeldb.h"
2
8
9// FUNCTION: LEGO1 0x10027690
10// FUNCTION: BETA10 0x100e5620
11void ModelDbModel::Free()
12{
13 delete[] m_modelName;
14 delete[] m_presenterName;
15}
16
17// FUNCTION: LEGO1 0x100276b0
19{
20 MxU32 len;
21
22 if (fread(&len, sizeof(len), 1, p_file) != 1) {
23 return FAILURE;
24 }
25
26 m_modelName = new char[len];
27 if (fread(m_modelName, len, 1, p_file) != 1) {
28 return FAILURE;
29 }
30
31 if (fread(&m_modelDataLength, sizeof(m_modelDataLength), 1, p_file) != 1) {
32 return FAILURE;
33 }
34 if (fread(&m_modelDataOffset, sizeof(m_modelDataOffset), 1, p_file) != 1) {
35 return FAILURE;
36 }
37 if (fread(&len, sizeof(len), 1, p_file) != 1) {
38 return FAILURE;
39 }
40
41 m_presenterName = new char[len];
42 if (fread(m_presenterName, len, 1, p_file) != 1) {
43 return FAILURE;
44 }
45
46 if (fread(&m_location, sizeof(*m_location), 3, p_file) != 3) {
47 return FAILURE;
48 }
49 if (fread(&m_direction, sizeof(*m_direction), 3, p_file) != 3) {
50 return FAILURE;
51 }
52 if (fread(&m_up, sizeof(*m_up), 3, p_file) != 3) {
53 return FAILURE;
54 }
55 if (fread(&m_unk0x34, sizeof(m_unk0x34), 1, p_file) != 1) {
56 return FAILURE;
57 }
58
59 return SUCCESS;
60}
61
62// FUNCTION: LEGO1 0x10027850
64{
65 MxU32 len;
66 char buff[128];
67
68 if (fread(&len, sizeof(len), 1, p_file) != 1) {
69 return FAILURE;
70 }
71
72 // (modernization) critical bug: buffer overrun
73 if (fread(buff, len, 1, p_file) != 1) {
74 return FAILURE;
75 }
76
77 m_roiName = buff;
78
79 if (fread(&m_partDataLength, sizeof(m_partDataLength), 1, p_file) != 1) {
80 return FAILURE;
81 }
82 if (fread(&m_partDataOffset, sizeof(m_partDataOffset), 1, p_file) != 1) {
83 return FAILURE;
84 }
85
86 return SUCCESS;
87}
88
89// FUNCTION: LEGO1 0x10027910
90MxResult ReadModelDbWorlds(FILE* p_file, ModelDbWorld*& p_worlds, MxS32& p_numWorlds)
91{
92 p_worlds = NULL;
93 p_numWorlds = 0;
94
95 MxS32 numWorlds;
96 if (fread(&numWorlds, sizeof(numWorlds), 1, p_file) != 1) {
97 return FAILURE;
98 }
99
100 ModelDbWorld* worlds = new ModelDbWorld[numWorlds];
101 MxS32 worldNameLen, numParts, i, j;
102
103 for (i = 0; i < numWorlds; i++) {
104 if (fread(&worldNameLen, sizeof(worldNameLen), 1, p_file) != 1) {
105 return FAILURE;
106 }
107
108 worlds[i].m_worldName = new char[worldNameLen];
109 if (fread(worlds[i].m_worldName, worldNameLen, 1, p_file) != 1) {
110 return FAILURE;
111 }
112
113 if (fread(&numParts, sizeof(numParts), 1, p_file) != 1) {
114 return FAILURE;
115 }
116
117 worlds[i].m_partList = new ModelDbPartList();
118
119 for (j = 0; j < numParts; j++) {
120 ModelDbPart* part = new ModelDbPart();
121
122 if (part->Read(p_file) != SUCCESS) {
123 return FAILURE;
124 }
125
126 worlds[i].m_partList->Append(part);
127 }
128
129 if (fread(&worlds[i].m_numModels, sizeof(worlds[i].m_numModels), 1, p_file) != 1) {
130 return FAILURE;
131 }
132
133 worlds[i].m_models = new ModelDbModel[worlds[i].m_numModels];
134
135 for (j = 0; j < worlds[i].m_numModels; j++) {
136 if (worlds[i].m_models[j].Read(p_file) != SUCCESS) {
137 return FAILURE;
138 }
139 }
140 }
141
142 p_worlds = worlds;
143 p_numWorlds = numWorlds;
144 return SUCCESS;
145}
146
147// FUNCTION: LEGO1 0x10028080
148// FUNCTION: BETA10 0x100e6431
149void FreeModelDbWorlds(ModelDbWorld*& p_worlds, MxS32 p_numWorlds)
150{
151 ModelDbWorld* worlds = p_worlds;
152
153 for (MxS32 i = 0; i < p_numWorlds; i++) {
154 delete[] worlds[i].m_worldName;
155
156 ModelDbPartListCursor cursor(worlds[i].m_partList);
157 ModelDbPart* part;
158
159 while (cursor.Next(part)) {
160 delete part;
161 }
162
163 delete worlds[i].m_partList;
164
165 ModelDbModel* models = worlds[i].m_models;
166 for (MxS32 j = 0; j < worlds[i].m_numModels; j++) {
167 models[j].Free();
168 }
169
170 delete[] worlds[i].m_models;
171 }
172
173 delete[] p_worlds;
174 p_worlds = NULL;
175}
[AI] Iterator for traversing ModelDbPartList contents (ModelDbPart pointers).
Definition: modeldb.h:87
[AI] Collection class representing a list of ModelDbPart pointers with custom comparison logic.
Definition: modeldb.h:44
MxBool Next()
[AI]
void Append(T p_obj)
[AI]
Definition: mxlist.h:100
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#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
MxResult ReadModelDbWorlds(FILE *p_file, ModelDbWorld *&p_worlds, MxS32 &p_numWorlds)
[AI] Reads the collection of worlds (ModelDbWorld) from a model database file.
Definition: modeldb.cpp:90
void FreeModelDbWorlds(ModelDbWorld *&p_worlds, MxS32 p_numWorlds)
[AI] Frees all resources related to ModelDbWorlds previously allocated by ReadModelDbWorlds.
Definition: modeldb.cpp:149
MxLong MxResult
[AI]
Definition: mxtypes.h:106
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
[AI] Represents a 3D model entry in a model database, including metadata and spatial transform info.
Definition: modeldb.h:132
char * m_presenterName
[AI] Name of the presenter/handler class used for this model, dynamically allocated....
Definition: modeldb.h:150
MxU32 m_modelDataLength
[AI] Length of the model's raw data in the file, in bytes. [AI]
Definition: modeldb.h:148
undefined m_unk0x34
[AI] Unknown field, possibly additional flags or type (purpose currently unknown)....
Definition: modeldb.h:154
char * m_modelName
[AI] Name of the model, dynamically allocated. [AI]
Definition: modeldb.h:147
float m_location[3]
[AI] World-space position of the model origin (as a 3D vector). [AI]
Definition: modeldb.h:151
float m_up[3]
[AI] World-space up vector (indicates model "up" orientation). [AI]
Definition: modeldb.h:153
MxU32 m_modelDataOffset
[AI] File offset to the model's raw data. [AI]
Definition: modeldb.h:149
float m_direction[3]
[AI] World-space direction vector (indicates model "forward" direction). [AI]
Definition: modeldb.h:152
MxResult Read(FILE *p_file)
[AI] Loads a ModelDbModel from the current file pointer.
Definition: modeldb.cpp:18
void Free()
[AI] Frees dynamically allocated memory in the model (model name and presenter name).
Definition: modeldb.cpp:11
[AI] Represents a single part within a 3D model database entry, including its name and data offsets i...
Definition: modeldb.h:17
MxString m_roiName
[AI] Name of the part/ROI this entry represents. [AI]
Definition: modeldb.h:26
undefined4 m_partDataOffset
[AI] Offset within the file to the part's data. [AI]
Definition: modeldb.h:28
undefined4 m_partDataLength
[AI] Length of binary part data in the file (in bytes). [AI]
Definition: modeldb.h:27
MxResult Read(FILE *p_file)
[AI] Reads a ModelDbPart object from a binary file.
Definition: modeldb.cpp:63
[AI] Represents a world/scene in the model database, containing its parts and models.
Definition: modeldb.h:163
MxS32 m_numModels
[AI] Number of models in the array m_models. [AI]
Definition: modeldb.h:167
ModelDbModel * m_models
[AI] Array of models within this world. [AI]
Definition: modeldb.h:166
char * m_worldName
[AI] Name of the world (scene); dynamically allocated on read. [AI]
Definition: modeldb.h:164
ModelDbPartList * m_partList
[AI] List of model parts belonging to this world. [AI]
Definition: modeldb.h:165