Revision: 7778
http://playerstage.svn.sourceforge.net/playerstage/?rev=7778&view=rev
Author: rtv
Date: 2009-06-04 00:04:56 +0000 (Thu, 04 Jun 2009)
Log Message:
-----------
switched list to vector in Cell block container for small speed up. Threads are
brojken
Modified Paths:
--------------
code/stage/trunk/examples/ctrl/CMakeLists.txt
code/stage/trunk/examples/ctrl/Makefile.libtool
code/stage/trunk/libstage/block.cc
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_laser.cc
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/webstage/webstage.cc
code/stage/trunk/worlds/fasr.world
Modified: code/stage/trunk/examples/ctrl/CMakeLists.txt
===================================================================
--- code/stage/trunk/examples/ctrl/CMakeLists.txt 2009-06-03 20:02:21 UTC
(rev 7777)
+++ code/stage/trunk/examples/ctrl/CMakeLists.txt 2009-06-04 00:04:56 UTC
(rev 7778)
@@ -5,7 +5,7 @@
sink
source
wander
-
+# sort
)
# need plaer's wavefront planning library for this one
Modified: code/stage/trunk/examples/ctrl/Makefile.libtool
===================================================================
--- code/stage/trunk/examples/ctrl/Makefile.libtool 2009-06-03 20:02:21 UTC
(rev 7777)
+++ code/stage/trunk/examples/ctrl/Makefile.libtool 2009-06-04 00:04:56 UTC
(rev 7778)
@@ -10,10 +10,10 @@
all: wander.la
wander.la: wander.lo
- $(LIBTOOL) --mode=link $(CXXLD) -rpath $(INSTALL_DIR) -module
-export-dynamic -version-info 0:0:0 $^ -o $@
+ $(LIBTOOL) -mode=link $(CXXLD) -rpath $(INSTALL_DIR) -module
-export-dynamic -version-info 0:0:0 $^ -o $@
%.lo: %.cc
- $(LIBTOOL) --mode=compile $(CXX) $(STAGE_CFLAGS) -c $<
+ $(LIBTOOL) -mode=compile $(CXX) $(STAGE_CFLAGS) -c $<
clean:
rm -rf *.o *.lo *.la .libs
Modified: code/stage/trunk/libstage/block.cc
===================================================================
--- code/stage/trunk/libstage/block.cc 2009-06-03 20:02:21 UTC (rev 7777)
+++ code/stage/trunk/libstage/block.cc 2009-06-04 00:04:56 UTC (rev 7778)
@@ -145,11 +145,10 @@
// for every cell we are rendered into
for( unsigned int i=0; i<rendered_cells->size(); i++ )
{
- //Cell* c = (Cell*)g_ptr_array_index( rendered_cells, i);
Cell* c = (*rendered_cells)[i];
// for every block rendered into that cell
- for( std::list<Block*>::iterator it = c->blocks.begin();
+ for( std::vector<Block*>::iterator it = c->blocks.begin();
it != c->blocks.end();
++it )
{
@@ -176,11 +175,10 @@
// for every cell we may be rendered into
for( unsigned int i=0; i<candidate_cells->size(); i++ )
{
- //Cell* c = (Cell*)g_ptr_array_index(candidate_cells, i);
Cell* c = (*candidate_cells)[i];
// for every rendered into that cell
- for( std::list<Block*>::iterator it = c->blocks.begin();
+ for( std::vector<Block*>::iterator it = c->blocks.begin();
it != c->blocks.end();
++it )
{
@@ -203,15 +201,6 @@
return NULL; // no hit
}
-
-
-
-// used as a callback to gather an array of cells in a polygon
-void AddBlockToCell( Cell* c, Block* block )
-{
- c->AddBlock( block );
-}
-
void Block::Map()
{
// TODO - if called often, we may not need to generate each time
@@ -225,8 +214,6 @@
void Block::UnMap()
{
RemoveFromCellArray( rendered_cells );
-
- //g_ptr_array_set_size( rendered_cells, 0 );
rendered_cells->clear();
mapped = false;
}
@@ -300,7 +287,9 @@
stg_point_t* mpts = GetPointsInModelCoords();
// convert the mpts in model coords into global pixel coords
- stg_point_int_t gpts[pt_count];
+ stg_point_int_t gpts[pt_count]; // should be plenty of room on the
+
// stack (crosses fingers). I don't
+
// want to pay for a malloc here.
for( unsigned int i=0; i<pt_count; i++ )
gpts[i] = mod->world->MetersToPixels( mod->LocalToGlobal(
mpts[i] ));
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2009-06-03 20:02:21 UTC (rev 7777)
+++ code/stage/trunk/libstage/model.cc 2009-06-04 00:04:56 UTC (rev 7778)
@@ -847,6 +847,8 @@
blockgroup.SwitchToTestedCells();
}
+bool collisions_enabled( false );
+
Model* Model::ConditionalMove( const Pose& newpose )
{
assert( newpose.a >= -M_PI );
@@ -854,7 +856,9 @@
Pose startpose = pose;
pose = newpose; // do the move provisionally - we might undo it below
-
+
+ // Model* hitmod = collisions_enabled ? TestCollisionTree() : NULL;
+
Model* hitmod = TestCollisionTree();
if( hitmod )
Modified: code/stage/trunk/libstage/model_laser.cc
===================================================================
--- code/stage/trunk/libstage/model_laser.cc 2009-06-03 20:02:21 UTC (rev
7777)
+++ code/stage/trunk/libstage/model_laser.cc 2009-06-04 00:04:56 UTC (rev
7778)
@@ -293,7 +293,7 @@
// find the global origin of our first emmitted ray
Pose rayorg = geom.pose;
rayorg.z += geom.size.z/2.0;
- rayorg.a = bearing;// + sample_incr/2.0;
+ rayorg.a = bearing;
rayorg = LocalToGlobal(rayorg);
// set up a ray to trace
Modified: code/stage/trunk/libstage/region.cc
===================================================================
--- code/stage/trunk/libstage/region.cc 2009-06-03 20:02:21 UTC (rev 7777)
+++ code/stage/trunk/libstage/region.cc 2009-06-04 00:04:56 UTC (rev 7778)
@@ -146,7 +146,7 @@
else // draw a rectangular solid
{
Cell* c =
&r->cells[p+(q*Region::WIDTH)];
- for(
std::list<Block*>::iterator it = c->blocks.begin();
+ for(
std::vector<Block*>::iterator it = c->blocks.begin();
it !=
c->blocks.end();
++it )
{
Modified: code/stage/trunk/libstage/region.hh
===================================================================
--- code/stage/trunk/libstage/region.hh 2009-06-03 20:02:21 UTC (rev 7777)
+++ code/stage/trunk/libstage/region.hh 2009-06-04 00:04:56 UTC (rev 7778)
@@ -31,14 +31,15 @@
private:
Region* region;
- std::list<Block*> blocks;
+ std::vector<Block*> blocks;
bool boundary;
public:
Cell()
: region( NULL),
blocks()
- { /* empty */ }
+ {
+ }
inline void RemoveBlock( Block* b );
inline void AddBlock( Block* b );
@@ -175,18 +176,39 @@
++count;
}
+inline void printvec( std::vector<Block*>& vec )
+ {
+ printf( "Vec: ");
+ for( size_t i=0; i<vec.size(); i++ )
+ printf( "%p ", vec[i] );
+ puts( "" );
+ }
+
inline void Cell::RemoveBlock( Block* b )
{
- // linear time removal, but these lists should be very short.
- blocks.remove( b );
-
+ // linear time removal, but these vectors are very short, usually 1
+ // or 2 elements. Fast removal - our strategy is to copy the last
+ // item in the vector over the item we want to remove, then pop off
+ // the tail. This avoids moving the other items in the vector. Saves
+ // maybe 1 or 2% run time in my tests.
+
+ // find the value in the vector
+ // printf( "\nremoving %p\n", b );
+ // puts( "before" );
+ // printvec( blocks );
+
+ // copy the last item in the vector to overwrite this one
+ 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();
}
inline void Cell::AddBlock( Block* b )
{
// constant time prepend
- blocks.push_front( b );
+ blocks.push_back( b );
region->IncrementOccupancy();
b->RecordRendering( this );
}
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-06-03 20:02:21 UTC (rev 7777)
+++ code/stage/trunk/libstage/stage.hh 2009-06-04 00:04:56 UTC (rev 7778)
@@ -927,7 +927,7 @@
GMutex* thread_mutex; ///< protect the worker thread management stuff
GThreadPool *threadpool; ///<worker threads for updating some sensor
models in parallel
int total_subs; ///< the total number of subscriptions to all models
- unsigned int update_jobs_pending;
+ //unsigned int update_jobs_pending;
GList* velocity_list; ///< Models with non-zero velocity and should have
their poses updated
unsigned int worker_threads; ///< the number of worker threads to use
GCond* worker_threads_done; ///< signalled when there are no more updates
for the worker threads to do
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2009-06-03 20:02:21 UTC (rev 7777)
+++ code/stage/trunk/libstage/world.cc 2009-06-04 00:04:56 UTC (rev 7778)
@@ -78,7 +78,7 @@
thread_mutex( g_mutex_new() ),
threadpool( NULL ),
total_subs( 0 ),
- update_jobs_pending(0),
+ //update_jobs_pending(0),
velocity_list( NULL ),
worker_threads( 0 ),
worker_threads_done( g_cond_new() ),
@@ -155,9 +155,10 @@
g_mutex_lock( world->thread_mutex );
- world->update_jobs_pending--;
-
- if( world->update_jobs_pending == 0 )
+// world->update_jobs_pending--;
+ // if( world->update_jobs_pending == 0 )
+
+ if( g_thread_pool_unprocessed( world->threadpool ) < 1 )
g_cond_signal( world->worker_threads_done );
g_mutex_unlock( world->thread_mutex );
@@ -524,9 +525,9 @@
if( mod->UpdateDue() )
{
// printf( "updating model %s in WORKER
thread\n", mod->Token() );
- g_mutex_lock( thread_mutex );
- update_jobs_pending++;
- g_mutex_unlock( thread_mutex );
+ //g_mutex_lock( thread_mutex );
+ //update_jobs_pending++;
+ //g_mutex_unlock( thread_mutex );
g_thread_pool_push( threadpool, mod, NULL );
}
}
@@ -534,7 +535,7 @@
// wait for all the last update job to complete - it will
// signal the worker_threads_done condition var
g_mutex_lock( thread_mutex );
- while( update_jobs_pending )
+ while( g_thread_pool_unprocessed( threadpool ) ) //update_jobs_pending )
g_cond_wait( worker_threads_done, thread_mutex );
g_mutex_unlock( thread_mutex );
@@ -729,7 +730,7 @@
{
//printf( "cx %d cy %d\n", cx, cy );
- for( std::list<Block*>::iterator it =
c->blocks.begin();
+ for( std::vector<Block*>::iterator it =
c->blocks.begin();
it != c->blocks.end();
++it )
{
@@ -972,7 +973,7 @@
return sr;
}
-inline Cell* World::GetCellNoCreate( const stg_point_int_t& glob )
+Cell* World::GetCellNoCreate( const stg_point_int_t& glob )
{
Region* r = GetSuperRegionCached( GETSREG(glob.x), GETSREG(glob.y) )
->GetRegionGlobal( glob );
@@ -982,18 +983,8 @@
return NULL;
}
-// inline Cell* World::GetCellCreate( const int32_t x, const int32_t y )
-// {
-// stg_point_int_t glob( x, y );
-// //printf( "GC[ %d %d ] ", glob.x, glob.y );
-
-// return( GetSuperRegionCached( GETSREG(x), GETSREG(y) )
-// ->GetRegionGlobal( glob )
-// ->GetCellGlobalCreate( glob )) ;
-// }
-
-inline Cell* World::GetCellCreate( const stg_point_int_t& glob )
+Cell* World::GetCellCreate( const stg_point_int_t& glob )
{
return( GetSuperRegionCached( GETSREG(glob.x), GETSREG(glob.y) )
->GetRegionGlobal( glob )
Modified: code/stage/trunk/webstage/webstage.cc
===================================================================
--- code/stage/trunk/webstage/webstage.cc 2009-06-03 20:02:21 UTC (rev
7777)
+++ code/stage/trunk/webstage/webstage.cc 2009-06-04 00:04:56 UTC (rev
7778)
@@ -360,12 +360,6 @@
return t;
}
-// static void UpdatePuppetCb( const std::string& name, WebSim::Puppet* pup,
void* arg )
-// {
-// WebStage* ws = (WebStage*)arg;
-// ws->Push( pup->name );
-// }
-
};
Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world 2009-06-03 20:02:21 UTC (rev 7777)
+++ code/stage/trunk/worlds/fasr.world 2009-06-04 00:04:56 UTC (rev 7778)
@@ -17,7 +17,7 @@
# threads may speed things up here depending on available CPU cores & workload
# threadpool 8
- threadpool 0
+threadpool 0
# configure the GUI window
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit