Browse Source

update gui slider for ivalMgr intervals

David Rose 23 years ago
parent
commit
cab9905657

+ 1 - 0
direct/src/extensions/CInterval-extensions.py

@@ -85,6 +85,7 @@
         if not hasattr(self, "setTHooks"):
             self.setTHooks = []
         self.setTHooks.append(update)
+        self.setWantsTCallback(1)
         # Clear out function on destroy
         def onDestroy(e, s=self, u=update):
             if u in s.setTHooks:

+ 4 - 0
direct/src/interval/MetaInterval.py

@@ -228,6 +228,10 @@ class MetaInterval(CMetaInterval):
     def getManager(self):
         return self.__manager
 
+    def setT(self, t):
+        self.__updateIvals()
+        CMetaInterval.setT(self, t)
+
     def start(self, startT = 0.0, endT = -1.0, playRate = 1.0):
         self.__updateIvals()
         self.setupPlay(startT, endT, playRate, 0)

+ 42 - 0
direct/src/interval/cInterval.I

@@ -143,6 +143,32 @@ get_interruptible() const {
   return _interruptible;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CInterval::set_wants_t_callback
+//       Access: Published
+//  Description: Changes the state of the 'wants_t_callback' flag.  If
+//               this is true, the interval will be returned by
+//               CIntervalManager::get_event() each time the
+//               interval's time value has been changed, regardless of
+//               whether it has any external events.
+////////////////////////////////////////////////////////////////////
+INLINE void CInterval::
+set_wants_t_callback(bool wants_t_callback) {
+  _wants_t_callback = wants_t_callback;
+  _last_t_callback = -1.0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CInterval::get_wants_t_callback
+//       Access: Published
+//  Description: Returns the state of the 'wants_t_callback' flag.
+//               See set_wants_t_callback().
+////////////////////////////////////////////////////////////////////
+INLINE bool CInterval::
+get_wants_t_callback() const {
+  return _wants_t_callback;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CInterval::set_manager
 //       Access: Published
@@ -172,6 +198,22 @@ get_manager() const {
   return _manager;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CInterval::check_t_callback
+//       Access: Public
+//  Description: Returns true if the wants_t_callback() flag is true
+//               and the interval's t value has changed since the last
+//               call to check_t_callback(), false otherwise.
+////////////////////////////////////////////////////////////////////
+INLINE bool CInterval::
+check_t_callback() {
+  if (get_wants_t_callback() && get_t() != _last_t_callback) {
+    _last_t_callback = get_t();
+    return true;
+  }
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CInterval::recompute
 //       Access: Protected

+ 2 - 0
direct/src/interval/cInterval.cxx

@@ -40,6 +40,8 @@ CInterval(const string &name, double duration, bool open_ended) :
   _dirty(false)
 {
   _interruptible = false;
+  _wants_t_callback = false;
+  _last_t_callback = -1.0;
   _manager = CIntervalManager::get_global_ptr();
   _clock_start = 0.0;
   _start_t = 0.0;

+ 6 - 0
direct/src/interval/cInterval.h

@@ -78,6 +78,9 @@ PUBLISHED:
   INLINE void set_interruptible(bool interruptible);
   INLINE bool get_interruptible() const;
 
+  INLINE void set_wants_t_callback(bool wants_t_callback);
+  INLINE bool get_wants_t_callback() const;
+
   INLINE void set_manager(CIntervalManager *manager);
   INLINE CIntervalManager *get_manager() const;
 
@@ -117,6 +120,7 @@ PUBLISHED:
 
 public:
   void mark_dirty();
+  INLINE bool check_t_callback();
 
 protected:
   void interval_done();
@@ -133,6 +137,8 @@ protected:
   double _duration;
 
   bool _interruptible;
+  bool _wants_t_callback;
+  double _last_t_callback;
   CIntervalManager *_manager;
 
   // For setup_play() and step_play().

+ 11 - 6
direct/src/interval/cIntervalManager.cxx

@@ -276,14 +276,19 @@ int CIntervalManager::
 get_next_event() {
   while (_next_event_index < (int)_intervals.size()) {
     IntervalDef &def = _intervals[_next_event_index];
-    if (def._interval != (CInterval *)NULL && 
-        (def._flags & F_meta_interval) != 0) {
-      CMetaInterval *meta_interval;
-      DCAST_INTO_R(meta_interval, def._interval, -1);
-      if (meta_interval->is_event_ready()) {
-        nassertr((def._flags & F_external) != 0, -1);
+    if (def._interval != (CInterval *)NULL) {
+      if ((def._flags & F_external) != 0 && 
+          def._interval->check_t_callback()) {
         return _next_event_index;
       }
+      if ((def._flags & F_meta_interval) != 0) {
+        CMetaInterval *meta_interval;
+        DCAST_INTO_R(meta_interval, def._interval, -1);
+        if (meta_interval->is_event_ready()) {
+          nassertr((def._flags & F_external) != 0, -1);
+          return _next_event_index;
+        }
+      }
     }
     _next_event_index++;
   }

+ 16 - 0
direct/src/interval/cMetaInterval.cxx

@@ -367,6 +367,14 @@ priv_initialize(double t) {
 
   int now = double_to_int_time(t);
 
+  // One special case: if we step to t == 0.0, it really means to the
+  // very beginning of the interval, *before* any events that occurred
+  // at time 0.  (Most of the time, stepping to a particular time
+  // means *after* any events that occurred at that time.)
+  if (t == 0.0) {
+    now = -1;
+  }
+
   // Now look for events from the beginning up to the current time.
   _processing_events = true;
   ActiveEvents new_active;
@@ -559,6 +567,14 @@ priv_reverse_initialize(double t) {
 
   int now = double_to_int_time(t);
 
+  // One special case: if we step to t == 0.0, it really means to the
+  // very beginning of the interval, *before* any events that occurred
+  // at time 0.  (Most of the time, stepping to a particular time
+  // means *after* any events that occurred at that time.)
+  if (t == 0.0) {
+    now = -1;
+  }
+
   // Now look for events from the end down to the current time.
   _processing_events = true;
   ActiveEvents new_active;