diff --git a/src/EC/Bitset.hpp b/src/EC/Bitset.hpp index b6faf73..e3dc07b 100644 --- a/src/EC/Bitset.hpp +++ b/src/EC/Bitset.hpp @@ -1,5 +1,6 @@ -// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License. +// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed +// under the Academic Free License. // His code is available here: https://github.com/SuperV1234/cppcon2015 @@ -53,7 +54,8 @@ namespace EC EC::Meta::forEach([&bitset] (auto t) { if(EC::Meta::Contains::value) { - bitset[EC::Meta::IndexOf::value] = true; + bitset[EC::Meta::IndexOf::value] = + true; } }); diff --git a/src/EC/EC.hpp b/src/EC/EC.hpp index 9b58346..77590af 100644 --- a/src/EC/EC.hpp +++ b/src/EC/EC.hpp @@ -1,5 +1,6 @@ -// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License. +// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed +// under the Academic Free License. // His code is available here: https://github.com/SuperV1234/cppcon2015 diff --git a/src/EC/Manager.hpp b/src/EC/Manager.hpp index d3c297e..263f501 100644 --- a/src/EC/Manager.hpp +++ b/src/EC/Manager.hpp @@ -1,5 +1,6 @@ -// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License. +// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed +// under the Academic Free License. // His code is available here: https://github.com/SuperV1234/cppcon2015 @@ -29,7 +30,8 @@ namespace EC /*! \brief Manages an EntityComponent system. - EC::Manager must be created with a list of all used Components and all used tags. + EC::Manager must be created with a list of all used Components and all + used tags. Note that all components must have a default constructor. @@ -181,7 +183,8 @@ namespace EC template Component& getEntityData(const std::size_t& index) { - return std::get >(componentsStorage).at(std::get(entities.at(index))); + return std::get >(componentsStorage).at( + std::get(entities.at(index))); } /*! @@ -202,6 +205,41 @@ namespace EC return getEntityData(index); } + /*! + \brief Returns a const reference to a component belonging to the + given Entity. + + This function will return a const reference to a Component + regardless of whether or not the Entity actually owns the reference. + If the Entity doesn't own the Component, changes to the Component + will not affect any Entity. It is recommended to use hasComponent() + to determine if the Entity actually owns that Component. + */ + template + const Component& getEntityData(const std::size_t& index) const + { + return std::get >(componentsStorage).at( + std::get(entities.at(index))); + } + + /*! + \brief Returns a const reference to a component belonging to the + given Entity. + + Note that this function is the same as getEntityData() (const). + + This function will return a const reference to a Component + regardless of whether or not the Entity actually owns the reference. + If the Entity doesn't own the Component, changes to the Component + will not affect any Entity. It is recommended to use hasComponent() + to determine if the Entity actually owns that Component. + */ + template + const Component& getEntityComponent(const std::size_t& index) const + { + return getEntityData(index); + } + /*! \brief Checks whether or not the given Entity has the given Component. @@ -240,7 +278,8 @@ namespace EC result in entity IDs changing if some Entities were marked for deletion. - This function should be called periodically to correctly handle deletion of entities. + This function should be called periodically to correctly handle + deletion of entities. */ void cleanup() { @@ -478,7 +517,8 @@ namespace EC } private: - std::unordered_map > forMatchingFunctions; + std::unordered_map > + forMatchingFunctions; std::size_t functionIndex = 0; public: @@ -664,9 +704,11 @@ namespace EC std::size_t keepSomeMatchingFunctions(List list) { std::size_t deletedCount = 0; - for(auto iter = forMatchingFunctions.begin(); iter != forMatchingFunctions.end();) + for(auto iter = forMatchingFunctions.begin(); + iter != forMatchingFunctions.end();) { - if(std::find(list.begin(), list.end(), iter->first) == list.end()) + if(std::find(list.begin(), list.end(), iter->first) + == list.end()) { iter = forMatchingFunctions.erase(iter); ++deletedCount; diff --git a/src/EC/Meta/Combine.hpp b/src/EC/Meta/Combine.hpp index fab0796..348cd0f 100644 --- a/src/EC/Meta/Combine.hpp +++ b/src/EC/Meta/Combine.hpp @@ -1,5 +1,6 @@ -// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License. +// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed +// under the Academic Free License. // His code is available here: https://github.com/SuperV1234/cppcon2015 @@ -18,7 +19,10 @@ namespace EC using type = TypeList<>; }; - template