More Progress
This commit is contained in:
47
src/dawn/scene/SceneItem.hpp
Normal file
47
src/dawn/scene/SceneItem.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SceneItemComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
typedef int32_t sceneitemid_t;
|
||||
|
||||
class Scene;
|
||||
|
||||
class SceneItem {
|
||||
private:
|
||||
std::vector<std::shared_ptr<SceneItemComponent>> components;
|
||||
|
||||
public:
|
||||
std::weak_ptr<Scene> scene;
|
||||
sceneitemid_t id;
|
||||
|
||||
SceneItem(std::weak_ptr<Scene> scene, sceneitemid_t id);
|
||||
|
||||
void init();
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> addComponent() {
|
||||
auto component = std::make_unique<T>(this);
|
||||
this->components.push_back(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> getComponent() {
|
||||
auto it = this->components.begin();
|
||||
while(it != this->components.end()) {
|
||||
std::shared_ptr<T> castedAs = dynamic_cast<std::shared_ptr<T>>(*it);
|
||||
if(castedAs != nullptr) return castedAs;
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
~SceneItem();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user