From c36c28e8f9a52c2b405a45bf7eaa0397ed7911dd Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Thu, 21 Jul 2022 15:51:34 +0400 Subject: [PATCH] Move NIF implementation to cpp files --- .../nifloader/testbulletnifloader.cpp | 2 + components/nif/base.cpp | 32 ++ components/nif/base.hpp | 38 +-- components/nif/controller.cpp | 4 +- components/nif/data.cpp | 1 + components/nif/data.hpp | 1 + components/nif/effect.cpp | 12 + components/nif/effect.hpp | 11 +- components/nif/niffile.cpp | 31 +- components/nif/niffile.hpp | 21 +- components/nif/nifkey.hpp | 3 +- components/nif/nifstream.hpp | 1 - components/nif/node.cpp | 275 +++++++++++++++++ components/nif/node.hpp | 279 ++---------------- components/nif/physics.cpp | 4 +- components/nifosg/nifloader.cpp | 5 +- components/resource/keyframemanager.cpp | 1 + components/resource/niffilemanager.cpp | 2 + 18 files changed, 397 insertions(+), 326 deletions(-) create mode 100644 components/nif/base.cpp diff --git a/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp b/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp index 21b9e9df3a..0a77a2a884 100644 --- a/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp +++ b/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include diff --git a/components/nif/base.cpp b/components/nif/base.cpp new file mode 100644 index 0000000000..8f0a069f3f --- /dev/null +++ b/components/nif/base.cpp @@ -0,0 +1,32 @@ +#include "base.hpp" + +namespace Nif +{ + void Extra::read(NIFStream *nif) + { + if (nif->getVersion() >= NIFStream::generateVersion(10,0,1,0)) + name = nif->getString(); + else if (nif->getVersion() <= NIFStream::generateVersion(4,2,2,0)) + { + next.read(nif); + recordSize = nif->getUInt(); + } + } + + void Named::read(NIFStream *nif) + { + name = nif->getString(); + if (nif->getVersion() < NIFStream::generateVersion(10,0,1,0)) + extra.read(nif); + else + extralist.read(nif); + controller.read(nif); + } + + void Named::post(NIFFile *nif) + { + extra.post(nif); + extralist.post(nif); + controller.post(nif); + } +} diff --git a/components/nif/base.hpp b/components/nif/base.hpp index 3c7ee160ea..35474ad385 100644 --- a/components/nif/base.hpp +++ b/components/nif/base.hpp @@ -2,14 +2,14 @@ #ifndef OPENMW_COMPONENTS_NIF_BASE_HPP #define OPENMW_COMPONENTS_NIF_BASE_HPP -#include "record.hpp" -#include "niffile.hpp" #include "recordptr.hpp" -#include "nifstream.hpp" -#include "nifkey.hpp" namespace Nif { +struct File; +struct Record; +struct Stream; + // An extra data record. All the extra data connected to an object form a linked list. struct Extra : public Record { @@ -17,17 +17,7 @@ struct Extra : public Record ExtraPtr next; // Next extra data record in the list unsigned int recordSize{0u}; - void read(NIFStream *nif) override - { - if (nif->getVersion() >= NIFStream::generateVersion(10,0,1,0)) - name = nif->getString(); - else if (nif->getVersion() <= NIFStream::generateVersion(4,2,2,0)) - { - next.read(nif); - recordSize = nif->getUInt(); - } - } - + void read(NIFStream *nif) override; void post(NIFFile *nif) override { next.post(nif); } }; @@ -66,22 +56,8 @@ struct Named : public Record ExtraList extralist; ControllerPtr controller; - void read(NIFStream *nif) override - { - name = nif->getString(); - if (nif->getVersion() < NIFStream::generateVersion(10,0,1,0)) - extra.read(nif); - else - extralist.read(nif); - controller.read(nif); - } - - void post(NIFFile *nif) override - { - extra.post(nif); - extralist.post(nif); - controller.post(nif); - } + void read(NIFStream *nif) override; + void post(NIFFile *nif) override; }; using NiSequenceStreamHelper = Named; diff --git a/components/nif/controller.cpp b/components/nif/controller.cpp index 16e6b5e40f..7106335668 100644 --- a/components/nif/controller.cpp +++ b/components/nif/controller.cpp @@ -1,7 +1,9 @@ #include "controller.hpp" -#include "node.hpp" +#include "controlled.hpp" #include "data.hpp" +#include "node.hpp" +#include "recordptr.hpp" namespace Nif { diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 36a123fdfa..b0ed2f4e53 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -1,4 +1,5 @@ #include "data.hpp" +#include "nifkey.hpp" #include "node.hpp" namespace Nif diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 919e442665..f220aae373 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -26,6 +26,7 @@ #include "base.hpp" +#include "nifkey.hpp" #include "niftypes.hpp" // Transformation namespace Nif diff --git a/components/nif/effect.cpp b/components/nif/effect.cpp index c12eb6c1b8..e1cab2bd50 100644 --- a/components/nif/effect.cpp +++ b/components/nif/effect.cpp @@ -1,10 +1,22 @@ #include "effect.hpp" +#include "controlled.hpp" #include "node.hpp" namespace Nif { +void NiDynamicEffect::read(NIFStream *nif) +{ + Node::read(nif); + if (nif->getVersion() >= nif->generateVersion(10,1,0,106) + && nif->getBethVersion() < NIFFile::BethVersion::BETHVER_FO4) + nif->getBoolean(); // Switch state + unsigned int numAffectedNodes = nif->getUInt(); + for (unsigned int i=0; igetUInt(); // ref to another Node +} + void NiLight::read(NIFStream *nif) { NiDynamicEffect::read(nif); diff --git a/components/nif/effect.hpp b/components/nif/effect.hpp index 4c546a1aef..dcbeef45e1 100644 --- a/components/nif/effect.hpp +++ b/components/nif/effect.hpp @@ -31,16 +31,7 @@ namespace Nif struct NiDynamicEffect : public Node { - void read(NIFStream *nif) override - { - Node::read(nif); - if (nif->getVersion() >= nif->generateVersion(10,1,0,106) - && nif->getBethVersion() < NIFFile::BethVersion::BETHVER_FO4) - nif->getBoolean(); // Switch state - unsigned int numAffectedNodes = nif->getUInt(); - for (unsigned int i=0; igetUInt(); // ref to another Node - } + void read(NIFStream *nif) override; }; // Used as base for NiAmbientLight, NiDirectionalLight, NiPointLight and NiSpotLight. diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index 4e0fd5a614..d09a8f6caa 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -1,12 +1,22 @@ #include "niffile.hpp" -#include "effect.hpp" +#include #include +#include #include +#include #include #include -#include +#include + +#include "controlled.hpp" +#include "controller.hpp" +#include "data.hpp" +#include "effect.hpp" +#include "extra.hpp" +#include "physics.hpp" +#include "property.hpp" namespace Nif { @@ -353,4 +363,21 @@ void NIFFile::setLoadUnsupportedFiles(bool load) sLoadUnsupportedFiles = load; } +void NIFFile::warn(const std::string &msg) const +{ + Log(Debug::Warning) << " NIFFile Warning: " << msg << "\nFile: " << filename; +} + +[[noreturn]] void NIFFile::fail(const std::string &msg) const +{ + throw std::runtime_error(" NIFFile Error: " + msg + "\nFile: " + filename); +} + +std::string NIFFile::getString(uint32_t index) const +{ + if (index == std::numeric_limits::max()) + return std::string(); + return strings.at(index); +} + } diff --git a/components/nif/niffile.hpp b/components/nif/niffile.hpp index 358428e94c..6b217df6e1 100644 --- a/components/nif/niffile.hpp +++ b/components/nif/niffile.hpp @@ -3,12 +3,9 @@ #ifndef OPENMW_COMPONENTS_NIF_NIFFILE_HPP #define OPENMW_COMPONENTS_NIF_NIFFILE_HPP -#include #include #include -#include -#include #include #include "record.hpp" @@ -97,15 +94,10 @@ public: }; /// Used if file parsing fails - [[noreturn]] void fail(const std::string &msg) const - { - throw std::runtime_error(" NIFFile Error: " + msg + "\nFile: " + filename); - } + [[noreturn]] void fail(const std::string &msg) const; + /// Used when something goes wrong, but not catastrophically so - void warn(const std::string &msg) const - { - Log(Debug::Warning) << " NIFFile Warning: " << msg << "\nFile: " << filename; - } + void warn(const std::string &msg) const; /// Open a NIF stream. The name is used for error messages. NIFFile(Files::IStreamPtr&& stream, const std::string &name); @@ -128,12 +120,7 @@ public: size_t numRoots() const override { return roots.size(); } /// Get a given string from the file's string table - std::string getString(uint32_t index) const override - { - if (index == std::numeric_limits::max()) - return std::string(); - return strings.at(index); - } + std::string getString(uint32_t index) const override; /// Set whether there is skinning contained in this NIF file. /// @note This is just a hint for users of the NIF file and has no effect on the loading procedure. diff --git a/components/nif/nifkey.hpp b/components/nif/nifkey.hpp index bcf186f333..48c53181a4 100644 --- a/components/nif/nifkey.hpp +++ b/components/nif/nifkey.hpp @@ -3,10 +3,9 @@ #ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP #define OPENMW_COMPONENTS_NIF_NIFKEY_HPP -#include "nifstream.hpp" - #include +#include "nifstream.hpp" #include "niffile.hpp" namespace Nif diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index acf1dd4704..5b41f4c8ed 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include diff --git a/components/nif/node.cpp b/components/nif/node.cpp index e69de29bb2..7c92cd3851 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -0,0 +1,275 @@ +#include "node.hpp" + +#include + +#include "data.hpp" +#include "physics.hpp" +#include "property.hpp" + +namespace Nif +{ + void NiBoundingVolume::read(NIFStream* nif) + { + type = nif->getUInt(); + switch (type) + { + case BASE_BV: + break; + case SPHERE_BV: + { + sphere.center = nif->getVector3(); + sphere.radius = nif->getFloat(); + break; + } + case BOX_BV: + { + box.center = nif->getVector3(); + box.axes = nif->getMatrix3(); + box.extents = nif->getVector3(); + break; + } + case CAPSULE_BV: + { + capsule.center = nif->getVector3(); + capsule.axis = nif->getVector3(); + capsule.extent = nif->getFloat(); + capsule.radius = nif->getFloat(); + break; + } + case LOZENGE_BV: + { + lozenge.radius = nif->getFloat(); + if (nif->getVersion() >= NIFStream::generateVersion(4,2,1,0)) + { + lozenge.extent0 = nif->getFloat(); + lozenge.extent1 = nif->getFloat(); + } + lozenge.center = nif->getVector3(); + lozenge.axis0 = nif->getVector3(); + lozenge.axis1 = nif->getVector3(); + break; + } + case UNION_BV: + { + unsigned int numChildren = nif->getUInt(); + if (numChildren == 0) + break; + children.resize(numChildren); + for (NiBoundingVolume& child : children) + child.read(nif); + break; + } + case HALFSPACE_BV: + { + halfSpace.plane = osg::Plane(nif->getVector4()); + if (nif->getVersion() >= NIFStream::generateVersion(4,2,1,0)) + halfSpace.origin = nif->getVector3(); + break; + } + default: + { + nif->file->fail("Unhandled NiBoundingVolume type: " + std::to_string(type)); + } + } + } + + void Node::read(NIFStream *nif) + { + Named::read(nif); + + flags = nif->getBethVersion() <= 26 ? nif->getUShort() : nif->getUInt(); + trafo = nif->getTrafo(); + if (nif->getVersion() <= NIFStream::generateVersion(4,2,2,0)) + velocity = nif->getVector3(); + if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3) + props.read(nif); + + if (nif->getVersion() <= NIFStream::generateVersion(4,2,2,0)) + hasBounds = nif->getBoolean(); + if (hasBounds) + bounds.read(nif); + // Reference to the collision object in Gamebryo files. + if (nif->getVersion() >= NIFStream::generateVersion(10,0,1,0)) + collision.read(nif); + + parents.clear(); + + isBone = false; + } + + void Node::post(NIFFile *nif) + { + Named::post(nif); + props.post(nif); + collision.post(nif); + } + + void Node::setBone() + { + isBone = true; + } + + void NiNode::read(NIFStream *nif) + { + Node::read(nif); + children.read(nif); + if (nif->getBethVersion() < NIFFile::BethVersion::BETHVER_FO4) + effects.read(nif); + + // Discard transformations for the root node, otherwise some meshes + // occasionally get wrong orientation. Only for NiNode-s for now, but + // can be expanded if needed. + // FIXME: if node 0 is *not* the only root node, this must not happen. + if (0 == recIndex && !Misc::StringUtils::ciEqual(name, "bip01")) + { + trafo = Nif::Transformation::getIdentity(); + } + } + + void NiNode::post(NIFFile *nif) + { + Node::post(nif); + children.post(nif); + effects.post(nif); + + for (size_t i = 0; i < children.length(); i++) + { + // Why would a unique list of children contain empty refs? + if (!children[i].empty()) + children[i]->parents.push_back(this); + } + } + + void NiGeometry::MaterialData::read(NIFStream *nif) + { + if (nif->getVersion() <= NIFStream::generateVersion(10,0,1,0)) + return; + unsigned int num = 0; + if (nif->getVersion() <= NIFStream::generateVersion(20,1,0,3)) + num = nif->getBoolean(); // Has Shader + else if (nif->getVersion() >= NIFStream::generateVersion(20,2,0,5)) + num = nif->getUInt(); + if (num) + { + nif->getStrings(names, num); + nif->getInts(extra, num); + } + if (nif->getVersion() >= NIFStream::generateVersion(20,2,0,5)) + active = nif->getUInt(); + if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS) + needsUpdate = nif->getBoolean(); + } + + void NiGeometry::read(NIFStream *nif) + { + Node::read(nif); + data.read(nif); + skin.read(nif); + material.read(nif); + if (nif->getVersion() == NIFFile::NIFVersion::VER_BGS && nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3) + { + shaderprop.read(nif); + alphaprop.read(nif); + } + } + + void NiGeometry::post(NIFFile *nif) + { + Node::post(nif); + data.post(nif); + skin.post(nif); + shaderprop.post(nif); + alphaprop.post(nif); + if (recType != RC_NiParticles && !skin.empty()) + nif->setUseSkinning(true); + } + + void BSLODTriShape::read(NIFStream *nif) + { + NiTriShape::read(nif); + lod0 = nif->getUInt(); + lod1 = nif->getUInt(); + lod2 = nif->getUInt(); + } + + void NiCamera::Camera::read(NIFStream *nif) + { + if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0)) + cameraFlags = nif->getUShort(); + left = nif->getFloat(); + right = nif->getFloat(); + top = nif->getFloat(); + bottom = nif->getFloat(); + nearDist = nif->getFloat(); + farDist = nif->getFloat(); + if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0)) + orthographic = nif->getBoolean(); + vleft = nif->getFloat(); + vright = nif->getFloat(); + vtop = nif->getFloat(); + vbottom = nif->getFloat(); + + LOD = nif->getFloat(); + } + + void NiCamera::read(NIFStream *nif) + { + Node::read(nif); + + cam.read(nif); + + nif->getInt(); // -1 + nif->getInt(); // 0 + if (nif->getVersion() >= NIFStream::generateVersion(4,2,1,0)) + nif->getInt(); // 0 + } + + void NiSwitchNode::read(NIFStream *nif) + { + NiNode::read(nif); + if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0)) + switchFlags = nif->getUShort(); + initialIndex = nif->getUInt(); + } + + void NiLODNode::read(NIFStream *nif) + { + NiSwitchNode::read(nif); + if (nif->getVersion() >= NIFFile::NIFVersion::VER_MW && nif->getVersion() <= NIFStream::generateVersion(10,0,1,0)) + lodCenter = nif->getVector3(); + else if (nif->getVersion() > NIFStream::generateVersion(10,0,1,0)) + { + nif->skip(4); // NiLODData, unsupported at the moment + return; + } + + unsigned int numLodLevels = nif->getUInt(); + for (unsigned int i=0; igetFloat(); + r.maxRange = nif->getFloat(); + lodLevels.push_back(r); + } + } + + void NiFltAnimationNode::read(NIFStream *nif) + { + NiSwitchNode::read(nif); + mDuration = nif->getFloat(); + } + + void NiSortAdjustNode::read(NIFStream *nif) + { + NiNode::read(nif); + mMode = nif->getInt(); + if (nif->getVersion() <= NIFStream::generateVersion(20,0,0,3)) + mSubSorter.read(nif); + } + + void NiSortAdjustNode::post(NIFFile *nif) + { + NiNode::post(nif); + mSubSorter.post(nif); + } +} diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 29c0f03e78..bfcd008fc9 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -3,16 +3,7 @@ #include -#include "controlled.hpp" -#include "extra.hpp" -#include "data.hpp" -#include "property.hpp" -#include "niftypes.hpp" -#include "controller.hpp" #include "base.hpp" -#include "physics.hpp" - -#include namespace Nif { @@ -70,70 +61,8 @@ struct NiBoundingVolume NiLozengeBV lozenge; std::vector children; NiHalfSpaceBV halfSpace; - void read(NIFStream* nif) - { - type = nif->getUInt(); - switch (type) - { - case BASE_BV: - break; - case SPHERE_BV: - { - sphere.center = nif->getVector3(); - sphere.radius = nif->getFloat(); - break; - } - case BOX_BV: - { - box.center = nif->getVector3(); - box.axes = nif->getMatrix3(); - box.extents = nif->getVector3(); - break; - } - case CAPSULE_BV: - { - capsule.center = nif->getVector3(); - capsule.axis = nif->getVector3(); - capsule.extent = nif->getFloat(); - capsule.radius = nif->getFloat(); - break; - } - case LOZENGE_BV: - { - lozenge.radius = nif->getFloat(); - if (nif->getVersion() >= NIFStream::generateVersion(4,2,1,0)) - { - lozenge.extent0 = nif->getFloat(); - lozenge.extent1 = nif->getFloat(); - } - lozenge.center = nif->getVector3(); - lozenge.axis0 = nif->getVector3(); - lozenge.axis1 = nif->getVector3(); - break; - } - case UNION_BV: - { - unsigned int numChildren = nif->getUInt(); - if (numChildren == 0) - break; - children.resize(numChildren); - for (NiBoundingVolume& child : children) - child.read(nif); - break; - } - case HALFSPACE_BV: - { - halfSpace.plane = osg::Plane(nif->getVector4()); - if (nif->getVersion() >= NIFStream::generateVersion(4,2,1,0)) - halfSpace.origin = nif->getVector3(); - break; - } - default: - { - nif->file->fail("Unhandled NiBoundingVolume type: " + std::to_string(type)); - } - } - } + + void read(NIFStream* nif); }; /** A Node is an object that's part of the main NIF tree. It has @@ -163,36 +92,8 @@ struct Node : public Named // Collision object info NiCollisionObjectPtr collision; - void read(NIFStream *nif) override - { - Named::read(nif); - - flags = nif->getBethVersion() <= 26 ? nif->getUShort() : nif->getUInt(); - trafo = nif->getTrafo(); - if (nif->getVersion() <= NIFStream::generateVersion(4,2,2,0)) - velocity = nif->getVector3(); - if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3) - props.read(nif); - - if (nif->getVersion() <= NIFStream::generateVersion(4,2,2,0)) - hasBounds = nif->getBoolean(); - if (hasBounds) - bounds.read(nif); - // Reference to the collision object in Gamebryo files. - if (nif->getVersion() >= NIFStream::generateVersion(10,0,1,0)) - collision.read(nif); - - parents.clear(); - - isBone = false; - } - - void post(NIFFile *nif) override - { - Named::post(nif); - props.post(nif); - collision.post(nif); - } + void read(NIFStream *nif) override; + void post(NIFFile *nif) override; // Parent node, or nullptr for the root node. As far as I'm aware, only // NiNodes (or types derived from NiNodes) can be parents. @@ -200,10 +101,7 @@ struct Node : public Named bool isBone{false}; - void setBone() - { - isBone = true; - } + void setBone(); bool isHidden() const { return flags & Flag_Hidden; } bool hasMeshCollision() const { return flags & Flag_MeshCollision; } @@ -224,36 +122,8 @@ struct NiNode : Node ParticleFlag_LocalSpace = 0x0080 }; - void read(NIFStream *nif) override - { - Node::read(nif); - children.read(nif); - if (nif->getBethVersion() < NIFFile::BethVersion::BETHVER_FO4) - effects.read(nif); - - // Discard transformations for the root node, otherwise some meshes - // occasionally get wrong orientation. Only for NiNode-s for now, but - // can be expanded if needed. - // FIXME: if node 0 is *not* the only root node, this must not happen. - if (0 == recIndex && !Misc::StringUtils::ciEqual(name, "bip01")) - { - trafo = Nif::Transformation::getIdentity(); - } - } - - void post(NIFFile *nif) override - { - Node::post(nif); - children.post(nif); - effects.post(nif); - - for(size_t i = 0;i < children.length();i++) - { - // Why would a unique list of children contain empty refs? - if(!children[i].empty()) - children[i]->parents.push_back(this); - } - } + void read(NIFStream *nif) override; + void post(NIFFile *nif) override; }; struct NiGeometry : Node @@ -271,25 +141,7 @@ struct NiGeometry : Node std::vector extra; unsigned int active{0}; bool needsUpdate{false}; - void read(NIFStream *nif) - { - if (nif->getVersion() <= NIFStream::generateVersion(10,0,1,0)) - return; - unsigned int num = 0; - if (nif->getVersion() <= NIFStream::generateVersion(20,1,0,3)) - num = nif->getBoolean(); // Has Shader - else if (nif->getVersion() >= NIFStream::generateVersion(20,2,0,5)) - num = nif->getUInt(); - if (num) - { - nif->getStrings(names, num); - nif->getInts(extra, num); - } - if (nif->getVersion() >= NIFStream::generateVersion(20,2,0,5)) - active = nif->getUInt(); - if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS) - needsUpdate = nif->getBoolean(); - } + void read(NIFStream *nif); }; NiGeometryDataPtr data; @@ -298,42 +150,15 @@ struct NiGeometry : Node BSShaderPropertyPtr shaderprop; NiAlphaPropertyPtr alphaprop; - void read(NIFStream *nif) override - { - Node::read(nif); - data.read(nif); - skin.read(nif); - material.read(nif); - if (nif->getVersion() == NIFFile::NIFVersion::VER_BGS && nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3) - { - shaderprop.read(nif); - alphaprop.read(nif); - } - } - - void post(NIFFile *nif) override - { - Node::post(nif); - data.post(nif); - skin.post(nif); - shaderprop.post(nif); - alphaprop.post(nif); - if (recType != RC_NiParticles && !skin.empty()) - nif->setUseSkinning(true); - } + void read(NIFStream *nif) override; + void post(NIFFile *nif) override; }; struct NiTriShape : NiGeometry {}; struct BSLODTriShape : NiTriShape { unsigned int lod0, lod1, lod2; - void read(NIFStream *nif) override - { - NiTriShape::read(nif); - lod0 = nif->getUInt(); - lod1 = nif->getUInt(); - lod2 = nif->getUInt(); - } + void read(NIFStream *nif) override; }; struct NiTriStrips : NiGeometry {}; struct NiLines : NiGeometry {}; @@ -357,39 +182,11 @@ struct NiCamera : Node // Orthographic projection usage flag bool orthographic{false}; - void read(NIFStream *nif) - { - if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0)) - cameraFlags = nif->getUShort(); - left = nif->getFloat(); - right = nif->getFloat(); - top = nif->getFloat(); - bottom = nif->getFloat(); - nearDist = nif->getFloat(); - farDist = nif->getFloat(); - if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0)) - orthographic = nif->getBoolean(); - vleft = nif->getFloat(); - vright = nif->getFloat(); - vtop = nif->getFloat(); - vbottom = nif->getFloat(); - - LOD = nif->getFloat(); - } + void read(NIFStream *nif); }; Camera cam; - void read(NIFStream *nif) override - { - Node::read(nif); - - cam.read(nif); - - nif->getInt(); // -1 - nif->getInt(); // 0 - if (nif->getVersion() >= NIFStream::generateVersion(4,2,1,0)) - nif->getInt(); // 0 - } + void read(NIFStream *nif) override; }; // A node used as the base to switch between child nodes, such as for LOD levels. @@ -398,13 +195,7 @@ struct NiSwitchNode : public NiNode unsigned int switchFlags{0}; unsigned int initialIndex{0}; - void read(NIFStream *nif) override - { - NiNode::read(nif); - if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0)) - switchFlags = nif->getUShort(); - initialIndex = nif->getUInt(); - } + void read(NIFStream *nif) override; }; struct NiLODNode : public NiSwitchNode @@ -418,26 +209,7 @@ struct NiLODNode : public NiSwitchNode }; std::vector lodLevels; - void read(NIFStream *nif) override - { - NiSwitchNode::read(nif); - if (nif->getVersion() >= NIFFile::NIFVersion::VER_MW && nif->getVersion() <= NIFStream::generateVersion(10,0,1,0)) - lodCenter = nif->getVector3(); - else if (nif->getVersion() > NIFStream::generateVersion(10,0,1,0)) - { - nif->skip(4); // NiLODData, unsupported at the moment - return; - } - - unsigned int numLodLevels = nif->getUInt(); - for (unsigned int i=0; igetFloat(); - r.maxRange = nif->getFloat(); - lodLevels.push_back(r); - } - } + void read(NIFStream *nif) override; }; struct NiFltAnimationNode : public NiSwitchNode @@ -448,11 +220,7 @@ struct NiFltAnimationNode : public NiSwitchNode Flag_Swing = 0x40 }; - void read(NIFStream *nif) override - { - NiSwitchNode::read(nif); - mDuration = nif->getFloat(); - } + void read(NIFStream *nif) override; bool swing() const { return flags & Flag_Swing; } }; @@ -478,18 +246,9 @@ struct NiSortAdjustNode : NiNode int mMode; NiAccumulatorPtr mSubSorter; - void read(NIFStream *nif) override - { - NiNode::read(nif); - mMode = nif->getInt(); - if (nif->getVersion() <= NIFStream::generateVersion(20,0,0,3)) - mSubSorter.read(nif); - } - void post(NIFFile *nif) override - { - NiNode::post(nif); - mSubSorter.post(nif); - } + + void read(NIFStream *nif) override; + void post(NIFFile *nif) override; }; } // Namespace diff --git a/components/nif/physics.cpp b/components/nif/physics.cpp index 9bbeb148dd..be5d5bf0cf 100644 --- a/components/nif/physics.cpp +++ b/components/nif/physics.cpp @@ -1,4 +1,6 @@ #include "physics.hpp" + +#include "data.hpp" #include "node.hpp" namespace Nif @@ -310,4 +312,4 @@ namespace Nif mBodyFlags = nif->getUShort(); } -} // Namespace \ No newline at end of file +} // Namespace diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index fd3fb40d9f..474fc30c32 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -39,8 +39,11 @@ #include #include -#include +#include #include +#include +#include +#include #include #include #include diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index 8aa32a28bc..5d1219de60 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/components/resource/niffilemanager.cpp b/components/resource/niffilemanager.cpp index 8d932ca64e..3f63544e0a 100644 --- a/components/resource/niffilemanager.cpp +++ b/components/resource/niffilemanager.cpp @@ -1,5 +1,7 @@ #include "niffilemanager.hpp" +#include + #include #include