Skip to content

Commit

Permalink
Allow compression when writing demo snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
res2k committed Dec 12, 2024
1 parent b43a4d0 commit bd24006
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion q2proto
Submodule q2proto updated 1 files
+114 −2 src/q2proto_proto_kex.c
6 changes: 6 additions & 0 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion src/client/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3538,6 +3538,7 @@ void CL_Shutdown(void)

#if USE_ZLIB
inflateEnd(&cls.z);
Z_Free(cls.demo.z_buffer);
#endif

HTTP_Shutdown();
Expand Down

0 comments on commit bd24006

Please sign in to comment.