Skip to content
Closed
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
129 changes: 124 additions & 5 deletions src/game/shared/hl2mp/hl2mp_playeranimstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ CHL2MPPlayerAnimState* CreateHL2MPPlayerAnimState( CHL2MP_Player *pPlayer )
CHL2MPPlayerAnimState::CHL2MPPlayerAnimState()
{
m_pHL2MPPlayer = NULL;
#ifdef NEO
m_iReloadGestureSequence = -1;
m_flReloadGestureStartCycle = 0.0f;
m_flReloadGestureEndCycle = 1.0f;
#endif

// Don't initialize HL2MP specific variables here. Init them in InitHL2MPAnimState()
}
Expand All @@ -93,6 +98,11 @@ CHL2MPPlayerAnimState::CHL2MPPlayerAnimState( CBasePlayer *pPlayer, MultiPlayerM
: CMultiPlayerAnimState( pPlayer, movementData )
{
m_pHL2MPPlayer = NULL;
#ifdef NEO
m_iReloadGestureSequence = -1;
m_flReloadGestureStartCycle = 0.0f;
m_flReloadGestureEndCycle = 1.0f;
#endif

// Don't initialize HL2MP specific variables here. Init them in InitHL2MPAnimState()
}
Expand Down Expand Up @@ -182,6 +192,7 @@ void CHL2MPPlayerAnimState::ComputeSequences(CStudioHdr* pStudioHdr)
// The groundspeed interpolator uses the main sequence info.
UpdateInterpolators();
ComputeGestureSequence(pStudioHdr);
UpdateReloadGesture();
}

#endif //NEO
Expand Down Expand Up @@ -343,11 +354,7 @@ void CHL2MPPlayerAnimState::DoAnimationEvent( PlayerAnimEvent_t event, int nData
{
#ifdef NEO
AddToGestureSlot(GESTURE_SLOT_ATTACK_AND_RELOAD, CalcReloadSequence(), true);
if (nData == RELOAD_EVENT_RESUMED)
{
// A reload resumed by the draw starts with the weapon change, which would otherwise clear the gesture
m_hActiveWeapon = GetBasePlayer()->GetActiveWeapon();
}
StartReloadGesture(nData);
#else
// Weapon reload.
if ( GetBasePlayer()->GetFlags() & FL_DUCKING )
Expand Down Expand Up @@ -1018,3 +1025,115 @@ void CHL2MPPlayerAnimState::DebugShowAnimStateFull(int iStartLine)

AnimStateLog("--------------------------------------------\n\n");
}

#ifdef NEO
// Start a gesture part way through its sequence, as AddVCDSequenceToGestureSlot does for scene gestures
void CHL2MPPlayerAnimState::SetGestureSlotCycle(int iGestureSlot, float flCycle)
{
GestureSlot_t &slot = m_aGestureSlots[iGestureSlot];
if (!slot.m_pAnimLayer)
{
return;
}

slot.m_pAnimLayer->m_flCycle = flCycle;
slot.m_pAnimLayer->m_flPrevCycle = flCycle;
#ifdef CLIENT_DLL
if (CBasePlayer *pPlayer = GetBasePlayer())
{
pPlayer->m_flOverlayPrevEventCycle[iGestureSlot] = flCycle;
}
#endif
}

// The reload event's data: the fit in the low bit, the first-person length in ms above it
static constexpr int RELOAD_GESTURE_KEEP_END_BIT = 1;
static constexpr int RELOAD_GESTURE_FIT_BITS = 1;
static constexpr float RELOAD_GESTURE_MS_PER_SECOND = 1000.0f;

// The player models' reload gestures have no blend of their own, so a gesture started or ended part way
// blends in or out over this long to hide the jump in pose
static constexpr float RELOAD_GESTURE_BLEND_TIME = 0.2f;

int CHL2MPPlayerAnimState::PackReloadGestureData(ReloadGestureFit_t fit, float flDuration)
{
const int iMs = static_cast<int>(Max(flDuration, 0.0f) * RELOAD_GESTURE_MS_PER_SECOND);
return (iMs << RELOAD_GESTURE_FIT_BITS) | ((fit == RELOAD_GESTURE_KEEP_END) ? RELOAD_GESTURE_KEEP_END_BIT : 0);
}

// Fit the reload gesture just added to a shorter first-person reload: play only its start or only its end, for as
// long as that reload lasts. An event without data plays the whole gesture
void CHL2MPPlayerAnimState::StartReloadGesture(int nData)
{
m_iReloadGestureSequence = -1;

CBasePlayer *pPlayer = GetBasePlayer();
const GestureSlot_t &slot = m_aGestureSlots[GESTURE_SLOT_ATTACK_AND_RELOAD];
if (nData == 0 || !pPlayer || !slot.m_bActive || !slot.m_pAnimLayer)
{
return;
}

// A reload resumed by the draw starts with the weapon change, which would otherwise clear the gesture
m_hActiveWeapon = pPlayer->GetActiveWeapon();

const int iSequence = slot.m_pAnimLayer->m_nSequence;
const float flDuration = (nData >> RELOAD_GESTURE_FIT_BITS) / RELOAD_GESTURE_MS_PER_SECOND;
const float flCycles = flDuration * pPlayer->GetSequenceCycleRate(pPlayer->GetModelPtr(), iSequence);
if (flDuration <= 0.0f || flCycles >= 1.0f)
{
return;
}

const bool bKeepEnd = (nData & RELOAD_GESTURE_KEEP_END_BIT) != 0;
m_flReloadGestureStartCycle = bKeepEnd ? 1.0f - flCycles : 0.0f;
m_flReloadGestureEndCycle = bKeepEnd ? 1.0f : flCycles;
m_iReloadGestureSequence = iSequence;
SetGestureSlotCycle(GESTURE_SLOT_ATTACK_AND_RELOAD, m_flReloadGestureStartCycle);
}

// Blend a fitted reload gesture in from its start cycle and out to its end cycle, then end it there
void CHL2MPPlayerAnimState::UpdateReloadGesture()
{
if (m_iReloadGestureSequence < 0)
{
return;
}

CBasePlayer *pPlayer = GetBasePlayer();
GestureSlot_t &slot = m_aGestureSlots[GESTURE_SLOT_ATTACK_AND_RELOAD];
if (!pPlayer || !slot.m_bActive || !slot.m_pAnimLayer || slot.m_pAnimLayer->m_nSequence != m_iReloadGestureSequence)
{
// a new gesture took the slot, or the reload gesture ended
m_iReloadGestureSequence = -1;
return;
}

const float flCycle = slot.m_pAnimLayer->m_flCycle;
if (m_flReloadGestureEndCycle < 1.0f && flCycle >= m_flReloadGestureEndCycle)
{
ResetGestureSlot(GESTURE_SLOT_ATTACK_AND_RELOAD);
m_iReloadGestureSequence = -1;
return;
}

const float flBlendCycles = RELOAD_GESTURE_BLEND_TIME * pPlayer->GetSequenceCycleRate(pPlayer->GetModelPtr(), m_iReloadGestureSequence);
if (flBlendCycles <= 0.0f)
{
return;
}

float flWeight = 1.0f;
if (m_flReloadGestureStartCycle > 0.0f)
{
flWeight = Min(flWeight, (flCycle - m_flReloadGestureStartCycle) / flBlendCycles);
}

if (m_flReloadGestureEndCycle < 1.0f)
{
flWeight = Min(flWeight, (m_flReloadGestureEndCycle - flCycle) / flBlendCycles);
}

slot.m_pAnimLayer->m_flWeight = clamp(flWeight, 0.0f, 1.0f);
}
#endif // NEO
22 changes: 20 additions & 2 deletions src/game/shared/hl2mp/hl2mp_playeranimstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class C_HL2MP_Player;
class CHL2MP_Player;
#endif

#ifdef NEO
// The part of the third-person reload gesture that a shorter first-person reload shows
enum ReloadGestureFit_t
{
RELOAD_GESTURE_KEEP_START, // a reload from the start: the gesture ends early
RELOAD_GESTURE_KEEP_END, // a resumed reload: the gesture starts late
};
#endif

// ------------------------------------------------------------------------------------------------ //
// CPlayerAnimState declaration.
// ------------------------------------------------------------------------------------------------ //
Expand Down Expand Up @@ -48,8 +57,8 @@ class CHL2MPPlayerAnimState : public CMultiPlayerAnimState
#ifdef NEO
virtual void ComputeSequences(CStudioHdr* pStudioHdr);

// Reload event data: the draw resumes an interrupted reload
static constexpr int RELOAD_EVENT_RESUMED = 1;
// A reload event's data: how long the first-person reload lasts, and which part of a longer gesture it shows
static int PackReloadGestureData(ReloadGestureFit_t fit, float flDuration);
#endif

void DebugShowAnimStateFull(int iStartLine);
Expand All @@ -67,9 +76,18 @@ class CHL2MPPlayerAnimState : public CMultiPlayerAnimState

#ifdef NEO
bool IsLeaning(CStudioHdr *pStudioHdr);
void SetGestureSlotCycle(int iGestureSlot, float flCycle);
void StartReloadGesture(int nData);
void UpdateReloadGesture();
#endif // NEO

CHL2MP_Player *m_pHL2MPPlayer;
#ifdef NEO
// The playing reload gesture's sequence (-1: none) and the cycles it blends in from and out to
int m_iReloadGestureSequence;
float m_flReloadGestureStartCycle;
float m_flReloadGestureEndCycle;
#endif
#ifndef NEO
bool m_bInAirWalk;
float m_flHoldDeployedPoseUntilTime;
Expand Down
15 changes: 10 additions & 5 deletions src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void CNEOBaseCombatWeapon::ReloadPhasesOnReload()
StartReloadPhases(pVM ? GetNEOWpnData().FindReloadTable(pVM->GetSequenceName(pVM->GetSequence())) : -1);
}

// The magazine is in: the phases up to the load are done, and a switch from here leaves nothing to resume
// The magazine is in: the phases up to the load are done; a switch from here resumes only where the table names a resume
void CNEOBaseCombatWeapon::ReloadPhasesOnFinish()
{
if (!IsReloadPhaseSystemEnabled())
Expand Down Expand Up @@ -672,8 +672,12 @@ bool CNEOBaseCombatWeapon::ResumeReload()
return false;
}

// the old magazine and its rounds are gone, as when a reload loads at its ready time
m_iClip1 = 0;
// After the unload the old magazine and its rounds are gone, as when a reload loads at its ready time.
// After the load the fresh magazine is already in.
if (m_nReloadPhase == RELOAD_PHASE_UNLOADED)
{
m_iClip1 = 0;
}

// The weapon entity draws its world model in third person, which has none of the viewmodel's sequences
const int iOwnSequence = LookupSequence(pszName);
Expand All @@ -683,9 +687,10 @@ bool CNEOBaseCombatWeapon::ResumeReload()
}
SendViewModelAnim(iSequence);

ToHL2MPPlayer(GetOwner())->DoAnimationEvent(PLAYERANIMEVENT_RELOAD, CHL2MPPlayerAnimState::RELOAD_EVENT_RESUMED);

// the third-person reload gesture lasts no longer than the resume
const float flDuration = ReloadViewModel()->SequenceDuration(iSequence);
ToHL2MPPlayer(GetOwner())->DoAnimationEvent(PLAYERANIMEVENT_RELOAD,
CHL2MPPlayerAnimState::PackReloadGestureData(RELOAD_GESTURE_KEEP_END, flDuration));

const float flEnd = gpGlobals->curtime + flDuration;
GetOwner()->SetNextAttack(flEnd);
Expand Down
Loading