PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/quake3/trunk/code/splines/q_shared.h

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