1#include <game/mLib/m_3d.hpp>
3#include <game/mLib/m_heap.hpp>
4#include <game/mLib/m_video.hpp>
5#include <lib/egg/gx/eggGfxEngine.hpp>
6#include <lib/egg/gx/eggStateGX.hpp>
7#include <lib/egg/gx/eggScreen.hpp>
8#include <lib/egg/gx/eggDrawGX.hpp>
9#include <lib/egg/gx/eggLightTexture.hpp>
10#include <lib/nw4r/g3d/g3d.hpp>
11#include <lib/nw4r/g3d/g3d_state.hpp>
12#include <lib/MSL_C/string.h>
16u32 m3d::internal::l_numLightMgr;
18u32 m3d::internal::l_numFogMgr;
21void m3d::initHio(
const char *name) {}
23bool m3d::create(
EGG::Heap *heap, ulong maxChildren, ulong maxScnObj, ulong numLightObj, ulong numLightSet) {
25 if (internal::l_allocator_p ==
nullptr) {
28 internal::l_allocator_p->attach(heap, 0x20);
30 nw4r::g3d::G3dInit(
true);
31 nw4r::g3d::G3DState::SetRenderModeObj(mVideo::m_video->mRenderModeObj);
34 internal::l_scnRoot_p = nw4r::g3d::ScnRoot::Construct(
35 internal::l_allocator_p, &size,
36 maxChildren, maxScnObj, numLightObj, numLightSet
40 if (internal::l_scnRoot_p ==
nullptr) {
41 delete internal::l_allocator_p;
42 internal::l_allocator_p =
nullptr;
49bool m3d::create(
EGG::Heap *heap, GXPixelFmt fmt,
GXColor col, ulong maxChildren, ulong maxScnObj,
50 ulong numLightObj, ulong numLightSet, ulong numLightMgr, ulong numFogMgr) {
51 if (internal::l_lightMgr_pp !=
nullptr && internal::l_fogMgr_pp !=
nullptr) {
56 u16 arg1[] = { cfg.x14, cfg.x16 };
57 u16 arg2[] = { cfg.x2, cfg.x2 };
58 EGG::StateGX::initialize(cfg.x0, cfg.x2, col, fmt);
59 EGG::Screen::Initialize(arg1, arg2,
nullptr);
60 EGG::Screen::SetTVModeDefault();
61 EGG::DrawGX::Initialize(heap);
62 EGG::LightTexture::initialize(0x20, heap);
65 if (internal::l_lightMgr_pp !=
nullptr) {
66 internal::l_numLightMgr = numLightMgr;
68 if (internal::l_fogMgr_pp !=
nullptr) {
69 internal::l_numFogMgr = numFogMgr;
72 memset(internal::l_lightMgr_pp, 0, numLightMgr *
sizeof(
void *));
73 memset(internal::l_fogMgr_pp, 0, numFogMgr *
sizeof(
void *));
75 if (create(heap, maxChildren, maxScnObj, numLightObj, numLightSet)) {
83 delete[] internal::l_lightMgr_pp;
84 internal::l_lightMgr_pp =
nullptr;
85 delete[] internal::l_fogMgr_pp;
86 internal::l_fogMgr_pp =
nullptr;
90bool m3d::createLightMgr(
EGG::Heap *heap, u16 lmArg1, u16 lmArg2, u8 lmArg3,
bool createFogMgr,
int idx) {
91 if (internal::l_lightMgr_pp ==
nullptr ||
94 idx < 0 || idx >= internal::l_numLightMgr || idx >= internal::l_numFogMgr ||
97 internal::l_lightMgr_pp[idx] !=
nullptr || internal::l_fogMgr_pp[idx] !=
nullptr) {
101 EGG::Heap *prevHeap = mHeap::setCurrentHeap(heap);
103 mHeap::setCurrentHeap(prevHeap);
107 if (!createFogMgr || m3d::createFogMgr(heap, 0x20, idx)) {
108 internal::l_lightMgr_pp[idx] = lm;
118void m3d::removeLightMgr(
int idx) {
124 if (mgrs !=
nullptr && mgrs[idx] !=
nullptr) {
126 if (mgrs[idx] !=
nullptr) {
132 for (
int i = 0; i < internal::l_numLightMgr; i++) {
133 if (mgrs[i] !=
nullptr) {
137 delete internal::l_lightMgr_pp;
138 internal::l_lightMgr_pp =
nullptr;
144bool m3d::createFogMgr(
EGG::Heap *heap,
int fmArg,
int idx) {
145 if (idx < 0 || idx >= internal::l_numFogMgr || internal::l_fogMgr_pp[idx] !=
nullptr) {
154 internal::l_fogMgr_pp[idx] = fm;
158void m3d::removeFogMgr(
int idx) {
160 if (mgrs ==
nullptr) {
165 if (mgrs[idx] !=
nullptr) {
167 if (mgrs[idx] !=
nullptr) {
172 for (
int i = 0; i < internal::l_numFogMgr; i++) {
173 if (mgrs[i] !=
nullptr) {
177 delete internal::l_fogMgr_pp;
178 internal::l_fogMgr_pp =
nullptr;
184 return internal::l_scnRoot_p;
188 return internal::l_scnRoot_p->GetCamera(idx);
192 return internal::l_scnRoot_p->GetCurrentCamera();
195int m3d::getCurrentCameraID() {
196 return internal::l_scnRoot_p->currCameraID;
199void m3d::setCurrentCamera(
int id) {
200 internal::l_scnRoot_p->SetCurrentCamera(
id);
204 return &internal::l_scnRoot_p->lightSetting;
208 return internal::l_lightMgr_pp[idx];
212 return internal::l_fogMgr_pp[idx];
215void m3d::drawDone(
int idx) {
216 if (internal::l_lightMgr_pp !=
nullptr && internal::l_lightMgr_pp[idx] !=
nullptr) {
217 internal::l_lightMgr_pp[idx]->DoneDraw();
220 if (internal::l_fogMgr_pp !=
nullptr && internal::l_fogMgr_pp[idx] !=
nullptr) {
221 internal::l_fogMgr_pp[idx]->DoneDraw();
225void m3d::drawLightMapTexture(
int idx) {
226 if (internal::l_lightMgr_pp !=
nullptr && internal::l_lightMgr_pp[idx] !=
nullptr) {
227 internal::l_lightMgr_pp[idx]->ltMgr->drawAndCaptureTexture(0, 0, 0, 0);
231bool m3d::replaceLightMapTexture(
char const *name,
m3d::bmdl_c &mdl,
int idx) {
232 if (internal::l_lightMgr_pp ==
nullptr) {
239 return ltm->replaceModelTexture(ltm->getTextureIndex(name), &mdlEx);
242void m3d::calcWorld(
int idx) {
243 if (internal::l_lightMgr_pp !=
nullptr && internal::l_lightMgr_pp[idx] !=
nullptr) {
244 internal::l_lightMgr_pp[idx]->Calc(internal::l_scnRoot_p);
246 if (internal::l_fogMgr_pp !=
nullptr && internal::l_fogMgr_pp[idx] !=
nullptr) {
247 internal::l_fogMgr_pp[idx]->Calc();
249 internal::l_scnRoot_p->CalcWorld();
252void m3d::calcMaterial() {
253 internal::l_scnRoot_p->CalcMaterial();
256void m3d::calcView(
int idx) {
257 if (internal::l_lightMgr_pp !=
nullptr && internal::l_lightMgr_pp[idx] !=
nullptr) {
260 cam.GetCameraMtx(&mtx);
262 internal::l_lightMgr_pp[idx]->CalcView(mtx, getCurrentCameraID(), internal::l_scnRoot_p);
265 if (internal::l_fogMgr_pp !=
nullptr && internal::l_fogMgr_pp[idx] !=
nullptr) {
266 internal::l_fogMgr_pp[idx]->CopyToG3D(internal::l_scnRoot_p);
269 internal::l_scnRoot_p->CalcView();
270 internal::l_scnRoot_p->GatherDrawScnObj();
271 internal::l_scnRoot_p->ZSort();
275 internal::l_scnRoot_p->DrawOpa();
279 internal::l_scnRoot_p->DrawXlu();
283 internal::l_scnRoot_p->Insert(internal::l_scnRoot_p->count, obj);
288 while (scnRoot->count != 0) {
289 scnRoot->Remove(scnRoot->count - 1);
294 nw4r::g3d::G3dReset();
295 if (internal::l_lightMgr_pp !=
nullptr || internal::l_fogMgr_pp !=
nullptr) {
296 EGG::StateGX::resetGXCache();
311 GXSetNumIndStages(0);
312 for (
int i = 0; i < GX_MAX_TEVSTAGE; i++) {
326bool m3d::proc_c::create(
mAllocator_c *allocator,
size_t *objSize) {
327 if (allocator ==
nullptr) {
328 allocator = internal::l_allocator_p;
332 if (objSize ==
nullptr) {
336 mpScn = nw4r::g3d::ScnProc::Construct(allocator, objSize, proc_c_drawProc,
true,
true, 0);
337 if (mpScn ==
nullptr) {
341 mpScn->SetPriorityDrawOpa(127);
342 mpScn->SetPriorityDrawXlu(127);
344 nw4r::g3d::ScnProc *p = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnProc>(mpScn);
An allocator class that wraps an EGG:Allocator .
struct _GXColor GXColor
A 32-bit RGBA color.
void resetMaterial()
Turns off all indirect texture processing.