Example Triangle Pog
This commit is contained in:
@ -11,7 +11,9 @@ namespace Dawn {
|
||||
|
||||
class Scene;
|
||||
|
||||
class SceneItem {
|
||||
class SceneItem :
|
||||
public std::enable_shared_from_this<SceneItem>
|
||||
{
|
||||
private:
|
||||
std::vector<std::shared_ptr<SceneItemComponent>> components;
|
||||
|
||||
@ -25,7 +27,7 @@ namespace Dawn {
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> addComponent() {
|
||||
auto component = std::make_unique<T>(this);
|
||||
auto component = std::make_shared<T>(weak_from_this());
|
||||
this->components.push_back(component);
|
||||
return component;
|
||||
}
|
||||
@ -34,10 +36,9 @@ namespace Dawn {
|
||||
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);
|
||||
auto castedAs = std::dynamic_pointer_cast<T>(*it);
|
||||
if(castedAs != nullptr) return castedAs;
|
||||
it++;
|
||||
continue;
|
||||
++it;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user