diff --git a/direct/src/extensions/CInterval-extensions.py b/direct/src/extensions/CInterval-extensions.py index 8be14c84f3..33f9e7304c 100644 --- a/direct/src/extensions/CInterval-extensions.py +++ b/direct/src/extensions/CInterval-extensions.py @@ -4,6 +4,9 @@ of the CInterval class """ + from DirectNotifyGlobal import directNotify + notify = directNotify.newCategory("Interval") + def setT(self, t): # Overridden from the C++ function to call privPostEvent # afterward. We do this by renaming the C++ function in @@ -12,15 +15,18 @@ self.privPostEvent() def play(self, t0 = 0.0, duration = None, scale = 1.0): + self.notify.warning("using deprecated CInterval.play() interface") if duration: # None or 0 implies full length self.start(t0, t0 + duration, scale) else: self.start(t0, -1, scale) def stop(self): + self.notify.warning("using deprecated CInterval.stop() interface") self.finish() def setFinalT(self): + self.notify.warning("using deprecated CInterval.setFinalT() interface") self.finish() def privPostEvent(self): diff --git a/direct/src/interval/Interval.py b/direct/src/interval/Interval.py index 0071c3ddff..6d58d8a20c 100644 --- a/direct/src/interval/Interval.py +++ b/direct/src/interval/Interval.py @@ -3,6 +3,7 @@ from DirectObject import * from PandaModules import * import Task +import PythonUtil import math class Interval(DirectObject): @@ -68,10 +69,8 @@ class Interval(DirectObject): self.privInitialize(t) if self.isPlaying(): self.setupResume() - elif state == CInterval.SFinal: - self.privReverseInitialize(t) - if self.isPlaying(): - self.setupResume() + else: + self.privInterrupt() elif state == CInterval.SStarted: # Support modifying t while the interval is playing. We # assume is_playing() will be true in this state. @@ -79,8 +78,22 @@ class Interval(DirectObject): self.privInterrupt() self.privStep(t) self.setupResume() - else: + elif state == CInterval.SPaused: + # Support modifying t while the interval is paused. In + # this case, we simply step to the new value of t; but + # this will change the state to S_started, so we must then + # change it back to S_paused by hand (because we're still + # paused). self.privStep(t) + self.privInterrupt() + elif state == CInterval.SFinal: + self.privReverseInitialize(t) + if self.isPlaying(): + self.setupResume() + else: + self.privInterrupt() + else: + self.notify.error("Invalid state: %s" % (state)) self.privPostEvent() def getT(self): @@ -274,11 +287,18 @@ class Interval(DirectObject): self.__clockStart += numLoops * timePerLoop else: - # Playing backwards. - # Not supported at the moment. + # Playing backwards. Not supported at the moment for + # Python-style intervals. To add support, copy the code + # from C++-style intervals in cInterval.cxx, and modify it + # for Python (as the above). pass - return (self.__loopCount == 0 or self.__doLoop) + shouldContinue = (self.__loopCount == 0 or self.__doLoop) + + if (not shouldContinue and self.getState() == CInterval.SStarted): + self.privInterrupt() + + return shouldContinue def __repr__(self, indent=0): """ __repr__(indent) @@ -293,12 +313,15 @@ class Interval(DirectObject): # for the CInterval class via the file CInterval-extensions.py. def play(self, *args, **kw): + self.notify.warning("using deprecated Interval.play() interface") self.start(*args, **kw) def stop(self): + self.notify.warning("using deprecated Interval.stop() interface") self.finish() def setFinalT(self): + self.notify.warning("using deprecated Interval.setFinalT() interface") self.finish() def privPostEvent(self): diff --git a/direct/src/interval/cInterval.cxx b/direct/src/interval/cInterval.cxx index 792aa044e4..db4ade6788 100644 --- a/direct/src/interval/cInterval.cxx +++ b/direct/src/interval/cInterval.cxx @@ -76,6 +76,8 @@ set_t(double t) { priv_initialize(t); if (is_playing()) { setup_resume(); + } else { + priv_interrupt(); } break; @@ -94,13 +96,15 @@ set_t(double t) { // change the state to S_started, so we must then change it back // to S_paused by hand (because we're still paused). priv_step(t); - _state = S_paused; + priv_interrupt(); break; case S_final: priv_reverse_initialize(t); if (is_playing()) { setup_resume(); + } else { + priv_interrupt(); } break; } @@ -607,7 +611,13 @@ step_play() { } } - return (_loop_count == 0 || _do_loop); + bool should_continue = (_loop_count == 0 || _do_loop); + + if (!should_continue && _state == S_started) { + priv_interrupt(); + } + + return should_continue; } ////////////////////////////////////////////////////////////////////