Split CInfoMessages::OnMessage into separate functions

Improve readability by splitting long `OnMessage` function into separate functions for each individual message.
This commit is contained in:
Robert Müller 2024-02-08 21:56:00 +01:00
parent e350ceeb16
commit 4cb0bb2744
2 changed files with 177 additions and 166 deletions

View file

@ -154,10 +154,22 @@ void CInfoMessages::OnMessage(int MsgType, void *pRawMsg)
if(m_pClient->m_SuppressEvents)
return;
if(MsgType == NETMSGTYPE_SV_KILLMSGTEAM)
switch(MsgType)
{
CNetMsg_Sv_KillMsgTeam *pMsg = (CNetMsg_Sv_KillMsgTeam *)pRawMsg;
case NETMSGTYPE_SV_KILLMSGTEAM:
OnTeamKillMessage(static_cast<CNetMsg_Sv_KillMsgTeam *>(pRawMsg));
break;
case NETMSGTYPE_SV_KILLMSG:
OnKillMessage(static_cast<CNetMsg_Sv_KillMsg *>(pRawMsg));
break;
case NETMSGTYPE_SV_RACEFINISH:
OnRaceFinishMessage(static_cast<CNetMsg_Sv_RaceFinish *>(pRawMsg));
break;
}
}
void CInfoMessages::OnTeamKillMessage(const CNetMsg_Sv_KillMsgTeam *pMsg)
{
CInfoMsg Kill{};
std::vector<std::pair<int, int>> vStrongWeakSorted;
@ -233,10 +245,8 @@ void CInfoMessages::OnMessage(int MsgType, void *pRawMsg)
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
if(MsgType == NETMSGTYPE_SV_KILLMSG)
void CInfoMessages::OnKillMessage(const CNetMsg_Sv_KillMsg *pMsg)
{
CNetMsg_Sv_KillMsg *pMsg = (CNetMsg_Sv_KillMsg *)pRawMsg;
CInfoMsg Kill{};
Kill.m_TeamSize = 1;
@ -300,10 +310,8 @@ void CInfoMessages::OnMessage(int MsgType, void *pRawMsg)
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
if(MsgType == NETMSGTYPE_SV_RACEFINISH)
void CInfoMessages::OnRaceFinishMessage(const CNetMsg_Sv_RaceFinish *pMsg)
{
CNetMsg_Sv_RaceFinish *pMsg = (CNetMsg_Sv_RaceFinish *)pRawMsg;
char aBuf[256];
CInfoMsg Finish;
@ -353,7 +361,6 @@ void CInfoMessages::OnMessage(int MsgType, void *pRawMsg)
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
}
void CInfoMessages::RenderKillMsg(CInfoMsg *pInfoMsg, float x, float y)
{

View file

@ -64,6 +64,10 @@ private:
void CreateNamesIfNotCreated(CInfoMsg *pInfoMsg);
void CreateFinishTextContainersIfNotCreated(CInfoMsg *pInfoMsg);
void OnTeamKillMessage(const struct CNetMsg_Sv_KillMsgTeam *pMsg);
void OnKillMessage(const struct CNetMsg_Sv_KillMsg *pMsg);
void OnRaceFinishMessage(const struct CNetMsg_Sv_RaceFinish *pMsg);
void DeleteTextContainers(CInfoMsg *pInfoMsg);
public: