diff options
Diffstat (limited to 'yage')
-rw-r--r-- | yage/engine/component.h | 21 | ||||
-rw-r--r-- | yage/engine/system.h | 52 | ||||
-rw-r--r-- | yage/entity/engine.cpp (renamed from yage/engine/engine.cpp) | 14 | ||||
-rw-r--r-- | yage/entity/engine.h (renamed from yage/engine/engine.h) | 6 | ||||
-rw-r--r-- | yage/entity/entity.cpp (renamed from yage/engine/entity.cpp) | 0 | ||||
-rw-r--r-- | yage/entity/entity.h (renamed from yage/engine/entity.h) | 8 | ||||
-rw-r--r-- | yage/entity/entitymanager.cpp (renamed from yage/engine/entitymanager.cpp) | 0 | ||||
-rw-r--r-- | yage/entity/entitymanager.h (renamed from yage/engine/entitymanager.h) | 0 | ||||
-rw-r--r-- | yage/entity/space.cpp (renamed from yage/engine/space.cpp) | 0 | ||||
-rw-r--r-- | yage/entity/space.h (renamed from yage/engine/space.h) | 3 | ||||
-rw-r--r-- | yage/entity/system.h | 45 | ||||
-rw-r--r-- | yage/entity/systemmanager.h | 15 | ||||
-rw-r--r-- | yage/util/noncopyable.h | 19 | ||||
-rw-r--r-- | yage/yage.h | 3 |
14 files changed, 85 insertions, 101 deletions
diff --git a/yage/engine/component.h b/yage/engine/component.h deleted file mode 100644 index 9fd85d82..00000000 --- a/yage/engine/component.h +++ /dev/null @@ -1,21 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: component.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_ENGINE_COMPONENT_H -#define YAGE_ENGINE_COMPONENT_H - -class Component -{ -}; - -enum class ComponentEnum { - POSITION, - NAX_COMPONENTS, -}; - -#endif diff --git a/yage/engine/system.h b/yage/engine/system.h deleted file mode 100644 index 32d6fc34..00000000 --- a/yage/engine/system.h +++ /dev/null @@ -1,52 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: system.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_ENGINE_SYSTEM_H -#define YAGE_ENGINE_SYSTEM_H - -namespace yage -{ - -/** - * System interface for the different systems in the engine. - */ -class System -{ -public: - /** - * Virtual destructor to destroy all the objects that implement this - * properly. - */ - virtual ~System() = 0; - - /** - * Initializes the system. Good practice to have this function instead - * using the constructor. - */ - virtual void init() = 0; - - /** - * Updates the system at each interval using the time step. - * - * @param dt The time difference between the previous frame and the current one. - */ - virtual void update(double dt) = 0; -}; - -/** - * Implement the default destructor, but leaving it as purely virtual in the - * definition of the abstract class. This is so that the classes that implement - * the abstract class have to implement a desctructor, but at the same time, - * that there is no undefined behavious when the stack unwinds to the system and - * calls the system destructor. - */ -inline System::~System() {} - -} // namespace yage - -#endif diff --git a/yage/engine/engine.cpp b/yage/entity/engine.cpp index cf6f73b7..919cff7c 100644 --- a/yage/engine/engine.cpp +++ b/yage/entity/engine.cpp @@ -14,10 +14,6 @@ namespace yage void Engine::init() { window_.create("Game Engine", 800, 640); - - for (auto &system : systems_) { - system->init(); - } } void Engine::mainLoop() @@ -33,16 +29,6 @@ void Engine::mainLoop() void Engine::update() { - const double dt = 1.0 / 60.0; - - for (auto &system : systems_) { - system->update(dt); - } -} - -void Engine::addSystem(System *system) -{ - systems_.push_back(system); } Engine &Engine::instance() diff --git a/yage/engine/engine.h b/yage/entity/engine.h index 147769e5..6e1bf49a 100644 --- a/yage/engine/engine.h +++ b/yage/entity/engine.h @@ -31,17 +31,11 @@ public: /// Updates the systems. void update(); - /// Adds a system to the engine. - void addSystem(System *system); - /// Returns the instance of the engine, as there is only one instance of the /// engine. static Engine &instance(); private: - /// Vector of all the systems in the engine. - std::vector<System *> systems_; - /// Window Window window_; }; diff --git a/yage/engine/entity.cpp b/yage/entity/entity.cpp index 4d9a4b0a..4d9a4b0a 100644 --- a/yage/engine/entity.cpp +++ b/yage/entity/entity.cpp diff --git a/yage/engine/entity.h b/yage/entity/entity.h index c31490e5..e6742893 100644 --- a/yage/engine/entity.h +++ b/yage/entity/entity.h @@ -14,6 +14,8 @@ namespace yage { +typedef unsigned EntityHandle; + class Space; /** @@ -32,20 +34,20 @@ public: * This handle refers to the position of he Entity in the list that is held * by the EntityManager, and therefore the id is enough to refer to it. */ - Entity(unsigned handle); + Entity(EntityHandle handle); /** * Handle getter, as the user will only interact with the id itself. The * handle is the unique identifier that the user can use to refer to the * entity. */ - unsigned getHandle() const; + EntityHandle getHandle() const; private: /** * Entity handle for the entity manager. */ - unsigned handle_; + EntityHandle handle_; }; } // namespace yage diff --git a/yage/engine/entitymanager.cpp b/yage/entity/entitymanager.cpp index 332ed9b8..332ed9b8 100644 --- a/yage/engine/entitymanager.cpp +++ b/yage/entity/entitymanager.cpp diff --git a/yage/engine/entitymanager.h b/yage/entity/entitymanager.h index da125d94..da125d94 100644 --- a/yage/engine/entitymanager.h +++ b/yage/entity/entitymanager.h diff --git a/yage/engine/space.cpp b/yage/entity/space.cpp index f3e343b5..f3e343b5 100644 --- a/yage/engine/space.cpp +++ b/yage/entity/space.cpp diff --git a/yage/engine/space.h b/yage/entity/space.h index e69df37a..96154ffc 100644 --- a/yage/engine/space.h +++ b/yage/entity/space.h @@ -16,8 +16,6 @@ namespace yage { -class System; - /** * Space that keeps track of all the entities, componenets and runs the systems * on the data to update them. There can be multiple instances of a space, which @@ -47,7 +45,6 @@ private: * component. These are specific to the Space, as other spaces might have * different Systems and not act on the same entities. */ - std::vector<System *> systems_; /** * Manages all the entities in the system, can create them for the current diff --git a/yage/entity/system.h b/yage/entity/system.h new file mode 100644 index 00000000..47d176c9 --- /dev/null +++ b/yage/entity/system.h @@ -0,0 +1,45 @@ +/** --------------------------------------------------------------------------- + * @file: system.h + * + * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_ENGINE_SYSTEM_H +#define YAGE_ENGINE_SYSTEM_H + +#include <cstddef> + +#include "../util/noncopyable.h" + +namespace yage +{ + +class BaseSystem : public yage::NonCopyable +{ +public: + typedef std::size_t Identifier; + + virtual void update() = 0; + +protected: + Identifier id_; +}; + +/** + * System interface for the different systems in the engine. + */ +template <typename Derived> +class System : public BaseSystem +{ +public: +}; + +class SystemManager : public yage::NonCopyable { + +}; + +} // namespace yage + +#endif diff --git a/yage/entity/systemmanager.h b/yage/entity/systemmanager.h new file mode 100644 index 00000000..5351e4bb --- /dev/null +++ b/yage/entity/systemmanager.h @@ -0,0 +1,15 @@ +#ifndef YAGE_ENTITY_SYSTEMMANAGER_H +#define YAGE_ENTITY_SYSTEMMANAGER_H + +#include <unordered_map> + +namespace yage { + +class SystemManager { +private: + std::unordered_map +}; + +} // namespace yage + +#endif diff --git a/yage/util/noncopyable.h b/yage/util/noncopyable.h new file mode 100644 index 00000000..f1325ed1 --- /dev/null +++ b/yage/util/noncopyable.h @@ -0,0 +1,19 @@ +#ifndef YAGE_UTIL_NONCOPYABLE_H +#define YAGE_UTIL_NONCOPYABLE_H + +namespace yage +{ + +class NonCopyable +{ +protected: + NonCopyable() = default; + ~NonCopyable() = default; + + NonCopyable(const NonCopyable &) = delete; + NonCopyable &operator=(const NonCopyable &) = delete; +}; + +} // namespace yage + +#endif diff --git a/yage/yage.h b/yage/yage.h index ed21d245..d5b34603 100644 --- a/yage/yage.h +++ b/yage/yage.h @@ -50,8 +50,7 @@ * Engine that includes a Entity Component System to organize the data and make * it more flexible and efficient. */ -#include "engine/engine.h" - +#include "entity/engine.h" /** * Project namespace. * |