diff options
-rw-r--r-- | yage/core/window.cpp | 3 | ||||
-rw-r--r-- | yage/core/window.h | 2 | ||||
-rw-r--r-- | yage/entity/engine.cpp | 11 | ||||
-rw-r--r-- | yage/entity/engine.h | 17 | ||||
-rw-r--r-- | yage/entity/entity.cpp | 23 | ||||
-rw-r--r-- | yage/entity/entity.h | 36 | ||||
-rw-r--r-- | yage/entity/space.h | 34 | ||||
-rw-r--r-- | yage/entity/systemmanager.h | 15 |
8 files changed, 48 insertions, 93 deletions
diff --git a/yage/core/window.cpp b/yage/core/window.cpp index c55b1ad1..e899d38a 100644 --- a/yage/core/window.cpp +++ b/yage/core/window.cpp @@ -34,8 +34,6 @@ void framebuffer_size_callback(GLFWwindow *window, int width, int height) } // namespace -Window::Window() = default; - Window::~Window() { glfwDestroyWindow(window_); @@ -49,6 +47,7 @@ void Window::create(std::string window_name, int width, int height) window_ = glfwCreateWindow(width, height, window_name.c_str(), nullptr, nullptr); + if (window_ == nullptr) { throw runtime_error("GLFW Window creation failed"); } diff --git a/yage/core/window.h b/yage/core/window.h index 93ed6c07..9980018d 100644 --- a/yage/core/window.h +++ b/yage/core/window.h @@ -34,7 +34,7 @@ private: GLFWwindow *window_ = nullptr; public: - Window(); + Window() = default; Window(const Window &) = delete; Window(Window &&) = delete; /// destroys the window handle diff --git a/yage/entity/engine.cpp b/yage/entity/engine.cpp index 919cff7c..503dc919 100644 --- a/yage/entity/engine.cpp +++ b/yage/entity/engine.cpp @@ -8,6 +8,9 @@ #include "engine.h" +#include "space.h" +#include "entity.h" + namespace yage { @@ -29,6 +32,14 @@ void Engine::mainLoop() void Engine::update() { + for(auto &space : spaces_) { + + } +} + +void Engine::addSpace(std::unique_ptr<Space> space) +{ + spaces_.push_back(std::move(space)); } Engine &Engine::instance() diff --git a/yage/entity/engine.h b/yage/entity/engine.h index 6e1bf49a..fe7e5eb0 100644 --- a/yage/entity/engine.h +++ b/yage/entity/engine.h @@ -9,16 +9,21 @@ #ifndef YAGE_CORE_ENGINE_H #define YAGE_CORE_ENGINE_H -#include "../core/window.h" #include "system.h" +#include "../core/window.h" +#include <memory> #include <vector> namespace yage { -/// Main engine class that contains a systems, the main loop and the update -/// function that updates all the systems. +class Space; + +/** + * Main engine class that contains a systems, the main loop and the update + * function that updates all the systems. + */ class Engine { public: @@ -31,6 +36,9 @@ public: /// Updates the systems. void update(); + /// Add spaces to the engine + void addSpace(std::unique_ptr<Space> space); + /// Returns the instance of the engine, as there is only one instance of the /// engine. static Engine &instance(); @@ -38,6 +46,9 @@ public: private: /// Window Window window_; + + /// A vector of all the spaces + std::vector<std::unique_ptr<Space>> spaces_; }; } // namespace yage diff --git a/yage/entity/entity.cpp b/yage/entity/entity.cpp deleted file mode 100644 index 4d9a4b0a..00000000 --- a/yage/entity/entity.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: entity.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * 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 index e6742893..097c1fa2 100644 --- a/yage/entity/entity.h +++ b/yage/entity/entity.h @@ -14,41 +14,7 @@ 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_; -}; +typedef unsigned int Handle; } // namespace yage diff --git a/yage/entity/space.h b/yage/entity/space.h index 96154ffc..2bee7da5 100644 --- a/yage/entity/space.h +++ b/yage/entity/space.h @@ -10,18 +10,22 @@ #define YAGE_ENGINE_SPACE_H #include <vector> +#include <memory> #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. + * 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 { @@ -32,23 +36,25 @@ public: 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. + * 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. + * The systems 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<std::unique_ptr<System>> systems_; /** - * Manages all the entities in the system, can create them for the current - * space. + * Manages all the entities in the system, can create them for the + * current space. */ EntityManager em_; }; diff --git a/yage/entity/systemmanager.h b/yage/entity/systemmanager.h deleted file mode 100644 index 5351e4bb..00000000 --- a/yage/entity/systemmanager.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef YAGE_ENTITY_SYSTEMMANAGER_H -#define YAGE_ENTITY_SYSTEMMANAGER_H - -#include <unordered_map> - -namespace yage { - -class SystemManager { -private: - std::unordered_map -}; - -} // namespace yage - -#endif |