From fda6b0b4f8deeb25c5b1469d4d0a92c23f2b0d76 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Sun, 3 Sep 2023 16:52:10 +0300 Subject: [PATCH] Modernize NiUVData, NiLinesData, NiTriBasedGeomData --- components/nif/data.cpp | 16 ++++++++-------- components/nif/data.hpp | 7 ++++--- components/nifbullet/bulletnifloader.cpp | 2 +- components/nifosg/nifloader.cpp | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 59ac33c1ff..910c67cdd7 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -85,7 +85,7 @@ namespace Nif { NiGeometryData::read(nif); - mNumTriangles = nif->getUShort(); + nif->read(mNumTriangles); } void NiTriShapeData::read(NIFStream* nif) @@ -150,15 +150,15 @@ namespace Nif { if (flags[i] & 1) { - lines.emplace_back(i); - lines.emplace_back(i + 1); + mLines.emplace_back(i); + mLines.emplace_back(i + 1); } } // If there are just two vertices, they can be connected twice. Probably isn't critical. if (flags[num - 1] & 1) { - lines.emplace_back(num - 1); - lines.emplace_back(0); + mLines.emplace_back(num - 1); + mLines.emplace_back(0); } } @@ -207,10 +207,10 @@ namespace Nif void NiUVData::read(NIFStream* nif) { - for (int i = 0; i < 4; i++) + for (FloatKeyMapPtr& keys : mKeyList) { - mKeyList[i] = std::make_shared(); - mKeyList[i]->read(nif); + keys = std::make_shared(); + keys->read(nif); } } diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 7f53f7333b..e853a30c33 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -47,7 +47,7 @@ namespace Nif // Abstract struct NiTriBasedGeomData : public NiGeometryData { - size_t mNumTriangles; + uint16_t mNumTriangles; void read(NIFStream* nif) override; }; @@ -71,7 +71,8 @@ namespace Nif struct NiLinesData : public NiGeometryData { // Lines, series of indices that correspond to connected vertices. - std::vector lines; + // NB: assumes <=65536 number of vertices + std::vector mLines; void read(NIFStream* nif) override; }; @@ -103,7 +104,7 @@ namespace Nif struct NiUVData : public Record { - FloatKeyMapPtr mKeyList[4]; + std::array mKeyList; void read(NIFStream* nif) override; }; diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index 0c85949a53..4ef1a35903 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -40,7 +40,7 @@ namespace for (const osg::Vec3f& vertex : vertices) mesh.findOrAddVertex(Misc::Convert::toBullet(vertex), false); - mesh.preallocateIndices(static_cast(data.mNumTriangles * 3)); + mesh.preallocateIndices(static_cast(data.mNumTriangles) * 3); } void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriShapeData& data) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 3d04aee28b..868cdfa137 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1458,7 +1458,7 @@ namespace NifOsg if (niGeometryData->recType != Nif::RC_NiLinesData) return; auto data = static_cast(niGeometryData); - const auto& line = data->lines; + const auto& line = data->mLines; if (line.empty()) return; geometry->addPrimitiveSet(