q_shared.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  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. //
  19. #ifndef __Q_SHARED_H
  20. #define __Q_SHARED_H
  21. // q_shared.h -- included first by ALL program modules.
  22. // A user mod should never modify this file
  23. #define Q3_VERSION "Q3 1.32b"
  24. // 1.32 released 7-10-2002
  25. #define MAX_TEAMNAME 32
  26. #ifdef _WIN32
  27. #pragma warning(disable : 4018) // signed/unsigned mismatch
  28. #pragma warning(disable : 4032)
  29. #pragma warning(disable : 4051)
  30. #pragma warning(disable : 4057) // slightly different base types
  31. #pragma warning(disable : 4100) // unreferenced formal parameter
  32. #pragma warning(disable : 4115)
  33. #pragma warning(disable : 4125) // decimal digit terminates octal escape sequence
  34. #pragma warning(disable : 4127) // conditional expression is constant
  35. #pragma warning(disable : 4136)
  36. #pragma warning(disable : 4152) // nonstandard extension, function/data pointer conversion in expression
  37. //#pragma warning(disable : 4201)
  38. //#pragma warning(disable : 4214)
  39. #pragma warning(disable : 4244)
  40. #pragma warning(disable : 4142) // benign redefinition
  41. //#pragma warning(disable : 4305) // truncation from const double to float
  42. //#pragma warning(disable : 4310) // cast truncates constant value
  43. //#pragma warning(disable: 4505) // unreferenced local function has been removed
  44. #pragma warning(disable : 4514)
  45. #pragma warning(disable : 4702) // unreachable code
  46. #pragma warning(disable : 4711) // selected for automatic inline expansion
  47. #pragma warning(disable : 4220) // varargs matches remaining parameters
  48. #endif
  49. /**********************************************************************
  50. VM Considerations
  51. The VM can not use the standard system headers because we aren't really
  52. using the compiler they were meant for. We use bg_lib.h which contains
  53. prototypes for the functions we define for our own use in bg_lib.c.
  54. When writing mods, please add needed headers HERE, do not start including
  55. stuff like <stdio.h> in the various .c files that make up each of the VMs
  56. since you will be including system headers files can will have issues.
  57. Remember, if you use a C library function that is not defined in bg_lib.c,
  58. you will have to add your own version for support in the VM.
  59. **********************************************************************/
  60. #ifdef Q3_VM
  61. #include "bg_lib.h"
  62. #else
  63. #include <assert.h>
  64. #include <math.h>
  65. #include <stdio.h>
  66. #include <stdarg.h>
  67. #include <string.h>
  68. #include <stdlib.h>
  69. #include <time.h>
  70. #include <ctype.h>
  71. #include <limits.h>
  72. #endif
  73. #ifdef _WIN32
  74. //#pragma intrinsic( memset, memcpy )
  75. #endif
  76. // this is the define for determining if we have an asm version of a C function
  77. #if (defined _M_IX86 || defined __i386__) && !defined __sun__ && !defined __LCC__
  78. #define id386 1
  79. #else
  80. #define id386 0
  81. #endif
  82. #if (defined(powerc) || defined(powerpc) || defined(ppc) || defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY)
  83. #define idppc 1
  84. #if defined(__VEC__)
  85. #define idppc_altivec 1
  86. #else
  87. #define idppc_altivec 0
  88. #endif
  89. #else
  90. #define idppc 0
  91. #define idppc_altivec 0
  92. #endif
  93. // for windows fastcall option
  94. #define QDECL
  95. short ShortSwap (short l);
  96. int LongSwap (int l);
  97. float FloatSwap (const float *f);
  98. //======================= WIN32 DEFINES =================================
  99. #ifdef WIN32
  100. #define MAC_STATIC
  101. #undef QDECL
  102. #define QDECL __cdecl
  103. // buildstring will be incorporated into the version string
  104. #ifdef NDEBUG
  105. #ifdef _M_IX86
  106. #define CPUSTRING "win-x86"
  107. #elif defined _M_ALPHA
  108. #define CPUSTRING "win-AXP"
  109. #endif
  110. #else
  111. #ifdef _M_IX86
  112. #define CPUSTRING "win-x86-debug"
  113. #elif defined _M_ALPHA
  114. #define CPUSTRING "win-AXP-debug"
  115. #endif
  116. #endif
  117. #define ID_INLINE __inline
  118. static ID_INLINE short BigShort( short l) { return ShortSwap(l); }
  119. #define LittleShort
  120. static ID_INLINE int BigLong(int l) { LongSwap(l); }
  121. #define LittleLong
  122. static ID_INLINE float BigFloat(const float *l) { FloatSwap(l); }
  123. #define LittleFloat
  124. #define PATH_SEP '\\'
  125. #endif
  126. //======================= MAC OS X DEFINES =====================
  127. #if defined(MACOS_X)
  128. #define MAC_STATIC
  129. #define __cdecl
  130. #define __declspec(x)
  131. #define stricmp strcasecmp
  132. #define ID_INLINE inline
  133. #ifdef __ppc__
  134. #define CPUSTRING "MacOSX-ppc"
  135. #elif defined __i386__
  136. #define CPUSTRING "MacOSX-i386"
  137. #else
  138. #define CPUSTRING "MacOSX-other"
  139. #endif
  140. #define PATH_SEP '/'
  141. #define __rlwimi(out, in, shift, maskBegin, maskEnd) asm("rlwimi %0,%1,%2,%3,%4" : "=r" (out) : "r" (in), "i" (shift), "i" (maskBegin), "i" (maskEnd))
  142. #define __dcbt(addr, offset) asm("dcbt %0,%1" : : "b" (addr), "r" (offset))
  143. static inline unsigned int __lwbrx(register void *addr, register int offset) {
  144. register unsigned int word;
  145. asm("lwbrx %0,%2,%1" : "=r" (word) : "r" (addr), "b" (offset));
  146. return word;
  147. }
  148. static inline unsigned short __lhbrx(register void *addr, register int offset) {
  149. register unsigned short halfword;
  150. asm("lhbrx %0,%2,%1" : "=r" (halfword) : "r" (addr), "b" (offset));
  151. return halfword;
  152. }
  153. static inline float __fctiw(register float f) {
  154. register float fi;
  155. asm("fctiw %0,%1" : "=f" (fi) : "f" (f));
  156. return fi;
  157. }
  158. #define BigShort
  159. static inline short LittleShort(short l) { return ShortSwap(l); }
  160. #define BigLong
  161. static inline int LittleLong (int l) { return LongSwap(l); }
  162. #define BigFloat
  163. static inline float LittleFloat (const float l) { return FloatSwap(&l); }
  164. #endif
  165. //======================= MAC DEFINES =================================
  166. #ifdef __MACOS__
  167. #include <MacTypes.h>
  168. #define MAC_STATIC
  169. #define ID_INLINE inline
  170. #define CPUSTRING "MacOS-PPC"
  171. #define PATH_SEP ':'
  172. void Sys_PumpEvents( void );
  173. #define BigShort
  174. static inline short LittleShort(short l) { return ShortSwap(l); }
  175. #define BigLong
  176. static inline int LittleLong (int l) { return LongSwap(l); }
  177. #define BigFloat
  178. static inline float LittleFloat (const float l) { return FloatSwap(&l); }
  179. #endif
  180. //======================= LINUX DEFINES =================================
  181. // the mac compiler can't handle >32k of locals, so we
  182. // just waste space and make big arrays static...
  183. #ifdef __linux__
  184. // bk001205 - from Makefile
  185. #define stricmp strcasecmp
  186. #define MAC_STATIC // bk: FIXME
  187. #define ID_INLINE inline
  188. #ifdef __i386__
  189. #define CPUSTRING "linux-i386"
  190. #elif defined __axp__
  191. #define CPUSTRING "linux-alpha"
  192. #else
  193. #define CPUSTRING "linux-other"
  194. #endif
  195. #define PATH_SEP '/'
  196. // bk001205 - try
  197. #ifdef Q3_STATIC
  198. #define GAME_HARD_LINKED
  199. #define CGAME_HARD_LINKED
  200. #define UI_HARD_LINKED
  201. #define BOTLIB_HARD_LINKED
  202. #endif
  203. #if !idppc
  204. inline static short BigShort( short l) { return ShortSwap(l); }
  205. #define LittleShort
  206. inline static int BigLong(int l) { return LongSwap(l); }
  207. #define LittleLong
  208. inline static float BigFloat(const float *l) { return FloatSwap(l); }
  209. #define LittleFloat
  210. #else
  211. #define BigShort
  212. inline static short LittleShort(short l) { return ShortSwap(l); }
  213. #define BigLong
  214. inline static int LittleLong (int l) { return LongSwap(l); }
  215. #define BigFloat
  216. inline static float LittleFloat (const float *l) { return FloatSwap(l); }
  217. #endif
  218. #endif
  219. //======================= FreeBSD DEFINES =====================
  220. #ifdef __FreeBSD__ // rb010123
  221. #define stricmp strcasecmp
  222. #define MAC_STATIC
  223. #define ID_INLINE inline
  224. #ifdef __i386__
  225. #define CPUSTRING "freebsd-i386"
  226. #elif defined __axp__
  227. #define CPUSTRING "freebsd-alpha"
  228. #else
  229. #define CPUSTRING "freebsd-other"
  230. #endif
  231. #define PATH_SEP '/'
  232. // bk010116 - omitted Q3STATIC (see Linux above), broken target
  233. #if !idppc
  234. static short BigShort( short l) { return ShortSwap(l); }
  235. #define LittleShort
  236. static int BigLong(int l) { LongSwap(l); }
  237. #define LittleLong
  238. static float BigFloat(const float *l) { FloatSwap(l); }
  239. #define LittleFloat
  240. #else
  241. #define BigShort
  242. static short LittleShort(short l) { return ShortSwap(l); }
  243. #define BigLong
  244. static int LittleLong (int l) { return LongSwap(l); }
  245. #define BigFloat
  246. static float LittleFloat (const float *l) { return FloatSwap(l); }
  247. #endif
  248. #endif
  249. //=============================================================
  250. typedef unsigned char byte;
  251. typedef enum {qfalse, qtrue} qboolean;
  252. typedef int qhandle_t;
  253. typedef int sfxHandle_t;
  254. typedef int fileHandle_t;
  255. typedef int clipHandle_t;
  256. #ifndef NULL
  257. #define NULL ((void *)0)
  258. #endif
  259. #define MAX_QINT 0x7fffffff
  260. #define MIN_QINT (-MAX_QINT-1)
  261. // angle indexes
  262. #define PITCH 0 // up / down
  263. #define YAW 1 // left / right
  264. #define ROLL 2 // fall over
  265. // the game guarantees that no string from the network will ever
  266. // exceed MAX_STRING_CHARS
  267. #define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
  268. #define MAX_STRING_TOKENS 1024 // max tokens resulting from Cmd_TokenizeString
  269. #define MAX_TOKEN_CHARS 1024 // max length of an individual token
  270. #define MAX_INFO_STRING 1024
  271. #define MAX_INFO_KEY 1024
  272. #define MAX_INFO_VALUE 1024
  273. #define BIG_INFO_STRING 8192 // used for system info key only
  274. #define BIG_INFO_KEY 8192
  275. #define BIG_INFO_VALUE 8192
  276. #define MAX_QPATH 64 // max length of a quake game pathname
  277. #ifdef PATH_MAX
  278. #define MAX_OSPATH PATH_MAX
  279. #else
  280. #define MAX_OSPATH 256 // max length of a filesystem pathname
  281. #endif
  282. #define MAX_NAME_LENGTH 32 // max length of a client name
  283. #define MAX_SAY_TEXT 150
  284. // paramters for command buffer stuffing
  285. typedef enum {
  286. EXEC_NOW, // don't return until completed, a VM should NEVER use this,
  287. // because some commands might cause the VM to be unloaded...
  288. EXEC_INSERT, // insert at current position, but don't run yet
  289. EXEC_APPEND // add to end of the command buffer (normal case)
  290. } cbufExec_t;
  291. //
  292. // these aren't needed by any of the VMs. put in another header?
  293. //
  294. #define MAX_MAP_AREA_BYTES 32 // bit vector of area visibility
  295. // print levels from renderer (FIXME: set up for game / cgame?)
  296. typedef enum {
  297. PRINT_ALL,
  298. PRINT_DEVELOPER, // only print when "developer 1"
  299. PRINT_WARNING,
  300. PRINT_ERROR
  301. } printParm_t;
  302. #ifdef ERR_FATAL
  303. #undef ERR_FATAL // this is be defined in malloc.h
  304. #endif
  305. // parameters to the main Error routine
  306. typedef enum {
  307. ERR_FATAL, // exit the entire game with a popup window
  308. ERR_DROP, // print to console and disconnect from game
  309. ERR_SERVERDISCONNECT, // don't kill server
  310. ERR_DISCONNECT, // client disconnected from the server
  311. ERR_NEED_CD // pop up the need-cd dialog
  312. } errorParm_t;
  313. // font rendering values used by ui and cgame
  314. #define PROP_GAP_WIDTH 3
  315. #define PROP_SPACE_WIDTH 8
  316. #define PROP_HEIGHT 27
  317. #define PROP_SMALL_SIZE_SCALE 0.75
  318. #define BLINK_DIVISOR 200
  319. #define PULSE_DIVISOR 75
  320. #define UI_LEFT 0x00000000 // default
  321. #define UI_CENTER 0x00000001
  322. #define UI_RIGHT 0x00000002
  323. #define UI_FORMATMASK 0x00000007
  324. #define UI_SMALLFONT 0x00000010
  325. #define UI_BIGFONT 0x00000020 // default
  326. #define UI_GIANTFONT 0x00000040
  327. #define UI_DROPSHADOW 0x00000800
  328. #define UI_BLINK 0x00001000
  329. #define UI_INVERSE 0x00002000
  330. #define UI_PULSE 0x00004000
  331. #if defined(_DEBUG) && !defined(BSPC)
  332. #define HUNK_DEBUG
  333. #endif
  334. typedef enum {
  335. h_high,
  336. h_low,
  337. h_dontcare
  338. } ha_pref;
  339. #ifdef HUNK_DEBUG
  340. #define Hunk_Alloc( size, preference ) Hunk_AllocDebug(size, preference, #size, __FILE__, __LINE__)
  341. void *Hunk_AllocDebug( int size, ha_pref preference, char *label, char *file, int line );
  342. #else
  343. void *Hunk_Alloc( int size, ha_pref preference );
  344. #endif
  345. #ifdef __linux__
  346. // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=371
  347. // custom Snd_Memset implementation for glibc memset bug workaround
  348. void Snd_Memset (void* dest, const int val, const size_t count);
  349. #else
  350. #define Snd_Memset Com_Memset
  351. #endif
  352. #if !( defined __VECTORC )
  353. void Com_Memset (void* dest, const int val, const size_t count);
  354. void Com_Memcpy (void* dest, const void* src, const size_t count);
  355. #else
  356. #define Com_Memset memset
  357. #define Com_Memcpy memcpy
  358. #endif
  359. #define CIN_system 1
  360. #define CIN_loop 2
  361. #define CIN_hold 4
  362. #define CIN_silent 8
  363. #define CIN_shader 16
  364. /*
  365. ==============================================================
  366. MATHLIB
  367. ==============================================================
  368. */
  369. typedef float vec_t;
  370. typedef vec_t vec2_t[2];
  371. typedef vec_t vec3_t[3];
  372. typedef vec_t vec4_t[4];
  373. typedef vec_t vec5_t[5];
  374. typedef int fixed4_t;
  375. typedef int fixed8_t;
  376. typedef int fixed16_t;
  377. #ifndef M_PI
  378. #define M_PI 3.14159265358979323846f // matches value in gcc v2 math.h
  379. #endif
  380. #define NUMVERTEXNORMALS 162
  381. extern vec3_t bytedirs[NUMVERTEXNORMALS];
  382. // all drawing is done to a 640*480 virtual screen size
  383. // and will be automatically scaled to the real resolution
  384. #define SCREEN_WIDTH 640
  385. #define SCREEN_HEIGHT 480
  386. #define TINYCHAR_WIDTH (SMALLCHAR_WIDTH)
  387. #define TINYCHAR_HEIGHT (SMALLCHAR_HEIGHT/2)
  388. #define SMALLCHAR_WIDTH 8
  389. #define SMALLCHAR_HEIGHT 16
  390. #define BIGCHAR_WIDTH 16
  391. #define BIGCHAR_HEIGHT 16
  392. #define GIANTCHAR_WIDTH 32
  393. #define GIANTCHAR_HEIGHT 48
  394. extern vec4_t colorBlack;
  395. extern vec4_t colorRed;
  396. extern vec4_t colorGreen;
  397. extern vec4_t colorBlue;
  398. extern vec4_t colorYellow;
  399. extern vec4_t colorMagenta;
  400. extern vec4_t colorCyan;
  401. extern vec4_t colorWhite;
  402. extern vec4_t colorLtGrey;
  403. extern vec4_t colorMdGrey;
  404. extern vec4_t colorDkGrey;
  405. #define Q_COLOR_ESCAPE '^'
  406. #define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE )
  407. #define COLOR_BLACK '0'
  408. #define COLOR_RED '1'
  409. #define COLOR_GREEN '2'
  410. #define COLOR_YELLOW '3'
  411. #define COLOR_BLUE '4'
  412. #define COLOR_CYAN '5'
  413. #define COLOR_MAGENTA '6'
  414. #define COLOR_WHITE '7'
  415. #define ColorIndex(c) ( ( (c) - '0' ) & 7 )
  416. #define S_COLOR_BLACK "^0"
  417. #define S_COLOR_RED "^1"
  418. #define S_COLOR_GREEN "^2"
  419. #define S_COLOR_YELLOW "^3"
  420. #define S_COLOR_BLUE "^4"
  421. #define S_COLOR_CYAN "^5"
  422. #define S_COLOR_MAGENTA "^6"
  423. #define S_COLOR_WHITE "^7"
  424. extern vec4_t g_color_table[8];
  425. #define MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
  426. #define MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
  427. #define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
  428. #define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
  429. struct cplane_s;
  430. extern vec3_t vec3_origin;
  431. extern vec3_t axisDefault[3];
  432. #define nanmask (255<<23)
  433. #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
  434. #if idppc
  435. static inline float Q_rsqrt( float number ) {
  436. float x = 0.5f * number;
  437. float y;
  438. #ifdef __GNUC__
  439. asm("frsqrte %0,%1" : "=f" (y) : "f" (number));
  440. #else
  441. y = __frsqrte( number );
  442. #endif
  443. return y * (1.5f - (x * y * y));
  444. }
  445. #ifdef __GNUC__
  446. static inline float Q_fabs(float x) {
  447. float abs_x;
  448. asm("fabs %0,%1" : "=f" (abs_x) : "f" (x));
  449. return abs_x;
  450. }
  451. #else
  452. #define Q_fabs __fabsf
  453. #endif
  454. #else
  455. float Q_fabs( float f );
  456. float Q_rsqrt( float f ); // reciprocal square root
  457. #endif
  458. #define SQRTFAST( x ) ( (x) * Q_rsqrt( x ) )
  459. signed char ClampChar( int i );
  460. signed short ClampShort( int i );
  461. // this isn't a real cheap function to call!
  462. int DirToByte( vec3_t dir );
  463. void ByteToDir( int b, vec3_t dir );
  464. #if 1
  465. #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
  466. #define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
  467. #define VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
  468. #define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
  469. #define VectorScale(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
  470. #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))
  471. #else
  472. #define DotProduct(x,y) _DotProduct(x,y)
  473. #define VectorSubtract(a,b,c) _VectorSubtract(a,b,c)
  474. #define VectorAdd(a,b,c) _VectorAdd(a,b,c)
  475. #define VectorCopy(a,b) _VectorCopy(a,b)
  476. #define VectorScale(v, s, o) _VectorScale(v,s,o)
  477. #define VectorMA(v, s, b, o) _VectorMA(v,s,b,o)
  478. #endif
  479. #ifdef __LCC__
  480. #ifdef VectorCopy
  481. #undef VectorCopy
  482. // this is a little hack to get more efficient copies in our interpreter
  483. typedef struct {
  484. float v[3];
  485. } vec3struct_t;
  486. #define VectorCopy(a,b) (*(vec3struct_t *)b=*(vec3struct_t *)a)
  487. #define ID_INLINE static
  488. #endif
  489. #endif
  490. #define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0)
  491. #define VectorNegate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
  492. #define VectorSet(v, x, y, z) ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
  493. #define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
  494. #define SnapVector(v) {v[0]=((int)(v[0]));v[1]=((int)(v[1]));v[2]=((int)(v[2]));}
  495. // just in case you do't want to use the macros
  496. vec_t _DotProduct( const vec3_t v1, const vec3_t v2 );
  497. void _VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out );
  498. void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out );
  499. void _VectorCopy( const vec3_t in, vec3_t out );
  500. void _VectorScale( const vec3_t in, float scale, vec3_t out );
  501. void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc );
  502. unsigned ColorBytes3 (float r, float g, float b);
  503. unsigned ColorBytes4 (float r, float g, float b, float a);
  504. float NormalizeColor( const vec3_t in, vec3_t out );
  505. float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
  506. void ClearBounds( vec3_t mins, vec3_t maxs );
  507. void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
  508. #ifndef __LCC__
  509. static ID_INLINE int VectorCompare( const vec3_t v1, const vec3_t v2 ) {
  510. if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]) {
  511. return 0;
  512. }
  513. return 1;
  514. }
  515. static ID_INLINE vec_t VectorLength( const vec3_t v ) {
  516. return (vec_t)sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  517. }
  518. static ID_INLINE vec_t VectorLengthSquared( const vec3_t v ) {
  519. return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  520. }
  521. static ID_INLINE vec_t Distance( const vec3_t p1, const vec3_t p2 ) {
  522. vec3_t v;
  523. VectorSubtract (p2, p1, v);
  524. return VectorLength( v );
  525. }
  526. static ID_INLINE vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 ) {
  527. vec3_t v;
  528. VectorSubtract (p2, p1, v);
  529. return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
  530. }
  531. // fast vector normalize routine that does not check to make sure
  532. // that length != 0, nor does it return length, uses rsqrt approximation
  533. static ID_INLINE void VectorNormalizeFast( vec3_t v )
  534. {
  535. float ilength;
  536. ilength = Q_rsqrt( DotProduct( v, v ) );
  537. v[0] *= ilength;
  538. v[1] *= ilength;
  539. v[2] *= ilength;
  540. }
  541. static ID_INLINE void VectorInverse( vec3_t v ){
  542. v[0] = -v[0];
  543. v[1] = -v[1];
  544. v[2] = -v[2];
  545. }
  546. static ID_INLINE void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ) {
  547. cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
  548. cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
  549. cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
  550. }
  551. #else
  552. int VectorCompare( const vec3_t v1, const vec3_t v2 );
  553. vec_t VectorLength( const vec3_t v );
  554. vec_t VectorLengthSquared( const vec3_t v );
  555. vec_t Distance( const vec3_t p1, const vec3_t p2 );
  556. vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 );
  557. void VectorNormalizeFast( vec3_t v );
  558. void VectorInverse( vec3_t v );
  559. void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
  560. #endif
  561. vec_t VectorNormalize (vec3_t v); // returns vector length
  562. vec_t VectorNormalize2( const vec3_t v, vec3_t out );
  563. void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out );
  564. void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out );
  565. int Q_log2(int val);
  566. float Q_acos(float c);
  567. int Q_rand( int *seed );
  568. float Q_random( int *seed );
  569. float Q_crandom( int *seed );
  570. #define random() ((rand () & 0x7fff) / ((float)0x7fff))
  571. #define crandom() (2.0 * (random() - 0.5))
  572. void vectoangles( const vec3_t value1, vec3_t angles);
  573. void AnglesToAxis( const vec3_t angles, vec3_t axis[3] );
  574. void AxisClear( vec3_t axis[3] );
  575. void AxisCopy( vec3_t in[3], vec3_t out[3] );
  576. void SetPlaneSignbits( struct cplane_s *out );
  577. int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *plane);
  578. float AngleMod(float a);
  579. float LerpAngle (float from, float to, float frac);
  580. float AngleSubtract( float a1, float a2 );
  581. void AnglesSubtract( vec3_t v1, vec3_t v2, vec3_t v3 );
  582. float AngleNormalize360 ( float angle );
  583. float AngleNormalize180 ( float angle );
  584. float AngleDelta ( float angle1, float angle2 );
  585. qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
  586. void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
  587. void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
  588. void RotateAroundDirection( vec3_t axis[3], float yaw );
  589. void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up );
  590. // perpendicular vector could be replaced by this
  591. //int PlaneTypeForNormal (vec3_t normal);
  592. void MatrixMultiply(float in1[3][3], float in2[3][3], float out[3][3]);
  593. void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
  594. void PerpendicularVector( vec3_t dst, const vec3_t src );
  595. //=============================================
  596. float Com_Clamp( float min, float max, float value );
  597. char *COM_SkipPath( char *pathname );
  598. void COM_StripExtension( const char *in, char *out );
  599. void COM_DefaultExtension( char *path, int maxSize, const char *extension );
  600. void COM_BeginParseSession( const char *name );
  601. int COM_GetCurrentParseLine( void );
  602. char *COM_Parse( char **data_p );
  603. char *COM_ParseExt( char **data_p, qboolean allowLineBreak );
  604. int COM_Compress( char *data_p );
  605. void COM_ParseError( char *format, ... );
  606. void COM_ParseWarning( char *format, ... );
  607. //int COM_ParseInfos( char *buf, int max, char infos[][MAX_INFO_STRING] );
  608. #define MAX_TOKENLENGTH 1024
  609. #ifndef TT_STRING
  610. //token types
  611. #define TT_STRING 1 // string
  612. #define TT_LITERAL 2 // literal
  613. #define TT_NUMBER 3 // number
  614. #define TT_NAME 4 // name
  615. #define TT_PUNCTUATION 5 // punctuation
  616. #endif
  617. typedef struct pc_token_s
  618. {
  619. int type;
  620. int subtype;
  621. int intvalue;
  622. float floatvalue;
  623. char string[MAX_TOKENLENGTH];
  624. } pc_token_t;
  625. // data is an in/out parm, returns a parsed out token
  626. void COM_MatchToken( char**buf_p, char *match );
  627. void SkipBracedSection (char **program);
  628. void SkipRestOfLine ( char **data );
  629. void Parse1DMatrix (char **buf_p, int x, float *m);
  630. void Parse2DMatrix (char **buf_p, int y, int x, float *m);
  631. void Parse3DMatrix (char **buf_p, int z, int y, int x, float *m);
  632. void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...);
  633. // mode parm for FS_FOpenFile
  634. typedef enum {
  635. FS_READ,
  636. FS_WRITE,
  637. FS_APPEND,
  638. FS_APPEND_SYNC
  639. } fsMode_t;
  640. typedef enum {
  641. FS_SEEK_CUR,
  642. FS_SEEK_END,
  643. FS_SEEK_SET
  644. } fsOrigin_t;
  645. //=============================================
  646. int Q_isprint( int c );
  647. int Q_islower( int c );
  648. int Q_isupper( int c );
  649. int Q_isalpha( int c );
  650. // portable case insensitive compare
  651. int Q_stricmp (const char *s1, const char *s2);
  652. int Q_strncmp (const char *s1, const char *s2, int n);
  653. int Q_stricmpn (const char *s1, const char *s2, int n);
  654. char *Q_strlwr( char *s1 );
  655. char *Q_strupr( char *s1 );
  656. char *Q_strrchr( const char* string, int c );
  657. // buffer size safe library replacements
  658. void Q_strncpyz( char *dest, const char *src, int destsize );
  659. void Q_strcat( char *dest, int size, const char *src );
  660. // strlen that discounts Quake color sequences
  661. int Q_PrintStrlen( const char *string );
  662. // removes color sequences from string
  663. char *Q_CleanStr( char *string );
  664. //=============================================
  665. // 64-bit integers for global rankings interface
  666. // implemented as a struct for qvm compatibility
  667. typedef struct
  668. {
  669. byte b0;
  670. byte b1;
  671. byte b2;
  672. byte b3;
  673. byte b4;
  674. byte b5;
  675. byte b6;
  676. byte b7;
  677. } qint64;
  678. //=============================================
  679. /*
  680. short BigShort(short l);
  681. short LittleShort(short l);
  682. int BigLong (int l);
  683. int LittleLong (int l);
  684. qint64 BigLong64 (qint64 l);
  685. qint64 LittleLong64 (qint64 l);
  686. float BigFloat (const float *l);
  687. float LittleFloat (const float *l);
  688. void Swap_Init (void);
  689. */
  690. char * QDECL va(char *format, ...);
  691. //=============================================
  692. //
  693. // key / value info strings
  694. //
  695. char *Info_ValueForKey( const char *s, const char *key );
  696. void Info_RemoveKey( char *s, const char *key );
  697. void Info_RemoveKey_big( char *s, const char *key );
  698. void Info_SetValueForKey( char *s, const char *key, const char *value );
  699. void Info_SetValueForKey_Big( char *s, const char *key, const char *value );
  700. qboolean Info_Validate( const char *s );
  701. void Info_NextPair( const char **s, char *key, char *value );
  702. // this is only here so the functions in q_shared.c and bg_*.c can link
  703. void QDECL Com_Error( int level, const char *error, ... );
  704. void QDECL Com_Printf( const char *msg, ... );
  705. /*
  706. ==========================================================
  707. CVARS (console variables)
  708. Many variables can be used for cheating purposes, so when
  709. cheats is zero, force all unspecified variables to their
  710. default values.
  711. ==========================================================
  712. */
  713. #define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc
  714. // used for system variables, not for player
  715. // specific configurations
  716. #define CVAR_USERINFO 2 // sent to server on connect or change
  717. #define CVAR_SERVERINFO 4 // sent in response to front end requests
  718. #define CVAR_SYSTEMINFO 8 // these cvars will be duplicated on all clients
  719. #define CVAR_INIT 16 // don't allow change from console at all,
  720. // but can be set from the command line
  721. #define CVAR_LATCH 32 // will only change when C code next does
  722. // a Cvar_Get(), so it can't be changed
  723. // without proper initialization. modified
  724. // will be set, even though the value hasn't
  725. // changed yet
  726. #define CVAR_ROM 64 // display only, cannot be set by user at all
  727. #define CVAR_USER_CREATED 128 // created by a set command
  728. #define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived
  729. #define CVAR_CHEAT 512 // can not be changed if cheats are disabled
  730. #define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued
  731. // nothing outside the Cvar_*() functions should modify these fields!
  732. typedef struct cvar_s {
  733. char *name;
  734. char *string;
  735. char *resetString; // cvar_restart will reset to this value
  736. char *latchedString; // for CVAR_LATCH vars
  737. int flags;
  738. qboolean modified; // set each time the cvar is changed
  739. int modificationCount; // incremented each time the cvar is changed
  740. float value; // atof( string )
  741. int integer; // atoi( string )
  742. struct cvar_s *next;
  743. struct cvar_s *hashNext;
  744. } cvar_t;
  745. #define MAX_CVAR_VALUE_STRING 256
  746. typedef int cvarHandle_t;
  747. // the modules that run in the virtual machine can't access the cvar_t directly,
  748. // so they must ask for structured updates
  749. typedef struct {
  750. cvarHandle_t handle;
  751. int modificationCount;
  752. float value;
  753. int integer;
  754. char string[MAX_CVAR_VALUE_STRING];
  755. } vmCvar_t;
  756. /*
  757. ==============================================================
  758. COLLISION DETECTION
  759. ==============================================================
  760. */
  761. #include "surfaceflags.h" // shared with the q3map utility
  762. // plane types are used to speed some tests
  763. // 0-2 are axial planes
  764. #define PLANE_X 0
  765. #define PLANE_Y 1
  766. #define PLANE_Z 2
  767. #define PLANE_NON_AXIAL 3
  768. /*
  769. =================
  770. PlaneTypeForNormal
  771. =================
  772. */
  773. #define PlaneTypeForNormal(x) (x[0] == 1.0 ? PLANE_X : (x[1] == 1.0 ? PLANE_Y : (x[2] == 1.0 ? PLANE_Z : PLANE_NON_AXIAL) ) )
  774. // plane_t structure
  775. // !!! if this is changed, it must be changed in asm code too !!!
  776. typedef struct cplane_s {
  777. vec3_t normal;
  778. float dist;
  779. byte type; // for fast side tests: 0,1,2 = axial, 3 = nonaxial
  780. byte signbits; // signx + (signy<<1) + (signz<<2), used as lookup during collision
  781. byte pad[2];
  782. } cplane_t;
  783. // a trace is returned when a box is swept through the world
  784. typedef struct {
  785. qboolean allsolid; // if true, plane is not valid
  786. qboolean startsolid; // if true, the initial point was in a solid area
  787. float fraction; // time completed, 1.0 = didn't hit anything
  788. vec3_t endpos; // final position
  789. cplane_t plane; // surface normal at impact, transformed to world space
  790. int surfaceFlags; // surface hit
  791. int contents; // contents on other side of surface hit
  792. int entityNum; // entity the contacted sirface is a part of
  793. } trace_t;
  794. // trace->entityNum can also be 0 to (MAX_GENTITIES-1)
  795. // or ENTITYNUM_NONE, ENTITYNUM_WORLD
  796. // markfragments are returned by CM_MarkFragments()
  797. typedef struct {
  798. int firstPoint;
  799. int numPoints;
  800. } markFragment_t;
  801. typedef struct {
  802. vec3_t origin;
  803. vec3_t axis[3];
  804. } orientation_t;
  805. //=====================================================================
  806. // in order from highest priority to lowest
  807. // if none of the catchers are active, bound key strings will be executed
  808. #define KEYCATCH_CONSOLE 0x0001
  809. #define KEYCATCH_UI 0x0002
  810. #define KEYCATCH_MESSAGE 0x0004
  811. #define KEYCATCH_CGAME 0x0008
  812. // sound channels
  813. // channel 0 never willingly overrides
  814. // other channels will allways override a playing sound on that channel
  815. typedef enum {
  816. CHAN_AUTO,
  817. CHAN_LOCAL, // menu sounds, etc
  818. CHAN_WEAPON,
  819. CHAN_VOICE,
  820. CHAN_ITEM,
  821. CHAN_BODY,
  822. CHAN_LOCAL_SOUND, // chat messages, etc
  823. CHAN_ANNOUNCER // announcer voices, etc
  824. } soundChannel_t;
  825. /*
  826. ========================================================================
  827. ELEMENTS COMMUNICATED ACROSS THE NET
  828. ========================================================================
  829. */
  830. #define ANGLE2SHORT(x) ((int)((x)*65536/360) & 65535)
  831. #define SHORT2ANGLE(x) ((x)*(360.0/65536))
  832. #define SNAPFLAG_RATE_DELAYED 1
  833. #define SNAPFLAG_NOT_ACTIVE 2 // snapshot used during connection and for zombies
  834. #define SNAPFLAG_SERVERCOUNT 4 // toggled every map_restart so transitions can be detected
  835. //
  836. // per-level limits
  837. //
  838. #define MAX_CLIENTS 64 // absolute limit
  839. #define MAX_LOCATIONS 64
  840. #define GENTITYNUM_BITS 10 // don't need to send any more
  841. #define MAX_GENTITIES (1<<GENTITYNUM_BITS)
  842. // entitynums are communicated with GENTITY_BITS, so any reserved
  843. // values that are going to be communcated over the net need to
  844. // also be in this range
  845. #define ENTITYNUM_NONE (MAX_GENTITIES-1)
  846. #define ENTITYNUM_WORLD (MAX_GENTITIES-2)
  847. #define ENTITYNUM_MAX_NORMAL (MAX_GENTITIES-2)
  848. #define MAX_MODELS 256 // these are sent over the net as 8 bits
  849. #define MAX_SOUNDS 256 // so they cannot be blindly increased
  850. #define MAX_CONFIGSTRINGS 1024
  851. // these are the only configstrings that the system reserves, all the
  852. // other ones are strictly for servergame to clientgame communication
  853. #define CS_SERVERINFO 0 // an info string with all the serverinfo cvars
  854. #define CS_SYSTEMINFO 1 // an info string for server system to client system configuration (timescale, etc)
  855. #define RESERVED_CONFIGSTRINGS 2 // game can't modify below this, only the system can
  856. #define MAX_GAMESTATE_CHARS 16000
  857. typedef struct {
  858. int stringOffsets[MAX_CONFIGSTRINGS];
  859. char stringData[MAX_GAMESTATE_CHARS];
  860. int dataCount;
  861. } gameState_t;
  862. //=========================================================
  863. // bit field limits
  864. #define MAX_STATS 16
  865. #define MAX_PERSISTANT 16
  866. #define MAX_POWERUPS 16
  867. #define MAX_WEAPONS 16
  868. #define MAX_PS_EVENTS 2
  869. #define PS_PMOVEFRAMECOUNTBITS 6
  870. // playerState_t is the information needed by both the client and server
  871. // to predict player motion and actions
  872. // nothing outside of pmove should modify these, or some degree of prediction error
  873. // will occur
  874. // you can't add anything to this without modifying the code in msg.c
  875. // playerState_t is a full superset of entityState_t as it is used by players,
  876. // so if a playerState_t is transmitted, the entityState_t can be fully derived
  877. // from it.
  878. typedef struct playerState_s {
  879. int commandTime; // cmd->serverTime of last executed command
  880. int pm_type;
  881. int bobCycle; // for view bobbing and footstep generation
  882. int pm_flags; // ducked, jump_held, etc
  883. int pm_time;
  884. vec3_t origin;
  885. vec3_t velocity;
  886. int weaponTime;
  887. int gravity;
  888. int speed;
  889. int delta_angles[3]; // add to command angles to get view direction
  890. // changed by spawns, rotating objects, and teleporters
  891. int groundEntityNum;// ENTITYNUM_NONE = in air
  892. int legsTimer; // don't change low priority animations until this runs out
  893. int legsAnim; // mask off ANIM_TOGGLEBIT
  894. int torsoTimer; // don't change low priority animations until this runs out
  895. int torsoAnim; // mask off ANIM_TOGGLEBIT
  896. int movementDir; // a number 0 to 7 that represents the reletive angle
  897. // of movement to the view angle (axial and diagonals)
  898. // when at rest, the value will remain unchanged
  899. // used to twist the legs during strafing
  900. vec3_t grapplePoint; // location of grapple to pull towards if PMF_GRAPPLE_PULL
  901. int eFlags; // copied to entityState_t->eFlags
  902. int eventSequence; // pmove generated events
  903. int events[MAX_PS_EVENTS];
  904. int eventParms[MAX_PS_EVENTS];
  905. int externalEvent; // events set on player from another source
  906. int externalEventParm;
  907. int externalEventTime;
  908. int clientNum; // ranges from 0 to MAX_CLIENTS-1
  909. int weapon; // copied to entityState_t->weapon
  910. int weaponstate;
  911. vec3_t viewangles; // for fixed views
  912. int viewheight;
  913. // damage feedback
  914. int damageEvent; // when it changes, latch the other parms
  915. int damageYaw;
  916. int damagePitch;
  917. int damageCount;
  918. int stats[MAX_STATS];
  919. int persistant[MAX_PERSISTANT]; // stats that aren't cleared on death
  920. int powerups[MAX_POWERUPS]; // level.time that the powerup runs out
  921. int ammo[MAX_WEAPONS];
  922. int generic1;
  923. int loopSound;
  924. int jumppad_ent; // jumppad entity hit this frame
  925. // not communicated over the net at all
  926. int ping; // server to game info for scoreboard
  927. int pmove_framecount; // FIXME: don't transmit over the network
  928. int jumppad_frame;
  929. int entityEventSequence;
  930. } playerState_t;
  931. //====================================================================
  932. //
  933. // usercmd_t->button bits, many of which are generated by the client system,
  934. // so they aren't game/cgame only definitions
  935. //
  936. #define BUTTON_ATTACK 1
  937. #define BUTTON_TALK 2 // displays talk balloon and disables actions
  938. #define BUTTON_USE_HOLDABLE 4
  939. #define BUTTON_GESTURE 8
  940. #define BUTTON_WALKING 16 // walking can't just be infered from MOVE_RUN
  941. // because a key pressed late in the frame will
  942. // only generate a small move value for that frame
  943. // walking will use different animations and
  944. // won't generate footsteps
  945. #define BUTTON_AFFIRMATIVE 32
  946. #define BUTTON_NEGATIVE 64
  947. #define BUTTON_GETFLAG 128
  948. #define BUTTON_GUARDBASE 256
  949. #define BUTTON_PATROL 512
  950. #define BUTTON_FOLLOWME 1024
  951. #define BUTTON_ANY 2048 // any key whatsoever
  952. #define MOVE_RUN 120 // if forwardmove or rightmove are >= MOVE_RUN,
  953. // then BUTTON_WALKING should be set
  954. // usercmd_t is sent to the server each client frame
  955. typedef struct usercmd_s {
  956. int serverTime;
  957. int angles[3];
  958. int buttons;
  959. byte weapon; // weapon
  960. signed char forwardmove, rightmove, upmove;
  961. } usercmd_t;
  962. //===================================================================
  963. // if entityState->solid == SOLID_BMODEL, modelindex is an inline model number
  964. #define SOLID_BMODEL 0xffffff
  965. typedef enum {
  966. TR_STATIONARY,
  967. TR_INTERPOLATE, // non-parametric, but interpolate between snapshots
  968. TR_LINEAR,
  969. TR_LINEAR_STOP,
  970. TR_SINE, // value = base + sin( time / duration ) * delta
  971. TR_GRAVITY
  972. } trType_t;
  973. typedef struct {
  974. trType_t trType;
  975. int trTime;
  976. int trDuration; // if non 0, trTime + trDuration = stop time
  977. vec3_t trBase;
  978. vec3_t trDelta; // velocity, etc
  979. } trajectory_t;
  980. // entityState_t is the information conveyed from the server
  981. // in an update message about entities that the client will
  982. // need to render in some way
  983. // Different eTypes may use the information in different ways
  984. // The messages are delta compressed, so it doesn't really matter if
  985. // the structure size is fairly large
  986. typedef struct entityState_s {
  987. int number; // entity index
  988. int eType; // entityType_t
  989. int eFlags;
  990. trajectory_t pos; // for calculating position
  991. trajectory_t apos; // for calculating angles
  992. int time;
  993. int time2;
  994. vec3_t origin;
  995. vec3_t origin2;
  996. vec3_t angles;
  997. vec3_t angles2;
  998. int otherEntityNum; // shotgun sources, etc
  999. int otherEntityNum2;
  1000. int groundEntityNum; // -1 = in air
  1001. int constantLight; // r + (g<<8) + (b<<16) + (intensity<<24)
  1002. int loopSound; // constantly loop this sound
  1003. int modelindex;
  1004. int modelindex2;
  1005. int clientNum; // 0 to (MAX_CLIENTS - 1), for players and corpses
  1006. int frame;
  1007. int solid; // for client side prediction, trap_linkentity sets this properly
  1008. int event; // impulse events -- muzzle flashes, footsteps, etc
  1009. int eventParm;
  1010. // for players
  1011. int powerups; // bit flags
  1012. int weapon; // determines weapon and flash model, etc
  1013. int legsAnim; // mask off ANIM_TOGGLEBIT
  1014. int torsoAnim; // mask off ANIM_TOGGLEBIT
  1015. int generic1;
  1016. } entityState_t;
  1017. typedef enum {
  1018. CA_UNINITIALIZED,
  1019. CA_DISCONNECTED, // not talking to a server
  1020. CA_AUTHORIZING, // not used any more, was checking cd key
  1021. CA_CONNECTING, // sending request packets to the server
  1022. CA_CHALLENGING, // sending challenge packets to the server
  1023. CA_CONNECTED, // netchan_t established, getting gamestate
  1024. CA_LOADING, // only during cgame initialization, never during main loop
  1025. CA_PRIMED, // got gamestate, waiting for first frame
  1026. CA_ACTIVE, // game views should be displayed
  1027. CA_CINEMATIC // playing a cinematic or a static pic, not connected to a server
  1028. } connstate_t;
  1029. // font support
  1030. #define GLYPH_START 0
  1031. #define GLYPH_END 255
  1032. #define GLYPH_CHARSTART 32
  1033. #define GLYPH_CHAREND 127
  1034. #define GLYPHS_PER_FONT GLYPH_END - GLYPH_START + 1
  1035. typedef struct {
  1036. int height; // number of scan lines
  1037. int top; // top of glyph in buffer
  1038. int bottom; // bottom of glyph in buffer
  1039. int pitch; // width for copying
  1040. int xSkip; // x adjustment
  1041. int imageWidth; // width of actual image
  1042. int imageHeight; // height of actual image
  1043. float s; // x offset in image where glyph starts
  1044. float t; // y offset in image where glyph starts
  1045. float s2;
  1046. float t2;
  1047. qhandle_t glyph; // handle to the shader with the glyph
  1048. char shaderName[32];
  1049. } glyphInfo_t;
  1050. typedef struct {
  1051. glyphInfo_t glyphs [GLYPHS_PER_FONT];
  1052. float glyphScale;
  1053. char name[MAX_QPATH];
  1054. } fontInfo_t;
  1055. #define Square(x) ((x)*(x))
  1056. // real time
  1057. //=============================================
  1058. typedef struct qtime_s {
  1059. int tm_sec; /* seconds after the minute - [0,59] */
  1060. int tm_min; /* minutes after the hour - [0,59] */
  1061. int tm_hour; /* hours since midnight - [0,23] */
  1062. int tm_mday; /* day of the month - [1,31] */
  1063. int tm_mon; /* months since January - [0,11] */
  1064. int tm_year; /* years since 1900 */
  1065. int tm_wday; /* days since Sunday - [0,6] */
  1066. int tm_yday; /* days since January 1 - [0,365] */
  1067. int tm_isdst; /* daylight savings time flag */
  1068. } qtime_t;
  1069. // server browser sources
  1070. // TTimo: AS_MPLAYER is no longer used
  1071. #define AS_LOCAL 0
  1072. #define AS_MPLAYER 1
  1073. #define AS_GLOBAL 2
  1074. #define AS_FAVORITES 3
  1075. // cinematic states
  1076. typedef enum {
  1077. FMV_IDLE,
  1078. FMV_PLAY, // play
  1079. FMV_EOF, // all other conditions, i.e. stop/EOF/abort
  1080. FMV_ID_BLT,
  1081. FMV_ID_IDLE,
  1082. FMV_LOOPED,
  1083. FMV_ID_WAIT
  1084. } e_status;
  1085. typedef enum _flag_status {
  1086. FLAG_ATBASE = 0,
  1087. FLAG_TAKEN, // CTF
  1088. FLAG_TAKEN_RED, // One Flag CTF
  1089. FLAG_TAKEN_BLUE, // One Flag CTF
  1090. FLAG_DROPPED
  1091. } flagStatus_t;
  1092. #define MAX_GLOBAL_SERVERS 4096
  1093. #define MAX_OTHER_SERVERS 128
  1094. #define MAX_PINGREQUESTS 32
  1095. #define MAX_SERVERSTATUSREQUESTS 16
  1096. #define SAY_ALL 0
  1097. #define SAY_TEAM 1
  1098. #define SAY_TELL 2
  1099. #define CDKEY_LEN 16
  1100. #define CDCHKSUM_LEN 2
  1101. #endif // __Q_SHARED_H