From e9bd903761605c7619a235edddf07c3a0b963968 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 8 Feb 2018 20:48:49 +0000 Subject: [Engine] More entity component systems options. --- yage/engine/system.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'yage') diff --git a/yage/engine/system.h b/yage/engine/system.h index 32d6fc34..9100fa17 100644 --- a/yage/engine/system.h +++ b/yage/engine/system.h @@ -36,6 +36,11 @@ public: * @param dt The time difference between the previous frame and the current one. */ virtual void update(double dt) = 0; + + /** + * Destroy the system and the components that are contained in it. + */ + virtual void destroy() = 0; }; /** -- cgit From 49af8b16ae3f9e6579656ed10f815e9c465557d0 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Tue, 13 Feb 2018 19:14:33 +0000 Subject: [entity] Starting work on entity system. --- yage/engine/component.h | 21 ----------- yage/engine/engine.cpp | 55 ---------------------------- yage/engine/engine.h | 51 -------------------------- yage/engine/entity.cpp | 23 ------------ yage/engine/entity.h | 53 --------------------------- yage/engine/entitymanager.cpp | 34 ------------------ yage/engine/entitymanager.h | 83 ------------------------------------------- yage/engine/space.cpp | 21 ----------- yage/engine/space.h | 61 ------------------------------- yage/engine/system.h | 57 ----------------------------- yage/entity/engine.cpp | 55 ++++++++++++++++++++++++++++ yage/entity/engine.h | 51 ++++++++++++++++++++++++++ yage/entity/entity.cpp | 23 ++++++++++++ yage/entity/entity.h | 55 ++++++++++++++++++++++++++++ yage/entity/entitymanager.cpp | 34 ++++++++++++++++++ yage/entity/entitymanager.h | 83 +++++++++++++++++++++++++++++++++++++++++++ yage/entity/space.cpp | 21 +++++++++++ yage/entity/space.h | 61 +++++++++++++++++++++++++++++++ yage/entity/system.h | 57 +++++++++++++++++++++++++++++ yage/util/noncopyable.h | 19 ++++++++++ yage/yage.h | 3 +- 21 files changed, 460 insertions(+), 461 deletions(-) delete mode 100644 yage/engine/component.h delete mode 100644 yage/engine/engine.cpp delete mode 100644 yage/engine/engine.h delete mode 100644 yage/engine/entity.cpp delete mode 100644 yage/engine/entity.h delete mode 100644 yage/engine/entitymanager.cpp delete mode 100644 yage/engine/entitymanager.h delete mode 100644 yage/engine/space.cpp delete mode 100644 yage/engine/space.h delete mode 100644 yage/engine/system.h create mode 100644 yage/entity/engine.cpp create mode 100644 yage/entity/engine.h create mode 100644 yage/entity/entity.cpp create mode 100644 yage/entity/entity.h create mode 100644 yage/entity/entitymanager.cpp create mode 100644 yage/entity/entitymanager.h create mode 100644 yage/entity/space.cpp create mode 100644 yage/entity/space.h create mode 100644 yage/entity/system.h create mode 100644 yage/util/noncopyable.h (limited to 'yage') 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 - * 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/engine.cpp b/yage/engine/engine.cpp deleted file mode 100644 index cf6f73b7..00000000 --- a/yage/engine/engine.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: engine.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "engine.h" - -namespace yage -{ - -void Engine::init() -{ - window_.create("Game Engine", 800, 640); - - for (auto &system : systems_) { - system->init(); - } -} - -void Engine::mainLoop() -{ - while (!window_.shouldClose()) { - window_.clearBuffer(); - - update(); - - window_.swapBuffer(); - } -} - -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() -{ - static Engine engine_instance; - - return engine_instance; -} - -} // namespace yage diff --git a/yage/engine/engine.h b/yage/engine/engine.h deleted file mode 100644 index 147769e5..00000000 --- a/yage/engine/engine.h +++ /dev/null @@ -1,51 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: engine.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_CORE_ENGINE_H -#define YAGE_CORE_ENGINE_H - -#include "../core/window.h" -#include "system.h" - -#include - -namespace yage -{ - -/// Main engine class that contains a systems, the main loop and the update -/// function that updates all the systems. -class Engine -{ -public: - /// Initialize window and other aspects of the engine. - void init(); - - /// Main game loop of the engine. - void mainLoop(); - - /// 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 systems_; - - /// Window - Window window_; -}; - -} // namespace yage - -#endif diff --git a/yage/engine/entity.cpp b/yage/engine/entity.cpp deleted file mode 100644 index 4d9a4b0a..00000000 --- a/yage/engine/entity.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: entity.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "entity.h" - -#include "space.h" - -namespace yage -{ - -Entity::Entity(unsigned handle) : handle_(handle) {} - -unsigned Entity::getHandle() const -{ - return handle_; -} - -} // naemspace yage diff --git a/yage/engine/entity.h b/yage/engine/entity.h deleted file mode 100644 index c31490e5..00000000 --- a/yage/engine/entity.h +++ /dev/null @@ -1,53 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: entity.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_ENGINE_ENTITY_H -#define YAGE_ENGINE_ENTITY_H - -#include - -namespace yage -{ - -class Space; - -/** - * Entity convenience class. It contains handles to where the entity is in the - * entity manager of the space, and a pointer back to the space itself. - * - * This class cannot be instantiated outside of a Space and should only be - * instantiated through an entity manager, as otherwise the handle will not have - * a meaning. - */ -class Entity -{ -public: - /** - * Creates an instance of an Entity with a handle that is associated to it. - * 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); - - /** - * 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; - -private: - /** - * Entity handle for the entity manager. - */ - unsigned handle_; -}; - -} // namespace yage - -#endif diff --git a/yage/engine/entitymanager.cpp b/yage/engine/entitymanager.cpp deleted file mode 100644 index 332ed9b8..00000000 --- a/yage/engine/entitymanager.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: entitymanager.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "entitymanager.h" - -namespace yage -{ - -EntityManager::EntityManager(Space *space) : next_handle_(0), space_(space) {} - -EntityManager::EntityManager(Space *space, std::size_t n) - : next_handle_(0), space_(space) -{ - entities_.reserve(n); -} - -unsigned EntityManager::createEntity() -{ - return createEntityInstance().getHandle(); -} - -Entity EntityManager::createEntityInstance() -{ - Entity entity(next_handle_++); - entities_.push_back(entity); - return entity; -} - -} // namespace yage diff --git a/yage/engine/entitymanager.h b/yage/engine/entitymanager.h deleted file mode 100644 index da125d94..00000000 --- a/yage/engine/entitymanager.h +++ /dev/null @@ -1,83 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: entitymanager.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_ENGINE_ENTITYMANAGER_H -#define YAGE_ENGINE_ENTITYMANAGER_H - -#include "entity.h" - -#include - -namespace yage -{ - -class Space; - -/** - * Manages entities in a space. - */ -class EntityManager -{ -public: - /** - * Default instance of an EntityManager. - */ - EntityManager() = default; - - /** - * Creates an instance of the entity manager, which refers back to the space - * it was created in and belongs to. - * - * @param space Current space that the EntityManager belongs to. - */ - EntityManager(Space *space); - - /** - * Creates an instance of the entitiy manager with an initial size. - * - * @param space Current space that the EntityManager belongs to. - * @param n Initial size of the EntityManager. - */ - EntityManager(Space *space, std::size_t n); - - /** - * Creates an Entity and returns the handle to the entity, which can then be - * used by the user to do operations on it. - * - * @return The handle to the entity that was created in the space. - */ - unsigned createEntity(); - - /** - * Creates an Entity and returns it. - * - * @return The entity that was created by the entity manager in the current - * space. - */ - Entity createEntityInstance(); - -private: - /** - * The next available handle to give to the user. - */ - unsigned next_handle_; - - /** - * The space that the entity manager belongs to. - */ - Space *space_; - - /** - * The entities in the current space. - */ - std::vector entities_; -}; - -} // namespace yage - -#endif diff --git a/yage/engine/space.cpp b/yage/engine/space.cpp deleted file mode 100644 index f3e343b5..00000000 --- a/yage/engine/space.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: space.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "space.h" - -namespace yage -{ - -Space::Space() : em_(this) {} - -unsigned Space::createEntity() -{ - return em_.createEntity(); -} - -} // namespace yage diff --git a/yage/engine/space.h b/yage/engine/space.h deleted file mode 100644 index e69df37a..00000000 --- a/yage/engine/space.h +++ /dev/null @@ -1,61 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: space.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_ENGINE_SPACE_H -#define YAGE_ENGINE_SPACE_H - -#include - -#include "entitymanager.h" - -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 - * can be used, for example, for different levels in the game that can be loaded - * separately, or a game menu that can be loaded above the other spaces when the - * user presses on pause. - */ -class Space -{ -public: - /** - * Default instance for a space. - */ - Space(); - - /** - * Create an entity that will belong to this space, and return the handle to - * the user. The Entity class itself should not be visible to the user, as - * the user only needs to worry about the handle when referring to the - * Entity and changing it. - */ - unsigned createEntity(); - -private: - /** - * The subspaces of the Space that act on the data and on their respective - * component. These are specific to the Space, as other spaces might have - * different Systems and not act on the same entities. - */ - std::vector systems_; - - /** - * Manages all the entities in the system, can create them for the current - * space. - */ - EntityManager em_; -}; - -} // namespace yage - -#endif diff --git a/yage/engine/system.h b/yage/engine/system.h deleted file mode 100644 index 9100fa17..00000000 --- a/yage/engine/system.h +++ /dev/null @@ -1,57 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: system.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * 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; - - /** - * Destroy the system and the components that are contained in it. - */ - virtual void destroy() = 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/entity/engine.cpp b/yage/entity/engine.cpp new file mode 100644 index 00000000..cf6f73b7 --- /dev/null +++ b/yage/entity/engine.cpp @@ -0,0 +1,55 @@ +/** --------------------------------------------------------------------------- + * @file: engine.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include "engine.h" + +namespace yage +{ + +void Engine::init() +{ + window_.create("Game Engine", 800, 640); + + for (auto &system : systems_) { + system->init(); + } +} + +void Engine::mainLoop() +{ + while (!window_.shouldClose()) { + window_.clearBuffer(); + + update(); + + window_.swapBuffer(); + } +} + +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() +{ + static Engine engine_instance; + + return engine_instance; +} + +} // namespace yage diff --git a/yage/entity/engine.h b/yage/entity/engine.h new file mode 100644 index 00000000..147769e5 --- /dev/null +++ b/yage/entity/engine.h @@ -0,0 +1,51 @@ +/** --------------------------------------------------------------------------- + * @file: engine.h + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_CORE_ENGINE_H +#define YAGE_CORE_ENGINE_H + +#include "../core/window.h" +#include "system.h" + +#include + +namespace yage +{ + +/// Main engine class that contains a systems, the main loop and the update +/// function that updates all the systems. +class Engine +{ +public: + /// Initialize window and other aspects of the engine. + void init(); + + /// Main game loop of the engine. + void mainLoop(); + + /// 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 systems_; + + /// Window + Window window_; +}; + +} // namespace yage + +#endif diff --git a/yage/entity/entity.cpp b/yage/entity/entity.cpp new file mode 100644 index 00000000..4d9a4b0a --- /dev/null +++ b/yage/entity/entity.cpp @@ -0,0 +1,23 @@ +/** --------------------------------------------------------------------------- + * @file: entity.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include "entity.h" + +#include "space.h" + +namespace yage +{ + +Entity::Entity(unsigned handle) : handle_(handle) {} + +unsigned Entity::getHandle() const +{ + return handle_; +} + +} // naemspace yage diff --git a/yage/entity/entity.h b/yage/entity/entity.h new file mode 100644 index 00000000..e6742893 --- /dev/null +++ b/yage/entity/entity.h @@ -0,0 +1,55 @@ +/** --------------------------------------------------------------------------- + * @file: entity.h + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_ENGINE_ENTITY_H +#define YAGE_ENGINE_ENTITY_H + +#include + +namespace yage +{ + +typedef unsigned EntityHandle; + +class Space; + +/** + * Entity convenience class. It contains handles to where the entity is in the + * entity manager of the space, and a pointer back to the space itself. + * + * This class cannot be instantiated outside of a Space and should only be + * instantiated through an entity manager, as otherwise the handle will not have + * a meaning. + */ +class Entity +{ +public: + /** + * Creates an instance of an Entity with a handle that is associated to it. + * 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(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. + */ + EntityHandle getHandle() const; + +private: + /** + * Entity handle for the entity manager. + */ + EntityHandle handle_; +}; + +} // namespace yage + +#endif diff --git a/yage/entity/entitymanager.cpp b/yage/entity/entitymanager.cpp new file mode 100644 index 00000000..332ed9b8 --- /dev/null +++ b/yage/entity/entitymanager.cpp @@ -0,0 +1,34 @@ +/** --------------------------------------------------------------------------- + * @file: entitymanager.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include "entitymanager.h" + +namespace yage +{ + +EntityManager::EntityManager(Space *space) : next_handle_(0), space_(space) {} + +EntityManager::EntityManager(Space *space, std::size_t n) + : next_handle_(0), space_(space) +{ + entities_.reserve(n); +} + +unsigned EntityManager::createEntity() +{ + return createEntityInstance().getHandle(); +} + +Entity EntityManager::createEntityInstance() +{ + Entity entity(next_handle_++); + entities_.push_back(entity); + return entity; +} + +} // namespace yage diff --git a/yage/entity/entitymanager.h b/yage/entity/entitymanager.h new file mode 100644 index 00000000..da125d94 --- /dev/null +++ b/yage/entity/entitymanager.h @@ -0,0 +1,83 @@ +/** --------------------------------------------------------------------------- + * @file: entitymanager.h + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_ENGINE_ENTITYMANAGER_H +#define YAGE_ENGINE_ENTITYMANAGER_H + +#include "entity.h" + +#include + +namespace yage +{ + +class Space; + +/** + * Manages entities in a space. + */ +class EntityManager +{ +public: + /** + * Default instance of an EntityManager. + */ + EntityManager() = default; + + /** + * Creates an instance of the entity manager, which refers back to the space + * it was created in and belongs to. + * + * @param space Current space that the EntityManager belongs to. + */ + EntityManager(Space *space); + + /** + * Creates an instance of the entitiy manager with an initial size. + * + * @param space Current space that the EntityManager belongs to. + * @param n Initial size of the EntityManager. + */ + EntityManager(Space *space, std::size_t n); + + /** + * Creates an Entity and returns the handle to the entity, which can then be + * used by the user to do operations on it. + * + * @return The handle to the entity that was created in the space. + */ + unsigned createEntity(); + + /** + * Creates an Entity and returns it. + * + * @return The entity that was created by the entity manager in the current + * space. + */ + Entity createEntityInstance(); + +private: + /** + * The next available handle to give to the user. + */ + unsigned next_handle_; + + /** + * The space that the entity manager belongs to. + */ + Space *space_; + + /** + * The entities in the current space. + */ + std::vector entities_; +}; + +} // namespace yage + +#endif diff --git a/yage/entity/space.cpp b/yage/entity/space.cpp new file mode 100644 index 00000000..f3e343b5 --- /dev/null +++ b/yage/entity/space.cpp @@ -0,0 +1,21 @@ +/** --------------------------------------------------------------------------- + * @file: space.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include "space.h" + +namespace yage +{ + +Space::Space() : em_(this) {} + +unsigned Space::createEntity() +{ + return em_.createEntity(); +} + +} // namespace yage diff --git a/yage/entity/space.h b/yage/entity/space.h new file mode 100644 index 00000000..e69df37a --- /dev/null +++ b/yage/entity/space.h @@ -0,0 +1,61 @@ +/** --------------------------------------------------------------------------- + * @file: space.h + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_ENGINE_SPACE_H +#define YAGE_ENGINE_SPACE_H + +#include + +#include "entitymanager.h" + +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 + * can be used, for example, for different levels in the game that can be loaded + * separately, or a game menu that can be loaded above the other spaces when the + * user presses on pause. + */ +class Space +{ +public: + /** + * Default instance for a space. + */ + Space(); + + /** + * Create an entity that will belong to this space, and return the handle to + * the user. The Entity class itself should not be visible to the user, as + * the user only needs to worry about the handle when referring to the + * Entity and changing it. + */ + unsigned createEntity(); + +private: + /** + * The subspaces of the Space that act on the data and on their respective + * component. These are specific to the Space, as other spaces might have + * different Systems and not act on the same entities. + */ + std::vector systems_; + + /** + * Manages all the entities in the system, can create them for the current + * space. + */ + EntityManager em_; +}; + +} // namespace yage + +#endif diff --git a/yage/entity/system.h b/yage/entity/system.h new file mode 100644 index 00000000..9100fa17 --- /dev/null +++ b/yage/entity/system.h @@ -0,0 +1,57 @@ +/** --------------------------------------------------------------------------- + * @file: system.h + * + * Copyright (c) 2017 Yann Herklotz Grave + * 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; + + /** + * Destroy the system and the components that are contained in it. + */ + virtual void destroy() = 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/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. * -- cgit