1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

Merge branch 'Embedded-error-marker' into 'master'

Embed marker error

See merge request OpenMW/openmw!1383
This commit is contained in:
psi29a 2021-11-20 18:07:13 +00:00
commit adc3bab51e
7 changed files with 1452 additions and 94 deletions

View file

@ -99,6 +99,7 @@
Feature #6161: Refactor Sky to use shaders and GLES/GL3 friendly
Feature #6162: Refactor GUI to use shaders and to be GLES and GL3+ friendly
Feature #6199: Support FBO Rendering
Feature #6248: Embedded error marker mesh
Feature #6249: Alpha testing support for Collada
Feature #6251: OpenMW-CS: Set instance movement based on camera zoom
Feature #6288: Preserve the "blocked" record flag for referenceable objects.

View file

@ -37,7 +37,7 @@ add_component_dir (settings
)
add_component_dir (bsa
bsa_file compressedbsafile memorystream
bsa_file compressedbsafile
)
add_component_dir (vfs
@ -93,7 +93,7 @@ add_component_dir (esmterrain
add_component_dir (misc
constants utf8stream stringops resourcehelpers rng messageformatparser weakcache thread
compression osguservalues
compression osguservalues errorMarker
)
add_component_dir (debug

View file

@ -1,48 +0,0 @@
/*
OpenMW - The completely unofficial reimplementation of Morrowind
Copyright (C) 2008-2010 Nicolay Korslund
Email: < korslund@gmail.com >
WWW: http://openmw.sourceforge.net/
This file (memorystream.cpp) is part of the OpenMW package.
OpenMW is distributed as free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
version 3 along with this program. If not, see
http://www.gnu.org/licenses/ .
Compressed BSA upgrade added by Azdul 2019
*/
#include "memorystream.hpp"
namespace Bsa
{
MemoryInputStreamBuf::MemoryInputStreamBuf(size_t bufferSize) : mBufferPtr(bufferSize)
{
this->setg(mBufferPtr.data(), mBufferPtr.data(), mBufferPtr.data() + bufferSize);
}
char* MemoryInputStreamBuf::getRawData() {
return mBufferPtr.data();
}
MemoryInputStream::MemoryInputStream(size_t bufferSize) :
MemoryInputStreamBuf(bufferSize),
std::istream(static_cast<std::streambuf*>(this)) {
}
char* MemoryInputStream::getRawData() {
return MemoryInputStreamBuf::getRawData();
}
}

View file

@ -28,22 +28,10 @@
#include <vector>
#include <iostream>
#include <components/files/memorystream.hpp>
namespace Bsa
{
/**
Class used internally by MemoryInputStream.
*/
class MemoryInputStreamBuf : public std::streambuf {
public:
explicit MemoryInputStreamBuf(size_t bufferSize);
virtual char* getRawData();
private:
//correct call to delete [] on C++ 11
std::vector<char> mBufferPtr;
};
/**
Class replaces Ogre memory streams without introducing any new external dependencies
beyond standard library.
@ -52,10 +40,18 @@ private:
Memory buffer is freed once the class instance is destroyed.
*/
class MemoryInputStream : virtual MemoryInputStreamBuf, std::istream {
class MemoryInputStream : private std::vector<char>, public virtual Files::MemBuf, public std::istream {
public:
explicit MemoryInputStream(size_t bufferSize);
char* getRawData() override;
explicit MemoryInputStream(size_t bufferSize)
: std::vector<char>(bufferSize)
, Files::MemBuf(this->data(), this->size())
, std::istream(static_cast<std::streambuf*>(this))
{}
char* getRawData()
{
return this->data();
}
};
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
#ifndef OPENMW_COMPONENTS_MISC_ERRORMARKER_H
#define OPENMW_COMPONENTS_MISC_ERRORMARKER_H
#include <string>
namespace Misc
{
extern const std::string errorMarker;
}
#endif

View file

@ -21,6 +21,7 @@
#include <components/misc/pathhelpers.hpp>
#include <components/misc/stringops.hpp>
#include <components/misc/algorithm.hpp>
#include <components/misc/errorMarker.hpp>
#include <components/misc/osguservalues.hpp>
#include <components/vfs/manager.hpp>
@ -36,6 +37,7 @@
#include <components/shader/shadermanager.hpp>
#include <components/files/hash.hpp>
#include <components/files/memorystream.hpp>
#include "imagemanager.hpp"
#include "niffilemanager.hpp"
@ -483,13 +485,11 @@ namespace Resource
Resource::ImageManager* mImageManager;
};
osg::ref_ptr<osg::Node> load (const std::string& normalizedFilename, const VFS::Manager* vfs, Resource::ImageManager* imageManager, Resource::NifFileManager* nifFileManager)
namespace
{
auto ext = Misc::getFileExtension(normalizedFilename);
if (ext == "nif")
return NifOsg::Loader::load(nifFileManager->get(normalizedFilename), imageManager);
else
osg::ref_ptr<osg::Node> loadNonNif(const std::string& normalizedFilename, std::istream& model, Resource::ImageManager* imageManager)
{
auto ext = Misc::getFileExtension(normalizedFilename);
osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension(std::string(ext));
if (!reader)
{
@ -505,10 +505,9 @@ namespace Resource
options->setReadFileCallback(new ImageReadCallback(imageManager));
if (ext == "dae") options->setOptionString("daeUseSequencedTextureUnits");
Files::IStreamPtr stream = vfs->get(normalizedFilename);
const std::uint64_t fileHash = Files::getHash(normalizedFilename, *stream);
const std::uint64_t fileHash = Files::getHash(normalizedFilename, model);
osgDB::ReaderWriter::ReadResult result = reader->readNode(*stream, options);
osgDB::ReaderWriter::ReadResult result = reader->readNode(model, options);
if (!result.success())
{
std::stringstream errormsg;
@ -519,7 +518,9 @@ namespace Resource
// Recognize and hide collision node
unsigned int hiddenNodeMask = 0;
SceneUtil::FindByNameVisitor nameFinder("Collision");
result.getNode()->accept(nameFinder);
auto node = result.getNode();
node->accept(nameFinder);
if (nameFinder.mFoundNode)
nameFinder.mFoundNode->setNodeMask(hiddenNodeMask);
@ -527,16 +528,14 @@ namespace Resource
{
// Collada alpha testing
Resource::ColladaAlphaTrickVisitor colladaAlphaTrickVisitor;
result.getNode()->accept(colladaAlphaTrickVisitor);
node->accept(colladaAlphaTrickVisitor);
result.getNode()->getOrCreateStateSet()->addUniform(new osg::Uniform("emissiveMult", 1.f));
result.getNode()->getOrCreateStateSet()->addUniform(new osg::Uniform("specStrength", 1.f));
result.getNode()->getOrCreateStateSet()->addUniform(new osg::Uniform("envMapColor", osg::Vec4f(1,1,1,1)));
result.getNode()->getOrCreateStateSet()->addUniform(new osg::Uniform("useFalloff", false));
node->getOrCreateStateSet()->addUniform(new osg::Uniform("emissiveMult", 1.f));
node->getOrCreateStateSet()->addUniform(new osg::Uniform("specStrength", 1.f));
node->getOrCreateStateSet()->addUniform(new osg::Uniform("envMapColor", osg::Vec4f(1,1,1,1)));
node->getOrCreateStateSet()->addUniform(new osg::Uniform("useFalloff", false));
}
auto node = result.getNode();
node->setUserValue(Misc::OsgUserValues::sFileHash,
std::string(reinterpret_cast<const char*>(&fileHash), sizeof(fileHash)));
@ -544,6 +543,15 @@ namespace Resource
}
}
osg::ref_ptr<osg::Node> load (const std::string& normalizedFilename, const VFS::Manager* vfs, Resource::ImageManager* imageManager, Resource::NifFileManager* nifFileManager)
{
auto ext = Misc::getFileExtension(normalizedFilename);
if (ext == "nif")
return NifOsg::Loader::load(nifFileManager->get(normalizedFilename), imageManager);
else
return loadNonNif(normalizedFilename, *vfs->get(normalizedFilename), imageManager);
}
class CanOptimizeCallback : public SceneUtil::Optimizer::IsOperationPermissibleForObjectCallback
{
public:
@ -659,23 +667,23 @@ namespace Resource
{
loaded = load(normalized, mVFS, mImageManager, mNifFileManager);
}
catch (std::exception& e)
catch (const std::exception& e)
{
static const char * const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2", "dae" };
static osg::ref_ptr<osg::Node> errorMarkerNode = [&] {
static const char* const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2", "dae" };
for (unsigned int i=0; i<sizeof(sMeshTypes)/sizeof(sMeshTypes[0]); ++i)
{
normalized = "meshes/marker_error." + std::string(sMeshTypes[i]);
if (mVFS->exists(normalized))
for (unsigned int i=0; i<sizeof(sMeshTypes)/sizeof(sMeshTypes[0]); ++i)
{
Log(Debug::Error) << "Failed to load '" << name << "': " << e.what() << ", using marker_error." << sMeshTypes[i] << " instead";
loaded = load(normalized, mVFS, mImageManager, mNifFileManager);
break;
normalized = "meshes/marker_error." + std::string(sMeshTypes[i]);
if (mVFS->exists(normalized))
return load(normalized, mVFS, mImageManager, mNifFileManager);
}
}
Files::IMemStream file(Misc::errorMarker.data(), Misc::errorMarker.size());
return loadNonNif("error_marker.osgt", file, mImageManager);
}();
if (!loaded)
throw;
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));
}
// set filtering settings