From: Rudolf Polzer Date: Sat, 9 Oct 2010 17:28:19 +0000 (+0200) Subject: the decompiler now can convert .map files too X-Git-Tag: xonotic-v0.5.0~186 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1b73f1f78b55c0e7c9d85aa7cba776007484bf49;p=xonotic%2Fnetradiant.git the decompiler now can convert .map files too --- diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index c600eaf2..55147b3a 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -1430,23 +1430,71 @@ int ScaleBSPMain( int argc, char **argv ) } +/* +PseudoCompileBSP() +a stripped down ProcessModels +*/ void PseudoCompileBSP() { - // a stripped down ProcessModels + int models; + char modelValue[10]; + entity_t *entity; + tree_t *tree; + node_t *node; + brush_t *brush; + side_t *side; + int i; + + SetDrawSurfacesBuffer(); + mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); + memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); + numMapDrawSurfs = 0; + BeginBSPFile(); + models = 1; for( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ ) { /* get entity */ entity = &entities[ mapEntityNum ]; if( entity->brushes == NULL && entity->patches == NULL ) continue; + + if(mapEntityNum != 0) + { + sprintf( modelValue, "*%d", models++); + SetKeyValue(entity, "model", modelValue); + } /* 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); + + entity->firstDrawSurf = numMapDrawSurfs; + + node = AllocNode(); + node->planenum = PLANENUM_LEAF; + tree = AllocTree(); + tree->headnode = node; + + /* a minimized ClipSidesIntoTree */ + for( brush = entity->brushes; brush; brush = brush->next ) + { + /* walk the brush sides */ + for( i = 0; i < brush->numsides; i++ ) + { + /* get side */ + side = &brush->sides[ i ]; + if( side->winding == NULL ) + continue; + /* save this winding as a visible surface */ + DrawSurfaceForSide(entity, brush, side, side->winding); + } + } + + FilterDrawsurfsIntoTree(entity, tree); + + EmitBrushes(entity->brushes, &entity->firstBrush, &entity->numBrushes ); + EndModel(entity, node); } } @@ -1530,8 +1578,7 @@ int ConvertBSPMain( int argc, char **argv ) StripExtension(source); DefaultExtension(source, ".map"); Sys_Printf("Loading %s\n", source); - LoadMapFile(name, qfalse, qtrue); - ParseEntities(); + LoadMapFile(source, qfalse, qtrue); PseudoCompileBSP(); } else diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index 3240153f..448a24fb 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -620,7 +620,7 @@ static void MergeOrigin(entity_t *ent, vec3_t origin) SetKeyValue(ent, "origin", string); } -brush_t *FinishBrush( void ) +brush_t *FinishBrush( qboolean noCollapseGroups ) { brush_t *b; @@ -665,7 +665,8 @@ brush_t *FinishBrush( void ) } /* add bevel planes */ - AddBrushBevels(); + if(!noCollapseGroups) + AddBrushBevels(); /* keep it */ b = CopyBrush( buildBrush ); @@ -1034,7 +1035,7 @@ ParseBrush() parses a brush out of a map file and sets it up */ -static void ParseBrush( qboolean onlyLights ) +static void ParseBrush( qboolean onlyLights, qboolean noCollapseGroups ) { brush_t *b; @@ -1081,7 +1082,7 @@ static void ParseBrush( qboolean onlyLights ) } /* finish the brush */ - b = FinishBrush(); + b = FinishBrush(noCollapseGroups); } @@ -1497,7 +1498,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups ) g_bBrushPrimit = BPRIMIT_NEWBRUSHES; /* parse brush primitive */ - ParseBrush( onlyLights ); + ParseBrush( onlyLights, noCollapseGroups ); } else { @@ -1507,7 +1508,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups ) /* parse old brush format */ UnGetToken(); - ParseBrush( onlyLights ); + ParseBrush( onlyLights, noCollapseGroups ); } entitySourceBrushes++; } diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 4ec0319c..28a94a33 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1580,7 +1580,7 @@ void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapse int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ); int PlaneTypeForNormal( vec3_t normal ); void AddBrushBevels( void ); -brush_t *FinishBrush( void ); +brush_t *FinishBrush(qboolean noCollapseGroups); /* portals.c */ diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c index 7d63e357..2ef8962b 100644 --- a/tools/quake3/q3map2/writebsp.c +++ b/tools/quake3/q3map2/writebsp.c @@ -630,8 +630,7 @@ void EndModel( entity_t *e, node_t *headnode ) /* emit the bsp */ mod = &bspModels[ numBSPModels ]; - if(headnode) - EmitDrawNode_r( headnode ); + EmitDrawNode_r( headnode ); /* set surfaces and brushes */ mod->numBSPSurfaces = numBSPDrawSurfaces - mod->firstBSPSurface;