Browse Source

finishIntervalsMatching

David Rose 22 years ago
parent
commit
dc6772b566

+ 22 - 0
direct/src/interval/IntervalManager.py

@@ -3,6 +3,7 @@ from DirectNotifyGlobal import *
 import EventManager
 import Interval
 import types
+import fnmatch
 
 class IntervalManager(CIntervalManager):
 
@@ -52,6 +53,27 @@ class IntervalManager(CIntervalManager):
             return self.ivals[index]
         return None
 
+    def finishIntervalsMatching(self, pattern):
+        count = 0
+        
+        maxIndex = self.getMaxIndex()
+        for index in range(maxIndex):
+            ival = self.getCInterval(index)
+            if ival and \
+               fnmatch.fnmatchcase(ival.getName(), pattern):
+                # Finish and remove this interval.  Finishing it
+                # automatically removes it.
+                count += 1
+                if self.ivals[index]:
+                    # Finish the python version if we have it
+                    self.ivals[index].finish()
+                else:
+                    # Otherwise, it's a C-only interval.
+                    ival.finish()
+
+        return count
+            
+
     def step(self):
         # This method should be called once per frame to perform all
         # of the per-frame processing on the active intervals.

+ 15 - 0
direct/src/interval/cIntervalManager.cxx

@@ -244,6 +244,21 @@ get_num_intervals() const {
   return _name_index.size();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CIntervalManager::get_max_index
+//       Access: Published
+//  Description: Returns one more than the largest interval index
+//               number in the manager.  If you walk through all the
+//               values between (0, get_max_index()] and call
+//               get_c_interval() on each number, you will retrieve
+//               all of the managed intervals (and possibly a number
+//               of NULL pointers as well).
+////////////////////////////////////////////////////////////////////
+int CIntervalManager::
+get_max_index() const {
+  return _intervals.size();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CIntervalManager::step
 //       Access: Published

+ 1 - 0
direct/src/interval/cIntervalManager.h

@@ -59,6 +59,7 @@ PUBLISHED:
 
   int interrupt();
   int get_num_intervals() const;
+  int get_max_index() const;
 
   void step();
   int get_next_event();