// Copyright (c) 2022 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "SceneItem.hpp" namespace Dawn { class DawnGame; class Scene : public std::enable_shared_from_this { private: sceneitemid_t nextId; std::map> items; std::map> itemsNotInitialized; public: std::weak_ptr game; /** * Construct a new Scene instance. * * @param game Weak pointer to the game that this scene belongs to. */ Scene(std::weak_ptr game); /** * Perform a one frame synchronous tick on the current scene. This may * change in future to be more event-like. */ void update(); /** * Create a Scene Item object and add to the current scene. * * @return A shared pointer to the created SceneItem. */ std::shared_ptr createSceneItem(); /** * Finds an existing component on the scene (Root Level Only) that has a * component matching the given component type. Returns nullptr if no item * with the specified component could be found. * * @tparam Component type to look for. * @return Pointer to the found component (and by extension the item). */ template std::shared_ptr findComponent() { auto it = this->items.begin(); while(it != this->items.end()) { auto component = it->second->getComponent(); if(component != nullptr) return component; ++it; } return nullptr; } /** * Destroys a previously initialized Scene. */ ~Scene(); }; }