Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
entity_model.c
Go to the documentation of this file.
1#include "common.h"
2#include "entity.h"
3
8Lights1 D_8014C268 = gdSPDefLights1(255, 255, 255, 0, 0, 0, 0, 0, 0);
9
11
15
24
25extern Gfx Gfx_RM1_SURFACE_OPA[];
26extern Gfx Gfx_RM1_DECAL_OPA[];
27extern Gfx Gfx_RM1_INTERSECTING_OPA[];
28extern Gfx Gfx_RM1_ALPHATEST[];
29extern Gfx Gfx_RM1_SURFACE_XLU[];
30extern Gfx Gfx_RM1_DECAL_XLU[];
31extern Gfx Gfx_RM1_INTERSECTING_XLU[];
33extern Gfx Gfx_RM1_SURFACE_XLU_NO_AA[];
34extern Gfx Gfx_RM1_DECAL_XLU_NO_AA[];
35extern Gfx Gfx_RM1_PASS_THROUGH[];
36extern Gfx Gfx_RM1_SURFACE_OPA_NO_ZB[];
37extern Gfx Gfx_RM1_ALPHATEST_NO_ZB[];
38extern Gfx Gfx_RM1_SURFACE_XLU_NO_ZB[];
39extern Gfx Gfx_RM1_CLOUD_NO_ZCMP[];
40extern Gfx Gfx_RM3_SURFACE_OPA[];
41extern Gfx Gfx_RM3_DECAL_OPA[];
42extern Gfx Gfx_RM3_INTERSECTING_OPA[];
43extern Gfx Gfx_RM3_ALPHATEST[];
44extern Gfx Gfx_RM3_SURFACE_XLU[];
45extern Gfx Gfx_RM3_DECAL_XLU[];
46extern Gfx Gfx_RM3_INTERSECTING_XLU[];
47
49void free_entity_model_by_ref(EntityModel* entityModel);
50
52 s32 i;
53
56 } else {
58 }
59
60 for (i = 0; i < MAX_ENTITY_MODELS; i++) {
61 (*gCurrentEntityModelList)[i] = NULL;
62 }
63
66 entity_fog_red = 10;
68 entity_fog_blue = 10;
72}
73
92
94 EntityModel* newEntityModel;
95 s32* entityModelCount;
96 s32 i;
97
98 for (i = 0; i < MAX_ENTITY_MODELS; i++) {
99 if ((*gCurrentEntityModelList)[i] == NULL) {
100 break;
101 }
102 }
104
105 (*gCurrentEntityModelList)[i] = newEntityModel = heap_malloc(sizeof(*newEntityModel));
106 entityModelCount = &gEntityModelCount;
107 (*entityModelCount)++;
108
109 ASSERT(newEntityModel != NULL);
110
112 newEntityModel->renderMode = 1;
113 newEntityModel->gfx.displayList = NULL;
114 newEntityModel->cmdListReadPos = cmdList;
115 newEntityModel->nextFrameTime = 1.0f;
116 newEntityModel->timeScale = 1.0f;
117 if (cmdList == NULL) {
118 newEntityModel->cmdListReadPos = &D_8014C260;
119 }
120 newEntityModel->vertexArray = NULL;
121 newEntityModel->fpSetupGfxCallback = NULL;
122 newEntityModel->cmdListSavedPos = newEntityModel->cmdListReadPos;
123
126 }
127 return i;
128}
129
131 EntityModel* newEntityModel;
132 SpriteRasterInfo* imageData;
133 s32 i;
134
135 for (i = 0; i < MAX_ENTITY_MODELS; i++) {
136 if ((*gCurrentEntityModelList)[i] == NULL) {
137 break;
138 }
139 }
141
142 {
143 s32* entityModelCount;
144 (*gCurrentEntityModelList)[i] = newEntityModel = heap_malloc(sizeof(*newEntityModel));
145 entityModelCount = &gEntityModelCount;
146 (*entityModelCount)++;
147 }
148
149 ASSERT(newEntityModel != NULL);
150
151 newEntityModel->gfx.imageData = imageData = heap_malloc(sizeof(*imageData));
152 ASSERT(imageData != NULL);
153
155 newEntityModel->renderMode = 1;
156 newEntityModel->cmdListReadPos = cmdList;
157 newEntityModel->nextFrameTime = 1.0f;
158 newEntityModel->timeScale = 1.0f;
159 if (cmdList == NULL) {
160 newEntityModel->cmdListReadPos = &D_8014C260;
161 }
162 newEntityModel->vertexArray = NULL;
163 newEntityModel->fpSetupGfxCallback = NULL;
164 newEntityModel->cmdListSavedPos = newEntityModel->cmdListReadPos;
165
168 }
169 return i;
170}
171
173 EntityModel* entityModel;
174
176 idx &= ~BATTLE_ENTITY_ID_BIT;
177 entityModel = (*gCurrentEntityModelList)[idx];
178 if (entityModel != NULL && (entityModel->flags)) {
179 if (!(entityModel->flags & ENTITY_MODEL_FLAG_HIDDEN)) {
180 if (!(entityModel->flags & ENTITY_MODEL_FLAG_DISABLE_SCRIPT)) {
181 entityModel->flags &= ~ENTITY_MODEL_FLAG_100;
182 entityModel->nextFrameTime -= entityModel->timeScale;
183 if (entityModel->nextFrameTime <= 0.0f) {
184 while (step_entity_model_commandlist(entityModel));
185 }
186 }
187 }
188 }
189 }
190}
191
193 SpriteRasterInfo* imageData;
194
195 u32* curPos = *entityModel->cmdListReadPos;
196 switch (*curPos++) {
197 case ENTITY_MODEL_SCRIPT_OP_End: // kill model
198 free_entity_model_by_ref(entityModel);
199 return 1;
200 case ENTITY_MODEL_SCRIPT_OP_Draw: // set display list ptr
201 entityModel->nextFrameTime = (f32) *curPos++;
202 entityModel->gfx.displayList = (Gfx*) *curPos++;
203 entityModel->cmdListReadPos = (EntityModelScript*) curPos;
204 break;
205 case ENTITY_MODEL_SCRIPT_OP_Restart: // restore saved position
206 entityModel->cmdListReadPos = entityModel->cmdListSavedPos;
207 return 1;
208 case ENTITY_MODEL_SCRIPT_OP_Loop: // set saved position
209 entityModel->cmdListReadPos = entityModel->cmdListSavedPos = (EntityModelScript*) curPos;
210 return 1;
211 case ENTITY_MODEL_SCRIPT_OP_SetRenderMode: // set render mode
212 entityModel->renderMode = *curPos++;
213 entityModel->cmdListReadPos = (EntityModelScript*) curPos;
214 return 1;
215 case ENTITY_MODEL_SCRIPT_OP_SetFlags: // set flags
216 entityModel->flags |= *curPos++;
217 entityModel->cmdListReadPos = (EntityModelScript*) curPos;
218 return 1;
219 case ENTITY_MODEL_SCRIPT_OP_ClearFlags: // clear flags
220 entityModel->flags &= ~*curPos++;
221 entityModel->cmdListReadPos = (EntityModelScript*) curPos;
222 return 1;
223 case ENTITY_MODEL_SCRIPT_OP_DrawImage: // set image data
224 imageData = entityModel->gfx.imageData;
225 entityModel->nextFrameTime = *curPos++;
226 imageData->raster = (u8*)*curPos++;
227 imageData->defaultPal = (PAL_PTR) *curPos++;
228 imageData->width = *curPos++;
229 imageData->height = *curPos++;
230 entityModel->cmdListReadPos = (EntityModelScript*) curPos;
231 break;
232 }
233 return 0;
234}
235
237 guMtxIdentF(mtx);
238 mtx[0][0] = 1.0f;
239 mtx[1][1] = 1.0f;
240 mtx[2][2] = -1.0f;
241 mtx[3][3] = 1.0f;
242}
243
245 Matrix4f mtx;
246 Matrix4f mtx2;
247 ImgFXTexture ifxImg;
248 Matrix4f imgfxMtx;
249
251 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
252 if (!(model->flags & ENTITY_MODEL_FLAG_USE_IMAGE)) {
253 if (!(model->flags & ENTITY_MODEL_FLAG_10000)) {
254 gDPPipeSync(gMainGfxPos++);
255 gDPSetRenderMode(gMainGfxPos++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
256 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 255, 255, 255);
257 gDPSetCombineMode(gMainGfxPos++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
258 gDPSetAlphaCompare(gMainGfxPos++, G_AC_NONE);
259 gSPSetOtherMode(gMainGfxPos++, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE);
260
262 case FALSE:
263 switch (model->renderMode) {
265 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_OPA);
266 break;
268 gSPDisplayList(gMainGfxPos++, Gfx_RM1_DECAL_OPA);
269 break;
271 gSPDisplayList(gMainGfxPos++, Gfx_RM1_INTERSECTING_OPA);
272 break;
274 gSPDisplayList(gMainGfxPos++, Gfx_RM1_ALPHATEST);
275 break;
279 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_XLU);
280 break;
282 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_XLU_NO_AA);
283 break;
286 gSPDisplayList(gMainGfxPos++, Gfx_RM1_DECAL_XLU);
287 break;
290 gSPDisplayList(gMainGfxPos++, Gfx_RM1_DECAL_XLU_NO_AA);
291 break;
293 gSPDisplayList(gMainGfxPos++, Gfx_RM1_INTERSECTING_XLU);
294 break;
296 gSPDisplayList(gMainGfxPos++, Gfx_RM1_PASS_THROUGH);
297 break;
299 gSPDisplayList(gMainGfxPos++, Gfx_RM1_ALPHATEST_ONESIDED);
300 break;
303 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_OPA_NO_ZB);
304 break;
307 gSPDisplayList(gMainGfxPos++, Gfx_RM1_ALPHATEST_NO_ZB);
308 break;
311 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_XLU_NO_ZB);
312 break;
314 gSPDisplayList(gMainGfxPos++, Gfx_RM1_CLOUD_NO_ZCMP);
315 break;
316 }
317 break;
318 case TRUE:
319 switch (model->renderMode) {
321 gSPDisplayList(gMainGfxPos++, Gfx_RM3_SURFACE_OPA);
322 break;
324 gSPDisplayList(gMainGfxPos++, Gfx_RM3_DECAL_OPA);
325 break;
327 gSPDisplayList(gMainGfxPos++, Gfx_RM3_INTERSECTING_OPA);
328 break;
330 gSPDisplayList(gMainGfxPos++, Gfx_RM3_ALPHATEST);
331 break;
333 gSPDisplayList(gMainGfxPos++, Gfx_RM3_SURFACE_XLU);
334 break;
336 gSPDisplayList(gMainGfxPos++, Gfx_RM3_DECAL_XLU);
337 break;
339 gSPDisplayList(gMainGfxPos++, Gfx_RM3_INTERSECTING_XLU);
340 break;
341 }
344 break;
345 }
346 gSPClearGeometryMode(gMainGfxPos++, G_LIGHTING);
348 gDPSetCombineMode(gMainGfxPos++, G_CC_MODULATEIA, G_CC_MODULATEIA);
349 } else {
350 gDPSetCombineMode(gMainGfxPos++, PM_CC_42, PM_CC2_MULTIPLY_SHADE);
351 }
352 }
353 if (model->vertexArray != NULL) {
355 }
356 gDPPipeSync(gMainGfxPos++);
357
358 if (model->fpSetupGfxCallback != NULL) {
360 }
361 gDPPipeSync(gMainGfxPos++);
362
363 gSPDisplayList(gMainGfxPos++, model->gfx.displayList);
364 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
365 gDPPipeSync(gMainGfxPos++);
366
367 if (!(model->flags & ENTITY_MODEL_FLAG_REFLECT)) {
368 return;
369 }
370
371 guMtxL2F(mtx, &model->transform);
373 guMtxCatF(mtx, mtx2, mtx);
374 guMtxF2L(mtx, &model->transform);
376 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
377 gSPDisplayList(gMainGfxPos++, model->gfx.displayList);
378 } else {
379 SpriteRasterInfo* imageData;
380
381 gDPPipeSync(gMainGfxPos++);
382 gSPClearGeometryMode(gMainGfxPos++, G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH);
383 gSPSetGeometryMode(gMainGfxPos++, G_ZBUFFER | G_SHADE | G_LIGHTING | G_SHADING_SMOOTH);
384 gSPSetLights1(gMainGfxPos++, D_8014C268);
385 gSPTexture(gMainGfxPos++, -1, -1, 0, G_TX_RENDERTILE, G_ON);
386 gDPSetAlphaCompare(gMainGfxPos++, G_AC_NONE);
387 gSPSetOtherMode(gMainGfxPos++, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE);
388
389 imageData = model->gfx.imageData;
390 ifxImg.raster = imageData->raster;
391 ifxImg.palette = imageData->defaultPal;
392 ifxImg.width = imageData->width;
393 ifxImg.height = imageData->height;
394 ifxImg.xOffset = -imageData->width / 2;
395 ifxImg.yOffset = imageData->height / 2;
396 ifxImg.alpha = 255;
397 guMtxL2F(imgfxMtx, &model->transform);
398 imgfx_appendGfx_component(0, &ifxImg, 0, imgfxMtx);
399 }
400
401 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
402 gDPPipeSync(gMainGfxPos++);
403}
404
405
406void draw_entity_model_A(s32 modelIdx, Mtx* transformMtx) {
407 EntityModel* model;
408 RenderTask rt;
409 RenderTask* rtPtr = &rt;
410 Camera* camera = &gCameras[gCurrentCamID];
411 Matrix4f mtx;
412 f32 x, y, z, w;
413 f32 inX, inY, inZ;
414
415 if ((gGameStatusPtr->context == CONTEXT_WORLD) || (modelIdx & BATTLE_ENTITY_ID_BIT)) {
416 modelIdx &= ~BATTLE_ENTITY_ID_BIT;
417 model = (*gCurrentEntityModelList)[modelIdx];
418
419 if (model != NULL) {
420 if (model->flags != 0) {
421 if (!(model->flags & ENTITY_MODEL_FLAG_100)) {
422 if (!(model->flags & ENTITY_MODEL_FLAG_HIDDEN)) {
423 if (!(model->flags & ENTITY_MODEL_FLAG_40) && (model->flags & (1 << gCurrentCamID))) {
424 model->transform = *transformMtx;
425 model->vertexArray = NULL;
426 guMtxL2F(mtx, transformMtx);
427 inX = mtx[3][0];
428 inY = mtx[3][1];
429 inZ = mtx[3][2];
430 transform_point(camera->mtxPerspective, inX, inY, inZ, 1.0f, &x, &y, &z, &w);
431 rtPtr->renderMode = model->renderMode;
432 rtPtr->appendGfxArg = model;
433 rtPtr->appendGfx = (void(*)(void*))appendGfx_entity_model;
434 rtPtr->dist = ((u32)(model->flags & 0xF000) >> 8) + inZ;
435 queue_render_task(rtPtr);
436 }
437 }
438 }
439 }
440 }
441 }
442}
443
444void draw_entity_model_B(s32 modelIdx, Mtx* transformMtx, s32 vertexSegment, Vec3s* vertexArray) {
445 EntityModel* model;
446 RenderTask rt;
447 RenderTask* rtPtr = &rt;
448 Camera* camera = &gCameras[gCurrentCamID];
449 Matrix4f mtx;
450 f32 x, y, z, w;
451 f32 inX, inY, inZ;
452
453 if ((gGameStatusPtr->context == CONTEXT_WORLD) || (modelIdx & BATTLE_ENTITY_ID_BIT)) {
454 modelIdx &= ~BATTLE_ENTITY_ID_BIT;
455 model = (*gCurrentEntityModelList)[modelIdx];
456
457 if (model != NULL) {
458 if (model->flags != 0) {
459 if (!(model->flags & ENTITY_MODEL_FLAG_100)) {
460 if (!(model->flags & ENTITY_MODEL_FLAG_HIDDEN)) {
461 if (model->flags & (1 << gCurrentCamID)) {
462 model->transform = *transformMtx;
463 D_80154374 = vertexSegment;
464 model->vertexArray = vertexArray;
465 guMtxL2F(mtx, transformMtx);
466 inX = mtx[3][0];
467 inY = mtx[3][1];
468 inZ = mtx[3][2];
469 transform_point(camera->mtxPerspective, inX, inY, inZ, 1.0f, &x, &y, &z, &w);
470 rtPtr->renderMode = model->renderMode;
471 rtPtr->appendGfxArg = model;
472 rtPtr->appendGfx = (void(*)(void*))appendGfx_entity_model;
473 rtPtr->dist = ((u32)(model->flags & 0xF000) >> 8) + inZ;
474 queue_render_task(rtPtr);
475 }
476 }
477 }
478 }
479 }
480 }
481}
482
483void draw_entity_model_C(s32 modelIdx, Mtx* transformMtx) {
484 EntityModel* model;
485 RenderTask rt;
486 RenderTask* rtPtr = &rt;
487
488 if ((gGameStatusPtr->context == CONTEXT_WORLD) || (modelIdx & BATTLE_ENTITY_ID_BIT)) {
489 modelIdx &= ~BATTLE_ENTITY_ID_BIT;
490 model = (*gCurrentEntityModelList)[modelIdx];
491
492 if (model != NULL) {
493 if (model->flags != 0) {
494 if (!(model->flags & ENTITY_MODEL_FLAG_100)) {
495 if (!(model->flags & ENTITY_MODEL_FLAG_HIDDEN)) {
496 if (!(model->flags & ENTITY_MODEL_FLAG_40) && (model->flags & (1 << gCurrentCamID))) {
498 model->transform = *transformMtx;
499 model->vertexArray = NULL;
500 rtPtr->renderMode = model->renderMode;
501 rtPtr->appendGfxArg = model;
502 rtPtr->appendGfx = (void(*)(void*))appendGfx_entity_model;
503 rtPtr->dist = (u32)(model->flags & 0xF000) >> 8;
504 queue_render_task(rtPtr);
505 }
506 }
507 }
508 }
509 }
510 }
511}
512
513void draw_entity_model_D(s32 modelIdx, Mtx* transformMtx, s32 arg2, Vec3s* vertexArray) {
514 EntityModel* model;
515 RenderTask rt;
516 RenderTask* rtPtr = &rt;
517
518 if ((gGameStatusPtr->context == CONTEXT_WORLD) || (modelIdx & BATTLE_ENTITY_ID_BIT)) {
519 modelIdx &= ~BATTLE_ENTITY_ID_BIT;
520 model = (*gCurrentEntityModelList)[modelIdx];
521
522 if (model != NULL) {
523 if (model->flags != 0) {
524 if (!(model->flags & ENTITY_MODEL_FLAG_100)) {
525 if (!(model->flags & ENTITY_MODEL_FLAG_HIDDEN)) {
526 if (model->flags & (1 << gCurrentCamID)) {
528 model->transform = *transformMtx;
529 D_80154374 = arg2;
530 model->vertexArray = vertexArray;
531 rtPtr->renderMode = model->renderMode;
532 rtPtr->appendGfxArg = model;
533 rtPtr->appendGfx = (void(*)(void*))appendGfx_entity_model;
534 rtPtr->dist = (u32)(model->flags & 0xF000) >> 8;
535 queue_render_task(rtPtr);
536 }
537 }
538 }
539 }
540 }
541 }
542}
543
544void draw_entity_model_E(s32 modelIdx, Mtx* transformMtx) {
545 EntityModel* model = (*gCurrentEntityModelList)[modelIdx & ~BATTLE_ENTITY_ID_BIT];
546 Matrix4f mtx;
547 Matrix4f mtx2;
548 ImgFXTexture ifxImg;
549 Matrix4f imgfxMtx;
550
551 if (model == NULL) {
552 return;
553 }
554 if (model->flags == 0) {
555 return;
556 }
557 if (model->flags & ENTITY_MODEL_FLAG_100) {
558 return;
559 }
560 if (model->flags & ENTITY_MODEL_FLAG_HIDDEN) {
561 return;
562 }
563 if (model->flags & ENTITY_MODEL_FLAG_40) {
564 return;
565 }
566 if (!(model->flags & ENTITY_MODEL_FLAG_CAM3)) {
567 return;
568 }
569
570 model->transform = *transformMtx;
571 model->vertexArray = NULL;
573 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
574 if (!(model->flags & ENTITY_MODEL_FLAG_USE_IMAGE)) {
576 case FALSE:
577 switch (model->renderMode) {
579 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_OPA);
580 break;
582 gSPDisplayList(gMainGfxPos++, Gfx_RM1_DECAL_OPA);
583 break;
585 gSPDisplayList(gMainGfxPos++, Gfx_RM1_INTERSECTING_OPA);
586 break;
588 gSPDisplayList(gMainGfxPos++, Gfx_RM1_ALPHATEST);
589 break;
593 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_XLU);
594 break;
596 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_XLU_NO_AA);
597 break;
600 gSPDisplayList(gMainGfxPos++, Gfx_RM1_DECAL_XLU);
601 break;
604 gSPDisplayList(gMainGfxPos++, Gfx_RM1_DECAL_XLU_NO_AA);
605 break;
607 gSPDisplayList(gMainGfxPos++, Gfx_RM1_INTERSECTING_XLU);
608 break;
610 gSPDisplayList(gMainGfxPos++, Gfx_RM1_PASS_THROUGH);
611 break;
613 gSPDisplayList(gMainGfxPos++, Gfx_RM1_ALPHATEST_ONESIDED);
614 break;
617 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_OPA_NO_ZB);
618 break;
621 gSPDisplayList(gMainGfxPos++, Gfx_RM1_ALPHATEST_NO_ZB);
622 break;
625 gSPDisplayList(gMainGfxPos++, Gfx_RM1_SURFACE_XLU_NO_ZB);
626 break;
628 gSPDisplayList(gMainGfxPos++, Gfx_RM1_CLOUD_NO_ZCMP);
629 break;
630 }
631 break;
632 case TRUE:
633 switch (model->renderMode) {
635 gSPDisplayList(gMainGfxPos++, Gfx_RM3_SURFACE_OPA);
636 break;
638 gSPDisplayList(gMainGfxPos++, Gfx_RM3_DECAL_OPA);
639 break;
641 gSPDisplayList(gMainGfxPos++, Gfx_RM3_INTERSECTING_OPA);
642 break;
644 gSPDisplayList(gMainGfxPos++, Gfx_RM3_ALPHATEST);
645 break;
647 gSPDisplayList(gMainGfxPos++, Gfx_RM3_SURFACE_XLU);
648 break;
650 gSPDisplayList(gMainGfxPos++, Gfx_RM3_DECAL_XLU);
651 break;
653 gSPDisplayList(gMainGfxPos++, Gfx_RM3_INTERSECTING_XLU);
654 break;
655 }
658 break;
659 }
660 gSPClearGeometryMode(gMainGfxPos++, G_LIGHTING);
662 gDPSetCombineMode(gMainGfxPos++, G_CC_MODULATEIA, G_CC_MODULATEIA);
663 } else {
664 gDPSetCombineMode(gMainGfxPos++, PM_CC_42, PM_CC2_MULTIPLY_SHADE);
665 }
666 if (model->vertexArray != NULL) {
668 }
669 gSPDisplayList(gMainGfxPos++, model->gfx.displayList);
670 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
671 gDPPipeSync(gMainGfxPos++);
672 if (!(model->flags & ENTITY_MODEL_FLAG_REFLECT)) {
673 return;
674 }
675
676 guMtxL2F(mtx, &model->transform);
678 guMtxCatF(mtx, mtx2, mtx);
679 guMtxF2L(mtx, &model->transform);
681 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
682 gSPDisplayList(gMainGfxPos++, model->gfx.displayList);
683 } else {
684 SpriteRasterInfo* imageData;
685
686 gDPPipeSync(gMainGfxPos++);
687 gSPClearGeometryMode(gMainGfxPos++, G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH);
688 gSPSetGeometryMode(gMainGfxPos++, G_ZBUFFER | G_SHADE | G_LIGHTING | G_SHADING_SMOOTH);
689 gSPSetLights1(gMainGfxPos++, D_8014C268);
690 gSPTexture(gMainGfxPos++, -1, -1, 0, G_TX_RENDERTILE, G_ON);
691 gDPSetAlphaCompare(gMainGfxPos++, G_AC_NONE);
692 gSPSetOtherMode(gMainGfxPos++, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE);
693
694 imageData = model->gfx.imageData;
695 ifxImg.raster = imageData->raster;
696 ifxImg.palette = imageData->defaultPal;
697 ifxImg.width = imageData->width;
698 ifxImg.height = imageData->height;
699 ifxImg.xOffset = -imageData->width / 2;
700 ifxImg.yOffset = imageData->height / 2;
701 ifxImg.alpha = 255;
702 guMtxL2F(imgfxMtx, &model->transform);
703 imgfx_appendGfx_component(0, &ifxImg, 0, imgfxMtx);
704 }
705
706 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
707 gDPPipeSync(gMainGfxPos++);
708}
709
711 EntityModel* entityModel = (*gCurrentEntityModelList)[idx & ~BATTLE_ENTITY_ID_BIT];
712
713 if (entityModel != NULL && entityModel->flags) {
714 if (cmdList == NULL) {
715 cmdList = &D_8014C260;
716 }
717 entityModel->cmdListReadPos = cmdList;
718 entityModel->cmdListSavedPos = cmdList;
719 entityModel->nextFrameTime = 1.0f;
720 entityModel->timeScale = 1.0f;
721 }
722}
723
725 return (*gCurrentEntityModelList)[listIndex & ~BATTLE_ENTITY_ID_BIT];
726}
727
729 s32 index = idx & ~BATTLE_ENTITY_ID_BIT;
730 EntityModel* entityModel = (*gCurrentEntityModelList)[index];
731
732 if (entityModel != NULL && entityModel->flags) {
733 if (entityModel->flags & ENTITY_MODEL_FLAG_USE_IMAGE) {
734 heap_free(entityModel->gfx.imageData);
735 }
736 {
737 s32* modelCount = &gEntityModelCount;
739 (*gCurrentEntityModelList)[index] = NULL;
740 (*modelCount)--;
741 }
742 }
743}
744
746 s32 i;
747
748 for (i = 0; i < MAX_ENTITY_MODELS; i++) {
749 if ((*gCurrentEntityModelList)[i] == entityModel) {
750 break;
751 }
752 }
753
754 if (i < MAX_ENTITY_MODELS) {
756 }
757}
758
759void set_entity_model_flags(s32 idx, s32 newFlags) {
760 EntityModel* entityModel = (*gCurrentEntityModelList)[idx & ~BATTLE_ENTITY_ID_BIT];
761
762 if (entityModel != NULL && entityModel->flags) {
763 entityModel->flags |= newFlags;
764 }
765}
766
767void clear_entity_model_flags(s32 idx, s32 newFlags) {
768 EntityModel* entityModel = (*gCurrentEntityModelList)[idx & ~BATTLE_ENTITY_ID_BIT];
769
770 if (entityModel != NULL && entityModel->flags) {
771 entityModel->flags &= ~newFlags;
772 }
773}
774
775void bind_entity_model_setupGfx(s32 idx, void* setupGfxCallbackArg0, void (*fpSetupGfxCallback)(void*)) {
776 EntityModel* entityModel = (*gCurrentEntityModelList)[idx & ~BATTLE_ENTITY_ID_BIT];
777
778 entityModel->fpSetupGfxCallback = fpSetupGfxCallback;
779 entityModel->setupGfxCallbackArg0 = setupGfxCallbackArg0;
780}
781
782void func_80122F8C(s32 idx, s32 newFlags) {
783 EntityModel* entityModel = (*gCurrentEntityModelList)[idx & ~BATTLE_ENTITY_ID_BIT];
784
785 entityModel->flags |= newFlags;
786}
787
788void func_80122FB8(s32 idx, s32 newFlags) {
789 EntityModel* entityModel = (*gCurrentEntityModelList)[idx & ~BATTLE_ENTITY_ID_BIT];
790
792}
793
796}
797
800}
801
802void set_entity_fog_dist(s32 min, s32 max) {
805}
806
807void set_entity_fog_color(s32 r, s32 g, s32 b, s32 a) {
808 entity_fog_red = r;
810 entity_fog_blue = b;
812}
813
815 return entity_fog_enabled;
816}
817
818void get_entity_fog_distance(s32* start, s32* end) {
819 *start = entity_fog_dist_min;
820 *end = entity_fog_dist_max;
821}
822
823void get_entity_fog_color(s32* r, s32* g, s32* b, s32* a) {
824 *r = entity_fog_red;
825 *g = entity_fog_green;
826 *b = entity_fog_blue;
827 *a = entity_fog_alpha;
828}
Mtx matrixStack[0x200]
#define PAL_PTR
f32 Matrix4f[4][4]
#define transform_point
#define queue_render_task
#define guMtxF2L
#define guMtxCatF
#define ASSERT(condition)
s32 EntityModelScript[]
Definition entity.h:7
@ ENTITY_MODEL_SCRIPT_OP_SetFlags
Definition entity.h:30
@ ENTITY_MODEL_SCRIPT_OP_Draw
Definition entity.h:26
@ ENTITY_MODEL_SCRIPT_OP_Loop
Definition entity.h:28
@ ENTITY_MODEL_SCRIPT_OP_SetRenderMode
Definition entity.h:29
@ ENTITY_MODEL_SCRIPT_OP_Restart
Definition entity.h:27
@ ENTITY_MODEL_SCRIPT_OP_End
Definition entity.h:25
@ ENTITY_MODEL_SCRIPT_OP_DrawImage
Definition entity.h:32
@ ENTITY_MODEL_SCRIPT_OP_ClearFlags
Definition entity.h:31
EntityModel * EntityModelList[256]
Definition entity.h:467
#define ems_End
Definition entity.h:47
Gfx Gfx_RM3_SURFACE_OPA[]
Definition model.c:1067
void enable_entity_fog(void)
void make_entity_model_mtx_flipZ(Matrix4f mtx)
BSS EntityModelList * gCurrentEntityModelList
Gfx Gfx_RM3_DECAL_XLU[]
Definition model.c:1117
Gfx Gfx_RM3_DECAL_OPA[]
Definition model.c:1077
s32 step_entity_model_commandlist(EntityModel *entityModel)
BSS s32 entity_fog_blue
void init_entity_models(void)
EntityModel * get_entity_model(s32 listIndex)
void clear_entity_model_flags(s32 idx, s32 newFlags)
BSS EntityModelList gBattleEntityModelList
void set_entity_model_flags(s32 idx, s32 newFlags)
void func_80122FB8(s32 idx, s32 newFlags)
s32 is_entity_fog_enabled(void)
s32 load_entity_model(EntityModelScript *cmdList)
Gfx Gfx_RM1_SURFACE_XLU[]
Definition model.c:686
Gfx Gfx_RM1_DECAL_XLU[]
Definition model.c:696
void func_80122F8C(s32 idx, s32 newFlags)
Gfx Gfx_RM1_ALPHATEST_ONESIDED[]
Definition model.c:746
BSS s32 entity_fog_red
BSS s32 D_80154374
void exec_entity_model_commandlist(s32 idx)
Lights1 D_8014C268
Definition entity_model.c:8
void draw_entity_model_E(s32 modelIdx, Mtx *transformMtx)
Gfx Gfx_RM1_SURFACE_XLU_NO_AA[]
Definition model.c:756
void appendGfx_entity_model(EntityModel *model)
void free_entity_model_by_ref(EntityModel *entityModel)
void draw_entity_model_D(s32 modelIdx, Mtx *transformMtx, s32 arg2, Vec3s *vertexArray)
void draw_entity_model_A(s32 modelIdx, Mtx *transformMtx)
s32 ALT_load_entity_model(EntityModelScript *cmdList)
BSS s32 entity_fog_dist_max
s32 gEntityModelCount
void get_entity_fog_distance(s32 *start, s32 *end)
void set_entity_model_render_command_list(s32 idx, EntityModelScript *cmdList)
void draw_entity_model_B(s32 modelIdx, Mtx *transformMtx, s32 vertexSegment, Vec3s *vertexArray)
void draw_entity_model_C(s32 modelIdx, Mtx *transformMtx)
BSS s32 entity_fog_green
Gfx Gfx_RM1_DECAL_OPA[]
Definition model.c:654
BSS s32 entity_fog_dist_min
void get_entity_fog_color(s32 *r, s32 *g, s32 *b, s32 *a)
void set_entity_fog_dist(s32 min, s32 max)
BSS s32 entity_fog_enabled
Gfx Gfx_RM1_ALPHATEST[]
Definition model.c:676
Gfx Gfx_RM1_INTERSECTING_XLU[]
Definition model.c:706
Gfx Gfx_RM1_SURFACE_OPA[]
Definition model.c:643
Gfx Gfx_RM3_INTERSECTING_XLU[]
Definition model.c:1127
Gfx Gfx_RM1_ALPHATEST_NO_ZB[]
Definition model.c:810
void set_entity_fog_color(s32 r, s32 g, s32 b, s32 a)
void bind_entity_model_setupGfx(s32 idx, void *setupGfxCallbackArg0, void(*fpSetupGfxCallback)(void *))
Gfx Gfx_RM3_INTERSECTING_OPA[]
Definition model.c:1087
Gfx Gfx_RM1_CLOUD_NO_ZCMP[]
Definition model.c:844
BSS s32 entity_fog_alpha
BSS EntityModelList gWorldEntityModelList
EntityModelScript D_8014C260
Definition entity_model.c:4
Gfx Gfx_RM3_ALPHATEST[]
Definition model.c:1097
void clear_entity_models(void)
Gfx Gfx_RM1_SURFACE_OPA_NO_ZB[]
Definition model.c:800
Gfx Gfx_RM1_DECAL_XLU_NO_AA[]
Definition model.c:766
Gfx Gfx_RM1_PASS_THROUGH[]
Definition model.c:779
Gfx Gfx_RM1_SURFACE_XLU_NO_ZB[]
Definition model.c:820
void free_entity_model_by_index(s32 idx)
void disable_entity_fog(void)
Gfx Gfx_RM1_INTERSECTING_OPA[]
Definition model.c:665
Gfx Gfx_RM3_SURFACE_XLU[]
Definition model.c:1107
@ ENTITY_MODEL_FLAG_CAM1
Definition enums.h:5011
@ ENTITY_MODEL_FLAG_FOG_DISABLED
Definition enums.h:5021
@ ENTITY_MODEL_FLAG_USE_IMAGE
Definition enums.h:5020
@ ENTITY_MODEL_FLAG_100
Definition enums.h:5018
@ ENTITY_MODEL_FLAG_40
Definition enums.h:5016
@ ENTITY_MODEL_FLAG_CAM3
Definition enums.h:5013
@ ENTITY_MODEL_FLAG_DISABLE_SCRIPT
Definition enums.h:5027
@ ENTITY_MODEL_FLAG_10000
Definition enums.h:5026
@ ENTITY_MODEL_FLAG_HIDDEN
Definition enums.h:5015
@ ENTITY_MODEL_FLAG_CAM2
Definition enums.h:5012
@ ENTITY_MODEL_FLAG_REFLECT
Definition enums.h:5019
@ ENTITY_MODEL_FLAG_CAM0
Definition enums.h:5010
@ ENTITY_MODEL_FLAG_ENABLED
Definition enums.h:5014
@ CONTEXT_WORLD
Definition enums.h:3529
@ RENDER_MODE_ALPHATEST_ONESIDED
Definition enums.h:3278
@ RENDER_MODE_SURFACE_OPA_NO_ZB
Definition enums.h:3267
@ RENDER_MODE_DECAL_OPA
Definition enums.h:3268
@ RENDER_MODE_SURFACE_XLU_LAYER3
Definition enums.h:3299
@ RENDER_MODE_DECAL_XLU_NO_AA
Definition enums.h:3293
@ RENDER_MODE_SURFACE_XLU_LAYER2
Definition enums.h:3287
@ RENDER_MODE_SURFACE_XLU_NO_AA
Definition enums.h:3284
@ RENDER_MODE_INTERSECTING_XLU
Definition enums.h:3303
@ RENDER_MODE_PASS_THROUGH
Definition enums.h:3306
@ RENDER_MODE_DECAL_XLU
Definition enums.h:3291
@ RENDER_MODE_SHADOW
Definition enums.h:3297
@ RENDER_MODE_SURFACE_XLU_NO_ZB
Definition enums.h:3285
@ RENDER_MODE_SURFACE_XLU_NO_ZB_BEHIND
Definition enums.h:3310
@ RENDER_MODE_SURFACE_OPA_NO_ZB_BEHIND
Definition enums.h:3308
@ RENDER_MODE_DECAL_XLU_AHEAD
Definition enums.h:3295
@ RENDER_MODE_ALPHATEST_NO_ZB_BEHIND
Definition enums.h:3309
@ RENDER_MODE_INTERSECTING_OPA
Definition enums.h:3272
@ RENDER_MODE_ALPHATEST
Definition enums.h:3276
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3264
@ RENDER_MODE_ALPHATEST_NO_ZB
Definition enums.h:3279
@ RENDER_MODE_SURFACE_XLU_LAYER1
Definition enums.h:3282
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
s32 imgfx_appendGfx_component(s32, ImgFXTexture *, u32, Matrix4f)
Definition imgfx.c:704
s32 heap_free(void *ptr)
Definition heap.c:42
void * heap_malloc(s32 size)
Definition heap.c:34
#define BSS
Definition macros.h:7
#define BATTLE_ENTITY_ID_BIT
Definition macros.h:146
#define MAX_ENTITY_MODELS
Definition macros.h:87
#define PM_CC2_MULTIPLY_SHADE
Definition macros.h:308
#define PM_CC_42
Definition macros.h:467
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
Matrix4f mtxPerspective
s32 flags
Definition entity.h:448
EntityModelScript * cmdListSavedPos
Definition entity.h:461
void(* fpSetupGfxCallback)(void *)
Definition entity.h:463
union EntityModel::@46 gfx
void * setupGfxCallbackArg0
Definition entity.h:464
Mtx transform
Definition entity.h:460
EntityModelScript * cmdListReadPos
Definition entity.h:455
Vec3s * vertexArray
Definition entity.h:462
f32 timeScale
Default is 1.0.
Definition entity.h:454
f32 nextFrameTime
Set to 1.0 after each update.
Definition entity.h:453
s8 renderMode
Definition entity.h:449
void * appendGfxArg
void(* appendGfx)(void *)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Camera gCameras[4]
Definition cam_main.c:17
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16
s16 gCurrentCamID
Definition cam_main.c:13