1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 12:32:36 +00:00
OpenMW/apps/openmw/mwworld/manualref.cpp
florent.teppe 65cdd489fb create a specific esm reader function for RefID to avoid allocation for string and then again for RefId
Fixed some types

removed useless header

applied clang format

fixed compile tests

fixed clang tidy, and closer to logic before this MR

Removed hardcoded refids

unless there is a returned value we don't use static RefIds
can use == between RefId and hardcoded string

Fix clang format

Fixed a few instances where std::string was used, when only const std::string& was needed

removed unused variable
2022-12-27 19:15:57 +01:00

102 lines
3.3 KiB
C++

#include "manualref.hpp"
#include <components/esm/records.hpp>
#include "esmstore.hpp"
namespace
{
template <typename T>
void create(const MWWorld::Store<T>& list, const ESM::RefId& name, std::any& refValue, MWWorld::Ptr& ptrValue)
{
const T* base = list.find(name);
ESM::CellRef cellRef;
cellRef.blank();
cellRef.mRefID = name;
MWWorld::LiveCellRef<T> ref(cellRef, base);
refValue = ref;
ptrValue = MWWorld::Ptr(&std::any_cast<MWWorld::LiveCellRef<T>&>(refValue), nullptr);
}
}
MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& name, const int count)
{
switch (store.find(name))
{
case ESM::REC_ACTI:
create(store.get<ESM::Activator>(), name, mRef, mPtr);
break;
case ESM::REC_ALCH:
create(store.get<ESM::Potion>(), name, mRef, mPtr);
break;
case ESM::REC_APPA:
create(store.get<ESM::Apparatus>(), name, mRef, mPtr);
break;
case ESM::REC_ARMO:
create(store.get<ESM::Armor>(), name, mRef, mPtr);
break;
case ESM::REC_BOOK:
create(store.get<ESM::Book>(), name, mRef, mPtr);
break;
case ESM::REC_CLOT:
create(store.get<ESM::Clothing>(), name, mRef, mPtr);
break;
case ESM::REC_CONT:
create(store.get<ESM::Container>(), name, mRef, mPtr);
break;
case ESM::REC_CREA:
create(store.get<ESM::Creature>(), name, mRef, mPtr);
break;
case ESM::REC_DOOR:
create(store.get<ESM::Door>(), name, mRef, mPtr);
break;
case ESM::REC_INGR:
create(store.get<ESM::Ingredient>(), name, mRef, mPtr);
break;
case ESM::REC_LEVC:
create(store.get<ESM::CreatureLevList>(), name, mRef, mPtr);
break;
case ESM::REC_LEVI:
create(store.get<ESM::ItemLevList>(), name, mRef, mPtr);
break;
case ESM::REC_LIGH:
create(store.get<ESM::Light>(), name, mRef, mPtr);
break;
case ESM::REC_LOCK:
create(store.get<ESM::Lockpick>(), name, mRef, mPtr);
break;
case ESM::REC_MISC:
create(store.get<ESM::Miscellaneous>(), name, mRef, mPtr);
break;
case ESM::REC_NPC_:
create(store.get<ESM::NPC>(), name, mRef, mPtr);
break;
case ESM::REC_PROB:
create(store.get<ESM::Probe>(), name, mRef, mPtr);
break;
case ESM::REC_REPA:
create(store.get<ESM::Repair>(), name, mRef, mPtr);
break;
case ESM::REC_STAT:
create(store.get<ESM::Static>(), name, mRef, mPtr);
break;
case ESM::REC_WEAP:
create(store.get<ESM::Weapon>(), name, mRef, mPtr);
break;
case ESM::REC_BODY:
create(store.get<ESM::BodyPart>(), name, mRef, mPtr);
break;
case 0:
throw std::logic_error("failed to create manual cell ref for " + name.getRefIdString() + " (unknown ID)");
default:
throw std::logic_error("failed to create manual cell ref for " + name.getRefIdString() + " (unknown type)");
}
mPtr.getRefData().setCount(count);
}