]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
the decompiler now can convert .map files too
authorRudolf Polzer <divverent@alientrap.org>
Sat, 9 Oct 2010 17:28:19 +0000 (19:28 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Sat, 9 Oct 2010 17:28:19 +0000 (19:28 +0200)
tools/quake3/q3map2/main.c
tools/quake3/q3map2/map.c
tools/quake3/q3map2/q3map2.h
tools/quake3/q3map2/writebsp.c

index c600eaf23e25b311d324c5eb67d7163d4896e325..55147b3ab145af8f2278cfd897b3998f1472c764 100644 (file)
@@ -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
index 3240153f4ecbbe624b26d93b2ae4871d79ea7a60..448a24fb2398b3e023d9d477e31e93dd29434d0b 100644 (file)
@@ -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++;
                }
index 4ec0319c0b764466de9bfadd3222bca336ad6272..28a94a33fad06e9994515eb172f8388480f05dca 100644 (file)
@@ -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 */
index 7d63e357dc003d03cde7653be05ae910f563ef2a..2ef8962b688cfad06dcb7ad864e9fb5a1a97813f 100644 (file)
@@ -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;