Skip to content

Commit

Permalink
Merge pull request #9472 from TsFreddie/fix-demo-cursor
Browse files Browse the repository at this point in the history
Fix cursor and auto spec cam in demo
  • Loading branch information
def- authored Jan 3, 2025
2 parents be5f7a5 + fe39848 commit 7df4613
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions src/game/client/components/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void CCamera::UpdateCamera()
bool IsSpectatingPlayer = !GameClient()->m_MultiViewActivated;
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
{
IsSpectatingPlayer = IsSpectatingPlayer && m_pClient->m_Snap.m_SpecInfo.m_SpectatorId >= 0;
IsSpectatingPlayer = IsSpectatingPlayer && (!m_pClient->m_Snap.m_SpecInfo.m_Active || m_pClient->m_Snap.m_SpecInfo.m_SpectatorId >= 0);
}
else
{
Expand All @@ -129,39 +129,41 @@ void CCamera::UpdateCamera()

bool UsingAutoSpecCamera = m_AutoSpecCamera && CanUseAutoSpecCamera();
float CurrentZoom = m_Zooming ? m_ZoomSmoothingTarget : m_Zoom;

bool ZoomChanged = false;
if(IsSpectatingPlayer && UsingAutoSpecCamera && CurrentZoom != m_pClient->m_Snap.m_SpecInfo.m_Zoom)
{
// start spectating player / turn on auto spec camera
bool ChangeTarget = m_PrevSpecId != m_pClient->m_Snap.m_SpecInfo.m_SpectatorId;
float SmoothTime = ChangeTarget ? g_Config.m_ClSmoothSpectatingTime : 250;
ChangeZoom(m_pClient->m_Snap.m_SpecInfo.m_Zoom, SmoothTime, false);

// it is auto spec camera zooming if only the zoom is changed during activation, not at the start of the activation
m_AutoSpecCameraZooming = !ChangeTarget && IsSpectatingPlayer && m_UsingAutoSpecCamera;

// snap zoom when going in and out of spectating
if(!m_WasSpectating)
{
m_Zoom = m_ZoomSmoothingTarget;
m_Zooming = false;
}
ZoomChanged = true;
}
else if((IsSpectatingPlayer && !UsingAutoSpecCamera) && CurrentZoom != m_UserZoomTarget)
{
// turning off auto spec camera
ChangeZoom(m_UserZoomTarget, g_Config.m_ClSmoothZoomTime, false);
m_AutoSpecCameraZooming = false;

ZoomChanged = true;
}
else if(!IsSpectatingPlayer && CurrentZoom != m_UserZoomTarget)
{
// stop spectating player
ChangeZoom(m_UserZoomTarget, GameClient()->m_MultiViewActivated ? g_Config.m_ClMultiViewZoomSmoothness : g_Config.m_ClSmoothZoomTime, false);
m_AutoSpecCameraZooming = false;

// snap zoom when going in and out of spectating
if(m_WasSpectating && !m_pClient->m_Snap.m_SpecInfo.m_Active)
{
m_Zoom = m_ZoomSmoothingTarget;
m_Zooming = false;
}
ZoomChanged = true;
}

// snap zoom when going in and out of spectating
if(ZoomChanged && m_WasSpectating != m_pClient->m_Snap.m_SpecInfo.m_Active)
{
m_Zoom = m_ZoomSmoothingTarget;
m_Zooming = false;
}

if(m_Zooming)
Expand Down Expand Up @@ -386,6 +388,8 @@ void CCamera::OnRender()

m_PrevCenter = m_Center;
m_PrevSpecId = SpecId;

// demo always count as spectating
m_WasSpectating = m_pClient->m_Snap.m_SpecInfo.m_Active;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3119,7 +3119,7 @@ void CGameClient::UpdatePrediction()
void CGameClient::UpdateSpectatorCursor()
{
int CursorOwnerId = m_Snap.m_LocalClientId;
if(m_Snap.m_SpecInfo.m_Active || Client()->State() == IClient::STATE_DEMOPLAYBACK)
if(m_Snap.m_SpecInfo.m_Active)
{
CursorOwnerId = m_Snap.m_SpecInfo.m_SpectatorId;
}
Expand Down

0 comments on commit 7df4613

Please sign in to comment.