mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-06-28 18:15:16 -04:00
Make the AddComponent function safe
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifndef VOID_ENTITY_H
|
||||
#define VOID_ENTITY_H
|
||||
#include "component.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class Entity {
|
||||
@@ -15,7 +16,7 @@ public:
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
std::vector<Component> components;
|
||||
std::vector<std::unique_ptr<Component>> components;
|
||||
};
|
||||
|
||||
#include "../src/entity_i.cpp"
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
#ifndef VOID_ENTITY_H
|
||||
#include "../include/entity.h"
|
||||
#endif
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
template <typename CompT, typename... Args>
|
||||
Component *Entity::AddComponent(Args &&...args) {
|
||||
return components.emplace_back(std::forward<Args>(args)...);
|
||||
components.push_back(std::make_unique(std::forward<Args>(args)...));
|
||||
return components.back().get();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user