Revision: 8590
http://playerstage.svn.sourceforge.net/playerstage/?rev=8590&view=rev
Author: rtv
Date: 2010-03-15 18:01:48 +0000 (Mon, 15 Mar 2010)
Log Message:
-----------
refactored callback code for simplicity and speed - will break many clients,
but the API just shrank quite a bit
Modified Paths:
--------------
code/stage/trunk/examples/ctrl/fasr.cc
code/stage/trunk/examples/ctrl/fasr2.cc
code/stage/trunk/examples/ctrl/pioneer_flocking.cc
code/stage/trunk/examples/ctrl/source.cc
code/stage/trunk/examples/ctrl/wander.cc
code/stage/trunk/examples/ctrl/wander_pioneer.cc
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_callbacks.cc
code/stage/trunk/libstage/model_getset.cc
code/stage/trunk/libstage/model_load.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/worlds/benchmark/expand_pioneer.cc
code/stage/trunk/worlds/benchmark/expand_swarm.cc
code/stage/trunk/worlds/pioneer_flocking.world
Modified: code/stage/trunk/examples/ctrl/fasr.cc
===================================================================
--- code/stage/trunk/examples/ctrl/fasr.cc 2010-03-15 17:54:04 UTC (rev
8589)
+++ code/stage/trunk/examples/ctrl/fasr.cc 2010-03-15 18:01:48 UTC (rev
8590)
@@ -93,15 +93,15 @@
// pos->GetUnusedModelOfType( "laser" );
// PositionUpdate() checks to see if we reached source or sink
- pos->AddUpdateCallback( (stg_model_callback_t)PositionUpdate, this );
+ pos->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)PositionUpdate, this );
pos->Subscribe();
// LaserUpdate() controls the robot, by reading from laser and
// writing to position
- laser->AddUpdateCallback( (stg_model_callback_t)LaserUpdate, this );
+ laser->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)LaserUpdate, this );
laser->Subscribe();
- fiducial->AddUpdateCallback( (stg_model_callback_t)FiducialUpdate,
this );
+ fiducial->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)FiducialUpdate, this );
fiducial->Subscribe();
//gripper->AddUpdateCallback( (stg_model_callback_t)GripperUpdate,
this );
Modified: code/stage/trunk/examples/ctrl/fasr2.cc
===================================================================
--- code/stage/trunk/examples/ctrl/fasr2.cc 2010-03-15 17:54:04 UTC (rev
8589)
+++ code/stage/trunk/examples/ctrl/fasr2.cc 2010-03-15 18:01:48 UTC (rev
8590)
@@ -283,19 +283,12 @@
// pos->GetUnusedModelOfType( "laser" );
// PositionUpdate() checks to see if we reached source or sink
- pos->AddUpdateCallback( (stg_model_callback_t)UpdateCallback, this );
+ pos->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)UpdateCallback, this );
pos->Subscribe();
// no other callbacks - we access all other data from the position
// callback
-
- // start with only the laser enabled - we switch laser, ranger and
- // fiducial on and off as needed to save energy and compute time
-
- //laser->AddUpdateCallback(
(stg_model_callback_t)Robot::LaserUpdateCallback, this );
-
-
EnableLaser(true);
pos->AddVisualizer( &graphvis, true );
Modified: code/stage/trunk/examples/ctrl/pioneer_flocking.cc
===================================================================
--- code/stage/trunk/examples/ctrl/pioneer_flocking.cc 2010-03-15 17:54:04 UTC
(rev 8589)
+++ code/stage/trunk/examples/ctrl/pioneer_flocking.cc 2010-03-15 18:01:48 UTC
(rev 8590)
@@ -50,11 +50,11 @@
assert( robot->ranger );
// ask Stage to call into our ranger update function
- robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot
);
+ robot->ranger->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)RangerUpdate, robot );
robot->fiducial = (ModelFiducial*)mod->GetUnusedModelOfType( "fiducial" ) ;
assert( robot->fiducial );
- robot->fiducial->AddUpdateCallback( (stg_model_callback_t)FiducialUpdate,
robot );
+ robot->fiducial->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)FiducialUpdate, robot );
robot->fiducial->Subscribe();
robot->ranger->Subscribe();
Modified: code/stage/trunk/examples/ctrl/source.cc
===================================================================
--- code/stage/trunk/examples/ctrl/source.cc 2010-03-15 17:54:04 UTC (rev
8589)
+++ code/stage/trunk/examples/ctrl/source.cc 2010-03-15 18:01:48 UTC (rev
8590)
@@ -1,7 +1,7 @@
#include "stage.hh"
using namespace Stg;
-const int INTERVAL = 100;
+const unsigned int INTERVAL = 100;
const double FLAGSZ = 0.25;
const unsigned int CAPACITY = 1;
@@ -18,7 +18,7 @@
// Stage calls this when the model starts up
extern "C" int Init( Model* mod )
{
- mod->AddUpdateCallback( (stg_model_callback_t)Update, NULL );
+ mod->AddCallback( Model::CB_UPDATE, (stg_model_callback_t)Update, NULL );
mod->Subscribe();
return 0; //ok
}
Modified: code/stage/trunk/examples/ctrl/wander.cc
===================================================================
--- code/stage/trunk/examples/ctrl/wander.cc 2010-03-15 17:54:04 UTC (rev
8589)
+++ code/stage/trunk/examples/ctrl/wander.cc 2010-03-15 18:01:48 UTC (rev
8590)
@@ -37,7 +37,7 @@
robot->pos = (ModelPosition*)mod;
robot->laser = (ModelLaser*)mod->GetChild( "laser:0" );
- robot->laser->AddUpdateCallback( (stg_model_callback_t)LaserUpdate, robot );
+ robot->laser->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)LaserUpdate, robot );
robot->laser->Subscribe(); // starts the laser updates
robot->pos->Subscribe(); // starts the position updates
Modified: code/stage/trunk/examples/ctrl/wander_pioneer.cc
===================================================================
--- code/stage/trunk/examples/ctrl/wander_pioneer.cc 2010-03-15 17:54:04 UTC
(rev 8589)
+++ code/stage/trunk/examples/ctrl/wander_pioneer.cc 2010-03-15 18:01:48 UTC
(rev 8590)
@@ -50,12 +50,12 @@
robot->ranger = (ModelRanger*)mod->GetUnusedModelOfType( "ranger" );
assert( robot->ranger );
// ask Stage to call into our ranger update function whenever the ranger is
updated
- robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot
);
+ robot->ranger->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)RangerUpdate, robot );
robot->fiducial = (ModelFiducial*)mod->GetUnusedModelOfType( "fiducial" ) ;
assert( robot->fiducial );
// ask Stage to call into our fiducial update function whenever the fiducial
is updated
- robot->fiducial->AddUpdateCallback( (stg_model_callback_t)FiducialUpdate,
robot );
+ robot->fiducial->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)FiducialUpdate, robot );
// subscribe to the laser, though we don't use it for navigating
//robot->laser = (ModelLaser*)mod->GetModel( "laser:0" );
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2010-03-15 17:54:04 UTC (rev 8589)
+++ code/stage/trunk/libstage/model.cc 2010-03-15 18:01:48 UTC (rev 8590)
@@ -162,7 +162,7 @@
uint64_t Model::trail_interval = 5;
std::map<stg_id_t,Model*> Model::modelsbyid;
std::map<std::string, creator_t> Model::name_map;
-std::map<void*, std::set<Model::stg_cb_t> > Model::callbacks;
+//std::map<void*, std::set<Model::stg_cb_t> > Model::callbacks;
void Size::Load( Worldfile* wf, int section, const char* keyword )
{
@@ -268,6 +268,7 @@
blockgroup(),
blocks_dl(0),
boundary(false),
+ callbacks(__CB_TYPE_COUNT),
color( 1,0,0 ), // red
data_fresh(false),
disabled(false),
@@ -361,7 +362,7 @@
void Model::InitControllers()
{
- CallCallbacks( &hooks.init );
+ CallCallbacks( CB_INIT );
}
@@ -370,7 +371,7 @@
if( flag )
{
flag_list.push_back( flag );
- CallCallbacks( &hooks.flag_incr );
+ CallCallbacks( CB_FLAGINCR );
}
}
@@ -379,17 +380,17 @@
if( flag )
{
EraseAll( flag, flag_list );
- CallCallbacks( &hooks.flag_decr );
+ CallCallbacks( CB_FLAGDECR );
}
}
void Model::PushFlag( Flag* flag )
{
if( flag )
- {
- flag_list.push_front( flag);
- CallCallbacks( &hooks.flag_incr );
- }
+ {
+ flag_list.push_front( flag);
+ CallCallbacks( CB_FLAGINCR );
+ }
}
Model::Flag* Model::PopFlag()
@@ -400,8 +401,8 @@
Flag* flag = flag_list.front();
flag_list.pop_front();
- CallCallbacks( &hooks.flag_decr );
-
+ CallCallbacks( CB_FLAGDECR );
+
return flag;
}
@@ -716,13 +717,13 @@
if( FindPowerPack() )
world->active_energy.insert( this );
- CallCallbacks( &hooks.startup );
+ CallCallbacks( CB_STARTUP );
}
void Model::Shutdown( void )
{
//printf( "Shutdown model %s\n", this->token );
- CallCallbacks( &hooks.shutdown );
+ CallCallbacks( CB_SHUTDOWN );
world->active_energy.erase( this );
world->active_velocity.erase( this );
@@ -734,9 +735,8 @@
void Model::Update( void )
{
- if( hooks.attached_update )
- CallCallbacks( &hooks.update );
-
+ CallCallbacks( CB_UPDATE );
+
last_update = world->sim_time;
world->Enqueue( event_queue_num, interval, this );
}
@@ -1045,7 +1045,6 @@
void Model::SetFriction( double friction )
{
this->friction = friction;
- CallCallbacks( &this->friction );
}
Model* Model::GetChild( const std::string& modelname ) const
Modified: code/stage/trunk/libstage/model_callbacks.cc
===================================================================
--- code/stage/trunk/libstage/model_callbacks.cc 2010-03-15 17:54:04 UTC
(rev 8589)
+++ code/stage/trunk/libstage/model_callbacks.cc 2010-03-15 18:01:48 UTC
(rev 8590)
@@ -2,54 +2,33 @@
using namespace Stg;
using namespace std;
-void Model::AddCallback( void* address,
- stg_model_callback_t cb,
- void* user )
+void Model::AddCallback( callback_type_t type,
+
stg_model_callback_t cb,
+
void* user )
{
- callbacks[address].insert( stg_cb_t( cb, user ));
-
- // count the number of callbacks attached to pose and
- // velocity. These are changed very often, so we avoid looking up
- // the callbacks if these values are zero. */
- if( address == &this->pose )
- ++hooks.attached_pose;
- else if( address == &this->velocity )
- ++hooks.attached_velocity;
- else if( address == &this->hooks.update )
- ++hooks.attached_update;
+ //callbacks[address].insert( stg_cb_t( cb, user ));
+ callbacks[type].insert( stg_cb_t( cb, user ));
}
-int Model::RemoveCallback( void* address,
+int Model::RemoveCallback( callback_type_t type,
stg_model_callback_t callback )
{
- set<stg_cb_t>& callset = callbacks[address];
-
+ set<stg_cb_t>& callset = callbacks[type];
callset.erase( stg_cb_t( callback, NULL) );
- // count the number of callbacks attached to pose and velocity. Can
- // not go below zero.
- if( address == &pose )
- hooks.attached_pose = max( --hooks.attached_pose, 0 );
- else if( address == &velocity )
- hooks.attached_velocity = max( --hooks.attached_velocity, 0 );
- else if( address == &hooks.update )
- hooks.attached_update = max( --hooks.attached_update, 0 );
-
// return the number of callbacks remaining for this address. Useful
// for detecting when there are none.
return callset.size();
}
-int Model::CallCallbacks( void* address )
+int Model::CallCallbacks( callback_type_t type )
{
- assert( address );
-
// maintain a list of callbacks that should be cancelled
vector<stg_cb_t> doomed;
- set<stg_cb_t>& callset = callbacks[address];
+ set<stg_cb_t>& callset = callbacks[type];
FOR_EACH( it, callset )
{
Modified: code/stage/trunk/libstage/model_getset.cc
===================================================================
--- code/stage/trunk/libstage/model_getset.cc 2010-03-15 17:54:04 UTC (rev
8589)
+++ code/stage/trunk/libstage/model_getset.cc 2010-03-15 18:01:48 UTC (rev
8590)
@@ -14,32 +14,28 @@
MapWithChildren();
- CallCallbacks( &geom );
+ CallCallbacks( CB_GEOM );
}
void Model::SetColor( Color val )
{
color = val;
NeedRedraw();
- CallCallbacks( &color );
}
void Model::SetMass( stg_kg_t val )
{
mass = val;
- CallCallbacks( &mass );
}
void Model::SetStall( stg_bool_t val )
{
stall = val;
- CallCallbacks( &stall );
}
void Model::SetGripperReturn( int val )
{
vis.gripper_return = val;
- CallCallbacks( &vis.gripper_return );
}
void Model::SetFiducialReturn( int val )
@@ -52,80 +48,66 @@
world->FiducialErase( this );
else
world->FiducialInsert( this );
-
- CallCallbacks( &vis.fiducial_return );
}
void Model::SetFiducialKey( int val )
{
vis.fiducial_key = val;
- CallCallbacks( &vis.fiducial_key );
}
void Model::SetLaserReturn( stg_laser_return_t val )
{
vis.laser_return = val;
- CallCallbacks( &vis.laser_return );
}
void Model::SetObstacleReturn( int val )
{
vis.obstacle_return = val;
- CallCallbacks( &vis.obstacle_return );
}
void Model::SetBlobReturn( int val )
{
vis.blob_return = val;
- CallCallbacks( &vis.blob_return );
}
void Model::SetRangerReturn( int val )
{
vis.ranger_return = val;
- CallCallbacks( &vis.ranger_return );
}
void Model::SetBoundary( int val )
{
boundary = val;
- CallCallbacks( &boundary );
}
void Model::SetGuiNose( int val )
{
gui.nose = val;
- CallCallbacks( &gui.nose );
}
void Model::SetGuiMove( int val )
{
gui.move = val;
- CallCallbacks( &gui.move );
}
void Model::SetGuiGrid( int val )
{
gui.grid = val;
- CallCallbacks( &this->gui.grid );
}
void Model::SetGuiOutline( int val )
{
gui.outline = val;
- CallCallbacks( &gui.outline );
}
void Model::SetWatts( stg_watts_t val )
{
watts = val;
- CallCallbacks( &watts );
}
void Model::SetMapResolution( stg_meters_t val )
{
map_resolution = val;
- CallCallbacks( &map_resolution );
}
// set the pose of model in global coordinates
@@ -146,7 +128,7 @@
// link from the model to its new parent
this->parent = newparent;
- CallCallbacks( &this->parent );
+ CallCallbacks( CB_PARENT );
return 0; //ok
}
@@ -213,9 +195,7 @@
void Model::SetVelocity( const Velocity& val )
{
velocity = val;
-
- if( hooks.attached_velocity )
- CallCallbacks( &velocity );
+ CallCallbacks( CB_VELOCITY );
}
@@ -237,6 +217,5 @@
world->dirty = true;
}
- if( hooks.attached_pose )
- CallCallbacks( &this->pose );
+ CallCallbacks( CB_POSE );
}
Modified: code/stage/trunk/libstage/model_load.cc
===================================================================
--- code/stage/trunk/libstage/model_load.cc 2010-03-15 17:54:04 UTC (rev
8589)
+++ code/stage/trunk/libstage/model_load.cc 2010-03-15 18:01:48 UTC (rev
8590)
@@ -242,7 +242,7 @@
Subscribe();
// call any type-specific load callbacks
- this->CallCallbacks( &hooks.load );
+ this->CallCallbacks( CB_LOAD );
// we may well have changed blocks or geometry
blockgroup.CalcSize();
@@ -265,42 +265,42 @@
return;
assert( wf_entity );
-
+
PRINT_DEBUG4( "saving model %s pose %.2f %.2f %.2f",
- this->token,
- this->pose.x,
- this->pose.y,
- this->pose.a );
-
+ token,
+ pose.x,
+ pose.y,
+ pose.a );
+
// just in case
pose.a = normalize( pose.a );
geom.pose.a = normalize( geom.pose.a );
if( wf->PropertyExists( wf_entity, "pose" ) )
{
- wf->WriteTupleLength( wf_entity, "pose", 0, this->pose.x);
- wf->WriteTupleLength( wf_entity, "pose", 1, this->pose.y);
- wf->WriteTupleLength( wf_entity, "pose", 2, this->pose.z);
- wf->WriteTupleAngle( wf_entity, "pose", 3, this->pose.a );
+ wf->WriteTupleLength( wf_entity, "pose", 0, pose.x);
+ wf->WriteTupleLength( wf_entity, "pose", 1, pose.y);
+ wf->WriteTupleLength( wf_entity, "pose", 2, pose.z);
+ wf->WriteTupleAngle( wf_entity, "pose", 3, pose.a );
}
if( wf->PropertyExists( wf_entity, "size" ) )
{
- wf->WriteTupleLength( wf_entity, "size", 0, this->geom.size.x);
- wf->WriteTupleLength( wf_entity, "size", 1, this->geom.size.y);
- wf->WriteTupleLength( wf_entity, "size", 2, this->geom.size.z);
+ wf->WriteTupleLength( wf_entity, "size", 0, geom.size.x);
+ wf->WriteTupleLength( wf_entity, "size", 1, geom.size.y);
+ wf->WriteTupleLength( wf_entity, "size", 2, geom.size.z);
}
if( wf->PropertyExists( wf_entity, "origin" ) )
{
- wf->WriteTupleLength( wf_entity, "origin", 0, this->geom.pose.x);
- wf->WriteTupleLength( wf_entity, "origin", 1, this->geom.pose.y);
- wf->WriteTupleLength( wf_entity, "origin", 2, this->geom.pose.z);
- wf->WriteTupleAngle( wf_entity, "origin", 3, this->geom.pose.a);
+ wf->WriteTupleLength( wf_entity, "origin", 0, geom.pose.x);
+ wf->WriteTupleLength( wf_entity, "origin", 1, geom.pose.y);
+ wf->WriteTupleLength( wf_entity, "origin", 2, geom.pose.z);
+ wf->WriteTupleAngle( wf_entity, "origin", 3, geom.pose.a);
}
// call any type-specific save callbacks
- this->CallCallbacks( &hooks.save );
+ CallCallbacks( CB_SAVE );
PRINT_DEBUG1( "Model \"%s\" saving complete.", token );
}
@@ -345,7 +345,7 @@
}
//else
- AddCallback( &hooks.init, initfunc, new
CtrlArgs(lib,World::ctrlargs) ); // pass complete string into initfunc
+ AddCallback( CB_INIT, initfunc, new
CtrlArgs(lib,World::ctrlargs) ); // pass complete string into initfunc
}
else
{
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2010-03-15 17:54:04 UTC (rev 8589)
+++ code/stage/trunk/libstage/stage.hh 2010-03-15 18:01:48 UTC (rev 8590)
@@ -841,7 +841,6 @@
avoids searching the whole world for fiducials. */
ModelPtrVec models_with_fiducials;
-
/** Add a model to the set of models with non-zero fiducials, if not
already there. */
void FiducialInsert( Model* mod )
{
@@ -917,6 +916,7 @@
/** Remove a callback function. Any argument data passed to
AddUpdateCallback is not automatically freed. */
int RemoveUpdateCallback( stg_world_callback_t cb, void* user );
+
/** Log the state of a Model */
void Log( Model* mod );
@@ -1016,16 +1016,34 @@
Event( stg_usec_t time, Model* mod )
: time(time), mod(mod) {}
- stg_usec_t time; // time that event occurs
- Model* mod; // model to update
+ stg_usec_t time; ///< time that event occurs
+ Model* mod; ///< model to update
+ /** order by time. Break ties by value of Model*.
+ @param event to compare with this one.
*/
bool operator<( const Event& other ) const;
};
+ /** Queue of pending simulation events for the main thread to
handle. */
std::vector<std::priority_queue<Event> > event_queues;
+
+ /** Create a new simulation event to be handled in the future.
+
+ @param queue_num Specify which queue the event
should be on. The main
+ thread is 0.
+
+ @param delay The time from now until the event
occurs, in
+ microseconds.
+
+ @param mod The model that should have its
Update() method
+ called at the specified time.
+ */
void Enqueue( unsigned int queue_num, stg_usec_t delay, Model* mod );
+ /** Set of models that require energy calculations at each
World::Update(). */
std::set<Model*> active_energy;
+
+ /** Set of models that require their positions to be
recalculated at each World::Update(). */
std::set<Model*> active_velocity;
/** The amount of simulated time to run for each call to Update() */
@@ -1047,22 +1065,53 @@
virtual ~World();
+ /** Returns the current simulated time in this world, in
microseconds. */
stg_usec_t SimTimeNow(void) const { return sim_time; }
+ /** Returns a pointer to the currently-open worlddfile object,
or
+ NULL if there is none. */
Worldfile* GetWorldFile() { return wf; };
+ /** Returns true iff this World implements a GUI. The base World
+ class returns false, but subclasses can
override this
+ behaviour. */
virtual bool IsGUI() const { return false; }
+ /** Open the file at the specified location, create a Worldfile
+ object, read the file and configure the world
from the
+ contents, creating models as necessary. The
created object
+ persists, and can be retrieved later with
+ World::GetWorldFile(). */
virtual void Load( const char* worldfile_path );
+
virtual void UnLoad();
+
virtual void Reload();
+
+ /** Save the current world state into a worldfile with the given
+ filename. @param Filename to save as. */
virtual bool Save( const char* filename );
+
+ /** Run one simulation timestep. Advances the simulation clock,
+ executes all simulation updates due at the
current time, then
+ queues up future events. */
virtual bool Update(void);
+ /** Returns true iff either the local or global quit flag was
set,
+ which usually happens because someone called
Quit() or
+ QuitAll(). */
bool TestQuit() const { return( quit || quit_all ); }
+
+ /** Request the world quits simulation before the next
timestep. */
void Quit(){ quit = true; }
+
+ /** Requests all worlds quit simulation before the next
timestep. */
void QuitAll(){ quit_all = true; }
+
+ /** Cancel a local quit request. */
void CancelQuit(){ quit = false; }
+
+ /** Cancel a global quit request. */
void CancelQuitAll(){ quit_all = false; }
void TryCharge( PowerPack* pp, const Pose& pose );
@@ -1663,7 +1712,7 @@
bool alwayson;
/** If true, the model is rendered lazily into the regions, to reduce
memory use. */
- // bool background;
+ // TODO bool background;
BlockGroup blockgroup;
/** OpenGL display list identifier for the blockgroup */
@@ -1715,24 +1764,56 @@
void Draw( GLUquadric* quadric );
};
+ typedef enum {
+ CB_FLAGDECR,
+ CB_FLAGINCR,
+ CB_GEOM,
+ CB_INIT,
+ CB_LOAD,
+ CB_PARENT,
+ CB_POSE,
+ CB_SAVE,
+ CB_SHUTDOWN,
+ CB_STARTUP,
+ CB_UPDATE,
+ CB_VELOCITY,
+ //CB_POSTUPDATE,
+ __CB_TYPE_COUNT // must be the last entry: counts the
number of types
+ } callback_type_t;
+
protected:
- /** A list of callback functions can be attached to any
- address. When Model::CallCallbacks( void*) is called, the
- callbacks are called.*/
- static std::map<void*, std::set<stg_cb_t> > callbacks;
+ /** A list of callback functions can be attached to any
+ address. When Model::CallCallbacks( void*) is
called, the
+ callbacks are called.*/
+ std::vector<std::set<stg_cb_t> > callbacks;
+
/** Default color of the model's blocks.*/
Color color;
+
+ /** Model the interaction between the model's blocks and the
+ surface they touch. @todo primitive at the
moment */
double friction;
/** This can be set to indicate that the model has new data that
may be of interest to users. This allows polling the model
instead of adding a data callback. */
bool data_fresh;
- stg_bool_t disabled; ///< if non-zero, the model is disabled
+
+ /** If set true, Update() is not called on this model. Useful
+ e.g. for temporarily disabling updates when
dragging models
+ with the mouse.*/
+ stg_bool_t disabled;
+
+ /** Container for Visualizers attached to this model. */
std::list<Visualizer*> cv_list;
+
+ /** Container for flags attached to this model. */
std::list<Flag*> flag_list;
- Geom geom;
+
+ /** Specifies the the size of this model's bounding box, and the
+ offset of its local coordinate system wrt that
its parent. */
+ Geom geom;
/** Records model state and functionality in the GUI, if used */
class GuiState
@@ -1748,38 +1829,8 @@
} gui;
bool has_default_block;
+
- /* Hooks for attaching special callback functions (not used as
- variables - we just need unique addresses for them.) */
- class CallbackHooks
- {
- public:
- int flag_incr;
- int flag_decr;
- int init;
- int load;
- int save;
- int shutdown;
- int startup;
- int update;
- int update_done;
-
- /* optimization: record the number of attached callbacks for
pose
- and velocity, so we can cheaply determine
whether we need to
- call a callback for SetPose() and
SetVelocity(), which happen
- very frequently. */
- int attached_velocity;
- int attached_pose;
- int attached_update;
-
- CallbackHooks() :
- attached_velocity(0),
- attached_pose(0),
- attached_update(0)
- {}
-
- } hooks;
-
/** unique process-wide identifier for this model */
uint32_t id;
stg_usec_t interval; ///< time between updates in usec
@@ -2120,7 +2171,7 @@
void PushFlag( Flag* flag );
Flag* PopFlag();
- int GetFlagCount() const { return flag_list.size(); }
+ unsigned int GetFlagCount() const { return flag_list.size(); }
/** Disable the model. Its pose will not change due to velocity
until re-enabled using Enable(). This is used for example when
@@ -2271,65 +2322,26 @@
void SetFriction( double friction );
bool DataIsFresh() const { return this->data_fresh; }
-
- /* attach callback functions to data members. The function gets
- called when the member is changed using SetX() accessor method
*/
- void AddCallback( void* address,
- stg_model_callback_t
cb,
- void* user );
+ /* attach callback functions to data members. The function gets
+ called when the member is changed using SetX()
accessor method */
- int RemoveCallback( void* member,
-
stg_model_callback_t callback );
+ /** Add a callback. The specified function is called whenever
the
+ indicated model method is called, and passed
the user
+ data. @param cb Pointer the function to be
called. @param
+ user Pointer to arbitrary user data, passed to
the callback
+ when called.
+ */
+ void AddCallback( callback_type_t type,
+
stg_model_callback_t cb,
+
void* user );
- int CallCallbacks( void* address );
+ int RemoveCallback( callback_type_t type,
+
stg_model_callback_t callback );
- /* wrappers for the generic callback add & remove functions that hide
- some implementation detail */
-
- void AddStartupCallback( stg_model_callback_t cb, void* user )
- { AddCallback( &hooks.startup, cb, user ); };
-
- void RemoveStartupCallback( stg_model_callback_t cb )
- { RemoveCallback( &hooks.startup, cb ); };
-
- void AddShutdownCallback( stg_model_callback_t cb, void* user )
- { AddCallback( &hooks.shutdown, cb, user ); };
-
- void RemoveShutdownCallback( stg_model_callback_t cb )
- { RemoveCallback( &hooks.shutdown, cb ); }
-
- void AddLoadCallback( stg_model_callback_t cb, void* user )
- { AddCallback( &hooks.load, cb, user ); }
-
- void RemoveLoadCallback( stg_model_callback_t cb )
- { RemoveCallback( &hooks.load, cb ); }
-
- void AddSaveCallback( stg_model_callback_t cb, void* user )
- { AddCallback( &hooks.save, cb, user ); }
-
- void RemoveSaveCallback( stg_model_callback_t cb )
- { RemoveCallback( &hooks.save, cb ); }
-
- void AddUpdateCallback( stg_model_callback_t cb, void* user )
- { AddCallback( &hooks.update, cb, user ); }
-
- void RemoveUpdateCallback( stg_model_callback_t cb )
- { RemoveCallback( &hooks.update, cb ); }
-
- void AddFlagIncrCallback( stg_model_callback_t cb, void* user )
- { AddCallback( &hooks.flag_incr, cb, user ); }
-
- void RemoveFlagIncrCallback( stg_model_callback_t cb )
- { RemoveCallback( &hooks.flag_incr, cb ); }
-
- void AddFlagDecrCallback( stg_model_callback_t cb, void* user )
- { AddCallback( &hooks.flag_decr, cb, user ); }
-
- void RemoveFlagDecrCallback( stg_model_callback_t cb )
- { RemoveCallback( &hooks.flag_decr, cb ); }
-
+ int CallCallbacks( callback_type_t type );
+
virtual void Print( char* prefix ) const;
virtual const char* PrintWithPose() const;
Modified: code/stage/trunk/worlds/benchmark/expand_pioneer.cc
===================================================================
--- code/stage/trunk/worlds/benchmark/expand_pioneer.cc 2010-03-15 17:54:04 UTC
(rev 8589)
+++ code/stage/trunk/worlds/benchmark/expand_pioneer.cc 2010-03-15 18:01:48 UTC
(rev 8590)
@@ -43,7 +43,7 @@
assert( robot->ranger );
// ask Stage to call into our ranger update function
- robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot
);
+ robot->ranger->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)RangerUpdate, robot );
// subscribe to the laser, though we don't use it for navigating
//robot->laser = (ModelLaser*)mod->GetUnusedModelOfType( "laser" );
Modified: code/stage/trunk/worlds/benchmark/expand_swarm.cc
===================================================================
--- code/stage/trunk/worlds/benchmark/expand_swarm.cc 2010-03-15 17:54:04 UTC
(rev 8589)
+++ code/stage/trunk/worlds/benchmark/expand_swarm.cc 2010-03-15 18:01:48 UTC
(rev 8590)
@@ -42,7 +42,7 @@
// ask Stage to call into our ranger update function
- robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot
);
+ robot->ranger->AddCallback( Model::CB_UPDATE,
(stg_model_callback_t)RangerUpdate, robot );
// subscribe to the laser, though we don't use it for navigating
//robot->laser = (ModelLaser*)mod->GetUnusedModelofType( "laser" );
Modified: code/stage/trunk/worlds/pioneer_flocking.world
===================================================================
--- code/stage/trunk/worlds/pioneer_flocking.world 2010-03-15 17:54:04 UTC
(rev 8589)
+++ code/stage/trunk/worlds/pioneer_flocking.world 2010-03-15 18:01:48 UTC
(rev 8590)
@@ -29,9 +29,9 @@
floorplan
(
name "cave"
-# size [100.000 100.000 0.800]
- size [32.000 32.000 0.600]
-pose [-24 -16 0 0]
+ size [100.000 100.000 0.800]
+# size [32.000 32.000 0.600]
+# pose [-24 -16 0 0]
bitmap "bitmaps/cave.png"
)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit