From 2acf4bfcbb5c4b457590e0ce6336645bc3900d83 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Fri, 15 Jun 2018 20:00:26 +0100 Subject: Deleting entity system so that it can be rewritten --- yage/entity/engine.cpp | 65 ------------------------------------------ yage/entity/engine.h | 58 -------------------------------------- yage/entity/entity.cpp | 42 ---------------------------- yage/entity/space.cpp | 29 ------------------- yage/entity/space.h | 76 -------------------------------------------------- 5 files changed, 270 deletions(-) delete mode 100644 yage/entity/engine.cpp delete mode 100644 yage/entity/engine.h delete mode 100644 yage/entity/entity.cpp delete mode 100644 yage/entity/space.cpp delete mode 100644 yage/entity/space.h diff --git a/yage/entity/engine.cpp b/yage/entity/engine.cpp deleted file mode 100644 index 73774093..00000000 --- a/yage/entity/engine.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/** --------------------------------------------------------------------------- - * -*- c++ -*- - * @file: engine.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "engine.h" - -#include "../core/core.h" - -#include "space.h" - -namespace yage -{ - -Engine::~Engine() -{ - quit(); -} - -Engine &Engine::init() -{ - yage::init(); - window_.create("Game Engine", 800, 640); - return *this; -} - -Engine &Engine::mainLoop() -{ - while (!window_.shouldClose()) { - window_.pollEvents(); - window_.clearBuffer(); - - update(); - - window_.swapBuffer(); - } - - return *this; -} - -void Engine::update() -{ - for (auto &space : spaces_) { - space->update(); - } -} - -Engine &Engine::addSpace(std::unique_ptr space) -{ - spaces_.push_back(std::move(space)); - return *this; -} - -Engine &Engine::instance() -{ - static Engine engine_instance; - - return engine_instance; -} - -} // namespace yage diff --git a/yage/entity/engine.h b/yage/entity/engine.h deleted file mode 100644 index 6719eeaf..00000000 --- a/yage/entity/engine.h +++ /dev/null @@ -1,58 +0,0 @@ -/** --------------------------------------------------------------------------- - * -*- c++ -*- - * @file: engine.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#pragma once - -#include "system.h" - -#include "../core/window.h" -#include "../util/noncopyable.h" - -#include -#include - -namespace yage -{ - -class Space; - -/** - * Main engine class that contains a systems, the main loop and the update - * function that updates all the systems. - */ -class Engine : public NonCopyable -{ -public: - ~Engine(); - - /// Initialize window and other aspects of the engine. - Engine &init(); - - /// Main game loop of the engine. - Engine &mainLoop(); - - /// Updates the systems. - void update(); - - /// Add spaces to the engine - Engine &addSpace(std::unique_ptr space); - - /// Returns the instance of the engine, as there is only one instance of the - /// engine. - static Engine &instance(); - -private: - /// Window - Window window_; - - /// A vector of all the spaces - std::vector> spaces_; -}; - -} // namespace yage diff --git a/yage/entity/entity.cpp b/yage/entity/entity.cpp deleted file mode 100644 index 1a2b16ad..00000000 --- a/yage/entity/entity.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/** --------------------------------------------------------------------------- - * -*- c++ -*- - * @file: entity.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "entity.h" - -#include - -namespace yage -{ - -BaseComponent::Group BaseComponent::group_id_counter_ = 0; - -EntityManager::EntityManager(Space *space) : space_(space) {} - -EntityManager::EntityManager(Space *space, std::size_t n) : space_(space) -{ - entities_.reserve(n); -} - -Entity EntityManager::createEntity() -{ - Entity entity = next_entity_++; - entities_.push_back(entity); - return entity; -} - -void EntityManager::deleteEntity(Entity entity) -{ - auto index = std::find_if(entities_.begin(), entities_.end(), - [&](Entity &value) { return value == entity; }); - if (index != entities_.end()) { - entities_.erase(index); - } -} - -} // namespace yage diff --git a/yage/entity/space.cpp b/yage/entity/space.cpp deleted file mode 100644 index 530f5b49..00000000 --- a/yage/entity/space.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/** --------------------------------------------------------------------------- - * -*- c++ -*- - * @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(); -} - -void Space::update() -{ - for (auto &system : systems_) { - system->update(); - } -} - -} // namespace yage diff --git a/yage/entity/space.h b/yage/entity/space.h deleted file mode 100644 index 0763b189..00000000 --- a/yage/entity/space.h +++ /dev/null @@ -1,76 +0,0 @@ -/** --------------------------------------------------------------------------- - * -*- c++ -*- - * @file: space.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#pragma once - -#include -#include - -#include "entity.h" -#include "system.h" - -struct Movement { -}; - -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. - */ - Entity createEntity(); - - /** - * Update all the systems. - */ - void update(); - -private: - /** - * 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> systems_; - - /** - * Manages all the entities in the system, can create them for the - * current space. - */ - EntityManager em_; - - /** - * Manages all the components - */ - // ComponentManager cm_; -}; - -} // namespace yage -- cgit