NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
g3d_obj.hpp
1#pragma once
2#include <types.h>
3
4// See https://github.com/kiwi515/ogws/blob/3729af7dc7d92939be12b14f0af415b22ce5d0ee/include/nw4r/g3d/g3d_obj.h
5
6#define NW4R_G3D_TYPE_OBJ_DECL(className) \
7 static const nw4r::g3d::G3dObj::ResNameDataT<sizeof(#className)> TYPE_NAME; \
8 static const TypeObj GetTypeObjStatic() { return TypeObj(TYPE_NAME); }
9
10#define NW4R_G3D_TYPE_OBJ_DEF(className) \
11 const nw4r::g3d::G3dObj::ResNameDataT<sizeof(#className)> className::TYPE_NAME = {sizeof(#className), #className}
12
13namespace nw4r {
14namespace g3d {
15
16class G3dObj {
17public:
18
19 template <u32 N>
20 struct ResNameDataT {
21 u32 mLength;
22 // Bug? +1 seemingly for null terminator,
23 // but size N already includes it
24 char mName[N + 1 + 3 & ~3];
25 };
26
27 struct TypeObj {
28 struct TypeObjData {
29 u32 mLength;
30 char mName[];
31 };
32
33 template <u32 N>
34 TypeObj(const ResNameDataT<N>& pRes) : mData((const TypeObjData *)&pRes) {}
35
36 const TypeObjData *GetTypeObj() const { return mData; }
37 const TypeObjData *mData;
38 };
39
40 /// @brief The possible G3D process operations.
41 enum G3dProcOp {
42 G3DPROC_CALC_WORLD = 1, ///< Calculates the world transform matrix.
43 G3DPROC_CALC_MAT, ///< Calculates the material settings.
44 G3DPROC_CALC_VTX, ///< Performs vertex array calculations.
45
46 /// @brief Calculates the view transform matrix.
47 /// @details A pointer to the camera matrix (MTX34) must be passed to the processing function.
49
50 G3DPROC_GATHER_SCNOBJ, ///< Gathers the ScnObj to be rendered.
51 G3DPROC_DRAW_OPA, ///< Draws the material specified as OPA.
52 G3DPROC_DRAW_XLU, ///< Draws the material specified as XLU.
53 G3DPROC_UPDATEFRAME, ///< Calls the UpdateFrame member function for all animation objects.
54
55 G3DPROC_CHILD_DETACHED = 0x00010001, ///< The child is about to be detached.
56 G3DPROC_ATTACHED, ///< A parent has been attached.
57 G3DPROC_DETACHED, ///< The child has been detached from the parent.
58 G3DPROC_SORT, ///< Sorts the gathered ScnObj.
59 };
60
61 /// @brief Additional parameters for G3D process operations.
63
64 /// @brief Will not update the world conversion matrix of the ScnObj
66
67 G3DPROCPARAM_SORT_ZSORT = BIT_FLAG(-1), ///< Use ScnRoot::ZSort() for sorting.
68 G3DPROCPARAM_SORT_SORT = BIT_FLAG(0), ///< Use ScnRoot::Sort() for sorting.
69 G3DPROCPARAM_SORT_SORT_WITHFUNC = BIT_FLAG(1), ///< Use ScnRoot::Sort(FuncLess, FuncLess) for sorting.
70 };
71
72 virtual bool IsDerivedFrom(G3dObj::TypeObj) const;
73 virtual void G3dProc(ulong proc, ulong param, void *info) = 0;
74 virtual ~G3dObj();
75 virtual const TypeObj GetTypeObj();
76 virtual const char *GetTypeName();
77
78 void Destroy();
79 void DetachFromParent();
80
81 template <typename DerivedType, typename Type>
82 static inline DerivedType *DynamicCast(Type *obj) {
83 if (obj != nullptr && obj->IsDerivedFrom(DerivedType::GetTypeObjStatic())) {
84 return (DerivedType*) (obj);
85 }
86 return nullptr;
87 }
88
89 private:
90 NW4R_G3D_TYPE_OBJ_DECL(G3dObj);
91};
92
93} // namespace g3d
94} // namespace nw4r
G3dProcParam
Additional parameters for G3D process operations.
Definition g3d_obj.hpp:62
@ G3DPROCPARAM_SORT_ZSORT
Use ScnRoot::ZSort() for sorting.
Definition g3d_obj.hpp:67
@ G3DPROCPARAM_SORT_SORT
Use ScnRoot::Sort() for sorting.
Definition g3d_obj.hpp:68
@ G3DPROCPARAM_SORT_SORT_WITHFUNC
Use ScnRoot::Sort(FuncLess, FuncLess) for sorting.
Definition g3d_obj.hpp:69
@ G3DPROCPARAM_CALC_WORLD_SCNOBJMTX_NOUPDATE
Will not update the world conversion matrix of the ScnObj.
Definition g3d_obj.hpp:65
G3dProcOp
The possible G3D process operations.
Definition g3d_obj.hpp:41
@ G3DPROC_CALC_VTX
Performs vertex array calculations.
Definition g3d_obj.hpp:44
@ G3DPROC_CHILD_DETACHED
The child is about to be detached.
Definition g3d_obj.hpp:55
@ G3DPROC_CALC_WORLD
Calculates the world transform matrix.
Definition g3d_obj.hpp:42
@ G3DPROC_GATHER_SCNOBJ
Gathers the ScnObj to be rendered.
Definition g3d_obj.hpp:50
@ G3DPROC_DRAW_OPA
Draws the material specified as OPA.
Definition g3d_obj.hpp:51
@ G3DPROC_CALC_VIEW
Calculates the view transform matrix.
Definition g3d_obj.hpp:48
@ G3DPROC_SORT
Sorts the gathered ScnObj.
Definition g3d_obj.hpp:58
@ G3DPROC_DETACHED
The child has been detached from the parent.
Definition g3d_obj.hpp:57
@ G3DPROC_ATTACHED
A parent has been attached.
Definition g3d_obj.hpp:56
@ G3DPROC_UPDATEFRAME
Calls the UpdateFrame member function for all animation objects.
Definition g3d_obj.hpp:53
@ G3DPROC_CALC_MAT
Calculates the material settings.
Definition g3d_obj.hpp:43
@ G3DPROC_DRAW_XLU
Draws the material specified as XLU.
Definition g3d_obj.hpp:52
3D graphics drawing library.
Definition docgroup.h:10