PageRenderTime 73ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/quake3/trunk/q3radiant/splines/q_shared.h

#
C Header | 798 lines | 491 code | 200 blank | 107 comment | 9 complexity | f039c9d46e769fcd77654fe5c7327496 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-3.0, AGPL-1.0, Unlicense
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #ifndef __Q_SHARED_H
  19. #define __Q_SHARED_H
  20. // q_shared.h -- included first by ALL program modules.
  21. // these are the definitions that have no dependance on
  22. // central system services, and can be used by any part
  23. // of the program without any state issues.
  24. // A user mod should never modify this file
  25. #define Q3_VERSION "DOOM 0.01"
  26. // alignment macros for SIMD
  27. #define ALIGN_ON
  28. #define ALIGN_OFF
  29. #ifdef _WIN32
  30. #pragma warning(disable : 4018) // signed/unsigned mismatch
  31. #pragma warning(disable : 4032)
  32. #pragma warning(disable : 4051)
  33. #pragma warning(disable : 4057) // slightly different base types
  34. #pragma warning(disable : 4100) // unreferenced formal parameter
  35. #pragma warning(disable : 4115)
  36. #pragma warning(disable : 4125) // decimal digit terminates octal escape sequence
  37. #pragma warning(disable : 4127) // conditional expression is constant
  38. #pragma warning(disable : 4136)
  39. #pragma warning(disable : 4201)
  40. #pragma warning(disable : 4214)
  41. #pragma warning(disable : 4244)
  42. #pragma warning(disable : 4305) // truncation from const double to float
  43. #pragma warning(disable : 4310) // cast truncates constant value
  44. #pragma warning(disable : 4514)
  45. #pragma warning(disable : 4711) // selected for automatic inline expansion
  46. #pragma warning(disable : 4220) // varargs matches remaining parameters
  47. #endif
  48. #include <assert.h>
  49. #include <math.h>
  50. #include <stdio.h>
  51. #include <stdarg.h>
  52. #include <string.h>
  53. #include <stdlib.h>
  54. #include <time.h>
  55. #include <ctype.h>
  56. #ifdef WIN32 // mac doesn't have malloc.h
  57. #include <malloc.h> // for _alloca()
  58. #endif
  59. #ifdef _WIN32
  60. //#pragma intrinsic( memset, memcpy )
  61. #endif
  62. // this is the define for determining if we have an asm version of a C function
  63. #if (defined _M_IX86 || defined __i386__) && !defined __sun__ && !defined __LCC__
  64. #define id386 1
  65. #else
  66. #define id386 0
  67. #endif
  68. // for windows fastcall option
  69. #define QDECL
  70. //======================= WIN32 DEFINES =================================
  71. #ifdef WIN32
  72. #define MAC_STATIC
  73. #undef QDECL
  74. #define QDECL __cdecl
  75. // buildstring will be incorporated into the version string
  76. #ifdef NDEBUG
  77. #ifdef _M_IX86
  78. #define CPUSTRING "win-x86"
  79. #elif defined _M_ALPHA
  80. #define CPUSTRING "win-AXP"
  81. #endif
  82. #else
  83. #ifdef _M_IX86
  84. #define CPUSTRING "win-x86-debug"
  85. #elif defined _M_ALPHA
  86. #define CPUSTRING "win-AXP-debug"
  87. #endif
  88. #endif
  89. #define PATH_SEP '\\'
  90. #endif
  91. //======================= MAC OS X SERVER DEFINES =====================
  92. #if defined(__MACH__) && defined(__APPLE__)
  93. #define MAC_STATIC
  94. #ifdef __ppc__
  95. #define CPUSTRING "MacOSXS-ppc"
  96. #elif defined __i386__
  97. #define CPUSTRING "MacOSXS-i386"
  98. #else
  99. #define CPUSTRING "MacOSXS-other"
  100. #endif
  101. #define PATH_SEP '/'
  102. #define GAME_HARD_LINKED
  103. #define CGAME_HARD_LINKED
  104. #define UI_HARD_LINKED
  105. #define _alloca alloca
  106. #undef ALIGN_ON
  107. #undef ALIGN_OFF
  108. #define ALIGN_ON #pragma align(16)
  109. #define ALIGN_OFF #pragma align()
  110. #ifdef __cplusplus
  111. extern "C" {
  112. #endif
  113. void *osxAllocateMemory(long size);
  114. void osxFreeMemory(void *pointer);
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif
  119. //======================= MAC DEFINES =================================
  120. #ifdef __MACOS__
  121. #define MAC_STATIC static
  122. #define CPUSTRING "MacOS-PPC"
  123. #define PATH_SEP ':'
  124. void Sys_PumpEvents( void );
  125. #endif
  126. #ifdef __MRC__
  127. #define MAC_STATIC
  128. #define CPUSTRING "MacOS-PPC"
  129. #define PATH_SEP ':'
  130. void Sys_PumpEvents( void );
  131. #undef QDECL
  132. #define QDECL __cdecl
  133. #define _alloca alloca
  134. #endif
  135. //======================= LINUX DEFINES =================================
  136. // the mac compiler can't handle >32k of locals, so we
  137. // just waste space and make big arrays static...
  138. #ifdef __linux__
  139. #define MAC_STATIC
  140. #ifdef __i386__
  141. #define CPUSTRING "linux-i386"
  142. #elif defined __axp__
  143. #define CPUSTRING "linux-alpha"
  144. #else
  145. #define CPUSTRING "linux-other"
  146. #endif
  147. #define PATH_SEP '/'
  148. #endif
  149. //=============================================================
  150. typedef enum {qfalse, qtrue} qboolean;
  151. typedef unsigned char byte;
  152. #define EQUAL_EPSILON 0.001
  153. typedef int qhandle_t;
  154. typedef int sfxHandle_t;
  155. typedef int fileHandle_t;
  156. typedef int clipHandle_t;
  157. typedef enum {
  158. INVALID_JOINT = -1
  159. } jointHandle_t;
  160. #ifndef NULL
  161. #define NULL ((void *)0)
  162. #endif
  163. #define MAX_QINT 0x7fffffff
  164. #define MIN_QINT (-MAX_QINT-1)
  165. #ifndef max
  166. #define max( x, y ) ( ( ( x ) > ( y ) ) ? ( x ) : ( y ) )
  167. #define min( x, y ) ( ( ( x ) < ( y ) ) ? ( x ) : ( y ) )
  168. #endif
  169. #ifndef sign
  170. #define sign( f ) ( ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 0 ) )
  171. #endif
  172. // angle indexes
  173. #define PITCH 0 // up / down
  174. #define YAW 1 // left / right
  175. #define ROLL 2 // fall over
  176. // the game guarantees that no string from the network will ever
  177. // exceed MAX_STRING_CHARS
  178. #define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
  179. #define MAX_STRING_TOKENS 256 // max tokens resulting from Cmd_TokenizeString
  180. #define MAX_TOKEN_CHARS 1024 // max length of an individual token
  181. #define MAX_INFO_STRING 1024
  182. #define MAX_INFO_KEY 1024
  183. #define MAX_INFO_VALUE 1024
  184. #define MAX_QPATH 64 // max length of a quake game pathname
  185. #define MAX_OSPATH 128 // max length of a filesystem pathname
  186. #define MAX_NAME_LENGTH 32 // max length of a client name
  187. // paramters for command buffer stuffing
  188. typedef enum {
  189. EXEC_NOW, // don't return until completed, a VM should NEVER use this,
  190. // because some commands might cause the VM to be unloaded...
  191. EXEC_INSERT, // insert at current position, but don't run yet
  192. EXEC_APPEND // add to end of the command buffer (normal case)
  193. } cbufExec_t;
  194. //
  195. // these aren't needed by any of the VMs. put in another header?
  196. //
  197. #define MAX_MAP_AREA_BYTES 32 // bit vector of area visibility
  198. #undef ERR_FATAL // malloc.h on unix
  199. // parameters to the main Error routine
  200. typedef enum {
  201. ERR_NONE,
  202. ERR_FATAL, // exit the entire game with a popup window
  203. ERR_DROP, // print to console and disconnect from game
  204. ERR_DISCONNECT, // don't kill server
  205. ERR_NEED_CD // pop up the need-cd dialog
  206. } errorParm_t;
  207. // font rendering values used by ui and cgame
  208. #define PROP_GAP_WIDTH 3
  209. #define PROP_SPACE_WIDTH 8
  210. #define PROP_HEIGHT 27
  211. #define PROP_SMALL_SIZE_SCALE 0.75
  212. #define BLINK_DIVISOR 200
  213. #define PULSE_DIVISOR 75
  214. #define UI_LEFT 0x00000000 // default
  215. #define UI_CENTER 0x00000001
  216. #define UI_RIGHT 0x00000002
  217. #define UI_FORMATMASK 0x00000007
  218. #define UI_SMALLFONT 0x00000010
  219. #define UI_BIGFONT 0x00000020 // default
  220. #define UI_GIANTFONT 0x00000040
  221. #define UI_DROPSHADOW 0x00000800
  222. #define UI_BLINK 0x00001000
  223. #define UI_INVERSE 0x00002000
  224. #define UI_PULSE 0x00004000
  225. /*
  226. ==============================================================
  227. MATHLIB
  228. ==============================================================
  229. */
  230. #ifdef __cplusplus // so we can include this in C code
  231. #define SIDE_FRONT 0
  232. #define SIDE_BACK 1
  233. #define SIDE_ON 2
  234. #define SIDE_CROSS 3
  235. #define Q_PI 3.14159265358979323846
  236. #ifndef M_PI
  237. #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
  238. #endif
  239. #include "math_vector.h"
  240. #include "math_angles.h"
  241. #include "math_matrix.h"
  242. #include "math_quaternion.h"
  243. class idVec3_t; // for defining vectors
  244. typedef idVec3_t &vec3_p; // for passing vectors as function arguments
  245. typedef const idVec3_t &vec3_c; // for passing vectors as const function arguments
  246. class angles_t; // for defining angle vectors
  247. typedef angles_t &angles_p; // for passing angles as function arguments
  248. typedef const angles_t &angles_c; // for passing angles as const function arguments
  249. class mat3_t; // for defining matrices
  250. typedef mat3_t &mat3_p; // for passing matrices as function arguments
  251. typedef const mat3_t &mat3_c; // for passing matrices as const function arguments
  252. #define NUMVERTEXNORMALS 162
  253. extern idVec3_t bytedirs[NUMVERTEXNORMALS];
  254. // all drawing is done to a 640*480 virtual screen size
  255. // and will be automatically scaled to the real resolution
  256. #define SCREEN_WIDTH 640
  257. #define SCREEN_HEIGHT 480
  258. #define TINYCHAR_WIDTH (SMALLCHAR_WIDTH)
  259. #define TINYCHAR_HEIGHT (SMALLCHAR_HEIGHT/2)
  260. #define SMALLCHAR_WIDTH 8
  261. #define SMALLCHAR_HEIGHT 16
  262. #define BIGCHAR_WIDTH 16
  263. #define BIGCHAR_HEIGHT 16
  264. #define GIANTCHAR_WIDTH 32
  265. #define GIANTCHAR_HEIGHT 48
  266. extern vec4_t colorBlack;
  267. extern vec4_t colorRed;
  268. extern vec4_t colorGreen;
  269. extern vec4_t colorBlue;
  270. extern vec4_t colorYellow;
  271. extern vec4_t colorMagenta;
  272. extern vec4_t colorCyan;
  273. extern vec4_t colorWhite;
  274. extern vec4_t colorLtGrey;
  275. extern vec4_t colorMdGrey;
  276. extern vec4_t colorDkGrey;
  277. #define Q_COLOR_ESCAPE '^'
  278. #define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE )
  279. #define COLOR_BLACK '0'
  280. #define COLOR_RED '1'
  281. #define COLOR_GREEN '2'
  282. #define COLOR_YELLOW '3'
  283. #define COLOR_BLUE '4'
  284. #define COLOR_CYAN '5'
  285. #define COLOR_MAGENTA '6'
  286. #define COLOR_WHITE '7'
  287. #define ColorIndex(c) ( ( (c) - '0' ) & 7 )
  288. #define S_COLOR_BLACK "^0"
  289. #define S_COLOR_RED "^1"
  290. #define S_COLOR_GREEN "^2"
  291. #define S_COLOR_YELLOW "^3"
  292. #define S_COLOR_BLUE "^4"
  293. #define S_COLOR_CYAN "^5"
  294. #define S_COLOR_MAGENTA "^6"
  295. #define S_COLOR_WHITE "^7"
  296. extern vec4_t g_color_table[8];
  297. #define MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
  298. #define MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
  299. #define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
  300. #define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
  301. struct cplane_s;
  302. extern idVec3_t vec3_origin;
  303. extern vec4_t vec4_origin;
  304. extern mat3_t axisDefault;
  305. #define nanmask (255<<23)
  306. #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
  307. float Q_fabs( float f );
  308. float Q_rsqrt( float f ); // reciprocal square root
  309. #define SQRTFAST( x ) ( 1.0f / Q_rsqrt( x ) )
  310. signed char ClampChar( int i );
  311. signed short ClampShort( int i );
  312. // this isn't a real cheap function to call!
  313. int DirToByte( const idVec3_t &dir );
  314. void ByteToDir( int b, vec3_p dir );
  315. #define DotProduct(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
  316. #define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
  317. #define VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
  318. #define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
  319. //#define VectorCopy(a,b) ((b).x=(a).x,(b).y=(a).y,(b).z=(a).z])
  320. #define VectorScale(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
  321. #define VectorMA(v, s, b, o) ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s))
  322. #define CrossProduct(a,b,c) ((c)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(c)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(c)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0])
  323. #define DotProduct4(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]+(x)[3]*(y)[3])
  324. #define VectorSubtract4(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2],(c)[3]=(a)[3]-(b)[3])
  325. #define VectorAdd4(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2],(c)[3]=(a)[3]+(b)[3])
  326. #define VectorCopy4(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
  327. #define VectorScale4(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s),(o)[3]=(v)[3]*(s))
  328. #define VectorMA4(v, s, b, o) ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s),(o)[3]=(v)[3]+(b)[3]*(s))
  329. #define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0)
  330. #define VectorNegate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
  331. #define VectorSet(v, x, y, z) ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
  332. #define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
  333. #define SnapVector(v) {v[0]=(int)v[0];v[1]=(int)v[1];v[2]=(int)v[2];}
  334. float NormalizeColor( vec3_c in, vec3_p out );
  335. int VectorCompare( vec3_c v1, vec3_c v2 );
  336. float VectorLength( vec3_c v );
  337. float Distance( vec3_c p1, vec3_c p2 );
  338. float DistanceSquared( vec3_c p1, vec3_c p2 );
  339. float VectorNormalize (vec3_p v); // returns vector length
  340. void VectorNormalizeFast(vec3_p v); // does NOT return vector length, uses rsqrt approximation
  341. float VectorNormalize2( vec3_c v, vec3_p out );
  342. void VectorInverse (vec3_p v);
  343. void VectorRotate( vec3_c in, mat3_c matrix, vec3_p out );
  344. void VectorPolar(vec3_p v, float radius, float theta, float phi);
  345. void VectorSnap(vec3_p v);
  346. void Vector53Copy( const idVec5_t &in, vec3_p out);
  347. void Vector5Scale( const idVec5_t &v, float scale, idVec5_t &out);
  348. void Vector5Add( const idVec5_t &va, const idVec5_t &vb, idVec5_t &out);
  349. void VectorRotate3( vec3_c vIn, vec3_c vRotation, vec3_p out);
  350. void VectorRotate3Origin(vec3_c vIn, vec3_c vRotation, vec3_c vOrigin, vec3_p out);
  351. int Q_log2(int val);
  352. int Q_rand( int *seed );
  353. float Q_random( int *seed );
  354. float Q_crandom( int *seed );
  355. #define random() ((rand () & 0x7fff) / ((float)0x7fff))
  356. #define crandom() (2.0 * (random() - 0.5))
  357. float Q_rint( float in );
  358. void vectoangles( vec3_c value1, angles_p angles);
  359. void AnglesToAxis( angles_c angles, mat3_p axis );
  360. void AxisCopy( mat3_c in, mat3_p out );
  361. qboolean AxisRotated( mat3_c in ); // assumes a non-degenerate axis
  362. int SignbitsForNormal( vec3_c normal );
  363. int BoxOnPlaneSide( const Bounds &b, struct cplane_s *p );
  364. float AngleMod(float a);
  365. float LerpAngle (float from, float to, float frac);
  366. float AngleSubtract( float a1, float a2 );
  367. void AnglesSubtract( angles_c v1, angles_c v2, angles_p v3 );
  368. float AngleNormalize360 ( float angle );
  369. float AngleNormalize180 ( float angle );
  370. float AngleDelta ( float angle1, float angle2 );
  371. qboolean PlaneFromPoints( vec4_t &plane, vec3_c a, vec3_c b, vec3_c c );
  372. void ProjectPointOnPlane( vec3_p dst, vec3_c p, vec3_c normal );
  373. void RotatePointAroundVector( vec3_p dst, vec3_c dir, vec3_c point, float degrees );
  374. void RotateAroundDirection( mat3_p axis, float yaw );
  375. void MakeNormalVectors( vec3_c forward, vec3_p right, vec3_p up );
  376. // perpendicular vector could be replaced by this
  377. int PlaneTypeForNormal( vec3_c normal );
  378. void MatrixMultiply( mat3_c in1, mat3_c in2, mat3_p out );
  379. void MatrixInverseMultiply( mat3_c in1, mat3_c in2, mat3_p out ); // in2 is transposed during multiply
  380. void MatrixTransformVector( vec3_c in, mat3_c matrix, vec3_p out );
  381. void MatrixProjectVector( vec3_c in, mat3_c matrix, vec3_p out ); // Places the vector into a new coordinate system.
  382. void AngleVectors( angles_c angles, vec3_p forward, vec3_p right, vec3_p up);
  383. void PerpendicularVector( vec3_p dst, vec3_c src );
  384. float TriangleArea( vec3_c a, vec3_c b, vec3_c c );
  385. #endif // __cplusplus
  386. //=============================================
  387. float Com_Clamp( float min, float max, float value );
  388. #define FILE_HASH_SIZE 1024
  389. int Com_HashString( const char *fname );
  390. char *Com_SkipPath( char *pathname );
  391. // it is ok for out == in
  392. void Com_StripExtension( const char *in, char *out );
  393. // "extension" should include the dot: ".map"
  394. void Com_DefaultExtension( char *path, int maxSize, const char *extension );
  395. int Com_ParseInfos( const char *buf, int max, char infos[][MAX_INFO_STRING] );
  396. /*
  397. =====================================================================================
  398. SCRIPT PARSING
  399. =====================================================================================
  400. */
  401. // this just controls the comment printing, it doesn't actually load a file
  402. void Com_BeginParseSession( const char *filename );
  403. void Com_EndParseSession( void );
  404. int Com_GetCurrentParseLine( void );
  405. // Will never return NULL, just empty strings.
  406. // An empty string will only be returned at end of file.
  407. // ParseOnLine will return empty if there isn't another token on this line
  408. // this funny typedef just means a moving pointer into a const char * buffer
  409. const char *Com_Parse( const char *(*data_p) );
  410. const char *Com_ParseOnLine( const char *(*data_p) );
  411. const char *Com_ParseRestOfLine( const char *(*data_p) );
  412. void Com_UngetToken( void );
  413. #ifdef __cplusplus
  414. void Com_MatchToken( const char *(*buf_p), const char *match, qboolean warning = qfalse );
  415. #else
  416. void Com_MatchToken( const char *(*buf_p), const char *match, qboolean warning );
  417. #endif
  418. void Com_ScriptError( const char *msg, ... );
  419. void Com_ScriptWarning( const char *msg, ... );
  420. void Com_SkipBracedSection( const char *(*program) );
  421. void Com_SkipRestOfLine( const char *(*data) );
  422. float Com_ParseFloat( const char *(*buf_p) );
  423. int Com_ParseInt( const char *(*buf_p) );
  424. void Com_Parse1DMatrix( const char *(*buf_p), int x, float *m );
  425. void Com_Parse2DMatrix( const char *(*buf_p), int y, int x, float *m );
  426. void Com_Parse3DMatrix( const char *(*buf_p), int z, int y, int x, float *m );
  427. //=====================================================================================
  428. #ifdef __cplusplus
  429. extern "C" {
  430. #endif
  431. void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...);
  432. // mode parm for FS_FOpenFile
  433. typedef enum {
  434. FS_READ,
  435. FS_WRITE,
  436. FS_APPEND,
  437. FS_APPEND_SYNC
  438. } fsMode_t;
  439. typedef enum {
  440. FS_SEEK_CUR,
  441. FS_SEEK_END,
  442. FS_SEEK_SET
  443. } fsOrigin_t;
  444. //=============================================
  445. int Q_isprint( int c );
  446. int Q_islower( int c );
  447. int Q_isupper( int c );
  448. int Q_isalpha( int c );
  449. // portable case insensitive compare
  450. int Q_stricmp (const char *s1, const char *s2);
  451. int Q_strncmp (const char *s1, const char *s2, int n);
  452. int Q_stricmpn (const char *s1, const char *s2, int n);
  453. char *Q_strlwr( char *s1 );
  454. char *Q_strupr( char *s1 );
  455. char *Q_strrchr( const char* string, int c );
  456. // buffer size safe library replacements
  457. void Q_strncpyz( char *dest, const char *src, int destsize );
  458. void Q_strcat( char *dest, int size, const char *src );
  459. // strlen that discounts Quake color sequences
  460. int Q_PrintStrlen( const char *string );
  461. // removes color sequences from string
  462. char *Q_CleanStr( char *string );
  463. int Com_Filter( const char *filter, const char *name, int casesensitive );
  464. const char *Com_StringContains( const char *str1, const char *str2, int casesensitive );
  465. //=============================================
  466. short BigShort(short l);
  467. short LittleShort(short l);
  468. int BigLong (int l);
  469. int LittleLong (int l);
  470. float BigFloat (float l);
  471. float LittleFloat (float l);
  472. void Swap_Init (void);
  473. char * QDECL va(char *format, ...);
  474. #ifdef __cplusplus
  475. }
  476. #endif
  477. //=============================================
  478. #ifdef __cplusplus
  479. //
  480. // mapfile parsing
  481. //
  482. typedef struct ePair_s {
  483. char *key;
  484. char *value;
  485. } ePair_t;
  486. typedef struct mapSide_s {
  487. char material[MAX_QPATH];
  488. vec4_t plane;
  489. vec4_t textureVectors[2];
  490. } mapSide_t;
  491. typedef struct {
  492. int numSides;
  493. mapSide_t **sides;
  494. } mapBrush_t;
  495. typedef struct {
  496. idVec3_t xyz;
  497. float st[2];
  498. } patchVertex_t;
  499. typedef struct {
  500. char material[MAX_QPATH];
  501. int width, height;
  502. patchVertex_t *patchVerts;
  503. } mapPatch_t;
  504. typedef struct {
  505. char modelName[MAX_QPATH];
  506. float matrix[16];
  507. } mapModel_t;
  508. typedef struct mapPrimitive_s {
  509. int numEpairs;
  510. ePair_t **ePairs;
  511. // only one of these will be non-NULL
  512. mapBrush_t *brush;
  513. mapPatch_t *patch;
  514. mapModel_t *model;
  515. } mapPrimitive_t;
  516. typedef struct mapEntity_s {
  517. int numPrimitives;
  518. mapPrimitive_t **primitives;
  519. int numEpairs;
  520. ePair_t **ePairs;
  521. } mapEntity_t;
  522. typedef struct {
  523. int numEntities;
  524. mapEntity_t **entities;
  525. } mapFile_t;
  526. // the order of entities, brushes, and sides will be maintained, the
  527. // lists won't be swapped on each load or save
  528. mapFile_t *ParseMapFile( const char *text );
  529. void FreeMapFile( mapFile_t *mapFile );
  530. void WriteMapFile( const mapFile_t *mapFile, FILE *f );
  531. // key names are case-insensitive
  532. const char *ValueForMapEntityKey( const mapEntity_t *ent, const char *key );
  533. float FloatForMapEntityKey( const mapEntity_t *ent, const char *key );
  534. qboolean GetVectorForMapEntityKey( const mapEntity_t *ent, const char *key, idVec3_t &vec );
  535. typedef struct {
  536. idVec3_t xyz;
  537. idVec2_t st;
  538. idVec3_t normal;
  539. idVec3_t tangents[2];
  540. byte smoothing[4]; // colors for silhouette smoothing
  541. } drawVert_t;
  542. typedef struct {
  543. int width, height;
  544. drawVert_t *verts;
  545. } drawVertMesh_t;
  546. // Tesselate a map patch into smoothed, drawable vertexes
  547. // MaxError of around 4 is reasonable
  548. drawVertMesh_t *SubdivideMapPatch( const mapPatch_t *patch, float maxError );
  549. #endif // __cplusplus
  550. //=========================================
  551. #ifdef __cplusplus
  552. extern "C" {
  553. #endif
  554. void QDECL Com_Error( int level, const char *error, ... );
  555. void QDECL Com_Printf( const char *msg, ... );
  556. void QDECL Com_DPrintf( const char *msg, ... );
  557. #ifdef __cplusplus
  558. }
  559. #endif
  560. typedef struct {
  561. qboolean frameMemory;
  562. int currentElements;
  563. int maxElements; // will reallocate and move when exceeded
  564. void **elements;
  565. } growList_t;
  566. // you don't need to init the growlist if you don't mind it growing and moving
  567. // the list as it expands
  568. void Com_InitGrowList( growList_t *list, int maxElements );
  569. int Com_AddToGrowList( growList_t *list, void *data );
  570. void *Com_GrowListElement( const growList_t *list, int index );
  571. int Com_IndexForGrowListElement( const growList_t *list, const void *element );
  572. //
  573. // key / value info strings
  574. //
  575. char *Info_ValueForKey( const char *s, const char *key );
  576. void Info_RemoveKey( char *s, const char *key );
  577. void Info_SetValueForKey( char *s, const char *key, const char *value );
  578. qboolean Info_Validate( const char *s );
  579. void Info_NextPair( const char *(*s), char key[MAX_INFO_KEY], char value[MAX_INFO_VALUE] );
  580. // get cvar defs, collision defs, etc
  581. //#include "../shared/interface.h"
  582. // get key code numbers for events
  583. //#include "../shared/keycodes.h"
  584. #ifdef __cplusplus
  585. // get the polygon winding functions
  586. //#include "../shared/windings.h"
  587. // get the flags class
  588. //#include "../shared/idflags.h"
  589. #endif // __cplusplus
  590. #endif // __Q_SHARED_H