Alert the user if attempting to play an animation fails

This is mostly propogating the error up the stack so the game can do something about it.
Working on avoiding log spam from calling an animation that doesn't exist every frame.
sceneinput
Arthur Moore 10 years ago
parent a391579382
commit 5e6fcc2aef

@ -160,12 +160,13 @@ namespace MWBase
virtual void forceStateUpdate(const MWWorld::Ptr &ptr) = 0;
///< Forces an object to refresh its animation state.
virtual void playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number=1) = 0;
virtual bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number=1) = 0;
///< Run animation for a MW-reference. Calls to this function for references that are currently not
/// in the scene should be ignored.
///
/// \param mode 0 normal, 1 immediate start, 2 immediate loop
/// \param count How many times the animation should be run
/// \return Success or error
virtual void skipAnimation(const MWWorld::Ptr& ptr) = 0;
///< Skip the animation for the given MW-reference for one frame. Calls to this function for

@ -1,6 +1,7 @@
#include "actors.hpp"
#include <typeinfo>
#include <iostream>
#include <osg/PositionAttitudeTransform>
@ -1241,11 +1242,18 @@ namespace MWMechanics
iter->second->getCharacterController()->forceStateUpdate();
}
void Actors::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
bool Actors::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
{
PtrActorMap::iterator iter = mActors.find(ptr);
if(iter != mActors.end())
iter->second->getCharacterController()->playGroup(groupName, mode, number);
{
return iter->second->getCharacterController()->playGroup(groupName, mode, number);
}
else
{
std::cerr<< "Error in Actors::playAnimationGroup: Unable to find " << ptr.getTypeName() << std::endl;
return false;
}
}
void Actors::skipAnimation(const MWWorld::Ptr& ptr)
{

@ -105,7 +105,7 @@ namespace MWMechanics
void forceStateUpdate(const MWWorld::Ptr &ptr);
void playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
void skipAnimation(const MWWorld::Ptr& ptr);
bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName);

@ -1866,10 +1866,13 @@ void CharacterController::update(float duration)
}
void CharacterController::playGroup(const std::string &groupname, int mode, int count)
bool CharacterController::playGroup(const std::string &groupname, int mode, int count)
{
if(!mAnimation || !mAnimation->hasAnimation(groupname))
{
std::cerr<< "Animation "<<groupname<<" not found for " << mPtr.getCellRef().getRefId() << std::endl;
return false;
}
else
{
count = std::max(count, 1);
@ -1894,6 +1897,7 @@ void CharacterController::playGroup(const std::string &groupname, int mode, int
mAnimQueue.push_back(std::make_pair(groupname, count-1));
}
}
return true;
}
void CharacterController::skipAnim()

@ -225,7 +225,7 @@ public:
void update(float duration);
void playGroup(const std::string &groupname, int mode, int count);
bool playGroup(const std::string &groupname, int mode, int count);
void skipAnim();
bool isAnimPlaying(const std::string &groupName);

@ -843,12 +843,12 @@ namespace MWMechanics
mActors.forceStateUpdate(ptr);
}
void MechanicsManager::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
bool MechanicsManager::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
{
if(ptr.getClass().isActor())
mActors.playAnimationGroup(ptr, groupName, mode, number);
return mActors.playAnimationGroup(ptr, groupName, mode, number);
else
mObjects.playAnimationGroup(ptr, groupName, mode, number);
return mObjects.playAnimationGroup(ptr, groupName, mode, number);
}
void MechanicsManager::skipAnimation(const MWWorld::Ptr& ptr)
{

@ -137,7 +137,9 @@ namespace MWMechanics
virtual void forceStateUpdate(const MWWorld::Ptr &ptr);
virtual void playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
/// Attempt to play an animation group
/// @return Success or error
virtual bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
virtual void skipAnimation(const MWWorld::Ptr& ptr);
virtual bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string &groupName);

@ -1,5 +1,7 @@
#include "objects.hpp"
#include <iostream>
#include "movement.hpp"
#include "../mwbase/environment.hpp"
@ -77,11 +79,18 @@ void Objects::update(float duration, bool paused)
}
}
void Objects::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
bool Objects::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
{
PtrControllerMap::iterator iter = mObjects.find(ptr);
if(iter != mObjects.end())
iter->second->playGroup(groupName, mode, number);
{
return iter->second->playGroup(groupName, mode, number);
}
else
{
std::cerr<< "Error in Objects::playAnimationGroup: Unable to find " << ptr.getTypeName() << std::endl;
return false;
}
}
void Objects::skipAnimation(const MWWorld::Ptr& ptr)
{

@ -38,7 +38,7 @@ namespace MWMechanics
void update(float duration, bool paused);
///< Update object animations
void playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
void skipAnimation(const MWWorld::Ptr& ptr);
void getObjectsInRange (const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out);

Loading…
Cancel
Save