Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
virtual_entity.c File Reference

Go to the source code of this file.

Functions

s32 create_worker_backUI (void(*updateFunc)(void), void(*drawFunc)(void))
 
void virtual_entity_appendGfx_quad (u8 r, u8 g, u8 b, u8 a, u16 left, u16 top, u16 right, u16 bottom)
 
void virtual_entity_render_quad (s32 r, s32 g, s32 b, s32 a, s32 posX, s32 posY, s32 width, s32 height)
 
void virtual_entity_move_polar (VirtualEntity *virtualEntity, f32 magnitude, f32 angle)
 
void virtual_entity_list_update (void)
 
void virtual_entity_list_render_world (void)
 
void virtual_entity_list_render_UI (void)
 
VirtualEntityvirtual_entity_get_by_index (s32 index)
 
VirtualEntityvirtual_entity_create_at_index (s32 index, EntityModelScript *entityModelData)
 
s32 virtual_entity_create (EntityModelScript *cmdList)
 
VirtualEntityALT_virtual_entity_create (EntityModelScript *cmdList)
 
void virtual_entity_set_pos (s32 index, s32 posX, s32 posY, s32 posZ)
 
void virtual_entity_set_scale (s32 index, f32 scaleX, f32 scaleY, f32 scaleZ)
 
void virtual_entity_set_rotation (s32 index, f32 angleX, f32 angleY, f32 angleZ)
 
void virtual_entity_delete_by_index (s32 index)
 
void virtual_entity_delete_by_ref (VirtualEntity *obj)
 
void clear_virtual_entity_list (void)
 
void init_virtual_entity_list (void)
 

Variables

VirtualEntityList bBattleVirtualEntityList
 
VirtualEntityList wWorldVirtualEntityList
 
VirtualEntityListgCurrentVirtualEntityListPtr
 

Function Documentation

◆ create_worker_backUI()

s32 create_worker_backUI ( void(*)(void) updateFunc,
void(*)(void) drawFunc )

Definition at line 94 of file worker.c.

94 {
95 Worker* worker;
96 s32 i;
97
98 for (i = 0; i < MAX_WORKERS; i++) {
99 Worker* lastWorker = (*gCurrentWorkerListPtr)[i];
100 if (lastWorker == NULL) {
101 break;
102 }
103 }
104 ASSERT(i < MAX_WORKERS);
105
106 (*gCurrentWorkerListPtr)[i] = worker = heap_malloc(sizeof(*worker));
107 ASSERT(worker != NULL);
108
110 worker->update = updateFunc;
111 if (updateFunc == NULL) {
113 }
114 worker->draw = drawFunc;
115 if (drawFunc == NULL) {
117 }
118
121 }
122 return i;
123}
#define ASSERT(condition)
@ WORKER_FLAG_BACK_UI
Definition enums.h:2773
@ WORKER_FLAG_1
Definition enums.h:2770
@ WORKER_FLAG_SKIP_DRAW_UNTIL_UPDATE
Definition enums.h:2771
@ CONTEXT_WORLD
Definition enums.h:3529
void * heap_malloc(s32 size)
Definition heap.c:34
#define BATTLE_ENTITY_ID_BIT
Definition macros.h:146
#define MAX_WORKERS
Definition macros.h:95
void(* draw)(void)
void(* update)(void)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
void worker_delegate_do_nothing(void)
Definition worker.c:7

Referenced by clear_virtual_entity_list().

◆ virtual_entity_appendGfx_quad()

void virtual_entity_appendGfx_quad ( u8 r,
u8 g,
u8 b,
u8 a,
u16 left,
u16 top,
u16 right,
u16 bottom )

Definition at line 10 of file virtual_entity.c.

10 {
11 gDPPipeSync(gMainGfxPos++);
12
13 if (a == 0xFF) {
15 } else {
16 gDPSetRenderMode(gMainGfxPos++, G_RM_XLU_SURF, G_RM_XLU_SURF2);
17 gDPSetCombineMode(gMainGfxPos++, G_CC_PRIMITIVE, G_CC_PRIMITIVE);
18 }
19
20 gDPSetPrimColor(gMainGfxPos++, 0, 0, r, g, b, a);
21 gDPFillRectangle(gMainGfxPos++, left, top, right, bottom);
22 gDPPipeSync(gMainGfxPos++);
23 gDPSetRenderMode(gMainGfxPos++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
24 gDPSetCombineMode(gMainGfxPos++, G_CC_DECALRGBA, G_CC_DECALRGBA);
25}
#define PM_CC_PRIM_FULL_ALPHA
Definition macros.h:283
Gfx * gMainGfxPos
Definition cam_main.c:15

Referenced by virtual_entity_render_quad().

◆ virtual_entity_render_quad()

void virtual_entity_render_quad ( s32 r,
s32 g,
s32 b,
s32 a,
s32 posX,
s32 posY,
s32 width,
s32 height )

Definition at line 27 of file virtual_entity.c.

27 {
28 u16 endX = posX + width;
29 u16 endY = posY + height;
30
31 virtual_entity_appendGfx_quad(r, g, b, a, posX, posY, endX, endY);
32}
void virtual_entity_appendGfx_quad(u8 r, u8 g, u8 b, u8 a, u16 left, u16 top, u16 right, u16 bottom)

◆ virtual_entity_move_polar()

void virtual_entity_move_polar ( VirtualEntity * virtualEntity,
f32 magnitude,
f32 angle )

Definition at line 34 of file virtual_entity.c.

34 {
35 f32 theta = DEG_TO_RAD(angle);
36 f32 sinTheta = sin_rad(theta);
37 f32 cosTheta = cos_rad(theta);
38
39 virtualEntity->pos.x += magnitude * sinTheta;
40 virtualEntity->pos.z += -magnitude * cosTheta;
41}
f32 cos_rad(f32 x)
Definition 43F0.c:717
f32 sin_rad(f32 x)
Definition 43F0.c:713
#define DEG_TO_RAD(deg)
Definition macros.h:134

◆ virtual_entity_list_update()

void virtual_entity_list_update ( void )

Definition at line 43 of file virtual_entity.c.

43 {
44 s32 i;
45
46 for (i = 0; i < ARRAY_COUNT(*gCurrentVirtualEntityListPtr); i++) {
47 VirtualEntity* virtualEntity = (*gCurrentVirtualEntityListPtr)[i];
48
49 if (virtualEntity != NULL && virtualEntity->entityModelIndex >= 0) {
51 }
52 }
53}
void exec_entity_model_commandlist(s32 idx)
#define ARRAY_COUNT(arr)
Definition macros.h:40
VirtualEntityList * gCurrentVirtualEntityListPtr
Definition script_list.c:47

Referenced by clear_virtual_entity_list().

◆ virtual_entity_list_render_world()

void virtual_entity_list_render_world ( void )

Definition at line 55 of file virtual_entity.c.

55 {
56 Matrix4f translation;
57 Matrix4f xRot;
58 Matrix4f yRot;
59 Matrix4f zRot;
60 Matrix4f rotation;
61 Matrix4f temp;
62 Matrix4f transform;
63 Matrix4f scale;
64 Mtx transformMtxL;
65 VirtualEntity* virtualEntity;
66 s32 i;
67
68 for (i = 0; i < ARRAY_COUNT(*gCurrentVirtualEntityListPtr); i++) {
69 virtualEntity = (*gCurrentVirtualEntityListPtr)[i];
70 if (virtualEntity != NULL) {
71 if (!(virtualEntity->entityModelIndex < 0 || get_entity_model(virtualEntity->entityModelIndex)->flags & ENTITY_MODEL_FLAG_CAM3)) {
72 guTranslateF(translation, virtualEntity->pos.x, virtualEntity->pos.y, virtualEntity->pos.z);
73 guRotateF(xRot, virtualEntity->rot.x, 1.0f, 0.0f, 0.0f);
74 guRotateF(yRot, virtualEntity->rot.y, 0.0f, 1.0f, 0.0f);
75 guRotateF(zRot, virtualEntity->rot.z, 0.0f, 0.0f, 1.0f);
76 guScaleF(scale, virtualEntity->scale.x, virtualEntity->scale.y, virtualEntity->scale.z);
77 guMtxCatF(zRot, xRot, temp);
78 guMtxCatF(temp, yRot, rotation);
79 guMtxCatF(scale, rotation, temp);
80 guMtxCatF(temp, translation, transform);
81 guMtxF2L(transform, &transformMtxL);
82 draw_entity_model_A(virtualEntity->entityModelIndex, &transformMtxL);
83 }
84 }
85 }
86}
f32 Matrix4f[4][4]
#define guRotateF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define guScaleF
EntityModel * get_entity_model(s32 idx)
@ ENTITY_MODEL_FLAG_CAM3
Definition enums.h:5013
void draw_entity_model_A(s32, Mtx *)
s32 flags
Definition entity.h:448

Referenced by clear_virtual_entity_list().

◆ virtual_entity_list_render_UI()

void virtual_entity_list_render_UI ( void )

Definition at line 88 of file virtual_entity.c.

88 {
89 Matrix4f translation;
90 Matrix4f xRot;
91 Matrix4f yRot;
92 Matrix4f zRot;
93 Matrix4f rotation;
94 Matrix4f temp;
95 Matrix4f transform;
96 Matrix4f scale;
97 Mtx transformMtxL;
98 VirtualEntity* virtualEntity;
99 s32 i;
100
101 for (i = 0; i < ARRAY_COUNT(*gCurrentVirtualEntityListPtr); i++) {
102 virtualEntity = (*gCurrentVirtualEntityListPtr)[i];
103 if (virtualEntity != NULL) {
104 if (!(virtualEntity->entityModelIndex < 0 || !(get_entity_model(virtualEntity->entityModelIndex)->flags & ENTITY_MODEL_FLAG_CAM3))) {
105 guTranslateF(translation, virtualEntity->pos.x, virtualEntity->pos.y, virtualEntity->pos.z);
106 guRotateF(xRot, virtualEntity->rot.x, 1.0f, 0.0f, 0.0f);
107 guRotateF(yRot, virtualEntity->rot.y, 0.0f, 1.0f, 0.0f);
108 guRotateF(zRot, virtualEntity->rot.z, 0.0f, 0.0f, 1.0f);
109 guScaleF(scale, virtualEntity->scale.x, virtualEntity->scale.y, virtualEntity->scale.z);
110 guMtxCatF(zRot, xRot, temp);
111 guMtxCatF(temp, yRot, rotation);
112 guMtxCatF(scale, rotation, temp);
113 guMtxCatF(temp, translation, transform);
114 guMtxF2L(transform, &transformMtxL);
115 draw_entity_model_E(virtualEntity->entityModelIndex, &transformMtxL);
116 }
117 }
118 }
119}
void draw_entity_model_E(s32, Mtx *)

Referenced by clear_virtual_entity_list().

◆ virtual_entity_get_by_index()

VirtualEntity * virtual_entity_get_by_index ( s32 index)

Definition at line 528 of file virtual_entity.c.

528 {
529 return (*gCurrentVirtualEntityListPtr)[index];
530}

◆ virtual_entity_create_at_index()

VirtualEntity * virtual_entity_create_at_index ( s32 index,
EntityModelScript * entityModelData )

Definition at line 532 of file virtual_entity.c.

532 {
533 VirtualEntity* virtualEntity = (*gCurrentVirtualEntityListPtr)[index];
534
535 virtualEntity->entityModelIndex = load_entity_model(entityModelData);
536 virtualEntity->pos.x = 0.0f;
537 virtualEntity->pos.y = 0.0f;
538 virtualEntity->pos.z = 0.0f;
539 virtualEntity->rot.x = 0.0f;
540 virtualEntity->rot.y = 0.0f;
541 virtualEntity->rot.z = 0.0f;
542 virtualEntity->scale.x = 1.0f;
543 virtualEntity->scale.y = 1.0f;
544 virtualEntity->scale.z = 1.0f;
546
547 return (*gCurrentVirtualEntityListPtr)[index];
548}
s32 load_entity_model(EntityModelScript *cmdList)

◆ virtual_entity_create()

s32 virtual_entity_create ( EntityModelScript * cmdList)

Definition at line 550 of file virtual_entity.c.

550 {
551 s32 i;
552 VirtualEntity* virtualEntity;
553
554 for (i = 0; i < ARRAY_COUNT(*gCurrentVirtualEntityListPtr); i++) {
555 virtualEntity = (*gCurrentVirtualEntityListPtr)[i];
556 if (virtualEntity->entityModelIndex < 0) {
557 break;
558 }
559 }
560
562 return 0;
563 }
564
565 virtualEntity->entityModelIndex = load_entity_model(cmdList);
566 virtualEntity->pos.x = 0.0f;
567 virtualEntity->pos.y = 0.0f;
568 virtualEntity->pos.z = 0.0f;
569 virtualEntity->rot.x = 0.0f;
570 virtualEntity->rot.y = 0.0f;
571 virtualEntity->rot.z = 0.0f;
572 virtualEntity->scale.x = 1.0f;
573 virtualEntity->scale.y = 1.0f;
574 virtualEntity->scale.z = 1.0f;
575
577
578 return i;
579}

◆ ALT_virtual_entity_create()

VirtualEntity * ALT_virtual_entity_create ( EntityModelScript * cmdList)

Definition at line 581 of file virtual_entity.c.

581 {
582 s32 i;
583 VirtualEntity* virtualEntity;
584
585 for (i = 0; i < ARRAY_COUNT(*gCurrentVirtualEntityListPtr); i++) {
586 virtualEntity = (*gCurrentVirtualEntityListPtr)[i];
587 if (virtualEntity->entityModelIndex < 0) {
588 break;
589 }
590 }
591
593 return NULL;
594 }
595
596 virtualEntity->entityModelIndex = ALT_load_entity_model(cmdList);
597 virtualEntity->pos.x = 0.0f;
598 virtualEntity->pos.y = 0.0f;
599 virtualEntity->pos.z = 0.0f;
600 virtualEntity->rot.x = 0.0f;
601 virtualEntity->rot.y = 0.0f;
602 virtualEntity->rot.z = 0.0f;
603 virtualEntity->scale.x = 1.0f;
604 virtualEntity->scale.y = 1.0f;
605 virtualEntity->scale.z = 1.0f;
606
608
609 return (*gCurrentVirtualEntityListPtr)[i];
610}
s32 ALT_load_entity_model(EntityModelScript *cmdList)

◆ virtual_entity_set_pos()

void virtual_entity_set_pos ( s32 index,
s32 posX,
s32 posY,
s32 posZ )

Definition at line 612 of file virtual_entity.c.

612 {
613 VirtualEntity* virtualEntity = (*gCurrentVirtualEntityListPtr)[index];
614
615 virtualEntity->pos.x = posX;
616 virtualEntity->pos.y = posY;
617 virtualEntity->pos.z = posZ;
618}

◆ virtual_entity_set_scale()

void virtual_entity_set_scale ( s32 index,
f32 scaleX,
f32 scaleY,
f32 scaleZ )

Definition at line 620 of file virtual_entity.c.

620 {
621 VirtualEntity* virtualEntity = (*gCurrentVirtualEntityListPtr)[index];
622
623 virtualEntity->scale.x = scaleX;
624 virtualEntity->scale.y = scaleY;
625 virtualEntity->scale.z = scaleZ;
626}

◆ virtual_entity_set_rotation()

void virtual_entity_set_rotation ( s32 index,
f32 angleX,
f32 angleY,
f32 angleZ )

Definition at line 628 of file virtual_entity.c.

628 {
629 VirtualEntity* virtualEntity = (*gCurrentVirtualEntityListPtr)[index];
630
631 virtualEntity->rot.x = angleX;
632 virtualEntity->rot.y = angleY;
633 virtualEntity->rot.z = angleZ;
634}

◆ virtual_entity_delete_by_index()

void virtual_entity_delete_by_index ( s32 index)

Definition at line 636 of file virtual_entity.c.

636 {
637 VirtualEntity* virtualEntity = (*gCurrentVirtualEntityListPtr)[index];
638
640 virtualEntity->entityModelIndex = -1;
641}
void free_entity_model_by_index(s32 idx)

Referenced by virtual_entity_delete_by_ref().

◆ virtual_entity_delete_by_ref()

void virtual_entity_delete_by_ref ( VirtualEntity * obj)

Definition at line 643 of file virtual_entity.c.

643 {
644 s32 i;
645
646 for (i = 0; i < ARRAY_COUNT(*gCurrentVirtualEntityListPtr); i++) {
647 if ((*gCurrentVirtualEntityListPtr)[i] == obj) {
649 return;
650 }
651 }
652}
void virtual_entity_delete_by_index(s32 index)

◆ clear_virtual_entity_list()

void clear_virtual_entity_list ( void )

Definition at line 654 of file virtual_entity.c.

654 {
655 s32 i;
656
659 } else {
661 }
662
663 for (i = 0; i < ARRAY_COUNT(*gCurrentVirtualEntityListPtr); i++) {
664 (*gCurrentVirtualEntityListPtr)[i] = heap_malloc(sizeof(VirtualEntity));
666 (*gCurrentVirtualEntityListPtr)[i]->entityModelIndex = -1;
667 }
668
671}
s32 create_worker_world(WorldArgs, WorldArgs)
VirtualEntityList wWorldVirtualEntityList
Definition script_list.c:46
void virtual_entity_list_render_world(void)
void virtual_entity_list_update(void)
s32 create_worker_backUI(void(*updateFunc)(void), void(*drawFunc)(void))
Definition worker.c:94
VirtualEntityList bBattleVirtualEntityList
Definition script_list.c:45
void virtual_entity_list_render_UI(void)

Referenced by clear_script_list().

◆ init_virtual_entity_list()

void init_virtual_entity_list ( void )

Variable Documentation

◆ bBattleVirtualEntityList

VirtualEntityList bBattleVirtualEntityList
extern

Definition at line 45 of file script_list.c.

Referenced by clear_virtual_entity_list(), and init_virtual_entity_list().

◆ wWorldVirtualEntityList

VirtualEntityList wWorldVirtualEntityList
extern

Definition at line 46 of file script_list.c.

Referenced by clear_virtual_entity_list(), and init_virtual_entity_list().

◆ gCurrentVirtualEntityListPtr