From a2406ea3d718b4032f60d3799d06bb51e03de35c Mon Sep 17 00:00:00 2001 From: Garux Date: Tue, 17 Oct 2017 12:59:56 +0300 Subject: [PATCH] q3map2: * Valve220 mapformat autodetection and support --- tools/quake3/q3map2/map.c | 69 +++++++++++++++++++++++++---------- tools/quake3/q3map2/patch.c | 2 +- tools/quake3/q3map2/q3map2.h | 13 ++++--- tools/quake3/q3map2/surface.c | 21 +++++------ 4 files changed, 68 insertions(+), 37 deletions(-) diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index 9c219d5c..b9e97599 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -1074,7 +1074,7 @@ static void ParseRawBrush( qboolean onlyLights ){ buildBrush->detail = qfalse; /* bp */ - if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { + if ( g_brushType == BPRIMIT_BP ) { MatchToken( "{" ); } @@ -1089,7 +1089,7 @@ static void ParseRawBrush( qboolean onlyLights ){ } /* ttimo : bp: here we may have to jump over brush epairs (only used in editor) */ - if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { + if ( g_brushType == BPRIMIT_BP ) { while ( 1 ) { if ( strcmp( token, "(" ) ) { @@ -1119,7 +1119,7 @@ static void ParseRawBrush( qboolean onlyLights ){ Parse1DMatrix( 3, planePoints[ 2 ] ); /* bp: read the texture matrix */ - if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { + if ( g_brushType == BPRIMIT_BP ) { Parse2DMatrix( 2, 3, (float*) side->texMat ); } @@ -1127,8 +1127,21 @@ static void ParseRawBrush( qboolean onlyLights ){ GetToken( qfalse ); strcpy( name, token ); - /* bp */ - if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { + /* AP or 220? */ + if ( g_brushType == BPRIMIT_UNDEFINED ){ + GetToken( qfalse ); + if ( !strcmp( token, "[" ) ){ + g_brushType = BPRIMIT_VALVE220; + Sys_FPrintf( SYS_VRB, "detected brushType = VALVE 220\n" ); + } + else{ + g_brushType = BPRIMIT_QUAKE; + Sys_FPrintf( SYS_VRB, "detected brushType = QUAKE (Axial Projection)\n" ); + } + UnGetToken(); + } + + if ( g_brushType == BPRIMIT_QUAKE ) { GetToken( qfalse ); shift[ 0 ] = atof( token ); GetToken( qfalse ); @@ -1140,6 +1153,29 @@ static void ParseRawBrush( qboolean onlyLights ){ GetToken( qfalse ); scale[ 1 ] = atof( token ); } + else if ( g_brushType == BPRIMIT_VALVE220 ){ + int axis, comp; + for ( axis = 0; axis < 2; ++axis ){ + MatchToken( "[" ); + for ( comp = 0; comp < 4; ++comp ){ + GetToken( qfalse ); + side->vecs[axis][comp] = atof( token ); + } + MatchToken( "]" ); + } + GetToken( qfalse ); + rotate = atof( token ); + GetToken( qfalse ); + scale[ 0 ] = atof( token ); + GetToken( qfalse ); + scale[ 1 ] = atof( token ); + + if ( !scale[0] ) scale[0] = 1.f; + if ( !scale[1] ) scale[1] = 1.f; + for ( axis = 0; axis < 2; ++axis ) + for ( comp = 0; comp < 3; ++comp ) + side->vecs[axis][comp] /= scale[axis]; + } /* set default flags and values */ sprintf( shader, "textures/%s", name ); @@ -1192,13 +1228,13 @@ static void ParseRawBrush( qboolean onlyLights ){ side->planenum = planenum; /* bp: get the texture mapping for this texturedef / plane combination */ - if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { + if ( g_brushType == BPRIMIT_QUAKE ) { QuakeTextureVecs( &mapplanes[ planenum ], shift, rotate, scale, side->vecs ); } } /* bp */ - if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { + if ( g_brushType == BPRIMIT_BP ) { UnGetToken(); MatchToken( "}" ); MatchToken( "}" ); @@ -1712,23 +1748,16 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups ) Sys_Printf( "WARNING: Terrain entity parsing not supported in this build.\n" ); /* ydnar */ } else if ( !strcmp( token, "brushDef" ) ) { - if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { - Error( "Old brush format not allowed in new brush format map" ); + if ( g_brushType == BPRIMIT_UNDEFINED ) { + Sys_FPrintf( SYS_VRB, "detected brushType = BRUSH PRIMITIVES\n" ); + g_brushType = BPRIMIT_BP; } - g_bBrushPrimit = BPRIMIT_NEWBRUSHES; - - /* parse brush primitive */ ParseBrush( onlyLights, noCollapseGroups ); } else { - if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { - Error( "New brush format not allowed in old brush format map" ); - } - g_bBrushPrimit = BPRIMIT_OLDBRUSHES; - - /* parse old brush format */ - UnGetToken(); + /* AP or 220 */ + UnGetToken(); // ( ParseBrush( onlyLights, noCollapseGroups ); } entitySourceBrushes++; @@ -1956,7 +1985,7 @@ void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups /* initial setup */ numMapDrawSurfs = 0; c_detail = 0; - g_bBrushPrimit = BPRIMIT_UNDEFINED; + g_brushType = BPRIMIT_UNDEFINED; /* allocate a very large temporary brush for building the brushes as they are loaded */ buildBrush = AllocBrush( MAX_BUILD_SIDES ); diff --git a/tools/quake3/q3map2/patch.c b/tools/quake3/q3map2/patch.c index 3b3949ce..b3f181a5 100644 --- a/tools/quake3/q3map2/patch.c +++ b/tools/quake3/q3map2/patch.c @@ -269,7 +269,7 @@ void ParsePatch( qboolean onlyLights ){ // if brush primitives format, we may have some epairs to ignore here GetToken( qtrue ); - if ( g_bBrushPrimit != BPRIMIT_OLDBRUSHES && strcmp( token,"}" ) ) { + if ( strcmp( token, "}" ) && ( g_brushType == BPRIMIT_BP || g_brushType == BPRIMIT_UNDEFINED ) ) { ep = ParseEPair(); free( ep->key ); free( ep->value ); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index ba10713e..bad7c824 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -208,10 +208,13 @@ #define PSIDE_BOTH ( PSIDE_FRONT | PSIDE_BACK ) #define PSIDE_FACING 4 -#define BPRIMIT_UNDEFINED 0 -#define BPRIMIT_OLDBRUSHES 1 -#define BPRIMIT_NEWBRUSHES 2 - +typedef enum{ + BPRIMIT_UNDEFINED = 0, + BPRIMIT_QUAKE, + BPRIMIT_BP, + BPRIMIT_VALVE220 +} +brushType_t; /* vis */ #define VIS_HEADER_SIZE 8 @@ -2128,7 +2131,7 @@ Q_EXTERN fog_t mapFogs[ MAX_MAP_FOGS ]; Q_EXTERN entity_t *mapEnt; Q_EXTERN brush_t *buildBrush; Q_EXTERN int numActiveBrushes; -Q_EXTERN int g_bBrushPrimit; +Q_EXTERN brushType_t g_brushType; Q_EXTERN int numStrippedLights Q_ASSIGN( 0 ); diff --git a/tools/quake3/q3map2/surface.c b/tools/quake3/q3map2/surface.c index 6b99ed4f..daf72a37 100644 --- a/tools/quake3/q3map2/surface.c +++ b/tools/quake3/q3map2/surface.c @@ -992,18 +992,8 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], vTranslated ); } - /* old quake-style texturing */ - else if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { - /* nearest-axial projection */ - dv->st[ 0 ] = s->vecs[ 0 ][ 3 ] + DotProduct( s->vecs[ 0 ], vTranslated ); - dv->st[ 1 ] = s->vecs[ 1 ][ 3 ] + DotProduct( s->vecs[ 1 ], vTranslated ); - dv->st[ 0 ] /= si->shaderWidth; - dv->st[ 1 ] /= si->shaderHeight; - } - /* brush primitive texturing */ - else - { + else if ( g_brushType == BPRIMIT_BP ) { /* calculate texture s/t from brush primitive texture matrix */ x = DotProduct( vTranslated, texX ); y = DotProduct( vTranslated, texY ); @@ -1011,6 +1001,15 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin dv->st[ 1 ] = s->texMat[ 1 ][ 0 ] * x + s->texMat[ 1 ][ 1 ] * y + s->texMat[ 1 ][ 2 ]; } + /* old quake-style or valve 220 texturing */ + else { + /* nearest-axial projection */ + dv->st[ 0 ] = s->vecs[ 0 ][ 3 ] + DotProduct( s->vecs[ 0 ], vTranslated ); + dv->st[ 1 ] = s->vecs[ 1 ][ 3 ] + DotProduct( s->vecs[ 1 ], vTranslated ); + dv->st[ 0 ] /= si->shaderWidth; + dv->st[ 1 ] /= si->shaderHeight; + } + /* copy normal */ VectorCopy( mapplanes[ s->planenum ].normal, dv->normal );