1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
OpenMW/apps/openmw/mwlua/worldview.cpp

77 lines
1.8 KiB
C++
Raw Normal View History

2020-12-18 23:21:10 +01:00
#include "worldview.hpp"
#include "../mwworld/class.hpp"
2021-03-12 18:29:51 +01:00
#include "../mwworld/timestamp.hpp"
2020-12-18 23:21:10 +01:00
namespace MWLua
{
void WorldView::update()
{
mObjectRegistry.update();
mActorsInScene.updateList();
mItemsInScene.updateList();
}
void WorldView::clear()
{
mObjectRegistry.clear();
mActorsInScene.clear();
mItemsInScene.clear();
}
void WorldView::objectAddedToScene(const MWWorld::Ptr& ptr)
{
if (ptr.getClass().isActor())
addToGroup(mActorsInScene, ptr);
else
addToGroup(mItemsInScene, ptr);
}
void WorldView::objectRemovedFromScene(const MWWorld::Ptr& ptr)
{
if (ptr.getClass().isActor())
removeFromGroup(mActorsInScene, ptr);
else
removeFromGroup(mItemsInScene, ptr);
}
2021-03-12 18:29:51 +01:00
double WorldView::getGameTimeInHours() const
{
MWBase::World* world = MWBase::Environment::get().getWorld();
MWWorld::TimeStamp timeStamp = world->getTimeStamp();
return static_cast<double>(timeStamp.getDay()) * 24 + timeStamp.getHour();
}
2020-12-18 23:21:10 +01:00
void WorldView::ObjectGroup::updateList()
{
if (mChanged)
{
mList->clear();
for (const ObjectId& id : mSet)
mList->push_back(id);
mChanged = false;
}
}
void WorldView::ObjectGroup::clear()
{
mChanged = false;
mList->clear();
mSet.clear();
}
void WorldView::addToGroup(ObjectGroup& group, const MWWorld::Ptr& ptr)
{
group.mSet.insert(getId(ptr));
group.mChanged = true;
}
void WorldView::removeFromGroup(ObjectGroup& group, const MWWorld::Ptr& ptr)
{
group.mSet.erase(getId(ptr));
group.mChanged = true;
}
}