From: divverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Date: Thu, 18 Jun 2009 06:45:31 +0000 (+0000)
Subject: try to fix FindFloatPlane bug
X-Git-Tag: svn-r421~38
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b5bff46ac332bf0b1a6881217a27e8cf79f0983b;p=xonotic%2Fnetradiant.git

try to fix FindFloatPlane bug
unlimit entity count


git-svn-id: svn://svn.icculus.org/netradiant/trunk@382 61c419a2-8eb2-4b30-bcec-8cead039b335
---

diff --git a/tools/quake3/q3map2/bspfile_abstract.c b/tools/quake3/q3map2/bspfile_abstract.c
index 0e77526f..ed08b8ca 100644
--- a/tools/quake3/q3map2/bspfile_abstract.c
+++ b/tools/quake3/q3map2/bspfile_abstract.c
@@ -649,6 +649,13 @@ void UnparseEntities( void )
 	/* run through entity list */
 	for( i = 0; i < numBSPEntities && i < numEntities; i++ )
 	{
+		{
+			int sz = end - buf;
+			AUTOEXPAND_BY_REALLOC(bspEntData, sz + 65536, allocatedBSPEntData, 1024);
+			buf = bspEntData;
+			end = buf + sz;
+		}
+
 		/* get epair */
 		ep = entities[ i ].epairs;
 		if( ep == NULL )
@@ -685,7 +692,7 @@ void UnparseEntities( void )
 		end += 2;
 		
 		/* check for overflow */
-		if( end > buf + MAX_MAP_ENTSTRING )
+		if( end > buf + allocatedBSPEntData )
 			Error( "Entity text too long" );
 	}
 	
diff --git a/tools/quake3/q3map2/bspfile_ibsp.c b/tools/quake3/q3map2/bspfile_ibsp.c
index 591d4d14..c9ec59c6 100644
--- a/tools/quake3/q3map2/bspfile_ibsp.c
+++ b/tools/quake3/q3map2/bspfile_ibsp.c
@@ -509,7 +509,7 @@ void LoadIBSPFile( const char *filename )
 		bspLightBytes = safe_malloc( numBSPLightBytes );
 		CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, 1 );
 	
-	bspEntDataSize = CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData, 1);
+	bspEntDataSize = CopyLump_Allocate( (bspHeader_t*) header, LUMP_ENTITIES, (void **) &bspEntData, 1, &allocatedBSPEntData);
 	
 	CopyLightGridLumps( header );
 
diff --git a/tools/quake3/q3map2/bspfile_rbsp.c b/tools/quake3/q3map2/bspfile_rbsp.c
index 0a48aae6..79f177ea 100644
--- a/tools/quake3/q3map2/bspfile_rbsp.c
+++ b/tools/quake3/q3map2/bspfile_rbsp.c
@@ -265,7 +265,7 @@ void LoadRBSPFile( const char *filename )
 		bspLightBytes = safe_malloc( numBSPLightBytes );
 		CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, 1 );
 	
-	bspEntDataSize = CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData, 1);
+	bspEntDataSize = CopyLump_Allocate( (bspHeader_t*) header, LUMP_ENTITIES, (void **) &bspEntData, 1, &allocatedBSPEntData);
 	
 	CopyLightGridLumps( header );
 	
diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c
index b9862c51..f29d7d62 100644
--- a/tools/quake3/q3map2/map.c
+++ b/tools/quake3/q3map2/map.c
@@ -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++ )
 	{
diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h
index 1224ae36..6deeed24 100644
--- a/tools/quake3/q3map2/q3map2.h
+++ b/tools/quake3/q3map2/q3map2.h
@@ -2385,7 +2385,8 @@ Q_EXTERN int				allocatedBSPShaders Q_ASSIGN( 0 );
 Q_EXTERN bspShader_t*		bspShaders Q_ASSIGN(0);
 
 Q_EXTERN int				bspEntDataSize Q_ASSIGN( 0 );
-Q_EXTERN char				bspEntData[ MAX_MAP_ENTSTRING ];
+Q_EXTERN int				allocatedBSPEntData Q_ASSIGN( 0 );
+Q_EXTERN char				*bspEntData Q_ASSIGN(0);
 
 Q_EXTERN int				numBSPLeafs Q_ASSIGN( 0 );
 Q_EXTERN bspLeaf_t			bspLeafs[ MAX_MAP_LEAFS ];