1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-01 01:09:41 +00:00

Add method to load and clone the error marker used by the scene manager

This commit is contained in:
Cédric Mocquillon 2023-02-21 13:25:18 +01:00
parent 97c42768e6
commit f7b45a6262
2 changed files with 32 additions and 26 deletions

View file

@ -831,6 +831,34 @@ namespace Resource
mSharedStateMutex.unlock(); mSharedStateMutex.unlock();
} }
osg::ref_ptr<osg::Node> SceneManager::loadErrorMarker()
{
try
{
for (const auto meshType : { "nif", "osg", "osgt", "osgb", "osgx", "osg2", "dae" })
{
const std::string normalized = "meshes/marker_error." + std::string(meshType);
if (mVFS->exists(normalized))
return load(normalized, mVFS, mImageManager, mNifFileManager);
}
}
catch (const std::exception& e)
{
Log(Debug::Warning) << "Failed to load error marker:" << e.what()
<< ", using embedded marker_error instead";
}
Files::IMemStream file(ErrorMarker::sValue.data(), ErrorMarker::sValue.size());
return loadNonNif("error_marker.osgt", file, mImageManager);
}
osg::ref_ptr<osg::Node> SceneManager::cloneErrorMarker()
{
if (!mErrorMarker)
mErrorMarker = loadErrorMarker();
return static_cast<osg::Node*>(mErrorMarker->clone(osg::CopyOp::DEEP_COPY_ALL));
}
osg::ref_ptr<const osg::Node> SceneManager::getTemplate(const std::string& name, bool compile) osg::ref_ptr<const osg::Node> SceneManager::getTemplate(const std::string& name, bool compile)
{ {
std::string normalized = mVFS->normalizeFilename(name); std::string normalized = mVFS->normalizeFilename(name);
@ -850,33 +878,8 @@ namespace Resource
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
static osg::ref_ptr<osg::Node> errorMarkerNode = [&] {
static const char* const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2", "dae" };
static bool useEmbedded = false;
if (!useEmbedded)
{
try
{
for (unsigned int i = 0; i < sizeof(sMeshTypes) / sizeof(sMeshTypes[0]); ++i)
{
normalized = "meshes/marker_error." + std::string(sMeshTypes[i]);
if (mVFS->exists(normalized))
return load(normalized, mVFS, mImageManager, mNifFileManager);
}
}
catch (const std::exception& e)
{
useEmbedded = true;
Log(Debug::Warning) << "Failed to load error marker:" << e.what()
<< ", using embedded marker_error instead";
}
}
Files::IMemStream file(ErrorMarker::sValue.data(), ErrorMarker::sValue.size());
return loadNonNif("error_marker.osgt", file, mImageManager);
}();
Log(Debug::Error) << "Failed to load '" << name << "': " << e.what() << ", using marker_error instead"; Log(Debug::Error) << "Failed to load '" << name << "': " << e.what() << ", using marker_error instead";
loaded = static_cast<osg::Node*>(errorMarkerNode->clone(osg::CopyOp::DEEP_COPY_ALL)); loaded = cloneErrorMarker();
} }
// set filtering settings // set filtering settings

View file

@ -228,6 +228,8 @@ namespace Resource
private: private:
Shader::ShaderVisitor* createShaderVisitor(const std::string& shaderPrefix = "objects"); Shader::ShaderVisitor* createShaderVisitor(const std::string& shaderPrefix = "objects");
osg::ref_ptr<osg::Node> loadErrorMarker();
osg::ref_ptr<osg::Node> cloneErrorMarker();
std::unique_ptr<Shader::ShaderManager> mShaderManager; std::unique_ptr<Shader::ShaderManager> mShaderManager;
bool mForceShaders; bool mForceShaders;
@ -260,6 +262,7 @@ namespace Resource
osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation; osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation;
unsigned int mParticleSystemMask; unsigned int mParticleSystemMask;
mutable osg::ref_ptr<osg::Node> mErrorMarker;
SceneManager(const SceneManager&); SceneManager(const SceneManager&);
void operator=(const SceneManager&); void operator=(const SceneManager&);