NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
ef_res_emitter.h
1#ifndef NW4R_EF_RES_EMITTER_H
2#define NW4R_EF_RES_EMITTER_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/ef/ef_types.h>
6#include <nw4r/ef/emform/ef_emform.h>
7
8#include <nw4r/math.h>
9
10#include <revolution/GX.h>
11
12namespace nw4r {
13namespace ef {
14
15// Forward declarations
17
19 u8 mA; // at 0x0
20 u8 mB; // at 0x1
21 u8 mC; // at 0x2
22 u8 mD; // at 0x3
23};
24
26 u8 mOp; // at 0x0
27 u8 mBias; // at 0x1
28 u8 mScale; // at 0x2
29 u8 mClamp; // at 0x3
30 u8 mOutReg; // at 0x4
31};
32
34 u8 mA; // at 0x0
35 u8 mB; // at 0x1
36 u8 mC; // at 0x2
37 u8 mD; // at 0x3
38};
39
40struct BlendMode {
41 u8 mType; // at 0x0
42 u8 mSrcFactor; // at 0x1
43 u8 mDstFactor; // at 0x2
44 u8 mOp; // at 0x3
45};
46
47struct ColorInput {
48 enum TevColor {
49 TEVCOLOR_NULL,
50 TEVCOLOR1_1,
51 TEVCOLOR1_2,
52 TEVCOLOR2_3,
53 TEVCOLOR2_2,
54 TEVCOLOR1_MULT,
55 TEVCOLOR2_MULT
56 };
57
58 enum RasColor {
59 RASCOLOR_NULL,
60 RASCOLOR_LIGHTING,
61 };
62
63 u8 mRasColor; // at 0x0
64 u8 mTevColor[GX_MAX_TEVREG - 1]; // at 0x1
65 u8 mTevKColor[GX_MAX_KCOLOR]; // at 0x4
66};
67
68// TODO: Why?
69#pragma pack(push, 1)
70struct Lighting {
71 enum Mode {
72 LIGHTING_MODE_OFF,
73 LIGHTING_MODE_SIMPLE,
74 LIGHTING_MODE_HARDWARE
75 };
76
77 enum Type {
78 LIGHTING_TYPE_NONE,
79 LIGHTING_TYPE_AMBIENT,
80 LIGHTING_TYPE_POINT
81 };
82
83 u8 mMode; // at 0x0
84 u8 mType; // at 0x1
85 GXColor mAmbient; // at 0x2
86 GXColor mDiffuse; // at 0x6
87 f32 mRadius; // at 0xA
88 math::VEC3 mPosition; // at 0xE
89};
90#pragma pack(pop)
91
93 enum Flag {
94 FLAG_ZCOMP_ENABLE_TEST = (1 << 0),
95 FLAG_ZCOMP_ENABLE_UPDATE = (1 << 1),
96 FLAG_ZCOMP_BEFORE_TEX = (1 << 2),
97 FLAG_CLIP_DISABLE = (1 << 3),
98 FLAG_TEX1_ENABLE = (1 << 4),
99 FLAG_TEX2_ENABLE = (1 << 5),
100 FLAG_TEXIND_ENABLE = (1 << 6),
101 FLAG_TEX1_PROJ = (1 << 7),
102 FLAG_TEX2_PROJ = (1 << 8),
103 FLAG_TEXIND_PROJ = (1 << 9),
104 FLAG_HIDDEN = (1 << 10),
105 FLAG_DRAW_ORDER = (1 << 11),
106 FLAG_FOG_ENABLE = (1 << 12),
107 FLAG_XY_SAME_SIZE = (1 << 13),
108 FLAG_XY_SAME_SCALE = (1 << 14),
109 };
110
111 enum AlphaFlickType {
112 ALPHAFLICK_NONE,
113 ALPHAFLICK_TRIANGLE,
114 ALPHAFLICK_SAWTOOTH1, // Inverse sawtooth wave
115 ALPHAFLICK_SAWTOOTH2,
116 ALPHAFLICK_SQUARE,
117 ALPHAFLICK_SINE
118 };
119
120 enum OptionTypeCommon { TYPE_CMN_NORMAL, TYPE_CMN_CROSS };
121
122 enum DirType {
123 DIR_NO_DESIGN = 5,
124 };
125
126 u16 mFlags; // at 0x0
127 u8 mACmpComp0; // at 0x2
128 u8 mACmpComp1; // at 0x3
129 u8 mACmpOp; // at 0x4
130 u8 mNumTevs; // at 0x5
131 u8 mFlagClamp; // at 0x6
132 u8 mIndirectTargetStage; // at 0x7
133 TevStageColor mTevColor[4]; // at 0x8
134 TevStageColorOp mTevColorOp[4]; // at 0x18
135 TevStageAlpha mTevAlpha[4]; // at 0x2C
136 TevStageColorOp mTevAlphaOp[4]; // at 0x3C
137 u8 mTevKColorSel[4]; // at 0x50
138 u8 mTevKAlphaSel[4]; // at 0x54
139 BlendMode mBlendMode; // at 0x58
140 ColorInput mColorInput; // at 0x5C
141 u8 mZCompareFunc; // at 0x64
142 u8 mAlphaFlickType; // at 0x65
143 u16 mAlphaFlickCycle; // at 0x66
144 u8 mAlphaFlickRandom; // at 0x68
145 u8 mAlphaFlickAmplitude; // at 0x69
146 Lighting mLighting; // at 0x6A
147 f32 mIndTexOffsetMtx[2][3]; // at 0x84
148 s8 mIndTexScaleExp; // at 0x9C
149 s8 pivotX; // at 0x9D
150 s8 pivotY; // at 0x9E
151 u8 PADDING_0xA3; // at 0x9F
152 u8 ptcltype; // at 0xA0
153 u8 typeOption; // at 0xA1
154 u8 typeDir; // at 0xA2
155 u8 typeAxis; // at 0xA3
156 u8 typeOption0; // at 0xA4
157 u8 typeOption1; // at 0xA5
158 u8 typeOption2; // at 0xA6
159 u8 PADDING_0xAB; // at 0xA7
160 f32 zOffset; // at 0xA8
161};
162
164 enum CommonFlag {
165 CMN_FLAG_SYNC_LIFE = (1 << 0),
166 CMN_FLAG_DISABLE_DRAW = (1 << 1),
167 CMN_FLAG_MAX_LIFE = (1 << 2),
168
169 CMN_FLAG_INHERIT_PTCL_SCALE = (1 << 5),
170 CMN_FLAG_INHERIT_PTCL_ROT = (1 << 6),
171
172 CMN_FLAG_EMIT_INHERIT_SCALE = (1 << 7),
173 CMN_FLAG_EMIT_INHERIT_ROT = (1 << 8),
174
175 CMN_FLAG_DISABLE_CALC = (1 << 9),
176
177 CMN_FLAG_RELOCATED = (1 << 30),
178 };
179
180 enum EmitFlag {
181 EMIT_FLAG_8 = (1 << 8),
182 EMIT_FLAG_15 = (1 << 15),
183 EMIT_FLAG_16 = (1 << 16),
184 EMIT_FLAG_17 = (1 << 17),
185 EMIT_FLAG_18 = (1 << 18),
186 EMIT_FLAG_24 = (1 << 24),
187 EMIT_FLAG_XYZ_SAME_SIZE = (1 << 25),
188 EMIT_FLAG_26 = (1 << 26),
189 };
190
191 ulong commonFlag; // at 0x0
192 ulong emitFlag; // at 0x4
193 u16 emitLife; // at 0x8
194 u16 ptclLife; // at 0xA
195 s8 ptclLifeRandom; // at 0xC
196 s8 inheritChildPtclTranslate; // at 0xD
197 s8 emitEmitIntarvalRandom; // at 0xE
198 s8 emitEmitRandom; // at 0xF
199 f32 emitEmit; // at 0x10
200 u16 emitEmitStart; // at 0x14
201 u16 emitEmitPast; // at 0x16
202 u16 emitEmitInterval; // at 0x18
203 s8 inheritPtclTranslate; // at 0x1A
204 s8 inheritChildEmitTranslate; // at 0x1B
205 f32 commonParam[NUM_PARAMS]; // at 0x1C
206 u16 emitEmitDiv; // at 0x34
207 s8 velInitVelocityRandom; // at 0x36
208 s8 velMomentumRandom; // at 0x37
209 f32 velPowerRadiationDir; // at 0x38
210 f32 velPowerYAxis; // at 0x3C
211 f32 velPowerRandomDir; // at 0x40
212 f32 velPowerNormalDir; // at 0x44
213 f32 velDiffusionEmitterNormal; // at 0x48
214 f32 velPowerSpecDir; // at 0x4C
215 f32 velDiffusionSpecDir; // at 0x50
216 math::VEC3 velSpecDir; // at 0x54
217 math::VEC3 scale; // at 0x60
218 math::VEC3 rotate; // at 0x6C
219 math::VEC3 translate; // at 0x78
220 u8 lodNear; // at 0x84
221 u8 lodFar; // at 0x85
222 u8 lodMinEmit; // at 0x86
223 u8 lodAlpha; // at 0x87
224 ulong randomSeed; // at 0x88
225 u8 userdata[8]; // at 0x8C
226 EmitterDrawSetting drawSetting; // at 0x94
227
228 EmitFormType GetFormType() {
229 return static_cast<EmitFormType>(emitFlag & 0xFF);
230 }
231};
232
234private:
235 char* name; // at 0x0
236 ulong headersize; // at 0x4
237
238public:
239 /******************************************************************************
240 * Emitter section
241 ******************************************************************************/
242 EmitterDesc* GetEmitterDesc() {
243 return reinterpret_cast<EmitterDesc*>(reinterpret_cast<u8*>(this) +
244 sizeof(EmitterResource));
245 }
246 u8* SkipEmitterDesc() {
247 u8* pPtr = reinterpret_cast<u8*>(this);
248 pPtr += headersize + sizeof(EmitterResource);
249 return pPtr;
250 }
251
252 const char* GetName() const {
253 return name;
254 }
255
256 EmitterDrawSetting* GetEmitterDrawSetting() {
257 return &GetEmitterDesc()->drawSetting;
258 }
259
260 /******************************************************************************
261 * Particle section
262 ******************************************************************************/
263 ParticleParameterDesc* GetParticleParameterDesc() {
264 u8* pPtr = SkipEmitterDesc();
265 pPtr += 4;
266 return reinterpret_cast<ParticleParameterDesc*>(pPtr);
267 }
268 u8* SkipParticleParameterDesc() {
269 u8* pPtr = SkipEmitterDesc();
270 pPtr += *reinterpret_cast<ulong*>(pPtr) + sizeof(ulong);
271 return pPtr;
272 }
273
274 /******************************************************************************
275 * Animation section
276 ******************************************************************************/
277 u16 NumPtclTrack() {
278 const u8* pPtr = SkipParticleParameterDesc();
279 u16 numPtclTrack = *(reinterpret_cast<const u16*>(pPtr) + 0);
280 return numPtclTrack;
281 }
282 u16 NumPtclInitTrack() {
283 const u8* pPtr = SkipParticleParameterDesc();
284 u16 numPtclTrack = *(reinterpret_cast<const u16*>(pPtr) + 1);
285 return numPtclTrack;
286 }
287
288 u16 NumEmitTrack() {
289 const u8* pPtr = SkipParticleParameterDesc();
290 u16 numPtclTrack = *reinterpret_cast<const u16*>(pPtr);
291
292 pPtr += numPtclTrack * 8 + 4;
293 u16 numEmitTrack = *(reinterpret_cast<const u16*>(pPtr) + 0);
294
295 return numEmitTrack;
296 }
297 u16 NumEmitInitTrack() {
298 const u8* pPtr = SkipParticleParameterDesc();
299 u16 numPtclTrack = *reinterpret_cast<const u16*>(pPtr);
300
301 pPtr += numPtclTrack * 8 + 4;
302 u16 numEmitTrack = *(reinterpret_cast<const u16*>(pPtr) + 1);
303
304 return numEmitTrack;
305 }
306
307 u8** GetPtclTrackTbl() {
308 u8* pPtr = SkipParticleParameterDesc();
309 u8** ppTbl = reinterpret_cast<u8**>(pPtr + 4);
310 return ppTbl;
311 }
312 u8** GetEmitTrackTbl() {
313 u8* pPtr = SkipParticleParameterDesc();
314 u16 numPtclTrack = *reinterpret_cast<const u16*>(pPtr);
315
316 pPtr += numPtclTrack * 8 + 4;
317 u8** ppTbl = reinterpret_cast<u8**>(pPtr + 4);
318 return ppTbl;
319 }
320
321 u8* GetPtclTrack(u16 idx) {
322 u8** ppTbl = GetPtclTrackTbl();
323 return ppTbl[idx];
324 }
325 u8* GetEmitTrack(u16 idx) {
326 u8** ppTbl = GetEmitTrackTbl();
327 return ppTbl[idx];
328 }
329
330 void LocateTracks() {
331 u8* pTail = SkipParticleParameterDesc();
332 pTail += NumPtclTrack() * 8 + 4;
333 pTail += NumEmitTrack() * 8 + 4;
334
335 ulong* pPtclPtrTbl = reinterpret_cast<ulong*>(GetPtclTrackTbl());
336 ulong* pEmitPtrTbl = reinterpret_cast<ulong*>(GetEmitTrackTbl());
337
338 ulong* pPtclSizeTbl =
339 reinterpret_cast<ulong*>(GetPtclTrackTbl()) + NumPtclTrack();
340 ulong* pEmitSizeTbl =
341 reinterpret_cast<ulong*>(GetEmitTrackTbl()) + NumEmitTrack();
342
343 int i;
344 for (i = 0; i < NumPtclTrack(); i++) {
345 pPtclPtrTbl[i] = reinterpret_cast<ulong>(pTail);
346 pTail += pPtclSizeTbl[i];
347 }
348
349 for (i = 0; i < NumEmitTrack(); i++) {
350 pEmitPtrTbl[i] = reinterpret_cast<ulong>(pTail);
351 pTail += pEmitSizeTbl[i];
352 }
353 }
354};
355
356class ResEmitter {
357private:
358 EmitterResource* mData; // at 0x0
359
360public:
361 explicit ResEmitter(EmitterResource* pData = NULL) : mData(pData) {}
362 explicit ResEmitter(const ResEmitter& rOther) : mData(rOther.mData) {}
363
364 bool IsValid() const {
365 return mData != NULL;
366 }
367
368 EmitterResource* ptr() {
369 return mData;
370 }
371};
372
373} // namespace ef
374} // namespace nw4r
375
376#endif