13 Aug 2008

This commit is contained in:
g-cont 2008-08-13 00:00:00 +04:00 committed by Alibek Omarov
parent e78902740f
commit f7d4c1c915
24 changed files with 629 additions and 683 deletions

View File

@ -6,69 +6,72 @@ void GetLeafNums (void);
//=============================================================================
int nummodels;
dmodel_t dmodels[MAX_MAP_MODELS];
int nummodels;
dmodel_t dmodels[MAX_MAP_MODELS];
int visdatasize;
byte dvisdata[MAX_MAP_VISIBILITY];
dvis_t *dvis = (dvis_t *)dvisdata;
int visdatasize;
byte dvisdata[MAX_MAP_VISIBILITY];
dvis_t *dvis = (dvis_t *)dvisdata;
int lightdatasize;
byte dlightdata[MAX_MAP_LIGHTING];
int lightdatasize;
byte dlightdata[MAX_MAP_LIGHTING];
int entdatasize;
char dentdata[MAX_MAP_ENTSTRING];
int entdatasize;
char dentdata[MAX_MAP_ENTSTRING];
int numleafs;
dleaf_t dleafs[MAX_MAP_LEAFS];
int numleafs;
dleaf_t dleafs[MAX_MAP_LEAFS];
int numplanes;
dplane_t dplanes[MAX_MAP_PLANES];
int numplanes;
dplane_t dplanes[MAX_MAP_PLANES];
int numvertexes;
dvertex_t dvertexes[MAX_MAP_VERTS];
int numvertexes;
dvertex_t dvertexes[MAX_MAP_VERTS];
int numnodes;
dnode_t dnodes[MAX_MAP_NODES];
int numnodes;
dnode_t dnodes[MAX_MAP_NODES];
int numtexinfo;
dsurfdesc_t texinfo[MAX_MAP_TEXINFO];
int numtexinfo;
dtexinfo_t texinfo[MAX_MAP_TEXINFO];
int numfaces;
dface_t dfaces[MAX_MAP_FACES];
int numfaces;
dface_t dfaces[MAX_MAP_FACES];
int numedges;
dedge_t dedges[MAX_MAP_EDGES];
int numedges;
dedge_t dedges[MAX_MAP_EDGES];
int numleaffaces;
dword dleaffaces[MAX_MAP_LEAFFACES];
int numleaffaces;
dword dleaffaces[MAX_MAP_LEAFFACES];
int numleafbrushes;
dword dleafbrushes[MAX_MAP_LEAFBRUSHES];
int numleafbrushes;
dword dleafbrushes[MAX_MAP_LEAFBRUSHES];
int numsurfedges;
int dsurfedges[MAX_MAP_SURFEDGES];
int numsurfedges;
int dsurfedges[MAX_MAP_SURFEDGES];
int numbrushes;
dbrush_t dbrushes[MAX_MAP_BRUSHES];
int numbrushes;
dbrush_t dbrushes[MAX_MAP_BRUSHES];
int numbrushsides;
int numbrushsides;
dbrushside_t dbrushsides[MAX_MAP_BRUSHSIDES];
int numareas;
darea_t dareas[MAX_MAP_AREAS];
int nummiptex;
dmiptex_t dmiptex[MAX_MAP_TEXTURES];
int numareaportals;
int numareas;
darea_t dareas[MAX_MAP_AREAS];
int numareaportals;
dareaportal_t dareaportals[MAX_MAP_AREAPORTALS];
byte dcollision[MAX_MAP_COLLISION];
int dcollisiondatasize = 256;
byte dcollision[MAX_MAP_COLLISION];
int dcollisiondatasize = 256; // variable sized
// string table system
char dstringdata[MAX_MAP_STRINGDATA];
int stringdatasize;
int dstringtable[MAX_MAP_NUMSTRINGS];
int numstrings;
char dstringdata[MAX_MAP_STRINGDATA];
int stringdatasize;
int dstringtable[MAX_MAP_NUMSTRINGS];
int numstrings;
/*
===============
@ -113,7 +116,7 @@ CompressVis
===============
*/
int CompressVis (byte *vis, byte *dest)
int CompressVis( byte *vis, byte *dest )
{
int j;
int rep;
@ -147,7 +150,7 @@ int CompressVis (byte *vis, byte *dest)
DecompressVis
===================
*/
void DecompressVis (byte *in, byte *decompressed)
void DecompressVis( byte *in, byte *decompressed )
{
int c;
byte *out;
@ -188,150 +191,72 @@ Byte swaps all data in a bsp file.
void SwapBSPFile (bool todisk)
{
int i, j;
dmodel_t *d;
// models
for (i = 0; i < nummodels; i++)
{
d = &dmodels[i];
d->firstface = LittleLong (d->firstface);
d->numfaces = LittleLong (d->numfaces);
d->headnode = LittleLong (d->headnode);
for( j = 0; j < 3; j++ )
{
d->mins[j] = LittleFloat(d->mins[j]);
d->maxs[j] = LittleFloat(d->maxs[j]);
}
}
SwapBlock( (int *)dmodels, nummodels * sizeof(dmodels[0]));
// vertexes
for( i = 0; i < numvertexes; i++)
{
for (j=0 ; j<3 ; j++)
dvertexes[i].point[j] = LittleFloat (dvertexes[i].point[j]);
}
SwapBlock( (int *)dvertexes, numvertexes * sizeof(dvertexes[0]));
// planes
for(i = 0; i < numplanes; i++)
{
for(j = 0; j < 3; j++)
dplanes[i].normal[j] = LittleFloat (dplanes[i].normal[j]);
dplanes[i].dist = LittleFloat (dplanes[i].dist);
}
SwapBlock( (int *)dplanes, numplanes * sizeof(dplanes[0]));
// texinfos
for (i=0 ; i<numtexinfo ; i++)
{
for (j=0 ; j<8 ; j++)
texinfo[i].vecs[0][j] = LittleFloat (texinfo[i].vecs[0][j]);
texinfo[i].flags = LittleLong (texinfo[i].flags);
texinfo[i].value = LittleLong (texinfo[i].value);
texinfo[i].animid = LittleLong (texinfo[i].animid);
}
// faces
for (i=0 ; i<numfaces ; i++)
{
dfaces[i].desc = LittleShort (dfaces[i].desc);
dfaces[i].planenum = LittleShort (dfaces[i].planenum);
dfaces[i].side = LittleShort (dfaces[i].side);
dfaces[i].lightofs = LittleLong (dfaces[i].lightofs);
dfaces[i].firstedge = LittleLong (dfaces[i].firstedge);
dfaces[i].numedges = LittleShort (dfaces[i].numedges);
}
SwapBlock( (int *)texinfo, numtexinfo * sizeof(texinfo[0]));
// nodes
for (i=0 ; i<numnodes ; i++)
{
dnodes[i].planenum = LittleLong (dnodes[i].planenum);
for (j=0 ; j<3 ; j++)
{
dnodes[i].mins[j] = LittleShort (dnodes[i].mins[j]);
dnodes[i].maxs[j] = LittleShort (dnodes[i].maxs[j]);
}
dnodes[i].children[0] = LittleLong (dnodes[i].children[0]);
dnodes[i].children[1] = LittleLong (dnodes[i].children[1]);
dnodes[i].firstface = LittleShort (dnodes[i].firstface);
dnodes[i].numfaces = LittleShort (dnodes[i].numfaces);
}
SwapBlock( (int *)dnodes, numnodes * sizeof(dnodes[0]));
// leafs
for (i=0 ; i<numleafs ; i++)
{
dleafs[i].contents = LittleLong (dleafs[i].contents);
dleafs[i].cluster = LittleShort (dleafs[i].cluster);
dleafs[i].area = LittleShort (dleafs[i].area);
for (j=0 ; j<3 ; j++)
{
dleafs[i].mins[j] = LittleShort (dleafs[i].mins[j]);
dleafs[i].maxs[j] = LittleShort (dleafs[i].maxs[j]);
}
dleafs[i].firstleafface = LittleShort (dleafs[i].firstleafface);
dleafs[i].numleaffaces = LittleShort (dleafs[i].numleaffaces);
dleafs[i].firstleafbrush = LittleShort (dleafs[i].firstleafbrush);
dleafs[i].numleafbrushes = LittleShort (dleafs[i].numleafbrushes);
}
SwapBlock( (int *)dleafs, numleafs * sizeof(dleafs[0]));
// leaffaces
for (i=0 ; i<numleaffaces ; i++)
dleaffaces[i] = LittleShort (dleaffaces[i]);
SwapBlock( (int *)dleaffaces, numleaffaces * sizeof(dleaffaces[0]));
// leafbrushes
for (i=0 ; i<numleafbrushes ; i++)
dleafbrushes[i] = LittleShort (dleafbrushes[i]);
SwapBlock( (int *)dleafbrushes, numleafbrushes * sizeof(dleafbrushes[0]));
// surfedges
for (i=0 ; i<numsurfedges ; i++)
dsurfedges[i] = LittleLong (dsurfedges[i]);
SwapBlock( (int *)texinfo, numsurfedges * sizeof(dsurfedges[0]));
// edges
for (i=0 ; i<numedges ; i++)
{
dedges[i].v[0] = LittleShort (dedges[i].v[0]);
dedges[i].v[1] = LittleShort (dedges[i].v[1]);
}
SwapBlock( (int *)dedges, numedges * sizeof(dedges[0]));
// brushes
for (i=0 ; i<numbrushes ; i++)
{
dbrushes[i].firstside = LittleLong (dbrushes[i].firstside);
dbrushes[i].numsides = LittleLong (dbrushes[i].numsides);
dbrushes[i].contents = LittleLong (dbrushes[i].contents);
}
SwapBlock( (int *)dbrushes, numbrushes * sizeof(dbrushes[0]));
// areas
for (i=0 ; i<numareas ; i++)
{
dareas[i].numareaportals = LittleLong (dareas[i].numareaportals);
dareas[i].firstareaportal = LittleLong (dareas[i].firstareaportal);
}
SwapBlock( (int *)dareas, numareas * sizeof(dareas[0]));
// areasportals
for (i=0 ; i<numareaportals ; i++)
{
dareaportals[i].portalnum = LittleLong (dareaportals[i].portalnum);
dareaportals[i].otherarea = LittleLong (dareaportals[i].otherarea);
}
SwapBlock( (int *)dareaportals, numareaportals * sizeof(dareaportals[0]));
// brushsides
for (i=0 ; i<numbrushsides ; i++)
SwapBlock( (int *)dbrushsides, numbrushsides * sizeof(dbrushsides[0]));
// miptexes
SwapBlock( (int *)dmiptex, nummiptex * sizeof(dmiptex[0]));
// faces
// FIXME: i want using SwapBlock too
for( i = 0; i < numfaces; i++ )
{
dbrushsides[i].planenum = LittleShort (dbrushsides[i].planenum);
dbrushsides[i].surfdesc = LittleShort (dbrushsides[i].surfdesc);
dfaces[i].planenum = LittleLong( dfaces[i].planenum );
dfaces[i].firstedge = LittleLong( dfaces[i].firstedge );
dfaces[i].numedges = LittleLong( dfaces[i].numedges );
dfaces[i].texinfo = LittleLong( dfaces[i].texinfo );
dfaces[i].lightofs = LittleLong( dfaces[i].lightofs );
dfaces[i].side = LittleShort (dfaces[i].side);
}
// visibility
if (todisk) j = dvis->numclusters;
else j = LittleLong(dvis->numclusters);
dvis->numclusters = LittleLong (dvis->numclusters);
for (i = 0; i < j; i++)
if( todisk ) j = dvis->numclusters;
else j = LittleLong( dvis->numclusters );
dvis->numclusters = LittleLong( dvis->numclusters );
for( i = 0; i < j; i++ )
{
dvis->bitofs[i][0] = LittleLong (dvis->bitofs[i][0]);
dvis->bitofs[i][1] = LittleLong (dvis->bitofs[i][1]);
dvis->bitofs[i][0] = LittleLong( dvis->bitofs[i][0] );
dvis->bitofs[i][1] = LittleLong( dvis->bitofs[i][1] );
}
}
@ -382,7 +307,7 @@ bool LoadBSPFile( void )
numvertexes = CopyLump (LUMP_VERTEXES, dvertexes, sizeof(dvertex_t));
visdatasize = CopyLump (LUMP_VISIBILITY, dvisdata, 1);
numnodes = CopyLump (LUMP_NODES, dnodes, sizeof(dnode_t));
numtexinfo = CopyLump (LUMP_SURFDESC, texinfo, sizeof(dsurfdesc_t));
numtexinfo = CopyLump (LUMP_TEXINFO, texinfo, sizeof(dtexinfo_t));
numfaces = CopyLump (LUMP_FACES, dfaces, sizeof(dface_t));
lightdatasize = CopyLump (LUMP_LIGHTING, dlightdata, 1);
numleafs = CopyLump (LUMP_LEAFS, dleafs, sizeof(dleaf_t));
@ -394,6 +319,7 @@ bool LoadBSPFile( void )
numbrushes = CopyLump (LUMP_BRUSHES, dbrushes, sizeof(dbrush_t));
numbrushsides = CopyLump (LUMP_BRUSHSIDES, dbrushsides, sizeof(dbrushside_t));
dcollisiondatasize = CopyLump(LUMP_COLLISION, dcollision, 1);
nummiptex = CopyLump(LUMP_TEXTURES, dmiptex, sizeof(dmiptex_t));
stringdatasize = CopyLump( LUMP_STRINGDATA, dstringdata, sizeof(dstringdata[0]));
numstrings = CopyLump( LUMP_STRINGTABLE, dstringtable, sizeof(dstringtable[0]));
numareas = CopyLump (LUMP_AREAS, dareas, sizeof(darea_t));
@ -405,60 +331,20 @@ bool LoadBSPFile( void )
return true;
}
/*
=============
LoadBSPFileTexinfo
Only loads the texinfo lump, so qdata can scan for textures
=============
*/
void LoadBSPFileTexinfo( char *filename )
{
int i;
file_t *f;
int length, ofs;
header = Malloc(sizeof(dheader_t));
f = FS_Open (filename, "rb" );
FS_Read(f, header, sizeof(dheader_t));
//fread (header, sizeof(dheader_t), 1, f);
// swap the header
for (i=0 ; i< sizeof(dheader_t)/4 ; i++)
((int *)header)[i] = LittleLong ( ((int *)header)[i]);
if (header->ident != IDBSPMODHEADER) Sys_Error("%s is not a IBSP file", filename);
if (header->version != BSPMOD_VERSION) Sys_Error("%s is version %i, not %i", filename, header->version, BSPMOD_VERSION);
length = header->lumps[LUMP_SURFDESC].filelen;
ofs = header->lumps[LUMP_SURFDESC].fileofs;
FS_Seek(f, ofs, SEEK_SET);
FS_Read(f, texinfo, length );
FS_Close(f);
numtexinfo = length / sizeof(dsurfdesc_t);
Mem_Free (header); // everything has been copied out
SwapBSPFile (false);
}
//============================================================================
file_t *wadfile;
file_t *wadfile; // because bsp it's really wadfile with fixed lump counter
dheader_t outheader;
void AddLump (int lumpnum, const void *data, int len)
void AddLump( int lumpnum, const void *data, size_t length )
{
lump_t *lump;
lump = &header->lumps[lumpnum];
lump->fileofs = LittleLong( FS_Tell(wadfile) );
lump->filelen = LittleLong( len );
lump->fileofs = LittleLong( FS_Tell( wadfile ));
lump->filelen = LittleLong( length );
FS_Write(wadfile, data, (len+3)&~3 );
FS_Write( wadfile, data, (length + 3) & ~3 );
}
/*
@ -480,10 +366,10 @@ void WriteBSPFile( void )
header->ident = LittleLong (IDBSPMODHEADER);
header->version = LittleLong (BSPMOD_VERSION);
//build path
sprintf (path, "maps/%s.bsp", gs_filename );
MsgDev(D_NOTE, "writing %s\n", path);
if(pe) pe->FreeBSP();
// build path
sprintf( path, "maps/%s.bsp", gs_filename );
MsgDev( D_NOTE, "writing %s\n", path );
if( pe ) pe->FreeBSP();
wadfile = FS_Open( path, "wb" );
FS_Write( wadfile, header, sizeof(dheader_t)); // overwritten later
@ -493,7 +379,7 @@ void WriteBSPFile( void )
AddLump (LUMP_VERTEXES, dvertexes, numvertexes*sizeof(dvertex_t));
AddLump (LUMP_VISIBILITY, dvisdata, visdatasize);
AddLump (LUMP_NODES, dnodes, numnodes*sizeof(dnode_t));
AddLump (LUMP_SURFDESC, texinfo, numtexinfo*sizeof(dsurfdesc_t));
AddLump (LUMP_TEXINFO, texinfo, numtexinfo*sizeof(dtexinfo_t));
AddLump (LUMP_FACES, dfaces, numfaces*sizeof(dface_t));
AddLump (LUMP_LIGHTING, dlightdata, lightdatasize);
AddLump (LUMP_LEAFS, dleafs, numleafs*sizeof(dleaf_t));
@ -505,6 +391,7 @@ void WriteBSPFile( void )
AddLump (LUMP_BRUSHES, dbrushes, numbrushes*sizeof(dbrush_t));
AddLump (LUMP_BRUSHSIDES, dbrushsides, numbrushsides*sizeof(dbrushside_t));
AddLump (LUMP_COLLISION, dcollision, dcollisiondatasize );
AddLump (LUMP_TEXTURES, dmiptex, nummiptex*sizeof(dmiptex[0]));
AddLump (LUMP_STRINGDATA, dstringdata, stringdatasize * sizeof(dstringdata[0]));
AddLump (LUMP_STRINGTABLE, dstringtable, numstrings * sizeof(dstringtable[0]));
AddLump (LUMP_AREAS, dareas, numareas*sizeof(darea_t));

View File

@ -104,10 +104,11 @@ typedef struct
typedef struct
{
char txcommand;
vects_u vects;
char txcommand;
char name[128];
int size[2];
int contents;
int flags;
int value;
} brush_texture_t;
@ -304,7 +305,7 @@ epair_t *ParseEpair (void);
extern int entity_num;
extern int g_mapversion;
extern plane_t mapplanes[MAX_MAP_PLANES];
extern int nummapplanes;
extern int nummapbrushes;
@ -330,7 +331,7 @@ extern dvertex_t dvertexes[MAX_MAP_VERTS];
extern int numnodes;
extern dnode_t dnodes[MAX_MAP_NODES];
extern int numtexinfo;
extern dsurfdesc_t texinfo[MAX_MAP_TEXINFO];
extern dtexinfo_t texinfo[MAX_MAP_TEXINFO];
extern int numfaces;
extern dface_t dfaces[MAX_MAP_FACES];
extern int numedges;
@ -351,37 +352,25 @@ extern int numbrushsides;
extern dbrushside_t dbrushsides[MAX_MAP_BRUSHSIDES];
extern int dcollisiondatasize;
extern byte dcollision[MAX_MAP_COLLISION];
extern dmiptex_t dmiptex[MAX_MAP_TEXTURES];
extern int nummiptex;
extern char outbase[32];
void LoadMapFile ( void );
int FindFloatPlane (vec3_t normal, vec_t dist);
bool LoadBSPFile ( void );
void LoadBSPFileTexinfo (char *filename); // just for qdata
void WriteBSPFile ( void );
void DecompressVis (byte *in, byte *decompressed);
int CompressVis (byte *vis, byte *dest);
void AddLump (int lumpnum, const void *data, int len);
void AddLump( int lumpnum, const void *data, size_t length );
const char *GetStringFromTable( int index );
int GetIndexFromTable( const char *string );
//=============================================================================
// textures.c
typedef struct
{
char texname[128];
char animname[128];
int size[2];
int flags;
int value;
int contents;
int numframes;
} textureref_t;
extern textureref_t textureref[MAX_MAP_TEXTURES];
int FindMiptex (char *name);
int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin);
int FindMiptex( const char *name );
int TexinfoForBrushTexture( plane_t *plane, brush_texture_t *bt, vec3_t origin );
//=============================================================================

View File

@ -813,28 +813,27 @@ SubdivideFace
Chop up faces that are larger than we want in the surface cache
===============
*/
void SubdivideFace (node_t *node, face_t *f)
void SubdivideFace( node_t *node, face_t *f )
{
float mins, maxs;
vec_t v;
int axis, i;
dsurfdesc_t *tex;
int axis, i;
dtexinfo_t *tex;
vec3_t temp;
vec_t dist;
winding_t *w, *frontw, *backw;
winding_t *w, *frontw, *backw;
if (f->merged)
return;
if( f->merged ) return;
// special (non-surface cached) faces don't need subdivision
// special (non-surface cached) faces don't need subdivision
tex = &texinfo[f->texinfo];
if ( tex->flags & (SURF_WARP|SURF_SKY) )
if( tex->flags & (SURF_WARP|SURF_SKY) )
{
return;
}
for (axis = 0 ; axis < 2 ; axis++)
for( axis = 0; axis < 2; axis++ )
{
while (1)
{

View File

@ -485,7 +485,7 @@ void CalcFaceExtents (lightinfo_t *l)
vec_t mins[2], maxs[2], val;
int i,j, e;
dvertex_t *v;
dsurfdesc_t *tex;
dtexinfo_t *tex;
vec3_t vt;
s = l->face;
@ -493,7 +493,7 @@ void CalcFaceExtents (lightinfo_t *l)
mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999;
tex = &texinfo[s->desc];
tex = &texinfo[s->texinfo];
for (i=0 ; i<s->numedges ; i++)
{
@ -540,14 +540,14 @@ Fills in texorg, worldtotex. and textoworld
*/
void CalcFaceVectors (lightinfo_t *l)
{
dsurfdesc_t *tex;
dtexinfo_t *tex;
int i, j;
vec3_t texnormal;
vec_t distscale;
vec_t dist, len;
int w, h;
tex = &texinfo[l->face->desc];
tex = &texinfo[l->face->texinfo];
// convert from float to double
for (i=0 ; i<2 ; i++)
@ -1032,7 +1032,7 @@ void BuildFacelights (int facenum)
f = &dfaces[facenum];
if ( texinfo[f->desc].flags & (SURF_WARP|SURF_SKY) )
if ( texinfo[f->texinfo].flags & (SURF_WARP|SURF_SKY) )
return; // non-lit texture
memset (styletable,0, sizeof(styletable));
@ -1144,7 +1144,7 @@ void FinalLightFace (int facenum)
f = &dfaces[facenum];
fl = &facelight[facenum];
if ( texinfo[f->desc].flags & (SURF_WARP|SURF_SKY) )
if ( texinfo[f->texinfo].flags & (SURF_WARP|SURF_SKY) )
return; // non-lit texture
ThreadLock ();

View File

@ -262,33 +262,28 @@ int PlaneFromPoints (vec_t *p0, vec_t *p1, vec_t *p2)
BrushContents
===========
*/
int BrushContents (mapbrush_t *b)
int BrushContents( mapbrush_t *b )
{
int contents;
side_t *s;
int i;
int trans;
int contents;
int i, trans;
side_t *s;
s = &b->original_sides[0];
contents = s->contents;
trans = texinfo[s->texinfo].flags;
for (i = 1; i < b->numsides; i++, s++)
for( i = 1; i < b->numsides; i++, s++ )
{
s = &b->original_sides[i];
trans |= texinfo[s->texinfo].flags;
if (s->contents != contents)
{
Msg ("Entity %i, Brush %i: mixed face contents\n", b->entitynum, b->brushnum);
break;
}
s->contents |= contents; // multi-contents support
}
// if any side is translucent, mark the contents
// and change solid to window
if ( trans & (SURF_TRANS|SURF_BLEND) )
if( trans & ( SURF_TRANS|SURF_BLEND ))
{
contents |= CONTENTS_TRANSLUCENT;
if (contents & CONTENTS_SOLID)
if( contents & CONTENTS_SOLID )
{
contents &= ~CONTENTS_SOLID;
contents |= CONTENTS_WINDOW;
@ -309,26 +304,26 @@ Adds any additional planes necessary to allow the brush to be expanded
against axial bounding boxes
=================
*/
void AddBrushBevels (mapbrush_t *b)
void AddBrushBevels( mapbrush_t *b )
{
int axis, dir;
int i, j, k, l, order;
side_t sidetemp;
side_t sidetemp;
brush_texture_t tdtemp;
side_t *s, *s2;
vec3_t normal;
float dist;
winding_t *w, *w2;
vec3_t vec, vec2;
float d;
side_t *s, *s2;
vec3_t normal;
float dist;
winding_t *w, *w2;
vec3_t vec, vec2;
float d;
//
// add the axial planes
//
order = 0;
for (axis=0 ; axis <3 ; axis++)
for( axis = 0; axis < 3; axis++ )
{
for (dir=-1 ; dir <= 1 ; dir+=2, order++)
for( dir = -1; dir <= 1; dir += 2, order++ )
{
// see if the plane is allready present
for (i=0, s=b->original_sides ; i<b->numsides ; i++,s++)
@ -514,130 +509,130 @@ void ParseBrush( bsp_entity_t *mapent )
int mt;
side_t *side, *s2;
int planenum;
vec_t planepts[3][3]; // quark used float coords
shader_t *si;
brush_texture_t td;
vec_t planepts[3][3]; //quark used float coords
if (nummapbrushes == MAX_MAP_BRUSHES)
Sys_Error ("nummapbrushes == MAX_MAP_BRUSHES");
if( nummapbrushes == MAX_MAP_BRUSHES ) Sys_Break( "MAX_MAP_BRUSHES limit exceeded\n");
b = &mapbrushes[nummapbrushes];
b->original_sides = &brushsides[nummapbrushsides];
b->entitynum = num_entities-1;
b->brushnum = nummapbrushes - mapent->firstbrush;
do
while( 1 )
{
g_TXcommand = 0;
if (!Com_GetToken (true)) break;
if (Com_MatchToken("}")) break;
if( !Com_GetToken( true )) break;
if( Com_MatchToken( "}" )) break;
if (nummapbrushsides == MAX_MAP_BRUSHSIDES)
Sys_Error ("MAX_MAP_BRUSHSIDES");
if( nummapbrushsides == MAX_MAP_BRUSHSIDES ) Sys_Break( "MAX_MAP_BRUSHSIDES limit exceeded\n" );
side = &brushsides[nummapbrushsides];
// read the three point plane definition
for (i = 0; i < 3; i++)
for( i = 0; i < 3; i++ )
{
if (i != 0) Com_GetToken (true);
if(!Com_MatchToken("(")) Sys_Error ("ParseBrush: error parsing %d", b->brushnum );
if(!Com_MatchToken( "(" )) Sys_Break( "ParseBrush: error parsing %d\n", b->brushnum );
for (j=0 ; j<3 ; j++)
for( j = 0; j < 3; j++ )
{
Com_GetToken (false);
planepts[i][j] = atof(com_token);
}
Com_GetToken (false);
if(!Com_MatchToken(")"))Sys_Error ("parsing brush");
Com_GetToken( false );
if(!Com_MatchToken( ")" )) Sys_Break( "ParseBrush: missing \")\" in brush definition\n" );
}
// read the texturedef
Com_GetToken( false );
strcpy( td.name, com_token );
com.strcpy( td.name, com_token );
if(g_mapversion == VALVE_FORMAT) // Worldcraft 2.2+
if( g_mapversion == VALVE_FORMAT ) // Worldcraft 2.2+
{
// texture U axis
Com_GetToken( false );
if(!Com_MatchToken("[")) Sys_Error("missing '[' in texturedef (U)");
if(!Com_MatchToken("[")) Sys_Break( "missing '[' in texturedef (U)\n" );
Com_GetToken(false);
td.vects.valve.UAxis[0] = atof(com_token);
td.vects.valve.UAxis[0] = com.atof(com_token);
Com_GetToken(false);
td.vects.valve.UAxis[1] = atof(com_token);
td.vects.valve.UAxis[1] = com.atof(com_token);
Com_GetToken(false);
td.vects.valve.UAxis[2] = atof(com_token);
td.vects.valve.UAxis[2] = com.atof(com_token);
Com_GetToken(false);
td.vects.valve.shift[0] = atof(com_token);
td.vects.valve.shift[0] = com.atof(com_token);
Com_GetToken(false);
if (strcmp(com_token, "]")) Sys_Error("missing ']' in texturedef (U)");
if (strcmp(com_token, "]")) Sys_Break( "missing ']' in texturedef (U)\n" );
// texture V axis
Com_GetToken(false);
if (strcmp(com_token, "[")) Sys_Error("missing '[' in texturedef (V)");
Com_GetToken(false);
td.vects.valve.VAxis[0] = atof(com_token);
Com_GetToken(false);
td.vects.valve.VAxis[1] = atof(com_token);
Com_GetToken(false);
td.vects.valve.VAxis[2] = atof(com_token);
Com_GetToken(false);
td.vects.valve.shift[1] = atof(com_token);
Com_GetToken(false);
if (strcmp(com_token, "]")) Sys_Error("missing ']' in texturedef (V)");
Com_GetToken( false );
if (strcmp(com_token, "[")) Sys_Break( "missing '[' in texturedef (V)\n" );
Com_GetToken( false );
td.vects.valve.VAxis[0] = com.atof( com_token );
Com_GetToken( false );
td.vects.valve.VAxis[1] = com.atof( com_token );
Com_GetToken( false );
td.vects.valve.VAxis[2] = com.atof( com_token );
Com_GetToken( false );
td.vects.valve.shift[1] = com.atof( com_token );
Com_GetToken( false );
if(com.strcmp( com_token, "]")) Sys_Break( "missing ']' in texturedef (V)\n");
// Texture rotation is implicit in U/V axes.
// texture rotation is implicit in U/V axes.
Com_GetToken(false);
td.vects.valve.rotate = 0;
// texure scale
Com_GetToken( false );
td.vects.valve.scale[0] = com.atof( com_token );
Com_GetToken(false);
td.vects.valve.scale[0] = atof(com_token);
Com_GetToken(false);
td.vects.valve.scale[1] = atof(com_token);
td.vects.valve.scale[1] = com.atof( com_token );
}
else
{
// Worldcraft 2.1-, Radiant
Com_GetToken (false);
td.vects.valve.shift[0] = atof(com_token);
Com_GetToken (false);
td.vects.valve.shift[1] = atof(com_token);
Com_GetToken (false);
td.vects.valve.rotate = atof(com_token);
Com_GetToken (false);
td.vects.valve.scale[0] = atof(com_token);
Com_GetToken (false);
td.vects.valve.scale[1] = atof(com_token);
// worldcraft 2.1-, Radiant
Com_GetToken( false );
td.vects.valve.shift[0] = com.atof(com_token);
Com_GetToken( false );
td.vects.valve.shift[1] = com.atof(com_token);
Com_GetToken( false );
td.vects.valve.rotate = com.atof(com_token);
Com_GetToken( false );
td.vects.valve.scale[0] = com.atof(com_token);
Com_GetToken( false );
td.vects.valve.scale[1] = com.atof(com_token);
}
if ((g_TXcommand == '1' || g_TXcommand == '2'))
if(( g_TXcommand == '1' || g_TXcommand == '2' ))
{
// We are QuArK mode and need to translate some numbers to align textures its way
// from QuArK, the texture vectors are given directly from the three points
vec3_t TexPt[2];
int k;
float dot22, dot23, dot33, mdet, aa, bb, dd;
int k;
k = g_TXcommand - '0';
for (j = 0; j < 3; j++)
for( j = 0; j < 3; j++ )
{
TexPt[1][j] = (planepts[k][j] - planepts[0][j]) * ScaleCorrection;
}
k = 3 - k;
for (j = 0; j < 3; j++)
for( j = 0; j < 3; j++ )
{
TexPt[0][j] = (planepts[k][j] - planepts[0][j]) * ScaleCorrection;
}
dot22 = DotProduct(TexPt[0], TexPt[0]);
dot23 = DotProduct(TexPt[0], TexPt[1]);
dot33 = DotProduct(TexPt[1], TexPt[1]);
dot22 = DotProduct( TexPt[0], TexPt[0] );
dot23 = DotProduct( TexPt[0], TexPt[1] );
dot33 = DotProduct( TexPt[1], TexPt[1] );
mdet = dot22 * dot33 - dot23 * dot23;
if (mdet < 1E-6 && mdet > -1E-6)
if( mdet < 1E-6 && mdet > -1E-6 )
{
aa = bb = dd = 0;
Msg("Degenerate QuArK-style brush texture : Entity %i, Brush %i\n", b->entitynum, b->brushnum);
Msg( "Degenerate QuArK-style brush texture : Entity %i, Brush %i\n", b->entitynum, b->brushnum );
}
else
{
@ -646,7 +641,7 @@ void ParseBrush( bsp_entity_t *mapent )
bb = -dot23 * mdet;
dd = dot22 * mdet;
}
for (j = 0; j < 3; j++)
for( j = 0; j < 3; j++ )
{
td.vects.quark.vects[0][j] = aa * TexPt[0][j] + bb * TexPt[1][j];
td.vects.quark.vects[1][j] = -(bb * TexPt[0][j] + dd * TexPt[1][j]);
@ -654,140 +649,162 @@ void ParseBrush( bsp_entity_t *mapent )
td.vects.quark.vects[0][3] = -DotProduct(td.vects.quark.vects[0], planepts[0]);
td.vects.quark.vects[1][3] = -DotProduct(td.vects.quark.vects[1], planepts[0]);
}
td.txcommand = g_TXcommand;// Quark stuff, but needs setting always
td.txcommand = g_TXcommand; // Quark stuff, but needs setting always
td.flags = td.contents = td.value = 0; // reset all values before setting
side->contents = side->surf = 0;
// find default flags and values
mt = FindMiptex (td.name);
td.size[0] = textureref[mt].size[0];
td.size[1] = textureref[mt].size[1];
td.flags = textureref[mt].flags;
td.value = textureref[mt].value;
side->contents = textureref[mt].contents;
side->surf = td.flags = textureref[mt].flags;
//Msg("flags %d, value %d, contents %d\n", td.flags, td.value, side->contents );
if (Com_TryToken()) //first com_token will be get automatically
// get size from miptex info
mt = FindMiptex( td.name );
td.size[0] = dmiptex[mt].size[0];
td.size[1] = dmiptex[mt].size[1];
// get flags and contents from shader
si = FindShader( td.name );
if( si )
{
side->contents = atoi(com_token);
Com_GetToken (false);
side->surf = td.flags = atoi(com_token);
Com_GetToken (false);
td.value = atoi(com_token);
int t_next, t_name;
side->contents = td.contents = si->contents;
side->surf = td.flags = si->surfaceFlags;
dmiptex[mt].s_next = t_next = FindMiptex( si->nextframe );
t_name = dmiptex[t_next].s_name;
// FIXME: register all animchains here
// NOTE: all textures in animchain must be stored into
// dmiptex array so engine can precache them correctly
while( t_next && dmiptex[mt].s_name != t_name )
{
si = FindShader(GetStringFromTable( t_name ));
if( !si ) break; // end of animchain
t_next = dmiptex[t_next].s_next = FindMiptex( si->nextframe );
t_name = dmiptex[t_next].s_name;
}
}
//Msg( "flags %d, value %d, contents %d\n", td.flags, td.value, side->contents );
if( Com_TryToken())
{
// first com_token will be get automatically
side->contents = td.contents = com.atoi( com_token );
Com_GetToken( false );
side->surf = td.flags = com.atoi( com_token );
Com_GetToken( false );
td.value = com.atoi(com_token);
}
// translucent objects are automatically classified as detail
if (side->surf & (SURF_TRANS|SURF_BLEND) )
side->contents |= CONTENTS_DETAIL;
if (side->contents & (CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP) )
side->contents |= CONTENTS_DETAIL;
if (!(side->contents & ((LAST_VISIBLE_CONTENTS-1)
| CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP|CONTENTS_MIST) ) )
side->contents |= CONTENTS_SOLID;
// hints and skips are never detail, and have no content
if (side->surf & (SURF_HINT|SURF_SKIP) )
if( side->surf & ( SURF_TRANS|SURF_BLEND ))
{
side->contents = 0;
side->contents |= CONTENTS_DETAIL;
td.contents |= CONTENTS_DETAIL;
}
if( side->contents & ( CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP ))
{
side->contents |= CONTENTS_DETAIL;
td.contents |= CONTENTS_DETAIL;
}
if(!(side->contents & ((LAST_VISIBLE_CONTENTS - 1)|CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP|CONTENTS_MIST)))
{
side->contents |= CONTENTS_SOLID;
td.contents |= CONTENTS_SOLID;
}
// hints and skips are never detail, and have no content
if( side->surf & ( SURF_HINT|SURF_SKIP ))
{
side->contents = td.contents = 0;
side->surf &= ~CONTENTS_DETAIL;
td.flags &= ~CONTENTS_DETAIL;
}
// find the plane number
planenum = PlaneFromPoints (planepts[0], planepts[1], planepts[2]);
if (planenum == -1)
planenum = PlaneFromPoints( planepts[0], planepts[1], planepts[2] );
if( planenum == -1 )
{
Msg ("Entity %i, Brush %i: plane with no normal\n", b->entitynum, b->brushnum);
Msg( "Entity %i, Brush %i: plane with no normal\n", b->entitynum, b->brushnum );
continue;
}
//
// see if the plane has been used already
//
for (k=0 ; k<b->numsides ; k++)
for( k = 0; k < b->numsides; k++ )
{
s2 = b->original_sides + k;
if (s2->planenum == planenum)
if( s2->planenum == planenum )
{
Msg("Entity %i, Brush %i: duplicate plane\n", b->entitynum, b->brushnum);
Msg( "Entity %i, Brush %i: duplicate plane\n", b->entitynum, b->brushnum );
break;
}
if ( s2->planenum == (planenum^1) )
if( s2->planenum == ( planenum^1 ))
{
Msg("Entity %i, Brush %i: mirrored plane\n", b->entitynum, b->brushnum);
Msg( "Entity %i, Brush %i: mirrored plane\n", b->entitynum, b->brushnum );
break;
}
}
if (k != b->numsides)
continue; // duplicated
if( k != b->numsides ) continue; // duplicated
//
// keep this side
//
side = b->original_sides + b->numsides;
side->planenum = planenum;
side->texinfo = TexinfoForBrushTexture (&mapplanes[planenum], &td, vec3_origin);
side->texinfo = TexinfoForBrushTexture( &mapplanes[planenum], &td, vec3_origin );
// save the td off in case there is an origin brush and we
// have to recalculate the texinfo
side_brushtextures[nummapbrushsides] = td;
nummapbrushsides++;
b->numsides++;
} while (1);
}
// get the content for the entire brush
b->contents = BrushContents (b);
b->contents = BrushContents( b );
// create windings for sides and bounds for brush
MakeBrushWindings (b);
MakeBrushWindings( b );
// brushes that will not be visible at all will never be
// used as bsp splitters
if (b->contents & (CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP) )
if( b->contents & ( CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP ))
{
c_clipbrushes++;
for (i=0 ; i<b->numsides ; i++)
for( i = 0; i < b->numsides; i++ )
b->original_sides[i].texinfo = TEXINFO_NODE;
}
//
// origin brushes are removed, but they set
// the rotation origin for the rest of the brushes
// in the entity. After the entire entity is parsed,
// the planenums and texinfos will be adjusted for
// the origin brush
//
if (b->contents & CONTENTS_ORIGIN)
if( b->contents & CONTENTS_ORIGIN )
{
char string[32];
vec3_t size, movedir, origin;
if (num_entities == 1)
if( num_entities == 1 )
{
Sys_Error ("Entity %i, Brush %i: origin brushes not allowed in world", b->entitynum, b->brushnum);
// g-cont. rotating world it's a interesting idea, hmm.....
Sys_Break( "Entity %i, Brush %i: origin brushes not allowed in world", b->entitynum, b->brushnum );
return;
}
VectorAdd (b->mins, b->maxs, origin);
VectorScale (origin, 0.5, origin);
VectorAverage( b->mins, b->maxs, origin );
//calcualte movedir (Xash 0.4 style)
VectorSubtract(b->maxs, b->mins, size );
if (size[2] > size[0] && size[2] > size[1])
// calcualte movedir (Xash 0.4 style)
VectorSubtract( b->maxs, b->mins, size );
if( size[2] > size[0] && size[2] > size[1] )
{
movedir[0] = 0;//x-rotate
movedir[0] = 0; // x-rotate
movedir[1] = 1;
movedir[2] = 0;
}
else if (size[1] > size[2] && size[1] > size[0])
{
movedir[0] = 1;//y-rotate
movedir[0] = 1; // y-rotate
movedir[1] = 0;
movedir[2] = 0;
}
else if (size[0] > size[2] && size[0] > size[1])
{
movedir[0] = 0;//z-rotate
movedir[0] = 0; // z-rotate
movedir[1] = 0;
movedir[2] = 1;
}
@ -796,23 +813,23 @@ void ParseBrush( bsp_entity_t *mapent )
movedir[0] = 0;//deafult x-rotate
movedir[1] = 1;
movedir[2] = 0;
Msg("Entity %d has origin with invalid form! Make axis form for it\n", b->entitynum );
// not warning, just notify
MsgDev( D_INFO, "Entity %d has origin with invalid form! Make axis form for it\n", b->entitynum );
}
sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
com.sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
SetKeyValue (&entities[b->entitynum], "origin", string);
sprintf (string, "%i %i %i", (int)movedir[0], (int)movedir[1], (int)movedir[2]);
com.sprintf (string, "%i %i %i", (int)movedir[0], (int)movedir[1], (int)movedir[2]);
SetKeyValue (&entities[b->entitynum], "movedir", string);
VectorCopy (origin, entities[b->entitynum].origin);
// don't keep this brush
b->numsides = 0;
return;
}
AddBrushBevels (b);
AddBrushBevels( b );
nummapbrushes++;
mapent->numbrushes++;

View File

@ -1,6 +1,6 @@
#include "bsplib.h"
vec3_t texture_reflectivity[MAX_MAP_TEXINFO];
vec3_t texture_reflectivity[MAX_MAP_TEXTURES];
/*
===================================================================
@ -31,7 +31,7 @@ void CalcTextureReflectivity( void )
// see if an earlier texinfo allready got the value
for (j = 0; j < i; j++)
{
if( texinfo[i].texid == texinfo[j].texid )
if( texinfo[i].texnum == texinfo[j].texnum )
{
VectorCopy( texture_reflectivity[j], texture_reflectivity[i] );
break;
@ -39,11 +39,11 @@ void CalcTextureReflectivity( void )
}
if( j != i ) continue;
pic = FS_LoadImage(GetStringFromTable( texinfo[i].texid ), NULL, 0 );
pic = FS_LoadImage(GetStringFromTable(dmiptex[texinfo[i].texnum].s_name ), NULL, 0 );
Image_GetColor( pic );
// try also get direct values from shader
if(si = FindShader( GetStringFromTable(texinfo[i].texid)))
if(si = FindShader( GetStringFromTable(dmiptex[texinfo[i].texnum].s_name)))
{
if(!VectorIsNull( si->color ))
{
@ -114,26 +114,26 @@ BaseLightForFace
*/
void BaseLightForFace (dface_t *f, vec3_t color)
{
dsurfdesc_t *tx;
dtexinfo_t *tx;
//
// check for light emited by texture
//
tx = &texinfo[f->desc];
tx = &texinfo[f->texinfo];
if (!(tx->flags & SURF_LIGHT) || tx->value == 0)
{
VectorClear (color);
return;
}
VectorScale (texture_reflectivity[f->desc], tx->value, color);
VectorScale (texture_reflectivity[f->texinfo], tx->value, color);
}
bool IsSky (dface_t *f)
{
dsurfdesc_t *tx;
dtexinfo_t *tx;
tx = &texinfo[f->desc];
tx = &texinfo[f->texinfo];
if (tx->flags & SURF_SKY)
return true;
return false;
@ -194,7 +194,7 @@ void MakePatchForFace (int fn, winding_t *w)
patch->area = 1;
patch->sky = IsSky (f);
VectorCopy (texture_reflectivity[f->desc], patch->reflectivity);
VectorCopy (texture_reflectivity[f->texinfo], patch->reflectivity);
// non-bmodel patches can emit light
if (fn < dmodels[0].numfaces)

View File

@ -91,11 +91,12 @@ static shader_t *AllocShaderInfo( void )
if ( numShaderInfo == MAX_SURFACE_INFO ) Sys_Error( "MAX_SURFACE_INFO" );
si = &shaderInfo[ numShaderInfo ];
si = &shaderInfo[numShaderInfo];
numShaderInfo++;
// set defaults
si->contents = CONTENTS_SOLID;
si->nextframe[0] = '\0';
si->color[0] = 0;
si->color[1] = 0;
si->color[2] = 0;

View File

@ -2,83 +2,68 @@
#include "bsplib.h"
#include "byteorder.h"
int nummiptex;
extern int g_mapversion;
textureref_t textureref[MAX_MAP_TEXTURES];
//==========================================================================
int FindMiptex( char *name )
int FindMiptex( const char *name )
{
int i;
shader_t *si;
rgbdata_t *tex;
for (i = 0; i < nummiptex; i++ )
int i;
string_t texname;
rgbdata_t *image;
if(!com.strlen( name )) return 0;
// register new name, or get already existing
texname = GetIndexFromTable( name );
for( i = 0; i < nummiptex; i++ )
{
if (!stricmp(name, textureref[i].texname))
if( dmiptex[i].s_name == texname )
return i;
}
if( nummiptex == MAX_MAP_TEXTURES ) Sys_Break("MAX_MAP_TEXTURES limit exceeds\n");
// register texture
com.strcpy (textureref[i].texname, name );
tex = FS_LoadImage( textureref[i].texname, NULL, 0 );
if( tex )
{
textureref[i].size[0] = tex->width;
textureref[i].size[1] = tex->height;
FS_FreeImage( tex );
}
else textureref[i].size[0] = textureref[i].size[1] = -1; // technically an error
// allocate a new texture
if( nummiptex == MAX_MAP_TEXTURES ) Sys_Break( "MAX_MAP_TEXTURES limit exceeded\n" );
si = FindShader( name );
if(si)
{
textureref[i].value = LittleLong (si->intensity);
textureref[i].flags = LittleLong (si->surfaceFlags);
textureref[i].contents = LittleLong (si->contents);
com.strcpy(textureref[i].animname, si->nextframe);
}
nummiptex++;
// alloc new texture
dmiptex[i].s_name = texname;
if (textureref[i].animname[0])
image = FS_LoadImage( name, NULL, 0 );
if( image )
{
// MsgDev(D_INFO, "FindMiptex: animation chain \"%s->%s\"\n", textureref[i].name, textureref[i].animname );
FindMiptex(textureref[i].texname);
// save texture dimensions that can be used
// for replacing original textures with HQ images
dmiptex[i].size[0] = image->width;
dmiptex[i].size[1] = image->height;
FS_FreeImage( image );
}
return i;
else dmiptex[i].size[0] = dmiptex[i].size[1] = -1; // technically an error
return nummiptex++;
}
/*
==================
textureAxisFromPlane
==================
*/
vec3_t baseaxis[18] =
vec3_t baseaxis[18] =
{
{0,0,1}, {1,0,0}, {0,-1,0}, // floor
{0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling
{1,0,0}, {0,1,0}, {0,0,-1}, // west wall
{-1,0,0}, {0,1,0}, {0,0,-1}, // east wall
{0,1,0}, {1,0,0}, {0,0,-1}, // south wall
{0,-1,0}, {1,0,0}, {0,0,-1} // north wall
{0,0,1}, {1,0,0}, {0,-1,0}, // floor
{0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling
{1,0,0}, {0,1,0}, {0,0,-1}, // west wall
{-1,0,0}, {0,1,0}, {0,0,-1}, // east wall
{0,1,0}, {1,0,0}, {0,0,-1}, // south wall
{0,-1,0}, {1,0,0}, {0,0,-1}, // north wall
};
void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv)
void TextureAxisFromPlane( plane_t *plane, vec3_t xv, vec3_t yv )
{
int bestaxis;
vec_t dot,best;
int i;
int bestaxis = 0;
vec_t dot, best = 0;
int i;
best = 0;
bestaxis = 0;
for (i=0 ; i<6 ; i++)
for( i = 0; i < 6; i++ )
{
dot = DotProduct (pln->normal, baseaxis[i*3]);
dot = DotProduct( plane->normal, baseaxis[i*3] );
if (dot > best)
{
best = dot;
@ -86,65 +71,62 @@ void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv)
}
}
VectorCopy (baseaxis[bestaxis*3+1], xv);
VectorCopy (baseaxis[bestaxis*3+2], yv);
VectorCopy( baseaxis[bestaxis*3+1], xv );
VectorCopy( baseaxis[bestaxis*3+2], yv );
}
int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin)
int TexinfoForBrushTexture( plane_t *plane, brush_texture_t *bt, vec3_t origin )
{
vec3_t vecs[2];
int sv, tv;
vec_t ang, sinv, cosv;
vec_t ns, nt;
dsurfdesc_t tx, *tc;
vec3_t vecs[2];
int i, j, k;
brush_texture_t anim;
int mt;
dtexinfo_t tx, *tc;
int sv, tv;
vec_t ns, nt;
if (!bt->name[0]) return 0;
if( !bt->name[0] ) return 0;
memset (&tx, 0, sizeof(tx));
tx.texid = GetIndexFromTable( bt->name );
memset( &tx, 0, sizeof( tx ));
tx.texnum = FindMiptex( bt->name );
if (bt->txcommand)
if( bt->txcommand )
{
Mem_Copy(tx.vecs, bt->vects.quark.vects, sizeof(tx.vecs));
Mem_Copy( tx.vecs, bt->vects.quark.vects, sizeof( tx.vecs ));
if (origin[0] || origin[1] || origin[2])
if(!VectorIsNull( origin ))
{
tx.vecs[0][3] += DotProduct(origin, tx.vecs[0]);
tx.vecs[1][3] += DotProduct(origin, tx.vecs[1]);
tx.vecs[0][3] += DotProduct( origin, tx.vecs[0] );
tx.vecs[1][3] += DotProduct( origin, tx.vecs[1] );
}
tx.contents = bt->contents;
tx.flags = bt->flags;
tx.value = bt->value;
tx.size[0] = bt->size[0];
tx.size[1] = bt->size[1];
}
else
{
if (g_mapversion < VALVE_FORMAT) TextureAxisFromPlane(plane, vecs[0], vecs[1]);
if (!bt->vects.valve.scale[0]) bt->vects.valve.scale[0] = 1;
if (!bt->vects.valve.scale[1]) bt->vects.valve.scale[1] = 1;
if( g_mapversion < VALVE_FORMAT ) TextureAxisFromPlane( plane, vecs[0], vecs[1] );
if( !bt->vects.valve.scale[0] ) bt->vects.valve.scale[0] = 1;
if( !bt->vects.valve.scale[1] ) bt->vects.valve.scale[1] = 1;
if (g_mapversion < VALVE_FORMAT)
if( g_mapversion < VALVE_FORMAT )
{
// rotate axis
if (bt->vects.valve.rotate == 0)
if( bt->vects.valve.rotate == 0 )
{
sinv = 0;
cosv = 1;
}
else if (bt->vects.valve.rotate == 90)
else if( bt->vects.valve.rotate == 90 )
{
sinv = 1;
cosv = 0;
}
else if (bt->vects.valve.rotate == 180)
else if( bt->vects.valve.rotate == 180 )
{
sinv = 0;
cosv = -1;
}
else if (bt->vects.valve.rotate == 270)
else if( bt->vects.valve.rotate == 270 )
{
sinv = -1;
cosv = 0;
@ -152,18 +134,18 @@ int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin)
else
{
ang = bt->vects.valve.rotate / 180 * M_PI;
sinv = sin(ang);
cosv = cos(ang);
sinv = sin( ang );
cosv = cos( ang );
}
if (vecs[0][0]) sv = 0;
else if (vecs[0][1]) sv = 1;
if( vecs[0][0] ) sv = 0;
else if( vecs[0][1] ) sv = 1;
else sv = 2;
if (vecs[1][0]) tv = 0;
else if (vecs[1][1]) tv = 1;
if( vecs[1][0] ) tv = 0;
else if( vecs[1][1] ) tv = 1;
else tv = 2;
for (i = 0; i < 2; i++)
for( i = 0; i < 2; i++ )
{
ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
nt = sinv * vecs[i][sv] + cosv * vecs[i][tv];
@ -171,17 +153,13 @@ int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin)
vecs[i][tv] = nt;
}
for (i = 0; i < 2; i++)
{
for (j = 0; j < 3; j++)
{
for( i = 0; i < 2; i++ )
for( j = 0; j < 3; j++ )
tx.vecs[i][j] = vecs[i][j] / bt->vects.valve.scale[i];
}
}
}
else
{
vec_t scale;
vec_t scale;
scale = 1 / bt->vects.valve.scale[0];
VectorScale(bt->vects.valve.UAxis, scale, tx.vecs[0]);
@ -193,41 +171,28 @@ int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin)
tx.vecs[1][3] = bt->vects.valve.shift[1] + DotProduct(origin, tx.vecs[1]);
tx.flags = bt->flags;
tx.value = bt->value;
tx.size[0] = bt->size[0];
tx.size[1] = bt->size[1];
}
// find the texinfo
tc = texinfo;
for (i = 0; i < numtexinfo; i++, tc++)
for( i = 0; i < numtexinfo; i++, tc++ )
{
if (tc->flags != tx.flags) continue;
if (tc->value != tx.value) continue;
for (j = 0; j < 2; j++)
if( tc->flags != tx.flags ) continue;
if( tc->value != tx.value ) continue;
for( j = 0; j < 2; j++ )
{
if( tc->texid != tx.texid ) goto skip;
if( tc->texnum != tx.texnum ) goto skip;
for( k = 0; k < 4; k++ )
{
if (tc->vecs[j][k] != tx.vecs[j][k])
if( tc->vecs[j][k] != tx.vecs[j][k] )
goto skip;
}
}
return i;
skip:;
}
// register new texinfo
*tc = tx;
numtexinfo++;
// load the next animation
mt = FindMiptex( bt->name );
if (textureref[mt].animname[0])
{
anim = *bt;
strcpy (anim.name, textureref[mt].animname);
tc->animid = TexinfoForBrushTexture (plane, &anim, origin);
}
else tc->animid = -1;
return i;
}
return numtexinfo++;
}

View File

@ -190,7 +190,7 @@ void EmitFace (face_t *f)
df->firstedge = numsurfedges;
df->numedges = f->numpoints;
df->desc = f->texinfo;
df->texinfo = f->texinfo;
for (i=0 ; i<f->numpoints ; i++)
{
// e = GetEdge (f->pts[i], f->pts[(i+1)%f->numpoints], f);
@ -396,7 +396,7 @@ void EmitBrushes (void)
cp = &dbrushsides[numbrushsides];
numbrushsides++;
cp->planenum = b->original_sides[j].planenum;
cp->surfdesc = b->original_sides[j].texinfo;
cp->texinfo = b->original_sides[j].texinfo;
}
// add any axis planes not contained in the brush to bevel off corners
@ -420,8 +420,7 @@ void EmitBrushes (void)
Sys_Error ("MAX_MAP_BRUSHSIDES");
dbrushsides[numbrushsides].planenum = planenum;
dbrushsides[numbrushsides].surfdesc =
dbrushsides[numbrushsides-1].surfdesc;
dbrushsides[numbrushsides].texinfo = dbrushsides[numbrushsides-1].texinfo;
numbrushsides++;
db->numsides++;
}

View File

@ -71,5 +71,5 @@ if exist vsound\vsound.plg del /f /q vsound\vsound.plg
echo Build succeeded!
echo Please wait. Xash is now loading
cd D:\Xash3D\
xash.exe -log -debug -dev 3 +map dm_qstyle
quake.exe -game tmpQuArK -log -debug -dev 3 +map start
:done

View File

@ -158,12 +158,13 @@ typedef struct clipmap_s
dedge_t *edges;
dface_t *surfaces;
int *surfedges;
csurface_t *surfdesc;
csurface_t *texinfo;
cbrush_t *brushes;
cbrushside_t *brushsides;
byte *visbase; // vis offset
dvis_t *vis;
NewtonCollision *collision;
dmiptex_t *textures;
char *stringdata;
int *stringtable;
carea_t *areas;
@ -177,6 +178,7 @@ typedef struct clipmap_s
int numleafs; // allow leaf funcs to be called without a map
int numleafbrushes;
int numleafsurfaces;
int numtextures;
int numbrushes;
int numfaces;
int numareas;

View File

@ -87,11 +87,11 @@ void CM_FreeModel( cmodel_t *mod )
mod = NULL;
}
int CM_NumTexinfo( void ) { return cm.numtexinfo; }
int CM_NumTextures( void ) { return cm.numtextures; }
int CM_NumClusters( void ) { return cm.numclusters; }
int CM_NumInlineModels( void ) { return cm.numbmodels; }
const char *CM_EntityString( void ) { return cm.entitystring; }
const char *CM_TexName( int index ) { return cm.surfdesc[index].name; }
const char *CM_TexName( int index ) { return CM_GetStringFromTable( cm.textures[index].s_name ); }
/*
===============================================================================
@ -131,7 +131,7 @@ void BSP_CreateMeshBuffer( int modelnum )
vec3_t *face;
m_face = cm.surfaces + i;
flags = cm.surfdesc[m_face->desc].surfaceflags;
flags = cm.texinfo[m_face->texinfo].surfaceflags;
k = m_face->firstedge;
// sky is noclip for all physobjects
@ -208,28 +208,56 @@ void BSP_LoadModels( lump_t *l )
/*
=================
BSP_LoadSurfDesc
BSP_LoadTextures
=================
*/
void BSP_LoadSurfDesc( lump_t *l )
void BSP_LoadTextures( lump_t *l )
{
dsurfdesc_t *in;
dmiptex_t *in;
dmiptex_t *out;
int i, count;
in = (void *)(cm.mod_base + l->fileofs);
if (l->filelen % sizeof(*in)) Host_Error("BSP_LoadTextures: funny lump size\n" );
count = l->filelen / sizeof(*in);
out = cm.textures = (dmiptex_t *)Mem_Alloc( cmappool, count * sizeof(*out));
cm.numtextures = count;
for ( i = 0; i < count; i++, in++, out++)
{
out->s_name = LittleLong( in->s_name );
out->s_name = LittleLong( in->s_next );
out->size[0] = LittleLong( in->size[0] );
out->size[1] = LittleLong( in->size[1] );
}
}
/*
=================
BSP_LoadTexinfo
=================
*/
void BSP_LoadTexinfo( lump_t *l )
{
dtexinfo_t *in;
csurface_t *out;
int i, count;
in = (void *)(cm.mod_base + l->fileofs);
if (l->filelen % sizeof(*in)) Host_Error("BSP_LoadSurfDesc: funny lump size\n" );
if (l->filelen % sizeof(*in)) Host_Error("BSP_LoadTexinfo: funny lump size\n" );
count = l->filelen / sizeof(*in);
out = cm.surfdesc = (csurface_t *)Mem_Alloc( cmappool, count * sizeof(*out));
out = cm.texinfo = (csurface_t *)Mem_Alloc( cmappool, count * sizeof(*out));
cm.numtexinfo = count;
for ( i = 0; i < count; i++, in++, out++)
{
com.strncpy( out->name, CM_GetStringFromTable(LittleLong( in->texid )), MAX_STRING );
com.strncpy( out->name, CM_TexName( LittleLong( in->texnum )), MAX_STRING );
out->contentflags = LittleLong( in->contents );
out->surfaceflags = LittleLong( in->flags );
out->contentflags = 0;//FIXME: upgrade BSP version, that include contents for all sides
out->value = LittleLong( in->value );
// currently not used
VectorClear( out->mins );
VectorClear( out->maxs );
@ -494,9 +522,9 @@ void BSP_LoadBrushSides( lump_t *l )
{
num = LittleLong(in->planenum);
out->plane = cm.planes + num;
j = LittleLong(in->surfdesc);
j = bound(0, j, cm.numtexinfo - 1);
out->surface = cm.surfdesc + j;
j = LittleLong( in->texinfo );
j = bound( 0, j, cm.numtexinfo - 1 );
out->surface = cm.texinfo + j;
}
}
@ -667,9 +695,9 @@ void BSP_LoadFaces( lump_t *l )
for( i = 0; i < cm.numfaces; i++, in++, out++)
{
out->firstedge = LittleLong(in->firstedge);
out->firstedge = LittleLong( in->firstedge );
out->numedges = LittleLong(in->numedges);
out->desc = LittleLong(in->desc);
out->texinfo = LittleLong( in->texinfo );
}
}
@ -781,7 +809,7 @@ static void BSP_RecursiveSetParent( cnode_t *node, cnode_t *parent )
for( i = 0; i < leaf->numleafsurfaces; i++ )
{
dface_t *m_face = cm.surfaces + leaf->firstleafsurface[i];
csurface_t *surface = cm.surfdesc + m_face->desc;
csurface_t *surface = cm.texinfo + m_face->texinfo;
if( surface->numtriangles )
{
leaf->havepatches = true;
@ -818,7 +846,7 @@ void BSP_AddCollisionFace( int facenum )
}
m_face = cm.surfaces + facenum;
flags = cm.surfdesc[m_face->desc].surfaceflags;
flags = cm.texinfo[m_face->texinfo].surfaceflags;
k = m_face->firstedge;
// sky is noclip for all physobjects
@ -827,7 +855,7 @@ void BSP_AddCollisionFace( int facenum )
if( cm_use_triangles->integer )
{
// convert polygon to triangles
for(j = 0; j < m_face->numedges - 2; j++)
for( j = 0; j < m_face->numedges - 2; j++ )
{
vec3_t face[3]; // triangle
CM_GetPoint( k, face[0] );
@ -868,7 +896,8 @@ void CM_LoadBSP( const void *buffer )
BSP_LoadVerts(&header.lumps[LUMP_VERTEXES]);
BSP_LoadEdges(&header.lumps[LUMP_EDGES]);
BSP_LoadSurfedges(&header.lumps[LUMP_SURFEDGES]);
BSP_LoadSurfDesc(&header.lumps[LUMP_SURFDESC]);
BSP_LoadTextures(&header.lumps[LUMP_TEXTURES]);
BSP_LoadTexinfo(&header.lumps[LUMP_TEXINFO]);
BSP_LoadFaces(&header.lumps[LUMP_FACES]);
BSP_LoadModels(&header.lumps[LUMP_MODELS]);
BSP_LoadCollision(&header.lumps[LUMP_COLLISION]);
@ -950,7 +979,7 @@ void CM_FreeWorld( void )
cm.numleafbrushes = cm.numfaces = cm.numbmodels = 0;
cm.floodvalid = cm.numbrushsides = cm.numtexinfo = 0;
cm.numbrushes = cm.numleafsurfaces = cm.numareas = 0;
cm.numareaportals = cm.numclusters = 0;
cm.numareaportals = cm.numclusters = cm.numtextures = 0;
cm.name[0] = 0;
memset( cm.matrix, 0, sizeof(matrix4x4));
@ -1027,7 +1056,8 @@ cmodel_t *CM_BeginRegistration( const char *name, bool clientload, uint *checksu
BSP_LoadStringData(&hdr->lumps[LUMP_STRINGDATA]);
BSP_LoadStringTable(&hdr->lumps[LUMP_STRINGTABLE]);
BSP_LoadEntityString(&hdr->lumps[LUMP_ENTITIES]);
BSP_LoadSurfDesc(&hdr->lumps[LUMP_SURFDESC]);
BSP_LoadTextures(&hdr->lumps[LUMP_TEXTURES]);
BSP_LoadTexinfo(&hdr->lumps[LUMP_TEXINFO]);
BSP_LoadPlanes(&hdr->lumps[LUMP_PLANES]);
BSP_LoadBrushSides(&hdr->lumps[LUMP_BRUSHSIDES]);
BSP_LoadBrushes(&hdr->lumps[LUMP_BRUSHES]);

View File

@ -114,7 +114,7 @@ static void CM_TraceLine_r( trace_t *trace, cmodel_t *model, cnode_t *node, cons
// line trace the curves
for( i = 0; i < leaf->numleafsurfaces; i++ )
{
surface = cm.surfdesc + cm.surfaces[leaf->firstleafsurface[i]].desc;
surface = cm.texinfo + cm.surfaces[leaf->firstleafsurface[i]].texinfo;
if( surface->numtriangles && surface->markframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
{
surface->markframe = markframe;
@ -191,7 +191,7 @@ static void CM_TraceBrush_r( trace_t *trace, cmodel_t *model, cnode_t *node, con
{
for( i = 0; i < leaf->numleafsurfaces; i++ )
{
surface = cm.surfdesc + cm.surfaces[leaf->firstleafsurface[i]].desc;
surface = cm.texinfo + cm.surfaces[leaf->firstleafsurface[i]].texinfo;
if( surface->numtriangles && surface->markframe != markframe && BoxesOverlap( nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs ))
{
surface->markframe = markframe;
@ -241,7 +241,7 @@ void CM_TraceBmodel( const vec3_t start, const vec3_t end, const vec3_t mins, co
if( brush->colbrushf ) CM_CollisionTraceLineBrushFloat( trace, start, end, brush->colbrushf, brush->colbrushf );
for( i = 0, j = model->firstface; i < model->numfaces; i++, j++ )
{
surface = cm.surfdesc + cm.surfaces[j].desc;
surface = cm.texinfo + cm.surfaces[j].texinfo;
if( surface->numtriangles ) CM_CollisionTraceLineTriangleMeshFloat( trace, start, end, surface->numtriangles, surface->indices, surface->vertices, surface->contentflags, surface->surfaceflags, surface, segmentmins, segmentmaxs );
}
}
@ -275,7 +275,7 @@ void CM_TraceBmodel( const vec3_t start, const vec3_t end, const vec3_t mins, co
if( brush->colbrushf ) CM_CollisionTraceBrushBrushFloat( trace, thisbrush_start, thisbrush_end, brush->colbrushf, brush->colbrushf );
for( i = 0, j = model->firstface; i < model->numfaces; i++, j++ )
{
surface = cm.surfdesc + cm.surfaces[j].desc;
surface = cm.texinfo + cm.surfaces[j].texinfo;
if( surface->numtriangles ) CM_CollisionTraceLineTriangleMeshFloat( trace, start, end, surface->numtriangles, surface->indices, surface->vertices, surface->contentflags, surface->surfaceflags, surface, segmentmins, segmentmaxs );
}
}

View File

@ -49,7 +49,7 @@ void CM_GetAreaPortals ( byte **portals, size_t *size );
void CM_SetAreaPortalState ( int portalnum, bool open );
int CM_NumClusters( void );
int CM_NumTexinfo( void );
int CM_NumTextures( void );
int CM_NumInlineModels( void );
const char *CM_EntityString( void );
const char *CM_TexName( int index );

View File

@ -88,7 +88,7 @@ physic_exp_t DLLEXPORT *CreateAPI ( stdlib_api_t *input, physic_imp_t *engfuncs
Phys.SetAreaPortalState = CM_SetAreaPortalState;
Phys.NumClusters = CM_NumClusters;
Phys.NumTextures = CM_NumTexinfo;
Phys.NumTextures = CM_NumTextures;
Phys.NumBmodels = CM_NumInlineModels;
Phys.GetEntityString = CM_EntityString;
Phys.GetTextureName = CM_TexName;

View File

@ -20,6 +20,10 @@ typedef unsigned short word;
typedef unsigned long dword;
typedef unsigned int uint;
typedef signed __int64 int64;
typedef int func_t;
typedef int sound_t;
typedef int model_t;
typedef int string_t;
typedef float vec_t;
typedef vec_t vec2_t[2];
typedef vec_t vec3_t[3];
@ -30,4 +34,5 @@ typedef vec_t matrix4x3[4][3];
typedef vec_t matrix4x4[4][4];
typedef char string[MAX_STRING];
#endif//BASETYPES_H

View File

@ -226,7 +226,7 @@ BRUSH MODELS
#define LUMP_VERTEXES 6
#define LUMP_EDGES 7
#define LUMP_SURFEDGES 8
#define LUMP_SURFDESC 9
#define LUMP_TEXINFO 9
#define LUMP_FACES 10
#define LUMP_MODELS 11
#define LUMP_BRUSHES 12
@ -234,7 +234,7 @@ BRUSH MODELS
#define LUMP_VISIBILITY 14
#define LUMP_LIGHTING 15
#define LUMP_COLLISION 16 // newton collision tree (worldmodel coords already convert to meters)
#define LUMP_BVHSTATIC 17 // bullet collision tree (currently not used)
#define LUMP_TEXTURES 17 // contains texture name and dims
#define LUMP_SVPROGS 18 // private server.dat for current map
#define LUMP_WAYPOINTS 19 // AI navigate tree (like .aas file for quake3)
#define LUMP_STRINGDATA 20 // string array
@ -253,6 +253,9 @@ BRUSH MODELS
#define DVIS_PVS 0
#define DVIS_PHS 1
#define DENT_KEY 0
#define DENT_VALUE 1
//other limits
#define MAXLIGHTMAPS 4
typedef struct
@ -279,6 +282,11 @@ typedef struct
int numbrushes;
} dmodel_t;
typedef struct
{
string_t epair[2]; // 0 - key, 1 - value (indexes from stringtable)
} dentity_t;
typedef struct
{
float point[3];
@ -300,15 +308,14 @@ typedef struct
int numfaces; // counting both sides
} dnode_t;
typedef struct dsurfdesc_s
typedef struct
{
float vecs[2][4]; // [s/t][xyz offset] texture s\t
int size[2]; // valid size for current s\t coords (used for replace texture)
int texid; // string table texture id number
int animid; // string table animchain id number
int flags; // surface flags
int value; // used by qrad, not engine
} dsurfdesc_t;
int texnum; // texture number in LUMP_TEXTURES array
int contents; // texture contents (can be replaced by shader)
int flags; // surface flags (can be replaced by shader)
int value; // get rid of this ? used by qrad, not engine
} dtexinfo_t;
typedef struct
{
@ -320,7 +327,7 @@ typedef struct
int planenum;
int firstedge;
int numedges;
int desc;
int texinfo; // number in LUMP_TEXINFO array
// lighting info
byte styles[MAXLIGHTMAPS];
@ -346,7 +353,7 @@ typedef struct
typedef struct
{
int planenum; // facing out of the leaf
int surfdesc; // surface description (s/t coords, flags, etc)
int texinfo; // surface description (s/t coords, flags, etc)
} dbrushside_t;
typedef struct
@ -362,6 +369,13 @@ typedef struct
int bitofs[8][2]; // bitofs[numclusters][2]
} dvis_t;
typedef struct
{
string_t s_name; // string system index
string_t s_next; // anim chain texture
int size[2]; // valid size for current s\t coords (used for replace texture)
} dmiptex_t;
typedef struct
{
int portalnum;

View File

@ -65,10 +65,6 @@ typedef struct sizebuf_s
int readcount;
} sizebuf_t;
typedef int func_t;
typedef int sound_t;
typedef int model_t;
typedef int string_t;
typedef struct edict_s edict_t;
typedef struct sv_edict_s sv_edict_t;
typedef struct cl_edict_s cl_edict_t;

View File

@ -436,19 +436,64 @@ void Mod_LoadEdges (lump_t *l)
/*
=================
Mod_LoadSurfDesc
BSP_LoadTextures
=================
*/
void Mod_LoadSurfDesc( lump_t *l )
void Mod_LoadTextures( lump_t *l )
{
dsurfdesc_t *in;
mtexinfo_t *out, *step;
dmiptex_t *in, *in2;
mtexture_t *out, *step;
int i, next, count;
in = in2 = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in)) Host_Error("Mod_LoadTextures: funny lump size\n" );
count = l->filelen / sizeof(*in);
out = (mtexture_t *)Mem_Alloc( loadmodel->mempool, count * sizeof(*out));
loadmodel->textures = out;
loadmodel->numtextures = count;
for ( i = 0; i < count; i++, in++, out++)
{
com.strncpy( out->name, Mod_GetStringFromTable( LittleLong( in->s_name )), MAX_STRING );
out->width = LittleLong( in->size[0] );
out->height = LittleLong( in->size[1] );
out->image = r_notexture; // make stub
next = LittleLong( in->s_next );
if( next ) out->next = loadmodel->textures + next;
else out->next = NULL;
}
// count animation frames
for( i = 0; i < count; i++ )
{
out = &loadmodel->textures[i];
out->numframes = 1;
for( step = out->next; step && step != out; step = step->next )
{
Msg("animchain %s\n", out->name );
out->numframes++;
}
}
}
/*
=================
Mod_LoadTexinfo
=================
*/
void Mod_LoadTexinfo( lump_t *l )
{
dtexinfo_t *in;
mtexinfo_t *out;
int texnum;
int i, j, count;
int next;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Host_Error("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
Host_Error("MOD_LoadTexinfo: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Mem_Alloc( loadmodel->mempool, count * sizeof(*out));
@ -458,27 +503,15 @@ void Mod_LoadSurfDesc( lump_t *l )
for ( i = 0; i < count; i++, in++, out++)
{
for( j = 0; j < 8; j++ )
out->vecs[0][j] = LittleFloat(in->vecs[0][j]);
out->vecs[0][j] = LittleFloat( in->vecs[0][j] );
out->flags = LittleLong (in->flags);
next = LittleLong (in->animid);
if( next > 0 ) out->next = loadmodel->texinfo + next;
else out->next = NULL;
out->flags = LittleLong( in->flags );
out->contents = LittleLong( in->contents );
texnum = LittleLong( in->texnum );
// fixed texture size
out->size[0] = LittleLong( in->size[0] );
out->size[1] = LittleLong( in->size[1] );
out->texid = LittleLong( in->texid ); // will be loading later
out->image = r_notexture; // make default
}
// count animation frames
for( i = 0; i < count; i++ )
{
out = &loadmodel->texinfo[i];
out->numframes = 1;
for( step = out->next; step && step != out; step = step->next )
out->numframes++;
if( texnum < 0 || texnum > loadmodel->numtextures )
Host_Error("MOD_LoadBmodel: bad texture number\n");
out->texture = loadmodel->textures + texnum;
}
}
@ -563,9 +596,9 @@ void Mod_LoadFaces (lump_t *l)
m_pRenderModel = loadmodel;
GL_BeginBuildingLightmaps (loadmodel);
GL_BeginBuildingLightmaps( loadmodel );
for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
for( surfnum = 0; surfnum < count; surfnum++, in++, out++ )
{
out->firstedge = LittleLong(in->firstedge);
out->numedges = LittleLong(in->numedges);
@ -573,31 +606,28 @@ void Mod_LoadFaces (lump_t *l)
out->polys = NULL;
planenum = LittleLong( in->planenum );
side = LittleShort(in->side);
side = LittleShort( in->side );
if( side ) out->flags |= SURF_PLANEBACK;
out->plane = loadmodel->planes + planenum;
ti = LittleLong (in->desc);
if (ti < 0 || ti >= loadmodel->numtexinfo)
Host_Error("MOD_LoadBmodel: bad texinfo number");
ti = LittleLong( in->texinfo );
if( ti < 0 || ti >= loadmodel->numtexinfo )
Host_Error("MOD_LoadBmodel: bad texinfo number\n");
out->texinfo = loadmodel->texinfo + ti;
CalcSurfaceExtents (out);
CalcSurfaceExtents( out );
// lighting info
for( i = 0; i < MAXLIGHTMAPS; i++)
for( i = 0; i < MAXLIGHTMAPS; i++ )
out->styles[i] = in->styles[i];
i = LittleLong(in->lightofs);
if (i == -1)
out->samples = NULL;
else
out->samples = loadmodel->lightdata + i;
i = LittleLong( in->lightofs );
if( i == -1 ) out->samples = NULL;
else out->samples = loadmodel->lightdata + i;
// set the drawing flags
if (out->texinfo->flags & SURF_WARP)
// set the drawing flags
if( out->texinfo->flags & SURF_WARP )
{
out->flags |= SURF_DRAWTURB;
for (i=0 ; i<2 ; i++)
@ -893,7 +923,8 @@ void Mod_LoadBrushModel (rmodel_t *mod, void *buffer)
Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
Mod_LoadSurfDesc (&header->lumps[LUMP_SURFDESC]);
Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
Mod_LoadFaces (&header->lumps[LUMP_FACES]);
Mod_LoadMarksurfaces (&header->lumps[LUMP_LEAFFACES]);
Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
@ -975,7 +1006,7 @@ rmodel_t *R_RegisterModel (const char *name)
case mod_world:
case mod_brush:
for (i = 0; i < mod->numtexinfo; i++)
mod->texinfo[i].image->registration_sequence = registration_sequence;
mod->texinfo[i].texture->image->registration_sequence = registration_sequence;
break;
case mod_studio:
case mod_sprite:

View File

@ -121,100 +121,108 @@ typedef struct
typedef struct
{
unsigned short v[2];
unsigned int cachededgeoffset;
uint v[2];
uint cachededgeoffset;
} medge_t;
typedef struct mtexture_s
{
string name;
image_t *image;
struct mtexture_s *next; // animation chain
uint width;
uint height;
int numframes;
} mtexture_t;
typedef struct mtexinfo_s
{
float vecs[2][4];
int size[2];
int flags;
int numframes;
int texid; // save texture id
struct mtexinfo_s *next; // animation chain
image_t *image;
int contents;
mtexture_t *texture;
} mtexinfo_t;
#define VERTEXSIZE 7
typedef struct glpoly_s
{
struct glpoly_s *next;
struct glpoly_s *chain;
struct glpoly_s *next;
struct glpoly_s *chain;
int numverts;
int flags; // for SURF_UNDERWATER (not needed anymore?)
float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
} glpoly_t;
typedef struct msurface_s
{
int visframe; // should be drawn when node is crossed
int visframe; // should be drawn when node is crossed
cplane_t *plane;
int flags;
cplane_t *plane;
int flags;
int firstedge; // look up in model->surfedges[], negative numbers
int numedges; // are backwards edges
int firstedge; // look up in model->surfedges[], negative numbers
int numedges; // are backwards edges
short texturemins[2];
short extents[2];
int light_s, light_t; // gl lightmap coordinates
int dlight_s, dlight_t; // gl lightmap coordinates for dynamic lightmaps
int light_s, light_t; // gl lightmap coordinates
int dlight_s, dlight_t; // gl lightmap coordinates for dynamic lightmaps
glpoly_t *polys; // multiple if warped
struct msurface_s *texturechain;
struct msurface_s *lightmapchain;
glpoly_t *polys; // multiple if warped
struct msurface_s *texturechain;
struct msurface_s *lightmapchain;
mtexinfo_t *texinfo;
// lighting info
int dlightframe;
int dlightbits;
// lighting info
int dlightframe;
int dlightbits;
int lightmaptexturenum;
int lightmaptexturenum;
byte styles[MAXLIGHTMAPS];
float cached_light[MAXLIGHTMAPS]; // values currently used in lightmap
byte *samples; // [numstyles*surfsize]
byte *samples; // [numstyles*surfsize]
} msurface_t;
typedef struct mnode_s
{
// common with leaf
int contents; // -1, to differentiate from leafs
int visframe; // node needs to be traversed if current
int contents; // -1, to differentiate from leafs
int visframe; // node needs to be traversed if current
float minmaxs[6]; // for bounding box culling
struct mnode_s *parent;
// node specific
cplane_t *plane;
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
uint firstsurface;
uint numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
// common with node
int contents; // wil be a negative contents number
int visframe; // node needs to be traversed if current
// common with node
int contents; // wil be a negative contents number
int visframe; // node needs to be traversed if current
float minmaxs[6]; // for bounding box culling
float minmaxs[6]; // for bounding box culling
struct mnode_s *parent;
// leaf specific
int cluster;
int area;
// leaf specific
int cluster;
int area;
msurface_t **firstmarksurface;
int nummarksurfaces;
int nummarksurfaces;
} mleaf_t;
//===================================================================
@ -235,24 +243,19 @@ typedef struct rmodel_s
int flags;
//
// volume occupied by the model graphics
//
// volume occupied by the model graphics
vec3_t mins, maxs;
float radius;
//
// solid volume for clipping
//
// solid volume for clipping
bool clipbox;
vec3_t clipmins, clipmaxs;
// simple lighting for sprites and models
vec3_t lightcolor;
//
// brush model //move this to brush_t struct
//
// brush model
// TODO: move this to union extradata_t
int firstmodelsurface, nummodelsurfaces;
int lightmap; // only for submodels
@ -278,6 +281,9 @@ typedef struct rmodel_s
int numtexinfo;
mtexinfo_t *texinfo;
int numtextures;
mtexture_t *textures;
int numsurfaces;
msurface_t *surfaces;
@ -300,12 +306,7 @@ typedef struct rmodel_s
studiohdr_t *phdr;
studiohdr_t *thdr;
void *extradata;
//sprite auto animating
float frame;
float animtime;
float prevanimtime;
void *extradata;
} rmodel_t;
//============================================================================

View File

@ -1305,19 +1305,17 @@ bool R_UploadModel( const char *name, int index )
return (mod != NULL);
}
bool R_UploadImage( const char *name, int index )
bool R_UploadImage( const char *unused, int index )
{
string filename;
image_t *texture;
// nothing to load
if( !r_worldmodel )
return false;
if( !r_worldmodel ) return false;
loadmodel = r_worldmodel;
com.strncpy( filename, Mod_GetStringFromTable( loadmodel->texinfo[index].texid ), sizeof(filename));
texture = R_FindImage( filename, NULL, 0, it_wall );
loadmodel->texinfo[index].image = texture;
Msg("load texture %s\n", loadmodel->textures[index].name );
texture = R_FindImage( loadmodel->textures[index].name, NULL, 0, it_wall );
loadmodel->textures[index].image = texture; // now all pointers are valid
return true;
}

View File

@ -80,14 +80,15 @@ R_TextureAnimation
Returns the proper texture for a given time and base texture
===============
*/
image_t *R_TextureAnimation (mtexinfo_t *tex)
image_t *R_TextureAnimation( mtexinfo_t *tinfo )
{
int c;
mtexture_t *tex = tinfo->texture;
int c;
if (!tex->next) return tex->image;
if( !tex->next ) return tex->image;
c = (int)m_pCurrentEntity->frame % tex->numframes;
while (c)
while( c )
{
tex = tex->next;
c--;
@ -101,7 +102,7 @@ image_t *R_TextureAnimation (mtexinfo_t *tex)
DrawGLPoly
================
*/
void DrawGLPoly (glpoly_t *p)
void DrawGLPoly( glpoly_t *p )
{
int i;
float *v;
@ -240,7 +241,7 @@ void R_DrawLumaChains( void )
for( s = r_luma_surfaces; s; s = s->texturechain )
{
GL_Bind(s->texinfo->image->lumatex[0]);
GL_Bind( s->texinfo->texture->image->lumatex[0] );
DrawGLPoly (s->polys);
}
@ -525,7 +526,7 @@ void R_DrawAlphaSurfaces (void)
for (s=r_alpha_surfaces ; s ; s=s->texturechain)
{
GL_Bind(s->texinfo->image->texnum[0]);
GL_Bind( s->texinfo->texture->image->texnum[0] );
c_brush_polys++;
if (s->texinfo->flags & SURF_BLEND)
pglColor4f(intens,intens, intens, 0.5);
@ -1435,12 +1436,12 @@ void GL_BuildPolygonFromSurface(msurface_t *fa)
vec = m_pRenderModel->vertexes[r_pedge->v[1]].position;
}
s = DotProduct( vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
if( fa->texinfo->size[0] != -1 ) s /= fa->texinfo->size[0];
else s /= fa->texinfo->image->width;
if( fa->texinfo->texture->width != -1 ) s /= fa->texinfo->texture->width;
else s /= fa->texinfo->texture->image->width;
t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
if(fa->texinfo->size[1] != -1) t /= fa->texinfo->size[1];
else t /= fa->texinfo->image->height;
t = DotProduct( vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
if( fa->texinfo->texture->height != -1) t /= fa->texinfo->texture->height;
else t /= fa->texinfo->texture->image->height;
VectorAdd (total, vec, total);

View File

@ -88,7 +88,7 @@ void R_Mirror( refdef_t *fd )
pglBlendFunc( GL_SRC_ALPHA, GL_ONE );
pglColor4f( 1.0f, 1.0f, 1.0f, mirror_alpha );
GL_Bind( s->texinfo->image->texnum[0] );
GL_Bind( s->texinfo->texture->image->texnum[0] );
if( mirror_entity )
{

View File

@ -32,8 +32,19 @@ TODO LIST
выбросить лишние ресурсы
забэкапить результат
#define DENTITY_KEY 0
#define DENTITY_VALUE 1
typedef struct
{
string_t epair[2]; [variable sized][2]
} dentity_t;
// only once bsp file can be opened
bool FS_OpenBSP( const char *name, const char *mode );
bool FS_ReadLump( const char *name, char type, int version, size_t *lmpsize, byte *data );
bool FS_SaveLump( const char *name, char type, int version, size_t lumpsize, byte *data );
bool FS_CloseBSP( void );
Список доступных рендереров: Что в них интересного
0. Q3Fusion (Mirrors, Portals)