From 114a256675578912268d8060e5175eda2d1ed17d Mon Sep 17 00:00:00 2001 From: mittorn Date: Sat, 26 Oct 2019 07:06:26 +0700 Subject: [PATCH] Implement XASH_LOW_MEMORY, memory-reduced configuration --- common/port.h | 3 +++ engine/client/cl_game.c | 5 +++-- engine/client/cl_parse.c | 8 ++++---- engine/client/client.h | 4 ++++ engine/client/console.c | 24 +++++++++++++++++------- engine/common/common.h | 5 +++++ engine/common/net_ws.h | 6 +++++- engine/common/netchan.h | 11 +++++++++-- engine/common/protocol.h | 25 +++++++++++++++++++++++++ engine/server/server.h | 4 ++++ engine/server/sv_init.c | 6 ++++-- 11 files changed, 83 insertions(+), 18 deletions(-) diff --git a/common/port.h b/common/port.h index 0c1a90f6..3aef3a17 100644 --- a/common/port.h +++ b/common/port.h @@ -126,6 +126,9 @@ GNU General Public License for more details. #define XASH_ALLOW_SAVERESTORE_OFFSETS #endif #endif //WIN32 +#ifndef XASH_LOW_MEMORY +#define XASH_LOW_MEMORY 0 +#endif #include #include diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 468542c0..8ffa78e0 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1123,8 +1123,9 @@ void CL_InitEdicts( void ) Assert( clgame.entities == NULL ); if( !clgame.mempool ) return; // Host_Error without client - - CL_UPDATE_BACKUP = ( cl.maxclients == 1 ) ? SINGLEPLAYER_BACKUP : MULTIPLAYER_BACKUP; +#if XASH_LOW_MEMORY != 2 + CL_UPDATE_BACKUP = ( cl.maxclients <= 1 ) ? SINGLEPLAYER_BACKUP : MULTIPLAYER_BACKUP; +#endif cls.num_client_entities = CL_UPDATE_BACKUP * NUM_PACKET_ENTITIES; cls.packet_entities = Mem_Realloc( clgame.mempool, cls.packet_entities, sizeof( entity_state_t ) * cls.num_client_entities ); clgame.entities = Mem_Calloc( clgame.mempool, sizeof( cl_entity_t ) * clgame.maxEntities ); diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 9fd165bc..778203f6 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -21,9 +21,9 @@ GNU General Public License for more details. #include "shake.h" #include "hltv.h" #include "input.h" - +#if XASH_LOW_MEMORY != 2 int CL_UPDATE_BACKUP = SINGLEPLAYER_BACKUP; - +#endif /* =============== CL_UserMsgStub @@ -881,7 +881,7 @@ void CL_ParseServerData( sizebuf_t *msg ) cl.playernum = MSG_ReadByte( msg ); cl.maxclients = MSG_ReadByte( msg ); clgame.maxEntities = MSG_ReadWord( msg ); - clgame.maxEntities = bound( 600, clgame.maxEntities, MAX_EDICTS ); + clgame.maxEntities = bound( 30, clgame.maxEntities, MAX_EDICTS ); clgame.maxModels = MSG_ReadWord( msg ); Q_strncpy( clgame.mapname, MSG_ReadString( msg ), MAX_STRING ); Q_strncpy( clgame.maptitle, MSG_ReadString( msg ), MAX_STRING ); @@ -2394,7 +2394,7 @@ void CL_ParseLegacyServerData( sizebuf_t *msg ) cl.playernum = MSG_ReadByte( msg ); cl.maxclients = MSG_ReadByte( msg ); clgame.maxEntities = MSG_ReadWord( msg ); - clgame.maxEntities = bound( 600, clgame.maxEntities, 4096 ); + clgame.maxEntities = bound( 30, clgame.maxEntities, 4096 ); clgame.maxModels = 512; Q_strncpy( clgame.mapname, MSG_ReadString( msg ), MAX_STRING ); Q_strncpy( clgame.maptitle, MSG_ReadString( msg ), MAX_STRING ); diff --git a/engine/client/client.h b/engine/client/client.h index 00c15e67..a6a92296 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -96,7 +96,11 @@ typedef struct #define ANGLE_MASK (ANGLE_BACKUP - 1) #define CL_UPDATE_MASK (CL_UPDATE_BACKUP - 1) +#if XASH_LOW_MEMORY == 2 +#define CL_UPDATE_BACKUP SINGLEPLAYER_BACKUP +#else extern int CL_UPDATE_BACKUP; +#endif #define SIGNONS 2 // signon messages to receive before connected #define INVALID_HANDLE 0xFFFF // for XashXT cache system diff --git a/engine/client/console.c b/engine/client/console.c index 8699e48c..ec48d904 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -37,15 +37,19 @@ static qboolean g_utf8 = false; #define COLOR_DEFAULT '7' #define CON_HISTORY 64 #define MAX_DBG_NOTIFY 128 +#if XASH_LOW_MEMORY +#define CON_NUMFONTS 1 // do not load different font textures +#define CON_TEXTSIZE 32768 // max scrollback buffer characters in console (32 kb) +#define CON_MAXLINES 2048 // max scrollback buffer lines in console +#else #define CON_NUMFONTS 3 // maxfonts - +#define CON_TEXTSIZE 1048576 // max scrollback buffer characters in console (1 Mb) +#define CON_MAXLINES 16384 // max scrollback buffer lines in console +#endif #define CON_LINES( i ) (con.lines[(con.lines_first + (i)) % con.maxlines]) #define CON_LINES_COUNT con.lines_count #define CON_LINES_LAST() CON_LINES( CON_LINES_COUNT - 1 ) -#define CON_TEXTSIZE 1048576 // max scrollback buffer characters in console (1 Mb) -#define CON_MAXLINES 16384 // max scrollback buffer lines in console - // console color typeing rgba_t g_color_table[8] = { @@ -663,7 +667,7 @@ static void Con_LoadConchars( void ) int i, fontSize; // load all the console fonts - for( i = 0; i < 3; i++ ) + for( i = 0; i < CON_NUMFONTS; i++ ) Con_LoadConsoleFont( i, con.chars + i ); // select properly fontsize @@ -673,6 +677,9 @@ static void Con_LoadConchars( void ) fontSize = 2; else fontSize = 1; + if( fontSize > CON_NUMFONTS - 1 ) + fontSize = CON_NUMFONTS - 1; + // sets the current font con.lastUsedFont = con.curFont = &con.chars[fontSize]; } @@ -929,7 +936,7 @@ choose font size */ void Con_SetFont( int fontNum ) { - fontNum = bound( 0, fontNum, 2 ); + fontNum = bound( 0, fontNum, CON_NUMFONTS - 1 ); con.curFont = &con.chars[fontNum]; } @@ -2359,7 +2366,9 @@ void Con_VidInit( void ) Con_CheckResize(); Con_LoadConchars(); - +#if XASH_LOW_MEMORY + con.background = R_GetBuiltinTexture( REF_BLACK_TEXTURE ); +#else // loading console image if( host.allow_console ) { @@ -2434,6 +2443,7 @@ void Con_VidInit( void ) // missed console image will be replaced as gray background like X-Ray or Crysis if( con.background == R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ) || con.background == 0 ) con.background = R_GetBuiltinTexture( REF_GRAY_TEXTURE ); +#endif } /* diff --git a/engine/common/common.h b/engine/common/common.h index 0b568410..37eae9b5 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -141,6 +141,11 @@ typedef enum #define MAX_DECALS 512 // touching TE_DECAL messages, etc #define MAX_STATIC_ENTITIES 3096 // static entities that moved on the client when level is spawn +#if XASH_LOW_MEMORY == 2 +#define MAX_DECALS 32 // touching TE_DECAL messages, etc +#define MAX_STATIC_ENTITIES 32 // static entities that moved on the client when level is spawn +#endif + // filesystem flags #define FS_STATIC_PATH ( 1U << 0 ) // FS_ClearSearchPath will be ignore this path #define FS_NOWRITE_PATH ( 1U << 1 ) // default behavior - last added gamedir set as writedir. This flag disables it diff --git a/engine/common/net_ws.h b/engine/common/net_ws.h index 86b197ff..240fb0c7 100644 --- a/engine/common/net_ws.h +++ b/engine/common/net_ws.h @@ -30,7 +30,11 @@ typedef enum #define MAX_MULTICAST 8192 // some mods spamming for rain effect #define MAX_INIT_MSG 0x20000 // max length of possible message - +#if XASH_LOW_MEMORY == 2 +#define MAX_INIT_MSG 0x8000 +#define MAX_DATAGRAM 1024 +#define MAX_MULTICAST 1024 +#endif // net packets type #define NET_HEADER_OUTOFBANDPACKET -1 #define NET_HEADER_SPLITPACKET -2 diff --git a/engine/common/netchan.h b/engine/common/netchan.h index aa608719..e64503bc 100644 --- a/engine/common/netchan.h +++ b/engine/common/netchan.h @@ -78,17 +78,24 @@ GNU General Public License for more details. #define PORT_SERVER 27015 #define MULTIPLAYER_BACKUP 64 // how many data slots to use when in multiplayer (must be power of 2) -#define SINGLEPLAYER_BACKUP 16 // same for single player +#define SINGLEPLAYER_BACKUP 16 // same for single player #define CMD_BACKUP 64 // allow a lot of command backups for very fast systems #define CMD_MASK (CMD_BACKUP - 1) #define NUM_PACKET_ENTITIES 256 // 170 Mb for multiplayer with 32 players #define MAX_CUSTOM_BASELINES 64 - #define NET_LEGACY_EXT_SPLIT (1U<<1) #define NETSPLIT_BACKUP 8 #define NETSPLIT_BACKUP_MASK (NETSPLIT_BACKUP - 1) #define NETSPLIT_HEADER_SIZE 18 +#if XASH_LOW_MEMORY == 2 + #define MULTIPLAYER_BACKUP 4 // how many data slots to use when in multiplayer (must be power of 2) + #define SINGLEPLAYER_BACKUP 4 // same for single player + #define NUM_PACKET_ENTITIES 32 // 170 Mb for multiplayer with 32 players + #define MAX_CUSTOM_BASELINES 8 + #define NET_MAX_FRAGMENT 32768 +#endif + typedef struct netsplit_chain_packet_s { // bool vector diff --git a/engine/common/protocol.h b/engine/common/protocol.h index a3221c75..c838ab60 100644 --- a/engine/common/protocol.h +++ b/engine/common/protocol.h @@ -133,6 +133,31 @@ GNU General Public License for more details. #define MAX_LIGHTSTYLES 64 // original quake limit #define MAX_RENDER_DECALS 4096 // max rendering decals per a level +#if XASH_LOW_MEMORY == 2 +// memory reduced protocol, not for use in multiplayer +#define MAX_VISIBLE_PACKET_BITS 7 // 2048 visible entities per frame (hl1 has 256) +#define MAX_VISIBLE_PACKET (1<