mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-27 14:37:04 +00:00
Revert "Various fixes for niftest"
This reverts commit 87ada56edd9d5d5b0a9e6a8dcfd06eb09b161746.
This commit is contained in:
parent
9eb876cc17
commit
903ce44634
@ -212,7 +212,7 @@ void NIFFile::parse(Files::IStreamPtr stream)
|
|||||||
userVer = nif.getUInt();
|
userVer = nif.getUInt();
|
||||||
|
|
||||||
// Number of records
|
// Number of records
|
||||||
const std::size_t recNum = nif.getUInt();
|
unsigned int recNum = nif.getUInt();
|
||||||
records.resize(recNum);
|
records.resize(recNum);
|
||||||
|
|
||||||
// Bethesda stream header
|
// Bethesda stream header
|
||||||
@ -251,7 +251,7 @@ void NIFFile::parse(Files::IStreamPtr stream)
|
|||||||
std::vector<unsigned int> recSizes; // Currently unused
|
std::vector<unsigned int> recSizes; // Currently unused
|
||||||
nif.getUInts(recSizes, recNum);
|
nif.getUInts(recSizes, recNum);
|
||||||
}
|
}
|
||||||
const std::size_t stringNum = nif.getUInt();
|
unsigned int stringNum = nif.getUInt();
|
||||||
nif.getUInt(); // Max string length
|
nif.getUInt(); // Max string length
|
||||||
if (stringNum)
|
if (stringNum)
|
||||||
nif.getSizedStrings(strings, stringNum);
|
nif.getSizedStrings(strings, stringNum);
|
||||||
@ -264,7 +264,7 @@ void NIFFile::parse(Files::IStreamPtr stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool hasRecordSeparators = ver >= NIFStream::generateVersion(10,0,0,0) && ver < NIFStream::generateVersion(10,2,0,0);
|
const bool hasRecordSeparators = ver >= NIFStream::generateVersion(10,0,0,0) && ver < NIFStream::generateVersion(10,2,0,0);
|
||||||
for (std::size_t i = 0; i < recNum; i++)
|
for (unsigned int i = 0; i < recNum; i++)
|
||||||
{
|
{
|
||||||
Record *r = nullptr;
|
Record *r = nullptr;
|
||||||
|
|
||||||
@ -308,14 +308,14 @@ void NIFFile::parse(Files::IStreamPtr stream)
|
|||||||
r->read(&nif);
|
r->read(&nif);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::size_t rootNum = nif.getUInt();
|
unsigned int rootNum = nif.getUInt();
|
||||||
roots.resize(rootNum);
|
roots.resize(rootNum);
|
||||||
|
|
||||||
//Determine which records are roots
|
//Determine which records are roots
|
||||||
for (std::size_t i = 0; i < rootNum; i++)
|
for (unsigned int i = 0; i < rootNum; i++)
|
||||||
{
|
{
|
||||||
int idx = nif.getInt();
|
int idx = nif.getInt();
|
||||||
if (idx >= 0 && static_cast<std::size_t>(idx) < records.size())
|
if (idx >= 0 && idx < int(records.size()))
|
||||||
{
|
{
|
||||||
roots[i] = records[idx];
|
roots[i] = records[idx];
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ namespace Nif
|
|||||||
osg::Quat NIFStream::getQuaternion()
|
osg::Quat NIFStream::getQuaternion()
|
||||||
{
|
{
|
||||||
float f[4];
|
float f[4];
|
||||||
readLittleEndianBufferOfType<4, float>(inp, f);
|
readLittleEndianBufferOfType<4, float>(inp, (float*)&f);
|
||||||
osg::Quat quat;
|
osg::Quat quat;
|
||||||
quat.w() = f[0];
|
quat.w() = f[0];
|
||||||
quat.x() = f[1];
|
quat.x() = f[1];
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <typeinfo>
|
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
#include <components/files/constrainedfilestream.hpp>
|
#include <components/files/constrainedfilestream.hpp>
|
||||||
#include <components/misc/endianness.hpp>
|
#include <components/misc/endianness.hpp>
|
||||||
@ -24,32 +22,31 @@ namespace Nif
|
|||||||
|
|
||||||
class NIFFile;
|
class NIFFile;
|
||||||
|
|
||||||
template <std::size_t numInstances, typename T> inline void readLittleEndianBufferOfType(Files::IStreamPtr &pIStream, T* dest)
|
/*
|
||||||
|
readLittleEndianBufferOfType: This template should only be used with arithmetic types
|
||||||
|
*/
|
||||||
|
template <uint32_t numInstances, typename T> inline void readLittleEndianBufferOfType(Files::IStreamPtr &pIStream, T* dest)
|
||||||
{
|
{
|
||||||
static_assert(std::is_arithmetic_v<T>, "Buffer element type is not arithmetic");
|
|
||||||
pIStream->read((char*)dest, numInstances * sizeof(T));
|
pIStream->read((char*)dest, numInstances * sizeof(T));
|
||||||
if (pIStream->bad())
|
|
||||||
throw std::runtime_error("Failed to read little endian typed (" + std::string(typeid(T).name()) + ") buffer of "
|
|
||||||
+ std::to_string(numInstances) + " instances");
|
|
||||||
if constexpr (Misc::IS_BIG_ENDIAN)
|
if constexpr (Misc::IS_BIG_ENDIAN)
|
||||||
for (std::size_t i = 0; i < numInstances; i++)
|
for (uint32_t i = 0; i < numInstances; i++)
|
||||||
Misc::swapEndiannessInplace(dest[i]);
|
Misc::swapEndiannessInplace(dest[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline void readLittleEndianDynamicBufferOfType(Files::IStreamPtr &pIStream, T* dest, std::size_t numInstances)
|
/*
|
||||||
|
readLittleEndianDynamicBufferOfType: This template should only be used with arithmetic types
|
||||||
|
*/
|
||||||
|
template <typename T> inline void readLittleEndianDynamicBufferOfType(Files::IStreamPtr &pIStream, T* dest, uint32_t numInstances)
|
||||||
{
|
{
|
||||||
static_assert(std::is_arithmetic_v<T>, "Buffer element type is not arithmetic");
|
|
||||||
pIStream->read((char*)dest, numInstances * sizeof(T));
|
pIStream->read((char*)dest, numInstances * sizeof(T));
|
||||||
if (pIStream->bad())
|
|
||||||
throw std::runtime_error("Failed to read little endian dynamic buffer of " + std::to_string(numInstances) + " instances");
|
|
||||||
if constexpr (Misc::IS_BIG_ENDIAN)
|
if constexpr (Misc::IS_BIG_ENDIAN)
|
||||||
for (std::size_t i = 0; i < numInstances; i++)
|
for (uint32_t i = 0; i < numInstances; i++)
|
||||||
Misc::swapEndiannessInplace(dest[i]);
|
Misc::swapEndiannessInplace(dest[i]);
|
||||||
}
|
}
|
||||||
template<typename type> type inline readLittleEndianType(Files::IStreamPtr &pIStream)
|
template<typename type> type inline readLittleEndianType(Files::IStreamPtr &pIStream)
|
||||||
{
|
{
|
||||||
type val;
|
type val;
|
||||||
readLittleEndianBufferOfType<1, type>(pIStream, &val);
|
readLittleEndianBufferOfType<1, type>(pIStream, (type*)&val);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,21 +96,21 @@ public:
|
|||||||
osg::Vec2f getVector2()
|
osg::Vec2f getVector2()
|
||||||
{
|
{
|
||||||
osg::Vec2f vec;
|
osg::Vec2f vec;
|
||||||
readLittleEndianBufferOfType<2,float>(inp, vec._v);
|
readLittleEndianBufferOfType<2,float>(inp, (float*)&vec._v[0]);
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Vec3f getVector3()
|
osg::Vec3f getVector3()
|
||||||
{
|
{
|
||||||
osg::Vec3f vec;
|
osg::Vec3f vec;
|
||||||
readLittleEndianBufferOfType<3, float>(inp, vec._v);
|
readLittleEndianBufferOfType<3, float>(inp, (float*)&vec._v[0]);
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Vec4f getVector4()
|
osg::Vec4f getVector4()
|
||||||
{
|
{
|
||||||
osg::Vec4f vec;
|
osg::Vec4f vec;
|
||||||
readLittleEndianBufferOfType<4, float>(inp, vec._v);
|
readLittleEndianBufferOfType<4, float>(inp, (float*)&vec._v[0]);
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,11 +142,11 @@ public:
|
|||||||
///Read in a string of the given length
|
///Read in a string of the given length
|
||||||
std::string getSizedString(size_t length)
|
std::string getSizedString(size_t length)
|
||||||
{
|
{
|
||||||
std::string str(length, '\0');
|
std::vector<char> str(length + 1, 0);
|
||||||
|
|
||||||
inp->read(str.data(), length);
|
inp->read(str.data(), length);
|
||||||
if (inp->bad())
|
|
||||||
throw std::runtime_error("Failed to read sized string of " + std::to_string(length) + " chars");
|
return str.data();
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
///Read in a string of the length specified in the file
|
///Read in a string of the length specified in the file
|
||||||
std::string getSizedString()
|
std::string getSizedString()
|
||||||
@ -170,8 +167,6 @@ public:
|
|||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
std::getline(*inp, result);
|
std::getline(*inp, result);
|
||||||
if (inp->bad())
|
|
||||||
throw std::runtime_error("Failed to read version string");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user