From e9a2a3fab5cf5c2105775eeb31e44aacd0135f99 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 3 Feb 2000 00:34:12 +0000 Subject: [PATCH] Add gzip support, add -Werror to gcc CFLAGS, clean up misc warnings. NOTE: demos are broken for gzipped demo files (possibly normal ones too, not yet tested). --- common/console.c | 5 ++- common/keys.c | 1 + common/pr_cmds.c | 1 + common/pr_edict.c | 1 + common/pr_exec.c | 5 +-- common/quakefs.c | 60 ++++++++++++++++++++++++++------- common/quakefs.h | 3 +- common/register_check.c | 4 +-- common/sbar.c | 13 +++++--- configure.in | 8 +++-- qw_client/cl_demo.c | 74 ++++++++++++++++++++--------------------- qw_client/cl_parse.c | 4 +-- qw_client/r_part.c | 9 +++-- qw_common/client.h | 4 ++- qw_server/server.h | 4 ++- qw_server/sv_ccmds.c | 4 +-- qw_server/sv_user.c | 8 ++--- uquake/cl_demo.c | 24 ++++++------- uquake/client.h | 4 ++- uquake/r_part.c | 9 +++-- 20 files changed, 155 insertions(+), 90 deletions(-) diff --git a/common/console.c b/common/console.c index 79bbc41..6f720c2 100644 --- a/common/console.c +++ b/common/console.c @@ -551,11 +551,14 @@ Draws the console with the solid background */ void Con_DrawConsole (int lines) { - int i, j, x, y, n; + int i, x, y; int rows; char *text; int row; +#ifdef QUAKEWORLD + int j, n; char dlbar[1024]; +#endif if (lines <= 0) return; diff --git a/common/keys.c b/common/keys.c index 7330ac2..78df937 100644 --- a/common/keys.c +++ b/common/keys.c @@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "console.h" #include "menu.h" #include "screen.h" +#include "sys.h" #ifdef _WIN32 #include diff --git a/common/pr_cmds.c b/common/pr_cmds.c index 2d05a84..8f6d243 100644 --- a/common/pr_cmds.c +++ b/common/pr_cmds.c @@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #define RETURN_EDICT(e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e)) #define RETURN_STRING(s) (((int *)pr_globals)[OFS_RETURN] = PR_SetString(s)) diff --git a/common/pr_edict.c b/common/pr_edict.c index 0840f42..53421fe 100644 --- a/common/pr_edict.c +++ b/common/pr_edict.c @@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include dprograms_t *progs; dfunction_t *pr_functions; diff --git a/common/pr_exec.c b/common/pr_exec.c index 979ebe5..0a2f72a 100644 --- a/common/pr_exec.c +++ b/common/pr_exec.c @@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif #include +#include typedef struct { @@ -371,9 +372,9 @@ PR_ExecuteProgram */ void PR_ExecuteProgram (func_t fnum) { - eval_t *a, *b, *c; + eval_t *a=0, *b=0, *c=0; int s; - dstatement_t *st; + dstatement_t *st=0; dfunction_t *f, *newf; int runaway; int i; diff --git a/common/quakefs.c b/common/quakefs.c index c0c8633..2e55377 100644 --- a/common/quakefs.c +++ b/common/quakefs.c @@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include +#include +#include #include #include #include @@ -260,6 +262,36 @@ void COM_CopyFile (char *netpath, char *cachepath) fclose (out); } + +gzFile *COM_gzOpenRead(const char *path, int offs, int len) +{ + int fd=open(path,O_RDONLY); + unsigned char id[2]; + unsigned char len_bytes[4]; + if (fd==-1) { + Sys_Error ("Couldn't open %s", path); + return 0; + } + if (offs<0 || len<0) { + // normal file + offs=0; + len=lseek(fd,0,SEEK_END); + lseek(fd,0,SEEK_SET); + } + read(fd,id,2); + if (id[0]==0x1f && id[1]==0x8b) { + lseek(fd,offs+len-4,SEEK_SET); + read(fd,len_bytes,4); + len=((len_bytes[3]<<24) + |(len_bytes[2]<<16) + |(len_bytes[1]<<8) + |(len_bytes[0])); + } + lseek(fd,offs,SEEK_SET); + com_filesize=len; + return gzdopen(fd,"rb"); +} + /* =========== COM_FindFile @@ -270,7 +302,7 @@ Sets com_filesize and one of handle or file */ int file_from_pak; // global indicating file came from pack file ZOID -int COM_FOpenFile (char *filename, FILE **file) +int COM_FOpenFile (char *filename, gzFile **gzfile) { searchpath_t *search; char netpath[MAX_OSPATH]; @@ -305,11 +337,13 @@ int COM_FOpenFile (char *filename, FILE **file) if(developer.value) Sys_Printf ("PackFile: %s : %s\n",pak->filename, fn); // open a new file on the pakfile - *file = fopen (pak->filename, "rb"); - if (!*file) - Sys_Error ("Couldn't reopen %s", pak->filename); - fseek (*file, pak->files[i].filepos, SEEK_SET); - com_filesize = pak->files[i].filelen; + //*file = fopen (pak->filename, "rb"); + //if (!*file) + // Sys_Error ("Couldn't reopen %s", pak->filename); + //fseek (*file, pak->files[i].filepos, SEEK_SET); + //com_filesize = pak->files[i].filelen; + *gzfile=COM_gzOpenRead(pak->filename,pak->files[i].filepos, + pak->files[i].filelen); file_from_pak = 1; return com_filesize; } @@ -333,15 +367,17 @@ int COM_FOpenFile (char *filename, FILE **file) if(developer.value) Sys_Printf ("FindFile: %s\n",netpath); - *file = fopen (netpath, "rb"); - return COM_filelength (*file); + //*file = fopen (netpath, "rb"); + //return COM_filelength (*file); + *gzfile=COM_gzOpenRead(netpath,-1,-1); + return com_filesize; } } Sys_Printf ("FindFile: can't find %s\n", filename); - *file = NULL; + *gzfile = NULL; com_filesize = -1; return -1; } @@ -359,7 +395,7 @@ byte *loadbuf; int loadsize; byte *COM_LoadFile (char *path, int usehunk) { - FILE *h; + gzFile *h; byte *buf; char base[32]; int len; @@ -399,8 +435,8 @@ byte *COM_LoadFile (char *path, int usehunk) #ifndef SERVERONLY Draw_BeginDisc (); #endif - fread (buf, 1, len, h); - fclose (h); + gzread (h, buf, len); + gzclose (h); #ifndef SERVERONLY Draw_EndDisc (); #endif diff --git a/common/quakefs.h b/common/quakefs.h index cc8685b..257f03f 100644 --- a/common/quakefs.h +++ b/common/quakefs.h @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _QUAKEFS_H #define _QUAKEFS_H +#include //============================================================================ @@ -35,7 +36,7 @@ struct cache_user_s; extern char com_gamedir[MAX_OSPATH]; void COM_WriteFile (char *filename, void *data, int len); -int COM_FOpenFile (char *filename, FILE **file); +int COM_FOpenFile (char *filename, gzFile **file); void COM_CloseFile (FILE *h); byte *COM_LoadStackFile (char *path, void *buffer, int bufsize); diff --git a/common/register_check.c b/common/register_check.c index a5d91db..c3808a7 100644 --- a/common/register_check.c +++ b/common/register_check.c @@ -44,7 +44,7 @@ cvar_t registered = {"registered", "0"}; void register_check ( void ) { - FILE *h; + gzFile *h; Cvar_RegisterVariable (®istered); @@ -52,6 +52,6 @@ register_check ( void ) { if (h) { Cvar_Set ("registered", "1"); - fclose (h); + gzclose (h); } } diff --git a/common/sbar.c b/common/sbar.c index 1159e37..aa24486 100644 --- a/common/sbar.c +++ b/common/sbar.c @@ -33,6 +33,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "cmd.h" #include +extern void M_DrawPic (int x, int y, qpic_t *pic); + int sb_updates; // if >= vid.numpages, no update needed #define STAT_MINUS 10 // num frame for '-' stats digit @@ -655,7 +657,6 @@ void Sbar_SoloScoreboard (void) { char str[80]; int minutes, seconds, tens, units; - int l; #ifdef QUAKEWORLD Sbar_DrawPic (0, 0, sb_scorebar); @@ -676,9 +677,11 @@ void Sbar_SoloScoreboard (void) Sbar_DrawString (184, 4, str); #ifdef UQUAKE - // draw level name - l = strlen (cl.levelname); - Sbar_DrawString (232 - l*4, 12, cl.levelname); + { + // draw level name + int l = strlen (cl.levelname); + Sbar_DrawString (232 - l*4, 12, cl.levelname); + } #endif // QUAKEWORLD } @@ -1194,7 +1197,9 @@ Sbar_Draw void Sbar_Draw (void) { qboolean headsup; +#ifdef QUAKEWORLD char st[512]; +#endif headsup = !(cl_sbar.value || scr_viewsize.value<100); if ((sb_updates >= vid.numpages) && !headsup) diff --git a/configure.in b/configure.in index 98c76db..09708d1 100644 --- a/configure.in +++ b/configure.in @@ -113,6 +113,10 @@ fi dnl Checks for working -lm AC_CHECK_LIB(m, pow,, AC_MSG_ERROR([math library (-lm) appears broken])) + +dnl Check for working -lz +AC_CHECK_LIB(z, gzopen, LIBS="$LIBS -lz" + HAS_ZLIB=yes, HAS_ZLIB=no, [$LIBS]) dnl Checks for X11 support dnl (XoXus: Since vid_x.c relies on XShm being there, this now disables @@ -435,7 +439,7 @@ dnl CFLAGS for release and devel versions if test "x$RELEASE" = xyes; then if test "x$GCC" = xyes; then AC_MSG_CHECKING(for special release compiler settings) - BASE_RELEASE_CFLAGS="-Wall -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations" + BASE_RELEASE_CFLAGS="-Wall -Werror -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations" case "${target}" in changequote(,)dnl i?86-*-*) @@ -478,7 +482,7 @@ fi dnl We want warnings, lots of warnings... if test "x$GCC" = xyes; then - CFLAGS="$CFLAGS -Wall" + CFLAGS="$CFLAGS -Wall -Werror" fi # CFLAGS="$CFLAGS -Wall -pedantic" diff --git a/qw_client/cl_demo.c b/qw_client/cl_demo.c index 02fb80f..1a35a07 100644 --- a/qw_client/cl_demo.c +++ b/qw_client/cl_demo.c @@ -54,7 +54,7 @@ void CL_StopPlayback (void) if (!cls.demoplayback) return; - fclose (cls.demofile); + gzclose (cls.demofile); cls.demofile = NULL; cls.state = ca_disconnected; cls.demoplayback = 0; @@ -84,10 +84,10 @@ void CL_WriteDemoCmd (usercmd_t *pcmd) //Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime); fl = LittleFloat((float)realtime); - fwrite (&fl, sizeof(fl), 1, cls.demofile); + gzwrite (cls.demofile, &fl, sizeof(fl)); c = dem_cmd; - fwrite (&c, sizeof(c), 1, cls.demofile); + gzwrite (cls.demofile, &c, sizeof(c)); // correct for byte order, bytes don't matter cmd = *pcmd; @@ -98,15 +98,15 @@ void CL_WriteDemoCmd (usercmd_t *pcmd) cmd.sidemove = LittleShort(cmd.sidemove); cmd.upmove = LittleShort(cmd.upmove); - fwrite(&cmd, sizeof(cmd), 1, cls.demofile); + gzwrite(cls.demofile, &cmd, sizeof(cmd)); for (i=0 ; i<3 ; i++) { fl = LittleFloat (cl.viewangles[i]); - fwrite (&fl, 4, 1, cls.demofile); + gzwrite (cls.demofile, &fl, 4); } - fflush (cls.demofile); + gzflush (cls.demofile, Z_SYNC_FLUSH); } /* @@ -128,16 +128,16 @@ void CL_WriteDemoMessage (sizebuf_t *msg) return; fl = LittleFloat((float)realtime); - fwrite (&fl, sizeof(fl), 1, cls.demofile); + gzwrite (cls.demofile, &fl, sizeof(fl)); c = dem_read; - fwrite (&c, sizeof(c), 1, cls.demofile); + gzwrite (cls.demofile, &c, sizeof(c)); len = LittleLong (msg->cursize); - fwrite (&len, 4, 1, cls.demofile); - fwrite (msg->data, msg->cursize, 1, cls.demofile); + gzwrite (cls.demofile, &len, 4); + gzwrite (cls.demofile, msg->data, msg->cursize); - fflush (cls.demofile); + gzflush (cls.demofile, Z_SYNC_FLUSH); } /* @@ -156,7 +156,7 @@ qboolean CL_GetDemoMessage (void) usercmd_t *pcmd; // read the time from the packet - fread(&demotime, sizeof(demotime), 1, cls.demofile); + gzread(cls.demofile, &demotime, sizeof(demotime)); demotime = LittleFloat(demotime); // decide if it is time to grab the next message @@ -166,7 +166,7 @@ qboolean CL_GetDemoMessage (void) else if (demotime > cls.td_lastframe) { cls.td_lastframe = demotime; // rewind back to time - fseek(cls.demofile, ftell(cls.demofile) - sizeof(demotime), + gzseek(cls.demofile, gztell(cls.demofile) - sizeof(demotime), SEEK_SET); return 0; // allready read this frame's message } @@ -180,12 +180,12 @@ qboolean CL_GetDemoMessage (void) // too far back realtime = demotime - 1.0; // rewind back to time - fseek(cls.demofile, ftell(cls.demofile) - sizeof(demotime), + gzseek(cls.demofile, gztell(cls.demofile) - sizeof(demotime), SEEK_SET); return 0; } else if (realtime < demotime) { // rewind back to time - fseek(cls.demofile, ftell(cls.demofile) - sizeof(demotime), + gzseek(cls.demofile, gztell(cls.demofile) - sizeof(demotime), SEEK_SET); return 0; // don't need another message yet } @@ -196,14 +196,14 @@ qboolean CL_GetDemoMessage (void) Host_Error ("CL_GetDemoMessage: cls.state != ca_active"); // get the msg type - fread (&c, sizeof(c), 1, cls.demofile); + gzread (cls.demofile, &c, sizeof(c)); switch (c) { case dem_cmd : // user sent input i = cls.netchan.outgoing_sequence & UPDATE_MASK; pcmd = &cl.frames[i].cmd; - r = fread (pcmd, sizeof(*pcmd), 1, cls.demofile); + r = gzread (cls.demofile, pcmd, sizeof(*pcmd)); if (r != 1) { CL_StopPlayback (); @@ -220,19 +220,19 @@ qboolean CL_GetDemoMessage (void) cls.netchan.outgoing_sequence++; for (i=0 ; i<3 ; i++) { - r = fread (&f, 4, 1, cls.demofile); + r = gzread (cls.demofile, &f, 4); cl.viewangles[i] = LittleFloat (f); } break; case dem_read: // get the next message - fread (&net_message.cursize, 4, 1, cls.demofile); + gzread (cls.demofile, &net_message.cursize, 4); net_message.cursize = LittleLong (net_message.cursize); //Con_Printf("read: %ld bytes\n", net_message.cursize); if (net_message.cursize > MAX_MSGLEN) Sys_Error ("Demo message > MAX_MSGLEN"); - r = fread (net_message.data, net_message.cursize, 1, cls.demofile); + r = gzread (cls.demofile, net_message.data, net_message.cursize); if (r != 1) { CL_StopPlayback (); @@ -241,9 +241,9 @@ qboolean CL_GetDemoMessage (void) break; case dem_set : - fread (&i, 4, 1, cls.demofile); + gzread (cls.demofile, &i, 4); cls.netchan.outgoing_sequence = LittleLong(i); - fread (&i, 4, 1, cls.demofile); + gzread (cls.demofile, &i, 4); cls.netchan.incoming_sequence = LittleLong(i); break; @@ -300,7 +300,7 @@ void CL_Stop_f (void) CL_WriteDemoMessage (&net_message); // finish up - fclose (cls.demofile); + gzclose (cls.demofile); cls.demofile = NULL; cls.demorecording = false; Con_Printf ("Completed demo\n"); @@ -327,21 +327,21 @@ void CL_WriteRecordDemoMessage (sizebuf_t *msg, int seq) return; fl = LittleFloat((float)realtime); - fwrite (&fl, sizeof(fl), 1, cls.demofile); + gzwrite (cls.demofile, &fl, sizeof(fl)); c = dem_read; - fwrite (&c, sizeof(c), 1, cls.demofile); + gzwrite (cls.demofile, &c, sizeof(c)); len = LittleLong (msg->cursize + 8); - fwrite (&len, 4, 1, cls.demofile); + gzwrite (cls.demofile, &len, 4); i = LittleLong(seq); - fwrite (&i, 4, 1, cls.demofile); - fwrite (&i, 4, 1, cls.demofile); + gzwrite (cls.demofile, &i, 4); + gzwrite (cls.demofile, &i, 4); - fwrite (msg->data, msg->cursize, 1, cls.demofile); + gzwrite (cls.demofile, msg->data, msg->cursize); - fflush (cls.demofile); + gzflush (cls.demofile, Z_SYNC_FLUSH); } @@ -357,17 +357,17 @@ void CL_WriteSetDemoMessage (void) return; fl = LittleFloat((float)realtime); - fwrite (&fl, sizeof(fl), 1, cls.demofile); + gzwrite (cls.demofile, &fl, sizeof(fl)); c = dem_set; - fwrite (&c, sizeof(c), 1, cls.demofile); + gzwrite (cls.demofile, &c, sizeof(c)); len = LittleLong(cls.netchan.outgoing_sequence); - fwrite (&len, 4, 1, cls.demofile); + gzwrite (cls.demofile, &len, 4); len = LittleLong(cls.netchan.incoming_sequence); - fwrite (&len, 4, 1, cls.demofile); + gzwrite (cls.demofile, &len, 4); - fflush (cls.demofile); + gzflush (cls.demofile, Z_SYNC_FLUSH); } @@ -416,7 +416,7 @@ void CL_Record_f (void) // COM_DefaultExtension (name, ".qwd"); - cls.demofile = fopen (name, "wb"); + cls.demofile = gzopen (name, "wb"); if (!cls.demofile) { Con_Printf ("ERROR: couldn't open.\n"); @@ -702,7 +702,7 @@ void CL_ReRecord_f (void) // COM_DefaultExtension (name, ".qwd"); - cls.demofile = fopen (name, "wb"); + cls.demofile = gzopen (name, "wb"); if (!cls.demofile) { Con_Printf ("ERROR: couldn't open.\n"); diff --git a/qw_client/cl_parse.c b/qw_client/cl_parse.c index c7ef36b..d4a1b82 100644 --- a/qw_client/cl_parse.c +++ b/qw_client/cl_parse.c @@ -167,7 +167,7 @@ to start a download from the server. */ qboolean CL_CheckOrDownloadFile (char *filename) { - FILE *f; + gzFile *f; if (strstr (filename, "..")) { @@ -178,7 +178,7 @@ qboolean CL_CheckOrDownloadFile (char *filename) COM_FOpenFile (filename, &f); if (f) { // it exists, no need to download - fclose (f); + gzclose (f); return true; } diff --git a/qw_client/r_part.c b/qw_client/r_part.c index 55ba947..fe615eb 100644 --- a/qw_client/r_part.c +++ b/qw_client/r_part.c @@ -93,12 +93,13 @@ void R_ClearParticles (void) void R_ReadPointFile_f (void) { - FILE *f; + gzFile *f; vec3_t org; int r; int c; particle_t *p; char name[MAX_OSPATH]; + char buf[256]; // FIXME snprintf(name, sizeof(name),"maps/%s.pts", sv.name); @@ -113,7 +114,9 @@ void R_ReadPointFile_f (void) c = 0; for ( ;; ) { - r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]); + if (!gzgets(f,buf,sizeof(buf))) + break; + r = sscanf (buf,"%f %f %f\n", &org[0], &org[1], &org[2]); if (r != 3) break; c++; @@ -135,7 +138,7 @@ void R_ReadPointFile_f (void) VectorCopy (org, p->org); } - fclose (f); + gzclose (f); Con_Printf ("%i points read\n", c); } diff --git a/qw_common/client.h b/qw_common/client.h index e8bb80b..f5aefaa 100644 --- a/qw_common/client.h +++ b/qw_common/client.h @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _CLIENT_H #define _CLIENT_H +#include + #include "qtypes.h" #include "zone.h" #include "protocol.h" @@ -195,7 +197,7 @@ typedef struct qboolean demorecording; qboolean demoplayback; qboolean timedemo; - FILE *demofile; + gzFile *demofile; float td_lastframe; // to meter out one message a frame int td_startframe; // host_framecount at start float td_starttime; // realtime at second frame of timedemo diff --git a/qw_server/server.h b/qw_server/server.h index da9f611..549b16a 100644 --- a/qw_server/server.h +++ b/qw_server/server.h @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _SERVER_H #define _SERVER_H +#include + #include #define QW_SERVER @@ -175,7 +177,7 @@ typedef struct client_s client_frame_t frames[UPDATE_BACKUP]; // updates can be deltad from here - FILE *download; // file being downloaded + gzFile *download; // file being downloaded int downloadsize; // total bytes int downloadcount; // bytes sent diff --git a/qw_server/sv_ccmds.c b/qw_server/sv_ccmds.c index 7142660..414c635 100644 --- a/qw_server/sv_ccmds.c +++ b/qw_server/sv_ccmds.c @@ -306,7 +306,7 @@ void SV_Map_f (void) { char level[MAX_QPATH]; char expanded[MAX_QPATH]; - FILE *f; + gzFile *f; if (Cmd_Argc() != 2) { @@ -331,7 +331,7 @@ void SV_Map_f (void) Con_Printf ("Can't find %s\n", expanded); return; } - fclose (f); + gzclose (f); SV_BroadcastCommand ("changing\n"); SV_SendMessagesToAll (); diff --git a/qw_server/sv_user.c b/qw_server/sv_user.c index f77319f..eece957 100644 --- a/qw_server/sv_user.c +++ b/qw_server/sv_user.c @@ -533,7 +533,7 @@ void SV_NextDownload_f (void) r = host_client->downloadsize - host_client->downloadcount; if (r > 768) r = 768; - r = fread (buffer, 1, r, host_client->download); + r = gzread (host_client->download, buffer, r); ClientReliableWrite_Begin (host_client, svc_download, 6+r); ClientReliableWrite_Short (host_client, r); @@ -548,7 +548,7 @@ void SV_NextDownload_f (void) if (host_client->downloadcount != host_client->downloadsize) return; - fclose (host_client->download); + gzclose (host_client->download); host_client->download = NULL; } @@ -678,7 +678,7 @@ void SV_BeginDownload_f(void) } if (host_client->download) { - fclose (host_client->download); + gzclose (host_client->download); host_client->download = NULL; } @@ -700,7 +700,7 @@ void SV_BeginDownload_f(void) || (strncmp(name, "maps/", 5) == 0 && file_from_pak)) { if (host_client->download) { - fclose(host_client->download); + gzclose(host_client->download); host_client->download = NULL; } diff --git a/uquake/cl_demo.c b/uquake/cl_demo.c index 872225a..8e49396 100644 --- a/uquake/cl_demo.c +++ b/uquake/cl_demo.c @@ -55,7 +55,7 @@ void CL_StopPlayback (void) if (!cls.demoplayback) return; - fclose (cls.demofile); + gzclose (cls.demofile); cls.demoplayback = false; cls.demofile = NULL; cls.state = ca_disconnected; @@ -78,14 +78,14 @@ void CL_WriteDemoMessage (void) float f; len = LittleLong (net_message.cursize); - fwrite (&len, 4, 1, cls.demofile); + gzwrite (cls.demofile, &len, 4); for (i=0 ; i<3 ; i++) { f = LittleFloat (cl.viewangles[i]); - fwrite (&f, 4, 1, cls.demofile); + gzwrite (cls.demofile, &f, 4); } - fwrite (net_message.data, net_message.cursize, 1, cls.demofile); - fflush (cls.demofile); + gzwrite (cls.demofile, net_message.data, net_message.cursize); + gzflush (cls.demofile, Z_SYNC_FLUSH); } /* @@ -122,18 +122,18 @@ int CL_GetMessage (void) } // get the next message - fread (&net_message.cursize, 4, 1, cls.demofile); + gzread (cls.demofile, &net_message.cursize, 4); VectorCopy (cl.mviewangles[0], cl.mviewangles[1]); for (i=0 ; i<3 ; i++) { - r = fread (&f, 4, 1, cls.demofile); + r = gzread (cls.demofile, &f, 4); cl.mviewangles[0][i] = LittleFloat (f); } net_message.cursize = LittleLong (net_message.cursize); if (net_message.cursize > MAX_MSGLEN) Sys_Error ("Demo message > MAX_MSGLEN"); - r = fread (net_message.data, net_message.cursize, 1, cls.demofile); + r = gzread (cls.demofile, net_message.data, net_message.cursize); if (r != 1) { CL_StopPlayback (); @@ -188,7 +188,7 @@ void CL_Stop_f (void) CL_WriteDemoMessage (); // finish up - fclose (cls.demofile); + gzclose (cls.demofile); cls.demofile = NULL; cls.demorecording = false; Con_Printf ("Completed demo\n"); @@ -252,7 +252,7 @@ void CL_Record_f (void) COM_DefaultExtension (name, ".dem"); Con_Printf ("recording to %s.\n", name); - cls.demofile = fopen (name, "wb"); + cls.demofile = gzopen (name, "wb"); if (!cls.demofile) { Con_Printf ("ERROR: couldn't open.\n"); @@ -260,7 +260,7 @@ void CL_Record_f (void) } cls.forcetrack = track; - fprintf (cls.demofile, "%i\n", cls.forcetrack); + gzprintf (cls.demofile, "%i\n", cls.forcetrack); cls.demorecording = true; } @@ -312,7 +312,7 @@ void CL_PlayDemo_f (void) cls.state = ca_connected; cls.forcetrack = 0; - while ((c = getc(cls.demofile)) != '\n') + while ((c = gzgetc(cls.demofile)) != '\n') if (c == '-') neg = true; else diff --git a/uquake/client.h b/uquake/client.h index 3bbd263..946b6f8 100644 --- a/uquake/client.h +++ b/uquake/client.h @@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _CLIENT_H #define _CLIENT_H +#include + #include #include #include @@ -129,7 +131,7 @@ typedef struct qboolean demoplayback; qboolean timedemo; int forcetrack; // -1 = use normal cd track - FILE *demofile; + gzFile *demofile; int td_lastframe; // to meter out one message a frame int td_startframe; // host_framecount at start float td_starttime; // realtime at second frame of timedemo diff --git a/uquake/r_part.c b/uquake/r_part.c index 93cf0d6..3144b26 100644 --- a/uquake/r_part.c +++ b/uquake/r_part.c @@ -199,12 +199,13 @@ void R_ClearParticles (void) void R_ReadPointFile_f (void) { - FILE *f; + gzFile *f; vec3_t org; int r; int c; particle_t *p; char name[MAX_OSPATH]; + char buf[256]; snprintf(name, sizeof(name),"maps/%s.pts", sv.name); @@ -219,7 +220,9 @@ void R_ReadPointFile_f (void) c = 0; for ( ;; ) { - r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]); + if (!gzgets(f,buf,sizeof(buf))) + break; + r = sscanf (buf,"%f %f %f\n", &org[0], &org[1], &org[2]); if (r != 3) break; c++; @@ -241,7 +244,7 @@ void R_ReadPointFile_f (void) VectorCopy (org, p->org); } - fclose (f); + gzclose (f); Con_Printf ("%i points read\n", c); }