Browse Source

Better usage of *Basic* in class names, part 2: SceneGraph animables.

Use Animable<dimensions, T> and AnimableGroup<dimensions, T> like before
and add two kinds of aliases instead of only one:
BasicAnimable[Group]2D<T>/BasicAnimable[Group]3D<T> for abstract type
and Animable[Group]2D/Animable[Group]3D for Float.

Partially reverts commit c32c12b387.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
ab1d2f8f5f
  1. 8
      src/SceneGraph/Animable.cpp
  2. 107
      src/SceneGraph/Animable.h
  3. 22
      src/SceneGraph/Animable.hpp
  4. 53
      src/SceneGraph/AnimableGroup.h
  5. 26
      src/SceneGraph/SceneGraph.h

8
src/SceneGraph/Animable.cpp

@ -27,10 +27,10 @@
namespace Magnum { namespace SceneGraph {
#ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_SCENEGRAPH_EXPORT BasicAnimable<2, Float>;
template class MAGNUM_SCENEGRAPH_EXPORT BasicAnimable<3, Float>;
template class MAGNUM_SCENEGRAPH_EXPORT BasicAnimableGroup<2, Float>;
template class MAGNUM_SCENEGRAPH_EXPORT BasicAnimableGroup<3, Float>;
template class MAGNUM_SCENEGRAPH_EXPORT Animable<2, Float>;
template class MAGNUM_SCENEGRAPH_EXPORT Animable<3, Float>;
template class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup<2, Float>;
template class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup<3, Float>;
#endif
Debug operator<<(Debug debug, AnimationState value) {

107
src/SceneGraph/Animable.h

@ -25,7 +25,7 @@
*/
/** @file
* @brief Class Magnum::SceneGraph::BasicAnimable, typedef Magnum::SceneGraph::Animable2D, Magnum::SceneGraph::Animable3D, enum Magnum::SceneGraph::AnimationState
* @brief Class Magnum::SceneGraph::Animable, alias Magnum::SceneGraph::BasicAnimable2D, Magnum::SceneGraph::BasicAnimable3D, typedef Magnum::SceneGraph::Animable2D, Magnum::SceneGraph::Animable3D, enum Magnum::SceneGraph::AnimationState
*/
#include "AbstractGroupedFeature.h"
@ -37,7 +37,7 @@ namespace Magnum { namespace SceneGraph {
/**
@brief Animation state
@see BasicAnimable::setState()
@see Animable::setState()
*/
enum class AnimationState: UnsignedByte {
/**
@ -56,7 +56,7 @@ enum class AnimationState: UnsignedByte {
Running
};
/** @debugoperator{Magnum::SceneGraph::BasicAnimable} */
/** @debugoperator{Magnum::SceneGraph::Animable} */
Debug MAGNUM_SCENEGRAPH_EXPORT operator<<(Debug debug, AnimationState value);
/**
@ -90,10 +90,9 @@ class AnimableObject: public Object3D, SceneGraph::Animable3D {
@endcode
Then add the object to your scene and some animation group. You can also use
BasicAnimableGroup::add() and BasicAnimableGroup::remove() instead of passing
the group in the constructor. The animation is initially in stopped state and
without repeat, see setState(), setRepeated() and setRepeatCount() for more
information.
AnimableGroup::add() and AnimableGroup::remove() instead of passing the group
in the constructor. The animation is initially in stopped state and without
repeat, see setState(), setRepeated() and setRepeatCount() for more information.
@code
Scene3D scene;
SceneGraph::AnimableGroup3D animables;
@ -103,10 +102,10 @@ SceneGraph::AnimableGroup3D animables;
// ...
@endcode
Animation step is performed by calling BasicAnimableGroup::step() in your draw
event implementation. The function expects absolute time from relative to some
fixed point in the past and time delta (i.e. duration of the frame). You can
use Timeline for that, see its documentation for more information.
Animation step is performed by calling AnimableGroup::step() in your draw event
implementation. The function expects absolute time from relative to some fixed
point in the past and time delta (i.e. duration of the frame). You can use
Timeline for that, see its documentation for more information.
@code
Timeline timeline;
timeline.start();
@ -122,11 +121,11 @@ void MyApplication::drawEvent() {
@section Animable-performance Using animable groups to improve performance
Animable group is optimized for case when no animation is running - it just
AnimableGroup is optimized for case when no animation is running - it just
puts itself to rest and waits until some animation changes its state to
@ref AnimationState "AnimationState::Running" again. If you put animations
which are not pernamently running to separate group, they will not be always
traversed when calling BasicAnimableGroup::step(), saving precious frame time.
traversed when calling AnimableGroup::step(), saving precious frame time.
@section Animable-explicit-specializations Explicit template specializations
@ -135,14 +134,14 @@ For other specializations (e.g. using Double type) you have to use
Animable.hpp implementation file to avoid linker errors. See also
@ref compilation-speedup-hpp for more information.
- @ref BasicAnimable "BasicAnimable<2, Float>", @ref BasicAnimableGroup "BasicAnimableGroup<2, Float>"
- @ref BasicAnimable "BasicAnimable<3, Float>", @ref BasicAnimableGroup "BasicAnimableGroup<3, Float>"
- @ref Animable "Animable<2, Float>", @ref AnimableGroup "AnimableGroup<2, Float>"
- @ref Animable "Animable<3, Float>", @ref AnimableGroup "AnimableGroup<3, Float>"
@see @ref Animable2D, @ref Animable3D, @ref scenegraph, @ref AnimableGroup2D,
@ref AnimableGroup3D
@see @ref scenegraph, @ref BasicAnimable2D, @ref BasicAnimable3D,
@ref Animable2D, @ref Animable3D
*/
template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAnimable: public AbstractBasicGroupedFeature<dimensions, BasicAnimable<dimensions, T>, T> {
friend class BasicAnimableGroup<dimensions, T>;
template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractBasicGroupedFeature<dimensions, Animable<dimensions, T>, T> {
friend class AnimableGroup<dimensions, T>;
public:
/**
@ -152,11 +151,11 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
*
* Creates stopped non-repeating animation with infinite duration,
* adds the feature to the object and also to group, if specified.
* @see setDuration(), setState(), setRepeated(), BasicAnimableGroup::add()
* @see setDuration(), setState(), setRepeated(), AnimableGroup::add()
*/
explicit BasicAnimable(AbstractObject<dimensions, T>* object, BasicAnimableGroup<dimensions, T>* group = nullptr);
explicit Animable(AbstractObject<dimensions, T>* object, AnimableGroup<dimensions, T>* group = nullptr);
~BasicAnimable();
~Animable();
/** @brief Animation duration */
Float duration() const { return _duration; }
@ -175,7 +174,7 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
* @see animationStarted(), animationPaused(), animationResumed(),
* animationStopped()
*/
BasicAnimable<dimensions, T>* setState(AnimationState state);
Animable<dimensions, T>* setState(AnimationState state);
/**
* @brief Whether the animation is repeated
@ -191,7 +190,7 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
* Default is `false`.
* @see setRepeatCount()
*/
BasicAnimable<dimensions, T>* setRepeated(bool repeated) {
Animable<dimensions, T>* setRepeated(bool repeated) {
_repeated = repeated;
return this;
}
@ -211,7 +210,7 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
* infinitely repeated animation. Default is `0`.
* @see setRepeated()
*/
BasicAnimable<dimensions, T>* setRepeatCount(UnsignedShort count) {
Animable<dimensions, T>* setRepeatCount(UnsignedShort count) {
_repeatCount = count;
return this;
}
@ -221,8 +220,8 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
*
* If the animable doesn't belong to any group, returns `nullptr`.
*/
BasicAnimableGroup<dimensions, T>* group();
const BasicAnimableGroup<dimensions, T>* group() const; /**< @overload */
AnimableGroup<dimensions, T>* group();
const AnimableGroup<dimensions, T>* group() const; /**< @overload */
protected:
/**
@ -233,7 +232,7 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
* infinite non-repeating animation. Default is `0.0f`.
*/
/* Protected so only animation implementer can change it */
BasicAnimable<dimensions, T>* setDuration(Float duration) {
Animable<dimensions, T>* setDuration(Float duration) {
_duration = duration;
return this;
}
@ -243,8 +242,8 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
* @param time Time from start of the animation
* @param delta Time delta for current frame
*
* This function is periodically called from BasicAnimableGroup::step()
* if the animation state is set to @ref AnimationState "AnimationState::Running".
* This function is periodically called from AnimableGroup::step() if
* the animation state is set to @ref AnimationState "AnimationState::Running".
* After animation duration is exceeded and repeat is not enabled or
* repeat count is exceeded, the animation state is set to
* @ref AnimationState "AnimationState::Stopped".
@ -262,7 +261,7 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
/**
* @brief Action on animation start
*
* Called from BasicAnimableGroup::step() when state is changed from
* Called from AnimableGroup::step() when state is changed from
* @ref AnimationState "AnimationState::Stopped" to
* @ref AnimationState "AnimationState::Running" and before first
* animationStep() is called.
@ -276,7 +275,7 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
/**
* @brief Action on animation pause
*
* Called from BasicAnimableGroup::step() when state changes from
* Called from AnimableGroup::step() when state changes from
* @ref AnimationState "AnimationState::Running" to
* @ref AnimationState "AnimationState::Paused" and after last
* animationStep() is called.
@ -290,7 +289,7 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
/**
* @brief Action on animation resume
*
* Called from BasicAnimableGroup::step() when state changes from
* Called from AnimableGroup::step() when state changes from
* @ref AnimationState "AnimationState::Paused" to
* @ref AnimationState "AnimationState::Running" and before first
* animationStep() is called.
@ -304,7 +303,7 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
/**
* @brief Action on animation stop
*
* Called from BasicAnimableGroup::step() when state changes from either
* Called from AnimableGroup::step() when state changes from either
* @ref AnimationState "AnimationState::Running" or
* @ref AnimationState "AnimationState::Paused" to
* @ref AnimationState "AnimationState::Stopped" and after last
@ -328,19 +327,51 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
UnsignedShort repeats;
};
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief %Animable for two-dimensional scenes
Convenience alternative to <tt>%Animable<2, T></tt>. See Animable for more
information.
@note Not available on GCC < 4.7. Use <tt>%Animable<2, T></tt> instead.
@see @ref Animable2D, @ref BasicAnimable3D
*/
template<class T> using BasicAnimable2D = Animable<2, T>;
#endif
/**
@brief Animable for two-dimensional float scenes
@brief %Animable for two-dimensional float scenes
@see @ref Animable3D
*/
typedef BasicAnimable<2, Float> Animable2D;
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef BasicAnimable2D<Float> Animable2D;
#else
typedef Animable<2, Float> Animable2D;
#endif
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief Animable for three-dimensional float scenes
@brief %Animable for three-dimensional scenes
Convenience alternative to <tt>%Animable<3, T></tt>. See Animable for more
information.
@note Not available on GCC < 4.7. Use <tt>%Animable<3, T></tt> instead.
@see @ref Animable3D, @ref BasicAnimable2D
*/
template<class T> using BasicAnimable3D = Animable<3, T>;
#endif
/**
@brief %Animable for three-dimensional float scenes
@see @ref Animable2D
*/
typedef BasicAnimable<3, Float> Animable3D;
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef BasicAnimable3D<Float> Animable3D;
#else
typedef Animable<3, Float> Animable3D;
#endif
}}

22
src/SceneGraph/Animable.hpp

@ -35,11 +35,11 @@
namespace Magnum { namespace SceneGraph {
template<UnsignedInt dimensions, class T> BasicAnimable<dimensions, T>::BasicAnimable(AbstractObject<dimensions, T>* object, BasicAnimableGroup<dimensions, T>* group): AbstractBasicGroupedFeature<dimensions, BasicAnimable<dimensions, T>, T>(object, group), _duration(0.0f), startTime(std::numeric_limits<Float>::infinity()), pauseTime(-std::numeric_limits<Float>::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {}
template<UnsignedInt dimensions, class T> Animable<dimensions, T>::Animable(AbstractObject<dimensions, T>* object, AnimableGroup<dimensions, T>* group): AbstractBasicGroupedFeature<dimensions, Animable<dimensions, T>, T>(object, group), _duration(0.0f), startTime(std::numeric_limits<Float>::infinity()), pauseTime(-std::numeric_limits<Float>::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {}
template<UnsignedInt dimensions, class T> BasicAnimable<dimensions, T>::~BasicAnimable() {}
template<UnsignedInt dimensions, class T> Animable<dimensions, T>::~Animable() {}
template<UnsignedInt dimensions, class T> BasicAnimable<dimensions, T>* BasicAnimable<dimensions, T>::setState(AnimationState state) {
template<UnsignedInt dimensions, class T> Animable<dimensions, T>* Animable<dimensions, T>::setState(AnimationState state) {
if(currentState == state) return this;
/* Not allowed (for sanity) */
@ -52,20 +52,20 @@ template<UnsignedInt dimensions, class T> BasicAnimable<dimensions, T>* BasicAni
return this;
}
template<UnsignedInt dimensions, class T> BasicAnimableGroup<dimensions, T>* BasicAnimable<dimensions, T>::group() {
return static_cast<BasicAnimableGroup<dimensions, T>*>(AbstractBasicGroupedFeature<dimensions, BasicAnimable<dimensions, T>, T>::group());
template<UnsignedInt dimensions, class T> AnimableGroup<dimensions, T>* Animable<dimensions, T>::group() {
return static_cast<AnimableGroup<dimensions, T>*>(AbstractBasicGroupedFeature<dimensions, Animable<dimensions, T>, T>::group());
}
template<UnsignedInt dimensions, class T> const BasicAnimableGroup<dimensions, T>* BasicAnimable<dimensions, T>::group() const {
return static_cast<const BasicAnimableGroup<dimensions, T>*>(AbstractBasicGroupedFeature<dimensions, BasicAnimable<dimensions, T>, T>::group());
template<UnsignedInt dimensions, class T> const AnimableGroup<dimensions, T>* Animable<dimensions, T>::group() const {
return static_cast<const AnimableGroup<dimensions, T>*>(AbstractBasicGroupedFeature<dimensions, Animable<dimensions, T>, T>::group());
}
template<UnsignedInt dimensions, class T> void BasicAnimableGroup<dimensions, T>::step(const Float time, const Float delta) {
template<UnsignedInt dimensions, class T> void AnimableGroup<dimensions, T>::step(const Float time, const Float delta) {
if(!_runningCount && !wakeUp) return;
wakeUp = false;
for(std::size_t i = 0; i != this->size(); ++i) {
BasicAnimable<dimensions, T>* animable = (*this)[i];
Animable<dimensions, T>* animable = (*this)[i];
/* The animation was stopped recently, just decrease count of running
animations if the animation was running before */
@ -126,9 +126,9 @@ template<UnsignedInt dimensions, class T> void BasicAnimableGroup<dimensions, T>
/* Animation is still running, perform animation step */
CORRADE_ASSERT(time-animable->startTime >= 0.0f,
"SceneGraph::BasicAnimableGroup::step(): animation was started in future - probably wrong time passed", );
"SceneGraph::AnimableGroup::step(): animation was started in future - probably wrong time passed", );
CORRADE_ASSERT(delta >= 0.0f,
"SceneGraph::BasicAnimableGroup::step(): negative delta passed", );
"SceneGraph::AnimableGroup::step(): negative delta passed", );
animable->animationStep(time - animable->startTime, delta);
}

53
src/SceneGraph/AnimableGroup.h

@ -25,7 +25,7 @@
*/
/** @file
* @brief Class Magnum::SceneGraph::BasicAnimableGroup, typedef Magnum::SceneGraph::AnimableGroup2D, Magnum::SceneGraph::AnimableGroup3D
* @brief Class Magnum::SceneGraph::AnimableGroup, alias Magnum::SceneGraph::BasicAnimableGroup2D, Magnum::SceneGraph::BasicAnimableGroup3D, typedef Magnum::SceneGraph::AnimableGroup2D, Magnum::SceneGraph::AnimableGroup3D
*/
#include "FeatureGroup.h"
@ -37,17 +37,18 @@ namespace Magnum { namespace SceneGraph {
/**
@brief Group of animables
See BasicAnimable for more information.
@see @ref AnimableGroup2D, @ref AnimableGroup3D, @ref scenegraph
See Animable for more information.
@see @ref scenegraph, @ref BasicAnimableGroup2D, @ref BasicAnimableGroup3D,
@ref AnimableGroup2D, @ref AnimableGroup3D
*/
template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAnimableGroup: public BasicFeatureGroup<dimensions, BasicAnimable<dimensions, T>, T> {
friend class BasicAnimable<dimensions, T>;
template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup: public BasicFeatureGroup<dimensions, Animable<dimensions, T>, T> {
friend class Animable<dimensions, T>;
public:
/**
* @brief Constructor
*/
explicit BasicAnimableGroup(): _runningCount(0), wakeUp(false) {}
explicit AnimableGroup(): _runningCount(0), wakeUp(false) {}
/**
* @brief Count of running animations
@ -71,19 +72,51 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT BasicAn
bool wakeUp;
};
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief Animable group for two-dimensional float scenes
@brief %Animable group for two-dimensional scenes
Convenience alternative to <tt>%AnimableGroup<2, T></tt>. See Animable for
more information.
@note Not available on GCC < 4.7. Use <tt>%AnimableGroup<2, T></tt> instead.
@see @ref AnimableGroup2D, @ref BasicAnimableGroup3D
*/
template<class T> using BasicAnimableGroup2D = AnimableGroup<2, T>;
#endif
/**
@brief %Animable group for two-dimensional float scenes
@see @ref AnimableGroup3D
*/
typedef BasicAnimableGroup<2, Float> AnimableGroup2D;
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef BasicAnimableGroup2D<Float> AnimableGroup2D;
#else
typedef AnimableGroup<2, Float> AnimableGroup2D;
#endif
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief %Animable group for three-dimensional scenes
Convenience alternative to <tt>%AnimableGroup<3, T></tt>. See Animable for
more information.
@note Not available on GCC < 4.7. Use <tt>%AnimableGroup<3, T></tt> instead.
@see @ref AnimableGroup3D, @ref BasicAnimableGroup2D
*/
template<class T> using BasicAnimableGroup3D = AnimableGroup<3, T>;
#endif
/**
@brief Animable group for three-dimensional float scenes
@brief %Animable group for three-dimensional float scenes
@see @ref AnimableGroup2D
*/
typedef BasicAnimableGroup<3, Float> AnimableGroup3D;
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef BasicAnimableGroup3D<Float> AnimableGroup3D;
#else
typedef AnimableGroup<3, Float> AnimableGroup3D;
#endif
}}

26
src/SceneGraph/SceneGraph.h

@ -85,15 +85,29 @@ template<class> class AbstractBasicTranslationRotationScaling3D;
typedef AbstractBasicTranslationRotationScaling2D<Float> AbstractTranslationRotationScaling2D;
typedef AbstractBasicTranslationRotationScaling3D<Float> AbstractTranslationRotationScaling3D;
template<UnsignedInt, class> class BasicAnimable;
typedef BasicAnimable<2, Float> Animable2D;
typedef BasicAnimable<3, Float> Animable3D;
template<UnsignedInt, class> class Animable;
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class T> using BasicAnimable2D = Animable<2, T>;
template<class T> using BasicAnimable3D = Animable<3, T>;
typedef BasicAnimable2D<Float> Animable2D;
typedef BasicAnimable3D<Float> Animable3D;
#else
typedef Animable<2, Float> Animable2D;
typedef Animable<3, Float> Animable3D;
#endif
enum class AnimationState: UnsignedByte;
template<UnsignedInt, class> class BasicAnimableGroup;
typedef BasicAnimableGroup<2, Float> AnimableGroup2D;
typedef BasicAnimableGroup<3, Float> AnimableGroup3D;
template<UnsignedInt, class> class AnimableGroup;
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class T> using BasicAnimableGroup2D = AnimableGroup<2, T>;
template<class T> using BasicAnimableGroup3D = AnimableGroup<3, T>;
typedef BasicAnimableGroup2D<Float> AnimableGroup2D;
typedef BasicAnimableGroup3D<Float> AnimableGroup3D;
#else
typedef AnimableGroup<2, Float> AnimableGroup2D;
typedef AnimableGroup<3, Float> AnimableGroup3D;
#endif
template<class> class BasicCamera2D;
template<class> class BasicCamera3D;

Loading…
Cancel
Save