mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-10-12 02:10:08 -04:00
Fix Entity functions sofar
This commit is contained in:
1 parent
650925b4e1
commit
af7adaa6f2
2 files changed
+9
-6
No files matched your search
+8
-5
@@ -7,14 +7,17 @@
|
||||
#include <vector>
|
||||
|
||||
template <typename CompT, typename... Args>
|
||||
Component *Entity::AddComponent(Args &&...args) {
|
||||
components.push_back(std::make_unique<CompT>(std::forward<Args>(args)...));
|
||||
return components.back().get();
|
||||
CompT *Entity::AddComponent(Args &&...args) {
|
||||
CompT *component = new CompT(std::forward<Args>(args)...);
|
||||
component->owner = this;
|
||||
components.emplace_back(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
template <typename CompT> CompT *Entity::GetComponent() {
|
||||
for (const auto &comp_ptr : components) {
|
||||
return dynamic_cast<CompT *>(comp_ptr.get());
|
||||
for (auto &comp_ptr : components) {
|
||||
if (CompT *casted = dynamic_cast<CompT *>(comp_ptr.get()))
|
||||
return casted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user