From: havoc Date: Mon, 9 Sep 2002 15:30:16 +0000 (+0000) Subject: svs.clients is now allocated dynamically according to svs.maxclients, and there is... X-Git-Tag: RELEASE_0_2_0_RC1~262 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bf87ef12e4419b568e57fc19f2f547b199b4f5aa;p=xonotic%2Fdarkplaces.git svs.clients is now allocated dynamically according to svs.maxclients, and there is now a function for updating svs.maxclients called SV_SetMaxClients this cuts the memory usage in singleplayer by 17mb git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2344 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/host.c b/host.c index 2816a121..7b6cd76e 100644 --- a/host.c +++ b/host.c @@ -165,29 +165,19 @@ void Host_Error (char *error, ...) longjmp (host_abortserver, 1); } -static mempool_t *clients_mempool; - -/* -================ -Host_FindMaxClients -================ -*/ -void Host_FindMaxClients (void) +void Host_ServerOptions (void) { - int i; + int i, numplayers; - svs.maxclients = 1; + numplayers = 1; i = COM_CheckParm ("-dedicated"); if (i) { cls.state = ca_dedicated; + numplayers = 0; if (i != (com_argc - 1)) - { - svs.maxclients = atoi (com_argv[i+1]); - } - else - svs.maxclients = 8; + numplayers = atoi (com_argv[i+1]); } else cls.state = ca_disconnected; @@ -197,34 +187,43 @@ void Host_FindMaxClients (void) { if (cls.state == ca_dedicated) Sys_Error ("Only one of -dedicated or -listen can be specified"); + numplayers = 0; if (i != (com_argc - 1)) - svs.maxclients = atoi (com_argv[i+1]); - else - svs.maxclients = 8; + numplayers = atoi (com_argv[i+1]); } + if (numplayers < 1) + numplayers = 8; + if (numplayers > MAX_SCOREBOARD) + numplayers = MAX_SCOREBOARD; + // Transfusion doesn't support single player games - if (gamemode == GAME_TRANSFUSION && svs.maxclients < 4) - svs.maxclients = 4; + if (gamemode == GAME_TRANSFUSION && numplayers < 4) + numplayers = 4; - if (svs.maxclients < 1) - svs.maxclients = 8; - else if (svs.maxclients > MAX_SCOREBOARD) - svs.maxclients = MAX_SCOREBOARD; + if (numplayers > 1) + Cvar_SetValueQuick (&deathmatch, 1); + else + Cvar_SetValueQuick (&deathmatch, 0); + + svs.maxclients = 0; + SV_SetMaxClients(numplayers); +} - svs.maxclientslimit = svs.maxclients; - if (svs.maxclientslimit < MAX_SCOREBOARD) // LordHavoc: upped listen mode limit from 4 to MAX_SCOREBOARD - svs.maxclientslimit = MAX_SCOREBOARD; +static mempool_t *clients_mempool; +void SV_SetMaxClients(int n) +{ + if (sv.active) + return; + n = bound(1, n, MAX_SCOREBOARD); + if (svs.maxclients == n) + return; + svs.maxclients = n; if (!clients_mempool) clients_mempool = Mem_AllocPool("clients"); if (svs.clients) Mem_Free(svs.clients); - svs.clients = Mem_Alloc(clients_mempool, svs.maxclientslimit*sizeof(client_t)); - - if (svs.maxclients > 1) - Cvar_SetValue ("deathmatch", 1.0); - else - Cvar_SetValue ("deathmatch", 0.0); + svs.clients = Mem_Alloc(clients_mempool, svs.maxclients*sizeof(client_t)); } @@ -267,7 +266,7 @@ void Host_InitLocal (void) Cvar_RegisterVariable (×tamps); Cvar_RegisterVariable (&timeformat); - Host_FindMaxClients (); + Host_ServerOptions (); } @@ -502,7 +501,7 @@ void Host_ShutdownServer(qboolean crash) // clear structures // memset (&sv, 0, sizeof(sv)); - memset (svs.clients, 0, svs.maxclientslimit*sizeof(client_t)); + memset (svs.clients, 0, svs.maxclients * sizeof(client_t)); } diff --git a/menu.c b/menu.c index 157d3ccc..1cb2aee6 100644 --- a/menu.c +++ b/menu.c @@ -2634,7 +2634,7 @@ void M_Menu_GameOptions_f (void) if (maxplayers == 0) maxplayers = svs.maxclients; if (maxplayers < 2) - maxplayers = svs.maxclientslimit; + maxplayers = MAX_SCOREBOARD; } @@ -2783,9 +2783,9 @@ void M_NetStart_Change (int dir) { case 1: maxplayers += dir; - if (maxplayers > svs.maxclientslimit) + if (maxplayers > MAX_SCOREBOARD) { - maxplayers = svs.maxclientslimit; + maxplayers = MAX_SCOREBOARD; m_serverInfoMessage = true; m_serverInfoMessageTime = realtime; } diff --git a/net_main.c b/net_main.c index 8db5a1b5..63edadcb 100644 --- a/net_main.c +++ b/net_main.c @@ -162,7 +162,7 @@ static void NET_Listen_f (void) static void MaxPlayers_f (void) { - int n; + int n; if (Cmd_Argc () != 2) { @@ -177,13 +177,9 @@ static void MaxPlayers_f (void) } n = atoi(Cmd_Argv(1)); - if (n < 1) - n = 1; - if (n > svs.maxclientslimit) - { - n = svs.maxclientslimit; + n = bound(1, n, MAX_SCOREBOARD); + if (svs.maxclients 1= n) Con_Printf ("\"maxplayers\" set to \"%u\"\n", n); - } if ((n == 1) && listening) Cbuf_AddText ("listen 0\n"); @@ -191,7 +187,7 @@ static void MaxPlayers_f (void) if ((n > 1) && (!listening)) Cbuf_AddText ("listen 1\n"); - svs.maxclients = n; + SV_SetMaxClients(n); } diff --git a/server.h b/server.h index a0d80b31..27c50c47 100644 --- a/server.h +++ b/server.h @@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. typedef struct { int maxclients; - int maxclientslimit; struct client_s *clients; // [maxclients] int serverflags; // episode completion information qboolean changelevel_issued; // cleared when at SV_SpawnServer @@ -270,5 +269,7 @@ void SV_RunClients (void); void SV_SaveSpawnparms (void); void SV_SpawnServer (char *server); +void SV_SetMaxClients(int n); + #endif