Skip to content

Commit

Permalink
Revert "components/nif/base.hpp now uses the templated get() function"
Browse files Browse the repository at this point in the history
This reverts commit ad609bf.

Revert "Made incorrect nif get error message more informative."

This reverts commit 9909c4a.

Revert "Build the nif file tester by default"

This reverts commit c1315ed.

Revert "Converted most nifstream "get multiple" functions to the templated version"

This reverts commit 2619d57.

Revert "Add a templated option for getting vectors to NIFStream"

This reverts commit f318ee0.

Revert "Made NIFStream getters templated"

This reverts commit 4edc414.
  • Loading branch information
scrawl committed Jan 6, 2015
1 parent 31f6ccd commit c6c7d10
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 63 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ option(BUILD_OPENCS "build OpenMW Construction Set" ON)
option(BUILD_WIZARD "build Installation Wizard" ON)
option(BUILD_WITH_CODE_COVERAGE "Enable code coverage with gconv" OFF)
option(BUILD_UNITTESTS "Enable Unittests with Google C++ Unittest and GMock frameworks" OFF)
option(BUILD_NIFTEST "build nif file tester" ON)
option(BUILD_NIFTEST "build nif file tester" OFF)
option(BUILD_MYGUI_PLUGIN "build MyGUI plugin for OpenMW resources, to use with MyGUI tools" ON)

# OS X deployment
Expand Down
12 changes: 6 additions & 6 deletions components/nif/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class Controller : public Record
{
next.read(nif);

flags = nif->get<unsigned short>();
flags = nif->getUShort();

frequency = nif->get<float>();
phase = nif->get<float>();
timeStart = nif->get<float>();
timeStop = nif->get<float>();
frequency = nif->getFloat();
phase = nif->getFloat();
timeStart = nif->getFloat();
timeStop = nif->getFloat();

target.read(nif);
}
Expand Down Expand Up @@ -81,7 +81,7 @@ class Named : public Controlled

void read(NIFStream *nif)
{
name = nif->get<std::string>();
name = nif->getString();
Controlled::read(nif);
}
};
Expand Down
16 changes: 8 additions & 8 deletions components/nif/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ class ShapeData : public Record
int verts = nif->getUShort();

if(nif->getInt())
vertices = nif->getItems<Ogre::Vector3>(verts);
nif->getVector3s(vertices, verts);

if(nif->getInt())
normals = nif->getItems<Ogre::Vector3>(verts);
nif->getVector3s(normals, verts);

center = nif->getVector3();
radius = nif->getFloat();

if(nif->getInt())
colors = nif->getItems<Ogre::Vector4>(verts);
nif->getVector4s(colors, verts);

// Only the first 6 bits are used as a count. I think the rest are
// flags of some sort.
Expand All @@ -64,7 +64,7 @@ class ShapeData : public Record
{
uvlist.resize(uvs);
for(int i = 0;i < uvs;i++)
uvlist[i] = nif->getItems<Ogre::Vector2>(verts);
nif->getVector2s(uvlist[i], verts);
}
}
};
Expand All @@ -84,7 +84,7 @@ class NiTriShapeData : public ShapeData
// We have three times as many vertices as triangles, so this
// is always equal to tris*3.
int cnt = nif->getInt();
triangles = nif->getItems<short>(cnt);
nif->getShorts(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
Expand Down Expand Up @@ -123,7 +123,7 @@ class NiAutoNormalParticlesData : public ShapeData
if(nif->getInt())
{
// Particle sizes
sizes = nif->getItems<float>(vertices.size());
nif->getFloats(sizes, vertices.size());
}
}
};
Expand All @@ -140,7 +140,7 @@ class NiRotatingParticlesData : public NiAutoNormalParticlesData
if(nif->getInt())
{
// Rotation quaternions.
rotations = nif->getItems<Ogre::Quaternion>(vertices.size());
nif->getQuaternions(rotations, vertices.size());
}
}
};
Expand Down Expand Up @@ -341,7 +341,7 @@ struct NiMorphData : public Record
for(int i = 0;i < morphCount;i++)
{
mMorphs[i].mData.read(nif, true);
mMorphs[i].mVertices = nif->getItems<Ogre::Vector3>(vertCount);
nif->getVector3s(mMorphs[i].mVertices, vertCount);
}
}
};
Expand Down
64 changes: 36 additions & 28 deletions components/nif/nifstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,41 @@ std::string NIFStream::getVersionString()
return inp->getLine();
}

template <>
char NIFStream::get<char>(){ return getChar(); }
template <>
short NIFStream::get<short>(){ return getShort(); }
template <>
unsigned short NIFStream::get<unsigned short>(){ return getUShort(); }
template <>
int NIFStream::get<int>(){ return getInt(); }
template <>
unsigned int NIFStream::get<unsigned int>(){ return getUInt(); }
template <>
float NIFStream::get<float>(){ return getFloat(); }

template <>
Ogre::Vector2 NIFStream::get<Ogre::Vector2>(){ return getVector2(); }
template <>
Ogre::Vector3 NIFStream::get<Ogre::Vector3>(){ return getVector3(); }
template <>
Ogre::Vector4 NIFStream::get<Ogre::Vector4>(){ return getVector4(); }
template <>
Ogre::Matrix3 NIFStream::get<Ogre::Matrix3>(){ return getMatrix3(); }
template <>
Ogre::Quaternion NIFStream::get<Ogre::Quaternion>(){ return getQuaternion(); }
template <>
Transformation NIFStream::get<Transformation>(){ return getTrafo(); }

template <>
std::string NIFStream::get<std::string>(){ return getString(); }
void NIFStream::getShorts(std::vector<short> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getShort();
}
void NIFStream::getFloats(std::vector<float> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getFloat();
}
void NIFStream::getVector2s(std::vector<Ogre::Vector2> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector2();
}
void NIFStream::getVector3s(std::vector<Ogre::Vector3> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector3();
}
void NIFStream::getVector4s(std::vector<Ogre::Vector4> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector4();
}
void NIFStream::getQuaternions(std::vector<Ogre::Quaternion> &quat, size_t size)
{
quat.resize(size);
for(size_t i = 0;i < quat.size();i++)
quat[i] = getQuaternion();
}

}
25 changes: 6 additions & 19 deletions components/nif/nifstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <stdint.h>
#include <stdexcept>
#include <typeinfo>
#include <string>

#include <OgreDataStream.h>
#include <OgreVector2.h>
Expand Down Expand Up @@ -86,23 +84,12 @@ class NIFStream {
///This is special since the version string doesn't start with a number, and ends with "\n"
std::string getVersionString();

//Templated functions to handle reads
template <typename T>
T get(){throw std::runtime_error("Can not read a <"+std::string(typeid(T).name())+"> from a NIF File! The get() function was called with the wrong template!");}

///Return a vector of whatever object is needed
template <typename T>
std::vector<T> getItems(size_t number_of_items)
{
std::vector<T> items;
items.reserve(number_of_items);
for(size_t i=0; i < number_of_items; ++i)
{
items.push_back(get<T>());
}
return items;
}

void getShorts(std::vector<short> &vec, size_t size);
void getFloats(std::vector<float> &vec, size_t size);
void getVector2s(std::vector<Ogre::Vector2> &vec, size_t size);
void getVector3s(std::vector<Ogre::Vector3> &vec, size_t size);
void getVector4s(std::vector<Ogre::Vector4> &vec, size_t size);
void getQuaternions(std::vector<Ogre::Quaternion> &quat, size_t size);
};

}
Expand Down
2 changes: 1 addition & 1 deletion components/nif/tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ find "$DATAFILESDIR" -iname *nif >> nifs.txt

sed -e 's/.*/\"&\"/' nifs.txt > quoted_nifs.txt

nice -n 10 xargs --arg-file=quoted_nifs.txt ../../../niftest
xargs --arg-file=quoted_nifs.txt ../../../niftest

rm nifs.txt
rm quoted_nifs.txt

0 comments on commit c6c7d10

Please sign in to comment.