1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-31 05:36:40 +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);
}
std::string_view ActorAdapter::ActorData::getPart(ESM::PartReferenceType index) const
ESM::RefId ActorAdapter::ActorData::getPart(ESM::PartReferenceType index) const
{
auto it = mParts.find(index);
if (it == mParts.end())
@ -146,12 +146,11 @@ namespace CSMWorld
if (mFemale)
{
// Note: we should use male parts for females as fallback
const std::string& femalePart = mRaceData->getFemalePart(index).getRefIdString();
if (!femalePart.empty())
if (const ESM::RefId femalePart = mRaceData->getFemalePart(index); !femalePart.empty())
return femalePart;
}
return mRaceData->getMalePart(index).getRefIdString();
return mRaceData->getMalePart(index);
}
return {};
@ -174,7 +173,7 @@ namespace CSMWorld
return;
}
mParts[index] = std::make_pair(partId.getRefIdString(), priority);
mParts[index] = std::make_pair(partId, priority);
addOtherDependency(partId);
}

View file

@ -35,7 +35,7 @@ namespace CSMWorld
Q_OBJECT
public:
/// 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
using RacePartList = std::array<ESM::RefId, ESM::BodyPart::MP_Count>;
/// Tracks unique strings
@ -95,7 +95,7 @@ namespace CSMWorld
/// Returns the skeleton the actor should use for attaching parts to
std::string getSkeleton() const;
/// 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
bool hasDependency(const ESM::RefId& id) const;

View file

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

View file

@ -51,7 +51,7 @@ namespace CSVRender
void loadBodyParts();
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;