From 6d20dc6eff2ec8d8ba3fb84750a37d8a25f334c1 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Tue, 4 Aug 2026 20:12:36 +0100 Subject: [PATCH] LapGhost2D: Add class implementation. --- configure.py | 2 +- include/Kameda/LapGhost2D.h | 41 +++++++--- include/Osako/KartPadRecord.h | 4 +- src/Kameda/LapGhost2D.cpp | 148 ++++++++++++++++++++++++++++++++-- 4 files changed, 175 insertions(+), 20 deletions(-) diff --git a/configure.py b/configure.py index 8ca49072..0776b4f5 100755 --- a/configure.py +++ b/configure.py @@ -1116,7 +1116,7 @@ def MatchingFor(*versions): Object(NonMatching, "Kameda/SceneLanEntry.cpp"), Object(NonMatching, "Kameda/SceneMapSelect.cpp"), Object(Matching, "Kameda/BattleName2D.cpp"), - Object(NonMatching, "Kameda/LapGhost2D.cpp"), + Object(Matching, "Kameda/LapGhost2D.cpp"), Object(Matching, "Kameda/CanNotSaveG2D.cpp"), Object(Matching, "Kameda/LANResult2D.cpp"), Object(NonMatching, "Kameda/LANNum2D.cpp"), diff --git a/include/Kameda/LapGhost2D.h b/include/Kameda/LapGhost2D.h index 579c84c6..88676f3f 100644 --- a/include/Kameda/LapGhost2D.h +++ b/include/Kameda/LapGhost2D.h @@ -1,18 +1,39 @@ #ifndef LAPGHOST2D_H #define LAPGHOST2D_H +#include "JSystem/J2D/J2DGrafContext.h" +#include "JSystem/J2D/J2DPicture.h" +#include "JSystem/J2D/J2DScreen.h" #include "JSystem/JKernel/JKRHeap.h" #include "Kaneshige/RaceTime.h" -class LapGhost2D { // Autogenerated +class LapGhost2D +{ public: - LapGhost2D(JKRHeap *); // 0x801949c4 - void init(); // 0x80194b58 - void draw(); // 0x80194bac - void calc(); // 0x80194c38 - void start(RaceTime, int); // 0x80194d08 - // Inline/Unused - ~LapGhost2D(); -}; // class LapGhost2D -#endif // LAPGHOST2D_H + LapGhost2D(JKRHeap *heap); // 0x801949c4 + ~LapGhost2D(); // Unused + + void init(); // 0x80194b58 + void draw(); // 0x80194bac + void calc(); // 0x80194c38 + void start(RaceTime raceTime, int lap); // 0x80194d08 + +private: + J2DAnmTransform *mTransform; // 0x00 + u32 _4; // 0x04 + f32 mTransformFrame; // 0x08 + + J2DAnmTevRegKey *mTevRegKey; // 0x0c + u32 _10; // 0x10 + f32 mTevRegKeyFrame; // 0x14 + + J2DGrafContext *mGrafContext; // 0x18 + J2DScreen *mScreen; // 0x1c + + J2DPicture *mPictures[8]; // 0x20 + + bool mVisible[2]; // 0x40 +}; + +#endif // LAPGHOST2D_H diff --git a/include/Osako/KartPadRecord.h b/include/Osako/KartPadRecord.h index d50ddad8..0221970f 100644 --- a/include/Osako/KartPadRecord.h +++ b/include/Osako/KartPadRecord.h @@ -59,11 +59,11 @@ class KartPadRecord : public TARecord mLapSplits[lap] = other; } - void calcLapTime(int lap, RaceTime nextSplit) + const RaceTime& getLapSplit(int lap) const { #line 109 JUT_MINMAX_ASSERT(0, lap, NUM_LAP_SPLITS) - nextSplit.sub(nextSplit, mLapSplits[lap]); + return mLapSplits[lap]; } private: diff --git a/src/Kameda/LapGhost2D.cpp b/src/Kameda/LapGhost2D.cpp index a51121fc..a38a5bb2 100644 --- a/src/Kameda/LapGhost2D.cpp +++ b/src/Kameda/LapGhost2D.cpp @@ -1,14 +1,148 @@ #include "Kameda/LapGhost2D.h" -#include "mathHelper.h" -LapGhost2D::LapGhost2D(JKRHeap *) {} +#include "JSystem/J2D/J2DAnmLoader.h" +#include "JSystem/J2D/J2DPane.h" +#include "JSystem/JAudio/JASFakeMatch2.h" // For static initializer +#include "JSystem/JKernel/JKRArchive.h" +#include "JSystem/JKernel/JKRFileLoader.h" +#include "JSystem/JUtility/JUTAssert.h" +#include "Kameda/J2DManager.h" +#include "Kaneshige/RaceMgr.h" +#include "Osako/GhostFile.h" +#include "Osako/Kart2DCommon.h" +#include "Osako/KartPadRecord.h" +#include "Osako/system.h" +#include "mathHelper.h" // For unused data -void LapGhost2D::init() {} +LapGhost2D::LapGhost2D(JKRHeap *heap) +{ + mGrafContext = System::getJ2DOrtho(); + mScreen = new (heap, 0) J2DScreen(); -void LapGhost2D::draw() {} + mScreen->J2DScreen::set("LapGhost.blo", 0x40000, J2DManager::getManager()->getArchive()); -void LapGhost2D::calc() {} + mTransform = (J2DAnmTransform *)J2DAnmLoaderDataBase::load( + JKRFileLoader::getGlbResource("LapGhost.bck", J2DManager::getManager()->getArchive())); + mScreen->setAnimation(mTransform); -void LapGhost2D::start(RaceTime, int) {} + mTevRegKey = (J2DAnmTevRegKey *)J2DAnmLoaderDataBase::load( + JKRFileLoader::getGlbResource("LapGhost.brk", J2DManager::getManager()->getArchive())); + mTevRegKey->searchUpdateMaterialID(mScreen); + mScreen->setAnimation(mTevRegKey); -#include "JSystem/JAudio/JASFakeMatch2.h" + for (int i = 0; i < 8; ++i) + { + J2DPicture *pane = (J2DPicture *)mScreen->search('GhTime0' + i); +#line 60 + JUT_ASSERT(pane->getTypeID() == J2DPane_Picture); + + mPictures[i] = pane; + } + + init(); +} + +void LapGhost2D::init() +{ + mTransformFrame = 0.0f; + mTevRegKeyFrame = 0.0f; + + mVisible[0] = false; + mVisible[1] = false; + + mTransform->setFrame(mTransformFrame); + mTevRegKey->setFrame(mTevRegKeyFrame); + + mScreen->animation(); +} + +LapGhost2D::~LapGhost2D() {} + +void LapGhost2D::draw() +{ + if (mVisible[0]) + { + ERacePhase racePhase = RCMGetManager()->getRacePhase(); + if (racePhase != PHASE_CRS_DEMO) + { + RaceMgr *raceMgr = RCMGetManager(); + if (!raceMgr->isReplayMode() && !raceMgr->mRaceInfo->isWaitDemo()) + { + mGrafContext->setPort(); + mScreen->draw(0.0f, 0.0f, mGrafContext); + } + } + } +} + +void LapGhost2D::calc() +{ + if (mVisible[0]) + { + if (mTransformFrame < 130.0f) + { + mTransform->setFrame(mTransformFrame); + mTevRegKey->setFrame(mTevRegKeyFrame); + + mTransformFrame += 1.0f; + + if (mVisible[1]) + { + if (++mTevRegKeyFrame >= 20.0f) + { + mTevRegKeyFrame = 0.0f; + } + } + + mScreen->animation(); + } + else + { + mTransformFrame = 0.0f; + mTevRegKeyFrame = 0.0f; + + mVisible[0] = false; + mVisible[1] = false; + + mTransform->setFrame(mTransformFrame); + mTevRegKey->setFrame(mTevRegKeyFrame); + + mScreen->animation(); + } + } +} + +void LapGhost2D::start(RaceTime raceTime, int lap) +{ + KartPadRecord &padRecord = gGhostFile.mFileData.mPadRecord; + + if (gGhostFile.isValidGhostOnRace()) + { + if (padRecord.isFrameValid()) + { + mVisible[0] = true; + + Kart2DCommon *kart2DCommon = Kart2DCommon::ptr(); + + raceTime.sub(padRecord.getLapSplit(lap).get()); + + int minutes, seconds, milliseconds; + raceTime.get(&minutes, &seconds, &milliseconds); + + if (raceTime.get() < 0) + { + mPictures[7]->changeTexture(kart2DCommon->getAsciiTexture('-'), 0); + mVisible[1] = true; + } + else + { + mPictures[7]->changeTexture(kart2DCommon->getAsciiTexture('+'), 0); + mVisible[1] = false; + } + + kart2DCommon->changeNumberTexture(minutes, &mPictures[5], 2, true, false); + kart2DCommon->changeNumberTexture(seconds, &mPictures[3], 2, true, false); + kart2DCommon->changeNumberTexture(milliseconds, &mPictures[0], 3, true, false); + } + } +}