Fix editor smooth zooming when joining/reloading game

Using `IClient::LocalTime` for smooth zooming in the editor causes the zoom to behave incorrectly when joining a game, as the local time is reset when joining a game.
This is fixed by adding a separate `IClient::GlobalTime` which is only set once when the client launches and never resets.
This commit is contained in:
Robert Müller 2022-12-15 18:18:06 +01:00
parent 612ef8358c
commit a0553f2d40
4 changed files with 8 additions and 4 deletions

View file

@ -84,6 +84,7 @@ protected:
float m_aPredIntraTick[NUM_DUMMIES];
float m_LocalTime;
float m_GlobalTime;
float m_RenderFrameTime;
int m_GameTickSpeed;
@ -146,6 +147,7 @@ public:
// other time access
inline float RenderFrameTime() const { return m_RenderFrameTime; }
inline float LocalTime() const { return m_LocalTime; }
inline float GlobalTime() const { return m_GlobalTime; }
inline float FrameTimeAvg() const { return m_FrameTimeAvg; }
// actions

View file

@ -2964,7 +2964,7 @@ void CClient::InitInterfaces()
void CClient::Run()
{
m_LocalStartTime = time_get();
m_LocalStartTime = m_GlobalStartTime = time_get();
#if defined(CONF_VIDEORECORDER)
IVideo::SetLocalStartTime(m_LocalStartTime);
#endif
@ -3383,8 +3383,9 @@ void CClient::Run()
g_Config.m_DbgHitch = 0;
}
// update local time
// update local and global time
m_LocalTime = (time_get() - m_LocalStartTime) / (float)time_freq();
m_GlobalTime = (time_get() - m_GlobalStartTime) / (float)time_freq();
}
#if defined(CONF_FAMILY_UNIX)

View file

@ -143,6 +143,7 @@ class CClient : public IClient, public CDemoPlayer::IListener
uint64_t m_aSnapshotParts[NUM_DUMMIES];
int64_t m_LocalStartTime;
int64_t m_GlobalStartTime;
IGraphics::CTextureHandle m_DebugFont;
int m_DebugSoundIndex = 0;

View file

@ -6080,7 +6080,7 @@ void CEditor::SetZoom(float Target)
{
Target = clamp(Target, MinZoomLevel(), MaxZoomLevel());
const float Now = Client()->LocalTime();
const float Now = Client()->GlobalTime();
float Current = m_Zoom;
float Derivative = 0.0f;
if(m_Zooming)
@ -6128,7 +6128,7 @@ void CEditor::UpdateZoom()
{
if(m_Zooming)
{
const float Time = Client()->LocalTime();
const float Time = Client()->GlobalTime();
const float OldLevel = m_Zoom;
if(Time >= m_ZoomSmoothingEnd)
{