1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-11 06:40:34 +00:00

comments by elsid

This commit is contained in:
Mads Buvik Sandvei 2024-06-06 11:20:14 +02:00
parent a1b695a8d5
commit 90b415a8dd
2 changed files with 29 additions and 50 deletions

View File

@ -29,79 +29,56 @@ namespace
} }
template <typename F> template <typename F>
void createGeneric(F func, const MWWorld::ESMStore& store, ESM::RefId name) void visitRefStore(const MWWorld::ESMStore& store, ESM::RefId name, F func)
{ {
switch (store.find(name)) switch (store.find(name))
{ {
case ESM::REC_ACTI: case ESM::REC_ACTI:
func(store.get<ESM::Activator>()); return func(store.get<ESM::Activator>());
break;
case ESM::REC_ALCH: case ESM::REC_ALCH:
func(store.get<ESM::Potion>()); return func(store.get<ESM::Potion>());
break;
case ESM::REC_APPA: case ESM::REC_APPA:
func(store.get<ESM::Apparatus>()); return func(store.get<ESM::Apparatus>());
break;
case ESM::REC_ARMO: case ESM::REC_ARMO:
func(store.get<ESM::Armor>()); return func(store.get<ESM::Armor>());
break;
case ESM::REC_BOOK: case ESM::REC_BOOK:
func(store.get<ESM::Book>()); return func(store.get<ESM::Book>());
break;
case ESM::REC_CLOT: case ESM::REC_CLOT:
func(store.get<ESM::Clothing>()); return func(store.get<ESM::Clothing>());
break;
case ESM::REC_CONT: case ESM::REC_CONT:
func(store.get<ESM::Container>()); return func(store.get<ESM::Container>());
break;
case ESM::REC_CREA: case ESM::REC_CREA:
func(store.get<ESM::Creature>()); return func(store.get<ESM::Creature>());
break;
case ESM::REC_DOOR: case ESM::REC_DOOR:
func(store.get<ESM::Door>()); return func(store.get<ESM::Door>());
break;
case ESM::REC_INGR: case ESM::REC_INGR:
func(store.get<ESM::Ingredient>()); return func(store.get<ESM::Ingredient>());
break;
case ESM::REC_LEVC: case ESM::REC_LEVC:
func(store.get<ESM::CreatureLevList>()); return func(store.get<ESM::CreatureLevList>());
break;
case ESM::REC_LEVI: case ESM::REC_LEVI:
func(store.get<ESM::ItemLevList>()); return func(store.get<ESM::ItemLevList>());
break;
case ESM::REC_LIGH: case ESM::REC_LIGH:
func(store.get<ESM::Light>()); return func(store.get<ESM::Light>());
break;
case ESM::REC_LOCK: case ESM::REC_LOCK:
func(store.get<ESM::Lockpick>()); return func(store.get<ESM::Lockpick>());
break;
case ESM::REC_MISC: case ESM::REC_MISC:
func(store.get<ESM::Miscellaneous>()); return func(store.get<ESM::Miscellaneous>());
break;
case ESM::REC_NPC_: case ESM::REC_NPC_:
func(store.get<ESM::NPC>()); return func(store.get<ESM::NPC>());
break;
case ESM::REC_PROB: case ESM::REC_PROB:
func(store.get<ESM::Probe>()); return func(store.get<ESM::Probe>());
break;
case ESM::REC_REPA: case ESM::REC_REPA:
func(store.get<ESM::Repair>()); return func(store.get<ESM::Repair>());
break;
case ESM::REC_STAT: case ESM::REC_STAT:
func(store.get<ESM::Static>()); return func(store.get<ESM::Static>());
break;
case ESM::REC_WEAP: case ESM::REC_WEAP:
func(store.get<ESM::Weapon>()); return func(store.get<ESM::Weapon>());
break;
case ESM::REC_BODY: case ESM::REC_BODY:
func(store.get<ESM::BodyPart>()); return func(store.get<ESM::BodyPart>());
break;
case ESM::REC_STAT4: case ESM::REC_STAT4:
func(store.get<ESM4::Static>()); return func(store.get<ESM4::Static>());
break;
case ESM::REC_TERM4: case ESM::REC_TERM4:
func(store.get<ESM4::Terminal>()); return func(store.get<ESM4::Terminal>());
break;
case 0: case 0:
throw std::logic_error( throw std::logic_error(
"failed to create manual cell ref for " + name.toDebugString() + " (unknown ID)"); "failed to create manual cell ref for " + name.toDebugString() + " (unknown ID)");
@ -116,7 +93,7 @@ namespace
MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& name, const int count) MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& name, const int count)
{ {
auto cb = [&](const auto& store) { create(store, name, mRef, mPtr); }; auto cb = [&](const auto& store) { create(store, name, mRef, mPtr); };
createGeneric(cb, store, name); visitRefStore(store, name, cb);
mPtr.getCellRef().setCount(count); mPtr.getCellRef().setCount(count);
} }
@ -124,7 +101,7 @@ MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId&
MWWorld::ManualRef::ManualRef(const ESMStore& store, const Ptr& template_, const int count) MWWorld::ManualRef::ManualRef(const ESMStore& store, const Ptr& template_, const int count)
{ {
auto cb = [&](const auto& store) { create(store, template_, mRef, mPtr); }; auto cb = [&](const auto& store) { create(store, template_, mRef, mPtr); };
createGeneric(cb, store, template_.getCellRef().getRefId()); visitRefStore(store, template_.getCellRef().getRefId(), cb);
mPtr.getCellRef().setCount(count); mPtr.getCellRef().setCount(count);
mPtr.getCellRef().unsetRefNum(); mPtr.getCellRef().unsetRefNum();

View File

@ -7,9 +7,11 @@
namespace MWWorld namespace MWWorld
{ {
/// \brief Manually constructed live cell ref /// \brief Manually constructed live cell ref. The resulting Ptr shares its lifetime with this ManualRef and must
/// not be used past its end.
class ManualRef class ManualRef
{ {
// Stores the ref (LiveCellRef<T>) by value.
std::any mRef; std::any mRef;
Ptr mPtr; Ptr mPtr;