2010-02-15 23:26:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-2001 Id Software, Inc.
|
|
|
|
Copyright (C) 2002-2009 John Fitzgibbons and others
|
2014-09-22 08:55:46 +00:00
|
|
|
Copyright (C) 2010-2014 QuakeSpasm developers
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
bspfile.h, cdaudio.h, client.h, cmd.h, common.h, console.h, crc.h, cvar.h,
d_ifacea.h, draw.h, gl_texmgr.h, glquake.h, image.h, input.h, keys.h, mathlib.h,
menu.h, modelgen.h, net.h, net_dgrm.h, net_loop.h, net_sdlnet.h, net_udp.h,
net_wins.h, platform.h, pr_comp.h, progdefs.h, progs.h, protocol.h, quakedef.h,
render.h, resource.h, sbar.h, screen.h, server.h, sound.h, spritegn.h, sys.h,
vid.h, view.h, wad.h, world.h, zone.h: added include guards to the headers.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@84 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-21 00:01:08 +00:00
|
|
|
|
|
|
|
#ifndef _Q_COMMON_H
|
|
|
|
#define _Q_COMMON_H
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
// comndef.h -- general definitions
|
|
|
|
|
2010-08-20 02:25:22 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning(disable:4244)
|
|
|
|
/* 'argument' : conversion from 'type1' to 'type2',
|
|
|
|
possible loss of data */
|
|
|
|
# pragma warning(disable:4305)
|
|
|
|
/* 'identifier' : truncation from 'type1' to 'type2' */
|
|
|
|
/* in our case, truncation from 'double' to 'float' */
|
|
|
|
# pragma warning(disable:4267)
|
|
|
|
/* 'var' : conversion from 'size_t' to 'type',
|
|
|
|
possible loss of data (/Wp64 warning) */
|
|
|
|
#endif /* _MSC_VER */
|
|
|
|
#endif /* _WIN32 */
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-01-10 10:35:40 +00:00
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
#define q_min(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#define q_max(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#define CLAMP(_minval, x, _maxval) \
|
|
|
|
((x) < (_minval) ? (_minval) : \
|
|
|
|
(x) > (_maxval) ? (_maxval) : (x))
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
typedef struct sizebuf_s
|
|
|
|
{
|
|
|
|
qboolean allowoverflow; // if false, do a Sys_Error
|
|
|
|
qboolean overflowed; // set to true if the buffer size failed
|
2010-08-29 02:22:55 +00:00
|
|
|
byte *data;
|
2010-02-15 23:26:55 +00:00
|
|
|
int maxsize;
|
|
|
|
int cursize;
|
|
|
|
} sizebuf_t;
|
|
|
|
|
|
|
|
void SZ_Alloc (sizebuf_t *buf, int startsize);
|
|
|
|
void SZ_Free (sizebuf_t *buf);
|
|
|
|
void SZ_Clear (sizebuf_t *buf);
|
|
|
|
void *SZ_GetSpace (sizebuf_t *buf, int length);
|
2010-08-29 02:22:55 +00:00
|
|
|
void SZ_Write (sizebuf_t *buf, const void *data, int length);
|
|
|
|
void SZ_Print (sizebuf_t *buf, const char *data); // strcats onto the sizebuf
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
typedef struct link_s
|
|
|
|
{
|
|
|
|
struct link_s *prev, *next;
|
|
|
|
} link_t;
|
|
|
|
|
|
|
|
|
|
|
|
void ClearLink (link_t *l);
|
|
|
|
void RemoveLink (link_t *l);
|
|
|
|
void InsertLinkBefore (link_t *l, link_t *before);
|
|
|
|
void InsertLinkAfter (link_t *l, link_t *after);
|
|
|
|
|
|
|
|
// (type *)STRUCT_FROM_LINK(link_t *link, type, member)
|
|
|
|
// ent = STRUCT_FROM_LINK(link,entity_t,order)
|
|
|
|
// FIXME: remove this mess!
|
2011-04-01 14:55:45 +00:00
|
|
|
#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (intptr_t)&(((t *)0)->m)))
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2011-06-12 12:25:22 +00:00
|
|
|
extern qboolean host_bigendian;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
extern short (*BigShort) (short l);
|
|
|
|
extern short (*LittleShort) (short l);
|
|
|
|
extern int (*BigLong) (int l);
|
|
|
|
extern int (*LittleLong) (int l);
|
|
|
|
extern float (*BigFloat) (float l);
|
|
|
|
extern float (*LittleFloat) (float l);
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
void MSG_WriteChar (sizebuf_t *sb, int c);
|
|
|
|
void MSG_WriteByte (sizebuf_t *sb, int c);
|
|
|
|
void MSG_WriteShort (sizebuf_t *sb, int c);
|
|
|
|
void MSG_WriteLong (sizebuf_t *sb, int c);
|
|
|
|
void MSG_WriteFloat (sizebuf_t *sb, float f);
|
2010-08-29 02:22:55 +00:00
|
|
|
void MSG_WriteString (sizebuf_t *sb, const char *s);
|
2010-02-15 23:26:55 +00:00
|
|
|
void MSG_WriteCoord (sizebuf_t *sb, float f);
|
|
|
|
void MSG_WriteAngle (sizebuf_t *sb, float f);
|
|
|
|
void MSG_WriteAngle16 (sizebuf_t *sb, float f); //johnfitz
|
|
|
|
|
|
|
|
extern int msg_readcount;
|
|
|
|
extern qboolean msg_badread; // set if a read goes beyond end of message
|
|
|
|
|
|
|
|
void MSG_BeginReading (void);
|
|
|
|
int MSG_ReadChar (void);
|
|
|
|
int MSG_ReadByte (void);
|
|
|
|
int MSG_ReadShort (void);
|
|
|
|
int MSG_ReadLong (void);
|
|
|
|
float MSG_ReadFloat (void);
|
2010-08-29 02:22:55 +00:00
|
|
|
const char *MSG_ReadString (void);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
float MSG_ReadCoord (void);
|
|
|
|
float MSG_ReadAngle (void);
|
|
|
|
float MSG_ReadAngle16 (void); //johnfitz
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2010-02-16 21:22:20 +00:00
|
|
|
void Q_memset (void *dest, int fill, size_t count);
|
|
|
|
void Q_memcpy (void *dest, const void *src, size_t count);
|
|
|
|
int Q_memcmp (const void *m1, const void *m2, size_t count);
|
2010-02-16 13:02:22 +00:00
|
|
|
void Q_strcpy (char *dest, const char *src);
|
|
|
|
void Q_strncpy (char *dest, const char *src, int count);
|
|
|
|
int Q_strlen (const char *str);
|
|
|
|
char *Q_strrchr (const char *s, char c);
|
|
|
|
void Q_strcat (char *dest, const char *src);
|
|
|
|
int Q_strcmp (const char *s1, const char *s2);
|
|
|
|
int Q_strncmp (const char *s1, const char *s2, int count);
|
|
|
|
int Q_atoi (const char *str);
|
|
|
|
float Q_atof (const char *str);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-27 11:03:39 +00:00
|
|
|
|
|
|
|
#include "strl_fn.h"
|
|
|
|
|
2013-09-25 17:01:40 +00:00
|
|
|
/* locale-insensitive strcasecmp replacement functions: */
|
|
|
|
extern int q_strcasecmp (const char * s1, const char * s2);
|
|
|
|
extern int q_strncasecmp (const char *s1, const char *s2, size_t n);
|
2010-08-31 14:09:00 +00:00
|
|
|
|
2013-09-25 17:01:40 +00:00
|
|
|
/* locale-insensitive strlwr/upr replacement functions: */
|
|
|
|
extern char *q_strlwr (char *str);
|
|
|
|
extern char *q_strupr (char *str);
|
|
|
|
|
|
|
|
/* snprintf, vsnprintf : always use our versions. */
|
2010-08-31 14:09:00 +00:00
|
|
|
extern int q_snprintf (char *str, size_t size, const char *format, ...) __attribute__((__format__(__printf__,3,4)));
|
|
|
|
extern int q_vsnprintf(char *str, size_t size, const char *format, va_list args)
|
|
|
|
__attribute__((__format__(__printf__,3,0)));
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
extern char com_token[1024];
|
|
|
|
extern qboolean com_eof;
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
const char *COM_Parse (const char *data);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern int com_argc;
|
|
|
|
extern char **com_argv;
|
|
|
|
|
2010-08-29 12:55:41 +00:00
|
|
|
extern int safemode;
|
|
|
|
/* safe mode: in true, the engine will behave as if one
|
|
|
|
of these arguments were actually on the command line:
|
|
|
|
-nosound, -nocdaudio, -nomidi, -stdvid, -dibonly,
|
|
|
|
-nomouse, -nojoy, -nolan
|
|
|
|
*/
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int COM_CheckParm (const char *parm);
|
2011-12-29 15:10:18 +00:00
|
|
|
|
2011-04-19 16:41:45 +00:00
|
|
|
void COM_Init (void);
|
2010-02-15 23:26:55 +00:00
|
|
|
void COM_InitArgv (int argc, char **argv);
|
2011-12-29 15:10:18 +00:00
|
|
|
void COM_InitFilesystem (void);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
const char *COM_SkipPath (const char *pathname);
|
2011-12-27 08:04:02 +00:00
|
|
|
void COM_StripExtension (const char *in, char *out, size_t outsize);
|
|
|
|
void COM_FileBase (const char *in, char *out, size_t outsize);
|
2014-04-26 07:50:54 +00:00
|
|
|
void COM_AddExtension (char *path, const char *extension, size_t len);
|
2014-04-27 08:33:05 +00:00
|
|
|
#if 0 /* COM_DefaultExtension can be dangerous */
|
2011-12-27 08:04:02 +00:00
|
|
|
void COM_DefaultExtension (char *path, const char *extension, size_t len);
|
2014-04-27 08:33:05 +00:00
|
|
|
#endif
|
2011-12-27 14:00:33 +00:00
|
|
|
const char *COM_FileGetExtension (const char *in); /* doesn't return NULL */
|
|
|
|
void COM_ExtractExtension (const char *in, char *out, size_t outsize);
|
chase.c, cl_input.c, cl_parse.c, client.h, common.c, common.h, console.h,
cvar.h, draw.h, gl_draw.c, gl_fog.c, gl_mesh.c, gl_model.c, gl_model.h,
gl_rmain.c, gl_rmisc.c, gl_screen.c, gl_sky.c, gl_texmgr.c, glquake.h,
host.c, keys.c, keys.h, main.c, menu.c, menu.h, pr_cmds.c, quakedef.h,
r_alias.c, r_brush.c, r_part.c, r_sprite.c, r_world.c, sbar.c, sbar.h,
screen.h, snd_dma.c, snd_mem.c, snd_mix.c, sv_main.c, sys_sdl.c, vid.h,
view.h, world.c, world.h: Loads of warning fixes about missing function
prototypes, missing parens around &, missing braces leading to ambiguous
else statements and unused and uninitialized variables. There are still a
couple of unitialised variables here and there, but not much. The warnings
about strict aliasing violations need taking care of.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@21 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-16 12:01:07 +00:00
|
|
|
void COM_CreatePath (char *path);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
Constified Con_DebugLog, Con_Print, Con_Printf, Con_Warning, Con_DPrintf,
Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, Con_LogCenterPrint,
Con_NotifyBox, PL_ErrorDialog, PR_RunError, Host_EndGame, Host_Error,
SV_ClientPrintf, SV_BroadcastPrintf, Host_ClientCommands, Sys_DebugLog,
Sys_Error, Sys_Printf, BOPS_Error and va. Added noreturn attribute to
Sys_Error, Sys_Quit, BOPS_Error, PR_RunError, Host_EndGame and Host_Error.
Added format printf attribute to Con_DebugLog, Con_Printf, Con_Warning,
Con_DPrintf, Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, PL_ErrorDialog,
PR_RunError, Host_EndGame, Host_Error, SV_ClientPrintf, SV_BroadcastPrintf,
Host_ClientCommands, Sys_DebugLog, Sys_Error, Sys_Printf and va. Adjusted
Host_Status_f and NET_Ban_f for the new attributes. Fixed broken format
strings in Con_Dump_f, Mod_LoadTexinfo, PR_AllocStringSlots and FloorDivMod.
Defined __attribute__ macros in quakedef.h so that we don't break non-gcc
compilers.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@154 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-04-26 16:30:40 +00:00
|
|
|
char *va (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
|
2010-02-15 23:26:55 +00:00
|
|
|
// does a varargs printf into a temp buffer
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2014-09-08 21:10:33 +00:00
|
|
|
// QUAKEFS
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char name[MAX_QPATH];
|
|
|
|
int filepos, filelen;
|
|
|
|
} packfile_t;
|
|
|
|
|
|
|
|
typedef struct pack_s
|
|
|
|
{
|
|
|
|
char filename[MAX_OSPATH];
|
|
|
|
int handle;
|
|
|
|
int numfiles;
|
|
|
|
packfile_t *files;
|
|
|
|
} pack_t;
|
|
|
|
|
|
|
|
typedef struct searchpath_s
|
|
|
|
{
|
|
|
|
unsigned int path_id; // identifier assigned to the game directory
|
|
|
|
// Note that <install_dir>/game1 and
|
|
|
|
// <userdir>/game1 have the same id.
|
|
|
|
char filename[MAX_OSPATH];
|
|
|
|
pack_t *pack; // only one of filename / pack will be used
|
|
|
|
struct searchpath_s *next;
|
|
|
|
} searchpath_t;
|
|
|
|
|
|
|
|
extern searchpath_t *com_searchpaths;
|
|
|
|
extern searchpath_t *com_base_searchpaths;
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
extern int com_filesize;
|
|
|
|
struct cache_user_s;
|
|
|
|
|
2010-03-01 11:55:13 +00:00
|
|
|
extern char com_basedir[MAX_OSPATH];
|
2010-02-15 23:26:55 +00:00
|
|
|
extern char com_gamedir[MAX_OSPATH];
|
2010-12-30 16:35:16 +00:00
|
|
|
extern int file_from_pak; // global indicating that file came from a pak
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
void COM_WriteFile (const char *filename, const void *data, int len);
|
2011-01-02 21:45:16 +00:00
|
|
|
int COM_OpenFile (const char *filename, int *handle, unsigned int *path_id);
|
|
|
|
int COM_FOpenFile (const char *filename, FILE **file, unsigned int *path_id);
|
2011-02-10 17:25:43 +00:00
|
|
|
qboolean COM_FileExists (const char *filename, unsigned int *path_id);
|
2010-02-15 23:26:55 +00:00
|
|
|
void COM_CloseFile (int h);
|
|
|
|
|
2010-12-31 10:29:38 +00:00
|
|
|
// these procedures open a file using COM_FindFile and loads it into a proper
|
|
|
|
// buffer. the buffer is allocated with a total size of com_filesize + 1. the
|
|
|
|
// procedures differ by their buffer allocation method.
|
2011-01-02 21:45:16 +00:00
|
|
|
byte *COM_LoadStackFile (const char *path, void *buffer, int bufsize,
|
|
|
|
unsigned int *path_id);
|
2010-12-31 10:29:38 +00:00
|
|
|
// uses the specified stack stack buffer with the specified size
|
|
|
|
// of bufsize. if bufsize is too short, uses temp hunk. the bufsize
|
|
|
|
// must include the +1
|
2011-01-02 21:45:16 +00:00
|
|
|
byte *COM_LoadTempFile (const char *path, unsigned int *path_id);
|
2010-12-31 10:29:38 +00:00
|
|
|
// allocates the buffer on the temp hunk.
|
2011-01-02 21:45:16 +00:00
|
|
|
byte *COM_LoadHunkFile (const char *path, unsigned int *path_id);
|
2010-12-31 10:29:38 +00:00
|
|
|
// allocates the buffer on the hunk.
|
2011-01-02 21:45:16 +00:00
|
|
|
byte *COM_LoadZoneFile (const char *path, unsigned int *path_id);
|
2010-12-31 10:29:38 +00:00
|
|
|
// allocates the buffer on the zone.
|
2011-01-02 21:45:16 +00:00
|
|
|
void COM_LoadCacheFile (const char *path, struct cache_user_s *cu,
|
|
|
|
unsigned int *path_id);
|
2010-12-31 10:29:38 +00:00
|
|
|
// uses cache mem for allocating the buffer.
|
2011-01-02 21:45:16 +00:00
|
|
|
byte *COM_LoadMallocFile (const char *path, unsigned int *path_id);
|
2010-12-31 10:29:38 +00:00
|
|
|
// allocates the buffer on the system mem (malloc).
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-12-30 16:50:15 +00:00
|
|
|
/* The following FS_*() stdio replacements are necessary if one is
|
|
|
|
* to perform non-sequential reads on files reopened on pak files
|
|
|
|
* because we need the bookkeeping about file start/end positions.
|
|
|
|
* Allocating and filling in the fshandle_t structure is the users'
|
|
|
|
* responsibility when the file is initially opened. */
|
|
|
|
|
|
|
|
typedef struct _fshandle_t
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
qboolean pak; /* is the file read from a pak */
|
|
|
|
long start; /* file or data start position */
|
|
|
|
long length; /* file or data size */
|
|
|
|
long pos; /* current position relative to start */
|
|
|
|
} fshandle_t;
|
|
|
|
|
|
|
|
size_t FS_fread(void *ptr, size_t size, size_t nmemb, fshandle_t *fh);
|
|
|
|
int FS_fseek(fshandle_t *fh, long offset, int whence);
|
|
|
|
long FS_ftell(fshandle_t *fh);
|
|
|
|
void FS_rewind(fshandle_t *fh);
|
|
|
|
int FS_feof(fshandle_t *fh);
|
|
|
|
int FS_ferror(fshandle_t *fh);
|
|
|
|
int FS_fclose(fshandle_t *fh);
|
2013-09-27 19:51:26 +00:00
|
|
|
int FS_fgetc(fshandle_t *fh);
|
2011-12-24 12:03:29 +00:00
|
|
|
char *FS_fgets(char *s, int size, fshandle_t *fh);
|
2013-09-25 11:01:12 +00:00
|
|
|
long FS_filelength (fshandle_t *fh);
|
2010-12-30 16:50:15 +00:00
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2013-09-27 19:51:26 +00:00
|
|
|
extern struct cvar_s registered;
|
2010-02-15 23:26:55 +00:00
|
|
|
extern qboolean standard_quake, rogue, hipnotic;
|
2010-02-18 11:45:18 +00:00
|
|
|
extern qboolean fitzmode;
|
2013-09-27 19:51:26 +00:00
|
|
|
/* if true, run in fitzquake mode disabling custom quakespasm hacks */
|
2010-02-18 11:45:18 +00:00
|
|
|
|
bspfile.h, cdaudio.h, client.h, cmd.h, common.h, console.h, crc.h, cvar.h,
d_ifacea.h, draw.h, gl_texmgr.h, glquake.h, image.h, input.h, keys.h, mathlib.h,
menu.h, modelgen.h, net.h, net_dgrm.h, net_loop.h, net_sdlnet.h, net_udp.h,
net_wins.h, platform.h, pr_comp.h, progdefs.h, progs.h, protocol.h, quakedef.h,
render.h, resource.h, sbar.h, screen.h, server.h, sound.h, spritegn.h, sys.h,
vid.h, view.h, wad.h, world.h, zone.h: added include guards to the headers.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@84 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-21 00:01:08 +00:00
|
|
|
#endif /* _Q_COMMON_H */
|
|
|
|
|