Avoid returning pointers from NIFFile

pull/21/head
Chris Robinson 13 years ago
parent d3a31a24ce
commit 0143cacd2b

@ -97,7 +97,7 @@ class ShapeData : public Record
{
public:
std::vector<float> vertices, normals, colors, uvlist;
const Vector *center;
Vector center;
float radius;
void read(NIFFile *nif)
@ -388,8 +388,8 @@ public:
struct BoneInfo
{
const BoneTrafo *trafo;
const Vector4 *unknown;
BoneTrafo trafo;
Vector4 unknown;
std::vector<VertWeight> weights;
};
struct BoneInfoCopy
@ -406,7 +406,7 @@ public:
unsigned int boneinfocopyindex;
};
const BoneTrafo *trafo;
BoneTrafo trafo;
std::vector<BoneInfo> bones;
void read(NIFFile *nif)
@ -414,7 +414,7 @@ public:
assert(sizeof(BoneTrafo) == 4*(9+3+1));
assert(sizeof(VertWeight) == 6);
trafo = nif->getPtr<BoneTrafo>();
trafo = nif->getType<BoneTrafo>();
int boneNum = nif->getInt();
nif->getInt(); // -1
@ -424,7 +424,7 @@ public:
{
BoneInfo &bi = bones[i];
bi.trafo = nif->getPtr<BoneTrafo>();
bi.trafo = nif->getType<BoneTrafo>();
bi.unknown = nif->getVector4();
// Number of vertex weights

@ -42,7 +42,7 @@ struct NiLight : Effect
Vector diffuse;
Vector specular;
};
const SLight *light;
SLight light;
void read(NIFFile *nif)
{
@ -50,7 +50,7 @@ struct NiLight : Effect
nif->getInt(); // 1
nif->getInt(); // 1?
light = nif->getPtr<SLight>();
light = nif->getType<SLight>();
}
};

@ -201,7 +201,7 @@ void NiSkinInstance::post(NIFFile *nif)
if(bnum != data->bones.size())
nif->fail("Mismatch in NiSkinData bone count");
root->makeRootBone(data->trafo);
root->makeRootBone(&data->trafo);
for(size_t i=0; i<bnum; i++)
{

@ -114,8 +114,10 @@ public:
void skip(size_t size) { inp->getPtr(size); }
template<class X> const X* getPtr() { return (const X*)inp->getPtr(sizeof(X)); }
template<class X> X getType() { return *getPtr<X>(); }
template<class X> X getType()
{
return *(const X*)inp->getPtr(sizeof(X));
}
unsigned short getShort() { return getType<unsigned short>(); }
int getInt() { return getType<int>(); }
float getFloat() { return getType<float>(); }
@ -136,10 +138,10 @@ public:
return getArrayLen<X>(len);
}
const Vector *getVector() { return getPtr<Vector>(); }
const Matrix *getMatrix() { return getPtr<Matrix>(); }
const Transformation *getTrafo() { return getPtr<Transformation>(); }
const Vector4 *getVector4() { return getPtr<Vector4>(); }
Vector getVector() { return getType<Vector>(); }
Matrix getMatrix() { return getType<Matrix>(); }
Transformation getTrafo() { return getType<Transformation>(); }
Vector4 getVector4() { return getType<Vector4>(); }
std::vector<float> getFloatLen(int num)
{ return getArrayLen<float>(num); }

@ -60,7 +60,7 @@ struct Transformation
float scale;
Vector velocity;
static const Transformation* getIdentity()
static const Transformation& getIdentity()
{
static Transformation identity;
static bool iset = false;
@ -73,7 +73,7 @@ struct Transformation
iset = true;
}
return &identity;
return identity;
}
};
#pragma pack(pop)

@ -42,14 +42,14 @@ class Node : public Named
public:
// Node flags. Interpretation depends somewhat on the type of node.
int flags;
const Transformation *trafo;
Transformation trafo;
PropertyList props;
// Bounding box info
bool hasBounds;
const Vector *boundPos;
const Matrix *boundRot;
const Vector *boundXYZ; // Box size
Vector boundPos;
Matrix boundRot;
Vector boundXYZ; // Box size
void read(NIFFile *nif)
{
@ -103,7 +103,7 @@ public:
void makeBone(short ind, const NiSkinData::BoneInfo &bi)
{
boneInfo = &bi;
boneTrafo = bi.trafo;
boneTrafo = &bi.trafo;
boneIndex = ind;
}
};
@ -219,13 +219,13 @@ struct NiCamera : Node
// Level of detail modifier
float LOD;
};
const Camera *cam;
Camera cam;
void read(NIFFile *nif)
{
Node::read(nif);
nif->getPtr<Camera>();
cam = nif->getType<Camera>();
nif->getInt(); // -1
nif->getInt(); // 0

@ -155,12 +155,12 @@ typedef Property NiWireframeProperty;
template <typename T>
struct StructPropT : Property
{
const T* data;
T data;
void read(NIFFile *nif)
{
Property::read(nif);
data = nif->getPtr<T>();
data = nif->getType<T>();
}
};

@ -226,7 +226,7 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
Ogre::Vector3 finalPos;
float finalScale;
Nif::Transformation &final = *((Nif::Transformation*)node->trafo);
Nif::Transformation &final = node->trafo;
Ogre::Vector3 nodePos = getVector(&final);
Ogre::Matrix3 nodeRot = getMatrix(&final);

@ -730,7 +730,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
if (a)
{
alphaFlags = a->flags;
alphaTest = a->data->threshold;
alphaTest = a->data.threshold;
}
// Material
@ -745,7 +745,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
if (m)
{
// Use NiMaterialProperty data to create the data
const S_MaterialProperty *d = m->data;
const S_MaterialProperty *d = &m->data;
std::multimap<std::string,std::string>::iterator itr = MaterialMap.find(texName);
std::multimap<std::string,std::string>::iterator lastElement;
@ -858,17 +858,17 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
Nif::NiSkinData::BoneInfoCopy boneinfocopy;
boneinfocopy.trafo.rotation = convertRotation(it->trafo->rotation);
boneinfocopy.trafo.trans = convertVector3(it->trafo->trans);
boneinfocopy.trafo.rotation = convertRotation(it->trafo.rotation);
boneinfocopy.trafo.trans = convertVector3(it->trafo.trans);
boneinfocopy.bonename = shape->skin->bones[boneIndex].name;
boneinfocopy.bonehandle = bonePtr->getHandle();
copy.boneinfo.push_back(boneinfocopy);
for (unsigned int i=0; i<it->weights.size(); i++)
{
vecPos = bonePtr->_getDerivedPosition() +
bonePtr->_getDerivedOrientation() * convertVector3(it->trafo->trans);
bonePtr->_getDerivedOrientation() * convertVector3(it->trafo.trans);
vecRot = bonePtr->_getDerivedOrientation() * convertRotation(it->trafo->rotation);
vecRot = bonePtr->_getDerivedOrientation() * convertRotation(it->trafo.rotation);
unsigned int verIndex = it->weights[i].vertex;
//boneinfo.weights.push_back(*(it->weights.ptr + i));
Nif::NiSkinData::IndividualWeight ind;
@ -959,9 +959,9 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
copy.boneSequence = boneSequence;
// Rotate, scale and translate all the vertices,
const Matrix &rot = shape->trafo->rotation;
const Vector &pos = shape->trafo->pos;
float scale = shape->trafo->scale;
const Matrix &rot = shape->trafo.rotation;
const Vector &pos = shape->trafo.pos;
float scale = shape->trafo.scale;
copy.trafo.trans = convertVector3(original.pos);
copy.trafo.rotation = convertRotation(original.rotation);
@ -1148,19 +1148,19 @@ void NIFLoader::handleNode(Nif::Node *node, int flags,
parentBone->addChild(bone);
bone->setInheritOrientation(true);
bone->setPosition(convertVector3(node->trafo->pos));
bone->setOrientation(convertRotation(node->trafo->rotation));
bone->setPosition(convertVector3(node->trafo.pos));
bone->setOrientation(convertRotation(node->trafo.rotation));
}
}
}
Transformation original = *(node->trafo);
Transformation original = node->trafo;
// Apply the parent transformation to this node. We overwrite the
// existing data with the final transformation.
if (trafo)
{
// Get a non-const reference to the node's data, since we're
// overwriting it. TODO: Is this necessary?
Transformation &final = *((Transformation*)node->trafo);
Transformation &final = node->trafo;
// For both position and rotation we have that:
// final_vector = old_vector + old_rotation*new_vector*old_scale
@ -1184,7 +1184,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags,
{
if (list.has(i))
handleNode(&list[i], flags, node->trafo, bounds, bone, boneSequence);
handleNode(&list[i], flags, &node->trafo, bounds, bone, boneSequence);
}
}
else if (node->recType == RC_NiTriShape && bNiTri)

Loading…
Cancel
Save