diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 899456e0b..41607b904 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -2668,6 +2668,19 @@ void CClient::Update() } } + if(State() == IClient::STATE_ONLINE) + { + if(m_EditJobs.size() > 0) + { + std::shared_ptr e = m_EditJobs.front(); + if(e->Status() == IJob::STATE_DONE) + { + Notify(Localize("Replay"), Localize("Successfully saved the replay!")); + m_EditJobs.pop_front(); + } + } + } + // update the maser server registry MasterServer()->Update(); @@ -3326,8 +3339,12 @@ void CClient::SaveReplay() const int StartTick = EndTick - g_Config.m_ClReplayLength * GameTickSpeed(); // Create a job to do this slicing in background because it can be a bit long depending on the file size - std::shared_ptr pDemoEditTask = std::make_shared(this, &m_SnapshotDelta, m_pConsole, pSrc, aFilename, StartTick, EndTick); + std::shared_ptr pDemoEditTask = std::make_shared(GameClient()->NetVersion(), &m_SnapshotDelta, m_pConsole, m_pStorage, pSrc, aFilename, StartTick, EndTick); Engine()->AddJob(pDemoEditTask); + m_EditJobs.push_back(pDemoEditTask); + + // And we restart the recorder + DemoRecorder_StartReplayRecorder(); } } } @@ -3989,13 +4006,9 @@ void CClient::GetSmoothTick(int *pSmoothTick, float *pSmoothIntraTick, float Mix *pSmoothIntraTick = (SmoothTime - (*pSmoothTick-1)*time_freq()/50) / (float)(time_freq()/50); } -CDemoEdit::~CDemoEdit() -{ -} - -CDemoEdit::CDemoEdit(CClient *pClient, CSnapshotDelta *pSnapshotDelta, IConsole *pConsole, const char *pDemo, const char *pDst, int StartTick, int EndTick) : - m_pClient(pClient), - m_pConsole(pConsole) +CDemoEdit::CDemoEdit(const char *pNetVersion, CSnapshotDelta *pSnapshotDelta, IConsole *pConsole, IStorage *pStorage, const char *pDemo, const char *pDst, int StartTick, int EndTick) : + m_pConsole(pConsole), + m_pStorage(pStorage) { str_copy(m_pDemo, pDemo, sizeof(m_pDemo)); str_copy(m_pDst, pDst, sizeof(m_pDst)); @@ -4004,7 +4017,7 @@ CDemoEdit::CDemoEdit(CClient *pClient, CSnapshotDelta *pSnapshotDelta, IConsole m_EndTick = EndTick; // Init the demoeditor - m_DemoEditor.Init(pClient->GameClient()->NetVersion(), pSnapshotDelta, pConsole, pClient->Storage()); + m_DemoEditor.Init(pNetVersion, pSnapshotDelta, pConsole, pStorage); } void CDemoEdit::Run() @@ -4017,12 +4030,6 @@ void CDemoEdit::Run() str_format(aBuf, sizeof(aBuf), "Successfully saved the replay to %s!", m_pDst); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", aBuf); - m_pClient->Notify(Localize("Replay"), Localize("Successfully saved the replay!")); - // We remove the temporary demo file - const char *pFilename = m_pClient->DemoRecorder(RECORDER_REPLAYS)->GetCurrentFilename(); - m_pClient->Storage()->RemoveFile(pFilename, IStorage::TYPE_SAVE); - - // And we restart the recorder - m_pClient->DemoRecorder_StartReplayRecorder(); + m_pStorage->RemoveFile(m_pDemo, IStorage::TYPE_SAVE); } diff --git a/src/engine/client/client.h b/src/engine/client/client.h index 3e3586abf..be8ca6154 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -55,6 +55,22 @@ public: void Update(CGraph *pGraph, int64 Target, int TimeLeft, int AdjustDirection); }; +class CDemoEdit : public IJob +{ + IStorage *m_pStorage; + IConsole *m_pConsole; + CDemoEditor m_DemoEditor; + char m_pDemo[256]; + char m_pDst[256]; + int m_StartTick; + int m_EndTick; + +public: + CDemoEdit(const char *pNetVersion, CSnapshotDelta *pSnapshotDelta, IConsole *pConsole, IStorage *pStorage, const char *pDemo, const char *pDst, int StartTick, int EndTick); + ~CDemoEdit(); + void Run(); +}; + class CClient : public IClient, public CDemoPlayer::IListener { // needed interfaces @@ -187,6 +203,8 @@ class CClient : public IClient, public CDemoPlayer::IListener class CSnapshotDelta m_SnapshotDelta; + std::list> m_EditJobs; + // class CServerInfo m_CurrentServerInfo; int64 m_CurrentServerInfoRequestTime; // >= 0 should request, == -1 got info @@ -425,20 +443,4 @@ public: void GetSmoothTick(int *pSmoothTick, float *pSmoothIntraTick, float MixAmount); }; -class CDemoEdit : public IJob -{ - CClient *m_pClient; - IConsole *m_pConsole; - CDemoEditor m_DemoEditor; - char m_pDemo[256]; - char m_pDst[256]; - int m_StartTick; - int m_EndTick; - -public: - CDemoEdit(CClient *pClient, CSnapshotDelta *pSnapshotDelta, IConsole *pConsole, const char *pDemo, const char *pDst, int StartTick, int EndTick); - ~CDemoEdit(); - void Run(); -}; - #endif