Use a separate class to handle activator mechanics
parent
487c83e943
commit
8d98f3649c
@ -0,0 +1,62 @@
|
||||
#include "activators.hpp"
|
||||
|
||||
#include <OgreVector3.h>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
|
||||
Activators::Activators()
|
||||
{
|
||||
}
|
||||
|
||||
void Activators::addActivator (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
MWRender::Animation *anim = MWBase::Environment::get().getWorld()->getAnimation(ptr);
|
||||
mActivators.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Idle, true)));
|
||||
}
|
||||
|
||||
void Activators::removeActivator (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
PtrControllerMap::iterator iter = mActivators.find(ptr);
|
||||
if(iter != mActivators.end())
|
||||
mActivators.erase(iter);
|
||||
}
|
||||
|
||||
void Activators::dropActivators (const MWWorld::Ptr::CellStore *cellStore)
|
||||
{
|
||||
PtrControllerMap::iterator iter = mActivators.begin();
|
||||
while(iter != mActivators.end())
|
||||
{
|
||||
if(iter->first.getCell()==cellStore)
|
||||
mActivators.erase(iter++);
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
void Activators::update(float duration, bool paused)
|
||||
{
|
||||
if(!paused)
|
||||
{
|
||||
for(PtrControllerMap::iterator iter(mActivators.begin());iter != mActivators.end();++iter)
|
||||
iter->second.update(duration);
|
||||
}
|
||||
}
|
||||
|
||||
void Activators::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
|
||||
{
|
||||
PtrControllerMap::iterator iter = mActivators.find(ptr);
|
||||
if(iter != mActivators.end())
|
||||
iter->second.playGroup(groupName, mode, number);
|
||||
}
|
||||
void Activators::skipAnimation(const MWWorld::Ptr& ptr)
|
||||
{
|
||||
PtrControllerMap::iterator iter = mActivators.find(ptr);
|
||||
if(iter != mActivators.end())
|
||||
iter->second.skipAnim();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
#ifndef GAME_MWMECHANICS_ACTIVATORS_H
|
||||
#define GAME_MWMECHANICS_ACTOVATRS_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "character.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Ptr;
|
||||
class CellStore;
|
||||
}
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
class Activators
|
||||
{
|
||||
typedef std::map<MWWorld::Ptr,CharacterController> PtrControllerMap;
|
||||
PtrControllerMap mActivators;
|
||||
|
||||
public:
|
||||
Activators();
|
||||
|
||||
void addActivator (const MWWorld::Ptr& ptr);
|
||||
///< Register an activator
|
||||
|
||||
void removeActivator (const MWWorld::Ptr& ptr);
|
||||
///< Deregister an activator
|
||||
|
||||
void dropActivators (const MWWorld::CellStore *cellStore);
|
||||
///< Deregister all activators in the given cell.
|
||||
|
||||
void update (float duration, bool paused);
|
||||
///< Update activator animations
|
||||
|
||||
void playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
|
||||
void skipAnimation(const MWWorld::Ptr& ptr);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue