NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
lyt_types.h
1#ifndef NW4R_LYT_TYPES_H
2#define NW4R_LYT_TYPES_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/math.h>
6#include <nw4r/ut.h>
7
8#define NW4R_LYT_LIBRARY_VERSION 8
9
10#define NW4R_LYT_RES_NAME_LEN 16
11#define NW4R_LYT_PANE_USERDATA_LEN 8
12#define NW4R_LYT_MATERIAL_NAME_LEN 20
13
14namespace nw4r {
15namespace lyt {
16
17// Forward declarations
18class AnimTransform;
19
20namespace detail {
21
22/******************************************************************************
23 *
24 * Pointer operations
25 *
26 ******************************************************************************/
27template <typename T> T* ConvertOffsToPtr(void* pBase, ulong offset) {
28 return reinterpret_cast<T*>(reinterpret_cast<u8*>(pBase) + offset);
29}
30template <typename T> const T* ConvertOffsToPtr(const void* pBase, ulong offset) {
31 return reinterpret_cast<const T*>(reinterpret_cast<const u8*>(pBase) +
32 offset);
33}
34
35/******************************************************************************
36 *
37 * Bit operations
38 *
39 ******************************************************************************/
40template <typename T> inline void SetBit(T* pBits, int pos, bool value) {
41 T mask = ~(1 << pos);
42 *pBits &= mask;
43 *pBits |= (value ? 1 : 0) << pos;
44}
45template <typename T> inline bool TestBit(T bits, int pos) {
46 T mask = 1 << pos;
47 return (bits & mask) != 0;
48}
49template <typename T> inline T GetBits(T bits, int pos, int len) {
50 T mask = ~(static_cast<T>(-1) << len);
51 return bits >> pos & mask;
52}
53
54} // namespace detail
55
56/******************************************************************************
57 *
58 * Size
59 *
60 ******************************************************************************/
61struct Size {
62 f32 width; // at 0x0
63 f32 height; // at 0x4
64
65 Size() : width(0.0f), height(0.0f) {}
66 Size(const Size& rOther) : width(rOther.width), height(rOther.height) {}
67 Size(f32 w, f32 h) : width(w), height(h) {}
68
69 friend bool operator==(const Size& rLhs, const Size& rRhs) {
70 return rLhs.width == rRhs.width && rLhs.height == rRhs.height;
71 }
72};
73
75 const char *GetTargetGroupName() const {
76 return targetGroupName;
77 }
78 const char *GetSrcPaneName() const {
79 return srcPaneName;
80 }
81
82 char srcPaneName[17]; // at 0x00
83 char targetGroupName[17]; // at 0x11
84 u8 padding[2]; // at 0x12
85};
86
87/******************************************************************************
88 *
89 * AnimationLink
90 *
91 ******************************************************************************/
92class AnimationLink {
93public:
94 AnimationLink() : mbDisable(false) {
95 Reset();
96 }
97
98 void Reset() {
99 SetAnimTransform(NULL, 0);
100 }
101
102 AnimTransform* GetAnimTransform() const {
103 return mAnimTrans;
104 }
105 void SetAnimTransform(AnimTransform* pAnimTrans, u16 idx) {
106 mAnimTrans = pAnimTrans;
107 mIdx = idx;
108 }
109
110 u16 GetIndex() const {
111 return mIdx;
112 }
113
114 bool IsEnable() const {
115 return !mbDisable;
116 }
117 void SetEnable(bool enable) {
118 mbDisable = !enable;
119 }
120
121public:
122 NW4R_UT_LINKLIST_NODE_DECL(); // at 0x0
123
124private:
125 AnimTransform* mAnimTrans; // at 0x8
126 u16 mIdx; // at 0xC
127 bool mbDisable; // at 0xE
128};
129
130NW4R_UT_LINKLIST_TYPEDEF_DECL(AnimationLink);
131
133 const char *GetName() const {
134 return name;
135 }
136
137 char name[17]; // at 0x00
138 u8 flag; // at 0x11
139 u8 padding[2]; // at 0x12
140};
141
142/******************************************************************************
143 *
144 * AlphaCompare
145 *
146 ******************************************************************************/
147struct AlphaCompare {
148 u8 comp; // at 0x0
149 u8 op; // at 0x1
150 u8 ref0; // at 0x2
151 u8 ref1; // at 0x3
152
153 AlphaCompare() {
154 Set(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
155 }
156
157 void Set(GXCompare comp0, u8 _ref0, GXAlphaOp _op, GXCompare comp1,
158 u8 _ref1) {
159
160 comp = (comp0 & 0b111) | ((comp1 & 0b111) << 4);
161 op = _op;
162 ref0 = _ref0;
163 ref1 = _ref1;
164 }
165
166 GXCompare GetComp0() const {
167 return static_cast<GXCompare>(comp & 0b1111);
168 }
169 GXCompare GetComp1() const {
170 return static_cast<GXCompare>(comp >> 4 & 0b1111);
171 }
172
173 GXAlphaOp GetOp() const {
174 return static_cast<GXAlphaOp>(op);
175 }
176
177 u8 GetRef0() const {
178 return ref0;
179 }
180 u8 GetRef1() const {
181 return ref1;
182 }
183};
184
185/******************************************************************************
186 *
187 * BlendMode
188 *
189 ******************************************************************************/
190struct BlendMode {
191 u8 type; // at 0x0
192 u8 srcFactor; // at 0x1
193 u8 dstFactor; // at 0x2
194 u8 op; // at 0x3
195
196 BlendMode() {
197 Set(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);
198 }
199
200 void Set(GXBlendMode _type, GXBlendFactor src, GXBlendFactor dst,
201 GXLogicOp _op) {
202
203 type = _type;
204 srcFactor = src;
205 dstFactor = dst;
206 op = _op;
207 }
208
209 GXBlendMode GetType() const {
210 return static_cast<GXBlendMode>(type);
211 }
212
213 GXBlendFactor GetSrcFactor() const {
214 return static_cast<GXBlendFactor>(srcFactor);
215 }
216 GXBlendFactor GetDstFactor() const {
217 return static_cast<GXBlendFactor>(dstFactor);
218 }
219
220 GXLogicOp GetOp() const {
221 return static_cast<GXLogicOp>(op);
222 }
223};
224
225/******************************************************************************
226 *
227 * ChanCtrl
228 *
229 ******************************************************************************/
230struct ChanCtrl {
231 u8 matSrcCol; // at 0x0
232 u8 matSrcAlp; // at 0x1
233 u8 reserve1; // at 0x2
234 u8 reserve2; // at 0x3
235
236 ChanCtrl() : reserve1(0), reserve2(0) {
237 Set(GX_SRC_VTX, GX_SRC_VTX);
238 }
239
240 void Set(GXColorSrc color, GXColorSrc alpha) {
241 matSrcCol = color;
242 matSrcAlp = alpha;
243 }
244
245 GXColorSrc GetColorSrc() const {
246 return static_cast<GXColorSrc>(matSrcCol);
247 }
248 GXColorSrc GetAlphaSrc() const {
249 return static_cast<GXColorSrc>(matSrcAlp);
250 }
251};
252
253/******************************************************************************
254 *
255 * IndirectStage
256 *
257 ******************************************************************************/
258struct IndirectStage {
259 u8 texCoordGen; // at 0x0
260 u8 texMap; // at 0x1
261 u8 scaleS; // at 0x2
262 u8 scaleT; // at 0x3
263
264 IndirectStage() {
265 Set(GX_TEXCOORD0, GX_TEXMAP0, GX_ITS_1, GX_ITS_1);
266 }
267
268 void Set(GXTexCoordID gen, GXTexMapID map, GXIndTexScale _scaleS,
269 GXIndTexScale _scaleT) {
270
271 texCoordGen = gen;
272 texMap = map;
273 scaleS = _scaleS;
274 scaleT = _scaleT;
275 }
276
277 GXTexCoordID GetTexCoordGen() const {
278 return static_cast<GXTexCoordID>(texCoordGen);
279 }
280
281 GXTexMapID GetTexMap() const {
282 return static_cast<GXTexMapID>(texMap);
283 }
284
285 GXIndTexScale GetScaleS() const {
286 return static_cast<GXIndTexScale>(scaleS);
287 }
288 GXIndTexScale GetScaleT() const {
289 return static_cast<GXIndTexScale>(scaleT);
290 }
291};
292
293/******************************************************************************
294 *
295 * TevStageInOp
296 *
297 ******************************************************************************/
299 u8 ab; // at 0x0
300 u8 cd; // at 0x1
301 u8 op; // at 0x2
302 u8 cl; // at 0x3
303
304 u8 GetA() const {
305 return ab & 0b1111;
306 }
307 u8 GetB() const {
308 return ab >> 4 & 0b1111;
309 }
310
311 u8 GetC() const {
312 return cd & 0b1111;
313 }
314 u8 GetD() const {
315 return cd >> 4 & 0b1111;
316 }
317
318 void SetIn(u8 a, u8 b, u8 c, u8 d) {
319 ab = a & 0b1111 | (b & 0b1111) << 4;
320 cd = c & 0b1111 | (d & 0b1111) << 4;
321 }
322
323 u8 GetOp() const {
324 return op & 0b1111;
325 }
326 u8 GetBias() const {
327 return op >> 4 & 0b11;
328 }
329 u8 GetScale() const {
330 return op >> 6 & 0b11;
331 }
332
333 bool IsClamp() const {
334 return cl & 0b1;
335 }
336 u8 GetOutReg() const {
337 return cl >> 1 & 0b11;
338 }
339 u8 GetKSel() const {
340 return cl >> 3 & 0b11111;
341 }
342
343 void SetOp(u8 _op, u8 bias, u8 scale, bool clamp, u8 outReg, u8 ksel) {
344 op = _op & 0b1111 | (bias & 0b11) << 4 | (scale & 0b11) << 6;
345 cl = clamp & 0b1 | (outReg & 0b11) << 1 | (ksel & 0b11111) << 3;
346 }
347};
348
349/******************************************************************************
350 *
351 * TevStage
352 *
353 ******************************************************************************/
354struct TevStage {
355 u8 texCoordGen; // at 0x0
356 u8 colChan; // at 0x1
357 u8 texMap; // at 0x2
358 u8 swapSel; // at 0x3
359 TevStageInOp colIn; // at 0x4
360 TevStageInOp alpIn; // at 0x8
361 u8 indStage; // at 0xC
362 u8 indBiMt; // at 0xD
363 u8 indWrap; // at 0xE
364 u8 indFoAdUtAl; // at 0xF
365
366 TevStage() {
367 SetOrder(GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0, GX_TEV_SWAP0,
368 GX_TEV_SWAP0);
369
370 SetColorIn(GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_RASC);
371 SetAlphaIn(GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_RASA);
372
373 SetColorOp(GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV,
374 GX_TEV_KCSEL_K0);
375 SetAlphaOp(GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV,
376 GX_TEV_KASEL_K0_R);
377
378 SetIndirect(GX_INDTEXSTAGE0, GX_ITF_8, GX_ITB_NONE, GX_ITM_OFF,
379 GX_ITW_OFF, GX_ITW_OFF, false, false, GX_ITBA_OFF);
380 }
381
382 void SetOrder(GXTexCoordID gen, GXTexMapID map, GXChannelID chan,
383 GXTevSwapSel ras, GXTevSwapSel tex) {
384
385 texCoordGen = gen;
386 colChan = chan;
387 texMap = map;
388 swapSel = (ras & 0b111) << 1 | (tex & 0b111) << 3 | (map >> 8);
389 }
390
391 void SetColorIn(GXTevColorArg a, GXTevColorArg b, GXTevColorArg c,
392 GXTevColorArg d) {
393
394 colIn.SetIn(a, b, c, d);
395 }
396 void SetColorOp(GXTevOp op, GXTevBias bias, GXTevScale scale, bool clamp,
397 GXTevRegID outReg, GXTevKColorSel ksel) {
398
399 colIn.SetOp(op, bias, scale, clamp, outReg, ksel);
400 }
401
402 void SetAlphaIn(GXTevAlphaArg a, GXTevAlphaArg b, GXTevAlphaArg c,
403 GXTevAlphaArg d) {
404
405 alpIn.SetIn(a, b, c, d);
406 }
407 void SetAlphaOp(GXTevOp op, GXTevBias bias, GXTevScale scale, bool clamp,
408 GXTevRegID outReg, GXTevKAlphaSel ksel) {
409
410 alpIn.SetOp(op, bias, scale, clamp, outReg, ksel);
411 }
412
413 void SetIndirect(GXIndTexStageID stage, GXIndTexFormat format,
414 GXIndTexBiasSel bias, GXIndTexMtxID mtx,
415 GXIndTexWrap wrapS, GXIndTexWrap wrapT, bool addPrev,
416 bool utcLod, GXIndTexAlphaSel alphaSel) {
417
418 indStage = stage;
419 indBiMt = bias & 0b111 | (mtx & 0b1111) << 4;
420 indWrap = wrapS & 0b111 | (wrapT & 0b111) << 3;
421
422 indFoAdUtAl = format & 0b111 | (addPrev ? 1 : 0) << 2 | utcLod << 3 |
423 (alphaSel & 0b11) << 4;
424 }
425
426 GXTexCoordID GetTexCoordGen() const {
427 return static_cast<GXTexCoordID>(texCoordGen);
428 }
429
430 GXChannelID GetColorChan() const {
431 return static_cast<GXChannelID>(colChan);
432 }
433
434 GXTexMapID GetTexMap() const {
435 return static_cast<GXTexMapID>(texMap | (swapSel & 0b1) << 8);
436 }
437
438 GXTevSwapSel GetRasSwapSel() const {
439 return static_cast<GXTevSwapSel>(swapSel >> 1 & 0b11);
440 }
441 GXTevSwapSel GetTexSwapSel() const {
442 return static_cast<GXTevSwapSel>(swapSel >> 3 & 0b11);
443 }
444
445 GXTevColorArg GetColorInA() const {
446 return static_cast<GXTevColorArg>(colIn.GetA());
447 }
448 GXTevColorArg GetColorInB() const {
449 return static_cast<GXTevColorArg>(colIn.GetB());
450 }
451 GXTevColorArg GetColorInC() const {
452 return static_cast<GXTevColorArg>(colIn.GetC());
453 }
454 GXTevColorArg GetColorInD() const {
455 return static_cast<GXTevColorArg>(colIn.GetD());
456 }
457
458 GXTevOp GetColorOp() const {
459 return static_cast<GXTevOp>(colIn.GetOp());
460 }
461 GXTevBias GetColorBias() const {
462 return static_cast<GXTevBias>(colIn.GetBias());
463 }
464 GXTevScale GetColorScale() const {
465 return static_cast<GXTevScale>(colIn.GetScale());
466 }
467
468 bool IsColorClamp() const {
469 return colIn.IsClamp();
470 }
471 GXTevRegID GetColorOutReg() const {
472 return static_cast<GXTevRegID>(colIn.GetOutReg());
473 }
474 GXTevKColorSel GetKColorSel() const {
475 return static_cast<GXTevKColorSel>(colIn.GetKSel());
476 }
477
478 GXTevAlphaArg GetAlphaInA() const {
479 return static_cast<GXTevAlphaArg>(alpIn.GetA());
480 }
481 GXTevAlphaArg GetAlphaInB() const {
482 return static_cast<GXTevAlphaArg>(alpIn.GetB());
483 }
484 GXTevAlphaArg GetAlphaInC() const {
485 return static_cast<GXTevAlphaArg>(alpIn.GetC());
486 }
487 GXTevAlphaArg GetAlphaInD() const {
488 return static_cast<GXTevAlphaArg>(alpIn.GetD());
489 }
490
491 GXTevOp GetAlphaOp() const {
492 return static_cast<GXTevOp>(alpIn.GetOp());
493 }
494 GXTevBias GetAlphaBias() const {
495 return static_cast<GXTevBias>(alpIn.GetBias());
496 }
497 GXTevScale GetAlphaScale() const {
498 return static_cast<GXTevScale>(alpIn.GetScale());
499 }
500
501 bool IsAlphaClamp() const {
502 return alpIn.IsClamp();
503 }
504 GXTevRegID GetAlphaOutReg() const {
505 return static_cast<GXTevRegID>(alpIn.GetOutReg());
506 }
507 GXTevKAlphaSel GetKAlphaSel() const {
508 return static_cast<GXTevKAlphaSel>(alpIn.GetKSel());
509 }
510
511 GXIndTexStageID GetIndStage() const {
512 return static_cast<GXIndTexStageID>(indStage);
513 }
514
515 GXIndTexBiasSel GetIndBiasSel() const {
516 return static_cast<GXIndTexBiasSel>(indBiMt & 0b111);
517 }
518 GXIndTexMtxID GetIndMtxSel() const {
519 return static_cast<GXIndTexMtxID>(indBiMt >> 3 & 0b1111);
520 }
521
522 GXIndTexWrap GetIndWrapS() const {
523 return static_cast<GXIndTexWrap>(indWrap & 0b111);
524 }
525 GXIndTexWrap GetIndWrapT() const {
526 return static_cast<GXIndTexWrap>(indWrap >> 3 & 0b111);
527 }
528
529 GXIndTexFormat GetIndFormat() const {
530 return static_cast<GXIndTexFormat>(indFoAdUtAl & 0b11);
531 }
532 bool IsIndAddPrev() const {
533 return indFoAdUtAl >> 2 & 0b1;
534 }
535 bool IsIndUtcLod() const {
536 return indFoAdUtAl >> 3 & 0b1;
537 }
538 GXIndTexAlphaSel GetIndAlphaSel() const {
539 return static_cast<GXIndTexAlphaSel>(indFoAdUtAl >> 4 & 0b11);
540 }
541};
542
543/******************************************************************************
544 *
545 * TevSwapMode
546 *
547 ******************************************************************************/
549 u8 swap; // at 0x0
550
551 void Set(GXTevColorChan r, GXTevColorChan g, GXTevColorChan b,
552 GXTevColorChan a) {
553
554 swap = r | g << 2 | b << 4 | a << 6;
555 }
556
557 GXTevColorChan GetR() const {
558 return static_cast<GXTevColorChan>(swap & 0b11);
559 }
560 GXTevColorChan GetG() const {
561 return static_cast<GXTevColorChan>(swap >> 2 & 0b11);
562 }
563 GXTevColorChan GetB() const {
564 return static_cast<GXTevColorChan>(swap >> 4 & 0b11);
565 }
566 GXTevColorChan GetA() const {
567 return static_cast<GXTevColorChan>(swap >> 6 & 0b11);
568 }
569};
570
571/******************************************************************************
572 *
573 * TexCoordGen
574 *
575 ******************************************************************************/
576struct TexCoordGen {
577 TexCoordGen() : reserve(0) {
578 Set(GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
579 }
580
581 void Set(GXTexGenType type, GXTexGenSrc src, ulong mtxID) {
582 texGenType = type;
583 texGenSrc = src;
584 texMtx = mtxID;
585 }
586
587 GXTexGenType GetTexGenType() const {
588 return static_cast<GXTexGenType>(texGenType);
589 }
590
591 GXTexGenSrc GetTexGenSrc() const {
592 return static_cast<GXTexGenSrc>(texGenSrc);
593 }
594
595 ulong GetTexMtx() const {
596 return texMtx;
597 }
598
599 u8 texGenType; // at 0x0
600 u8 texGenSrc; // at 0x1
601 u8 texMtx; // at 0x2
602 u8 reserve; // at 0x3
603};
604
605/******************************************************************************
606 *
607 * TexSRT
608 *
609 ******************************************************************************/
610struct TexSRT {
611 math::VEC2 translate; // at 0x0
612 f32 rotate; // at 0x8
613 math::VEC2 scale; // at 0xC
614};
615
616} // namespace lyt
617} // namespace nw4r
618
619#endif
2D graphics drawing library.