Revision: 7821
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7821&view=rev
Author:   rtv
Date:     2009-06-08 19:18:00 +0000 (Mon, 08 Jun 2009)

Log Message:
-----------
added lazy region allocation for fast start up of large worlds

Modified Paths:
--------------
    code/stage/trunk/README.txt
    code/stage/trunk/libstage/region.cc
    code/stage/trunk/libstage/region.hh
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc
    code/stage/trunk/worlds/SFU.world

Modified: code/stage/trunk/README.txt
===================================================================
--- code/stage/trunk/README.txt 2009-06-08 16:24:59 UTC (rev 7820)
+++ code/stage/trunk/README.txt 2009-06-08 19:18:00 UTC (rev 7821)
@@ -1,5 +1,5 @@
 
-Copyright Richard Vaughan and contributors 1998-2008.  
+Copyright Richard Vaughan and contributors 1998-2009.  
 Part of the Player Project (http://playerstage.org)
 
 License

Modified: code/stage/trunk/libstage/region.cc
===================================================================
--- code/stage/trunk/libstage/region.cc 2009-06-08 16:24:59 UTC (rev 7820)
+++ code/stage/trunk/libstage/region.cc 2009-06-08 19:18:00 UTC (rev 7821)
@@ -19,30 +19,12 @@
 {
 }
 
-void Region::DecrementOccupancy()
-{ 
-       assert( superregion );
-       superregion->DecrementOccupancy();
-       --count; 
-}
-
-void Region::IncrementOccupancy()
-{ 
-       assert( superregion );
-       superregion->IncrementOccupancy();
-       ++count; 
-}
-
 SuperRegion::SuperRegion( World* world, stg_point_int_t origin )
-  : count(0), origin(origin), world(world)      
+  : regions(NULL), origin(origin), world(world), count(0)       
 {
   //static int srcount=0;
   //printf( "created SR number %d\n", ++srcount ); 
-  //  printf( "superregion at %d %d\n", origin.x, origin.y );
- 
-  // initialize the parent pointer for all my child regions
-  for( int i=0; i<SUPERREGIONSIZE; i++ )
-        regions[i].superregion = this;
+  //  printf( "superregion at %d %d\n", origin.x, origin.y ); 
 }
 
 SuperRegion::~SuperRegion()

Modified: code/stage/trunk/libstage/region.hh
===================================================================
--- code/stage/trunk/libstage/region.hh 2009-06-08 16:24:59 UTC (rev 7820)
+++ code/stage/trunk/libstage/region.hh 2009-06-08 19:18:00 UTC (rev 7821)
@@ -42,7 +42,7 @@
   Region* region;  
   std::vector<Block*> blocks;
   bool boundary;
-
+  
 public:
   Cell() 
         : region( NULL),
@@ -61,7 +61,7 @@
   
   Cell* cells;
   SuperRegion* superregion;    
-  unsigned int count; // number of blocks rendered into these cells
+  unsigned long count; // number of blocks rendered into this region
   
   Region();
   ~Region();
@@ -78,39 +78,41 @@
 
                return( (Cell*)&cells[ x + y * REGIONWIDTH ] ); 
   }
-       
-       void DecrementOccupancy();
-       void IncrementOccupancy();
 };
   
-       class SuperRegion
+  class SuperRegion
   {
-               friend class World;
-               friend class Model;
+        friend class World;
+        friend class Model;     
         
   private:
-
-        Region regions[SUPERREGIONSIZE];
-        unsigned long count; // number of blocks rendered into these regions
         
+        Region* regions;        
         stg_point_int_t origin;
         World* world;
         
   public:
-
+        
         SuperRegion( World* world, stg_point_int_t origin );
         ~SuperRegion();
+        
+        // lazy allocation of regions: wait until someone asks
+        const Region* GetRegion( int32_t x, int32_t y )
+        {
+               if( ! regions )
+                 {
+                        regions = new Region[ SUPERREGIONSIZE ];
+                        for( int i=0; i<SUPERREGIONSIZE; i++ )
+                               regions[i].superregion = this;
+                 }
                
-               const Region* GetRegion( int32_t x, int32_t y ) const
-               {
-                       return( &regions[ x + y * SUPERREGIONWIDTH ] );
-               }
-               
+               return( &regions[ x + y * SUPERREGIONWIDTH ] );
+        }
+        
         void Draw( bool drawall );
         void Floor();
         
-        void DecrementOccupancy(){ --count; };
-        void IncrementOccupancy(){ ++count; };
+        unsigned long count; // number of blocks rendered into this superregion
   };
 
 
@@ -139,16 +141,18 @@
   copy_backward( blocks.end(), blocks.end(), std::find( blocks.begin(), 
blocks.end(), b ));
   blocks.pop_back(); // and remove the redundant copy at the end of
                                                        // the vector
-  
-  region->DecrementOccupancy();
+
+  --region->count;
+  --region->superregion->count;  
 }
 
 void Cell::AddBlock( Block* b )
 {
-  // constant time prepend
-  blocks.push_back( b );
-  region->IncrementOccupancy();
+  blocks.push_back( b );  
   b->RecordRendering( this );
+
+  ++region->count;
+  ++region->superregion->count;
 }
 
 

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-06-08 16:24:59 UTC (rev 7820)
+++ code/stage/trunk/libstage/stage.hh  2009-06-08 19:18:00 UTC (rev 7821)
@@ -1182,7 +1182,7 @@
         void SetZ( double min, double max );
 
     void RecordRendering( Cell* cell )
-    { //g_ptr_array_add( rendered_cells, (gpointer)cell ); };
+    {
                rendered_cells->push_back( cell );
         }
   
@@ -1214,11 +1214,6 @@
   
     stg_color_t GetColor();
         
-//      void Rasterize( uint8_t* data, 
-//                                               unsigned int width, unsigned 
int height, 
-//                                               double scalex, double scaley, 
-//                                               double offsetx, double 
offsety );
-        
         void Rasterize( uint8_t* data, 
                                                  unsigned int width, unsigned 
int height,              
                                                  stg_meters_t cellwidth, 
stg_meters_t cellheight );

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2009-06-08 16:24:59 UTC (rev 7820)
+++ code/stage/trunk/libstage/world.cc  2009-06-08 19:18:00 UTC (rev 7821)
@@ -693,7 +693,8 @@
                        // coordinates of the region inside the superregion
                        int32_t rx( GETREG(glob.x) );
                        int32_t ry( GETREG(glob.y) );           
-                       Region* reg( &sr->regions[ rx + ry * SUPERREGIONWIDTH ] 
);
+                       //Region* reg( &sr->regions[ rx + ry * SUPERREGIONWIDTH 
] );
+                       const Region* reg( sr->GetRegion( rx, ry ) );
 
                        if( reg->count ) // if the region contains any objects
                                {
@@ -706,7 +707,8 @@
                                        int32_t cy( GETCELL(glob.y) );
                         
                                        Cell* c( &reg->cells[ cx + cy * 
REGIONWIDTH ] );
-                                       assert(c); // should be a cell there 
+                                       assert(c); // should be there since we 
know the region
+                                                                 // contains 
objects
                         
                                        // while within the bounds of this 
region and while some ray remains
                                        // we'll tweak the cell pointer 
directly to move around quickly

Modified: code/stage/trunk/worlds/SFU.world
===================================================================
--- code/stage/trunk/worlds/SFU.world   2009-06-08 16:24:59 UTC (rev 7820)
+++ code/stage/trunk/worlds/SFU.world   2009-06-08 19:18:00 UTC (rev 7821)
@@ -9,9 +9,9 @@
 interval_sim 100  # simulation timestep in milliseconds
 interval_real 0  # real-time interval between simulation updates in 
milliseconds 
 
-quit_time 1800
+quit_time 1
 
-paused 1
+paused 0
 
 resolution 0.02
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to