set(HEADERS
ResourceManager.hxx
interpolator.hxx
+ make_new.hxx
sg_dir.hxx
sg_path.hxx
sgstream.hxx
--- /dev/null
+// 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_ */
#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>
PropertyInterpolationMgr::PropertyInterpolationMgr()
{
addInterpolatorFactory<NumericInterpolator>("numeric");
-#ifndef SIMGEAR_HEADLESS
- addInterpolatorFactory<ColorInterpolator>("color");
-#endif
for( size_t i = 0; easing_functions[i].name; ++i )
addEasingFunction
}
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;
#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>
public SGSubsystem
{
public:
- typedef PropertyInterpolator*
- (*InterpolatorFactory)(const SGPropertyNode* target);
+ typedef PropertyInterpolator* (*InterpolatorFactory)();
PropertyInterpolationMgr();
template<class T>
void addInterpolatorFactory(const std::string& type)
{
- addInterpolatorFactory(type, &PropertyInterpolator::create<T>);
+ addInterpolatorFactory
+ (
+ type,
+ &simgear::make_new_derived<PropertyInterpolator, T>
+ );
}
/**
//----------------------------------------------------------------------------
PropertyInterpolator::PropertyInterpolator():
_duration(1),
- _cur_t(-1)
+ _cur_t(0)
{
setEasingFunction(0);
}
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;
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)");
#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