- Move gi->getCrouchState() into DCorePlayer.

This commit is contained in:
Mitchell Richters 2023-11-05 17:12:58 +11:00
parent 8705afc223
commit 4d7094b63b
14 changed files with 42 additions and 73 deletions

View file

@ -40,6 +40,7 @@ public:
// All overridable methods.
virtual DCoreActor* GetActor() = 0;
virtual const bool canSlopeTilt() const { return false; }
virtual const unsigned getCrouchFlags() const = 0;
virtual const DVector2& GetInputVelocity() const { return actor->vel.XY(); }
virtual const double GetMaxInputVel() const = 0;

View file

@ -48,18 +48,6 @@ GameInput gameInput{};
bool crouch_toggle = false;
//---------------------------------------------------------------------------
//
// Clears crouch toggle state for new games.
//
//---------------------------------------------------------------------------
void GameInput::resetCrouchToggle()
{
crouch_toggle = false;
}
//---------------------------------------------------------------------------
//
// Default player movement function for the games. Can be overridden.
@ -72,6 +60,18 @@ void GameInterface::doPlayerMovement()
}
//---------------------------------------------------------------------------
//
// Clears crouch toggle state for new games.
//
//---------------------------------------------------------------------------
void GameInput::resetCrouchToggle()
{
crouch_toggle = false;
}
//---------------------------------------------------------------------------
//
// Player's movement function, called from game's ticker or from gi->doPlayerMovement() as required.
@ -248,7 +248,7 @@ void GameInput::processInputBits()
}
else dpad_lock = 0;
const auto crouchState = gi->getCrouchState();
const auto crouchFlags = PlayerArray[myconnectindex]->getCrouchFlags();
inputBuffer.actions |= ActionsToSend;
ActionsToSend = 0;
@ -266,12 +266,12 @@ void GameInput::processInputBits()
if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch))
{
const bool canCrouch = crouchState & CS_CANCROUCH;
const bool canCrouch = crouchFlags & CS_CANCROUCH;
crouch_toggle = !crouch_toggle && canCrouch;
if (canCrouch) buttonMap.ClearButton(gamefunc_Toggle_Crouch);
}
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || (crouchState & CS_DISABLETOGGLE))
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || (crouchFlags & CS_DISABLETOGGLE))
crouch_toggle = false;
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || crouch_toggle)

View file

@ -111,7 +111,6 @@ struct GameInterface
virtual bool WantEscape() { return false; }
virtual void StartSoundEngine() = 0;
virtual void doPlayerMovement();
virtual unsigned getCrouchState() = 0;
};
extern GameInterface* gi;

View file

@ -362,7 +362,6 @@ struct GameInterface : public ::GameInterface
void AddQAVInterpProps(const int res_id, const FString& interptype, const bool loopable, const TMap<int, TArray<int>>&& ignoredata) override;
void RemoveQAVInterpProps(const int res_id) override;
void StartSoundEngine() override;
unsigned getCrouchState() override;
void FinalizeSetup() override;
};

View file

@ -311,6 +311,12 @@ public:
const int florhit = pActor->hit.florhit.type;
return pActor->xspr.height < 16 && (florhit == kHitSector || florhit == 0);
}
const unsigned getCrouchFlags() const override
{
const bool swimming = posture == kPostureSwim;
return (CS_CANCROUCH * !swimming) | (CS_DISABLETOGGLE * swimming);
}
};
inline DBloodPlayer* getPlayer(int index)

View file

@ -1520,18 +1520,6 @@ int ActionScan(DBloodPlayer* pPlayer, HitInfo* out)
//
//---------------------------------------------------------------------------
unsigned GameInterface::getCrouchState()
{
const bool swimming = getPlayer(myconnectindex)->posture == kPostureSwim;
return (CS_CANCROUCH * !swimming) | (CS_DISABLETOGGLE * swimming);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void ProcessInput(DBloodPlayer* pPlayer)
{
enum

View file

@ -38,7 +38,6 @@ struct GameInterface : public ::GameInterface
void ExitFromMenu() override;
void DrawPlayerSprite(const DVector2& origin, bool onteam) override;
void doPlayerMovement() override;
unsigned getCrouchState() override;
void UpdateSounds() override;
void Startup() override;
void DrawBackground() override;

View file

@ -486,21 +486,6 @@ void hud_input(DDukePlayer* const p)
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
unsigned GameInterface::getCrouchState()
{
const auto p = getPlayer(myconnectindex);
const int sectorLotag = p->insector() ? p->cursector->lotag : 0;
const int crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge) && !p->jetpack_on;
const int disableToggle = (!crouchable && p->on_ground) || p->jetpack_on || (isRRRA() && (p->OnMotorcycle || p->OnBoat));
return (CS_CANCROUCH * crouchable) | (CS_DISABLETOGGLE * disableToggle);
}
//---------------------------------------------------------------------------
//
// External entry point

View file

@ -419,6 +419,14 @@ public:
{
cmd.ucmd.setItemUsed(num - 1);
}
const unsigned getCrouchFlags() const override
{
const int sectorLotag = insector() ? cursector->lotag : 0;
const int crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || spritebridge) && !jetpack_on;
const int disableToggle = (!crouchable && on_ground) || jetpack_on || (isRRRA() && (OnMotorcycle || OnBoat));
return (CS_CANCROUCH * crouchable) | (CS_DISABLETOGGLE * disableToggle);
}
};
struct Cycler

View file

@ -238,7 +238,6 @@ struct GameInterface : public ::GameInterface
void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double interpfrac) override;
int GetCurrentSkill() override;
void StartSoundEngine() override;
unsigned getCrouchState() override;
};

View file

@ -1199,18 +1199,6 @@ static void updatePlayerWeapon(DExhumedPlayer* const pPlayer)
//
//---------------------------------------------------------------------------
unsigned GameInterface::getCrouchState()
{
const bool swimming = getPlayer(nLocalPlayer)->bUnderwater;
return (CS_CANCROUCH * !swimming) | (CS_DISABLETOGGLE * swimming);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
static void updatePlayerAction(DExhumedPlayer* const pPlayer)
{
const auto pPlayerActor = pPlayer->GetActor();

View file

@ -123,6 +123,11 @@ public:
{
return 15.25;
}
const unsigned getCrouchFlags() const override
{
return (CS_CANCROUCH * !bUnderwater) | (CS_DISABLETOGGLE * bUnderwater);
}
};
extern int PlayerCount;

View file

@ -1875,6 +1875,13 @@ public:
{
GetActor()->spr.pos.Z = val - GetActor()->viewzoffset;
}
const unsigned getCrouchFlags() const override
{
const bool crouchable = true;
const bool disableToggle = (Flags & (PF_JUMPING|PF_FALLING|PF_CLIMBING|PF_DIVING|PF_DEAD)) || sop;
return (CS_CANCROUCH * crouchable) | (CS_DISABLETOGGLE * disableToggle);
}
};
inline DSWPlayer* getPlayer(int index)
@ -1920,7 +1927,6 @@ struct GameInterface : public ::GameInterface
void ExitFromMenu() override;
int GetCurrentSkill() override;
void StartSoundEngine() override;
unsigned getCrouchState() override;
void doPlayerMovement() override
{
const auto pp = getPlayer(myconnectindex);

View file

@ -5882,20 +5882,6 @@ void DoPlayerRun(DSWPlayer* pp)
//
//---------------------------------------------------------------------------
unsigned GameInterface::getCrouchState()
{
const auto pp = getPlayer(myconnectindex);
const bool crouchable = true;
const bool disableToggle = (pp->Flags & (PF_JUMPING|PF_FALLING|PF_CLIMBING|PF_DIVING|PF_DEAD)) || pp->sop;
return (CS_CANCROUCH * crouchable) | (CS_DISABLETOGGLE * disableToggle);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void PlayerStateControl(DSWActor* actor)
{
if (actor == nullptr || !actor->hasU()) return;