Phase out NIFStream::get[Types]

macos_ci_fix
Alexei Kotov 2 years ago
parent e7bbfed1fd
commit 57144accf6

@ -55,7 +55,7 @@ namespace Nif
nif->skip(2); // Keep flags and compress flags nif->skip(2); // Keep flags and compress flags
if (nif->getBoolean()) if (nif->getBoolean())
nif->getVector3s(vertices, verts); nif->readVector(vertices, verts);
unsigned int dataFlags = 0; unsigned int dataFlags = 0;
if (nif->getVersion() >= NIFStream::generateVersion(10, 0, 1, 0)) if (nif->getVersion() >= NIFStream::generateVersion(10, 0, 1, 0))
@ -67,11 +67,11 @@ namespace Nif
if (nif->getBoolean()) if (nif->getBoolean())
{ {
nif->getVector3s(normals, verts); nif->readVector(normals, verts);
if (dataFlags & 0x1000) if (dataFlags & 0x1000)
{ {
nif->getVector3s(tangents, verts); nif->readVector(tangents, verts);
nif->getVector3s(bitangents, verts); nif->readVector(bitangents, verts);
} }
} }
@ -79,7 +79,7 @@ namespace Nif
radius = nif->getFloat(); radius = nif->getFloat();
if (nif->getBoolean()) if (nif->getBoolean())
nif->getVector4s(colors, verts); nif->readVector(colors, verts);
unsigned int numUVs = dataFlags; unsigned int numUVs = dataFlags;
if (nif->getVersion() <= NIFStream::generateVersion(4, 2, 2, 0)) if (nif->getVersion() <= NIFStream::generateVersion(4, 2, 2, 0))
@ -102,7 +102,7 @@ namespace Nif
uvlist.resize(numUVs); uvlist.resize(numUVs);
for (unsigned int i = 0; i < numUVs; i++) for (unsigned int i = 0; i < numUVs; i++)
{ {
nif->getVector2s(uvlist[i], verts); nif->readVector(uvlist[i], verts);
// flip the texture coordinates to convert them to the OpenGL convention of bottom-left image origin // flip the texture coordinates to convert them to the OpenGL convention of bottom-left image origin
for (unsigned int uv = 0; uv < uvlist[i].size(); ++uv) for (unsigned int uv = 0; uv < uvlist[i].size(); ++uv)
{ {
@ -135,7 +135,7 @@ namespace Nif
if (nif->getVersion() > NIFFile::NIFVersion::VER_OB_OLD) if (nif->getVersion() > NIFFile::NIFVersion::VER_OB_OLD)
hasTriangles = nif->getBoolean(); hasTriangles = nif->getBoolean();
if (hasTriangles) if (hasTriangles)
nif->getUShorts(triangles, cnt); nif->readVector(triangles, cnt);
// Read the match list, which lists the vertices that are equal to // Read the match list, which lists the vertices that are equal to
// vertices. We don't actually need need this for anything, so // vertices. We don't actually need need this for anything, so
@ -157,7 +157,7 @@ namespace Nif
int numStrips = nif->getUShort(); int numStrips = nif->getUShort();
std::vector<unsigned short> lengths; std::vector<unsigned short> lengths;
nif->getUShorts(lengths, numStrips); nif->readVector(lengths, numStrips);
// "Has Strips" flag. Exceptionally useful. // "Has Strips" flag. Exceptionally useful.
bool hasStrips = true; bool hasStrips = true;
@ -168,15 +168,15 @@ namespace Nif
strips.resize(numStrips); strips.resize(numStrips);
for (int i = 0; i < numStrips; i++) for (int i = 0; i < numStrips; i++)
nif->getUShorts(strips[i], lengths[i]); nif->readVector(strips[i], lengths[i]);
} }
void NiLinesData::read(NIFStream* nif) void NiLinesData::read(NIFStream* nif)
{ {
NiGeometryData::read(nif); NiGeometryData::read(nif);
size_t num = vertices.size(); size_t num = vertices.size();
std::vector<char> flags; std::vector<uint8_t> flags;
nif->getChars(flags, num); nif->readVector(flags, num);
// Can't construct a line from a single vertex. // Can't construct a line from a single vertex.
if (num < 2) if (num < 2)
return; return;
@ -208,21 +208,21 @@ namespace Nif
if (nif->getVersion() <= NIFStream::generateVersion(10, 0, 1, 0)) if (nif->getVersion() <= NIFStream::generateVersion(10, 0, 1, 0))
std::fill(particleRadii.begin(), particleRadii.end(), nif->getFloat()); std::fill(particleRadii.begin(), particleRadii.end(), nif->getFloat());
else if (nif->getBoolean()) else if (nif->getBoolean())
nif->getFloats(particleRadii, vertices.size()); nif->readVector(particleRadii, vertices.size());
activeCount = nif->getUShort(); activeCount = nif->getUShort();
// Particle sizes // Particle sizes
if (nif->getBoolean()) if (nif->getBoolean())
nif->getFloats(sizes, vertices.size()); nif->readVector(sizes, vertices.size());
if (nif->getVersion() >= NIFStream::generateVersion(10, 0, 1, 0) && nif->getBoolean()) if (nif->getVersion() >= NIFStream::generateVersion(10, 0, 1, 0) && nif->getBoolean())
nif->getQuaternions(rotations, vertices.size()); nif->readVector(rotations, vertices.size());
if (nif->getVersion() >= NIFStream::generateVersion(20, 0, 0, 4)) if (nif->getVersion() >= NIFStream::generateVersion(20, 0, 0, 4))
{ {
if (nif->getBoolean()) if (nif->getBoolean())
nif->getFloats(rotationAngles, vertices.size()); nif->readVector(rotationAngles, vertices.size());
if (nif->getBoolean()) if (nif->getBoolean())
nif->getVector3s(rotationAxes, vertices.size()); nif->readVector(rotationAxes, vertices.size());
} }
} }
@ -231,7 +231,7 @@ namespace Nif
NiParticlesData::read(nif); NiParticlesData::read(nif);
if (nif->getVersion() <= NIFStream::generateVersion(4, 2, 2, 0) && nif->getBoolean()) if (nif->getVersion() <= NIFStream::generateVersion(4, 2, 2, 0) && nif->getBoolean())
nif->getQuaternions(rotations, vertices.size()); nif->readVector(rotations, vertices.size());
} }
void NiPosData::read(NIFStream* nif) void NiPosData::read(NIFStream* nif)
@ -301,8 +301,7 @@ namespace Nif
unsigned int numPixels = nif->getUInt(); unsigned int numPixels = nif->getUInt();
bool hasFaces = nif->getVersion() >= NIFStream::generateVersion(10, 4, 0, 2); bool hasFaces = nif->getVersion() >= NIFStream::generateVersion(10, 4, 0, 2);
unsigned int numFaces = hasFaces ? nif->getUInt() : 1; unsigned int numFaces = hasFaces ? nif->getUInt() : 1;
if (numPixels && numFaces) nif->readVector(data, numPixels * numFaces);
nif->getUChars(data, numPixels * numFaces);
} }
void NiPixelData::post(Reader& nif) void NiPixelData::post(Reader& nif)
@ -397,24 +396,22 @@ namespace Nif
size_t numBones = nif->getUShort(); size_t numBones = nif->getUShort();
size_t numStrips = nif->getUShort(); size_t numStrips = nif->getUShort();
size_t bonesPerVertex = nif->getUShort(); size_t bonesPerVertex = nif->getUShort();
if (numBones) nif->readVector(bones, numBones);
nif->getUShorts(bones, numBones);
bool hasVertexMap = true; bool hasVertexMap = true;
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0))
hasVertexMap = nif->getBoolean(); hasVertexMap = nif->getBoolean();
if (hasVertexMap && numVertices) if (hasVertexMap)
nif->getUShorts(vertexMap, numVertices); nif->readVector(vertexMap, numVertices);
bool hasVertexWeights = true; bool hasVertexWeights = true;
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0))
hasVertexWeights = nif->getBoolean(); hasVertexWeights = nif->getBoolean();
if (hasVertexWeights && numVertices && bonesPerVertex) if (hasVertexWeights)
nif->getFloats(weights, numVertices * bonesPerVertex); nif->readVector(weights, numVertices * bonesPerVertex);
std::vector<unsigned short> stripLengths; std::vector<unsigned short> stripLengths;
if (numStrips) nif->readVector(stripLengths, numStrips);
nif->getUShorts(stripLengths, numStrips);
bool hasFaces = true; bool hasFaces = true;
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0))
@ -425,14 +422,14 @@ namespace Nif
{ {
strips.resize(numStrips); strips.resize(numStrips);
for (size_t i = 0; i < numStrips; i++) for (size_t i = 0; i < numStrips; i++)
nif->getUShorts(strips[i], stripLengths[i]); nif->readVector(strips[i], stripLengths[i]);
} }
else if (numTriangles) else
nif->getUShorts(triangles, numTriangles * 3); nif->readVector(triangles, numTriangles * 3);
} }
bool hasBoneIndices = nif->getChar() != 0; bool hasBoneIndices = nif->getChar() != 0;
if (hasBoneIndices && numVertices && bonesPerVertex) if (hasBoneIndices)
nif->getChars(boneIndices, numVertices * bonesPerVertex); nif->readVector(boneIndices, numVertices * bonesPerVertex);
if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3) if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3)
{ {
nif->getChar(); // LOD level nif->getChar(); // LOD level
@ -490,7 +487,7 @@ namespace Nif
{ {
mMorphs[i].mKeyFrames = std::make_shared<FloatKeyMap>(); mMorphs[i].mKeyFrames = std::make_shared<FloatKeyMap>();
mMorphs[i].mKeyFrames->read(nif, /*morph*/ true); mMorphs[i].mKeyFrames->read(nif, /*morph*/ true);
nif->getVector3s(mMorphs[i].mVertices, vertCount); nif->readVector(mMorphs[i].mVertices, vertCount);
} }
} }

@ -6,8 +6,7 @@ namespace Nif
void NiExtraData::read(NIFStream* nif) void NiExtraData::read(NIFStream* nif)
{ {
Extra::read(nif); Extra::read(nif);
if (recordSize) nif->readVector(data, recordSize);
nif->getChars(data, recordSize);
} }
void NiStringExtraData::read(NIFStream* nif) void NiStringExtraData::read(NIFStream* nif)
@ -47,17 +46,13 @@ namespace Nif
{ {
Extra::read(nif); Extra::read(nif);
unsigned int num = nif->getUInt(); nif->readVector(data, nif->getUInt());
if (num)
nif->getUInts(data, num);
} }
void NiBinaryExtraData::read(NIFStream* nif) void NiBinaryExtraData::read(NIFStream* nif)
{ {
Extra::read(nif); Extra::read(nif);
unsigned int size = nif->getUInt(); nif->readVector(data, nif->getUInt());
if (size)
nif->getChars(data, size);
} }
void NiBooleanExtraData::read(NIFStream* nif) void NiBooleanExtraData::read(NIFStream* nif)
@ -82,9 +77,7 @@ namespace Nif
void NiFloatsExtraData::read(NIFStream* nif) void NiFloatsExtraData::read(NIFStream* nif)
{ {
Extra::read(nif); Extra::read(nif);
unsigned int num = nif->getUInt(); nif->readVector(data, nif->getUInt());
if (num)
nif->getFloats(data, num);
} }
void BSBound::read(NIFStream* nif) void BSBound::read(NIFStream* nif)

@ -319,28 +319,26 @@ namespace Nif
if (hasRecTypeListings) if (hasRecTypeListings)
{ {
unsigned short recTypeNum = nif.getUShort(); unsigned short recTypeNum = nif.getUShort();
if (recTypeNum) // Record type list // Record type list
nif.getSizedStrings(recTypes, recTypeNum); nif.getSizedStrings(recTypes, recTypeNum);
if (recNum) // Record type mapping for each record // Record type mapping for each record
nif.getUShorts(recTypeIndices, recNum); nif.readVector(recTypeIndices, recNum);
if (ver >= NIFStream::generateVersion(5, 0, 0, 6)) // Groups if (ver >= NIFStream::generateVersion(5, 0, 0, 6)) // Groups
{ {
if (ver >= NIFStream::generateVersion(20, 1, 0, 1)) // String table if (ver >= NIFStream::generateVersion(20, 1, 0, 1)) // String table
{ {
if (ver >= NIFStream::generateVersion(20, 2, 0, 5) && recNum) // Record sizes if (ver >= NIFStream::generateVersion(20, 2, 0, 5)) // Record sizes
{ {
std::vector<unsigned int> recSizes; // Currently unused std::vector<unsigned int> recSizes; // Currently unused
nif.getUInts(recSizes, recNum); nif.readVector(recSizes, recNum);
} }
const std::size_t stringNum = nif.getUInt(); const std::size_t stringNum = nif.getUInt();
nif.getUInt(); // Max string length nif.getUInt(); // Max string length
if (stringNum) nif.getSizedStrings(strings, stringNum);
nif.getSizedStrings(strings, stringNum);
} }
std::vector<unsigned int> groups; // Currently unused std::vector<unsigned int> groups; // Currently unused
unsigned int groupNum = nif.getUInt(); unsigned int groupNum = nif.getUInt();
if (groupNum) nif.readVector(groups, groupNum);
nif.getUInts(groups, groupNum);
} }
} }

@ -155,19 +155,6 @@ namespace Nif
Transformation getTrafo() { return get<Transformation>(); } Transformation getTrafo() { return get<Transformation>(); }
bool getBoolean() { return get<bool>(); } bool getBoolean() { return get<bool>(); }
std::string getString() { return get<std::string>(); } std::string getString() { return get<std::string>(); }
/// DEPRECATED: Use readVector()
void getChars(std::vector<char>& vec, size_t size) { readVector(vec, size); }
void getUChars(std::vector<unsigned char>& vec, size_t size) { readVector(vec, size); }
void getUShorts(std::vector<unsigned short>& vec, size_t size) { readVector(vec, size); }
void getFloats(std::vector<float>& vec, size_t size) { readVector(vec, size); }
void getInts(std::vector<int>& vec, size_t size) { readVector(vec, size); }
void getUInts(std::vector<unsigned int>& vec, size_t size) { readVector(vec, size); }
void getVector2s(std::vector<osg::Vec2f>& vec, size_t size) { readVector(vec, size); }
void getVector3s(std::vector<osg::Vec3f>& vec, size_t size) { readVector(vec, size); }
void getVector4s(std::vector<osg::Vec4f>& vec, size_t size) { readVector(vec, size); }
void getQuaternions(std::vector<osg::Quat>& vec, size_t size) { readVector(vec, size); }
void getStrings(std::vector<std::string>& vec, size_t size) { readVector(vec, size); }
}; };
template <> template <>

@ -157,11 +157,9 @@ namespace Nif
num = nif->getBoolean(); // Has Shader num = nif->getBoolean(); // Has Shader
else if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 5)) else if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 5))
num = nif->getUInt(); num = nif->getUInt();
if (num)
{ nif->readVector(names, num);
nif->getStrings(names, num); nif->readVector(extra, num);
nif->getInts(extra, num);
}
if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 5)) if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 5))
active = nif->getUInt(); active = nif->getUInt();
if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS) if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS)
@ -377,10 +375,7 @@ namespace Nif
} }
if (mDataSize > 0) if (mDataSize > 0)
{
mTriangles.resize(triNum * 3);
nif->readVector(mTriangles, triNum * 3); nif->readVector(mTriangles, triNum * 3);
}
if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_SSE) if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_SSE)
{ {

@ -53,8 +53,7 @@ namespace Nif
mOffset = nif->getVector4(); mOffset = nif->getVector4();
if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3) if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3)
nif->getChar(); // MOPP data build type nif->getChar(); // MOPP data build type
if (size) nif->readVector(mData, size);
nif->getChars(mData, size);
} }
void bhkEntityCInfo::read(NIFStream* nif) void bhkEntityCInfo::read(NIFStream* nif)
@ -99,18 +98,10 @@ namespace Nif
mMaterialIndex = nif->getUInt(); mMaterialIndex = nif->getUInt();
mReference = nif->getUShort(); mReference = nif->getUShort();
mTransformIndex = nif->getUShort(); mTransformIndex = nif->getUShort();
size_t numVertices = nif->getUInt(); nif->readVector(mVertices, nif->getUInt());
if (numVertices) nif->readVector(mIndices, nif->getUInt());
nif->getUShorts(mVertices, numVertices); nif->readVector(mStrips, nif->getUInt());
size_t numIndices = nif->getUInt(); nif->readVector(mWeldingInfos, nif->getUInt());
if (numIndices)
nif->getUShorts(mIndices, numIndices);
size_t numStrips = nif->getUInt();
if (numStrips)
nif->getUShorts(mStrips, numStrips);
size_t numInfos = nif->getUInt();
if (numInfos)
nif->getUShorts(mWeldingInfos, numInfos);
} }
void bhkRigidBodyCInfo::read(NIFStream* nif) void bhkRigidBodyCInfo::read(NIFStream* nif)
@ -395,8 +386,7 @@ namespace Nif
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0))
mScale = nif->getVector4(); mScale = nif->getVector4();
readRecordList(nif, mData); readRecordList(nif, mData);
unsigned int numFilters = nif->getUInt(); nif->readVector(mFilters, nif->getUInt());
nif->getUInts(mFilters, numFilters);
} }
void bhkNiTriStripsShape::post(Reader& nif) void bhkNiTriStripsShape::post(Reader& nif)
@ -438,7 +428,7 @@ namespace Nif
if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS) if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS)
compressed = nif->getBoolean(); compressed = nif->getBoolean();
if (!compressed) if (!compressed)
nif->getVector3s(mVertices, numVertices); nif->readVector(mVertices, numVertices);
else else
nif->skip(6 * numVertices); // Half-precision vectors are not currently supported nif->skip(6 * numVertices); // Half-precision vectors are not currently supported
if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS) if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS)
@ -465,12 +455,8 @@ namespace Nif
bhkConvexShape::read(nif); bhkConvexShape::read(nif);
mVerticesProperty.read(nif); mVerticesProperty.read(nif);
mNormalsProperty.read(nif); mNormalsProperty.read(nif);
unsigned int numVertices = nif->getUInt(); nif->readVector(mVertices, nif->getUInt());
if (numVertices) nif->readVector(mNormals, nif->getUInt());
nif->getVector4s(mVertices, numVertices);
unsigned int numNormals = nif->getUInt();
if (numNormals)
nif->getVector4s(mNormals, numNormals);
} }
void bhkConvexTransformShape::read(NIFStream* nif) void bhkConvexTransformShape::read(NIFStream* nif)
@ -564,9 +550,7 @@ namespace Nif
for (bhkQsTransform& transform : mChunkTransforms) for (bhkQsTransform& transform : mChunkTransforms)
transform.read(nif); transform.read(nif);
size_t numBigVertices = nif->getUInt(); nif->readVector(mBigVerts, nif->getUInt());
if (numBigVertices)
nif->getVector4s(mBigVerts, numBigVertices);
size_t numBigTriangles = nif->getUInt(); size_t numBigTriangles = nif->getUInt();
mBigTris.resize(numBigTriangles); mBigTris.resize(numBigTriangles);

Loading…
Cancel
Save