diff --git a/src/dawn/scene/components/display/AnimationController.cpp b/archive/AnimationController.cpp similarity index 100% rename from src/dawn/scene/components/display/AnimationController.cpp rename to archive/AnimationController.cpp diff --git a/src/dawn/scene/components/display/AnimationController.hpp b/archive/AnimationController.hpp similarity index 100% rename from src/dawn/scene/components/display/AnimationController.hpp rename to archive/AnimationController.hpp diff --git a/src/dawn/display/animation/Animation.cpp b/archive/animation/Animation.cpp similarity index 100% rename from src/dawn/display/animation/Animation.cpp rename to archive/animation/Animation.cpp diff --git a/src/dawn/display/animation/Animation.hpp b/archive/animation/Animation.hpp similarity index 100% rename from src/dawn/display/animation/Animation.hpp rename to archive/animation/Animation.hpp diff --git a/src/dawn/display/animation/CMakeLists.txt b/archive/animation/CMakeLists.txt similarity index 100% rename from src/dawn/display/animation/CMakeLists.txt rename to archive/animation/CMakeLists.txt diff --git a/src/dawn/display/animation/SimpleAnimation.hpp b/archive/animation/SimpleAnimation.hpp similarity index 92% rename from src/dawn/display/animation/SimpleAnimation.hpp rename to archive/animation/SimpleAnimation.hpp index fe652400..26089e31 100644 --- a/src/dawn/display/animation/SimpleAnimation.hpp +++ b/archive/animation/SimpleAnimation.hpp @@ -40,7 +40,7 @@ namespace Dawn { } public: - easefunction_t *easing = &easeLinear; + std::function easing = easeLinear; T *modifies; std::vector> keyframes; @@ -50,7 +50,7 @@ namespace Dawn { * @param modifies Pointer to the value that will be modified. */ SimpleAnimation(T *modifies) { - assertNotNull(modifies, "SimpleAnimation::SimpleAnimation: Modifies cannot be null"); + assertNotNull(modifies, "Modifies cannot be null"); this->modifies = modifies; } @@ -61,7 +61,7 @@ namespace Dawn { * @param value Value at this given time. */ void addKeyframe(float_t time, T value) { - assertTrue(time >= 0, "SimpleAnimation::addKeyframe: Time must be >= 0"); + assertTrue(time >= 0, "Time must be >= 0"); struct SimpleKeyframe keyframe; keyframe.time = time; diff --git a/src/dawn/display/animation/SimpleCallbackAnimation.hpp b/archive/animation/SimpleCallbackAnimation.hpp similarity index 100% rename from src/dawn/display/animation/SimpleCallbackAnimation.hpp rename to archive/animation/SimpleCallbackAnimation.hpp diff --git a/src/dawn/display/animation/SimplerCallbackAnimation.hpp b/archive/animation/SimplerCallbackAnimation.hpp similarity index 100% rename from src/dawn/display/animation/SimplerCallbackAnimation.hpp rename to archive/animation/SimplerCallbackAnimation.hpp diff --git a/src/dawn/display/animation/TiledSpriteAnimation.cpp b/archive/animation/TiledSpriteAnimation.cpp similarity index 100% rename from src/dawn/display/animation/TiledSpriteAnimation.cpp rename to archive/animation/TiledSpriteAnimation.cpp diff --git a/src/dawn/display/animation/TiledSpriteAnimation.hpp b/archive/animation/TiledSpriteAnimation.hpp similarity index 100% rename from src/dawn/display/animation/TiledSpriteAnimation.hpp rename to archive/animation/TiledSpriteAnimation.hpp diff --git a/src/dawn/display/animation/easing.cpp b/archive/animation/easing.cpp similarity index 100% rename from src/dawn/display/animation/easing.cpp rename to archive/animation/easing.cpp diff --git a/src/dawn/display/animation/easing.hpp b/archive/animation/easing.hpp similarity index 100% rename from src/dawn/display/animation/easing.hpp rename to archive/animation/easing.hpp diff --git a/src/dawn/display/CMakeLists.txt b/src/dawn/display/CMakeLists.txt index 32c99d2a..0e535246 100644 --- a/src/dawn/display/CMakeLists.txt +++ b/src/dawn/display/CMakeLists.txt @@ -12,7 +12,6 @@ target_sources(${DAWN_TARGET_NAME} ) # Subdirs -add_subdirectory(animation) add_subdirectory(font) add_subdirectory(mesh) add_subdirectory(shader) \ No newline at end of file diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index e6b2f622..fc56ca74 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -105,7 +105,7 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr scene, std::shared // Update shader parameter buffers with current knowledge struct RenderPipelineShaderBufferData shaderBufferData; shaderBufferData.projection = camera->getProjection(); - shaderBufferData.view = camera->item->getWorldTransform(); + shaderBufferData.view = camera->item.lock()->getWorldTransform(); shaderBuffer.buffer(&shaderBufferData); // Prepare a render context. This is just a nice way of letting renderables @@ -128,30 +128,6 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr scene, std::shared ++itRenderables; } - // Debug Lines - #if DAWN_DEBUG_BUILD - Mesh lineMesh; - if(scene->debugLines.size() > 0) { - int32_t lineIndex = 0; - lineMesh.createBuffers( - scene->debugLines.size() * SCENE_DEBUG_LINE_VERTICE_COUNT, - scene->debugLines.size() * SCENE_DEBUG_LINE_INDICE_COUNT - ); - auto itDebugLine = scene->debugLines.begin(); - while(itDebugLine != scene->debugLines.end()) { - auto item = itDebugLine->createShaderItem( - &lineMesh, - &lineIndex, - camera, - renderManager->simpleTexturedShader - ); - shaderPassItems.push_back(item); - itDebugLine = scene->debugLines.erase(itDebugLine); - lineIndex++; - } - } - #endif - // Inject index into each item itPassItem = shaderPassItems.begin(); while(itPassItem != shaderPassItems.end()) { diff --git a/src/dawn/games/poker/PokerGame.cpp b/src/dawn/games/poker/PokerGame.cpp index 522891b1..dace9a5f 100644 --- a/src/dawn/games/poker/PokerGame.cpp +++ b/src/dawn/games/poker/PokerGame.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -PokerGame::PokerGame(SceneItem *item) : SceneItemComponent(item) { +PokerGame::PokerGame(std::weak_ptr item) : SceneItemComponent(item) { } diff --git a/src/dawn/games/poker/PokerGame.hpp b/src/dawn/games/poker/PokerGame.hpp index 9311cba2..996b6650 100644 --- a/src/dawn/games/poker/PokerGame.hpp +++ b/src/dawn/games/poker/PokerGame.hpp @@ -33,7 +33,7 @@ namespace Dawn { std::vector pots; uint8_t betterIndex; - PokerGame(SceneItem *item); + PokerGame(std::weak_ptr item); void onStart() override; diff --git a/src/dawn/games/poker/PokerPlayer.cpp b/src/dawn/games/poker/PokerPlayer.cpp index 46ef133c..1136a2d9 100644 --- a/src/dawn/games/poker/PokerPlayer.cpp +++ b/src/dawn/games/poker/PokerPlayer.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -PokerPlayer::PokerPlayer(SceneItem *item) : SceneItemComponent(item) { +PokerPlayer::PokerPlayer(std::weak_ptr item) : SceneItemComponent(item) { } diff --git a/src/dawn/games/poker/PokerPlayer.hpp b/src/dawn/games/poker/PokerPlayer.hpp index b29e7c4e..9f736d5a 100644 --- a/src/dawn/games/poker/PokerPlayer.hpp +++ b/src/dawn/games/poker/PokerPlayer.hpp @@ -43,7 +43,7 @@ namespace Dawn { * * @param item Item that this poker player belongs to. */ - PokerPlayer(SceneItem *item); + PokerPlayer(std::weak_ptr item); /** Override for scene item component event for init */ void onStart() override; diff --git a/src/dawn/games/vn/components/VNManager.cpp b/src/dawn/games/vn/components/VNManager.cpp index 569bc1aa..c4b3620e 100644 --- a/src/dawn/games/vn/components/VNManager.cpp +++ b/src/dawn/games/vn/components/VNManager.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -VNManager::VNManager(SceneItem *item) : +VNManager::VNManager(std::weak_ptr item) : SceneItemComponent(item), defaultFont("{{ text }}") { diff --git a/src/dawn/games/vn/components/VNManager.hpp b/src/dawn/games/vn/components/VNManager.hpp index 2b5e1009..d55244bf 100644 --- a/src/dawn/games/vn/components/VNManager.hpp +++ b/src/dawn/games/vn/components/VNManager.hpp @@ -31,7 +31,7 @@ namespace Dawn { * * @param item Item that the VN manager belongs to. */ - VNManager(SceneItem *item); + VNManager(std::weak_ptr item); /** * Creats an event for you to decide how to queue. diff --git a/src/dawn/games/vn/components/VNTextboxScroller.cpp b/src/dawn/games/vn/components/VNTextboxScroller.cpp index 5b402524..1f9f9274 100644 --- a/src/dawn/games/vn/components/VNTextboxScroller.cpp +++ b/src/dawn/games/vn/components/VNTextboxScroller.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -VNTextboxScroller::VNTextboxScroller(SceneItem *item) : +VNTextboxScroller::VNTextboxScroller(std::weak_ptr item) : SceneItemComponent(item), label(nullptr), visibleLines(4) diff --git a/src/dawn/games/vn/components/VNTextboxScroller.hpp b/src/dawn/games/vn/components/VNTextboxScroller.hpp index e1707110..407cd034 100644 --- a/src/dawn/games/vn/components/VNTextboxScroller.hpp +++ b/src/dawn/games/vn/components/VNTextboxScroller.hpp @@ -28,7 +28,7 @@ namespace Dawn { size_t lineCurrent = 0; float_t timeCharacter = 0.0f; - VNTextboxScroller(SceneItem *item); + VNTextboxScroller(std::weak_ptr item); virtual void onStart() override; /** diff --git a/src/dawn/games/vn/events/VNPositionEvent.hpp b/src/dawn/games/vn/events/VNPositionEvent.hpp index 076b12b2..d129e49c 100644 --- a/src/dawn/games/vn/events/VNPositionEvent.hpp +++ b/src/dawn/games/vn/events/VNPositionEvent.hpp @@ -11,7 +11,7 @@ namespace Dawn { class VNPositionEvent : public VNAnimateEvent { public: - SceneItem *item = nullptr; + std::weak_ptr item = nullptr; VNPositionEvent() { from = glm::vec3( diff --git a/src/dawn/prefab/Prefab.hpp b/src/dawn/prefab/Prefab.hpp index d442fcf0..e4d68b68 100644 --- a/src/dawn/prefab/Prefab.hpp +++ b/src/dawn/prefab/Prefab.hpp @@ -30,7 +30,7 @@ namespace Dawn { * @param context Custom context that this prefab needs to initialize. * @return The instance of the created prefab. */ - static O * create(J *context) { + static std::shared_ptr create(J *context) { assertNotNull(context, "Prefab::create: Context cannot be null"); return P::prefabCreate(context); } diff --git a/src/dawn/prefab/SceneItemPrefab.hpp b/src/dawn/prefab/SceneItemPrefab.hpp index 4ff9705d..2b50bd70 100644 --- a/src/dawn/prefab/SceneItemPrefab.hpp +++ b/src/dawn/prefab/SceneItemPrefab.hpp @@ -20,8 +20,8 @@ namespace Dawn { * @param scene Scene that this prefab is going to be added to. * @return The created prefab instance. */ - static O * prefabCreate(Scene *scene) { - O *item = scene->createSceneItemOfType(); + static std::shared_ptr prefabCreate(Scene *scene) { + std::shared_ptr item = scene->createSceneItemOfType(); auto game = scene->game.lock(); assertNotNull(game, "Game cannot be null!"); item->prefabInit(&game->assetManager); diff --git a/src/dawn/scene/Scene.cpp b/src/dawn/scene/Scene.cpp index 4175da4d..9e70a493 100644 --- a/src/dawn/scene/Scene.cpp +++ b/src/dawn/scene/Scene.cpp @@ -34,30 +34,17 @@ void Scene::update() { if(!game->timeManager.isPaused) this->eventSceneUnpausedUpdate.invoke(game->timeManager.delta); } -SceneItem * Scene::createSceneItem() { +std::shared_ptr Scene::createSceneItem() { return this->createSceneItemOfType(); } Scene::~Scene() { delete this->physics; - // Early cleanup without disposing. + // Invoke cleanup. auto it = this->items.begin(); while(it != this->items.end()) { it->second->destroy(); ++it; } - - // Now dispose everything. - it = this->items.begin(); - while(it != this->items.end()) { - delete it->second; - ++it; - } - - auto it2 = this->itemsNotInitialized.begin(); - while(it2 != this->itemsNotInitialized.end()) { - delete it2->second; - ++it2; - } } \ No newline at end of file diff --git a/src/dawn/scene/Scene.hpp b/src/dawn/scene/Scene.hpp index 58c7dfd8..db2d9d7a 100644 --- a/src/dawn/scene/Scene.hpp +++ b/src/dawn/scene/Scene.hpp @@ -20,16 +20,18 @@ namespace Dawn { typedef int32_t sceneitemid_t; template - std::shared_ptr _sceneForwardGetComponent(SceneItem *item); + std::shared_ptr _sceneForwardGetComponent(std::shared_ptr item); template - std::vector> _sceneForwardGetComponents(SceneItem *item); + std::vector> _sceneForwardGetComponents( + std::shared_ptr item + ); class Scene : public StateOwner, public std::enable_shared_from_this { private: sceneitemid_t nextId; - std::map items; - std::map itemsNotInitialized; + std::map> items; + std::map> itemsNotInitialized; public: std::weak_ptr game; @@ -56,10 +58,10 @@ namespace Dawn { * @return A shared pointer to the created SceneItem. */ template - T * createSceneItemOfType() { + std::shared_ptr createSceneItemOfType() { sceneitemid_t id = this->nextId++; - auto item = new T(weak_from_this(), id); - assertNotNull(item, "Scene::createSceneItemOfType: Failed to create SceneItem (Memory Filled?)"); + auto item = std::make_shared(weak_from_this(), id); + assertNotNull(item, "Failed to create SceneItem (Memory Filled?)"); this->itemsNotInitialized[id] = item; return item; } @@ -69,7 +71,7 @@ namespace Dawn { * * @return A shared pointer to the created SceneItem. */ - SceneItem * createSceneItem(); + std::shared_ptr createSceneItem(); /** * Returns the required assets for this scene. Assets required are meant diff --git a/src/dawn/scene/SceneItem.hpp b/src/dawn/scene/SceneItem.hpp index 7b1987d4..0a89d8a8 100644 --- a/src/dawn/scene/SceneItem.hpp +++ b/src/dawn/scene/SceneItem.hpp @@ -79,7 +79,7 @@ namespace Dawn { */ template std::shared_ptr addComponent() { - auto component = std::make_shared(this); + auto component = std::make_shared(weak_from_this()); this->components.push_back(component); return component; } diff --git a/src/dawn/scene/SceneItemComponent.cpp b/src/dawn/scene/SceneItemComponent.cpp index 1c0c14ae..2436210e 100644 --- a/src/dawn/scene/SceneItemComponent.cpp +++ b/src/dawn/scene/SceneItemComponent.cpp @@ -10,8 +10,7 @@ using namespace Dawn; -SceneItemComponent::SceneItemComponent(SceneItem *item) { - assertNotNull(item, "SceneItemComponent::SceneItemComponent: Item cannot be null"); +SceneItemComponent::SceneItemComponent(std::weak_ptr item) { this->item = item; } @@ -25,7 +24,7 @@ std::vector> SceneItemComponent::getDependen } std::shared_ptr SceneItemComponent::getScene() { - auto scene = this->item->scene.lock(); + auto scene = this->item.lock()->scene.lock(); assertNotNull(scene, "Scene cannot be null!"); return scene; } diff --git a/src/dawn/scene/SceneItemComponent.hpp b/src/dawn/scene/SceneItemComponent.hpp index 87793e5e..92097744 100644 --- a/src/dawn/scene/SceneItemComponent.hpp +++ b/src/dawn/scene/SceneItemComponent.hpp @@ -13,7 +13,7 @@ namespace Dawn { class SceneItemComponent : public StateOwner { public: - SceneItem *item; + std::weak_ptr item; bool_t hasInitialized = false; /** @@ -23,7 +23,7 @@ namespace Dawn { * * @param item Scene Item thsi component belongs to. */ - SceneItemComponent(SceneItem *item); + SceneItemComponent(std::weak_ptr item); /** * Requested on the first frame that the parent scene item has become @@ -78,12 +78,16 @@ namespace Dawn { }; template - std::shared_ptr _sceneForwardGetComponent(SceneItem *item) { + std::shared_ptr _sceneForwardGetComponent( + std::shared_ptr item + ) { return item->getComponent(); } template - std::shared_ptr _sceneForwardGetComponents(SceneItem *item) { + std::shared_ptr _sceneForwardGetComponents( + std::shared_ptr item + ) { return item->getComponents(); } } \ No newline at end of file diff --git a/src/dawn/scene/components/debug/FPSLabelComponent.cpp b/src/dawn/scene/components/debug/FPSLabelComponent.cpp index 3d3aa162..3de95865 100644 --- a/src/dawn/scene/components/debug/FPSLabelComponent.cpp +++ b/src/dawn/scene/components/debug/FPSLabelComponent.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -FPSLabelComponent::FPSLabelComponent(SceneItem *item) : +FPSLabelComponent::FPSLabelComponent(std::weak_ptr item) : SceneItemComponent(item) { diff --git a/src/dawn/scene/components/debug/FPSLabelComponent.hpp b/src/dawn/scene/components/debug/FPSLabelComponent.hpp index 2a6c7f5f..2498982a 100644 --- a/src/dawn/scene/components/debug/FPSLabelComponent.hpp +++ b/src/dawn/scene/components/debug/FPSLabelComponent.hpp @@ -12,7 +12,7 @@ namespace Dawn { /* @optional */ UILabel *label = nullptr; - FPSLabelComponent(SceneItem *item); + FPSLabelComponent(std::weak_ptr item); void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/display/CMakeLists.txt b/src/dawn/scene/components/display/CMakeLists.txt index 070a64c1..1c1803f6 100644 --- a/src/dawn/scene/components/display/CMakeLists.txt +++ b/src/dawn/scene/components/display/CMakeLists.txt @@ -6,7 +6,6 @@ # Sources target_sources(${DAWN_TARGET_NAME} PRIVATE - AnimationController.cpp Camera.cpp Material.cpp PixelPerfectCamera.cpp diff --git a/src/dawn/scene/components/display/Camera.cpp b/src/dawn/scene/components/display/Camera.cpp index 0bc143c3..a669eaa9 100644 --- a/src/dawn/scene/components/display/Camera.cpp +++ b/src/dawn/scene/components/display/Camera.cpp @@ -8,9 +8,9 @@ using namespace Dawn; -Camera::Camera(SceneItem *item) : +Camera::Camera(std::weak_ptr item) : SceneItemComponent(item), - renderTarget(item->scene.lock()->game.lock()->renderManager->getBackBuffer()), + renderTarget(this->getGame()->renderManager->getBackBuffer()), fov(0.785398f),// 45 degrees, type(CAMERA_TYPE_PERSPECTIVE), orthoLeft(-0.5f), @@ -66,7 +66,7 @@ glm::vec3 Camera::getRayDirectionFromScreenSpace(glm::vec2 screenSpace) { glm::vec4 eyeCoords = inverseProjectionMatrix * clipCoords; eyeCoords = glm::vec4(eyeCoords.x, eyeCoords.y, -1.0f, 0.0f); - glm::mat4 inverseViewMatrix = glm::inverse(item->getWorldTransform()); + glm::mat4 inverseViewMatrix = glm::inverse(item.lock()->getWorldTransform()); glm::vec4 t = inverseViewMatrix * eyeCoords; return glm::normalize(glm::vec3(t.x, t.y, t.z)); diff --git a/src/dawn/scene/components/display/Camera.hpp b/src/dawn/scene/components/display/Camera.hpp index bee407ca..a2c18697 100644 --- a/src/dawn/scene/components/display/Camera.hpp +++ b/src/dawn/scene/components/display/Camera.hpp @@ -55,7 +55,7 @@ namespace Dawn { * * @param item SceneItem that this component belongs to. */ - Camera(SceneItem *item); + Camera(std::weak_ptr item); /** * Returns the current projection matrix. diff --git a/src/dawn/scene/components/display/CameraTexture.cpp b/src/dawn/scene/components/display/CameraTexture.cpp index f6093804..13a154c5 100644 --- a/src/dawn/scene/components/display/CameraTexture.cpp +++ b/src/dawn/scene/components/display/CameraTexture.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -CameraTexture::CameraTexture(SceneItem *item) : +CameraTexture::CameraTexture(std::weak_ptr item) : SceneItemComponent(item), camera(nullptr) { @@ -15,7 +15,7 @@ CameraTexture::CameraTexture(SceneItem *item) : } void CameraTexture::onStart() { - if(this->camera == nullptr) this->camera = item->getComponent(); + if(this->camera == nullptr) this->camera = item.lock()->getComponent(); useEffect([&]{ if(this->camera == nullptr) return; diff --git a/src/dawn/scene/components/display/CameraTexture.hpp b/src/dawn/scene/components/display/CameraTexture.hpp index df26fe37..168c0161 100644 --- a/src/dawn/scene/components/display/CameraTexture.hpp +++ b/src/dawn/scene/components/display/CameraTexture.hpp @@ -14,7 +14,7 @@ namespace Dawn { StateProperty> camera; std::shared_ptr renderTarget; - CameraTexture(SceneItem *item); + CameraTexture(std::weak_ptr item); void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/display/Material.cpp b/src/dawn/scene/components/display/Material.cpp index 5d3e33c5..784fe9f2 100644 --- a/src/dawn/scene/components/display/Material.cpp +++ b/src/dawn/scene/components/display/Material.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -Material::Material(SceneItem *item) : SceneItemComponent(item) { +Material::Material(std::weak_ptr item) : SceneItemComponent(item) { } ShaderManager & Material::getShaderManager() { diff --git a/src/dawn/scene/components/display/Material.hpp b/src/dawn/scene/components/display/Material.hpp index 8fdaf8fa..e5a8c02b 100644 --- a/src/dawn/scene/components/display/Material.hpp +++ b/src/dawn/scene/components/display/Material.hpp @@ -16,7 +16,7 @@ namespace Dawn { * * @param item Scene Item this component belongs to. */ - Material(SceneItem *item); + Material(std::weak_ptr item); /** * Returns the shader manager for the game. diff --git a/src/dawn/scene/components/display/PixelPerfectCamera.cpp b/src/dawn/scene/components/display/PixelPerfectCamera.cpp index c4341f07..1d6c09ad 100644 --- a/src/dawn/scene/components/display/PixelPerfectCamera.cpp +++ b/src/dawn/scene/components/display/PixelPerfectCamera.cpp @@ -8,8 +8,8 @@ using namespace Dawn; -PixelPerfectCamera::PixelPerfectCamera(SceneItem *i) : - SceneItemComponent(i), +PixelPerfectCamera::PixelPerfectCamera(std::weak_ptr item) : + SceneItemComponent(item), scale(1.0f), camera(nullptr) { @@ -33,7 +33,7 @@ void PixelPerfectCamera::updateDimensions() { break; case CAMERA_TYPE_PERSPECTIVE: - item->lookAtPixelPerfect( + item.lock()->lookAtPixelPerfect( glm::vec3(0, 0, 0), glm::vec3(0, 0, 0), target->getHeight() / this->scale, @@ -48,7 +48,7 @@ void PixelPerfectCamera::updateDimensions() { } void PixelPerfectCamera::onStart() { - if(camera == nullptr) camera = item->getComponent(); + if(camera == nullptr) camera = item.lock()->getComponent(); useEffect([&]{ this->updateDimensions(); diff --git a/src/dawn/scene/components/display/PixelPerfectCamera.hpp b/src/dawn/scene/components/display/PixelPerfectCamera.hpp index cf850d5c..0b95f55f 100644 --- a/src/dawn/scene/components/display/PixelPerfectCamera.hpp +++ b/src/dawn/scene/components/display/PixelPerfectCamera.hpp @@ -28,7 +28,7 @@ namespace Dawn { * * @param item Item that this component belongs to. */ - PixelPerfectCamera(SceneItem *item); + PixelPerfectCamera(std::weak_ptr item); void onStart() override; }; diff --git a/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp b/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp index 45a6520d..43ad71c7 100644 --- a/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp +++ b/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) : +SimpleRenderTargetQuad::SimpleRenderTargetQuad(std::weak_ptr i) : SceneItemComponent(i), renderTarget(nullptr) { @@ -15,7 +15,7 @@ SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) : std::vector> SimpleRenderTargetQuad::getDependencies() { return { - (this->meshHost = this->item->getComponent()) + (this->meshHost = this->item.lock()->getComponent()) }; } diff --git a/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp b/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp index e57cf4ea..1e1ee6a7 100644 --- a/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp +++ b/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp @@ -25,7 +25,7 @@ namespace Dawn { * * @param item Item that this component is attached to. */ - SimpleRenderTargetQuad(SceneItem *item); + SimpleRenderTargetQuad(std::weak_ptr item); std::vector> getDependencies() override; void onStart() override; diff --git a/src/dawn/scene/components/display/TiledSprite.cpp b/src/dawn/scene/components/display/TiledSprite.cpp index 502d47e5..ab34c859 100644 --- a/src/dawn/scene/components/display/TiledSprite.cpp +++ b/src/dawn/scene/components/display/TiledSprite.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -TiledSprite::TiledSprite(SceneItem *item) : +TiledSprite::TiledSprite(std::weak_ptr item) : SceneItemComponent(item), tile(-1), tileset(nullptr), @@ -22,7 +22,7 @@ TiledSprite::TiledSprite(SceneItem *item) : std::vector> TiledSprite::getDependencies() { if(this->meshHost == nullptr) { - this->meshHost = this->item->getComponent(); + this->meshHost = item.lock()->getComponent(); } return { this->meshHost._realValue }; diff --git a/src/dawn/scene/components/display/TiledSprite.hpp b/src/dawn/scene/components/display/TiledSprite.hpp index 6786f7a0..db77b82d 100644 --- a/src/dawn/scene/components/display/TiledSprite.hpp +++ b/src/dawn/scene/components/display/TiledSprite.hpp @@ -32,7 +32,7 @@ namespace Dawn { // @optional StateProperty size; - TiledSprite(SceneItem *item); + TiledSprite(std::weak_ptr item); std::vector> getDependencies(); void onStart() override; }; diff --git a/src/dawn/scene/components/display/mesh/CapsuleMeshHost.cpp b/src/dawn/scene/components/display/mesh/CapsuleMeshHost.cpp index 252b16dd..407c7ff7 100644 --- a/src/dawn/scene/components/display/mesh/CapsuleMeshHost.cpp +++ b/src/dawn/scene/components/display/mesh/CapsuleMeshHost.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -CapsuleMeshHost::CapsuleMeshHost(SceneItem *item) : +CapsuleMeshHost::CapsuleMeshHost(std::weak_ptr item) : MeshHost(item), radius(0.5f), height(1.0f) diff --git a/src/dawn/scene/components/display/mesh/CapsuleMeshHost.hpp b/src/dawn/scene/components/display/mesh/CapsuleMeshHost.hpp index 07c4f88a..2b0d7b8f 100644 --- a/src/dawn/scene/components/display/mesh/CapsuleMeshHost.hpp +++ b/src/dawn/scene/components/display/mesh/CapsuleMeshHost.hpp @@ -15,7 +15,7 @@ namespace Dawn { // @optional StateProperty height; - CapsuleMeshHost(SceneItem *item); + CapsuleMeshHost(std::weak_ptr item); void onStart() override; }; diff --git a/src/dawn/scene/components/display/mesh/CubeMeshHost.cpp b/src/dawn/scene/components/display/mesh/CubeMeshHost.cpp index d55a91b9..72d039fe 100644 --- a/src/dawn/scene/components/display/mesh/CubeMeshHost.cpp +++ b/src/dawn/scene/components/display/mesh/CubeMeshHost.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -CubeMeshHost::CubeMeshHost(SceneItem *item) : +CubeMeshHost::CubeMeshHost(std::weak_ptr item) : MeshHost(item), size(glm::vec3(1,1,1)) { diff --git a/src/dawn/scene/components/display/mesh/CubeMeshHost.hpp b/src/dawn/scene/components/display/mesh/CubeMeshHost.hpp index b15266df..2a535a5d 100644 --- a/src/dawn/scene/components/display/mesh/CubeMeshHost.hpp +++ b/src/dawn/scene/components/display/mesh/CubeMeshHost.hpp @@ -13,7 +13,7 @@ namespace Dawn { // @optional StateProperty size; - CubeMeshHost(SceneItem *item); + CubeMeshHost(std::weak_ptr item); void onStart() override; }; diff --git a/src/dawn/scene/components/display/mesh/MeshHost.cpp b/src/dawn/scene/components/display/mesh/MeshHost.cpp index fb6fc699..88341946 100644 --- a/src/dawn/scene/components/display/mesh/MeshHost.cpp +++ b/src/dawn/scene/components/display/mesh/MeshHost.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -MeshHost::MeshHost(SceneItem *item) : +MeshHost::MeshHost(std::weak_ptr item) : mesh(), SceneItemComponent(item) { diff --git a/src/dawn/scene/components/display/mesh/MeshHost.hpp b/src/dawn/scene/components/display/mesh/MeshHost.hpp index cfd9c234..a400e003 100644 --- a/src/dawn/scene/components/display/mesh/MeshHost.hpp +++ b/src/dawn/scene/components/display/mesh/MeshHost.hpp @@ -12,6 +12,6 @@ namespace Dawn { public: Mesh mesh; - MeshHost(SceneItem *item); + MeshHost(std::weak_ptr item); }; } \ 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 e66c03dc..06bc2c90 100644 --- a/src/dawn/scene/components/display/mesh/MeshRenderer.cpp +++ b/src/dawn/scene/components/display/mesh/MeshRenderer.cpp @@ -9,12 +9,12 @@ using namespace Dawn; -MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) { +MeshRenderer::MeshRenderer(std::weak_ptr item) : SceneItemComponent(item) { } std::vector> MeshRenderer::getDependencies() { return { - this->meshHost = this->item->getComponent() + meshHost = item.lock()->getComponent() }; } diff --git a/src/dawn/scene/components/display/mesh/MeshRenderer.hpp b/src/dawn/scene/components/display/mesh/MeshRenderer.hpp index 767c8f7c..65db6679 100644 --- a/src/dawn/scene/components/display/mesh/MeshRenderer.hpp +++ b/src/dawn/scene/components/display/mesh/MeshRenderer.hpp @@ -23,7 +23,7 @@ namespace Dawn { * * @param item Scene Item this mesh renderer belongs to. */ - MeshRenderer(SceneItem *item); + MeshRenderer(std::weak_ptr item); std::vector> getDependencies() override; void onStart() override; diff --git a/src/dawn/scene/components/display/mesh/QuadMeshHost.cpp b/src/dawn/scene/components/display/mesh/QuadMeshHost.cpp index a5a3f62d..6162606e 100644 --- a/src/dawn/scene/components/display/mesh/QuadMeshHost.cpp +++ b/src/dawn/scene/components/display/mesh/QuadMeshHost.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -QuadMeshHost::QuadMeshHost(SceneItem *item) : +QuadMeshHost::QuadMeshHost(std::weak_ptr item) : xy0(glm::vec2(-0.5f, -0.5f)), xy1(glm::vec2(0.5f, 0.5f)), uv0(glm::vec2(0, 0)), uv1(glm::vec2(1, 1)), MeshHost(item) diff --git a/src/dawn/scene/components/display/mesh/QuadMeshHost.hpp b/src/dawn/scene/components/display/mesh/QuadMeshHost.hpp index b3e5c291..8181115e 100644 --- a/src/dawn/scene/components/display/mesh/QuadMeshHost.hpp +++ b/src/dawn/scene/components/display/mesh/QuadMeshHost.hpp @@ -19,7 +19,7 @@ namespace Dawn { // @optional StateProperty uv1; - QuadMeshHost(SceneItem *item); + QuadMeshHost(std::weak_ptr item); void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/example/ExampleSpin.cpp b/src/dawn/scene/components/example/ExampleSpin.cpp index 235e89e2..dff845bc 100644 --- a/src/dawn/scene/components/example/ExampleSpin.cpp +++ b/src/dawn/scene/components/example/ExampleSpin.cpp @@ -11,7 +11,7 @@ using namespace Dawn; -SceneItem * ExampleSpin::create(Scene *scene) { +std::shared_ptr ExampleSpin::create(Scene *scene) { auto item = scene->createSceneItem(); auto mr = item->addComponent(); mr->mesh = new Mesh(); @@ -22,17 +22,18 @@ SceneItem * ExampleSpin::create(Scene *scene) { return item; } -ExampleSpin::ExampleSpin(SceneItem *item) : +ExampleSpin::ExampleSpin(std::weak_ptr item) : SceneItemComponent(item) { } void ExampleSpin::onStart() { useEvent([&](float_t delta){ - auto quat = item->getLocalRotation(); + auto i = item.lock(); + auto quat = i->getLocalRotation(); quat = glm::rotate(quat, delta, glm::vec3(0, 1, 0)); quat = glm::rotate(quat, delta / 2.0f, glm::vec3(1, 0, 0)); quat = glm::rotate(quat, delta / 4.0f, glm::vec3(0, 0, 1)); - item->setLocalRotation(quat); + i->setLocalRotation(quat); }, getScene()->eventSceneUnpausedUpdate); } \ No newline at end of file diff --git a/src/dawn/scene/components/example/ExampleSpin.hpp b/src/dawn/scene/components/example/ExampleSpin.hpp index ea7b9dae..2132c849 100644 --- a/src/dawn/scene/components/example/ExampleSpin.hpp +++ b/src/dawn/scene/components/example/ExampleSpin.hpp @@ -10,9 +10,9 @@ namespace Dawn { class ExampleSpin : public SceneItemComponent { public: - static SceneItem * create(Scene *scene); + static std::shared_ptr create(Scene *scene); - ExampleSpin(SceneItem *item); + ExampleSpin(std::weak_ptr item); void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/BoxCollider.cpp b/src/dawn/scene/components/physics/2d/BoxCollider.cpp index 91f5db9c..b88daab8 100644 --- a/src/dawn/scene/components/physics/2d/BoxCollider.cpp +++ b/src/dawn/scene/components/physics/2d/BoxCollider.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -BoxCollider::BoxCollider(SceneItem *i) : Collider2D(i) { +BoxCollider::BoxCollider(std::weak_ptr item) : Collider2D(item) { } diff --git a/src/dawn/scene/components/physics/2d/BoxCollider.hpp b/src/dawn/scene/components/physics/2d/BoxCollider.hpp index edf2d80c..a0ea81e8 100644 --- a/src/dawn/scene/components/physics/2d/BoxCollider.hpp +++ b/src/dawn/scene/components/physics/2d/BoxCollider.hpp @@ -16,7 +16,7 @@ namespace Dawn { // @optional glm::vec2 max = glm::vec2( 0.5f, 0.5f); - BoxCollider(SceneItem *item); + BoxCollider(std::weak_ptr item); enum Collider2DType getColliderType() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/CharacterController2D.cpp b/src/dawn/scene/components/physics/2d/CharacterController2D.cpp index c452d372..9fa5f0bf 100644 --- a/src/dawn/scene/components/physics/2d/CharacterController2D.cpp +++ b/src/dawn/scene/components/physics/2d/CharacterController2D.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -CharacterController2D::CharacterController2D(SceneItem *i) : +CharacterController2D::CharacterController2D(std::weak_ptr i) : SceneItemComponent(i) { } @@ -17,6 +17,7 @@ void CharacterController2D::onStart() { // if(velocity == glm::vec2(0, 0)) return; // Common variables + auto item = this->item.lock(); auto myCollider = item->getComponent(); // Friction @@ -38,7 +39,8 @@ void CharacterController2D::onStart() { while(itColliders != allColliders.end()) { auto c = *itColliders; ++itColliders; - if(c->item == this->item || c->item->isChildOf(item->shared_from_this())) continue; + auto cItem = c->item.lock(); + if(cItem == item || cItem->isChildOf(item)) continue; result = c->getCollidingResult( velocity, myCollider, @@ -76,7 +78,8 @@ void CharacterController2D::onStart() { while(itTriggers != allTriggers.end()) { auto c = *itTriggers; ++itTriggers; - if(c->item == this->item || c->item->isChildOf(item->shared_from_this())) continue; + auto cItem = c->item.lock(); + if(cItem == item || cItem->isChildOf(item)) continue; if(c->getCollidingResult(myCollider)) { c->eventTriggerEnter.invoke(this); } diff --git a/src/dawn/scene/components/physics/2d/CharacterController2D.hpp b/src/dawn/scene/components/physics/2d/CharacterController2D.hpp index 7d7da834..14266f3c 100644 --- a/src/dawn/scene/components/physics/2d/CharacterController2D.hpp +++ b/src/dawn/scene/components/physics/2d/CharacterController2D.hpp @@ -26,7 +26,7 @@ namespace Dawn { StateEvent eventCollision; - CharacterController2D(SceneItem *i); + CharacterController2D(std::weak_ptr i); void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/Collider2D.cpp b/src/dawn/scene/components/physics/2d/Collider2D.cpp index 41ed803a..b53b278d 100644 --- a/src/dawn/scene/components/physics/2d/Collider2D.cpp +++ b/src/dawn/scene/components/physics/2d/Collider2D.cpp @@ -8,6 +8,6 @@ using namespace Dawn; -Collider2D::Collider2D(SceneItem *i) : SceneItemComponent(i) { +Collider2D::Collider2D(std::weak_ptr i) : SceneItemComponent(i) { } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/Collider2D.hpp b/src/dawn/scene/components/physics/2d/Collider2D.hpp index c11aded7..2ed9020b 100644 --- a/src/dawn/scene/components/physics/2d/Collider2D.hpp +++ b/src/dawn/scene/components/physics/2d/Collider2D.hpp @@ -22,7 +22,7 @@ namespace Dawn { class Collider2D : public SceneItemComponent { public: - Collider2D(SceneItem *item); + Collider2D(std::weak_ptr item); /** * Returns which type of collider this is. diff --git a/src/dawn/scene/components/physics/2d/SolidController2D.cpp b/src/dawn/scene/components/physics/2d/SolidController2D.cpp index 31f45a4a..36e0125c 100644 --- a/src/dawn/scene/components/physics/2d/SolidController2D.cpp +++ b/src/dawn/scene/components/physics/2d/SolidController2D.cpp @@ -7,12 +7,12 @@ using namespace Dawn; -SolidController2D::SolidController2D(SceneItem *item) : SceneItemComponent(item) { +SolidController2D::SolidController2D(std::weak_ptr item) : SceneItemComponent(item) { } std::vector> SolidController2D::getDependencies() { return { - (this->collider = item->getComponent()) + (this->collider = item.lock()->getComponent()) }; } @@ -29,7 +29,7 @@ bool_t SolidController2D::getCollidingResult( assertNotNull(movingObject, "SolidController2D::getCollidingResult: Moving object cannot be null"); if(movement.x == 0 && movement.y == 0) return false; - auto myPos = physics3Dto2D(movingObject->item->getWorldPosition()); + auto myPos = physics3Dto2D(movingObject->item.lock()->getWorldPosition()); // Check what the moving object is switch(movingObject->getColliderType()) { @@ -42,7 +42,7 @@ bool_t SolidController2D::getCollidingResult( case COLLIDER2D_TYPE_BOX: { auto box2 = std::static_pointer_cast(this->collider); assertNotNull(box2, "SolidController2D::getCollidingResult: Collider is not a BoxCollider"); - auto otherPos = physics3Dto2D(box2->item->getWorldPosition()); + auto otherPos = physics3Dto2D(box2->item.lock()->getWorldPosition()); return boxCheckCollision( myPos, box1->min, box1->max, diff --git a/src/dawn/scene/components/physics/2d/SolidController2D.hpp b/src/dawn/scene/components/physics/2d/SolidController2D.hpp index cccf6e63..21e4e78e 100644 --- a/src/dawn/scene/components/physics/2d/SolidController2D.hpp +++ b/src/dawn/scene/components/physics/2d/SolidController2D.hpp @@ -12,7 +12,7 @@ namespace Dawn { public: std::shared_ptr collider; - SolidController2D(SceneItem *item); + SolidController2D(std::weak_ptr item); std::vector> getDependencies() override; /** diff --git a/src/dawn/scene/components/physics/2d/TriggerController2D.cpp b/src/dawn/scene/components/physics/2d/TriggerController2D.cpp index 8d7cf409..1486b411 100644 --- a/src/dawn/scene/components/physics/2d/TriggerController2D.cpp +++ b/src/dawn/scene/components/physics/2d/TriggerController2D.cpp @@ -7,13 +7,13 @@ using namespace Dawn; -TriggerController2D::TriggerController2D(SceneItem *i) : SceneItemComponent(i) { +TriggerController2D::TriggerController2D(std::weak_ptr i) : SceneItemComponent(i) { } std::vector> TriggerController2D::getDependencies() { return { - (this->collider = this->item->getComponent()) + (this->collider = this->item.lock()->getComponent()) }; } @@ -32,8 +32,8 @@ bool_t TriggerController2D::getCollidingResult(std::shared_ptr movin auto box2 = std::static_pointer_cast(collider); assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider"); return boxIsBoxColliding( - physics3Dto2D(box1->item->getWorldPosition()), box1->min, box1->max, - physics3Dto2D(box2->item->getWorldPosition()), box2->min, box2->max + physics3Dto2D(box1->item.lock()->getWorldPosition()), box1->min, box1->max, + physics3Dto2D(box2->item.lock()->getWorldPosition()), box2->min, box2->max ); } diff --git a/src/dawn/scene/components/physics/2d/TriggerController2D.hpp b/src/dawn/scene/components/physics/2d/TriggerController2D.hpp index 8b7df395..64254e44 100644 --- a/src/dawn/scene/components/physics/2d/TriggerController2D.hpp +++ b/src/dawn/scene/components/physics/2d/TriggerController2D.hpp @@ -15,7 +15,7 @@ namespace Dawn { std::shared_ptr collider; StateEvent eventTriggerEnter; - TriggerController2D(SceneItem *i); + TriggerController2D(std::weak_ptr i); std::vector> getDependencies() override; /** diff --git a/src/dawn/scene/components/physics/3d/CapsuleCollider.cpp b/src/dawn/scene/components/physics/3d/CapsuleCollider.cpp index 9e54385a..13aa2079 100644 --- a/src/dawn/scene/components/physics/3d/CapsuleCollider.cpp +++ b/src/dawn/scene/components/physics/3d/CapsuleCollider.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -CapsuleCollider::CapsuleCollider(SceneItem *item) : Collider3D(item) { +CapsuleCollider::CapsuleCollider(std::weak_ptr item) : Collider3D(item) { } @@ -22,7 +22,7 @@ bool_t CapsuleCollider::performRaycast( { .height = this->height, .radius = this->radius, - .origin = item->getWorldPosition() + .origin = item.lock()->getWorldPosition() }, &result->point, &result->normal, diff --git a/src/dawn/scene/components/physics/3d/CapsuleCollider.hpp b/src/dawn/scene/components/physics/3d/CapsuleCollider.hpp index c0088b0b..b1ecc07c 100644 --- a/src/dawn/scene/components/physics/3d/CapsuleCollider.hpp +++ b/src/dawn/scene/components/physics/3d/CapsuleCollider.hpp @@ -21,7 +21,7 @@ namespace Dawn { // @optional float_t radius = 0.5f; - CapsuleCollider(SceneItem *item); + CapsuleCollider(std::weak_ptr item); enum Collider3DType getColliderType() override; }; diff --git a/src/dawn/scene/components/physics/3d/CharacterController3D.cpp b/src/dawn/scene/components/physics/3d/CharacterController3D.cpp index 74a77597..c9e2caf9 100644 --- a/src/dawn/scene/components/physics/3d/CharacterController3D.cpp +++ b/src/dawn/scene/components/physics/3d/CharacterController3D.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -CharacterController3D::CharacterController3D(SceneItem *item) : +CharacterController3D::CharacterController3D(std::weak_ptr item) : SceneItemComponent(item) { @@ -15,6 +15,8 @@ CharacterController3D::CharacterController3D(SceneItem *item) : void CharacterController3D::onStart() { useEvent([&](float_t delta){ + auto item = this->item.lock(); + // Friction velocity -= glm::vec3(velocity.x, 0, velocity.z) * friction * delta; diff --git a/src/dawn/scene/components/physics/3d/CharacterController3D.hpp b/src/dawn/scene/components/physics/3d/CharacterController3D.hpp index 729e7dcd..8c594f7a 100644 --- a/src/dawn/scene/components/physics/3d/CharacterController3D.hpp +++ b/src/dawn/scene/components/physics/3d/CharacterController3D.hpp @@ -16,7 +16,7 @@ namespace Dawn { // @optional float_t friction = 12.0f; - CharacterController3D(SceneItem *item); + CharacterController3D(std::weak_ptr item); void onStart() override; }; diff --git a/src/dawn/scene/components/physics/3d/Collider3D.cpp b/src/dawn/scene/components/physics/3d/Collider3D.cpp index d36518d1..a4fdc5ce 100644 --- a/src/dawn/scene/components/physics/3d/Collider3D.cpp +++ b/src/dawn/scene/components/physics/3d/Collider3D.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -Collider3D::Collider3D(SceneItem *item) : SceneItemComponent(item) { +Collider3D::Collider3D(std::weak_ptr item) : SceneItemComponent(item) { } diff --git a/src/dawn/scene/components/physics/3d/Collider3D.hpp b/src/dawn/scene/components/physics/3d/Collider3D.hpp index 6605f460..ea3b8950 100644 --- a/src/dawn/scene/components/physics/3d/Collider3D.hpp +++ b/src/dawn/scene/components/physics/3d/Collider3D.hpp @@ -36,7 +36,7 @@ namespace Dawn { ) = 0; public: - Collider3D(SceneItem *item); + Collider3D(std::weak_ptr item); /** * Perform a raycast against this collider. diff --git a/src/dawn/scene/components/physics/3d/CubeCollider.cpp b/src/dawn/scene/components/physics/3d/CubeCollider.cpp index a0127f21..fca13b43 100644 --- a/src/dawn/scene/components/physics/3d/CubeCollider.cpp +++ b/src/dawn/scene/components/physics/3d/CubeCollider.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -CubeCollider::CubeCollider(SceneItem *item) : Collider3D(item) { +CubeCollider::CubeCollider(std::weak_ptr item) : Collider3D(item) { } @@ -20,7 +20,7 @@ bool_t CubeCollider::performRaycast( return Dawn::raytestCube( ray, { .min = this->min, .max = this->max }, - item->getWorldTransform(), + item.lock()->getWorldTransform(), &result->point, &result->normal, &result->distance diff --git a/src/dawn/scene/components/physics/3d/CubeCollider.hpp b/src/dawn/scene/components/physics/3d/CubeCollider.hpp index 9cf020d7..d5d1338c 100644 --- a/src/dawn/scene/components/physics/3d/CubeCollider.hpp +++ b/src/dawn/scene/components/physics/3d/CubeCollider.hpp @@ -21,7 +21,7 @@ namespace Dawn { // @optional glm::vec3 max = glm::vec3(0.5f, 0.5f, 0.5f); - CubeCollider(SceneItem *item); + CubeCollider(std::weak_ptr item); enum Collider3DType getColliderType() override; }; diff --git a/src/dawn/scene/components/physics/3d/SphereCollider.cpp b/src/dawn/scene/components/physics/3d/SphereCollider.cpp index 8d26dfaa..2021b08d 100644 --- a/src/dawn/scene/components/physics/3d/SphereCollider.cpp +++ b/src/dawn/scene/components/physics/3d/SphereCollider.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -SphereCollider::SphereCollider(SceneItem *item) : Collider3D(item) { +SphereCollider::SphereCollider(std::weak_ptr item) : Collider3D(item) { } @@ -23,7 +23,7 @@ bool_t SphereCollider::performRaycast( return raytestSphere( ray, - { .center = item->getLocalPosition(), .radius = this->radius }, + { .center = item.lock()->getLocalPosition(), .radius = this->radius }, &result->point, &result->normal, &result->distance diff --git a/src/dawn/scene/components/physics/3d/SphereCollider.hpp b/src/dawn/scene/components/physics/3d/SphereCollider.hpp index c931fee5..118f2cb3 100644 --- a/src/dawn/scene/components/physics/3d/SphereCollider.hpp +++ b/src/dawn/scene/components/physics/3d/SphereCollider.hpp @@ -18,7 +18,7 @@ namespace Dawn { // @optional float_t radius = 1.0f; - SphereCollider(SceneItem *item); + SphereCollider(std::weak_ptr item); enum Collider3DType getColliderType() override; }; diff --git a/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp b/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp index 4809d296..a9af94da 100644 --- a/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp +++ b/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -SubSceneCameraAlign::SubSceneCameraAlign(SceneItem *i) : +SubSceneCameraAlign::SubSceneCameraAlign(std::weak_ptr i) : SceneItemComponent(i), camera(nullptr), renderTarget(nullptr) @@ -23,7 +23,7 @@ void SubSceneCameraAlign::realign() { float_t myRatio = this->camera->getAspect(); this->camera->type = CAMERA_TYPE_ORTHONOGRAPHIC; - this->camera->item->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0)); + this->camera->item.lock()->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0)); if(ratio > myRatio) { // My Ratio is narrower diff --git a/src/dawn/scene/components/scene/SubSceneCameraAlign.hpp b/src/dawn/scene/components/scene/SubSceneCameraAlign.hpp index 4a393e84..11b91f79 100644 --- a/src/dawn/scene/components/scene/SubSceneCameraAlign.hpp +++ b/src/dawn/scene/components/scene/SubSceneCameraAlign.hpp @@ -31,7 +31,7 @@ namespace Dawn { * * @param item Scene Item that this component belongs to. */ - SubSceneCameraAlign(SceneItem *item); + SubSceneCameraAlign(std::weak_ptr item); void onStart() override; }; diff --git a/src/dawn/scene/components/scene/SubSceneController.cpp b/src/dawn/scene/components/scene/SubSceneController.cpp index 0dec6e68..28c31eba 100644 --- a/src/dawn/scene/components/scene/SubSceneController.cpp +++ b/src/dawn/scene/components/scene/SubSceneController.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -SubSceneController::SubSceneController(SceneItem *i) : SceneItemComponent(i) { +SubSceneController::SubSceneController(std::weak_ptr i) : SceneItemComponent(i) { } diff --git a/src/dawn/scene/components/scene/SubSceneController.hpp b/src/dawn/scene/components/scene/SubSceneController.hpp index ec7c1270..f8a6d4b9 100644 --- a/src/dawn/scene/components/scene/SubSceneController.hpp +++ b/src/dawn/scene/components/scene/SubSceneController.hpp @@ -14,7 +14,7 @@ namespace Dawn { // @optional bool_t onlyUpdateUnpaused = false; - SubSceneController(SceneItem *item); + SubSceneController(std::weak_ptr item); void onStart() override; }; diff --git a/src/dawn/scene/components/ui/UIBorder.cpp b/src/dawn/scene/components/ui/UIBorder.cpp index bf30323a..6e7f731e 100644 --- a/src/dawn/scene/components/ui/UIBorder.cpp +++ b/src/dawn/scene/components/ui/UIBorder.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -UIBorder::UIBorder(SceneItem *item) : +UIBorder::UIBorder(std::weak_ptr item) : texture(nullptr), borderSize(glm::vec2(8, 8)), UIComponentRenderable(item) @@ -37,7 +37,7 @@ std::vector UIBorder::getUIRenderPasses() { item.shader = shader; item.colorValues[shader->paramColor] = COLOR_WHITE; item.parameterBuffers[shader->bufferUiCanvas] = &this->getCanvas()->shaderBuffer; - item.matrixValues[shader->paramModel] = this->item->getWorldTransform(); + item.matrixValues[shader->paramModel] = this->item.lock()->getWorldTransform(); if(this->texture == nullptr) { item.boolValues[shader->paramHasTexture] = false; } else { @@ -45,7 +45,7 @@ std::vector UIBorder::getUIRenderPasses() { item.textureSlots[0] = this->texture; item.textureValues[shader->paramTexture] = 0; } - item.w = this->item->getWorldPosition().z; + item.w = this->item.lock()->getWorldPosition().z; item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND; item.mesh = &mesh; diff --git a/src/dawn/scene/components/ui/UIBorder.hpp b/src/dawn/scene/components/ui/UIBorder.hpp index d5b01709..a7ca2484 100644 --- a/src/dawn/scene/components/ui/UIBorder.hpp +++ b/src/dawn/scene/components/ui/UIBorder.hpp @@ -20,7 +20,7 @@ namespace Dawn { // @optional StateProperty texture; - UIBorder(SceneItem *item); + UIBorder(std::weak_ptr item); float_t getContentWidth() override; float_t getContentHeight() override; diff --git a/src/dawn/scene/components/ui/UICanvas.cpp b/src/dawn/scene/components/ui/UICanvas.cpp index 0f8435a0..23c021c2 100644 --- a/src/dawn/scene/components/ui/UICanvas.cpp +++ b/src/dawn/scene/components/ui/UICanvas.cpp @@ -14,7 +14,7 @@ std::shared_ptr UICanvas::create(Scene *scene) { return item->addComponent(); } -UICanvas::UICanvas(SceneItem *item) : +UICanvas::UICanvas(std::weak_ptr item) : SceneItemComponent(item), camera(nullptr) { @@ -26,7 +26,7 @@ void UICanvas::rebufferShaderParameters() { switch(this->drawType) { case UI_DRAW_TYPE_WORLD_ABSOLUTE: data.projection = camera->getProjection(); - data.view = camera->item->getWorldTransform(); + data.view = camera->item.lock()->getWorldTransform(); break; case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE: @@ -91,7 +91,7 @@ void UICanvas::onStart() { this->h = h / this->getScale(); this->rebufferShaderParameters(); - auto comps = this->item->findChildren(); + auto comps = this->item.lock()->findChildren(); auto itComps = comps.begin(); while(itComps != comps.end()) { (*itComps)->alignmentNeedsUpdating = true; diff --git a/src/dawn/scene/components/ui/UICanvas.hpp b/src/dawn/scene/components/ui/UICanvas.hpp index d80d85ef..3c372336 100644 --- a/src/dawn/scene/components/ui/UICanvas.hpp +++ b/src/dawn/scene/components/ui/UICanvas.hpp @@ -94,7 +94,7 @@ namespace Dawn { * * @param item Item that this canvas item belongs to. */ - UICanvas(SceneItem *item); + UICanvas(std::weak_ptr item); /** * Returns the scale of this canvas. diff --git a/src/dawn/scene/components/ui/UIComponent.cpp b/src/dawn/scene/components/ui/UIComponent.cpp index 35c47149..f56032c5 100644 --- a/src/dawn/scene/components/ui/UIComponent.cpp +++ b/src/dawn/scene/components/ui/UIComponent.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -UIComponent::UIComponent(SceneItem *item) : +UIComponent::UIComponent(std::weak_ptr item) : SceneItemComponent(item), alignment(glm::vec4(0, 0, 128, 128)), alignUnitLeft(UI_COMPONENT_ALIGN_UNIT_SCALE), @@ -22,7 +22,7 @@ UIComponent::UIComponent(SceneItem *item) : } std::shared_ptr UIComponent::getParentDimensional() { - auto parent = item->getParent(); + auto parent = item.lock()->getParent(); if(parent == nullptr) return nullptr; auto dimensional = parent->getComponent(); assertNotNull(dimensional, "UIComponent::getParentDimensional: Parent must have a UIComponentDimensional"); @@ -34,7 +34,7 @@ void UIComponent::updateAlignment() { auto align = (glm::vec4)this->alignment; auto dimensional = this->getParentDimensional(); - auto translate = item->getLocalPosition(); + auto translate = item.lock()->getLocalPosition(); assertNotNull(dimensional, "UIComponent::updateAlignment: Parent must have a UIComponentDimensional"); @@ -99,7 +99,7 @@ void UIComponent::updateAlignment() { translate.x += dimensional->getChildOffsetX(); translate.y += dimensional->getChildOffsetY(); - item->setLocalPosition(translate); + item.lock()->setLocalPosition(translate); this->alignmentNeedsUpdating = false; this->eventAlignmentUpdated.invoke(); } @@ -240,7 +240,7 @@ void UIComponent::calculateDimensions( std::shared_ptr UIComponent::getCanvas() { // TODO: Cache this on first hit. - auto parent = item->getParent(); + auto parent = item.lock()->getParent(); while(parent) { auto canvas = parent->getComponent(); if(canvas != nullptr) return canvas; @@ -274,7 +274,7 @@ void UIComponent::onStart() { useEffect([&]{ this->updateAlignment(); - auto child = this->item->findChildren(); + auto child = this->item.lock()->findChildren(); auto itChild = child.begin(); while(itChild != child.end()) { (*itChild)->alignmentNeedsUpdating = true; diff --git a/src/dawn/scene/components/ui/UIComponent.hpp b/src/dawn/scene/components/ui/UIComponent.hpp index 7ef00847..cb21ef8f 100644 --- a/src/dawn/scene/components/ui/UIComponent.hpp +++ b/src/dawn/scene/components/ui/UIComponent.hpp @@ -123,7 +123,7 @@ namespace Dawn { // @optional StateProperty alignment; - UIComponent(SceneItem *item); + UIComponent(std::weak_ptr item); /** * Returns the canvas that this UI element is belonging to. diff --git a/src/dawn/scene/components/ui/UIComponentRenderable.cpp b/src/dawn/scene/components/ui/UIComponentRenderable.cpp index 47440076..8df4a96c 100644 --- a/src/dawn/scene/components/ui/UIComponentRenderable.cpp +++ b/src/dawn/scene/components/ui/UIComponentRenderable.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -UIComponentRenderable::UIComponentRenderable(SceneItem *i) : UIComponent(i) { +UIComponentRenderable::UIComponentRenderable(std::weak_ptr i) : UIComponent(i) { } diff --git a/src/dawn/scene/components/ui/UIComponentRenderable.hpp b/src/dawn/scene/components/ui/UIComponentRenderable.hpp index 0f65ce9f..f9bbeffe 100644 --- a/src/dawn/scene/components/ui/UIComponentRenderable.hpp +++ b/src/dawn/scene/components/ui/UIComponentRenderable.hpp @@ -9,7 +9,7 @@ namespace Dawn { class UIComponentRenderable : public UIComponent, public IRenderable { public: - UIComponentRenderable(SceneItem *item); + UIComponentRenderable(std::weak_ptr item); std::vector getRenderPasses( struct IRenderableContext &context diff --git a/src/dawn/scene/components/ui/UIEmpty.cpp b/src/dawn/scene/components/ui/UIEmpty.cpp index 875e7a67..c104b475 100644 --- a/src/dawn/scene/components/ui/UIEmpty.cpp +++ b/src/dawn/scene/components/ui/UIEmpty.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -UIEmpty::UIEmpty(SceneItem *item) : UIComponent(item) { } +UIEmpty::UIEmpty(std::weak_ptr item) : UIComponent(item) { } float_t UIEmpty::getContentWidth() { return this->getWidthFromAlignment(); diff --git a/src/dawn/scene/components/ui/UIEmpty.hpp b/src/dawn/scene/components/ui/UIEmpty.hpp index af4a2808..4d7ef18b 100644 --- a/src/dawn/scene/components/ui/UIEmpty.hpp +++ b/src/dawn/scene/components/ui/UIEmpty.hpp @@ -9,7 +9,7 @@ namespace Dawn { class UIEmpty : public UIComponent { public: - UIEmpty(SceneItem *item); + UIEmpty(std::weak_ptr item); float_t getContentWidth() override; float_t getContentHeight() override; float_t getChildOffsetX() override; diff --git a/src/dawn/scene/components/ui/UIImage.cpp b/src/dawn/scene/components/ui/UIImage.cpp index 55ad08e7..d409c09c 100644 --- a/src/dawn/scene/components/ui/UIImage.cpp +++ b/src/dawn/scene/components/ui/UIImage.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -UIImage::UIImage(SceneItem *item) : +UIImage::UIImage(std::weak_ptr item) : texture(nullptr), UIComponentRenderable(item), uvs(glm::vec4(0, 1, 1, 0)) @@ -32,7 +32,7 @@ std::vector UIImage::getUIRenderPasses() { item.shader = shader; item.colorValues[shader->paramColor] = this->color; item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer; - item.matrixValues[shader->paramModel] = this->item->getWorldTransform(); + item.matrixValues[shader->paramModel] = this->item.lock()->getWorldTransform(); if(this->texture == nullptr) { item.boolValues[shader->paramHasTexture] = false; } else { @@ -40,7 +40,7 @@ std::vector UIImage::getUIRenderPasses() { item.textureSlots[0] = this->texture; item.textureValues[shader->paramTexture] = 0; } - item.w = this->item->getWorldPosition().z; + item.w = this->item.lock()->getWorldPosition().z; item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND; item.mesh = &mesh; return { item }; diff --git a/src/dawn/scene/components/ui/UIImage.hpp b/src/dawn/scene/components/ui/UIImage.hpp index bcd0a766..e7ece2fc 100644 --- a/src/dawn/scene/components/ui/UIImage.hpp +++ b/src/dawn/scene/components/ui/UIImage.hpp @@ -20,7 +20,7 @@ namespace Dawn { // @optional StateProperty uvs; - UIImage(SceneItem *item); + UIImage(std::weak_ptr item); float_t getContentWidth() override; float_t getContentHeight() override; diff --git a/src/dawn/scene/components/ui/UIMesh.cpp b/src/dawn/scene/components/ui/UIMesh.cpp index 63755567..6237be98 100644 --- a/src/dawn/scene/components/ui/UIMesh.cpp +++ b/src/dawn/scene/components/ui/UIMesh.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -UIMesh::UIMesh(SceneItem *i) : +UIMesh::UIMesh(std::weak_ptr i) : texture(nullptr), UIComponentRenderable(i) { @@ -31,7 +31,7 @@ std::vector UIMesh::getUIRenderPasses() { shaderItem.shader = shader; shaderItem.colorValues[shader->paramColor] = this->color; shaderItem.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer; - shaderItem.matrixValues[shader->paramModel] = item->getWorldTransform(); + shaderItem.matrixValues[shader->paramModel] = item.lock()->getWorldTransform(); if(this->texture == nullptr) { shaderItem.boolValues[shader->paramHasTexture] = false; } else { @@ -39,7 +39,7 @@ std::vector UIMesh::getUIRenderPasses() { shaderItem.textureSlots[0] = this->texture; shaderItem.textureValues[shader->paramTexture] = 0; } - shaderItem.w = item->getWorldPosition().z; + shaderItem.w = item.lock()->getWorldPosition().z; shaderItem.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND; shaderItem.mesh = &mesh; return { shaderItem }; diff --git a/src/dawn/scene/components/ui/UIMesh.hpp b/src/dawn/scene/components/ui/UIMesh.hpp index b9703ec2..f7ac113a 100644 --- a/src/dawn/scene/components/ui/UIMesh.hpp +++ b/src/dawn/scene/components/ui/UIMesh.hpp @@ -22,7 +22,7 @@ namespace Dawn { // @optional StateProperty texture; - UIMesh(SceneItem *item); + UIMesh(std::weak_ptr item); float_t getContentWidth() override; float_t getContentHeight() override; std::vector getUIRenderPasses() override; diff --git a/src/dawn/scene/components/ui/menu/UIMenuController.cpp b/src/dawn/scene/components/ui/menu/UIMenuController.cpp index 2d58fd8b..7a969da9 100644 --- a/src/dawn/scene/components/ui/menu/UIMenuController.cpp +++ b/src/dawn/scene/components/ui/menu/UIMenuController.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -UIMenuController::UIMenuController(SceneItem *item) : +UIMenuController::UIMenuController(std::weak_ptr item) : SceneItemComponent(item), active(true), menuX(0), diff --git a/src/dawn/scene/components/ui/menu/UIMenuController.hpp b/src/dawn/scene/components/ui/menu/UIMenuController.hpp index 47f00f01..62d6b072 100644 --- a/src/dawn/scene/components/ui/menu/UIMenuController.hpp +++ b/src/dawn/scene/components/ui/menu/UIMenuController.hpp @@ -22,7 +22,7 @@ namespace Dawn { StateEvent eventItemSelected; StateEvent<> eventMenuCancel; - UIMenuController(SceneItem *item); + UIMenuController(std::weak_ptr item); void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp b/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp index de344673..6a6eeaf9 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -UISimpleMenu::UISimpleMenu(SceneItem *item) : +UISimpleMenu::UISimpleMenu(std::weak_ptr item) : SceneItemComponent(item) { @@ -16,8 +16,8 @@ UISimpleMenu::UISimpleMenu(SceneItem *item) : std::vector> UISimpleMenu::getDependencies() { return { - (this->menu = this->item->getComponent()), - (this->canvas == nullptr ? (this->canvas = this->item->getComponent()) : nullptr) + (this->menu = this->item.lock()->getComponent()), + (this->canvas == nullptr ? (this->canvas = this->item.lock()->getComponent()) : nullptr) }; } @@ -26,7 +26,7 @@ void UISimpleMenu::onStart() { assertNotNull(this->menu, "UISimpleMenu::onStart: Menu cannot be null"); assertNotNull(this->canvas, "UISimpleMenu::onStart: Canvas cannot be null"); - menuItems = this->item->findChildren(); + menuItems = this->item.lock()->findChildren(); auto updateSimpleMenuPos = [&](int32_t x, int32_t y) { if(currentlySelected != nullptr) { @@ -75,7 +75,7 @@ void UISimpleMenu::onStart() { case UI_DRAW_TYPE_WORLD_ABSOLUTE: mouse *= 2.0f; mouse -= glm::vec2(1, 1); - ray.origin = canvas->camera->item->getWorldPosition(); + ray.origin = canvas->camera->item.lock()->getWorldPosition(); ray.direction = canvas->camera->getRayDirectionFromScreenSpace(mouse); break; @@ -107,7 +107,7 @@ void UISimpleMenu::onStart() { if(!raytestQuad( ray, glm::vec2(0, 0), size, - highlight->item->getWorldTransform(), + highlight->item.lock()->getWorldTransform(), &point, &normal, &distance diff --git a/src/dawn/scene/components/ui/menu/UISimpleMenu.hpp b/src/dawn/scene/components/ui/menu/UISimpleMenu.hpp index 118e476c..a9656927 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenu.hpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenu.hpp @@ -16,7 +16,7 @@ namespace Dawn { std::vector> menuItems; public: - UISimpleMenu(SceneItem *item); + UISimpleMenu(std::weak_ptr item); std::vector> getDependencies() override; void onStart() override; }; diff --git a/src/dawn/scene/components/ui/menu/UISimpleMenuItem.cpp b/src/dawn/scene/components/ui/menu/UISimpleMenuItem.cpp index 3266c56d..4e2f9235 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenuItem.cpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenuItem.cpp @@ -7,11 +7,11 @@ using namespace Dawn; -UISimpleMenuItem::UISimpleMenuItem(SceneItem *item) : SceneItemComponent(item) { +UISimpleMenuItem::UISimpleMenuItem(std::weak_ptr item) : SceneItemComponent(item) { } std::shared_ptr UISimpleMenuItem::getComponentForHighlighting() { - if(uiComponent == nullptr) uiComponent = item->getComponent(); + if(uiComponent == nullptr) uiComponent = item.lock()->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 cff2f510..0dbb311d 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenuItem.hpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenuItem.hpp @@ -17,7 +17,7 @@ namespace Dawn { int32_t menuY = 0; std::shared_ptr uiComponent = nullptr; - UISimpleMenuItem(SceneItem *item); + UISimpleMenuItem(std::weak_ptr item); /** * Returns the UI component that this simple UI menu item uses to figure diff --git a/src/dawn/scene/components/ui/text/UILabel.cpp b/src/dawn/scene/components/ui/text/UILabel.cpp index 953f41a9..dce1b62d 100644 --- a/src/dawn/scene/components/ui/text/UILabel.cpp +++ b/src/dawn/scene/components/ui/text/UILabel.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -UILabel::UILabel(SceneItem *item) : +UILabel::UILabel(std::weak_ptr item) : UIComponentRenderable(item), lineHeight(1.0f), textAlign(UI_LABEL_TEXT_ALIGN_LEFT) @@ -90,7 +90,7 @@ std::vector UILabel::getUIRenderPasses() { auto shader = getGame()->renderManager->fontShader; // Translate - glm::mat4 model = item->getWorldTransform(); + glm::mat4 model = item.lock()->getWorldTransform(); model = glm::translate(model, glm::vec3(this->textOffset, 0.0f)); struct ShaderPassItem item; diff --git a/src/dawn/scene/components/ui/text/UILabel.hpp b/src/dawn/scene/components/ui/text/UILabel.hpp index aad652fc..4881625e 100644 --- a/src/dawn/scene/components/ui/text/UILabel.hpp +++ b/src/dawn/scene/components/ui/text/UILabel.hpp @@ -79,7 +79,7 @@ namespace Dawn { // @optional StateProperty textAlign; - UILabel(SceneItem *item); + UILabel(std::weak_ptr item); void onStart() override; std::vector getUIRenderPasses() override; diff --git a/src/dawn/scene/components/ui/text/UIRichTextLabel.cpp b/src/dawn/scene/components/ui/text/UIRichTextLabel.cpp index 99a3b342..034bdb9d 100644 --- a/src/dawn/scene/components/ui/text/UIRichTextLabel.cpp +++ b/src/dawn/scene/components/ui/text/UIRichTextLabel.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -UIRichTextLabel::UIRichTextLabel(SceneItem *item) : +UIRichTextLabel::UIRichTextLabel(std::weak_ptr item) : UILabel(item) { diff --git a/src/dawn/scene/components/ui/text/UIRichTextLabel.hpp b/src/dawn/scene/components/ui/text/UIRichTextLabel.hpp index d1e612ab..a558b0f9 100644 --- a/src/dawn/scene/components/ui/text/UIRichTextLabel.hpp +++ b/src/dawn/scene/components/ui/text/UIRichTextLabel.hpp @@ -12,7 +12,7 @@ namespace Dawn { // @innerXml StateProperty richText; - UIRichTextLabel(SceneItem *item); + UIRichTextLabel(std::weak_ptr item); void onStart() override; }; diff --git a/src/dawn/scene/components/ui/text/UISimpleLabel.cpp b/src/dawn/scene/components/ui/text/UISimpleLabel.cpp index ac86ee76..97fbd5d6 100644 --- a/src/dawn/scene/components/ui/text/UISimpleLabel.cpp +++ b/src/dawn/scene/components/ui/text/UISimpleLabel.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -UISimpleLabel::UISimpleLabel(SceneItem *i) : +UISimpleLabel::UISimpleLabel(std::weak_ptr i) : UILabel(i), text("Hello World"), font(nullptr), diff --git a/src/dawn/scene/components/ui/text/UISimpleLabel.hpp b/src/dawn/scene/components/ui/text/UISimpleLabel.hpp index 5baed970..1f5960f7 100644 --- a/src/dawn/scene/components/ui/text/UISimpleLabel.hpp +++ b/src/dawn/scene/components/ui/text/UISimpleLabel.hpp @@ -22,7 +22,7 @@ namespace Dawn { // @optional StateProperty color; - UISimpleLabel(SceneItem *item); + UISimpleLabel(std::weak_ptr item); void onStart() override; }; diff --git a/src/dawn/scenes/TestScene.hpp b/src/dawn/scenes/TestScene.hpp index 986253ca..bedc31e3 100644 --- a/src/dawn/scenes/TestScene.hpp +++ b/src/dawn/scenes/TestScene.hpp @@ -14,7 +14,7 @@ namespace Dawn { SimpleSpinningCubePrefab *cube; void stage() override { - camera = Camera::create(this); + camera = Camera::create(shared_from_this()); camera->lookAt(glm::vec3(5, 5, 5), glm::vec3(0, 0, 0)); cube = SimpleSpinningCubePrefab::prefabCreate(this); diff --git a/src/dawnhelloworld/scenes/HelloWorldScene.hpp b/src/dawnhelloworld/scenes/HelloWorldScene.hpp index cae4f8e9..03fe0596 100644 --- a/src/dawnhelloworld/scenes/HelloWorldScene.hpp +++ b/src/dawnhelloworld/scenes/HelloWorldScene.hpp @@ -12,12 +12,12 @@ namespace Dawn { class HelloWorldScene : public Scene { protected: std::shared_ptr camera; - SimpleSpinningCubePrefab *cube; + std::shared_ptr cube; std::shared_ptr canvas; void stage() override { camera = Camera::create(shared_from_this()); - camera->item->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0)); + camera->item.lock()->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0)); cube = SimpleSpinningCubePrefab::create(this); diff --git a/src/dawnliminal/scenes/HelloWorldScene.hpp b/src/dawnliminal/scenes/HelloWorldScene.hpp index c288fe10..05f4379f 100644 --- a/src/dawnliminal/scenes/HelloWorldScene.hpp +++ b/src/dawnliminal/scenes/HelloWorldScene.hpp @@ -16,7 +16,7 @@ namespace Dawn { SimpleSpinningCubePrefab *cube; void stage() override { - camera = Camera::create(this); + camera = Camera::create(shared_from_this()); camera->transform->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0)); cube = SimpleSpinningCubePrefab::create(this); diff --git a/src/dawnopenal/scene/components/audio/AudioListener.cpp b/src/dawnopenal/scene/components/audio/AudioListener.cpp index 85e64e86..7733a603 100644 --- a/src/dawnopenal/scene/components/audio/AudioListener.cpp +++ b/src/dawnopenal/scene/components/audio/AudioListener.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -AudioListener::AudioListener(SceneItem *i) : SceneItemComponent(i) { +AudioListener::AudioListener(std::weak_ptr i) : SceneItemComponent(i) { } diff --git a/src/dawnopenal/scene/components/audio/AudioListener.hpp b/src/dawnopenal/scene/components/audio/AudioListener.hpp index a9660bc3..9c325378 100644 --- a/src/dawnopenal/scene/components/audio/AudioListener.hpp +++ b/src/dawnopenal/scene/components/audio/AudioListener.hpp @@ -13,7 +13,7 @@ namespace Dawn { void onTransformUpdate(); public: - AudioListener(SceneItem *item); + AudioListener(std::weak_ptr item); void onStart() override; void onDispose() override; diff --git a/src/dawnopenal/scene/components/audio/AudioSource.cpp b/src/dawnopenal/scene/components/audio/AudioSource.cpp index 1915ca01..03353096 100644 --- a/src/dawnopenal/scene/components/audio/AudioSource.cpp +++ b/src/dawnopenal/scene/components/audio/AudioSource.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -AudioSource::AudioSource(SceneItem *i) : +AudioSource::AudioSource(std::weak_ptr i) : SceneItemComponent(i), playMode(AUDIO_PLAY_MODE_UNPAUSED) { diff --git a/src/dawnopenal/scene/components/audio/AudioSource.hpp b/src/dawnopenal/scene/components/audio/AudioSource.hpp index db2885c4..68543dc3 100644 --- a/src/dawnopenal/scene/components/audio/AudioSource.hpp +++ b/src/dawnopenal/scene/components/audio/AudioSource.hpp @@ -64,7 +64,7 @@ namespace Dawn { * * @param item SceneItem that this audio source is attached to. */ - AudioSource(SceneItem *item); + AudioSource(std::weak_ptr item); /** * Returns the real current state of the sound. Refer to getPlayingState diff --git a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp index 9a03d8d0..84d5826f 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp +++ b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp @@ -9,7 +9,7 @@ using namespace Dawn; -SimpleBillboardedMaterial::SimpleBillboardedMaterial(SceneItem *i) : +SimpleBillboardedMaterial::SimpleBillboardedMaterial(std::weak_ptr i) : Material(i) { } @@ -25,7 +25,7 @@ void SimpleBillboardedMaterial::onDispose() { std::vector SimpleBillboardedMaterial::getRenderPasses(IRenderableContext &context) { - auto mesh = item->getComponent(); + auto mesh = item.lock()->getComponent(); auto shader = getShaderManager().getShader(this->shaderLock); assertNotNull(mesh, "Mesh cannot be null"); @@ -36,7 +36,7 @@ std::vector onlyPass.mesh = mesh->mesh; onlyPass.shader = shader; onlyPass.colorValues[shader->paramColor] = this->color; - onlyPass.matrixValues[shader->paramModel] = item->getWorldTransform(); + onlyPass.matrixValues[shader->paramModel] = item.lock()->getWorldTransform(); onlyPass.parameterBuffers[shader->bufferRenderPipeline] = &context.renderPipeline->shaderBuffer ; diff --git a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.hpp b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.hpp index d40b9bef..e6eda5a6 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.hpp +++ b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.hpp @@ -23,7 +23,7 @@ namespace Dawn { * * @param i Scene Item this interface belongs to. */ - SimpleBillboardedMaterial(SceneItem *i); + SimpleBillboardedMaterial(std::weak_ptr i); void onStart() override; void onDispose() override; diff --git a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp index 13c5f4c0..de0ccae9 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp +++ b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -SimpleTexturedMaterial::SimpleTexturedMaterial(SceneItem *i) : +SimpleTexturedMaterial::SimpleTexturedMaterial(std::weak_ptr i) : Material(i) { } @@ -24,7 +24,7 @@ void SimpleTexturedMaterial::onDispose() { std::vector SimpleTexturedMaterial::getRenderPasses(IRenderableContext &context) { - auto mesh = this->item->getComponent(); + auto mesh = this->item.lock()->getComponent(); auto shader = getShaderManager() .getShader(this->shaderLock) ; @@ -38,7 +38,7 @@ std::vector onlyPass.shader = shader; onlyPass.colorValues[shader->paramColor] = this->color; onlyPass.matrixValues[shader->paramModel] = - item->getWorldTransform() + item.lock()->getWorldTransform() ; onlyPass.parameterBuffers[ shader->bufferRenderPipeline diff --git a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.hpp b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.hpp index c88bbcf4..a5279c7b 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.hpp +++ b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.hpp @@ -25,7 +25,7 @@ namespace Dawn { * * @param i Scene Item this interface belongs to. */ - SimpleTexturedMaterial(SceneItem *i); + SimpleTexturedMaterial(std::weak_ptr i); void onStart() override; void onDispose() override; diff --git a/src/dawnrose/scene/components/GameCamera.cpp b/src/dawnrose/scene/components/GameCamera.cpp index b85b0c51..52ca0dd0 100644 --- a/src/dawnrose/scene/components/GameCamera.cpp +++ b/src/dawnrose/scene/components/GameCamera.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -GameCamera::GameCamera(SceneItem *i) : SceneItemComponent(i) {} +GameCamera::GameCamera(std::weak_ptr i) : SceneItemComponent(i) {} std::vector GameCamera::getDependencies() { return { diff --git a/src/dawnrose/scene/components/GameCamera.hpp b/src/dawnrose/scene/components/GameCamera.hpp index 902d9a73..3d9e593d 100644 --- a/src/dawnrose/scene/components/GameCamera.hpp +++ b/src/dawnrose/scene/components/GameCamera.hpp @@ -24,7 +24,7 @@ namespace Dawn { // @optional PlayerController *player = nullptr; - GameCamera(SceneItem *item); + GameCamera(std::weak_ptr item); std::vector getDependencies() override; void onStart() override; }; diff --git a/src/dawnrose/scene/components/PlayerController.cpp b/src/dawnrose/scene/components/PlayerController.cpp index b00737bf..e4fed046 100644 --- a/src/dawnrose/scene/components/PlayerController.cpp +++ b/src/dawnrose/scene/components/PlayerController.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -PlayerController::PlayerController(SceneItem *item) : SceneItemComponent(item) { +PlayerController::PlayerController(std::weak_ptr item) : SceneItemComponent(item) { } diff --git a/src/dawnrose/scene/components/PlayerController.hpp b/src/dawnrose/scene/components/PlayerController.hpp index df1d2724..a0ecf7f3 100644 --- a/src/dawnrose/scene/components/PlayerController.hpp +++ b/src/dawnrose/scene/components/PlayerController.hpp @@ -16,7 +16,7 @@ namespace Dawn { EntityShootingAttack *entityShootingAttack = nullptr; public: - PlayerController(SceneItem *item); + PlayerController(std::weak_ptr item); std::vector getDependencies() override; void onStart() override; }; diff --git a/src/dawnrose/scene/components/entity/EntityInteractable.hpp b/src/dawnrose/scene/components/entity/EntityInteractable.hpp index bb8fef80..7a0573e9 100644 --- a/src/dawnrose/scene/components/entity/EntityInteractable.hpp +++ b/src/dawnrose/scene/components/entity/EntityInteractable.hpp @@ -10,7 +10,7 @@ namespace Dawn { class EntityInteractable : public SceneItemComponent { public: - EntityInteractable(SceneItem *item); + EntityInteractable(std::weak_ptr item); /** * Called when one entity interacts with this entity. diff --git a/src/dawnrose/scenes/HelloWorldScene.hpp b/src/dawnrose/scenes/HelloWorldScene.hpp index 068d05ac..edf5b01e 100644 --- a/src/dawnrose/scenes/HelloWorldScene.hpp +++ b/src/dawnrose/scenes/HelloWorldScene.hpp @@ -40,7 +40,7 @@ namespace Dawn { // wallBox2->min = glm::vec2(-3, -4); // wallBox2->max = glm::vec2(3, -3); - camera = Camera::create(this); + camera = Camera::create(shared_from_this()); camera->fov = 0.436332f; camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0)); auto gameCamera = camera->item->addComponent();