diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 667e77ffd..babc07545 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -105,25 +105,24 @@ public: int verts = nif->getShort(); if(nif->getInt()) - vertices = nif->getArrayLen(verts*3); + nif->load(vertices, verts*3); if(nif->getInt()) - normals = nif->getArrayLen(verts*3); + nif->load(normals, verts*3); center = nif->getVector(); radius = nif->getFloat(); if(nif->getInt()) - colors = nif->getArrayLen(verts*4); - - int uvs = nif->getShort(); + nif->load(colors, verts*4); // Only the first 6 bits are used as a count. I think the rest are // flags of some sort. + int uvs = nif->getShort(); uvs &= 0x3f; if(nif->getInt()) - uvlist = nif->getArrayLen(uvs*verts*2); + nif->load(uvlist, uvs*verts*2); } }; @@ -143,7 +142,7 @@ public: // We have three times as many vertices as triangles, so this // is always equal to tris*3. int cnt = nif->getInt(); - triangles = nif->getArrayLen(cnt); + nif->load(triangles, cnt); } // Read the match list, which lists the vertices that are equal to @@ -175,13 +174,13 @@ public: activeCount = nif->getShort(); // Skip all the info, we don't support particles yet - nif->getFloat(); // Active radius ? + nif->getFloat(); // Active radius ? nif->getShort(); // Number of valid entries in the following arrays ? if(nif->getInt()) { // Particle sizes - nif->getArrayLen(activeCount); + nif->skip(activeCount * sizeof(float)); } } }; diff --git a/components/nif/extra.hpp b/components/nif/extra.hpp index 5615d833e..7659bb3d2 100644 --- a/components/nif/extra.hpp +++ b/components/nif/extra.hpp @@ -47,16 +47,21 @@ public: class NiVertWeightsExtraData : public Extra { public: + std::vector weights; + void read(NIFFile *nif) { Extra::read(nif); + int i; + unsigned short s; + // We should have s*4+2 == i, for some reason. Might simply be the // size of the rest of the record, unhelpful as that may be. - /*int i =*/ nif->getInt(); - int s = nif->getShort(); // number of vertices + nif->load(i); - nif->getArrayLen(s); // vertex weights I guess + nif->load(s); // number of vertices + nif->load(weights, s); // vertex weights I guess } }; diff --git a/components/nif/nif_file.cpp b/components/nif/nif_file.cpp index 36badbf0d..5b88b45fe 100644 --- a/components/nif/nif_file.cpp +++ b/components/nif/nif_file.cpp @@ -46,7 +46,7 @@ using namespace Misc; void NIFFile::parse() { // Check the header string - std::string head = getString(40); + std::string head = read_string(40); if(head.compare(0, 22, "NetImmerse File Format") != 0) fail("Invalid NIF header"); diff --git a/components/nif/nif_file.hpp b/components/nif/nif_file.hpp index d9fdd97ae..6165f5811 100644 --- a/components/nif/nif_file.hpp +++ b/components/nif/nif_file.hpp @@ -164,9 +164,6 @@ public: } - template - std::vector getArrayLen(size_t num); - char getByte() { char c; return load(c); } unsigned short getShort() { unsigned short s; return load(s); } int getInt() { int i; return load(i); } @@ -202,39 +199,12 @@ public: } - // For fixed-size strings where you already know the size - std::string getString(size_t size) - { - std::string str; - str.resize(size); - if(inp->read(&str[0], size) != size) - fail("Failed to read from NIF"); - return str.substr(0, str.find('\0')); - } std::string getString() { - size_t size = getInt(); - return getString(size); + size_t size = read_le32(); + return read_string(size); } }; -template<> -inline std::vector NIFFile::getArrayLen(size_t num) -{ - std::vector v(num); - for(size_t i = 0;i < num;i++) - load(v[i]); - return v; -} - -template<> -inline std::vector NIFFile::getArrayLen(size_t num) -{ - std::vector v(num); - for(size_t i = 0;i < num;i++) - load(v[i]); - return v; -} - } // Namespace #endif