NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
g3d_obj.h
1#ifndef NW4R_G3D_OBJ_H
2#define NW4R_G3D_OBJ_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/g3d/g3d_rtti.h>
6#include <nw4r/g3d/platform/g3d_allocator.h>
7
8namespace nw4r {
9namespace g3d {
10namespace {
11
12/******************************************************************************
13 *
14 * Alignment
15 *
16 ******************************************************************************/
17inline ulong align4(ulong x) {
18 return ROUND_UP(x, 4);
19}
20inline ulong align32(ulong x) {
21 return ROUND_UP(x, 32);
22}
23
24} // namespace
25
26/******************************************************************************
27 *
28 * G3dObj
29 *
30 ******************************************************************************/
31class G3dObj {
32public:
33 template <ulong N> struct ResNameDataT {
34 ulong len; // at 0x0
35 // @bug 'N' already includes the null terminator
36 char str[ROUND_UP(N + 1, 4)]; // at 0x4
37 };
38
39 class TypeObj {
40 public:
42 ulong len; // at 0x0
43 char str[4]; // at 0x4
44 };
45
46 public:
47 template <ulong N>
48 explicit TypeObj(const ResNameDataT<N>& rName)
49 : mName(reinterpret_cast<const ResNameDataPT*>(&rName)) {}
50
51 ulong GetTypeID() const {
52 // @note Address is used for comparing TypeObjs
53 return reinterpret_cast<ulong>(mName);
54 }
55
56 const char* GetTypeName() const {
57 return mName->str;
58 }
59
60 bool operator==(const TypeObj& rOther) const {
61 return GetTypeID() == rOther.GetTypeID();
62 }
63
64 private:
65 const ResNameDataPT* mName; // at 0x0
66 };
67
68 enum G3dProcTask {
69 G3DPROC_NONE = 0x00000,
70
71 G3DPROC_CALC_WORLD = 0x00001,
72 G3DPROC_CALC_MAT = 0x00002,
73 G3DPROC_CALC_VTX = 0x00003,
74 G3DPROC_CALC_VIEW = 0x00004,
75 G3DPROC_GATHER_SCNOBJ = 0x00005,
76 G3DPROC_DRAW_OPA = 0x00006,
77 G3DPROC_DRAW_XLU = 0x00007,
78 G3DPROC_UPDATEFRAME = 0x00008,
79
80 // Tasks below cannot be disabled
81 __G3DPROC_OPTIONAL_END,
82
83 G3DPROC_CHILD_DETACHED = 0x10001,
84 G3DPROC_ATTACH_PARENT = 0x10002,
85 G3DPROC_DETACH_PARENT = 0x10003,
86 G3DPROC_ZSORT = 0x10004
87 };
88
89public:
90 virtual bool IsDerivedFrom(TypeObj other) const {
91 return other == GetTypeObjStatic();
92 } // at 0x8
93
94 virtual void G3dProc(ulong task, ulong param, void* pInfo) = 0; // at 0xC
95 virtual ~G3dObj(); // at 0x10
96
97 virtual const TypeObj GetTypeObj() const {
98 return TypeObj(TYPE_NAME);
99 } // at 0x14
100 static const G3dObj::TypeObj GetTypeObjStatic() {
101 return TypeObj(TYPE_NAME);
102 }
103 virtual const char* GetTypeName() const {
104 return GetTypeObj().GetTypeName();
105 } // at 0x18
106
107 G3dObj(MEMAllocator* pAllocator, G3dObj* pParent)
108 : mpHeap(pAllocator), mpParent(pParent) {}
109
110 G3dObj* GetParent() const {
111 return mpParent;
112 }
113 void SetParent(G3dObj* pParent) {
114 mpParent = pParent;
115 }
116 void DetachFromParent();
117
118 void Destroy();
119
120 static void* Alloc(MEMAllocator* pAllocator, ulong size) {
121 return detail::AllocFromAllocator(pAllocator, size);
122 }
123 static void Dealloc(MEMAllocator* pAllocator, void* pBlock) {
124 detail::FreeToAllocator(pAllocator, pBlock);
125 }
126
127 static inline void* operator new(size_t /* size */, void* pBlock) {
128 return pBlock;
129 }
130 static inline void operator delete(void* /* pBlock */) {}
131
132 template <typename TTo> static TTo* DynamicCast(G3dObj* pObj) {
133 if (pObj != NULL && pObj->IsDerivedFrom(TTo::GetTypeObjStatic())) {
134 return static_cast<TTo*>(pObj);
135 }
136 return NULL;
137 }
138
139private:
140 G3dObj* mpParent; // at 0x4
141 MEMAllocator* mpHeap; // at 0x8
142
143 __NW4R_G3D_TYPEOBJ_DECL(G3dObj);
144};
145
146} // namespace g3d
147} // namespace nw4r
148
149#endif
3D graphics drawing library.
Definition g3d_3dsmax.h:10