Skip to content

Commit

Permalink
Demo: Fixed time & archived time
Browse files Browse the repository at this point in the history
  • Loading branch information
Iswenzz committed Aug 3, 2023
1 parent 7e75a07 commit 585f85f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
14 changes: 12 additions & 2 deletions src/API/DemoReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,23 @@ namespace Iswenzz::CoD4::DM1
}

float DemoReader::GetTime()
{
return (DemoFile->CurrentSnapshotTime - DemoFile->StartSnapshotTime) / 50.0f / 20.0f;
}

float DemoReader::GetArchiveTime()
{
return (DemoFile->CurrentFrameTime - DemoFile->StartFrameTime) / 50.0f / 20.0f;
}

float DemoReader::GetTimeMilliseconds()
int DemoReader::GetTimeMilliseconds()
{
return GetTime() * 1000;
}

int DemoReader::GetArchiveTimeMilliseconds()
{
return GetTime() * 1000.0f;
return GetArchiveTime() * 1000;
}

int DemoReader::GetServerTime()
Expand Down
18 changes: 15 additions & 3 deletions src/API/DemoReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,28 @@ namespace Iswenzz::CoD4::DM1
void Close();

/// <summary>
/// Get the demo time.
/// Get the snapshot time.
/// </summary>
/// <returns></returns>
float GetTime();

/// <summary>
/// Get the demo time in milliseconds.
/// Get the archive time.
/// </summary>
/// <returns></returns>
float GetTimeMilliseconds();
float GetArchiveTime();

/// <summary>
/// Get the snapshot time in milliseconds.
/// </summary>
/// <returns></returns>
int GetTimeMilliseconds();

/// <summary>
/// Get the archive time in milliseconds.
/// </summary>
/// <returns></returns>
int GetArchiveTimeMilliseconds();

/// <summary>
/// Get the server time.
Expand Down
8 changes: 2 additions & 6 deletions src/API/__test__/DemoReader.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ TEST_F(DemoFixture, DemoReader)
auto snapshot = Reader->GetCurrentSnapshot();
auto entities = Reader->GetLastUpdatedEntities();

if (!Reader->GetCurrentSnapshot().valid)
if (!snapshot.valid)
continue;

float x = snapshot.ps.velocity[0];
float y = snapshot.ps.velocity[1];

//std::cout << snapshot.serverTime << " " << std::sqrt((x * x) + (y * y)) << std::endl;
//std::cout << Reader->GetFPS() << std::endl;
std::cout << Reader->GetTime() << " " << Reader->GetTimeMilliseconds() << std::endl;
}
EXPECT_TRUE(Reader->GetCurrentFrame().commandTime);
}
Expand Down
13 changes: 10 additions & 3 deletions src/Demo/Demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ namespace Iswenzz::CoD4::DM1
DemoFile.read(reinterpret_cast<char*>(&frame.angles[1]), sizeof(float));
DemoFile.read(reinterpret_cast<char*>(&frame.angles[2]), sizeof(float));

if (!StartFrameTime)
StartFrameTime = frame.commandTime;
if (frame.commandTime > CurrentFrameTime)
{
PreviousFrameTime = CurrentFrameTime;
Expand Down Expand Up @@ -467,13 +469,18 @@ namespace Iswenzz::CoD4::DM1
CurrentSnapshot.serverTime = msg.ReadInt();
CurrentSnapshot.messageNum = msg.SrvMsgSeq;

if (!StartFrameTime)
StartFrameTime = CurrentSnapshot.serverTime;

uint8_t deltaNum = msg.ReadByte();
CurrentSnapshot.deltaNum = !deltaNum ? -1 : CurrentSnapshot.messageNum - deltaNum;
CurrentSnapshot.snapFlags = msg.ReadByte();

if (!StartSnapshotTime)
StartSnapshotTime = CurrentSnapshot.serverTime;
if (CurrentSnapshot.serverTime > CurrentSnapshotTime)
{
PreviousSnapshotTime = CurrentSnapshotTime;
CurrentSnapshotTime = CurrentSnapshot.serverTime;
}

// Integrity checks
if (CurrentSnapshot.deltaNum > 0)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Demo/Demo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ namespace Iswenzz::CoD4::DM1
bool IsOpen = false;
bool IsEOF = true;
bool IsWriting = false;
bool Verbose;
bool Verbose = false;

int Protocol = COD4_PROTOCOL;
MSGType CurrentMessageType = { };

int StartFrameTime = 0;
int PreviousFrameTime = 0;
int CurrentFrameTime = 0;
int StartSnapshotTime = 0;
int PreviousSnapshotTime = 0;
int CurrentSnapshotTime = 0;
int LastFrameSrvMsgSeq = 0;
int FirstFrameSrvMsgSeq = 0;

Expand Down

0 comments on commit 585f85f

Please sign in to comment.