From 0721b895ae3651df51b28295ce704955cfe30c44 Mon Sep 17 00:00:00 2001 From: Redix Date: Sun, 10 Sep 2017 04:57:03 +0200 Subject: [PATCH] Make sure that we have a free ghost slot for new records --- src/game/client/components/ghost.cpp | 14 +++++++++++++- src/game/client/components/ghost.h | 3 ++- src/game/client/components/menus_ingame.cpp | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/ghost.cpp b/src/game/client/components/ghost.cpp index e072426da..a981b4841 100644 --- a/src/game/client/components/ghost.cpp +++ b/src/game/client/components/ghost.cpp @@ -90,6 +90,15 @@ int CGhost::GetSlot() const return -1; } +int CGhost::FreeSlot() const +{ + int Num = 0; + for(int i = 0; i < MAX_ACTIVE_GHOSTS; i++) + if(m_aActiveGhosts[i].Empty()) + Num++; + return Num; +} + void CGhost::OnRender() { // only for race @@ -226,8 +235,11 @@ void CGhost::StopRecord(int Time) CMenus::CGhostItem *pOwnGhost = m_pClient->m_pMenus->GetOwnGhost(); if(Time > 0 && (!pOwnGhost || Time < pOwnGhost->m_Time)) { + if(pOwnGhost && pOwnGhost->Active()) + Unload(pOwnGhost->m_Slot); + // add to active ghosts - int Slot = pOwnGhost ? pOwnGhost->m_Slot : GetSlot(); + int Slot = GetSlot(); if(Slot != -1) m_aActiveGhosts[Slot] = m_CurGhost; diff --git a/src/game/client/components/ghost.h b/src/game/client/components/ghost.h index a0bf2b737..5461638dd 100644 --- a/src/game/client/components/ghost.h +++ b/src/game/client/components/ghost.h @@ -85,6 +85,7 @@ private: static void GetNetObjCharacter(CNetObj_Character *pChar, const CGhostCharacter *pGhostChar); void AddInfos(const CNetObj_Character *pChar); + int GetSlot() const; void StartRecord(); void StopRecord(int Time = -1); @@ -106,7 +107,7 @@ public: virtual void OnMessage(int MsgType, void *pRawMsg); virtual void OnMapLoad(); - int GetSlot() const; + int FreeSlot() const; int Load(const char *pFilename); void Unload(int Slot); diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 2b70de5d1..21fbbfc61 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -1140,7 +1140,9 @@ void CMenus::RenderGhost(CUIRect MainView) static int s_SaveButton = 0; static int s_ReloadButton = 0; - if(pGhost->HasFile() && (pGhost->Active() || m_pClient->m_pGhost->GetSlot() != -1)) + CGhostItem *pOwnGhost = GetOwnGhost(); + int ReservedSlots = !pGhost->m_Own && !(pOwnGhost && pOwnGhost->Active()); + if(pGhost->HasFile() && (pGhost->Active() || m_pClient->m_pGhost->FreeSlot() > ReservedSlots)) { Status.VSplitRight(120.0f, &Status, &Button);