From: Thomas Geymayer Date: Sat, 16 Mar 2013 11:19:23 +0000 (+0100) Subject: Remove unecessary dependency from libSimGearCore on libSimGearScene. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=40be69ae8ec70a47b59b88b2953dd8b99245f0db;p=simgear.git Remove unecessary dependency from libSimGearCore on libSimGearScene. --- diff --git a/simgear/misc/CMakeLists.txt b/simgear/misc/CMakeLists.txt index a58330f0..d6d37b7f 100644 --- a/simgear/misc/CMakeLists.txt +++ b/simgear/misc/CMakeLists.txt @@ -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 index 00000000..2339c6d9 --- /dev/null +++ b/simgear/misc/make_new.hxx @@ -0,0 +1,52 @@ +// Helper functions which created objects with new. +// +// Copyright (C) 2013 Thomas Geymayer +// +// 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 + T* make_new() + { return new T; } + + template + T* make_new(const A1& a1) + { return new T(a1); } + + template + T* make_new(const A1& a1, const A2& a2) + { return new T(a1, a2); } + + template + Base* make_new_derived() + { return new Derived; } + + template + Base* make_new_derived(const A1& a1) + { return new Derived(a1); } + + template + 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_ */ diff --git a/simgear/props/PropertyInterpolationMgr.cxx b/simgear/props/PropertyInterpolationMgr.cxx index 3600bb02..60ff3224 100644 --- a/simgear/props/PropertyInterpolationMgr.cxx +++ b/simgear/props/PropertyInterpolationMgr.cxx @@ -18,14 +18,7 @@ #include "PropertyInterpolationMgr.hxx" #include "PropertyInterpolator.hxx" - -#include - -#ifndef SIMGEAR_HEADLESS -# include -#endif - -#include +#include "props.hxx" #include @@ -36,9 +29,6 @@ namespace simgear PropertyInterpolationMgr::PropertyInterpolationMgr() { addInterpolatorFactory("numeric"); -#ifndef SIMGEAR_HEADLESS - addInterpolatorFactory("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; diff --git a/simgear/props/PropertyInterpolationMgr.hxx b/simgear/props/PropertyInterpolationMgr.hxx index 4271a9f0..96e942c1 100644 --- a/simgear/props/PropertyInterpolationMgr.hxx +++ b/simgear/props/PropertyInterpolationMgr.hxx @@ -19,8 +19,10 @@ #ifndef SG_PROPERTY_INTERPOLATION_MGR_HXX_ #define SG_PROPERTY_INTERPOLATION_MGR_HXX_ +#include "PropertyInterpolator.hxx" + +#include #include -#include #include @@ -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 void addInterpolatorFactory(const std::string& type) { - addInterpolatorFactory(type, &PropertyInterpolator::create); + addInterpolatorFactory + ( + type, + &simgear::make_new_derived + ); } /** diff --git a/simgear/props/PropertyInterpolator.cxx b/simgear/props/PropertyInterpolator.cxx index 19c30179..79b830ca 100644 --- a/simgear/props/PropertyInterpolator.cxx +++ b/simgear/props/PropertyInterpolator.cxx @@ -68,7 +68,7 @@ namespace simgear //---------------------------------------------------------------------------- PropertyInterpolator::PropertyInterpolator(): _duration(1), - _cur_t(-1) + _cur_t(0) { setEasingFunction(0); } diff --git a/simgear/props/PropertyInterpolator.hxx b/simgear/props/PropertyInterpolator.hxx index 7936acbb..a89b3e2d 100644 --- a/simgear/props/PropertyInterpolator.hxx +++ b/simgear/props/PropertyInterpolator.hxx @@ -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 - static PropertyInterpolator* create(const SGPropertyNode* target) - { - assert(target); - - PropertyInterpolator* interp = new Derived; - interp->reset(target); - - return interp; - } - protected: friend class PropertyInterpolationMgr; diff --git a/simgear/scene/util/parse_color_test.cxx b/simgear/scene/util/parse_color_test.cxx index d5605bf2..e82884a7 100644 --- a/simgear/scene/util/parse_color_test.cxx +++ b/simgear/scene/util/parse_color_test.cxx @@ -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(&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)"); diff --git a/simgear/simgear_config_cmake.h.in b/simgear/simgear_config_cmake.h.in index 725556a6..135b7f44 100644 --- a/simgear/simgear_config_cmake.h.in +++ b/simgear/simgear_config_cmake.h.in @@ -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