diff --git a/q2proto b/q2proto index 394c35cb4..e22f0b111 160000 --- a/q2proto +++ b/q2proto @@ -1 +1 @@ -Subproject commit 394c35cb4ed6f598cdeed33296175afaf0528590 +Subproject commit e22f0b111c5cdd805348c0548df3d695f006d6c3 diff --git a/src/client/client.h b/src/client/client.h index 45950766b..29483900e 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -622,6 +622,12 @@ typedef struct { // q2proto fields q2proto_server_info_t server_info; q2proto_servercontext_t q2proto_context; +#if USE_ZLIB + z_stream z; // for compressing in demo snaps + byte *z_buffer; + unsigned z_buffer_size; + q2protoio_deflate_args_t q2proto_deflate; +#endif } demo; #if USE_CLIENT_GTV diff --git a/src/client/demo.c b/src/client/demo.c index b649ed439..cb23f9c54 100644 --- a/src/client/demo.c +++ b/src/client/demo.c @@ -917,6 +917,19 @@ static void CL_PlayDemo_f(void) SZ_InitWrite(&cls.demo.buffer, demo_buffer, MAX_MSGLEN); demo_q2protoio_ioarg.max_msg_len = MAX_MSGLEN; +#if USE_ZLIB + if (!cls.demo.z_buffer) { + Q_assert(deflateInit2(&cls.demo.z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, + -MAX_WBITS, 9, Z_DEFAULT_STRATEGY) == Z_OK); + cls.demo.z_buffer_size = deflateBound(&cls.demo.z, MAX_MSGLEN) + 6 /* zlib header/footer */; + cls.demo.z_buffer = Z_Malloc(cls.demo.z_buffer_size); + } + + cls.demo.q2proto_deflate.z_buffer = cls.demo.z_buffer; + cls.demo.q2proto_deflate.z_buffer_size = cls.demo.z_buffer_size; + cls.demo.q2proto_deflate.z_raw = &cls.demo.z; +#endif + // read and parse messages util `precache' command for (int i = 0; cls.state == ca_connected && i < 1000; i++) { Cbuf_Execute(&cl_cmdbuf); @@ -1003,7 +1016,11 @@ void CL_EmitDemoSnapshot(void) Q2PROTO_MakeEntityDelta(&cls.demo.q2proto_context, &baseline->delta_state, NULL, &packed_entity, 0); } - q2proto_server_write_gamestate(&cls.demo.q2proto_context, NULL, Q2PROTO_IOARG_DEMO_WRITE, &gamestate);; + q2protoio_deflate_args_t *deflate_args = NULL; +#if USE_ZLIB + deflate_args = &cls.demo.q2proto_deflate; +#endif + q2proto_server_write_gamestate(&cls.demo.q2proto_context, deflate_args, Q2PROTO_IOARG_DEMO_WRITE, &gamestate);; // write all the backups, since we can't predict what frame the next // delta will come from diff --git a/src/client/main.c b/src/client/main.c index fa01a5096..e343c81fa 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -3538,6 +3538,7 @@ void CL_Shutdown(void) #if USE_ZLIB inflateEnd(&cls.z); + Z_Free(cls.demo.z_buffer); #endif HTTP_Shutdown();