From dafc9beef5f3b93698d654750c22c7b381986c27 Mon Sep 17 00:00:00 2001 From: Joseph Aquino Date: Thu, 31 Jul 2025 03:36:14 -0400 Subject: [PATCH] Start implementing Game -added ecc.sh to export compile commands -changed EntityMemoryPool to not be singleton so that each EntityManager can have its own pool -Entities now store a reference to the EntityManager that spawned them so they get data from the right pool -added Random.h from learncpp.com -DrawQueue can now be used with std::sort -Array containers have swap function --- Engine-Core/include/Action.h | 14 ++++ Engine-Core/include/Assets.h | 6 ++ Engine-Core/include/Containers/DrawQueue.h | 19 ++++- Engine-Core/include/Containers/HeapArray.h | 22 +++++- Engine-Core/include/Containers/StackArray.h | 16 ++++ Engine-Core/include/Entities/Components.h | 8 +- Engine-Core/include/Entities/Entity.h | 38 ++++++--- Engine-Core/include/Entities/EntityManager.h | 3 + .../include/Entities/EntityMemoryPool.h | 20 ++--- Engine-Core/include/Entities/EntityView.h | 6 +- Engine-Core/include/Random.h | 74 ++++++++++++++++++ Engine-Core/include/utility.h | 3 +- Engine-Core/src/Assets.cpp | 2 + Engine-Core/src/Containers/DrawQueue.cpp | 78 +++++++++++++------ Engine-Core/src/Entities/EntityManager.cpp | 46 ++++++++++- Engine-Core/src/Entities/EntityMemoryPool.cpp | 17 ++-- Engine-Core/src/Entities/EntityView.cpp | 25 +++--- Game/include/ConstGlobals.h | 13 ++++ Game/include/Game.h | 7 -- Game/include/GameEngine.h | 37 +++++++++ Game/include/Scenes.h | 4 + Game/include/Scenes/Play.h | 8 ++ Game/include/Scenes/Scene.h | 6 ++ Game/src/Game.cpp | 0 Game/src/GameEngine.cpp | 1 + Game/src/game-main.cpp | 30 ++----- ecc.sh | 3 + 27 files changed, 392 insertions(+), 114 deletions(-) create mode 100644 Engine-Core/include/Action.h create mode 100644 Engine-Core/include/Assets.h create mode 100644 Engine-Core/include/Random.h create mode 100644 Engine-Core/src/Assets.cpp create mode 100644 Game/include/ConstGlobals.h delete mode 100644 Game/include/Game.h create mode 100644 Game/include/GameEngine.h create mode 100644 Game/include/Scenes.h create mode 100644 Game/include/Scenes/Play.h create mode 100644 Game/include/Scenes/Scene.h delete mode 100644 Game/src/Game.cpp create mode 100644 Game/src/GameEngine.cpp create mode 100755 ecc.sh diff --git a/Engine-Core/include/Action.h b/Engine-Core/include/Action.h new file mode 100644 index 0000000..24e342f --- /dev/null +++ b/Engine-Core/include/Action.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +struct Action +{ + Action(u8 name_in, u8 type_in) + : name(name_in) + , type(type_in) + { } + + u8 name; + u8 type; +}; \ No newline at end of file diff --git a/Engine-Core/include/Assets.h b/Engine-Core/include/Assets.h new file mode 100644 index 0000000..5f7049e --- /dev/null +++ b/Engine-Core/include/Assets.h @@ -0,0 +1,6 @@ +#pragma once + +class Assets +{ + +}; \ No newline at end of file diff --git a/Engine-Core/include/Containers/DrawQueue.h b/Engine-Core/include/Containers/DrawQueue.h index 0ac3448..813074b 100644 --- a/Engine-Core/include/Containers/DrawQueue.h +++ b/Engine-Core/include/Containers/DrawQueue.h @@ -2,6 +2,7 @@ #include #include + class Sprite; namespace container @@ -9,13 +10,15 @@ namespace container class DrawQueue { - using size_type = unsigned int; + using size_type = size_t; public: class iterator { public: using value_type = Sprite; + using pointer = Sprite*; + using reference = Sprite&; using difference_type = std::ptrdiff_t; using iterator_category = std::random_access_iterator_tag; @@ -24,14 +27,24 @@ public: iterator operator++(int); iterator& operator--(); iterator operator--(int); - + iterator operator+(difference_type) const; + iterator operator-(difference_type) const; + iterator& operator+=(difference_type); + iterator& operator-=(difference_type); + difference_type operator-(iterator) const; + friend iterator operator+(difference_type, iterator); + Sprite& operator*(); Sprite* operator->(); Sprite& operator[](size_type); bool operator==(iterator) const; bool operator!=(iterator) const; - private: + bool operator>(iterator) const; + bool operator<(iterator) const; + bool operator>=(iterator) const; + bool operator<=(iterator) const; + private: Sprite* m_ptr; }; diff --git a/Engine-Core/include/Containers/HeapArray.h b/Engine-Core/include/Containers/HeapArray.h index 147f4d6..9b4425f 100644 --- a/Engine-Core/include/Containers/HeapArray.h +++ b/Engine-Core/include/Containers/HeapArray.h @@ -130,6 +130,13 @@ public: inline constexpr CapacityType size() const { return capacity; } + void swap(index_t first, index_t second) + { + auto temp = m_data[first]; + m_data[first] = m_data[second]; + m_data[second] = temp; + } + iterator begin() { return iterator(data()); } iterator end() { return iterator(data() + capacity); } @@ -196,7 +203,6 @@ public: { public: using value_type = data_type; - using reference = reference; using difference_type = std::ptrdiff_t; using iterator_category = std::forward_iterator_tag; @@ -288,7 +294,6 @@ public: { public: using value_type = data_type; - using reference = reference; using difference_type = std::ptrdiff_t; using iterator_category = std::forward_iterator_tag; @@ -424,6 +429,16 @@ public: void setFalseAt(CapacityType index) { m_data[index / 8] &= ~(1 << (index % 8)); } + + void swap(index_t first, index_t second) + { + auto firstElem = reference(m_data + (first / 8), 1 << (first % 8)); + auto secondElem = reference(m_data + (second / 8), 1 << (second % 8)); + bool temp = firstElem; + firstElem = secondElem; + secondElem = temp; + } + iterator begin() { return iterator(data(), 0); } iterator end() { return iterator(data() + (capacity / 8), capacity % 8); } @@ -434,4 +449,5 @@ private: data_type* m_data; }; -}//namespace \ No newline at end of file +}//namespace + diff --git a/Engine-Core/include/Containers/StackArray.h b/Engine-Core/include/Containers/StackArray.h index 72332e6..d6e4419 100644 --- a/Engine-Core/include/Containers/StackArray.h +++ b/Engine-Core/include/Containers/StackArray.h @@ -109,6 +109,13 @@ public: inline constexpr CapacityType size() const { return capacity; } + void swap(index_t first, index_t second) + { + auto temp = m_data[first]; + m_data[first] = m_data[second]; + m_data[second] = temp; + } + iterator begin() { return iterator(data()); } iterator end() { return iterator(data() + capacity); } @@ -372,6 +379,15 @@ public: void setFalseAt(CapacityType index) { m_data[index / 8] &= ~(1 << (index % 8)); } + void swap(index_t first, index_t second) + { + auto firstElem = reference(m_data + (first / 8), 1 << (first % 8)); + auto secondElem = reference(m_data + (second / 8), 1 << (second % 8)); + bool temp = firstElem; + firstElem = secondElem; + secondElem = temp; + } + iterator begin() { return iterator(data(), 0); } iterator end() { return iterator(data() + (capacity / 8), capacity % 8); } diff --git a/Engine-Core/include/Entities/Components.h b/Engine-Core/include/Entities/Components.h index f2e7acc..5d4bf0d 100644 --- a/Engine-Core/include/Entities/Components.h +++ b/Engine-Core/include/Entities/Components.h @@ -22,7 +22,13 @@ class Sprite { public: Sprite() = default; - + Sprite(u8 x_in, u8 y_in, u8 textureIndex_in, u8 drawDepth_in) + : x(x_in) + , y(y_in) + , textureIndex(textureIndex_in) + , drawDepth(drawDepth_in) + { } + u8 x{}; u8 y{}; u8 textureIndex{}; diff --git a/Engine-Core/include/Entities/Entity.h b/Engine-Core/include/Entities/Entity.h index 129f049..dd8357e 100644 --- a/Engine-Core/include/Entities/Entity.h +++ b/Engine-Core/include/Entities/Entity.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -11,48 +12,61 @@ public: friend class EntityMemoryPool; Entity() = delete; - Entity(index_t index_in) - : m_index(index_in) + Entity(EntityMemoryPool& dataLocation, index_t index_in) + : m_data(dataLocation) + , m_index(index_in) { } + void add() + { m_data.getAlive(m_index).setTrue(); } + public: // template // bool hasComponent() const; template T& getComponent() const - { return EntityMemoryPool::instance().getComponent(m_index); } + { return m_data.getComponent(m_index); } template void addComponent(const T& data) { - T& component = EntityMemoryPool::instance().getComponent(m_index); + T& component = m_data.getComponent(m_index); component = data; } + template + void removeComponent() + { + T& component = m_data.getComponent(m_index); + component = T(); + } + size_t id() const - { return EntityMemoryPool::instance().getId(m_index); } + { return m_data.getId(m_index); } tag_t tag() const - { return EntityMemoryPool::instance().getTag(m_index); } + { return m_data.getTag(m_index); } bool alive() const - { return EntityMemoryPool::instance().getAlive(m_index); } + { return m_data.getAlive(m_index); } bool visible() const - { return EntityMemoryPool::instance().getVisiblity(m_index); } + { return m_data.getVisiblity(m_index); } void makeVisible() - { EntityMemoryPool::instance().getVisiblity(m_index).setTrue(); } + { m_data.getVisiblity(m_index).setTrue(); } void makeInvisible() - { EntityMemoryPool::instance().getVisiblity(m_index).setFalse(); } + { m_data.getVisiblity(m_index).setFalse(); } void flipVisibility() - { EntityMemoryPool::instance().getVisiblity(m_index).flip(); } + { m_data.getVisiblity(m_index).flip(); } void destroy() - { EntityMemoryPool::instance().getAlive(m_index).setFalse(); } + { m_data.getAlive(m_index).setFalse(); } + private: + EntityMemoryPool& m_data; index_t m_index; }; \ No newline at end of file diff --git a/Engine-Core/include/Entities/EntityManager.h b/Engine-Core/include/Entities/EntityManager.h index 20d23b6..b13da9d 100644 --- a/Engine-Core/include/Entities/EntityManager.h +++ b/Engine-Core/include/Entities/EntityManager.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -19,6 +20,8 @@ public: Entity addEntity(tag_t); private: + EntityMemoryPool m_entityData; + size_t m_nextId{}; index_t m_numEntities[util::TAG_COUNT]{}; index_t m_numEntitiesToAdd[util::TAG_COUNT]{}; #ifdef CORE_DEBUG diff --git a/Engine-Core/include/Entities/EntityMemoryPool.h b/Engine-Core/include/Entities/EntityMemoryPool.h index a96b673..57e35d8 100644 --- a/Engine-Core/include/Entities/EntityMemoryPool.h +++ b/Engine-Core/include/Entities/EntityMemoryPool.h @@ -12,8 +12,8 @@ class Entity; using ComponentsContainer = std::tuple < container::HeapArray, - container::HeapArray, - container::HeapArray + container::HeapArray, + container::HeapArray >; class EntityMemoryPool @@ -34,26 +34,18 @@ private: EntityMemoryPool(const EntityMemoryPool&) = delete; - static EntityMemoryPool& instance() - { - static EntityMemoryPool pool{}; - return pool; - } - template T& getComponent(index_t index) { return std::get>(m_components)[index]; } - tag_t getTag(index_t index) const - { return m_tags[index]; } - auto getAlive(index_t index) { return m_aliveStates[index]; } - size_t getId(index_t index) const - { return m_ids[index]; } - auto getVisiblity(index_t index) { return m_visibility[index]; } + + tag_t getTag(index_t) const; + + size_t getId(index_t) const; }; diff --git a/Engine-Core/include/Entities/EntityView.h b/Engine-Core/include/Entities/EntityView.h index d99b85d..579af13 100644 --- a/Engine-Core/include/Entities/EntityView.h +++ b/Engine-Core/include/Entities/EntityView.h @@ -14,12 +14,12 @@ private: friend class EntityMemoryPool; EntityView() = delete; - EntityView(index_t, index_t); + EntityView(EntityMemoryPool&, index_t, index_t); public: class iterator { public: - iterator(index_t); + iterator(EntityMemoryPool&, index_t); iterator& operator++(); iterator operator++(int); iterator& operator--(); @@ -29,6 +29,7 @@ public: bool operator==(iterator); bool operator!=(iterator); private: + EntityMemoryPool& m_data; index_t m_currentEntity{}; }; @@ -38,6 +39,7 @@ public: iterator end(); private: + EntityMemoryPool& m_data; index_t m_start{}; index_t m_size{}; }; \ No newline at end of file diff --git a/Engine-Core/include/Random.h b/Engine-Core/include/Random.h new file mode 100644 index 0000000..28c2beb --- /dev/null +++ b/Engine-Core/include/Random.h @@ -0,0 +1,74 @@ +#pragma once + +#ifndef RANDOM_MT_H +#define RANDOM_MT_H + +#include +#include + +// This header-only Random namespace implements a self-seeding Mersenne Twister. +// Requires C++17 or newer. +// It can be #included into as many code files as needed (The inline keyword avoids ODR violations) +// Freely redistributable, courtesy of learncpp.com (https://www.learncpp.com/cpp-tutorial/global-random-numbers-random-h/) +namespace Random +{ + // Returns a seeded Mersenne Twister + // Note: we'd prefer to return a std::seed_seq (to initialize a std::mt19937), but std::seed can't be copied, so it can't be returned by value. + // Instead, we'll create a std::mt19937, seed it, and then return the std::mt19937 (which can be copied). + inline std::mt19937 generate() + { + std::random_device rd{}; + + // Create seed_seq with clock and 7 random numbers from std::random_device + std::seed_seq ss{ + static_cast(std::chrono::steady_clock::now().time_since_epoch().count()), + rd(), rd(), rd(), rd(), rd(), rd(), rd() }; + + return std::mt19937{ ss }; + } + + // Here's our global std::mt19937 object. + // The inline keyword means we only have one global instance for our whole program. + inline std::mt19937 mt{ generate() }; // generates a seeded std::mt19937 and copies it into our global object + + // Generate a random int between [min, max] (inclusive) + // * also handles cases where the two arguments have different types but can be converted to int + inline int get(int min, int max) + { + return std::uniform_int_distribution{min, max}(mt); + } + + // The following function templates can be used to generate random numbers in other cases + + // See https://www.learncpp.com/cpp-tutorial/function-template-instantiation/ + // You can ignore these if you don't understand them + + // Generate a random value between [min, max] (inclusive) + // * min and max must have the same type + // * return value has same type as min and max + // * Supported types: + // * short, int, long, long long + // * unsigned short, unsigned int, unsigned long, or unsigned long long + // Sample call: Random::get(1L, 6L); // returns long + // Sample call: Random::get(1u, 6u); // returns unsigned int + template + T get(T min, T max) + { + return std::uniform_int_distribution{min, max}(mt); + } + + // Generate a random value between [min, max] (inclusive) + // * min and max can have different types + // * return type must be explicitly specified as a template argument + // * min and max will be converted to the return type + // Sample call: Random::get(0, 6); // returns std::size_t + // Sample call: Random::get(0, 6u); // returns std::size_t + // Sample call: Random::get(0, 6u); // returns int + template + R get(S min, T max) + { + return get(static_cast(min), static_cast(max)); + } +} + +#endif \ No newline at end of file diff --git a/Engine-Core/include/utility.h b/Engine-Core/include/utility.h index 075d06b..e5eeffe 100644 --- a/Engine-Core/include/utility.h +++ b/Engine-Core/include/utility.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -16,7 +17,7 @@ using s64 = int64_t; using tag_t = uint8_t; using subtag_t = uint8_t; -using index_t = uint16_t; +using index_t = size_t; namespace Tag { diff --git a/Engine-Core/src/Assets.cpp b/Engine-Core/src/Assets.cpp new file mode 100644 index 0000000..7689fa2 --- /dev/null +++ b/Engine-Core/src/Assets.cpp @@ -0,0 +1,2 @@ +#include + diff --git a/Engine-Core/src/Containers/DrawQueue.cpp b/Engine-Core/src/Containers/DrawQueue.cpp index 76650f6..4d79e49 100644 --- a/Engine-Core/src/Containers/DrawQueue.cpp +++ b/Engine-Core/src/Containers/DrawQueue.cpp @@ -1,9 +1,13 @@ -#include "log.h" -#include "utility.h" +#include #include #include #include +container::DrawQueue::iterator operator+(container::DrawQueue::iterator::difference_type offset, container::DrawQueue::iterator it) +{ + return it + offset; +} + namespace container { //iterator @@ -37,6 +41,33 @@ namespace container return it; } + DrawQueue::iterator DrawQueue::iterator::operator+(difference_type offset) const + { + return m_ptr + offset; + } + + DrawQueue::iterator DrawQueue::iterator::operator-(difference_type offset) const + { + return m_ptr - offset; + } + + DrawQueue::iterator& DrawQueue::iterator::operator+=(difference_type offset) + { + m_ptr += offset; + return *this; + } + + DrawQueue::iterator& DrawQueue::iterator::operator-=(difference_type offset) + { + m_ptr -= offset; + return *this; + } + + DrawQueue::iterator::difference_type DrawQueue::iterator::operator-(iterator other) const + { + return m_ptr - other.m_ptr; + } + Sprite& DrawQueue::iterator::operator*() { return *m_ptr; @@ -62,6 +93,26 @@ namespace container return m_ptr != other.m_ptr; } + bool DrawQueue::iterator::operator>(iterator other) const + { + return m_ptr > other.m_ptr; + } + + bool DrawQueue::iterator::operator<(iterator other) const + { + return m_ptr < other.m_ptr; + } + + bool DrawQueue::iterator::operator>=(iterator other) const + { + return m_ptr >= other.m_ptr; + } + + bool DrawQueue::iterator::operator<=(iterator other) const + { + return m_ptr <= other.m_ptr; + } + //const_iterator DrawQueue::const_iterator::const_iterator(const Sprite* input) : m_ptr(input) @@ -226,31 +277,12 @@ namespace container m_data[m_size] = input; - sort(); + std::sort(begin(), end(), [](Sprite first, Sprite second){ return first.drawDepth < second.drawDepth;}); } void DrawQueue::sort() { - Sprite temp; - size_type i = 0, end = m_size - 1; - - while (end != 0) - { - if (m_data[i].drawDepth > m_data[i + 1].drawDepth) - { - temp = m_data[i]; - m_data[i] = m_data[i + 1]; - m_data[i + 1] = temp; - } - - i++; - - if (i == end) - { - i = 0; - end--; - } - } + std::sort(begin(), end(), [](Sprite first, Sprite second){ return first.drawDepth < second.drawDepth;}); } DrawQueue::iterator DrawQueue::begin() diff --git a/Engine-Core/src/Entities/EntityManager.cpp b/Engine-Core/src/Entities/EntityManager.cpp index b8d8ac0..dfa3c77 100644 --- a/Engine-Core/src/Entities/EntityManager.cpp +++ b/Engine-Core/src/Entities/EntityManager.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -9,26 +10,65 @@ inline constexpr index_t PLAYER_INDEX = util::tagStart[Tag::player]; int EntityManager::update() { + //adding entities for(int i = 0; i < util::TAG_COUNT; i++) { + #ifdef CORE_DEBUG if (m_numEntities[i] + m_numEntitiesToAdd[i] >= util::getTagSize(i)) { LOG("Error: Entity Overflow"); return ErrorCode::entityOverflow; } + #endif + + EntityView toAdd(m_entityData, util::getTagStart(i) + m_numEntities[i], m_numEntitiesToAdd[i] - 1); + + for (auto ent : toAdd) + { + ent.add(); + m_entityData.m_ids[ent.m_index] = m_nextId++; + m_numEntities[i]++; + + #ifdef CORE_DEBUG + m_totalEntities++; + #endif + } + + m_numEntitiesToAdd[i] = 0; + + //removing entites + EntityView entites(m_entityData, util::getTagStart(i), m_numEntities[i]); + Entity swapWith(m_entityData, 0); + + for (auto ent : entites) + { + if (ent.alive()) continue; + + if (ent.m_index != m_numEntities[i] - 1)//not at the end + { + swapWith.m_index = m_numEntities[i] - 1; + std::apply([=](auto&&... args) {((args.swap(ent.m_index, swapWith.m_index)), ...); }, m_entityData.m_components); + + m_numEntities[i]--; + continue; + } + + m_numEntities[i]--; + } } + return 0; } inline Entity EntityManager::player() { - return Entity(PLAYER_INDEX); + return Entity(m_entityData, PLAYER_INDEX); } EntityView EntityManager::getEntities(tag_t tag) { - return EntityView(util::getTagStart(tag), m_numEntities[tag]); + return EntityView(m_entityData, util::getTagStart(tag), m_numEntities[tag]); } Entity EntityManager::addEntity(tag_t tag) @@ -37,5 +77,5 @@ Entity EntityManager::addEntity(tag_t tag) m_totalEntities++; #endif - return Entity(util::tagStart[tag] + m_numEntities[tag] + m_numEntitiesToAdd[tag]++); + return Entity(m_entityData, util::tagStart[tag] + m_numEntities[tag] + m_numEntitiesToAdd[tag]++); } \ No newline at end of file diff --git a/Engine-Core/src/Entities/EntityMemoryPool.cpp b/Engine-Core/src/Entities/EntityMemoryPool.cpp index a5b6a3c..77a897d 100644 --- a/Engine-Core/src/Entities/EntityMemoryPool.cpp +++ b/Engine-Core/src/Entities/EntityMemoryPool.cpp @@ -2,24 +2,23 @@ #include #include -#include #include #include EntityMemoryPool::EntityMemoryPool() { - /* - std::apply([=](auto&&... args) {((args.reserve(util::MAX_ENTITIES)), ...); }, m_components); - m_tags.reserve(util::MAX_ENTITIES); - m_aliveStates.reserve(util::MAX_ENTITIES); - */ - for (int i = 0; i < util::TAG_COUNT; i++) { - EntityView x(util::tagStart[i], util::tagSize[i]); + EntityView x(*this, util::tagStart[i], util::tagSize[i]); for (auto entity : x) { m_tags[entity.m_index] = i; } } -} \ No newline at end of file +} + +tag_t EntityMemoryPool::getTag(index_t index) const +{ return m_tags[index]; } + +size_t EntityMemoryPool::getId(index_t index) const +{ return m_ids[index]; } \ No newline at end of file diff --git a/Engine-Core/src/Entities/EntityView.cpp b/Engine-Core/src/Entities/EntityView.cpp index d195ac5..1c2beb5 100644 --- a/Engine-Core/src/Entities/EntityView.cpp +++ b/Engine-Core/src/Entities/EntityView.cpp @@ -1,21 +1,24 @@ +#include "Entities/EntityMemoryPool.h" #include #include #include -EntityView::EntityView(index_t start, index_t size) - : m_start(start) +EntityView::EntityView(EntityMemoryPool& data, index_t start, index_t size) + : m_data(data) + , m_start(start) , m_size(size) { } Entity EntityView::operator[](index_t index) const { - return Entity(m_start + index); + return Entity(m_data, m_start + index); } //non-const iterator -EntityView::iterator::iterator(index_t index) - : m_currentEntity(index) +EntityView::iterator::iterator(EntityMemoryPool& data, index_t index) + : m_data(data) + , m_currentEntity(index) { } EntityView::iterator& EntityView::iterator::operator++() @@ -27,7 +30,7 @@ EntityView::iterator& EntityView::iterator::operator++() EntityView::iterator EntityView::iterator::operator++(int) { m_currentEntity++; - return m_currentEntity - 1; + return iterator(m_data, m_currentEntity - 1); } EntityView::iterator& EntityView::iterator::operator--() @@ -39,17 +42,17 @@ EntityView::iterator& EntityView::iterator::operator--() EntityView::iterator EntityView::iterator::operator--(int) { m_currentEntity--; - return m_currentEntity + 1; + return iterator(m_data, m_currentEntity + 1); } Entity EntityView::iterator::operator*() { - return m_currentEntity; + return Entity(m_data, m_currentEntity); } Entity EntityView::iterator::operator[](int index) { - return m_currentEntity + index; + return Entity(m_data, m_currentEntity + index); } bool EntityView::iterator::operator==(iterator other) @@ -64,10 +67,10 @@ bool EntityView::iterator::operator!=(iterator other) EntityView::iterator EntityView::begin() { - return iterator(m_start); + return iterator(m_data, m_start); } EntityView::iterator EntityView::end() { - return iterator(m_start + m_size); + return iterator(m_data, m_start + m_size); } \ No newline at end of file diff --git a/Game/include/ConstGlobals.h b/Game/include/ConstGlobals.h new file mode 100644 index 0000000..18d03a7 --- /dev/null +++ b/Game/include/ConstGlobals.h @@ -0,0 +1,13 @@ +#pragma once + +namespace global +{ + enum class Scenes : int + { + Play, + SceneCount + }; + + inline constexpr int SCENE_COUNT {(int)Scenes::SceneCount}; + +}//namespace \ No newline at end of file diff --git a/Game/include/Game.h b/Game/include/Game.h deleted file mode 100644 index c5c2af6..0000000 --- a/Game/include/Game.h +++ /dev/null @@ -1,7 +0,0 @@ -//#include "imgui.h" -#include - -class Game -{ - -}; \ No newline at end of file diff --git a/Game/include/GameEngine.h b/Game/include/GameEngine.h new file mode 100644 index 0000000..e2abf40 --- /dev/null +++ b/Game/include/GameEngine.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include +#include + +#include + + +using SceneContainer = std::tuple +< + Play_s +>; + +class GameEngine +{ +public: + void changeScene(Scene* scene_in) + { + m_previousScene = m_currentScene; + m_currentScene = scene_in; + } + + Scene* getCurrentScene() + { + return m_currentScene; + } + +private: + sf::RenderWindow m_window; + SceneContainer m_scenes; + Scene* m_currentScene; + Scene* m_previousScene; + bool m_running; + +}; \ No newline at end of file diff --git a/Game/include/Scenes.h b/Game/include/Scenes.h new file mode 100644 index 0000000..c393b7f --- /dev/null +++ b/Game/include/Scenes.h @@ -0,0 +1,4 @@ +#pragma once + +#include +#include \ No newline at end of file diff --git a/Game/include/Scenes/Play.h b/Game/include/Scenes/Play.h new file mode 100644 index 0000000..7ed72a6 --- /dev/null +++ b/Game/include/Scenes/Play.h @@ -0,0 +1,8 @@ +#pragma once + +#include "Scene.h" + +class Play_s final : public Scene +{ + +}; \ No newline at end of file diff --git a/Game/include/Scenes/Scene.h b/Game/include/Scenes/Scene.h new file mode 100644 index 0000000..11b06cc --- /dev/null +++ b/Game/include/Scenes/Scene.h @@ -0,0 +1,6 @@ +#pragma once + +class Scene +{ + +}; \ No newline at end of file diff --git a/Game/src/Game.cpp b/Game/src/Game.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Game/src/GameEngine.cpp b/Game/src/GameEngine.cpp new file mode 100644 index 0000000..4d1bb4c --- /dev/null +++ b/Game/src/GameEngine.cpp @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/Game/src/game-main.cpp b/Game/src/game-main.cpp index 4f6684a..edce942 100644 --- a/Game/src/game-main.cpp +++ b/Game/src/game-main.cpp @@ -1,4 +1,3 @@ - #define DRAW_SCREEN 1 #include @@ -8,36 +7,17 @@ #include #include -#include #include -#include int main(int argc, char* argv[]) { LOG("\n\n\033[32mTODO: "); - LOG("-Implement swapback functionality when removing entites"); - LOG("-Implement adding and removing of entities"); - LOG("-Implement EntityManager::update()"); LOG("\033[0m"); EntityManager em; auto x = em.getEntities(Tag::enemy); - - for (auto entt : x) - { - LOG(entt.tag()); - } - - container::HeapArray arr; - arr.setTrueAt(0); - arr.setTrueAt(3); - arr.setFalseAt(3); - - for (auto ent : arr) - { - LOG(ent); - } - + +#if DRAW_SCREEN == 1 auto window = sf::RenderWindow(sf::VideoMode({ 1920u, 1080u }), "2d-platformer"); window.setFramerateLimit(60); if (!ImGui::SFML::Init(window)) @@ -71,11 +51,11 @@ int main(int argc, char* argv[]) ImGui::End(); window.clear(); ImGui::SFML::Render(window); - #if DRAW_SCREEN == 1 + window.display(); - #endif + } ImGui::SFML::Shutdown(); - +#endif } \ No newline at end of file diff --git a/ecc.sh b/ecc.sh new file mode 100755 index 0000000..006ddac --- /dev/null +++ b/ecc.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +./vendor/premake5/premake5 ecc \ No newline at end of file