diff --git a/.gitignore b/.gitignore index 634cd24..a97800a 100644 --- a/.gitignore +++ b/.gitignore @@ -383,4 +383,6 @@ Makefile *.d -*.ninja* \ No newline at end of file +*.ninja* + +.idea/ \ No newline at end of file diff --git a/imgui.ini b/imgui.ini index 07d6d90..c113d5b 100644 --- a/imgui.ini +++ b/imgui.ini @@ -11,6 +11,6 @@ Pos=60,60 Size=536,286 [Window][sdfkjasbdf] -Pos=249,161 +Pos=679,86 Size=610,481 diff --git a/include/Containers.h b/include/Containers.h new file mode 100644 index 0000000..4fe1656 --- /dev/null +++ b/include/Containers.h @@ -0,0 +1,3 @@ +#pragma once + +#include \ No newline at end of file diff --git a/include/Containers/Array.h b/include/Containers/Array.h new file mode 100644 index 0000000..9b81a92 --- /dev/null +++ b/include/Containers/Array.h @@ -0,0 +1,451 @@ +#pragma once + +#include "utility.h" +#include +#include + +namespace container +{ + + +template +class Array +{ +public: + using data_type = T; + using pointer = data_type*; + using reference = data_type&; + using const_pointer = const pointer; + using const_reference = const data_type&; + using difference_type = std::ptrdiff_t; + using iterator_category = std::forward_iterator_tag; + +public: + class Iterator + { + public: + Iterator(const_pointer input) + : m_ptr(input) + { } + + Iterator& operator++() + { + m_ptr++; + return *this; + } + + Iterator operator++(int) + { + auto it = *this; + m_ptr++; + return it; + } + + Iterator& operator--() + { + m_ptr--; + return *this; + } + + + Iterator operator--(int) + { + auto it = *this; + m_ptr++; + return it; + } + + + reference operator[](const int index) const { return m_ptr[index]; } + pointer operator->() const { return m_ptr; } + reference operator*() const { return *m_ptr; } + + bool operator==(const Iterator& other) const { return m_ptr == other.m_ptr; } + bool operator!=(const Iterator& other) const { return m_ptr != other.m_ptr; } + private: + pointer m_ptr; + }; + + class ConstIterator + { + public: + ConstIterator(const_pointer input) + : m_ptr(input) + { } + + ConstIterator& operator++() + { + m_ptr++; + return *this; + } + + ConstIterator operator++(int) + { + auto it = *this; + m_ptr++; + return it; + } + + ConstIterator& operator--() + { + m_ptr--; + return *this; + } + + + ConstIterator operator--(int) + { + auto it = *this; + m_ptr++; + return it; + } + + + const_reference operator[](const int index) const { return m_ptr[index]; } + const_pointer operator->() const { return m_ptr; } + const_reference operator*() const { return *m_ptr; } + + bool operator==(const ConstIterator& other) const { return m_ptr == other.m_ptr; } + bool operator!=(const ConstIterator& other) const { return m_ptr != other.m_ptr; } + + private: + pointer m_ptr; + }; + +public: + Array() { m_data = new T[capacity]; } + + ~Array() { delete[] m_data; } + + Array(const Array&) = delete; + + Array(Array&& other) + : m_data(other.m_data) + { + other.m_data = nullptr; + } + + + Array& operator=(Array&& other) + { + if (this != &other) + { + delete[] m_data; + m_data = other.m_data; + other.m_data = nullptr; + } + + return *this; + } + + + pointer data() { return m_data; } + + reference operator[](const int index) { return m_data[index]; } + + const_reference operator[](const int index) const { return m_data[index]; } + + inline constexpr EntityIndex size() { return capacity; } + + Iterator begin() { return Iterator(m_data); } + Iterator end() { return Iterator(m_data + capacity); } + + ConstIterator cbegin() const { return ConstIterator(m_data); } + ConstIterator cend() const { return ConstIterator(m_data + capacity); } + +private: + pointer m_data; + +}; + + +template +class Array +{ +public: + class reference; + class const_reference; + using data_type = u8; + using pointer = reference; + using const_pointer = const_reference; + using difference_type = std::ptrdiff_t; + using iterator_category = std::forward_iterator_tag; + +public: + class reference + { + friend class Array; + reference(data_type* ptr_in, u8 mask_in) + : m_ptr(ptr_in) + , m_mask(mask_in) + { + + } + + public: + ~reference() + { } + + reference(const reference&) = default; + + operator bool () const + { + return !!(*m_ptr & m_mask); + } + + reference& operator=(bool input) + { + if (input) + { + *m_ptr |= m_mask; + } + else + { + *m_ptr &= m_mask; + } + return *this; + } + + reference& operator=(const reference& other) + { + return *this = bool(other); + } + + void flip() + { + *m_ptr ^= m_mask; + } + + private: + data_type* m_ptr; + u8 m_mask; + }; + + class const_reference + { + friend class Array; + const_reference(data_type* ptr_in, u8 mask_in) + : m_ptr(ptr_in) + , m_mask(mask_in) + { } + + public: + ~const_reference() + { } + + const_reference(const const_reference&) = delete; + + operator bool () const { return !!(*m_ptr & m_mask); } + + const_reference& operator=(bool) = delete; + + const_reference& operator=(const const_reference& other) = delete; + const_reference& operator=(const reference& other) = delete; + void flip() = delete; + + private: + const data_type* m_ptr; + u8 m_mask; + }; + + + class Iterator + { + public: + Iterator(data_type* input, u8 index) + : m_ptr(input) + , m_currentClusterIndex(index) + { } + + Iterator& operator++() + { + if (m_currentClusterIndex++ == 7) + { + m_currentClusterIndex = 0; + m_ptr++; + } + + return *this; + } + + Iterator operator++(int) + { + auto it = *this; + if (m_currentClusterIndex++ == 7) + { + m_ptr++; + m_currentClusterIndex = 0; + } + + return it; + } + + Iterator& operator--() + { + if (m_currentClusterIndex-- == 0) + { + m_ptr--; + m_currentClusterIndex = 7; + } + + return *this; + } + + Iterator operator--(int) + { + auto it = *this; + if (m_currentClusterIndex-- == 0) + { + m_ptr--; + m_currentClusterIndex = 7; + } + + return it; + } + + bool operator[](const int) = delete; + reference operator*() const + { + return reference(m_ptr, 1 << m_currentClusterIndex); + } + + bool operator==(const Iterator& other) const + { + return (m_ptr == other.m_ptr) && (m_currentClusterIndex == other.m_currentClusterIndex); + } + + bool operator!=(const Iterator& other) const + { + return (m_ptr != other.m_ptr) || (m_currentClusterIndex != other.m_currentClusterIndex); + } + + private: + data_type* m_ptr; + u8 m_currentClusterIndex{}; + }; + + class ConstIterator + { + public: + ConstIterator(const data_type* input, u8 index) + : m_ptr(input) + , m_currentClusterIndex(index) + { } + + ConstIterator& operator++() + { + if (m_currentClusterIndex++ == 7) + { + m_currentClusterIndex = 0; + m_ptr++; + } + + return *this; + } + + ConstIterator operator++(int) + { + auto it = *this; + if (m_currentClusterIndex++ == 7) + { + m_ptr++; + m_currentClusterIndex = 0; + } + + return it; + } + + ConstIterator& operator--() + { + if (m_currentClusterIndex-- == 0) + { + m_ptr--; + m_currentClusterIndex = 7; + } + + return *this; + } + + ConstIterator operator--(int) + { + auto it = *this; + if (m_currentClusterIndex-- == 0) + { + m_ptr--; + m_currentClusterIndex = 7; + } + + return it; + } + + bool operator[](const int) = delete; + const_reference operator*() const + { + return const_reference(m_ptr, 1 << m_currentClusterIndex); + } + + bool operator==(const ConstIterator& other) const + { return (m_ptr == other.m_ptr) && (m_currentClusterIndex == other.m_currentClusterIndex); } + + + bool operator!=(const ConstIterator& other) const + { return (m_ptr != other.m_ptr) || (m_currentClusterIndex != other.m_currentClusterIndex); } + + private: + const data_type* m_ptr; + u8 m_currentClusterIndex{}; + }; + +public: + Array() { m_data = new data_type[(capacity / 8) + 1]; } + + ~Array() { delete[] m_data; } + + Array(const Array&) = delete; + + Array(Array&& other) + : m_data(other.m_data) + { + other.m_data = nullptr; + } + + Array& operator=(Array&& other) + { + if (this != &other) + { + delete[] m_data; + m_data = other.m_data; + other.m_data = nullptr; + } + + return *this; + } + + data_type* data() { return m_data; } + + //use readAt() instead + reference operator[](int index) + { + return reference(m_data + (index / 8), 1 << (index % 8)); + } + + inline constexpr EntityIndex size() { return capacity; } + + bool readAt(const int index) const { return m_data[index / 8] & (1 << (index % 8)); } + + void setTrueAt(const int index) { m_data[index / 8] |= (1 << (index % 8)); } + + void setFalseAt(const int index) { m_data[index / 8] &= ~(1 << (index % 8)); } + + Iterator begin() { return Iterator(m_data, 0); } + Iterator end() { return Iterator(m_data + (capacity / 8), capacity % 8); } + + ConstIterator cbegin() const { return ConstIterator(m_data, 0); } + ConstIterator cend() const { return ConstIterator(m_data + (capacity / 8), capacity % 8); } + +private: + data_type* m_data; + +}; + +}//namespace \ No newline at end of file diff --git a/include/Entities/Components.h b/include/Entities/Components.h index 9067825..a23b526 100644 --- a/include/Entities/Components.h +++ b/include/Entities/Components.h @@ -17,11 +17,11 @@ public: sf::Vector2f position{}; sf::Vector2f speed{}; - Transform() = default; - Transform(sf::Vector2f position_in, sf::Vector2f speed_in) - : position(position_in) - , speed(speed_in) - { } + Transform() = default; + Transform(sf::Vector2f position_in, sf::Vector2f speed_in) + : position(position_in) + , speed(speed_in) + { } }; diff --git a/include/Entities/Entity.h b/include/Entities/Entity.h index 0406579..cd72e9e 100644 --- a/include/Entities/Entity.h +++ b/include/Entities/Entity.h @@ -11,31 +11,31 @@ class Entity //private: public: friend class EntityManager; - friend class EntityViewIterator; - friend class EntityViewConstIterator; + friend class EntityViewIterator; + friend class EntityViewConstIterator; Entity() = delete; - Entity(EntityIndex); + Entity(EntityIndex); public: - template - bool hasComponent() const; + template + bool hasComponent() const; - template - T& getComponent() const; + template + T& getComponent() const; - template - T& getComponent(); + template + T& getComponent(); - template - void addComponent(const T&&); + template + void addComponent(const T&&); - EntityIndex id() const; + EntityIndex id() const; - EntityTag tag() const; + EntityTag tag() const; - bool isAlive() const; + bool isAlive() const; private: - EntityIndex m_id; + EntityIndex m_index; }; \ No newline at end of file diff --git a/include/Entities/EntityManager.h b/include/Entities/EntityManager.h index 0697b55..3ccbec6 100644 --- a/include/Entities/EntityManager.h +++ b/include/Entities/EntityManager.h @@ -8,12 +8,14 @@ class EntityManager { +public: + void update(); private: - EntityView getEntiites(EntityTag); + EntityView getEntiites(EntityTag); - inline Entity player(); + inline Entity player(); private: - Entity m_player{0}; - std::array m_numEntitiesByTag{}; - u16 m_numEntities{}; + Entity m_player{0}; + std::array m_numEntitiesByTag{}; + u16 m_numEntities{}; }; diff --git a/include/Entities/EntityMemoryPool.h b/include/Entities/EntityMemoryPool.h index c61498b..b231951 100644 --- a/include/Entities/EntityMemoryPool.h +++ b/include/Entities/EntityMemoryPool.h @@ -1,5 +1,7 @@ #pragma once +#include "utility.h" +#include #include #include @@ -19,27 +21,30 @@ private: ComponentVectorTuple m_components; std::vector m_tags; std::vector m_aliveStates; - + std::vector m_ids; + private: EntityMemoryPool(); EntityMemoryPool(const EntityMemoryPool&) = delete; public: - static EntityMemoryPool& instance(); + static EntityMemoryPool& instance(); - template - bool hasComponent(EntityIndex) const; - - template - T& getComponent(EntityIndex) const; + template + bool hasComponent(EntityIndex) const; + + template + T& getComponent(EntityIndex) const; - template - T& getComponent(EntityIndex); + template + T& getComponent(EntityIndex); - EntityTag getTag(EntityIndex) const; + EntityTag getTag(EntityIndex) const; - bool getAlive(EntityIndex) const; + bool getAlive(EntityIndex) const; - void removeEntity(EntityIndex); + size_t getId(EntityIndex) const; + + void removeEntity(EntityIndex); }; \ No newline at end of file diff --git a/include/Entities/EntityView.h b/include/Entities/EntityView.h index 71f9e80..ff453ea 100644 --- a/include/Entities/EntityView.h +++ b/include/Entities/EntityView.h @@ -7,77 +7,72 @@ class EntityView; class EntityViewIterator { - friend class EntityView; + friend class EntityView; - EntityViewIterator(EntityIndex); + EntityViewIterator(EntityIndex); - EntityViewIterator& operator++(); + EntityViewIterator& operator++(); - EntityViewIterator operator++(int); + EntityViewIterator operator++(int); - EntityViewIterator& operator--(); + EntityViewIterator& operator--(); - EntityViewIterator operator--(int); + EntityViewIterator operator--(int); - Entity operator*(); + Entity operator*(); - Entity operator[](int); - Entity* operator->(); + Entity operator[](int); - bool operator==(EntityViewIterator); - bool operator!=(EntityViewIterator); + bool operator==(EntityViewIterator); + bool operator!=(EntityViewIterator); private: - Entity m_currentEntity; + EntityIndex m_currentEntity; }; class EntityViewConstIterator { - friend class EntityView; - - EntityViewConstIterator(EntityIndex index); + friend class EntityView; + + EntityViewConstIterator(EntityIndex index); - EntityViewConstIterator& operator++(); + EntityViewConstIterator& operator++(); - EntityViewConstIterator operator++(int); + EntityViewConstIterator operator++(int); - EntityViewConstIterator& operator--(); + EntityViewConstIterator& operator--(); - EntityViewConstIterator operator--(int); + EntityViewConstIterator operator--(int); - const Entity operator*(); + const Entity operator*(); - const Entity operator[](int index); - - const Entity* operator->(); + const Entity operator[](int index); - bool operator==(EntityViewConstIterator); - bool operator!=(EntityViewConstIterator); + bool operator==(EntityViewConstIterator); + bool operator!=(EntityViewConstIterator); private: - Entity m_currentEntity; + EntityIndex m_currentEntity; }; class EntityView { public: - friend class EntityManager; - EntityView() = delete; - EntityView(EntityIndex, EntityIndex); + friend class EntityManager; + EntityView() = delete; + EntityView(EntityIndex, EntityIndex); - using iterator = EntityViewIterator; - using const_iterator = EntityViewConstIterator; + using iterator = EntityViewIterator; + using const_iterator = EntityViewConstIterator; - iterator begin() { return iterator(m_start); } - iterator end() { return iterator(m_start + m_size); } + iterator begin() { return iterator(m_start); } + iterator end() { return iterator(m_start + m_size); } - - - const_iterator cbegin() const { return const_iterator(m_start); } - const_iterator cend() const { return const_iterator(m_start + m_size); } + const_iterator cbegin() const { return const_iterator(m_start); } + const_iterator cend() const { return const_iterator(m_start + m_size); } private: - EntityIndex m_start; - EntityIndex m_size; + EntityIndex m_start; + EntityIndex m_size; }; diff --git a/include/log.h b/include/log.h index 941e055..835b47c 100644 --- a/include/log.h +++ b/include/log.h @@ -3,7 +3,9 @@ #include #ifdef LOG_ENABLE +#define LOG_CONDITON(x) if (x) #define LOG(x) std::cout << x << "\n" #else #define LOG(x) +#define LOG_CONDITON(x) #endif \ No newline at end of file diff --git a/include/utility.h b/include/utility.h index dbc2c65..eb2f225 100644 --- a/include/utility.h +++ b/include/utility.h @@ -17,10 +17,10 @@ using EntityIndex = u16; enum EntityTag : u8 { - player, - tile, - enemy, - tagCount + player, + tile, + enemy, + tagCount }; @@ -29,28 +29,32 @@ namespace util { using namespace std::string_view_literals; - - inline constexpr EntityIndex MAX_ENTITIES {60'000u}; - inline constexpr EntityIndex MAX_TILES {1'000u}; - inline constexpr EntityIndex MAX_ENEMIES {1'000u}; + inline constexpr EntityIndex MAX_PLAYERS{1u}; + inline constexpr EntityIndex MAX_TILES {1'000u}; + inline constexpr EntityIndex MAX_ENEMIES {1'000u}; + inline constexpr EntityIndex MAX_ENTITIES {MAX_PLAYERS + MAX_TILES + MAX_ENEMIES}; // used for imgui inline constexpr std::array tagStringsC = { - "player" + "player", + "tile", + "enemy" }; inline constexpr std::array tagStrings = { - "player"sv + "player"sv, + "tile"sv, + "enemy"sv }; - inline constexpr std::array tagStart = - { - 0,//player - 1,//tile start - MAX_TILES,//enemy start - }; + inline constexpr std::array tagStart = + { + 0,//player + 1,//tile start + MAX_TILES,//enemy start + }; } diff --git a/src/Classes/Entity.cpp b/src/Classes/Entity.cpp deleted file mode 100644 index dea76b0..0000000 --- a/src/Classes/Entity.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include - -#include - -Entity::Entity(EntityIndex id_in) - : m_id(id_in) -{ - -} - -template -bool Entity::hasComponent() const -{ - return EntityMemoryPool::instance().hasComponent(m_id); -} - -template -T& Entity::getComponent() const -{ - return EntityMemoryPool::instance().getComponent(m_id); -} - -template -T& Entity::getComponent() -{ - return EntityMemoryPool::instance().getComponent(m_id); -} - -template -void Entity::addComponent(const T&& data) -{ - T& component = EntityMemoryPool::instance().getComponent(m_id); - component = data; - component.active = true; -} - -EntityIndex Entity::id() const -{ - return m_id; -} - -EntityTag Entity::tag() const -{ - return EntityMemoryPool::instance().getTag(m_id); -} - -bool Entity::isAlive() const -{ - return EntityMemoryPool::instance().getAlive(m_id); -} \ No newline at end of file diff --git a/src/Classes/EntityMemoryPool.cpp b/src/Classes/EntityMemoryPool.cpp deleted file mode 100644 index baec869..0000000 --- a/src/Classes/EntityMemoryPool.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#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); -} - -EntityMemoryPool& EntityMemoryPool::instance() -{ - static EntityMemoryPool pool{}; - return pool; -} - -template -bool EntityMemoryPool::hasComponent(EntityIndex id) const -{ - return std::get>(m_components)[id].active; -} - -template -T& EntityMemoryPool::getComponent(EntityIndex id) const -{ - return std::get>(m_components)[id]; -} - -template -T& EntityMemoryPool::getComponent(EntityIndex id) -{ - return std::get>(m_components)[id]; -} - -EntityTag EntityMemoryPool::getTag(EntityIndex id) const -{ - return m_tags[id]; -} - -bool EntityMemoryPool::getAlive(EntityIndex id) const -{ - return m_aliveStates[id]; -} - -void EntityMemoryPool::removeEntity(EntityIndex id) -{ - m_aliveStates[id] = false; - return; -} \ No newline at end of file diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp new file mode 100644 index 0000000..bf69fb7 --- /dev/null +++ b/src/Entities/Entity.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +#include + +Entity::Entity(EntityIndex index_in) + : m_index(index_in) +{ + +} + +template +bool Entity::hasComponent() const +{ + return EntityMemoryPool::instance().hasComponent(m_index); +} + +template +T& Entity::getComponent() const +{ + return EntityMemoryPool::instance().getComponent(m_index); +} + +template +T& Entity::getComponent() +{ + return EntityMemoryPool::instance().getComponent(m_index); +} + +template +void Entity::addComponent(const T&& data) +{ + T& component = EntityMemoryPool::instance().getComponent(m_index); + component = data; + component.active = true; +} + +EntityIndex Entity::id() const +{ + return EntityMemoryPool::instance().getId(m_index); +} + +EntityTag Entity::tag() const +{ + return EntityMemoryPool::instance().getTag(m_index); +} + +bool Entity::isAlive() const +{ + return EntityMemoryPool::instance().getAlive(m_index); +} \ No newline at end of file diff --git a/src/Classes/EntityManager.cpp b/src/Entities/EntityManager.cpp similarity index 68% rename from src/Classes/EntityManager.cpp rename to src/Entities/EntityManager.cpp index 4a99138..e18fa01 100644 --- a/src/Classes/EntityManager.cpp +++ b/src/Entities/EntityManager.cpp @@ -5,12 +5,17 @@ inline constexpr EntityIndex PLAYER_INDEX = 0; +void EntityManager::update() +{ + +} + inline Entity EntityManager::player() { - return m_player; + return m_player; } EntityView EntityManager::getEntiites(EntityTag tag) { - return EntityView(util::tagStart[tag], m_numEntitiesByTag[tag]); + return EntityView(util::tagStart[tag], m_numEntitiesByTag[tag]); } \ No newline at end of file diff --git a/src/Entities/EntityMemoryPool.cpp b/src/Entities/EntityMemoryPool.cpp new file mode 100644 index 0000000..63e6473 --- /dev/null +++ b/src/Entities/EntityMemoryPool.cpp @@ -0,0 +1,58 @@ +#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); +} + +EntityMemoryPool& EntityMemoryPool::instance() +{ + static EntityMemoryPool pool{}; + return pool; +} + +template +bool EntityMemoryPool::hasComponent(EntityIndex index) const +{ + return std::get>(m_components)[index].active; +} + +template +T& EntityMemoryPool::getComponent(EntityIndex index) const +{ + return std::get>(m_components)[index]; +} + +template +T& EntityMemoryPool::getComponent(EntityIndex index) +{ + return std::get>(m_components)[index]; +} + +EntityTag EntityMemoryPool::getTag(EntityIndex index) const +{ + return m_tags[index]; +} + +bool EntityMemoryPool::getAlive(EntityIndex index) const +{ + return m_aliveStates[index]; +} + +size_t EntityMemoryPool::getId(EntityIndex index) const +{ + return m_ids[index]; +} + +void EntityMemoryPool::removeEntity(EntityIndex index) +{ + m_aliveStates[index] = false; + return; +} \ No newline at end of file diff --git a/src/Classes/EntityView.cpp b/src/Entities/EntityView.cpp similarity index 57% rename from src/Classes/EntityView.cpp rename to src/Entities/EntityView.cpp index 9375981..a19ddcc 100644 --- a/src/Classes/EntityView.cpp +++ b/src/Entities/EntityView.cpp @@ -3,8 +3,8 @@ #include "utility.h" EntityView::EntityView(EntityIndex start, EntityIndex size) - : m_start(start) - , m_size(size) + : m_start(start) + , m_size(size) { } @@ -12,112 +12,102 @@ EntityView::EntityView(EntityIndex start, EntityIndex size) //non-const iterator EntityViewIterator::EntityViewIterator(EntityIndex index) - : m_currentEntity(index) + : m_currentEntity(index) { } EntityViewIterator& EntityViewIterator::operator++() { - m_currentEntity.m_id++; - return *this; + m_currentEntity++; + return *this; } EntityViewIterator EntityViewIterator::operator++(int) { - m_currentEntity.m_id++; - return m_currentEntity.m_id - 1; + m_currentEntity++; + return m_currentEntity - 1; } EntityViewIterator& EntityViewIterator::operator--() { - m_currentEntity.m_id--; - return *this; + m_currentEntity--; + return *this; } EntityViewIterator EntityViewIterator::operator--(int) { - m_currentEntity.m_id--; - return m_currentEntity.m_id + 1; + m_currentEntity--; + return m_currentEntity + 1; } Entity EntityViewIterator::operator*() { - return m_currentEntity; + return m_currentEntity; } Entity EntityViewIterator::operator[](int index) { - return m_currentEntity.m_id + index; -} - -Entity* EntityViewIterator::operator->() -{ - return &m_currentEntity; + return m_currentEntity + index; } bool EntityViewIterator::operator==(EntityViewIterator other) { - return m_currentEntity.m_id == other->m_id; + return m_currentEntity == other.m_currentEntity; } bool EntityViewIterator::operator!=(EntityViewIterator other) { - return m_currentEntity.m_id != other->m_id; + return m_currentEntity != other.m_currentEntity; } //const iterator EntityViewConstIterator::EntityViewConstIterator(EntityIndex index) - : m_currentEntity(index) + : m_currentEntity(index) { } EntityViewConstIterator& EntityViewConstIterator::operator++() { - m_currentEntity.m_id++; - return *this; + m_currentEntity++; + return *this; } EntityViewConstIterator EntityViewConstIterator::operator++(int) { - m_currentEntity.m_id++; - return m_currentEntity.m_id - 1; + m_currentEntity++; + return m_currentEntity - 1; } EntityViewConstIterator& EntityViewConstIterator::operator--() { - m_currentEntity.m_id--; - return *this; + m_currentEntity--; + return *this; } EntityViewConstIterator EntityViewConstIterator::operator--(int) { - m_currentEntity.m_id--; - return m_currentEntity.m_id + 1; + m_currentEntity--; + return m_currentEntity + 1; } const Entity EntityViewConstIterator::operator*() { - return m_currentEntity; + return m_currentEntity; } const Entity EntityViewConstIterator::operator[](int index) { - return m_currentEntity.m_id + index; -} - -const Entity* EntityViewConstIterator::operator->() -{ - return &m_currentEntity; + return m_currentEntity + index; } bool EntityViewConstIterator::operator==(EntityViewConstIterator other) { - return m_currentEntity.m_id == other->m_id; + return m_currentEntity == other.m_currentEntity; } bool EntityViewConstIterator::operator!=(EntityViewConstIterator other) { - return m_currentEntity.m_id != other->m_id; + return m_currentEntity != other.m_currentEntity; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index d463fa1..66a143b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ +#include "Containers/Array.h" +#include "log.h" #include #include #include @@ -10,34 +12,35 @@ int main() { + container::Array arr; - auto window = sf::RenderWindow(sf::VideoMode({ 1920u, 1080u }), "Fake Mario"); - window.setFramerateLimit(144); - if (!ImGui::SFML::Init(window)) - return -1; + auto window = sf::RenderWindow(sf::VideoMode({ 1920u, 1080u }), "Fake Mario"); + window.setFramerateLimit(144); + if (!ImGui::SFML::Init(window)) + return -1; - sf::Clock clock; - while (window.isOpen()) - { - while (const std::optional event = window.pollEvent()) - { - ImGui::SFML::ProcessEvent(window, *event); + sf::Clock clock; + while (window.isOpen()) + { + while (const std::optional event = window.pollEvent()) + { + ImGui::SFML::ProcessEvent(window, *event); - if (event->is()) - { - window.close(); - } - }// end user input loop + if (event->is()) + { + window.close(); + } + }// end user input loop - ImGui::SFML::Update(window, clock.restart()); + ImGui::SFML::Update(window, clock.restart()); - ImGui::Begin("sdfkjasbdf"); - ImGui::End(); - window.clear(); - ImGui::SFML::Render(window); - window.display(); - } + ImGui::Begin("sdfkjasbdf"); + ImGui::End(); + window.clear(); + ImGui::SFML::Render(window); + window.display(); + } - ImGui::SFML::Shutdown(); - + ImGui::SFML::Shutdown(); + } \ No newline at end of file diff --git a/src/utility.cpp b/src/utility.cpp deleted file mode 100644 index e69de29..0000000