From c72aa19d6d8a91c3ce34659e5d5a8bb4826bc0db Mon Sep 17 00:00:00 2001 From: Date: Wed, 20 Sep 2017 23:53:12 -0500 Subject: [PATCH 1/5] first pass on optimization of nif parsing functions from the file stream --- components/files/constrainedfilestream.cpp | 2 +- components/nif/nifstream.cpp | 132 +--------------- components/nif/nifstream.hpp | 170 ++++++++++++++++++--- 3 files changed, 151 insertions(+), 153 deletions(-) diff --git a/components/files/constrainedfilestream.cpp b/components/files/constrainedfilestream.cpp index 4f76139d9..b239ec6a1 100644 --- a/components/files/constrainedfilestream.cpp +++ b/components/files/constrainedfilestream.cpp @@ -8,7 +8,7 @@ namespace { // somewhat arbitrary though 64KB buffers didn't seem to improve performance any -const size_t sBufferSize = 4096; +const size_t sBufferSize = 8192; } namespace Files diff --git a/components/nif/nifstream.cpp b/components/nif/nifstream.cpp index d0fc9bab0..08a7466fa 100644 --- a/components/nif/nifstream.cpp +++ b/components/nif/nifstream.cpp @@ -6,138 +6,8 @@ namespace Nif { //Private functions -uint8_t NIFStream::read_byte() -{ - uint8_t byte; - inp->read((char*)&byte, 1); - return byte; -} -uint16_t NIFStream::read_le16() -{ - uint8_t buffer[2]; - inp->read((char*)buffer, 2); - return buffer[0] | (buffer[1]<<8); -} -uint32_t NIFStream::read_le32() -{ - uint8_t buffer[4]; - inp->read((char*)buffer, 4); - return buffer[0] | (buffer[1]<<8) | (buffer[2]<<16) | (buffer[3]<<24); -} -float NIFStream::read_le32f() -{ - union { - uint32_t i; - float f; - } u = { read_le32() }; - return u.f; -} -//Public functions -osg::Vec2f NIFStream::getVector2() -{ - osg::Vec2f vec; - for(size_t i = 0;i < 2;i++) - vec._v[i] = getFloat(); - return vec; -} -osg::Vec3f NIFStream::getVector3() -{ - osg::Vec3f vec; - for(size_t i = 0;i < 3;i++) - vec._v[i] = getFloat(); - return vec; -} -osg::Vec4f NIFStream::getVector4() -{ - osg::Vec4f vec; - for(size_t i = 0;i < 4;i++) - vec._v[i] = getFloat(); - return vec; -} -Matrix3 NIFStream::getMatrix3() -{ - Matrix3 mat; - for(size_t i = 0;i < 3;i++) - { - for(size_t j = 0;j < 3;j++) - mat.mValues[i][j] = getFloat(); - } - return mat; -} -osg::Quat NIFStream::getQuaternion() -{ - osg::Quat quat; - quat.w() = getFloat(); - quat.x() = getFloat(); - quat.y() = getFloat(); - quat.z() = getFloat(); - return quat; -} -Transformation NIFStream::getTrafo() -{ - Transformation t; - t.pos = getVector3(); - t.rotation = getMatrix3(); - t.scale = getFloat(); - return t; -} -std::string NIFStream::getString(size_t length) -{ - std::vector str (length+1, 0); - - inp->read(&str[0], length); - - return &str[0]; -} -std::string NIFStream::getString() -{ - size_t size = read_le32(); - return getString(size); -} -std::string NIFStream::getVersionString() -{ - std::string result; - std::getline(*inp, result); - return result; -} - -void NIFStream::getUShorts(std::vector &vec, size_t size) -{ - vec.resize(size); - for(size_t i = 0;i < vec.size();i++) - vec[i] = getUShort(); -} -void NIFStream::getFloats(std::vector &vec, size_t size) -{ - vec.resize(size); - for(size_t i = 0;i < vec.size();i++) - vec[i] = getFloat(); -} -void NIFStream::getVector2s(std::vector &vec, size_t size) -{ - vec.resize(size); - for(size_t i = 0;i < vec.size();i++) - vec[i] = getVector2(); -} -void NIFStream::getVector3s(std::vector &vec, size_t size) -{ - vec.resize(size); - for(size_t i = 0;i < vec.size();i++) - vec[i] = getVector3(); -} -void NIFStream::getVector4s(std::vector &vec, size_t size) -{ - vec.resize(size); - for(size_t i = 0;i < vec.size();i++) - vec[i] = getVector4(); -} -void NIFStream::getQuaternions(std::vector &quat, size_t size) -{ - quat.resize(size); - for(size_t i = 0;i < quat.size();i++) - quat[i] = getQuaternion(); -} +//Public functions } diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index 860c62e64..d33771f45 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -2,7 +2,7 @@ #ifndef OPENMW_COMPONENTS_NIF_NIFSTREAM_HPP #define OPENMW_COMPONENTS_NIF_NIFSTREAM_HPP - +#include #include #include #include @@ -26,10 +26,44 @@ class NIFStream { /// Input stream Files::IStreamPtr inp; - uint8_t read_byte(); - uint16_t read_le16(); - uint32_t read_le32(); - float read_le32f(); + uint8_t read_byte() { + uint8_t byte; + inp->read((char*)&byte, 1); + return byte; + } + + uint16_t read_le16() { + alignas(2) uint8_t buffer[2]; + inp->read((char*)buffer, 2); + return static_cast(*((uint16_t*)buffer)); + } + uint32_t read_le32() { + alignas(4) uint8_t buffer[4]; + inp->read((char*)buffer, 4); + return static_cast(*((uint32_t*)buffer)); + } + uint64_t read_le64() { + alignas(8) uint8_t buffer[8]; + inp->read((char*)buffer, 8); + return static_cast(*((uint64_t*)buffer)); + } + __m128 read_le96() { + alignas(8) uint8_t buffer[16]; + inp->read((char*)buffer, 12); + return static_cast<__m128>(*((__m128*)buffer)); + } + __m128 read_le128() { + alignas(16) uint8_t buffer[16]; + inp->read((char*)buffer, 16); + return static_cast<__m128>(*((__m128*)buffer)); + } + float read_le32f() { + union { + uint32_t i; + float f; + } u = { read_le32() }; + return u.f; + } public: @@ -46,26 +80,120 @@ public: unsigned int getUInt() { return read_le32(); } float getFloat() { return read_le32f(); } - osg::Vec2f getVector2(); - osg::Vec3f getVector3(); - osg::Vec4f getVector4(); - Matrix3 getMatrix3(); - osg::Quat getQuaternion(); - Transformation getTrafo(); + osg::Vec2f getVector2() { + union { + uint64_t i; + float f[2]; + } u = { read_le64() }; + osg::Vec2f vec; + for (size_t i = 0;i < 2;i++) + vec._v[i] = u.f[i]; + return vec; + } + osg::Vec3f getVector3() { + union { + __m128 i; + float f[4]; + } u = { read_le96() }; + osg::Vec3f vec; + for (size_t i = 0;i < 3;i++) + vec._v[i] = u.f[i]; + return vec; + } + osg::Vec4f getVector4() { + union { + __m128 i; + float f[4]; + } u = { read_le128() }; + osg::Vec4f vec; + for (size_t i = 0;i < 4;i++) + vec._v[i] = u.f[i]; + return vec; + } + Matrix3 getMatrix3() { + Matrix3 mat; + alignas(16) union { + float f[9]; + uint8_t buffer[36]; + } u; + inp->read((char*)u.buffer, 36); + for (size_t i = 0;i < 3;i++) + { + for (size_t j = 0;j < 3;j++) + mat.mValues[i][j] = u.f[3*i+j]; + } + return mat; + } + osg::Quat getQuaternion() { + union { + __m128 i; + float f[4]; + } u = { read_le128() }; + osg::Quat quat; + quat.w() = u.f[0]; + quat.x() = u.f[1]; + quat.y() = u.f[2]; + quat.z() = u.f[3]; + return quat; + } + Transformation getTrafo() { + Transformation t; + t.pos = getVector3(); + t.rotation = getMatrix3(); + t.scale = getFloat(); + return t; + } ///Read in a string of the given length - std::string getString(size_t length); + std::string getString(size_t length) { + std::vector str(length + 1, 0); + + inp->read(&str[0], length); + + return &str[0]; + } ///Read in a string of the length specified in the file - std::string getString(); + std::string getString() { + size_t size = read_le32(); + return getString(size); + } ///This is special since the version string doesn't start with a number, and ends with "\n" - std::string getVersionString(); - - void getUShorts(std::vector &vec, size_t size); - void getFloats(std::vector &vec, size_t size); - void getVector2s(std::vector &vec, size_t size); - void getVector3s(std::vector &vec, size_t size); - void getVector4s(std::vector &vec, size_t size); - void getQuaternions(std::vector &quat, size_t size); + std::string getVersionString() { + std::string result; + std::getline(*inp, result); + return result; + } + + void getUShorts(std::vector &vec, size_t size) { + vec.resize(size); + for (size_t i = 0;i < vec.size();i++) + vec[i] = getUShort(); + } + void getFloats(std::vector &vec, size_t size) { + vec.resize(size); + for (size_t i = 0;i < vec.size();i++) + vec[i] = getFloat(); + } + void getVector2s(std::vector &vec, size_t size) { + vec.resize(size); + for (size_t i = 0;i < vec.size();i++) + vec[i] = getVector2(); + } + void getVector3s(std::vector &vec, size_t size) { + vec.resize(size); + for (size_t i = 0;i < vec.size();i++) + vec[i] = getVector3(); + } + void getVector4s(std::vector &vec, size_t size) { + vec.resize(size); + for (size_t i = 0;i < vec.size();i++) + vec[i] = getVector4(); + } + void getQuaternions(std::vector &quat, size_t size) { + quat.resize(size); + for (size_t i = 0;i < quat.size();i++) + quat[i] = getQuaternion(); + } }; } From 090a8408b828192498209342bcab29d8bdd12357 Mon Sep 17 00:00:00 2001 From: Date: Thu, 21 Sep 2017 22:37:19 -0500 Subject: [PATCH 2/5] made nif basic type read optimizations more portable --- components/nif/nifstream.hpp | 146 +++++++++++++++-------------------- 1 file changed, 63 insertions(+), 83 deletions(-) diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index d33771f45..35c042e7d 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -2,7 +2,7 @@ #ifndef OPENMW_COMPONENTS_NIF_NIFSTREAM_HPP #define OPENMW_COMPONENTS_NIF_NIFSTREAM_HPP -#include + #include #include #include @@ -21,50 +21,38 @@ namespace Nif class NIFFile; +template inline void readLittleEndianBufferOfType(Files::IStreamPtr &pIStream, T* dest) +{ +#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) + pIStream->read((char*)dest, numInstances * sizeof(T)); +#else + char buffer[numInstances * sizeof(T)]; + pIStream->read((char*)buffer, numInstances * sizeof(T)); + /* + Due to the loop iterations being known at compile time, + this nested loop will most likely be unrolled + */ + for (uint32_t i = 0; i < numInstances; i++) + { + dest[i] = 0; + for (uint32_t byte = 0; byte < sizeof(T); byte++) + dest[i] |= ((T)buffer[i * sizeof(T) + byte]) << (byte * 8); + } +#endif +} + +template type inline readLittleEndianType(Files::IStreamPtr &pIStream) +{ + type val; + readLittleEndianBufferOfType<1,type>(pIStream, (type*)&val); + return val; +} + class NIFStream { /// Input stream Files::IStreamPtr inp; - uint8_t read_byte() { - uint8_t byte; - inp->read((char*)&byte, 1); - return byte; - } - - uint16_t read_le16() { - alignas(2) uint8_t buffer[2]; - inp->read((char*)buffer, 2); - return static_cast(*((uint16_t*)buffer)); - } - uint32_t read_le32() { - alignas(4) uint8_t buffer[4]; - inp->read((char*)buffer, 4); - return static_cast(*((uint32_t*)buffer)); - } - uint64_t read_le64() { - alignas(8) uint8_t buffer[8]; - inp->read((char*)buffer, 8); - return static_cast(*((uint64_t*)buffer)); - } - __m128 read_le96() { - alignas(8) uint8_t buffer[16]; - inp->read((char*)buffer, 12); - return static_cast<__m128>(*((__m128*)buffer)); - } - __m128 read_le128() { - alignas(16) uint8_t buffer[16]; - inp->read((char*)buffer, 16); - return static_cast<__m128>(*((__m128*)buffer)); - } - float read_le32f() { - union { - uint32_t i; - float f; - } u = { read_le32() }; - return u.f; - } - public: NIFFile * const file; @@ -73,67 +61,59 @@ public: void skip(size_t size) { inp->ignore(size); } - char getChar() { return read_byte(); } - short getShort() { return read_le16(); } - unsigned short getUShort() { return read_le16(); } - int getInt() { return read_le32(); } - unsigned int getUInt() { return read_le32(); } - float getFloat() { return read_le32f(); } + char getChar() + { + return readLittleEndianType(inp); + } + short getShort() + { + return readLittleEndianType(inp); + } + unsigned short getUShort() + { + return readLittleEndianType(inp); + } + int getInt() + { + return readLittleEndianType(inp); + } + unsigned int getUInt() + { + return readLittleEndianType(inp); + } + float getFloat() + { + return readLittleEndianType(inp); + } osg::Vec2f getVector2() { - union { - uint64_t i; - float f[2]; - } u = { read_le64() }; osg::Vec2f vec; - for (size_t i = 0;i < 2;i++) - vec._v[i] = u.f[i]; + readLittleEndianBufferOfType<2,float>(inp, (float*)&vec._v[0]); return vec; } osg::Vec3f getVector3() { - union { - __m128 i; - float f[4]; - } u = { read_le96() }; osg::Vec3f vec; - for (size_t i = 0;i < 3;i++) - vec._v[i] = u.f[i]; + readLittleEndianBufferOfType<3, float>(inp, (float*)&vec._v[0]); return vec; } osg::Vec4f getVector4() { - union { - __m128 i; - float f[4]; - } u = { read_le128() }; osg::Vec4f vec; - for (size_t i = 0;i < 4;i++) - vec._v[i] = u.f[i]; + readLittleEndianBufferOfType<4, float>(inp, (float*)&vec._v[0]); return vec; } Matrix3 getMatrix3() { Matrix3 mat; - alignas(16) union { - float f[9]; - uint8_t buffer[36]; - } u; - inp->read((char*)u.buffer, 36); - for (size_t i = 0;i < 3;i++) - { - for (size_t j = 0;j < 3;j++) - mat.mValues[i][j] = u.f[3*i+j]; - } + readLittleEndianBufferOfType<9, float>(inp, (float*)&mat.mValues); return mat; } osg::Quat getQuaternion() { - union { - __m128 i; - float f[4]; - } u = { read_le128() }; + float f[4]; + readLittleEndianBufferOfType<4, float>(inp, (float*)&f); osg::Quat quat; - quat.w() = u.f[0]; - quat.x() = u.f[1]; - quat.y() = u.f[2]; - quat.z() = u.f[3]; + quat.w() = f[0]; + quat.x() = f[1]; + quat.y() = f[2]; + quat.z() = f[3]; return quat; } Transformation getTrafo() { @@ -154,7 +134,7 @@ public: } ///Read in a string of the length specified in the file std::string getString() { - size_t size = read_le32(); + size_t size = readLittleEndianType(inp); return getString(size); } ///This is special since the version string doesn't start with a number, and ends with "\n" From 8834066dea932defa23f8345210eca2ecf2739c3 Mon Sep 17 00:00:00 2001 From: Date: Thu, 21 Sep 2017 23:47:09 -0500 Subject: [PATCH 3/5] make streaming to a type array in nif a direct copy from the file into the vector --- components/nif/nifstream.hpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index 35c042e7d..4d7e39ecb 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -41,6 +41,25 @@ template inline void readLittleEndianBufferO #endif } +template inline void readLittleEndianDynamicBufferOfType(Files::IStreamPtr &pIStream, T* dest, uint32_t numInstances) +{ +#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) + pIStream->read((char*)dest, numInstances * sizeof(T)); +#else + char buffer[numInstances * sizeof(T)]; + pIStream->read((char*)buffer, numInstances * sizeof(T)); + /* + Due to the loop iterations being known at compile time, + this nested loop will most likely be unrolled + */ + for (uint32_t i = 0; i < numInstances; i++) + { + dest[i] = 0; + for (uint32_t byte = 0; byte < sizeof(T); byte++) + dest[i] |= ((T)buffer[i * sizeof(T) + byte]) << (byte * 8); + } +#endif +} template type inline readLittleEndianType(Files::IStreamPtr &pIStream) { type val; @@ -146,28 +165,23 @@ public: void getUShorts(std::vector &vec, size_t size) { vec.resize(size); - for (size_t i = 0;i < vec.size();i++) - vec[i] = getUShort(); + readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); } void getFloats(std::vector &vec, size_t size) { vec.resize(size); - for (size_t i = 0;i < vec.size();i++) - vec[i] = getFloat(); + readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); } void getVector2s(std::vector &vec, size_t size) { vec.resize(size); - for (size_t i = 0;i < vec.size();i++) - vec[i] = getVector2(); + readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); } void getVector3s(std::vector &vec, size_t size) { vec.resize(size); - for (size_t i = 0;i < vec.size();i++) - vec[i] = getVector3(); + readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); } void getVector4s(std::vector &vec, size_t size) { vec.resize(size); - for (size_t i = 0;i < vec.size();i++) - vec[i] = getVector4(); + readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); } void getQuaternions(std::vector &quat, size_t size) { quat.resize(size); From 30a213a9b3bccfcfad3e50b5eb96ecb50c6e8d70 Mon Sep 17 00:00:00 2001 From: Date: Fri, 22 Sep 2017 21:08:25 -0500 Subject: [PATCH 4/5] updates for nifstream optimization including fixing the non-x86 path for little endian reads --- components/nif/nifstream.hpp | 84 ++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index 4d7e39ecb..290800042 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -14,6 +14,8 @@ #include #include +#include + #include "niftypes.hpp" namespace Nif @@ -21,49 +23,62 @@ namespace Nif class NIFFile; -template inline void readLittleEndianBufferOfType(Files::IStreamPtr &pIStream, T* dest) +/* + readLittleEndianBufferOfType: This template should only be used with non POD data types +*/ +template inline void readLittleEndianBufferOfType(Files::IStreamPtr &pIStream, T* dest) { #if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) pIStream->read((char*)dest, numInstances * sizeof(T)); #else - char buffer[numInstances * sizeof(T)]; - pIStream->read((char*)buffer, numInstances * sizeof(T)); + uint8_t* destByteBuffer = (uint8_t*)dest; + pIStream->read((char*)dest, numInstances * sizeof(T)); /* Due to the loop iterations being known at compile time, this nested loop will most likely be unrolled + For example, for 2 instances of a 4 byte data type, you should get the below result */ + union { + IntegerT i; + T t; + } u; for (uint32_t i = 0; i < numInstances; i++) { - dest[i] = 0; + u = { 0 }; for (uint32_t byte = 0; byte < sizeof(T); byte++) - dest[i] |= ((T)buffer[i * sizeof(T) + byte]) << (byte * 8); + u.i |= (((IntegerT)destByteBuffer[i * sizeof(T) + byte]) << (byte * 8)); + dest[i] = u.t; } #endif } -template inline void readLittleEndianDynamicBufferOfType(Files::IStreamPtr &pIStream, T* dest, uint32_t numInstances) +/* + readLittleEndianDynamicBufferOfType: This template should only be used with non POD data types +*/ +template inline void readLittleEndianDynamicBufferOfType(Files::IStreamPtr &pIStream, T* dest, uint32_t numInstances) { #if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) pIStream->read((char*)dest, numInstances * sizeof(T)); #else - char buffer[numInstances * sizeof(T)]; - pIStream->read((char*)buffer, numInstances * sizeof(T)); - /* - Due to the loop iterations being known at compile time, - this nested loop will most likely be unrolled - */ + uint8_t* destByteBuffer = (uint8_t*)dest; + pIStream->read((char*)dest, numInstances * sizeof(T)); + union { + IntegerT i; + T t; + } u; for (uint32_t i = 0; i < numInstances; i++) { - dest[i] = 0; + u.i = 0; for (uint32_t byte = 0; byte < sizeof(T); byte++) - dest[i] |= ((T)buffer[i * sizeof(T) + byte]) << (byte * 8); + u.i |= ((IntegerT)destByteBuffer[i * sizeof(T) + byte]) << (byte * 8); + dest[i] = u.t; } #endif } -template type inline readLittleEndianType(Files::IStreamPtr &pIStream) +template type inline readLittleEndianType(Files::IStreamPtr &pIStream) { type val; - readLittleEndianBufferOfType<1,type>(pIStream, (type*)&val); + readLittleEndianBufferOfType<1,type,IntegerT>(pIStream, (type*)&val); return val; } @@ -82,52 +97,52 @@ public: char getChar() { - return readLittleEndianType(inp); + return readLittleEndianType(inp); } short getShort() { - return readLittleEndianType(inp); + return readLittleEndianType(inp); } unsigned short getUShort() { - return readLittleEndianType(inp); + return readLittleEndianType(inp); } int getInt() { - return readLittleEndianType(inp); + return readLittleEndianType(inp); } unsigned int getUInt() { - return readLittleEndianType(inp); + return readLittleEndianType(inp); } float getFloat() { - return readLittleEndianType(inp); + return readLittleEndianType(inp); } osg::Vec2f getVector2() { osg::Vec2f vec; - readLittleEndianBufferOfType<2,float>(inp, (float*)&vec._v[0]); + readLittleEndianBufferOfType<2,float,uint32_t>(inp, (float*)&vec._v[0]); return vec; } osg::Vec3f getVector3() { osg::Vec3f vec; - readLittleEndianBufferOfType<3, float>(inp, (float*)&vec._v[0]); + readLittleEndianBufferOfType<3, float,uint32_t>(inp, (float*)&vec._v[0]); return vec; } osg::Vec4f getVector4() { osg::Vec4f vec; - readLittleEndianBufferOfType<4, float>(inp, (float*)&vec._v[0]); + readLittleEndianBufferOfType<4, float,uint32_t>(inp, (float*)&vec._v[0]); return vec; } Matrix3 getMatrix3() { Matrix3 mat; - readLittleEndianBufferOfType<9, float>(inp, (float*)&mat.mValues); + readLittleEndianBufferOfType<9, float,uint32_t>(inp, (float*)&mat.mValues); return mat; } osg::Quat getQuaternion() { float f[4]; - readLittleEndianBufferOfType<4, float>(inp, (float*)&f); + readLittleEndianBufferOfType<4, float,uint32_t>(inp, (float*)&f); osg::Quat quat; quat.w() = f[0]; quat.x() = f[1]; @@ -153,7 +168,7 @@ public: } ///Read in a string of the length specified in the file std::string getString() { - size_t size = readLittleEndianType(inp); + size_t size = readLittleEndianType(inp); return getString(size); } ///This is special since the version string doesn't start with a number, and ends with "\n" @@ -165,23 +180,26 @@ public: void getUShorts(std::vector &vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); + readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); } void getFloats(std::vector &vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); + readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); } void getVector2s(std::vector &vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); + /* The packed storage of each Vec2f is 2 floats exactly */ + readLittleEndianDynamicBufferOfType(inp,(float*) &vec.front(), size*2); } void getVector3s(std::vector &vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); + /* The packed storage of each Vec3f is 3 floats exactly */ + readLittleEndianDynamicBufferOfType(inp, (float*) &vec.front(), size*3); } void getVector4s(std::vector &vec, size_t size) { vec.resize(size); - readLittleEndianDynamicBufferOfType(inp, &vec.front(), size); + /* The packed storage of each Vec4f is 4 floats exactly */ + readLittleEndianDynamicBufferOfType(inp, (float*) &vec.front(), size*4); } void getQuaternions(std::vector &quat, size_t size) { quat.resize(size); From 825de71b294867a177cfd44543da10b0f4d45fa2 Mon Sep 17 00:00:00 2001 From: Date: Sat, 23 Sep 2017 11:10:05 -0500 Subject: [PATCH 5/5] removed an iostream include used for debug prints from nifstream.hpp --- components/nif/nifstream.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index 290800042..d00069be7 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -14,8 +14,6 @@ #include #include -#include - #include "niftypes.hpp" namespace Nif