mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-26 16:06:48 +00:00
Cleanup(Actoradapter.cpp): Create new struct for race stats, use
std::pair instead
This commit is contained in:
parent
b31664a78f
commit
049550d73e
3 changed files with 41 additions and 14 deletions
|
@ -67,6 +67,11 @@ namespace CSMWorld
|
||||||
return mMaleParts[ESM::getMeshPart(index)];
|
return mMaleParts[ESM::getMeshPart(index)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::pair<float, float>& ActorAdapter::RaceData::getRaceAttributes(bool isFemale)
|
||||||
|
{
|
||||||
|
return isFemale == true ? mHeightsWeights.mFemaleAttributes : mHeightsWeights.mMaleAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
bool ActorAdapter::RaceData::hasDependency(const ESM::RefId& id) const
|
bool ActorAdapter::RaceData::hasDependency(const ESM::RefId& id) const
|
||||||
{
|
{
|
||||||
return mDependencies.find(id) != mDependencies.end();
|
return mDependencies.find(id) != mDependencies.end();
|
||||||
|
@ -90,10 +95,11 @@ namespace CSMWorld
|
||||||
mDependencies.emplace(id);
|
mDependencies.emplace(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActorAdapter::RaceData::reset_data(const ESM::RefId& id, bool isBeast)
|
void ActorAdapter::RaceData::reset_data(const ESM::RefId& id, const BodyAttributes& raceStats, bool isBeast)
|
||||||
{
|
{
|
||||||
mId = id;
|
mId = id;
|
||||||
mIsBeast = isBeast;
|
mIsBeast = isBeast;
|
||||||
|
mHeightsWeights = raceStats;
|
||||||
for (auto& str : mFemaleParts)
|
for (auto& str : mFemaleParts)
|
||||||
str = ESM::RefId();
|
str = ESM::RefId();
|
||||||
for (auto& str : mMaleParts)
|
for (auto& str : mMaleParts)
|
||||||
|
@ -163,9 +169,9 @@ namespace CSMWorld
|
||||||
return it->second.first;
|
return it->second.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ESM::RefId& ActorAdapter::ActorData::getActorRaceName() const
|
const std::pair<float, float>& ActorAdapter::ActorData::getRaceHeightWeight() const
|
||||||
{
|
{
|
||||||
return mRaceData->getId();
|
return mRaceData->getRaceAttributes(isFemale());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActorAdapter::ActorData::hasDependency(const ESM::RefId& id) const
|
bool ActorAdapter::ActorData::hasDependency(const ESM::RefId& id) const
|
||||||
|
@ -509,7 +515,11 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& race = raceRecord.get();
|
auto& race = raceRecord.get();
|
||||||
data->reset_data(id, race.mData.mFlags & ESM::Race::Beast);
|
|
||||||
|
BodyAttributes scaleStats = BodyAttributes(
|
||||||
|
race.mData.mMaleHeight, race.mData.mMaleWeight, race.mData.mFemaleHeight, race.mData.mFemaleWeight);
|
||||||
|
|
||||||
|
data->reset_data(id, scaleStats, race.mData.mFlags & ESM::Race::Beast);
|
||||||
|
|
||||||
// Setup body parts
|
// Setup body parts
|
||||||
for (int i = 0; i < mBodyParts.getSize(); ++i)
|
for (int i = 0; i < mBodyParts.getSize(); ++i)
|
||||||
|
|
|
@ -41,6 +41,25 @@ namespace CSMWorld
|
||||||
/// Tracks unique strings
|
/// Tracks unique strings
|
||||||
using RefIdSet = std::unordered_set<ESM::RefId>;
|
using RefIdSet = std::unordered_set<ESM::RefId>;
|
||||||
|
|
||||||
|
class BodyAttributes
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::pair<float, float> mMaleAttributes;
|
||||||
|
std::pair<float, float> mFemaleAttributes;
|
||||||
|
|
||||||
|
BodyAttributes()
|
||||||
|
: mMaleAttributes(std::make_pair(1.0f, 1.0f))
|
||||||
|
, mFemaleAttributes(std::make_pair(1.0f, 1.0f))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BodyAttributes(float maleHeight, float maleWeight, float femaleHeight, float femaleWeight)
|
||||||
|
{
|
||||||
|
mMaleAttributes = std::make_pair(maleHeight, maleWeight);
|
||||||
|
mFemaleAttributes = std::make_pair(femaleHeight, femaleWeight);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/// Contains base race data shared between actors
|
/// Contains base race data shared between actors
|
||||||
class RaceData
|
class RaceData
|
||||||
{
|
{
|
||||||
|
@ -57,6 +76,8 @@ namespace CSMWorld
|
||||||
const ESM::RefId& getFemalePart(ESM::PartReferenceType index) const;
|
const ESM::RefId& getFemalePart(ESM::PartReferenceType index) const;
|
||||||
/// Retrieves the associated body part
|
/// Retrieves the associated body part
|
||||||
const ESM::RefId& getMalePart(ESM::PartReferenceType index) const;
|
const ESM::RefId& getMalePart(ESM::PartReferenceType index) const;
|
||||||
|
|
||||||
|
const std::pair<float, float>& getRaceAttributes(bool isFemale);
|
||||||
/// Checks if the race has a data dependency
|
/// Checks if the race has a data dependency
|
||||||
bool hasDependency(const ESM::RefId& id) const;
|
bool hasDependency(const ESM::RefId& id) const;
|
||||||
|
|
||||||
|
@ -67,7 +88,8 @@ namespace CSMWorld
|
||||||
/// Marks an additional dependency
|
/// Marks an additional dependency
|
||||||
void addOtherDependency(const ESM::RefId& id);
|
void addOtherDependency(const ESM::RefId& id);
|
||||||
/// Clears parts and dependencies
|
/// Clears parts and dependencies
|
||||||
void reset_data(const ESM::RefId& raceId, bool isBeast = false);
|
void reset_data(
|
||||||
|
const ESM::RefId& raceId, const BodyAttributes& raceStats = BodyAttributes(), bool isBeast = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool handles(ESM::PartReferenceType type) const;
|
bool handles(ESM::PartReferenceType type) const;
|
||||||
|
@ -75,6 +97,7 @@ namespace CSMWorld
|
||||||
bool mIsBeast;
|
bool mIsBeast;
|
||||||
RacePartList mFemaleParts;
|
RacePartList mFemaleParts;
|
||||||
RacePartList mMaleParts;
|
RacePartList mMaleParts;
|
||||||
|
BodyAttributes mHeightsWeights;
|
||||||
RefIdSet mDependencies;
|
RefIdSet mDependencies;
|
||||||
};
|
};
|
||||||
using RaceDataPtr = std::shared_ptr<RaceData>;
|
using RaceDataPtr = std::shared_ptr<RaceData>;
|
||||||
|
@ -97,7 +120,7 @@ namespace CSMWorld
|
||||||
/// Retrieves the associated actor part
|
/// Retrieves the associated actor part
|
||||||
ESM::RefId getPart(ESM::PartReferenceType index) const;
|
ESM::RefId getPart(ESM::PartReferenceType index) const;
|
||||||
|
|
||||||
const ESM::RefId& getActorRaceName() const;
|
const std::pair<float, float>& getRaceHeightWeight() 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;
|
||||||
|
|
||||||
|
|
|
@ -63,15 +63,9 @@ namespace CSVRender
|
||||||
// Attach parts to skeleton
|
// Attach parts to skeleton
|
||||||
loadBodyParts();
|
loadBodyParts();
|
||||||
|
|
||||||
const CSMWorld::IdCollection<ESM::Race>& races = mData.getRaces();
|
const std::pair<float, float> attributes = mActorData.get()->getRaceHeightWeight();
|
||||||
const auto& targetRace = races.getRecord(mActorData->getActorRaceName()).get().mData;
|
|
||||||
osg::Vec3d scale;
|
|
||||||
|
|
||||||
mActorData.get()->isFemale()
|
mBaseNode->setScale(osg::Vec3d(attributes.second, attributes.second, attributes.first));
|
||||||
? scale = osg::Vec3(targetRace.mFemaleWeight, targetRace.mFemaleWeight, targetRace.mFemaleHeight)
|
|
||||||
: scale = osg::Vec3(targetRace.mMaleWeight, targetRace.mMaleWeight, targetRace.mMaleHeight);
|
|
||||||
|
|
||||||
mBaseNode->setScale(scale);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue