Browse Source

task.frame

David Rose 17 years ago
parent
commit
7cca74a597

+ 15 - 0
panda/src/event/asyncTask.I

@@ -129,6 +129,21 @@ get_start_time() const {
   return _start_time;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: AsyncTask::get_start_frame
+//       Access: Published
+//  Description: Returns the frame number at which the task was
+//               started, according to the task manager's clock.
+//
+//               It is only valid to call this if the task's status is
+//               not S_inactive.
+////////////////////////////////////////////////////////////////////
+INLINE int AsyncTask::
+get_start_frame() const {
+  nassertr(_state != S_inactive, 0);
+  return _start_frame;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: AsyncTask::clear_name
 //       Access: Public

+ 19 - 0
panda/src/event/asyncTask.cxx

@@ -40,6 +40,8 @@ AsyncTask(const string &name) :
   _servicing_thread(NULL),
   _manager(NULL),
   _chain(NULL),
+  _start_time(0.0),
+  _start_frame(0),
   _dt(0.0),
   _max_dt(0.0),
   _total_dt(0.0),
@@ -102,6 +104,23 @@ get_elapsed_time() const {
   return _manager->_clock->get_frame_time() - _start_time;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: AsyncTask::get_elapsed_frames
+//       Access: Published
+//  Description: Returns the number of frames that have elapsed since
+//               the task was started, according to the task manager's
+//               clock.
+//
+//               It is only valid to call this if the task's status is
+//               not S_inactive.
+////////////////////////////////////////////////////////////////////
+int AsyncTask::
+get_elapsed_frames() const {
+  nassertr(_state != S_inactive, 0);
+  nassertr(_manager != (AsyncTaskManager *)NULL, 0);
+  return _manager->_clock->get_frame_count() - _start_frame;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: AsyncTask::set_name
 //       Access: Published

+ 6 - 1
panda/src/event/asyncTask.h

@@ -77,6 +77,8 @@ PUBLISHED:
   
   INLINE double get_start_time() const;
   double get_elapsed_time() const;
+  INLINE int get_start_frame() const;
+  int get_elapsed_frames() const;
 
   void set_name(const string &name);
   INLINE void clear_name();
@@ -121,15 +123,18 @@ protected:
   double _delay;
   bool _has_delay;
   double _wake_time;
-  double _start_time;
   int _sort;
   int _priority;
   string _done_event;
+
   State _state;
   Thread *_servicing_thread;
   AsyncTaskManager *_manager;
   AsyncTaskChain *_chain;
 
+  double _start_time;
+  int _start_frame;
+
   double _dt;
   double _max_dt;
   double _total_dt;

+ 2 - 0
panda/src/event/asyncTaskChain.cxx

@@ -452,6 +452,7 @@ do_add(AsyncTask *task) {
 
   double now = _manager->_clock->get_frame_time();
   task->_start_time = now;
+  task->_start_frame = _manager->_clock->get_frame_count();
 
   _manager->add_task_by_name(task);
 
@@ -882,6 +883,7 @@ finish_sort_group() {
       pop_heap(_sleeping.begin(), _sleeping.end(), AsyncTaskSortWakeTime());
       _sleeping.pop_back();
       task->_state = AsyncTask::S_active;
+      task->_start_frame = _manager->_clock->get_frame_count();
       _active.push_back(task);
     }
 

+ 4 - 2
panda/src/event/asyncTaskManager.cxx

@@ -597,8 +597,10 @@ write(ostream &out, int indent_level) const {
        tci != _task_chains.end();
        ++tci) {
     AsyncTaskChain *chain = (*tci);
-    out << "\n";
-    chain->do_write(out, indent_level + 2);
+    if (chain->_num_tasks != 0) {
+      out << "\n";
+      chain->do_write(out, indent_level + 2);
+    }
   }
 }
 

+ 4 - 1
panda/src/event/pythonTask.cxx

@@ -263,7 +263,8 @@ __setattr__(const string &attr_name, PyObject *v) {
       set_name(name);
     }
 
-  } else if (attr_name == "id" || attr_name == "wakeTime") {
+  } else if (attr_name == "id" || attr_name == "time" || 
+             attr_name == "frame" || attr_name == "wakeTime") {
     nassert_raise("Cannot set constant value");
     return true;
 
@@ -313,6 +314,8 @@ __getattr__(const string &attr_name) const {
       Py_RETURN_NONE;
     }
     return PyFloat_FromDouble(get_delay());
+  } else if (attr_name == "frame") {
+    return PyInt_FromLong(get_elapsed_frames());
   } else if (attr_name == "id") {
     return PyInt_FromLong(_task_id);
   } else {