diff options
-rw-r--r-- | .dir-locals.el | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | examples/shooter/main.cpp | 2 | ||||
-rw-r--r-- | examples/simplegame/main.cpp | 3 | ||||
-rw-r--r-- | tests/engine/entities.json | 23 | ||||
-rw-r--r-- | tests/engine/test.cpp | 4 | ||||
-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 |
21 files changed, 130 insertions, 106 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index 2e2c2aaa..f1672c13 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,3 +1,3 @@ -((nil . ((projectile-project-compilation-cmd . "mkdir -p build && cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && make -j4") +((nil . ((projectile-project-compilation-cmd . "mkdir -p build && cd build && cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && ninja -j4") (projectile-project-test-cmd . "cd build/tests && ctest") (projectile-project-run-cmd . "./build/bin/simplegame")))) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea15bb0a..2633d4a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ file(GLOB YAGE_MATH_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} yage/math/*.cpp file(GLOB YAGE_PHYSICS_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} yage/physics/*.cpp) file(GLOB YAGE_UTIL_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} yage/util/*.cpp) file(GLOB YAGE_RENDER_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} yage/render/*.cpp) -file(GLOB YAGE_ENGINE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} yage/engine/*.cpp) +file(GLOB YAGE_ENGINE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} yage/entity/*.cpp) file(GLOB YAGE_CURRENT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} yage/*.cpp) set(YAGE_SOURCES @@ -57,6 +57,20 @@ The test suite can then be run using cd build/tests && ctest ``` +## Using the game engine + +The game engine can be initialised as follows. + +``` c++ +yage::init(); +``` + +It can be then cleaned up by running. + +``` objective-c++ +yage::quit(); +``` + ## Future Improvements The first step is to have full support of 3D meshes with their corresponding diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index e38bf53b..5d80c350 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -11,6 +11,7 @@ using std::cout; int main(int argc, char **argv) { + yage::init(); yage::Window window; window.create("Shooter example", 800, 600); @@ -166,4 +167,5 @@ int main(int argc, char **argv) window.swapBuffer(); } + yage::quit(); } diff --git a/examples/simplegame/main.cpp b/examples/simplegame/main.cpp index ed6b78f3..bea3bc8d 100644 --- a/examples/simplegame/main.cpp +++ b/examples/simplegame/main.cpp @@ -18,7 +18,7 @@ using namespace yage; int main() { - + yage::init(); Logger logger; srand(time(nullptr)); Window window; @@ -109,4 +109,5 @@ int main() } i = (i + 1) % 30; } + yage::quit(); } diff --git a/tests/engine/entities.json b/tests/engine/entities.json new file mode 100644 index 00000000..25959311 --- /dev/null +++ b/tests/engine/entities.json @@ -0,0 +1,23 @@ +{ + "Entities": [ + { + "name": "Object1", + "mass": "Hello", + "position": [ + 0, + 0, + 0 + ], + "velocity": [ + 0, + 0, + 0 + ], + "acceleration": [ + 0, + 0, + 0 + ] + } + ] +} diff --git a/tests/engine/test.cpp b/tests/engine/test.cpp index 6026e40a..5095a974 100644 --- a/tests/engine/test.cpp +++ b/tests/engine/test.cpp @@ -1,4 +1,4 @@ -#include <yage/engine/space.h> +#include <yage/entity/space.h> #include <yage/yage.h> @@ -8,12 +8,12 @@ int main() auto entity = space.createEntity(); auto entity2 = space.createEntity(); auto entity3 = space.createEntity(); - auto entity4 = space.createEntity(); yLogInfo << "Entity 1: " << entity; yLogInfo << "Entity 3: " << entity3; yLogInfo << "Entity 2: " << entity2; yLogInfo << "Entity 4: " << entity4; + return 0; } 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. * |