qfiles.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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 __QFILES_H__
  19. #define __QFILES_H__
  20. //
  21. // qfiles.h: quake file formats
  22. // This file must be identical in the quake and utils directories
  23. //
  24. // surface geometry should not exceed these limits
  25. #define SHADER_MAX_VERTEXES 1000
  26. #define SHADER_MAX_INDEXES (6*SHADER_MAX_VERTEXES)
  27. // the maximum size of game reletive pathnames
  28. #define MAX_QPATH 64
  29. /*
  30. ========================================================================
  31. QVM files
  32. ========================================================================
  33. */
  34. #define VM_MAGIC 0x12721444
  35. typedef struct {
  36. int vmMagic;
  37. int instructionCount;
  38. int codeOffset;
  39. int codeLength;
  40. int dataOffset;
  41. int dataLength;
  42. int litLength; // ( dataLength - litLength ) should be byteswapped on load
  43. int bssLength; // zero filled memory appended to datalength
  44. } vmHeader_t;
  45. /*
  46. ========================================================================
  47. PCX files are used for 8 bit images
  48. ========================================================================
  49. */
  50. typedef struct {
  51. char manufacturer;
  52. char version;
  53. char encoding;
  54. char bits_per_pixel;
  55. unsigned short xmin,ymin,xmax,ymax;
  56. unsigned short hres,vres;
  57. unsigned char palette[48];
  58. char reserved;
  59. char color_planes;
  60. unsigned short bytes_per_line;
  61. unsigned short palette_type;
  62. char filler[58];
  63. unsigned char data; // unbounded
  64. } pcx_t;
  65. /*
  66. ========================================================================
  67. TGA files are used for 24/32 bit images
  68. ========================================================================
  69. */
  70. typedef struct _TargaHeader {
  71. unsigned char id_length, colormap_type, image_type;
  72. unsigned short colormap_index, colormap_length;
  73. unsigned char colormap_size;
  74. unsigned short x_origin, y_origin, width, height;
  75. unsigned char pixel_size, attributes;
  76. } TargaHeader;
  77. /*
  78. ========================================================================
  79. .MD3 triangle model file format
  80. ========================================================================
  81. */
  82. #define MD3_IDENT (('3'<<24)+('P'<<16)+('D'<<8)+'I')
  83. #define MD3_VERSION 15
  84. // limits
  85. #define MD3_MAX_LODS 3
  86. #define MD3_MAX_TRIANGLES 8192 // per surface
  87. #define MD3_MAX_VERTS 4096 // per surface
  88. #define MD3_MAX_SHADERS 256 // per surface
  89. #define MD3_MAX_FRAMES 1024 // per model
  90. #define MD3_MAX_SURFACES 32 // per model
  91. #define MD3_MAX_TAGS 16 // per frame
  92. // vertex scales
  93. #define MD3_XYZ_SCALE (1.0/64)
  94. typedef struct md3Frame_s {
  95. vec3_t bounds[2];
  96. vec3_t localOrigin;
  97. float radius;
  98. char name[16];
  99. } md3Frame_t;
  100. typedef struct md3Tag_s {
  101. char name[MAX_QPATH]; // tag name
  102. vec3_t origin;
  103. vec3_t axis[3];
  104. } md3Tag_t;
  105. /*
  106. ** md3Surface_t
  107. **
  108. ** CHUNK SIZE
  109. ** header sizeof( md3Surface_t )
  110. ** shaders sizeof( md3Shader_t ) * numShaders
  111. ** triangles[0] sizeof( md3Triangle_t ) * numTriangles
  112. ** st sizeof( md3St_t ) * numVerts
  113. ** XyzNormals sizeof( md3XyzNormal_t ) * numVerts * numFrames
  114. */
  115. typedef struct {
  116. int ident; //
  117. char name[MAX_QPATH]; // polyset name
  118. int flags;
  119. int numFrames; // all surfaces in a model should have the same
  120. int numShaders; // all surfaces in a model should have the same
  121. int numVerts;
  122. int numTriangles;
  123. int ofsTriangles;
  124. int ofsShaders; // offset from start of md3Surface_t
  125. int ofsSt; // texture coords are common for all frames
  126. int ofsXyzNormals; // numVerts * numFrames
  127. int ofsEnd; // next surface follows
  128. } md3Surface_t;
  129. typedef struct {
  130. char name[MAX_QPATH];
  131. int shaderIndex; // for in-game use
  132. } md3Shader_t;
  133. typedef struct {
  134. int indexes[3];
  135. } md3Triangle_t;
  136. typedef struct {
  137. float st[2];
  138. } md3St_t;
  139. typedef struct {
  140. short xyz[3];
  141. short normal;
  142. } md3XyzNormal_t;
  143. typedef struct {
  144. int ident;
  145. int version;
  146. char name[MAX_QPATH]; // model name
  147. int flags;
  148. int numFrames;
  149. int numTags;
  150. int numSurfaces;
  151. int numSkins;
  152. int ofsFrames; // offset for first frame
  153. int ofsTags; // numFrames * numTags
  154. int ofsSurfaces; // first surface, others follow
  155. int ofsEnd; // end of file
  156. } md3Header_t;
  157. /*
  158. ==============================================================================
  159. MD4 file format
  160. ==============================================================================
  161. */
  162. #define MD4_IDENT (('4'<<24)+('P'<<16)+('D'<<8)+'I')
  163. #define MD4_VERSION 1
  164. #define MD4_MAX_BONES 128
  165. typedef struct {
  166. int boneIndex; // these are indexes into the boneReferences,
  167. float boneWeight; // not the global per-frame bone list
  168. vec3_t offset;
  169. } md4Weight_t;
  170. typedef struct {
  171. vec3_t normal;
  172. vec2_t texCoords;
  173. int numWeights;
  174. md4Weight_t weights[1]; // variable sized
  175. } md4Vertex_t;
  176. typedef struct {
  177. int indexes[3];
  178. } md4Triangle_t;
  179. typedef struct {
  180. int ident;
  181. char name[MAX_QPATH]; // polyset name
  182. char shader[MAX_QPATH];
  183. int shaderIndex; // for in-game use
  184. int ofsHeader; // this will be a negative number
  185. int numVerts;
  186. int ofsVerts;
  187. int numTriangles;
  188. int ofsTriangles;
  189. // Bone references are a set of ints representing all the bones
  190. // present in any vertex weights for this surface. This is
  191. // needed because a model may have surfaces that need to be
  192. // drawn at different sort times, and we don't want to have
  193. // to re-interpolate all the bones for each surface.
  194. int numBoneReferences;
  195. int ofsBoneReferences;
  196. int ofsEnd; // next surface follows
  197. } md4Surface_t;
  198. typedef struct {
  199. float matrix[3][4];
  200. } md4Bone_t;
  201. typedef struct {
  202. vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame
  203. vec3_t localOrigin; // midpoint of bounds, used for sphere cull
  204. float radius; // dist from localOrigin to corner
  205. char name[16];
  206. md4Bone_t bones[1]; // [numBones]
  207. } md4Frame_t;
  208. typedef struct {
  209. int numSurfaces;
  210. int ofsSurfaces; // first surface, others follow
  211. int ofsEnd; // next lod follows
  212. } md4LOD_t;
  213. typedef struct {
  214. int ident;
  215. int version;
  216. char name[MAX_QPATH]; // model name
  217. // frames and bones are shared by all levels of detail
  218. int numFrames;
  219. int numBones;
  220. int ofsFrames; // md4Frame_t[numFrames]
  221. // each level of detail has completely separate sets of surfaces
  222. int numLODs;
  223. int ofsLODs;
  224. int ofsEnd; // end of file
  225. } md4Header_t;
  226. /*
  227. ==============================================================================
  228. .BSP file format
  229. ==============================================================================
  230. */
  231. #define BSP_IDENT (('P'<<24)+('S'<<16)+('B'<<8)+'I')
  232. // little-endian "IBSP"
  233. #define BSP_VERSION 46
  234. // there shouldn't be any problem with increasing these values at the
  235. // expense of more memory allocation in the utilities
  236. #define MAX_MAP_MODELS 0x400
  237. #define MAX_MAP_BRUSHES 0x8000
  238. #define MAX_MAP_ENTITIES 0x800
  239. #define MAX_MAP_ENTSTRING 0x40000
  240. #define MAX_MAP_SHADERS 0x400
  241. #define MAX_MAP_AREAS 0x100 // MAX_MAP_AREA_BYTES in q_shared must match!
  242. #define MAX_MAP_FOGS 0x100
  243. #define MAX_MAP_PLANES 0x20000
  244. #define MAX_MAP_NODES 0x20000
  245. #define MAX_MAP_BRUSHSIDES 0x20000
  246. #define MAX_MAP_LEAFS 0x20000
  247. #define MAX_MAP_LEAFFACES 0x20000
  248. #define MAX_MAP_LEAFBRUSHES 0x40000
  249. #define MAX_MAP_PORTALS 0x20000
  250. #define MAX_MAP_LIGHTING 0x800000
  251. #define MAX_MAP_LIGHTGRID 0x800000
  252. #define MAX_MAP_VISIBILITY 0x200000
  253. #define MAX_MAP_DRAW_SURFS 0x20000
  254. #define MAX_MAP_DRAW_VERTS 0x80000
  255. #define MAX_MAP_DRAW_INDEXES 0x80000
  256. // key / value pair sizes in the entities lump
  257. #define MAX_KEY 32
  258. #define MAX_VALUE 1024
  259. // the editor uses these predefined yaw angles to orient entities up or down
  260. #define ANGLE_UP -1
  261. #define ANGLE_DOWN -2
  262. #define LIGHTMAP_WIDTH 128
  263. #define LIGHTMAP_HEIGHT 128
  264. //=============================================================================
  265. typedef struct {
  266. int fileofs, filelen;
  267. } lump_t;
  268. #define LUMP_ENTITIES 0
  269. #define LUMP_SHADERS 1
  270. #define LUMP_PLANES 2
  271. #define LUMP_NODES 3
  272. #define LUMP_LEAFS 4
  273. #define LUMP_LEAFSURFACES 5
  274. #define LUMP_LEAFBRUSHES 6
  275. #define LUMP_MODELS 7
  276. #define LUMP_BRUSHES 8
  277. #define LUMP_BRUSHSIDES 9
  278. #define LUMP_DRAWVERTS 10
  279. #define LUMP_DRAWINDEXES 11
  280. #define LUMP_FOGS 12
  281. #define LUMP_SURFACES 13
  282. #define LUMP_LIGHTMAPS 14
  283. #define LUMP_LIGHTGRID 15
  284. #define LUMP_VISIBILITY 16
  285. #define HEADER_LUMPS 17
  286. typedef struct {
  287. int ident;
  288. int version;
  289. lump_t lumps[HEADER_LUMPS];
  290. } dheader_t;
  291. typedef struct {
  292. float mins[3], maxs[3];
  293. int firstSurface, numSurfaces;
  294. int firstBrush, numBrushes;
  295. } dmodel_t;
  296. typedef struct {
  297. char shader[MAX_QPATH];
  298. int surfaceFlags;
  299. int contentFlags;
  300. } dshader_t;
  301. // planes x^1 is allways the opposite of plane x
  302. typedef struct {
  303. float normal[3];
  304. float dist;
  305. } dplane_t;
  306. typedef struct {
  307. int planeNum;
  308. int children[2]; // negative numbers are -(leafs+1), not nodes
  309. int mins[3]; // for frustom culling
  310. int maxs[3];
  311. } dnode_t;
  312. typedef struct {
  313. int cluster; // -1 = opaque cluster (do I still store these?)
  314. int area;
  315. int mins[3]; // for frustum culling
  316. int maxs[3];
  317. int firstLeafSurface;
  318. int numLeafSurfaces;
  319. int firstLeafBrush;
  320. int numLeafBrushes;
  321. } dleaf_t;
  322. typedef struct {
  323. int planeNum; // positive plane side faces out of the leaf
  324. int shaderNum;
  325. } dbrushside_t;
  326. typedef struct {
  327. int firstSide;
  328. int numSides;
  329. int shaderNum; // the shader that determines the contents flags
  330. } dbrush_t;
  331. typedef struct {
  332. char shader[MAX_QPATH];
  333. int brushNum;
  334. int visibleSide; // the brush side that ray tests need to clip against (-1 == none)
  335. } dfog_t;
  336. typedef struct {
  337. vec3_t xyz;
  338. float st[2];
  339. float lightmap[2];
  340. vec3_t normal;
  341. byte color[4];
  342. } drawVert_t;
  343. typedef enum {
  344. MST_BAD,
  345. MST_PLANAR,
  346. MST_PATCH,
  347. MST_TRIANGLE_SOUP,
  348. MST_FLARE
  349. } mapSurfaceType_t;
  350. typedef struct {
  351. int shaderNum;
  352. int fogNum;
  353. int surfaceType;
  354. int firstVert;
  355. int numVerts;
  356. int firstIndex;
  357. int numIndexes;
  358. int lightmapNum;
  359. int lightmapX, lightmapY;
  360. int lightmapWidth, lightmapHeight;
  361. vec3_t lightmapOrigin;
  362. vec3_t lightmapVecs[3]; // for patches, [0] and [1] are lodbounds
  363. int patchWidth;
  364. int patchHeight;
  365. } dsurface_t;
  366. #endif