Update of /cvsroot/playerstage/code/stage/libstage
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23085

Modified Files:
        Makefile ctrl.cc main.cc model.cc model_load.cc stage.hh 
Log Message:
refined inline controller implementation

Index: model.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/libstage/model.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** model.cc    20 Feb 2008 06:03:58 -0000      1.5
--- model.cc    21 Feb 2008 03:35:05 -0000      1.6
***************
*** 217,221 ****
    
    this->initfunc = NULL;
!   this->updatefunc = NULL;
  
    // now we can add the basic square shape
--- 217,221 ----
    
    this->initfunc = NULL;
!   //this->updatefunc = NULL;
  
    // now we can add the basic square shape
***************
*** 243,247 ****
  void StgModel::Init()
  {
!   if( initfunc && updatefunc )
      Subscribe();
    
--- 243,247 ----
  void StgModel::Init()
  {
!   if( initfunc )
      Subscribe();
    
***************
*** 678,683 ****
    
    //puts( "UPDATE" );
!   if( updatefunc )
!     updatefunc( this );
    
    CallCallbacks( &update );
--- 678,683 ----
    
    //puts( "UPDATE" );
!  //  if( updatefunc )
! //     updatefunc( this );
    
    CallCallbacks( &update );
***************
*** 1444,1445 ****
--- 1444,1461 ----
    return NULL;
  }
+ 
+ StgModel* StgModel::GetModel( const char* modelname )
+ {
+   // construct the full model name and look it up
+   char* buf = new char[TOKEN_MAX];
+   snprintf( buf, TOKEN_MAX, "%s.%s", this->token, modelname );
+   
+   StgModel* mod = world->GetModel( buf );
+   
+   if( mod == NULL )
+     PRINT_WARN1( "Model %s not found", buf );
+   
+   delete[] buf;
+ 
+   return mod;
+ }

Index: ctrl.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/libstage/ctrl.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ctrl.cc     20 Feb 2008 06:03:58 -0000      1.1
--- ctrl.cc     21 Feb 2008 03:35:05 -0000      1.2
***************
*** 2,29 ****
  using namespace Stg;
    
! extern "C" void Init( StgModel* mod );
! extern "C" void Update( StgModel* mod );
! 
! StgModelPosition* pos = NULL;
! StgModelLaser* laser = NULL;
  
  
! // Stage calls this once when the model starts up
! void Init( StgModel* mod )
  {
    puts( "Init controller" );
    
!   pos = (StgModelPosition*)mod;
   
!   laser = (StgModelLaser*)mod->GetUnsubscribedModelOfType( "laser" );
!   assert( laser );
!   laser->Subscribe();
  }
  
! // Stage calls this once per simulation update
! void Update( StgModel* mod )
  {
!  
!   pos->SetSpeed( 0.1, 0, 0.1 );  
  }
  
--- 2,47 ----
  using namespace Stg;
    
! typedef struct
! {
!   StgModelPosition* pos;
!   StgModelLaser* laser;
! } robot_t;
  
+ int LaserUpdate( StgModel* mod, robot_t* robot );
+ int PositionUpdate( StgModel* mod, robot_t* robot );
  
! // Stage calls this when the model starts up
! extern "C" int Init( StgModel* mod )
  {
    puts( "Init controller" );
    
!   robot_t* robot = new robot_t;
   
!   robot->pos = (StgModelPosition*)mod;
!   robot->laser = (StgModelLaser*)mod->GetModel( "laser:0" );
!   
!   assert( robot->laser );
!   robot->laser->Subscribe();
!   
!   robot->laser->AddUpdateCallback( (stg_model_callback_t)LaserUpdate, robot );
!   robot->pos->AddUpdateCallback( (stg_model_callback_t)PositionUpdate, robot 
);
! 
!   return 0; //ok
  }
  
! int LaserUpdate( StgModel* mod, robot_t* robot )
  {
!   robot->pos->SetSpeed( 0.1, 0, 0.1 );  
!   return FALSE; // run again
! }
! 
! int PositionUpdate( StgModel* mod, robot_t* robot )
! {
!   stg_pose_t pose = robot->pos->GetPose();
! 
!   printf( "Pose: [%.2f %.2f %.2f %.2f]\n",
!         pose.x, pose.y, pose.z, pose.a );
! 
!   return FALSE; // run again
  }
  

Index: main.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/libstage/main.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** main.cc     20 Feb 2008 06:03:58 -0000      1.1
--- main.cc     21 Feb 2008 03:35:05 -0000      1.2
***************
*** 4,8 ****
  int main( int argc, char* argv[] )
  {
!   printf( %s %s\n", PACKAGE, VERSION );
    
    if( argc < 2 )
--- 4,8 ----
  int main( int argc, char* argv[] )
  {
!   printf( "%s %s\n", PACKAGE, VERSION );
    
    if( argc < 2 )


Index: model_load.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/libstage/model_load.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** model_load.cc       20 Feb 2008 06:03:58 -0000      1.4
--- model_load.cc       21 Feb 2008 03:35:05 -0000      1.5
***************
*** 397,406 ****
    assert( this->initfunc );
    
!   this->updatefunc = (ctrlupdate_t*)lt_dlsym( handle, "Update" );
!   if( this->updatefunc  == NULL )
!     {
!       puts( lt_dlerror() );         
!     }
!   assert( this->updatefunc );
    
    //this->Subscribe(); // causes the model to startup and update
--- 397,406 ----
    assert( this->initfunc );
    
! //   this->updatefunc = (ctrlupdate_t*)lt_dlsym( handle, "Update" );
! //   if( this->updatefunc  == NULL )
! //     {
! //       puts( lt_dlerror() );              
! //     }
! //   assert( this->updatefunc );
    
    //this->Subscribe(); // causes the model to startup and update

Index: stage.hh
===================================================================
RCS file: /cvsroot/playerstage/code/stage/libstage/stage.hh,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** stage.hh    20 Feb 2008 06:03:58 -0000      1.7
--- stage.hh    21 Feb 2008 03:35:05 -0000      1.8
***************
*** 1067,1072 ****
    } stg_trail_item_t;
    
!   typedef void ctrlinit_t( StgModel* mod );
!   typedef void ctrlupdate_t( StgModel* mod );
  
    // MODEL CLASS
--- 1067,1072 ----
    } stg_trail_item_t;
    
!   typedef int ctrlinit_t( StgModel* mod );
!   //typedef void ctrlupdate_t( StgModel* mod );
  
    // MODEL CLASS
***************
*** 1224,1228 ****
      
      ctrlinit_t* initfunc;
!     ctrlupdate_t* updatefunc;
  
    public:
--- 1224,1228 ----
      
      ctrlinit_t* initfunc;
!     //ctrlupdate_t* updatefunc;
  
    public:
***************
*** 1278,1281 ****
--- 1278,1282 ----
      const char* TypeStr(){ return this->typestr; }
      StgModel* Parent(){ return this->parent; }
+     StgModel* GetModel( const char* name );
      bool Stall(){ return this->stall; }
      int GuiMask(){ return this->gui_mask; };  


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to