45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
// Copyright (c) 2024 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "SceneItem.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
SceneItem::SceneItem(
|
|
std::weak_ptr<SceneItem> parent,
|
|
std::weak_ptr<Scene> scene
|
|
) :
|
|
parent(parent),
|
|
scene(scene)
|
|
{
|
|
}
|
|
|
|
std::shared_ptr<SceneItem> SceneItem::getParent() {
|
|
return parent.lock();
|
|
}
|
|
|
|
std::shared_ptr<Scene> SceneItem::getScene() {
|
|
return scene.lock();
|
|
}
|
|
|
|
void SceneItem::removeSceneItem(std::shared_ptr<SceneItem> item) {
|
|
// I don't need to go through the trouble of removing items if I'm already
|
|
// disposing, since I'll be clearing them all anyway.
|
|
if(isDisposing) return;
|
|
|
|
auto it = std::find(items.begin(), items.end(), item);
|
|
if(it != items.end()) items.erase(it);
|
|
}
|
|
|
|
SceneItem::~SceneItem() {
|
|
this->isDisposing = true;
|
|
|
|
// Clear children first, saves them trying to remove themselves from me.
|
|
this->items.clear();
|
|
|
|
// Now remove myself from my parent.
|
|
auto parent = this->getParent();
|
|
if(parent) parent->removeSceneItem(shared_from_this());
|
|
} |