1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +00:00
Bo Svensson ef906cbfa8
improves MWClass mapping (#3166)
Currently, we use a peculiar mapping of ESM classes by their std::type_info::name. This mapping is an undefined behaviour because std::type_info::name is strictly implementation defined. It could return a non-unique value on some platforms. With this PR we use the unsigned int sRecordId of the ESM class as a more efficient lookup type that does not build on undefined behaviour. We can expect marginally faster save-game loading with these changes as well.
2021-10-11 13:46:21 +02:00

90 lines
1.7 KiB
C++

#include "ptr.hpp"
#include <cassert>
#include "containerstore.hpp"
#include "class.hpp"
#include "livecellref.hpp"
unsigned int MWWorld::Ptr::getType() const
{
if(mRef != nullptr)
return mRef->mClass->getType();
throw std::runtime_error("Can't get type name from an empty object.");
}
MWWorld::LiveCellRefBase *MWWorld::Ptr::getBase() const
{
if (!mRef)
throw std::runtime_error ("Can't access cell ref pointed to by null Ptr");
return mRef;
}
MWWorld::CellRef& MWWorld::Ptr::getCellRef() const
{
assert(mRef);
return mRef->mRef;
}
MWWorld::RefData& MWWorld::Ptr::getRefData() const
{
assert(mRef);
return mRef->mData;
}
void MWWorld::Ptr::setContainerStore (ContainerStore *store)
{
assert (store);
assert (!mCell);
mContainerStore = store;
}
MWWorld::ContainerStore *MWWorld::Ptr::getContainerStore() const
{
return mContainerStore;
}
MWWorld::Ptr::operator const void *()
{
return mRef;
}
// -------------------------------------------------------------------------------
unsigned int MWWorld::ConstPtr::getType() const
{
if(mRef != nullptr)
return mRef->mClass->getType();
throw std::runtime_error("Can't get type name from an empty object.");
}
const MWWorld::LiveCellRefBase *MWWorld::ConstPtr::getBase() const
{
if (!mRef)
throw std::runtime_error ("Can't access cell ref pointed to by null Ptr");
return mRef;
}
void MWWorld::ConstPtr::setContainerStore (const ContainerStore *store)
{
assert (store);
assert (!mCell);
mContainerStore = store;
}
const MWWorld::ContainerStore *MWWorld::ConstPtr::getContainerStore() const
{
return mContainerStore;
}
MWWorld::ConstPtr::operator const void *()
{
return mRef;
}