Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DummyPole #176

Merged
merged 1 commit into from
Nov 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Test Case | Frames | |
[`mg-ng-rta-1-40-273`](https://youtu.be/8-0Xetey5xY) | 877 / 6422 | ❌ | Mushroom
[`tf-rta-1-44-178`](https://youtu.be/2XWFuncJAGk) | 743 / 6656 | ❌ | Moving road
[`tf-ng-rta-1-49-039`](https://youtu.be/mqQa_1Cq1bw) | 689 / 6947 | ❌ | Moving road
[`mc-rta-0-46-553`](https://youtu.be/1F2xfHYrkXM) | 686 / 3202 | ❌ | KMP
[`mc-rta-0-46-553`](https://youtu.be/1F2xfHYrkXM) | 1494 / 3202 | ❌ | KMP
[`mc-ng-rta-1-20-357`](https://youtu.be/kG8PvG8K1ZA) | 1222 / 4228 | ❌ | KMP
[`cm-rta-0-25-145`](https://youtu.be/F_RUQVghmuA) | 1919 / 1919 | ✔️ |
[`cm-ng-rta-1-55-264`](https://youtu.be/XxKG3IYWduE) | 651 / 7320 | ❌ | KMP
Expand Down
22 changes: 18 additions & 4 deletions source/game/field/ObjectDirector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ size_t ObjectDirector::checkKartObjectCollision(Kart::KartObject *kartObj,
obj->onObjectCollision(kartObj);
}

m_collisionObjects[count] = obj;
m_collidingObjects[count] = obj;
if (m_hitDepths[count].y < 0.0f) {
m_hitDepths[count].y = 0.0f;
}
Expand All @@ -95,6 +95,12 @@ const ObjectFlowTable &ObjectDirector::flowTable() const {
return m_flowTable;
}

const ObjectBase *ObjectDirector::collidingObject(size_t idx) const {
ASSERT(idx < m_collidingObjects.size());

return m_collidingObjects[idx];
}

Kart::Reaction ObjectDirector::reaction(size_t idx) const {
ASSERT(idx < m_reactions.size());

Expand Down Expand Up @@ -150,9 +156,13 @@ ObjectDirector::~ObjectDirector() {
void ObjectDirector::createObjects() {
const auto *courseMap = System::CourseMap::Instance();
size_t objectCount = courseMap->getGeoObjCount();
m_objects.reserve(objectCount);
m_calcObjects.reserve(objectCount);
m_collisionObjects.reserve(objectCount);

// It's possible for the KMP to specify settings for objects that aren't tracked here
// MAX_UNIT_COUNT is the upper bound for tracked object count, so we reserve the minimum
size_t maxCount = std::min(objectCount, MAX_UNIT_COUNT);
m_objects.reserve(maxCount);
m_calcObjects.reserve(maxCount);
m_collisionObjects.reserve(maxCount);

for (size_t i = 0; i < objectCount; ++i) {
const auto *pObj = courseMap->getGeoObj(i);
Expand Down Expand Up @@ -181,6 +191,10 @@ ObjectBase *ObjectDirector::createObject(const System::MapdataGeoObj &params) {
return new ObjectDokan(params);
case ObjectId::OilSFC:
return new ObjectOilSFC(params);
// Non-specified objects are stock collidable objects by default
// However, we need to specify an impl, so we don't use default
case ObjectId::DummyPole:
malleoz marked this conversation as resolved.
Show resolved Hide resolved
return new ObjectCollidable(params);
default:
return new ObjectNoImpl(params);
}
Expand Down
3 changes: 3 additions & 0 deletions source/game/field/ObjectDirector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public:
ObjectCollisionConvexHull *convexHull);

const ObjectFlowTable &flowTable() const;
const ObjectBase *collidingObject(size_t idx) const;
Kart::Reaction reaction(size_t idx) const;
const EGG::Vector3f &hitDepth(size_t idx) const;

Expand All @@ -43,6 +44,8 @@ private:

static constexpr size_t MAX_UNIT_COUNT = 0x100;

std::array<ObjectBase *, MAX_UNIT_COUNT>
m_collidingObjects; ///< Objects we are currently colliding with
std::array<EGG::Vector3f, MAX_UNIT_COUNT> m_hitDepths;
std::array<Kart::Reaction, MAX_UNIT_COUNT> m_reactions;

Expand Down
1 change: 1 addition & 0 deletions source/game/field/obj/ObjectId.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Field {

enum class ObjectId {
DummyPole = 0x066,
DokanSFC = 0x12e,
OilSFC = 0x15d,
};
Expand Down
32 changes: 32 additions & 0 deletions source/game/kart/KartCollide.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void KartCollide::init() {
m_suspBottomHeightSoftWall = 0.0f;
m_someNonSoftWallTimer = 0;
m_someSoftWallTimer = 0;
m_poleAngVelTimer = 0;
m_poleYaw = 0.0f;
m_colPerpendicularity = 0.0f;
}

Expand Down Expand Up @@ -461,6 +463,10 @@ void KartCollide::calcBoundingRadius() {

/// @addr{0x80571F10}
void KartCollide::calcObjectCollision() {
constexpr f32 COS_PI_OVER_4 = 0.707f;
constexpr s32 DUMMY_POLE_ANG_VEL_TIME = 3;
constexpr f32 DUMMY_POLE_ANG_VEL = 0.005f;

m_totalReactionWallNrm = EGG::Vector3f::zero;
m_surfaceFlags.resetBit(eSurfaceFlags::ObjectWall, eSurfaceFlags::ObjectWall3);

Expand All @@ -481,7 +487,33 @@ void KartCollide::calcObjectCollision() {
m_movement += hitDepth;
}
}

if (objectDirector->collidingObject(i)->id() == Field::ObjectId::DummyPole) {
EGG::Vector3f hitDirection = objectCollisionKart()->GetHitDirection(i);
const EGG::Vector3f &lastDir = move()->lastDir();

if (lastDir.dot(hitDirection) < -COS_PI_OVER_4) {
EGG::Vector3f angVel = hitDirection.cross(lastDir);
f32 sign = angVel.y > 0.0f ? -1.0f : 1.0f;

m_poleAngVelTimer = DUMMY_POLE_ANG_VEL_TIME;
m_poleYaw = DUMMY_POLE_ANG_VEL * sign;
}
}
}

calcPoleTimer();
}

/// @addr{Inlined in 0x80571F10}
void KartCollide::calcPoleTimer() {
if (m_poleAngVelTimer > 0 && (state()->isAccelerate() || state()->isBrake())) {
malleoz marked this conversation as resolved.
Show resolved Hide resolved
EGG::Vector3f angVel2 = dynamics()->angVel2();
angVel2.y += m_poleYaw;
dynamics()->setAngVel2(angVel2);
}

m_poleAngVelTimer = std::max(0, m_poleAngVelTimer - 1);
}

/// @stage All
Expand Down
3 changes: 3 additions & 0 deletions source/game/kart/KartCollide.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public:
Field::CourseColMgr::CollisionInfo *colInfo);
void calcBoundingRadius();
void calcObjectCollision();
void calcPoleTimer();

void processWheel(CollisionData &collisionData, Hitbox &hitbox,
Field::CourseColMgr::CollisionInfo *colInfo, Field::KCLTypeMask *maskOut);
Expand Down Expand Up @@ -154,6 +155,8 @@ private:
u16 m_someSoftWallTimer;
f32 m_suspBottomHeightNonSoftWall;
u16 m_someNonSoftWallTimer;
s16 m_poleAngVelTimer;
f32 m_poleYaw;
f32 m_colPerpendicularity;

static std::array<ObjectCollisionHandler, 33> s_objectCollisionHandlers;
Expand Down