Update of /cvsroot/playerstage/code/stage/libstage
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23845

Modified Files:
      Tag: opengl
        blockgrid.cc stage.hh stest.cc 
Log Message:
added trash stack support in blockgrid - eliminates mallocs in the steady state 
- nice speedup. raytracing is now very fast

Index: stage.hh
===================================================================
RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/stage.hh,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -C2 -d -r1.1.2.10 -r1.1.2.11
*** stage.hh    30 Oct 2007 04:20:45 -0000      1.1.2.10
--- stage.hh    30 Oct 2007 07:30:01 -0000      1.1.2.11
***************
*** 1175,1181 ****
  {
  private:
-   //GSList** lists;
    stg_bigblock_t* map;
    
  public:
    uint32_t width, height, bwidth, bheight;
--- 1175,1182 ----
  {
  private:
    stg_bigblock_t* map;
    
+   GTrashStack* trashstack;
+ 
  public:
    uint32_t width, height, bwidth, bheight;

Index: stest.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/stest.cc,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -C2 -d -r1.1.2.9 -r1.1.2.10
*** stest.cc    30 Oct 2007 01:22:44 -0000      1.1.2.9
--- stest.cc    30 Oct 2007 07:30:01 -0000      1.1.2.10
***************
*** 71,79 ****
     //assert(position);
  
!    StgModelLaser* laser0 = (StgModelLaser*)world.GetModel( 
"MyWorld:0.model:1.laser:0" );
!    StgModelLaser* laser1 = (StgModelLaser*)world.GetModel( 
"MyWorld:0.model:2.laser:0" );
!    StgModelLaser* laser2 = (StgModelLaser*)world.GetModel( 
"MyWorld:0.model:3.laser:0" );
!    StgModelLaser* laser3 = (StgModelLaser*)world.GetModel( 
"MyWorld:0.model:4.laser:0" );
!    //   assert(laser);
  
  //   StgModelRanger* ranger = (StgModelRanger*)world.GetModel( rangername );
--- 71,84 ----
     //assert(position);
  
!    char namebuf[256];
!    StgModelLaser* lasers[200];
! 
!    for( int i=1; i<10; i++ )
!      {
!        sprintf( namebuf, "MyWorld:0.model:%d.laser:0", i );
!        lasers[i] = (StgModelLaser*)world.GetModel( namebuf );
!        assert(lasers[i]);
!        lasers[i]->Subscribe();
!      }
  
  //   StgModelRanger* ranger = (StgModelRanger*)world.GetModel( rangername );
***************
*** 82,89 ****
  //   // subscribe to the laser - starts it collecting data
  //   position->Subscribe();
!    laser0->Subscribe();
!    laser1->Subscribe();
!    laser2->Subscribe();
!    laser3->Subscribe();
  //   ranger->Subscribe();
  
--- 87,91 ----
  //   // subscribe to the laser - starts it collecting data
  //   position->Subscribe();
! 
  //   ranger->Subscribe();
  

Index: blockgrid.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/blockgrid.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** blockgrid.cc        30 Oct 2007 04:20:45 -0000      1.1.2.2
--- blockgrid.cc        30 Oct 2007 07:30:01 -0000      1.1.2.3
***************
*** 1,7 ****
  #include "stage.hh"
  
! #define NBITS 4
! #define NSIZE (1<<NBITS)
! #define MASK (NSIZE-1)
  
  
--- 1,8 ----
  #include "stage.hh"
  
! static const uint32_t NBITS = 5;
! static const uint32_t NSIZE = 1<<NBITS;
! static const uint32_t NSQR = NSIZE*NSIZE;
! static const uint32_t MASK = NSIZE-1;
  
  
***************
*** 17,29 ****
          width, height, bwidth, bheight );
    
    
!   size_t bits = bwidth * bheight;
!   this->map = new stg_bigblock_t[ bits ];
!   bzero( map, sizeof(stg_bigblock_t)*bits );
  }    
  
  StgBlockGrid::~StgBlockGrid()
  {
!   //delete[] lists;
    delete[] map;
  }
--- 18,39 ----
          width, height, bwidth, bheight );
    
+   trashstack = NULL;
    
!   size_t bbs = bwidth * bheight;
!   this->map = new stg_bigblock_t[ bbs ];
!   bzero( map, sizeof(stg_bigblock_t)*bbs );
  }    
  
  StgBlockGrid::~StgBlockGrid()
  {
!   for( uint32_t x=0; x<bwidth; x++ )
!     for( uint32_t y=0; y<bheight; y++ )
!       {
!       stg_bigblock_t* bb = &map[ x + y*bwidth ];
!       
!       if( bb && bb->lists )
!         delete[] bb->lists;
!       }       
!   
    delete[] map;
  }
***************
*** 39,50 ****
        assert(bb); // it really should be there
  
-       //printf( "incrementing block at %u %u (width %u height %u\n",
-       //      a,b, bwidth, bheight );
- 
        if( bb->lists == NULL  )
        {         
!         assert( bb->lists == NULL );
!         bb->lists = new GSList*[ NSIZE*NSIZE ]; 
!         bzero( bb->lists, NSIZE*NSIZE * sizeof(GSList*));
        }
        
--- 49,68 ----
        assert(bb); // it really should be there
  
        if( bb->lists == NULL  )
        {         
!         assert( bb->counter == 0 );
!         
!         if( g_trash_stack_peek( &trashstack ) )
!           {
!             bb->lists = (GSList**)g_trash_stack_pop( &trashstack );
!             //printf( "recycled %p\n", bb->lists );
!           }
!         else                                  
!           {
!             bb->lists = new GSList*[ NSQR ]; 
!             //printf( "alloced %p\n", bb->lists );
!           }
! 
!         bzero( bb->lists, NSQR * sizeof(GSList*));
        }
        
***************
*** 99,105 ****
        if( bb->counter == 0 ) // this was the last entry in this block;
        {
!         delete[] bb->lists; 
          bb->lists = NULL;
        }
      }
  }
--- 117,126 ----
        if( bb->counter == 0 ) // this was the last entry in this block;
        {
!         g_trash_stack_push( &trashstack, bb->lists );
!         //printf( "pushed %p\n", bb->lists );
          bb->lists = NULL;
        }
+ 
+       assert( bb->counter >=0 );
      }
  }
***************
*** 107,111 ****
  void StgBlockGrid::RemoveBlock( StgBlock* block )
  {
-   // todo - speed this up a great deal
    for( uint32_t x=0; x<width; x++ )
      for( uint32_t y=0; y<height; y++ )
--- 128,131 ----
***************
*** 124,135 ****
            glRecti( x<<NBITS,y<<NBITS,(x+1)<<NBITS,(y+1)<<NBITS );
            
!           for( uint32_t a=0; a<NSIZE*NSIZE; a++ )
!             {           
!               if( drawall || bb->lists[ a ] )           
!                 glRecti( (x<<NBITS)+a%NSIZE,
!                          (y<<NBITS)+a/NSIZE,
!                          (x<<NBITS)+a%NSIZE+1,
!                          (y<<NBITS)+a/NSIZE+1 );              
!               
                }
          }     
--- 144,156 ----
            glRecti( x<<NBITS,y<<NBITS,(x+1)<<NBITS,(y+1)<<NBITS );
            
!           if( bb->lists )
!             for( uint32_t a=0; a<NSQR; a++ )
!               {                 
!                 if( drawall || bb->lists[ a ] )                 
!                   glRecti( (x<<NBITS)+a%NSIZE,
!                            (y<<NBITS)+a/NSIZE,
!                            (x<<NBITS)+a%NSIZE+1,
!                            (y<<NBITS)+a/NSIZE+1 );            
!                 
                }
          }     


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to