1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-08 17:16:42 +00:00

Use ESM::RefId for actor parts

To avoid redundant conversion RefId to string and back.
This commit is contained in:
elsid 2023-03-03 11:42:30 +01:00
parent 4cb095ce39
commit 419a86f0b9
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
4 changed files with 11 additions and 13 deletions

View file

@ -136,7 +136,7 @@ namespace CSMWorld
return SceneUtil::getActorSkeleton(firstPerson, mFemale, beast, werewolf); return SceneUtil::getActorSkeleton(firstPerson, mFemale, beast, werewolf);
} }
std::string_view ActorAdapter::ActorData::getPart(ESM::PartReferenceType index) const ESM::RefId ActorAdapter::ActorData::getPart(ESM::PartReferenceType index) const
{ {
auto it = mParts.find(index); auto it = mParts.find(index);
if (it == mParts.end()) if (it == mParts.end())
@ -146,12 +146,11 @@ namespace CSMWorld
if (mFemale) if (mFemale)
{ {
// Note: we should use male parts for females as fallback // Note: we should use male parts for females as fallback
const std::string& femalePart = mRaceData->getFemalePart(index).getRefIdString(); if (const ESM::RefId femalePart = mRaceData->getFemalePart(index); !femalePart.empty())
if (!femalePart.empty())
return femalePart; return femalePart;
} }
return mRaceData->getMalePart(index).getRefIdString(); return mRaceData->getMalePart(index);
} }
return {}; return {};
@ -174,7 +173,7 @@ namespace CSMWorld
return; return;
} }
mParts[index] = std::make_pair(partId.getRefIdString(), priority); mParts[index] = std::make_pair(partId, priority);
addOtherDependency(partId); addOtherDependency(partId);
} }

View file

@ -35,7 +35,7 @@ namespace CSMWorld
Q_OBJECT Q_OBJECT
public: public:
/// A list indexed by ESM::PartReferenceType /// A list indexed by ESM::PartReferenceType
using ActorPartList = std::map<ESM::PartReferenceType, std::pair<std::string, int>>; using ActorPartList = std::map<ESM::PartReferenceType, std::pair<ESM::RefId, int>>;
/// A list indexed by ESM::BodyPart::MeshPart /// A list indexed by ESM::BodyPart::MeshPart
using RacePartList = std::array<ESM::RefId, ESM::BodyPart::MP_Count>; using RacePartList = std::array<ESM::RefId, ESM::BodyPart::MP_Count>;
/// Tracks unique strings /// Tracks unique strings
@ -95,7 +95,7 @@ namespace CSMWorld
/// Returns the skeleton the actor should use for attaching parts to /// Returns the skeleton the actor should use for attaching parts to
std::string getSkeleton() const; std::string getSkeleton() const;
/// Retrieves the associated actor part /// Retrieves the associated actor part
std::string_view getPart(ESM::PartReferenceType index) const; ESM::RefId getPart(ESM::PartReferenceType index) const;
/// Checks if the actor has a data dependency /// Checks if the actor has a data dependency
bool hasDependency(const ESM::RefId& id) const; bool hasDependency(const ESM::RefId& id) const;

View file

@ -104,9 +104,8 @@ namespace CSVRender
{ {
for (int i = 0; i < ESM::PRT_Count; ++i) for (int i = 0; i < ESM::PRT_Count; ++i)
{ {
auto type = (ESM::PartReferenceType)i; const auto type = static_cast<ESM::PartReferenceType>(i);
const std::string_view partId = mActorData->getPart(type); attachBodyPart(type, getBodyPartMesh(mActorData->getPart(type)));
attachBodyPart(type, getBodyPartMesh(partId));
} }
} }
@ -124,11 +123,11 @@ namespace CSVRender
} }
} }
std::string Actor::getBodyPartMesh(std::string_view bodyPartId) std::string Actor::getBodyPartMesh(const ESM::RefId& bodyPartId)
{ {
const auto& bodyParts = mData.getBodyParts(); const auto& bodyParts = mData.getBodyParts();
const int index = bodyParts.searchId(ESM::RefId::stringRefId(bodyPartId)); const int index = bodyParts.searchId(bodyPartId);
if (index != -1 && !bodyParts.getRecord(index).isDeleted()) if (index != -1 && !bodyParts.getRecord(index).isDeleted())
return MeshPrefix + bodyParts.getRecord(index).get().mModel; return MeshPrefix + bodyParts.getRecord(index).get().mModel;
else else

View file

@ -51,7 +51,7 @@ namespace CSVRender
void loadBodyParts(); void loadBodyParts();
void attachBodyPart(ESM::PartReferenceType, const std::string& mesh); void attachBodyPart(ESM::PartReferenceType, const std::string& mesh);
std::string getBodyPartMesh(std::string_view bodyPartId); std::string getBodyPartMesh(const ESM::RefId& bodyPartId);
static const std::string MeshPrefix; static const std::string MeshPrefix;