Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
foliage.cpp
Go to the documentation of this file.
1#include "foliage.hpp"
2
3namespace foliage {
4
6 guMtxIdentF(mtx);
7 mtx[1][0] = scale * xAmount;
8 mtx[1][1] = 1.0f;
9 mtx[1][2] = scale * zAmount;
10}
11
17API_CALLABLE(TransformFoliage) {
18 Bytecode* args = script->ptrReadPos;
20 f32 scale = evt_get_float_variable(script, *args++);
25 Matrix4f mtx;
26
27 if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM)) {
28 guTranslateF(model->userTransformMtx, 0.0f, dy, 0.0f);
29 setup_shear_mtx(mtx, scale, dx, dz);
30 guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx);
31 guTranslateF(mtx, 0.0f, -dy, 0.0f);
32 guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx);
34 } else {
35 guTranslateF(mtx, 0.0f, dy, 0.0f);
36 guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx);
37 setup_shear_mtx(mtx, scale, dx, dz);
38 guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx);
39 guTranslateF(mtx, 0.0f, -dy, 0.0f);
40 guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx);
41 }
42
43 return ApiStatus_DONE2;
44}
45
47 UseBuf(LVar0) // SearchBushConfig
48 BufRead4(LVar1, LVar2, LVar3, LVar4) // bush, drops, vectors, callback
50 Thread
52 IfNe(LVar1, 0)
53 Loop(5)
54 UseBuf(LVar1) // FoliageVectorList bush
55 BufRead1(LVar2) // count
56 BufRead1(LVarD) // vectors
57 UseBuf(LVarD) // *vectors
58 Loop(LVar2)
64 EndIf
66 Wait(1)
67 UseBuf(LVar1) // FoliageVectorList bush
68 BufRead1(LVar2) // count
69 BufRead1(LVarD) // vectors
70 UseBuf(LVarD) // *vectors
71 Loop(LVar2)
73 Call(TransformFoliage, LVar3, Float(0.1), -1, LVarF, 0)
75 Wait(1)
77 UseBuf(LVar1) // FoliageVectorList bush
78 BufRead1(LVar2) // count
79 BufRead1(LVarD) // vectors
80 UseBuf(LVarD) // *vectors
81 Loop(LVar2)
83 Call(TranslateModel, LVar3, 0, 0, 0)
85 Wait(1)
86 EndIf
88 Thread
89 IfNe(LVar2, 0)
90 UseBuf(LVar2) // FoliageDropList drops
91 BufRead1(LVar3) // count
92 BufRead1(LVarD) // vectors
93 UseBuf(LVarD) // *vectors
94 Loop(LVar3)
98 IfEq(LVarA, 0)
100 Else
102 IfEq(LVarB, 0)
105 EndIf
106 EndIf
107 EndLoop
108 EndIf
110 Wait(15)
111 IfNe(LVar4, 0)
113 EndIf
114 Return
115 End
116};
117
119 SetTimescale(Float(2.0))
120 UseBuf(LVar0) // ShakeTreeConfig
121 BufRead4(LVar1, LVar2, LVar3, LVar4) // leaves, trunk, drops, vectors
122 BufRead1(LVar5) // callback
124 //Call(PlaySound, SOUND_SMACK_TREE)
125 //Call(PlaySound, SOUND_SHAKE_TREE_LEAVES)
126 Thread
128 IfNe(LVar1, 0)
129 Wait(1)
130 Loop(5)
131 UseBuf(LVar1) // FoliageModelList leaves
132 BufRead1(LVar2) // count
133 BufRead1(LVarD) // models
134 UseBuf(LVarD) // *models
135 Loop(LVar2)
137 Call(TransformFoliage, LVar3, Float(0.1), Float(0.2), LVarF, 0)
139 Set(LFlag0, TRUE)
141 EndIf
142 EndLoop
143 Wait(1)
144 UseBuf(LVar1) // FoliageModelList leaves
145 BufRead1(LVar2) // count
146 BufRead1(LVarD) // models
147 UseBuf(LVarD) // *models
148 Loop(LVar2)
150 Call(TransformFoliage, LVar3, Float(0.1), Float(-0.2), LVarF, 0)
151 EndLoop
152 Wait(1)
153 EndLoop
154 UseBuf(LVar1) // FoliageModelList leaves
155 BufRead1(LVar2) // count
156 BufRead1(LVarD) // models
157 UseBuf(LVarD) // *models
158 Loop(LVar2)
160 Call(TranslateModel, LVar3, 0, 0, 0)
161 EndLoop
162 Wait(1)
163 EndIf
165 Thread
167 IfNe(LVar2, 0)
168 Loop(5)
169 UseBuf(LVar2) // FoliageModelList trunk
170 BufRead1(LVar3) // count
171 BufRead1(LVarD) // models
172 UseBuf(LVarD) // *models
173 Loop(LVar3)
175 Call(TransformFoliage, LVar4, Float(0.1), Float(0.2), LVarF, 0)
177 Set(LFlag0, TRUE)
179 EndIf
180 EndLoop
181 Wait(1)
182 UseBuf(LVar2) // FoliageModelList trunk
183 BufRead1(LVar3) // count
184 BufRead1(LVarD) // models
185 UseBuf(LVarD) // *models
186 Loop(LVar3)
188 Call(TransformFoliage, LVar4, Float(0.1), Float(-0.2), LVarF, 0)
189 EndLoop
190 Wait(1)
191 EndLoop
192 UseBuf(LVar2) // FoliageModelList trunk
193 BufRead1(LVar3) // count
194 BufRead1(LVarD) // models
195 UseBuf(LVarD) // *models
196 Loop(LVar3)
198 Call(TranslateModel, LVar4, 0, 0, 0)
199 EndLoop
200 Wait(1)
201 EndIf
203 Thread
204 IfNe(LVar3, 0)
205 UseBuf(LVar3) // FoliageDropList drops
206 BufRead1(LVar4) // count
207 BufRead1(LVarD) // drops
208 UseBuf(LVarD) // *drops
209 Loop(LVar4)
213 IfEq(LVarB, 0)
215 Else
217 IfEq(LVarC, 0)
220 EndIf
221 EndIf
222 EndLoop
223 EndIf
225 Thread
226 IfNe(LVar4, 0)
227 UseBuf(LVar4) // FoliageDropList vectors
228 BufRead1(LVar5) // count
229 BufRead1(LVarD) // vectors
230 UseBuf(LVarD) // *vectors
231 Loop(LVar5)
232 BufRead3(LVar6, LVar7, LVar8) // x y z
234 EndLoop
235 EndIf
237 IfNe(LVar5, 0)
239 EndIf
240 Wait(15)
241 Return
242 End
243};
244
245}; // namespace foliage
BSS s32 PopupMenu_SelectedIndex
f32 Matrix4f[4][4]
Bytecode EvtScript[]
#define guTranslateF
#define guMtxCatF
@ MODEL_FLAG_HAS_TRANSFORM
Definition enums.h:4366
@ MODEL_FLAG_MATRIX_DIRTY
Definition enums.h:4368
@ SOUND_SMACK_TREE
Definition enums.h:787
@ SOUND_SEARCH_BUSH
Definition enums.h:773
@ SOUND_SHAKE_TREE_LEAVES
Definition enums.h:788
@ SOUND_SPACE_DEFAULT
Definition enums.h:1737
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1689
s32 get_model_list_index_from_tree_index(s32 treeIndex)
Definition model.c:3396
struct Model * get_model_from_list_index(s32 listIndex)
Definition model.c:3314
f32 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1929
Definition model.h:59
void setup_shear_mtx(Matrix4f mtx, f32 scale, f32 xAmount, f32 zAmount)
Definition foliage.cpp:5
EvtScript EVS_SearchBush
Definition foliage.cpp:46
EvtScript EVS_ShakeTree
Definition foliage.cpp:118
ApiStatus PlaySoundAtModel(Evt *script, b32 isInitialCall)
Plays the given sound at the given model.
ApiStatus TranslateModel(Evt *script, b32 isInitialCall)
Translates the given model's position.
ApiStatus DropItemEntity(Evt *script, b32 isInitialCall)
ApiStatus SetValueByRef(Evt *script, b32 isInitialCall)
ApiStatus GetValueByRef(Evt *script, b32 isInitialCall)
ApiStatus GetPlayerPos(Evt *script, b32 isInitialCall)
#define Else
Marks the end of an if statement and the start of the else block.
Definition macros.h:295
#define LVar6
Definition macros.h:154
#define Set(VAR, INT_VALUE)
Sets the given variable to a given value casted to an integer.
Definition macros.h:365
#define LVarF
Definition macros.h:163
#define IfNe(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR != RVAR.
Definition macros.h:272
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define UseBuf(INT_PTR)
Loads a s32 pointer for use with subsequent EVT_BUF_READ commands.
Definition macros.h:389
#define EndLoop
Marks the end of a loop.
Definition macros.h:248
#define BufRead4(VAR1, VAR2, VAR3, VAR4)
Consumes the next four s32s from the buffer and stores them in the given variables.
Definition macros.h:401
#define LVarC
Definition macros.h:160
#define BufRead1(VAR)
Consumes the next s32 from the buffer and stores it in the given variable.
Definition macros.h:392
#define Float(DOUBLE)
Definition macros.h:51
#define BufRead3(VAR1, VAR2, VAR3)
Consumes the next three s32s from the buffer and stores them in the given variables.
Definition macros.h:398
#define EndIf
Marks the end of an if statement or an else block.
Definition macros.h:298
#define LVar5
Definition macros.h:153
#define SetTimescale(TIMESCALE)
Sets the current thread's timescale. This is a multiplier applied to Wait and Wait_SECONDS.
Definition macros.h:516
#define LVarB
Definition macros.h:159
#define ExecWait(EVT_SOURCE)
Launches a new child thread.
Definition macros.h:475
#define LVar7
Definition macros.h:155
#define Thread
Marks the start of a thread block.
Definition macros.h:544
#define EndThread
Marks the end of a thread block.
Definition macros.h:547
#define LVar8
Definition macros.h:156
#define LVar2
Definition macros.h:150
#define LVar1
Definition macros.h:149
#define LFlag0
Definition macros.h:167
#define LVarA
Definition macros.h:158
#define LVarD
Definition macros.h:161
#define Wait(NUM_FRAMES)
Blocks for the given number of frames.
Definition macros.h:254
#define LVar9
Definition macros.h:157
#define PlayEffect(args...)
Definition macros.h:807
#define IfEq(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR == RVAR.
Definition macros.h:269
#define Call(FUNC, ARGS...)
Calls a given C EVT API function with any number of arguments.
Definition macros.h:576
#define Loop(TIMES)
Marks the beginning of a loop.
Definition macros.h:245
#define LVar4
Definition macros.h:152
#define LVar3
Definition macros.h:151
#define LVar0
Definition macros.h:148
#define Return
Kills the current EVT thread.
Definition macros.h:217