Revision: 7156
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7156&view=rev
Author:   rtv
Date:     2008-11-17 23:06:46 +0000 (Mon, 17 Nov 2008)

Log Message:
-----------
reduced CPU use on idle, and eliminated superfluous screen redraws - some 
models may need to be tweaked to force screen updates in some unusual situations

Modified Paths:
--------------
    code/stage/trunk/libstage/blockgroup.cc
    code/stage/trunk/libstage/canvas.cc
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/worldgui.cc
    code/stage/trunk/worlds/benchmark/cave.world
    code/stage/trunk/worlds/benchmark/hospital.world
    code/stage/trunk/worlds/fasr.world
    code/stage/trunk/worlds/simple.world

Modified: code/stage/trunk/libstage/blockgroup.cc
===================================================================
--- code/stage/trunk/libstage/blockgroup.cc     2008-11-17 21:08:21 UTC (rev 
7155)
+++ code/stage/trunk/libstage/blockgroup.cc     2008-11-17 23:06:46 UTC (rev 
7156)
@@ -176,9 +176,7 @@
                else
                  blk->DrawSolid();
         }
-  
-  //           LISTMETHOD( blocks, StgBlock*, DrawSolid );
-  
+
   glDepthMask(GL_TRUE);
   glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
   

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-11-17 21:08:21 UTC (rev 7155)
+++ code/stage/trunk/libstage/canvas.cc 2008-11-17 23:06:46 UTC (rev 7156)
@@ -25,20 +25,23 @@
 static  const int      checkImageHeight = 2;
 static  GLubyte checkImage[checkImageHeight][checkImageWidth][4];
 static  GLuint texName;
+static bool blur = true;
 
+
 void StgCanvas::TimerCallback( StgCanvas* c )
 {
-  c->redraw();
+  if( c->world->dirty )
+        {
+               //puts( "timer redraw" );
+               c->redraw();
+               c->world->dirty = false;
+        }
   
   Fl::repeat_timeout(((double)c->interval/1000),
                                                        
(Fl_Timeout_Handler)StgCanvas::TimerCallback, 
                                                        c);
 }
 
-
-
-
-
 StgCanvas::StgCanvas( StgWorldGui* world, int x, int y, int w, int h) :
   Fl_Gl_Window(x,y,w,h),
   // initialize Option objects
@@ -76,13 +79,17 @@
        
   startx = starty = -1;
   interval = 50; //msec between redraws
+  
+  // enable accumulation buffer
+  mode( mode() | FL_ACCUM );
+  assert( can_do( FL_ACCUM ) );
 
   graphics = true;
   
-  // // start the timer that causes regular redraws
-  Fl::add_timeout( ((double)interval/1000), 
-                                                
(Fl_Timeout_Handler)StgCanvas::TimerCallback, 
-                                                this);
+//   // // start the timer that causes regular redraws
+//   Fl::add_timeout( ((double)interval/1000), 
+//                                              
(Fl_Timeout_Handler)StgCanvas::TimerCallback, 
+//                                              this);
 
  
   GLenum status;
@@ -183,7 +190,9 @@
     {
                last_selection = mod;
                selected_models = g_list_prepend( selected_models, mod );
+               
                //              mod->Disable();
+               redraw();
     }
 }
 
@@ -196,6 +205,7 @@
                         selected_models = 
                                g_list_remove_link( selected_models, link );
                         //                     mod->Enable();
+                        redraw();
                  }
         }  
 }
@@ -415,6 +425,19 @@
                  {
                  case 'p': // pause
                         world->TogglePause();
+                        
+                        if( ! world->paused )
+                               {
+                                 // // start the timer that causes regular 
redraws
+                                 Fl::add_timeout( ((double)interval/1000), 
+                                                                               
 (Fl_Timeout_Handler)StgCanvas::TimerCallback, 
+                                                                               
 this);
+                               }
+                        else
+                               { // remove the timeout
+                                 Fl::remove_timeout( 
(Fl_Timeout_Handler)StgCanvas::TimerCallback );
+                               }
+
                         break;
                  case ' ': // space bar
                  
@@ -503,16 +526,14 @@
   glColor3f( 1.0, 1.0, 1.0 );
 
   glBegin(GL_QUADS);
-
-  glTexCoord2f( bounds.x.min/2.0, bounds.y.min/2.0 ); 
-  glVertex2f( bounds.x.min, bounds.y.min );
-  glTexCoord2f( bounds.x.max/2.0, bounds.y.min/2.0); 
-  glVertex2f(  bounds.x.max, bounds.y.min );
-  glTexCoord2f( bounds.x.max/2.0, bounds.y.max/2.0 ); 
-  glVertex2f(  bounds.x.max, bounds.y.max );
-  glTexCoord2f( bounds.x.min/2.0, bounds.y.max/2.0 ); 
-  glVertex2f( bounds.x.min, bounds.y.max );
-
+    glTexCoord2f( bounds.x.min/2.0, bounds.y.min/2.0 ); 
+    glVertex2f( bounds.x.min, bounds.y.min );
+    glTexCoord2f( bounds.x.max/2.0, bounds.y.min/2.0); 
+    glVertex2f(  bounds.x.max, bounds.y.min );
+    glTexCoord2f( bounds.x.max/2.0, bounds.y.max/2.0 ); 
+    glVertex2f(  bounds.x.max, bounds.y.max );
+    glTexCoord2f( bounds.x.min/2.0, bounds.y.max/2.0 ); 
+    glVertex2f( bounds.x.min, bounds.y.max );
   glEnd();
 
   glDisable(GL_TEXTURE_2D);
@@ -628,10 +649,6 @@
       glPopMatrix();
     }
 
-  if( showGrid )
-    DrawGlobalGrid();
-  else
-    DrawFloor();
   
   if( showFootprints )
     {
@@ -642,10 +659,95 @@
                }
       glEnable( GL_DEPTH_TEST );
     }
+  
+  if( showGrid )
+        DrawGlobalGrid();
+  else
+        DrawFloor();
 
   if( showBlocks )
-    DrawBlocks();
-  
+        DrawBlocks();
+
+
+// MOTION BLUR
+//   if( showBlocks )
+//      {
+//             DrawBlocks();
+               
+//             static float count = 0; 
+               
+//             if( ! blur )
+//               {
+//                      blur = true;
+//                      glClear( GL_ACCUM_BUFFER_BIT | GL_COLOR_BUFFER_BIT | 
GL_DEPTH_BUFFER_BIT );
+//                      glAccum( GL_LOAD, 1.0 );
+//               }
+//             else
+//               {     
+//                      glAccum( GL_MULT, 0.9 );
+//                      glAccum( GL_ACCUM, 0.1 );
+                        
+//                      glAccum( GL_RETURN, 1.1 );
+                        
+//                      DrawBlocks(); // outline at current location
+//               }
+//      }
+
+// GRAY TRAILS
+//   if( showBlocks )
+//      {
+               
+//             static float count = 0; 
+               
+//             if( ! blur )
+//               {
+//                      blur = true;
+//                      glClear( GL_ACCUM_BUFFER_BIT );
+//                      DrawBlocks();
+//                      glAccum( GL_LOAD, 1.0 );
+//               }
+//             else
+//               {     
+//                      glAccum( GL_MULT, 0.9 );
+
+//                      DrawBlocks();
+
+//                      glAccum( GL_ACCUM, 0.1);
+
+//                      glAccum( GL_RETURN, 1.0 );
+
+//                      DrawBlocks();
+//               }
+//      }
+
+// PRETTY BLACK
+//   if( showBlocks )
+//      {
+               
+//             static float count = 0; 
+               
+//             if( ! blur )
+//               {
+//                      blur = true;
+//                      glClear( GL_ACCUM_BUFFER_BIT );
+//                      DrawBlocks();
+//                      glAccum( GL_LOAD, 1.0 );
+//               }
+//             else
+//               {     
+//                      glAccum( GL_MULT, 0.9 );
+//                      glAccum( GL_RETURN, 1.0 );
+
+//                      DrawBlocks();
+
+//                      glAccum( GL_ACCUM, 0.1);
+
+//                      glAccum( GL_RETURN, 1.0 );
+
+//                      DrawBlocks();
+//               }
+//      }
+
   if( showTrailRise )
     {
                for( std::multimap< float, StgModel* >::reverse_iterator i = 
ordered.rbegin(); i != ordered.rend(); i++ ) {
@@ -908,6 +1010,12 @@
   showScreenshots.Load( wf, sec );
   pCamOn.Load( wf, sec );
 
+  if( ! world->paused )
+        // // start the timer that causes regular redraws
+        Fl::add_timeout( ((double)interval/1000), 
+                                                       
(Fl_Timeout_Handler)StgCanvas::TimerCallback, 
+                                                       this);
+
   invalidate(); // we probably changed something
 }
 
@@ -937,6 +1045,9 @@
 
 void StgCanvas::draw()
 {
+//   static unsigned long calls=0;
+//   printf( "Draw calls %lu\n", ++calls );
+
   static bool loaded_texture = false;
 
   //Enable the following to debug camera model
@@ -964,6 +1075,8 @@
                glEnableClientState( GL_VERTEX_ARRAY );
                glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
 
+               blur = false;
+
       //TODO find a better home for loading textures
       if( loaded_texture == false ) 
                  {

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2008-11-17 21:08:21 UTC (rev 7155)
+++ code/stage/trunk/libstage/model.cc  2008-11-17 23:06:46 UTC (rev 7156)
@@ -159,7 +159,6 @@
         parent(parent),
         type(type),
     id( StgModel::count++ ),
-        gpose_dirty(true),
         trail( g_array_new( false, false, sizeof(stg_trail_item_t) )),
         blocks_dl(0),
         data_fresh(false),
@@ -553,28 +552,20 @@
 { 
   //printf( "model %s global pose ", token );
 
-  // if( this->gpose_dirty )
-  {
-        stg_pose_t parent_pose;
-
-        // find my parent's pose
-        if( this->parent )
-               {
-                 parent_pose = parent->GetGlobalPose();          
-                 stg_pose_sum( &global_pose, &parent_pose, &pose );
-                        
-                 // we are on top of our parent
-                 global_pose.z += parent->geom.size.z;
-               }
-        else
-               memcpy( &global_pose, &pose, sizeof(stg_pose_t));
+  stg_pose_t parent_pose;
+  
+  // find my parent's pose
+  if( this->parent )
+        {
+               parent_pose = parent->GetGlobalPose();    
+               stg_pose_sum( &global_pose, &parent_pose, &pose );
                
-        this->gpose_dirty = false;
-        //printf( " WORK " );
-  }
-  //else
-  //printf( " CACHED " );
-
+               // we are on top of our parent
+               global_pose.z += parent->geom.size.z;
+        }
+  else
+        memcpy( &global_pose, &pose, sizeof(stg_pose_t));
+  
   //   PRINT_DEBUG4( "GET GLOBAL POSE [x:%.2f y:%.2f z:%.2f a:%.2f]",
   //           global_pose.x,
   //           global_pose.y,
@@ -1301,15 +1292,17 @@
 
   if( parent )
     parent->NeedRedraw();
+  else
+        world->NeedRedraw();
 }
 
-void StgModel::GPoseDirtyTree( void )
-{
-  this->gpose_dirty = true; // our global pose may have changed
+// void StgModel::GPoseDirtyTree( void )
+// {
+//   this->gpose_dirty = true; // our global pose may have changed
 
-  for( GList* it = this->children; it; it=it->next )
-    ((StgModel*)it->data)->GPoseDirtyTree();
-}
+//   for( GList* it = this->children; it; it=it->next )
+//     ((StgModel*)it->data)->GPoseDirtyTree();
+// }
 
 void StgModel::SetPose( stg_pose_t pose )
 {
@@ -1329,10 +1322,11 @@
       this->pose.a = normalize(this->pose.a);
 
       this->NeedRedraw();
-      this->GPoseDirtyTree(); // global pose may have changed
 
                this->map_caches_are_invalid = true;
       MapWithChildren();
+
+               world->dirty = true;
     }
 
   // register a model change even if the pose didn't actually change
@@ -1365,8 +1359,6 @@
   //  geom->pose.x, geom->pose.y, geom->pose.a,
   //  geom->size.x, geom->size.y );
 
-  this->gpose_dirty = true;
-
   UnMapWithChildren();
   
   this->geom = geom;
@@ -1553,8 +1545,11 @@
   if( hitmod )
         pose = startpose; // move failed - put me back where I started
   else
-        CommitTestedPose(); // shift anyrecursively commit to blocks to the 
new pose
-  
+        {
+               CommitTestedPose(); // shift anyrecursively commit to blocks to 
the new pose 
+               world->dirty = true; // need redraw
+        }
+
   return hitmod;
 }
 

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-11-17 21:08:21 UTC (rev 7155)
+++ code/stage/trunk/libstage/stage.hh  2008-11-17 23:06:46 UTC (rev 7156)
@@ -883,6 +883,9 @@
         /** StgWorld::quit is set true when this simulation time is reached */
         stg_usec_t quit_time;
 
+        // hint that the world needs to be redrawn if a GUI is attached
+        void NeedRedraw(){ dirty = true; };
+
         void LoadModel( Worldfile* wf, int entity, GHashTable* entitytable );
         void LoadBlock( Worldfile* wf, int entity, GHashTable* entitytable );
         void LoadBlockGroup( Worldfile* wf, int entity, GHashTable* 
entitytable );

Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc       2008-11-17 21:08:21 UTC (rev 
7155)
+++ code/stage/trunk/libstage/worldgui.cc       2008-11-17 23:06:46 UTC (rev 
7156)
@@ -298,20 +298,35 @@
     Fl::check();
 
     timenow = RealTimeNow();
-    interval = timenow - real_time_of_last_update; // guaranteed to be >= 0
         
-    double sleeptime = (double)interval_real - (double)interval;
-        
-    if( sleeptime > 0  ) 
-      usleep( (stg_usec_t)MIN(sleeptime,100000) ); // check the GUI at 10Hz min
-        
+        // if we're attempting to match some real time interval
+        //if( interval_real > 0 )
+               {
+                 interval = timenow - real_time_of_last_update; // guaranteed 
to be >= 0
+                 
+                 double sleeptime = (double)interval_real - (double)interval;
+                 
+                 if( paused ) sleeptime = 20000; // spare the CPU if we're 
paused
+                 
+                 // printf( "real %.2f interval %.2f sleeptime %.2f\n", 
+                 //     (double)interval_real,
+                 //     (double)interval,
+                 //     sleeptime );
+                 
+                 if( sleeptime > 0 ) 
+                        usleep( (stg_usec_t)MIN(sleeptime,20000) ); // check 
the GUI at 10Hz min
+               }
   } while( interval < interval_real );
   
+  // if( paused ) // gentle on the CPU when paused
+                //usleep( 10000 );
   
   interval_log[updates%INTERVAL_LOG_LEN] =  timenow - real_time_of_last_update;
 
   real_time_of_last_update = timenow;
   
+  //puts( "FINSHED UPDATE" );
+
   return val;
 }
 

Modified: code/stage/trunk/worlds/benchmark/cave.world
===================================================================
--- code/stage/trunk/worlds/benchmark/cave.world        2008-11-17 21:08:21 UTC 
(rev 7155)
+++ code/stage/trunk/worlds/benchmark/cave.world        2008-11-17 23:06:46 UTC 
(rev 7156)
@@ -11,7 +11,7 @@
 interval_real 0 # real-time interval between simulation updates in 
milliseconds 
 paused 1
 
-threadpool 2
+threadpool 0
 
 # configure the GUI window
 window

Modified: code/stage/trunk/worlds/benchmark/hospital.world
===================================================================
--- code/stage/trunk/worlds/benchmark/hospital.world    2008-11-17 21:08:21 UTC 
(rev 7155)
+++ code/stage/trunk/worlds/benchmark/hospital.world    2008-11-17 23:06:46 UTC 
(rev 7156)
@@ -23,11 +23,8 @@
   rotate [ 38.000 -36.500 ]
   scale 12.611 
 
-#  size [ 640 480 ] 
-#  center [929.990 -377.040] 
-#  rotate [ 0.000 0.000 ]
-#  scale 20.806 
   show_data 0
+  interval 200
 )
 
 # load an environment bitmap

Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world  2008-11-17 21:08:21 UTC (rev 7155)
+++ code/stage/trunk/worlds/fasr.world  2008-11-17 23:06:46 UTC (rev 7156)
@@ -8,13 +8,14 @@
 
 interval_sim 100  # simulation timestep in milliseconds
 interval_real 0 # real-time interval between simulation updates in 
milliseconds 
-paused 1
+paused 0
 
 resolution 0.02
 
 # threads don't help here as the per-robot update is very fast
 threadpool 0
 
+
 # configure the GUI window
 window
 ( 
@@ -65,27 +66,27 @@
  ctrl "fasr"
 )
 
-autorob( pose [5.133 4.841 0  -179.934] )
-autorob( pose [6.381 5.316 0 -85.327] )
-autorob( pose [5.972 4.982 0 -41.506] )
-autorob( pose [7.627 6.296 0 -120.309] )
-autorob( pose [5.509 6.440 0 -104.877] )
-autorob( pose [7.024 6.433 0 125.724] )
-autorob( pose [5.688 4.291 0 -12.027] )
-autorob( pose [4.887 6.172 0 -144.634] )
-autorob( pose [7.135 5.076 0 -162.054] )
-autorob( pose [7.409 5.691 0 146.028] )
+autorob( pose [5.099 4.804 0  -73.937] )
+autorob( pose [6.471 5.304 0 14.941] )
+autorob( pose [5.937 4.858 0 -147.503] )
+autorob( pose [7.574 6.269 0 -111.715] )
+autorob( pose [5.664 5.938 0 -51.799] )
+autorob( pose [7.016 6.428 0 -128.279] )
+autorob( pose [5.911 4.040 0 -97.047] )
+autorob( pose [4.909 6.097 0 -44.366] )
+autorob( pose [6.898 4.775 0 -117.576] )
+autorob( pose [7.012 5.706 0 129.497] )
 
-autorob( pose [6.752 6.937 0 -103.060] )
-autorob( pose [6.546 4.535 0 -153.940] )
-autorob( pose [5.642 7.205 0 97.307] )
-autorob( pose [4.386 5.877 0 -35.838] )
-autorob( pose [4.892 4.191 0 63.840] )
-autorob( pose [4.516 5.050 0 -76.859] )
-autorob( pose [5.354 5.353 0 -63.787] )
-autorob( pose [7.566 6.939 0 57.242] )
-autorob( pose [7.604 4.795 0 -147.661] )
-autorob( pose [6.284 3.807 0 -145.026] )
+autorob( pose [6.616 6.893 0 170.743] )
+autorob( pose [6.451 4.189 0 -61.453] )
+autorob( pose [5.098 6.788 0 -61.295] )
+autorob( pose [4.374 5.163 0 -90.417] )
+autorob( pose [4.999 4.230 0 -42.157] )
+autorob( pose [4.331 4.217 0 -95.000] )
+autorob( pose [5.440 5.317 0 -26.545] )
+autorob( pose [7.518 6.973 0 163.239] )
+autorob( pose [7.559 4.764 0 -139.066] )
+autorob( pose [4.839 3.595 0 -179.567] )
 
 #autorob( pose [7.122 4.175 0 -31.440] )
 #autorob( pose [6.203 6.963 0 2.937] )

Modified: code/stage/trunk/worlds/simple.world
===================================================================
--- code/stage/trunk/worlds/simple.world        2008-11-17 21:08:21 UTC (rev 
7155)
+++ code/stage/trunk/worlds/simple.world        2008-11-17 23:06:46 UTC (rev 
7156)
@@ -7,7 +7,7 @@
 include "sick.inc"
 
 interval_sim 100  # simulation timestep in milliseconds
-interval_real 50  # real-time interval between simulation updates in 
milliseconds 
+interval_real 0  # real-time interval between simulation updates in 
milliseconds 
 
 paused 1
 


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