diff --git a/src/Core/Scene/CSceneNode.cpp b/src/Core/Scene/CSceneNode.cpp index d67c5197..132c8f8c 100644 --- a/src/Core/Scene/CSceneNode.cpp +++ b/src/Core/Scene/CSceneNode.cpp @@ -13,21 +13,9 @@ uint32 CSceneNode::smNumNodes = 0; CColor CSceneNode::skSelectionTint = CColor::Integral(39, 154, 167); CSceneNode::CSceneNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent) - : mpScene(pScene) + : _mID(NodeID) , mpParent(pParent) - , _mID(NodeID) - , mPosition(CVector3f::skZero) - , mRotation(CQuaternion::skIdentity) - , mScale(CVector3f::skOne) - , _mTransformDirty(true) - , _mInheritsPosition(true) - , _mInheritsRotation(true) - , _mInheritsScale(true) - , mLightLayerIndex(0) - , mLightCount(0) - , mMouseHovering(false) - , mSelected(false) - , mVisible(true) + , mpScene(pScene) { smNumNodes++; @@ -38,8 +26,7 @@ CSceneNode::CSceneNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent) CSceneNode::~CSceneNode() { smNumNodes--; - for (auto it = mChildren.begin(); it != mChildren.end(); it++) - delete (*it); + DeleteChildren(); } // ************ VIRTUAL ************ @@ -81,8 +68,8 @@ void CSceneNode::OnLoadFinished() { PostLoad(); - for (auto it = mChildren.begin(); it != mChildren.end(); it++) - (*it)->OnLoadFinished(); + for (auto* child : mChildren) + child->OnLoadFinished(); } void CSceneNode::Unparent() @@ -97,7 +84,7 @@ void CSceneNode::Unparent() void CSceneNode::RemoveChild(CSceneNode *pChild) { - for (auto it = mChildren.begin(); it != mChildren.end(); it++) + for (auto it = mChildren.begin(); it != mChildren.end(); ++it) { if (*it == pChild) { @@ -109,8 +96,8 @@ void CSceneNode::RemoveChild(CSceneNode *pChild) void CSceneNode::DeleteChildren() { - for (auto it = mChildren.begin(); it != mChildren.end(); it++) - delete *it; + for (auto* child : mChildren) + delete child; mChildren.clear(); } @@ -329,8 +316,8 @@ void CSceneNode::ForceRecalculateTransform() const // If so, the children will already be marked if (!_mTransformDirty) { - for (auto it = mChildren.begin(); it != mChildren.end(); it++) - (*it)->MarkTransformChanged(); + for (auto* child : mChildren) + child->MarkTransformChanged(); } _mTransformDirty = false; } @@ -339,8 +326,8 @@ void CSceneNode::MarkTransformChanged() const { if (!_mTransformDirty) { - for (auto it = mChildren.begin(); it != mChildren.end(); it++) - (*it)->MarkTransformChanged(); + for (auto* child : mChildren) + child->MarkTransformChanged(); } _mTransformDirty = true; @@ -367,7 +354,7 @@ CVector3f CSceneNode::AbsolutePosition() const { CVector3f ret = mPosition; - if ((mpParent) && (InheritsPosition())) + if (mpParent != nullptr && InheritsPosition()) ret += mpParent->AbsolutePosition(); return ret; @@ -377,7 +364,7 @@ CQuaternion CSceneNode::AbsoluteRotation() const { CQuaternion ret = mRotation; - if ((mpParent) && (InheritsRotation())) + if (mpParent != nullptr && InheritsRotation()) ret *= mpParent->AbsoluteRotation(); return ret; @@ -387,7 +374,7 @@ CVector3f CSceneNode::AbsoluteScale() const { CVector3f ret = mScale; - if ((mpParent) && (InheritsScale())) + if (mpParent != nullptr && InheritsScale()) ret *= mpParent->AbsoluteScale(); return ret; diff --git a/src/Core/Scene/CSceneNode.h b/src/Core/Scene/CSceneNode.h index 802b82d9..eae48c65 100644 --- a/src/Core/Scene/CSceneNode.h +++ b/src/Core/Scene/CSceneNode.h @@ -15,6 +15,7 @@ #include #include #include +#include class CRenderer; class CScene; @@ -71,11 +72,11 @@ class CSceneNode : public IRenderable private: mutable CTransform4f _mCachedTransform; mutable CAABox _mCachedAABox; - mutable bool _mTransformDirty; + mutable bool _mTransformDirty = true; - bool _mInheritsPosition; - bool _mInheritsRotation; - bool _mInheritsScale; + bool _mInheritsPosition = true; + bool _mInheritsRotation = true; + bool _mInheritsScale = true; uint32 _mID; @@ -85,29 +86,29 @@ protected: CSceneNode *mpParent; CScene *mpScene; - CVector3f mPosition; - CQuaternion mRotation; - CVector3f mScale; + CVector3f mPosition{CVector3f::skZero}; + CQuaternion mRotation{CQuaternion::skIdentity}; + CVector3f mScale{CVector3f::skOne}; CAABox mLocalAABox; - bool mMouseHovering; - bool mSelected; - bool mVisible; + bool mMouseHovering = false; + bool mSelected = false; + bool mVisible = true; std::list mChildren; - uint32 mLightLayerIndex; - uint32 mLightCount; - CLight* mLights[8]; + uint32 mLightLayerIndex = 0; + uint32 mLightCount = 0; + std::array mLights{}; CColor mAmbientColor; public: explicit CSceneNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent = 0); - virtual ~CSceneNode(); + ~CSceneNode() override; virtual ENodeType NodeType() = 0; virtual void PostLoad() {} virtual void OnTransformed() {} - virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*rkViewInfo*/) {} - virtual void DrawSelection(); + void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*rkViewInfo*/) override {} + void DrawSelection() override; virtual void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo); virtual SRayIntersection RayNodeIntersectTest(const CRay& rkRay, uint32 AssetID, const SViewInfo& rkViewInfo) = 0; virtual bool AllowsTranslate() const { return true; } @@ -179,7 +180,7 @@ public: void SetVisible(bool Visible) { mVisible = Visible; } // Static - inline static int NumNodes() { return smNumNodes; } + static int NumNodes() { return smNumNodes; } static CColor skSelectionTint; };