From 38cdcbdbd30aa9d4938a3fa757047b90c554ea1d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 28 Jun 2020 05:45:06 -0400 Subject: [PATCH] CSceneViewport: Make use of in-class initializers where applicable --- src/Editor/CSceneViewport.cpp | 29 +++++++--------------- src/Editor/CSceneViewport.h | 45 ++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/src/Editor/CSceneViewport.cpp b/src/Editor/CSceneViewport.cpp index 121883dd..4804cfa8 100644 --- a/src/Editor/CSceneViewport.cpp +++ b/src/Editor/CSceneViewport.cpp @@ -11,34 +11,23 @@ CSceneViewport::CSceneViewport(QWidget *pParent) : CBasicViewport(pParent) - , mpEditor(nullptr) - , mpScene(nullptr) - , mRenderingMergedWorld(true) - , mGizmoTransforming(false) - , mpHoverNode(nullptr) - , mHoverPoint(CVector3f::Zero()) - , mpContextMenu(nullptr) - , mpMenuNode(nullptr) { mGrid.SetColor(CColor(0.f, 0.f, 0.6f, 0.f), CColor(0.f, 0.f, 1.f, 0.f)); mLinkLine.SetColor(CColor::Yellow()); - mpRenderer = new CRenderer(); + mpRenderer = std::make_unique(); mpRenderer->SetClearColor(CColor::Black()); - qreal pixelRatio = devicePixelRatioF(); + const qreal pixelRatio = devicePixelRatioF(); mpRenderer->SetViewportSize(width() * pixelRatio, height() * pixelRatio); mViewInfo.pScene = mpScene; - mViewInfo.pRenderer = mpRenderer; + mViewInfo.pRenderer = mpRenderer.get(); mViewInfo.ShowFlags = EShowFlag::MergedWorld | EShowFlag::ObjectGeometry | EShowFlag::Lights | EShowFlag::Sky; CreateContextMenu(); } -CSceneViewport::~CSceneViewport() -{ - delete mpRenderer; -} +CSceneViewport::~CSceneViewport() = default; void CSceneViewport::SetScene(INodeEditor *pEditor, CScene *pScene) { @@ -72,7 +61,7 @@ FShowFlags CSceneViewport::ShowFlags() const CRenderer* CSceneViewport::Renderer() { - return mpRenderer; + return mpRenderer.get(); } CSceneNode* CSceneViewport::HoverNode() @@ -317,22 +306,22 @@ void CSceneViewport::Paint() } mCamera.LoadMatrices(); - mpScene->AddSceneToRenderer(mpRenderer, mViewInfo); + mpScene->AddSceneToRenderer(mpRenderer.get(), mViewInfo); // Add gizmo to renderer if (mpEditor->IsGizmoVisible() && !mViewInfo.GameMode) { CGizmo *pGizmo = mpEditor->Gizmo(); pGizmo->UpdateForCamera(mCamera); - pGizmo->AddToRenderer(mpRenderer, mViewInfo); + pGizmo->AddToRenderer(mpRenderer.get(), mViewInfo); } // Draw grid if the scene is empty if (!mViewInfo.GameMode && mpScene->ActiveArea() == nullptr) - mGrid.AddToRenderer(mpRenderer, mViewInfo); + mGrid.AddToRenderer(mpRenderer.get(), mViewInfo); // Draw the line for the link the user is editing. - if (mLinkLineEnabled) mLinkLine.AddToRenderer(mpRenderer, mViewInfo); + if (mLinkLineEnabled) mLinkLine.AddToRenderer(mpRenderer.get(), mViewInfo); mpRenderer->RenderBuckets(mViewInfo); mpRenderer->EndFrame(); diff --git a/src/Editor/CSceneViewport.h b/src/Editor/CSceneViewport.h index 4f9b27fe..66063391 100644 --- a/src/Editor/CSceneViewport.h +++ b/src/Editor/CSceneViewport.h @@ -10,20 +10,20 @@ class CSceneViewport : public CBasicViewport { Q_OBJECT - INodeEditor *mpEditor; - CScene *mpScene; - CRenderer *mpRenderer; - bool mRenderingMergedWorld; + INodeEditor *mpEditor = nullptr; + CScene *mpScene = nullptr; + std::unique_ptr mpRenderer; + bool mRenderingMergedWorld = true; // Scene interaction - bool mGizmoHovering; - bool mGizmoTransforming; + bool mGizmoHovering = false; + bool mGizmoTransforming = false; SRayIntersection mRayIntersection; - CSceneNode *mpHoverNode; - CVector3f mHoverPoint; + CSceneNode *mpHoverNode = nullptr; + CVector3f mHoverPoint{CVector3f::Zero()}; // Context Menu - QMenu *mpContextMenu; + QMenu *mpContextMenu = nullptr; QAction *mpToggleSelectAction; QAction *mpHideSelectionSeparator; QAction *mpHideSelectionAction; @@ -36,7 +36,7 @@ class CSceneViewport : public CBasicViewport QAction *mpUnhideAllAction; QAction *mpPlayFromHereSeparator; QAction *mpPlayFromHereAction; - CSceneNode *mpMenuNode; + CSceneNode *mpMenuNode = nullptr; CVector3f mMenuPoint; QMenu *mpSelectConnectedMenu; @@ -52,8 +52,9 @@ class CSceneViewport : public CBasicViewport CLineRenderable mLinkLine; public: - CSceneViewport(QWidget *pParent = 0); - ~CSceneViewport(); + explicit CSceneViewport(QWidget *pParent = nullptr); + ~CSceneViewport() override; + void SetScene(INodeEditor *pEditor, CScene *pScene); void SetShowWorld(bool Visible); void SetRenderMergedWorld(bool RenderMerged); @@ -66,11 +67,11 @@ public: void ResetHover(); bool IsHoveringGizmo(); - void keyPressEvent(QKeyEvent* pEvent); - void keyReleaseEvent(QKeyEvent* pEvent); + void keyPressEvent(QKeyEvent* pEvent) override; + void keyReleaseEvent(QKeyEvent* pEvent) override; - inline void SetLinkLineEnabled(bool Enable) { mLinkLineEnabled = Enable; } - inline void SetLinkLine(const CVector3f& rkPointA, const CVector3f& rkPointB) { mLinkLine.SetPoints(rkPointA, rkPointB); } + void SetLinkLineEnabled(bool Enable) { mLinkLineEnabled = Enable; } + void SetLinkLine(const CVector3f& rkPointA, const CVector3f& rkPointB) { mLinkLine.SetPoints(rkPointA, rkPointB); } protected: void CreateContextMenu(); @@ -84,12 +85,12 @@ signals: void CameraOrbit(); protected slots: - void CheckUserInput(); - void Paint(); - void ContextMenu(QContextMenuEvent *pEvent); - void OnResize(); - void OnMouseClick(QMouseEvent *pEvent); - void OnMouseRelease(QMouseEvent *pEvent); + void CheckUserInput() override; + void Paint() override; + void ContextMenu(QContextMenuEvent *pEvent) override; + void OnResize() override; + void OnMouseClick(QMouseEvent *pEvent) override; + void OnMouseRelease(QMouseEvent *pEvent) override; // Menu Actions void OnToggleSelect();