mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
Remove NIFFile::getArrayLen
This commit is contained in:
parent
ca37706b34
commit
95b804a104
4 changed files with 19 additions and 45 deletions
|
@ -105,25 +105,24 @@ public:
|
|||
int verts = nif->getShort();
|
||||
|
||||
if(nif->getInt())
|
||||
vertices = nif->getArrayLen<float>(verts*3);
|
||||
nif->load(vertices, verts*3);
|
||||
|
||||
if(nif->getInt())
|
||||
normals = nif->getArrayLen<float>(verts*3);
|
||||
nif->load(normals, verts*3);
|
||||
|
||||
center = nif->getVector();
|
||||
radius = nif->getFloat();
|
||||
|
||||
if(nif->getInt())
|
||||
colors = nif->getArrayLen<float>(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<float>(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<short>(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<float>(activeCount);
|
||||
nif->skip(activeCount * sizeof(float));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -47,16 +47,21 @@ public:
|
|||
class NiVertWeightsExtraData : public Extra
|
||||
{
|
||||
public:
|
||||
std::vector<float> 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<float>(s); // vertex weights I guess
|
||||
nif->load(s); // number of vertices
|
||||
nif->load(weights, s); // vertex weights I guess
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -164,9 +164,6 @@ public:
|
|||
}
|
||||
|
||||
|
||||
template<typename X>
|
||||
std::vector<X> 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<short> NIFFile::getArrayLen<short>(size_t num)
|
||||
{
|
||||
std::vector<short> v(num);
|
||||
for(size_t i = 0;i < num;i++)
|
||||
load(v[i]);
|
||||
return v;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::vector<float> NIFFile::getArrayLen<float>(size_t num)
|
||||
{
|
||||
std::vector<float> v(num);
|
||||
for(size_t i = 0;i < num;i++)
|
||||
load(v[i]);
|
||||
return v;
|
||||
}
|
||||
|
||||
} // Namespace
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue