mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-06-28 19:35:12 -04:00
Fix Entity functions sofar
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
template <typename CompT, typename... Args>
|
template <typename CompT, typename... Args>
|
||||||
Component *AddComponent(Args &&...args);
|
CompT *AddComponent(Args &&...args);
|
||||||
template <typename CompT> CompT *GetComponent();
|
template <typename CompT> CompT *GetComponent();
|
||||||
template <typename CompT> bool HasComponent();
|
template <typename CompT> bool HasComponent();
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,17 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
template <typename CompT, typename... Args>
|
template <typename CompT, typename... Args>
|
||||||
Component *Entity::AddComponent(Args &&...args) {
|
CompT *Entity::AddComponent(Args &&...args) {
|
||||||
components.push_back(std::make_unique<CompT>(std::forward<Args>(args)...));
|
CompT *component = new CompT(std::forward<Args>(args)...);
|
||||||
return components.back().get();
|
component->owner = this;
|
||||||
|
components.emplace_back(component);
|
||||||
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename CompT> CompT *Entity::GetComponent() {
|
template <typename CompT> CompT *Entity::GetComponent() {
|
||||||
for (const auto &comp_ptr : components) {
|
for (auto &comp_ptr : components) {
|
||||||
return dynamic_cast<CompT *>(comp_ptr.get());
|
if (CompT *casted = dynamic_cast<CompT *>(comp_ptr.get()))
|
||||||
|
return casted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user