]> git.mxchange.org Git - simgear.git/commitdiff
Remove unecessary dependency from libSimGearCore on libSimGearScene.
authorThomas Geymayer <tomgey@gmail.com>
Sat, 16 Mar 2013 11:19:23 +0000 (12:19 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Sat, 16 Mar 2013 11:19:23 +0000 (12:19 +0100)
simgear/misc/CMakeLists.txt
simgear/misc/make_new.hxx [new file with mode: 0644]
simgear/props/PropertyInterpolationMgr.cxx
simgear/props/PropertyInterpolationMgr.hxx
simgear/props/PropertyInterpolator.cxx
simgear/props/PropertyInterpolator.hxx
simgear/scene/util/parse_color_test.cxx
simgear/simgear_config_cmake.h.in

index a58330f03324b571bb454e1ca8e92f5b7dedfea6..d6d37b7f0672fa6faa605336f524ed989d606c7b 100644 (file)
@@ -4,6 +4,7 @@ include (SimGearComponent)
 set(HEADERS 
     ResourceManager.hxx
     interpolator.hxx
+    make_new.hxx
     sg_dir.hxx
     sg_path.hxx
     sgstream.hxx
diff --git a/simgear/misc/make_new.hxx b/simgear/misc/make_new.hxx
new file mode 100644 (file)
index 0000000..2339c6d
--- /dev/null
@@ -0,0 +1,52 @@
+// Helper functions which created objects with new.
+//
+// Copyright (C) 2013  Thomas Geymayer <tomgey@gmail.com>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
+
+#ifndef SG_MAKE_NEW_HXX_
+#define SG_MAKE_NEW_HXX_
+
+namespace simgear
+{
+  template<class T>
+  T* make_new()
+  { return new T; }
+
+  template<class T, class A1>
+  T* make_new(const A1& a1)
+  { return new T(a1); }
+
+  template<class T, class A1, class A2>
+  T* make_new(const A1& a1, const A2& a2)
+  { return new T(a1, a2); }
+
+  template<class Base, class Derived>
+  Base* make_new_derived()
+  { return new Derived; }
+
+  template<class Base, class Derived, class A1>
+  Base* make_new_derived(const A1& a1)
+  { return new Derived(a1); }
+
+  template<class Base, class Derived, class A1, class A2>
+  Base* make_new_derived(const A1& a1, const A2& a2)
+  { return new Derived(a1, a2); }
+
+  // Add more if needed (Variadic templates would be really nice!)
+
+} // namespace simgear
+
+#endif /* SG_MAKE_NEW_HXX_ */
index 3600bb02f1839d16be84a72c5c7d589c503f4887..60ff32244597712f7340ee9ec1d8235535737591 100644 (file)
 
 #include "PropertyInterpolationMgr.hxx"
 #include "PropertyInterpolator.hxx"
-
-#include <simgear_config.h>
-
-#ifndef SIMGEAR_HEADLESS
-# include <simgear/scene/util/ColorInterpolator.hxx>
-#endif
-
-#include <simgear/props/props.hxx>
+#include "props.hxx"
 
 #include <algorithm>
 
@@ -36,9 +29,6 @@ namespace simgear
   PropertyInterpolationMgr::PropertyInterpolationMgr()
   {
     addInterpolatorFactory<NumericInterpolator>("numeric");
-#ifndef SIMGEAR_HEADLESS
-    addInterpolatorFactory<ColorInterpolator>("color");
-#endif
 
     for( size_t i = 0; easing_functions[i].name; ++i )
       addEasingFunction
@@ -128,7 +118,8 @@ namespace simgear
     }
 
     PropertyInterpolatorRef interp;
-    interp = (*interpolator_factory->second)(target);
+    interp = (*interpolator_factory->second)();
+    interp->reset(target);
     interp->_type = type;
     interp->_duration = duration;
     interp->_easing = easing_func->second;
index 4271a9f016b022f1a8c66b1e98f6eb5463272dab..96e942c1fee99ef5a9264da627cef239a5ab5b2a 100644 (file)
 #ifndef SG_PROPERTY_INTERPOLATION_MGR_HXX_
 #define SG_PROPERTY_INTERPOLATION_MGR_HXX_
 
+#include "PropertyInterpolator.hxx"
+
+#include <simgear/misc/make_new.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
-#include <simgear/props/PropertyInterpolator.hxx>
 
 #include <list>
 
@@ -45,8 +47,7 @@ namespace simgear
     public SGSubsystem
   {
     public:
-      typedef PropertyInterpolator*
-              (*InterpolatorFactory)(const SGPropertyNode* target);
+      typedef PropertyInterpolator* (*InterpolatorFactory)();
 
       PropertyInterpolationMgr();
 
@@ -90,7 +91,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>
+        );
       }
 
       /**
index 19c30179e85e39d6e23cef8916b6becc8e3909c0..79b830caf6ebdc2fbc1e635d2f9e5bdd3224be63 100644 (file)
@@ -68,7 +68,7 @@ namespace simgear
   //----------------------------------------------------------------------------
   PropertyInterpolator::PropertyInterpolator():
     _duration(1),
-    _cur_t(-1)
+    _cur_t(0)
   {
     setEasingFunction(0);
   }
index 7936acbb46434342f4ba209d09169d4cd81f6b33..a89b3e2d992947c725b68f0e9b464ec7d5b0f027 100644 (file)
@@ -67,23 +67,6 @@ namespace simgear
 
       const std::string& getType() const    { return _type; }
 
-      /**
-       * Create new animation for given property.
-       *
-       * @param prop    Property to be animated
-       * @param target  Property containing target value
-       */
-      template<class Derived>
-      static PropertyInterpolator* create(const SGPropertyNode* target)
-      {
-        assert(target);
-
-        PropertyInterpolator* interp = new Derived;
-        interp->reset(target);
-
-        return interp;
-      }
-
     protected:
       friend class PropertyInterpolationMgr;
 
index d5605bf2c9cabadbca467bf0d544ba0252a58fad..e82884a787bbb8b4180e70566f3751f4cbe3921b 100644 (file)
@@ -41,9 +41,8 @@ int main (int ac, char ** av)
   SGPropertyNode color_node, color_arg;
   color_arg.setStringValue("#000000");
 
-  simgear::PropertyInterpolator* interp =
-    simgear::PropertyInterpolator
-           ::create<simgear::ColorInterpolator>(&color_arg);
+  simgear::PropertyInterpolator* interp = new simgear::ColorInterpolator;
+  interp->reset(&color_arg);
 
   interp->update(&color_node, 0.5); // with no color it should immediately set to the target
   VERIFY_NODE_STR(color_node, "rgb(0,0,0)");
index 725556a693566190b50fd25712d85b8d4938248e..135b7f44d00a9bf72f946e22333dac40800c5d9f 100644 (file)
@@ -20,5 +20,4 @@
 #cmakedefine GCC_ATOMIC_BUILTINS_FOUND
 
 #cmakedefine SYSTEM_EXPAT
-#cmakedefine ENABLE_SOUND
-#cmakedefine SIMGEAR_HEADLESS
\ No newline at end of file
+#cmakedefine ENABLE_SOUND
\ No newline at end of file