Skip to content

Commit

Permalink
mp_fadetoblack 2 fade timings now depends from mp_dying_time CVar…
Browse files Browse the repository at this point in the history
… and code fixes (#845)

 Fix forcing 1-person view for players when `mp_fadetoblack = 2`;
 Fix player blackout on server entry when `mp_fadetoblack = 2`;
 Fix observer not being blinded when `mp_fadetoblack = 2`;
 Fix fadetoblack message timings using new CVar `mp_dying_time`.

fix #501
fix #506

Co-authored-by: s1lentq <[email protected]>
  • Loading branch information
SergeyShorokhov and s1lentq authored Jul 16, 2023
1 parent c526fa5 commit 9427767
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 35 deletions.
2 changes: 1 addition & 1 deletion regamedll/dlls/API/CSPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ EXT_FUNC bool CCSPlayer::JoinTeam(TeamName team)
pPlayer->StartObserver(pentSpawnSpot->v.origin, pentSpawnSpot->v.angles);

// do we have fadetoblack on? (need to fade their screen back in)
if (fadetoblack.value)
if (fadetoblack.value == FADETOBLACK_STAY)
{
UTIL_ScreenFade(pPlayer, Vector(0, 0, 0), 0.001, 0, 0, FFADE_IN);
}
Expand Down
5 changes: 5 additions & 0 deletions regamedll/dlls/animating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ NOXREF int CBaseAnimating::GetBodygroup(int iGroup)
return ::GetBodygroup(GET_MODEL_PTR(ENT(pev)), pev, iGroup);
}

float CBaseAnimating::GetSequenceDuration() const
{
return ::GetSequenceDuration(GET_MODEL_PTR(ENT(pev)), pev);
}

int CBaseAnimating::ExtractBbox(int sequence, float *mins, float *maxs)
{
return ::ExtractBbox(GET_MODEL_PTR(ENT(pev)), sequence, mins, maxs);
Expand Down
15 changes: 15 additions & 0 deletions regamedll/dlls/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ void GetSequenceInfo(void *pmodel, entvars_t *pev, float *pflFrameRate, float *p
*pflGroundSpeed = *pflGroundSpeed * pseqdesc->fps / (pseqdesc->numframes - 1);
}

float GetSequenceDuration(void *pmodel, entvars_t *pev)
{
studiohdr_t *pstudiohdr = (studiohdr_t *)pmodel;
if (!pstudiohdr)
return 0; // model ptr is not valid

if (pev->sequence < 0 || pev->sequence >= pstudiohdr->numseq)
return 0; // sequence is not valid

// get current sequence time
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + int(pev->sequence);

return pseqdesc->numframes / pseqdesc->fps;
}

int GetSequenceFlags(void *pmodel, entvars_t *pev)
{
studiohdr_t *pstudiohdr = (studiohdr_t *)pmodel;
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int LookupActivity(void *pmodel, entvars_t *pev, int activity);
int LookupActivityHeaviest(void *pmodel, entvars_t *pev, int activity);
int LookupSequence(void *pmodel, const char *label);
void GetSequenceInfo(void *pmodel, entvars_t *pev, float *pflFrameRate, float *pflGroundSpeed);
float GetSequenceDuration(void *pmodel, entvars_t *pev);
int GetSequenceFlags(void *pmodel, entvars_t *pev);
float SetController(void *pmodel, entvars_t *pev, int iController, float flValue);
float SetBlending(void *pmodel, entvars_t *pev, int iBlender, float flValue);
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class CBaseAnimating: public CBaseDelay {
float SetBoneController(int iController, float flValue = 0.0f);
void InitBoneControllers();

float GetSequenceDuration() const;
float SetBlending(int iBlender, float flValue);
void GetBonePosition(int iBone, Vector &origin, Vector &angles);
void GetAutomovement(Vector &origin, Vector &angles, float flInterval = 0.1f);
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ BOOL EXT_FUNC __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *pPlayer, int slot)
MESSAGE_END();
#endif
// do we have fadetoblack on? (need to fade their screen back in)
if (fadetoblack.value)
if (fadetoblack.value == FADETOBLACK_STAY)
{
UTIL_ScreenFade(pPlayer, Vector(0, 0, 0), 0.001, 0, 0, FFADE_IN);
}
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void PlayerBlind(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAt
{
UTIL_ScreenFade(pPlayer, color, fadeTime, fadeHold, alpha, 0);

if (!fadetoblack.value)
if (fadetoblack.value != FADETOBLACK_STAY)
{
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions regamedll/dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,7 @@ void CHalfLifeMultiplay::Think()
MESSAGE_BEGIN(MSG_ALL, gmsgForceCam);
WRITE_BYTE(forcecamera.value != 0);
WRITE_BYTE(forcechasecam.value != 0);
WRITE_BYTE(fadetoblack.value != 0);
WRITE_BYTE(fadetoblack.value == FADETOBLACK_STAY);
MESSAGE_END();

m_flForceCameraValue = forcecamera.value;
Expand Down Expand Up @@ -3456,7 +3456,7 @@ void CHalfLifeMultiplay::InitHUD(CBasePlayer *pl)
MESSAGE_BEGIN(MSG_ONE, gmsgForceCam, nullptr, pl->edict());
WRITE_BYTE(forcecamera.value != 0);
WRITE_BYTE(forcechasecam.value != 0);
WRITE_BYTE(fadetoblack.value != 0);
WRITE_BYTE(fadetoblack.value == FADETOBLACK_STAY);
MESSAGE_END();

if (m_bGameOver)
Expand Down Expand Up @@ -3874,7 +3874,7 @@ BOOL EXT_FUNC CHalfLifeMultiplay::__API_HOOK(FPlayerCanRespawn)(CBasePlayer *pPl
{
// If this player just connected and fadetoblack is on, then maybe
// the server admin doesn't want him peeking around.
if (fadetoblack.value != 0.0f)
if (fadetoblack.value == FADETOBLACK_STAY)
{
UTIL_ScreenFade(pPlayer, Vector(0, 0, 0), 3, 3, 255, (FFADE_OUT | FFADE_STAYOUT));
}
Expand Down
4 changes: 2 additions & 2 deletions regamedll/dlls/observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int __API_HOOK(GetForceCamera)(CBasePlayer *pObserver)
{
int retVal;

if (!fadetoblack.value)
if (fadetoblack.value != FADETOBLACK_STAY)
{
retVal = int(CVAR_GET_FLOAT("mp_forcechasecam"));

Expand Down Expand Up @@ -51,7 +51,7 @@ void UpdateClientEffects(CBasePlayer *pObserver, int oldMode)
{
bool clearProgress = false;
bool clearBlindness = false;
bool blindnessOk = (fadetoblack.value == 0);
bool blindnessOk = (fadetoblack.value != FADETOBLACK_STAY);
bool clearNightvision = false;

if (pObserver->GetObserverMode() == OBS_IN_EYE)
Expand Down
6 changes: 6 additions & 0 deletions regamedll/dlls/observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#define CAMERA_MODE_SPEC_ONLY_TEAM 1
#define CAMERA_MODE_SPEC_ONLY_FIRST_PERSON 2

enum FadeToBlack {
FADETOBLACK_OFF,
FADETOBLACK_STAY,
FADETOBLACK_AT_DYING,
};

int GetForceCamera(CBasePlayer *pObserver);
void UpdateClientEffects(CBasePlayer *pObserver, int oldMode);

Expand Down
51 changes: 24 additions & 27 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,8 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
UTIL_ScreenFade(this, Vector(0, 0, 0), 3, 3, 255, (FFADE_OUT | FFADE_STAYOUT));
}
#else

float flDyingDuration = GetSequenceDuration() + CGameRules::GetDyingTime();
switch ((int)fadetoblack.value)
{
default:
Expand All @@ -2307,12 +2309,12 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)

break;
}
case 1:
case FADETOBLACK_STAY:
{
UTIL_ScreenFade(this, Vector(0, 0, 0), 3, 3, 255, (FFADE_OUT | FFADE_STAYOUT));
UTIL_ScreenFade(this, Vector(0, 0, 0), 0.8f, flDyingDuration, 255, (FFADE_OUT | FFADE_STAYOUT));
break;
}
case 2:
case FADETOBLACK_AT_DYING:
{
pev->iuser1 = OBS_CHASE_FREE;
pev->iuser2 = ENTINDEX(edict());
Expand All @@ -2323,15 +2325,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
MESSAGE_BEGIN(MSG_ONE, gmsgADStop, nullptr, pev);
MESSAGE_END();

for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer* pObserver = UTIL_PlayerByIndex(i);

if (pObserver == this || (pObserver && pObserver->IsObservingPlayer(this)))
{
UTIL_ScreenFade(pObserver, Vector(0, 0, 0), 1, 4, 255, (FFADE_OUT));
}
}
UTIL_ScreenFade(this, Vector(0, 0, 0), 0.8f, flDyingDuration, 255, (FFADE_OUT));

break;
}
Expand Down Expand Up @@ -8811,6 +8805,23 @@ int GetPlayerGaitsequence(const edict_t *pEdict)
return pPlayer->m_iGaitsequence;
}

float CBasePlayer::GetDyingAnimationDuration() const
{
float animDuration = -1.0f;

if (CGameRules::GetDyingTime() < DEATH_ANIMATION_TIME) // a short time, timeDiff estimates to be small
{
float flSequenceDuration = GetSequenceDuration();
if (flSequenceDuration > 0)
animDuration = flSequenceDuration;
}

if (animDuration <= 0)
animDuration = CGameRules::GetDyingTime(); // in case of failure

return animDuration;
}

void CBasePlayer::SpawnClientSideCorpse()
{
#ifdef REGAMEDLL_FIXES
Expand All @@ -8833,21 +8844,7 @@ void CBasePlayer::SpawnClientSideCorpse()
#ifdef REGAMEDLL_ADD
if (CGameRules::GetDyingTime() < DEATH_ANIMATION_TIME) // a short time, timeDiff estimates to be small
{
float animDuration = -1.0;

studiohdr_t *pstudiohdr = (studiohdr_t *)GET_MODEL_PTR(ENT(pev));
if (pstudiohdr && pev->sequence < pstudiohdr->numseq) // model ptr and sequence validation
{
// get current sequence time
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + int(pev->sequence);
animDuration = pseqdesc->numframes / pseqdesc->fps;
}

if (animDuration <= 0.0)
{
// in case of failure
animDuration = DEATH_ANIMATION_TIME;
}
float animDuration = GetDyingAnimationDuration();

// client receives a negative value
animDuration *= -1.0;
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ class CBasePlayer: public CBaseMonster {
static CBasePlayer *Instance(entvars_t *pev) { return Instance(ENT(pev)); }
static CBasePlayer *Instance(int offset) { return Instance(ENT(offset)); }

float GetDyingAnimationDuration() const;
void SpawnClientSideCorpse();
void Observer_FindNextPlayer(bool bReverse, const char *name = nullptr);
CBasePlayer *Observer_IsValidTarget(int iPlayerIndex, bool bSameTeam);
Expand Down

0 comments on commit 9427767

Please sign in to comment.