From 3ab98bf2eaed06ee6349915d2ee89c93511c8c1e Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 10 Nov 2023 23:21:59 -0600 Subject: [PATCH] Changed scene item components to smart pointers --- src/dawn/display/RenderPipeline.cpp | 10 +++---- src/dawn/display/RenderPipeline.hpp | 4 +-- src/dawn/prefabs/SimpleSpinningCubePrefab.hpp | 2 +- src/dawn/scene/Scene.hpp | 10 +++---- src/dawn/scene/SceneItem.cpp | 12 +-------- src/dawn/scene/SceneItem.hpp | 27 +++++++++---------- src/dawn/scene/SceneItemComponent.cpp | 4 +-- src/dawn/scene/SceneItemComponent.hpp | 6 ++--- src/dawn/scene/components/display/Camera.hpp | 2 +- .../components/display/CameraTexture.hpp | 2 +- .../scene/components/display/IRenderable.hpp | 6 ++--- .../components/display/PixelPerfectCamera.cpp | 2 +- .../components/display/PixelPerfectCamera.hpp | 2 +- .../display/SimpleRenderTargetQuad.cpp | 4 +-- .../display/SimpleRenderTargetQuad.hpp | 4 +-- .../scene/components/display/TiledSprite.cpp | 6 ++--- .../scene/components/display/TiledSprite.hpp | 4 +-- .../components/display/mesh/MeshRenderer.cpp | 4 +-- .../components/display/mesh/MeshRenderer.hpp | 4 +-- .../physics/2d/CharacterController2D.hpp | 2 +- .../physics/2d/SolidController2D.cpp | 8 +++--- .../physics/2d/SolidController2D.hpp | 6 ++--- .../physics/2d/TriggerController2D.cpp | 8 +++--- .../physics/2d/TriggerController2D.hpp | 6 ++--- src/dawn/scene/components/ui/UICanvas.cpp | 2 +- src/dawn/scene/components/ui/UICanvas.hpp | 4 +-- src/dawn/scene/components/ui/UIComponent.cpp | 4 +-- src/dawn/scene/components/ui/UIComponent.hpp | 4 +-- .../scene/components/ui/menu/UISimpleMenu.cpp | 2 +- .../scene/components/ui/menu/UISimpleMenu.hpp | 10 +++---- .../components/ui/menu/UISimpleMenuItem.cpp | 2 +- .../components/ui/menu/UISimpleMenuItem.hpp | 4 +-- src/dawnhelloworld/scenes/HelloWorldScene.hpp | 4 +-- 33 files changed, 84 insertions(+), 97 deletions(-) diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 92b3aa9d..8e17b87b 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -59,7 +59,7 @@ void RenderPipeline::renderScene(std::shared_ptr scene) { // Now render backbuffers. auto backBuffer = rm->getBackBuffer(); auto cameras = scene->findComponents(); - Camera *backBufferCamera = nullptr; + std::shared_ptr backBufferCamera; // First, render all non-backbuffer cameras. auto it = cameras.begin(); @@ -74,7 +74,7 @@ void RenderPipeline::renderScene(std::shared_ptr scene) { } else if(cameraTarget == backBuffer) { backBufferCamera = *it; } else { - renderSceneCamera(&(*scene), *it); + renderSceneCamera(scene, *it); } ++it; @@ -82,10 +82,10 @@ void RenderPipeline::renderScene(std::shared_ptr scene) { // Now render the backbuffer camera. if(backBufferCamera == nullptr) return; - renderSceneCamera(&(*scene), backBufferCamera); + renderSceneCamera(scene, backBufferCamera); } -void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) { +void RenderPipeline::renderSceneCamera(std::shared_ptr scene, std::shared_ptr camera) { auto rm = renderManager.lock(); assertNotNull(rm, "RenderPipeline::renderSceneCamera: RenderManager cannot be null"); @@ -114,7 +114,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) { struct IRenderableContext context = { scene, camera, - this + shared_from_this() }; // Get the list of things to render first. diff --git a/src/dawn/display/RenderPipeline.hpp b/src/dawn/display/RenderPipeline.hpp index e7835858..41b922f1 100644 --- a/src/dawn/display/RenderPipeline.hpp +++ b/src/dawn/display/RenderPipeline.hpp @@ -13,7 +13,7 @@ namespace Dawn { class RenderManager; - class RenderPipeline { + class RenderPipeline : public std::enable_shared_from_this { private: int_fast16_t renderId = -1; @@ -54,7 +54,7 @@ namespace Dawn { * @param scene Scene to render. * @param camera Camera within the scene to render. */ - virtual void renderSceneCamera(Scene *scene, Camera *camera); + virtual void renderSceneCamera(std::shared_ptr scene, std::shared_ptr camera); /** * Cleanup a render pipeline that has been initialized. diff --git a/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp b/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp index 4092eeb9..97b982d2 100644 --- a/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp +++ b/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp @@ -17,7 +17,7 @@ namespace Dawn { public SceneItemPrefab { public: - SimpleTexturedMaterial *material; + std::shared_ptr material; static std::vector> prefabAssets(AssetManager *man) { return std::vector>(); diff --git a/src/dawn/scene/Scene.hpp b/src/dawn/scene/Scene.hpp index 5f73a37a..b23a1b99 100644 --- a/src/dawn/scene/Scene.hpp +++ b/src/dawn/scene/Scene.hpp @@ -20,10 +20,10 @@ namespace Dawn { typedef int32_t sceneitemid_t; template - T * _sceneForwardGetComponent(SceneItem *item); + std::shared_ptr _sceneForwardGetComponent(SceneItem *item); template - std::vector _sceneForwardGetComponents(SceneItem *item); + std::vector> _sceneForwardGetComponents(SceneItem *item); class Scene : public StateOwner { private: @@ -95,7 +95,7 @@ namespace Dawn { * @return Pointer to the found component (and by extension the item). */ template - T * findComponent() { + std::shared_ptr findComponent() { auto it = this->itemsNotInitialized.begin(); while(it != this->itemsNotInitialized.end()) { auto component = _sceneForwardGetComponent(it->second); @@ -119,8 +119,8 @@ namespace Dawn { * @return List of matching compnoents. */ template - std::vector findComponents() { - std::vector components; + std::vector> findComponents() { + std::vector> components; auto it = this->itemsNotInitialized.begin(); while(it != this->itemsNotInitialized.end()) { diff --git a/src/dawn/scene/SceneItem.cpp b/src/dawn/scene/SceneItem.cpp index 2f1c1463..bef45a04 100644 --- a/src/dawn/scene/SceneItem.cpp +++ b/src/dawn/scene/SceneItem.cpp @@ -60,18 +60,8 @@ void SceneItem::init() { } void SceneItem::destroy() { - auto it = this->components.begin(); - while(it != this->components.end()) { - (*it)->onDispose(); - ++it; - } + this->components.clear(); } SceneItem::~SceneItem() { - auto it = this->components.begin(); - it = this->components.begin(); - while(it != this->components.end()) { - delete *it; - ++it; - } } \ No newline at end of file diff --git a/src/dawn/scene/SceneItem.hpp b/src/dawn/scene/SceneItem.hpp index c3067661..3e3b723c 100644 --- a/src/dawn/scene/SceneItem.hpp +++ b/src/dawn/scene/SceneItem.hpp @@ -13,7 +13,7 @@ namespace Dawn { class SceneItem : public StateOwner { private: - std::vector components; + std::vector> components; public: Scene *scene; @@ -52,9 +52,8 @@ namespace Dawn { * @return A shared pointer to the newly added component. */ template - T * addComponent() { - auto component = new T(this); - assertNotNull(component, "SceneItem::addComponent: Component could not be created (Memory filled?)"); + std::shared_ptr addComponent() { + auto component = std::make_shared(this); this->components.push_back(component); return component; } @@ -68,10 +67,10 @@ namespace Dawn { * @return A shared pointer to the component, or nullptr if not found. */ template - T * getComponent() { + std::shared_ptr getComponent() { auto it = this->components.begin(); while(it != this->components.end()) { - T *castedAs = dynamic_cast(*it); + std::shared_ptr castedAs = std::dynamic_pointer_cast(*it); if(castedAs != nullptr) return castedAs; ++it; } @@ -88,11 +87,11 @@ namespace Dawn { * @return An array of pointers to the components. */ template - std::vector getComponents() { - std::vector components; + std::vector> getComponents() { + std::vector> components; auto it = this->components.begin(); while(it != this->components.end()) { - T *castedAs = dynamic_cast(*it); + T *castedAs = std::dynamic_pointer_cast(it); if(castedAs != nullptr) components.push_back(castedAs); ++it; } @@ -106,7 +105,7 @@ namespace Dawn { * @return Pointer to the child, or nullptr if not found. */ template - T * findChild() { + std::shared_ptr findChild() { auto it = this->transform.children.begin(); while(it != this->transform.children.end()) { auto child = (*it)->item->getComponent(); @@ -124,9 +123,9 @@ namespace Dawn { * @return Array of pointers to matching children. */ template - std::vector findChildren() { + std::vector> findChildren() { auto it = this->transform.children.begin(); - std::vector children; + std::vector> children; while(it != this->transform.children.end()) { auto child = (*it)->item->getComponent(); if(child != nullptr) children.push_back(child); @@ -143,9 +142,9 @@ namespace Dawn { * @return Array of pointers to matching children components. */ template - std::vector findChildrenDeep() { + std::vector> findChildrenDeep() { std::vector transformsToCheck = this->transform.children; - std::vector itemsFound; + std::vector> itemsFound; while(transformsToCheck.size() > 0) { Transform *tras = *transformsToCheck.begin(); diff --git a/src/dawn/scene/SceneItemComponent.cpp b/src/dawn/scene/SceneItemComponent.cpp index 1ad45ff7..8a6fd777 100644 --- a/src/dawn/scene/SceneItemComponent.cpp +++ b/src/dawn/scene/SceneItemComponent.cpp @@ -21,8 +21,8 @@ void SceneItemComponent::init() { this->hasInitialized = true; } -std::vector SceneItemComponent::getDependencies() { - return std::vector(); +std::vector> SceneItemComponent::getDependencies() { + return {}; } Scene * SceneItemComponent::getScene() { diff --git a/src/dawn/scene/SceneItemComponent.hpp b/src/dawn/scene/SceneItemComponent.hpp index 8f032c61..f93922d1 100644 --- a/src/dawn/scene/SceneItemComponent.hpp +++ b/src/dawn/scene/SceneItemComponent.hpp @@ -39,7 +39,7 @@ namespace Dawn { * * @return Array of dependencies. */ - virtual std::vector getDependencies(); + virtual std::vector> getDependencies(); /** * Shorthand to return the scene that this component's item belongs to. @@ -80,12 +80,12 @@ namespace Dawn { }; template - T * _sceneForwardGetComponent(SceneItem *item) { + std::shared_ptr _sceneForwardGetComponent(SceneItem *item) { return item->getComponent(); } template - T * _sceneForwardGetComponents(SceneItem *item) { + std::shared_ptr _sceneForwardGetComponents(SceneItem *item) { return item->getComponents(); } } \ No newline at end of file diff --git a/src/dawn/scene/components/display/Camera.hpp b/src/dawn/scene/components/display/Camera.hpp index 3d9b3492..8f8994e1 100644 --- a/src/dawn/scene/components/display/Camera.hpp +++ b/src/dawn/scene/components/display/Camera.hpp @@ -22,7 +22,7 @@ namespace Dawn { std::function evtResized; public: - static Camera * create(Scene *scene) { + static std::shared_ptr create(Scene *scene) { auto item = scene->createSceneItem(); auto cam = item->addComponent(); return cam; diff --git a/src/dawn/scene/components/display/CameraTexture.hpp b/src/dawn/scene/components/display/CameraTexture.hpp index b29be618..df26fe37 100644 --- a/src/dawn/scene/components/display/CameraTexture.hpp +++ b/src/dawn/scene/components/display/CameraTexture.hpp @@ -11,7 +11,7 @@ namespace Dawn { class CameraTexture : public SceneItemComponent { public: // @optional - StateProperty camera; + StateProperty> camera; std::shared_ptr renderTarget; CameraTexture(SceneItem *item); diff --git a/src/dawn/scene/components/display/IRenderable.hpp b/src/dawn/scene/components/display/IRenderable.hpp index 91990f9a..2c271748 100644 --- a/src/dawn/scene/components/display/IRenderable.hpp +++ b/src/dawn/scene/components/display/IRenderable.hpp @@ -12,9 +12,9 @@ namespace Dawn { class RenderPipeline; struct IRenderableContext { - Scene *scene; - Camera *camera; - RenderPipeline *renderPipeline; + std::shared_ptr scene; + std::shared_ptr camera; + std::shared_ptr renderPipeline; }; class IRenderable { diff --git a/src/dawn/scene/components/display/PixelPerfectCamera.cpp b/src/dawn/scene/components/display/PixelPerfectCamera.cpp index b3fd31a3..1072019b 100644 --- a/src/dawn/scene/components/display/PixelPerfectCamera.cpp +++ b/src/dawn/scene/components/display/PixelPerfectCamera.cpp @@ -55,7 +55,7 @@ void PixelPerfectCamera::onStart() { }, scale); useEffectWithTeardown([&]{ - if(!camera) { + if(!camera._realValue) { return teardown = [&]{}; } diff --git a/src/dawn/scene/components/display/PixelPerfectCamera.hpp b/src/dawn/scene/components/display/PixelPerfectCamera.hpp index 6ba7ee59..cf850d5c 100644 --- a/src/dawn/scene/components/display/PixelPerfectCamera.hpp +++ b/src/dawn/scene/components/display/PixelPerfectCamera.hpp @@ -18,7 +18,7 @@ namespace Dawn { public: // @optional - StateProperty camera; + StateProperty> camera; // @optional StateProperty scale; diff --git a/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp b/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp index 540d7967..29624b9b 100644 --- a/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp +++ b/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp @@ -13,8 +13,8 @@ SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) : { } -std::vector SimpleRenderTargetQuad::getDependencies() { - return std::vector{ +std::vector> SimpleRenderTargetQuad::getDependencies() { + return { (this->meshHost = this->item->getComponent()) }; } diff --git a/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp b/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp index a7b1809c..e57cf4ea 100644 --- a/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp +++ b/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp @@ -11,7 +11,7 @@ namespace Dawn { class SimpleRenderTargetQuad : public SceneItemComponent { protected: - MeshHost *meshHost = nullptr; + std::shared_ptr meshHost; std::function evtResized; public: @@ -27,7 +27,7 @@ namespace Dawn { */ SimpleRenderTargetQuad(SceneItem *item); - std::vector getDependencies() override; + std::vector> getDependencies() override; void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/display/TiledSprite.cpp b/src/dawn/scene/components/display/TiledSprite.cpp index 4dbf78ed..502d47e5 100644 --- a/src/dawn/scene/components/display/TiledSprite.cpp +++ b/src/dawn/scene/components/display/TiledSprite.cpp @@ -20,14 +20,12 @@ TiledSprite::TiledSprite(SceneItem *item) : } -std::vector TiledSprite::getDependencies() { +std::vector> TiledSprite::getDependencies() { if(this->meshHost == nullptr) { this->meshHost = this->item->getComponent(); } - return { - this->meshHost - }; + return { this->meshHost._realValue }; } void TiledSprite::onStart() { diff --git a/src/dawn/scene/components/display/TiledSprite.hpp b/src/dawn/scene/components/display/TiledSprite.hpp index b8aafb40..6786f7a0 100644 --- a/src/dawn/scene/components/display/TiledSprite.hpp +++ b/src/dawn/scene/components/display/TiledSprite.hpp @@ -22,7 +22,7 @@ namespace Dawn { // @optional StateProperty tileset; // @optional - StateProperty meshHost; + StateProperty> meshHost; // @optional StateProperty tile; // @optional @@ -33,7 +33,7 @@ namespace Dawn { StateProperty size; TiledSprite(SceneItem *item); - std::vector getDependencies(); + std::vector> getDependencies(); void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/display/mesh/MeshRenderer.cpp b/src/dawn/scene/components/display/mesh/MeshRenderer.cpp index 235dd065..e66c03dc 100644 --- a/src/dawn/scene/components/display/mesh/MeshRenderer.cpp +++ b/src/dawn/scene/components/display/mesh/MeshRenderer.cpp @@ -12,8 +12,8 @@ using namespace Dawn; MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) { } -std::vector MeshRenderer::getDependencies() { - return std::vector{ +std::vector> MeshRenderer::getDependencies() { + return { this->meshHost = this->item->getComponent() }; } diff --git a/src/dawn/scene/components/display/mesh/MeshRenderer.hpp b/src/dawn/scene/components/display/mesh/MeshRenderer.hpp index 73437c41..767c8f7c 100644 --- a/src/dawn/scene/components/display/mesh/MeshRenderer.hpp +++ b/src/dawn/scene/components/display/mesh/MeshRenderer.hpp @@ -12,7 +12,7 @@ namespace Dawn { class MeshRenderer : public SceneItemComponent { protected: - MeshHost *meshHost = nullptr; + std::shared_ptr meshHost; public: // @optional @@ -25,7 +25,7 @@ namespace Dawn { */ MeshRenderer(SceneItem *item); - std::vector getDependencies() override; + std::vector> getDependencies() override; void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/CharacterController2D.hpp b/src/dawn/scene/components/physics/2d/CharacterController2D.hpp index 08a4e8f1..7d7da834 100644 --- a/src/dawn/scene/components/physics/2d/CharacterController2D.hpp +++ b/src/dawn/scene/components/physics/2d/CharacterController2D.hpp @@ -9,7 +9,7 @@ namespace Dawn { struct CharacterController2DCollisionEventInfo { - SolidController2D *collider; + std::shared_ptr collider; glm::vec2 normal; float_t entryTime; float_t exitTime; diff --git a/src/dawn/scene/components/physics/2d/SolidController2D.cpp b/src/dawn/scene/components/physics/2d/SolidController2D.cpp index 81592590..4ffbe945 100644 --- a/src/dawn/scene/components/physics/2d/SolidController2D.cpp +++ b/src/dawn/scene/components/physics/2d/SolidController2D.cpp @@ -10,7 +10,7 @@ using namespace Dawn; SolidController2D::SolidController2D(SceneItem *item) : SceneItemComponent(item) { } -std::vector SolidController2D::getDependencies() { +std::vector> SolidController2D::getDependencies() { return { (this->collider = item->getComponent()) }; @@ -18,7 +18,7 @@ std::vector SolidController2D::getDependencies() { bool_t SolidController2D::getCollidingResult( glm::vec2 movement, - Collider2D *movingObject, + std::shared_ptr movingObject, glm::vec2 &normal, float_t &entryTime, float_t &exitTime, @@ -34,13 +34,13 @@ bool_t SolidController2D::getCollidingResult( // Check what the moving object is switch(movingObject->getColliderType()) { case COLLIDER2D_TYPE_BOX: { - auto box1 = dynamic_cast(movingObject); + auto box1 = std::static_pointer_cast(movingObject); assertNotNull(box1, "SolidController2D::getCollidingResult: Moving object is not a BoxCollider"); // Box VS (this)? switch(this->collider->getColliderType()) { case COLLIDER2D_TYPE_BOX: { - auto box2 = dynamic_cast(this->collider); + auto box2 = std::static_pointer_cast(this->collider); assertNotNull(box2, "SolidController2D::getCollidingResult: Collider is not a BoxCollider"); auto otherPos = physics3Dto2D(box2->transform->getWorldPosition()); diff --git a/src/dawn/scene/components/physics/2d/SolidController2D.hpp b/src/dawn/scene/components/physics/2d/SolidController2D.hpp index 68db6896..cccf6e63 100644 --- a/src/dawn/scene/components/physics/2d/SolidController2D.hpp +++ b/src/dawn/scene/components/physics/2d/SolidController2D.hpp @@ -10,10 +10,10 @@ namespace Dawn { class SolidController2D : public SceneItemComponent { public: - Collider2D *collider = nullptr; + std::shared_ptr collider; SolidController2D(SceneItem *item); - std::vector getDependencies() override; + std::vector> getDependencies() override; /** * Gets the result of checking if two collider bodies are intersecting. @@ -31,7 +31,7 @@ namespace Dawn { */ bool_t getCollidingResult( glm::vec2 movement, - Collider2D *movingObject, + std::shared_ptr movingObject, glm::vec2 &normal, float_t &entryTime, float_t &exitTime, diff --git a/src/dawn/scene/components/physics/2d/TriggerController2D.cpp b/src/dawn/scene/components/physics/2d/TriggerController2D.cpp index cb8237c3..d52251c3 100644 --- a/src/dawn/scene/components/physics/2d/TriggerController2D.cpp +++ b/src/dawn/scene/components/physics/2d/TriggerController2D.cpp @@ -11,25 +11,25 @@ TriggerController2D::TriggerController2D(SceneItem *i) : SceneItemComponent(i) { } -std::vector TriggerController2D::getDependencies() { +std::vector> TriggerController2D::getDependencies() { return { (this->collider = this->item->getComponent()) }; } -bool_t TriggerController2D::getCollidingResult(Collider2D* movingObject) { +bool_t TriggerController2D::getCollidingResult(std::shared_ptr movingObject) { assertNotNull(this->collider, "TriggerController2D::getCollidingResult: Collider cannot be null"); assertNotNull(movingObject, "TriggerController2D::getCollidingResult: Moving object cannot be null"); switch(movingObject->getColliderType()) { case COLLIDER2D_TYPE_BOX: { - auto box1 = dynamic_cast(movingObject); + auto box1 = std::static_pointer_cast(movingObject); assertNotNull(box1, "TriggerController2D::getCollidingResult: Moving object is not a BoxCollider"); // Box VS ? switch(collider->getColliderType()) { case COLLIDER2D_TYPE_BOX: { - auto box2 = dynamic_cast(collider); + auto box2 = std::static_pointer_cast(collider); assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider"); return boxIsBoxColliding( physics3Dto2D(box1->transform->getWorldPosition()), box1->min, box1->max, diff --git a/src/dawn/scene/components/physics/2d/TriggerController2D.hpp b/src/dawn/scene/components/physics/2d/TriggerController2D.hpp index 3cbefcb1..8b7df395 100644 --- a/src/dawn/scene/components/physics/2d/TriggerController2D.hpp +++ b/src/dawn/scene/components/physics/2d/TriggerController2D.hpp @@ -12,16 +12,16 @@ namespace Dawn { class TriggerController2D : public SceneItemComponent { public: - Collider2D *collider = nullptr; + std::shared_ptr collider; StateEvent eventTriggerEnter; TriggerController2D(SceneItem *i); - std::vector getDependencies() override; + std::vector> getDependencies() override; /** * Returns whether or not the given moving object is colliding with this * trigger collider. */ - bool_t getCollidingResult(Collider2D* movingObject); + bool_t getCollidingResult(std::shared_ptr movingObject); }; } \ No newline at end of file diff --git a/src/dawn/scene/components/ui/UICanvas.cpp b/src/dawn/scene/components/ui/UICanvas.cpp index 30a0bdfa..dc2523ba 100644 --- a/src/dawn/scene/components/ui/UICanvas.cpp +++ b/src/dawn/scene/components/ui/UICanvas.cpp @@ -9,7 +9,7 @@ using namespace Dawn; -UICanvas * UICanvas::create(Scene *scene) { +std::shared_ptr UICanvas::create(Scene *scene) { auto item = scene->createSceneItem(); return item->addComponent(); } diff --git a/src/dawn/scene/components/ui/UICanvas.hpp b/src/dawn/scene/components/ui/UICanvas.hpp index 6739becb..d80d85ef 100644 --- a/src/dawn/scene/components/ui/UICanvas.hpp +++ b/src/dawn/scene/components/ui/UICanvas.hpp @@ -83,10 +83,10 @@ namespace Dawn { * @param scene Scene to create the UI Canvas for. * @return Created UI Canvas. */ - static UICanvas * create(Scene *scene); + static std::shared_ptr create(Scene *scene); //======================================================================// - StateProperty camera; + StateProperty> camera; enum UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE; /** diff --git a/src/dawn/scene/components/ui/UIComponent.cpp b/src/dawn/scene/components/ui/UIComponent.cpp index b22411a8..733c7b78 100644 --- a/src/dawn/scene/components/ui/UIComponent.cpp +++ b/src/dawn/scene/components/ui/UIComponent.cpp @@ -21,7 +21,7 @@ UIComponent::UIComponent(SceneItem *item) : } -UIComponentDimensional * UIComponent::getParentDimensional() { +std::shared_ptr UIComponent::getParentDimensional() { auto parent = this->transform->getParent(); if(parent == nullptr) return nullptr; auto dimensional = parent->item->getComponent(); @@ -238,7 +238,7 @@ void UIComponent::calculateDimensions( } } -UICanvas * UIComponent::getCanvas() { +std::shared_ptr UIComponent::getCanvas() { // TODO: Cache this on first hit. auto parent = this->transform->getParent(); while(parent != nullptr) { diff --git a/src/dawn/scene/components/ui/UIComponent.hpp b/src/dawn/scene/components/ui/UIComponent.hpp index 37c87c6f..7ef00847 100644 --- a/src/dawn/scene/components/ui/UIComponent.hpp +++ b/src/dawn/scene/components/ui/UIComponent.hpp @@ -38,7 +38,7 @@ namespace Dawn { * * @return Pointer to the parent dimensional. */ - UIComponentDimensional * getParentDimensional(); + std::shared_ptr getParentDimensional(); /** * Internal method to update the alignment of this item. @@ -130,7 +130,7 @@ namespace Dawn { * * @return Pointer to the UI Canvas this component is a child of. */ - virtual UICanvas * getCanvas(); + virtual std::shared_ptr getCanvas(); float_t getWidth() override; float_t getHeight() override; diff --git a/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp b/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp index 1d9bc105..414d4df7 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp @@ -14,7 +14,7 @@ UISimpleMenu::UISimpleMenu(SceneItem *item) : } -std::vector UISimpleMenu::getDependencies() { +std::vector> UISimpleMenu::getDependencies() { return { (this->menu = this->item->getComponent()), (this->canvas == nullptr ? (this->canvas = this->item->getComponent()) : nullptr) diff --git a/src/dawn/scene/components/ui/menu/UISimpleMenu.hpp b/src/dawn/scene/components/ui/menu/UISimpleMenu.hpp index db765561..118e476c 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenu.hpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenu.hpp @@ -10,14 +10,14 @@ namespace Dawn { class UISimpleMenu : public SceneItemComponent { protected: - UIMenuController *menu = nullptr; - UICanvas *canvas = nullptr; - UISimpleMenuItem *currentlySelected = nullptr; - std::vector menuItems; + std::shared_ptr menu; + std::shared_ptr canvas; + std::shared_ptr currentlySelected; + std::vector> menuItems; public: UISimpleMenu(SceneItem *item); - std::vector getDependencies() override; + std::vector> getDependencies() override; void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/ui/menu/UISimpleMenuItem.cpp b/src/dawn/scene/components/ui/menu/UISimpleMenuItem.cpp index 067b1980..3266c56d 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenuItem.cpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenuItem.cpp @@ -11,7 +11,7 @@ UISimpleMenuItem::UISimpleMenuItem(SceneItem *item) : SceneItemComponent(item) { } -UIComponent * UISimpleMenuItem::getComponentForHighlighting() { +std::shared_ptr UISimpleMenuItem::getComponentForHighlighting() { if(uiComponent == nullptr) uiComponent = item->getComponent(); return uiComponent; } \ No newline at end of file diff --git a/src/dawn/scene/components/ui/menu/UISimpleMenuItem.hpp b/src/dawn/scene/components/ui/menu/UISimpleMenuItem.hpp index fc73c527..cff2f510 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenuItem.hpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenuItem.hpp @@ -15,7 +15,7 @@ namespace Dawn { // May make these into either state events or make a new event. int32_t menuX = 0; int32_t menuY = 0; - UIComponent *uiComponent = nullptr; + std::shared_ptr uiComponent = nullptr; UISimpleMenuItem(SceneItem *item); @@ -25,6 +25,6 @@ namespace Dawn { * * @return UI Component to use for highlighting / hovering. */ - virtual UIComponent * getComponentForHighlighting(); + virtual std::shared_ptr getComponentForHighlighting(); }; } \ No newline at end of file diff --git a/src/dawnhelloworld/scenes/HelloWorldScene.hpp b/src/dawnhelloworld/scenes/HelloWorldScene.hpp index 1f2f68f1..5d600e0b 100644 --- a/src/dawnhelloworld/scenes/HelloWorldScene.hpp +++ b/src/dawnhelloworld/scenes/HelloWorldScene.hpp @@ -11,9 +11,9 @@ namespace Dawn { class HelloWorldScene : public Scene { protected: - Camera *camera; + std::shared_ptr camera; SimpleSpinningCubePrefab *cube; - UICanvas *canvas; + std::shared_ptr canvas; void stage() override { camera = Camera::create(this);