diff --git a/src/engine/client.h b/src/engine/client.h index a9599f89b4a..8dcc9839e2a 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -282,8 +282,6 @@ class IClient : public IInterface virtual bool IsSixup() const = 0; - virtual int GetCurrentRaceTime() = 0; - virtual void RaceRecord_Start(const char *pFilename) = 0; virtual void RaceRecord_Stop() = 0; virtual bool RaceRecord_IsRecording() = 0; @@ -369,7 +367,6 @@ class IGameClient : public IInterface virtual int OnSnapInput(int *pData, bool Dummy, bool Force) = 0; virtual void OnDummySwap() = 0; virtual void SendDummyInfo(bool Start) = 0; - virtual int GetLastRaceTick() const = 0; virtual const char *GetItemName(int Type) const = 0; virtual const char *Version() const = 0; diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index d66254ef6e3..fa1bcc6f8d7 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -772,13 +772,6 @@ bool CClient::DummyAllowed() const return m_ServerCapabilities.m_AllowDummy; } -int CClient::GetCurrentRaceTime() -{ - if(GameClient()->GetLastRaceTick() < 0) - return 0; - return (GameTick(g_Config.m_ClDummy) - GameClient()->GetLastRaceTick()) / GameTickSpeed(); -} - void CClient::GetServerInfo(CServerInfo *pServerInfo) const { mem_copy(pServerInfo, &m_CurrentServerInfo, sizeof(m_CurrentServerInfo)); diff --git a/src/engine/client/client.h b/src/engine/client/client.h index 6113c4acf67..9b3104727e7 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -487,8 +487,6 @@ class CClient : public IClient, public CDemoPlayer::IListener void GenerateTimeoutSeed() override; void GenerateTimeoutCodes(const NETADDR *pAddrs, int NumAddrs); - int GetCurrentRaceTime() override; - const char *GetCurrentMap() const override; const char *GetCurrentMapPath() const override; SHA256_DIGEST GetCurrentMapSha256() const override; diff --git a/src/game/client/components/ghost.cpp b/src/game/client/components/ghost.cpp index a6fe5ab3020..090eed3e7a5 100644 --- a/src/game/client/components/ghost.cpp +++ b/src/game/client/components/ghost.cpp @@ -15,9 +15,6 @@ const char *CGhost::ms_pGhostDir = "ghosts"; -CGhost::CGhost() : - m_NewRenderTick(-1), m_StartRenderTick(-1), m_LastDeathTick(-1), m_LastRaceTick(-1), m_Recording(false), m_Rendering(false) {} - void CGhost::GetGhostSkin(CGhostSkin *pSkin, const char *pSkinName, int UseCustomColor, int ColorBody, int ColorFeet) { StrToInts(&pSkin->m_Skin0, 6, pSkinName); @@ -187,13 +184,13 @@ void CGhost::CheckStart() int RaceTick = -m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer; int RenderTick = m_NewRenderTick; - if(m_LastRaceTick != RaceTick && Client()->GameTick(g_Config.m_ClDummy) - RaceTick < Client()->GameTickSpeed()) + if(GameClient()->LastRaceTick() != RaceTick && Client()->GameTick(g_Config.m_ClDummy) - RaceTick < Client()->GameTickSpeed()) { if(m_Rendering && m_RenderingStartedByServer) // race restarted: stop rendering StopRender(); - if(m_Recording && m_LastRaceTick != -1) // race restarted: activate restarting for local start detection so we have a smooth transition + if(m_Recording && GameClient()->LastRaceTick() != -1) // race restarted: activate restarting for local start detection so we have a smooth transition m_AllowRestart = true; - if(m_LastRaceTick == -1) // no restart: reset rendering preparations + if(GameClient()->LastRaceTick() == -1) // no restart: reset rendering preparations m_NewRenderTick = -1; if(GhostRecorder()->IsRecording()) // race restarted: stop recording GhostRecorder()->Stop(0, -1); @@ -271,28 +268,21 @@ void CGhost::TryRenderStart(int Tick, bool ServerControl) void CGhost::OnNewSnapshot() { - if(!GameClient()->m_GameInfo.m_Race || Client()->State() != IClient::STATE_ONLINE) + if(!GameClient()->m_GameInfo.m_Race || !g_Config.m_ClRaceGhost || Client()->State() != IClient::STATE_ONLINE) return; if(!m_pClient->m_Snap.m_pGameInfoObj || m_pClient->m_Snap.m_SpecInfo.m_Active || !m_pClient->m_Snap.m_pLocalCharacter || !m_pClient->m_Snap.m_pLocalPrevCharacter) return; - bool RaceFlag = m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_RACETIME; - bool ServerControl = RaceFlag && g_Config.m_ClRaceGhostServerControl; - - if(g_Config.m_ClRaceGhost) - { - if(!ServerControl) - CheckStartLocal(false); - else - CheckStart(); + const bool RaceFlag = m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_RACETIME; + const bool ServerControl = RaceFlag && g_Config.m_ClRaceGhostServerControl; - if(m_Recording) - AddInfos(m_pClient->m_Snap.m_pLocalCharacter, (m_pClient->m_Snap.m_LocalClientId != -1 && m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_LocalClientId].m_HasExtendedData) ? &m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_LocalClientId].m_ExtendedData : nullptr); - } + if(!ServerControl) + CheckStartLocal(false); + else + CheckStart(); - // Record m_LastRaceTick for g_Config.m_ClConfirmDisconnect/QuitTime anyway - int RaceTick = -m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer; - m_LastRaceTick = RaceFlag ? RaceTick : -1; + if(m_Recording) + AddInfos(m_pClient->m_Snap.m_pLocalCharacter, (m_pClient->m_Snap.m_LocalClientId != -1 && m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_LocalClientId].m_HasExtendedData) ? &m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_LocalClientId].m_ExtendedData : nullptr); } void CGhost::OnNewPredictedSnapshot() @@ -302,8 +292,8 @@ void CGhost::OnNewPredictedSnapshot() if(!m_pClient->m_Snap.m_pGameInfoObj || m_pClient->m_Snap.m_SpecInfo.m_Active || !m_pClient->m_Snap.m_pLocalCharacter || !m_pClient->m_Snap.m_pLocalPrevCharacter) return; - bool RaceFlag = m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_RACETIME; - bool ServerControl = RaceFlag && g_Config.m_ClRaceGhostServerControl; + const bool RaceFlag = m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_RACETIME; + const bool ServerControl = RaceFlag && g_Config.m_ClRaceGhostServerControl; if(!ServerControl) CheckStartLocal(true); @@ -647,7 +637,6 @@ void CGhost::OnReset() StopRecord(); StopRender(); m_LastDeathTick = -1; - m_LastRaceTick = -1; } void CGhost::OnShutdown() @@ -663,11 +652,6 @@ void CGhost::OnMapLoad() m_AllowRestart = false; } -int CGhost::GetLastRaceTick() const -{ - return m_LastRaceTick; -} - void CGhost::OnRefreshSkins() { const auto &&RefindSkin = [&](auto &Ghost) { diff --git a/src/game/client/components/ghost.h b/src/game/client/components/ghost.h index e1c263677c4..7fd6ed354ea 100644 --- a/src/game/client/components/ghost.h +++ b/src/game/client/components/ghost.h @@ -113,16 +113,14 @@ class CGhost : public CComponent CGhostItem m_aActiveGhosts[MAX_ACTIVE_GHOSTS]; CGhostItem m_CurGhost; - char m_aTmpFilename[128]; + char m_aTmpFilename[IO_MAX_PATH_LENGTH]; - int m_NewRenderTick; - int m_StartRenderTick; - int m_LastDeathTick; - int m_LastRaceTick; - bool m_Recording; - bool m_Rendering; - - bool m_RenderingStartedByServer; + int m_NewRenderTick = -1; + int m_StartRenderTick = -1; + int m_LastDeathTick = -1; + bool m_Recording = false; + bool m_Rendering = false; + bool m_RenderingStartedByServer = false; static void GetGhostSkin(CGhostSkin *pSkin, const char *pSkinName, int UseCustomColor, int ColorBody, int ColorFeet); static void GetGhostCharacter(CGhostCharacter *pGhostChar, const CNetObj_Character *pChar, const CNetObj_DDNetCharacter *pDDnetChar); @@ -149,7 +147,6 @@ class CGhost : public CComponent public: bool m_AllowRestart; - CGhost(); virtual int Sizeof() const override { return sizeof(*this); } virtual void OnRender() override; @@ -174,8 +171,6 @@ class CGhost : public CComponent class IGhostLoader *GhostLoader() const { return m_pGhostLoader; } class IGhostRecorder *GhostRecorder() const { return m_pGhostRecorder; } - - int GetLastRaceTick() const; }; #endif diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 7712e650721..8e95087f8c8 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -548,7 +548,7 @@ void CMenus::RenderMenubar(CUIRect Box, IClient::EClientState ClientState) ColorRGBA QuitColor(1, 0, 0, 0.5f); if(DoButton_MenuTab(&s_QuitButton, FONT_ICON_POWER_OFF, 0, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_QUIT], nullptr, nullptr, &QuitColor, 10.0f)) { - if(m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0)) + if(m_pClient->Editor()->HasUnsavedData() || (GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0)) { m_Popup = POPUP_QUIT; } diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 608975e4660..fd935719ca3 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -637,7 +637,7 @@ void CMenus::RenderServerbrowserStatusBox(CUIRect StatusBox, bool WasListboxItem void CMenus::Connect(const char *pAddress) { - if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) + if(Client()->State() == IClient::STATE_ONLINE && GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) { str_copy(m_aNextServer, pAddress); PopupConfirm(Localize("Disconnect"), Localize("Are you sure that you want to disconnect and switch to a different server?"), Localize("Yes"), Localize("No"), &CMenus::PopupConfirmSwitchServer); diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index ab511e76889..fdc8459e347 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -58,7 +58,7 @@ void CMenus::RenderGame(CUIRect MainView) static CButtonContainer s_DisconnectButton; if(DoButton_Menu(&s_DisconnectButton, Localize("Disconnect"), 0, &Button)) { - if(Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) + if(GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) { PopupConfirm(Localize("Disconnect"), Localize("Are you sure that you want to disconnect?"), Localize("Yes"), Localize("No"), &CMenus::PopupConfirmDisconnect); } @@ -95,7 +95,7 @@ void CMenus::RenderGame(CUIRect MainView) } else { - if(Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) + if(GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) { PopupConfirm(Localize("Disconnect Dummy"), Localize("Are you sure that you want to disconnect your dummy?"), Localize("Yes"), Localize("No"), &CMenus::PopupConfirmDisconnectDummy); } diff --git a/src/game/client/components/menus_start.cpp b/src/game/client/components/menus_start.cpp index de7520404b9..0224b7c2672 100644 --- a/src/game/client/components/menus_start.cpp +++ b/src/game/client/components/menus_start.cpp @@ -108,7 +108,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) bool UsedEscape = false; if(DoButton_Menu(&s_QuitButton, Localize("Quit"), 0, &Button, 0, IGraphics::CORNER_ALL, Rounding, 0.5f, ColorRGBA(0.0f, 0.0f, 0.0f, 0.25f)) || (UsedEscape = Ui()->ConsumeHotkey(CUi::HOTKEY_ESCAPE)) || CheckHotKey(KEY_Q)) { - if(UsedEscape || m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0)) + if(UsedEscape || m_pClient->Editor()->HasUnsavedData() || (GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0)) { m_Popup = POPUP_QUIT; } diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 23158a84118..dd62db7031a 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -572,6 +572,7 @@ void CGameClient::OnReset() std::fill(std::begin(m_aLastNewPredictedTick), std::end(m_aLastNewPredictedTick), -1); m_LastRoundStartTick = -1; + m_LastRaceTick = -1; m_LastFlagCarrierRed = -4; m_LastFlagCarrierBlue = -4; @@ -844,9 +845,18 @@ void CGameClient::OnDummyDisconnect() m_PredictedDummyId = -1; } -int CGameClient::GetLastRaceTick() const +int CGameClient::LastRaceTick() const { - return m_Ghost.GetLastRaceTick(); + return m_LastRaceTick; +} + +int CGameClient::CurrentRaceTime() const +{ + if(m_LastRaceTick < 0) + { + return 0; + } + return (Client()->GameTick(g_Config.m_ClDummy) - m_LastRaceTick) / Client()->GameTickSpeed(); } bool CGameClient::Predict() const @@ -2088,6 +2098,19 @@ void CGameClient::OnNewSnapshot() } } } + + // Record m_LastRaceTick for g_Config.m_ClConfirmDisconnect/QuitTime + if(m_GameInfo.m_Race && + Client()->State() == IClient::STATE_ONLINE && + m_Snap.m_pGameInfoObj && + !m_Snap.m_SpecInfo.m_Active && + m_Snap.m_pLocalCharacter && + m_Snap.m_pLocalPrevCharacter) + { + const bool RaceFlag = m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_RACETIME; + m_LastRaceTick = RaceFlag ? -m_Snap.m_pGameInfoObj->m_WarmupTimer : -1; + } + if(m_Snap.m_LocalClientId != m_PrevLocalId) m_PredictedDummyId = m_PrevLocalId; m_PrevLocalId = m_Snap.m_LocalClientId; diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 619f2d2fcbe..b8f2d9c95c7 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -209,6 +209,7 @@ class CGameClient : public IGameClient int m_aLastNewPredictedTick[NUM_DUMMIES]; int m_LastRoundStartTick; + int m_LastRaceTick; int m_LastFlagCarrierRed; int m_LastFlagCarrierBlue; @@ -579,7 +580,8 @@ class CGameClient : public IGameClient int IntersectCharacter(vec2 HookPos, vec2 NewPos, vec2 &NewPos2, int OwnId); - int GetLastRaceTick() const override; + int LastRaceTick() const; + int CurrentRaceTime() const; bool IsTeamPlay() { return m_Snap.m_pGameInfoObj && m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS; }