diff --git a/include/JSystem/J3DGraphAnimator/J3DAnimation.h b/include/JSystem/J3DGraphAnimator/J3DAnimation.h index 20247455c..8fb43249f 100644 --- a/include/JSystem/J3DGraphAnimator/J3DAnimation.h +++ b/include/JSystem/J3DGraphAnimator/J3DAnimation.h @@ -367,6 +367,7 @@ public: u16 getUpdateMaterialID(u16 idx) const { return mUpdateMaterialID[idx]; } u16 getUpdateMaterialNum() const { return mTrackNum / 3; } + JUTNameTab * getUpdateMaterialName() { return &mMaterialName; } u16 getUpdateTexMtxID(u16 idx) const { return mUpdateTexMtxID[idx]; } u32 getTexMtxCalcType() const { return mTexMtxCalcType; } diff --git a/include/d/d_com_inf_game.h b/include/d/d_com_inf_game.h index 9060946cd..b45da38e6 100644 --- a/include/d/d_com_inf_game.h +++ b/include/d/d_com_inf_game.h @@ -188,7 +188,7 @@ public: /* 0x04 */ s32 mTimerNowTimeMs; /* 0x08 */ s32 mTimerLimitTimeMs; /* 0x0C */ s32 mTimerMode; - /* 0x10 */ u8 mTimerType; + /* 0x10 */ u16 mTimerType; }; class dADM_CharTbl : public cDT { @@ -1262,6 +1262,7 @@ BOOL dComIfGs_checkSeaLandingEvent(s8 i_roomNo); void dComIfGp_setNextStage(const char* i_stageName, s16 i_point, s8 i_roomNo, s8 i_layer, f32 i_lastSpeed, u32 i_lastMode, int, s8 i_wipe); dStage_Ship_data* dComIfGp_getShip(int i_roomNo, int param_1); +bool dComIfGp_getMapTrans(int i_roomNo, f32* o_transX, f32* o_transY, s16* o_angle); inline camera_class* dComIfGp_getCamera(int idx) { return g_dComIfG_gameInfo.play.getCamera(idx); @@ -1407,6 +1408,10 @@ inline dBgW* dComIfGp_roomControl_getBgW(int i_roomNo) { return dStage_roomControl_c::getBgW(i_roomNo); } +inline void dComIfGp_roomControl_setBgW(int i_roomNo, dBgW * i_bgw) { + dStage_roomControl_c::setBgW(i_roomNo, i_bgw); +} + inline s32 dComIfGp_roomControl_getZoneNo(int i_roomNo) { return dStage_roomControl_c::getZoneNo(i_roomNo); } @@ -1415,6 +1420,10 @@ inline void dComIfGp_roomControl_setZoneNo(int i_roomNo, int i_zoneNo) { dStage_roomControl_c::setZoneNo(i_roomNo, i_zoneNo); } +inline dKy_tevstr_c* dComIfGp_roomControl_getTevStr(int room_no) { + return g_dComIfG_gameInfo.play.getRoomControl()->getTevStr(room_no); +} + inline void dComIfGp_roomControl_init() { g_dComIfG_gameInfo.play.getRoomControl()->init(); } @@ -1435,6 +1444,14 @@ inline void dComIfGp_roomControl_setStatusFlag(int i_roomNo, u8 i_flag) { g_dComIfG_gameInfo.play.getRoomControl()->setStatusFlag(i_roomNo, i_flag); } +inline void dComIfGp_roomControl_onStatusFlag(int i_roomNo, u8 i_flag) { + g_dComIfG_gameInfo.play.getRoomControl()->onStatusFlag(i_roomNo, i_flag); +} + +inline void dComIfGp_roomControl_offStatusFlag(int i_roomNo, u8 i_flag) { + g_dComIfG_gameInfo.play.getRoomControl()->offStatusFlag(i_roomNo, i_flag); +} + inline BOOL dComIfGp_roomControl_checkStatusFlag(int i_roomNo, u8 i_flag) { return g_dComIfG_gameInfo.play.getRoomControl()->checkStatusFlag(i_roomNo, i_flag); } diff --git a/include/d/d_flower.h b/include/d/d_flower.h index bbf4388df..77462b5ad 100644 --- a/include/d/d_flower.h +++ b/include/d/d_flower.h @@ -54,6 +54,7 @@ public: void newData(s8, cXyz&, int, s8); void newAnm(); void setAnm(int, s16); + void deleteRoom(s32 roomNo) { mRoom[roomNo].deleteData(); } virtual void draw(); virtual ~dFlower_packet_c(); diff --git a/include/d/d_grass.h b/include/d/d_grass.h index 83863f999..eaa79f329 100644 --- a/include/d/d_grass.h +++ b/include/d/d_grass.h @@ -57,6 +57,7 @@ public: void newData(cXyz&, int, s8); void newAnm(); void setAnm(int, s16); + void deleteRoom(s32 roomNo) { mGrassRoom[roomNo].deleteData(); } virtual void draw(); virtual ~dGrass_packet_c(); diff --git a/include/d/d_magma.h b/include/d/d_magma.h index 3219cc8dd..e13f876da 100644 --- a/include/d/d_magma.h +++ b/include/d/d_magma.h @@ -47,6 +47,7 @@ public: void update(); void checkYpos(cXyz&); void newFloor(cXyz&, cXyz&, int, s16); + void deleteRoom(s32 roomNo) { mRoom[roomNo].deleteFloor(); } virtual void draw(); virtual ~dMagma_packet_c(); diff --git a/include/d/d_tree.h b/include/d/d_tree.h index 50fd94765..5e71fc140 100644 --- a/include/d/d_tree.h +++ b/include/d/d_tree.h @@ -70,6 +70,7 @@ public: void newData(cXyz&, u8, int); void newAnm(s16); void setAnm(int, s16); + void deleteRoom(s32 roomNo) { mRoom[roomNo].deleteData(); } virtual void draw(); virtual ~dTree_packet_c(); diff --git a/include/m_Do/m_Do_lib.h b/include/m_Do/m_Do_lib.h index 0a397ee14..436208f96 100644 --- a/include/m_Do/m_Do_lib.h +++ b/include/m_Do/m_Do_lib.h @@ -22,7 +22,9 @@ struct mDoLib_clipper { return mClipper.clip(m, center, radius); } - static s32 clip(J3DModel*); + static s32 clip(J3DModel* model) { + return mClipper.clipByBox(model); + } static f32 getFar() { return mSystemFar; } static f32 getFovyRate() { return mFovyRate; } diff --git a/src/d/actor/d_a_bg.cpp b/src/d/actor/d_a_bg.cpp index 4a2d7a2ac..75b6fde26 100644 --- a/src/d/actor/d_a_bg.cpp +++ b/src/d/actor/d_a_bg.cpp @@ -3,91 +3,462 @@ // Translation Unit: d_a_bg.cpp // -#include "d_a_bg.h" -#include "dolphin/types.h" +#include "f_op/f_op_actor_mng.h" +#include "d/d_com_inf_game.h" +#include "d/d_procname.h" +#include "d/d_magma.h" +#include "d/d_grass.h" +#include "d/d_tree.h" +#include "d/d_wood.h" +#include "d/d_flower.h" +#include "m_Do/m_Do_ext.h" +#include "m_Do/m_Do_graphic.h" +#include "m_Do/m_Do_lib.h" +#include "m_Do/m_Do_mtx.h" +#include "SSystem/SComponent/c_lib.h" +#include "JSystem/JKernel/JKRExpHeap.h" +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JKernel/JKRSolidHeap.h" +#include "JSystem/JUtility/JUTAssert.h" + +class daBg_btkAnm_c { +public: + BOOL create(J3DModelData*, J3DAnmTextureSRTKey*); + void entry(J3DModelData*); + void play(); + +public: + /* 0x00 */ mDoExt_btkAnm * anm; + /* 0x04 */ u8 special; +}; + +class daBg_brkAnm_c { +public: + BOOL create(J3DModelData*, J3DAnmTevRegKey*); + void entry(J3DModelData*); + void play(); + +public: + /* 0x00 */ mDoExt_brkAnm * anm; + /* 0x04 */ u8 special; +}; + +class daBg_c : public fopAc_ac_c { +public: + ~daBg_c(); + const char * setArcName(); + BOOL createHeap(); + s32 create(); + inline BOOL execute(); + inline BOOL draw(); + inline BOOL isDelete(); + +public: + /* 0x290 */ request_of_phase_process_class mPhs; + /* 0x298 */ struct BgModel { + J3DModel * model; + daBg_btkAnm_c * btk; + daBg_brkAnm_c * brk; + dKy_tevstr_c * mpTevStr; + } bg[4]; + /* 0x2D8 */ dBgW * bgw; + /* 0x2DC */ u8 mUnloadTimer; +}; /* 800D8434-800D8478 .text setArcName__6daBg_cFv */ -void daBg_c::setArcName() { - /* Nonmatching */ +const char* daBg_c::setArcName() { + static char arcName[32]; + sprintf(arcName, "Room%d", fopAcM_GetParam(this)); + return arcName; } /* 800D8478-800D8514 .text createMatAnm__FP12J3DModelDataUs */ -void createMatAnm(J3DModelData*, unsigned short) { - /* Nonmatching */ +BOOL createMatAnm(J3DModelData* modelData, u16 mat_no) { + if (mat_no != 0xFFFF) { + J3DMaterial * mat = modelData->getMaterialNodePointer(mat_no); + if (mat->getMaterialAnm() == NULL) { + J3DMaterialAnm * anm = new J3DMaterialAnm(); + if (anm == NULL) + return FALSE; + mat->setMaterialAnm(anm); + } + } + + return TRUE; } /* 800D8514-800D862C .text create__13daBg_btkAnm_cFP12J3DModelDataP19J3DAnmTextureSRTKey */ -void daBg_btkAnm_c::create(J3DModelData*, J3DAnmTextureSRTKey*) { - /* Nonmatching */ +BOOL daBg_btkAnm_c::create(J3DModelData* modelData, J3DAnmTextureSRTKey* anmData) { + anm = new mDoExt_btkAnm(); + if (anm == NULL) + return FALSE; + + if (!anm->init(modelData, anmData, true, J3DFrameCtrl::LOOP_REPEAT_e, 1.0f, 0, -1, false, 0)) + return FALSE; + + // probably an inline + J3DAnmTextureSRTKey * data = anm->getBtkAnm(); + for (u16 i = 0; i < data->getUpdateMaterialNum(); i++) { + u16 mat_no = data->getUpdateMaterialID(i); + if (!createMatAnm(modelData, mat_no)) + return FALSE; + } + + return TRUE; } /* 800D862C-800D86C4 .text entry__13daBg_btkAnm_cFP12J3DModelData */ -void daBg_btkAnm_c::entry(J3DModelData*) { - /* Nonmatching */ +void daBg_btkAnm_c::entry(J3DModelData* modelData) { + anm->entry(modelData, 0.0f); + + const char * name = anm->getBtkAnm()->getUpdateMaterialName()->getName(0); + if (name[0] == 'S' && name[1] == 'C' && name[2] == '_' && name[3] == '0' && name[4] == '1') + special = 1; + else + special = 0; } /* 800D86C4-800D8728 .text play__13daBg_btkAnm_cFv */ void daBg_btkAnm_c::play() { - /* Nonmatching */ + if (special == 1) { + anm->setFrame(g_dComIfG_gameInfo.play.mTimerInfo.mTimerType); + } else { + anm->play(); + } } /* 800D8728-800D8878 .text create__13daBg_brkAnm_cFP12J3DModelDataP15J3DAnmTevRegKey */ -void daBg_brkAnm_c::create(J3DModelData*, J3DAnmTevRegKey*) { - /* Nonmatching */ +BOOL daBg_brkAnm_c::create(J3DModelData* modelData, J3DAnmTevRegKey* anmData) { + anm = new mDoExt_brkAnm(); + if (anm == NULL) + return FALSE; + + if (!anm->init(modelData, anmData, true, J3DFrameCtrl::LOOP_REPEAT_e, 1.0f, 0, -1, false, 0)) + return FALSE; + + // probably an inline + J3DAnmTevRegKey * data = anm->getBrkAnm(); + for (u16 i = 0; i < data->getCRegUpdateMaterialNum(); i++) { + u16 mat_no = data->getCRegUpdateMaterialID(i); + if (!createMatAnm(modelData, mat_no)) + return FALSE; + } + + for (u16 i = 0; i < data->getKRegUpdateMaterialNum(); i++) { + u16 mat_no = data->getKRegUpdateMaterialID(i); + if (!createMatAnm(modelData, mat_no)) + return FALSE; + } + + return TRUE; } /* 800D8878-800D88B4 .text entry__13daBg_brkAnm_cFP12J3DModelData */ -void daBg_brkAnm_c::entry(J3DModelData*) { - /* Nonmatching */ +void daBg_brkAnm_c::entry(J3DModelData* modelData) { + anm->entry(modelData, 0.0f); + special = 0; } /* 800D88B4-800D88D8 .text play__13daBg_brkAnm_cFv */ void daBg_brkAnm_c::play() { - /* Nonmatching */ + anm->play(); } /* 800D88D8-800D88F8 .text checkCreateHeap__FP10fopAc_ac_c */ -void checkCreateHeap(fopAc_ac_c*) { - /* Nonmatching */ +BOOL checkCreateHeap(fopAc_ac_c* i_ac) { + return ((daBg_c*)i_ac)->createHeap(); } /* 800D88F8-800D8C50 .text createHeap__6daBg_cFv */ -void daBg_c::createHeap() { - /* Nonmatching */ +BOOL daBg_c::createHeap() { + /* Nonmatching - array loads */ + static char l_modelName[4][13] = { + "model.bmd", + "model1.bmd", + "model2.bmd", + "model3.bmd", + }; + static char l_modelName2[4][13] = { + "model.bdl", + "model1.bdl", + "model2.bdl", + "model3.bdl", + }; + static char l_btkName[4][13] = { + "model.btk", + "model1.btk", + "model2.btk", + "model3.btk", + }; + static char l_brkName[4][13] = { + "model.brk", + "model1.brk", + "model2.brk", + "model3.brk", + }; + + const char * arcName = setArcName(); + u32 roomNo = fopAcM_GetParam(this); + + for (u32 i = 0; i < 4; i++) { + BgModel * bgm = &bg[i]; + + J3DModelData * modelData = (J3DModelData *) dComIfG_getStageRes(arcName, l_modelName[i]); + if (modelData == NULL) + modelData = (J3DModelData *) dComIfG_getStageRes(arcName, l_modelName2[i]); + if (modelData == NULL) + continue; + + u32 diffFlag = 0x11000022; + + for (u16 mat_no = 0; mat_no < modelData->getMaterialNum(); mat_no++) + modelData->getMaterialNodePointer(mat_no)->setMaterialAnm(NULL); + + J3DAnmTextureSRTKey * btk = (J3DAnmTextureSRTKey *) dComIfG_getStageRes(arcName, l_btkName[i]); + if (btk != NULL) { + bgm->btk = new daBg_btkAnm_c(); + if (bgm->btk == NULL) + return FALSE; + if (!bgm->btk->create(modelData, btk)) + return FALSE; + diffFlag = 0x12000000; + } else { + bgm->btk = NULL; + } + + J3DAnmTevRegKey * brk = (J3DAnmTevRegKey *) dComIfG_getStageRes(arcName, l_brkName[i]); + if (brk != NULL) { + bgm->brk = new daBg_brkAnm_c(); + if (bgm->brk == NULL) + return FALSE; + if (!bgm->brk->create(modelData, brk)) + return FALSE; + } else { + bgm->brk = NULL; + } + + bgm->model = mDoExt_J3DModel__create(modelData, 0, diffFlag); + if (bgm->model == NULL) + return FALSE; + bgm->mpTevStr = new dKy_tevstr_c(); + if (bgm->mpTevStr == NULL) + return FALSE; + dKy_tevstr_init(bgm->mpTevStr, roomNo, 0xFF); + } + + cBgD_t * dzb = (cBgD_t *) dComIfG_getStageRes(arcName, "room.dzb"); + if (dzb != NULL) { + bgw = new dBgW(); + if (bgw == NULL) + return FALSE; + if (bgw->Set(dzb, cBgW::GLOBAL_e, NULL)) + return FALSE; + dComIfGp_roomControl_setBgW(roomNo, bgw); + bgw->mWallCorrectPriority = 0; + } else { + bgw = NULL; + } + + return TRUE; } /* 800D8C50-800D8DB8 .text __dt__6daBg_cFv */ daBg_c::~daBg_c() { - /* Nonmatching */ + s32 roomNo = fopAcM_GetParam(this); + + if (heap != NULL && bgw != NULL) { + dComIfG_Bgsp()->Release(bgw); + dComIfGp_roomControl_setBgW(roomNo, NULL); + } + if (dComIfGp_getMagma() != NULL) + dComIfGp_getMagma()->deleteRoom(roomNo); + if (dComIfGp_getGrass() != NULL) + dComIfGp_getGrass()->deleteRoom(roomNo); + if (dComIfGp_getTree() != NULL) + dComIfGp_getTree()->deleteRoom(roomNo); + if (dComIfGp_getWood() != NULL) + dComIfGp_getWood()->delete_room(roomNo); + if (dComIfGp_getFlower() != NULL) + dComIfGp_getFlower()->deleteRoom(roomNo); + + dComIfGp_roomControl_offStatusFlag(roomNo, 0x10); +} + +BOOL daBg_c::draw() { + s32 roomNo = fopAcM_GetParam(this); + BgModel * bgm = &bg[0]; + J3DModel * model; + + dComIfGd_setListBG(); + mDoLib_clipper::changeFar(100000.0f); + + for (s32 i = 0; i < 4; i++, bgm++) { + model = bgm->model; + if (model == NULL) + continue; + + if (bgm->btk != NULL) + bgm->btk->anm->entryFrame(); + if (bgm->brk != NULL) + bgm->brk->anm->entryFrame(); + model->calc(); + mDoLib_clipper::clip(model); + g_env_light.settingTevStruct(TEV_TYPE_BG0 + i, NULL, bgm->mpTevStr); + g_env_light.setLightTevColorType(model, bgm->mpTevStr); + mDoExt_modelEntryDL(model); + } + + mDoLib_clipper::resetFar(); + dComIfGd_setList(); + g_env_light.settingTevStruct(TEV_TYPE_BG0, NULL, dComIfGp_roomControl_getTevStr(roomNo)); + return TRUE; } /* 800D8DB8-800D8F34 .text daBg_Draw__FP6daBg_c */ -void daBg_Draw(daBg_c*) { - /* Nonmatching */ +BOOL daBg_Draw(daBg_c* i_this) { + return i_this->draw(); +} + +BOOL daBg_c::execute() { + if (mUnloadTimer != 0) { + if (cLib_calcTimer(&mUnloadTimer) == 0) + fopAcM_delete(this); + + return TRUE; + } + + if (dComIfGp_roomControl_checkStatusFlag(fopAcM_GetParam(this), 0x04)) { + if (strcmp(dComIfGp_getStartStageName(), "sea") == 0) + mUnloadTimer = 16; + else + mUnloadTimer = 1; + } else { + BgModel * bgm = &bg[0]; + for (s32 i = 0; i < 4; i++, bgm++) { + if (!mDoGph_gInf_c::isMonotone() || i == 2) { + if (bgm->btk != NULL) + bgm->btk->play(); + if (bgm->brk != NULL) + bgm->brk->play(); + } + } + } + + return TRUE; } /* 800D8F34-800D903C .text daBg_Execute__FP6daBg_c */ -void daBg_Execute(daBg_c*) { - /* Nonmatching */ +BOOL daBg_Execute(daBg_c* i_this) { + return i_this->execute(); +} + +BOOL daBg_c::isDelete() { + if (mUnloadTimer == 0) + return TRUE; + else + return FALSE; } /* 800D903C-800D904C .text daBg_IsDelete__FP6daBg_c */ -void daBg_IsDelete(daBg_c*) { - /* Nonmatching */ +BOOL daBg_IsDelete(daBg_c* i_this) { + return i_this->isDelete(); } /* 800D904C-800D9074 .text daBg_Delete__FP6daBg_c */ -void daBg_Delete(daBg_c*) { - /* Nonmatching */ +BOOL daBg_Delete(daBg_c* i_this) { + i_this->~daBg_c(); + return TRUE; } /* 800D9074-800D9094 .text daBg_Create__FP10fopAc_ac_c */ -void daBg_Create(fopAc_ac_c*) { - /* Nonmatching */ +s32 daBg_Create(fopAc_ac_c* i_ac) { + return ((daBg_c*)i_ac)->create(); } +// searchRoomMemory__Fi d_a_bg.o +// searchRoomNo__FiP10readRoom_c d_a_bg.o +// getRoomMemory__6daBg_cFi d_a_bg.o +// initRoomMemory__6daBg_cFv d_a_bg.o +// calcRoomMemory__6daBg_cFPPcPlPPcPl d_a_bg.o + /* 800D9094-800D9318 .text create__6daBg_cFv */ -void daBg_c::create() { - /* Nonmatching */ +s32 daBg_c::create() { + fopAcM_SetupActor(this, daBg_c); + + s32 roomNo = fopAcM_GetParam(this); + JKRExpHeap * roomHeap = g_dComIfG_gameInfo.play.getRoomControl()->getMemoryBlock(roomNo); + if (roomHeap != NULL) { + heap = JKRSolidHeap::create(-1, roomHeap, false); + JUT_ASSERT(0x2fd, heap != 0); + JKRHeap * oldHeap = mDoExt_setCurrentHeap(heap); + s32 rt = createHeap(); + JUT_ASSERT(0x302, rt == 1); + mDoExt_setCurrentHeap(oldHeap); + heap->adjustSize(); + } else { + if (!fopAcM_entrySolidHeap(this, checkCreateHeap, 0)) { + dStage_escapeRestart(); + return cPhs_ERROR_e; + } + } + + BgModel * bgm = &bg[0]; + for (s32 i = 0; i < 4; i++, bgm++) { + if (bgm->model == NULL) + continue; + J3DModelData * modelData = bgm->model->getModelData(); + if (bgm->btk != NULL) + bgm->btk->entry(modelData); + if (bgm->brk != NULL) + bgm->brk->entry(modelData); + } + + f32 transX, transZ; + s16 angleY; + if (dComIfGp_getMapTrans(roomNo, &transX, &transZ, &angleY)) { + BgModel * bgm = &bg[0]; + J3DModel * model; + for (s32 i = 0; i < 4; i++, bgm++) { + model = bgm->model; + if (model == NULL) + continue; + mDoMtx_stack_c::transS(transX, 0.0f, transZ); + mDoMtx_stack_c::YrotM(angleY); + model->setBaseTRMtx(mDoMtx_stack_c::get()); + } + } + + if (bgw != NULL && dComIfG_Bgsp()->Regist(bgw, this)) { + dStage_escapeRestart(); + return cPhs_ERROR_e; + } + + dKy_tevstr_init(dComIfGp_roomControl_getTevStr(roomNo), roomNo, 0xFF); + dComIfGp_roomControl_onStatusFlag(roomNo, 0x10); + return cPhs_COMPLEATE_e; } +actor_method_class l_daBg_Method = { + (process_method_func)daBg_Create, + (process_method_func)daBg_Delete, + (process_method_func)daBg_Execute, + (process_method_func)daBg_IsDelete, + (process_method_func)daBg_Draw, +}; + +actor_process_profile_definition g_profile_BG = { + fpcLy_CURRENT_e, + 7, + fpcPi_CURRENT_e, + PROC_BG, + &g_fpcLf_Method.mBase, + sizeof(daBg_c), + 0, + 0, + &g_fopAc_Method.base, + 0x01C2, + &l_daBg_Method, + fopAcStts_UNK4000_e | fopAcStts_UNK40000_e, + fopAc_ACTOR_e, + fopAc_CULLBOX_0_e, +};