Browse Source

overrides

David Rose 16 years ago
parent
commit
ff81be2aee

+ 29 - 10
direct/src/interval/LerpInterval.py

@@ -637,28 +637,32 @@ class LerpPosQuatScaleShearInterval(LerpNodePathInterval):
 class LerpColorInterval(LerpNodePathInterval):
 class LerpColorInterval(LerpNodePathInterval):
     def __init__(self, nodePath, duration, color, startColor = None,
     def __init__(self, nodePath, duration, color, startColor = None,
                  other = None, blendType = 'noBlend',
                  other = None, blendType = 'noBlend',
-                 bakeInStart = 1, name = None):
+                 bakeInStart = 1, name = None, override = None):
         LerpNodePathInterval.__init__(self, name, duration, blendType,
         LerpNodePathInterval.__init__(self, name, duration, blendType,
                                       bakeInStart, 0, nodePath, other)
                                       bakeInStart, 0, nodePath, other)
         self.setEndColor(color)
         self.setEndColor(color)
         if startColor != None:
         if startColor != None:
             self.setStartColor(startColor)
             self.setStartColor(startColor)
+        if override != None:
+            self.setOverride(override)
 
 
 class LerpColorScaleInterval(LerpNodePathInterval):
 class LerpColorScaleInterval(LerpNodePathInterval):
     def __init__(self, nodePath, duration, colorScale, startColorScale = None,
     def __init__(self, nodePath, duration, colorScale, startColorScale = None,
                  other = None, blendType = 'noBlend',
                  other = None, blendType = 'noBlend',
-                 bakeInStart = 1, name = None):
+                 bakeInStart = 1, name = None, override = None):
         LerpNodePathInterval.__init__(self, name, duration, blendType,
         LerpNodePathInterval.__init__(self, name, duration, blendType,
                                       bakeInStart, 0, nodePath, other)
                                       bakeInStart, 0, nodePath, other)
         self.setEndColorScale(colorScale)
         self.setEndColorScale(colorScale)
         if startColorScale != None:
         if startColorScale != None:
             self.setStartColorScale(startColorScale)
             self.setStartColorScale(startColorScale)
+        if override != None:
+            self.setOverride(override)
 
 
 class LerpTexOffsetInterval(LerpNodePathInterval):
 class LerpTexOffsetInterval(LerpNodePathInterval):
     def __init__(self, nodePath, duration, texOffset, startTexOffset = None,
     def __init__(self, nodePath, duration, texOffset, startTexOffset = None,
                  other = None, blendType = 'noBlend',
                  other = None, blendType = 'noBlend',
                  textureStage = None,
                  textureStage = None,
-                 bakeInStart = 1, name = None):
+                 bakeInStart = 1, name = None, override = None):
         LerpNodePathInterval.__init__(self, name, duration, blendType,
         LerpNodePathInterval.__init__(self, name, duration, blendType,
                                       bakeInStart, 0, nodePath, other)
                                       bakeInStart, 0, nodePath, other)
         self.setEndTexOffset(texOffset)
         self.setEndTexOffset(texOffset)
@@ -666,12 +670,14 @@ class LerpTexOffsetInterval(LerpNodePathInterval):
             self.setStartTexOffset(startTexOffset)
             self.setStartTexOffset(startTexOffset)
         if textureStage != None:
         if textureStage != None:
             self.setTextureStage(textureStage)
             self.setTextureStage(textureStage)
+        if override != None:
+            self.setOverride(override)
 
 
 class LerpTexRotateInterval(LerpNodePathInterval):
 class LerpTexRotateInterval(LerpNodePathInterval):
     def __init__(self, nodePath, duration, texRotate, startTexRotate = None,
     def __init__(self, nodePath, duration, texRotate, startTexRotate = None,
                  other = None, blendType = 'noBlend',
                  other = None, blendType = 'noBlend',
                  textureStage = None,
                  textureStage = None,
-                 bakeInStart = 1, name = None):
+                 bakeInStart = 1, name = None, override = None):
         LerpNodePathInterval.__init__(self, name, duration, blendType,
         LerpNodePathInterval.__init__(self, name, duration, blendType,
                                       bakeInStart, 0, nodePath, other)
                                       bakeInStart, 0, nodePath, other)
         self.setEndTexRotate(texRotate)
         self.setEndTexRotate(texRotate)
@@ -679,12 +685,14 @@ class LerpTexRotateInterval(LerpNodePathInterval):
             self.setStartTexRotate(startTexRotate)
             self.setStartTexRotate(startTexRotate)
         if textureStage != None:
         if textureStage != None:
             self.setTextureStage(textureStage)
             self.setTextureStage(textureStage)
+        if override != None:
+            self.setOverride(override)
 
 
 class LerpTexScaleInterval(LerpNodePathInterval):
 class LerpTexScaleInterval(LerpNodePathInterval):
     def __init__(self, nodePath, duration, texScale, startTexScale = None,
     def __init__(self, nodePath, duration, texScale, startTexScale = None,
                  other = None, blendType = 'noBlend',
                  other = None, blendType = 'noBlend',
                  textureStage = None,
                  textureStage = None,
-                 bakeInStart = 1, name = None):
+                 bakeInStart = 1, name = None, override = None):
         LerpNodePathInterval.__init__(self, name, duration, blendType,
         LerpNodePathInterval.__init__(self, name, duration, blendType,
                                       bakeInStart, 0, nodePath, other)
                                       bakeInStart, 0, nodePath, other)
         self.setEndTexScale(texScale)
         self.setEndTexScale(texScale)
@@ -692,15 +700,31 @@ class LerpTexScaleInterval(LerpNodePathInterval):
             self.setStartTexScale(startTexScale)
             self.setStartTexScale(startTexScale)
         if textureStage != None:
         if textureStage != None:
             self.setTextureStage(textureStage)
             self.setTextureStage(textureStage)
+        if override != None:
+            self.setOverride(override)
 
 
 
 
 
 
 
 
+#
+# The remaining intervals defined in this module are the old-school
+# Python-based intervals.
+#
+
+
 class LerpFunctionNoStateInterval(Interval.Interval):
 class LerpFunctionNoStateInterval(Interval.Interval):
     """
     """
     Class used to execute a function over time.  Function can access fromData
     Class used to execute a function over time.  Function can access fromData
     and toData to perform blend.  If fromData and toData not specified, will
     and toData to perform blend.  If fromData and toData not specified, will
     execute the given function passing in values ranging from 0 to 1
     execute the given function passing in values ranging from 0 to 1
+
+    This is different from a standard LerpFunction, in that it assumes
+    the function is not modifying any state that needs to be kept; so
+    that it will only call the function while the lerp is actually
+    running, and will not be guaranteed to call the function with its
+    final value of the lerp.  In particular, if the lerp interval
+    happens to get skipped over completely, it will not bother to call
+    the function at all.
     """
     """
     
     
     # Interval counter
     # Interval counter
@@ -773,11 +797,6 @@ class LerpFuncNS(LerpFunctionNoStateInterval):
         LerpFunctionNoStateInterval.__init__(self, *args, **kw)
         LerpFunctionNoStateInterval.__init__(self, *args, **kw)
 
 
 
 
-#
-# The remaining intervals defined in this module are the old-school
-# Python-based intervals.
-#
-
 class LerpFunctionInterval(Interval.Interval):
 class LerpFunctionInterval(Interval.Interval):
     """
     """
     Class used to execute a function over time.  Function can access fromData
     Class used to execute a function over time.  Function can access fromData

+ 27 - 0
direct/src/interval/cLerpNodePathInterval.I

@@ -447,3 +447,30 @@ set_end_tex_scale(const LVecBase2f &tex_scale) {
   _end_tex_scale = tex_scale;
   _end_tex_scale = tex_scale;
   _flags |= F_end_tex_scale;
   _flags |= F_end_tex_scale;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: CLerpNodePathInterval::set_override
+//       Access: Published
+//  Description: Changes the override value that will be associated
+//               with any state changes applied by the lerp.  If this
+//               lerp is changing state (for instance, a color lerp or
+//               a tex matrix lerp), then the new attributes created
+//               by this lerp will be assigned the indicated override
+//               value when they are applied to the node.
+////////////////////////////////////////////////////////////////////
+INLINE void CLerpNodePathInterval::
+set_override(int override) {
+  _override = override;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CLerpNodePathInterval::get_override
+//       Access: Published
+//  Description: Returns the override value that will be associated
+//               with any state changes applied by the lerp.  See
+//               set_override().
+////////////////////////////////////////////////////////////////////
+INLINE int CLerpNodePathInterval::
+get_override() const {
+  return _override;
+}

+ 5 - 4
direct/src/interval/cLerpNodePathInterval.cxx

@@ -65,6 +65,7 @@ CLerpNodePathInterval(const string &name, double duration,
   _other(other),
   _other(other),
   _flags(0),
   _flags(0),
   _texture_stage(TextureStage::get_default()),
   _texture_stage(TextureStage::get_default()),
+  _override(0),
   _slerp(NULL)
   _slerp(NULL)
 {
 {
   if (bake_in_start) {
   if (bake_in_start) {
@@ -431,7 +432,7 @@ priv_step(double t) {
         lerp_value_from_prev(color, d, _prev_d, color, _end_color);
         lerp_value_from_prev(color, d, _prev_d, color, _end_color);
       }
       }
 
 
-      state = state->add_attrib(ColorAttrib::make_flat(color));
+      state = state->add_attrib(ColorAttrib::make_flat(color), _override);
     }
     }
 
 
     if ((_flags & F_end_color_scale) != 0) {
     if ((_flags & F_end_color_scale) != 0) {
@@ -453,7 +454,7 @@ priv_step(double t) {
         lerp_value_from_prev(color_scale, d, _prev_d, color_scale, _end_color_scale);
         lerp_value_from_prev(color_scale, d, _prev_d, color_scale, _end_color_scale);
       }
       }
 
 
-      state = state->add_attrib(ColorScaleAttrib::make(color_scale));
+      state = state->add_attrib(ColorScaleAttrib::make(color_scale), _override);
     }    
     }    
 
 
     if ((_flags & (F_end_tex_offset | F_end_tex_rotate | F_end_tex_scale)) != 0) {
     if ((_flags & (F_end_tex_offset | F_end_tex_rotate | F_end_tex_scale)) != 0) {
@@ -512,9 +513,9 @@ priv_step(double t) {
 
 
       // Apply the modified transform back to the state.
       // Apply the modified transform back to the state.
       if (tma != (TexMatrixAttrib *)NULL) {
       if (tma != (TexMatrixAttrib *)NULL) {
-        state = state->add_attrib(tma->add_stage(_texture_stage, transform));
+        state = state->add_attrib(tma->add_stage(_texture_stage, transform), _override);
       } else {
       } else {
-        state = state->add_attrib(TexMatrixAttrib::make(_texture_stage, transform));
+        state = state->add_attrib(TexMatrixAttrib::make(_texture_stage, transform), _override);
       }
       }
     }    
     }    
 
 

+ 4 - 0
direct/src/interval/cLerpNodePathInterval.h

@@ -61,6 +61,9 @@ PUBLISHED:
   INLINE void set_start_tex_scale(const LVecBase2f &tex_scale);
   INLINE void set_start_tex_scale(const LVecBase2f &tex_scale);
   INLINE void set_end_tex_scale(const LVecBase2f &tex_scale);
   INLINE void set_end_tex_scale(const LVecBase2f &tex_scale);
 
 
+  INLINE void set_override(int override);
+  INLINE int get_override() const;
+
   virtual void priv_initialize(double t);
   virtual void priv_initialize(double t);
   virtual void priv_instant();
   virtual void priv_instant();
   virtual void priv_step(double t);
   virtual void priv_step(double t);
@@ -117,6 +120,7 @@ private:
   float _start_tex_rotate, _end_tex_rotate;
   float _start_tex_rotate, _end_tex_rotate;
   LVecBase2f _start_tex_scale, _end_tex_scale;
   LVecBase2f _start_tex_scale, _end_tex_scale;
 
 
+  int _override;
   double _prev_d;
   double _prev_d;
   float _slerp_angle;
   float _slerp_angle;
   float _slerp_denom;
   float _slerp_denom;