if (!cls.demoplayback)
return;
- fclose (cls.demofile);
+ Qclose (cls.demofile);
cls.demoplayback = false;
cls.demofile = NULL;
cls.state = ca_disconnected;
return;
len = LittleLong (net_message.cursize);
- fwrite (&len, 4, 1, cls.demofile);
+ Qwrite (cls.demofile, &len, 4);
for (i=0 ; i<3 ; i++)
{
f = LittleFloat (cl.viewangles[i]);
- fwrite (&f, 4, 1, cls.demofile);
+ Qwrite (cls.demofile, &f, 4);
}
- fwrite (net_message.data, net_message.cursize, 1, cls.demofile);
- fflush (cls.demofile);
+ Qwrite (cls.demofile, net_message.data, net_message.cursize);
+ Qflush (cls.demofile);
}
/*
}
// get the next message
- fread (&net_message.cursize, 4, 1, cls.demofile);
+ Qread (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 = Qread (cls.demofile, &f, 4);
cl.mviewangles[0][i] = LittleFloat (f);
}
net_message.cursize = LittleLong (net_message.cursize);
if (net_message.cursize > MAX_MSGLEN)
Host_Error ("Demo message > MAX_MSGLEN");
- r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
- if (r != 1)
+ r = Qread (cls.demofile, net_message.data, net_message.cursize);
+ if (r != net_message.cursize)
{
CL_StopPlayback ();
return 0;
CL_WriteDemoMessage ();
// finish up
- fclose (cls.demofile);
+ Qclose (cls.demofile);
cls.demofile = NULL;
cls.demorecording = false;
Con_Printf ("Completed demo\n");
COM_DefaultExtension (name, ".dem");
Con_Printf ("recording to %s.\n", name);
- cls.demofile = fopen (name, "wb");
+ cls.demofile = Qopen (name, "wb");
if (!cls.demofile)
{
Con_Printf ("ERROR: couldn't open.\n");
}
cls.forcetrack = track;
- fprintf (cls.demofile, "%i\n", cls.forcetrack);
+ Qprintf (cls.demofile, "%i\n", cls.forcetrack);
cls.demorecording = true;
}
COM_DefaultExtension (name, ".dem");
Con_Printf ("Playing demo from %s.\n", name);
- COM_FOpenFile (name, &cls.demofile, false);
+ COM_FOpenFile (name, &cls.demofile, false, true);
if (!cls.demofile)
{
Con_Printf ("ERROR: couldn't open.\n");
cls.state = ca_connected;
cls.forcetrack = 0;
- while ((c = getc(cls.demofile)) != '\n')
+ while ((c = Qgetc(cls.demofile)) != '\n')
if (c == '-')
neg = true;
else
qboolean demoplayback;
qboolean timedemo;
int forcetrack; // -1 = use normal cd track
- FILE *demofile;
+ QFile *demofile;
int td_lastframe; // to meter out one message a frame
int td_startframe; // host_framecount at start
double td_starttime; // realtime at second frame of timedemo (LordHavoc: changed to double)
*/
// common.c -- misc functions used in client and server
+#include <fcntl.h>
+#ifndef WIN32
+#include <unistd.h>
+#endif
+#include <stdlib.h>
+
#include "quakedef.h"
#define NUM_SAFE_ARGVS 7
*/
void COM_CheckRegistered (void)
{
- int h;
+ QFile *h;
unsigned short check[128];
int i;
Cvar_Set ("cmdline", com_cmdline);
- COM_OpenFile("gfx/pop.lmp", &h, false);
+ COM_FOpenFile("gfx/pop.lmp", &h, false, true);
static_registered = 0;
- if (h == -1)
+ if (!h)
{
if (com_modified)
Con_Printf ("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
return;
}
- Sys_FileRead (h, check, sizeof(check));
- COM_CloseFile (h);
+ Qread (h, check, sizeof(check));
+ Qclose (h);
for (i=0 ; i<128 ; i++)
if (pop[i] != (unsigned short)BigShort (check[i]))
Sys_FileClose (out);
}
+/*
+===========
+COM_OpenRead
+===========
+*/
+QFile * COM_OpenRead (const char *path, int offs, int len, qboolean zip)
+{
+ 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);
+ }
+ lseek (fd, offs, SEEK_SET);
+ if (zip)
+ {
+ 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;
+
+#ifdef WIN32
+ setmode (fd, O_BINARY);
+#endif
+ if (zip)
+ return Qdopen (fd, "rbz");
+ else
+ return Qdopen (fd, "rb");
+}
+
/*
===========
COM_FindFile
Sets com_filesize and one of handle or file
===========
*/
-int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
+int COM_FindFile (char *filename, QFile **file, qboolean quiet, qboolean zip)
{
searchpath_t *search;
char netpath[MAX_OSPATH];
pack_t *pak;
int i;
int findtime;
+ char gzfilename[MAX_OSPATH];
+ int filenamelen;
+
+ filenamelen = strlen (filename);
+ snprintf (gzfilename, sizeof (gzfilename), "%s.gz", filename);
- if (file && handle)
- Sys_Error ("COM_FindFile: both handle and file set");
- if (!file && !handle)
- Sys_Error ("COM_FindFile: neither handle or file set");
+ if (!file)
+ Sys_Error ("COM_FindFile: file not set");
//
// search through the path, one element at a time
// look through all the pak file elements
pak = search->pack;
for (i=0 ; i<pak->numfiles ; i++)
- if (!strcmp (pak->files[i].name, filename))
+ if (!strcmp (pak->files[i].name, filename)
+ || !strcmp (pak->files[i].name, gzfilename))
{ // found it!
if (!quiet)
- Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename);
- if (handle)
- {
- *handle = pak->handle;
- Sys_FileSeek (pak->handle, pak->files[i].filepos);
- }
- else
- { // open a new file on the pakfile
- *file = fopen (pak->filename, "rb");
- if (*file)
- fseek (*file, pak->files[i].filepos, SEEK_SET);
- }
- com_filesize = pak->files[i].filelen;
+ Sys_Printf ("PackFile: %s : %s\n",pak->filename, pak->files[i].name);
+ // open a new file on the pakfile
+ *file = COM_OpenRead (pak->filename, pak->files[i].filepos, pak->files[i].filelen, zip);
return com_filesize;
}
}
if (!quiet)
Sys_Printf ("FindFile: %s\n",netpath);
- com_filesize = Sys_FileOpenRead (netpath, &i);
- if (handle)
- *handle = i;
- else
- {
- Sys_FileClose (i);
- *file = fopen (netpath, "rb");
- }
+ *file = COM_OpenRead (netpath, -1, -1, zip);
return com_filesize;
}
if (!quiet)
Sys_Printf ("FindFile: can't find %s\n", filename);
- if (handle)
- *handle = -1;
- else
- *file = NULL;
+ *file = NULL;
com_filesize = -1;
return -1;
}
-/*
-===========
-COM_OpenFile
-
-filename never has a leading slash, but may contain directory walks
-returns a handle and a length
-it may actually be inside a pak file
-===========
-*/
-int COM_OpenFile (char *filename, int *handle, qboolean quiet)
-{
- return COM_FindFile (filename, handle, NULL, quiet);
-}
-
/*
===========
COM_FOpenFile
-If the requested file is inside a packfile, a new FILE * will be opened
+If the requested file is inside a packfile, a new QFile * will be opened
into the file.
===========
*/
-int COM_FOpenFile (char *filename, FILE **file, qboolean quiet)
+int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip)
{
- return COM_FindFile (filename, NULL, file, quiet);
-}
-
-/*
-============
-COM_CloseFile
-
-If it is a pak file handle, don't really close it
-============
-*/
-void COM_CloseFile (int h)
-{
- searchpath_t *s;
-
- for (s = com_searchpaths ; s ; s=s->next)
- if (s->pack && s->pack->handle == h)
- return;
-
- Sys_FileClose (h);
+ return COM_FindFile (filename, file, quiet, zip);
}
int loadsize;
byte *COM_LoadFile (char *path, int usehunk, qboolean quiet)
{
- int h;
+ QFile *h;
byte *buf;
char base[1024];
int len;
buf = NULL; // quiet compiler warning
// look for it in the filesystem or pack files
- len = COM_OpenFile (path, &h, quiet);
- if (h == -1)
+ len = COM_FOpenFile (path, &h, quiet, true);
+ if (!h)
return NULL;
// extract the filename base name for hunk tag
((byte *)buf)[len] = 0;
- Sys_FileRead (h, buf, len);
- COM_CloseFile (h);
+ Qread (h, buf, len);
+ Qclose (h);
return buf;
}
typedef enum {false, true} qboolean;
+#include "quakeio.h"
+
//============================================================================
extern void *qmalloc(unsigned int size);
extern char com_gamedir[MAX_OSPATH];
void COM_WriteFile (char *filename, void *data, int len);
-int COM_OpenFile (char *filename, int *hndl, qboolean quiet);
-int COM_FOpenFile (char *filename, FILE **file, qboolean quiet);
-void COM_CloseFile (int h);
+int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip);
byte *COM_LoadHunkFile (char *path, qboolean quiet);
byte *COM_LoadMallocFile (char *path, qboolean quiet);
with the archive flag set to true.
============
*/
-void Cvar_WriteVariables (FILE *f)
+void Cvar_WriteVariables (QFile *f)
{
cvar_t *var;
for (var = cvar_vars ; var ; var = var->next)
if (var->archive)
- fprintf (f, "%s \"%s\"\n", var->name, var->string);
+ Qprintf (f, "%s \"%s\"\n", var->name, var->string);
}
// command. Returns true if the command was a variable reference that
// was handled. (print or change)
-void Cvar_WriteVariables (FILE *f);
+void Cvar_WriteVariables (QFile *f);
// Writes lines containing "set variable value" for all variables
// with the archive flag set to true.
*/
void Host_WriteConfiguration (void)
{
- FILE *f;
+ QFile *f;
// dedicated servers initialize the host but don't parse and set the
// config.cfg cvars
if (host_initialized & !isDedicated)
{
- f = fopen (va("%s/config.cfg",com_gamedir), "w");
+ f = Qopen (va("%s/config.cfg",com_gamedir), "w");
if (!f)
{
Con_Printf ("Couldn't write config.cfg.\n");
Key_WriteBindings (f);
Cvar_WriteVariables (f);
- fclose (f);
+ Qclose (f);
}
}
void Host_Savegame_f (void)
{
char name[256];
- FILE *f;
+ QFile *f;
int i;
char comment[SAVEGAME_COMMENT_LENGTH+1];
COM_DefaultExtension (name, ".sav");
Con_Printf ("Saving game to %s...\n", name);
- f = fopen (name, "w");
+ f = Qopen (name, "w");
if (!f)
{
Con_Printf ("ERROR: couldn't open.\n");
return;
}
- fprintf (f, "%i\n", SAVEGAME_VERSION);
+ Qprintf (f, "%i\n", SAVEGAME_VERSION);
Host_SavegameComment (comment);
- fprintf (f, "%s\n", comment);
+ Qprintf (f, "%s\n", comment);
for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
- fprintf (f, "%f\n", svs.clients->spawn_parms[i]);
- fprintf (f, "%d\n", current_skill);
- fprintf (f, "%s\n", sv.name);
- fprintf (f, "%f\n",sv.time);
+ Qprintf (f, "%f\n", svs.clients->spawn_parms[i]);
+ Qprintf (f, "%d\n", current_skill);
+ Qprintf (f, "%s\n", sv.name);
+ Qprintf (f, "%f\n",sv.time);
// write the light styles
for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{
if (sv.lightstyles[i])
- fprintf (f, "%s\n", sv.lightstyles[i]);
+ Qprintf (f, "%s\n", sv.lightstyles[i]);
else
- fprintf (f,"m\n");
+ Qprintf (f,"m\n");
}
for (i=0 ; i<sv.num_edicts ; i++)
{
ED_Write (f, EDICT_NUM(i));
- fflush (f);
+ Qflush (f);
}
- fclose (f);
+ Qclose (f);
Con_Printf ("done.\n");
}
void Host_Loadgame_f (void)
{
char name[MAX_OSPATH];
- FILE *f;
+ QFile *f;
char mapname[MAX_QPATH];
float time, tfloat;
- char str[32768], *start;
+ char buf[32768], *start;
+ char *str;
int i, r;
edict_t *ent;
int entnum;
// SCR_BeginLoadingPlaque ();
Con_Printf ("Loading game from %s...\n", name);
- f = fopen (name, "r");
+ f = Qopen (name, "rz");
if (!f)
{
Con_Printf ("ERROR: couldn't open.\n");
return;
}
- fscanf (f, "%i\n", &version);
+ str = Qgetline (f);
+ sscanf (str, "%i\n", &version);
if (version != SAVEGAME_VERSION)
{
- fclose (f);
+ Qclose (f);
Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
return;
}
- fscanf (f, "%s\n", str);
- for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
- fscanf (f, "%f\n", &spawn_parms[i]);
+ str = Qgetline (f);
+ for (i=0 ; i<NUM_SPAWN_PARMS ; i++) {
+ str = Qgetline (f);
+ sscanf (str, "%f\n", &spawn_parms[i]);
+ }
// this silliness is so we can load 1.06 save files, which have float skill values
- fscanf (f, "%f\n", &tfloat);
+ str = Qgetline (f);
+ sscanf (str, "%f\n", &tfloat);
current_skill = (int)(tfloat + 0.1);
Cvar_SetValue ("skill", (float)current_skill);
- fscanf (f, "%s\n",mapname);
- fscanf (f, "%f\n",&time);
+ strcpy (mapname, Qgetline (f));
+ str = Qgetline (f);
+ sscanf (str, "%f\n",&time);
CL_Disconnect_f ();
for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{
- fscanf (f, "%s\n", str);
+ str = Qgetline (f);
sv.lightstyles[i] = Hunk_AllocName (strlen(str)+1, "lightstyles");
strcpy (sv.lightstyles[i], str);
}
// load the edicts out of the savegame file
entnum = -1; // -1 is the globals
- while (!feof(f))
+ while (!Qeof(f))
{
- for (i=0 ; i<sizeof(str)-1 ; i++)
+ for (i=0 ; i<sizeof(buf)-1 ; i++)
{
- r = fgetc (f);
+ r = Qgetc (f);
if (r == EOF || !r)
break;
- str[i] = r;
+ buf[i] = r;
if (r == '}')
{
i++;
break;
}
}
- if (i == sizeof(str)-1)
+ if (i == sizeof(buf)-1)
Sys_Error ("Loadgame buffer overflow");
- str[i] = 0;
- start = str;
- start = COM_Parse(str);
+ buf[i] = 0;
+ start = buf;
+ start = COM_Parse(buf);
if (!com_token[0])
break; // end of file
if (strcmp(com_token,"{"))
sv.num_edicts = entnum;
sv.time = time;
- fclose (f);
+ Qclose (f);
for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
svs.clients->spawn_parms[i] = spawn_parms[i];
LoadPCX
============
*/
-byte* LoadPCX (FILE *f, int matchwidth, int matchheight)
+byte* LoadPCX (QFile *f, int matchwidth, int matchheight)
{
pcx_t *pcx, pcxbuf;
byte palette[768];
//
// parse the PCX file
//
- fread (&pcxbuf, 1, sizeof(pcxbuf), f);
+ Qread (f, &pcxbuf, sizeof(pcxbuf));
pcx = &pcxbuf;
return NULL;
// seek to palette
- fseek (f, -768, SEEK_END);
- fread (palette, 1, 768, f);
+ Qseek (f, -768, SEEK_END);
+ Qread (f, palette, 768);
- fseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
+ Qseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
count = (pcx->xmax+1) * (pcx->ymax+1);
image_rgba = qmalloc( count * 4);
pix = image_rgba + 4*y*(pcx->xmax+1);
for (x=0 ; x<=pcx->xmax ; )
{
- dataByte = fgetc(f);
+ dataByte = Qgetc(f);
if((dataByte & 0xC0) == 0xC0)
{
runLength = dataByte & 0x3F;
- dataByte = fgetc(f);
+ dataByte = Qgetc(f);
if (runLength)
{
x += runLength;
}
}
- fclose(f);
+ Qclose(f);
image_width = pcx->xmax+1;
image_height = pcx->ymax+1;
return image_rgba;
TargaHeader targa_header;
-int fgetLittleShort (FILE *f)
+int fgetLittleShort (QFile *f)
{
byte b1, b2;
- b1 = fgetc(f);
- b2 = fgetc(f);
+ b1 = Qgetc(f);
+ b2 = Qgetc(f);
return (short)(b1 + b2*256);
}
-int fgetLittleLong (FILE *f)
+int fgetLittleLong (QFile *f)
{
byte b1, b2, b3, b4;
- b1 = fgetc(f);
- b2 = fgetc(f);
- b3 = fgetc(f);
- b4 = fgetc(f);
+ b1 = Qgetc(f);
+ b2 = Qgetc(f);
+ b3 = Qgetc(f);
+ b4 = Qgetc(f);
return b1 + (b2<<8) + (b3<<16) + (b4<<24);
}
LoadTGA
=============
*/
-byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
+byte* LoadTGA (QFile *fin, int matchwidth, int matchheight)
{
int columns, rows, numPixels;
byte *pixbuf;
int row, column;
byte *image_rgba;
- targa_header.id_length = fgetc(fin);
- targa_header.colormap_type = fgetc(fin);
- targa_header.image_type = fgetc(fin);
+ targa_header.id_length = Qgetc(fin);
+ targa_header.colormap_type = Qgetc(fin);
+ targa_header.image_type = Qgetc(fin);
targa_header.colormap_index = fgetLittleShort(fin);
targa_header.colormap_length = fgetLittleShort(fin);
- targa_header.colormap_size = fgetc(fin);
+ targa_header.colormap_size = Qgetc(fin);
targa_header.x_origin = fgetLittleShort(fin);
targa_header.y_origin = fgetLittleShort(fin);
targa_header.width = fgetLittleShort(fin);
return NULL;
if (matchheight && targa_header.height != matchheight)
return NULL;
- targa_header.pixel_size = fgetc(fin);
- targa_header.attributes = fgetc(fin);
+ targa_header.pixel_size = Qgetc(fin);
+ targa_header.attributes = Qgetc(fin);
if (targa_header.image_type!=2
&& targa_header.image_type!=10)
image_rgba = qmalloc(numPixels*4);
if (targa_header.id_length != 0)
- fseek(fin, targa_header.id_length, SEEK_CUR); // skip TARGA image comment
+ Qseek(fin, targa_header.id_length, SEEK_CUR); // skip TARGA image comment
if (targa_header.image_type==2) { // Uncompressed, RGB images
for(row=rows-1; row>=0; row--) {
switch (targa_header.pixel_size) {
case 24:
- blue = getc(fin);
- green = getc(fin);
- red = getc(fin);
+ blue = Qgetc(fin);
+ green = Qgetc(fin);
+ red = Qgetc(fin);
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = 255;
break;
case 32:
- blue = getc(fin);
- green = getc(fin);
- red = getc(fin);
- alphabyte = getc(fin);
+ blue = Qgetc(fin);
+ green = Qgetc(fin);
+ red = Qgetc(fin);
+ alphabyte = Qgetc(fin);
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
for(row=rows-1; row>=0; row--) {
pixbuf = image_rgba + row*columns*4;
for(column=0; column<columns; ) {
- packetHeader=getc(fin);
+ packetHeader=Qgetc(fin);
packetSize = 1 + (packetHeader & 0x7f);
if (packetHeader & 0x80) { // run-length packet
switch (targa_header.pixel_size) {
case 24:
- blue = getc(fin);
- green = getc(fin);
- red = getc(fin);
+ blue = Qgetc(fin);
+ green = Qgetc(fin);
+ red = Qgetc(fin);
alphabyte = 255;
break;
case 32:
- blue = getc(fin);
- green = getc(fin);
- red = getc(fin);
- alphabyte = getc(fin);
+ blue = Qgetc(fin);
+ green = Qgetc(fin);
+ red = Qgetc(fin);
+ alphabyte = Qgetc(fin);
break;
}
for(j=0;j<packetSize;j++) {
switch (targa_header.pixel_size) {
case 24:
- blue = getc(fin);
- green = getc(fin);
- red = getc(fin);
+ blue = Qgetc(fin);
+ green = Qgetc(fin);
+ red = Qgetc(fin);
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = 255;
break;
case 32:
- blue = getc(fin);
- green = getc(fin);
- red = getc(fin);
- alphabyte = getc(fin);
+ blue = Qgetc(fin);
+ green = Qgetc(fin);
+ red = Qgetc(fin);
+ alphabyte = Qgetc(fin);
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
}
}
- fclose(fin);
+ Qclose(fin);
image_width = columns;
image_height = rows;
return image_rgba;
LoadLMP
============
*/
-byte* LoadLMP (FILE *f, int matchwidth, int matchheight)
+byte* LoadLMP (QFile *f, int matchwidth, int matchheight)
{
byte *image_rgba;
int width, height;
return NULL;
image_rgba = qmalloc(width*height*4);
- fread(image_rgba + width*height*3, 1, width*height, f);
- fclose(f);
+ Qread(f, image_rgba + width*height*3, width*height);
+ Qclose(f);
Image_Copy8bitRGBA(image_rgba + width*height*3, image_rgba, width*height, d_8to24table);
image_width = width;
byte* loadimagepixels (char* filename, qboolean complain, int matchwidth, int matchheight)
{
- FILE *f;
+ QFile *f;
char basename[256], name[256];
byte *c;
Image_StripImageExtension(filename, basename); // strip .tga, .pcx and .lmp extensions to allow replacement by other types
if (*c == '*')
*c = '#';
sprintf (name, "textures/%s.tga", basename);
- COM_FOpenFile (name, &f, true);
+ COM_FOpenFile (name, &f, true, true);
if (f)
return LoadTGA (f, matchwidth, matchheight);
sprintf (name, "textures/%s.pcx", basename);
- COM_FOpenFile (name, &f, true);
+ COM_FOpenFile (name, &f, true, true);
if (f)
return LoadPCX (f, matchwidth, matchheight);
sprintf (name, "%s.tga", basename);
- COM_FOpenFile (name, &f, true);
+ COM_FOpenFile (name, &f, true, true);
if (f)
return LoadTGA (f, matchwidth, matchheight);
sprintf (name, "%s.pcx", basename);
- COM_FOpenFile (name, &f, true);
+ COM_FOpenFile (name, &f, true, true);
if (f)
return LoadPCX (f, matchwidth, matchheight);
sprintf (name, "%s.lmp", basename);
- COM_FOpenFile (name, &f, true);
+ COM_FOpenFile (name, &f, true, true);
if (f)
return LoadLMP (f, matchwidth, matchheight);
if (complain)
Writes lines containing "bind key value"
============
*/
-void Key_WriteBindings (FILE *f)
+void Key_WriteBindings (QFile *f)
{
int i;
for (i=0 ; i<256 ; i++)
if (keybindings[i])
if (*keybindings[i])
- fprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
+ Qprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
}
void Key_Event (int key, qboolean down);
void Key_Init (void);
-void Key_WriteBindings (FILE *f);
+void Key_WriteBindings (QFile *f);
void Key_SetBinding (int keynum, char *binding);
void Key_ClearStates (void);
#if you use the kernel sound driver or OSS
SND=snd_oss.o
-OBJECTS= buildnumber.o cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o gl_poly.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_screen.o gl_warp.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_part.o r_explosion.o sbar.o snd_dma.o snd_mem.o snd_mix.o $(SND) sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o r_modules.o r_explosion.o r_lerpanim.o cl_effects.o r_decals.o protocol.o
+OBJECTS= buildnumber.o cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o gl_poly.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_screen.o gl_warp.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_part.o r_explosion.o sbar.o snd_dma.o snd_mem.o snd_mix.o $(SND) sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o r_modules.o r_explosion.o r_lerpanim.o cl_effects.o r_decals.o protocol.o quakeio.o
OPTIMIZATIONS= -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations
#OPTIMIZATIONS= -O -g
CFLAGS= -Wall -Werror -I/usr/X11R6/include -I/usr/include/glide $(OPTIMIZATIONS)
#CFLAGS= -Wall -Werror -I/usr/X11R6/include -ggdb $(OPTIMIZATIONS)
#LDFLAGS= -L/usr/X11R6/lib -lm -lX11 -lXext -lXIE -lXxf86dga -lXxf86vm -lGL -ldl
-LDFLAGS= -L/usr/X11R6/lib -lm -lX11 -lXext -lXIE -lXxf86dga -lXxf86vm -lGL -ldl -lasound
+LDFLAGS= -L/usr/X11R6/lib -lm -lX11 -lXext -lXIE -lXxf86dga -lXxf86vm -lGL -ldl -lasound -lz
#most people can't build the -3dfx version (-3dfx version needs some updates for new mesa)
all: darkplaces-glx
int NehGameType;
-enum {m_none, m_main, m_demo, m_singleplayer, m_load, m_save, m_multiplayer, m_setup, m_net, m_options, m_video, m_keys, m_help, m_quit, m_lanconfig, m_gameoptions, m_search, m_slist} m_state;
+enum m_state_e m_state;
void M_Menu_Main_f (void);
void M_Menu_SinglePlayer_f (void);
{
int i, j;
char name[MAX_OSPATH];
- FILE *f;
+ char *str;
+ QFile *f;
int version;
for (i=0 ; i<MAX_SAVEGAMES ; i++)
strcpy (m_filenames[i], "--- UNUSED SLOT ---");
loadable[i] = false;
sprintf (name, "%s/s%i.sav", com_gamedir, i);
- f = fopen (name, "r");
+ f = Qopen (name, "rz");
if (!f)
continue;
- fscanf (f, "%i\n", &version);
- fscanf (f, "%79s\n", name);
- strncpy (m_filenames[i], name, sizeof(m_filenames[i])-1);
+ str = Qgetline (f);
+ sscanf (str, "%i\n", &version);
+ str = Qgetline (f);
+ strncpy (m_filenames[i], str, sizeof(m_filenames[i])-1);
// change _ back to space
for (j=0 ; j<SAVEGAME_COMMENT_LENGTH ; j++)
if (m_filenames[i][j] == '_')
m_filenames[i][j] = ' ';
loadable[i] = true;
- fclose (f);
+ Qclose (f);
}
}
#define MNET_IPX 1
#define MNET_TCP 2
+enum m_state_e {
+ m_none,
+ m_main,
+ m_demo,
+ m_singleplayer,
+ m_load,
+ m_save,
+ m_multiplayer,
+ m_setup,
+ m_net,
+ m_options,
+ m_video,
+ m_keys,
+ m_help,
+ m_quit,
+ m_lanconfig,
+ m_gameoptions,
+ m_search,
+ m_slist
+};
+
extern int m_activenet;
extern int m_return_state;
-extern int m_state;
+extern enum m_state_e m_state;
extern qboolean m_return_onerror;
extern char m_return_reason[32];
extern rtexture_t *r_notexture;
extern texture_t r_notexture_mip;
+struct model_s;
extern void Mod_LoadBrushModel (struct model_s *mod, void *buffer);
extern void Mod_BrushInit(void);
For savegames
=============
*/
-void ED_Write (FILE *f, edict_t *ed)
+void ED_Write (QFile *f, edict_t *ed)
{
ddef_t *d;
int *v;
char *name;
int type;
- fprintf (f, "{\n");
+ Qprintf (f, "{\n");
if (ed->free)
{
- fprintf (f, "}\n");
+ Qprintf (f, "}\n");
return;
}
if (j == type_size[type])
continue;
- fprintf (f,"\"%s\" ",name);
- fprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
+ Qprintf (f,"\"%s\" ",name);
+ Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
}
- fprintf (f, "}\n");
+ Qprintf (f, "}\n");
}
void ED_PrintNum (int ent)
ED_WriteGlobals
=============
*/
-void ED_WriteGlobals (FILE *f)
+void ED_WriteGlobals (QFile *f)
{
ddef_t *def;
int i;
char *name;
int type;
- fprintf (f,"{\n");
+ Qprintf (f,"{\n");
for (i=0 ; i<progs->numglobaldefs ; i++)
{
def = &pr_globaldefs[i];
continue;
name = pr_strings + def->s_name;
- fprintf (f,"\"%s\" ", name);
- fprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
+ Qprintf (f,"\"%s\" ", name);
+ Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
}
- fprintf (f,"}\n");
+ Qprintf (f,"}\n");
}
/*
// returns a copy of the string allocated from the server's string heap
void ED_Print (edict_t *ed);
-void ED_Write (FILE *f, edict_t *ed);
+void ED_Write (QFile *f, edict_t *ed);
char *ED_ParseEdict (char *data, edict_t *ent);
-void ED_WriteGlobals (FILE *f);
+void ED_WriteGlobals (QFile *f);
void ED_ParseGlobals (char *data);
void ED_LoadFromFile (char *data);
}
return buf;
}
-
-int
-Qgetpos (QFile *file, fpos_t * pos)
-{
-#ifdef HAVE_FPOS_T_STRUCT
- pos->__pos = Qtell (file);
- return pos->__pos == -1 ? -1 : 0;
-#else
- *pos = Qtell (file);
- return *pos == -1 ? -1 : 0;
-#endif
-}
-
-int
-Qsetpos (QFile *file, fpos_t * pos)
-{
-#ifdef HAVE_FPOS_T_STRUCT
- return Qseek (file, pos->__pos, 0);
-#else
- return Qseek (file, *pos, 0);
-#endif
-}
int Qflush(QFile *file);
int Qeof(QFile *file);
char *Qgetline(QFile *file);
-int Qgetpos(QFile *file, fpos_t *pos);
-int Qsetpos(QFile *file, fpos_t *pos);
#endif /*__quakeio_h*/
void R_ReadPointFile_f (void)
{
- FILE *f;
+ QFile *f;
vec3_t org;
int r;
int c;
sprintf (name,"maps/%s.pts", sv.name);
- COM_FOpenFile (name, &f, false);
+ COM_FOpenFile (name, &f, false, true);
if (!f)
{
Con_Printf ("couldn't open %s\n", name);
c = 0;
for (;;)
{
- r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
+ char *str = Qgetline (f);
+ r = sscanf (str,"%f %f %f\n", &org[0], &org[1], &org[2]);
if (r != 3)
break;
c++;
particle(pt_static, (-c)&15, particletexture, TPOLYTYPE_ALPHA, false, 2, 255, 99999, 0, org[0], org[1], org[2], 0, 0, 0);
}
- fclose (f);
+ Qclose (f);
Con_Printf ("%i points read\n", c);
}
switch (mmap_control->status.status) {
case SND_PCM_STATUS_PREPARED:
if ((rc=snd_pcm_channel_go(pcm_handle, SND_PCM_CHANNEL_PLAYBACK))<0) {
- fprintf(stderr, "unable to start playback. %s\n",
+ Qprintf(stderr, "unable to start playback. %s\n",
snd_strerror(rc));
exit(1);
}
break;
case SND_PCM_STATUS_UNDERRUN:
if ((rc=snd_pcm_plugin_prepare(pcm_handle, SND_PCM_CHANNEL_PLAYBACK))<0) {
- fprintf(stderr, "underrun: playback channel prepare error. %s\n",
+ Qprintf(stderr, "underrun: playback channel prepare error. %s\n",
snd_strerror(rc));
exit(1);
}
return 0;
}
// shm->samplepos = (count.bytes / (shm->samplebits / 8)) & (shm->samples-1);
-// fprintf(stderr, "%d \r", count.ptr);
+// Qprintf(stderr, "%d \r", count.ptr);
shm->samplepos = count.ptr / (shm->samplebits / 8);
return shm->samplepos;
va_start (argptr,fmt);
vsprintf (text,fmt,argptr);
va_end (argptr);
- fprintf(stderr, "%s", text);
+ Qprintf(stderr, "%s", text);
Con_Print (text);
}
/*
===============================================================================
-FILE IO
+QFile IO
===============================================================================
*/
// LordHavoc: 256 pak files (was 10)
#define MAX_HANDLES 256
-FILE *sys_handles[MAX_HANDLES];
+QFile *sys_handles[MAX_HANDLES];
int findhandle (void)
{
filelength
================
*/
-int filelength (FILE *f)
+int filelength (QFile *f)
{
int pos;
int end;
- pos = ftell (f);
- fseek (f, 0, SEEK_END);
- end = ftell (f);
- fseek (f, pos, SEEK_SET);
+ pos = Qtell (f);
+ Qseek (f, 0, SEEK_END);
+ end = Qtell (f);
+ Qseek (f, pos, SEEK_SET);
return end;
}
int Sys_FileOpenRead (char *path, int *hndl)
{
- FILE *f;
+ QFile *f;
int i, retval;
i = findhandle ();
- f = fopen(path, "rb");
+ f = Qopen(path, "rbz");
if (!f)
{
int Sys_FileOpenWrite (char *path)
{
- FILE *f;
+ QFile *f;
int i;
i = findhandle ();
- f = fopen(path, "wb");
+ f = Qopen(path, "wb");
if (!f)
Host_Error ("Error opening %s: %s", path,strerror(errno));
sys_handles[i] = f;
void Sys_FileClose (int handle)
{
- fclose (sys_handles[handle]);
+ Qclose (sys_handles[handle]);
sys_handles[handle] = NULL;
}
void Sys_FileSeek (int handle, int position)
{
- fseek (sys_handles[handle], position, SEEK_SET);
+ Qseek (sys_handles[handle], position, SEEK_SET);
}
int Sys_FileRead (int handle, void *dest, int count)
{
- return fread (dest, 1, count, sys_handles[handle]);
+ return Qread (dest, 1, count, sys_handles[handle]);
}
int Sys_FileWrite (int handle, void *data, int count)
{
- return fwrite (data, 1, count, sys_handles[handle]);
+ return Qwrite (data, 1, count, sys_handles[handle]);
}
int Sys_FileTime (char *path)
{
- FILE *f;
+ QFile *f;
- f = fopen(path, "rb");
+ f = Qopen(path, "rb");
if (f)
{
- fclose(f);
+ Qclose(f);
return 1;
}
typedef struct
{
char name[16];
- FILE *file;
+ QFile *file;
int position;
int size;
} texwadlump_t;
wadinfo_t header;
unsigned i, j;
int infotableofs;
- FILE *file;
+ QFile *file;
int numlumps;
- COM_FOpenFile (filename, &file, false);
+ COM_FOpenFile (filename, &file, false, true);
if (!file)
{
if (complain)
return;
}
- if (fread(&header, sizeof(wadinfo_t), 1, file) != 1)
+ if (Qread(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t))
{Con_Printf ("W_LoadTextureWadFile: unable to read wad header");return;}
if(header.identification[0] != 'W'
if (numlumps < 1 || numlumps > TEXWAD_MAXIMAGES)
{Con_Printf ("W_LoadTextureWadFile: invalid number of lumps (%i)\n", numlumps);return;}
infotableofs = LittleLong(header.infotableofs);
- if (fseek(file, infotableofs, SEEK_SET))
+ if (Qseek(file, infotableofs, SEEK_SET))
{Con_Printf ("W_LoadTextureWadFile: unable to seek to lump table");return;}
if (!(lumps = qmalloc(sizeof(lumpinfo_t)*numlumps)))
{Con_Printf ("W_LoadTextureWadFile: unable to allocate temporary memory for lump table");return;}
- if (fread(lumps, sizeof(lumpinfo_t), numlumps, file) != numlumps)
+ if (Qread(file, lumps, sizeof(lumpinfo_t) * numlumps) != sizeof(lumpinfo_t) * numlumps)
{Con_Printf ("W_LoadTextureWadFile: unable to read lump table");return;}
for (i=0, lump_p = lumps ; i<numlumps ; i++,lump_p++)
// byte pal[256][3], *indata, *outdata, *data;
char texname[17];
int i, j;
- FILE *file;
+ QFile *file;
miptex_t *tex;
byte *data;
texname[16] = 0;
if (!strcmp(texname, texwadlump[i].name)) // found it
{
file = texwadlump[i].file;
- if (fseek(file, texwadlump[i].position, SEEK_SET))
+ if (Qseek(file, texwadlump[i].position, SEEK_SET))
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
tex = qmalloc(texwadlump[i].size);
if (!tex)
return NULL;
- if (fread(tex, 1, texwadlump[i].size, file) < texwadlump[i].size)
+ if (Qread(file, tex, texwadlump[i].size) < texwadlump[i].size)
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
tex->width = LittleLong(tex->width);
indata = outdata + image_width*image_height*3;
datasize = image_width*image_height*85/64;
// read the image data
- if (fseek(file, texwadlump[i].position + sizeof(t), SEEK_SET))
+ if (Qseek(file, texwadlump[i].position + sizeof(t), SEEK_SET))
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
- if (fread(indata, 1, image_width*image_height, file) != image_width*image_height)
+ if (Qread(file, indata, image_width*image_height) != image_width*image_height)
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
// read the number of colors used (always 256)
- if (fseek(file, texwadlump[i].position + sizeof(t) + datasize, SEEK_SET))
+ if (Qseek(file, texwadlump[i].position + sizeof(t) + datasize, SEEK_SET))
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
- if (fread(&colorcount, 2, 1, file) != 1)
+ if (Qread(file, &colorcount, 2) != 2)
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
if (texwadlump[i].size > (datasize + sizeof(t)))
{
if (colorcount < 0) colorcount = 0;
if (colorcount > 256) colorcount = 256;
// read the palette
- // fseek(file, texwadlump[i].position + sizeof(t) + datasize + 2, SEEK_SET);
- if (fread(&pal, 3, colorcount, file) != colorcount)
+ // Qseek(file, texwadlump[i].position + sizeof(t) + datasize + 2, SEEK_SET);
+ if (Qread(file, &pal, 3 * colorcount) != 3 * colorcount)
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
}
else