Record team practice mode making replay easier

This commit is contained in:
Zwelf 2021-08-14 14:51:11 +02:00
parent d6912f7ced
commit 81f4263428
5 changed files with 53 additions and 0 deletions

View file

@ -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")

View file

@ -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();
}

View file

@ -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)
@ -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);

View file

@ -58,6 +58,7 @@ public:
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();
@ -125,6 +126,7 @@ private:
int m_PrevMaxClientID;
int m_MaxClientID;
int m_aPrevPlayerTeam[MAX_CLIENTS];
bool m_aPrevTeamPractice[MAX_CLIENTS];
CPlayer m_aPrevPlayers[MAX_CLIENTS];
};

View file

@ -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));
}