diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index a86c3f07c8..7238c84aec 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -3401,7 +3401,7 @@ namespace MWWorld void World::rest(double hours) { - mWorldModel.rest(hours); + mWorldModel.forEachLoadedCellStore([hours](CellStore& store) { store.rest(hours); }); } void World::rechargeItems(double duration, bool activeOnly) @@ -3417,7 +3417,7 @@ namespace MWWorld } } else - mWorldModel.recharge(duration); + mWorldModel.forEachLoadedCellStore([duration](CellStore& store) { store.recharge(duration); }); } void World::teleportToClosestMarker(const MWWorld::Ptr& ptr, const ESM::RefId& id) diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 3f4370b729..a501c669d1 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -212,32 +212,6 @@ MWWorld::CellStore* MWWorld::WorldModel::getInterior(const ESM::RefId& name) return &result->second; } -void MWWorld::WorldModel::rest(double hours) -{ - for (auto& interior : mInteriors) - { - interior.second.rest(hours); - } - - for (auto& exterior : mExteriors) - { - exterior.second.rest(hours); - } -} - -void MWWorld::WorldModel::recharge(float duration) -{ - for (auto& interior : mInteriors) - { - interior.second.recharge(duration); - } - - for (auto& exterior : mExteriors) - { - exterior.second.recharge(duration); - } -} - MWWorld::CellStore* MWWorld::WorldModel::getCell(const ESM::CellId& id) { if (id.mPaged) diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index 4c481a110d..8c32d55780 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -6,6 +6,7 @@ #include #include +#include "cellstore.hpp" #include "ptr.hpp" namespace ESM @@ -82,8 +83,14 @@ namespace MWWorld Ptr getPtr(const ESM::RefId& id, const ESM::RefNum& refNum); - void rest(double hours); - void recharge(float duration); + template + void forEachLoadedCellStore(Fn&& fn) + { + for (auto& [_, store] : mInteriors) + fn(store); + for (auto& [_, store] : mExteriors) + fn(store); + } /// Get all Ptrs referencing \a name in exterior cells /// @note Due to the current implementation of getPtr this only supports one Ptr per cell.