// Copyright (c) 2022 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "SceneItem.hpp" #include "SceneItemComponent.hpp" using namespace Dawn; SceneItem::SceneItem(Scene *scene, sceneitemid_t id) : transform(this) { assertNotNull(scene); this->id = id; this->scene = scene; } void SceneItem::init() { // Keep checking all components until they have all inited int32_t waitingOn; do { waitingOn = 0; // For each component auto it = this->components.begin(); while(it != this->components.end()) { // Has this component already inited? if((*it)->hasInitialized) { ++it; continue; } // For each dependency. auto deps = (*it)->getDependencies(); bool_t waiting = false; auto it2 = deps.begin(); while(it2 != deps.end()) { if(*it2 == nullptr) { ++it2; continue; } // Has the dep not yet inited? if(!(*it2)->hasInitialized) { waiting = true; break; } ++it2; } // Are we waiting for a dep? if(waiting) { waitingOn++; } else { (*it)->init(); } ++it; } } while(waitingOn != 0); } void SceneItem::destroy() { auto it = this->components.begin(); while(it != this->components.end()) { (*it)->onDispose(); ++it; } } SceneItem::~SceneItem() { auto it = this->components.begin(); it = this->components.begin(); while(it != this->components.end()) { delete *it; ++it; } }