]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/map.c
the decompiler now can convert .map files too
[xonotic/netradiant.git] / tools / quake3 / q3map2 / map.c
index 0173d834ff1c9d0c19e41962a24d1076d0fe27f8..448a24fb2398b3e023d9d477e31e93dd29434d0b 100644 (file)
@@ -212,7 +212,7 @@ ydnar: changed to allow a number of test points to be supplied that
 must be within an epsilon distance of the plane
 */
 
-int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ) // NOTE: this has a side effect on the normal. Good or bad?
+int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points ) // NOTE: this has a side effect on the normal. Good or bad?
 
 #ifdef USE_HASHING
 
@@ -222,12 +222,14 @@ int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ) /
        plane_t *p;
        vec_t   d;
        vec3_t centerofweight;
+       vec3_t normal;
 
        VectorClear(centerofweight);
        for(i = 0; i < numPoints; ++i)
                VectorMA(centerofweight, 1.0 / numPoints, points[i], centerofweight);
        
        /* hash the plane */
+       VectorCopy(innormal, normal);
        SnapPlane( normal, &dist, centerofweight );
        hash = (PLANE_HASHES - 1) & (int) fabs( dist );
        
@@ -269,6 +271,7 @@ int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ) /
 {
        int             i;
        plane_t *p;
+       vec3_t normal;
        
 
        vec3_t centerofweight;
@@ -277,6 +280,7 @@ int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ) /
        for(i = 0; i < numPoints; ++i)
                VectorMA(centerofweight, 1.0 / numPoints, points[i], centerofweight);
 
+       VectorCopy(innormal, normal);
        SnapPlane( normal, &dist, centerofweight );
        for( i = 0, p = mapplanes; i < nummapplanes; i++, p++ )
        {
@@ -345,6 +349,9 @@ void SetBrushContents( brush_t *b )
                        continue;
                if( s->contentFlags != contentFlags || s->compileFlags != compileFlags )
                        mixed = qtrue;
+
+               contentFlags |= s->contentFlags;
+               compileFlags |= s->compileFlags;
        }
        
        /* ydnar: getting rid of this stupid warning */
@@ -613,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;
        
@@ -658,7 +665,8 @@ brush_t *FinishBrush( void )
        }
        
        /* add bevel planes */
-       AddBrushBevels();
+       if(!noCollapseGroups)
+               AddBrushBevels();
        
        /* keep it */
        b = CopyBrush( buildBrush );
@@ -830,7 +838,7 @@ static void ParseRawBrush( qboolean onlyLights )
        int                             planenum;
        shaderInfo_t    *si;
        vec_t                   shift[ 2 ];
-       vec_t                   rotate;
+       vec_t                   rotate = 0;
        vec_t                   scale[ 2 ];
        char                    name[ MAX_QPATH ];
        char                    shader[ MAX_QPATH ];
@@ -1027,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;
        
@@ -1074,7 +1082,7 @@ static void ParseBrush( qboolean onlyLights )
        }
        
        /* finish the brush */
-       b = FinishBrush();
+       b = FinishBrush(noCollapseGroups);
 }
 
 
@@ -1411,7 +1419,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;
@@ -1490,7 +1498,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
                                g_bBrushPrimit = BPRIMIT_NEWBRUSHES;
                                
                                /* parse brush primitive */
-                               ParseBrush( onlyLights );
+                               ParseBrush( onlyLights, noCollapseGroups );
                        }
                        else
                        {
@@ -1500,7 +1508,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
                                
                                /* parse old brush format */
                                UnGetToken();
-                               ParseBrush( onlyLights );
+                               ParseBrush( onlyLights, noCollapseGroups );
                        }
                        entitySourceBrushes++;
                }
@@ -1578,12 +1586,19 @@ static qboolean ParseMapEntity( qboolean onlyLights )
                value = ValueForKey( &entities[ 0 ], "_celshader" );
        if( value[ 0 ] != '\0' )
        {
-               sprintf( shader, "textures/%s", value );
-               celShader = ShaderInfoForShader( shader );
-               Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader );
+               if(strcmp(value, "none"))
+               {
+                       sprintf( shader, "textures/%s", value );
+                       celShader = ShaderInfoForShader( shader );
+                       Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader );
+               }
+               else
+               {
+                       celShader = NULL;
+               }
        }
        else
-               celShader = *globalCelShader ? ShaderInfoForShader(globalCelShader) : NULL;
+               celShader = (*globalCelShader ? ShaderInfoForShader(globalCelShader) : NULL);
 
        /* jal : entity based _shadeangle */
        shadeAngle = 0.0f;
@@ -1650,14 +1665,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--;
@@ -1675,11 +1690,11 @@ 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;
-       int                     oldNumEntities, numMapBrushes;
+       int                     oldNumEntities = 0, numMapBrushes;
        
        
        /* note it */
@@ -1708,7 +1723,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 )