From 41d49978fc359fee0f48165e3197ca0641fe9c84 Mon Sep 17 00:00:00 2001 From: terencehill Date: Mon, 18 Jun 2018 19:59:02 +0200 Subject: [PATCH] Turn complain_weapon into an entity to reduce accesses to .m_id field --- qcsrc/client/hud/hud.qh | 4 ++-- qcsrc/client/hud/panel/weapons.qc | 12 ++++++------ qcsrc/client/main.qc | 9 +++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index 950dee17a..68d1e6bff 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -86,8 +86,8 @@ const float BORDER_MULTIPLIER = 4; float scoreboard_bottom; int weapon_accuracy[Weapons_MAX]; -int complain_weapon; -float complain_weapon_type; +entity complain_weapon; +int complain_weapon_type; float complain_weapon_time; PlayerScoreField ps_primary, ps_secondary; diff --git a/qcsrc/client/hud/panel/weapons.qc b/qcsrc/client/hud/panel/weapons.qc index f94979133..5d75c7dd2 100644 --- a/qcsrc/client/hud/panel/weapons.qc +++ b/qcsrc/client/hud/panel/weapons.qc @@ -108,7 +108,7 @@ void HUD_Weapons() } if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime) - complain_weapon = 0; + complain_weapon = NULL; entity wepent = viewmodels[0]; // TODO: unhardcode @@ -169,13 +169,13 @@ void HUD_Weapons() if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current { for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i) - if (weaponorder[i] == panel_switchweapon || weaponorder[i].m_id == complain_weapon) + if (weaponorder[i] == panel_switchweapon || weaponorder[i] == complain_weapon) ++weapon_count; } else { for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i) - if ((weapons_stat & WepSet_FromWeapon(weaponorder[i])) || weaponorder[i].m_id == complain_weapon) + if ((weapons_stat & WepSet_FromWeapon(weaponorder[i])) || weaponorder[i] == complain_weapon) ++weapon_count; } @@ -407,12 +407,12 @@ void HUD_Weapons() { if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current { - if (!(it == panel_switchweapon || it.m_id == complain_weapon)) + if (!(it == panel_switchweapon || it == complain_weapon)) continue; } else { - if (!((weapons_stat & WepSet_FromWeapon(it)) || (it.m_id == complain_weapon))) + if (!((weapons_stat & WepSet_FromWeapon(it)) || (it == complain_weapon))) continue; } } @@ -534,7 +534,7 @@ void HUD_Weapons() } // draw the complain message - if(it.m_id == complain_weapon) + if(it == complain_weapon) { if(fadetime) a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1)); diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 3de8cefeb..218df18a4 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1216,7 +1216,8 @@ NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew) NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew) { - complain_weapon = ReadByte(); + int weapon_id = ReadByte(); + complain_weapon = Weapons_from(weapon_id); complain_weapon_type = ReadByte(); return = true; @@ -1225,9 +1226,9 @@ NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew) switch(complain_weapon_type) { - case 0: Local_Notification(MSG_MULTI, ITEM_WEAPON_NOAMMO, complain_weapon); break; - case 1: Local_Notification(MSG_MULTI, ITEM_WEAPON_DONTHAVE, complain_weapon); break; - default: Local_Notification(MSG_MULTI, ITEM_WEAPON_UNAVAILABLE, complain_weapon); break; + case 0: Local_Notification(MSG_MULTI, ITEM_WEAPON_NOAMMO, weapon_id); break; + case 1: Local_Notification(MSG_MULTI, ITEM_WEAPON_DONTHAVE, weapon_id); break; + default: Local_Notification(MSG_MULTI, ITEM_WEAPON_UNAVAILABLE, weapon_id); break; } } -- 2.39.2