|
|
|
@ -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);
|
|
|
|
|