mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-08-13 02:28:41 -04:00
Fix Entity::GetComponent()
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ class Entity {
|
|||||||
public:
|
public:
|
||||||
template <typename CompT, typename... Args>
|
template <typename CompT, typename... Args>
|
||||||
Component *AddComponent(Args &&...args);
|
Component *AddComponent(Args &&...args);
|
||||||
template <typename CompT> Component *GetComponent();
|
template <typename CompT> CompT *GetComponent();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -8,13 +8,12 @@
|
|||||||
|
|
||||||
template <typename CompT, typename... Args>
|
template <typename CompT, typename... Args>
|
||||||
Component *Entity::AddComponent(Args &&...args) {
|
Component *Entity::AddComponent(Args &&...args) {
|
||||||
components.push_back(std::make_unique(std::forward<Args>(args)...));
|
components.push_back(std::make_unique<CompT>(std::forward<Args>(args)...));
|
||||||
return components.back().get();
|
return components.back().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename CompT> Component *Entity::GetComponent() {
|
template <typename CompT> CompT *Entity::GetComponent() {
|
||||||
for (const auto &comp_ptr : components) {
|
for (const auto &comp_ptr : components) {
|
||||||
if (auto *comp = dynamic_cast<CompT *>(comp_ptr.get()))
|
return dynamic_cast<CompT *>(comp_ptr.get());
|
||||||
return comp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user