Revision: 8029
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8029&view=rev
Author:   rtv
Date:     2009-07-16 03:25:18 +0000 (Thu, 16 Jul 2009)

Log Message:
-----------
more STLing

Modified Paths:
--------------
    code/stage/trunk/libstage/CMakeLists.txt
    code/stage/trunk/libstage/canvas.cc
    code/stage/trunk/libstage/canvas.hh
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/model_draw.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc
    code/stage/trunk/worlds/fasr.world

Removed Paths:
-------------
    code/stage/trunk/libstage/glcolorstack.cc

Modified: code/stage/trunk/libstage/CMakeLists.txt
===================================================================
--- code/stage/trunk/libstage/CMakeLists.txt    2009-07-16 01:10:16 UTC (rev 
8028)
+++ code/stage/trunk/libstage/CMakeLists.txt    2009-07-16 03:25:18 UTC (rev 
8029)
@@ -12,7 +12,6 @@
        file_manager.cc
        file_manager.hh
        gl.cc
-       glcolorstack.cc
        logentry.cc
        model.cc
        model_actuator.cc

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2009-07-16 01:10:16 UTC (rev 8028)
+++ code/stage/trunk/libstage/canvas.cc 2009-07-16 03:25:18 UTC (rev 8029)
@@ -18,6 +18,8 @@
 #include <string>
 #include <sstream>
 #include <png.h>
+#include <algorithm>
+#include <functional>      // For greater<int>( )
 
 #include "region.hh"
 #include "file_manager.hh"
@@ -52,7 +54,7 @@
                                                         int width, int height) 
:
   Fl_Gl_Window( x, y, width, height ),
   colorstack(),  
-  models_sorted( NULL ),
+  models_sorted(),
   current_camera( NULL ),
   camera(),
   perspective_camera(),
@@ -60,7 +62,7 @@
   wf( NULL ),
   startx( -1 ),
   starty( -1 ),
-  selected_models( NULL ),
+  selected_models(),
   last_selection( NULL ),
   interval(  50 ), //msec between redraws
   // initialize Option objects
@@ -264,44 +266,34 @@
   return mod;
 }
 
-bool Canvas::selected( Model* mod ) {
-  if( g_list_find( selected_models, mod ) )
-        return true;
-  else
-        return false;
+bool Canvas::selected( Model* mod ) 
+{
+  return( std::find( selected_models.begin(), selected_models.end(), mod ) != 
selected_models.end() );
 }
 
 void Canvas::select( Model* mod ) {
   if( mod )
     {
                last_selection = mod;
-               selected_models = g_list_prepend( selected_models, mod );
+               selected_models.push_front( mod );
                
                //              mod->Disable();
                redraw();
     }
 }
 
-void Canvas::unSelect( Model* mod ) {
+void Canvas::unSelect( Model* mod ) 
+{
   if( mod )
         {
-               if ( GList* link = g_list_find( selected_models, mod ) ) 
-                 {
-                        // remove it from the selected list
-                        selected_models = 
-                               g_list_remove_link( selected_models, link );
-                        //                     mod->Enable();
-                        redraw();
-                 }
-        }  
+               selected_models.erase( std::remove( selected_models.begin(), 
selected_models.end(), mod ));
+               redraw();
+        }
 }
 
-void Canvas::unSelectAll() { 
-  //   for( GList* it=selected_models; it; it=it->next )
-  //           ((Model*)it->data)->Enable();
-       
-  g_list_free( selected_models );
-  selected_models = NULL;
+void Canvas::unSelectAll() 
+{ 
+  selected_models.clear();
 }
 
 // convert from 2d window pixel to 3d world coordinates
@@ -470,9 +462,9 @@
                                CanvasToWorld( Fl::event_x(), Fl::event_y(),
                                                                        &x, &y, 
&z );
                                // move all selected models to the mouse pointer
-                               for( GList* it = selected_models; it; 
it=it->next )
+                               FOR_EACH( it, selected_models )
                                  {
-                                        Model* mod = (Model*)it->data;
+                                        Model* mod = *it;
                                         mod->AddToPose( x-sx, y-sy, 0, 0 );
                                  }
                         }
@@ -490,9 +482,9 @@
                  }
                  else if ( Fl::event_state( FL_BUTTON3 ) || ( Fl::event_state( 
FL_BUTTON1 ) &&  Fl::event_state( FL_CTRL )  ) ) {
                         // rotate all selected models
-                        for( GList* it = selected_models; it; it=it->next )
+                        FOR_EACH( it, selected_models )
                                {
-                                 Model* mod = (Model*)it->data;
+                                 Model* mod = *it;
                                  mod->AddToPose( 0,0,0, 0.05*(dx+dy) );
                                }
                  }
@@ -561,13 +553,13 @@
 
 void Canvas::AddModel( Model*  mod  )
 {
-  models_sorted = g_list_append( models_sorted, mod );
+  models_sorted.push_back( mod );
 }
 
 void Canvas::RemoveModel( Model*  mod  )
 {
   printf( "removing model %s from canvas list\n", mod->Token() );
-  models_sorted = g_list_remove( models_sorted, mod );
+  models_sorted.erase( std::remove( models_sorted.begin(), 
models_sorted.end(), mod ));
 }
 
 void Canvas::DrawGlobalGrid()
@@ -664,8 +656,9 @@
 
 void Canvas::DrawBlocks() 
 {
-  LISTMETHOD( models_sorted, Model*, DrawBlocksTree );
-  
+  FOR_EACH( it, models_sorted )
+        (*it)->DrawBlocksTree();
+
   // some models may be carried by others - this prevents them being drawn 
twice
 //   for( GList* it = models_sorted; it; it=it->next )
 //      {
@@ -722,27 +715,29 @@
   //TODO reset perspective cam
 }
 
-// used to sort a list of models by inverse distance from the x,y pose in 
[coords]
-gint compare_distance( Model* a, Model* b, double coords[2] )
+
+class DistFuncObj
 {
-  Pose a_pose = a->GetGlobalPose();
-  Pose b_pose = b->GetGlobalPose();
+  stg_meters_t x, y;
+  DistFuncObj( stg_meters_t x, stg_meters_t y ) 
+  : x(x), y(y) {}
   
-  double a_dist = hypot( coords[1] - a_pose.y,
-                                                                coords[0] - 
a_pose.x );
-  
-  double b_dist = hypot( coords[1] - b_pose.y,
-                                                                coords[0] - 
b_pose.x );
-  
-  if( a_dist < b_dist )
-        return 1;
+  bool operator()(const Model* a, const Model* b ) const
+  { 
+        Pose a_pose = a->GetGlobalPose();
+        Pose b_pose = b->GetGlobalPose();
+        
+        stg_meters_t a_dist = hypot( y - a_pose.y,
+                                                                               
        x - a_pose.x );
+        
+        stg_meters_t b_dist = hypot( y - b_pose.y,
+                                                                               
        x - b_pose.x );
+        
+        return (  a_dist < b_dist );
+  }
+};
 
-  if( a_dist > b_dist )
-        return -1;
 
-  return 0; // must be the same
-}
-
 void Canvas::renderFrame()
 {
   //before drawing, order all models based on distance from camera
@@ -754,15 +749,19 @@
   x += -sin( sphi ) * 100;
   y += -cos( sphi ) * 100;
        
-  double coords[2];
-  coords[0] = x;
-  coords[1] = y;
+  //double coords[2];
+  //coords[0] = x;
+  //coords[1] = y;
   
   // sort the list of models by inverse distance from the camera -
   // probably doesn't change too much between frames so this is
   // usually fast
-  models_sorted = g_list_sort_with_data( models_sorted, 
(GCompareDataFunc)compare_distance, coords );
+  // TODO
+  //models_sorted = g_list_sort_with_data( models_sorted, 
(GCompareDataFunc)compare_distance, coords );
   
+  // TODO: understand why this doesn't work and fix it - just cosmetic but 
important!
+  //std::sort( models_sorted.begin(), models_sorted.end(), DistFuncObj(x,y) );
+
   glEnable( GL_DEPTH_TEST );
 
   if( ! showTrails )
@@ -886,7 +885,10 @@
   if( showFootprints )
         {
                glDisable( GL_DEPTH_TEST );             
-               LISTMETHOD( models_sorted, Model*, DrawTrailFootprint );
+
+               FOR_EACH( it, models_sorted )
+                 (*it)->DrawTrailFootprint();
+
                glEnable( GL_DEPTH_TEST );
         }
   
@@ -1000,8 +1002,8 @@
 //     }
 
 
-  for( GList* it=selected_models; it; it=it->next )
-        ((Model*)it->data)->DrawSelected();
+  FOR_EACH( it, selected_models )
+        (*it)->DrawSelected();
 
   // useful debug - puts a point at the origin of each model
   //for( GList* it = world->World::children; it; it=it->next ) 
@@ -1013,7 +1015,7 @@
                FOR_EACH( it, world->World::children )
                  (*it)->DataVisualizeTree( current_camera );
         }
-        else if ( selected_models ) {
+        else if ( selected_models.size() > 0 ) {
                FOR_EACH( it, world->World::children )
                  (*it)->DataVisualizeTree( current_camera );
         }
@@ -1023,14 +1025,17 @@
   }
    
   if( showGrid ) 
-        LISTMETHOD( models_sorted, Model*, DrawGrid );
-                 
+        FOR_EACH( it, models_sorted )
+               (*it)->DrawGrid();
+                 
   if( showFlags ) 
-        LISTMETHOD( models_sorted, Model*, DrawFlagList );
-                       
+        FOR_EACH( it, models_sorted )
+               (*it)->DrawFlagList();
+
   if( showBlinken ) 
-        LISTMETHOD( models_sorted, Model*, DrawBlinkenlights );
-  
+        FOR_EACH( it, models_sorted )
+               (*it)->DrawBlinkenlights();
+
   if( showStatus ) 
         {
       glDisable( GL_DEPTH_TEST );
@@ -1039,20 +1044,21 @@
                //ensure two icons can't be in the exact same plane
                if( camera.pitch() == 0 && !pCamOn )
                  glTranslatef( 0, 0, 0.1 );
-       
-               LISTMETHODARG( models_sorted, Model*, DrawStatusTree, &camera );
                
+               FOR_EACH( it, models_sorted )
+                 (*it)->DrawStatusTree( &camera );
+               
       glEnable( GL_DEPTH_TEST );
                glPopMatrix();
         }
   
-  if( world->GetRayList() )
+  if( world->ray_list.size() > 0 )
     {
       glDisable( GL_DEPTH_TEST );
       PushColor( 0,0,0,0.5 );
-      for( GList* it = world->GetRayList(); it; it=it->next )
+               FOR_EACH( it, world->ray_list )
                  {
-                        float* pts = (float*)it->data;
+                        float* pts = *it;
                         glBegin( GL_LINES );
                         glVertex2f( pts[0], pts[1] );
                         glVertex2f( pts[2], pts[3] );

Modified: code/stage/trunk/libstage/canvas.hh
===================================================================
--- code/stage/trunk/libstage/canvas.hh 2009-07-16 01:10:16 UTC (rev 8028)
+++ code/stage/trunk/libstage/canvas.hh 2009-07-16 03:25:18 UTC (rev 8029)
@@ -3,144 +3,157 @@
 #include "option.hh"
 
 #include <map>
+#include <stack>
 
 namespace Stg
 {
-// COLOR STACK CLASS
-class GlColorStack
-{
-       public:
-               GlColorStack();
-               ~GlColorStack();
+  class Canvas : public Fl_Gl_Window
+  {
+        friend class WorldGui; // allow access to private members
+        friend class Model;
+  
+  private:
 
-               void Push( GLdouble col[4] );
-               void Push( double r, double g, double b, double a );
-               void Push( double r, double g, double b );
-               void Push( Color col );
-
-               void Pop();
-
+        class GlColorStack
+        {
+        public:
+               GlColorStack() : colorstack() {}
+               ~GlColorStack() {}
+               
+               void Push( double r, double g, double b, double a=1.0 )
+               {
+                 Push( Color(r,g,b,a) );
+               }
+               
+               void Push( Color col )
+               {
+                 colorstack.push( col );               
+                 glColor4f( col.r, col.g, col.b, col.a );
+               }
+               
+               void Pop()
+               {
+                 if( colorstack.size() < 1 )
+                        PRINT_WARN1( "Attempted to ColorStack.Pop() but 
ColorStack %p is empty",
+                                                         this );
+                 else
+                        {
+                               Color& old = colorstack.top();
+                               colorstack.pop();
+                               glColor4f( old.r,  old.g,  old.b,  old.a ); 
+                        }
+               }
+               
                unsigned int Length()
-               { return g_queue_get_length( colorstack ); }
-
-       private:
-               GQueue* colorstack;
-};
-
-
-class Canvas : public Fl_Gl_Window
-{
-       friend class WorldGui; // allow access to private members
-       friend class Model;
+               { return colorstack.size(); }
+               
+        private:
+               std::stack<Color> colorstack;
+        } colorstack;
+        
+        std::list<Model*> models_sorted;
   
-private:
-       GlColorStack colorstack;
+        Camera* current_camera;
+        OrthoCamera camera;
+        PerspectiveCamera perspective_camera;
+        bool dirty_buffer;
+        Worldfile* wf;
 
-   GList* models_sorted;
+        int startx, starty;
+        bool selectedModel;
+        bool clicked_empty_space;
+        int empty_space_startx, empty_space_starty;
+        std::list<Model*> selected_models;
+        Model* last_selection; ///< the most recently selected model
+        ///(even if it is now unselected).
 
-       Camera* current_camera;
-       OrthoCamera camera;
-       PerspectiveCamera perspective_camera;
-       bool dirty_buffer;
-       Worldfile* wf;
+        stg_msec_t interval; // window refresh interval in ms
 
-       int startx, starty;
-       bool selectedModel;
-       bool clicked_empty_space;
-       int empty_space_startx, empty_space_starty;
-       GList* selected_models; ///< a list of models that are currently
-       ///selected by the user
-       Model* last_selection; ///< the most recently selected model
-       ///(even if it is now unselected).
-
-       stg_msec_t interval; // window refresh interval in ms
-
-       GList* ray_list;
-       void RecordRay( double x1, double y1, double x2, double y2 );
-       void DrawRays();
-       void ClearRays();
-       void DrawGlobalGrid();
+        void RecordRay( double x1, double y1, double x2, double y2 );
+        void DrawRays();
+        void ClearRays();
+        void DrawGlobalGrid();
   
-  void AddModel( Model* mod );
-  void RemoveModel( Model* mod );
+        void AddModel( Model* mod );
+        void RemoveModel( Model* mod );
 
-  Option showBlinken, 
-        showBlocks, 
-        showClock, 
-        showData, 
-        showFlags,
-        showFollow,
-        showFootprints, 
-        showGrid, 
-        showOccupancy, 
-        showScreenshots,
-        showStatus,
-        showTrailArrows, 
-        showTrailRise, 
-        showTrails, 
-        showTree,
-        showBBoxes,
-        showBlur,
-        pCamOn,
-        visualizeAll;
+        Option showBlinken, 
+               showBlocks, 
+               showClock, 
+               showData, 
+               showFlags,
+               showFollow,
+               showFootprints, 
+               showGrid, 
+               showOccupancy, 
+               showScreenshots,
+               showStatus,
+               showTrailArrows, 
+               showTrailRise, 
+               showTrails, 
+               showTree,
+               showBBoxes,
+               showBlur,
+               pCamOn,
+               visualizeAll;
   
-public:
-  Canvas( WorldGui* world, int x, int y, int width, int height);
-       ~Canvas();
+  public:
+        Canvas( WorldGui* world, int x, int y, int width, int height);
+        ~Canvas();
   
-  bool graphics;
-  WorldGui* world;
-  unsigned long frames_rendered_count;
-  int screenshot_frame_skip;
+        bool graphics;
+        WorldGui* world;
+        unsigned long frames_rendered_count;
+        int screenshot_frame_skip;
   
-  std::map< std::string, Option* > _custom_options;
+        std::map< std::string, Option* > _custom_options;
 
-       void Screenshot();
-  void InitGl();
-       void createMenuItems( Fl_Menu_Bar* menu, std::string path );
+        void Screenshot();
+        void InitGl();
+        void createMenuItems( Fl_Menu_Bar* menu, std::string path );
   
-       void FixViewport(int W,int H);
-       void DrawFloor(); //simpler floor compared to grid
-       void DrawBlocks();
-  void DrawBoundingBoxes();
-       void resetCamera();
-       virtual void renderFrame();
-       virtual void draw();
-       virtual int handle( int event );
-       void resize(int X,int Y,int W,int H);
+        void FixViewport(int W,int H);
+        void DrawFloor(); //simpler floor compared to grid
+        void DrawBlocks();
+        void DrawBoundingBoxes();
+        void resetCamera();
+        virtual void renderFrame();
+        virtual void draw();
+        virtual int handle( int event );
+        void resize(int X,int Y,int W,int H);
 
-       void CanvasToWorld( int px, int py, 
-                       double *wx, double *wy, double* wz );
+        void CanvasToWorld( int px, int py, 
+                                                               double *wx, 
double *wy, double* wz );
 
-       Model* getModel( int x, int y );
-       bool selected( Model* mod );
-       void select( Model* mod );
-       void unSelect( Model* mod );
-       void unSelectAll();
+        Model* getModel( int x, int y );
+        bool selected( Model* mod );
+        void select( Model* mod );
+        void unSelect( Model* mod );
+        void unSelectAll();
 
-       inline void setDirtyBuffer( void ) { dirty_buffer = true; }
-       inline bool dirtyBuffer( void ) const { return dirty_buffer; }
+        inline void setDirtyBuffer( void ) { dirty_buffer = true; }
+        inline bool dirtyBuffer( void ) const { return dirty_buffer; }
        
-       inline void PushColor( Color col )
-       { colorstack.Push( col ); } 
+        inline void PushColor( Color col )
+        { colorstack.Push( col ); } 
 
-       void PushColor( double r, double g, double b, double a )
-       { colorstack.Push( r,g,b,a ); }
+        void PushColor( double r, double g, double b, double a )
+        { colorstack.Push( r,g,b,a ); }
 
-       void PopColor(){ colorstack.Pop(); } 
+        void PopColor(){ colorstack.Pop(); } 
   
-  void InvertView( uint32_t invertflags );
+        void InvertView( uint32_t invertflags );
 
-  bool VisualizeAll(){ return ! visualizeAll; }
+        bool VisualizeAll(){ return ! visualizeAll; }
   
-  static void TimerCallback( Canvas* canvas );
-  static void perspectiveCb( Fl_Widget* w, void* p );
+        static void TimerCallback( Canvas* canvas );
+        static void perspectiveCb( Fl_Widget* w, void* p );
   
-  void EnterScreenCS();
-  void LeaveScreenCS();
+        void EnterScreenCS();
+        void LeaveScreenCS();
 
-  void Load( Worldfile* wf, int section );
-  void Save( Worldfile* wf, int section );
-};
+        void Load( Worldfile* wf, int section );
+        void Save( Worldfile* wf, int section );
+  };
 
 } // namespace Stg

Deleted: code/stage/trunk/libstage/glcolorstack.cc
===================================================================
--- code/stage/trunk/libstage/glcolorstack.cc   2009-07-16 01:10:16 UTC (rev 
8028)
+++ code/stage/trunk/libstage/glcolorstack.cc   2009-07-16 03:25:18 UTC (rev 
8029)
@@ -1,74 +0,0 @@
-#include "canvas.hh"
-
-using namespace Stg;
-
-GlColorStack::GlColorStack()
-{
-       colorstack = g_queue_new();
-}
-
-GlColorStack::~GlColorStack()
-{
-}
-
-void GlColorStack::Push( GLdouble col[4] )
-{
-  GLdouble *keep = new GLdouble[4];
-  memcpy( keep, col, 4*sizeof(GLdouble) );
-
-       g_queue_push_head( colorstack, keep );
-
-       // and select this color in GL
-       glColor4dv( col );
-}
-
-
-void GlColorStack::Push( double r, double g, double b )
-{
-       GLdouble col[4];
-       col[0] = r;
-       col[1] = g;
-       col[2] = b;
-       col[3] = 1.0;
-
-       Push( col );
-}
-
-// a convenience wrapper around push_color()
-void GlColorStack::Push( double r, double g, double b, double a )
-{
-       GLdouble col[4];
-       col[0] = r;
-       col[1] = g;
-       col[2] = b;
-       col[3] = a;
-
-       Push( col );
-}
-
-void GlColorStack::Push( Color col )
-{
-       GLdouble d[4];
-
-       d[0] = col.r;
-       d[1] = col.g;
-       d[2] = col.b;
-       d[3] = col.a;
-
-       Push( d );
-}
-
-
-// reset GL to the color we stored using store_color()
-void GlColorStack::Pop( void )
-{
-       if( g_queue_is_empty( colorstack ) )
-               PRINT_WARN1( "Attempted to ColorStack.Pop() but ColorStack %p 
is empty",
-                               this );
-       else
-       {
-               GLdouble *col = (GLdouble*)g_queue_pop_head( colorstack );
-               glColor4dv( col );
-               delete[] col;
-       }
-}

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2009-07-16 01:10:16 UTC (rev 8028)
+++ code/stage/trunk/libstage/model.cc  2009-07-16 03:25:18 UTC (rev 8029)
@@ -201,7 +201,7 @@
     color( 1,0,0 ), // red
     data_fresh(false),
     disabled(false),
-        custom_visual_list( NULL ),
+        cv_list(),
     flag_list(),
     geom(),
     has_default_block( true ),
@@ -216,7 +216,7 @@
     parent(parent),
     pose(),
        power_pack( NULL ),
-       pps_charging(NULL),
+       pps_charging(),
     props(NULL),
        rastervis(),
     rebuild_displaylist(true),
@@ -479,16 +479,6 @@
                   ztest );
 }
 
-// utility for g_free()ing everything in a list
-void list_gfree( GList* list )
-{
-  // free all the data in the list
-  LISTFUNCTION( list, gpointer, g_free );
-
-  // free the list elements themselves
-  g_list_free( list );
-}
-
 // convert a global pose into the model's local coordinate system
 Pose Model::GlobalToLocal( const Pose& pose ) const
 {
@@ -805,22 +795,15 @@
   assert( mypp );
   
   // detach charger from all the packs charged last time
-  for( GList* it = pps_charging; it; it = it->next )
-        ((PowerPack*)it->data)->ChargeStop();
-  g_list_free( pps_charging );
-  pps_charging = NULL;
-  
+  FOR_EACH( it, pps_charging )
+        (*it)->ChargeStop();
+  pps_charging.clear();
+
   // run through and update all appropriate touchers
   ModelPtrSet touchers;
   AppendTouchingModels( touchers );
 
-  //  for( GList* touchers = AppendTouchingModels( NULL );
-  //    touchers;
-  //    touchers = touchers->next )
   FOR_EACH( it, touchers )
-//   for( GList* touchers = AppendTouchingModels( NULL );
-//              touchers;
-//              touchers = touchers->next )
         {
           Model* toucher = (*it); //(Model*)touchers->data;            
                PowerPack* hispp =toucher->FindPowerPack();             
@@ -843,7 +826,7 @@
                         mypp->TransferTo( hispp, amount );
                         
                         // remember who we are charging so we can detatch next 
time
-                        pps_charging = g_list_prepend( pps_charging, hispp );
+                        pps_charging.push_front( hispp );
                  }
         }
 }
@@ -1072,7 +1055,7 @@
         height(0),
         cellwidth(0),
         cellheight(0),
-        pts(NULL)
+        pts()
 {
 }
 
@@ -1088,7 +1071,7 @@
   Gl::pose_inverse_shift( mod->GetGlobalPose() );
 
   
-  if( pts )
+  if( pts.size() > 0 )
         {
                glPushMatrix();
                Size sz = mod->blockgroup.GetSize();
@@ -1098,15 +1081,15 @@
                // now we're in world meters coordinates
                glPointSize( 4 );
                glBegin( GL_POINTS );
-               for( GList* it=pts; it; it=it->next )
+               
+               FOR_EACH( it, pts )
                  {
-                        stg_point_t* pt = (stg_point_t*)it->data;
-                        assert( pt );
-                        glVertex2f( pt->x, pt->y );
+                        stg_point_t& pt = *it;
+                        glVertex2f( pt.x, pt.y );
                         
                         char buf[128];
-                        snprintf( buf, 127, "[%.2f x %.2f]", pt->x, pt->y );
-                        Gl::draw_string( pt->x, pt->y, 0, buf );               
  
+                        snprintf( buf, 127, "[%.2f x %.2f]", pt.x, pt.y );
+                        Gl::draw_string( pt.x, pt.y, 0, buf );           
                  }
                glEnd();
                
@@ -1185,16 +1168,10 @@
 
 void Model::RasterVis::AddPoint( stg_meters_t x, stg_meters_t y )
 {
-  pts = g_list_prepend( pts, new stg_point_t( x, y ) );
+  pts.push_back( stg_point_t( x, y ) );
 }
 
 void Model::RasterVis::ClearPts()
 {
-  if( pts )
-        for( GList* it=pts; it; it=it->next )
-               if( it->data )
-                 delete (stg_point_t*)it->data;
-
-  g_list_free( pts );
-  pts = NULL;
+  pts.clear();
 }

Modified: code/stage/trunk/libstage/model_draw.cc
===================================================================
--- code/stage/trunk/libstage/model_draw.cc     2009-07-16 01:10:16 UTC (rev 
8028)
+++ code/stage/trunk/libstage/model_draw.cc     2009-07-16 03:25:18 UTC (rev 
8029)
@@ -253,9 +253,9 @@
   glPopMatrix();
 }
 
-void Model::AddVisualizer( Visualizer* custom_visual, bool on_by_default )
+void Model::AddVisualizer( Visualizer* cv, bool on_by_default )
 {
-  if( !custom_visual )
+  if( !cv )
         return;
   
   // If there's no GUI, ignore this request
@@ -263,27 +263,29 @@
         return;
        
        //save visual instance
-       custom_visual_list = g_list_append(custom_visual_list, custom_visual );
+       //cv_list = g_list_append(cv_list, cv );
+  cv_list.push_back( cv );
 
        //register option for all instances which share the same name
        Canvas* canvas = world_gui->GetCanvas();
-       std::map< std::string, Option* >::iterator i = 
canvas->_custom_options.find( custom_visual->GetMenuName() );
+       std::map< std::string, Option* >::iterator i = 
canvas->_custom_options.find( cv->GetMenuName() );
        if( i == canvas->_custom_options.end() ) {
-         Option* op = new Option( custom_visual->GetMenuName(), 
-                                                                               
custom_visual->GetWorldfileName(), 
+         Option* op = new Option( cv->GetMenuName(), 
+                                                                               
cv->GetWorldfileName(), 
                                                                                
"", 
                                                                                
on_by_default, 
                                                                                
world_gui );
-               canvas->_custom_options[ custom_visual->GetMenuName() ] = op;
+               canvas->_custom_options[ cv->GetMenuName() ] = op;
                RegisterOption( op );
        }
 }
 
-void Model::RemoveVisualizer( Visualizer* custom_visual )
+void Model::RemoveVisualizer( Visualizer* cv )
 {
-       if( custom_visual )
-               custom_visual_list = g_list_remove(custom_visual_list, 
custom_visual );
+  if( cv )
+         cv_list.erase( remove( cv_list.begin(), cv_list.end(), cv ));
 
+
        //TODO unregister option - tricky because there might still be 
instances attached to different models which have the same name
 }
 
@@ -450,7 +452,6 @@
   Pose gpose = GetGlobalPose();
   glRotatef( 180 + rtod(-gpose.a),0,0,1 );
   
-  
   for( std::list<Flag*>::reverse_iterator it( flag_list.rbegin()); 
                 it != flag_list.rend(); 
                 it++ )
@@ -529,13 +530,15 @@
   PushLocalCoords();
   DataVisualize( cam ); // virtual function overridden by most model types  
 
-  Visualizer* vis;
-  for( GList* item = custom_visual_list; item; item = item->next ) {
-    vis = static_cast<Visualizer* >( item->data );
-       if( world_gui->GetCanvas()->_custom_options[ vis->GetMenuName() 
]->isEnabled() )
-         vis->Visualize( this, cam );
-  }
-
+  for( std::list<Visualizer*>::iterator it = cv_list.begin();
+                it != cv_list.end();
+                it++ )
+        {
+      Visualizer* vis = *it;
+               if( world_gui->GetCanvas()->_custom_options[ vis->GetMenuName() 
]->isEnabled() )
+                 vis->Visualize( this, cam );
+        }
+  
   // and draw the children
   FOR_EACH( it, children )
         (*it)->DataVisualizeTree( cam );

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-07-16 01:10:16 UTC (rev 8028)
+++ code/stage/trunk/libstage/stage.hh  2009-07-16 03:25:18 UTC (rev 8029)
@@ -656,13 +656,6 @@
 #define VAR(V,init) __typeof(init) V=(init)
 #define FOR_EACH(I,C) for(VAR(I,(C).begin());I!=(C).end();I++)
 
-  // list iterator macros
-  // todo: retire these along with glib
-#define LISTFUNCTION( LIST, TYPE, FUNC ) for( GList* it=LIST; it; it=it->next 
) FUNC((TYPE)it->data);
-#define LISTMETHOD( LIST, TYPE, METHOD ) for( GList* it=LIST; it; it=it->next 
) ((TYPE)it->data)->METHOD();
-#define LISTFUNCTIONARG( LIST, TYPE, FUNC, ARG ) for( GList* it=LIST; it; 
it=it->next ) FUNC((TYPE)it->data, ARG);
-#define LISTMETHODARG( LIST, TYPE, METHOD, ARG ) for( GList* it=LIST; it; 
it=it->next ) ((TYPE)it->data)->METHOD(ARG);
-
   // Error macros - output goes to stderr
 #define PRINT_ERR(m) fprintf( stderr, "\033[41merr\033[0m: "m" (%s %s)\n", 
__FILE__, __FUNCTION__)
 #define PRINT_ERR1(m,a) fprintf( stderr, "\033[41merr\033[0m: "m" (%s %s)\n", 
a, __FILE__, __FUNCTION__)    
@@ -850,7 +843,6 @@
        ModelPtrSet charge_list; ///< Models which receive charge are listed 
here
     bool destroy;
     bool dirty; ///< iff true, a gui redraw would be required
-       // GList* event_list; //< 
     GHashTable* models_by_name; ///< the models that make up the world, 
indexed by name
        /** Keep a list of all models with detectable fiducials. This
                avoids searching the whole world for fiducials. */
@@ -879,13 +871,13 @@
     stg_bounds3d_t extent; ///< Describes the 3D volume of the world
     bool graphics;///< true iff we have a GUI
     stg_usec_t interval_sim; ///< temporal resolution: microseconds that 
elapse between simulated time steps 
-       GHashTable* option_table; ///< GUI options (toggles) registered by 
models
-       GList* powerpack_list; ///< List of all the powerpacks attached to 
models in the world
-    GList* ray_list;///< List of rays traced for debug visualization
+        GHashTable* option_table; ///< GUI options (toggles) registered by 
models
+        std::list<PowerPack*> powerpack_list; ///< List of all the powerpacks 
attached to models in the world
+        std::list<float*> ray_list;///< List of rays traced for debug 
visualization
     stg_usec_t sim_time; ///< the current sim time in this world in 
microseconds
-       std::map<stg_point_int_t,SuperRegion*> superregions;
+        std::map<stg_point_int_t,SuperRegion*> superregions;
     SuperRegion* sr_cached; ///< The last superregion looked up by this world
-       
+        
        // todo - test performance of std::set
        std::vector<ModelPtrVec > update_lists;  
         
@@ -1000,7 +992,6 @@
     void AddPowerPack( PowerPack* pp );
     void RemovePowerPack( PowerPack* pp );
   
-    GList* GetRayList(){ return ray_list; };
     void ClearRays();
   
     /** store rays traced for debugging purposes */
@@ -1720,7 +1711,7 @@
                  instead of adding a data callback. */
         bool data_fresh;
         stg_bool_t disabled; ///< if non-zero, the model is disabled  
-        GList* custom_visual_list;
+        std::list<Visualizer*> cv_list;
         std::list<Flag*> flag_list;
         Geom geom;
         Pose global_pose;
@@ -1757,7 +1748,7 @@
 
         /** list of powerpacks that this model is currently charging,
                  initially NULL. */
-        GList* pps_charging;
+        std::list<PowerPack*> pps_charging;
 
         /** GData datalist can contain arbitrary named data items. Can be used
                  by derived model types to store properties, and for user code
@@ -1771,7 +1762,8 @@
          uint8_t* data;
          unsigned int width, height;
          stg_meters_t cellwidth, cellheight;
-         GList* pts;
+         //GList* pts;
+         std::vector<stg_point_t> pts;
          
        public:
          RasterVis();

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2009-07-16 01:10:16 UTC (rev 8028)
+++ code/stage/trunk/libstage/world.cc  2009-07-16 03:25:18 UTC (rev 8029)
@@ -104,8 +104,8 @@
   graphics( false ), 
   interval_sim( (stg_usec_t)thousand * interval_sim ),
   option_table( g_hash_table_new( g_str_hash, g_str_equal ) ), 
-  powerpack_list( NULL ),
-  ray_list( NULL ),  
+  powerpack_list(),
+  ray_list(),  
   sim_time( 0 ),
   superregions(),
   sr_cached(NULL),
@@ -404,8 +404,7 @@
                
   update_lists.resize(1);
   
-  g_list_free( ray_list );
-  ray_list = NULL;
+  ray_list.clear();
 
   // todo
   //g_hash_table_foreach( superregions, (GHFunc)destroy_sregion, NULL );
@@ -618,19 +617,18 @@
   drawpts[1] = y1;
   drawpts[2] = x2;
   drawpts[3] = y2;
-  ray_list = g_list_append( ray_list, drawpts );
+  ray_list.push_back( drawpts );
 }
 
 void World::ClearRays()
 {
-  for( GList* it = ray_list; it; it=it->next )
-    {
-      float* pts = (float*)it->data;
-      delete [] pts;
-    }
-
-  g_list_free(ray_list );
-  ray_list = NULL;
+  FOR_EACH( it, ray_list )
+        {
+               float* pts = *it;
+               delete [] pts;
+        }
+  
+  ray_list.clear();
 }
 
 
@@ -1059,12 +1057,12 @@
 
 void World::AddPowerPack( PowerPack* pp )
 {
-  powerpack_list = g_list_append( powerpack_list, pp ); 
+  powerpack_list.push_back( pp ); 
 }
 
 void World::RemovePowerPack( PowerPack* pp )
 {
-  powerpack_list = g_list_remove( powerpack_list, pp ); 
+  powerpack_list.erase( remove( powerpack_list.begin(), powerpack_list.end(), 
pp ));
 }
 
 /// Register an Option for pickup by the GUI

Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world  2009-07-16 01:10:16 UTC (rev 8028)
+++ code/stage/trunk/worlds/fasr.world  2009-07-16 03:25:18 UTC (rev 8029)
@@ -22,7 +22,7 @@
 ( 
   size [ 600.000 600.000 ] 
 
-  center [ 0.250 -0.680 ] 
+  center [ 0.217 -0.222 ] 
   rotate [ 0 0 ]
   scale 30.643 
   
@@ -102,15 +102,15 @@
  charging_bump( fiducial( range 3 pose [ 0 0 -0.100 0 ] ) )
 )
 
-autorob( pose [-1.667 -2.152 0 -90.000] joules 300000 )
+autorob( pose [-3.164 0.806 0 33.186] joules 300000 name "r0" )
 autorob( pose [1.384 7.361 0 -0.139] joules 100000 )
 autorob( pose [-5.258 -5.871 0 -120.113] joules 200000 )
 autorob( pose [6.600 5.211 0 -89.911] joules 400000 )
 autorob( pose [-6.355 1.726 0 90.000] joules 100000 )
-autorob( pose [4.452 -1.179 0 164.286] joules 200000 )
-autorob( pose [4.820 -3.446 0 24.788] joules 300000 )
-autorob( pose [-0.187 3.065 0 -153.738] joules 400000 )
-autorob( pose [4.309 3.736 0 121.988] joules 100000 )
+autorob( pose [-1.530 -2.099 0 82.171] joules 200000 )
+autorob( pose [4.661 -1.695 0 147.974] joules 300000 )
+autorob( pose [-0.947 2.798 0 124.147] joules 400000 )
+autorob( pose [3.573 6.962 0 -32.711] joules 100000 )
 autorob( pose [6.261 7.461 0 0] joules 200000 )
 
 


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

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to