Remove unecessary dependency from libSimGearCore on libSimGearScene.

This commit is contained in:
Thomas Geymayer 2013-03-16 12:19:23 +01:00
parent 17eec81071
commit 40be69ae8e
8 changed files with 69 additions and 39 deletions

View File

@ -4,6 +4,7 @@ include (SimGearComponent)
set(HEADERS
ResourceManager.hxx
interpolator.hxx
make_new.hxx
sg_dir.hxx
sg_path.hxx
sgstream.hxx

52
simgear/misc/make_new.hxx Normal file
View File

@ -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_ */

View File

@ -18,14 +18,7 @@
#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;

View File

@ -19,8 +19,10 @@
#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>
);
}
/**

View File

@ -68,7 +68,7 @@ namespace simgear
//----------------------------------------------------------------------------
PropertyInterpolator::PropertyInterpolator():
_duration(1),
_cur_t(-1)
_cur_t(0)
{
setEasingFunction(0);
}

View 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;

View 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)");

View File

@ -20,5 +20,4 @@
#cmakedefine GCC_ATOMIC_BUILTINS_FOUND
#cmakedefine SYSTEM_EXPAT
#cmakedefine ENABLE_SOUND
#cmakedefine SIMGEAR_HEADLESS
#cmakedefine ENABLE_SOUND