Revision: 7190
http://playerstage.svn.sourceforge.net/playerstage/?rev=7190&view=rev
Author: rtv
Date: 2008-12-06 21:25:20 +0000 (Sat, 06 Dec 2008)
Log Message:
-----------
on-demand cell allocation in a Region gives drastic memory use improvement for
minor CPU overhead. WARNING - mysterious lock-up bug exists (not related to
this commit)
Modified Paths:
--------------
code/stage/trunk/libstage/region.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/stage_internal.hh
code/stage/trunk/libstage/world.cc
code/stage/trunk/libstage/worldgui.cc
Modified: code/stage/trunk/libstage/region.cc
===================================================================
--- code/stage/trunk/libstage/region.cc 2008-12-05 22:31:14 UTC (rev 7189)
+++ code/stage/trunk/libstage/region.cc 2008-12-06 21:25:20 UTC (rev 7190)
@@ -14,24 +14,25 @@
Region::Region()
- : count(0)
+ : count(0), cells(NULL)
{
- for( unsigned int i=0; i<Region::SIZE; i++ )
- cells[i].region = this;
+ //for( unsigned int i=0; i<Region::SIZE; i++ )
+ //cells[i].region = this;
}
Region::~Region()
{
- delete[] cells;
+ if(cells)
+ delete[] cells;
}
-SuperRegion::SuperRegion( int32_t x, int32_t y )
- : count(0)
+SuperRegion::SuperRegion( StgWorld* world, stg_point_int_t origin )
+ : count(0), origin(origin), world(world)
{
- origin.x = x;
- origin.y = y;
-
+ //static int srcount=0;
+ //printf( "created SR number %d\n", ++srcount );
+
// initialize the parent pointer for all my child regions
for( unsigned int i=0; i<SuperRegion::SIZE; i++ )
regions[i].superregion = this;
@@ -39,7 +40,7 @@
SuperRegion::~SuperRegion()
{
- // nothing to do
+ //printf( "deleting SR %p at [%d,%d]\n", this, origin.x, origin.y );
}
void SuperRegion::Draw( bool drawall )
@@ -55,13 +56,20 @@
glColor3f( 0,1,0 );
for( unsigned int x=0; x<SuperRegion::WIDTH; x++ )
for( unsigned int y=0; y<SuperRegion::WIDTH; y++ )
- glRecti( x<<RBITS, y<<RBITS,
- (x+1)<<RBITS, (y+1)<<RBITS );
-
+ glRecti( x<<RBITS, y<<RBITS,
+ (x+1)<<RBITS, (y+1)<<RBITS );
+
// outline superregion
- glColor3f( 0,0,1 );
+ glColor3f( 0,0,1 );
+
glRecti( 0,0, 1<<SRBITS, 1<<SRBITS );
+ char buf[32];
+ snprintf( buf, 15, "%lu", count );
+ gl_draw_string( 1<<SBITS, 1<<SBITS, 0, buf );
+
+ glColor3f( 1.0,0,0 );
+
for( unsigned int x=0; x<SuperRegion::WIDTH; x++ )
for( unsigned int y=0; y<SuperRegion::WIDTH; y++ )
{
@@ -70,7 +78,6 @@
if( r->count < 1 )
continue;
- char buf[16];
snprintf( buf, 15, "%lu", r->count );
gl_draw_string( x<<RBITS, y<<RBITS, 0, buf );
@@ -84,7 +91,6 @@
if( ! drawall ) // draw a rectangle on
the floor
{
- glColor3f( 1.0,0,0 );
glRecti( xx, yy,
xx+1,
yy+1);
}
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-12-05 22:31:14 UTC (rev 7189)
+++ code/stage/trunk/libstage/stage.hh 2008-12-06 21:25:20 UTC (rev 7190)
@@ -170,10 +170,11 @@
*/
inline double normalize( double a )
{
- //optimized version of return( atan2(sin(a), cos(a)));
- while( a < -M_PI ) a += 2.0 * M_PI;
- while( a > M_PI ) a -= 2.0 * M_PI;
- return a;
+ return( atan2(sin(a), cos(a)));
+ // faster than return( atan2(sin(a), cos(a)));
+ //while( a < -M_PI ) a += 2.0 * M_PI;
+ //while( a > M_PI ) a -= 2.0 * M_PI;
+ //return a;
}
@@ -927,7 +928,8 @@
SuperRegion* AddSuperRegion( const stg_point_int_t& coord );
SuperRegion* GetSuperRegion( const stg_point_int_t& coord );
SuperRegion* GetSuperRegionCached( const stg_point_int_t& coord);
-
+ void ExpireSuperRegion( SuperRegion* sr );
+
inline Cell* GetCell( const int32_t x, const int32_t y );
void ForEachCellInPolygonGLfloat( const GLfloat pts[],
@@ -960,7 +962,7 @@
virtual void PushColor( double r, double g, double b, double a ) { /*
do nothing */ };
virtual void PopColor(){ /* do nothing */ };
- SuperRegion* CreateSuperRegion( int32_t x, int32_t y );
+ SuperRegion* CreateSuperRegion( stg_point_int_t origin );
void DestroySuperRegion( SuperRegion* sr );
stg_raytrace_result_t Raytrace( const stg_pose_t& pose,
Modified: code/stage/trunk/libstage/stage_internal.hh
===================================================================
--- code/stage/trunk/libstage/stage_internal.hh 2008-12-05 22:31:14 UTC (rev
7189)
+++ code/stage/trunk/libstage/stage_internal.hh 2008-12-06 21:25:20 UTC (rev
7190)
@@ -192,7 +192,8 @@
static const uint32_t WIDTH;
static const uint32_t SIZE;
- Cell cells[REGIONSIZE];
+ //Cell cells[REGIONSIZE];
+ Cell* cells;
SuperRegion* superregion;
public:
@@ -203,7 +204,14 @@
Cell* GetCell( int32_t x, int32_t y )
{
- return( &cells[x + (y*Region::WIDTH)] );
+ if( ! cells )
+ {
+ cells = new Cell[REGIONSIZE];
+ for( unsigned int i=0; i<Region::SIZE; i++ )
+ cells[i].region = this;
+ }
+ return( &cells[x + (y*Region::WIDTH)] );
+
};
void DecrementOccupancy();
@@ -224,10 +232,11 @@
unsigned long count; // number of blocks rendered into these regions
stg_point_int_t origin;
-
+ StgWorld* world;
+
public:
- SuperRegion( int32_t x, int32_t y );
+ SuperRegion( StgWorld* world, stg_point_int_t origin );
~SuperRegion();
Region* GetRegion( int32_t x, int32_t y )
@@ -237,8 +246,8 @@
void Draw( bool drawall );
void Floor();
-
- void DecrementOccupancy(){ --count; };
+
+ void DecrementOccupancy(){ --count; };
void IncrementOccupancy(){ ++count; };
};
@@ -250,7 +259,7 @@
assert( superregion );
superregion->DecrementOccupancy();
--count;
-}
+};
inline void Region::IncrementOccupancy()
{
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2008-12-05 22:31:14 UTC (rev 7189)
+++ code/stage/trunk/libstage/world.cc 2008-12-06 21:25:20 UTC (rev 7190)
@@ -121,9 +121,9 @@
}
-SuperRegion* StgWorld::CreateSuperRegion( int32_t x, int32_t y )
+SuperRegion* StgWorld::CreateSuperRegion( stg_point_int_t origin )
{
- SuperRegion* sr = new SuperRegion( x, y );
+ SuperRegion* sr = new SuperRegion( this, origin );
g_hash_table_insert( superregions, &sr->origin, sr );
dirty = true; // force redraw
@@ -397,6 +397,7 @@
return( (quit_time > 0) && (sim_time >= quit_time) );
}
+
bool StgWorld::Update()
{
PRINT_DEBUG( "StgWorld::Update()" );
@@ -406,7 +407,7 @@
if( IsGUI() == false )
return true;
}
-
+
// upate all positions first
LISTMETHOD( velocity_list, StgModel*, UpdatePose );
@@ -783,7 +784,7 @@
SuperRegion* StgWorld::AddSuperRegion( const stg_point_int_t& sup )
{
//printf( "Creating super region [ %d %d ]\n", sup.x, sup.y );
- SuperRegion* sr = CreateSuperRegion( sup.x, sup.y );
+ SuperRegion* sr = CreateSuperRegion( sup );
// the bounds of the world have changed
stg_point3_t pt;
@@ -800,6 +801,7 @@
return sr;
}
+
inline SuperRegion* StgWorld::GetSuperRegionCached( const stg_point_int_t& sup
)
{
// around 99% of the time the SR is the same as last
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2008-12-05 22:31:14 UTC (rev
7189)
+++ code/stage/trunk/libstage/worldgui.cc 2008-12-06 21:25:20 UTC (rev
7190)
@@ -325,7 +325,7 @@
}
} while( interval < interval_real );
-
+ //printf( "\r \t\t timenow %lu", timenow );
//printf( "interval_real %.20f\n", interval_real );
// if( paused ) // gentle on the CPU when paused
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit