diff --git a/configure.py b/configure.py index 8aca9664..46e81efc 100644 --- a/configure.py +++ b/configure.py @@ -525,9 +525,9 @@ config.libs = [ Object(NonMatching, "d/lyt/msg_window/d_lyt_msg_window.cpp"), Object(NonMatching, "d/lyt/msg_window/d_lyt_msg_window_select_btn.cpp"), Object(Matching, "d/lyt/msg_window/d_lyt_msg_window_common.cpp"), - Object(NonMatching, "d/lyt/msg_window/d_lyt_msg_window_talk.cpp"), - Object(NonMatching, "d/lyt/msg_window/d_lyt_msg_window_link.cpp"), - Object(NonMatching, "d/lyt/msg_window/d_lyt_msg_window_get.cpp"), + Object(Matching, "d/lyt/msg_window/d_lyt_msg_window_talk.cpp"), + Object(Matching, "d/lyt/msg_window/d_lyt_msg_window_link.cpp"), + Object(Matching, "d/lyt/msg_window/d_lyt_msg_window_get.cpp"), Object(Matching, "d/lyt/msg_window/d_lyt_msg_window_sword.cpp"), Object(Matching, "d/lyt/msg_window/d_lyt_msg_window_wood.cpp"), Object(Matching, "d/lyt/msg_window/d_lyt_msg_window_stone.cpp"), diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index 73eea22f..707062f3 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -1,9 +1,11 @@ #ifndef NW4R_LYT_TYPES_H #define NW4R_LYT_TYPES_H -#include "nw4r/math.h" // IWYU pragma: export #include "nw4r/ut/ut_LinkList.h" #include "nw4r/ut/ut_algorithm.h" + +#include "nw4r/math.h" // IWYU pragma: export + #include "rvl/GX.h" // IWYU pragma: export namespace nw4r { @@ -31,8 +33,10 @@ inline bool TestBit(T bits, int index) { } template inline void SetBit(T *bits, int pos, bool val) { - T mask = ~T(1 << pos); - *bits = T((*bits & mask)) | (val << pos); + T mask = 1 << pos; + + *bits &= ~mask; + *bits |= val ? mask : 0; } template diff --git a/src/d/lyt/d_lyt_map.cpp b/src/d/lyt/d_lyt_map.cpp index ba3a0aff..ef795225 100644 --- a/src/d/lyt/d_lyt_map.cpp +++ b/src/d/lyt/d_lyt_map.cpp @@ -675,7 +675,7 @@ bool dLytMapPinIcon_c::draw() { void dLytMapPinIconAggregate_c::initializeState_Wait() {} void dLytMapPinIconAggregate_c::executeState_Wait() { - for (int i = 0; i < 5; i++) { + for (int i = 0; i < (int)ARRAY_LENGTH(mPins); i++) { if (mPins[i].isSelect()) { mStateMgr.changeState(StateID_Select); } @@ -686,7 +686,7 @@ void dLytMapPinIconAggregate_c::finalizeState_Wait() {} void dLytMapPinIconAggregate_c::initializeState_Select() {} void dLytMapPinIconAggregate_c::executeState_Select() { bool anyRemove = false; - for (int i = 0; i < 5; i++) { + for (int i = 0; i < (int)ARRAY_LENGTH(mPins); i++) { if (mPins[i].isRemove()) { mStateMgr.changeState(StateID_Remove); anyRemove = true; @@ -697,7 +697,7 @@ void dLytMapPinIconAggregate_c::executeState_Select() { if (!anyRemove) { bool allSelect = true; - for (int i = 0; i < 5; i++) { + for (int i = 0; i < (int)ARRAY_LENGTH(mPins); i++) { if (mPins[i].isSelect()) { allSelect = false; break; @@ -4552,12 +4552,12 @@ void dLytMapMain_c::executeState_Active() { dSndSmallEffectMgr_c::GetInstance()->playSound(SE_S_MAP_BEACON_SET); } } else if ((dPad::getDownTrigLeft() && canZoomOut(mCurrentMapMode)) || - (dPad::getDownTrigA() && mCurrentMapMode == dLytMapGlobal_c::MAPMODE_ZOOM && canZoomOut(mCurrentMapMode) - )) { + (dPad::getDownTrigA() && mCurrentMapMode == dLytMapGlobal_c::MAPMODE_ZOOM && + canZoomOut(mCurrentMapMode))) { zoomOut(); } else if ((dPad::getDownTrigRight() && canZoomIn(mCurrentMapMode)) || - (dPad::getDownTrigA() && mCurrentMapMode == dLytMapGlobal_c::MAPMODE_STAGE && canZoomIn(mCurrentMapMode) - )) { + (dPad::getDownTrigA() && mCurrentMapMode == dLytMapGlobal_c::MAPMODE_STAGE && + canZoomIn(mCurrentMapMode))) { zoomIn(); } else if ((mRoomType == ROOMTYPE_FIELD || mRoomType == ROOMTYPE_DUNGEON || mRoomType == ROOMTYPE_SKYLOFT || mRoomType == ROOMTYPE_SKYFIELD) && @@ -5388,7 +5388,6 @@ void dLytMapMain_c::executeState_EventGoddessCube_Step2() { f32 f4 = field_0x8D50 + factor * (field_0x8D4C - field_0x8D50); global->setField_0x44(f4); - // TODO stack and reg swaps global->setMapRotation(factor * mAng(field_0x8D46 - field_0x8D44) + field_0x8D44); @@ -5398,7 +5397,7 @@ void dLytMapMain_c::executeState_EventGoddessCube_Step2() { if (field_0x8C7C - field_0x8C80) { f1 = 0.0f; } - + mAnmGroups[MAP_MAIN_ANIM_ROTATE].setFrame(length - f3 * length); global->setMapScroll(mPlayerPos + (mMapScroll - mPlayerPos) * (1.0f / (f4 / field_0x8D50)) * (1.0f - factor)); diff --git a/src/d/lyt/d_lyt_map_markers.cpp b/src/d/lyt/d_lyt_map_markers.cpp index b3b2a335..07b48e47 100644 --- a/src/d/lyt/d_lyt_map_markers.cpp +++ b/src/d/lyt/d_lyt_map_markers.cpp @@ -140,11 +140,7 @@ bool dLytMapPopup_c::execute() { void dLytMapPopup_c::draw() { u8 alpha = dLytMapGlobal_c::GetInstance()->getAlpha(); mpPanes[MAP_POPUP_PANE_ALL]->SetAlpha(alpha); - mVec3_c pos; - pos.x = mPosition.x; - pos.y = mPosition.y; - pos.z = 0.0f; - mpPanes[MAP_POPUP_PANE_ALL]->SetTranslate(pos); + mpPanes[MAP_POPUP_PANE_ALL]->SetTranslate(vec2ToVec3XY(mPosition)); mpPanes[MAP_POPUP_PANE_ALL]->Animate(0); mpPanes[MAP_POPUP_PANE_ALL]->CalculateMtx(mLyt.getDrawInfo()); mpPanes[MAP_POPUP_PANE_ALL]->Draw(mLyt.getDrawInfo()); @@ -787,7 +783,7 @@ bool dLytMapIcon01_c::build(d2d::ResAccIf_c *resAcc) { loadFlags(); for (int i = 0; i < (int)ARRAY_LENGTH(mIconAnims); i++) { - mIconAnims[i].cmdIndex = 100; + mIconAnims[i].cmdIndex = ARRAY_LENGTH(mCommands); mIconAnims[i].frame = 0.0f; mIconAnims[i].animIn = false; mIconAnims[i].animOut = false; @@ -930,17 +926,17 @@ void dLytMapIcon01_c::draw() { break; } case MAP_ICON_01_PANE_AREALIGHT_00: { - if (field_0x0D48 != 100 && field_0x0D48 == cmd) { + if (field_0x0D48 != ARRAY_LENGTH(mCommands) && field_0x0D48 == cmd) { setAreaLight(0, pane); - } else if (field_0x0D49 != 100 && field_0x0D49 == cmd) { + } else if (field_0x0D49 != ARRAY_LENGTH(mCommands) && field_0x0D49 == cmd) { setAreaLight(1, pane); - } else if (field_0x0D4A != 100 && field_0x0D4A == cmd) { + } else if (field_0x0D4A != ARRAY_LENGTH(mCommands) && field_0x0D4A == cmd) { setAreaLight(2, pane); } break; } case MAP_ICON_01_PANE_SAVEICON_00: { - if (field_0x0D4B[cmd] != 100) { + if (field_0x0D4B[cmd] != ARRAY_LENGTH(mCommands)) { setSaveObj(field_0x0D4B[cmd], pane); } break; @@ -1042,7 +1038,8 @@ void dLytMapIcon01_c::draw() { for (int i = 0; i < field_0x0E13; i++) { if (mPopupConfigs[i + MAP_ICON_01_BOUNDING_COMMONICON_00].bounding->IsVisible()) { v2 = mPopupConfigs[i + MAP_ICON_01_BOUNDING_COMMONICON_00].boundingPos; - mPopupConfigs[i + MAP_ICON_01_BOUNDING_COMMONICON_00].bounding->SetTranslate(vec2ToVec3XY(v2 + field_0x0D40) + mPopupConfigs[i + MAP_ICON_01_BOUNDING_COMMONICON_00].bounding->SetTranslate( + vec2ToVec3XY(v2 + field_0x0D40) ); mPopupConfigs[i + MAP_ICON_01_BOUNDING_COMMONICON_00].bounding->CalculateMtx(mLyt.getDrawInfo()); mPopupConfigs[i + MAP_ICON_01_BOUNDING_COMMONICON_00].bounding->Draw(mLyt.getDrawInfo()); @@ -1060,7 +1057,7 @@ void dLytMapIcon01_c::resetDrawCommands() { mCommands[i].rotation.setF(0.0f); mCommands[i].paneIdx = MAP_ICON_01_NUM_PANES; mCommands[i].passIdx = 35; - field_0x0D4B[i] = 100; + field_0x0D4B[i] = ARRAY_LENGTH(mCommands); field_0x0C85[i] = 0; } @@ -1073,7 +1070,7 @@ void dLytMapIcon01_c::resetDrawCommands() { mNumCommands = 0; for (int i = 0; i < (int)ARRAY_LENGTH(mPopupConfigs); i++) { - mPopupConfigs[i].cmdIdx = 100; + mPopupConfigs[i].cmdIdx = ARRAY_LENGTH(mCommands); mPopupConfigs[i].boundingPos.set(0.0f, 0.0f); mPopupConfigs[i].textPos.set(0.0f, 0.0f); mPopupConfigs[i].pointedAt = false; @@ -1087,9 +1084,9 @@ void dLytMapIcon01_c::resetDrawCommands() { fn_80181C40(); - field_0x0D48 = 100; - field_0x0D49 = 100; - field_0x0D4A = 100; + field_0x0D48 = ARRAY_LENGTH(mCommands); + field_0x0D49 = ARRAY_LENGTH(mCommands); + field_0x0D4A = ARRAY_LENGTH(mCommands); mFunFunIslandDiscovered = false; mLumpyPumkpinDiscovered = false; @@ -1182,10 +1179,6 @@ void dLytMapIcon01_c::setSaveObj(u32 color, nw4r::lyt::Pane *pane) { } void dLytMapIcon01_c::setTerry(bool present) { - // NONMATCHING - // TODO - SetVisible clrlwi - // When you fix this, maybe also fix other instances of this problem - // by searching for 91657b77 mpTerryOnOffPane->SetVisible(present); } @@ -1300,22 +1293,22 @@ void dLytMapIcon01_c::setupActorDrawCommands() { setupObjHarpHintDrawCommand(ac); if (field_0x184D) { - setupNpcKenseiDrawCommand(ac); + setupNpcBeeDrawCommand(ac); } - setupNpcBeeDrawCommand(ac); + setupNpcKenseiDrawCommand(ac); setupObjSaveDrawCommand(ac); setupObjLightLineDrawCommand(ac); setupObjRoAtTargetDrawCommand(ac); - if (mNumCommands >= 100) { + if (mNumCommands >= ARRAY_LENGTH(mCommands)) { break; } } } void dLytMapIcon01_c::setupNpcKenseiDrawCommand(dAcBase_c *actor) { - if (mNumCommands < 100) { + if (mNumCommands < ARRAY_LENGTH(mCommands)) { if (actor->mProfileName == fProfile::NPC_KENSEI && !actor->checkActorProperty(dAcBase_c::AC_PROP_0x100) && mCurrentFloor == dStage_c::GetInstance()->getMapRelated()->fn_801B4F10(actor->mRoomID, actor->mPosition)) { mVec2_c pos(0.0f, 0.0f); @@ -1351,7 +1344,7 @@ void dLytMapIcon01_c::setupTboxDrawCommand(dAcBase_c *actor) { } void dLytMapIcon01_c::setupTboxDrawCommandClosed(dAcTbox_c *box) { - if (mNumCommands < 100) { + if (mNumCommands < ARRAY_LENGTH(mCommands)) { mVec2_c pos(0.0f, 0.0f); projectOntoMap(box->mPosition, pos); mCommands[mNumCommands].passIdx = 17; @@ -1381,7 +1374,7 @@ void dLytMapIcon01_c::setupTboxDrawCommandClosed(dAcTbox_c *box) { } void dLytMapIcon01_c::setupTboxDrawCommandOpen(dAcTbox_c *box) { - if (mNumCommands < 100) { + if (mNumCommands < ARRAY_LENGTH(mCommands)) { mVec2_c pos(0.0f, 0.0f); projectOntoMap(box->mPosition, pos); mCommands[mNumCommands].passIdx = 17; @@ -1395,7 +1388,7 @@ void dLytMapIcon01_c::setupTboxDrawCommandOpen(dAcTbox_c *box) { } void dLytMapIcon01_c::setupTboxDrawCommandGoddessClosed(dAcTbox_c *box) { - if (mNumCommands < 100) { + if (mNumCommands < ARRAY_LENGTH(mCommands)) { mVec2_c pos(0.0f, 0.0f); projectOntoMap(box->mPosition, pos); mCommands[mNumCommands].passIdx = 28; @@ -1417,7 +1410,7 @@ void dLytMapIcon01_c::setupObjDoorDrawCommand(dAcBase_c *actor) { } void dLytMapIcon01_c::setupObjSaveDrawCommand(dAcBase_c *actor) { - if (mNumCommands < 100) { + if (mNumCommands < ARRAY_LENGTH(mCommands)) { if (actor->mProfileName == fProfile::OBJ_SAVE && !actor->checkActorProperty(dAcBase_c::AC_PROP_0x100) && mCurrentFloor == dStage_c::GetInstance()->getMapRelated()->fn_801B4F10(actor->mRoomID, actor->mPosition)) { dAcOSave_c *save = static_cast(actor); @@ -1555,7 +1548,7 @@ void dLytMapIcon01_c::setupStageDrawCommands() { setupTgInsectDrawCommand(ac); } - if (mNumCommands >= 100) { + if (mNumCommands >= ARRAY_LENGTH(mCommands)) { break; } } @@ -1604,7 +1597,7 @@ void dLytMapIcon01_c::setupLinkDrawCommand2() { } void dLytMapIcon01_c::setupCloudBigDrawCommand() { - if (mNumCommands < 100) { + if (mNumCommands < ARRAY_LENGTH(mCommands)) { mVec3_c thunderHeadPos(-135210.0f, 0.0f, -84790.0f); mVec2_c pos(0.0f, 0.0f); projectOntoMap(thunderHeadPos, pos); @@ -1742,7 +1735,7 @@ void dLytMapIcon00_c::resetDrawCommands() { mCommands[i].rotation.setF(0.0f); mCommands[i].paneIdx = 39; mCommands[i].passIdx = 35; - field_0x0F20[i] = 100; + field_0x0F20[i] = ARRAY_LENGTH(mCommands); field_0x13A8[i] = 0; field_0x1342[i] = 0; field_0x0E5B[i] = 0; @@ -1760,7 +1753,7 @@ void dLytMapIcon00_c::resetDrawCommands() { } for (int i = 0; i < (int)ARRAY_LENGTH(mPopupConfigs); i++) { - mPopupConfigs[i].cmdIdx = 100; + mPopupConfigs[i].cmdIdx = ARRAY_LENGTH(mCommands); mPopupConfigs[i].boundingPos.set(0.0f, 0.0f); mPopupConfigs[i].textPos.set(0.0f, 0.0f); mPopupConfigs[i].pointedAt = false; diff --git a/src/d/lyt/msg_window/d_lyt_msg_window_get.cpp b/src/d/lyt/msg_window/d_lyt_msg_window_get.cpp index 4274e323..4c1c206e 100644 --- a/src/d/lyt/msg_window/d_lyt_msg_window_get.cpp +++ b/src/d/lyt/msg_window/d_lyt_msg_window_get.cpp @@ -176,19 +176,9 @@ bool dLytMsgWindowGet_c::execute() { } void dLytMsgWindowGet_c::draw() { - // NONMATCHING - // TODO - SetVisible clrlwi - // The instruction patterns here are the same that EGG::StateGX::Scoped - // generates, but there's no RAII to be found here. What's the missing - // link that makes the compiler generate these? - // When you fix this, fix other instances of this problem - // by searching for 91657b77 - bool bVis[5] = { - mpPanes[0]->IsVisible(), - mpPanes[1]->IsVisible(), - mpPanes[2]->IsVisible(), - mpPanes[3]->IsVisible(), - mpPanes[4]->IsVisible(), + bool bVis[5]; + for (int i = 0; i < 5; ++i) { + bVis[i] = mpPanes[i]->IsVisible(); }; mpPanes[0]->SetVisible(bVis[0]); @@ -208,11 +198,9 @@ void dLytMsgWindowGet_c::draw() { mLyt.draw(); - mpPanes[0]->SetVisible(bVis[0]); - mpPanes[1]->SetVisible(bVis[1]); - mpPanes[2]->SetVisible(bVis[2]); - mpPanes[3]->SetVisible(bVis[3]); - mpPanes[4]->SetVisible(bVis[4]); + for (int i = 0; i < 5; ++i) { + mpPanes[i]->SetVisible(bVis[i]); + }; } void dLytMsgWindowGet_c::open(dAcObjBase_c *obj, u32 param) { diff --git a/src/d/lyt/msg_window/d_lyt_msg_window_link.cpp b/src/d/lyt/msg_window/d_lyt_msg_window_link.cpp index 6564a7f3..d47b6a72 100644 --- a/src/d/lyt/msg_window/d_lyt_msg_window_link.cpp +++ b/src/d/lyt/msg_window/d_lyt_msg_window_link.cpp @@ -1,8 +1,8 @@ #include "d/lyt/msg_window/d_lyt_msg_window_link.h" #include "common.h" -#include "d/d_tag_processor.h" #include "d/d_lyt_hio.h" +#include "d/d_tag_processor.h" #include "d/lyt/d2d.h" #include "d/lyt/d_textbox.h" #include "d/lyt/msg_window/d_lyt_msg_window_common.h" @@ -17,10 +17,10 @@ STATE_DEFINE(dLytMsgWindowLink_c, Visible); STATE_DEFINE(dLytMsgWindowLink_c, Out); static const d2d::LytBrlanMapping brlanMap[] = { - { "linkWindow_00_in.brlan", "G_inOut_00"}, - { "linkWindow_00_out.brlan", "G_inOut_00"}, - {"linkWindow_00_position.brlan", "G_position_00"}, - {"linkWindow_00_loop.brlan", "G_loop_00"}, + { "linkWindow_00_in.brlan", "G_inOut_00"}, + { "linkWindow_00_out.brlan", "G_inOut_00"}, + {"linkWindow_00_position.brlan", "G_position_00"}, + { "linkWindow_00_loop.brlan", "G_loop_00"}, }; #define LINK_ANIM_IN 0 @@ -98,7 +98,7 @@ bool dLytMsgWindowLink_c::build(d2d::ResAccIf_c *resAcc1, d2d::ResAccIf_c *resAc mParam = 0; mOffset.x = mOffset.y = 0.0f; - + mWaitDelay = 0; mStateMgr.changeState(StateID_Invisible); @@ -239,17 +239,9 @@ bool dLytMsgWindowLink_c::execute() { } void dLytMsgWindowLink_c::draw() { - // NONMATCHING - // TODO - SetVisible clrlwi - // The instruction patterns here are the same that EGG::StateGX::Scoped - // generates, but there's no RAII to be found here. What's the missing - // link that makes the compiler generate these? - // When you fix this, fix other instances of this problem - // by searching for 91657b77 - bool bVis[3] = { - mpPanes[0]->IsVisible(), - mpPanes[1]->IsVisible(), - mpPanes[2]->IsVisible(), + bool bVis[3]; + for (int i = 0; i < 3; ++i) { + bVis[i] = mpPanes[i]->IsVisible(); }; mpPanes[0]->SetVisible(bVis[0]); @@ -267,9 +259,9 @@ void dLytMsgWindowLink_c::draw() { mLyt.draw(); - mpPanes[0]->SetVisible(bVis[0]); - mpPanes[1]->SetVisible(bVis[1]); - mpPanes[2]->SetVisible(bVis[2]); + for (int i = 0; i < 3; ++i) { + mpPanes[i]->SetVisible(bVis[i]); + }; } void dLytMsgWindowLink_c::open(dAcObjBase_c *obj, u32 param) { diff --git a/src/d/lyt/msg_window/d_lyt_msg_window_talk.cpp b/src/d/lyt/msg_window/d_lyt_msg_window_talk.cpp index 8f9cde37..5c89d671 100644 --- a/src/d/lyt/msg_window/d_lyt_msg_window_talk.cpp +++ b/src/d/lyt/msg_window/d_lyt_msg_window_talk.cpp @@ -1,8 +1,8 @@ #include "d/lyt/msg_window/d_lyt_msg_window_talk.h" #include "common.h" -#include "d/d_tag_processor.h" #include "d/d_lyt_hio.h" +#include "d/d_tag_processor.h" #include "d/lyt/d2d.h" #include "d/lyt/d_textbox.h" #include "d/lyt/msg_window/d_lyt_msg_window_common.h" @@ -239,17 +239,9 @@ bool dLytMsgWindowTalk_c::execute() { } void dLytMsgWindowTalk_c::draw() { - // NONMATCHING - // TODO - SetVisible clrlwi - // The instruction patterns here are the same that EGG::StateGX::Scoped - // generates, but there's no RAII to be found here. What's the missing - // link that makes the compiler generate these? - // When you fix this, fix other instances of this problem - // by searching for 91657b77 - bool bVis[3] = { - mpPanes[0]->IsVisible(), - mpPanes[1]->IsVisible(), - mpPanes[2]->IsVisible(), + bool bVis[3]; + for (int i = 0; i < 3; ++i) { + bVis[i] = mpPanes[i]->IsVisible(); }; mpPanes[0]->SetVisible(bVis[0]); @@ -265,9 +257,9 @@ void dLytMsgWindowTalk_c::draw() { mLyt.draw(); - mpPanes[0]->SetVisible(bVis[0]); - mpPanes[1]->SetVisible(bVis[1]); - mpPanes[2]->SetVisible(bVis[2]); + for (int i = 0; i < 3; ++i) { + mpPanes[i]->SetVisible(bVis[i]); + }; } void dLytMsgWindowTalk_c::open(dAcObjBase_c *obj, u32 param) {