Revision: 8186
http://playerstage.svn.sourceforge.net/playerstage/?rev=8186&view=rev
Author: rtv
Date: 2009-08-08 01:44:39 +0000 (Sat, 08 Aug 2009)
Log Message:
-----------
removed ext::hash_map for portability
Modified Paths:
--------------
code/stage/trunk/libstage/color.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/world.cc
code/stage/trunk/libstage/worldfile.cc
code/stage/trunk/libstage/worldfile.hh
code/stage/trunk/libstage/worldgui.cc
code/stage/trunk/libstageplugin/p_driver.cc
code/stage/trunk/worlds/fasr.world
Modified: code/stage/trunk/libstage/color.cc
===================================================================
--- code/stage/trunk/libstage/color.cc 2009-08-07 20:57:37 UTC (rev 8185)
+++ code/stage/trunk/libstage/color.cc 2009-08-08 01:44:39 UTC (rev 8186)
@@ -48,7 +48,7 @@
PRINT_DEBUG( "Success!" );
- // load the file into the hash table
+ // load the file into the map
while(1)
{
char line[1024];
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-08-07 20:57:37 UTC (rev 8185)
+++ code/stage/trunk/libstage/stage.hh 2009-08-08 01:44:39 UTC (rev 8186)
@@ -47,7 +47,6 @@
#include <vector>
#include <list>
#include <map>
-#include <ext/hash_map>
#include <set>
#include <queue>
#include <algorithm>
@@ -822,20 +821,15 @@
bool destroy;
bool dirty; ///< iff true, a gui redraw would be required
- // functor for comparing C strings in a hash_map
- struct eqstr
- {
- bool operator()( const char* a, const char* b )
- { return( strcmp( a, b ) == 0 ); }
- };
-
- __gnu_cxx::hash_map<const char*, Model*, __gnu_cxx::hash<const
char*>, eqstr > models_by_name; ///< the models that make up the world, indexed
by name.
-
- std::map<int,Model*> models_by_wfentity;
+ /** pointers to the models that make up the world, indexed by
name. */
+ std::map<std::string, Model*> models_by_name;
- /** Keep a list of all models with detectable fiducials. This
- avoids searching the whole world for fiducials. */
- ModelPtrSet models_with_fiducials;
+ /** pointers to the models that make up the world, indexed by
worldfiel entry index */
+ std::map<int,Model*> models_by_wfentity;
+
+ /** Keep a list of all models with detectable fiducials. This
+ avoids searching the whole world for fiducials.
*/
+ ModelPtrSet models_with_fiducials;
double ppm; ///< the resolution of the world model in pixels per meter
bool quit; ///< quit this world ASAP
@@ -846,8 +840,9 @@
stg_usec_t real_time_start; ///< the real time at which this world was
created
bool show_clock; ///< iff true, print the sim time on stdout
unsigned int show_clock_interval; ///< updates between clock xoutputs
+
pthread_mutex_t thread_mutex; ///< protect the worker thread management
stuff
- unsigned int threads_working; ///< the number of worker threads not
yet finished
+ unsigned int threads_working; ///< the number of worker threads
not yet finished
pthread_cond_t threads_start_cond; ///< signalled to unblock worker threads
pthread_cond_t threads_done_cond; ///< signalled by last worker thread to
unblock main thread
int total_subs; ///< the total number of subscriptions to all models
@@ -1049,7 +1044,7 @@
/** Returns a pointer to the model identified by name, or NULL if
nonexistent */
- Model* GetModel( const char* name );
+ Model* GetModel( const char* name ) const;
/** Return the 3D bounding box of the world, in meters */
stg_bounds3d_t GetExtent(){ return extent; };
@@ -1863,21 +1858,6 @@
unsigned int width, unsigned int height,
stg_meters_t cellwidth, stg_meters_t
cellheight );
-// void Lock()
-// {
-// if( access_mutex == NULL )
-// access_mutex = g_mutex_new();
-
-// assert( access_mutex );
-// g_mutex_lock( access_mutex );
-// }
-
-// void Unlock()
-// {
-// assert( access_mutex );
-// g_mutex_unlock( access_mutex );
-// }
-
private:
/** Private copy constructor declared but not defined, to make it
impossible to copy models. */
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2009-08-07 20:57:37 UTC (rev 8185)
+++ code/stage/trunk/libstage/world.cc 2009-08-08 01:44:39 UTC (rev 8186)
@@ -204,7 +204,6 @@
void World::RemoveModel( Model* mod )
{
- //g_hash_table_remove( models_by_name, mod );
models_by_name.erase( mod->token );
}
@@ -226,7 +225,7 @@
{
Model* mod = NULL; // new model to return
- // find the creator function pointer in the hash table. use the
+ // find the creator function pointer in the map. use the
// vanilla model if the type is NULL.
stg_creator_t creator = NULL;
@@ -376,16 +375,13 @@
delete (*it);
children.clear();
- //g_hash_table_remove_all( models_by_name );
models_by_name.clear();
models_by_wfentity.clear();
ray_list.clear();
- // todo
- //g_hash_table_foreach( superregions, (GHFunc)destroy_sregion, NULL );
- //g_hash_table_remove_all( superregions );
-
+ // todo - clean up regions & superregions?
+
token = NULL;
}
@@ -625,23 +621,25 @@
return false;
}
-
void World::AddModel( Model* mod )
{
- //g_hash_table_insert( this->models_by_name, (gpointer)mod->Token(), mod );
models_by_name[mod->token] = mod;
}
-Model* World::GetModel( const char* name )
+Model* World::GetModel( const char* name ) const
{
PRINT_DEBUG1( "looking up model name %s in models_by_name", name );
- //Model* mod = (Model*)g_hash_table_lookup( this->models_by_name, name );
- Model* mod = models_by_name[ name ];
- if( mod == NULL )
- PRINT_WARN1( "lookup of model name %s: no matching name", name );
-
- return mod;
+ std::map<std::string,Model*>::const_iterator it =
+ models_by_name.find( name );
+
+ if( it == models_by_name.end() )
+ {
+ PRINT_WARN1( "lookup of model name %s: no matching
name", name );
+ return NULL;
+ }
+ else
+ return it->second; // the Model*
}
void World::RecordRay( double x1, double y1, double x2, double y2 )
@@ -1102,7 +1100,6 @@
/// Register an Option for pickup by the GUI
void World:: RegisterOption( Option* opt )
{
- //g_hash_table_insert( option_table, (void*)opt->htname, opt );
option_table.insert( opt );
}
Modified: code/stage/trunk/libstage/worldfile.cc
===================================================================
--- code/stage/trunk/libstage/worldfile.cc 2009-08-07 20:57:37 UTC (rev
8185)
+++ code/stage/trunk/libstage/worldfile.cc 2009-08-08 01:44:39 UTC (rev
8186)
@@ -58,25 +58,6 @@
PRINT_ERR2("%s:%d : " z, this->filename, l)
-
-// guint PropertyHash( const CProperty* prop )
-// {
-// char key[128];
-// snprintf( key, 127, "%d%s", prop->entity, prop->name );
-// prop->key = strdup( key );
-
-// return g_str_hash( prop->key );
-// }
-
-// void destroy_property(gpointer value)
-// {
-// CProperty * prop = reinterpret_cast<CProperty *> (value);
-// free(prop->key);
-// free(prop->values);
-// g_free(value);
-
-// }
-
///////////////////////////////////////////////////////////////////////////
// Default constructor
Worldfile::Worldfile() :
Modified: code/stage/trunk/libstage/worldfile.hh
===================================================================
--- code/stage/trunk/libstage/worldfile.hh 2009-08-07 20:57:37 UTC (rev
8185)
+++ code/stage/trunk/libstage/worldfile.hh 2009-08-08 01:44:39 UTC (rev
8186)
@@ -42,7 +42,7 @@
// Name of property
const char *name;
- char* key; // this property's hash table key
+ char* key; // this property's map key
// A list of token indexes
int value_count;
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2009-08-07 20:57:37 UTC (rev
8185)
+++ code/stage/trunk/libstage/worldgui.cc 2009-08-08 01:44:39 UTC (rev
8186)
@@ -450,22 +450,21 @@
void WorldGui::DrawTree( bool drawall )
{
- //g_hash_table_foreach( superregions, (GHFunc)Draw_cb, (void*)drawall );
-
- for( std::map<stg_point_int_t,SuperRegion*>::iterator it =
superregions.begin();
- it != superregions.end();
- it++ )
+ FOR_EACH( it, superregions )
+// for( std::map<stg_point_int_t,SuperRegion*>::iterator it =
superregions.begin();
+// it != superregions.end();
+// it++ )
(*it).second->Draw( drawall );
}
void WorldGui::DrawFloor()
{
PushColor( 1,1,1,1 );
- //g_hash_table_foreach( superregions, (GHFunc)Floor_cb, NULL );
- for( std::map<stg_point_int_t,SuperRegion*>::iterator it =
superregions.begin();
- it != superregions.end();
- it++ )
+ FOR_EACH( it, superregions )
+// for( std::map<stg_point_int_t,SuperRegion*>::iterator it =
superregions.begin();
+// it != superregions.end();
+// it++ )
(*it).second->Floor();
PopColor();
Modified: code/stage/trunk/libstageplugin/p_driver.cc
===================================================================
--- code/stage/trunk/libstageplugin/p_driver.cc 2009-08-07 20:57:37 UTC (rev
8185)
+++ code/stage/trunk/libstageplugin/p_driver.cc 2009-08-08 01:44:39 UTC (rev
8186)
@@ -465,11 +465,9 @@
// todo - faster lookup with a better data structure
Interface* StgDriver::LookupDevice( player_devaddr_t addr )
{
- //for( int i=0; i<(int)this->devices->len; i++ )
FOR_EACH( it, this->devices )
{
Interface* candidate = *it;
- //(Interface*)g_ptr_array_index( this->devices,
i );
if( candidate->addr.robot == addr.robot &&
candidate->addr.interf == addr.interf &&
@@ -521,11 +519,8 @@
StgDriver::~StgDriver()
{
- // todo - when the sim thread exits, destroy the world. It's not
- // urgent, because right now this only happens when Player quits.
- // stg_world_destroy( StgDriver::world );
-
- //puts( "Stage driver destroyed" );
+ delete world;
+ puts( "Stage driver destroyed" );
}
@@ -535,16 +530,9 @@
{
//puts("Shutting stage driver down");
- // Stop and join the driver thread
- // this->StopThread(); // todo - the thread only runs in the sim instance
+ FOR_EACH( it, this->devices )
+ (*it)->Unsubscribe();
- // shutting unsubscribe to data from all the devices
- //for( int i=0; i<(int)this->devices->len; i++ )
- //{
- // Interface* device = (Interface*)g_ptr_array_index( this->devices, i );
- // stg_model_unsubscribe( device->mod );
- // }
-
puts("Stage driver has been shutdown");
return(0);
@@ -580,38 +568,35 @@
{
Driver::ProcessMessages();
- // puts( "STG driver update" );
-
- //for( int i=0; i<(int)this->devices->len; i++ )
FOR_EACH( it, this->devices )
{
- Interface* interface = *it;
//(Interface*)g_ptr_array_index( this->devices, i );
-
- assert( interface );
-
- switch( interface->addr.interf )
- {
- case PLAYER_SIMULATION_CODE:
- world->Update();
- break;
-
- default:
- {
- // Has enough time elapsed since the last time we
published on this
- // interface? This really needs some thought, as each
model/interface
- // should have a configurable publishing rate. For
now, I'm using the
- // world's update rate (which appears to be stored as
msec). - BPG
- double currtime;
- GlobalTime->GetTimeDouble(&currtime);
- if((currtime - interface->last_publish_time) >=
- (interface->publish_interval_msec / 1e3))
+ Interface* interface = *it;
+
+ assert( interface );
+
+ switch( interface->addr.interf )
{
- interface->Publish();
- interface->last_publish_time = currtime;
+ case PLAYER_SIMULATION_CODE:
+ world->Update();
+ break;
+
+ default:
+ {
+ // Has enough time elapsed
since the last time we published on this
+ // interface? This really
needs some thought, as each model/interface
+ // should have a configurable
publishing rate. For now, I'm using the
+ // world's update rate (which
appears to be stored as msec). - BPG
+ double currtime;
+
GlobalTime->GetTimeDouble(&currtime);
+ if((currtime -
interface->last_publish_time) >=
+
(interface->publish_interval_msec / 1e3))
+ {
+
interface->Publish();
+
interface->last_publish_time = currtime;
+ }
+ }
}
- }
- }
- }
+ }
}
Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world 2009-08-07 20:57:37 UTC (rev 8185)
+++ code/stage/trunk/worlds/fasr.world 2009-08-08 01:44:39 UTC (rev 8186)
@@ -15,7 +15,7 @@
resolution 0.02
-threads 0
+threads 2
# configure the GUI window
window
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit