Skip to content

Commit

Permalink
Implement raceCompletion and bump KRKGs version to 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
malleoz committed Dec 17, 2024
1 parent 4c73a1d commit 22180e3
Show file tree
Hide file tree
Showing 65 changed files with 164 additions and 8 deletions.
Binary file modified samples/bc-ng-rta-2-20-001.krkg
Binary file not shown.
Binary file modified samples/bc-rta-2-08-697.krkg
Binary file not shown.
Binary file modified samples/cm-ng-rta-1-55-264.krkg
Binary file not shown.
Binary file modified samples/cm-rta-0-25-145.krkg
Binary file not shown.
Binary file modified samples/dc-rta-1-28-321.krkg
Binary file not shown.
Binary file modified samples/ddr-rta-1-46-400.krkg
Binary file not shown.
Binary file modified samples/dks-rta-1-44-568.krkg
Binary file not shown.
Binary file modified samples/gv-ng-rta-1-32-914.krkg
Binary file not shown.
Binary file modified samples/gv-nosc-rta-1-50-927.krkg
Binary file not shown.
Binary file modified samples/gv-rta-0-15-425.krkg
Binary file not shown.
Binary file modified samples/kc-ng-rta-2-17-176.krkg
Binary file not shown.
Binary file modified samples/kc-rta-1-55-250.krkg
Binary file not shown.
Binary file modified samples/lc-rta-1-08-733.krkg
Binary file not shown.
Binary file modified samples/mc-ng-rta-1-20-357.krkg
Binary file not shown.
Binary file modified samples/mc-rta-0-46-553.krkg
Binary file not shown.
Binary file modified samples/mg-ng-rta-1-40-273.krkg
Binary file not shown.
Binary file modified samples/mg-rta-0-19-758.krkg
Binary file not shown.
Binary file modified samples/mh-rta-1-42-872.krkg
Binary file not shown.
Binary file modified samples/mmm-rta-1-15-273.krkg
Binary file not shown.
Binary file modified samples/mt-ng-rta-2-13-126.krkg
Binary file not shown.
Binary file modified samples/mt-rta-1-33-239.krkg
Binary file not shown.
Binary file modified samples/rbc-ng-rta-2-30-459.krkg
Binary file not shown.
Binary file modified samples/rbc-rta-2-17-997.krkg
Binary file not shown.
Binary file modified samples/rbc3-ng-rta-2-16-183.krkg
Binary file not shown.
Binary file modified samples/rbc3-rta-1-55-715.krkg
Binary file not shown.
Binary file modified samples/rdh-ng-rta-1-34-237.krkg
Binary file not shown.
Binary file modified samples/rdh-rta-1-30-425.krkg
Binary file not shown.
Binary file modified samples/rdkjp-ng-rta-2-09-321.krkg
Binary file not shown.
Binary file modified samples/rdkjp-nosc-rta-2-10-546.krkg
Binary file not shown.
Binary file modified samples/rdkjp-rta-0-40-105.krkg
Binary file not shown.
Binary file modified samples/rdkm-ng-rta-2-04-775.krkg
Binary file not shown.
Binary file modified samples/rdkm-rta-1-58-133.krkg
Binary file not shown.
Binary file modified samples/rds-rta-2-03-525.krkg
Binary file not shown.
Binary file modified samples/rgv2-ng-rta-0-52-746.krkg
Binary file not shown.
Binary file modified samples/rgv2-rta-0-49-992.krkg
Binary file not shown.
Binary file modified samples/rmc-ng-rta-1-30-272.krkg
Binary file not shown.
Binary file modified samples/rmc-rta-1-29-945.krkg
Binary file not shown.
Binary file modified samples/rmc3-kierio-test-3-24-416.krkg
Binary file not shown.
Binary file modified samples/rmc3-rta-1-17-843.krkg
Binary file not shown.
Binary file modified samples/rmr-rta-1-41-193.krkg
Binary file not shown.
Binary file modified samples/rpb-ng-rta-1-12-656.krkg
Binary file not shown.
Binary file modified samples/rpb-rta-0-59-978.krkg
Binary file not shown.
Binary file modified samples/rpg-rta-1-58-890.krkg
Binary file not shown.
Binary file modified samples/rr-ng-rta-2-24-281.krkg
Binary file not shown.
Binary file modified samples/rr-rta-1-24-751.krkg
Binary file not shown.
Binary file modified samples/rsgb-ng-rta-1-21-363.krkg
Binary file not shown.
Binary file modified samples/rsgb-rta-1-14-513.krkg
Binary file not shown.
Binary file modified samples/rsl-ng-rta-2-03-750.krkg
Binary file not shown.
Binary file modified samples/rsl-rta-1-12-225.krkg
Binary file not shown.
Binary file modified samples/rws-ng-rta-1-48-193.krkg
Binary file not shown.
Binary file modified samples/rws-rta-1-31-987.krkg
Binary file not shown.
Binary file modified samples/ryf-rta-0-58-648.krkg
Binary file not shown.
Binary file modified samples/tf-ng-rta-1-49-039.krkg
Binary file not shown.
Binary file modified samples/tf-rta-1-44-178.krkg
Binary file not shown.
Binary file modified samples/wgm-ng-rta-1-49-934.krkg
Binary file not shown.
Binary file modified samples/wgm-rta-0-31-678.krkg
Binary file not shown.
4 changes: 4 additions & 0 deletions source/game/system/CourseMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ MapdataCheckPathAccessor *CourseMap::checkPath() const {
return m_checkPath;
}

MapdataCheckPointAccessor *CourseMap::checkPoint() const {
return m_checkPoint;
}

f32 CourseMap::startTmpAngle() const {
return m_startTmpAngle;
}
Expand Down
1 change: 1 addition & 0 deletions source/game/system/CourseMap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public:
[[nodiscard]] u16 getGeoObjCount() const;
[[nodiscard]] u32 version() const;
[[nodiscard]] MapdataCheckPathAccessor *checkPath() const;
[[nodiscard]] MapdataCheckPointAccessor *checkPoint() const;
[[nodiscard]] f32 startTmpAngle() const;
[[nodiscard]] f32 startTmp0() const;
[[nodiscard]] f32 startTmp1() const;
Expand Down
92 changes: 88 additions & 4 deletions source/game/system/RaceManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,20 @@ RaceManager::~RaceManager() {
/// @addr{0x80533ED8}
RaceManager::Player::Player() {
m_checkpointId = 0;
m_raceCompletion = 0.0f;
m_checkpointFactor = -1.0f;
m_checkpointStartLapCompletion = 0.0f;
m_lapCompletion = 0.999999f;

auto *courseMap = CourseMap::Instance();

if (courseMap->getCheckPointCount() > 0 && courseMap->getCheckPathCount() > 0) {
m_maxKcp = courseMap->checkPoint()->lastKcpType();
} else {
m_maxKcp = -1;
}

m_currentLap = 0;
m_inputs = &KPadDirector::Instance()->playerInput();
}

Expand Down Expand Up @@ -150,24 +163,76 @@ void RaceManager::Player::calc() {
if (m_checkpointFactor < 0.0f || m_checkpointId != checkpointId) {
calcCheckpoint(checkpointId, distanceRatio);
}

m_raceCompletion = static_cast<f32>(m_currentLap) +
(m_checkpointStartLapCompletion + m_checkpointFactor * distanceRatio);
m_raceCompletion = std::min(m_raceCompletion, static_cast<f32>(m_currentLap) + 0.99999f);
}

u16 RaceManager::Player::checkpointId() const {
return m_checkpointId;
}

f32 RaceManager::Player::raceCompletion() const {
return m_raceCompletion;
}

s8 RaceManager::Player::jugemId() const {
return m_jugemId;
}

const KPad *RaceManager::Player::inputs() const {
return m_inputs;
}

/// @addr{0x80534DF8}
MapdataCheckPoint *RaceManager::Player::calcCheckpoint(u16 checkpointId, f32 /*distanceRatio*/) {
MapdataCheckPoint *RaceManager::Player::calcCheckpoint(u16 checkpointId, f32 distanceRatio) {
auto *courseMap = CourseMap::Instance();

u16 oldCheckpointId = m_checkpointId;
m_checkpointId = checkpointId;

f32 lapProportion = courseMap->checkPath()->lapProportion();
MapdataCheckPath *checkPath = courseMap->checkPath()->findCheckpathForCheckpoint(checkpointId);
m_checkpointFactor = checkPath->oneOverCount() * courseMap->checkPath()->lapProportion();
m_checkpointFactor = checkPath->oneOverCount() * lapProportion;

m_checkpointStartLapCompletion = static_cast<f32>(checkPath->depth()) * lapProportion +
(m_checkpointFactor * static_cast<f32>(checkpointId - checkPath->start()));

f32 deltaLapCompletion =
m_lapCompletion - (m_checkpointStartLapCompletion + distanceRatio * m_checkpointFactor);

return courseMap->getCheckPoint(checkpointId);
MapdataCheckPoint *newCheckpoint = courseMap->getCheckPoint(checkpointId);
const MapdataCheckPoint *oldCheckpoint = courseMap->getCheckPoint(oldCheckpointId);

s8 newJugemIdx = newCheckpoint->jugemIndex();
if (newJugemIdx >= 0) {
m_jugemId = newJugemIdx;
}

if (!newCheckpoint->isNormalCheckpoint()) {
if (newCheckpoint->checkArea() > m_maxKcp) {
m_maxKcp = newCheckpoint->checkArea();
} else if (m_maxKcp == courseMap->checkPoint()->lastKcpType()) {
if ((newCheckpoint->isFinishLine() &&
areCheckpointsSubsequent(oldCheckpoint, checkpointId)) ||
deltaLapCompletion > 0.95f) {
incrementLap();
}
}
}

if ((oldCheckpoint->isFinishLine() &&
areCheckpointsSubsequent(newCheckpoint, oldCheckpointId)) ||
deltaLapCompletion < -0.95f) {
decrementLap();
}

return newCheckpoint;
}

/// @addr{Inlined in 0x80534DF8}
bool RaceManager::Player::areCheckpointsSubsequent(MapdataCheckPoint *checkpoint,
bool RaceManager::Player::areCheckpointsSubsequent(const MapdataCheckPoint *checkpoint,
u16 nextCheckpointId) const {
for (size_t i = 0; i < checkpoint->nextCount(); ++i) {
if (nextCheckpointId == checkpoint->nextPoint(i)->id()) {
Expand All @@ -178,6 +243,25 @@ bool RaceManager::Player::areCheckpointsSubsequent(MapdataCheckPoint *checkpoint
return false;
}

/// @addr{0x80534D6C}
void RaceManager::Player::decrementLap() {
auto *courseMap = CourseMap::Instance();

if (courseMap->getCheckPointCount() > 0 && courseMap->getCheckPathCount() > 0) {
m_maxKcp = courseMap->checkPoint()->lastKcpType();
} else {
m_maxKcp = -1;
}

--m_currentLap;
}

/// @addr{0x805349B8}
void RaceManager::Player::incrementLap() {
m_maxKcp = 0;
++m_currentLap;
}

RaceManager *RaceManager::s_instance = nullptr; ///< @addr{0x809BD730}

} // namespace System
17 changes: 15 additions & 2 deletions source/game/system/RaceManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,29 @@ public:
void init();
void calc();

/// @beginGetters
[[nodiscard]] u16 checkpointId() const;
[[nodiscard]] f32 raceCompletion() const;
[[nodiscard]] s8 jugemId() const;
[[nodiscard]] const KPad *inputs() const;
/// @endGetters

private:
MapdataCheckPoint *calcCheckpoint(u16 checkpointId, f32 distanceRatio);
[[nodiscard]] bool areCheckpointsSubsequent(MapdataCheckPoint *checkpoint,
[[nodiscard]] bool areCheckpointsSubsequent(const MapdataCheckPoint *checkpoint,
u16 nextCheckpointId) const;

void decrementLap();
void incrementLap();

u16 m_checkpointId;
f32 m_raceCompletion;
f32 m_checkpointFactor; ///< The proportion of a lap for the current checkpoint
u8 m_jugemId;
f32 m_checkpointStartLapCompletion;
f32 m_lapCompletion;
s8 m_jugemId;
s16 m_currentLap;
s8 m_maxKcp;
const KPad *m_inputs;
};

Expand Down
6 changes: 5 additions & 1 deletion source/game/system/map/MapdataCheckPoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void MapdataCheckPoint::clearSearched() {
bool MapdataCheckPoint::searched() const {
return m_searched;
}
u8 MapdataCheckPoint::jugemIndex() const {
s8 MapdataCheckPoint::jugemIndex() const {
return m_jugemIndex;
}

Expand Down Expand Up @@ -219,6 +219,10 @@ MapdataCheckPointAccessor::MapdataCheckPointAccessor(const MapSectionHeader *hea

MapdataCheckPointAccessor::~MapdataCheckPointAccessor() = default;

s8 MapdataCheckPointAccessor::lastKcpType() const {
return m_lastKcpType;
}

/// @addr{0x80515244}
/// @brief Initializes all checkpoint links, and finds the finish line and last key checkpoint.
void MapdataCheckPointAccessor::init() {
Expand Down
4 changes: 3 additions & 1 deletion source/game/system/map/MapdataCheckPoint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public:

/// @beginGetters
[[nodiscard]] bool searched() const;
[[nodiscard]] u8 jugemIndex() const;
[[nodiscard]] s8 jugemIndex() const;
[[nodiscard]] s8 checkArea() const;
[[nodiscard]] u16 nextCount() const;
[[nodiscard]] u16 prevCount() const;
Expand Down Expand Up @@ -105,6 +105,8 @@ public:
MapdataCheckPointAccessor(const MapSectionHeader *header);
~MapdataCheckPointAccessor() override;

[[nodiscard]] s8 lastKcpType() const;

private:
void init();

Expand Down
4 changes: 4 additions & 0 deletions source/test/Test.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ struct TestData {
// Added in 0.5
EGG::Quatf mainRot;
EGG::Vector3f angVel2;
// Added in 0.6
f32 raceCompletion;
u16 checkpointId;
u8 jugemId;
};

} // namespace Test
26 changes: 26 additions & 0 deletions source/test/TestDirector.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "TestDirector.hh"

#include <game/kart/KartObjectManager.hh>
#include <game/system/RaceManager.hh>

#include <abstract/File.hh>
#include <host/System.hh>
Expand All @@ -17,6 +18,7 @@ enum Changelog {
AddedIntVel = 3,
AddedSpeed = 4,
AddedRotation = 5,
AddedCheckpoints = 6,
};

TestDirector::TestDirector(const std::span<u8> &suiteData) {
Expand Down Expand Up @@ -131,7 +133,17 @@ void TestDirector::test(const TestData &data) {
const auto &mainRot = object->mainRot();
const auto &angVel2 = object->angVel2();

const auto &player = System::RaceManager::Instance()->player();
f32 raceCompletion = player.raceCompletion();
u16 checkpointId = player.checkpointId();
u8 jugemId = player.jugemId();

switch (m_versionMinor) {
case Changelog::AddedCheckpoints:
checkDesync(data.raceCompletion, raceCompletion, "raceCompletion");
checkDesync(data.checkpointId, checkpointId, "checkpointId");
checkDesync(data.jugemId, jugemId, "jugemId");
[[fallthrough]];
case Changelog::AddedRotation:
checkDesync(data.mainRot, mainRot, "mainRot");
checkDesync(data.angVel2, angVel2, "angVel2");
Expand Down Expand Up @@ -182,6 +194,10 @@ TestData TestDirector::findNextEntry() {
f32 softSpeedLimit = 0.0f;
EGG::Quatf mainRot;
EGG::Vector3f angVel2;
f32 raceCompletion = 0.0f;
u16 checkpointId = 0;
u8 jugemId = 0;

pos.read(m_stream);
fullRot.read(m_stream);

Expand All @@ -204,6 +220,13 @@ TestData TestDirector::findNextEntry() {
angVel2.read(m_stream);
}

if (m_versionMinor >= Changelog::AddedCheckpoints) {
raceCompletion = m_stream.read_f32();
checkpointId = m_stream.read_u16();
jugemId = m_stream.read_u8();
m_stream.skip(1);
}

TestData data;
data.pos = pos;
data.fullRot = fullRot;
Expand All @@ -214,6 +237,9 @@ TestData TestDirector::findNextEntry() {
data.softSpeedLimit = softSpeedLimit;
data.mainRot = mainRot;
data.angVel2 = angVel2;
data.raceCompletion = raceCompletion;
data.checkpointId = checkpointId;
data.jugemId = jugemId;
return data;
}

Expand Down
18 changes: 18 additions & 0 deletions source/test/TestDirector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ public:
private:
void readHeader();

template <IntegralType T>
void checkDesync(const T &t0, const T &t1, const char *name) {
if (t0 == t1) {
return;
}

if (m_sync) {
REPORT("Test Case Failed: %s [%d / %d]", testCase().name.c_str(), m_currentFrame,
m_frameCount);
}

REPORT("DESYNC! Name: %s", name);
REPORT("Expected: %d", t0);
REPORT("Observed: %d", t1);

m_sync = false;
}

template <typename T>
void checkDesync(const T &t0, const T &t1, const char *name) {
if (t0 == t1) {
Expand Down

0 comments on commit 22180e3

Please sign in to comment.