From 57144accf676aedd9ff3c3197345caec49b6843a Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Mon, 10 Jul 2023 02:07:51 +0300 Subject: [PATCH] Phase out NIFStream::get[Types] --- components/nif/data.cpp | 63 +++++++++++++++++------------------- components/nif/extra.cpp | 15 +++------ components/nif/niffile.cpp | 18 +++++------ components/nif/nifstream.hpp | 13 -------- components/nif/node.cpp | 11 ++----- components/nif/physics.cpp | 36 ++++++--------------- 6 files changed, 55 insertions(+), 101 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 018e9fc603..1574462892 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -55,7 +55,7 @@ namespace Nif nif->skip(2); // Keep flags and compress flags if (nif->getBoolean()) - nif->getVector3s(vertices, verts); + nif->readVector(vertices, verts); unsigned int dataFlags = 0; if (nif->getVersion() >= NIFStream::generateVersion(10, 0, 1, 0)) @@ -67,11 +67,11 @@ namespace Nif if (nif->getBoolean()) { - nif->getVector3s(normals, verts); + nif->readVector(normals, verts); if (dataFlags & 0x1000) { - nif->getVector3s(tangents, verts); - nif->getVector3s(bitangents, verts); + nif->readVector(tangents, verts); + nif->readVector(bitangents, verts); } } @@ -79,7 +79,7 @@ namespace Nif radius = nif->getFloat(); if (nif->getBoolean()) - nif->getVector4s(colors, verts); + nif->readVector(colors, verts); unsigned int numUVs = dataFlags; if (nif->getVersion() <= NIFStream::generateVersion(4, 2, 2, 0)) @@ -102,7 +102,7 @@ namespace Nif uvlist.resize(numUVs); 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 for (unsigned int uv = 0; uv < uvlist[i].size(); ++uv) { @@ -135,7 +135,7 @@ namespace Nif if (nif->getVersion() > NIFFile::NIFVersion::VER_OB_OLD) hasTriangles = nif->getBoolean(); if (hasTriangles) - nif->getUShorts(triangles, cnt); + nif->readVector(triangles, cnt); // Read the match list, which lists the vertices that are equal to // vertices. We don't actually need need this for anything, so @@ -157,7 +157,7 @@ namespace Nif int numStrips = nif->getUShort(); std::vector lengths; - nif->getUShorts(lengths, numStrips); + nif->readVector(lengths, numStrips); // "Has Strips" flag. Exceptionally useful. bool hasStrips = true; @@ -168,15 +168,15 @@ namespace Nif strips.resize(numStrips); for (int i = 0; i < numStrips; i++) - nif->getUShorts(strips[i], lengths[i]); + nif->readVector(strips[i], lengths[i]); } void NiLinesData::read(NIFStream* nif) { NiGeometryData::read(nif); size_t num = vertices.size(); - std::vector flags; - nif->getChars(flags, num); + std::vector flags; + nif->readVector(flags, num); // Can't construct a line from a single vertex. if (num < 2) return; @@ -208,21 +208,21 @@ namespace Nif if (nif->getVersion() <= NIFStream::generateVersion(10, 0, 1, 0)) std::fill(particleRadii.begin(), particleRadii.end(), nif->getFloat()); else if (nif->getBoolean()) - nif->getFloats(particleRadii, vertices.size()); + nif->readVector(particleRadii, vertices.size()); activeCount = nif->getUShort(); // Particle sizes if (nif->getBoolean()) - nif->getFloats(sizes, vertices.size()); + nif->readVector(sizes, vertices.size()); 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->getBoolean()) - nif->getFloats(rotationAngles, vertices.size()); + nif->readVector(rotationAngles, vertices.size()); if (nif->getBoolean()) - nif->getVector3s(rotationAxes, vertices.size()); + nif->readVector(rotationAxes, vertices.size()); } } @@ -231,7 +231,7 @@ namespace Nif NiParticlesData::read(nif); 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) @@ -301,8 +301,7 @@ namespace Nif unsigned int numPixels = nif->getUInt(); bool hasFaces = nif->getVersion() >= NIFStream::generateVersion(10, 4, 0, 2); unsigned int numFaces = hasFaces ? nif->getUInt() : 1; - if (numPixels && numFaces) - nif->getUChars(data, numPixels * numFaces); + nif->readVector(data, numPixels * numFaces); } void NiPixelData::post(Reader& nif) @@ -397,24 +396,22 @@ namespace Nif size_t numBones = nif->getUShort(); size_t numStrips = nif->getUShort(); size_t bonesPerVertex = nif->getUShort(); - if (numBones) - nif->getUShorts(bones, numBones); + nif->readVector(bones, numBones); bool hasVertexMap = true; if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) hasVertexMap = nif->getBoolean(); - if (hasVertexMap && numVertices) - nif->getUShorts(vertexMap, numVertices); + if (hasVertexMap) + nif->readVector(vertexMap, numVertices); bool hasVertexWeights = true; if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) hasVertexWeights = nif->getBoolean(); - if (hasVertexWeights && numVertices && bonesPerVertex) - nif->getFloats(weights, numVertices * bonesPerVertex); + if (hasVertexWeights) + nif->readVector(weights, numVertices * bonesPerVertex); std::vector stripLengths; - if (numStrips) - nif->getUShorts(stripLengths, numStrips); + nif->readVector(stripLengths, numStrips); bool hasFaces = true; if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) @@ -425,14 +422,14 @@ namespace Nif { strips.resize(numStrips); for (size_t i = 0; i < numStrips; i++) - nif->getUShorts(strips[i], stripLengths[i]); + nif->readVector(strips[i], stripLengths[i]); } - else if (numTriangles) - nif->getUShorts(triangles, numTriangles * 3); + else + nif->readVector(triangles, numTriangles * 3); } bool hasBoneIndices = nif->getChar() != 0; - if (hasBoneIndices && numVertices && bonesPerVertex) - nif->getChars(boneIndices, numVertices * bonesPerVertex); + if (hasBoneIndices) + nif->readVector(boneIndices, numVertices * bonesPerVertex); if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3) { nif->getChar(); // LOD level @@ -490,7 +487,7 @@ namespace Nif { mMorphs[i].mKeyFrames = std::make_shared(); mMorphs[i].mKeyFrames->read(nif, /*morph*/ true); - nif->getVector3s(mMorphs[i].mVertices, vertCount); + nif->readVector(mMorphs[i].mVertices, vertCount); } } diff --git a/components/nif/extra.cpp b/components/nif/extra.cpp index 0e93f1a0ce..4384289f9e 100644 --- a/components/nif/extra.cpp +++ b/components/nif/extra.cpp @@ -6,8 +6,7 @@ namespace Nif void NiExtraData::read(NIFStream* nif) { Extra::read(nif); - if (recordSize) - nif->getChars(data, recordSize); + nif->readVector(data, recordSize); } void NiStringExtraData::read(NIFStream* nif) @@ -47,17 +46,13 @@ namespace Nif { Extra::read(nif); - unsigned int num = nif->getUInt(); - if (num) - nif->getUInts(data, num); + nif->readVector(data, nif->getUInt()); } void NiBinaryExtraData::read(NIFStream* nif) { Extra::read(nif); - unsigned int size = nif->getUInt(); - if (size) - nif->getChars(data, size); + nif->readVector(data, nif->getUInt()); } void NiBooleanExtraData::read(NIFStream* nif) @@ -82,9 +77,7 @@ namespace Nif void NiFloatsExtraData::read(NIFStream* nif) { Extra::read(nif); - unsigned int num = nif->getUInt(); - if (num) - nif->getFloats(data, num); + nif->readVector(data, nif->getUInt()); } void BSBound::read(NIFStream* nif) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index 1757488e3d..0edabdd7a7 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -319,28 +319,26 @@ namespace Nif if (hasRecTypeListings) { unsigned short recTypeNum = nif.getUShort(); - if (recTypeNum) // Record type list - nif.getSizedStrings(recTypes, recTypeNum); - if (recNum) // Record type mapping for each record - nif.getUShorts(recTypeIndices, recNum); + // Record type list + nif.getSizedStrings(recTypes, recTypeNum); + // Record type mapping for each record + nif.readVector(recTypeIndices, recNum); if (ver >= NIFStream::generateVersion(5, 0, 0, 6)) // Groups { 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 recSizes; // Currently unused - nif.getUInts(recSizes, recNum); + nif.readVector(recSizes, recNum); } const std::size_t stringNum = nif.getUInt(); nif.getUInt(); // Max string length - if (stringNum) - nif.getSizedStrings(strings, stringNum); + nif.getSizedStrings(strings, stringNum); } std::vector groups; // Currently unused unsigned int groupNum = nif.getUInt(); - if (groupNum) - nif.getUInts(groups, groupNum); + nif.readVector(groups, groupNum); } } diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index a9db083406..93f2613f11 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -155,19 +155,6 @@ namespace Nif Transformation getTrafo() { return get(); } bool getBoolean() { return get(); } std::string getString() { return get(); } - - /// DEPRECATED: Use readVector() - void getChars(std::vector& vec, size_t size) { readVector(vec, size); } - void getUChars(std::vector& vec, size_t size) { readVector(vec, size); } - void getUShorts(std::vector& vec, size_t size) { readVector(vec, size); } - void getFloats(std::vector& vec, size_t size) { readVector(vec, size); } - void getInts(std::vector& vec, size_t size) { readVector(vec, size); } - void getUInts(std::vector& vec, size_t size) { readVector(vec, size); } - void getVector2s(std::vector& vec, size_t size) { readVector(vec, size); } - void getVector3s(std::vector& vec, size_t size) { readVector(vec, size); } - void getVector4s(std::vector& vec, size_t size) { readVector(vec, size); } - void getQuaternions(std::vector& vec, size_t size) { readVector(vec, size); } - void getStrings(std::vector& vec, size_t size) { readVector(vec, size); } }; template <> diff --git a/components/nif/node.cpp b/components/nif/node.cpp index 3f12f23840..a2ae77830a 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -157,11 +157,9 @@ namespace Nif num = nif->getBoolean(); // Has Shader else if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 5)) num = nif->getUInt(); - if (num) - { - nif->getStrings(names, num); - nif->getInts(extra, num); - } + + nif->readVector(names, num); + nif->readVector(extra, num); if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 5)) active = nif->getUInt(); if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS) @@ -377,10 +375,7 @@ namespace Nif } if (mDataSize > 0) - { - mTriangles.resize(triNum * 3); nif->readVector(mTriangles, triNum * 3); - } if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_SSE) { diff --git a/components/nif/physics.cpp b/components/nif/physics.cpp index 450f5588cb..daa4f90c2a 100644 --- a/components/nif/physics.cpp +++ b/components/nif/physics.cpp @@ -53,8 +53,7 @@ namespace Nif mOffset = nif->getVector4(); if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3) nif->getChar(); // MOPP data build type - if (size) - nif->getChars(mData, size); + nif->readVector(mData, size); } void bhkEntityCInfo::read(NIFStream* nif) @@ -99,18 +98,10 @@ namespace Nif mMaterialIndex = nif->getUInt(); mReference = nif->getUShort(); mTransformIndex = nif->getUShort(); - size_t numVertices = nif->getUInt(); - if (numVertices) - nif->getUShorts(mVertices, numVertices); - size_t numIndices = 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); + nif->readVector(mVertices, nif->getUInt()); + nif->readVector(mIndices, nif->getUInt()); + nif->readVector(mStrips, nif->getUInt()); + nif->readVector(mWeldingInfos, nif->getUInt()); } void bhkRigidBodyCInfo::read(NIFStream* nif) @@ -395,8 +386,7 @@ namespace Nif if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) mScale = nif->getVector4(); readRecordList(nif, mData); - unsigned int numFilters = nif->getUInt(); - nif->getUInts(mFilters, numFilters); + nif->readVector(mFilters, nif->getUInt()); } void bhkNiTriStripsShape::post(Reader& nif) @@ -438,7 +428,7 @@ namespace Nif if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS) compressed = nif->getBoolean(); if (!compressed) - nif->getVector3s(mVertices, numVertices); + nif->readVector(mVertices, numVertices); else nif->skip(6 * numVertices); // Half-precision vectors are not currently supported if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS) @@ -465,12 +455,8 @@ namespace Nif bhkConvexShape::read(nif); mVerticesProperty.read(nif); mNormalsProperty.read(nif); - unsigned int numVertices = nif->getUInt(); - if (numVertices) - nif->getVector4s(mVertices, numVertices); - unsigned int numNormals = nif->getUInt(); - if (numNormals) - nif->getVector4s(mNormals, numNormals); + nif->readVector(mVertices, nif->getUInt()); + nif->readVector(mNormals, nif->getUInt()); } void bhkConvexTransformShape::read(NIFStream* nif) @@ -564,9 +550,7 @@ namespace Nif for (bhkQsTransform& transform : mChunkTransforms) transform.read(nif); - size_t numBigVertices = nif->getUInt(); - if (numBigVertices) - nif->getVector4s(mBigVerts, numBigVertices); + nif->readVector(mBigVerts, nif->getUInt()); size_t numBigTriangles = nif->getUInt(); mBigTris.resize(numBigTriangles);