engine: client: allocate static entities only when server sends static entity packet

This commit is contained in:
Alibek Omarov 2024-12-18 06:49:45 +03:00
parent 2aa13c8347
commit 98e587285b
4 changed files with 13 additions and 7 deletions

View file

@ -1046,7 +1046,7 @@ void CL_InitEdicts( int maxclients )
cls.num_client_entities = CL_UPDATE_BACKUP * NUM_PACKET_ENTITIES; 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 ); 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 ); clgame.entities = Mem_Calloc( clgame.mempool, sizeof( cl_entity_t ) * clgame.maxEntities );
clgame.static_entities = Mem_Calloc( clgame.mempool, sizeof( cl_entity_t ) * MAX_STATIC_ENTITIES ); clgame.static_entities = NULL; // will be initialized later
clgame.numStatics = 0; clgame.numStatics = 0;
if(( clgame.maxRemapInfos - 1 ) != clgame.maxEntities ) if(( clgame.maxRemapInfos - 1 ) != clgame.maxEntities )

View file

@ -311,10 +311,13 @@ static client entity
static void CL_ParseStaticEntity( sizebuf_t *msg ) static void CL_ParseStaticEntity( sizebuf_t *msg )
{ {
int i, newnum; int i, newnum;
entity_state_t from, to; const entity_state_t from = { 0 };
entity_state_t to;
cl_entity_t *ent; cl_entity_t *ent;
memset( &from, 0, sizeof( from )); if( !clgame.static_entities )
clgame.static_entities = Mem_Calloc( clgame.mempool, sizeof( cl_entity_t ) * MAX_STATIC_ENTITIES );
newnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS ); newnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS );
MSG_ReadDeltaEntity( msg, &from, &to, 0, DELTA_STATIC, cl.mtime[0] ); MSG_ReadDeltaEntity( msg, &from, &to, 0, DELTA_STATIC, cl.mtime[0] );

View file

@ -33,10 +33,12 @@ static client entity
static void CL_LegacyParseStaticEntity( sizebuf_t *msg ) static void CL_LegacyParseStaticEntity( sizebuf_t *msg )
{ {
int i; int i;
entity_state_t state; entity_state_t state = { 0 };
cl_entity_t *ent; cl_entity_t *ent;
memset( &state, 0, sizeof( state )); if( !clgame.static_entities )
clgame.static_entities = Mem_Calloc( clgame.mempool, sizeof( cl_entity_t ) * MAX_STATIC_ENTITIES );
state.modelindex = MSG_ReadShort( msg ); state.modelindex = MSG_ReadShort( msg );
state.sequence = MSG_ReadByte( msg ); state.sequence = MSG_ReadByte( msg );
state.frame = MSG_ReadByte( msg ); state.frame = MSG_ReadByte( msg );

View file

@ -628,11 +628,12 @@ CL_ParseStaticEntity
*/ */
static void CL_ParseQuakeStaticEntity( sizebuf_t *msg ) static void CL_ParseQuakeStaticEntity( sizebuf_t *msg )
{ {
entity_state_t state; entity_state_t state = { 0 };
cl_entity_t *ent; cl_entity_t *ent;
int i; int i;
memset( &state, 0, sizeof( state )); if( !clgame.static_entities )
clgame.static_entities = Mem_Calloc( clgame.mempool, sizeof( cl_entity_t ) * MAX_STATIC_ENTITIES );
state.modelindex = MSG_ReadByte( msg ); state.modelindex = MSG_ReadByte( msg );
state.frame = MSG_ReadByte( msg ); state.frame = MSG_ReadByte( msg );