Revision: 8271
http://playerstage.svn.sourceforge.net/playerstage/?rev=8271&view=rev
Author: rtv
Date: 2009-09-30 17:42:49 +0000 (Wed, 30 Sep 2009)
Log Message:
-----------
fixed problems that broke things when creating models dynamically from
controllers. temporarily disabled multiple threads, until I figure out a clean
way to do that
Modified Paths:
--------------
code/stage/trunk/examples/ctrl/CMakeLists.txt
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_load.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/world.cc
code/stage/trunk/worlds/fasr.world
Added Paths:
-----------
code/stage/trunk/examples/ctrl/dynamic.cc
Modified: code/stage/trunk/examples/ctrl/CMakeLists.txt
===================================================================
--- code/stage/trunk/examples/ctrl/CMakeLists.txt 2009-09-30 16:59:13 UTC
(rev 8270)
+++ code/stage/trunk/examples/ctrl/CMakeLists.txt 2009-09-30 17:42:49 UTC
(rev 8271)
@@ -8,6 +8,7 @@
wander_pioneer
pioneer_flocking
rasterize
+ dynamic
)
# need plaer's wavefront planning library for this one
Added: code/stage/trunk/examples/ctrl/dynamic.cc
===================================================================
--- code/stage/trunk/examples/ctrl/dynamic.cc (rev 0)
+++ code/stage/trunk/examples/ctrl/dynamic.cc 2009-09-30 17:42:49 UTC (rev
8271)
@@ -0,0 +1,21 @@
+#include "stage.hh"
+using namespace Stg;
+
+
+// Stage calls this when the model starts up
+extern "C" int Init( Model* mod )
+{
+ printf( "Creating 100 models" );
+
+ for( int i=0; i<100; i++ )
+ {
+ Model* child = mod->GetWorld()->CreateModel( mod, "model" );
+ assert(child);
+
+ child->SetPose( Pose::Random( -1, 1, -1, 1 ) );
+ child->SetGeom( Geom( Pose(), Size( 0.1, 0.1, 0.1 ) ));
+ child->SetColor( Color(0,0,1,1) );
+ }
+ return 0; //ok
+}
+
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2009-09-30 16:59:13 UTC (rev 8270)
+++ code/stage/trunk/libstage/model.cc 2009-09-30 17:42:49 UTC (rev 8271)
@@ -343,37 +343,13 @@
world->RemoveModel( this );
}
-// this should be called after all models have loaded from the
-// worldfile - it's a chance to do any setup now that all models are
-// in existence
-void Model::Init()
-{
- // init is called after the model is loaded
- blockgroup.CalcSize();
- // remove any old cruft rendered during startup
- UnMap();
- Map();
-
- // find the queue for update events: zero if thread safe, else we
- // ask the world to assign us to a queue
- event_queue_num = thread_safe ? world->GetEventQueue( this ) : 0;
-
+void Model::InitControllers()
+{
CallCallbacks( &hooks.init );
+}
- if( alwayson )
- Subscribe();
-}
-void Model::InitRecursive()
-{
- // must init children first
- FOR_EACH( it, children )
- (*it)->InitRecursive();
-
- Init();
-}
-
void Model::AddFlag( Flag* flag )
{
if( flag )
Modified: code/stage/trunk/libstage/model_load.cc
===================================================================
--- code/stage/trunk/libstage/model_load.cc 2009-09-30 16:59:13 UTC (rev
8270)
+++ code/stage/trunk/libstage/model_load.cc 2009-09-30 17:42:49 UTC (rev
8271)
@@ -226,13 +226,17 @@
trail_interval = wf->ReadInt( wf_entity, "trail_interval",
trail_interval );
this->alwayson = wf->ReadInt( wf_entity, "alwayson", alwayson );
-
+ if( alwayson )
+ Subscribe();
+
// call any type-specific load callbacks
this->CallCallbacks( &hooks.load );
-
-
+
+ // we may well have changed blocks or geometry
+ blockgroup.CalcSize();
+ UnMapWithChildren();
MapWithChildren();
-
+
if( this->debug )
printf( "Model \"%s\" is in debug mode\n", token.c_str() );
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-09-30 16:59:13 UTC (rev 8270)
+++ code/stage/trunk/libstage/stage.hh 2009-09-30 17:42:49 UTC (rev 8271)
@@ -786,10 +786,16 @@
bool destroy;
bool dirty; ///< iff true, a gui redraw would be required
+ /** pointers to the models in the world, indexed by id */
+ //std::map<unsigned int, Model*> models_by_id;
+
+ /** Pointers to all the models in this world. */
+ std::set<Model*> models;
+
/** pointers to the models that make up the world, indexed by name. */
std::map<std::string, Model*> models_by_name;
- /** pointers to the models that make up the world, indexed by
worldfiel entry index */
+ /** pointers to the models that make up the world, indexed by
worldfile entry index */
std::map<int,Model*> models_by_wfentity;
/** Keep a list of all models with detectable fiducials. This
@@ -1840,7 +1846,7 @@
std::string GetSayString(){return std::string(say_string);}
/** Returns a pointer to the model identified by name, or NULL if
- it doesn't exist in this world. */
+ it doesn't exist in this model. */
Model* GetChild( const std::string& name ) const;
class Visibility
@@ -2044,10 +2050,13 @@
/** save the state of the model to the current world file */
virtual void Save();
- /** Should be called after all models are loaded, to do any
last-minute setup */
- void Init();
- void InitRecursive();
+ // Should be called after all models are loaded, to do any last-minute
setup */
+ //void Init();
+ //void InitRecursive();
+ /** Call Init() for all attached controllers. */
+ void InitControllers();
+
void AddFlag( Flag* flag );
void RemoveFlag( Flag* flag );
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2009-09-30 16:59:13 UTC (rev 8270)
+++ code/stage/trunk/libstage/world.cc 2009-09-30 17:42:49 UTC (rev 8271)
@@ -103,6 +103,7 @@
// private
destroy( false ),
dirty( true ),
+ models(),
models_by_name(),
models_with_fiducials(),
ppm( ppm ), // raytrace resolution
@@ -216,8 +217,20 @@
return NULL;
}
+void World::AddModel( Model* mod )
+{
+ models.insert( mod );
+ models_by_name[mod->token] = mod;
+}
+
+void World::AddModelName( Model* mod, const std::string& name )
+{
+ models_by_name[name] = mod;
+}
+
void World::RemoveModel( Model* mod )
{
+ models.erase( mod );
models_by_name.erase( mod->token );
}
@@ -289,7 +302,7 @@
// configure the model with properties from the world file
mod->Load(wf, entity );
- // record the model we created for this worlfile entry
+ // record the model we created for this worldfile entry
models_by_wfentity[entity] = mod;
}
@@ -370,8 +383,9 @@
LoadModel( wf, entity );
}
- FOR_EACH( it, children )
- (*it)->InitRecursive();
+ // call all controller init functions
+ FOR_EACH( it, models )
+ (*it)->InitControllers();
putchar( '\n' );
}
@@ -549,17 +563,8 @@
return false;
}
-void World::AddModel( Model* mod )
-{
- models_by_name[mod->token] = mod;
-}
-void World::AddModelName( Model* mod, const std::string& name )
-{
- models_by_name[name] = mod;
-}
-
unsigned int World::GetEventQueue( Model* mod )
{
if( worker_threads < 1 )
Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world 2009-09-30 16:59:13 UTC (rev 8270)
+++ code/stage/trunk/worlds/fasr.world 2009-09-30 17:42:49 UTC (rev 8271)
@@ -46,7 +46,7 @@
color "green"
pose [ -7.000 -7.000 0 0 ]
name "source"
- ctrl "source"
+ ctrl "dynamic"
)
zone
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit