67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
// 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<Scene>
|
|
{
|
|
private:
|
|
sceneitemid_t nextId;
|
|
std::map<sceneitemid_t,std::shared_ptr<SceneItem>> items;
|
|
std::map<sceneitemid_t,std::shared_ptr<SceneItem>> itemsNotInitialized;
|
|
|
|
public:
|
|
std::weak_ptr<DawnGame> game;
|
|
|
|
/**
|
|
* Construct a new Scene instance.
|
|
*
|
|
* @param game Weak pointer to the game that this scene belongs to.
|
|
*/
|
|
Scene(std::weak_ptr<DawnGame> 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<SceneItem> 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<class T>
|
|
std::shared_ptr<T> findComponent() {
|
|
auto it = this->items.begin();
|
|
while(it != this->items.end()) {
|
|
auto component = it->second->getComponent<T>();
|
|
if(component != nullptr) return component;
|
|
++it;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
/**
|
|
* Destroys a previously initialized Scene.
|
|
*/
|
|
~Scene();
|
|
};
|
|
} |