mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-06-28 19:35:12 -04:00
Make the AddComponent function safe
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#ifndef VOID_ENTITY_H
|
#ifndef VOID_ENTITY_H
|
||||||
#define VOID_ENTITY_H
|
#define VOID_ENTITY_H
|
||||||
#include "component.h"
|
#include "component.h"
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class Entity {
|
class Entity {
|
||||||
@@ -15,7 +16,7 @@ public:
|
|||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Component> components;
|
std::vector<std::unique_ptr<Component>> components;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "../src/entity_i.cpp"
|
#include "../src/entity_i.cpp"
|
||||||
|
|||||||
@@ -2,8 +2,12 @@
|
|||||||
#ifndef VOID_ENTITY_H
|
#ifndef VOID_ENTITY_H
|
||||||
#include "../include/entity.h"
|
#include "../include/entity.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
template <typename CompT, typename... Args>
|
template <typename CompT, typename... Args>
|
||||||
Component *Entity::AddComponent(Args &&...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