mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-06-17 17:05:11 -04:00
Compare commits
2 Commits
af7adaa6f2
...
27eb6ff7bb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27eb6ff7bb | ||
|
|
a730e82247 |
@@ -1,14 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
namespace VoidFrame {
|
||||||
class Entity;
|
class Entity;
|
||||||
|
|
||||||
class Component {
|
class Component {
|
||||||
public:
|
public:
|
||||||
virtual void Init();
|
|
||||||
virtual void Draw();
|
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
virtual void FixedUpdate();
|
|
||||||
virtual void Destroy();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Entity *owner;
|
Entity *owner;
|
||||||
};
|
};
|
||||||
|
} // namespace VoidFrame
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
#ifndef VOID_ENTITY_H
|
#ifndef VOID_ENTITY_H
|
||||||
#define VOID_ENTITY_H
|
#define VOID_ENTITY_H
|
||||||
#include "component.h"
|
#include "component.h"
|
||||||
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace VoidFrame {
|
||||||
|
|
||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
template <typename CompT, typename... Args>
|
template <typename CompT, typename... Args>
|
||||||
CompT *AddComponent(Args &&...args);
|
CompT *AddComponent(Args &&...args);
|
||||||
template <typename CompT> CompT *GetComponent();
|
template <typename CompT> CompT *GetComponent();
|
||||||
template <typename CompT> bool HasComponent();
|
template <typename CompT> bool HasComponent();
|
||||||
|
template <typename CompT> void RemoveComponent();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
@@ -18,4 +23,5 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#include "../src/entity_i.cpp"
|
#include "../src/entity_i.cpp"
|
||||||
|
} // namespace VoidFrame
|
||||||
#endif // VOID_ENTITY_H
|
#endif // VOID_ENTITY_H
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "../include/entity.h"
|
#include "../include/entity.h"
|
||||||
|
|
||||||
|
using namespace VoidFrame;
|
||||||
|
|
||||||
void Entity::Update() {
|
void Entity::Update() {
|
||||||
for (auto &comp : components) {
|
for (auto &comp : components) {
|
||||||
comp.get()->Update();
|
comp.get()->Update();
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
#ifndef VOID_ENTITY_H
|
#ifndef VOID_ENTITY_H
|
||||||
#include "../include/entity.h"
|
#include "../include/entity.h"
|
||||||
#endif
|
#endif
|
||||||
#include <memory>
|
|
||||||
#include <utility>
|
using namespace VoidFrame;
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
template <typename CompT, typename... Args>
|
template <typename CompT, typename... Args>
|
||||||
CompT *Entity::AddComponent(Args &&...args) {
|
CompT *Entity::AddComponent(Args &&...args) {
|
||||||
@@ -24,3 +23,12 @@ template <typename CompT> CompT *Entity::GetComponent() {
|
|||||||
template <typename CompT> bool Entity::HasComponent() {
|
template <typename CompT> bool Entity::HasComponent() {
|
||||||
return GetComponent<CompT>() != nullptr;
|
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