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;
@ -231,12 +243,10 @@ void CInfoMessages::OnMessage(int MsgType, void *pRawMsg)
}
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
if(MsgType == NETMSGTYPE_SV_KILLMSG)
{
CNetMsg_Sv_KillMsg *pMsg = (CNetMsg_Sv_KillMsg *)pRawMsg;
}
void CInfoMessages::OnKillMessage(const CNetMsg_Sv_KillMsg *pMsg)
{
CInfoMsg Kill{};
Kill.m_TeamSize = 1;
@ -298,12 +308,10 @@ void CInfoMessages::OnMessage(int MsgType, void *pRawMsg)
}
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
if(MsgType == NETMSGTYPE_SV_RACEFINISH)
{
CNetMsg_Sv_RaceFinish *pMsg = (CNetMsg_Sv_RaceFinish *)pRawMsg;
}
void CInfoMessages::OnRaceFinishMessage(const CNetMsg_Sv_RaceFinish *pMsg)
{
char aBuf[256];
CInfoMsg Finish;
@ -352,7 +360,6 @@ void CInfoMessages::OnMessage(int MsgType, void *pRawMsg)
AddInfoMsg(EType::TYPE_FINISH, Finish);
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: