Skip to content

Commit

Permalink
Record team practice mode making replay easier
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwelf committed Sep 14, 2021
1 parent d6912f7 commit 81f4263
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/engine/shared/teehistorian_ex_chunks.h
Expand Up @@ -13,3 +13,4 @@ UUID(TEEHISTORIAN_SAVE_FAILURE, "teehistorian-save-failure@ddnet.tw")
UUID(TEEHISTORIAN_LOAD_SUCCESS, "teehistorian-load-success@ddnet.tw")
UUID(TEEHISTORIAN_LOAD_FAILURE, "teehistorian-load-failure@ddnet.tw")
UUID(TEEHISTORIAN_TEAM_CHANGE, "teehistorian-team-change@ddnet.tw")
UUID(TEEHISTORIAN_TEAM_PRACTICE, "teehistorian-team-practice@ddnet.tw")
4 changes: 4 additions & 0 deletions src/game/server/gamecontext.cpp
Expand Up @@ -1078,6 +1078,10 @@ void CGameContext::OnTick()
m_TeeHistorian.RecordPlayerTeam(i, pController->m_Teams.m_Core.Team(i));
}
}
for(int i = 0; i < MAX_CLIENTS; i++)
{
m_TeeHistorian.RecordTeamPractice(i, pController->m_Teams.IsPractice(i));
}
m_TeeHistorian.EndPlayers();
m_TeeHistorian.BeginInputs();
}
Expand Down
26 changes: 26 additions & 0 deletions src/game/server/teehistorian.cpp
Expand Up @@ -52,6 +52,10 @@ void CTeeHistorian::Reset(const CGameInfo *pGameInfo, WRITE_CALLBACK pfnWriteCal
{
PrevPlayerTeam = 0;
}
for(auto &PrevTeamPractice : m_aPrevTeamPractice)
{
PrevTeamPractice = false;
}

// `m_PrevMaxClientID` is initialized in `BeginPlayers`
for(auto &PrevPlayer : m_aPrevPlayers)
Expand Down Expand Up @@ -338,6 +342,28 @@ void CTeeHistorian::RecordPlayerTeam(int ClientID, int Team)
}
}

void CTeeHistorian::RecordTeamPractice(int Team, bool Practice)
{
if(m_aPrevTeamPractice[Team] != Practice)
{
m_aPrevTeamPractice[Team] = Practice;

EnsureTickWritten();

CPacker Buffer;
Buffer.Reset();
Buffer.AddInt(Team);
Buffer.AddInt(Practice);

if(m_Debug)
{
dbg_msg("teehistorian", "team_rescue team=%d practice=%d", Team, Practice);
}

WriteExtra(UUID_TEEHISTORIAN_TEAM_PRACTICE, Buffer.Data(), Buffer.Size());
}
}

void CTeeHistorian::Write(const void *pData, int DataSize)
{
m_pfnWriteCallback(pData, DataSize, m_pWriteCallbackUserdata);
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/teehistorian.h
Expand Up @@ -58,6 +58,7 @@ class CTeeHistorian
void RecordPlayer(int ClientID, const CNetObj_CharacterCore *pChar);
void RecordDeadPlayer(int ClientID);
void RecordPlayerTeam(int ClientID, int Team);
void RecordTeamPractice(int Team, bool Practice);
void EndPlayers();

void BeginInputs();
Expand Down Expand Up @@ -125,6 +126,7 @@ class CTeeHistorian
int m_PrevMaxClientID;
int m_MaxClientID;
int m_aPrevPlayerTeam[MAX_CLIENTS];
bool m_aPrevTeamPractice[MAX_CLIENTS];
CPlayer m_aPrevPlayers[MAX_CLIENTS];
};

Expand Down
20 changes: 20 additions & 0 deletions src/test/teehistorian.cpp
Expand Up @@ -552,3 +552,23 @@ TEST_F(TeeHistorian, TeamChange)
Finish();
Expect(EXPECTED, sizeof(EXPECTED));
}

TEST_F(TeeHistorian, TeamPractice)
{
const unsigned char EXPECTED[] = {
// EX uuid=5792834e-81d1-34c9-a29b-b5ff25dac3bc datalen=2
0x4a,
0x57, 0x92, 0x83, 0x4e, 0x81, 0xd1, 0x34, 0xc9,
0xa2, 0x9b, 0xb5, 0xff, 0x25, 0xda, 0xc3, 0xbc,
0x02,
// team=23
0x17,
// practice=1
0x01,
// FINISH
0x40};

m_TH.RecordTeamPractice(23, 1);
Finish();
Expect(EXPECTED, sizeof(EXPECTED));
}

0 comments on commit 81f4263

Please sign in to comment.