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/gfxe/eggGfxEngine.h>
6#include <lib/egg/gfxe/eggStateGX.h>
7#include <lib/egg/gfxe/eggScreen.h>
8#include <lib/egg/gfxe/eggDrawGX.h>
9#include <lib/egg/gfxe/eggLightTexture.h>
15u32 m3d::internal::l_numLightMgr;
17u32 m3d::internal::l_numFogMgr;
20void m3d::initHio(
const char *name) {}
22bool m3d::create(
EGG::Heap *heap, ulong maxChildren, ulong maxScnObj, ulong numLightObj, ulong numLightSet) {
24 if (internal::l_allocator_p ==
nullptr) {
27 internal::l_allocator_p->attach(heap, 0x20);
29 nw4r::g3d::G3dInit(
true);
30 nw4r::g3d::G3DState::SetRenderModeObj(mVideo::m_video->mRenderModeObj);
33 internal::l_scnRoot_p = nw4r::g3d::ScnRoot::Construct(
34 internal::l_allocator_p, &size,
35 maxChildren, maxScnObj, numLightObj, numLightSet
39 if (internal::l_scnRoot_p ==
nullptr) {
40 delete internal::l_allocator_p;
41 internal::l_allocator_p =
nullptr;
48bool m3d::create(
EGG::Heap *heap, GXPixelFmt fmt, GXColor col, ulong maxChildren, ulong maxScnObj,
49 ulong numLightObj, ulong numLightSet, ulong numLightMgr, ulong numFogMgr) {
50 if (internal::l_lightMgr_pp !=
nullptr && internal::l_fogMgr_pp !=
nullptr) {
55 u16 arg1[] = { cfg.x14, cfg.x16 };
56 u16 arg2[] = { cfg.x2, cfg.x2 };
57 EGG::StateGX::initialize(cfg.x0, cfg.x2, col, fmt);
58 EGG::Screen::Initialize(arg1, arg2,
nullptr);
59 EGG::Screen::SetTVModeDefault();
60 EGG::DrawGX::Initialize(heap);
61 EGG::LightTexture::initialize(0x20, heap);
64 if (internal::l_lightMgr_pp !=
nullptr) {
65 internal::l_numLightMgr = numLightMgr;
67 if (internal::l_fogMgr_pp !=
nullptr) {
68 internal::l_numFogMgr = numFogMgr;
71 memset(internal::l_lightMgr_pp, 0, numLightMgr *
sizeof(
void *));
72 memset(internal::l_fogMgr_pp, 0, numFogMgr *
sizeof(
void *));
74 if (create(heap, maxChildren, maxScnObj, numLightObj, numLightSet)) {
82 delete[] internal::l_lightMgr_pp;
83 internal::l_lightMgr_pp =
nullptr;
84 delete[] internal::l_fogMgr_pp;
85 internal::l_fogMgr_pp =
nullptr;
89bool m3d::createLightMgr(
EGG::Heap *heap, u16 lmArg1, u16 lmArg2, u8 lmArg3,
bool createFogMgr,
int idx) {
90 if (internal::l_lightMgr_pp ==
nullptr ||
93 idx < 0 || idx >= internal::l_numLightMgr || idx >= internal::l_numFogMgr ||
96 internal::l_lightMgr_pp[idx] !=
nullptr || internal::l_fogMgr_pp[idx] !=
nullptr) {
100 EGG::Heap *prevHeap = mHeap::setCurrentHeap(heap);
102 mHeap::setCurrentHeap(prevHeap);
106 if (!createFogMgr || m3d::createFogMgr(heap, 0x20, idx)) {
107 internal::l_lightMgr_pp[idx] = lm;
117void m3d::removeLightMgr(
int idx) {
123 if (mgrs !=
nullptr && mgrs[idx] !=
nullptr) {
125 if (mgrs[idx] !=
nullptr) {
131 for (
int i = 0; i < internal::l_numLightMgr; i++) {
132 if (mgrs[i] !=
nullptr) {
136 delete internal::l_lightMgr_pp;
137 internal::l_lightMgr_pp =
nullptr;
143bool m3d::createFogMgr(
EGG::Heap *heap,
int fmArg,
int idx) {
144 if (idx < 0 || idx >= internal::l_numFogMgr || internal::l_fogMgr_pp[idx] !=
nullptr) {
153 internal::l_fogMgr_pp[idx] = fm;
157void m3d::removeFogMgr(
int idx) {
159 if (mgrs ==
nullptr) {
164 if (mgrs[idx] !=
nullptr) {
166 if (mgrs[idx] !=
nullptr) {
171 for (
int i = 0; i < internal::l_numFogMgr; i++) {
172 if (mgrs[i] !=
nullptr) {
176 delete internal::l_fogMgr_pp;
177 internal::l_fogMgr_pp =
nullptr;
183 return internal::l_scnRoot_p;
187 return internal::l_scnRoot_p->GetCamera(idx);
191 return internal::l_scnRoot_p->GetCurrentCamera();
194int m3d::getCurrentCameraID() {
195 return internal::l_scnRoot_p->GetCurrentCameraID();
198void m3d::setCurrentCamera(
int id) {
199 internal::l_scnRoot_p->SetCurrentCamera(
id);
203 return &internal::l_scnRoot_p->GetLightSetting();
207 return internal::l_lightMgr_pp[idx];
211 return internal::l_fogMgr_pp[idx];
214void m3d::drawDone(
int idx) {
215 if (internal::l_lightMgr_pp !=
nullptr && internal::l_lightMgr_pp[idx] !=
nullptr) {
216 internal::l_lightMgr_pp[idx]->DoneDraw();
219 if (internal::l_fogMgr_pp !=
nullptr && internal::l_fogMgr_pp[idx] !=
nullptr) {
220 internal::l_fogMgr_pp[idx]->DoneDraw();
224void m3d::drawLightMapTexture(
int idx) {
225 if (internal::l_lightMgr_pp !=
nullptr && internal::l_lightMgr_pp[idx] !=
nullptr) {
226 internal::l_lightMgr_pp[idx]->ltMgr->drawAndCaptureTexture(0, 0, 0, 0);
230bool m3d::replaceLightMapTexture(
char const *name,
m3d::bmdl_c &mdl,
int idx) {
231 if (internal::l_lightMgr_pp ==
nullptr) {
238 return ltm->replaceModelTexture(ltm->getTextureIndex(name), &mdlEx);
241void m3d::calcWorld(
int idx) {
242 if (internal::l_lightMgr_pp !=
nullptr && internal::l_lightMgr_pp[idx] !=
nullptr) {
243 internal::l_lightMgr_pp[idx]->Calc(internal::l_scnRoot_p);
245 if (internal::l_fogMgr_pp !=
nullptr && internal::l_fogMgr_pp[idx] !=
nullptr) {
246 internal::l_fogMgr_pp[idx]->Calc();
248 internal::l_scnRoot_p->CalcWorld();
251void m3d::calcMaterial() {
252 internal::l_scnRoot_p->CalcMaterial();
255void m3d::calcView(
int idx) {
256 if (internal::l_lightMgr_pp !=
nullptr && internal::l_lightMgr_pp[idx] !=
nullptr) {
259 cam.GetCameraMtx(&mtx);
261 internal::l_lightMgr_pp[idx]->CalcView(mtx, getCurrentCameraID(), internal::l_scnRoot_p);
264 if (internal::l_fogMgr_pp !=
nullptr && internal::l_fogMgr_pp[idx] !=
nullptr) {
265 internal::l_fogMgr_pp[idx]->CopyToG3D(internal::l_scnRoot_p);
268 internal::l_scnRoot_p->CalcView();
269 internal::l_scnRoot_p->GatherDrawScnObj();
270 internal::l_scnRoot_p->ZSort();
274 internal::l_scnRoot_p->DrawOpa();
278 internal::l_scnRoot_p->DrawXlu();
282 internal::l_scnRoot_p->PushBack(obj);
287 while (scnRoot->Size() != 0) {
288 scnRoot->Remove(scnRoot->Size() - 1);
293 nw4r::g3d::G3dReset();
294 if (internal::l_lightMgr_pp !=
nullptr || internal::l_fogMgr_pp !=
nullptr) {
295 EGG::StateGX::resetGXCache();
310 GXSetNumIndStages(0);
311 for (
int i = 0; i < GX_MAX_TEVSTAGE; i++) {
312 GXSetTevDirect((GXTevStageID) i);
325bool m3d::proc_c::create(
mAllocator_c *allocator,
size_t *objSize) {
326 if (allocator ==
nullptr) {
327 allocator = internal::l_allocator_p;
331 if (objSize ==
nullptr) {
335 mpScn = nw4r::g3d::ScnProc::Construct(allocator, objSize, proc_c_drawProc,
true,
true, 0);
336 if (mpScn ==
nullptr) {
340 mpScn->SetPriorityDrawOpa(127);
341 mpScn->SetPriorityDrawXlu(127);
343 nw4r::g3d::ScnProc *p = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnProc>(mpScn);
344 p->SetUserData(
this);
An allocator class that wraps an EGG:Allocator .
void resetMaterial()
Turns off all indirect texture processing.