1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-23 19:11:33 +00:00

Cache cell description

It should not change over time and it's relatively small enough to trade some
CPU time for some memory.
This commit is contained in:
elsid 2023-07-30 15:46:33 +02:00
parent d2f16774d9
commit 385dab3df3
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
2 changed files with 10 additions and 15 deletions

View file

@ -22,13 +22,15 @@ namespace MWWorld
, mRegion(ESM::RefId()) // Unimplemented for now , mRegion(ESM::RefId()) // Unimplemented for now
, mId(cell.mId) , mId(cell.mId)
, mParent(cell.mParent) , mParent(cell.mParent)
,mMood{ , mWaterHeight(cell.mWaterHeight)
, mDescription(cell.mEditorId)
, mMood{
.mAmbiantColor = cell.mLighting.ambient, .mAmbiantColor = cell.mLighting.ambient,
.mDirectionalColor = cell.mLighting.directional, .mDirectionalColor = cell.mLighting.directional,
.mFogColor = cell.mLighting.fogColor, .mFogColor = cell.mLighting.fogColor,
// TODO: use ESM4::Lighting fog parameters // TODO: use ESM4::Lighting fog parameters
.mFogDensity = 1.f,} .mFogDensity = 1.f,
,mWaterHeight(cell.mWaterHeight) }
{ {
if (isExterior()) if (isExterior())
{ {
@ -50,26 +52,19 @@ namespace MWWorld
, mRegion(cell.mRegion) , mRegion(cell.mRegion)
, mId(cell.mId) , mId(cell.mId)
, mParent(ESM::Cell::sDefaultWorldspaceId) , mParent(ESM::Cell::sDefaultWorldspaceId)
, mWaterHeight(cell.mWater)
, mDescription(cell.getDescription())
, mMood{ , mMood{
.mAmbiantColor = cell.mAmbi.mAmbient, .mAmbiantColor = cell.mAmbi.mAmbient,
.mDirectionalColor = cell.mAmbi.mSunlight, .mDirectionalColor = cell.mAmbi.mSunlight,
.mFogColor = cell.mAmbi.mFog, .mFogColor = cell.mAmbi.mFog,
.mFogDensity = cell.mAmbi.mFogDensity, .mFogDensity = cell.mAmbi.mFogDensity,
} }
,mWaterHeight(cell.mWater)
{ {
if (isExterior()) if (isExterior())
mWaterHeight = -1.f; mWaterHeight = -1.f;
} }
std::string Cell::getDescription() const
{
return ESM::visit(ESM::VisitOverload{
[&](const ESM::Cell& cell) { return cell.getDescription(); },
[&](const ESM4::Cell& cell) { return cell.mEditorId; },
},
*this);
}
ESM::RefId Cell::getWorldSpace() const ESM::RefId Cell::getWorldSpace() const
{ {
if (isExterior()) if (isExterior())

View file

@ -44,7 +44,7 @@ namespace MWWorld
const ESM::RefId& getRegion() const { return mRegion; } const ESM::RefId& getRegion() const { return mRegion; }
std::string_view getNameId() const { return mNameID; } std::string_view getNameId() const { return mNameID; }
std::string_view getDisplayName() const { return mDisplayname; } std::string_view getDisplayName() const { return mDisplayname; }
std::string getDescription() const; std::string_view getDescription() const { return mDescription; }
const MoodData& getMood() const { return mMood; } const MoodData& getMood() const { return mMood; }
float getWaterHeight() const { return mWaterHeight; } float getWaterHeight() const { return mWaterHeight; }
const ESM::RefId& getId() const { return mId; } const ESM::RefId& getId() const { return mId; }
@ -63,9 +63,9 @@ namespace MWWorld
ESM::RefId mRegion; ESM::RefId mRegion;
ESM::RefId mId; ESM::RefId mId;
ESM::RefId mParent; ESM::RefId mParent;
MoodData mMood;
float mWaterHeight; float mWaterHeight;
std::string mDescription;
MoodData mMood;
}; };
} }