]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/PropertyInterpolationMgr.hxx
Fixed a crash: the singleton needs to be instantiated the first time SGCommandMgr...
[simgear.git] / simgear / props / PropertyInterpolationMgr.hxx
index 4271a9f016b022f1a8c66b1e98f6eb5463272dab..efd907d9a4317383bc3d9a43ba6f6d120c6223a0 100644 (file)
 #ifndef SG_PROPERTY_INTERPOLATION_MGR_HXX_
 #define SG_PROPERTY_INTERPOLATION_MGR_HXX_
 
+#include "PropertyInterpolator.hxx"
+
+#include <simgear/math/sg_types.hxx>
+#include <simgear/misc/make_new.hxx>
+#include <simgear/props/props.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
-#include <simgear/props/PropertyInterpolator.hxx>
 
 #include <list>
 
@@ -45,8 +49,7 @@ namespace simgear
     public SGSubsystem
   {
     public:
-      typedef PropertyInterpolator*
-              (*InterpolatorFactory)(const SGPropertyNode* target);
+      typedef PropertyInterpolator* (*InterpolatorFactory)();
 
       PropertyInterpolationMgr();
 
@@ -66,21 +69,34 @@ namespace simgear
        * @param duration    Duration if the animation (in seconds)
        * @param easing      Type of easing ("linear", "swing", etc.)
        */
-      PropertyInterpolatorRef
+      PropertyInterpolator*
       createInterpolator( const std::string& type,
-                          const SGPropertyNode* target,
-                          double duration = 1.0,
-                          const std::string& easing = "swing" );
+                          const SGPropertyNode& target,
+                          double duration,
+                          const std::string& easing );
 
       /**
-       * Add animation of the given property from current its current value to
-       * the target value of the interpolator.
+       * Add animation of the given property from its current value to the
+       * target value of the interpolator. If no interpolator is given any
+       * existing animation of the given property is aborted.
        *
        * @param prop    Property to be interpolated
        * @param interp  Interpolator used for interpolation
        */
-      void interpolate( SGPropertyNode* prop,
-                        PropertyInterpolatorRef interp );
+      bool interpolate( SGPropertyNode* prop,
+                        PropertyInterpolatorRef interp  = 0 );
+
+      bool interpolate( SGPropertyNode* prop,
+                        const std::string& type,
+                        const SGPropertyNode& target,
+                        double duration,
+                        const std::string& easing );
+
+      bool interpolate( SGPropertyNode* prop,
+                        const std::string& type,
+                        const PropertyList& values,
+                        const double_list& deltas,
+                        const std::string& easing );
 
       /**
        * Register factory for interpolation type.
@@ -90,7 +106,11 @@ namespace simgear
       template<class T>
       void addInterpolatorFactory(const std::string& type)
       {
-        addInterpolatorFactory(type, &PropertyInterpolator::create<T>);
+        addInterpolatorFactory
+        (
+          type,
+          &simgear::make_new_derived<PropertyInterpolator, T>
+        );
       }
 
       /**
@@ -98,6 +118,13 @@ namespace simgear
        */
       void addEasingFunction(const std::string& type, easing_func_t func);
 
+      /**
+       * Set property containing real time delta (not sim time)
+       *
+       * TODO better pass both deltas to all update methods...
+       */
+      void setRealtimeProperty(SGPropertyNode* node);
+
     protected:
 
       typedef std::map<std::string, InterpolatorFactory> InterpolatorFactoryMap;
@@ -111,6 +138,8 @@ namespace simgear
       InterpolatorFactoryMap    _interpolator_factories;
       EasingFunctionMap         _easing_functions;
       InterpolatorList          _interpolators;
+
+      SGPropertyNode_ptr        _rt_prop;
   };
 
 } // namespace simgear