Skip to content

Commit cd9be72

Browse files
committed
Fix entity baseline overflow
1 parent 262638a commit cd9be72

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

src/engine/client/cl_parse.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,13 @@ void CL_ParseGamestate( msg_t *msg )
403403

404404
clc.connectPacketCount = 0;
405405

406-
// wipe local client state
407-
CL_ClearState();
406+
if ( !cl.reading ) {
407+
// wipe local client state
408+
CL_ClearState();
408409

409-
// a gamestate always marks a server command sequence
410-
clc.serverCommandSequence = MSG_ReadLong( msg );
410+
// a gamestate always marks a server command sequence
411+
clc.serverCommandSequence = MSG_ReadLong( msg );
412+
}
411413

412414
// parse all the configstrings and baselines
413415
while (true)
@@ -443,21 +445,30 @@ void CL_ParseGamestate( msg_t *msg )
443445
entityState_t nullstate{};
444446
es = &cl.entityBaselines[ newnum ];
445447
MSG_ReadDeltaEntity( msg, &nullstate, es, newnum );
448+
449+
cl.reading = false;
450+
}
451+
else if ( cmd == svc_gamestatePartial )
452+
{
453+
cl.reading = true;
454+
break;
446455
}
447456
else
448457
{
449458
Sys::Drop( "CL_ParseGamestate: bad command byte" );
450459
}
451460
}
452461

453-
clc.clientNum = MSG_ReadLong( msg );
462+
if ( !cl.reading ) {
463+
clc.clientNum = MSG_ReadLong( msg );
454464

455-
// parse serverId and other cvars
456-
CL_SystemInfoChanged();
465+
// parse serverId and other cvars
466+
CL_SystemInfoChanged();
457467

458-
// This used to call CL_StartHunkUsers, but now we enter the download state before loading the
459-
// cgame
460-
CL_InitDownloads();
468+
// This used to call CL_StartHunkUsers, but now we enter the download state before loading the
469+
// cgame
470+
CL_InitDownloads();
471+
}
461472
}
462473

463474
//=====================================================================

src/engine/client/client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ struct clientActive_t
153153
clSnapshot_t snapshots[ PACKET_BACKUP ];
154154

155155
entityState_t entityBaselines[ MAX_GENTITIES ]; // for delta compression when not in previous frame
156+
157+
bool reading; // For gamestate that is split between different msg_t
156158
};
157159

158160
extern clientActive_t cl;

src/engine/qcommon/qcommon.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ enum svc_ops_e
248248
svc_bad,
249249
svc_nop,
250250
svc_gamestate,
251+
svc_gamestatePartial,
251252
svc_configstring, // [short] [string] only in gamestate messages
252253
svc_baseline, // only in gamestate messages
253254
svc_serverCommand, // [string] to be executed by client game module
254255
svc_download, // [short] size [size bytes]
255256
svc_snapshot,
256-
svc_EOF,
257+
svc_EOF
257258
};
258259

259260
//

src/engine/server/sv_client.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,16 @@ void SV_SendClientGameState( client_t *client )
385385

386386
MSG_WriteByte( &msg, svc_baseline );
387387
MSG_WriteDeltaEntity( &msg, &nullstate, base, true );
388+
389+
if ( MAX_MSGLEN - msg.cursize < 128 ) {
390+
// We have too many entities to put them all into one msg_t, so split it here
391+
MSG_WriteByte( &msg, svc_gamestatePartial );
392+
SV_SendMessageToClient( &msg, client );
393+
394+
MSG_Init( &msg, msgBuffer, sizeof( msgBuffer ) );
395+
MSG_WriteLong( &msg, client->lastClientCommand );
396+
MSG_WriteByte( &msg, svc_gamestate );
397+
}
388398
}
389399

390400
MSG_WriteByte( &msg, svc_EOF );

0 commit comments

Comments
 (0)