Dawn/src/dawn/scene/SceneItem.hpp

82 lines
2.1 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/item/SceneItemTransform.hpp"
#include "scene/item/SceneItemComponents.hpp"
namespace Dawn {
class Scene;
enum class SceneItemState : flag_t {
INITIAL = FLAG(0),
INITIALIZED = FLAG(1),
DEINITIALIZED = FLAG(2),
};
class SceneItem final :
public SceneItemTransform,
public SceneItemComponents,
public std::enable_shared_from_this<SceneItem>
{
private:
std::weak_ptr<Scene> scene;
flag_t state = (flag_t)SceneItemState::INITIAL;
protected:
std::shared_ptr<SceneItem> sceneItemComponentsSelf() override;
public:
std::string name;
/**
* Constructs a scene item.
*
* @param scene Scene that this item belongs to.
*/
SceneItem(const std::weak_ptr<Scene> scene);
/**
* Called when the scene item is supposed to initialize. Should happen
* on the first frame that the scene item is staged.
*/
void init();
/**
* Called when the scene item is supposed to deinitialize. Should happen
* when the scene item is removed from the scene.
*/
void deinit();
/**
* Loads this scene item from the given context. Scene items are not
* responsible for loading their components, this is handled by the scene
* loader.
*
* @param ctx Context to load this scene item from.
*/
void load(std::shared_ptr<SceneLoadContext> ctx);
/**
* Returns the scene that this scene item belongs to.
*
* @return Pointer to the scene that this item belongs to.
*/
std::shared_ptr<Scene> getScene();
/**
* Queues this scene item to be removed from the scene (on the next scene
* update).
*/
void remove();
/**
* Returns the scene that this item belongs to.
*
* @return Scene that this item belongs to.
*/
virtual ~SceneItem();
};
}