Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cursor and auto spec cam in demo #9472

Merged
merged 1 commit into from
Jan 3, 2025
Merged
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
fix demo cursor
  • Loading branch information
TsFreddie committed Jan 3, 2025
commit fe3984846fbc8e0319c6a407c8f7d353ddda5d8e
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
Loading