mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 22:09:42 +00:00
NIFStream: clean up comments
This commit is contained in:
parent
e8f9a918ae
commit
ce13f05187
2 changed files with 18 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
#include "nifstream.hpp"
|
||||
// For error reporting
|
||||
|
||||
#include "niffile.hpp"
|
||||
|
||||
namespace Nif
|
||||
|
@ -25,19 +25,16 @@ namespace Nif
|
|||
return t;
|
||||
}
|
||||
|
||||
/// Booleans in 4.0.0.2 (Morrowind format) and earlier are 4 byte, while in 4.1.0.0+ they're 1 byte.
|
||||
bool NIFStream::getBoolean()
|
||||
{
|
||||
return getVersion() < generateVersion(4, 1, 0, 0) ? getInt() != 0 : getChar() != 0;
|
||||
}
|
||||
|
||||
/// Read in a string, either from the string table using the index or from the stream using the specified length
|
||||
std::string NIFStream::getString()
|
||||
{
|
||||
return getVersion() < generateVersion(20, 1, 0, 1) ? getSizedString() : mReader.getString(getUInt());
|
||||
}
|
||||
|
||||
// Convenience utility functions: get the versions of the currently read file
|
||||
unsigned int NIFStream::getVersion() const
|
||||
{
|
||||
return mReader.getVersion();
|
||||
|
|
|
@ -79,6 +79,7 @@ namespace Nif
|
|||
|
||||
void skip(size_t size) { mStream->ignore(size); }
|
||||
|
||||
/// Read into a single instance of type
|
||||
template <class T>
|
||||
void read(T& data)
|
||||
{
|
||||
|
@ -88,12 +89,14 @@ namespace Nif
|
|||
void read(osg::Vec3f& data) { readBufferOfType<3, float>(mStream, data._v); }
|
||||
void read(osg::Vec4f& data) { readBufferOfType<4, float>(mStream, data._v); }
|
||||
|
||||
/// Extract an instance of type
|
||||
template <class T>
|
||||
T get()
|
||||
{
|
||||
return readType<T>(mStream);
|
||||
}
|
||||
|
||||
/// Read multiple instances of type into a vector
|
||||
template <class T>
|
||||
void readVector(std::vector<T>& vec, size_t size)
|
||||
{
|
||||
|
@ -101,6 +104,7 @@ namespace Nif
|
|||
readDynamicBufferOfType<T>(mStream, vec.data(), size);
|
||||
}
|
||||
|
||||
/// Read multiple instances of type into an array
|
||||
template <class T, size_t size>
|
||||
void readArray(std::array<T, size>& arr)
|
||||
{
|
||||
|
@ -158,21 +162,23 @@ namespace Nif
|
|||
|
||||
Transformation getTrafo();
|
||||
|
||||
/// Read in a boolean. Boolean serialization format differs between versions
|
||||
bool getBoolean();
|
||||
|
||||
/// Read in a string, either from the string table or from the stream depending on the version
|
||||
std::string getString();
|
||||
|
||||
unsigned int getVersion() const;
|
||||
unsigned int getUserVersion() const;
|
||||
unsigned int getBethVersion() const;
|
||||
|
||||
// Convert human-readable version numbers into a number that can be compared.
|
||||
/// Convert human-readable version numbers into a number that can be compared
|
||||
static constexpr uint32_t generateVersion(uint8_t major, uint8_t minor, uint8_t patch, uint8_t rev)
|
||||
{
|
||||
return (major << 24) + (minor << 16) + (patch << 8) + rev;
|
||||
}
|
||||
|
||||
/// Read in a string of the given length
|
||||
/// Read a string of the given length
|
||||
std::string getSizedString(size_t length)
|
||||
{
|
||||
std::string str(length, '\0');
|
||||
|
@ -184,21 +190,22 @@ namespace Nif
|
|||
str.erase(end);
|
||||
return str;
|
||||
}
|
||||
/// Read in a string of the length specified in the file
|
||||
|
||||
/// Read a string of the length specified in the file
|
||||
std::string getSizedString()
|
||||
{
|
||||
size_t size = readType<uint32_t>(mStream);
|
||||
return getSizedString(size);
|
||||
}
|
||||
|
||||
/// Specific to Bethesda headers, uses a byte for length
|
||||
/// Read a Bethesda header string that uses a byte for length
|
||||
std::string getExportString()
|
||||
{
|
||||
size_t size = static_cast<size_t>(readType<uint8_t>(mStream));
|
||||
return getSizedString(size);
|
||||
}
|
||||
|
||||
/// This is special since the version string doesn't start with a number, and ends with "\n"
|
||||
/// Read the version string which doesn't start with a number and ends with "\n"
|
||||
std::string getVersionString()
|
||||
{
|
||||
std::string result;
|
||||
|
@ -264,21 +271,21 @@ namespace Nif
|
|||
void getVector2s(std::vector<osg::Vec2f>& vec, size_t size)
|
||||
{
|
||||
vec.resize(size);
|
||||
/* The packed storage of each Vec2f is 2 floats exactly */
|
||||
// The packed storage of each Vec2f is 2 floats exactly
|
||||
readDynamicBufferOfType<float>(mStream, (float*)vec.data(), size * 2);
|
||||
}
|
||||
|
||||
void getVector3s(std::vector<osg::Vec3f>& vec, size_t size)
|
||||
{
|
||||
vec.resize(size);
|
||||
/* The packed storage of each Vec3f is 3 floats exactly */
|
||||
// The packed storage of each Vec3f is 3 floats exactly
|
||||
readDynamicBufferOfType<float>(mStream, (float*)vec.data(), size * 3);
|
||||
}
|
||||
|
||||
void getVector4s(std::vector<osg::Vec4f>& vec, size_t size)
|
||||
{
|
||||
vec.resize(size);
|
||||
/* The packed storage of each Vec4f is 4 floats exactly */
|
||||
// The packed storage of each Vec4f is 4 floats exactly
|
||||
readDynamicBufferOfType<float>(mStream, (float*)vec.data(), size * 4);
|
||||
}
|
||||
|
||||
|
@ -295,7 +302,8 @@ namespace Nif
|
|||
for (size_t i = 0; i < vec.size(); i++)
|
||||
vec[i] = getString();
|
||||
}
|
||||
/// We need to use this when the string table isn't actually initialized.
|
||||
|
||||
/// Read a list of strings without using the string table, e.g. the string table itself
|
||||
void getSizedStrings(std::vector<std::string>& vec, size_t size)
|
||||
{
|
||||
vec.resize(size);
|
||||
|
|
Loading…
Reference in a new issue