Revision: 8285
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8285&view=rev
Author:   rtv
Date:     2009-10-11 01:57:26 +0000 (Sun, 11 Oct 2009)

Log Message:
-----------
rolled back event queue to make things more simple and faster

Modified Paths:
--------------
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2009-10-07 22:30:38 UTC (rev 8284)
+++ code/stage/trunk/libstage/model.cc  2009-10-11 01:57:26 UTC (rev 8285)
@@ -674,14 +674,19 @@
 {
   //printf( "Startup model %s\n", this->token );  
   //printf( "model %s using queue %d\n", token, event_queue_num );
+
+  // if we're thread safe, we can use an event queue >0  
+  if( thread_safe )
+        event_queue_num = world->GetEventQueue( this );
+
+  // put my first update request in the world's queue
+  world->Enqueue( event_queue_num, interval, this );
+
+  world->active_velocity.insert( this );
   
-  // put my first events in the world's queue
-  world->Enqueue( event_queue_num, World::Event::UPDATE, interval, this );
-  world->Enqueue( 0, World::Event::POSE, interval_pose, this );
   if( FindPowerPack() )
-        world->Enqueue( 0, World::Event::ENERGY, interval_energy, this );
+        world->active_energy.insert( this );
   
-
   CallCallbacks( &hooks.startup );
 }
 
@@ -690,6 +695,9 @@
   //printf( "Shutdown model %s\n", this->token );
   CallCallbacks( &hooks.shutdown );
 
+  world->active_energy.erase( this );
+  world->active_velocity.erase( this );
+  
   // allows data visualizations to be cleared.
   NeedRedraw();
 }
@@ -699,7 +707,7 @@
 { 
   CallCallbacks( &hooks.update );  
   last_update = world->sim_time;  
-  world->Enqueue( event_queue_num, World::Event::UPDATE, interval, this );
+  world->Enqueue( event_queue_num, interval, this );
 }
 
 
@@ -819,7 +827,7 @@
         }
   
   // set up the next event
-  world->Enqueue( 0, World::Event::ENERGY, interval_energy, this );
+  //world->Enqueue( 0, World::Event::ENERGY, interval_energy, this );
 }
 
 void Model::CommitTestedPose()
@@ -856,6 +864,9 @@
 
 void Model::UpdatePose( void )
 {
+  if( velocity.IsZero() )
+        return;
+
   if( disabled )
     return;
   
@@ -881,8 +892,6 @@
                if( trail.size() > trail_length )
                  trail.pop_front();
         }                  
-  
-  world->Enqueue( 0, World::Event::POSE, interval_pose, this );
 }
 
 Model* Model::GetUnsubscribedModelOfType( const std::string& type ) const

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-10-07 22:30:38 UTC (rev 8284)
+++ code/stage/trunk/libstage/stage.hh  2009-10-11 01:57:26 UTC (rev 8285)
@@ -969,27 +969,25 @@
     class Event
     {
     public:
-      typedef enum {POSE, ENERGY, UPDATE } type_t;
       
-      Event( type_t type, stg_usec_t time, Model* mod ) 
-                 : type(type), time(time), mod(mod) {}
+      Event( stg_usec_t time, Model* mod ) 
+                 : time(time), mod(mod) {}
       
-      type_t type;
       stg_usec_t time; // time that event occurs
       Model* mod; // model to update
       
       /** Update the model appropriately, based on the event type. */
-      void Execute();
-      static const char* TypeStr( type_t type );
+      //void Execute();
+      //static const char* TypeStr( type_t type );
       bool operator<( const Event& other ) const;
       bool operator==( const Event& other ) const;
     };
     
         std::vector<std::priority_queue<Event> > event_queues;
-        void Enqueue( unsigned int queue_num, Event::type_t type, stg_usec_t 
delay, Model* mod );
+        void Enqueue( unsigned int queue_num, stg_usec_t delay, Model* mod );
         
-        /** The sim time of the next event in the queue. */
-        uint32_t event_pending_count;   
+        std::set<Model*> active_energy;
+        std::set<Model*> active_velocity;
 
         /** The amount of simulated time to run for each call to Update() */
         stg_usec_t sim_interval;

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2009-10-07 22:30:38 UTC (rev 8284)
+++ code/stage/trunk/libstage/world.cc  2009-10-11 01:57:26 UTC (rev 8285)
@@ -499,12 +499,8 @@
       // printf( "@ %llu next event <%s %llu %s>\n",  sim_time, ev.TypeStr( 
ev.type ), ev.time, ev.mod->Token() ); 
       queue.pop();      
                
-      // only update events are allowed in queues other than zero
-      if( queue_num > 0 && ev.type != Event::UPDATE )
-                 PRINT_WARN1( "event type %d in async queue", queue_num );
-      
                if( ev.mod->subs > 0 ) // no subscriptions means the event is 
discarded
-                 ev.Execute(); // simulate the event
+                 ev.mod->Update(); // update the model
 
       // and move to the next
       ev = queue.top();
@@ -520,17 +516,11 @@
   if( PastQuitTime() ) 
         return true;           
   
-  if( event_pending_count < 1 )
-    {
-      PRINT_WARN( "event queue(s) empty." );
-      return false;
-    }
-
   sim_time += sim_interval; 
 
   // handle the zeroth queue synchronously in the main thread
   ConsumeQueue( 0 );
-  
+    
   // handle all the remaining queues asynchronously in worker threads
   if( worker_threads > 0 )
     {
@@ -560,7 +550,13 @@
   
   // world callbacks
   CallUpdateCallbacks();
-    
+  
+  FOR_EACH( it, active_velocity )
+        (*it)->UpdatePose();
+
+  FOR_EACH( it, active_energy )
+        (*it)->UpdateCharge();
+  
   if( show_clock && ((this->updates % show_clock_interval) == 0) )
     {
       printf( "\r[Stage: %s]", ClockString().c_str() );
@@ -1061,12 +1057,11 @@
   //LogEntry::Print();
 }
 
-void World::Enqueue( unsigned int queue_num, Event::type_t type, stg_usec_t 
delay, Model* mod )
+void World::Enqueue( unsigned int queue_num, stg_usec_t delay, Model* mod )
 {
   //printf( "enqueue at %llu %p %s\n", sim_time + delay, mod, mod->Token() );
   
-  event_queues[queue_num].push( Event( type, sim_time + delay, mod ) );
-  ++event_pending_count;
+  event_queues[queue_num].push( Event( sim_time + delay, mod ) );
 }
 
 
@@ -1077,50 +1072,18 @@
   if( time > other.time )
     return true;
   
-  if( time == other.time ) 
-    {          
-      if( type > other.type )
-                 return true;
+//   if( time == other.time ) 
+//     {               
+//       if( type > other.type )
+//               return true;
 
-      if( type == other.type ) 
-                 {             
-                        if( mod < other.mod ) // tends to do children first
-                               return true;
-                 }
-    }
+//       if( type == other.type ) 
+//               {             
+//                      if( mod < other.mod ) // tends to do children first
+//                             return true;
+//               }
+//     }
            
   return false;
 }
 
-
-const char* World::Event::TypeStr( type_t type )
-{
-  switch( type )
-    {
-    case POSE: return "POSE";
-    case ENERGY: return "ENERGY";
-    case UPDATE: return "UPDATE";
-    default: return "<unknown>";
-    }
-}
-
-void World::Event::Execute()
-{
-  switch( type )
-    {
-    case UPDATE:                                 
-      mod->Update();
-      break;
-      
-    case POSE:                           
-      mod->UpdatePose();
-      break;
-      
-    case ENERGY:                                 
-      mod->UpdateCharge();
-      break;
-      
-    default:
-      PRINT_WARN1( "unknown event type %d", type );
-    }
-}


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

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) 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/devconference
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to