From 565c27f615a61637197bdd449f9f40631779400a Mon Sep 17 00:00:00 2001 From: Sam V Date: Thu, 2 Dec 2021 00:32:12 +0100 Subject: [PATCH] Use MAX_PLAYERS everywhere for maximum player count #96 --- cl_dll/StudioModelRenderer.cpp | 6 +++--- cl_dll/entity.cpp | 2 +- cl_dll/ev_hldm.cpp | 2 +- cl_dll/hud_msg.cpp | 2 -- cl_dll/voice_status.cpp | 16 ++++++++++------ cl_dll/voice_status.h | 4 ++-- common/com_model.h | 1 - dlls/cdll_dll.h | 1 + dlls/triggers.cpp | 2 ++ game_shared/voice_common.h | 6 +++--- game_shared/voice_gamemgr.cpp | 9 +++++---- pm_shared/pm_shared.cpp | 6 ++---- 12 files changed, 30 insertions(+), 27 deletions(-) diff --git a/cl_dll/StudioModelRenderer.cpp b/cl_dll/StudioModelRenderer.cpp index 956c3745f..e831c2eee 100644 --- a/cl_dll/StudioModelRenderer.cpp +++ b/cl_dll/StudioModelRenderer.cpp @@ -31,7 +31,7 @@ extern extra_player_info_t g_PlayerExtraInfo[MAX_PLAYERS_HUD + 1]; #define TEAM3_COLOR 45 #define TEAM4_COLOR 100 -int m_nPlayerGaitSequences[MAX_CLIENTS]; +int m_nPlayerGaitSequences[MAX_PLAYERS]; // Global engine <-> studio model rendering code interface engine_studio_api_t IEngineStudio; @@ -1639,8 +1639,8 @@ char* ReturnCorrectedModelString(int iSwitchClass) #endif #ifdef _TFC -float g_flSpinUpTime[33]; -float g_flSpinDownTime[33]; +float g_flSpinUpTime[MAX_PLAYERS + 1]; +float g_flSpinDownTime[MAX_PLAYERS + 1]; #endif diff --git a/cl_dll/entity.cpp b/cl_dll/entity.cpp index c195b8778..3639c4114 100644 --- a/cl_dll/entity.cpp +++ b/cl_dll/entity.cpp @@ -316,7 +316,7 @@ void DLLEXPORT HUD_CreateEntities() } #if defined(_TFC) -extern int g_bACSpinning[33]; +extern int g_bACSpinning[MAX_PLAYERS + 1]; #endif /* diff --git a/cl_dll/ev_hldm.cpp b/cl_dll/ev_hldm.cpp index af695a75b..21b5dc45e 100644 --- a/cl_dll/ev_hldm.cpp +++ b/cl_dll/ev_hldm.cpp @@ -43,7 +43,7 @@ extern engine_studio_api_t IEngineStudio; -static int tracerCount[32]; +static int tracerCount[MAX_PLAYERS]; #include "pm_shared.h" diff --git a/cl_dll/hud_msg.cpp b/cl_dll/hud_msg.cpp index 6bd25b343..219c3ce32 100644 --- a/cl_dll/hud_msg.cpp +++ b/cl_dll/hud_msg.cpp @@ -24,8 +24,6 @@ #include "particleman.h" extern IParticleMan* g_pParticleMan; -#define MAX_CLIENTS 32 - #if !defined(_TFC) extern BEAM* pBeam; extern BEAM* pBeam2; diff --git a/cl_dll/voice_status.cpp b/cl_dll/voice_status.cpp index dca912903..da1a64a83 100644 --- a/cl_dll/voice_status.cpp +++ b/cl_dll/voice_status.cpp @@ -327,7 +327,7 @@ void CVoiceStatus::Frame(double frametime) m_Labels[i].m_pBackground->setVisible(false); } - for (int i = 0; i < VOICE_MAX_PLAYERS; i++) + for (int i = 0; i < MAX_PLAYERS; i++) UpdateBanButton(i); } @@ -340,7 +340,7 @@ void CVoiceStatus::CreateEntities() cl_entity_t* localPlayer = gEngfuncs.GetLocalPlayer(); int iOutModel = 0; - for (int i = 0; i < VOICE_MAX_PLAYERS; i++) + for (int i = 0; i < MAX_PLAYERS; i++) { if (!m_VoicePlayers[i]) continue; @@ -424,7 +424,7 @@ void CVoiceStatus::UpdateSpeakerStatus(int entindex, bool bTalking) m_bServerAcked = bTalking; } - if (entindex >= 0 && entindex <= VOICE_MAX_PLAYERS) + if (entindex >= 0 && entindex <= MAX_PLAYERS) { int iClient = entindex - 1; if (iClient < 0) @@ -530,9 +530,13 @@ void CVoiceStatus::UpdateServerState(bool bForce) for (unsigned long dw = 0; dw < VOICE_MAX_PLAYERS_DW; dw++) { + //The ban mask is a 32 bit int, so make sure this doesn't silently break. + //Note that the server will also need updating. + static_assert(MAX_PLAYERS <= 32, "The voice ban bit vector only supports up to 32 players"); + unsigned long serverBanMask = 0; unsigned long banMask = 0; - for (unsigned long i = 0; i < 32; i++) + for (unsigned long i = 0; i < MAX_PLAYERS; i++) { char playerID[16]; if (0 == gEngfuncs.GetPlayerUniqueID(i + 1, playerID)) @@ -541,7 +545,7 @@ void CVoiceStatus::UpdateServerState(bool bForce) if (m_BanMgr.GetPlayerBan(playerID)) banMask |= 1 << i; - if (m_ServerBannedPlayers[dw * 32 + i]) + if (m_ServerBannedPlayers[dw * MAX_PLAYERS + i]) serverBanMask |= 1 << i; } @@ -811,7 +815,7 @@ void CVoiceStatus::FreeBitmaps() m_pScoreboardBanned = NULL; // Clear references to the images in panels. - for (int i = 0; i < VOICE_MAX_PLAYERS; i++) + for (int i = 0; i < MAX_PLAYERS; i++) { if (m_pBanButtons[i]) { diff --git a/cl_dll/voice_status.h b/cl_dll/voice_status.h index 97ed7fd25..000140f69 100644 --- a/cl_dll/voice_status.h +++ b/cl_dll/voice_status.h @@ -169,7 +169,7 @@ class CVoiceStatus : public CHudBase, public vgui::CDefaultInputSignal // It is checked periodically, and the server is told to squelch or unsquelch the appropriate players. CPlayerBitVec m_ServerBannedPlayers; - cl_entity_s m_VoiceHeadModels[VOICE_MAX_PLAYERS]; // These aren't necessarily in the order of players. They are just + cl_entity_s m_VoiceHeadModels[MAX_PLAYERS]; // These aren't necessarily in the order of players. They are just // a place for it to put data in during CreateEntities. IVoiceStatusHelper *m_pHelper; // Each mod provides an implementation of this. @@ -184,7 +184,7 @@ class CVoiceStatus : public CHudBase, public vgui::CDefaultInputSignal vgui::BitmapTGA *m_pScoreboardSquelch; vgui::BitmapTGA *m_pScoreboardBanned; - vgui::Label *m_pBanButtons[VOICE_MAX_PLAYERS]; // scoreboard buttons. + vgui::Label *m_pBanButtons[MAX_PLAYERS]; // scoreboard buttons. // Squelch mode stuff. bool m_bInSquelchMode; diff --git a/common/com_model.h b/common/com_model.h index df757e915..d46ad54b6 100644 --- a/common/com_model.h +++ b/common/com_model.h @@ -12,7 +12,6 @@ #define STUDIO_RENDER 1 #define STUDIO_EVENTS 2 -#define MAX_CLIENTS 32 #define MAX_EDICTS 900 #define MAX_MODEL_NAME 64 diff --git a/dlls/cdll_dll.h b/dlls/cdll_dll.h index de274a0eb..9a2e48371 100644 --- a/dlls/cdll_dll.h +++ b/dlls/cdll_dll.h @@ -19,6 +19,7 @@ #pragma once +constexpr int MAX_PLAYERS = 32; #define MAX_WEAPONS 64 // ??? #define MAX_WEAPON_SLOTS 5 // hud item selection slots diff --git a/dlls/triggers.cpp b/dlls/triggers.cpp index 4ae4117e6..09023a5b5 100644 --- a/dlls/triggers.cpp +++ b/dlls/triggers.cpp @@ -926,6 +926,8 @@ void CBaseTrigger::HurtTouch(CBaseEntity* pOther) if ((pev->spawnflags & SF_TRIGGER_HURT_NO_CLIENTS) != 0 && pOther->IsPlayer()) return; + static_assert(MAX_PLAYERS <= 32, "Rework the player mask logic to support more than 32 players"); + // HACKHACK -- In multiplayer, players touch this based on packet receipt. // So the players who send packets later aren't always hurt. Keep track of // how much time has passed and whether or not you've touched that player diff --git a/game_shared/voice_common.h b/game_shared/voice_common.h index 72563ca74..74870c0e0 100644 --- a/game_shared/voice_common.h +++ b/game_shared/voice_common.h @@ -7,9 +7,9 @@ #pragma once +#include "cdll_dll.h" #include "bitvec.h" -#define VOICE_MAX_PLAYERS 32 // (todo: this should just be set to MAX_CLIENTS). -#define VOICE_MAX_PLAYERS_DW ((VOICE_MAX_PLAYERS / 32) + !!(VOICE_MAX_PLAYERS & 31)) +constexpr int VOICE_MAX_PLAYERS_DW = (MAX_PLAYERS / 32) + ((MAX_PLAYERS & 31) != 0 ? 1 : 0); -typedef CBitVec CPlayerBitVec; +typedef CBitVec CPlayerBitVec; diff --git a/game_shared/voice_gamemgr.cpp b/game_shared/voice_gamemgr.cpp index de4c090bf..567010597 100644 --- a/game_shared/voice_gamemgr.cpp +++ b/game_shared/voice_gamemgr.cpp @@ -5,6 +5,7 @@ // $NoKeywords: $ //============================================================================= +#include "extdll.h" #include "voice_gamemgr.h" #include #include "extdll.h" @@ -22,12 +23,12 @@ CPlayerBitVec g_PlayerModEnable; // Set to 1 for each player if the player wants // (If it's zero, then the server reports that the game rules are saying the // player can't hear anyone). -CPlayerBitVec g_BanMasks[VOICE_MAX_PLAYERS]; // Tells which players don't want to hear each other. +CPlayerBitVec g_BanMasks[MAX_PLAYERS]; // Tells which players don't want to hear each other. // These are indexed as clients and each bit represents a client // (so player entity is bit+1). -CPlayerBitVec g_SentGameRulesMasks[VOICE_MAX_PLAYERS]; // These store the masks we last sent to each client so we can determine if -CPlayerBitVec g_SentBanMasks[VOICE_MAX_PLAYERS]; // we need to resend them. +CPlayerBitVec g_SentGameRulesMasks[MAX_PLAYERS]; // These store the masks we last sent to each client so we can determine if +CPlayerBitVec g_SentBanMasks[MAX_PLAYERS]; // we need to resend them. CPlayerBitVec g_bWantModEnable; cvar_t voice_serverdebug = {"voice_serverdebug", "0"}; @@ -101,7 +102,7 @@ bool CVoiceGameMgr::Init( int maxClients) { m_pHelper = pHelper; - m_nMaxPlayers = VOICE_MAX_PLAYERS < maxClients ? VOICE_MAX_PLAYERS : maxClients; + m_nMaxPlayers = MAX_PLAYERS < maxClients ? MAX_PLAYERS : maxClients; g_engfuncs.pfnPrecacheModel("sprites/voiceicon.spr"); m_msgPlayerVoiceMask = REG_USER_MSG("VoiceMask", VOICE_MAX_PLAYERS_DW * 4 * 2); diff --git a/pm_shared/pm_shared.cpp b/pm_shared/pm_shared.cpp index 1d2555d8c..3cb0ca7b0 100644 --- a/pm_shared/pm_shared.cpp +++ b/pm_shared/pm_shared.cpp @@ -126,8 +126,6 @@ typedef struct hull_s // fall over #define ROLL 2 -#define MAX_CLIENTS 32 - #define CONTENTS_CURRENT_0 -9 #define CONTENTS_CURRENT_90 -10 #define CONTENTS_CURRENT_180 -11 @@ -138,7 +136,7 @@ typedef struct hull_s #define CONTENTS_TRANSLUCENT -15 static Vector rgv3tStuckTable[54]; -static int rgStuckLast[MAX_CLIENTS][2]; +static int rgStuckLast[MAX_PLAYERS][2]; // Texture names static int gcTextures = 0; @@ -1707,7 +1705,7 @@ bool PM_CheckStuck() int i; pmtrace_t traceresult; - static float rgStuckCheckTime[MAX_CLIENTS][2]; // Last time we did a full + static float rgStuckCheckTime[MAX_PLAYERS][2]; // Last time we did a full // If position is okay, exit hitent = pmove->PM_TestPlayerPosition(pmove->origin, &traceresult);