Skip to content

Commit

Permalink
Sync to frame 1747
Browse files Browse the repository at this point in the history
  • Loading branch information
vabold committed May 12, 2024
1 parent 7d3d733 commit 293f569
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
62 changes: 55 additions & 7 deletions source/game/kart/KartMove.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ KartMove::KartMove() : m_smoothedUp(EGG::Vector3f::ey), m_scale(1.0f, 1.0f, 1.0f
m_bRampBoost = false;
m_bPadJump = false;
m_bSsmtCharged = false;
m_bSsmtLeeway = false;
m_jump = nullptr;
}

Expand Down Expand Up @@ -110,6 +111,9 @@ void KartMove::init(bool b1, bool b2) {
m_driftState = DriftState::NotDrifting;
m_mtCharge = 0;
m_offroadInvincibility = 0;
m_ssmtCharge = 0;
m_ssmtLeewayTimer = 0;
m_ssmtDisableAccelTimer = 0;
m_nonZipperAirtime = 0;
m_realTurn = 0.0f;
m_weightedTurn = 0.0f;
Expand Down Expand Up @@ -428,25 +432,65 @@ void KartMove::calcRampBoost() {
}
}

void KartMove::calcDisableBackwardsAccel() {
if (!state()->isDisableBackwardsAccel()) {
return;
}

if (--m_ssmtDisableAccelTimer < 0 || (!m_bSsmtLeeway && !state()->isBrake())) {
state()->setDisableBackwardsAccel(false);
m_ssmtDisableAccelTimer = 0;
}
}

void KartMove::calcSsmt() {
constexpr s16 MAX_SSMT_CHARGE = 75;
constexpr s16 SSMT_BOOST_FRAMES = 30;
constexpr s16 LEEWAY_FRAMES = 1;
constexpr s16 DISABLE_ACCEL_FRAMES = 20;

calcDisableBackwardsAccel();

if (state()->isChargingSsmt()) {
if (++m_ssmtCharge > MAX_SSMT_CHARGE) {
m_ssmtCharge = MAX_SSMT_CHARGE;
m_bSsmtCharged = true;
m_ssmtLeewayTimer = 0;
}
} else {
m_ssmtCharge = 0;
if (!m_bSsmtCharged) {
return;
}

if (state()->isAccelerate() && !state()->isBrake()) {
activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
if (m_bSsmtLeeway) {
if (--m_ssmtLeewayTimer < 0) {
m_ssmtLeewayTimer = 0;
m_bSsmtCharged = false;
m_bSsmtLeeway = false;
m_ssmtDisableAccelTimer = DISABLE_ACCEL_FRAMES;
state()->setDisableBackwardsAccel(true);
} else {
if (!state()->isAccelerate() && !state()->isBrake()) {
activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
m_ssmtLeewayTimer = 0;
m_bSsmtCharged = false;
m_bSsmtLeeway = false;
}
}
} else {
if (state()->isAccelerate() && !state()->isBrake()) {
activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
m_ssmtLeewayTimer = 0;
m_bSsmtCharged = false;
m_bSsmtLeeway = false;
} else {
m_ssmtLeewayTimer = LEEWAY_FRAMES;
m_bSsmtLeeway = true;
state()->setDisableBackwardsAccel(true);
m_ssmtDisableAccelTimer = LEEWAY_FRAMES;
}
}

m_bSsmtCharged = false;
}
}

Expand Down Expand Up @@ -653,7 +697,7 @@ void KartMove::calcVehicleSpeed() {
if (state()->isAccelerate()) {
m_acceleration = calcVehicleAcceleration();
} else {
if (!state()->isBrake()) {
if (!state()->isBrake() || state()->isDisableBackwardsAccel()) {
m_speed *= m_speed > 0.0f ? 0.98f : 0.95f;
} else if (m_drivingDirection == DrivingDirection::Braking) {
m_acceleration = -1.5f;
Expand Down Expand Up @@ -1234,8 +1278,8 @@ void KartMoveBike::calcVehicleRotation(f32 turn) {
constexpr f32 LEAN_ROT_MIN_DRIFT = 0.7f;

// TODO: Use 2c0 infra! This is a temporary measure
constexpr f32 SSMT_LEAN_ROT_INC = 1.6f;
constexpr f32 SSMT_LEAN_ROT_CAP = 0.9f;
constexpr f32 SSMT_LEAN_ROT_INC = 0.15f;
constexpr f32 SSMT_LEAN_ROT_CAP = 1.3f;

f32 leanRotInc = LEAN_ROT_INC_RACE;
f32 leanRotCap = LEAN_ROT_CAP_RACE;
Expand Down Expand Up @@ -1444,6 +1488,7 @@ f32 KartMoveBike::wheelieRotFactor() const {

// Also handles cancelling wheelies
void KartMoveBike::tryStartWheelie() {
constexpr s16 COOLDOWN_FRAMES = 20;
bool dpadUp = inputs()->currentState().trickUp();

if (!state()->isWheelie()) {
Expand All @@ -1454,6 +1499,9 @@ void KartMoveBike::tryStartWheelie() {

startWheelie();
}
} else if (inputs()->currentState().trickDown() && m_wheelieCooldown <= 0) {
cancelWheelie();
m_wheelieCooldown = COOLDOWN_FRAMES;
}
}

Expand Down
6 changes: 5 additions & 1 deletion source/game/kart/KartMove.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public:
void calcOffroad();
void calcBoost();
void calcRampBoost();
void calcDisableBackwardsAccel();
void calcSsmt();
bool calcPreDrift();
void calcManualDrift();
Expand Down Expand Up @@ -145,6 +146,8 @@ protected:
KartBoost m_boost;
s16 m_offroadInvincibility;
s16 m_ssmtCharge;
s16 m_ssmtLeewayTimer;
s16 m_ssmtDisableAccelTimer;
f32 m_realTurn;
f32 m_weightedTurn;
EGG::Vector3f m_scale;
Expand All @@ -166,6 +169,7 @@ protected:
bool m_bPadJump;
// Miscellaneous flags
bool m_bSsmtCharged;
bool m_bSsmtLeeway;
KartJump *m_jump;
f32 m_rawTurn;
};
Expand Down Expand Up @@ -200,7 +204,7 @@ private:
f32 m_wheelieRot;
f32 m_maxWheelieRot;
u32 m_wheelieFrames;
u16 m_wheelieCooldown;
s16 m_wheelieCooldown;
f32 m_wheelieRotDec;
};

Expand Down
9 changes: 9 additions & 0 deletions source/game/kart/KartState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ bool KartState::isBoostOffroadInvincibility() const {
return m_bBoostOffroadInvincibility;
}

bool KartState::isDisableBackwardsAccel() const {
return m_bDisableBackwardsAccel;
}

bool KartState::isTrickRot() const {
return m_bTrickRot;
}
Expand Down Expand Up @@ -506,6 +510,7 @@ void KartState::clearBitfield1() {
m_bTrickStart = false;
m_bInATrick = false;
m_bBoostOffroadInvincibility = false;
m_bDisableBackwardsAccel = false;
m_bTrickRot = false;
m_bChargingSsmt = false;
m_bTrickable = false;
Expand Down Expand Up @@ -594,6 +599,10 @@ void KartState::setBoostOffroadInvincibility(bool isSet) {
m_bBoostOffroadInvincibility = isSet;
}

void KartState::setDisableBackwardsAccel(bool isSet) {
m_bDisableBackwardsAccel = isSet;
}

void KartState::setTrickRot(bool isSet) {
m_bTrickRot = isSet;
}
Expand Down
3 changes: 3 additions & 0 deletions source/game/kart/KartState.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public:
bool isTrickStart() const;
bool isInATrick() const;
bool isBoostOffroadInvincibility() const;
bool isDisableBackwardsAccel() const;
bool isTrickRot() const;
bool isChargingSsmt() const;
bool isTrickable() const;
Expand Down Expand Up @@ -89,6 +90,7 @@ public:
void setInATrick(bool isSet);
void setJumpPad(bool isSet);
void setBoostOffroadInvincibility(bool isSet);
void setDisableBackwardsAccel(bool isSet);
void setTrickRot(bool isSet);
void setChargingSsmt(bool isSet);
void setTrickable(bool isSet);
Expand Down Expand Up @@ -131,6 +133,7 @@ private:
bool m_bTrickStart;
bool m_bInATrick;
bool m_bBoostOffroadInvincibility;
bool m_bDisableBackwardsAccel;
bool m_bTrickRot;
bool m_bChargingSsmt;
bool m_bTrickable;
Expand Down
4 changes: 4 additions & 0 deletions source/game/system/KPadController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ bool RaceInputState::trickUp() const {
return trick == Trick::Up;
}

bool RaceInputState::trickDown() const {
return trick == Trick::Down;
}

KPadGhostButtonsStream::KPadGhostButtonsStream()
: currentSequence(std::numeric_limits<u32>::max()), state(2) {}

Expand Down
1 change: 1 addition & 0 deletions source/game/system/KPadController.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct RaceInputState {
bool item() const;
bool drift() const;
bool trickUp() const;
bool trickDown() const;

u16 buttons;
u16 buttonsRaw;
Expand Down

0 comments on commit 293f569

Please sign in to comment.