Merge branch 'optimize_add_item' into 'master'

Optimize ContainerStore::stacks (attempt #2)

See merge request OpenMW/openmw!1200
pull/3096/head
psi29a 3 years ago
commit aef6ec464c

@ -71,7 +71,7 @@ namespace MWLua
else
{
const std::string& recordId = std::get<std::string>(item);
if (old_it != store.end() && *old_it->getCellRef().getRefIdPtr() == recordId)
if (old_it != store.end() && old_it->getCellRef().getRefIdRef() == recordId)
return true; // already equipped
itemPtr = store.search(recordId);
if (itemPtr.isEmpty() || itemPtr.getRefData().getCount() == 0)

@ -284,7 +284,7 @@ namespace MWLua
std::shared_ptr<LocalScripts> scripts;
// When loading a game, it can be called before LuaManager::setPlayer,
// so we can't just check ptr == mPlayer here.
if (*ptr.getCellRef().getRefIdPtr() == "player")
if (ptr.getCellRef().getRefIdRef() == "player")
{
scripts = std::make_shared<PlayerScripts>(&mLua, LObject(getId(ptr), mWorldView.getObjectRegistry()));
scripts->addPackage("openmw.ui", mUserInterfacePackage);

@ -51,13 +51,13 @@ namespace MWLua
bool isMarker(const MWWorld::Ptr& ptr)
{
std::string_view id = *ptr.getCellRef().getRefIdPtr();
std::string_view id = ptr.getCellRef().getRefIdRef();
return id == "prisonmarker" || id == "divinemarker" || id == "templemarker" || id == "northmarker";
}
std::string_view getMWClassName(const MWWorld::Ptr& ptr)
{
if (*ptr.getCellRef().getRefIdPtr() == "player")
if (ptr.getCellRef().getRefIdRef() == "player")
return "Player";
if (isMarker(ptr))
return "Marker";
@ -71,7 +71,7 @@ namespace MWLua
res.append(" (");
res.append(getMWClassName(ptr));
res.append(", ");
res.append(*ptr.getCellRef().getRefIdPtr());
res.append(ptr.getCellRef().getRefIdRef());
res.append(")");
return res;
}

@ -48,11 +48,6 @@ namespace MWWorld
return mCellRef.mRefID;
}
const std::string* CellRef::getRefIdPtr() const
{
return &mCellRef.mRefID;
}
bool CellRef::getTeleport() const
{
return mCellRef.mTeleport;

@ -38,8 +38,8 @@ namespace MWWorld
// Id of object being referenced
std::string getRefId() const;
// Pointer to ID of the object being referenced
const std::string* getRefIdPtr() const;
// Reference to ID of the object being referenced
const std::string& getRefIdRef() const { return mCellRef.mRefID; }
// For doors - true if this door teleports to somewhere else, false
// if it should open through animation.

@ -36,7 +36,7 @@ namespace
}
bool cont = cell.second.forEach([&] (MWWorld::Ptr ptr)
{
if(*ptr.getCellRef().getRefIdPtr() == id)
if (ptr.getCellRef().getRefIdRef() == id)
{
return visitor(ptr);
}

@ -181,7 +181,7 @@ namespace
{
for (typename MWWorld::CellRefList<T>::List::iterator iter (collection.mList.begin());
iter!=collection.mList.end(); ++iter)
if (iter->mRef.getRefNum()==state.mRef.mRefNum && *iter->mRef.getRefIdPtr() == state.mRef.mRefID)
if (iter->mRef.getRefNum()==state.mRef.mRefNum && iter->mRef.getRefIdRef() == state.mRef.mRefID)
{
// overwrite existing reference
float oldscale = iter->mRef.getScale();
@ -417,7 +417,7 @@ namespace MWWorld
const std::string *mIdToFind;
bool operator()(const PtrType& ptr)
{
if (*ptr.getCellRef().getRefIdPtr() == *mIdToFind)
if (ptr.getCellRef().getRefIdRef() == *mIdToFind)
{
mFound = ptr;
return false;

@ -184,7 +184,7 @@ int MWWorld::ContainerStore::count(const std::string &id) const
{
int total=0;
for (const auto&& iter : *this)
if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefId(), id))
if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefIdRef(), id))
total += iter.getRefData().getCount();
return total;
}
@ -249,7 +249,7 @@ bool MWWorld::ContainerStore::stacks(const ConstPtr& ptr1, const ConstPtr& ptr2)
const MWWorld::Class& cls1 = ptr1.getClass();
const MWWorld::Class& cls2 = ptr2.getClass();
if (!Misc::StringUtils::ciEqual(ptr1.getCellRef().getRefId(), ptr2.getCellRef().getRefId()))
if (!Misc::StringUtils::ciEqual(ptr1.getCellRef().getRefIdRef(), ptr2.getCellRef().getRefIdRef()))
return false;
// If it has an enchantment, don't stack when some of the charge is already used
@ -364,7 +364,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addImp (const Ptr& ptr,
for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter)
{
if (Misc::StringUtils::ciEqual((*iter).getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId))
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefIdRef(), MWWorld::ContainerStore::sGoldId))
{
iter->getRefData().setCount(addItems(iter->getRefData().getCount(false), realCount));
flagAsModified();
@ -465,7 +465,7 @@ int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const
int toRemove = count;
for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter)
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId))
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefIdRef(), itemId))
toRemove -= remove(*iter, toRemove, actor, equipReplacement, resolveFirst);
flagAsModified();
@ -740,7 +740,7 @@ MWWorld::Ptr MWWorld::ContainerStore::findReplacement(const std::string& id)
for (auto&& iter : *this)
{
int iterHealth = iter.getClass().hasItemHealth(iter) ? iter.getClass().getItemHealth(iter) : 1;
if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefId(), id))
if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefIdRef(), id))
{
// Prefer the stack with the lowest remaining uses
// Try to get item with zero durability only if there are no other items found

Loading…
Cancel
Save