qfiles.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. #ifndef __QFILES_H__
  2. #define __QFILES_H__
  3. //
  4. // qfiles.h: quake file formats
  5. // This file must be identical in the quake and utils directories
  6. //
  7. // surface geometry should not exceed these limits
  8. #define SHADER_MAX_VERTEXES 1000
  9. #define SHADER_MAX_INDEXES (6*SHADER_MAX_VERTEXES)
  10. // the maximum size of game reletive pathnames
  11. #define MAX_QPATH 64
  12. /*
  13. ========================================================================
  14. QVM files
  15. ========================================================================
  16. */
  17. #define VM_MAGIC 0x12721444
  18. typedef struct {
  19. int vmMagic;
  20. int instructionCount;
  21. int codeOffset;
  22. int codeLength;
  23. int dataOffset;
  24. int dataLength;
  25. int litLength; // ( dataLength - litLength ) should be byteswapped on load
  26. int bssLength; // zero filled memory appended to datalength
  27. } vmHeader_t;
  28. /*
  29. ========================================================================
  30. PCX files are used for 8 bit images
  31. ========================================================================
  32. */
  33. typedef struct {
  34. char manufacturer;
  35. char version;
  36. char encoding;
  37. char bits_per_pixel;
  38. unsigned short xmin,ymin,xmax,ymax;
  39. unsigned short hres,vres;
  40. unsigned char palette[48];
  41. char reserved;
  42. char color_planes;
  43. unsigned short bytes_per_line;
  44. unsigned short palette_type;
  45. char filler[58];
  46. unsigned char data; // unbounded
  47. } pcx_t;
  48. /*
  49. ========================================================================
  50. TGA files are used for 24/32 bit images
  51. ========================================================================
  52. */
  53. typedef struct _TargaHeader {
  54. unsigned char id_length, colormap_type, image_type;
  55. unsigned short colormap_index, colormap_length;
  56. unsigned char colormap_size;
  57. unsigned short x_origin, y_origin, width, height;
  58. unsigned char pixel_size, attributes;
  59. } TargaHeader;
  60. /*
  61. ========================================================================
  62. .MD3 triangle model file format
  63. ========================================================================
  64. */
  65. #define MD3_IDENT (('3'<<24)+('P'<<16)+('D'<<8)+'I')
  66. #define MD3_VERSION 15
  67. // limits
  68. #define MD3_MAX_LODS 3
  69. #define MD3_MAX_TRIANGLES 8192 // per surface
  70. #define MD3_MAX_VERTS 4096 // per surface
  71. #define MD3_MAX_SHADERS 256 // per surface
  72. #define MD3_MAX_FRAMES 1024 // per model
  73. #define MD3_MAX_SURFACES 32 + 32 // per model
  74. #define MD3_MAX_TAGS 16 // per frame
  75. // vertex scales
  76. #define MD3_XYZ_SCALE (1.0/64)
  77. typedef struct md3Frame_s {
  78. vec3_t bounds[2];
  79. vec3_t localOrigin;
  80. float radius;
  81. char name[16];
  82. } md3Frame_t;
  83. typedef struct md3Tag_s {
  84. char name[MAX_QPATH]; // tag name
  85. vec3_t origin;
  86. vec3_t axis[3];
  87. } md3Tag_t;
  88. /*
  89. ** md3Surface_t
  90. **
  91. ** CHUNK SIZE
  92. ** header sizeof( md3Surface_t )
  93. ** shaders sizeof( md3Shader_t ) * numShaders
  94. ** triangles[0] sizeof( md3Triangle_t ) * numTriangles
  95. ** st sizeof( md3St_t ) * numVerts
  96. ** XyzNormals sizeof( md3XyzNormal_t ) * numVerts * numFrames
  97. */
  98. typedef struct {
  99. int ident; //
  100. char name[MAX_QPATH]; // polyset name
  101. int flags;
  102. int numFrames; // all surfaces in a model should have the same
  103. int numShaders; // all surfaces in a model should have the same
  104. int numVerts;
  105. int numTriangles;
  106. int ofsTriangles;
  107. int ofsShaders; // offset from start of md3Surface_t
  108. int ofsSt; // texture coords are common for all frames
  109. int ofsXyzNormals; // numVerts * numFrames
  110. int ofsEnd; // next surface follows
  111. } md3Surface_t;
  112. typedef struct {
  113. char name[MAX_QPATH];
  114. int shaderIndex; // for in-game use
  115. } md3Shader_t;
  116. typedef struct {
  117. int indexes[3];
  118. } md3Triangle_t;
  119. typedef struct {
  120. float st[2];
  121. } md3St_t;
  122. typedef struct {
  123. short xyz[3];
  124. short normal;
  125. } md3XyzNormal_t;
  126. typedef struct {
  127. int ident;
  128. int version;
  129. char name[MAX_QPATH]; // model name
  130. int flags;
  131. int numFrames;
  132. int numTags;
  133. int numSurfaces;
  134. int numSkins;
  135. int ofsFrames; // offset for first frame
  136. int ofsTags; // numFrames * numTags
  137. int ofsSurfaces; // first surface, others follow
  138. int ofsEnd; // end of file
  139. } md3Header_t;
  140. /*
  141. ==============================================================================
  142. .BSP file format
  143. ==============================================================================
  144. */
  145. #define BSP_IDENT (('P'<<24)+('S'<<16)+('B'<<8)+'R')
  146. // little-endian "IBSP"
  147. #define BSP_VERSION 1
  148. // there shouldn't be any problem with increasing these values at the
  149. // expense of more memory allocation in the utilities
  150. #define MAX_MAP_MODELS 0x400
  151. #define MAX_MAP_BRUSHES 0x8000
  152. #define MAX_MAP_ENTITIES 0x800
  153. #define MAX_MAP_ENTSTRING 0x40000
  154. #define MAX_MAP_SHADERS 0x400
  155. #define MAX_MAP_AREAS 0x100 // MAX_MAP_AREA_BYTES in q_shared must match!
  156. #define MAX_MAP_FOGS 0x100
  157. #define MAX_MAP_PLANES 0x20000
  158. #define MAX_MAP_NODES 0x20000
  159. #define MAX_MAP_BRUSHSIDES 0x20000
  160. #define MAX_MAP_LEAFS 0x20000
  161. #define MAX_MAP_LEAFFACES 0x20000
  162. #define MAX_MAP_LEAFBRUSHES 0x40000
  163. #define MAX_MAP_PORTALS 0x20000
  164. #define MAX_MAP_LIGHTING 0x800000
  165. #define MAX_MAP_LIGHTGRID 65535
  166. #define MAX_MAP_LIGHTGRID_ARRAY 0x100000
  167. #define MAX_MAP_VISIBILITY 0x400000
  168. #define MAX_MAP_DRAW_SURFS 0x20000
  169. #define MAX_MAP_DRAW_VERTS 0x80000
  170. #define MAX_MAP_DRAW_INDEXES 0x80000
  171. // key / value pair sizes in the entities lump
  172. #define MAX_KEY 32
  173. #define MAX_VALUE 1024
  174. // the editor uses these predefined yaw angles to orient entities up or down
  175. #define ANGLE_UP -1
  176. #define ANGLE_DOWN -2
  177. #define LIGHTMAP_WIDTH 128
  178. #define LIGHTMAP_HEIGHT 128
  179. //=============================================================================
  180. #ifdef _XBOX
  181. #pragma pack(push, 1)
  182. typedef struct {
  183. float mins[3], maxs[3];
  184. int firstSurface;
  185. unsigned short numSurfaces;
  186. int firstBrush;
  187. unsigned short numBrushes;
  188. } dmodel_t;
  189. typedef struct {
  190. char shader[MAX_QPATH];
  191. int surfaceFlags;
  192. int contentFlags;
  193. } dshader_t;
  194. // planes x^1 is allways the opposite of plane x
  195. typedef struct {
  196. float normal[3];
  197. float dist;
  198. } dplane_t;
  199. typedef struct {
  200. int planeNum;
  201. short children[2]; // negative numbers are -(leafs+1), not nodes
  202. short mins[3]; // for frustom culling
  203. short maxs[3];
  204. } dnode_t;
  205. typedef struct {
  206. short cluster; // -1 = opaque cluster (do I still store these?)
  207. signed char area;
  208. short mins[3]; // for frustum culling
  209. short maxs[3];
  210. unsigned short firstLeafSurface;
  211. unsigned short numLeafSurfaces;
  212. unsigned short firstLeafBrush;
  213. unsigned short numLeafBrushes;
  214. } dleaf_t;
  215. typedef struct {
  216. int planeNum; // positive plane side faces out of the leaf
  217. byte shaderNum;
  218. } dbrushside_t;
  219. typedef struct {
  220. int firstSide;
  221. byte numSides;
  222. unsigned short shaderNum; // the shader that determines the contents flags
  223. } dbrush_t;
  224. typedef struct {
  225. char shader[MAX_QPATH];
  226. int brushNum;
  227. int visibleSide; // the brush side that ray tests need to clip against (-1 == none)
  228. } dfog_t;
  229. // Light Style Constants
  230. #define MAXLIGHTMAPS 4
  231. #define LS_NORMAL 0x00
  232. #define LS_UNUSED 0xfe
  233. #define LS_NONE 0xff
  234. #define MAX_LIGHT_STYLES 64
  235. typedef struct {
  236. float lightmap[MAXLIGHTMAPS][2];
  237. float st[2];
  238. short xyz[3];
  239. short normal[3];
  240. byte color[MAXLIGHTMAPS][4];
  241. } mapVert_t;
  242. #define DRAWVERT_LIGHTMAP_SCALE 32768.0f
  243. // Change texture coordinates for TriSurfs to be even more fine grain.
  244. // See below for note about keeping MIN_ST and MAX_ST up to date with
  245. // ST_SCALE. These are in 4.12. Okay, how about 5.11? Gah. 9.7!
  246. //#define DRAWVERT_ST_SCALE 4096.0f
  247. //#define DRAWVERT_ST_SCALE 2048.0f
  248. #define DRAWVERT_ST_SCALE 128.0f
  249. // We use a slightly different format for the fixed point texture
  250. // coords in Grid/Mesh drawverts: 10.6 rather than 12.4
  251. // To be sure that this is ok, keep the max and min values equal to
  252. // the largest and smallest whole numbers that can be stored using the
  253. // format. (ie: Don't change GRID_DRAWVERT_ST_SCALE without changing
  254. // the other two!) (And don't forget that we're using a bit for sign.)
  255. #define GRID_DRAWVERT_ST_SCALE 64.0f
  256. // This master switch controls whether we use compressed (4-bit per channel)
  257. // vertex colors in draw and surface verts. It saves memory, but I'm switching
  258. // it off, because we end up with that nasty green/purple streaking effect.
  259. // If we ever figure out how to do it better... (1555? 565?)
  260. //#define COMPRESS_VERTEX_COLORS
  261. typedef struct {
  262. short xyz[3];
  263. short dvst[2];
  264. short dvlightmap[MAXLIGHTMAPS][2];
  265. short normal[3];
  266. #ifdef _XBOX
  267. vec3_t tangent;
  268. #endif
  269. #ifdef COMPRESS_VERTEX_COLORS
  270. byte dvcolor[MAXLIGHTMAPS][1];
  271. #else
  272. byte dvcolor[MAXLIGHTMAPS][4];
  273. #endif
  274. } drawVert_t;
  275. typedef struct {
  276. byte flags;
  277. byte latLong[2];
  278. } dgrid_t;
  279. typedef struct {
  280. int code;
  281. byte shaderNum;
  282. signed char fogNum;
  283. unsigned int verts; // high 20 bits are first vert, low 12 are num verts
  284. unsigned int indexes; // high 20 bits are first index, low 12 are num indices
  285. byte lightmapStyles[MAXLIGHTMAPS];
  286. byte lightmapNum[MAXLIGHTMAPS];
  287. short lightmapVecs[3];
  288. } dface_t;
  289. typedef struct {
  290. int code;
  291. byte shaderNum;
  292. signed char fogNum;
  293. unsigned int verts; // high 20 bits are first vert, low 12 are num verts
  294. byte lightmapStyles[MAXLIGHTMAPS];
  295. byte lightmapNum[MAXLIGHTMAPS];
  296. short lightmapVecs[2][3]; // for patches, [0] and [1] are lodbounds
  297. byte patchWidth;
  298. byte patchHeight;
  299. } dpatch_t;
  300. typedef struct {
  301. int code;
  302. byte shaderNum;
  303. signed char fogNum;
  304. unsigned int verts; // high 20 bits are first vert, low 12 are num verts
  305. unsigned int indexes; // high 20 bits are first index, low 12 are num indices
  306. byte lightmapStyles[MAXLIGHTMAPS];
  307. } dtrisurf_t;
  308. typedef struct {
  309. int code;
  310. byte shaderNum;
  311. signed char fogNum;
  312. short origin[3];
  313. short normal[3];
  314. byte color[3];
  315. } dflare_t;
  316. #pragma pack(pop)
  317. #else // _XBOX
  318. typedef struct {
  319. int fileofs, filelen;
  320. } lump_t;
  321. #define LUMP_ENTITIES 0
  322. #define LUMP_SHADERS 1
  323. #define LUMP_PLANES 2
  324. #define LUMP_NODES 3
  325. #define LUMP_LEAFS 4
  326. #define LUMP_LEAFSURFACES 5
  327. #define LUMP_LEAFBRUSHES 6
  328. #define LUMP_MODELS 7
  329. #define LUMP_BRUSHES 8
  330. #define LUMP_BRUSHSIDES 9
  331. #define LUMP_DRAWVERTS 10
  332. #define LUMP_DRAWINDEXES 11
  333. #define LUMP_FOGS 12
  334. #define LUMP_SURFACES 13
  335. #define LUMP_LIGHTMAPS 14
  336. #define LUMP_LIGHTGRID 15
  337. #define LUMP_VISIBILITY 16
  338. #define LUMP_LIGHTARRAY 17
  339. #define HEADER_LUMPS 18
  340. typedef struct {
  341. int ident;
  342. int version;
  343. lump_t lumps[HEADER_LUMPS];
  344. } dheader_t;
  345. typedef struct {
  346. float mins[3], maxs[3];
  347. int firstSurface, numSurfaces;
  348. int firstBrush, numBrushes;
  349. } dmodel_t;
  350. typedef struct dshader_s {
  351. char shader[MAX_QPATH];
  352. int surfaceFlags;
  353. int contentFlags;
  354. } dshader_t;
  355. // planes x^1 is allways the opposite of plane x
  356. typedef struct {
  357. float normal[3];
  358. float dist;
  359. } dplane_t;
  360. typedef struct {
  361. int planeNum;
  362. int children[2]; // negative numbers are -(leafs+1), not nodes
  363. int mins[3]; // for frustom culling
  364. int maxs[3];
  365. } dnode_t;
  366. typedef struct {
  367. int cluster; // -1 = opaque cluster (do I still store these?)
  368. int area;
  369. int mins[3]; // for frustum culling
  370. int maxs[3];
  371. int firstLeafSurface;
  372. int numLeafSurfaces;
  373. int firstLeafBrush;
  374. int numLeafBrushes;
  375. } dleaf_t;
  376. typedef struct {
  377. int planeNum; // positive plane side faces out of the leaf
  378. int shaderNum;
  379. int drawSurfNum;
  380. } dbrushside_t;
  381. typedef struct {
  382. int firstSide;
  383. int numSides;
  384. int shaderNum; // the shader that determines the contents flags
  385. } dbrush_t;
  386. typedef struct {
  387. char shader[MAX_QPATH];
  388. int brushNum;
  389. int visibleSide; // the brush side that ray tests need to clip against (-1 == none)
  390. } dfog_t;
  391. // Light Style Constants
  392. #define MAXLIGHTMAPS 4
  393. #define LS_NORMAL 0x00
  394. #define LS_UNUSED 0xfe
  395. #define LS_NONE 0xff
  396. #define MAX_LIGHT_STYLES 64
  397. typedef struct {
  398. vec3_t xyz;
  399. float st[2];
  400. float lightmap[MAXLIGHTMAPS][2];
  401. vec3_t normal;
  402. byte color[MAXLIGHTMAPS][4];
  403. } mapVert_t;
  404. typedef struct {
  405. vec3_t xyz;
  406. float st[2];
  407. float lightmap[MAXLIGHTMAPS][2];
  408. vec3_t normal;
  409. byte color[MAXLIGHTMAPS][4];
  410. } drawVert_t;
  411. typedef struct
  412. {
  413. byte ambientLight[MAXLIGHTMAPS][3];
  414. byte directLight[MAXLIGHTMAPS][3];
  415. byte styles[MAXLIGHTMAPS];
  416. byte latLong[2];
  417. } dgrid_t;
  418. typedef enum {
  419. MST_BAD,
  420. MST_PLANAR,
  421. MST_PATCH,
  422. MST_TRIANGLE_SOUP,
  423. MST_FLARE
  424. } mapSurfaceType_t;
  425. typedef struct {
  426. int shaderNum;
  427. int fogNum;
  428. int surfaceType;
  429. int firstVert;
  430. int numVerts;
  431. int firstIndex;
  432. int numIndexes;
  433. byte lightmapStyles[MAXLIGHTMAPS], vertexStyles[MAXLIGHTMAPS];
  434. int lightmapNum[MAXLIGHTMAPS];
  435. int lightmapX[MAXLIGHTMAPS], lightmapY[MAXLIGHTMAPS];
  436. int lightmapWidth, lightmapHeight;
  437. vec3_t lightmapOrigin;
  438. vec3_t lightmapVecs[3]; // for patches, [0] and [1] are lodbounds
  439. int patchWidth;
  440. int patchHeight;
  441. } dsurface_t;
  442. #endif _XBOX
  443. typedef enum //# hunkAllocType_e
  444. {
  445. HA_MISC,
  446. HA_MAP,
  447. HA_SHADERS,
  448. HA_LIGHTING,
  449. HA_FOG,
  450. HA_PATCHES,
  451. HA_VIS,
  452. HA_SUBMODELS,
  453. HA_MODELS,
  454. MAX_HA_TYPES
  455. } hunkAllocType_t;
  456. /////////////////////////////////////////////////////////////
  457. //
  458. // Defines and structures required for fonts
  459. #define GLYPH_COUNT 256
  460. // Must match define in stmparse.h
  461. #define STYLE_DROPSHADOW 0x80000000
  462. #define STYLE_BLINK 0x40000000
  463. #define SET_MASK 0x00ffffff
  464. typedef struct
  465. {
  466. short width; // number of pixels wide
  467. short height; // number of scan lines
  468. short horizAdvance; // number of pixels to advance to the next char
  469. short horizOffset; // x offset into space to render glyph
  470. int baseline; // y offset
  471. float s; // x start tex coord
  472. float t; // y start tex coord
  473. float s2; // x end tex coord
  474. float t2; // y end tex coord
  475. } glyphInfo_t;
  476. // this file corresponds 1:1 with the "*.fontdat" files, so don't change it unless you're going to
  477. // recompile the fontgen util and regenerate all the fonts!
  478. //
  479. typedef struct dfontdat_s
  480. {
  481. glyphInfo_t mGlyphs[GLYPH_COUNT];
  482. short mPointSize;
  483. short mHeight; // max height of font
  484. short mAscender;
  485. short mDescender;
  486. short mKoreanHack; // unused field, written out by John's fontgen program but we have to leave it there for disk structs <sigh>
  487. } dfontdat_t;
  488. /////////////////// fonts end ////////////////////////////////////
  489. #endif