X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=common.h;h=c772fef8ee1acce7020575ad1903098f66bd3db0;hb=95b881bd92f57e84a2fb4c8d52ca7cd84f04cb02;hp=eb2175cdf6ca98ed1e5787949a59e32f3f927a80;hpb=8dcce44300385b12c46d494c06aadcfa35a8bc14;p=xonotic%2Fdarkplaces.git diff --git a/common.h b/common.h index eb2175cd..c772fef8 100644 --- a/common.h +++ b/common.h @@ -29,6 +29,18 @@ typedef unsigned char byte; typedef enum {false, true} qboolean; +#include "quakeio.h" + +// LordHavoc: MSVC has a different name for snprintf +#ifndef snprintf +#define snprintf _snprintf +#endif + +//============================================================================ + +extern void *qmalloc(unsigned int size); +extern void qfree(void *mem); + //============================================================================ typedef struct sizebuf_s @@ -49,58 +61,47 @@ void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf //============================================================================ -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! -#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m))) - -//============================================================================ - #ifndef NULL #define NULL ((void *)0) #endif -#define Q_MAXCHAR ((char)0x7f) -#define Q_MAXSHORT ((short)0x7fff) -#define Q_MAXINT ((int)0x7fffffff) -#define Q_MAXLONG ((int)0x7fffffff) -#define Q_MAXFLOAT ((int)0x7fffffff) - -#define Q_MINCHAR ((char)0x80) -#define Q_MINSHORT ((short)0x8000) -#define Q_MININT ((int)0x80000000) -#define Q_MINLONG ((int)0x80000000) -#define Q_MINFLOAT ((int)0x7fffffff) - //============================================================================ -#ifdef WIN32 -short ShortSwap (short l); -int LongSwap (int l); +#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG) +#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || (defined(__alpha__) || defined(__alpha)) || defined(__arm__) || (defined(__mips__) && defined(__MIPSEL__)) || defined(__LITTLE_ENDIAN__) +#define ENDIAN_LITTLE +#else +#define ENDIAN_BIG +#endif +#endif + +short ShortSwap (short l); +int LongSwap (int l); float FloatSwap (float f); + +#ifdef ENDIAN_LITTLE +// little endian #define BigShort(l) ShortSwap(l) #define LittleShort(l) (l) #define BigLong(l) LongSwap(l) #define LittleLong(l) (l) #define BigFloat(l) FloatSwap(l) #define LittleFloat(l) (l) +#elif ENDIAN_BIG +// big endian +#define BigShort(l) (l) +#define LittleShort(l) ShortSwap(l) +#define BigLong(l) (l) +#define LittleLong(l) LongSwap(l) +#define BigFloat(l) (l) +#define LittleFloat(l) FloatSwap(l) #else -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); +// figure it out at runtime +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); #endif //============================================================================ @@ -113,6 +114,9 @@ void MSG_WriteFloat (sizebuf_t *sb, float f); void MSG_WriteString (sizebuf_t *sb, char *s); void MSG_WriteCoord (sizebuf_t *sb, float f); void MSG_WriteAngle (sizebuf_t *sb, float f); +void MSG_WritePreciseAngle (sizebuf_t *sb, float f); + +#define MSG_WriteFloatCoord MSG_WriteFloat extern int msg_readcount; extern qboolean msg_badread; // set if a read goes beyond end of message @@ -130,11 +134,17 @@ char *MSG_ReadString (void); //#define MSG_ReadShort() ((msg_readcount + 2) > net_message.cursize ? (msg_badread = true, -1) : (short)net_message.data[msg_readcount+=2, msg_readcount-2] | (net_message.data[msg_readcount-1] << 8)) //#define MSG_ReadLong() ((msg_readcount + 4) > net_message.cursize ? (msg_badread = true, -1) : (int)net_message.data[msg_readcount+=4, msg_readcount-4] | (net_message.data[msg_readcount-3] << 8) | (net_message.data[msg_readcount-2] << 16) | (net_message.data[msg_readcount-1] << 24)) -//float MSG_ReadCoord (void); +float MSG_ReadCoord (void); //float MSG_ReadAngle (void); +#define MSG_ReadFloatCoord MSG_ReadFloat + #define MSG_ReadAngle() (MSG_ReadByte() * (360.0f / 256.0f)) -#define MSG_ReadCoord() (MSG_ReadShort() * 0.125f) +#define MSG_ReadPreciseAngle() (MSG_ReadShort() * (360.0f / 65536.0f)) + +#define MSG_ReadVector(v) {(v)[0] = MSG_ReadCoord();(v)[1] = MSG_ReadCoord();(v)[2] = MSG_ReadCoord();} + +extern qboolean dpprotocol; //============================================================================ @@ -189,14 +199,13 @@ struct cache_user_s; 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_LoadStackFile (char *path, void *buffer, int bufsize, qboolean quiet); -byte *COM_LoadTempFile (char *path, qboolean quiet); +// set by COM_LoadFile functions +extern int loadsize; byte *COM_LoadHunkFile (char *path, qboolean quiet); -void COM_LoadCacheFile (char *path, struct cache_user_s *cu, qboolean quiet); +byte *COM_LoadMallocFile (char *path, qboolean quiet); +//void COM_LoadCacheFile (char *path, struct cache_user_s *cu, qboolean quiet); byte *COM_LoadFile (char *path, int usehunk, qboolean quiet); @@ -205,3 +214,7 @@ int COM_FileExists(char *filename); extern struct cvar_s registered; extern qboolean standard_quake, rogue, hipnotic, nehahra; + +// LordHavoc: useful... +extern void COM_ToLowerString(char *in, char *out); +extern void COM_ToUpperString(char *in, char *out);