2013-03-31 22:29:41 +00:00
|
|
|
#include "objects.hpp"
|
|
|
|
|
2018-08-14 19:05:43 +00:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2018-09-22 08:57:50 +00:00
|
|
|
#include <components/esm/loadcont.hpp>
|
2015-07-29 18:15:06 +00:00
|
|
|
|
2013-03-31 22:29:41 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2018-09-22 08:57:50 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2013-03-31 22:29:41 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2019-02-18 22:10:55 +00:00
|
|
|
#include "character.hpp"
|
2016-06-17 14:07:16 +00:00
|
|
|
#include "movement.hpp"
|
|
|
|
|
2013-03-31 22:29:41 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
|
|
|
|
Objects::Objects()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-30 20:47:06 +00:00
|
|
|
Objects::~Objects()
|
|
|
|
{
|
2020-07-25 11:54:49 +00:00
|
|
|
for(auto& object : mObjects)
|
2013-12-30 20:47:06 +00:00
|
|
|
{
|
2020-07-25 11:54:49 +00:00
|
|
|
delete object.second;
|
|
|
|
object.second = nullptr;
|
2013-12-30 20:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-31 22:29:41 +00:00
|
|
|
void Objects::addObject(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
2013-07-18 04:39:21 +00:00
|
|
|
removeObject(ptr);
|
|
|
|
|
2013-03-31 22:29:41 +00:00
|
|
|
MWRender::Animation *anim = MWBase::Environment::get().getWorld()->getAnimation(ptr);
|
2017-02-12 09:22:11 +00:00
|
|
|
if(anim) mObjects.insert(std::make_pair(ptr, new CharacterController(ptr, anim)));
|
2013-03-31 22:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Objects::removeObject(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
PtrControllerMap::iterator iter = mObjects.find(ptr);
|
|
|
|
if(iter != mObjects.end())
|
2013-07-16 06:47:04 +00:00
|
|
|
{
|
|
|
|
delete iter->second;
|
2013-03-31 22:29:41 +00:00
|
|
|
mObjects.erase(iter);
|
2013-07-16 06:47:04 +00:00
|
|
|
}
|
2013-03-31 22:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Objects::updateObject(const MWWorld::Ptr &old, const MWWorld::Ptr &ptr)
|
|
|
|
{
|
|
|
|
PtrControllerMap::iterator iter = mObjects.find(old);
|
|
|
|
if(iter != mObjects.end())
|
|
|
|
{
|
2013-07-16 06:47:04 +00:00
|
|
|
CharacterController *ctrl = iter->second;
|
2013-03-31 22:29:41 +00:00
|
|
|
mObjects.erase(iter);
|
|
|
|
|
2013-07-16 06:47:04 +00:00
|
|
|
ctrl->updatePtr(ptr);
|
2013-03-31 22:29:41 +00:00
|
|
|
mObjects.insert(std::make_pair(ptr, ctrl));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-05 12:21:26 +00:00
|
|
|
void Objects::dropObjects (const MWWorld::CellStore *cellStore)
|
2013-03-31 22:29:41 +00:00
|
|
|
{
|
|
|
|
PtrControllerMap::iterator iter = mObjects.begin();
|
|
|
|
while(iter != mObjects.end())
|
|
|
|
{
|
|
|
|
if(iter->first.getCell()==cellStore)
|
2013-07-16 06:47:04 +00:00
|
|
|
{
|
|
|
|
delete iter->second;
|
2013-03-31 22:29:41 +00:00
|
|
|
mObjects.erase(iter++);
|
2013-07-16 06:47:04 +00:00
|
|
|
}
|
2013-03-31 22:29:41 +00:00
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Objects::update(float duration, bool paused)
|
|
|
|
{
|
|
|
|
if(!paused)
|
|
|
|
{
|
2020-07-25 11:54:49 +00:00
|
|
|
for(auto& object : mObjects)
|
|
|
|
object.second->update(duration);
|
2013-03-31 22:29:41 +00:00
|
|
|
}
|
2018-09-22 08:57:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// We still should play container opening animation in the Container GUI mode.
|
|
|
|
MWGui::GuiMode mode = MWBase::Environment::get().getWindowManager()->getMode();
|
|
|
|
if(mode != MWGui::GM_Container)
|
|
|
|
return;
|
|
|
|
|
2020-07-25 11:54:49 +00:00
|
|
|
for(auto& object : mObjects)
|
2018-09-22 08:57:50 +00:00
|
|
|
{
|
2020-07-25 11:54:49 +00:00
|
|
|
if (object.first.getTypeName() != typeid(ESM::Container).name())
|
2018-09-22 08:57:50 +00:00
|
|
|
continue;
|
|
|
|
|
2020-07-25 11:54:49 +00:00
|
|
|
if (object.second->isAnimPlaying("containeropen"))
|
2018-09-22 08:57:50 +00:00
|
|
|
{
|
2020-07-25 11:54:49 +00:00
|
|
|
object.second->update(duration);
|
|
|
|
MWBase::Environment::get().getWorld()->updateAnimatedCollisionShape(object.first);
|
2018-09-22 08:57:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Objects::onOpen(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
PtrControllerMap::iterator iter = mObjects.find(ptr);
|
|
|
|
if(iter != mObjects.end())
|
|
|
|
return iter->second->onOpen();
|
2019-07-19 21:12:05 +00:00
|
|
|
return true;
|
2018-09-22 08:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Objects::onClose(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
PtrControllerMap::iterator iter = mObjects.find(ptr);
|
|
|
|
if(iter != mObjects.end())
|
|
|
|
iter->second->onClose();
|
2013-03-31 22:29:41 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 17:24:03 +00:00
|
|
|
bool Objects::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist)
|
2013-03-31 22:29:41 +00:00
|
|
|
{
|
|
|
|
PtrControllerMap::iterator iter = mObjects.find(ptr);
|
|
|
|
if(iter != mObjects.end())
|
2015-07-29 18:15:06 +00:00
|
|
|
{
|
2016-07-30 17:24:03 +00:00
|
|
|
return iter->second->playGroup(groupName, mode, number, persist);
|
2015-07-29 18:15:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-14 19:05:43 +00:00
|
|
|
Log(Debug::Warning) << "Warning: Objects::playAnimationGroup: Unable to find " << ptr.getCellRef().getRefId();
|
2015-07-29 18:15:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-03-31 22:29:41 +00:00
|
|
|
}
|
|
|
|
void Objects::skipAnimation(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
PtrControllerMap::iterator iter = mObjects.find(ptr);
|
|
|
|
if(iter != mObjects.end())
|
2013-07-16 06:47:04 +00:00
|
|
|
iter->second->skipAnim();
|
2013-03-31 22:29:41 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 17:24:03 +00:00
|
|
|
void Objects::persistAnimationStates()
|
|
|
|
{
|
|
|
|
for (PtrControllerMap::iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
|
|
|
|
iter->second->persistAnimationState();
|
|
|
|
}
|
|
|
|
|
2015-06-01 19:41:13 +00:00
|
|
|
void Objects::getObjectsInRange(const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out)
|
2014-01-20 12:00:43 +00:00
|
|
|
{
|
|
|
|
for (PtrControllerMap::iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
|
|
|
|
{
|
2015-06-01 19:41:13 +00:00
|
|
|
if ((position - iter->first.getRefData().getPosition().asVec3()).length2() <= radius*radius)
|
2014-01-20 12:00:43 +00:00
|
|
|
out.push_back(iter->first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-31 22:29:41 +00:00
|
|
|
}
|