1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 06:53:53 +00:00

optimize moveItem() by unsetting refnum instead of calling unstackItem.

This commit is contained in:
Mads Buvik Sandvei 2023-07-17 15:10:54 +02:00
parent 64e55b37ec
commit e22eec0585

View file

@ -2,6 +2,7 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwworld/worldmodel.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
@ -58,10 +59,15 @@ namespace MWGui
MWWorld::Ptr ItemModel::moveItem(const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip) MWWorld::Ptr ItemModel::moveItem(const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip)
{ {
MWWorld::Ptr ret = otherModel->addItem(item, count, allowAutoEquip); MWWorld::Ptr ret = otherModel->addItem(item, count, allowAutoEquip);
// Unstacking here ensures that new a refnum is assigned to the leftover stack if there is a leftover.
// Otherwise we end up with duplicated instances.
unstackItem(item, count);
removeItem(item, count); removeItem(item, count);
// Although logically the same as an unstack, to avoid unneccesarily allocating a new stack
// and then immediately removing it, we assign a new refnum here instead of calling unstack()
if (!item.mBase.getRefData().isDeleted())
{
ret.getCellRef().unsetRefNum();
ret.getRefData().setLuaScripts(nullptr);
MWBase::Environment::get().getWorldModel()->registerPtr(ret);
}
return ret; return ret;
} }