Compare commits

..
9 Commits
8 changed files with 69 additions and 5 deletions
+1
View File
@@ -0,0 +1 @@
build*/
+3 -3
View File
@@ -4,10 +4,10 @@ project(VoidEngine VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp" "include/*.h")
add_library(${PROJECT_NAME}
STATIC
src/*.cpp
include/*.hpp
STATIC ${SOURCE_FILES}
)
target_include_directories(${PROJECT_NAME}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
class Entity;
class Component {
public:
virtual void Init();
virtual void Draw();
virtual void Update();
virtual void FixedUpdate();
virtual void Destroy();
private:
Entity *owner;
};
+21
View File
@@ -0,0 +1,21 @@
#ifndef VOID_ENTITY_H
#define VOID_ENTITY_H
#include "component.h"
#include <memory>
#include <vector>
class Entity {
public:
template <typename CompT, typename... Args>
Component *AddComponent(Args &&...args);
template <typename CompT> CompT *GetComponent();
template <typename CompT> bool HasComponent();
void Update();
private:
std::vector<std::unique_ptr<Component>> components;
};
#include "../src/entity_i.cpp"
#endif // VOID_ENTITY_H
-1
View File
@@ -1 +0,0 @@
// Public code time!
+7
View File
@@ -0,0 +1,7 @@
#include "../include/entity.h"
void Entity::Update() {
for (auto &comp : components) {
comp.get()->Update();
}
}
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#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) {
components.push_back(std::make_unique<CompT>(std::forward<Args>(args)...));
return components.back().get();
}
template <typename CompT> CompT *Entity::GetComponent() {
for (const auto &comp_ptr : components) {
return dynamic_cast<CompT *>(comp_ptr.get());
}
}
template <typename CompT> bool Entity::HasComponent() {
return GetComponent<CompT>() != nullptr;
}
-1
View File
@@ -1 +0,0 @@
// Code time!