Skip to content

Commit

Permalink
Main: SceneManager - implement the AnimationContainer API
Browse files Browse the repository at this point in the history
and unify docs while at it
  • Loading branch information
paroj committed Aug 13, 2024
1 parent 5d4469b commit d47c2d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 51 deletions.
14 changes: 11 additions & 3 deletions OgreMain/include/OgreAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ namespace Ogre {
class _OgreExport AnimationContainer
{
public:
typedef std::map<String, Animation*> AnimationList;

virtual ~AnimationContainer() {}

/** Gets the number of animations in this container. */
Expand All @@ -64,16 +66,22 @@ namespace Ogre {
/** Retrieve an animation by index. */
virtual Animation* getAnimation(unsigned short index) const = 0;

/** Retrieve an animation by name. */
/** Looks up an Animation object previously created with createAnimation.
@note Throws an exception if the named instance does not exist
@param name The name of the animation.
*/
virtual Animation* getAnimation(const String& name) const = 0;

/** Create a new animation with a given length owned by this container. */
/** Create a new animation with a given length owned by this container
@param name The name of the animation, must be unique within this container.
@param length The length of the animation in seconds
*/
virtual Animation* createAnimation(const String& name, Real length) = 0;

/** Returns whether this object contains the named animation. */
virtual bool hasAnimation(const String& name) const = 0;

/** Removes an Animation from this container. */
/** Remove & destroy an Animation from this container. */
virtual void removeAnimation(const String& name) = 0;

};
Expand Down
19 changes: 0 additions & 19 deletions OgreMain/include/OgreMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ namespace Ogre {
bool mAutoBuildEdgeLists;

/// Storage of morph animations, lookup by name
typedef std::map<String, Animation*> AnimationList;
AnimationList mAnimationsList;
/// The vertex animation type associated with the shared vertex data
mutable VertexAnimationType mSharedVertexDataAnimationType;
Expand Down Expand Up @@ -851,18 +850,8 @@ namespace Ogre {
/// Returns whether animation on shared vertex data includes normals.
bool getSharedVertexDataAnimationIncludesNormals() const { return mSharedVertexDataAnimationIncludesNormals; }

/** Creates a new Animation object for vertex animating this mesh.
@param name
The name of this animation.
@param length
The length of the animation in seconds.
*/
Animation* createAnimation(const String& name, Real length) override;

/** Returns the named vertex Animation object.
@param name
The name of the animation.
*/
Animation* getAnimation(const String& name) const override;

/** Internal access to the named vertex Animation object - returns null
Expand All @@ -872,17 +861,9 @@ namespace Ogre {
*/
virtual Animation* _getAnimationImpl(const String& name) const;

/** Returns whether this mesh contains the named vertex animation. */
bool hasAnimation(const String& name) const override;

/** Removes vertex Animation from this mesh. */
void removeAnimation(const String& name) override;

/** Gets the number of morph animations in this mesh. */
unsigned short getNumAnimations(void) const override;

/** Gets a single morph animation by index.
*/
Animation* getAnimation(unsigned short index) const override;

/** Removes all morph Animations from this mesh. */
Expand Down
29 changes: 11 additions & 18 deletions OgreMain/include/OgreSceneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Torus Knot Software Ltd.
#include "OgreCommon.h"
#include "OgreSceneQuery.h"
#include "OgreAutoParamDataSource.h"
#include "OgreAnimationState.h"
#include "OgreAnimation.h"
#include "OgreRenderQueue.h"
#include "OgreRenderQueueSortingGrouping.h"
#include "OgreResourceGroupManager.h"
Expand Down Expand Up @@ -234,7 +234,7 @@ namespace Ogre {
dependent on the Camera, which will always call back the SceneManager
which created it to render the scene.
*/
class _OgreExport SceneManager : public SceneMgtAlloc
class _OgreExport SceneManager : public AnimationContainer, public SceneMgtAlloc
{
public:
enum QueryTypeMask : uint32
Expand Down Expand Up @@ -403,7 +403,6 @@ namespace Ogre {
friend class SceneMgrQueuedRenderableVisitor;

typedef std::map<String, Camera* > CameraList;
typedef std::map<String, Animation*> AnimationList;
typedef std::map<String, MovableObject*> MovableObjectMap;
typedef std::map<String, StaticGeometry* > StaticGeometryMap;
private:
Expand Down Expand Up @@ -2191,25 +2190,19 @@ namespace Ogre {
although this is more useful when performing skeletal animation (see Skeleton::createAnimation).
@note whilst it uses the same classes, the animations created here are kept separate from the
skeletal animations of meshes (each Skeleton owns those animations).
@param name The name of the animation, must be unique within this SceneManager.
@param length The total length of the animation.
*/
Animation* createAnimation(const String& name, Real length);
/** Looks up an Animation object previously created with createAnimation.
@note Throws an exception if the named instance does not exist
*/
Animation* getAnimation(const String& name) const;
/** Returns whether an animation with the given name exists.
@copydetails AnimationContainer::createAnimation
*/
bool hasAnimation(const String& name) const;
Animation* createAnimation(const String& name, Real length) override;

/** Destroys an Animation.

You should ensure that none of your code is referencing this animation objects since the
memory will be freed.
*/
void destroyAnimation(const String& name);
Animation* getAnimation(const String& name) const override;
bool hasAnimation(const String& name) const override;
uint16 getNumAnimations(void) const override { return static_cast<uint16>(mAnimationsList.size()); }
Animation* getAnimation(unsigned short index) const override;
void removeAnimation(const String& name) override;

void destroyAnimation(const String& name) { removeAnimation(name); }

/** Removes all animations created using this SceneManager. */
void destroyAllAnimations(void);
Expand Down
8 changes: 1 addition & 7 deletions OgreMain/include/OgreSkeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ namespace Ogre {
virtual void reset(bool resetManualBones = false);

/** Creates a new Animation object for animating this skeleton.
@param name The name of this animation
@param length The length of the animation in seconds
@copydetails AnimationContainer::createAnimation
*/
Animation* createAnimation(const String& name, Real length) override;

Expand Down Expand Up @@ -239,10 +238,7 @@ namespace Ogre {
const LinkedSkeletonAnimationSource** linker = 0) const;


/** Returns whether this skeleton contains the named animation. */
bool hasAnimation(const String& name) const override;

/** Removes an Animation from this skeleton. */
void removeAnimation(const String& name) override;

/** Changes the state of the skeleton to reflect the application of the passed in collection of animations.
Expand Down Expand Up @@ -278,7 +274,6 @@ namespace Ogre {
*/
virtual void _getBoneMatrices(Affine3* pMatrices);

/** Gets the number of animations on this skeleton. */
unsigned short getNumAnimations(void) const override;

/** Gets a single animation by index.
Expand Down Expand Up @@ -422,7 +417,6 @@ namespace Ogre {

protected:
/// Storage of animations, lookup by name
typedef std::map<String, Animation*> AnimationList;
AnimationList mAnimationsList;
private:
/// Lookup by bone name
Expand Down
16 changes: 12 additions & 4 deletions OgreMain/src/OgreSceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,14 +2072,24 @@ Animation* SceneManager::getAnimation(const String& name) const
}
return i->second;
}
Animation* SceneManager::getAnimation(unsigned short index) const
{
assert( index < mAnimationsList.size() );
OGRE_LOCK_MUTEX(mAnimationsListMutex);

AnimationList::const_iterator i = mAnimationsList.begin();
std::advance(i, index);
return i->second;
}

//-----------------------------------------------------------------------
bool SceneManager::hasAnimation(const String& name) const
{
OGRE_LOCK_MUTEX(mAnimationsListMutex);
return (mAnimationsList.find(name) != mAnimationsList.end());
}
//-----------------------------------------------------------------------
void SceneManager::destroyAnimation(const String& name)
void SceneManager::removeAnimation(const String& name)
{
OGRE_LOCK_MUTEX(mAnimationsListMutex);

Expand All @@ -2089,9 +2099,7 @@ void SceneManager::destroyAnimation(const String& name)
AnimationList::iterator i = mAnimationsList.find(name);
if (i == mAnimationsList.end())
{
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
"Cannot find animation with name " + name,
"SceneManager::getAnimation");
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot find animation with name " + name);
}

// Free memory
Expand Down

0 comments on commit d47c2d5

Please sign in to comment.