qfiles.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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 relative 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. md4Bone_t bones[1]; // [numBones]
  206. } md4Frame_t;
  207. typedef struct {
  208. int numSurfaces;
  209. int ofsSurfaces; // first surface, others follow
  210. int ofsEnd; // next lod follows
  211. } md4LOD_t;
  212. typedef struct {
  213. int ident;
  214. int version;
  215. char name[MAX_QPATH]; // model name
  216. // frames and bones are shared by all levels of detail
  217. int numFrames;
  218. int numBones;
  219. int ofsBoneNames; // char name[ MAX_QPATH ]
  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. #define MAX_WORLD_COORD ( 128*1024 )
  265. #define MIN_WORLD_COORD ( -128*1024 )
  266. #define WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD )
  267. //=============================================================================
  268. typedef struct {
  269. int fileofs, filelen;
  270. } lump_t;
  271. #define LUMP_ENTITIES 0
  272. #define LUMP_SHADERS 1
  273. #define LUMP_PLANES 2
  274. #define LUMP_NODES 3
  275. #define LUMP_LEAFS 4
  276. #define LUMP_LEAFSURFACES 5
  277. #define LUMP_LEAFBRUSHES 6
  278. #define LUMP_MODELS 7
  279. #define LUMP_BRUSHES 8
  280. #define LUMP_BRUSHSIDES 9
  281. #define LUMP_DRAWVERTS 10
  282. #define LUMP_DRAWINDEXES 11
  283. #define LUMP_FOGS 12
  284. #define LUMP_SURFACES 13
  285. #define LUMP_LIGHTMAPS 14
  286. #define LUMP_LIGHTGRID 15
  287. #define LUMP_VISIBILITY 16
  288. #define HEADER_LUMPS 17
  289. typedef struct {
  290. int ident;
  291. int version;
  292. lump_t lumps[HEADER_LUMPS];
  293. } dheader_t;
  294. typedef struct {
  295. float mins[3], maxs[3];
  296. int firstSurface, numSurfaces;
  297. int firstBrush, numBrushes;
  298. } dmodel_t;
  299. typedef struct {
  300. char shader[MAX_QPATH];
  301. int surfaceFlags;
  302. int contentFlags;
  303. } dshader_t;
  304. // planes x^1 is allways the opposite of plane x
  305. typedef struct {
  306. float normal[3];
  307. float dist;
  308. } dplane_t;
  309. typedef struct {
  310. int planeNum;
  311. int children[2]; // negative numbers are -(leafs+1), not nodes
  312. int mins[3]; // for frustom culling
  313. int maxs[3];
  314. } dnode_t;
  315. typedef struct {
  316. int cluster; // -1 = opaque cluster (do I still store these?)
  317. int area;
  318. int mins[3]; // for frustum culling
  319. int maxs[3];
  320. int firstLeafSurface;
  321. int numLeafSurfaces;
  322. int firstLeafBrush;
  323. int numLeafBrushes;
  324. } dleaf_t;
  325. typedef struct {
  326. int planeNum; // positive plane side faces out of the leaf
  327. int shaderNum;
  328. } dbrushside_t;
  329. typedef struct {
  330. int firstSide;
  331. int numSides;
  332. int shaderNum; // the shader that determines the contents flags
  333. } dbrush_t;
  334. typedef struct {
  335. char shader[MAX_QPATH];
  336. int brushNum;
  337. int visibleSide; // the brush side that ray tests need to clip against (-1 == none)
  338. } dfog_t;
  339. typedef struct {
  340. vec3_t xyz;
  341. float st[2];
  342. float lightmap[2];
  343. vec3_t normal;
  344. byte color[4];
  345. } drawVert_t;
  346. typedef enum {
  347. MST_BAD,
  348. MST_PLANAR,
  349. MST_PATCH,
  350. MST_TRIANGLE_SOUP,
  351. MST_FLARE
  352. } mapSurfaceType_t;
  353. typedef struct {
  354. int shaderNum;
  355. int fogNum;
  356. int surfaceType;
  357. int firstVert;
  358. int numVerts;
  359. int firstIndex;
  360. int numIndexes;
  361. int lightmapNum;
  362. int lightmapX, lightmapY;
  363. int lightmapWidth, lightmapHeight;
  364. vec3_t lightmapOrigin;
  365. vec3_t lightmapVecs[3]; // for patches, [0] and [1] are lodbounds
  366. int patchWidth;
  367. int patchHeight;
  368. } dsurface_t;
  369. #endif