mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-10-12 02:10:08 -04:00
Namespace project & add RemoveComponent
This commit is contained in:
1 parent
af7adaa6f2
commit
a730e82247
4 files changed
+22
-3
No files matched your search
@@ -1,5 +1,7 @@
|
||||
#include "../include/entity.h"
|
||||
|
||||
using namespace VoidFrame;
|
||||
|
||||
void Entity::Update() {
|
||||
for (auto &comp : components) {
|
||||
comp.get()->Update();
|
||||
|
||||
+11
-3
@@ -2,9 +2,8 @@
|
||||
#ifndef VOID_ENTITY_H
|
||||
#include "../include/entity.h"
|
||||
#endif
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using namespace VoidFrame;
|
||||
|
||||
template <typename CompT, typename... Args>
|
||||
CompT *Entity::AddComponent(Args &&...args) {
|
||||
@@ -24,3 +23,12 @@ template <typename CompT> CompT *Entity::GetComponent() {
|
||||
template <typename CompT> bool Entity::HasComponent() {
|
||||
return GetComponent<CompT>() != nullptr;
|
||||
}
|
||||
|
||||
template <typename CompT> void Entity::RemoveComponent() {
|
||||
components.erase(std::remove_if(components.begin(), components.end(),
|
||||
[](const std::unique_ptr<Component> &comp) {
|
||||
return dynamic_cast<CompT *>(comp.get()) !=
|
||||
nullptr;
|
||||
}),
|
||||
components.end());
|
||||
}
|
||||
Reference in new issue
Block a user