Merge pull request #26 from lioncash/scene

CSceneNode: Minor cleanup
This commit is contained in:
LC 2020-06-11 10:53:51 -04:00 committed by GitHub
commit b5ddc20771
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 45 deletions

View File

@ -13,21 +13,9 @@ uint32 CSceneNode::smNumNodes = 0;
CColor CSceneNode::skSelectionTint = CColor::Integral(39, 154, 167); CColor CSceneNode::skSelectionTint = CColor::Integral(39, 154, 167);
CSceneNode::CSceneNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent) CSceneNode::CSceneNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent)
: mpScene(pScene) : _mID(NodeID)
, mpParent(pParent) , mpParent(pParent)
, _mID(NodeID) , mpScene(pScene)
, 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)
{ {
smNumNodes++; smNumNodes++;
@ -38,8 +26,7 @@ CSceneNode::CSceneNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent)
CSceneNode::~CSceneNode() CSceneNode::~CSceneNode()
{ {
smNumNodes--; smNumNodes--;
for (auto it = mChildren.begin(); it != mChildren.end(); it++) DeleteChildren();
delete (*it);
} }
// ************ VIRTUAL ************ // ************ VIRTUAL ************
@ -81,8 +68,8 @@ void CSceneNode::OnLoadFinished()
{ {
PostLoad(); PostLoad();
for (auto it = mChildren.begin(); it != mChildren.end(); it++) for (auto* child : mChildren)
(*it)->OnLoadFinished(); child->OnLoadFinished();
} }
void CSceneNode::Unparent() void CSceneNode::Unparent()
@ -97,7 +84,7 @@ void CSceneNode::Unparent()
void CSceneNode::RemoveChild(CSceneNode *pChild) 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) if (*it == pChild)
{ {
@ -109,8 +96,8 @@ void CSceneNode::RemoveChild(CSceneNode *pChild)
void CSceneNode::DeleteChildren() void CSceneNode::DeleteChildren()
{ {
for (auto it = mChildren.begin(); it != mChildren.end(); it++) for (auto* child : mChildren)
delete *it; delete child;
mChildren.clear(); mChildren.clear();
} }
@ -329,8 +316,8 @@ void CSceneNode::ForceRecalculateTransform() const
// If so, the children will already be marked // If so, the children will already be marked
if (!_mTransformDirty) if (!_mTransformDirty)
{ {
for (auto it = mChildren.begin(); it != mChildren.end(); it++) for (auto* child : mChildren)
(*it)->MarkTransformChanged(); child->MarkTransformChanged();
} }
_mTransformDirty = false; _mTransformDirty = false;
} }
@ -339,8 +326,8 @@ void CSceneNode::MarkTransformChanged() const
{ {
if (!_mTransformDirty) if (!_mTransformDirty)
{ {
for (auto it = mChildren.begin(); it != mChildren.end(); it++) for (auto* child : mChildren)
(*it)->MarkTransformChanged(); child->MarkTransformChanged();
} }
_mTransformDirty = true; _mTransformDirty = true;
@ -367,7 +354,7 @@ CVector3f CSceneNode::AbsolutePosition() const
{ {
CVector3f ret = mPosition; CVector3f ret = mPosition;
if ((mpParent) && (InheritsPosition())) if (mpParent != nullptr && InheritsPosition())
ret += mpParent->AbsolutePosition(); ret += mpParent->AbsolutePosition();
return ret; return ret;
@ -377,7 +364,7 @@ CQuaternion CSceneNode::AbsoluteRotation() const
{ {
CQuaternion ret = mRotation; CQuaternion ret = mRotation;
if ((mpParent) && (InheritsRotation())) if (mpParent != nullptr && InheritsRotation())
ret *= mpParent->AbsoluteRotation(); ret *= mpParent->AbsoluteRotation();
return ret; return ret;
@ -387,7 +374,7 @@ CVector3f CSceneNode::AbsoluteScale() const
{ {
CVector3f ret = mScale; CVector3f ret = mScale;
if ((mpParent) && (InheritsScale())) if (mpParent != nullptr && InheritsScale())
ret *= mpParent->AbsoluteScale(); ret *= mpParent->AbsoluteScale();
return ret; return ret;

View File

@ -15,6 +15,7 @@
#include <Common/Math/CTransform4f.h> #include <Common/Math/CTransform4f.h>
#include <Common/Math/CVector3f.h> #include <Common/Math/CVector3f.h>
#include <Common/Math/ETransformSpace.h> #include <Common/Math/ETransformSpace.h>
#include <array>
class CRenderer; class CRenderer;
class CScene; class CScene;
@ -71,11 +72,11 @@ class CSceneNode : public IRenderable
private: private:
mutable CTransform4f _mCachedTransform; mutable CTransform4f _mCachedTransform;
mutable CAABox _mCachedAABox; mutable CAABox _mCachedAABox;
mutable bool _mTransformDirty; mutable bool _mTransformDirty = true;
bool _mInheritsPosition; bool _mInheritsPosition = true;
bool _mInheritsRotation; bool _mInheritsRotation = true;
bool _mInheritsScale; bool _mInheritsScale = true;
uint32 _mID; uint32 _mID;
@ -85,29 +86,29 @@ protected:
CSceneNode *mpParent; CSceneNode *mpParent;
CScene *mpScene; CScene *mpScene;
CVector3f mPosition; CVector3f mPosition{CVector3f::skZero};
CQuaternion mRotation; CQuaternion mRotation{CQuaternion::skIdentity};
CVector3f mScale; CVector3f mScale{CVector3f::skOne};
CAABox mLocalAABox; CAABox mLocalAABox;
bool mMouseHovering; bool mMouseHovering = false;
bool mSelected; bool mSelected = false;
bool mVisible; bool mVisible = true;
std::list<CSceneNode*> mChildren; std::list<CSceneNode*> mChildren;
uint32 mLightLayerIndex; uint32 mLightLayerIndex = 0;
uint32 mLightCount; uint32 mLightCount = 0;
CLight* mLights[8]; std::array<CLight*, 8> mLights{};
CColor mAmbientColor; CColor mAmbientColor;
public: public:
explicit CSceneNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent = 0); explicit CSceneNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent = 0);
virtual ~CSceneNode(); ~CSceneNode() override;
virtual ENodeType NodeType() = 0; virtual ENodeType NodeType() = 0;
virtual void PostLoad() {} virtual void PostLoad() {}
virtual void OnTransformed() {} virtual void OnTransformed() {}
virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*rkViewInfo*/) {} void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*rkViewInfo*/) override {}
virtual void DrawSelection(); void DrawSelection() override;
virtual void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo); virtual void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo);
virtual SRayIntersection RayNodeIntersectTest(const CRay& rkRay, uint32 AssetID, const SViewInfo& rkViewInfo) = 0; virtual SRayIntersection RayNodeIntersectTest(const CRay& rkRay, uint32 AssetID, const SViewInfo& rkViewInfo) = 0;
virtual bool AllowsTranslate() const { return true; } virtual bool AllowsTranslate() const { return true; }
@ -179,7 +180,7 @@ public:
void SetVisible(bool Visible) { mVisible = Visible; } void SetVisible(bool Visible) { mVisible = Visible; }
// Static // Static
inline static int NumNodes() { return smNumNodes; } static int NumNodes() { return smNumNodes; }
static CColor skSelectionTint; static CColor skSelectionTint;
}; };