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

Go to the source code of this file.

Functions

void Entity_BoardedFloor_setupGfx (s32)
 
void Entity_BoardedFloor_init_fragments (Entity *entity, Gfx **dlists, Mtx *matrices)
 
void Entity_BoardedFloor_init (Entity *entity)
 
void Entity_BoardedFloor_update_fragments (Entity *entity)
 
void Entity_BoardedFloor_idle (Entity *entity)
 
void Entity_BoardedFloor_shatter (Entity *entity)
 

Variables

Gfx Entity_RenderNone []
 
Gfx * Entity_BoardedFloor_FragmentsRender []
 
Mtx Entity_BoardedFloor_FragmentMatrices []
 
EntityModelScript Entity_BoardedFloor_RenderScript = STANDARD_ENTITY_MODEL_SCRIPT(Entity_RenderNone, RENDER_MODE_SURFACE_OPA)
 
EntityModelScript Entity_BoardedFloor_RenderScriptShattered = STANDARD_ENTITY_MODEL_SCRIPT(Entity_RenderNone, RENDER_MODE_SURFACE_XLU_LAYER1)
 
EntityModelScript Entity_BoardedFloor_Script
 
EntityBlueprint Entity_BoardedFloor
 

Function Documentation

◆ Entity_BoardedFloor_setupGfx()

void Entity_BoardedFloor_setupGfx ( s32 entityIndex)

Definition at line 160 of file BoardedFloor.c.

160 {
161 s32 i;
162 Matrix4f mtxTransInv;
163 Matrix4f mtx;
164 Matrix4f mtxRotX;
165 Matrix4f mtxRotY;
166 f32 x_inv;
167 f32 y_inv;
168 f32 z_inv;
169 Gfx* gfxPos = gMainGfxPos;
170 Entity* entity = get_entity_by_index(entityIndex);
171 BoardedFloorData* data = entity->dataBuf.boardedFloor;
172 Gfx* fragmentDlist;
173 Gfx** gfx = data->fragmentsGfx;
174
175 x_inv = -entity->pos.x;
176 y_inv = -entity->pos.y;
177 z_inv = -entity->pos.z;
178
179 for (i = 0; i < 12; i++) {
180 if (data->fragmentRebounds[i] < 2) {
181 gDPSetRenderMode(gfxPos++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
182 gDPSetCombineMode(gfxPos++, G_CC_MODULATEIA, G_CC_MODULATEIA);
183 } else {
184 gDPSetCombineMode(gfxPos++, PM_CC_11, PM_CC_12);
185 gDPSetPrimColor(gfxPos++, 0, 0, 0, 0, 0, data->fragmentMoveAngle[i]);
186 }
187
188 guTranslateF(mtxTransInv, x_inv, y_inv, z_inv);
189 guRotateF(mtxRotX, data->fragmentRotX[i] * 360.0f / 256, 1.0f, 0.0f, 0.0f);
190 guRotateF(mtxRotY, data->fragmentRotY[i] * 360.0f / 256, 0.0f, 1.0f, 0.0f);
191 guMtxCatF(mtxRotX, mtxRotY, mtxRotY);
192 guMtxCatF(mtxRotY, mtxTransInv, mtxTransInv);
193 guTranslateF(mtx, data->fragmentPosX[i], data->fragmentPosY[i], data->fragmentPosZ[i]);
194 guMtxCatF(mtxTransInv, mtx, mtx);
196
197 gSPMatrix(gfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
198 fragmentDlist = ENTITY_ADDR(entity, Gfx*, *gfx++);
199 gSPDisplayList(gfxPos++, fragmentDlist);
200 gSPPopMatrix(gfxPos++, G_MTX_MODELVIEW);
201 }
202
203 gMainGfxPos = gfxPos;
204}
struct BoardedFloorData * boardedFloor
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define guRotateF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define ENTITY_ADDR(entity, type, data)
Definition entity.h:64
f32 fragmentPosZ[13]
Definition entity.h:279
u8 fragmentMoveAngle[13]
Definition entity.h:272
Gfx ** fragmentsGfx
Definition entity.h:269
f32 fragmentPosX[13]
Definition entity.h:277
s8 fragmentRebounds[13]
Definition entity.h:271
f32 fragmentPosY[13]
Definition entity.h:278
u8 fragmentRotY[13]
Definition entity.h:274
u8 fragmentRotX[13]
Definition entity.h:273
Entity * get_entity_by_index(s32 index)
Definition entity.c:530
#define PM_CC_11
Definition macros.h:294
#define PM_CC_12
Definition macros.h:295
EntityData dataBuf
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16

Referenced by Entity_BoardedFloor_init_fragments().

◆ Entity_BoardedFloor_init_fragments()

void Entity_BoardedFloor_init_fragments ( Entity * entity,
Gfx ** dlists,
Mtx * matrices )

Definition at line 11 of file BoardedFloor.c.

11 {
13 Matrix4f mtxFragment;
14 Matrix4f mtxTrans;
15 s32 i;
16 s32 rotationSpeed;
17
18 data->fragmentsGfx = ENTITY_ADDR(entity, Gfx**, dlists);
20 entity->alpha = 255;
21 entity->pos.y = data->inititalY;
22 guTranslateF(mtxTrans, entity->pos.x, entity->pos.y, entity->pos.z);
23
24 for (i = 0; i < FRAGMENT_BUF_SIZE - 1; i++) {
25 guMtxL2F(mtxFragment, ENTITY_ADDR(entity, Mtx*, matrices++));
26 guMtxCatF(mtxTrans, mtxFragment, mtxFragment);
27 data->fragmentPosX[i] = mtxFragment[3][0];
28 data->fragmentPosY[i] = mtxFragment[3][1];
29 data->fragmentPosZ[i] = mtxFragment[3][2];
30 data->fragmentMoveAngle[i] = -rand_int(255);
31 data->fragmentLateralSpeed[i] = 20;
32
33 rotationSpeed = rand_int(5);
34 if (i % 2 != 0) {
35 data->fragmentRotSpeed[i] = rotationSpeed + 10;
36 } else {
37 data->fragmentRotSpeed[i] = -10 - rotationSpeed;
38 }
39
40 data->fragmentFallSpeed[i] = 10.0f;
41 data->fragmentRebounds[i] = 0;
42 data->fragmentRotX[i] = 0;
43 data->fragmentRotY[i] = 0;
44 }
45}
void Entity_BoardedFloor_setupGfx(s32)
#define rand_int
f32 fragmentRotSpeed[13]
Definition entity.h:276
#define FRAGMENT_BUF_SIZE
Definition entity.h:266
u8 fragmentLateralSpeed[13]
Definition entity.h:275
f32 fragmentFallSpeed[13]
Definition entity.h:280
void(* renderSetupFunc)(s32)

Referenced by Entity_BoardedFloor_init().

◆ Entity_BoardedFloor_init()

void Entity_BoardedFloor_init ( Entity * entity)

Definition at line 47 of file BoardedFloor.c.

47 {
48 entity->dataBuf.boardedFloor->inititalY = entity->pos.y;
50}
Mtx Entity_BoardedFloor_FragmentMatrices[]
Gfx * Entity_BoardedFloor_FragmentsRender[]
void Entity_BoardedFloor_init_fragments(Entity *entity, Gfx **dlists, Mtx *matrices)

◆ Entity_BoardedFloor_update_fragments()

void Entity_BoardedFloor_update_fragments ( Entity * entity)

Definition at line 52 of file BoardedFloor.c.

52 {
54 f32 rotSpeed, lateralSpeed, reboundSpeed;
55 f32 moveAngle, yawRad;
56 s32 i;
57 s32 numFragmentsDisappeared;
58 f32 hitX, hitY, hitZ, hitDepth;
59
60 numFragmentsDisappeared = 0;
61 rotSpeed = 0.0f;
62 reboundSpeed = 0.0f;
63 lateralSpeed = 0.0f;
64
65 for (i = 0; i < 12; i++) {
66 switch (data->fragmentRebounds[i]) {
67 case 0:
68 reboundSpeed = 2.0f;
69 rotSpeed = data->fragmentRotSpeed[i];
70 lateralSpeed = data->fragmentLateralSpeed[i] / 10.0f;
71 if (rotSpeed >= 0.0f) {
72 data->fragmentRotSpeed[i] = rotSpeed - 0.4;
73 } else {
74 data->fragmentRotSpeed[i] = rotSpeed + 0.5;
75 }
76 break;
77 case 1:
78 lateralSpeed = 1.0f;
79 reboundSpeed = 0.0f;
80 rotSpeed = data->fragmentRotSpeed[i] * 0.25f;
81 break;
82 case 2:
83 data->fragmentRotSpeed[i] += 1.0f;
84 if (data->fragmentRotSpeed[i] > 20.0f) {
85 data->fragmentRotSpeed[i] = 20.0f;
86 }
87
88 data->fragmentPosY[i] -= data->fragmentRotSpeed[i] / 70.0f;
89
90 data->fragmentMoveAngle[i] -= 5;
91 if (data->fragmentMoveAngle[i] <= 5) {
92 data->fragmentMoveAngle[i] = 0;
93 data->fragmentRebounds[i]++;
94 }
95 break;
96 case 3:
97 numFragmentsDisappeared++;
98 break;
99 }
100
101 if (data->fragmentRebounds[i] < 2) {
102 if (data->fragmentFallSpeed[i] >= 0.0f) {
103 data->fragmentFallSpeed[i] -= 0.8;
104 if (data->fragmentFallSpeed[i] < -10.2) {
105 data->fragmentFallSpeed[i] = -10.2f;
106 }
107 } else {
108 data->fragmentFallSpeed[i] -= 1.6;
109 if (data->fragmentFallSpeed[i] < -10.2) {
110 data->fragmentFallSpeed[i] = -10.2f;
111 }
112 }
113
114 data->fragmentPosY[i] += data->fragmentFallSpeed[i];
115 yawRad = data->fragmentMoveAngle[i] * 360.0f / 256;
116 moveAngle = DEG_TO_RAD(yawRad);
117 data->fragmentPosX[i] += lateralSpeed * sin_rad(moveAngle);
118 data->fragmentPosZ[i] += lateralSpeed * cos_rad(moveAngle);
119
120 hitX = data->fragmentPosX[i];
121 hitY = data->fragmentPosY[i];
122 hitZ = data->fragmentPosZ[i];
123 if (npc_test_move_taller_with_slipping(COLLISION_IGNORE_ENTITIES, &hitX, &hitY, &hitZ, lateralSpeed, yawRad, 8.0f, 8.0f)) {
124 data->fragmentPosX[i] = hitX;
125 data->fragmentPosY[i] = hitY;
126 data->fragmentPosZ[i] = hitZ;
127 data->fragmentMoveAngle[i] += 0x80; // inverse yaw
128
129 moveAngle = DEG_TO_RAD(data->fragmentMoveAngle[i] * 360.0f / 256);
130 lateralSpeed = 8.0f;
131 data->fragmentPosX[i] += lateralSpeed * sin_rad(moveAngle);
132 data->fragmentPosZ[i] += lateralSpeed * cos_rad(moveAngle);
133
134 }
135
136 hitX = data->fragmentPosX[i];
137 hitY = data->fragmentPosY[i];
138 hitZ = data->fragmentPosZ[i];
139 hitDepth = fabsf(data->fragmentFallSpeed[i]);
140 if (npc_raycast_down_sides(COLLISION_IGNORE_ENTITIES, &hitX, &hitY, &hitZ, &hitDepth) || hitY < data->inititalY - 200.0f) {
141 data->fragmentRebounds[i]++;
142 data->fragmentPosY[i] = hitY + fabsf(data->fragmentFallSpeed[i]);
143 data->fragmentFallSpeed[i] = reboundSpeed;
144 if (data->fragmentRebounds[i] == 2) {
145 data->fragmentMoveAngle[i] = 254;
146 data->fragmentRotSpeed[i] = 0.0f;
147 }
148 }
149
150 data->fragmentRotX[i] += rotSpeed;
151 data->fragmentRotY[i] -= rotSpeed;
152 }
153 }
154
155 if (numFragmentsDisappeared >= 12) {
157 }
158}
#define npc_raycast_down_sides
@ COLLISION_IGNORE_ENTITIES
Definition enums.h:4698
f32 fabsf(f32 f)
f32 cos_rad(f32 x)
Definition 43F0.c:717
b32 npc_test_move_taller_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
void exec_entity_commandlist(Entity *entity)
Definition entity.c:313
f32 sin_rad(f32 x)
Definition 43F0.c:713
#define DEG_TO_RAD(deg)
Definition macros.h:134

◆ Entity_BoardedFloor_idle()

void Entity_BoardedFloor_idle ( Entity * entity)

Definition at line 206 of file BoardedFloor.c.

206 {
207 PlayerStatus* playerStatus = &gPlayerStatus;
208
210 if (playerStatus->actionState == ACTION_STATE_SPIN_POUND
211 || playerStatus->actionState == ACTION_STATE_TORNADO_POUND) {
212 entity_start_script(entity);
214 }
215 }
216}
@ ENTITY_COLLISION_PLAYER_TOUCH_FLOOR
Definition enums.h:2648
@ ACTION_STATE_SPIN_POUND
Definition enums.h:2442
@ ACTION_STATE_TORNADO_POUND
Definition enums.h:2444
s32 entity_start_script(Entity *entity)
Definition entity.c:560
u8 collisionFlags
PlayerStatus gPlayerStatus
Definition 77480.c:39

◆ Entity_BoardedFloor_shatter()

void Entity_BoardedFloor_shatter ( Entity * entity)

Definition at line 221 of file BoardedFloor.c.

221 {
222 BoardedFloorData* data = entity->dataBuf.boardedFloor;
223 s32 i;
224
225 for (i = 0; i < 12; i++) {
226 data->fragmentPosY[i] += 1.0f;
227 }
228
230}
EntityModelScript Entity_BoardedFloor_RenderScriptShattered
void entity_set_render_script(Entity *entity, EntityModelScript *cmdList)
Definition entity.c:761

Variable Documentation

◆ Entity_RenderNone

Gfx Entity_RenderNone[]
extern

Definition at line 69 of file Shadow.c.

69 {
70 gsSPEndDisplayList(),
71};

◆ Entity_BoardedFloor_FragmentsRender

Gfx* Entity_BoardedFloor_FragmentsRender[]
extern

Definition at line 461 of file BoardedFloor.c.

461 {
474};
Gfx D_0A002E08_E515F8[]
Gfx D_0A002958_E51148[]
Gfx D_0A002CC8_E514B8[]
Gfx D_0A0029F0_E511E0[]
Gfx D_0A002A88_E51278[]
Gfx D_0A002B08_E512F8[]
Gfx D_0A002C28_E51418[]
Gfx D_0A002858_E51048[]
Gfx D_0A002B88_E51378[]
Gfx D_0A0028D8_E510C8[]
Gfx D_0A0027E8_E50FD8[]
Gfx D_0A002D68_E51558[]

Referenced by Entity_BoardedFloor_init().

◆ Entity_BoardedFloor_FragmentMatrices

Mtx Entity_BoardedFloor_FragmentMatrices[]
extern

Definition at line 30 of file BoardedFloor.c.

30 {
31 {
32 .m = {
33 { 0x00010000, 0x00000000,
34 0x00000001, 0x00000000 },
35 { 0x00000000, 0x00010000,
36 0xFFF30002, 0xFFF30001 },
37 { 0x00000000, 0x00000000,
38 0x00000000, 0x00000000 },
39 { 0x00000000, 0x00000000,
40 0xD5558000, 0x8E390000 }
41 }
42 },
43 {
44 .m = {
45 { 0x00010000, 0x00000000,
46 0x00000001, 0x00000000 },
47 { 0x00000000, 0x00010000,
48 0x00010002, 0x00080001 },
49 { 0x00000000, 0x00000000,
50 0x00000000, 0x00000000 },
51 { 0x00000000, 0x00000000,
52 0xD5558000, 0x8E390000 }
53 }
54 },
55 {
56 .m = {
57 { 0x00010000, 0x00000000,
58 0x00000001, 0x00000000 },
59 { 0x00000000, 0x00010000,
60 0xFFF50001, 0x00020001 },
61 { 0x00000000, 0x00000000,
62 0x00000000, 0x00000000 },
63 { 0x00000000, 0x00000000,
64 0xE65D8000, 0x046B0000 }
65 }
66 },
67 {
68 .m = {
69 { 0x00010000, 0x00000000,
70 0x00000001, 0x00000000 },
71 { 0x00000000, 0x00010000,
72 0x000C0001, 0xFFF40001 },
73 { 0x00000000, 0x00000000,
74 0x00000000, 0x00000000 },
75 { 0x00000000, 0x00000000,
76 0x65928000, 0x7ED60000 }
77 }
78 },
79 {
80 .m = {
81 { 0x00010000, 0x00000000,
82 0x00000001, 0x00000000 },
83 { 0x00000000, 0x00010000,
84 0x000FFFFF, 0x00190001 },
85 { 0x00000000, 0x00000000,
86 0x00000000, 0x00000000 },
87 { 0x00000000, 0x00000000,
88 0x00008000, 0x80000000 }
89 }
90 },
91 {
92 .m = {
93 { 0x00010000, 0x00000000,
94 0x00000001, 0x00000000 },
95 { 0x00000000, 0x00010000,
96 0xFFF1FFFF, 0x00190001 },
97 { 0x00000000, 0x00000000,
98 0x00000000, 0x00000000 },
99 { 0x00000000, 0x00000000,
100 0x00008000, 0x80000000 }
101 }
102 },
103 {
104 .m = {
105 { 0x00010000, 0x00000000,
106 0x00000001, 0x00000000 },
107 { 0x00000000, 0x00010000,
108 0x000BFFFF, 0x000A0001 },
109 { 0x00000000, 0x00000000,
110 0x00000000, 0x00000000 },
111 { 0x00000000, 0x00000000,
112 0x40008000, 0x80000000 }
113 }
114 },
115 {
116 .m = {
117 { 0x00010000, 0x00000000,
118 0x00000001, 0x00000000 },
119 { 0x00000000, 0x00010000,
120 0xFFEEFFFF, 0x000A0001 },
121 { 0x00000000, 0x00000000,
122 0x00000000, 0x00000000 },
123 { 0x00000000, 0x00000000,
124 0x40008000, 0x80000000 }
125 }
126 },
127 {
128 .m = {
129 { 0x00010000, 0x00000000,
130 0x00000001, 0x00000000 },
131 { 0x00000000, 0x00010000,
132 0xFFEFFFFF, 0xFFF80001 },
133 { 0x00000000, 0x00000000,
134 0x00000000, 0x00000000 },
135 { 0x00000000, 0x00000000,
136 0x80008000, 0x00000000 }
137 }
138 },
139 {
140 .m = {
141 { 0x00010000, 0x00000000,
142 0x00000001, 0x00000000 },
143 { 0x00000000, 0x00010000,
144 0x000CFFFF, 0xFFF80001 },
145 { 0x00000000, 0x00000000,
146 0x00000000, 0x00000000 },
147 { 0x00000000, 0x00000000,
148 0x80008000, 0x00000000 }
149 }
150 },
151 {
152 .m = {
153 { 0x00010000, 0x00000000,
154 0x00000001, 0x00000000 },
155 { 0x00000000, 0x00010000,
156 0xFFECFFFF, 0xFFEC0001 },
157 { 0x00000000, 0x00000000,
158 0x00000000, 0x00000000 },
159 { 0x00000000, 0x00000000,
160 0x00008000, 0x55550000 }
161 }
162 },
163 {
164 .m = {
165 { 0x00010000, 0x00000000,
166 0x00000001, 0x00000000 },
167 { 0x00000000, 0x00010000,
168 0x0007FFFF, 0xFFE90001 },
169 { 0x00000000, 0x00000000,
170 0x00000000, 0x00000000 },
171 { 0x00000000, 0x00000000,
172 0x80008000, 0x00000000 }
173 }
174 },
175};

Referenced by Entity_BoardedFloor_init().

◆ Entity_BoardedFloor_RenderScript

Definition at line 218 of file BoardedFloor.c.

◆ Entity_BoardedFloor_RenderScriptShattered

Definition at line 219 of file BoardedFloor.c.

Referenced by Entity_BoardedFloor_shatter().

◆ Entity_BoardedFloor_Script

EntityModelScript Entity_BoardedFloor_Script
Initial value:
= {
}
void Entity_BoardedFloor_shatter(Entity *entity)
void Entity_BoardedFloor_idle(Entity *entity)
void Entity_BoardedFloor_update_fragments(Entity *entity)
#define es_Call(func)
Definition entity.h:37
#define es_SetCallback(func, time)
Definition entity.h:38
#define es_SetFlags(flags)
Definition entity.h:43
#define es_End
Definition entity.h:35
#define es_PlaySound(soundId)
Definition entity.h:45
#define es_ClearFlags(flags)
Definition entity.h:44
@ SOUND_BREAK_FLOOR
Definition enums.h:1438
@ ENTITY_FLAG_HIDDEN
Definition enums.h:2613
@ ENTITY_FLAG_PENDING_INSTANCE_DELETE
Definition enums.h:2642
@ ENTITY_FLAG_DISABLE_COLLISION
Definition enums.h:2618

Definition at line 232 of file BoardedFloor.c.

◆ Entity_BoardedFloor

EntityBlueprint Entity_BoardedFloor
Initial value:
= {
.flags = 0,
.typeDataSize = sizeof(BoardedFloorData),
.renderCommandList = Entity_BoardedFloor_RenderScript,
.modelAnimationNodes = 0,
.updateEntityScript = Entity_BoardedFloor_Script,
.fpHandleCollision = NULL,
{ .dma = ENTITY_ROM(BoardedFloor) },
.aabbSize = { 60, 5, 60 }
}
void Entity_BoardedFloor_init(Entity *entity)
EntityModelScript Entity_BoardedFloor_Script
EntityModelScript Entity_BoardedFloor_RenderScript
#define ENTITY_ROM(name)
Definition entity.h:65
@ ENTITY_TYPE_BOARDED_FLOOR
Definition enums.h:2580

Definition at line 244 of file BoardedFloor.c.

244 {
245 .flags = 0,
246 .typeDataSize = sizeof(BoardedFloorData),
247 .renderCommandList = Entity_BoardedFloor_RenderScript,
248 .modelAnimationNodes = 0,
249 .fpInit = Entity_BoardedFloor_init,
250 .updateEntityScript = Entity_BoardedFloor_Script,
251 .fpHandleCollision = NULL,
252 { .dma = ENTITY_ROM(BoardedFloor) },
253 .entityType = ENTITY_TYPE_BOARDED_FLOOR,
254 .aabbSize = { 60, 5, 60 }
255};