Revision: 8444 http://playerstage.svn.sourceforge.net/playerstage/?rev=8444&view=rev Author: rtv Date: 2009-12-01 00:12:34 +0000 (Tue, 01 Dec 2009)
Log Message: ----------- removing unused code. applied polygon winding patch from Jeff Donner Modified Paths: -------------- code/stage/trunk/libstage/block.cc code/stage/trunk/libstage/model_load.cc code/stage/trunk/libstage/region.hh code/stage/trunk/libstage/stage.hh code/stage/trunk/libstage/world.cc code/stage/trunk/todo.txt code/stage/trunk/worlds/SFU.world code/stage/trunk/worlds/benchmark/hospital.world code/stage/trunk/worlds/fasr.world Modified: code/stage/trunk/libstage/block.cc =================================================================== --- code/stage/trunk/libstage/block.cc 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/libstage/block.cc 2009-12-01 00:12:34 UTC (rev 8444) @@ -2,7 +2,11 @@ #include "worldfile.hh" using namespace Stg; +using std::vector; +static void canonicalize_winding(vector<stg_point_t>& pts); + + /** Create a new block. A model's body is a list of these blocks. The point data is copied, so pts can safely be freed after calling this.*/ @@ -32,6 +36,7 @@ this->pts.reserve( pt_count ); for( size_t p=0; p<pt_count; p++ ) this->pts.push_back( pts[p] ); + canonicalize_winding(this->pts); } /** A from-file constructor */ @@ -52,6 +57,7 @@ assert(entity); Load( wf, entity ); + canonicalize_winding(this->pts); } Block::~Block() @@ -458,3 +464,92 @@ glow = wf->ReadFloat( entity, "glow", glow ); } + +static +/// util; puts angle into [0, 2pi) +void positivize(stg_radians_t& angle) +{ + while (angle < 0) angle += 2 * M_PI; +} + +static +/// util; puts angle into -pi/2, pi/2 +void pi_ize(stg_radians_t& angle) +{ + while (angle < -M_PI) angle += 2 * M_PI; + while (M_PI < angle) angle -= 2 * M_PI; +} + +typedef stg_point_t V2; + +static +/// util; How much was v1 rotated to get to v2? +stg_radians_t angle_change(V2 v1, V2 v2) +{ + stg_radians_t a1 = atan2(v1.y, v1.x); + positivize(a1); + + stg_radians_t a2 = atan2(v2.y, v2.x); + positivize(a2); + + stg_radians_t angle_change = a2 - a1; + pi_ize(angle_change); + + return angle_change; +} + +static +/// util; find vectors between adjacent points, pts[next] - pts[cur] +vector<stg_point_t> find_vectors(vector<stg_point_t> const& pts) +{ + vector<stg_point_t> vs; + assert(2 <= pts.size()); + for (unsigned i = 0, n = pts.size(); i < n; ++i) + { + unsigned j = (i + 1) % n; + vs.push_back(V2(pts[j].x - pts[i].x, pts[j].y - pts[i].y)); + } + assert(vs.size() == pts.size()); + return vs; +} + +static +/// util; finds sum of angle changes, from each vertex to the +/// next one (in current ordering), wrapping around. +stg_radians_t angles_sum(vector<stg_point_t> const& vs) +{ + stg_radians_t angle_sum = 0; + for (unsigned i = 0, n = vs.size(); i < n; ++i) + { + unsigned j = (i + 1) % n; + angle_sum += angle_change(vs[i], vs[j]); + } + return angle_sum; +} + +static +/// Util +bool is_canonical_winding(vector<stg_point_t> const& ps) +{ + // reuse stg_point_t as vector + vector<stg_point_t> vs = find_vectors(ps); + stg_radians_t sum = angles_sum(vs); + bool bCanon = 0 < sum; + + return bCanon; +} + +static +/// util; sums angle changes to see whether it's 2pi or -2pi. +/// 2pi is counter-clockwise winding (which OpenGL requires), +/// -2pi is clockwise. Reverses <pts> when winding is clockwise. +// Note that a simple line that doubles back on itself has an +// angle sum of 0, but that's intrinsic to a line - its winding could +// be either way. +void canonicalize_winding(vector<stg_point_t>& ps) +{ + if (not is_canonical_winding(ps)) + { + std::reverse(ps.begin(), ps.end()); + } +} Modified: code/stage/trunk/libstage/model_load.cc =================================================================== --- code/stage/trunk/libstage/model_load.cc 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/libstage/model_load.cc 2009-12-01 00:12:34 UTC (rev 8444) @@ -51,26 +51,16 @@ watts_give = wf->ReadFloat( wf_entity, "give_watts", watts_give ); watts_take = wf->ReadFloat( wf_entity, "take_watts", watts_take ); - if( wf->PropertyExists( wf_entity, "debug" ) ) - { - PRINT_WARN2( "debug property specified for model %d %s\n", - wf_entity, this->token.c_str() ); - this->debug = wf->ReadInt( wf_entity, "debug", this->debug ); - } + this->debug = wf->ReadInt( wf_entity, "debug", this->debug ); - if( wf->PropertyExists( wf_entity, "name" ) ) - { - const std::string& name = wf->ReadString(wf_entity, "name", token ); - if( name != token ) - { - //printf( "adding name %s to %s\n", name, this->token ); - this->token = name ; - world->AddModelName( this, name ); // add this name to the world's table - } - else - PRINT_ERR1( "Name blank for model %s. Check your worldfile\n", this->token.c_str() ); - } - + const std::string& name = wf->ReadString(wf_entity, "name", token ); + if( name != token ) + { + //printf( "adding name %s to %s\n", name, this->token ); + this->token = name ; + world->AddModelName( this, name ); // add this name to the world's table + } + //PRINT_WARN1( "%s::Load", token ); if( wf->PropertyExists( wf_entity, "origin" ) ) @@ -176,24 +166,22 @@ AddBlockRect(blockgroup.maxx-epsilon,blockgroup.miny, epsilon, bgsize.y, bgsize.z ); } } - - if( wf->PropertyExists( wf_entity, "mass" )) - this->SetMass( wf->ReadFloat(wf_entity, "mass", this->mass )); - + + stg_kg_t m = wf->ReadFloat(wf_entity, "mass", this->mass ); + if( m != this->mass ) + SetMass( m ); + vis.Load( wf, wf_entity ); - SetFiducialReturn( vis.fiducial_return ); // may have some work to do - + SetFiducialReturn( vis.fiducial_return ); // may have some work to do + gui.Load( wf, wf_entity ); - if( wf->PropertyExists( wf_entity, "map_resolution" )) - this->SetMapResolution( wf->ReadFloat(wf_entity, "map_resolution", this->map_resolution )); - - // todo - look into this - //if (vis.gravity_return) - //this->SetVelocity( GetVelocity() ); + double res = wf->ReadFloat(wf_entity, "map_resolution", this->map_resolution ); + if( res != this->map_resolution ) + SetMapResolution( res ); + + velocity_enable = wf->ReadInt( wf_entity, "enable_velocity", velocity_enable ); - velocity_enable = wf->ReadInt( wf_entity, "enable_velocity", velocity_enable ); - if( wf->PropertyExists( wf_entity, "friction" )) { this->SetFriction( wf->ReadFloat(wf_entity, "friction", this->friction )); @@ -214,11 +202,11 @@ } - if( wf->PropertyExists( wf_entity, "say" )) - this->Say( wf->ReadString(wf_entity, "say", "" )); + + Say( wf->ReadString(wf_entity, "say", "" )); - trail_length = wf->ReadInt( wf_entity, "trail_length", trail_length ); - trail.resize( trail_length ); + trail_length = wf->ReadInt( wf_entity, "trail_length", trail_length ); + trail.resize( trail_length ); trail_interval = wf->ReadInt( wf_entity, "trail_interval", trail_interval ); Modified: code/stage/trunk/libstage/region.hh =================================================================== --- code/stage/trunk/libstage/region.hh 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/libstage/region.hh 2009-12-01 00:12:34 UTC (rev 8444) @@ -11,6 +11,8 @@ { // a bit of experimenting suggests that these values are fast. YMMV. + //const int32_t RBITS( 5 ); // regions contain (2^RBITS)^2 pixels + //const int32_t SBITS( 5 );// superregions contain (2^SBITS)^2 regions const int32_t RBITS( 5 ); // regions contain (2^RBITS)^2 pixels const int32_t SBITS( 5 );// superregions contain (2^SBITS)^2 regions const int32_t SRBITS( RBITS+SBITS ); Modified: code/stage/trunk/libstage/stage.hh =================================================================== --- code/stage/trunk/libstage/stage.hh 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/libstage/stage.hh 2009-12-01 00:12:34 UTC (rev 8444) @@ -783,6 +783,9 @@ bool destroy; bool dirty; ///< iff true, a gui redraw would be required + /** Models that should be rendered into the background just-in-time, before sensing occurs */ + //std::vector<Model*> jit_render; + /** Pointers to all the models in this world. */ std::set<Model*> models; @@ -887,9 +890,9 @@ virtual Model* RecentlySelectedModel(){ return NULL; } SuperRegion* AddSuperRegion( const stg_point_int_t& coord ); - SuperRegion* GetSuperRegion( const stg_point_int_t& coord ); - SuperRegion* GetSuperRegionCached( const stg_point_int_t& coord); - SuperRegion* GetSuperRegionCached( int32_t x, int32_t y ); + //SuperRegion* GetSuperRegion( const stg_point_int_t& coord ); + //SuperRegion* GetSuperRegionCached( const stg_point_int_t& coord); + SuperRegion* GetSuperRegion( int32_t x, int32_t y ); void ExpireSuperRegion( SuperRegion* sr ); /** add a Cell pointer to the vector for each cell on the line from @@ -1610,6 +1613,9 @@ always runs. Defaults to false. */ bool alwayson; + /** If true, the model is rendered lazily into the regions, to reduce memory use. */ + // bool background; + BlockGroup blockgroup; /** OpenGL display list identifier for the blockgroup */ int blocks_dl; Modified: code/stage/trunk/libstage/world.cc =================================================================== --- code/stage/trunk/libstage/world.cc 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/libstage/world.cc 2009-12-01 00:12:34 UTC (rev 8444) @@ -47,9 +47,9 @@ detection and sensing. The default is often a reasonable choice. - show_clock <int>\n - If non-zero, print the simulation time on stdout every - $show_clock_interval updates. Useful to watch the progress of - non-GUI simulations. + If non-zero, print the simulation time on stdout every + $show_clock_interval updates. Useful to watch the progress of + non-GUI simulations. - show_clock_interval <int>\n Sets the number of updates between printing the time on stdoutm, @@ -103,6 +103,7 @@ // private destroy( false ), dirty( true ), + //jit_render(), models(), models_by_name(), models_with_fiducials(), @@ -351,18 +352,18 @@ // kick off the threads for( unsigned int t=0; t<worker_threads; t++ ) - { - std::pair<World*,int> *p = new std::pair<World*,int>( this, t+1 ); + { + std::pair<World*,int> info( this, t+1 ); + + //normal posix pthread C function pointer + typedef void* (*func_ptr) (void*); - //normal posix pthread C function pointer - typedef void* (*func_ptr) (void*); - - pthread_t pt; - pthread_create( &pt, - NULL, - (func_ptr)World::update_thread_entry, - p ); - } + pthread_t pt; + pthread_create( &pt, + NULL, + (func_ptr)World::update_thread_entry, + &info ); + } printf( "[threads %u]", worker_threads ); } @@ -374,13 +375,13 @@ // don't load window entries here if( strcmp( typestr, "window" ) == 0 ) - { - /* do nothing here */ - } + { + /* do nothing here */ + } else if( strcmp( typestr, "block" ) == 0 ) - LoadBlock( wf, entity ); + LoadBlock( wf, entity ); else - LoadModel( wf, entity ); + LoadModel( wf, entity ); } // call all controller init functions @@ -448,7 +449,7 @@ } void World::AddUpdateCallback( stg_world_callback_t cb, - void* user ) + void* user ) { // add the callback & argument to the list std::pair<stg_world_callback_t,void*> p(cb, user); @@ -456,7 +457,7 @@ } int World::RemoveUpdateCallback( stg_world_callback_t cb, - void* user ) + void* user ) { std::pair<stg_world_callback_t,void*> p( cb, user ); @@ -705,7 +706,7 @@ // inline calls have a noticeable (2-3%) effect on performance. while( n > 0 ) // while we are still not at the ray end { - Region* reg( GetSuperRegionCached( GETSREG(globx), GETSREG(globy) ) + Region* reg( GetSuperRegion( GETSREG(globx), GETSREG(globy) ) ->GetRegion( GETREG(globx), GETREG(globy) )); if( reg->count ) // if the region contains any objects @@ -903,56 +904,36 @@ //printf( "top right (%.2f,%.2f,%.2f)\n", pt.x, pt.y, pt.z ); Extend( pt ); // top right corner of the new superregion +// // map all jit models +// FOR_EACH( it, jit_render ) +// (*it)->Map(); + return sr; } -inline SuperRegion* World::GetSuperRegionCached( int32_t x, int32_t y ) + +inline SuperRegion* World::GetSuperRegion( int32_t x, int32_t y ) { // around 99% of the time the SR is the same as last // lookup - cache gives a 4% overall speed up :) if( sr_cached && sr_cached->origin.x == x && sr_cached->origin.y == y ) return sr_cached; - //else - // delay constructing the object as long as possible - return GetSuperRegion( stg_point_int_t(x,y) ); -} - -inline SuperRegion* World::GetSuperRegionCached( const stg_point_int_t& sup ) -{ - // around 99% of the time the SR is the same as last - // lookup - cache gives a 4% overall speed up :) - if( sr_cached && sr_cached->origin == sup ) - return sr_cached; - //else - return GetSuperRegion( sup); -} - - -inline SuperRegion* World::GetSuperRegion( const stg_point_int_t& sup ) -{ - //printf( "SUP[ %d %d ] ", sup.x, sup.y ); - SuperRegion* sr = superregions[ sup ]; + stg_point_int_t pt(x,y); + SuperRegion* sr = superregions[ pt ]; + if( sr == NULL ) // no superregion exists! make a new one - sr = AddSuperRegion( sup ); + sr = AddSuperRegion( pt ); // cache for next time around sr_cached = sr; - assert( sr ); + //assert( sr ); return sr; } -// Cell* World::GetCell( const stg_point_int_t& glob ) -// { -// return( ((Region*)GetSuperRegionCached( GETSREG(glob.x), GETSREG(glob.y) ) -// ->GetRegion( GETREG(glob.x), GETREG(glob.y) )) -// ->GetCell( GETCELL(glob.x), GETCELL(glob.y) )) ; -// } - - void World::ForEachCellInLine( const stg_point_int_t& start, const stg_point_int_t& end, CellPtrVec& cells ) @@ -975,9 +956,9 @@ while( n ) { - Region* reg( GetSuperRegionCached( GETSREG(globx), GETSREG(globy) ) + Region* reg( GetSuperRegion( GETSREG(globx), GETSREG(globy) ) ->GetRegion( GETREG(globx), GETREG(globy) )); - + // add all the required cells in this region before looking up // another region int32_t cx( GETCELL(globx) ); @@ -994,7 +975,7 @@ n > 0 ) { // find the cell at this location, then add it to the vector - cells.push_back( c ); + cells.push_back( c ); // cleverly skip to the next cell (now it's safe to // manipulate the cell pointer) Modified: code/stage/trunk/todo.txt =================================================================== --- code/stage/trunk/todo.txt 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/todo.txt 2009-12-01 00:12:34 UTC (rev 8444) @@ -16,6 +16,7 @@ OS X 16.20 (rev 7949) 19.94 (rev 8210 - new event queue is slower but more powerful and elegant) 14.5 (rev 8295) threads: 6: 13.7 3: 13.4 + 14.16 (rev 8329) threads 3: 13.4 MBA 17.3 MBA 23.1 (1 thread) Modified: code/stage/trunk/worlds/SFU.world =================================================================== --- code/stage/trunk/worlds/SFU.world 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/worlds/SFU.world 2009-12-01 00:12:34 UTC (rev 8444) @@ -9,7 +9,7 @@ speedup -1 # as fast as possible paused 0 -resolution 0.1 +resolution 0.05 threads 0 # configure the GUI window Modified: code/stage/trunk/worlds/benchmark/hospital.world =================================================================== --- code/stage/trunk/worlds/benchmark/hospital.world 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/worlds/benchmark/hospital.world 2009-12-01 00:12:34 UTC (rev 8444) @@ -32,6 +32,7 @@ # load an environment bitmap floorplan ( + background 0 size [140.000 60.000 0.500] pose [0 0.500 0 0] bitmap "../bitmaps/hospital.png" @@ -43,22 +44,22 @@ color "random" ranger( pose [ 0 0 -0.050 0 ] - alwayson 1 + # alwayson 1 - scount 12 - spose[0] [0 0 0] - spose[1] [0 0 30] - spose[2] [0 0 60] - spose[3] [0 0 90] - spose[4] [0 0 120] - spose[5] [0 0 150] - spose[6] [0 0 180] - spose[7] [0 0 210] - spose[8] [0 0 240] - spose[9] [0 0 270] - spose[10] [0 0 300] - spose[11] [0 0 330] - sview [ 0 2 30] ) + scount 12 + spose[0] [0 0 0] + spose[1] [0 0 30] + spose[2] [0 0 60] + spose[3] [0 0 90] + spose[4] [0 0 120] + spose[5] [0 0 150] + spose[6] [0 0 180] + spose[7] [0 0 210] + spose[8] [0 0 240] + spose[9] [0 0 270] + spose[10] [0 0 300] + spose[11] [0 0 330] + sview [ 0 2 30] ) ctrl "expand_swarm" ) Modified: code/stage/trunk/worlds/fasr.world =================================================================== --- code/stage/trunk/worlds/fasr.world 2009-11-24 19:39:13 UTC (rev 8443) +++ code/stage/trunk/worlds/fasr.world 2009-12-01 00:12:34 UTC (rev 8444) @@ -15,7 +15,7 @@ resolution 0.02 -#threads 2 + threads 0 # configure the GUI window window @@ -35,7 +35,7 @@ # load an environment bitmap floorplan ( - name "cave" + name "cave" pose [0 0 0 0] size [16.000 16.000 0.600] bitmap "bitmaps/cave.png" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit