Skip to content

Commit

Permalink
Support multiple test cases in one instance
Browse files Browse the repository at this point in the history
  • Loading branch information
malleoz committed Apr 18, 2024
1 parent 8b0db73 commit 4d2e55a
Show file tree
Hide file tree
Showing 45 changed files with 269 additions and 88 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Kinoko

[![Luke's rMC3 RTA WR](<https://vabold.github.io/Kinoko/Luke rMC3 RTA WR.svg>)](<https://vabold.github.io/Kinoko/Luke rMC3 RTA WR.svg>)
[![Luke's rMC3 RTA WR](<https://vabold.github.io/Kinoko/Luke rMC3 RTA WR.svg>)](https://www.youtube.com/watch?v=6H6UnSDPPdI)
[![Kasey's LC RTA WR](<https://vabold.github.io/Kinoko/Kasey LC RTA WR.svg>)](https://www.youtube.com/watch?v=HPcvNS8QFVI)

Kinoko is a reimplementation of Mario Kart Wii's physics engine in C++. This project is a spiritual continuation of [stblr/Hanachan](https://github.com/stblr/Hanachan). Like Hanachan, the goal of this reimplementation is to reach perfectly accurate ghost replay.

Expand Down
Binary file added samples/lc-rta-1-08-733.krkg
Binary file not shown.
Binary file added samples/lc-rta-1-08-733.rkg
Binary file not shown.
14 changes: 14 additions & 0 deletions source/abstract/List.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ void List::append(void *data) {
m_tail = node;
}

void List::remove(Node *node) {
if (m_head == node) {
m_head = node->m_next;
} else {
node->m_prev->m_next = node->m_next;
}

if (!node->m_next) {
m_tail = node->m_prev;
} else {
node->m_next->m_prev = node->m_prev;
}
}

} // namespace Abstract
1 change: 1 addition & 0 deletions source/abstract/List.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public:
Node *getNext(Node *node) const;

void append(void *data);
void remove(Node *node);

private:
Node *m_head;
Expand Down
8 changes: 5 additions & 3 deletions source/egg/core/Archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace EGG {

Archive::~Archive() = default;
Archive::~Archive() {
s_archiveList.erase(s_archiveList.begin() + m_vectorIdx);
}

void Archive::unmount() {
if (--m_refCount == 0) {
Expand Down Expand Up @@ -42,13 +44,13 @@ Archive *Archive::Mount(void *archiveStart) {
archive->m_refCount++;
} else {
// Create a new archive and add it to the vector
archive = new Archive(archiveStart);
archive = new Archive(archiveStart, s_archiveList.size());
s_archiveList.push_back(archive);
}

return archive;
}

Archive::Archive(void *archiveStart) : m_handle(archiveStart) {}
Archive::Archive(void *archiveStart, size_t idx) : m_handle(archiveStart), m_vectorIdx(idx) {}

} // namespace EGG
4 changes: 2 additions & 2 deletions source/egg/core/Archive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public:
static Archive *Mount(void *archiveStart);

private:
Archive(void *archiveStart);
Archive(void *archiveStart, size_t idx);

Abstract::ArchiveHandle m_handle;
size_t m_vectorIdx = -1;
size_t m_vectorIdx;
s32 m_refCount = 1;
};

Expand Down
4 changes: 4 additions & 0 deletions source/egg/util/Stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ void RamStream::setBufferAndSize(void *buffer, u32 size) {
m_size = size;
}

u8 *RamStream::data() {
return m_buffer;
}

RamStream RamStream::split(u32 size) {
RamStream stream = RamStream(m_buffer + m_index, size);
m_index += size;
Expand Down
1 change: 1 addition & 0 deletions source/egg/util/Stream.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public:
std::string read_string();
RamStream split(u32 size);
void setBufferAndSize(void *buffer, u32 size);
u8 *data();

private:
u8 *m_buffer;
Expand Down
15 changes: 10 additions & 5 deletions source/game/kart/CollisionGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ void CollisionData::reset() {
floor = false;
}

Hitbox::Hitbox() : m_bspHitbox(nullptr) {}
Hitbox::Hitbox() : m_bspHitbox(nullptr), m_ownsBSP(false) {}

Hitbox::~Hitbox() = default;
Hitbox::~Hitbox() {
if (m_ownsBSP) {
delete m_bspHitbox;
}
}

void Hitbox::calc(f32 param_1, f32 totalScale, const EGG::Vector3f &scale, const EGG::Quatf &rot,
const EGG::Vector3f &pos) {
Expand All @@ -45,7 +49,8 @@ void Hitbox::setRadius(f32 radius) {
m_radius = radius;
}

void Hitbox::setBspHitbox(const BSP::Hitbox *hitbox) {
void Hitbox::setBspHitbox(const BSP::Hitbox *hitbox, bool owns) {
m_ownsBSP = owns;
m_bspHitbox = hitbox;
}

Expand Down Expand Up @@ -149,14 +154,14 @@ f32 CollisionGroup::computeCollisionLimits() {
}

void CollisionGroup::createSingleHitbox(f32 radius, const EGG::Vector3f &relPos) {
m_hitboxes = new std::span<Hitbox>(new Hitbox, 1);
m_hitboxes = new std::span<Hitbox>(new Hitbox[1], 1);

// TODO: Do we need for loop if this is just one?
// And how exactly will we identify to free the BSP::Hitbox on destruction?
for (auto &hitbox : *m_hitboxes) {
hitbox.reset();
BSP::Hitbox *bspHitbox = new BSP::Hitbox;
hitbox.setBspHitbox(bspHitbox);
hitbox.setBspHitbox(bspHitbox, true);
bspHitbox->position = relPos;
bspHitbox->radius = radius;
hitbox.setRadius(radius);
Expand Down
4 changes: 3 additions & 1 deletion source/game/kart/CollisionGroup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public:
void reset();
void setScale(f32 scale);
void setRadius(f32 radius);
void setBspHitbox(const BSP::Hitbox *hitbox);
void setBspHitbox(const BSP::Hitbox *hitbox, bool owns = false);
void setWorldPos(const EGG::Vector3f &pos);
void setLastPos(const EGG::Vector3f &pos);
void setLastPos(const EGG::Vector3f &scale, const EGG::Matrix34f &pose);
Expand All @@ -56,6 +56,8 @@ private:
EGG::Vector3f m_worldPos;
EGG::Vector3f m_lastPos;
EGG::Vector3f m_relPos;

bool m_ownsBSP;
};

class CollisionGroup {
Expand Down
8 changes: 8 additions & 0 deletions source/game/kart/KartBody.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ void KartBody::setAngle(f32 val) {

KartBodyKart::KartBodyKart(KartPhysics *physics) : KartBody(physics) {}

KartBodyKart::~KartBodyKart() {
delete m_physics;
}

KartBodyBike::KartBodyBike(KartPhysics *physics) : KartBody(physics) {}

KartBodyBike::~KartBodyBike() {
delete m_physics;
}

EGG::Matrix34f KartBodyBike::wheelMatrix(u16 wheelIdx) {
EGG::Matrix34f mat;

Expand Down
2 changes: 2 additions & 0 deletions source/game/kart/KartBody.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ protected:
class KartBodyKart : public KartBody {
public:
KartBodyKart(KartPhysics *physics);
~KartBodyKart();
};

class KartBodyBike : public KartBody {
public:
KartBodyBike(KartPhysics *physics);
~KartBodyBike();

EGG::Matrix34f wheelMatrix(u16 wheelIdx) override;
};
Expand Down
2 changes: 2 additions & 0 deletions source/game/kart/KartDynamics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ KartDynamics::KartDynamics() {
init();
}

KartDynamics::~KartDynamics() = default;

void KartDynamics::init() {
m_speedNorm = 0.0f;
m_gravity = -1.0f;
Expand Down
1 change: 1 addition & 0 deletions source/game/kart/KartDynamics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Kart {
class KartDynamics {
public:
KartDynamics();
virtual ~KartDynamics();

virtual void forceUpright() {}
virtual void stabilize() {}
Expand Down
3 changes: 3 additions & 0 deletions source/game/kart/KartMove.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ KartMove::KartMove() : m_smoothedUp(EGG::Vector3f::ey), m_scale(1.0f, 1.0f, 1.0f
m_bPadBoost = false;
}

KartMove::~KartMove() = default;

void KartMove::calcTurn() {
m_realTurn = 0.0f;
m_rawTurn = 0.0f;
Expand Down Expand Up @@ -887,6 +889,7 @@ void KartMoveBike::init(bool b1, bool b2) {
m_leanRotCap = 0.0f;
m_leanRotInc = 0.0f;
m_wheelieRot = 0.0f;
m_maxWheelieRot = 0.0f;
m_wheelieCooldown = 0;
}

Expand Down
1 change: 1 addition & 0 deletions source/game/kart/KartMove.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Kart {
class KartMove : public KartObjectProxy {
public:
KartMove();
virtual ~KartMove();

virtual void calcTurn();
virtual void calcWheelie() {}
Expand Down
14 changes: 11 additions & 3 deletions source/game/kart/KartObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ KartObject::KartObject(KartParam *param) {

KartObject::~KartObject() {
delete m_pointers.param;
delete m_pointers.body;
delete m_pointers.sub;

for (auto *susp : m_pointers.suspensions) {
delete susp;
}

for (auto *tire : m_pointers.tires) {
delete tire;
}
}

KartBody *KartObject::createBody(KartPhysics *physics) {
Expand Down Expand Up @@ -139,9 +149,7 @@ KartObject *KartObject::Create(Character character, Vehicle vehicle, u8 playerId

KartObjectBike::KartObjectBike(KartParam *param) : KartObject(param) {}

KartObjectBike::~KartObjectBike() {
delete m_pointers.param;
}
KartObjectBike::~KartObjectBike() = default;

KartBody *KartObjectBike::createBody(KartPhysics *physics) {
return new KartBodyBike(physics);
Expand Down
10 changes: 9 additions & 1 deletion source/game/kart/KartObjectManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ KartObjectManager::KartObjectManager() {
}
}

KartObjectManager::~KartObjectManager() = default;
KartObjectManager::~KartObjectManager() {
KartParamFileManager::DestroyInstance();

for (size_t i = 0; i < m_count; ++i) {
delete m_objects[i];
}

delete[] m_objects;
}

KartObjectManager *KartObjectManager::s_instance = nullptr;

Expand Down
6 changes: 6 additions & 0 deletions source/game/kart/KartSub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace Kart {

KartSub::KartSub() = default;

KartSub::~KartSub() {
delete m_collide;
delete m_state;
delete m_move;
}

void KartSub::createSubsystems(bool isBike) {
m_move = isBike ? new KartMoveBike : new KartMove;
m_state = new KartState;
Expand Down
1 change: 1 addition & 0 deletions source/game/kart/KartSub.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Kart {
class KartSub : public KartObjectProxy {
public:
KartSub();
~KartSub();

void createSubsystems(bool isBike);
void copyPointers(KartAccessor &pointers);
Expand Down
12 changes: 11 additions & 1 deletion source/game/kart/KartSuspension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace Kart {

KartSuspension::KartSuspension() = default;

KartSuspension::~KartSuspension() = default;
KartSuspension::~KartSuspension() {
delete m_physics;
}

void KartSuspension::init(u16 wheelIdx, u16 bspWheelIdx) {
m_physics = new KartSuspensionPhysics(wheelIdx, bspWheelIdx);
Expand All @@ -22,4 +24,12 @@ KartSuspensionPhysics *KartSuspension::suspPhysics() {
return m_physics;
}

KartSuspensionFrontBike::KartSuspensionFrontBike() = default;

KartSuspensionFrontBike::~KartSuspensionFrontBike() = default;

KartSuspensionRearBike::KartSuspensionRearBike() = default;

KartSuspensionRearBike::~KartSuspensionRearBike() = default;

} // namespace Kart
14 changes: 11 additions & 3 deletions source/game/kart/KartSuspension.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Kart {
class KartSuspension : KartObjectProxy {
public:
KartSuspension();
~KartSuspension();
virtual ~KartSuspension();

void init(u16 wheelIdx, u16 bspWheelIdx);
void initPhysics();
Expand All @@ -20,8 +20,16 @@ private:
KartSuspensionPhysics *m_physics;
};

class KartSuspensionFrontBike : public KartSuspension {};
class KartSuspensionFrontBike : public KartSuspension {
public:
KartSuspensionFrontBike();
~KartSuspensionFrontBike();
};

class KartSuspensionRearBike : public KartSuspension {};
class KartSuspensionRearBike : public KartSuspension {
public:
KartSuspensionRearBike();
~KartSuspensionRearBike();
};

} // namespace Kart
4 changes: 3 additions & 1 deletion source/game/kart/KartSuspensionPhysics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace Kart {
WheelPhysics::WheelPhysics(u16 wheelIdx, u16 bspWheelIdx)
: m_wheelIdx(wheelIdx), m_bspWheelIdx(bspWheelIdx), m_bspWheel(nullptr) {}

WheelPhysics::~WheelPhysics() = default;
WheelPhysics::~WheelPhysics() {
delete m_hitboxGroup;
}

void WheelPhysics::init() {
m_hitboxGroup = new CollisionGroup;
Expand Down
4 changes: 3 additions & 1 deletion source/game/kart/KartTire.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace Kart {

KartTire::KartTire(u16 bspWheelIdx) : m_bspWheelIdx(bspWheelIdx) {}

KartTire::~KartTire() = default;
KartTire::~KartTire() {
delete m_wheelPhysics;
}

void KartTire::createPhysics(u16 tireIdx) {
m_wheelPhysics = new WheelPhysics(tireIdx, 1);
Expand Down
2 changes: 1 addition & 1 deletion source/game/kart/KartTire.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Kart {
class KartTire {
public:
KartTire(u16 bspWheelIdx);
~KartTire();
virtual ~KartTire();

virtual void createPhysics(u16 tireIdx);

Expand Down
Loading

0 comments on commit 4d2e55a

Please sign in to comment.