sv_send: realloc send buffer

This commit is contained in:
Denis Pauk 2024-02-10 15:23:38 +02:00
parent bc260a97e2
commit 322c3ee9e8
4 changed files with 63 additions and 5 deletions

View file

@ -33,6 +33,7 @@ Monsters:
Models support: Models support:
| Format | Original Game | Comments | | Format | Original Game | Comments |
| ------ | --------------- | ------------------------------------------------- |
| mdl | Quake 1 | could be issues with textures | | mdl | Quake 1 | could be issues with textures |
| md2 | Quake 2 | full support | | md2 | Quake 2 | full support |
| md2 | Anachronox | incorrect normals, does no suport tagged surfaces | | md2 | Anachronox | incorrect normals, does no suport tagged surfaces |
@ -47,6 +48,7 @@ All models support only single texture for all meshes and only up to 255 frames.
Texture supported Texture supported
| Format | Original Game | Comments | | Format | Original Game | Comments |
| ------ | -------------- | -------- |
| wal | Quake 2 | 8 bit | | wal | Quake 2 | 8 bit |
| wal | Daikatana | 8 bit | | wal | Daikatana | 8 bit |
| m8 | Heretic 2 | 8 bit | | m8 | Heretic 2 | 8 bit |

View file

@ -217,6 +217,8 @@ void Master_Packet(void);
void SV_InitGame(void); void SV_InitGame(void);
void SV_Map(qboolean attractloop, char *levelstring, qboolean loadgame, qboolean isautosave); void SV_Map(qboolean attractloop, char *levelstring, qboolean loadgame, qboolean isautosave);
void SV_SendInitBuffers();
void SV_SendFreeBuffers();
void SV_PrepWorldFrame(void); void SV_PrepWorldFrame(void);

View file

@ -569,6 +569,7 @@ SV_UserinfoChanged(client_t *cl)
void void
SV_Init(void) SV_Init(void)
{ {
SV_SendInitBuffers();
SV_InitOperatorCommands(); SV_InitOperatorCommands();
rcon_password = Cvar_Get("rcon_password", "", 0); rcon_password = Cvar_Get("rcon_password", "", 0);
@ -704,5 +705,7 @@ SV_Shutdown(char *finalmsg, qboolean reconnect)
} }
memset(&svs, 0, sizeof(svs)); memset(&svs, 0, sizeof(svs));
SV_SendFreeBuffers();
} }

View file

@ -428,15 +428,65 @@ SV_StartSound(vec3_t origin, edict_t *entity, int channel, int soundindex,
} }
} }
static int msgbuff_size = 0;
static byte *msgbuff_cache = NULL;
static byte *
SV_SendReallocBuffers(int num)
{
void *ptr;
if (num < msgbuff_size)
{
return msgbuff_cache;
}
msgbuff_size = num * 2;
ptr = realloc(msgbuff_cache, msgbuff_size);
if (!ptr)
{
Com_Error(ERR_FATAL, "%s: can't allocate memory", __func__);
return NULL;
}
msgbuff_cache = ptr;
Com_DPrintf("%s: Realloc send buffer: %d\n", __func__, msgbuff_size);
return msgbuff_cache;
}
void
SV_SendInitBuffers()
{
msgbuff_size = 0;
msgbuff_cache = NULL;
SV_SendReallocBuffers(MAX_MSGLEN);
}
void
SV_SendFreeBuffers()
{
if (msgbuff_cache)
{
free(msgbuff_cache);
msgbuff_cache = NULL;
}
msgbuff_size = 0;
}
static qboolean static qboolean
SV_SendClientDatagram(client_t *client) SV_SendClientDatagram(client_t *client)
{ {
byte msg_buf[MAX_MSGLEN]; byte *msg_buf;
sizebuf_t msg; sizebuf_t msg;
msg_buf = SV_SendReallocBuffers(MAX_MSGLEN);
SV_BuildClientFrame(client); SV_BuildClientFrame(client);
SZ_Init(&msg, msg_buf, sizeof(msg_buf)); SZ_Init(&msg, msg_buf, MAX_MSGLEN);
msg.allowoverflow = true; msg.allowoverflow = true;
/* send over all the relevant entity_state_t /* send over all the relevant entity_state_t
@ -525,7 +575,7 @@ SV_SendClientMessages(void)
int i; int i;
client_t *c; client_t *c;
int msglen; int msglen;
byte msgbuf[MAX_MSGLEN]; byte *msgbuf;
size_t r; size_t r;
msglen = 0; msglen = 0;
@ -556,10 +606,11 @@ SV_SendClientMessages(void)
return; return;
} }
msgbuf = SV_SendReallocBuffers(Q_max(msglen, MAX_MSGLEN));
if (msglen > MAX_MSGLEN) if (msglen > MAX_MSGLEN)
{ {
Com_Error(ERR_DROP, Com_Printf("%s: msglen %d > MAX_MSGLEN\n", __func__, msglen);
"%s: msglen > MAX_MSGLEN", __func__);
} }
r = FS_FRead(msgbuf, msglen, 1, sv.demofile); r = FS_FRead(msgbuf, msglen, 1, sv.demofile);