Only use integers for ghost and race demo handling

Ghosts still use floats internally
This commit is contained in:
Redix 2017-08-31 01:59:22 +02:00
parent cf09b6b08b
commit affa3faeec
6 changed files with 15 additions and 21 deletions

View file

@ -1,7 +1,5 @@
/* (c) Rajh, Redix and Sushi. */
#include <cstdio>
#include <engine/storage.h>
#include <engine/graphics.h>
#include <engine/shared/config.h>
@ -320,10 +318,8 @@ void CGhost::Save()
}
char aFilename[256];
char aBuf[256];
str_format(aFilename, sizeof(aFilename), "%s_%s_%.3f_%08x.gho", Client()->GetCurrentMap(), aName, m_BestTime, Client()->GetCurrentMapCrc());
str_format(aBuf, sizeof(aBuf), "ghosts/%s", aFilename);
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_WRITE, IStorage::TYPE_SAVE);
str_format(aFilename, sizeof(aFilename), "ghosts/%s_%s_%d.%03d_%08x.gho", Client()->GetCurrentMap(), aName, m_BestTime / 1000, m_BestTime % 1000, Client()->GetCurrentMapCrc());
IOHANDLE File = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!File)
return;
@ -338,7 +334,7 @@ void CGhost::Save()
Header.m_aCrc[1] = (Crc>>16)&0xff;
Header.m_aCrc[2] = (Crc>>8)&0xff;
Header.m_aCrc[3] = (Crc)&0xff;
Header.m_Time = m_BestTime;
Header.m_Time = m_BestTime / 1000.f;
Header.m_NumShots = m_CurGhost.m_Path.size();
io_write(File, &Header, sizeof(Header));
@ -455,7 +451,7 @@ void CGhost::Load(const char* pFilename, int ID)
}
if(ID == -1)
m_BestTime = Header.m_Time;
m_BestTime = Header.m_Time * 1000;
int NumShots = Header.m_NumShots;
@ -560,11 +556,10 @@ void CGhost::OnMessage(int MsgType, void *pRawMsg)
if(Time > 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) == 0)
{
m_RaceState = RACE_FINISHED;
float CurTime = Time / 1000.f;
if(m_Recording && (CurTime < m_BestTime || m_BestTime == -1))
if(m_Recording && (Time < m_BestTime || m_BestTime == -1))
{
m_NewRecord = true;
m_BestTime = CurTime;
m_BestTime = Time;
m_Saving = true;
}
}

View file

@ -52,7 +52,7 @@ private:
bool m_Recording;
bool m_Rendering;
int m_RaceState;
float m_BestTime;
int m_BestTime;
bool m_NewRecord;
bool m_Saving;

View file

@ -333,7 +333,7 @@ public:
char m_aFilename[256];
char m_aPlayer[MAX_NAME_LENGTH];
float m_Time;
int m_Time;
bool m_Active;
int m_ID;

View file

@ -851,7 +851,7 @@ int CMenus::GhostlistFetchCallback(const char *pName, int IsDir, int StorageType
CGhostItem Item;
str_copy(Item.m_aFilename, pName, sizeof(Item.m_aFilename));
str_copy(Item.m_aPlayer, Header.m_aOwner, sizeof(Item.m_aPlayer));
Item.m_Time = Header.m_Time;
Item.m_Time = Header.m_Time * 1000;
Item.m_Active = false;
Item.m_ID = pSelf->m_lGhosts.add(Item);
@ -1079,7 +1079,7 @@ void CMenus::RenderGhost(CUIRect MainView)
Cursor.m_LineWidth = Button.w;
char aBuf[64];
str_format(aBuf, sizeof(aBuf), "%02d:%06.3f", (int)pItem->m_Time/60, pItem->m_Time-((int)pItem->m_Time/60*60));
str_format(aBuf, sizeof(aBuf), "%02d:%02d.%03d", pItem->m_Time / (60 * 1000), (pItem->m_Time / 1000) % 60, pItem->m_Time % 1000);
TextRender()->TextEx(&Cursor, aBuf, -1);
}
}

View file

@ -117,7 +117,7 @@ void CRaceDemo::OnMessage(int MsgType, void *pRawMsg)
{
m_RaceState = RACE_FINISHED;
m_RecordStopTime = Client()->GameTick() + Client()->GameTickSpeed();
m_Time = Time / 1000.f;
m_Time = Time;
}
}
}
@ -145,8 +145,7 @@ void CRaceDemo::CheckDemo()
// set cursor
pDemo += MapLen + 1;
int Time = CRaceHelper::TimeFromSecondsStr(pDemo);
float DemoTime = Time / 1000.f;
if(Time > 0 && m_Time < DemoTime)
if(Time > 0 && m_Time < Time)
{
// save new record
SaveDemo(m_pMap);
@ -187,11 +186,11 @@ void CRaceDemo::SaveDemo(const char* pDemo)
if(aPlayerName[i] == '\\' || aPlayerName[i] == '/' || aPlayerName[i] == '|' || aPlayerName[i] == ':' || aPlayerName[i] == '*' || aPlayerName[i] == '?' || aPlayerName[i] == '<' || aPlayerName[i] == '>' || aPlayerName[i] == '"')
aPlayerName[i] = '%';
str_format(aNewFilename, sizeof(aNewFilename), "demos/%s_%.2f_%s.demo", pDemo, m_Time, aPlayerName);
str_format(aNewFilename, sizeof(aNewFilename), "demos/%s_%d.%03d_%s.demo", pDemo, m_Time / 1000, m_Time % 1000, aPlayerName);
}
}
else
str_format(aNewFilename, sizeof(aNewFilename), "demos/%s_%.2f.demo", pDemo, m_Time);
str_format(aNewFilename, sizeof(aNewFilename), "demos/%s_%d.%03d.demo", pDemo, m_Time / 1000, m_Time % 1000);
str_format(aOldFilename, sizeof(aOldFilename), "demos/%s_tmp_%d.demo", m_pMap, pid());

View file

@ -11,7 +11,7 @@ class CRaceDemo : public CComponent
{
int m_RecordStopTime;
int m_DemoStartTick;
float m_Time;
int m_Time;
const char *m_pMap;
void Stop();