Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
part2.inc.c
Go to the documentation of this file.
1#include "ld_addrs.h"
2
3BSS s32 N(VineRenderState);
4
5#define PIRANHA_DMA_ENTRY(name) \
6 (s32) world_model_anim_kzn_##name##_ROM_START,\
7 (s32) world_model_anim_kzn_##name##_ROM_END,\
8 (s32) world_model_anim_kzn_##name##_VRAM
9
10s32 N(VineAnimationsDmaTable)[] = {
48};
49
51 Evt dummyEvt;
52 Evt* dummyEvtPtr = &dummyEvt;
53 s32 args[4];
54 s32 count;
55
56 // setup dummy call to LoadPath
57 args[0] = 3 * vine->boneCount; // generate three output samples per input
58 args[1] = (s32) &vine->bonePos; // points
59 args[2] = vine->boneCount; // num vectors
60 args[3] = EASING_LINEAR;
61 dummyEvtPtr->ptrReadPos = args;
62 LoadPath(dummyEvtPtr, 1);
63
64 count = 0;
65 do {
66 GetNextPathPos(dummyEvtPtr, 1);
67 vine->points[count].x = evt_get_float_variable(dummyEvtPtr, LVar1);
68 vine->points[count].y = evt_get_float_variable(dummyEvtPtr, LVar2);
69 vine->points[count].z = evt_get_float_variable(dummyEvtPtr, LVar3);
70 count++;
71 } while (dummyEvtPtr->varTable[0] != 0);
72 vine->numPoints = count;
73}
74
75API_CALLABLE(N(SetVineBonePos)) {
76 Bytecode* args = script->ptrReadPos;
77 s32 vineIdx = evt_get_variable(script, *args++);
78 s32 jointIdx = evt_get_variable(script, *args++);
79 s32 x = evt_get_variable(script, *args++);
80 s32 y = evt_get_variable(script, *args++);
81 s32 z = evt_get_variable(script, *args++);
82 LavaPiranhaVine* vines = (LavaPiranhaVine*) evt_get_variable(NULL, MV_VinesData);
83 LavaPiranhaVine* vine = &vines[vineIdx];
84
85 vine->bonePos[jointIdx].x = x;
86 vine->bonePos[jointIdx].y = y;
87 vine->bonePos[jointIdx].z = z;
88 return ApiStatus_DONE2;
89}
90
91API_CALLABLE(N(SetVineBoneRot)) {
92 Bytecode* args = script->ptrReadPos;
93 s32 vineIdx = evt_get_variable(script, *args++);
94 s32 jointIdx = evt_get_variable(script, *args++);
95 s32 rx = evt_get_variable(script, *args++);
96 s32 ry = evt_get_variable(script, *args++);
97 s32 rz = evt_get_variable(script, *args++);
98 LavaPiranhaVine* vines = (LavaPiranhaVine*) evt_get_variable(NULL, MV_VinesData);
99 LavaPiranhaVine* vine = &vines[vineIdx];
100
101 vine->boneRot[jointIdx] = rz;
102 return ApiStatus_DONE2;
103}
104
105API_CALLABLE(N(SetVineBoneScale)) {
106 Bytecode* args = script->ptrReadPos;
107 s32 vineIdx = evt_get_variable(script, *args++);
108 s32 jointIdx = evt_get_variable(script, *args++);
109 s32 sx = evt_get_variable(script, *args++);
110 s32 sy = evt_get_variable(script, *args++);
111 s32 sz = evt_get_variable(script, *args++);
112 LavaPiranhaVine* vines = (LavaPiranhaVine*) evt_get_variable(NULL, MV_VinesData);
113 LavaPiranhaVine* vine = &vines[vineIdx];
114
115 // do nothing
116 return ApiStatus_DONE2;
117}
118
119void N(appendGfx_piranha_vines)(void* data) {
120 Vtx_t* vtxBuffer;
121 Vtx_t* vtx;
122
123 f32 boneLength;
124 s32 boneCount;
125
126 f32 angle;
127 f32 nextAngle;
128 f32 curAngle1;
129 f32 curAngle2;
130
131 f32 alphaCoord;
132 f32 alphaFrac;
133 s32 nearest;
134
135 s32 numPoints;
136 s32 i, j;
137
138 f32 deltaX, deltaY;
139 f32 posX, posY, posZ;
140
141 if (N(VineRenderState) == -1) {
142 return;
143 }
144
145 if (N(VineRenderState) == 0) {
146 for (i = 0; i < NUM_VINES; i++) {
147 LavaPiranhaVine* vines = (LavaPiranhaVine*) evt_get_variable(NULL, MV_VinesData);
148 LavaPiranhaVine* vine = &vines[i];
149
150 switch (i) {
151 default:
152 return;
153 case 0:
154 boneCount = 9;
155 boneLength = 10.0f;
156 break;
157 case 1:
158 boneCount = 7;
159 boneLength = 8.0f;
160 break;
161 case 2:
162 boneCount = 7;
163 boneLength = 8.0f;
164 break;
165 case 3:
166 boneCount = 5;
167 boneLength = 8.0f;
168 break;
169 }
170
171 vine->boneCount = boneCount;
172 vine->boneLength = boneLength;
173
174 for (j = 0; j < boneCount; j++) {
175 if (j == (boneCount - 1)) {
176 vine->boneRot[j] += 90.0f;
177 } else {
178 curAngle1 = vine->boneRot[j];
179 nextAngle = vine->boneRot[j + 1];
180 if (nextAngle - curAngle1 > 180.0f) {
181 curAngle1 += 360.0f;
182 } else if (nextAngle - curAngle1 < -180.0f) {
183 nextAngle += 360.0f;
184 }
185 // average cur and next angles
186 vine->boneRot[j] = ((curAngle1 + nextAngle) / 2.0) + 90.0;
187 }
188 }
189
191 }
192
193 N(VineRenderState) = 1;
194 }
195
196 gDPPipeSync(gMainGfxPos++);
197 gSPDisplayList(gMainGfxPos++, N(lava_piranha_vine_gfx));
198
199 for (i = 0; i < NUM_VINES; i++) {
200 LavaPiranhaVine* vines = (LavaPiranhaVine*) evt_get_variable(NULL, MV_VinesData);
201 LavaPiranhaVine* vine = &vines[i];
202
203 boneLength = vine->boneLength;
204 boneCount = vine->boneCount;
205 numPoints = vine->numPoints;
206
207 // we'll build the vertex data and place it in the display list, so jump forward
208 // here and leave space behind for the gSPBranchList command followed by two vertices
209 // for each point in numPoints
210
211 vtxBuffer = (Vtx_t*)(gMainGfxPos + 1);
212 gSPBranchList(gMainGfxPos, &gMainGfxPos[1 + 2 * (2 * numPoints)]);
213 vtx = (Vtx_t*) (++gMainGfxPos);
214 gMainGfxPos = &gMainGfxPos[2 * (2 * numPoints)];
215
216 for (j = 0; j < numPoints; j++) {
217 posX = vine->points[j].x;
218 posY = vine->points[j].y;
219 posZ = vine->points[j].z;
220
221 alphaCoord = ((f32) j * boneCount) / numPoints;
222 nearest = (s32) alphaCoord;
223 alphaFrac = alphaCoord - (f32)nearest;
224
225 if (nearest + 1 >= boneCount) {
226 angle = vine->boneRot[boneCount - 1];
227 } else {
228 curAngle2 = vine->boneRot[nearest];
229 nextAngle = vine->boneRot[nearest + 1];
230 if (nextAngle - curAngle2 > 180.0f) {
231 nextAngle -= 360.0f;
232 }
233 if (nextAngle - curAngle2 < -180.0f) {
234 nextAngle += 360.0f;
235 }
236 angle = ((nextAngle - curAngle2) * alphaFrac) + curAngle2;
237 }
238
239 deltaX = sin_deg(angle) * boneLength;
240 deltaY = -cos_deg(angle) * boneLength;
241
242 vtx->ob[0] = posX + deltaX;
243 vtx->ob[1] = posY + deltaY;
244 vtx->ob[2] = posZ;
245 vtx->tc[0] = j * 0x140;
246 vtx->tc[1] = 0;
247 vtx->cn[0] = j * 50;
248 vtx->cn[1] = j * 120;
249 vtx->cn[2] = j * 30;
250 vtx++;
251
252 vtx->ob[0] = posX - deltaX;
253 vtx->ob[1] = posY - deltaY;
254 vtx->ob[2] = posZ;
255 vtx->tc[0] = j * 0x140;
256 vtx->tc[1] = 0x400;
257 vtx->cn[0] = j * 50;
258 vtx->cn[1] = j * 120;
259 vtx->cn[2] = j * 30;
260 vtx++;
261 }
262
263 for (j = 0; j < numPoints - 1; j++) {
264 gSPVertex(gMainGfxPos++, &vtxBuffer[2*j], 4, 0);
265 gSP2Triangles(gMainGfxPos++, 1, 0, 2, 0, 1, 2, 3, 0);
266 }
267 }
268
269 gDPPipeSync(gMainGfxPos++);
270}
271
273 RenderTask renderTask;
274
275 renderTask.appendGfx = &N(appendGfx_piranha_vines);
276 renderTask.appendGfxArg = 0;
277 renderTask.dist = 10;
279
280 queue_render_task(&renderTask);
281}
282
283API_CALLABLE(N(MarkVineInterpolationDirty)) {
284 N(VineRenderState) = 0;
285 return ApiStatus_DONE2;
286}
287
288API_CALLABLE(N(CreateVineRenderer)) {
289 LavaPiranhaVine* data = heap_malloc(NUM_VINES * sizeof(*data));
290 evt_set_variable(script, MV_VinesData, (s32) data);
291 N(VineRenderState) = -1;
293 return ApiStatus_DONE2;
294}
Bytecode * ptrReadPos
#define queue_render_task
#define sin_deg
#define cos_deg
@ EASING_LINEAR
Definition enums.h:510
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3264
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
s32 create_worker_world(WorldArgs, WorldArgs)
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1847
f32 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1930
void * heap_malloc(s32 size)
Definition heap.c:34
@ NUM_VINES
Definition part1.inc.c:6
#define PIRANHA_DMA_ENTRY(name)
Definition part2.inc.c:5
void N appendGfx_piranha_vines(void *data)
Definition part2.inc.c:119
void N make_vine_interpolation(LavaPiranhaVine *vine)
Definition part2.inc.c:50
void N worker_render_piranha_vines(void)
Definition part2.inc.c:272
ApiStatus LoadPath(Evt *script, b32 isInitialCall)
ApiStatus GetNextPathPos(Evt *script, b32 isInitialCall)
#define BSS
Definition macros.h:7
#define LVar2
Definition macros.h:150
#define LVar1
Definition macros.h:149
#define A(sym)
Definition macros.h:36
#define LVar3
Definition macros.h:151
void * appendGfxArg
void(* appendGfx)(void *)
Gfx * gMainGfxPos
Definition cam_main.c:15