diff --git a/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp b/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp index c94907e68..b02b8b9ef 100644 --- a/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp +++ b/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp @@ -208,18 +208,13 @@ namespace void init(Nif::Extra& value) { - value.extra = Nif::ExtraPtr(nullptr); - } - - void init(Nif::Controlled& value) - { - init(static_cast(value)); - value.controller = Nif::ControllerPtr(nullptr); + value.next = Nif::ExtraPtr(nullptr); } void init(Nif::Named& value) { - init(static_cast(value)); + value.extra = Nif::ExtraPtr(nullptr); + value.controller = Nif::ControllerPtr(nullptr); } void init(Nif::Node& value) @@ -254,7 +249,7 @@ namespace value.phase = 0; value.timeStart = 0; value.timeStop = 0; - value.target = Nif::ControlledPtr(nullptr); + value.target = Nif::NamedPtr(nullptr); } void copy(const btTransform& src, Nif::Transformation& dst) @@ -884,7 +879,7 @@ namespace TEST_F(TestBulletNifLoader, for_tri_shape_child_node_with_not_first_extra_data_string_starting_with_nc_should_return_shape_with_null_collision_shape) { - mNiStringExtraData.extra = Nif::ExtraPtr(&mNiStringExtraData2); + mNiStringExtraData.next = Nif::ExtraPtr(&mNiStringExtraData2); mNiStringExtraData2.string = "NC___"; mNiStringExtraData2.recType = Nif::RC_NiStringExtraData; mNiTriShape.extra = Nif::ExtraPtr(&mNiStringExtraData); diff --git a/components/nif/base.hpp b/components/nif/base.hpp index 4b2e40dec..f67de0221 100644 --- a/components/nif/base.hpp +++ b/components/nif/base.hpp @@ -10,17 +10,19 @@ namespace Nif { -/** A record that can have extra data. The extra data objects - themselves descend from the Extra class, and all the extra data - connected to an object form a linked list -*/ +// An extra data record. All the extra data connected to an object form a linked list. class Extra : public Record { public: - ExtraPtr extra; + ExtraPtr next; // Next extra data record in the list + + void read(NIFStream *nif) + { + next.read(nif); + nif->getUInt(); // Size of the record + } - void read(NIFStream *nif) { extra.read(nif); } - void post(NIFFile *nif) { extra.post(nif); } + void post(NIFFile *nif) { next.post(nif); } }; class Controller : public Record @@ -30,43 +32,33 @@ public: int flags; float frequency, phase; float timeStart, timeStop; - ControlledPtr target; + NamedPtr target; void read(NIFStream *nif); void post(NIFFile *nif); }; -/// Anything that has a controller -class Controlled : public Extra +/// Has name, extra-data and controller +class Named : public Record { public: + std::string name; + ExtraPtr extra; ControllerPtr controller; void read(NIFStream *nif) { - Extra::read(nif); + name = nif->getString(); + extra.read(nif); controller.read(nif); } void post(NIFFile *nif) { - Extra::post(nif); + extra.post(nif); controller.post(nif); } }; - -/// Has name, extra-data and controller -class Named : public Controlled -{ -public: - std::string name; - - void read(NIFStream *nif) - { - name = nif->getString(); - Controlled::read(nif); - } -}; typedef Named NiSequenceStreamHelper; } // Namespace diff --git a/components/nif/controlled.cpp b/components/nif/controlled.cpp index 52e7a7302..51ccf8541 100644 --- a/components/nif/controlled.cpp +++ b/components/nif/controlled.cpp @@ -31,28 +31,40 @@ namespace Nif data.post(nif); } + void NiParticleModifier::read(NIFStream *nif) + { + next.read(nif); + controller.read(nif); + } + + void NiParticleModifier::post(NIFFile *nif) + { + next.post(nif); + controller.post(nif); + } + void NiParticleGrowFade::read(NIFStream *nif) { - Controlled::read(nif); + NiParticleModifier::read(nif); growTime = nif->getFloat(); fadeTime = nif->getFloat(); } void NiParticleColorModifier::read(NIFStream *nif) { - Controlled::read(nif); + NiParticleModifier::read(nif); data.read(nif); } void NiParticleColorModifier::post(NIFFile *nif) { - Controlled::post(nif); + NiParticleModifier::post(nif); data.post(nif); } void NiGravity::read(NIFStream *nif) { - Controlled::read(nif); + NiParticleModifier::read(nif); mDecay = nif->getFloat(); mForce = nif->getFloat(); @@ -61,11 +73,17 @@ namespace Nif mDirection = nif->getVector3(); } - void NiPlanarCollider::read(NIFStream *nif) + void NiParticleCollider::read(NIFStream *nif) { - Controlled::read(nif); + NiParticleModifier::read(nif); mBounceFactor = nif->getFloat(); + } + + void NiPlanarCollider::read(NIFStream *nif) + { + NiParticleCollider::read(nif); + /*unknown*/nif->getFloat(); for (int i=0;i<10;++i) @@ -77,7 +95,7 @@ namespace Nif void NiParticleRotation::read(NIFStream *nif) { - Controlled::read(nif); + NiParticleModifier::read(nif); /* byte (0 or 1) @@ -89,9 +107,8 @@ namespace Nif void NiSphericalCollider::read(NIFStream* nif) { - Controlled::read(nif); + NiParticleCollider::read(nif); - mBounceFactor = nif->getFloat(); mRadius = nif->getFloat(); mCenter = nif->getVector3(); } diff --git a/components/nif/controlled.hpp b/components/nif/controlled.hpp index be48e912e..00ff45eda 100644 --- a/components/nif/controlled.hpp +++ b/components/nif/controlled.hpp @@ -66,7 +66,16 @@ public: void post(NIFFile *nif); }; -class NiParticleGrowFade : public Controlled +struct NiParticleModifier : public Record +{ + NiParticleModifierPtr next; + ControllerPtr controller; + + void read(NIFStream *nif); + void post(NIFFile *nif); +}; + +class NiParticleGrowFade : public NiParticleModifier { public: float growTime; @@ -75,7 +84,7 @@ public: void read(NIFStream *nif); }; -class NiParticleColorModifier : public Controlled +class NiParticleColorModifier : public NiParticleModifier { public: NiColorDataPtr data; @@ -84,7 +93,7 @@ public: void post(NIFFile *nif); }; -class NiGravity : public Controlled +class NiGravity : public NiParticleModifier { public: float mForce; @@ -99,29 +108,32 @@ public: void read(NIFStream *nif); }; +struct NiParticleCollider : public NiParticleModifier +{ + float mBounceFactor; + void read(NIFStream *nif); +}; + // NiPinaColada -class NiPlanarCollider : public Controlled +class NiPlanarCollider : public NiParticleCollider { public: void read(NIFStream *nif); - float mBounceFactor; - osg::Vec3f mPlaneNormal; float mPlaneDistance; }; -class NiSphericalCollider : public Controlled +class NiSphericalCollider : public NiParticleCollider { public: - float mBounceFactor; float mRadius; osg::Vec3f mCenter; void read(NIFStream *nif); }; -class NiParticleRotation : public Controlled +class NiParticleRotation : public NiParticleModifier { public: void read(NIFStream *nif); diff --git a/components/nif/controller.hpp b/components/nif/controller.hpp index 113a7becd..52ab6f1f6 100644 --- a/components/nif/controller.hpp +++ b/components/nif/controller.hpp @@ -72,8 +72,8 @@ public: int activeCount; std::vector particles; - ExtraPtr affectors; - ExtraPtr colliders; + NiParticleModifierPtr affectors; + NiParticleModifierPtr colliders; void read(NIFStream *nif); void post(NIFFile *nif); diff --git a/components/nif/extra.cpp b/components/nif/extra.cpp index b7e221668..cb654d5a0 100644 --- a/components/nif/extra.cpp +++ b/components/nif/extra.cpp @@ -6,8 +6,6 @@ namespace Nif void NiStringExtraData::read(NIFStream *nif) { Extra::read(nif); - - nif->getInt(); // size of string + 4. Really useful... string = nif->getString(); } @@ -15,8 +13,6 @@ void NiTextKeyExtraData::read(NIFStream *nif) { Extra::read(nif); - nif->getInt(); // 0 - int keynum = nif->getInt(); list.resize(keynum); for(int i=0; igetInt(); - int s = nif->getUShort(); - - nif->skip(s * sizeof(float)); // vertex weights I guess + nif->skip(nif->getUShort() * sizeof(float)); // vertex weights I guess } diff --git a/components/nif/recordptr.hpp b/components/nif/recordptr.hpp index e23beb786..fbd148a04 100644 --- a/components/nif/recordptr.hpp +++ b/components/nif/recordptr.hpp @@ -127,7 +127,7 @@ class NiUVData; class NiPosData; class NiVisData; class Controller; -class Controlled; +class Named; class NiSkinData; class NiFloatData; struct NiMorphData; @@ -141,6 +141,7 @@ class NiSourceTexture; class NiRotatingParticlesData; class NiAutoNormalParticlesData; class NiPalette; +struct NiParticleModifier; typedef RecordPtrT NodePtr; typedef RecordPtrT ExtraPtr; @@ -148,7 +149,7 @@ typedef RecordPtrT NiUVDataPtr; typedef RecordPtrT NiPosDataPtr; typedef RecordPtrT NiVisDataPtr; typedef RecordPtrT ControllerPtr; -typedef RecordPtrT ControlledPtr; +typedef RecordPtrT NamedPtr; typedef RecordPtrT NiSkinDataPtr; typedef RecordPtrT NiMorphDataPtr; typedef RecordPtrT NiPixelDataPtr; @@ -162,6 +163,7 @@ typedef RecordPtrT NiSourceTexturePtr; typedef RecordPtrT NiRotatingParticlesDataPtr; typedef RecordPtrT NiAutoNormalParticlesDataPtr; typedef RecordPtrT NiPalettePtr; +typedef RecordPtrT NiParticleModifierPtr; typedef RecordListT NodeList; typedef RecordListT PropertyList; diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index 2f24a4067..5993d04fd 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -260,18 +260,13 @@ void BulletNifLoader::handleNode(const std::string& fileName, const Nif::Node *n Log(Debug::Info) << "RootCollisionNode is not attached to the root node in " << fileName << ". Treating it as a common NiTriShape."; // Check for extra data - Nif::Extra const *e = node; - while (!e->extra.empty()) + for (Nif::ExtraPtr e = node->extra; !e.empty(); e = e->next) { - // Get the next extra data in the list - e = e->extra.getPtr(); - assert(e != nullptr); - if (e->recType == Nif::RC_NiStringExtraData) { // String markers may contain important information // affecting the entire subtree of this node - Nif::NiStringExtraData *sd = (Nif::NiStringExtraData*)e; + Nif::NiStringExtraData *sd = (Nif::NiStringExtraData*)e.getPtr(); if (Misc::StringUtils::ciCompareLen(sd->string, "NC", 2) == 0) { diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 568286a4d..7699271d3 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -222,9 +222,9 @@ namespace NifOsg extractTextKeys(static_cast(extra.getPtr()), target.mTextKeys); - extra = extra->extra; + extra = extra->next; Nif::ControllerPtr ctrl = seq->controller; - for(;!extra.empty() && !ctrl.empty();(extra=extra->extra),(ctrl=ctrl->next)) + for(;!extra.empty() && !ctrl.empty();(extra=extra->next),(ctrl=ctrl->next)) { if(extra->recType != Nif::RC_NiStringExtraData || ctrl->recType != Nif::RC_NiKeyframeController) { @@ -524,7 +524,7 @@ namespace NifOsg node->getOrCreateUserDataContainer()->addUserObject( new NodeUserData(nifNode->recIndex, nifNode->trafo.scale, nifNode->trafo.rotation)); - for (Nif::ExtraPtr e = nifNode->extra; !e.empty(); e = e->extra) + for (Nif::ExtraPtr e = nifNode->extra; !e.empty(); e = e->next) { if(e->recType == Nif::RC_NiTextKeyExtraData && textKeys) { @@ -802,13 +802,13 @@ namespace NifOsg } } - void handleParticlePrograms(Nif::ExtraPtr affectors, Nif::ExtraPtr colliders, osg::Group *attachTo, osgParticle::ParticleSystem* partsys, osgParticle::ParticleProcessor::ReferenceFrame rf) + void handleParticlePrograms(Nif::NiParticleModifierPtr affectors, Nif::NiParticleModifierPtr colliders, osg::Group *attachTo, osgParticle::ParticleSystem* partsys, osgParticle::ParticleProcessor::ReferenceFrame rf) { osgParticle::ModularProgram* program = new osgParticle::ModularProgram; attachTo->addChild(program); program->setParticleSystem(partsys); program->setReferenceFrame(rf); - for (; !affectors.empty(); affectors = affectors->extra) + for (; !affectors.empty(); affectors = affectors->next) { if (affectors->recType == Nif::RC_NiParticleGrowFade) { @@ -833,7 +833,7 @@ namespace NifOsg else Log(Debug::Info) << "Unhandled particle modifier " << affectors->recName << " in " << mFilename; } - for (; !colliders.empty(); colliders = colliders->extra) + for (; !colliders.empty(); colliders = colliders->next) { if (colliders->recType == Nif::RC_NiPlanarCollider) {