Fix race recorder, make it remove tmp files consistently and clean it up a bit

This commit is contained in:
def 2015-08-22 15:09:19 +02:00
parent 79a523e8a8
commit 321f0d210a
2 changed files with 65 additions and 61 deletions

View file

@ -18,6 +18,27 @@ CRaceDemo::CRaceDemo()
m_DemoStartTick = 0;
}
void CRaceDemo::Stop()
{
if(Client()->RaceRecordIsRecording())
Client()->RaceRecordStop();
char aFilename[512];
str_format(aFilename, sizeof(aFilename), "demos/%s_tmp_%d.demo", m_pMap, pid());
Storage()->RemoveFile(aFilename, IStorage::TYPE_SAVE);
m_Time = 0;
m_RaceState = RACE_NONE;
m_RecordStopTime = 0;
m_DemoStartTick = 0;
}
void CRaceDemo::OnStateChange(int NewState, int OldState)
{
if(OldState == IClient::STATE_ONLINE)
Stop();
}
void CRaceDemo::OnRender()
{
if(!g_Config.m_ClAutoRaceRecord || !m_pClient->m_Snap.m_pGameInfoObj || m_pClient->m_Snap.m_SpecInfo.m_Active || Client()->State() != IClient::STATE_ONLINE)
@ -40,8 +61,6 @@ void CRaceDemo::OnRender()
if(m_pClient->Collision()->GetFTileIndex(m_pClient->Collision()->GetPureMapIndex(m_pClient->m_LocalCharacterPos)) == TILE_BEGIN) start = true;
}
if(start)
{
OnReset();
@ -59,35 +78,17 @@ void CRaceDemo::OnRender()
CheckDemo();
OnReset();
}
}
void CRaceDemo::OnReset()
{
if(Client()->State() != IClient::STATE_ONLINE)
return;
if(Client()->RaceRecordIsRecording())
Client()->RaceRecordStop();
char aFilename[512];
str_format(aFilename, sizeof(aFilename), "demos/%s_tmp_%d.demo", m_pMap, pid());
Storage()->RemoveFile(aFilename, IStorage::TYPE_SAVE);
m_Time = 0;
m_RaceState = RACE_NONE;
m_RecordStopTime = 0;
m_DemoStartTick = 0;
if(Client()->State() == IClient::STATE_ONLINE)
Stop();
}
void CRaceDemo::OnShutdown()
{
if(Client()->RaceRecordIsRecording())
Client()->RaceRecordStop();
char aFilename[512];
str_format(aFilename, sizeof(aFilename), "demos/%s_tmp_%d.demo", m_pMap, pid());
Storage()->RemoveFile(aFilename, IStorage::TYPE_SAVE);
Stop();
}
void CRaceDemo::OnMessage(int MsgType, void *pRawMsg)

View file

@ -14,6 +14,8 @@ class CRaceDemo : public CComponent
float m_Time;
const char *m_pMap;
void Stop();
public:
int m_RaceState;
@ -28,6 +30,7 @@ public:
CRaceDemo();
virtual void OnReset();
virtual void OnStateChange(int NewState, int OldState);
virtual void OnRender();
virtual void OnShutdown();
virtual void OnMessage(int MsgType, void *pRawMsg);