mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-06-20 07:25:11 -04:00
Compare commits
9 Commits
8e3420f32a
...
650925b4e1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
650925b4e1 | ||
|
|
1166bc8911 | ||
|
|
4afd985a50 | ||
|
|
45c7b2412c | ||
|
|
03c3a75232 | ||
|
|
f99daa2f9d | ||
|
|
3c309da421 | ||
|
|
9d9a574b87 | ||
|
|
63477b20f5 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
build*/
|
||||||
@@ -4,10 +4,10 @@ project(VoidEngine VERSION 1.0.0 LANGUAGES CXX)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp" "include/*.h")
|
||||||
|
|
||||||
add_library(${PROJECT_NAME}
|
add_library(${PROJECT_NAME}
|
||||||
STATIC
|
STATIC ${SOURCE_FILES}
|
||||||
src/*.cpp
|
|
||||||
include/*.hpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
|||||||
14
include/component.h
Normal file
14
include/component.h
Normal 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
include/entity.h
Normal file
21
include/entity.h
Normal 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 +0,0 @@
|
|||||||
// Public code time!
|
|
||||||
7
src/entity.cpp
Normal file
7
src/entity.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "../include/entity.h"
|
||||||
|
|
||||||
|
void Entity::Update() {
|
||||||
|
for (auto &comp : components) {
|
||||||
|
comp.get()->Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/entity_i.cpp
Normal file
23
src/entity_i.cpp
Normal 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 +0,0 @@
|
|||||||
// Code time!
|
|
||||||
Reference in New Issue
Block a user