MCPcopy Create free account
hub / github.com/ddnet/ddnet / UpdateCamera

Method UpdateCamera

src/game/client/components/camera.cpp:117–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117void CCamera::UpdateCamera()
118{
119 // use hardcoded smooth camera for spectating unless player explicitly turn it off
120 bool CanUseCameraInfo = !GameClient()->m_MultiViewActivated;
121 if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
122 {
123 // only follow mode have the correct camera info
124 CanUseCameraInfo = CanUseCameraInfo && GameClient()->m_DemoSpecId == SPEC_FOLLOW;
125 }
126 else
127 {
128 CanUseCameraInfo = CanUseCameraInfo && GameClient()->m_Snap.m_SpecInfo.m_Active &&
129 GameClient()->m_Snap.m_SpecInfo.m_SpectatorId >= 0 &&
130 GameClient()->m_Snap.m_SpecInfo.m_SpectatorId != GameClient()->m_aLocalIds[0] &&
131 (!GameClient()->Client()->DummyConnected() || GameClient()->m_Snap.m_SpecInfo.m_SpectatorId != GameClient()->m_aLocalIds[1]);
132 }
133
134 bool UsingAutoSpecCamera = m_AutoSpecCamera && CanUseAutoSpecCamera();
135 float CurrentZoom = m_Zooming ? m_ZoomSmoothingTarget : m_Zoom;
136 bool ZoomChanged = false;
137 if(CanUseCameraInfo && UsingAutoSpecCamera && CurrentZoom != GameClient()->m_Snap.m_SpecInfo.m_Zoom)
138 {
139 // start spectating player / turn on auto spec camera
140 bool ChangeTarget = m_PrevSpecId != GameClient()->m_Snap.m_SpecInfo.m_SpectatorId;
141 float SmoothTime = ChangeTarget ? g_Config.m_ClSmoothSpectatingTime : 250;
142 ChangeZoom(GameClient()->m_Snap.m_SpecInfo.m_Zoom, SmoothTime, false);
143
144 // it is auto spec camera zooming if only the zoom is changed during activation, not at the start of the activation
145 m_AutoSpecCameraZooming = !ChangeTarget && CanUseCameraInfo && m_UsingAutoSpecCamera;
146
147 ZoomChanged = true;
148 }
149 else if((CanUseCameraInfo && !UsingAutoSpecCamera) && CurrentZoom != m_UserZoomTarget)
150 {
151 // turning off auto spec camera
152 ChangeZoom(m_UserZoomTarget, g_Config.m_ClSmoothZoomTime, false);
153 m_AutoSpecCameraZooming = false;
154
155 ZoomChanged = true;
156 }
157 else if(!CanUseCameraInfo && CurrentZoom != m_UserZoomTarget)
158 {
159 // stop spectating player
160 if(!GameClient()->m_MultiViewActivated)
161 ChangeZoom(m_UserZoomTarget, g_Config.m_ClSmoothZoomTime, false);
162 m_AutoSpecCameraZooming = false;
163
164 ZoomChanged = true;
165 }
166
167 // snap zoom when going in and out of spectating
168 if(ZoomChanged && m_WasSpectating != GameClient()->m_Snap.m_SpecInfo.m_Active)
169 {
170 m_Zoom = m_ZoomSmoothingTarget;
171 m_Zooming = false;
172 }
173
174 if(m_Zooming)

Callers 1

OnRenderMethod · 0.80

Calls 12

lengthFunction · 0.85
maximumFunction · 0.85
normalize_pre_lengthFunction · 0.85
DummyConnectedMethod · 0.80
EvaluateMethod · 0.80
TargetMethod · 0.80
RenderFrameTimeMethod · 0.80
ClientFunction · 0.50
minimumFunction · 0.50
StateMethod · 0.45
ClientMethod · 0.45
LocalTimeMethod · 0.45

Tested by

no test coverage detected