547 lines
13 KiB
C
547 lines
13 KiB
C
/*
|
|
===========================================================================
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
Copyright (C) 2007 HermitWorks Entertainment Corporation
|
|
|
|
This file is part of the Space Trader source code.
|
|
|
|
The Space Trader source code is free software; you can redistribute it
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
or (at your option) any later version.
|
|
|
|
The Space Trader source code is distributed in the hope that it will be
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with the Space Trader source code; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
===========================================================================
|
|
*/
|
|
#ifndef __QFILES_H__
|
|
#define __QFILES_H__
|
|
|
|
//
|
|
// qfiles.h: quake file formats
|
|
// This file must be identical in the quake and utils directories
|
|
//
|
|
|
|
//Ignore __attribute__ on non-gcc platforms
|
|
#ifndef __GNUC__
|
|
#ifndef __attribute__
|
|
#define __attribute__(x)
|
|
#endif
|
|
#endif
|
|
|
|
// surface geometry should not exceed these limits
|
|
#define SHADER_MAX_VERTEXES 10000
|
|
#define SHADER_MAX_INDEXES (6*SHADER_MAX_VERTEXES)
|
|
|
|
|
|
// the maximum size of game relative pathnames
|
|
#define MAX_QPATH 64
|
|
|
|
/*
|
|
========================================================================
|
|
|
|
QVM files
|
|
|
|
========================================================================
|
|
*/
|
|
|
|
#define VM_MAGIC 0x12721444
|
|
#define VM_MAGIC_VER2 0x12721445
|
|
typedef struct {
|
|
int vmMagic;
|
|
|
|
int instructionCount;
|
|
|
|
int codeOffset;
|
|
int codeLength;
|
|
|
|
int dataOffset;
|
|
int dataLength;
|
|
int litLength; // ( dataLength - litLength ) should be byteswapped on load
|
|
int bssLength; // zero filled memory appended to datalength
|
|
|
|
//!!! below here is VM_MAGIC_VER2 !!!
|
|
int jtrgLength; // number of jump table targets
|
|
} vmHeader_t;
|
|
|
|
|
|
/*
|
|
========================================================================
|
|
|
|
PCX files are used for 8 bit images
|
|
|
|
========================================================================
|
|
*/
|
|
|
|
typedef struct {
|
|
char manufacturer;
|
|
char version;
|
|
char encoding;
|
|
char bits_per_pixel;
|
|
unsigned short xmin,ymin,xmax,ymax;
|
|
unsigned short hres,vres;
|
|
unsigned char palette[48];
|
|
char reserved;
|
|
char color_planes;
|
|
unsigned short bytes_per_line;
|
|
unsigned short palette_type;
|
|
char filler[58];
|
|
unsigned char data; // unbounded
|
|
} pcx_t;
|
|
|
|
|
|
/*
|
|
========================================================================
|
|
|
|
TGA files are used for 24/32 bit images
|
|
|
|
========================================================================
|
|
*/
|
|
|
|
typedef struct _TargaHeader {
|
|
unsigned char id_length, colormap_type, image_type;
|
|
unsigned short colormap_index, colormap_length;
|
|
unsigned char colormap_size;
|
|
unsigned short x_origin, y_origin, width, height;
|
|
unsigned char pixel_size, attributes;
|
|
} TargaHeader;
|
|
|
|
|
|
|
|
/*
|
|
========================================================================
|
|
|
|
.MD3 triangle model file format
|
|
|
|
========================================================================
|
|
*/
|
|
|
|
#define MD3_IDENT (('3'<<24)+('P'<<16)+('D'<<8)+'I')
|
|
#define MD3_VERSION 15
|
|
|
|
// limits
|
|
#define MD3_MAX_LODS 3
|
|
#define MD3_MAX_TRIANGLES 8192 // per surface
|
|
#define MD3_MAX_VERTS 4096 // per surface
|
|
#define MD3_MAX_SHADERS 256 // per surface
|
|
#define MD3_MAX_FRAMES 1024 // per model
|
|
#define MD3_MAX_SURFACES 32 // per model
|
|
#define MD3_MAX_TAGS 16 // per frame
|
|
|
|
// vertex scales
|
|
#define MD3_XYZ_SCALE (1.0F / 64.0F)
|
|
|
|
typedef struct md3Frame_s {
|
|
vec3_t bounds[2];
|
|
vec3_t localOrigin;
|
|
float radius;
|
|
char name[16];
|
|
} md3Frame_t;
|
|
|
|
typedef struct md3Tag_s {
|
|
char name[MAX_QPATH]; // tag name
|
|
vec3_t origin;
|
|
vec3_t axis[3];
|
|
} md3Tag_t;
|
|
|
|
/*
|
|
** md3Surface_t
|
|
**
|
|
** CHUNK SIZE
|
|
** header sizeof( md3Surface_t )
|
|
** shaders sizeof( md3Shader_t ) * numShaders
|
|
** triangles[0] sizeof( md3Triangle_t ) * numTriangles
|
|
** st sizeof( md3St_t ) * numVerts
|
|
** XyzNormals sizeof( md3XyzNormal_t ) * numVerts * numFrames
|
|
*/
|
|
typedef struct {
|
|
int ident; //
|
|
|
|
char name[MAX_QPATH]; // polyset name
|
|
|
|
int flags;
|
|
int numFrames; // all surfaces in a model should have the same
|
|
|
|
int numShaders; // all surfaces in a model should have the same
|
|
int numVerts;
|
|
|
|
int numTriangles;
|
|
int ofsTriangles;
|
|
|
|
int ofsShaders; // offset from start of md3Surface_t
|
|
int ofsSt; // texture coords are common for all frames
|
|
int ofsXyzNormals; // numVerts * numFrames
|
|
|
|
int ofsEnd; // next surface follows
|
|
} md3Surface_t;
|
|
|
|
typedef struct {
|
|
char name[MAX_QPATH];
|
|
int shaderIndex; // for in-game use
|
|
} md3Shader_t;
|
|
|
|
typedef struct {
|
|
int indexes[3];
|
|
} md3Triangle_t;
|
|
|
|
typedef struct {
|
|
float st[2];
|
|
} md3St_t;
|
|
|
|
typedef struct {
|
|
short xyz[3];
|
|
short normal;
|
|
} md3XyzNormal_t;
|
|
|
|
typedef struct {
|
|
int ident;
|
|
int version;
|
|
|
|
char name[MAX_QPATH]; // model name
|
|
|
|
int flags;
|
|
|
|
int numFrames;
|
|
int numTags;
|
|
int numSurfaces;
|
|
|
|
int numSkins;
|
|
|
|
int ofsFrames; // offset for first frame
|
|
int ofsTags; // numFrames * numTags
|
|
int ofsSurfaces; // first surface, others follow
|
|
|
|
int ofsEnd; // end of file
|
|
} md3Header_t;
|
|
|
|
/*
|
|
==============================================================================
|
|
|
|
.BSP file format
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
|
|
#define BSP_IDENT (('P'<<24)+('S'<<16)+('B'<<8)+'I')
|
|
// little-endian "IBSP"
|
|
|
|
#define BSP_VERSION 46
|
|
|
|
|
|
// there shouldn't be any problem with increasing these values at the
|
|
// expense of more memory allocation in the utilities
|
|
#define MAX_MAP_MODELS 0x400
|
|
#define MAX_MAP_BRUSHES 0x8000
|
|
#define MAX_MAP_ENTITIES 0x800
|
|
#define MAX_MAP_ENTSTRING 0x40000
|
|
#define MAX_MAP_SHADERS 0x400
|
|
|
|
#define MAX_MAP_AREAS 0x100 // MAX_MAP_AREA_BYTES in q_shared must match!
|
|
#define MAX_MAP_FOGS 0x100
|
|
#define MAX_MAP_PLANES 0x20000
|
|
#define MAX_MAP_NODES 0x20000
|
|
#define MAX_MAP_BRUSHSIDES 0x20000
|
|
#define MAX_MAP_LEAFS 0x20000
|
|
#define MAX_MAP_LEAFFACES 0x20000
|
|
#define MAX_MAP_LEAFBRUSHES 0x40000
|
|
#define MAX_MAP_PORTALS 0x20000
|
|
#define MAX_MAP_LIGHTING 0x800000
|
|
#define MAX_MAP_LIGHTGRID 0x800000
|
|
#define MAX_MAP_VISIBILITY 0x200000
|
|
|
|
#define MAX_MAP_DRAW_SURFS 0x20000
|
|
#define MAX_MAP_DRAW_VERTS 0x80000
|
|
#define MAX_MAP_DRAW_INDEXES 0x80000
|
|
|
|
|
|
// key / value pair sizes in the entities lump
|
|
#define MAX_KEY 32
|
|
#define MAX_VALUE 1024
|
|
|
|
// the editor uses these predefined yaw angles to orient entities up or down
|
|
#define ANGLE_UP -1
|
|
#define ANGLE_DOWN -2
|
|
|
|
#define LIGHTMAP_WIDTH 128
|
|
#define LIGHTMAP_HEIGHT 128
|
|
|
|
#define MAX_WORLD_COORD ( 128*1024 )
|
|
#define MIN_WORLD_COORD ( -128*1024 )
|
|
#define WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD )
|
|
|
|
//=============================================================================
|
|
|
|
|
|
typedef struct {
|
|
int fileofs, filelen;
|
|
} lump_t;
|
|
|
|
#define LUMP_ENTITIES 0
|
|
#define LUMP_SHADERS 1
|
|
#define LUMP_PLANES 2
|
|
#define LUMP_NODES 3
|
|
#define LUMP_LEAFS 4
|
|
#define LUMP_LEAFSURFACES 5
|
|
#define LUMP_LEAFBRUSHES 6
|
|
#define LUMP_MODELS 7
|
|
#define LUMP_BRUSHES 8
|
|
#define LUMP_BRUSHSIDES 9
|
|
#define LUMP_DRAWVERTS 10
|
|
#define LUMP_DRAWINDEXES 11
|
|
#define LUMP_FOGS 12
|
|
#define LUMP_SURFACES 13
|
|
#define LUMP_LIGHTMAPS 14
|
|
#define LUMP_LIGHTGRID 15
|
|
#define LUMP_VISIBILITY 16
|
|
#define HEADER_LUMPS 17
|
|
|
|
typedef struct {
|
|
int ident;
|
|
int version;
|
|
|
|
lump_t lumps[HEADER_LUMPS];
|
|
} dheader_t;
|
|
|
|
typedef struct {
|
|
float mins[3], maxs[3];
|
|
int firstSurface, numSurfaces;
|
|
int firstBrush, numBrushes;
|
|
} dmodel_t;
|
|
|
|
typedef struct {
|
|
char shader[MAX_QPATH];
|
|
int surfaceFlags;
|
|
int contentFlags;
|
|
} dshader_t;
|
|
|
|
// planes x^1 is allways the opposite of plane x
|
|
|
|
typedef struct {
|
|
float normal[3];
|
|
float dist;
|
|
} dplane_t;
|
|
|
|
typedef struct {
|
|
int planeNum;
|
|
int children[2]; // negative numbers are -(leafs+1), not nodes
|
|
int mins[3]; // for frustom culling
|
|
int maxs[3];
|
|
} dnode_t;
|
|
|
|
typedef struct {
|
|
int cluster; // -1 = opaque cluster (do I still store these?)
|
|
int area;
|
|
|
|
int mins[3]; // for frustum culling
|
|
int maxs[3];
|
|
|
|
int firstLeafSurface;
|
|
int numLeafSurfaces;
|
|
|
|
int firstLeafBrush;
|
|
int numLeafBrushes;
|
|
} dleaf_t;
|
|
|
|
typedef struct {
|
|
int planeNum; // positive plane side faces out of the leaf
|
|
int shaderNum;
|
|
} dbrushside_t;
|
|
|
|
typedef struct {
|
|
int firstSide;
|
|
int numSides;
|
|
int shaderNum; // the shader that determines the contents flags
|
|
} dbrush_t;
|
|
|
|
typedef struct
|
|
{
|
|
char shader[MAX_QPATH];
|
|
int brushNum;
|
|
int visibleSide; // the brush side that ray tests need to clip against (-1 == none)
|
|
} dfog_t;
|
|
|
|
typedef struct
|
|
{
|
|
vec3_t xyz;
|
|
float st[2];
|
|
float lightmap[2];
|
|
vec3_t normal;
|
|
byte color[4];
|
|
} drawVert_t;
|
|
|
|
typedef struct cmodel_s
|
|
{
|
|
dleaf_t leaf; // submodels don't reference the main tree
|
|
} cmodel_t;
|
|
|
|
#define drawVert_t_cleared(x) drawVert_t (x) = {{0, 0, 0}, {0, 0}, {0, 0}, {0, 0, 0}, {0, 0, 0, 0}}
|
|
|
|
typedef enum {
|
|
MST_BAD,
|
|
MST_PLANAR,
|
|
MST_PATCH,
|
|
MST_TRIANGLE_SOUP,
|
|
MST_FLARE
|
|
} mapSurfaceType_t;
|
|
|
|
typedef struct {
|
|
int shaderNum;
|
|
int fogNum;
|
|
int surfaceType;
|
|
|
|
int firstVert;
|
|
int numVerts;
|
|
|
|
int firstIndex;
|
|
int numIndexes;
|
|
|
|
int lightmapNum;
|
|
int lightmapX, lightmapY;
|
|
int lightmapWidth, lightmapHeight;
|
|
|
|
vec3_t lightmapOrigin;
|
|
vec3_t lightmapVecs[3]; // for patches, [0] and [1] are lodbounds
|
|
|
|
int patchWidth;
|
|
int patchHeight;
|
|
} dsurface_t;
|
|
|
|
|
|
/*
|
|
BSP extension data types.
|
|
*/
|
|
#define BSP_EX_VERSION 1
|
|
|
|
#define LUMP_EXT_SURFS 0
|
|
#define LUMP_EXT_SURFS_MAP 1
|
|
#define LUMP_EXT_VERTS 2
|
|
#define LUMP_EXT_INDICES 3
|
|
#define LUMP_EXT_LIGHT_TREE_16 4
|
|
#define LUMP_EXT_LIGHT_TREE_32 5
|
|
#define LUMP_EXT_LIGHT_TREE_LEAVES 6
|
|
|
|
typedef struct
|
|
{
|
|
int ident;
|
|
int version;
|
|
|
|
int numLumps;
|
|
lump_t lumps[1]; //actually var-length up to numLumps
|
|
} dheader_ex_t;
|
|
|
|
typedef struct
|
|
{
|
|
vec3_t pos;
|
|
vec3_t norm;
|
|
vec3_t tan;
|
|
vec3_t bin;
|
|
vec2_t uvC;
|
|
vec2_t uvL;
|
|
byte cl[4];
|
|
} drawVert_ex_t;
|
|
|
|
typedef enum
|
|
{
|
|
SURF_PRIM_TRI_LIST,
|
|
SURF_PRIM_TRI_STRIP,
|
|
SURF_PRIM_TRI_FAN,
|
|
|
|
SURF_PRIM_TRI_COMPILE_TO_32_BITS = 0xFFFFFFFF,
|
|
} dprimType_t;
|
|
|
|
typedef struct
|
|
{
|
|
dprimType_t primType;
|
|
|
|
unsigned int firstVert;
|
|
unsigned int numVerts;
|
|
unsigned int firstIndex;
|
|
unsigned int numIndices;
|
|
} dsurface_ext_t;
|
|
|
|
#define FBSP_IDENT (('P' << 24) | ('S' << 16) | ('B' << 8) | 'F')
|
|
#define FBSP_VERSION 1
|
|
#define FBSP_EX_VERSION 1
|
|
|
|
#define FLUMP_ENTITIES 0
|
|
/*
|
|
Same as usual except that an additional CONTENTS_BODY
|
|
utility shader sits at the end of the array.
|
|
*/
|
|
#define FLUMP_SHADERS 1
|
|
/*
|
|
Same as normal planes except the type has been changed
|
|
to cplane_t. The extra fields are calculated the way
|
|
Quake calculates them.
|
|
*/
|
|
#define FLUMP_PLANES 2 //type has been expanded to
|
|
#define FLUMP_NODES 3
|
|
#define FLUMP_LEAFS 4
|
|
#define FLUMP_LEAFSURFACES 5
|
|
#define FLUMP_LEAFBRUSHES 6
|
|
#define FLUMP_MODELS 7
|
|
/*
|
|
Type is changed to cbrush_t. Note that this is the stripped
|
|
cbrush_t used in the SpaceTrader engine, not the stock Q3 type.
|
|
*/
|
|
#define FLUMP_BRUSHES 8
|
|
#define FLUMP_BRUSHSIDES 9
|
|
/*
|
|
This array contains only the positions of the original draw
|
|
verts. Not all of the original verts are to be emitted. Only
|
|
those belonging to patches and faces go out.
|
|
|
|
Patch verts go out first. Face verts follow. These are used
|
|
by collision and mark/shadow generation.
|
|
*/
|
|
#define FLUMP_DRAWVERTS 10
|
|
/*
|
|
This array contains only the normals that correspond to the
|
|
FLUMP_DRAWVERTS lump. Only the patch surface normals are stored.
|
|
*/
|
|
#define FLUMP_DRAWNORMS 11
|
|
/*
|
|
Indices for the original surfaces that survive the cull.
|
|
*/
|
|
#define FLUMP_DRAWINDEXES 12
|
|
#define FLUMP_FOGS 13
|
|
/*
|
|
This is the same (in fact parallell) to the original draw surfs
|
|
except that the vertex and index data has been moved around (and
|
|
the appropriate offsets are adjusted). Surfaces that have had
|
|
their data stripped (triangle soup surfaces, for example) should
|
|
have their offsets set to -1.
|
|
*/
|
|
#define FLUMP_SURFACES 14
|
|
//LUMP_LIGHTMAPS is no longer here (external files only!)
|
|
#define FLUMP_LIGHTGRID 15
|
|
#define FLUMP_VISIBILITY 16
|
|
|
|
//these match the usual extended lumps
|
|
#define FLUMP_EXT_SURFS 17
|
|
#define FLUMP_EXT_SURFS_MAP 18
|
|
#define FLUMP_EXT_VERTS 19
|
|
#define FLUMP_EXT_INDICES 20
|
|
|
|
#define FLUMP_EXT_LIGHT_TREE_16 21
|
|
#define FLUMP_EXT_LIGHT_TREE_32 22
|
|
#define FLUMP_EXT_LIGHT_TREE_LEAVES 23
|
|
|
|
#define FHEADER_LUMPS 24
|
|
|
|
typedef struct fbspHeader_t
|
|
{
|
|
int ident;
|
|
int version;
|
|
|
|
lump_t lumps[FHEADER_LUMPS];
|
|
} fbspHeader_t;
|
|
|
|
#endif
|