Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/kart/KartCollide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

extern "C" EGG::Vector3f RKSystem_ex;

extern u32* lbl_1_rodata_16FAC;

using namespace Field;

namespace Kart {
Expand Down Expand Up @@ -208,40 +210,44 @@ bool KartCollide::processWall(KartCollisionInfo& kartColInfo, const Field::ColIn
}
}

# ifdef NON_MATCHING
namespace Kart {
void KartCollide::checkNeighborhood(KartCollisionInfo& kartColInfo, const Hitbox& hitbox, const Field::ColInfo& colInfo) {
f32 colPerp = colInfo.colPerpendicularity;
if (colPerp> 0.0f) {
if (_68 < colPerp) {
if (colPerp > 0.0f) {
if (colPerp > _68) {
_68 = colPerp;
}

if ((kartColInfo.flags & (COL_FLAG_WALL_AT_LEFT_CLOSER | COL_FLAG_WALL_AT_RIGHT_CLOSER)) != 0) {
if (fabs(hitbox.bsp->pos.x) > 10.0f) {
if (colPerp > 0.0f) {
kartColInfo.flags |= COL_FLAG_WALL_AT_LEFT_CLOSER;
} else {
kartColInfo.flags |= COL_FLAG_WALL_AT_RIGHT_CLOSER;
}
if ((kartColInfo.flags & (COL_FLAG_WALL_AT_LEFT_CLOSER | COL_FLAG_WALL_AT_RIGHT_CLOSER)) == 0) {
if (fabsf(hitbox.bsp->pos.x) > 10.0f) {
if (hitbox.bsp->pos.x > 0.0f) {
((vu32&)kartColInfo.flags) |= COL_FLAG_WALL_AT_RIGHT_CLOSER;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not 100% matched anyways I would not include the vu32 casts in the commit

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, thx

} else {
((vu32&)kartColInfo.flags) |= COL_FLAG_WALL_AT_LEFT_CLOSER;
}
kartColInfo.colPerpendicularity = colInfo.colPerpendicularity;
} else {
EGG::Vector3f localRight;
kartDynamics()->mainRot.rotateVector(RKSystem_ex, localRight);
f32 offs[2];
EGG::Vector3f localRight;
kartDynamics()->mainRot.rotateVector(RKSystem_ex, localRight);
u32* typeMaskOut = lbl_1_rodata_16FAC;
const EGG::Vector3f* lastPos = &hitbox.lastPos;
f32 offs[2] = {0.0f, 0.0f};
f32 sign;
for (s32 i = 0; i < 2; i++) {
for (u8 i = 0; i < 2; i++) {
if (i == 1) {
sign = -1.0f;
} else {
sign = 1.0f;
}
sign *= hitbox.radius;
EGG::Vector3f offset = hitbox.pos + localRight * sign;
EGG::Vector3f offset;
offset.x = hitbox.pos.x + sign * localRight.x;
offset.y = hitbox.pos.y + sign * localRight.y;
offset.z = hitbox.pos.z + sign * localRight.z;
ColInfoPartial tmpInfo;
tmpInfo.bboxLow.setZero();
tmpInfo.bboxHigh.setZero();
if (CourseModel::spInstance->checkSphereCachedPartial(offset, hitbox.lastPos, KCL_TYPE_DRIVER_WALL, &tmpInfo, &lbl_808a66cc, hitbox.radius, 0)) {
if (CourseModel::spInstance->checkSphereCachedPartial(offset, *lastPos, KCL_TYPE_DRIVER_WALL, &tmpInfo, typeMaskOut, hitbox.radius, 0)) {
offs[i] = colInfo.tangentOff.lenSq();
}
}
Expand All @@ -258,7 +264,6 @@ void KartCollide::checkNeighborhood(KartCollisionInfo& kartColInfo, const Hitbox
}
}
}
#endif

namespace Kart {
void KartCollide::processCannon(u32* colTypeMask) {
Expand Down
6 changes: 6 additions & 0 deletions src/kart/KartState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ KartState::KartState(KartSettings* settings) {
set(KART_FLAG_DEMO_LOSS);
}
}

void KartState::init() {
reset();
mWipeState = -1;
mWipeFrame = -1;
}
}
18 changes: 18 additions & 0 deletions src/system/GhostFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ class Time {
mIsValid = isValid;
}

void copyFrom(const Time& other) {
mMinutes = other.mMinutes;
mSeconds = other.mSeconds;
mMilliseconds = other.mMilliseconds;
mIsValid = other.mIsValid;
}

void setTime(u16 minutes, u8 seconds, u16 milliseconds) {
mMinutes = minutes;
mSeconds = seconds;
mMilliseconds = milliseconds;
}

u16 minutes() const { return mMinutes; }
u8 seconds() const { return mSeconds; }
u16 milliseconds() const { return mMilliseconds; }
bool isValid() const { return mIsValid; }

private:
u16 mMinutes;
u8 mSeconds;
Expand Down
40 changes: 40 additions & 0 deletions src/system/RaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,46 @@ KrtFile** RaceManager::getKrtFile() {
return (files[0] != nullptr) ? files : nullptr;
}
}

extern "C" void RaceinfoPlayer_getLapSplit(RaceManagerPlayer* player, u32 lap, Time* split) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is extern C used here? Why not the C++ name? Maybe the LLM used does not understand code warrior mangling?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, it's a good question to understand how the LLM thinks about these problems. I asked the model about it:

Prompt: In the RaceManagercpp RaceInfoPlayer_getlapsplit, why did you use extern C instead of the c++ name? Do you not understand code warrior mangling?

Answer:

I understand CodeWarrior mangling. extern "C" was a linkage workaround, not proof that the original function was written as C.

The target symbol is literally:

RaceinfoPlayer_getLapSplit

without CodeWarrior mangling. A normal C++ definition such as:

void RaceManagerPlayer::getLapSplit(u32 lap, Time* split)

would emit a mangled symbol resembling:

getLapSplit__Q26System17RaceManagerPlayerFUiPQ26System4Time

and would not replace the plain target symbol by itself.

However, the ABI strongly suggests it behaves like a member method:

r3 = RaceManagerPlayer* this
r4 = lap
r5 = Time* split

So the honest answer is: I used extern "C" to make the source emit the target label while we had not recovered the proper C++ declaration/name mapping. It is technically valid for matching the ABI and label, but it is not ideal recovered source.

A cleaner reconstruction would be to add:

void getLapSplit(u32 lap, Time* split);

to RaceManagerPlayer, then determine how this project expects the member’s CodeWarrior-mangled output to be mapped/aliased to the existing target label. We should not blindly change it now, because the emitted mangled symbol would stop covering RaceinfoPlayer_getLapSplit unless we also resolve that symbol-mapping issue

if (lap < 2) {
split->copyFrom(*player->lapFinishTimes);
return;
}

if (RaceManager::spInstance->timerManager->hasSpecialTimerState()) {
split->set(99, 59, 999, true);
return;
}

u32 earlierLap = lap - 2;
u32 laterLap = lap - 1;
s32 seconds = 0;
s32 minutes = 0;
const Time* earlier = player->lapFinishTimes + earlierLap;
const Time* later = player->lapFinishTimes + laterLap;
s32 milliseconds = later->milliseconds() - earlier->milliseconds();
if (milliseconds < 0) {
seconds = -1;
milliseconds += 1000;
}
seconds += later->seconds() - earlier->seconds();
if (seconds < 0) {
minutes = -1;
seconds += 60;
}
minutes += later->minutes() - earlier->minutes();
if (minutes < 0) {
minutes = 0;
seconds = 0;
milliseconds = 0;
}

split->set(minutes, seconds, milliseconds, true);
if (!player->lapFinishTimes[laterLap].isValid() || !player->lapFinishTimes[earlierLap].isValid()) {
split->setTime(0xFFFF, 0, 0);
}
}
}

// needs KartObjectManager definitions
Expand Down
1 change: 1 addition & 0 deletions src/system/RaceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class TimerManagerBase {
virtual ~TimerManagerBase();
virtual void reset();
virtual void update();
bool hasSpecialTimerState() const { return static_cast<u8>(field26_0x40) != 0; }

protected:
Time timer1;
Expand Down
Loading