From 62d643f668015564dddd0a29eabf4837e636ff39 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Wed, 26 Jul 2023 04:10:55 +0300 Subject: [PATCH] NIFStream: Drop LittleEndian from reading methods This is just noise. We don't clarify reading endianness for any other file format. --- components/nif/nifstream.cpp | 2 +- components/nif/nifstream.hpp | 64 ++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/components/nif/nifstream.cpp b/components/nif/nifstream.cpp index 2bd57d1633..8e7833e127 100644 --- a/components/nif/nifstream.cpp +++ b/components/nif/nifstream.cpp @@ -7,7 +7,7 @@ namespace Nif osg::Quat NIFStream::getQuaternion() { float f[4]; - readLittleEndianBufferOfType<4, float>(inp, f); + readBufferOfType<4, float>(inp, f); osg::Quat quat; quat.w() = f[0]; quat.x() = f[1]; diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index c3fc03320d..8cd11b9829 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -27,7 +27,7 @@ namespace Nif class Reader; template - inline void readLittleEndianBufferOfType(Files::IStreamPtr& pIStream, T* dest) + inline void readBufferOfType(Files::IStreamPtr& pIStream, T* dest) { static_assert( std::is_arithmetic_v || std::is_same_v, "Buffer element type is not arithmetic"); @@ -42,7 +42,7 @@ namespace Nif } template - inline void readLittleEndianDynamicBufferOfType(Files::IStreamPtr& pIStream, T* dest, std::size_t numInstances) + inline void readDynamicBufferOfType(Files::IStreamPtr& pIStream, T* dest, std::size_t numInstances) { static_assert( std::is_arithmetic_v || std::is_same_v, "Buffer element type is not arithmetic"); @@ -56,10 +56,10 @@ namespace Nif Misc::swapEndiannessInplace(dest[i]); } template - type inline readLittleEndianType(Files::IStreamPtr& pIStream) + type inline readType(Files::IStreamPtr& pIStream) { type val; - readLittleEndianBufferOfType<1, type>(pIStream, &val); + readBufferOfType<1, type>(pIStream, &val); return val; } @@ -84,53 +84,53 @@ namespace Nif template void read(T& data) { - data = readLittleEndianType(inp); + data = readType(inp); } - void read(osg::Vec3f& data) { readLittleEndianBufferOfType<3, float>(inp, data._v); } - void read(osg::Vec4f& data) { readLittleEndianBufferOfType<4, float>(inp, data._v); } + void read(osg::Vec3f& data) { readBufferOfType<3, float>(inp, data._v); } + void read(osg::Vec4f& data) { readBufferOfType<4, float>(inp, data._v); } template T get() { - return readLittleEndianType(inp); + return readType(inp); } template void readVector(std::vector& vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + readDynamicBufferOfType(inp, vec.data(), size); } template void readArray(std::array& arr) { - readLittleEndianDynamicBufferOfType(inp, arr.data(), size); + readDynamicBufferOfType(inp, arr.data(), size); } // DEPRECATED: Use read() or get() whenever relevant - char getChar() { return readLittleEndianType(inp); } + char getChar() { return readType(inp); } // DEPRECATED: Use read() or get() whenever relevant - short getShort() { return readLittleEndianType(inp); } + short getShort() { return readType(inp); } // DEPRECATED: Use read() or get() whenever relevant - unsigned short getUShort() { return readLittleEndianType(inp); } + unsigned short getUShort() { return readType(inp); } // DEPRECATED: Use read() or get() whenever relevant - int getInt() { return readLittleEndianType(inp); } + int getInt() { return readType(inp); } // DEPRECATED: Use read() or get() whenever relevant - unsigned int getUInt() { return readLittleEndianType(inp); } + unsigned int getUInt() { return readType(inp); } // DEPRECATED: Use read() or get() whenever relevant - float getFloat() { return readLittleEndianType(inp); } + float getFloat() { return readType(inp); } osg::Vec2f getVector2() { osg::Vec2f vec; - readLittleEndianBufferOfType<2, float>(inp, vec._v); + readBufferOfType<2, float>(inp, vec._v); return vec; } @@ -138,21 +138,21 @@ namespace Nif osg::Vec3f getVector3() { osg::Vec3f vec; - readLittleEndianBufferOfType<3, float>(inp, vec._v); + readBufferOfType<3, float>(inp, vec._v); return vec; } osg::Vec4f getVector4() { osg::Vec4f vec; - readLittleEndianBufferOfType<4, float>(inp, vec._v); + readBufferOfType<4, float>(inp, vec._v); return vec; } Matrix3 getMatrix3() { Matrix3 mat; - readLittleEndianBufferOfType<9, float>(inp, (float*)&mat.mValues); + readBufferOfType<9, float>(inp, (float*)&mat.mValues); return mat; } @@ -189,14 +189,14 @@ namespace Nif /// Read in a string of the length specified in the file std::string getSizedString() { - size_t size = readLittleEndianType(inp); + size_t size = readType(inp); return getSizedString(size); } /// Specific to Bethesda headers, uses a byte for length std::string getExportString() { - size_t size = static_cast(readLittleEndianType(inp)); + size_t size = static_cast(readType(inp)); return getSizedString(size); } @@ -213,7 +213,7 @@ namespace Nif /// Read a sequence of null-terminated strings std::string getStringPalette() { - size_t size = readLittleEndianType(inp); + size_t size = readType(inp); std::string str(size, '\0'); inp->read(str.data(), size); if (inp->bad()) @@ -225,63 +225,63 @@ namespace Nif void getChars(std::vector& vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + readDynamicBufferOfType(inp, vec.data(), size); } // DEPRECATED: Use readVector() void getUChars(std::vector& vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + readDynamicBufferOfType(inp, vec.data(), size); } // DEPRECATED: Use readVector() void getUShorts(std::vector& vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + readDynamicBufferOfType(inp, vec.data(), size); } // DEPRECATED: Use readVector() void getFloats(std::vector& vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + readDynamicBufferOfType(inp, vec.data(), size); } // DEPRECATED: Use readVector() void getInts(std::vector& vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + readDynamicBufferOfType(inp, vec.data(), size); } // DEPRECATED: Use readVector() void getUInts(std::vector& vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + readDynamicBufferOfType(inp, vec.data(), size); } void getVector2s(std::vector& vec, size_t size) { vec.resize(size); /* The packed storage of each Vec2f is 2 floats exactly */ - readLittleEndianDynamicBufferOfType(inp, (float*)vec.data(), size * 2); + readDynamicBufferOfType(inp, (float*)vec.data(), size * 2); } void getVector3s(std::vector& vec, size_t size) { vec.resize(size); /* The packed storage of each Vec3f is 3 floats exactly */ - readLittleEndianDynamicBufferOfType(inp, (float*)vec.data(), size * 3); + readDynamicBufferOfType(inp, (float*)vec.data(), size * 3); } void getVector4s(std::vector& vec, size_t size) { vec.resize(size); /* The packed storage of each Vec4f is 4 floats exactly */ - readLittleEndianDynamicBufferOfType(inp, (float*)vec.data(), size * 4); + readDynamicBufferOfType(inp, (float*)vec.data(), size * 4); } void getQuaternions(std::vector& quat, size_t size)