mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
Merge pull request #8016 from dobrykafe/pr-save-replay-improve
Improvements regarding `save_replay`
This commit is contained in:
commit
7c4d51f111
|
@ -2612,11 +2612,20 @@ void CClient::Update()
|
||||||
if(pJob->State() == IJob::STATE_DONE)
|
if(pJob->State() == IJob::STATE_DONE)
|
||||||
{
|
{
|
||||||
char aBuf[IO_MAX_PATH_LENGTH + 64];
|
char aBuf[IO_MAX_PATH_LENGTH + 64];
|
||||||
str_format(aBuf, sizeof(aBuf), "Successfully saved the replay to %s!", pJob->Destination());
|
if(pJob->Success())
|
||||||
|
{
|
||||||
|
str_format(aBuf, sizeof(aBuf), "Successfully saved the replay to '%s'!", pJob->Destination());
|
||||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", aBuf);
|
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", aBuf);
|
||||||
|
|
||||||
GameClient()->Echo(Localize("Successfully saved the replay!"));
|
GameClient()->Echo(Localize("Successfully saved the replay!"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str_format(aBuf, sizeof(aBuf), "Failed saving the replay to '%s'...", pJob->Destination());
|
||||||
|
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", aBuf);
|
||||||
|
|
||||||
|
GameClient()->Echo(Localize("Failed saving the replay!"));
|
||||||
|
}
|
||||||
m_EditJobs.pop_front();
|
m_EditJobs.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3482,9 +3491,6 @@ void CClient::SaveReplay(const int Length, const char *pFilename)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// First we stop the recorder to slice correctly the demo after
|
|
||||||
DemoRecorder(RECORDER_REPLAYS)->Stop(IDemoRecorder::EStopMode::KEEP_FILE);
|
|
||||||
|
|
||||||
char aFilename[IO_MAX_PATH_LENGTH];
|
char aFilename[IO_MAX_PATH_LENGTH];
|
||||||
if(pFilename[0] == '\0')
|
if(pFilename[0] == '\0')
|
||||||
{
|
{
|
||||||
|
@ -3495,7 +3501,18 @@ void CClient::SaveReplay(const int Length, const char *pFilename)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str_format(aFilename, sizeof(aFilename), "demos/replays/%s.demo", pFilename);
|
str_format(aFilename, sizeof(aFilename), "demos/replays/%s.demo", pFilename);
|
||||||
|
IOHANDLE Handle = m_pStorage->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
|
if(!Handle)
|
||||||
|
{
|
||||||
|
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", "ERROR: invalid filename. Try a different one!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
io_close(Handle);
|
||||||
|
m_pStorage->RemoveFile(aFilename, IStorage::TYPE_SAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop the recorder to correctly slice the demo after
|
||||||
|
DemoRecorder(RECORDER_REPLAYS)->Stop(IDemoRecorder::EStopMode::KEEP_FILE);
|
||||||
|
|
||||||
// Slice the demo to get only the last cl_replay_length seconds
|
// Slice the demo to get only the last cl_replay_length seconds
|
||||||
const char *pSrc = m_aDemoRecorder[RECORDER_REPLAYS].CurrentFilename();
|
const char *pSrc = m_aDemoRecorder[RECORDER_REPLAYS].CurrentFilename();
|
||||||
|
|
|
@ -20,7 +20,8 @@ CDemoEdit::CDemoEdit(const char *pNetVersion, class CSnapshotDelta *pSnapshotDel
|
||||||
void CDemoEdit::Run()
|
void CDemoEdit::Run()
|
||||||
{
|
{
|
||||||
// Slice the current demo
|
// Slice the current demo
|
||||||
m_DemoEditor.Slice(m_aDemo, m_aDst, m_StartTick, m_EndTick, NULL, 0);
|
m_Success = m_DemoEditor.Slice(m_aDemo, m_aDst, m_StartTick, m_EndTick, NULL, 0);
|
||||||
// We remove the temporary demo file
|
// We remove the temporary demo file if slicing is successful
|
||||||
|
if(m_Success)
|
||||||
m_pStorage->RemoveFile(m_aDemo, IStorage::TYPE_SAVE);
|
m_pStorage->RemoveFile(m_aDemo, IStorage::TYPE_SAVE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,12 @@ class CDemoEdit : public IJob
|
||||||
char m_aDst[256];
|
char m_aDst[256];
|
||||||
int m_StartTick;
|
int m_StartTick;
|
||||||
int m_EndTick;
|
int m_EndTick;
|
||||||
|
bool m_Success;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CDemoEdit(const char *pNetVersion, CSnapshotDelta *pSnapshotDelta, IStorage *pStorage, const char *pDemo, const char *pDst, int StartTick, int EndTick);
|
CDemoEdit(const char *pNetVersion, CSnapshotDelta *pSnapshotDelta, IStorage *pStorage, const char *pDemo, const char *pDst, int StartTick, int EndTick);
|
||||||
void Run() override;
|
void Run() override;
|
||||||
char *Destination() { return m_aDst; }
|
char *Destination() { return m_aDst; }
|
||||||
|
bool Success() { return m_Success; }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -118,7 +118,7 @@ class IDemoEditor : public IInterface
|
||||||
{
|
{
|
||||||
MACRO_INTERFACE("demoeditor")
|
MACRO_INTERFACE("demoeditor")
|
||||||
public:
|
public:
|
||||||
virtual void Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser) = 0;
|
virtual bool Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1225,11 +1225,11 @@ void CDemoEditor::Init(const char *pNetVersion, class CSnapshotDelta *pSnapshotD
|
||||||
m_pStorage = pStorage;
|
m_pStorage = pStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser)
|
bool CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser)
|
||||||
{
|
{
|
||||||
CDemoPlayer DemoPlayer(m_pSnapshotDelta, false);
|
CDemoPlayer DemoPlayer(m_pSnapshotDelta, false);
|
||||||
if(DemoPlayer.Load(m_pStorage, m_pConsole, pDemo, IStorage::TYPE_ALL_OR_ABSOLUTE) == -1)
|
if(DemoPlayer.Load(m_pStorage, m_pConsole, pDemo, IStorage::TYPE_ALL_OR_ABSOLUTE) == -1)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
const CMapInfo *pMapInfo = DemoPlayer.GetMapInfo();
|
const CMapInfo *pMapInfo = DemoPlayer.GetMapInfo();
|
||||||
const CDemoPlayer::CPlaybackInfo *pInfo = DemoPlayer.Info();
|
const CDemoPlayer::CPlaybackInfo *pInfo = DemoPlayer.Info();
|
||||||
|
@ -1248,7 +1248,7 @@ void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int
|
||||||
if(Result != 0)
|
if(Result != 0)
|
||||||
{
|
{
|
||||||
DemoPlayer.Stop();
|
DemoPlayer.Stop();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDemoRecordingListener Listener;
|
CDemoRecordingListener Listener;
|
||||||
|
@ -1280,4 +1280,5 @@ void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int
|
||||||
|
|
||||||
DemoPlayer.Stop();
|
DemoPlayer.Stop();
|
||||||
DemoRecorder.Stop(IDemoRecorder::EStopMode::KEEP_FILE);
|
DemoRecorder.Stop(IDemoRecorder::EStopMode::KEEP_FILE);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ class CDemoEditor : public IDemoEditor
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Init(const char *pNetVersion, class CSnapshotDelta *pSnapshotDelta, class IConsole *pConsole, class IStorage *pStorage);
|
virtual void Init(const char *pNetVersion, class CSnapshotDelta *pSnapshotDelta, class IConsole *pConsole, class IStorage *pStorage);
|
||||||
void Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser) override;
|
bool Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue