diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 9cdbec537..a9a5895f4 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -97,7 +97,7 @@ class ShapeData : public Record { public: std::vector 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 weights; }; struct BoneInfoCopy @@ -406,7 +406,7 @@ public: unsigned int boneinfocopyindex; }; - const BoneTrafo *trafo; + BoneTrafo trafo; std::vector bones; void read(NIFFile *nif) @@ -414,7 +414,7 @@ public: assert(sizeof(BoneTrafo) == 4*(9+3+1)); assert(sizeof(VertWeight) == 6); - trafo = nif->getPtr(); + trafo = nif->getType(); int boneNum = nif->getInt(); nif->getInt(); // -1 @@ -424,7 +424,7 @@ public: { BoneInfo &bi = bones[i]; - bi.trafo = nif->getPtr(); + bi.trafo = nif->getType(); bi.unknown = nif->getVector4(); // Number of vertex weights diff --git a/components/nif/effect.hpp b/components/nif/effect.hpp index bac412c76..6ecc7c61a 100644 --- a/components/nif/effect.hpp +++ b/components/nif/effect.hpp @@ -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(); + light = nif->getType(); } }; diff --git a/components/nif/nif_file.cpp b/components/nif/nif_file.cpp index 35714bfbe..36badbf0d 100644 --- a/components/nif/nif_file.cpp +++ b/components/nif/nif_file.cpp @@ -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; igetPtr(size); } - template const X* getPtr() { return (const X*)inp->getPtr(sizeof(X)); } - template X getType() { return *getPtr(); } + template X getType() + { + return *(const X*)inp->getPtr(sizeof(X)); + } unsigned short getShort() { return getType(); } int getInt() { return getType(); } float getFloat() { return getType(); } @@ -136,10 +138,10 @@ public: return getArrayLen(len); } - const Vector *getVector() { return getPtr(); } - const Matrix *getMatrix() { return getPtr(); } - const Transformation *getTrafo() { return getPtr(); } - const Vector4 *getVector4() { return getPtr(); } + Vector getVector() { return getType(); } + Matrix getMatrix() { return getType(); } + Transformation getTrafo() { return getType(); } + Vector4 getVector4() { return getType(); } std::vector getFloatLen(int num) { return getArrayLen(num); } diff --git a/components/nif/nif_types.hpp b/components/nif/nif_types.hpp index ee796cc99..41900a14e 100644 --- a/components/nif/nif_types.hpp +++ b/components/nif/nif_types.hpp @@ -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) diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 9d99dbd1d..8a6af5777 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -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(); + cam = nif->getType(); nif->getInt(); // -1 nif->getInt(); // 0 diff --git a/components/nif/property.hpp b/components/nif/property.hpp index 619e3db0e..8485d978f 100644 --- a/components/nif/property.hpp +++ b/components/nif/property.hpp @@ -155,12 +155,12 @@ typedef Property NiWireframeProperty; template struct StructPropT : Property { - const T* data; + T data; void read(NIFFile *nif) { Property::read(nif); - data = nif->getPtr(); + data = nif->getType(); } }; diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 9f31a3eed..f32b5e896 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -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); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 55dbba518..616e462fd 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -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::iterator itr = MaterialMap.find(texName); std::multimap::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; iweights.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)