decompile RoomMapMgr::makeOneRoom

This commit is contained in:
HeartPiece 2023-11-28 01:01:49 +11:00
parent 009b41586b
commit e3e36a1ae0
9 changed files with 360 additions and 30 deletions

View File

@ -132,8 +132,8 @@
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/itemUjamushi.cpp">itemUjamushi.cpp</a> | 76345 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/singleGameSection.cpp">singleGameSection.cpp</a> | 86519 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/baseGameSection.cpp">baseGameSection.cpp</a> | 92198 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/itemMgr.cpp">itemMgr.cpp</a> | 102156 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/aiPrimitives.cpp">aiPrimitives.cpp</a> | 116963 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/pelletMgr.cpp">pelletMgr.cpp</a> | 142715 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/pikiState.cpp">pikiState.cpp</a> | 152886 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/gameMapParts.cpp">gameMapParts.cpp</a> | 158960 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/navi.cpp">navi.cpp</a> | 164852 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/naviState.cpp">naviState.cpp</a> | 180369 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/pikiState.cpp">pikiState.cpp</a> | 152886 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/navi.cpp">navi.cpp</a> | 164885 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/gameMapParts.cpp">gameMapParts.cpp</a> | 167801 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/naviState.cpp">naviState.cpp</a> | 180369 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectKandoU/singleGS_Zukan.cpp">singleGS_Zukan.cpp</a> | 192282 | | |
### <section id="plugProjectKonoU">plugProjectKonoU</section>

View File

@ -54,6 +54,28 @@ struct BoundBox {
}
}
inline void include(BoundBox& box)
{
if (box.mMin.x < mMin.x) {
mMin.x = box.mMin.x;
}
if (box.mMin.y < mMin.y) {
mMin.y = box.mMin.y;
}
if (box.mMin.z < mMin.z) {
mMin.z = box.mMin.z;
}
if (box.mMax.x > mMax.x) {
mMax.x = box.mMax.x;
}
if (box.mMax.y > mMax.y) {
mMax.y = box.mMax.y;
}
if (box.mMax.z > mMax.z) {
mMax.z = box.mMax.z;
}
}
Vector3f mMin; // _00
Vector3f mMax; // _0C
};

View File

@ -41,8 +41,8 @@ struct ObjectLayoutNode : public CNode {
struct ObjectLayoutInfo {
ObjectLayoutInfo() { }
virtual s32 getCount(int) = 0;
virtual CNode* getNode(int, int) = 0;
virtual int getCount(int) = 0;
virtual ObjectLayoutNode* getNode(int, int) = 0;
};
namespace Cave {
@ -92,8 +92,8 @@ struct UnitInfo {
struct ObjectLayout : public ObjectLayoutInfo {
ObjectLayout(MapNode*);
virtual s32 getCount(int); // _08
virtual CNode* getNode(int, int); // _0C
virtual int getCount(int); // _08
virtual ObjectLayoutNode* getNode(int, int); // _0C
void setNode(int, Game::ObjectLayoutNode*);

View File

@ -60,9 +60,7 @@ struct MoveInfo {
Vector3f mReflectPosition; // _5C
Vector3f _68; // _68, related to tri at _4C
u8 _74; // _74
f32 _78; // _78
f32 _7C; // _7C
f32 _80; // _80
Vector3f _78; // _78
Vector3f _84; // _84
u8 _90; // _90
TDispTriangleArray* mTriangleArray; // _94

View File

@ -94,8 +94,8 @@ struct RoomLink : public CNode {
// _00 = VTBL
// _00-_18 = CNode
s16 mLinkIndex; // _18
s16 mBirthDoorIndex; // _1A
u16 mLinkIndex; // _18
u16 mBirthDoorIndex; // _1A
s16 mAliveMapIndex; // _1C
};
@ -225,7 +225,7 @@ struct MapRoom : public CellObject {
bool mIsVisited; // _0BC
MapUnitInterface* mInterface; // _0C0
Cave::ObjectLayout* mObjectLayoutInfo; // _0C4
int _0C8; // _0C8
int mAnimationCount; // _0C8
Sys::MatLoopAnimator* mAnimators; // _0CC
int mDoorNum; // _0D0
RoomDoorInfo* mDoorInfos; // _0D4
@ -239,8 +239,7 @@ struct MapRoom : public CellObject {
RoomLink* mLink; // _180
s16 mIndex; // _184
s16 mUnitKind; // _186
u8 _188; // _188
u8 _189; // _189
BitFlag<u16> mFlags; // _188
int* mWpIndices; // _18C
Sys::Sphere _190; // _190
};
@ -275,7 +274,7 @@ struct RoomMapMgr : public MapMgr {
virtual void doEntry(); // _54
virtual void doSetView(int viewportNumber); // _58
virtual void doViewCalc(); // _5C
virtual void traceMove_new(MoveInfo&, f32); // _60
virtual Sys::TriIndexList* traceMove_new(MoveInfo&, f32); // _60
virtual void traceMove_original(MoveInfo&, f32); // _64
MapRoom* getMapRoom(s16 roomIdx);

View File

@ -48,18 +48,19 @@ struct PelletConfig : public CNode {
PrimTagParm<f32> mDepthC; // _1E4
PrimTagParm<f32> mDepthD; // _1F4
PrimTagParm<Vector3f> mOffset; // _204
PrimTagParm<u64> mMessage;
PrimTagParm<u16> mCode;
PrimTagParm<u16> mDictionary;
s16 mIndex;
u8 mIndirectState;
}; // struct TParms
PrimTagParm<u64> mMessage; // _21C
PrimTagParm<u16> mCode; // _234
PrimTagParm<u16> mDictionary; // _248
s16 mIndex; // _25C
u8 mIndirectState; // _25A
}; // struct TParms
PelletConfig();
virtual ~PelletConfig() { }
TParms mParams; // _04
// _00 = VTBL
// _00-_18 = CNode
TParms mParams; // _18
};
struct PelletConfigList : public CNode {

View File

@ -64,6 +64,8 @@ struct WayPoint : public JKRDisposer {
{
}
inline RoomList(s16 idx) { mRoomIdx = idx; }
virtual ~RoomList() { } // _08 (weak)
// _00 = VTBL

View File

@ -11,6 +11,7 @@
#include "JSystem/JUtility/JUTTexture.h"
#include "Dolphin/rand.h"
#include "Sys/TriangleTable.h"
#include "VsOtakaraName.h"
#include "nans.h"
namespace Game {
@ -379,8 +380,6 @@ void MapUnitMgr::load(char*)
*/
MapRoom::MapRoom()
{
_188 = 0;
_189 = 0;
mModel = nullptr;
mUnit = nullptr;
PSMTXIdentity(_0D8.mMatrix.mtxView);
@ -688,7 +687,7 @@ void MapRoom::doEntry()
}
if (isVisible) {
if (!gameSystem->paused()) {
for (int i = 0; i < _0C8; i++) {
for (int i = 0; i < mAnimationCount; i++) {
mAnimators[i].animate(30.0f);
}
}
@ -2385,7 +2384,47 @@ void RoomMapMgr::drawCollision(Graphics&, Sys::Sphere&) { }
*/
Sys::TriIndexList* RoomMapMgr::traceMove(MoveInfo& moveInfo, f32 rate)
{
int counter = 1;
Sys::TriIndexList* list;
f32 rad = moveInfo.mMoveSphere->mRadius;
f32 speed = moveInfo.mVelocity->length();
do {
if (rate * speed > rad) {
counter *= 2;
rate *= 0.5f;
continue;
}
break;
} while (counter <= 4);
for (int i = 0; i < counter; i++) {
list = traceMove_new(moveInfo, rate);
}
if (mFloorInfo->hasHiddenCollision() && !moveInfo.mBounceTriangle
&& (moveInfo.mMoveSphere->mPosition.y - moveInfo.mMoveSphere->mRadius) < 0.0f) {
moveInfo.mMoveSphere->mPosition.y = moveInfo.mMoveSphere->mRadius;
if (moveInfo.mVelocity->y < 0.0f) {
moveInfo.mVelocity->y = -moveInfo.mVelocity->y * (moveInfo.mTraceRadius - 1.0f);
}
Vector3f vec1 = moveInfo.mMoveSphere->mPosition;
vec1.y -= moveInfo.mMoveSphere->mRadius;
moveInfo.mBounceTriangle = &mTriangle;
moveInfo.mPosition = Vector3f(0.0f, 1.0f, 0.0f);
moveInfo._78 = Vector3f(0.0f, 1.0f, 0.0f);
moveInfo._84 = vec1;
if (moveInfo._10) {
Vector3f vec2(0.0f, 1.0f, 0.0f);
moveInfo._10->invoke(vec1, vec2);
}
}
return list;
/*
stwu r1, -0x50(r1)
mflr r0
@ -3393,7 +3432,7 @@ lbl_801BAB44:
* Address: 801BAD60
* Size: 000328
*/
void RoomMapMgr::traceMove_new(MoveInfo&, f32)
Sys::TriIndexList* RoomMapMgr::traceMove_new(MoveInfo&, f32)
{
/*
stwu r1, -0xe0(r1)
@ -5399,6 +5438,275 @@ lbl_801BC900:
void RoomMapMgr::makeOneRoom(f32 centreX, f32 centreY, f32 direction, char* unitName, s16 roomIdx, RoomLink* link,
ObjectLayoutInfo* layoutInfo)
{
f32 faceAngle = TORADIANS(direction); // f31
MapRoom* room = mRoomMgr.birth(); // r31
room->mIndex = roomIdx;
room->mLink = link;
room->mObjectLayoutInfo = static_cast<Cave::ObjectLayout*>(layoutInfo);
for (int i = 0; i < room->mObjectLayoutInfo->getCount(0); i++) {
ObjectLayoutNode* node = room->mObjectLayoutInfo->getNode(0, i);
PelletMgr::OtakaraItemCode itemCode;
itemCode.mValue = node->getExtraCode();
PelletInitArg initArg;
if (pelletMgr->makePelletInitArg(initArg, itemCode)) {
if (pelletMgr->setUse(&initArg)) {
if (Pellet::sFromTekiEnable) {
PelletBirthBuffer::entry(initArg);
}
} else {
itemCode.mValue = 0;
}
}
u8 num = node->getBirthCount();
generalEnemyMgr->addEnemyNum(node->getObjectId(), num, nullptr);
}
for (int i = 0; i < room->mObjectLayoutInfo->getCount(1); i++) {
ObjectLayoutNode* node = room->mObjectLayoutInfo->getNode(1, i);
PelletIndexInitArg initArg(node->getObjectId());
pelletMgr->setUse(&initArg);
}
if (gameSystem && gameSystem->isVersusMode()) {
PelletList::cKind kind;
PelletConfig* config = PelletList::Mgr::getConfigAndKind(const_cast<char*>(VsOtakaraName::cCoin), kind);
if (config) {
PelletIndexInitArg initArg(pelletMgr->encode(kind, config->mParams.mIndex));
pelletMgr->setUse(&initArg);
}
}
Matrixf mtx1; // 0x214
Vector3f translation(centreX * 170.0f, 0.0f, centreY * 170.0f); // 0xD0
Vector3f rotation1(0.0f, faceAngle, 0.0f); // 0xC4
mtx1.makeTR(translation, rotation1);
MapUnit* unit = mMapUnitMgr->findMapUnit(unitName); // r22
room->mUnit = unit;
PSMTXCopy(mtx1.mMatrix.mtxView, room->_0D8.mMatrix.mtxView);
PSMTXInverse(mtx1.mMatrix.mtxView, room->_108.mMatrix.mtxView);
room->mModel = new SysShape::Model(unit->mModelData, 0x20000, 2);
room->mModel->mJ3dModel->newDifferedTexMtx(TexDiff_0);
room->mModel->mJ3dModel->newDifferedDisplayList(0x200);
PSMTXCopy(room->_0D8.mMatrix.mtxView, room->mModel->mJ3dModel->mPosMtx);
room->mModel->mJ3dModel->calc();
room->mModel->mJ3dModel->calcMaterial();
room->mModel->mJ3dModel->makeDL();
room->mModel->mJ3dModel->lock();
room->mAnimationCount = unit->mAnimationCount;
room->mAnimators = new Sys::MatLoopAnimator[room->mAnimationCount];
for (int i = 0; i < room->mAnimationCount; i++) {
room->mAnimators[i].start(&unit->mAnimations[i]);
}
Matrixf boundMtx; // 0x1E4
BoundBox bBox(unit->mBoundingBox); // 0xF4
Vector3f rotation2(0.0f, faceAngle, 0.0f); // 0xB8
boundMtx.makeTR(translation, rotation2);
bBox.transform(boundMtx);
mBoundbox.include(bBox);
bBox.makeBoundSphere(room->mBoundingSphere);
BoundBox bBox2(bBox);
bBox2.mMin.y = 0.0f;
bBox2.mMax.y = 0.0f;
bBox2.makeBoundSphere(room->_190);
Vector3f modelCenter = room->mModel->getRoughCenter(); // f30, f29, f28
f32 val = 0.0f;
for (int i = 0; i < room->mModel->mJointCount; i++) {
if (val < room->mModel->mJoints[i].mJ3d->mBoundingSphereRadius) {
val = room->mModel->mJoints[i].mJ3d->mBoundingSphereRadius;
}
}
if (strcmp(unitName, "cap_conc") == 0) {
val += 30.0f;
}
room->_150.mPosition = modelCenter + translation;
room->_150.mRadius = val;
Vector3f startCyl = Vector3f(room->mBoundingSphere.mPosition);
Vector3f endCyl = Vector3f(room->mBoundingSphere.mPosition);
endCyl.y -= 100.0f;
room->_160.set(startCyl, endCyl, room->mBoundingSphere.mRadius);
mSeaMgr->addSeaMgr(&unit->mSeaMgr, mtx1);
MapUnitInterface* mui = getMUI(unit); // r27
room->mUnitKind = mui->mUnitKind;
room->mInterface = mui;
room->mDoorNum = mui->mDoorCount;
room->mDoorInfos = new RoomDoorInfo[room->mDoorNum];
room->mFlags = mui->_6E;
for (int i = 0; i < mui->mDoorCount; i++) {
Door* door = mui->getDoor(i);
WayPoint* wp = unit->mRouteMgr.getWayPoint(door->mWpIndex);
wp->mDoFloorSnap = 1;
wp->_76 = i;
}
int counter = 0;
Iterator<WayPoint> iterWP(&unit->mRouteMgr);
CI_LOOP(iterWP)
{
*iterWP;
counter++;
}
room->mWpIndices = new (-0x20) int[counter];
int nextIdx = 0;
CI_LOOP(iterWP)
{
WayPoint* wp = *iterWP; // r25
if (wp->mDoFloorSnap) {
RoomLink* targetLink = nullptr; // r23
FOREACH_NODE(RoomLink, link->mChild, linkNode)
{
if (linkNode->mLinkIndex == wp->_76) {
targetLink = linkNode;
break;
}
}
P2ASSERTLINE(3459, targetLink);
MapRoom* aliveRoom = getMapRoom(targetLink->mAliveMapIndex); // r21
Door* door = mui->getDoor(wp->_76); // r22
Vector3f doorDirs[4] = { (Vector3f) { 1.0f, 0.0f, 0.0f }, (Vector3f) { 0.0f, 0.0f, 1.0f }, (Vector3f) { 0.0f, 0.0f, 0.0f },
(Vector3f) { 0.0f, 1.0f, 0.0f } }; // 0x1B4
if (!aliveRoom) {
P2ASSERTBOOLLINE(3480, wp->mIndex >= 0 && wp->mIndex < counter);
WayPoint* newWP = new WayPoint();
static_cast<EditorRouteMgr*>(mRouteMgr)->addWayPoint(newWP);
room->mWpIndices[wp->mIndex] = newWP->mIndex;
newWP->mRadius = wp->mRadius;
newWP->mPosition = mtx1.mtxMult(wp->mPosition);
if (wp->mDoFloorSnap) {
newWP->mPosition.y = 0.0f;
} else {
newWP->mPosition.y = mapMgr->getMinY(newWP->mPosition);
}
wp = newWP;
} else {
WayPoint* newWP = aliveRoom->mUnit->mRouteMgr.getWayPoint(targetLink->mBirthDoorIndex); // r23
P2ASSERTLINE(3504, aliveRoom->mWpIndices);
room->mWpIndices[wp->mIndex] = aliveRoom->mWpIndices[newWP->mIndex];
wp = mRouteMgr->getWayPoint(room->mWpIndices[wp->mIndex]);
}
RoomDoorInfo* doorInfo = &room->mDoorInfos[nextIdx++];
doorInfo->mWaypoint = wp;
WayPoint::RoomList* roomList = new WayPoint::RoomList(room->mIndex);
wp->mRoomList.add(roomList);
Matrixf mtx2;
Vector3f rotation3(0.0f, faceAngle, 0.0f);
mtx2.makeTR(Vector3f::zero, rotation3);
doorInfo->mLookAtPos = mtx2.getBasis(3) + (Vector3f)(doorDirs[door->mDir]); // not right, just a placeholder
} else {
P2ASSERTBOOLLINE(3530, wp->mIndex >= 0 && wp->mIndex < counter);
WayPoint* newWP = new WayPoint();
static_cast<EditorRouteMgr*>(mRouteMgr)->addWayPoint(newWP);
room->mWpIndices[wp->mIndex] = newWP->mIndex;
newWP->mRadius = wp->mRadius;
newWP->mPosition = mtx1.mtxMult(wp->mPosition);
if (wp->mDoFloorSnap) {
newWP->mPosition.y = 0.0f;
} else {
newWP->mPosition.y = mapMgr->getMinY(newWP->mPosition);
}
WayPoint::RoomList* roomList = new WayPoint::RoomList(room->mIndex);
newWP->mRoomList.add(roomList);
}
}
CI_LOOP(iterWP)
{
WayPoint* wp1 = *iterWP; // r22
WayPoint* wp2 = mRouteMgr->getWayPoint(room->mWpIndices[wp1->mIndex]); // r24
if (wp1->mDoFloorSnap) {
int numFromLinks = wp2->mNumFromLinks;
if (wp2->mNumFromLinks == 0) {
wp2->mNumFromLinks = wp1->mNumFromLinks;
for (int i = 0; i < 8; i++) {
if (wp1->mFromLinks[i] == -1) {
wp2->mFromLinks[i] = -1;
} else {
wp2->mFromLinks[i] = room->mWpIndices[wp1->mFromLinks[i]];
}
}
} else {
for (int i = 0; i < wp1->mNumFromLinks; i++) {
int totalLinks = numFromLinks + i;
P2ASSERTLINE(3572, totalLinks < 8);
if (wp1->mFromLinks[i] == -1) {
wp2->mFromLinks[totalLinks] = -1;
} else {
wp2->mFromLinks[totalLinks] = room->mWpIndices[wp1->mFromLinks[i]];
}
}
wp2->mNumFromLinks += wp1->mNumFromLinks;
}
} else {
wp2->mNumFromLinks = wp1->mNumFromLinks;
for (int i = 0; i < 8; i++) {
if (wp1->mFromLinks[i] == -1) {
wp2->mFromLinks[i] = -1;
} else {
wp2->mFromLinks[i] = room->mWpIndices[wp1->mFromLinks[i]];
}
}
}
}
/*
.loc_0x0:
stwu r1, -0x2D0(r1)

View File

@ -35,7 +35,7 @@ void ObjectLayout::setNode(int idx, ObjectLayoutNode* layoutNode) { mNodeList[id
* Address: 80250900
* Size: 000048
*/
s32 ObjectLayout::getCount(int idx)
int ObjectLayout::getCount(int idx)
{
ObjectLayoutNode* node = mNodeList[idx];
return node ? node->getChildCount() : 0;
@ -46,10 +46,10 @@ s32 ObjectLayout::getCount(int idx)
* Address: 80250948
* Size: 000040
*/
CNode* ObjectLayout::getNode(int idx, int at)
ObjectLayoutNode* ObjectLayout::getNode(int idx, int at)
{
ObjectLayoutNode* node = mNodeList[idx];
return node ? node->getChildAt(at) : nullptr;
return node ? (ObjectLayoutNode*)node->getChildAt(at) : nullptr;
}
} // namespace Cave
} // namespace Game