]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Merge remote-tracking branch 'origin/divVerent/leak-fix'
authorRudolf Polzer <divverent@xonotic.org>
Sun, 19 Feb 2012 17:40:59 +0000 (18:40 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Sun, 19 Feb 2012 17:40:59 +0000 (18:40 +0100)
contrib/bobtoolz/DPatch.cpp
contrib/bobtoolz/DPatch.h
radiant/map.cpp
tools/quake3/q3map2/bspfile_ibsp.c
tools/quake3/q3map2/bspfile_rbsp.c
tools/quake3/q3map2/q3map2.h
tools/quake3/q3map2/surface.c
tools/quake3/q3map2/writebsp.c

index 10dbb4bb58d73493a99031d6614a0151279bd96c..85a95cb03c87eaa5bb2078c1169134b9e38fa096 100644 (file)
@@ -80,11 +80,11 @@ void DPatch::BuildInRadiant(scene::Node* entity)
   GlobalPatchCreator().Patch_setShader(patch, texture);
   GlobalPatchCreator().Patch_resize(patch, height, width);
   PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints(patch);
-       for(int x = 0; x < height; x++)
+       for(int x = 0; x < width; x++)
   {
-               for(int y = 0; y < width; y++)
+               for(int y = 0; y < height; y++)
     {
-      PatchControl& p = matrix(y, x);
+      PatchControl& p = matrix(x, y);
       p.m_vertex[0] = points[x][y].xyz[0];
       p.m_vertex[1] = points[x][y].xyz[1];
       p.m_vertex[2] = points[x][y].xyz[2];
@@ -148,11 +148,11 @@ void DPatch::LoadFromPatch(scene::Instance& patch)
   width = static_cast<int>(matrix.x());
        height = static_cast<int>(matrix.y());
 
-  for(int x = 0; x < height; x++)
+  for(int x = 0; x < width; x++)
   {
-               for(int y = 0; y < width; y++)
+               for(int y = 0; y < height; y++)
     {
-      PatchControl& p = matrix(y, x);
+      PatchControl& p = matrix(x, y);
       points[x][y].xyz[0] = p.m_vertex[0];
       points[x][y].xyz[1] = p.m_vertex[1];
       points[x][y].xyz[2] = p.m_vertex[2];
@@ -307,17 +307,13 @@ DPatch* DPatch::MergePatches(patch_merge_t merge_info, DPatch *p1, DPatch *p2)
                if(merge_info.pos2 < 0)
                        merge_info.pos2 += 3;
        }
-       //
 
        int newHeight = p1->height + p2->height - 1; 
        if(newHeight > MAX_PATCH_HEIGHT)
                return false;
-/*     int newWidth = p1->width + p2->width - 1;
-       if(newWidth > MAX_PATCH_WIDTH)
-               return NULL;
-*/     
+
        DPatch* newPatch = new DPatch();
-       //switched..
+
        newPatch->height        = newHeight;
        newPatch->width         = p1->width;
        newPatch->SetTexture(p1->texture);
@@ -346,6 +342,45 @@ void DPatch::Invert()
                }
        }
 }
+/*
+//Was used for debugging, obsolete function
+DPatch* DPatch::TransposePatch(DPatch *p1)
+{
+       globalOutputStream() << "Source patch ";
+    p1->DebugPrint();
+    p1->Transpose();
+    globalOutputStream() << "Transposed";
+    p1->DebugPrint();
+  
+    DPatch* newPatch = new DPatch();
+       newPatch->height        = p1->height;
+       newPatch->width         = p1->width;
+       newPatch->SetTexture(p1->texture);
+    
+       for(int x = 0; x < p1->height; x++)
+       {
+               for(int y = 0; y < p1->width; y++)
+               {
+            newPatch->points[x][y] = p1->points[x][y];
+        }
+    }
+       return newPatch;
+}
+
+//Function to figure out what is actually going wrong.
+void DPatch::DebugPrint()
+{
+    globalOutputStream() << "width: " << width << "\theight: " << height << "\n";
+    for(int x = 0; x < height; x++)
+       {
+               for(int y = 0; y < width; y++)
+               {
+            globalOutputStream() << "\t(" << points[x][y].xyz[0] << " " << points[x][y].xyz[1] << " " << points[x][y].xyz[2] << ")\t";
+        }
+        globalOutputStream() << "\n";
+    }
+}
+ */
 
 void DPatch::Transpose()
 {
@@ -397,7 +432,7 @@ void DPatch::Transpose()
        Invert();
 }
 
-std::list<DPatch> DPatch::SplitRows()
+std::list<DPatch> DPatch::SplitCols()
 {
        std::list<DPatch> patchList;
        int i;
@@ -410,39 +445,25 @@ std::list<DPatch> DPatch::SplitRows()
                        DPatch p;
 
                        p.width = width;
-                       p.height = 3;
+                       p.height = MIN_PATCH_HEIGHT;
                        p.SetTexture(texture);
-                       for(x = 0; x < 3; x++)
+                       for(x = 0; x < p.width; x++)
                        {
-                               for(y = 0; y < p.width; y++)
+                               for(y = 0; y < MIN_PATCH_HEIGHT; y++)
                                {
-                                       p.points[x][y] = points[(i*2)+x][y];
+                                       p.points[x][y] = points[x][(i*2)+y];
                                }
                        }                       
                        patchList.push_back(p);
                }
        } else {
-               //This returns exactly what comes in.. I don't know better :/
-               //If nothing is returned, the Patch in Radiant is just deleted - I suppose for evil follow up erros.
-               DPatch p;
-               
-               p.height = height;
-               p.width = width;
-               p.SetTexture(texture);
-               
-               for(x = 0; x < p.height; x++)
-               {
-                       for(y = 0; y < p.width; y++)
-                       {
-                               p.points[x][y] = points[x][y];
+        //globalErrorStream() << "bobToolz SplitPatchRows: Patch has not enough rows for splitting.\n";
+               patchList.push_back(*this);
                        }
-               }
-               patchList.push_back(p);
-       }
        return patchList;
 }
 
-std::list<DPatch> DPatch::SplitCols()
+std::list<DPatch> DPatch::SplitRows()
 {
        std::list<DPatch> patchList;
        int i;
@@ -454,38 +475,23 @@ std::list<DPatch> DPatch::SplitCols()
                {
                        DPatch p;
                        
-                       p.width = 3;
+                       p.width = MIN_PATCH_WIDTH;
                        p.height = height;
                        p.SetTexture(texture);
                        
-                       for(x = 0; x < p.height; x++)
+                       for(x = 0; x < MIN_PATCH_WIDTH; x++)
                        {
-                               for(y = 0; y < 3; y++)
+                               for(y = 0; y < p.height; y++)
                                {
-                                       p.points[x][y] = points[x][(i*2)+y];
+                                       p.points[x][y] = points[(i*2)+x][y];
                                }
                        }
                        patchList.push_back(p);
                }
        } else 
        {
-               //This returns exactly what comes in.. I don't know better :/
-               //If nothing is returned, the Patch in Radiant is just deleted - I suppose for evil follow up erros.
-               DPatch p;
-               
-               p.height = height;
-               p.width = width;
-               p.SetTexture(texture);
-               
-               for(x = 0; x < p.height; x++)
-               {
-                       for(y = 0; y < p.width; y++)
-                       {
-                               p.points[x][y] = points[x][y];
+               patchList.push_back(*this);
                        }
-               }
-               patchList.push_back(p);
-       }
        return patchList;
 }
 
@@ -497,77 +503,26 @@ std::list<DPatch> DPatch::Split()
        
        if(width >= 5)
        {
-               for(i = 0; i < (width-1)/2; i++)
+               std::list<DPatch> patchColList = SplitCols();
+        for(std::list<DPatch>::iterator patchesCol = patchColList.begin(); patchesCol != patchColList.end(); patchesCol++)
                {
-                       DPatch p;
-                       
-                       p.width = 3;
-                       p.height = height;
-                       p.SetTexture(texture);
-                       
-                       for(x = 0; x < p.height; x++)
+                  std::list<DPatch> patchRowList = (*patchesCol).SplitRows();
+              for(std::list<DPatch>::iterator patchesRow = patchRowList.begin(); patchesRow != patchRowList.end(); patchesRow++)
                        {
-                               for(y = 0; y < 3; y++)
-                               {
-                                       p.points[x][y] = points[x][(i*2)+y];
+              patchList.push_front(*patchesRow);
                                }
                        }
-                       patchList.push_back(p);
-               }
-               std::list<DPatch> patchList2;
-               for(std::list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++)
-               {
-                       std::list<DPatch> patchList3 = (*patches).SplitRows();
-                       for(std::list<DPatch>::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++)
-                               patchList2.push_front(*patches2);
-               }
-               return patchList2;
-               
        } else  if(height >= 5) 
        {
-               for(i = 0; i < (height-1)/2; i++)
+               std::list<DPatch> patchRowList = SplitRows();
+        for(std::list<DPatch>::iterator patchesRow = patchRowList.begin(); patchesRow != patchRowList.end(); patchesRow++)
                {
-                       DPatch p;
-                       
-                       p.width = width;
-                       p.height = 3;
-                       p.SetTexture(texture);
-                       for(x = 0; x < 3; x++)
-                       {
-                               for(y = 0; y < p.width; y++)
-                               {
-                                       p.points[x][y] = points[(i*2)+x][y];
+           patchList.push_front(*patchesRow);
                                }
-                       }                       
-                       patchList.push_back(p);
-               }               
-               std::list<DPatch> patchList2;
-               for(std::list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++)
-               {
-                       std::list<DPatch> patchList3 = (*patches).SplitCols();
-                       for(std::list<DPatch>::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++)
-                               patchList2.push_front(*patches2);
-               }
-               return patchList2;
-               
        } else 
        {
-               //This returns exactly what comes in.. I don't know better :/
-               //If nothing is returned, the Patch in Radiant is just deleted - I suppose for evil follow up erros.
-               DPatch p;
-               
-               p.height = height;
-               p.width = width;
-               p.SetTexture(texture);
-               
-               for(x = 0; x < p.height; x++)
-               {
-                       for(y = 0; y < p.width; y++)
-                       {
-                               p.points[x][y] = points[x][y];
+        //globalErrorStream() << "bobToolz SplitPatchRows: Patch has not enough rows for splitting.\n";
+               patchList.push_back(*this);
                        }
-               }
-               patchList.push_back(p);         
-       }
        return patchList;
 }
index a10773d6fc8f5c307516b23373db556d7e10f047..63e15eea1a8c89d1a321f1dc8630308e1427756b 100644 (file)
@@ -59,6 +59,8 @@ public:
        std::list<DPatch> SplitCols();
        std::list<DPatch> Split();
        void Transpose();
+       //DPatch* TransposePatch(DPatch* p1);
+       //void DebugPrint();
        void Invert();
        DPatch* MergePatches(patch_merge_t merge_info, DPatch* p1, DPatch* p2);
        patch_merge_t IsMergable(DPatch* other);
index ec412965883f92352d5465d50c8b9fe61ea3133d..bf9891d5106edd4a415013c045d700430219202f 100644 (file)
@@ -1690,13 +1690,15 @@ tryDecompile:
     output.push_string((type && *type) ? type : "quake3");
     output.push_string(" -fs_basepath \"");
     output.push_string(EnginePath_get());
-    output.push_string(" -fs_homepath \"");
+    output.push_string("\" -fs_homepath \"");
     output.push_string(g_qeglobals.m_userEnginePath.c_str());
     output.push_string("\" -fs_game ");
     output.push_string(gamename_get());
     output.push_string(" -convert -format ");
     output.push_string(Brush::m_type == eBrushTypeQuake3BP ? "map_bp" : "map");
-    output.push_string(" -readmap \"");
+    if(extension_equal(path_get_extension(filename), "map"))
+      output.push_string(" -readmap ");
+    output.push_string(" \"");
     output.push_string(filename);
     output.push_string("\"");
 
index 77ffd704a747586e705744b26e1bff89b1b4b10e..221df3ce36eda8c08ecac788c5e64479b0cc14e6 100644 (file)
@@ -501,7 +501,7 @@ void LoadIBSPFile( const char *filename )
        
        numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFog_t ) ); // TODO fix overflow
        
-       numBSPDrawIndexes = CopyLump( (bspHeader_t*) header, LUMP_DRAWINDEXES, bspDrawIndexes, sizeof( bspDrawIndexes[ 0 ] ) );
+       numBSPDrawIndexes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_DRAWINDEXES, (void **) &bspDrawIndexes, sizeof( bspDrawIndexes[ 0 ] ), &allocatedBSPDrawIndexes );
        
        numBSPVisBytes = CopyLump( (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, 1 ); // TODO fix overflow
        
index 644f1f5f97c8289673e7c04386f3a129cc5ff5ec..22ead1844b626d02e5e0259012143f8fa90ec6ee 100644 (file)
@@ -257,7 +257,7 @@ void LoadRBSPFile( const char *filename )
        
        numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFogs[ 0 ] ) );
        
-       numBSPDrawIndexes = CopyLump( (bspHeader_t*) header, LUMP_DRAWINDEXES, bspDrawIndexes, sizeof( bspDrawIndexes[ 0 ] ) );
+       numBSPDrawIndexes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_DRAWINDEXES, (void **) &bspDrawIndexes, sizeof( bspDrawIndexes[ 0 ] ), &allocatedBSPDrawIndexes );
        
        numBSPVisBytes = CopyLump( (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, 1 );
        
index abde6c8573ce2d022e3cc6bbb9fc7a60a0a98df5..49cdd11dafe297dc83f24faa4f32d2088cf9cca0 100644 (file)
@@ -327,7 +327,6 @@ abstracted bsp file
 #define        MAX_MAP_VISIBILITY              (VIS_HEADER_SIZE + MAX_MAP_VISCLUSTERS * (((MAX_MAP_VISCLUSTERS + 63) & ~63) >> 3))
 
 #define        MAX_MAP_DRAW_SURFS              0x20000
-#define        MAX_MAP_DRAW_INDEXES    0x80000
 
 #define MAX_MAP_ADVERTISEMENTS 30
 
@@ -2514,10 +2513,11 @@ Q_EXTERN int                            numBSPVisBytes Q_ASSIGN( 0 );
 Q_EXTERN byte                          bspVisBytes[ MAX_MAP_VISIBILITY ];
 
 Q_EXTERN int                           numBSPDrawVerts Q_ASSIGN( 0 );
-Q_EXTERN bspDrawVert_t         *bspDrawVerts Q_ASSIGN( NULL );
+Q_EXTERN bspDrawVert_t                 *bspDrawVerts Q_ASSIGN( NULL );
 
 Q_EXTERN int                           numBSPDrawIndexes Q_ASSIGN( 0 );
-Q_EXTERN int                           bspDrawIndexes[ MAX_MAP_DRAW_INDEXES ];
+Q_EXTERN int                           allocatedBSPDrawIndexes Q_ASSIGN( 0 );
+Q_EXTERN int                           *bspDrawIndexes Q_ASSIGN(NULL);
 
 Q_EXTERN int                           numBSPDrawSurfaces Q_ASSIGN( 0 );
 Q_EXTERN bspDrawSurface_t      *bspDrawSurfaces Q_ASSIGN( NULL );
index e2ec89093b9155fd5946a38e1dc80e2987887e39..005456ef78b86c958ed325c40edde1d650177f54 100644 (file)
@@ -2435,8 +2435,7 @@ void EmitDrawIndexes( mapDrawSurface_t *ds, bspDrawSurface_t *out )
                /* copy new unique indexes */
                for( i = 0; i < ds->numIndexes; i++ )
                {
-                       if( numBSPDrawIndexes == MAX_MAP_DRAW_INDEXES )
-                               Error( "MAX_MAP_DRAW_INDEXES" );
+                       AUTOEXPAND_BY_REALLOC_BSP(DrawIndexes, 1024);
                        bspDrawIndexes[ numBSPDrawIndexes ] = ds->indexes[ i ];
 
                        /* validate the index */
index 106e618f23ae88158f8562106820783dca90bc78..5321d068e755d910ea042d058007239320ca6503 100644 (file)
@@ -388,6 +388,7 @@ void BeginBSPFile( void )
        
        /* ydnar: gs mods: set the first 6 drawindexes to 0 1 2 2 1 3 for triangles and quads */
        numBSPDrawIndexes = 6;
+       AUTOEXPAND_BY_REALLOC_BSP(DrawIndexes, 1024);
        bspDrawIndexes[ 0 ] = 0;
        bspDrawIndexes[ 1 ] = 1;
        bspDrawIndexes[ 2 ] = 2;