From 205771e916f16f76f5c38b599a198528cf006719 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sat, 9 Oct 2010 18:25:19 +0200 Subject: [PATCH] initial code for converting .map to .map --- tools/quake3/q3map2/bsp.c | 6 ++-- tools/quake3/q3map2/light.c | 2 +- tools/quake3/q3map2/main.c | 66 ++++++++++++++++++++++++++-------- tools/quake3/q3map2/map.c | 10 +++--- tools/quake3/q3map2/q3map2.h | 2 +- tools/quake3/q3map2/writebsp.c | 3 +- 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/tools/quake3/q3map2/bsp.c b/tools/quake3/q3map2/bsp.c index 214f62f0..f0763eb7 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -639,7 +639,7 @@ void OnlyEnts( void ) numEntities = 0; LoadShaderInfo(); - LoadMapFile( name, qfalse ); + LoadMapFile( name, qfalse, qfalse ); SetModelNumbers(); SetLightStyles(); @@ -955,9 +955,9 @@ int BSPMain( int argc, char **argv ) /* load original file from temp spot in case it was renamed by the editor on the way in */ if( strlen( tempSource ) > 0 ) - LoadMapFile( tempSource, qfalse ); + LoadMapFile( tempSource, qfalse, qfalse ); else - LoadMapFile( name, qfalse ); + LoadMapFile( name, qfalse, qfalse ); /* div0: inject command line parameters */ InjectCommandLine(argv, 1, argc - 1); diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 3af7ddbf..59ceab8e 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -2800,7 +2800,7 @@ int LightMain( int argc, char **argv ) /* load map file */ value = ValueForKey( &entities[ 0 ], "_keepLights" ); if( value[ 0 ] != '1' ) - LoadMapFile( mapSource, qtrue ); + LoadMapFile( mapSource, qtrue, qfalse ); /* set the entity/model origins and init yDrawVerts */ SetEntityOrigins(); diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index d922efc2..c600eaf2 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -1430,6 +1430,25 @@ int ScaleBSPMain( int argc, char **argv ) } +void PseudoCompileBSP() +{ + // a stripped down ProcessModels + BeginBSPFile(); + for( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ ) + { + /* get entity */ + entity = &entities[ mapEntityNum ]; + if( entity->brushes == NULL && entity->patches == NULL ) + continue; + + /* process the model */ + Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels ); + BeginModel(); + entity>firstDrawSurf = 0; + EmitBrushes(entity->brushes, &entity>firstBrush, &entity>numBrushes ); + EndModel(entity, NULL); + } +} /* ConvertBSPMain() @@ -1441,11 +1460,14 @@ int ConvertBSPMain( int argc, char **argv ) int i; int (*convertFunc)( char * ); game_t *convertGame; + qboolean map_allowed; + char ext[1024]; /* set default */ convertFunc = ConvertBSPToASE; convertGame = NULL; + map_allowed = qfalse; /* arg checking */ if( argc < 1 ) @@ -1462,11 +1484,19 @@ int ConvertBSPMain( int argc, char **argv ) { i++; if( !Q_stricmp( argv[ i ], "ase" ) ) + { convertFunc = ConvertBSPToASE; + } else if( !Q_stricmp( argv[ i ], "map_bp" ) ) + { convertFunc = ConvertBSPToMap_BP; + map_allowed = qtrue; + } else if( !Q_stricmp( argv[ i ], "map" ) ) + { convertFunc = ConvertBSPToMap; + map_allowed = qtrue; + } else { convertGame = GetGame( argv[ i ] ); @@ -1489,23 +1519,29 @@ int ConvertBSPMain( int argc, char **argv ) else if( !strcmp( argv[ i ], "-shadersasbitmap" ) ) shadersAsBitmap = qtrue; } - - /* clean up map name */ - strcpy( source, ExpandArg( argv[ i ] ) ); - StripExtension( source ); - DefaultExtension( source, ".bsp" ); - + LoadShaderInfo(); - Sys_Printf( "Loading %s\n", source ); - - /* ydnar: load surface file */ - //% LoadSurfaceExtraFile( source ); - - LoadBSPFile( source ); - - /* parse bsp entities */ - ParseEntities(); + /* clean up map name */ + strcpy(source, ExpandArg(argv[i])); + ExtractFileExtension(source, ext); + if(!Q_stricmp(ext, "map") && map_allowed) + { + StripExtension(source); + DefaultExtension(source, ".map"); + Sys_Printf("Loading %s\n", source); + LoadMapFile(name, qfalse, qtrue); + ParseEntities(); + PseudoCompileBSP(); + } + else + { + StripExtension(source); + DefaultExtension(source, ".bsp"); + Sys_Printf("Loading %s\n", source); + LoadBSPFile(source); + ParseEntities(); + } /* bsp format convert? */ if( convertGame != NULL ) diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index 3bc4e6f9..3240153f 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -1418,7 +1418,7 @@ ParseMapEntity() parses a single entity out of a map file */ -static qboolean ParseMapEntity( qboolean onlyLights ) +static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups ) { epair_t *ep; const char *classname, *value; @@ -1664,14 +1664,14 @@ static qboolean ParseMapEntity( qboolean onlyLights ) AdjustBrushesForOrigin( mapEnt ); /* group_info entities are just for editor grouping (fixme: leak!) */ - if( !Q_stricmp( "group_info", classname ) ) + if( !noCollapseGroups && !Q_stricmp( "group_info", classname ) ) { numEntities--; return qtrue; } /* group entities are just for editor convenience, toss all brushes into worldspawn */ - if( funcGroup ) + if( !noCollapseGroups && funcGroup ) { MoveBrushesToWorld( mapEnt ); numEntities--; @@ -1689,7 +1689,7 @@ LoadMapFile() loads a map file into a list of entities */ -void LoadMapFile( char *filename, qboolean onlyLights ) +void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups ) { FILE *file; brush_t *b; @@ -1722,7 +1722,7 @@ void LoadMapFile( char *filename, qboolean onlyLights ) buildBrush = AllocBrush( MAX_BUILD_SIDES ); /* parse the map file */ - while( ParseMapEntity( onlyLights ) ); + while( ParseMapEntity( onlyLights, noCollapseGroups ) ); /* light loading */ if( onlyLights ) diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 39f60d9a..4ec0319c 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1576,7 +1576,7 @@ void MakeNormalVectors( vec3_t forward, vec3_t right, vec3_t up ); /* map.c */ -void LoadMapFile( char *filename, qboolean onlyLights ); +void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups ); int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ); int PlaneTypeForNormal( vec3_t normal ); void AddBrushBevels( void ); diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c index 2ef8962b..7d63e357 100644 --- a/tools/quake3/q3map2/writebsp.c +++ b/tools/quake3/q3map2/writebsp.c @@ -630,7 +630,8 @@ void EndModel( entity_t *e, node_t *headnode ) /* emit the bsp */ mod = &bspModels[ numBSPModels ]; - EmitDrawNode_r( headnode ); + if(headnode) + EmitDrawNode_r( headnode ); /* set surfaces and brushes */ mod->numBSPSurfaces = numBSPDrawSurfaces - mod->firstBSPSurface; -- 2.39.2