-
Notifications
You must be signed in to change notification settings - Fork 72
/
dobj.c
350 lines (290 loc) · 7.69 KB
/
dobj.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#include "dobj.h"
#include "aobj.h"
#include "class.h"
#include "debug.h"
#include "mobj.h"
#include "pobj.h"
#include <dolphin/os.h>
static void DObjInfoInit(void);
HSD_DObjInfo hsdDObj = { DObjInfoInit };
static HSD_ClassInfo* default_class = NULL;
static HSD_DObj* current_dobj = NULL;
static char HSD_DObj_804D5C78[7] = "dobj.c\0";
void HSD_DObjSetCurrent(HSD_DObj* dobj)
{
current_dobj = dobj;
}
u32 HSD_DObjGetFlags(HSD_DObj* dobj)
{
if (dobj != NULL) {
return dobj->flags;
}
return 0;
}
void HSD_DObjSetFlags(HSD_DObj* dobj, u32 flags)
{
if (dobj != NULL) {
dobj->flags |= flags;
}
}
void HSD_DObjClearFlags(HSD_DObj* dobj, u32 flags)
{
if (dobj != NULL) {
dobj->flags &= ~flags;
}
}
void HSD_DObjModifyFlags(HSD_DObj* dobj, u32 flags, u32 mask)
{
if (dobj == NULL) {
return;
}
dobj->flags = (dobj->flags & ~mask) | (flags & mask);
}
void HSD_DObjRemoveAnimByFlags(HSD_DObj* dobj, u32 flags)
{
if (dobj == NULL) {
return;
}
if ((flags & 2) != 0) {
HSD_AObjRemove(dobj->aobj);
dobj->aobj = NULL;
}
HSD_PObjRemoveAnimAllByFlags(dobj->pobj, flags);
HSD_MObjRemoveAnimByFlags(dobj->mobj, flags);
}
void HSD_DObjRemoveAnimAllByFlags(HSD_DObj* dobj, u32 flags)
{
HSD_DObj* dp;
if (dobj == NULL) {
return;
}
for (dp = dobj; dp != NULL; dp = dp->next) {
HSD_DObjRemoveAnimByFlags(dp, flags);
}
}
void HSD_DObjAddAnim(HSD_DObj* dobj, HSD_MatAnim* mat_anim,
HSD_ShapeAnimDObj* sh_anim)
{
HSD_ShapeAnim* shapeanim;
if (dobj == NULL) {
return;
}
if (sh_anim != NULL) {
shapeanim = sh_anim->shapeanim;
} else {
shapeanim = NULL;
}
HSD_PObjAddAnimAll(dobj->pobj, shapeanim);
HSD_MObjAddAnim(dobj->mobj, mat_anim);
}
void HSD_DObjAddAnimAll(HSD_DObj* dobj, HSD_MatAnim* matanim,
HSD_ShapeAnimDObj* shapeanimdobj)
{
HSD_DObj* dp;
HSD_MatAnim* ma;
HSD_ShapeAnimDObj* sd;
if (dobj == NULL) {
return;
}
for (dp = dobj, ma = matanim, sd = shapeanimdobj; dp != NULL;
dp = dp->next, ma = next_p(ma), sd = next_p(sd))
{
HSD_DObjAddAnim(dp, ma, sd);
}
}
void HSD_DObjReqAnimByFlags(HSD_DObj* dobj, f32 startframe, u32 flags)
{
if (dobj == NULL) {
return;
}
HSD_PObjReqAnimAllByFlags(dobj->pobj, startframe, flags);
HSD_MObjReqAnimByFlags(dobj->mobj, startframe, flags);
}
void HSD_DObjReqAnimAllByFlags(HSD_DObj* dobj, f32 startframe, u32 flags)
{
HSD_DObj* dp;
if (dobj == NULL) {
return;
}
for (dp = dobj; dp != NULL; dp = dp->next) {
HSD_DObjReqAnimByFlags(dp, startframe, flags);
}
}
void HSD_DObjReqAnimAll(HSD_DObj* dobj, f32 startframe)
{
HSD_DObj* dp;
if (dobj == NULL) {
return;
}
for (dp = dobj; dp != NULL; dp = dp->next) {
HSD_DObjReqAnimByFlags(dp, startframe, 0x7FF);
}
}
void HSD_DObjAnim(HSD_DObj* dobj)
{
if (dobj == NULL) {
return;
}
HSD_PObjAnimAll(dobj->pobj);
HSD_MObjAnim(dobj->mobj);
}
void HSD_DObjAnimAll(HSD_DObj* dobj)
{
HSD_DObj* dp;
if (dobj == NULL) {
return;
}
for (dp = dobj; dp != NULL; dp = dp->next) {
HSD_DObjAnim(dp);
}
}
static int DObjLoad(HSD_DObj* dobj, HSD_DObjDesc* desc)
{
dobj->next = HSD_DObjLoadDesc(desc->next);
dobj->mobj = HSD_MObjLoadDesc(desc->mobjdesc);
dobj->pobj = HSD_PObjLoadDesc(desc->pobjdesc);
if (dobj->mobj != NULL) {
switch (dobj->mobj->rendermode & 0x60000000) {
case 0:
HSD_DObjModifyFlags(dobj, 2, 0xE);
break;
case 0x40000000:
HSD_DObjModifyFlags(dobj, 8, 0xE);
break;
case 0x60000000:
HSD_DObjModifyFlags(dobj, 4, 0xE);
break;
default:
OSReport("mobj has unexpected blending flags (0x%x).",
dobj->mobj->rendermode);
HSD_Panic(HSD_DObj_804D5C78, 312, "\0");
}
}
return 0;
}
static char HSD_DObj_804D5C84[5] = "dobj\0";
HSD_DObj* HSD_DObjLoadDesc(HSD_DObjDesc* desc)
{
HSD_DObj* dobj;
HSD_ClassInfo* info;
if (desc == NULL) {
return NULL;
}
if (desc->class_name == NULL ||
(info = hsdSearchClassInfo(desc->class_name)) == NULL)
{
dobj = HSD_DObjAlloc();
} else {
dobj = HSD_DOBJ(hsdNew(info));
if (dobj == NULL) {
__assert(HSD_DObj_804D5C78, 378, HSD_DObj_804D5C84);
}
}
HSD_DOBJ_METHOD(dobj)->load(dobj, desc);
return dobj;
}
void HSD_DObjRemove(HSD_DObj* dobj)
{
hsdDelete(dobj);
}
void HSD_DObjRemoveAll(HSD_DObj* dobj)
{
HSD_DObj* next;
for (; dobj != NULL; dobj = next) {
next = dobj->next;
HSD_DObjRemove(dobj);
}
}
void HSD_DObjSetDefaultClass(HSD_ClassInfo* info)
{
if (info) {
if (!hsdIsDescendantOf(info, &hsdDObj)) {
// The line number here is totally made up, this function is
// removed in practice but the string isn't
__assert(HSD_DObj_804D5C78, __LINE__,
"hsdIsDescendantOf(info, &hsdDObj)");
}
}
default_class = info;
}
HSD_DObj* HSD_DObjAlloc(void)
{
HSD_DObj* dobj =
(HSD_DObj*) hsdNew(default_class ? default_class : &hsdDObj.parent);
if (dobj == NULL) {
__assert(HSD_DObj_804D5C78, 525, HSD_DObj_804D5C84);
}
return dobj;
}
void HSD_DObjResolveRefs(HSD_DObj* dobj, HSD_DObjDesc* desc)
{
if (dobj == NULL || desc == NULL) {
return;
}
HSD_PObjResolveRefsAll(dobj->pobj, desc->pobjdesc);
}
void HSD_DObjResolveRefsAll(HSD_DObj* dobj, HSD_DObjDesc* desc)
{
for (; dobj != NULL && desc != NULL; dobj = dobj->next, desc = desc->next)
{
HSD_DObjResolveRefs(dobj, desc);
}
}
void forceStringAllocation(
HSD_DObj* dobj,
HSD_MObj*
mobj) // This function exists for the sole purpose of causing strings
// to end up in data by the compiler despite not being used
{
if (dobj->pobj == NULL) {
__assert(HSD_DObj_804D5C78, 700,
"can not find specified pobj in link.\n");
}
if (dobj->pobj == NULL) {
__assert(HSD_DObj_804D5C78, 702,
"can not find specified pobj in link.");
}
if (dobj->mobj != mobj) {
__assert(HSD_DObj_804D5C78, 704, "dobj->mobj == mobj");
}
}
void HSD_DObjDisp(HSD_DObj* dobj, Mtx vmtx, Mtx pmtx, u32 rendermode)
{
HSD_PObj* p;
HSD_MObjSetCurrent(dobj->mobj);
if ((rendermode & 0x4000000) == 0) {
HSD_MOBJ_METHOD(dobj->mobj)->setup(dobj->mobj, rendermode);
}
for (p = dobj->pobj; p != NULL; p = p->next) {
HSD_POBJ_METHOD(p)->disp(p, vmtx, pmtx, rendermode);
}
if ((rendermode & 0x4000000) == 0) {
HSD_MOBJ_METHOD(dobj->mobj)->unset(dobj->mobj, rendermode);
}
HSD_MObjSetCurrent(NULL);
}
static void DObjRelease(HSD_Class* o)
{
HSD_DObj* dobj = HSD_DOBJ(o);
HSD_MObjRemove(dobj->mobj);
HSD_PObjRemoveAll(dobj->pobj);
HSD_AObjRemove(dobj->aobj);
HSD_PARENT_INFO(&hsdDObj)->release(o);
}
static void DObjAmnesia(HSD_ClassInfo* info)
{
if (info == HSD_CLASS_INFO(default_class)) {
default_class = NULL;
}
HSD_PARENT_INFO(&hsdDObj)->amnesia(info);
}
static void DObjInfoInit(void)
{
hsdInitClassInfo(HSD_CLASS_INFO(&hsdDObj), HSD_CLASS_INFO(&hsdClass),
"sysdolphin_base_library", "hsd_dobj",
sizeof(HSD_DObjInfo), sizeof(HSD_DObj));
HSD_CLASS_INFO(&hsdDObj)->release = DObjRelease;
HSD_CLASS_INFO(&hsdDObj)->amnesia = DObjAmnesia;
HSD_DOBJ_INFO(&hsdDObj)->disp = HSD_DObjDisp;
HSD_DOBJ_INFO(&hsdDObj)->load = DObjLoad;
}