codemp/qcommon/qfiles.h

Go to the documentation of this file.
00001 #ifndef __QFILES_H__
00002 #define __QFILES_H__
00003 
00004 //
00005 // qfiles.h: quake file formats
00006 // This file must be identical in the quake and utils directories
00007 //
00008 
00009 // surface geometry should not exceed these limits
00010 #define SHADER_MAX_VERTEXES     1000
00011 #define SHADER_MAX_INDEXES      (6*SHADER_MAX_VERTEXES)
00012 
00013 
00014 // the maximum size of game relative pathnames
00015 #define MAX_QPATH               64
00016 
00017 /*
00018 ========================================================================
00019 
00020 QVM files
00021 
00022 ========================================================================
00023 */
00024 
00025 #define VM_MAGIC        0x12721444
00026 typedef struct {
00027         int             vmMagic;
00028 
00029         int             instructionCount;
00030 
00031         int             codeOffset;
00032         int             codeLength;
00033 
00034         int             dataOffset;
00035         int             dataLength;
00036         int             litLength;                      // ( dataLength - litLength ) should be byteswapped on load
00037         int             bssLength;                      // zero filled memory appended to datalength
00038 } vmHeader_t;
00039 
00040 
00041 /*
00042 ========================================================================
00043 
00044 PCX files are used for 8 bit images
00045 
00046 ========================================================================
00047 */
00048 
00049 typedef struct {
00050     char        manufacturer;
00051     char        version;
00052     char        encoding;
00053     char        bits_per_pixel;
00054     unsigned short      xmin,ymin,xmax,ymax;
00055     unsigned short      hres,vres;
00056     unsigned char       palette[48];
00057     char        reserved;
00058     char        color_planes;
00059     unsigned short      bytes_per_line;
00060     unsigned short      palette_type;
00061     char        filler[58];
00062     unsigned char       data;                   // unbounded
00063 } pcx_t;
00064 
00065 
00066 /*
00067 ========================================================================
00068 
00069 TGA files are used for 24/32 bit images
00070 
00071 ========================================================================
00072 */
00073 
00074 typedef struct _TargaHeader {
00075         unsigned char   id_length, colormap_type, image_type;
00076         unsigned short  colormap_index, colormap_length;
00077         unsigned char   colormap_size;
00078         unsigned short  x_origin, y_origin, width, height;
00079         unsigned char   pixel_size, attributes;
00080 } TargaHeader;
00081 
00082 
00083 
00084 /*
00085 ========================================================================
00086 
00087 .MD3 triangle model file format
00088 
00089 ========================================================================
00090 */
00091 
00092 #define MD3_IDENT                       (('3'<<24)+('P'<<16)+('D'<<8)+'I')
00093 #define MD3_VERSION                     15
00094 
00095 // limits
00096 #define MD3_MAX_LODS            3
00097 #define MD3_MAX_TRIANGLES       8192    // per surface
00098 #define MD3_MAX_VERTS           4096    // per surface
00099 #define MD3_MAX_SHADERS         256             // per surface
00100 #define MD3_MAX_FRAMES          1024    // per model
00101 #define MD3_MAX_SURFACES        32 + 32 // per model
00102 #define MD3_MAX_TAGS            16              // per frame
00103 
00104 // vertex scales
00105 #define MD3_XYZ_SCALE           (1.0/64)
00106 
00107 typedef struct md3Frame_s {
00108         vec3_t          bounds[2];
00109         vec3_t          localOrigin;
00110         float           radius;
00111         char            name[16];
00112 } md3Frame_t;
00113 
00114 typedef struct md3Tag_s {
00115         char            name[MAX_QPATH];        // tag name
00116         vec3_t          origin;
00117         vec3_t          axis[3];
00118 } md3Tag_t;
00119 
00120 /*
00121 ** md3Surface_t
00122 **
00123 ** CHUNK                        SIZE
00124 ** header                       sizeof( md3Surface_t )
00125 ** shaders                      sizeof( md3Shader_t ) * numShaders
00126 ** triangles[0]         sizeof( md3Triangle_t ) * numTriangles
00127 ** st                           sizeof( md3St_t ) * numVerts
00128 ** XyzNormals           sizeof( md3XyzNormal_t ) * numVerts * numFrames
00129 */
00130 typedef struct {
00131         int             ident;                          // 
00132 
00133         char    name[MAX_QPATH];        // polyset name
00134 
00135         int             flags;
00136         int             numFrames;                      // all surfaces in a model should have the same
00137 
00138         int             numShaders;                     // all surfaces in a model should have the same
00139         int             numVerts;
00140 
00141         int             numTriangles;
00142         int             ofsTriangles;
00143 
00144         int             ofsShaders;                     // offset from start of md3Surface_t
00145         int             ofsSt;                          // texture coords are common for all frames
00146         int             ofsXyzNormals;          // numVerts * numFrames
00147 
00148         int             ofsEnd;                         // next surface follows
00149 } md3Surface_t;
00150 
00151 typedef struct {
00152         char                    name[MAX_QPATH];
00153         int                             shaderIndex;    // for in-game use
00154 } md3Shader_t;
00155 
00156 typedef struct {
00157         int                     indexes[3];
00158 } md3Triangle_t;
00159 
00160 typedef struct {
00161         float           st[2];
00162 } md3St_t;
00163 
00164 typedef struct {
00165         short           xyz[3];
00166         short           normal;
00167 } md3XyzNormal_t;
00168 
00169 typedef struct {
00170         int                     ident;
00171         int                     version;
00172 
00173         char            name[MAX_QPATH];        // model name
00174 
00175         int                     flags;
00176 
00177         int                     numFrames;
00178         int                     numTags;                        
00179         int                     numSurfaces;
00180 
00181         int                     numSkins;
00182 
00183         int                     ofsFrames;                      // offset for first frame
00184         int                     ofsTags;                        // numFrames * numTags
00185         int                     ofsSurfaces;            // first surface, others follow
00186 
00187         int                     ofsEnd;                         // end of file
00188 } md3Header_t;
00189 
00190 
00191 /*
00192 ==============================================================================
00193 
00194   .BSP file format
00195 
00196 ==============================================================================
00197 */
00198 
00199 
00200 // little-endian "RBSP"
00201 #define BSP_IDENT                               (('P'<<24)+('S'<<16)+('B'<<8)+'R')
00202 
00203 #define BSP_VERSION                             1
00204 
00205 
00206 // there shouldn't be any problem with increasing these values at the
00207 // expense of more memory allocation in the utilities
00208 #define MAX_MAP_MODELS                  0x400
00209 #define MAX_MAP_BRUSHES                 0x8000
00210 #define MAX_MAP_ENTITIES                0x800
00211 #define MAX_MAP_ENTSTRING               0x40000
00212 #define MAX_MAP_SHADERS                 0x400
00213 
00214 #define MAX_MAP_AREAS                   0x100   // MAX_MAP_AREA_BYTES in q_shared must match!
00215 #define MAX_MAP_FOGS                    0x100
00216 #define MAX_MAP_PLANES                  0x20000
00217 #define MAX_MAP_NODES                   0x20000
00218 #define MAX_MAP_BRUSHSIDES              0x20000
00219 #define MAX_MAP_LEAFS                   0x20000
00220 #define MAX_MAP_LEAFFACES               0x20000
00221 #define MAX_MAP_LEAFBRUSHES             0x40000
00222 #define MAX_MAP_PORTALS                 0x20000
00223 #define MAX_MAP_LIGHTING                0x800000
00224 #define MAX_MAP_LIGHTGRID               65535
00225 #define MAX_MAP_LIGHTGRID_ARRAY 0x100000
00226 #define MAX_MAP_VISIBILITY              0x600000
00227 
00228 #define MAX_MAP_DRAW_SURFS      0x20000
00229 #define MAX_MAP_DRAW_VERTS      0x80000
00230 #define MAX_MAP_DRAW_INDEXES    0x80000
00231 
00232 
00233 // key / value pair sizes in the entities lump
00234 #define MAX_KEY                         32
00235 #define MAX_VALUE                       1024
00236 
00237 // the editor uses these predefined yaw angles to orient entities up or down
00238 #define ANGLE_UP                        -1
00239 #define ANGLE_DOWN                      -2
00240 
00241 #define LIGHTMAP_WIDTH          128
00242 #define LIGHTMAP_HEIGHT         128
00243 
00244 //=============================================================================
00245 
00246 #ifdef _XBOX
00247 removed
00248 #else // _XBOX
00249 
00250 typedef struct {
00251         int             fileofs, filelen;
00252 } lump_t;
00253 
00254 #define LUMP_ENTITIES           0
00255 #define LUMP_SHADERS            1
00256 #define LUMP_PLANES                     2
00257 #define LUMP_NODES                      3
00258 #define LUMP_LEAFS                      4
00259 #define LUMP_LEAFSURFACES       5
00260 #define LUMP_LEAFBRUSHES        6
00261 #define LUMP_MODELS                     7
00262 #define LUMP_BRUSHES            8
00263 #define LUMP_BRUSHSIDES         9
00264 #define LUMP_DRAWVERTS          10
00265 #define LUMP_DRAWINDEXES        11
00266 #define LUMP_FOGS                       12
00267 #define LUMP_SURFACES           13
00268 #define LUMP_LIGHTMAPS          14
00269 #define LUMP_LIGHTGRID          15
00270 #define LUMP_VISIBILITY         16
00271 #define LUMP_LIGHTARRAY         17
00272 #define HEADER_LUMPS            18
00273 
00274 typedef struct {
00275         int                     ident;
00276         int                     version;
00277 
00278         lump_t          lumps[HEADER_LUMPS];
00279 } dheader_t;
00280 
00281 typedef struct {
00282         float           mins[3], maxs[3];
00283         int                     firstSurface, numSurfaces;
00284         int                     firstBrush, numBrushes;
00285 } dmodel_t;
00286 
00287 typedef struct {
00288         char            shader[MAX_QPATH];
00289         int                     surfaceFlags;
00290         int                     contentFlags;
00291 } dshader_t;
00292 
00293 // planes x^1 is allways the opposite of plane x
00294 
00295 typedef struct {
00296         float           normal[3];
00297         float           dist;
00298 } dplane_t;
00299 
00300 typedef struct {
00301         int                     planeNum;
00302         int                     children[2];    // negative numbers are -(leafs+1), not nodes
00303         int                     mins[3];                // for frustom culling
00304         int                     maxs[3];
00305 } dnode_t;
00306 
00307 typedef struct {
00308         int                     cluster;                        // -1 = opaque cluster (do I still store these?)
00309         int                     area;
00310 
00311         int                     mins[3];                        // for frustum culling
00312         int                     maxs[3];
00313 
00314         int                     firstLeafSurface;
00315         int                     numLeafSurfaces;
00316 
00317         int                     firstLeafBrush;
00318         int                     numLeafBrushes;
00319 } dleaf_t;
00320 
00321 typedef struct {
00322         int                     planeNum;                       // positive plane side faces out of the leaf
00323         int                     shaderNum;
00324         int                     drawSurfNum;
00325 } dbrushside_t;
00326 
00327 typedef struct {
00328         int                     firstSide;
00329         int                     numSides;
00330         int                     shaderNum;              // the shader that determines the contents flags
00331 } dbrush_t;
00332 
00333 typedef struct {
00334         char            shader[MAX_QPATH];
00335         int                     brushNum;
00336         int                     visibleSide;    // the brush side that ray tests need to clip against (-1 == none)
00337 } dfog_t;
00338 
00339 // Light Style Constants
00340 #define MAXLIGHTMAPS    4
00341 #define LS_NORMAL               0x00
00342 #define LS_UNUSED               0xfe
00343 #define LS_LSNONE               0xff //rww - changed name because it unhappily conflicts with a lightsaber state name and changing this is just easier
00344 #define MAX_LIGHT_STYLES                64
00345 
00346 typedef struct {
00347         vec3_t          xyz;
00348         float           st[2];
00349         float           lightmap[MAXLIGHTMAPS][2];
00350         vec3_t          normal;
00351         byte            color[MAXLIGHTMAPS][4];
00352 } mapVert_t;
00353 
00354 typedef struct {
00355         vec3_t          xyz;
00356         float           st[2];
00357         float           lightmap[MAXLIGHTMAPS][2];
00358         vec3_t          normal;
00359         byte            color[MAXLIGHTMAPS][4];
00360 } drawVert_t;
00361 
00362 typedef struct
00363 {
00364         byte            ambientLight[MAXLIGHTMAPS][3];
00365         byte            directLight[MAXLIGHTMAPS][3];
00366         byte            styles[MAXLIGHTMAPS];
00367         byte            latLong[2];
00368 }  dgrid_t;
00369 
00370 typedef enum {
00371         MST_BAD,
00372         MST_PLANAR,
00373         MST_PATCH,
00374         MST_TRIANGLE_SOUP,
00375         MST_FLARE
00376 } mapSurfaceType_t;
00377 
00378 typedef struct {
00379         int                     shaderNum;
00380         int                     fogNum;
00381         int                     surfaceType;
00382 
00383         int                     firstVert;
00384         int                     numVerts;
00385 
00386         int                     firstIndex;
00387         int                     numIndexes;
00388 
00389         byte            lightmapStyles[MAXLIGHTMAPS], vertexStyles[MAXLIGHTMAPS];
00390         int                     lightmapNum[MAXLIGHTMAPS];
00391         int                     lightmapX[MAXLIGHTMAPS], lightmapY[MAXLIGHTMAPS];
00392         int                     lightmapWidth, lightmapHeight;
00393 
00394         vec3_t          lightmapOrigin;
00395         vec3_t          lightmapVecs[3];        // for patches, [0] and [1] are lodbounds
00396 
00397         int                     patchWidth;
00398         int                     patchHeight;
00399 } dsurface_t;
00400 
00401 #endif // _XBOX
00402 
00404 //
00405 // Defines and structures required for fonts
00406 
00407 #define GLYPH_COUNT                     256
00408 
00409 // Must match define in stmparse.h
00410 #define STYLE_DROPSHADOW        0x80000000
00411 #define STYLE_BLINK                     0x40000000
00412 #define SET_MASK                        0x00ffffff
00413 
00414 typedef struct 
00415 {
00416         short           width;                                  // number of pixels wide
00417         short           height;                                 // number of scan lines
00418         short           horizAdvance;                   // number of pixels to advance to the next char
00419         short           horizOffset;                    // x offset into space to render glyph
00420         int                     baseline;                               // y offset 
00421         float           s;                                              // x start tex coord
00422         float           t;                                              // y start tex coord
00423         float           s2;                                             // x end tex coord
00424         float           t2;                                             // y end tex coord
00425 } glyphInfo_t;
00426 
00427 
00428 // this file corresponds 1:1 with the "*.fontdat" files, so don't change it unless you're going to
00429 //      recompile the fontgen util and regenerate all the fonts!
00430 //
00431 typedef struct dfontdat_s
00432 {
00433         glyphInfo_t             mGlyphs[GLYPH_COUNT];
00434 
00435         short                   mPointSize;
00436         short                   mHeight;                                // max height of font
00437         short                   mAscender;
00438         short                   mDescender;
00439 
00440         short                   mKoreanHack;
00441 } dfontdat_t;
00442 
00444 
00445 
00446 #endif