Revision: 6918
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6918&view=rev
Author:   jeremy_asher
Date:     2008-07-24 00:00:30 +0000 (Thu, 24 Jul 2008)

Log Message:
-----------
stage: fixed ForEachModel being called multiple times for some models by 
replacing with new ForEachDescendant method in StgAncestor

Modified Paths:
--------------
    code/stage/trunk/libstage/ancestor.cc
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/model_fiducial.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc

Modified: code/stage/trunk/libstage/ancestor.cc
===================================================================
--- code/stage/trunk/libstage/ancestor.cc       2008-07-23 21:50:03 UTC (rev 
6917)
+++ code/stage/trunk/libstage/ancestor.cc       2008-07-24 00:00:30 UTC (rev 
6918)
@@ -63,3 +63,12 @@
        return pose;
 }
 
+void StgAncestor::ForEachDescendant( stg_model_callback_t func, void* arg )
+{
+       for( GList* it=children; it; it=it->next ) {
+               StgModel* mod = (StgModel*)it->data;
+               func( mod, arg );
+               mod->ForEachDescendant( func, arg );
+       }
+}
+

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2008-07-23 21:50:03 UTC (rev 6917)
+++ code/stage/trunk/libstage/model.cc  2008-07-24 00:00:30 UTC (rev 6918)
@@ -705,6 +705,7 @@
 {
   //printf( "Startup model %s\n", this->token );
 
+  // TODO:  this could be a callback
   if( initfunc )
     initfunc( this );
 

Modified: code/stage/trunk/libstage/model_fiducial.cc
===================================================================
--- code/stage/trunk/libstage/model_fiducial.cc 2008-07-23 21:50:03 UTC (rev 
6917)
+++ code/stage/trunk/libstage/model_fiducial.cc 2008-07-24 00:00:30 UTC (rev 
6918)
@@ -228,7 +228,7 @@
 
        // TODO - add a fiducial-only hash table to the world to speed this
        // up a lot for large populations
-       world->ForEachModel( 
(GHFunc)(StgModelFiducial::AddModelIfVisibleStatic), 
+       world->ForEachDescendant( 
(stg_model_callback_t)(StgModelFiducial::AddModelIfVisibleStatic), 
                        this );
 
        PRINT_DEBUG2( "model %s saw %d fiducials", token, data->len );
@@ -310,3 +310,15 @@
                PopColor();
        }
 }
+
+void StgModelFiducial::Shutdown( void )
+{ 
+       PRINT_DEBUG( "fiducial shutdown" );
+       
+       // clear the data  
+       data = g_array_set_size( data, 0 );
+       fiducials = NULL;
+       fiducial_count = 0;
+       
+       StgModel::Shutdown();
+}

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-07-23 21:50:03 UTC (rev 6917)
+++ code/stage/trunk/libstage/stage.hh  2008-07-24 00:00:30 UTC (rev 6918)
@@ -848,13 +848,14 @@
 
        protected:
        GList* children;
-  //GHashTable* child_types;
-  
 
        char* token;
        bool debug;
 
        public:
+       
+       /** recursively call func( model, arg ) for each descendant */
+       void ForEachDescendant( stg_model_callback_t func, void* arg );
 
   /** array contains the number of each type of child model */
   unsigned int child_type_counts[MODEL_TYPE_COUNT];
@@ -1118,10 +1119,6 @@
        /** Return the 3D bounding box of the world, in meters */
        stg_bounds3d_t GetExtent(){ return extent; };
 
-       /** call func( model, arg ) for each model in the world */
-       void ForEachModel( GHFunc func, void* arg )
-       { g_hash_table_foreach( models_by_name, func, arg ); };
-
        /** Return the number of times the world has been updated. */
        long unsigned int GetUpdateCount() { return updates; }
 };
@@ -2354,9 +2351,7 @@
                void AddModelIfVisible( StgModel* him );
 
                // static wrapper function can be used as a function pointer
-               static void AddModelIfVisibleStatic( gpointer key, 
-                               StgModel* him, 
-                               StgModelFiducial* me )
+               static int AddModelIfVisibleStatic( StgModel* him, 
StgModelFiducial* me )
                { if( him != me ) me->AddModelIfVisible( him ); };
 
                virtual void Update();
@@ -2375,6 +2370,7 @@
   virtual ~StgModelFiducial();
   
                virtual void Load();
+               void Shutdown( void );
 
                stg_meters_t max_range_anon; //< maximum detection range
                stg_meters_t max_range_id; ///< maximum range at which the ID 
can be read

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2008-07-23 21:50:03 UTC (rev 6917)
+++ code/stage/trunk/libstage/world.cc  2008-07-24 00:00:30 UTC (rev 6918)
@@ -622,9 +622,9 @@
        return;
 }
 
-static void _save_cb( gpointer key, gpointer data, gpointer user )
+static int _save_cb( StgModel* mod, void* dummy )
 {
-       ((StgModel*)data)->Save();
+       mod->Save();
 }
 
 bool StgWorld::Save( const char *filename )
@@ -632,20 +632,20 @@
        // ask every model to save itself
        //g_hash_table_foreach( this->models_by_id, stg_model_save_cb, NULL );
 
-       ForEachModel( _save_cb, NULL );
+       ForEachDescendant( _save_cb, NULL );
 
        return this->wf->Save( filename );
 }
 
-static void _reload_cb( gpointer key, gpointer data, gpointer user )
+static int _reload_cb(  StgModel* mod, void* dummy )
 {
-       ((StgModel*)data)->Load();
+       mod->Load();
 }
 
 // reload the current worldfile
 void StgWorld::Reload( void )
 {
-       ForEachModel( _reload_cb, NULL );
+       ForEachDescendant( _reload_cb, NULL );
 }
 
 void StgWorld::StartUpdatingModel( StgModel* mod )


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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to