mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-06-28 18:15:16 -04:00
Fix Entity functions sofar
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
class Entity {
|
||||
public:
|
||||
template <typename CompT, typename... Args>
|
||||
Component *AddComponent(Args &&...args);
|
||||
CompT *AddComponent(Args &&...args);
|
||||
template <typename CompT> CompT *GetComponent();
|
||||
template <typename CompT> bool HasComponent();
|
||||
|
||||
|
||||
@@ -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