Skip to content

Commit

Permalink
Merge branch 'vfs_normalized_path_9' into 'master'
Browse files Browse the repository at this point in the history
Use normalized path for models settings (#8138)

See merge request OpenMW/openmw!4348
  • Loading branch information
psi29a committed Sep 2, 2024
2 parents ba18b81 + 9e36b3f commit 89976a9
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 62 deletions.
5 changes: 2 additions & 3 deletions apps/openmw/mwclass/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,11 @@ namespace MWClass
{
const MWWorld::LiveCellRef<ESM::NPC>* ref = ptr.get<ESM::NPC>();

const std::string& model = Settings::models().mBaseanim;
const ESM::Race* race = MWBase::Environment::get().getESMStore()->get<ESM::Race>().find(ref->mBase->mRace);
if (race->mData.mFlags & ESM::Race::Beast)
return Settings::models().mBaseanimkna;
return Settings::models().mBaseanimkna.get().value();

return model;
return Settings::models().mBaseanim.get().value();
}

void Npc::getModelsToPreload(const MWWorld::ConstPtr& ptr, std::vector<std::string_view>& models) const
Expand Down
16 changes: 8 additions & 8 deletions apps/openmw/mwrender/actorutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ namespace MWRender
if (!firstPerson)
{
if (isWerewolf)
return Settings::models().mWolfskin;
return Settings::models().mWolfskin.get().value();
else if (isBeast)
return Settings::models().mBaseanimkna;
return Settings::models().mBaseanimkna.get().value();
else if (isFemale)
return Settings::models().mBaseanimfemale;
return Settings::models().mBaseanimfemale.get().value();
else
return Settings::models().mBaseanim;
return Settings::models().mBaseanim.get().value();
}
else
{
if (isWerewolf)
return Settings::models().mWolfskin1st;
return Settings::models().mWolfskin1st.get().value();
else if (isBeast)
return Settings::models().mBaseanimkna1st;
return Settings::models().mBaseanimkna1st.get().value();
else if (isFemale)
return Settings::models().mBaseanimfemale1st;
return Settings::models().mBaseanimfemale1st.get().value();
else
return Settings::models().mXbaseanim1st;
return Settings::models().mXbaseanim1st.get().value();
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ namespace MWRender
MWWorld::LiveCellRef<ESM::Creature>* ref = mPtr.get<ESM::Creature>();
if (ref->mBase->mFlags & ESM::Creature::Bipedal)
{
defaultSkeleton = Settings::models().mXbaseanim;
defaultSkeleton = Settings::models().mXbaseanim.get().value();
inject = true;
}
}
Expand Down
5 changes: 2 additions & 3 deletions apps/openmw/mwrender/npcanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ namespace MWRender

if (!is1stPerson)
{
const std::string& base = Settings::models().mXbaseanim;
const std::string& base = Settings::models().mXbaseanim.get().value();
if (!isWerewolf)
addAnimSource(base, smodel);

Expand All @@ -521,9 +521,8 @@ namespace MWRender
}
else
{
const std::string& base = Settings::models().mXbaseanim1st;
if (!isWerewolf)
addAnimSource(base, smodel);
addAnimSource(Settings::models().mXbaseanim1st.get().value(), smodel);

if (!isBase)
addAnimSource(smodel, smodel);
Expand Down
18 changes: 9 additions & 9 deletions apps/openmw/mwrender/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,22 @@ namespace MWRender
{
try
{
for (std::vector<std::string>::const_iterator it = mModels.begin(); it != mModels.end(); ++it)
mResourceSystem->getSceneManager()->getTemplate(*it);
for (std::vector<std::string>::const_iterator it = mTextures.begin(); it != mTextures.end(); ++it)
mResourceSystem->getImageManager()->getImage(*it);
for (std::vector<std::string>::const_iterator it = mKeyframes.begin(); it != mKeyframes.end(); ++it)
mResourceSystem->getKeyframeManager()->get(*it);
for (const VFS::Path::Normalized& v : mModels)
mResourceSystem->getSceneManager()->getTemplate(v);
for (const VFS::Path::Normalized& v : mTextures)
mResourceSystem->getImageManager()->getImage(v);
for (const VFS::Path::Normalized& v : mKeyframes)
mResourceSystem->getKeyframeManager()->get(v);
}
catch (const std::exception& e)
{
Log(Debug::Warning) << "Failed to preload common assets: " << e.what();
}
}

std::vector<std::string> mModels;
std::vector<std::string> mTextures;
std::vector<std::string> mKeyframes;
std::vector<VFS::Path::Normalized> mModels;
std::vector<VFS::Path::Normalized> mTextures;
std::vector<VFS::Path::Normalized> mKeyframes;

private:
Resource::ResourceSystem* mResourceSystem;
Expand Down
3 changes: 2 additions & 1 deletion apps/openmw/mwrender/sky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ namespace MWRender
mUnderwaterSwitch->setWaterLevel(height);
}

void SkyManager::listAssetsToPreload(std::vector<std::string>& models, std::vector<std::string>& textures)
void SkyManager::listAssetsToPreload(
std::vector<VFS::Path::Normalized>& models, std::vector<VFS::Path::Normalized>& textures)
{
models.push_back(Settings::models().mSkyatmosphere);
if (mSceneManager->getVFS()->exists(Settings::models().mSkynight02.get()))
Expand Down
5 changes: 4 additions & 1 deletion apps/openmw/mwrender/sky.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <osg/Vec4f>
#include <osg/ref_ptr>

#include <components/vfs/pathutil.hpp>

#include "precipitationocclusion.hpp"
#include "skyutil.hpp"

Expand Down Expand Up @@ -100,7 +102,8 @@ namespace MWRender
/// Set height of water plane (used to remove underwater weather particles)
void setWaterHeight(float height);

void listAssetsToPreload(std::vector<std::string>& models, std::vector<std::string>& textures);
void listAssetsToPreload(
std::vector<VFS::Path::Normalized>& models, std::vector<VFS::Path::Normalized>& textures);

float getBaseWindSpeed() const;

Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwrender/water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,15 @@ namespace MWRender
}
}

void Water::listAssetsToPreload(std::vector<std::string>& textures)
void Water::listAssetsToPreload(std::vector<VFS::Path::Normalized>& textures)
{
const int frameCount = std::clamp(Fallback::Map::getInt("Water_SurfaceFrameCount"), 0, 320);
std::string_view texture = Fallback::Map::getString("Water_SurfaceTexture");
for (int i = 0; i < frameCount; ++i)
{
std::ostringstream texname;
texname << "textures/water/" << texture << std::setw(2) << std::setfill('0') << i << ".dds";
textures.push_back(texname.str());
textures.emplace_back(texname.str());
}
}

Expand Down
3 changes: 2 additions & 1 deletion apps/openmw/mwrender/water.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <osg/ref_ptr>

#include <components/settings/settings.hpp>
#include <components/vfs/pathutil.hpp>

namespace osg
{
Expand Down Expand Up @@ -92,7 +93,7 @@ namespace MWRender

void setCullCallback(osg::Callback* callback);

void listAssetsToPreload(std::vector<std::string>& textures);
void listAssetsToPreload(std::vector<VFS::Path::Normalized>& textures);

void setEnabled(bool enabled);

Expand Down
55 changes: 24 additions & 31 deletions components/settings/categories/models.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
#define OPENMW_COMPONENTS_SETTINGS_CATEGORIES_MODELS_H

#include <components/settings/settingvalue.hpp>

#include <osg/Math>
#include <osg/Vec2f>
#include <osg/Vec3f>

#include <cstdint>
#include <string>
#include <string_view>
#include <components/vfs/pathutil.hpp>

namespace Settings
{
Expand All @@ -18,29 +11,29 @@ namespace Settings
using WithIndex::WithIndex;

SettingValue<bool> mLoadUnsupportedNifFiles{ mIndex, "Models", "load unsupported nif files" };
SettingValue<std::string> mXbaseanim{ mIndex, "Models", "xbaseanim" };
SettingValue<std::string> mBaseanim{ mIndex, "Models", "baseanim" };
SettingValue<std::string> mXbaseanim1st{ mIndex, "Models", "xbaseanim1st" };
SettingValue<std::string> mBaseanimkna{ mIndex, "Models", "baseanimkna" };
SettingValue<std::string> mBaseanimkna1st{ mIndex, "Models", "baseanimkna1st" };
SettingValue<std::string> mXbaseanimfemale{ mIndex, "Models", "xbaseanimfemale" };
SettingValue<std::string> mBaseanimfemale{ mIndex, "Models", "baseanimfemale" };
SettingValue<std::string> mBaseanimfemale1st{ mIndex, "Models", "baseanimfemale1st" };
SettingValue<std::string> mWolfskin{ mIndex, "Models", "wolfskin" };
SettingValue<std::string> mWolfskin1st{ mIndex, "Models", "wolfskin1st" };
SettingValue<std::string> mXargonianswimkna{ mIndex, "Models", "xargonianswimkna" };
SettingValue<std::string> mXbaseanimkf{ mIndex, "Models", "xbaseanimkf" };
SettingValue<std::string> mXbaseanim1stkf{ mIndex, "Models", "xbaseanim1stkf" };
SettingValue<std::string> mXbaseanimfemalekf{ mIndex, "Models", "xbaseanimfemalekf" };
SettingValue<std::string> mXargonianswimknakf{ mIndex, "Models", "xargonianswimknakf" };
SettingValue<std::string> mSkyatmosphere{ mIndex, "Models", "skyatmosphere" };
SettingValue<std::string> mSkyclouds{ mIndex, "Models", "skyclouds" };
SettingValue<std::string> mSkynight01{ mIndex, "Models", "skynight01" };
SettingValue<std::string> mSkynight02{ mIndex, "Models", "skynight02" };
SettingValue<std::string> mWeatherashcloud{ mIndex, "Models", "weatherashcloud" };
SettingValue<std::string> mWeatherblightcloud{ mIndex, "Models", "weatherblightcloud" };
SettingValue<std::string> mWeathersnow{ mIndex, "Models", "weathersnow" };
SettingValue<std::string> mWeatherblizzard{ mIndex, "Models", "weatherblizzard" };
SettingValue<VFS::Path::Normalized> mXbaseanim{ mIndex, "Models", "xbaseanim" };
SettingValue<VFS::Path::Normalized> mBaseanim{ mIndex, "Models", "baseanim" };
SettingValue<VFS::Path::Normalized> mXbaseanim1st{ mIndex, "Models", "xbaseanim1st" };
SettingValue<VFS::Path::Normalized> mBaseanimkna{ mIndex, "Models", "baseanimkna" };
SettingValue<VFS::Path::Normalized> mBaseanimkna1st{ mIndex, "Models", "baseanimkna1st" };
SettingValue<VFS::Path::Normalized> mXbaseanimfemale{ mIndex, "Models", "xbaseanimfemale" };
SettingValue<VFS::Path::Normalized> mBaseanimfemale{ mIndex, "Models", "baseanimfemale" };
SettingValue<VFS::Path::Normalized> mBaseanimfemale1st{ mIndex, "Models", "baseanimfemale1st" };
SettingValue<VFS::Path::Normalized> mWolfskin{ mIndex, "Models", "wolfskin" };
SettingValue<VFS::Path::Normalized> mWolfskin1st{ mIndex, "Models", "wolfskin1st" };
SettingValue<VFS::Path::Normalized> mXargonianswimkna{ mIndex, "Models", "xargonianswimkna" };
SettingValue<VFS::Path::Normalized> mXbaseanimkf{ mIndex, "Models", "xbaseanimkf" };
SettingValue<VFS::Path::Normalized> mXbaseanim1stkf{ mIndex, "Models", "xbaseanim1stkf" };
SettingValue<VFS::Path::Normalized> mXbaseanimfemalekf{ mIndex, "Models", "xbaseanimfemalekf" };
SettingValue<VFS::Path::Normalized> mXargonianswimknakf{ mIndex, "Models", "xargonianswimknakf" };
SettingValue<VFS::Path::Normalized> mSkyatmosphere{ mIndex, "Models", "skyatmosphere" };
SettingValue<VFS::Path::Normalized> mSkyclouds{ mIndex, "Models", "skyclouds" };
SettingValue<VFS::Path::Normalized> mSkynight01{ mIndex, "Models", "skynight01" };
SettingValue<VFS::Path::Normalized> mSkynight02{ mIndex, "Models", "skynight02" };
SettingValue<VFS::Path::Normalized> mWeatherashcloud{ mIndex, "Models", "weatherashcloud" };
SettingValue<VFS::Path::Normalized> mWeatherblightcloud{ mIndex, "Models", "weatherblightcloud" };
SettingValue<VFS::Path::Normalized> mWeathersnow{ mIndex, "Models", "weathersnow" };
SettingValue<VFS::Path::Normalized> mWeatherblizzard{ mIndex, "Models", "weatherblizzard" };
SettingValue<bool> mWriteNifDebugLog{ mIndex, "Models", "write nif debug log" };
};
}
Expand Down
8 changes: 8 additions & 0 deletions components/settings/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <components/detournavigator/collisionshapetype.hpp>
#include <components/sceneutil/lightingmethod.hpp>
#include <components/sdlutil/vsyncmode.hpp>
#include <components/vfs/pathutil.hpp>

#include <filesystem>
#include <set>
Expand Down Expand Up @@ -263,6 +264,13 @@ namespace Settings
return SDLUtil::VSyncMode::Disabled;
return static_cast<SDLUtil::VSyncMode>(value);
}

template <>
inline VFS::Path::Normalized Manager::getImpl<VFS::Path::Normalized>(
std::string_view setting, std::string_view category)
{
return VFS::Path::Normalized(getString(setting, category));
}
}

#endif // COMPONENTS_SETTINGS_H
14 changes: 12 additions & 2 deletions components/settings/settingvalue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#include "sanitizer.hpp"
#include "settings.hpp"

#include "components/debug/debuglog.hpp"
#include "components/detournavigator/collisionshapetype.hpp"
#include <components/debug/debuglog.hpp>
#include <components/detournavigator/collisionshapetype.hpp>
#include <components/vfs/pathutil.hpp>

#include <osg/io_utils>

Expand Down Expand Up @@ -44,6 +45,7 @@ namespace Settings
HrtfMode,
WindowMode,
VSyncMode,
NormalizedPath,
};

template <class T>
Expand Down Expand Up @@ -175,6 +177,12 @@ namespace Settings
return SettingValueType::VSyncMode;
}

template <>
inline constexpr SettingValueType getSettingValueType<VFS::Path::Normalized>()
{
return SettingValueType::NormalizedPath;
}

inline constexpr std::string_view getSettingValueTypeName(SettingValueType type)
{
switch (type)
Expand Down Expand Up @@ -221,6 +229,8 @@ namespace Settings
return "window mode";
case SettingValueType::VSyncMode:
return "vsync mode";
case SettingValueType::NormalizedPath:
return "normalized path";
}
return "unsupported";
}
Expand Down

0 comments on commit 89976a9

Please sign in to comment.