2023-08-06 16:21:43 +02:00
|
|
|
#include "objectlists.hpp"
|
2020-12-18 23:21:10 +01:00
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/esmreader.hpp>
|
|
|
|
#include <components/esm3/esmwriter.hpp>
|
|
|
|
#include <components/esm3/loadcell.hpp>
|
2021-01-29 02:38:09 +01:00
|
|
|
|
2023-03-05 21:47:49 +01:00
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
|
|
|
|
2023-08-06 14:46:15 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2021-12-14 00:51:18 +01:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
|
2021-01-29 01:54:54 +01:00
|
|
|
#include "../mwclass/container.hpp"
|
|
|
|
|
2020-12-18 23:21:10 +01:00
|
|
|
#include "../mwworld/class.hpp"
|
2022-12-06 00:11:19 +01:00
|
|
|
#include "../mwworld/worldmodel.hpp"
|
2020-12-18 23:21:10 +01:00
|
|
|
|
|
|
|
namespace MWLua
|
|
|
|
{
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
void ObjectLists::update()
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
2021-01-29 01:54:54 +01:00
|
|
|
mActivatorsInScene.updateList();
|
2020-12-18 23:21:10 +01:00
|
|
|
mActorsInScene.updateList();
|
2021-01-29 01:54:54 +01:00
|
|
|
mContainersInScene.updateList();
|
|
|
|
mDoorsInScene.updateList();
|
2020-12-18 23:21:10 +01:00
|
|
|
mItemsInScene.updateList();
|
|
|
|
}
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
void ObjectLists::clear()
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
2021-01-29 01:54:54 +01:00
|
|
|
mActivatorsInScene.clear();
|
2020-12-18 23:21:10 +01:00
|
|
|
mActorsInScene.clear();
|
2021-01-29 01:54:54 +01:00
|
|
|
mContainersInScene.clear();
|
|
|
|
mDoorsInScene.clear();
|
2020-12-18 23:21:10 +01:00
|
|
|
mItemsInScene.clear();
|
|
|
|
}
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
ObjectLists::ObjectGroup* ObjectLists::chooseGroup(const MWWorld::Ptr& ptr)
|
2021-01-29 01:54:54 +01:00
|
|
|
{
|
2021-04-17 11:50:20 +02:00
|
|
|
// It is important to check `isMarker` first.
|
|
|
|
// For example "prisonmarker" has class "Door" despite that it is only an invisible marker.
|
2023-03-05 21:47:49 +01:00
|
|
|
if (Misc::ResourceHelpers::isHiddenMarker(ptr.getCellRef().getRefId()))
|
2021-04-17 11:50:20 +02:00
|
|
|
return nullptr;
|
2021-01-29 01:54:54 +01:00
|
|
|
const MWWorld::Class& cls = ptr.getClass();
|
|
|
|
if (cls.isActivator())
|
|
|
|
return &mActivatorsInScene;
|
|
|
|
if (cls.isActor())
|
|
|
|
return &mActorsInScene;
|
2023-05-25 01:39:51 +02:00
|
|
|
if (ptr.mRef->getType() == ESM::REC_DOOR || ptr.mRef->getType() == ESM::REC_DOOR4)
|
2021-01-29 01:54:54 +01:00
|
|
|
return &mDoorsInScene;
|
|
|
|
if (typeid(cls) == typeid(MWClass::Container))
|
|
|
|
return &mContainersInScene;
|
2023-07-04 08:48:35 +02:00
|
|
|
if (cls.isItem(ptr) || ptr.mRef->getType() == ESM::REC_LIGH)
|
2021-01-29 01:54:54 +01:00
|
|
|
return &mItemsInScene;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
void ObjectLists::objectAddedToScene(const MWWorld::Ptr& ptr)
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
2023-05-30 21:44:54 +02:00
|
|
|
MWBase::Environment::get().getWorldModel()->registerPtr(ptr);
|
2021-01-29 01:54:54 +01:00
|
|
|
ObjectGroup* group = chooseGroup(ptr);
|
|
|
|
if (group)
|
|
|
|
addToGroup(*group, ptr);
|
2020-12-18 23:21:10 +01:00
|
|
|
}
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
void ObjectLists::objectRemovedFromScene(const MWWorld::Ptr& ptr)
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
2021-01-29 01:54:54 +01:00
|
|
|
ObjectGroup* group = chooseGroup(ptr);
|
|
|
|
if (group)
|
|
|
|
removeFromGroup(*group, ptr);
|
2020-12-18 23:21:10 +01:00
|
|
|
}
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
void ObjectLists::ObjectGroup::updateList()
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
|
|
|
if (mChanged)
|
|
|
|
{
|
|
|
|
mList->clear();
|
2023-09-15 19:38:09 +02:00
|
|
|
for (ObjectId id : mSet)
|
2020-12-18 23:21:10 +01:00
|
|
|
mList->push_back(id);
|
|
|
|
mChanged = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
void ObjectLists::ObjectGroup::clear()
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
|
|
|
mChanged = false;
|
|
|
|
mList->clear();
|
|
|
|
mSet.clear();
|
|
|
|
}
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
void ObjectLists::addToGroup(ObjectGroup& group, const MWWorld::Ptr& ptr)
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
|
|
|
group.mSet.insert(getId(ptr));
|
|
|
|
group.mChanged = true;
|
|
|
|
}
|
|
|
|
|
2023-08-06 16:21:43 +02:00
|
|
|
void ObjectLists::removeFromGroup(ObjectGroup& group, const MWWorld::Ptr& ptr)
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
|
|
|
group.mSet.erase(getId(ptr));
|
|
|
|
group.mChanged = true;
|
|
|
|
}
|
|
|
|
}
|