diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-20 21:40:38 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-20 21:40:38 +0100 |
commit | 61bf6d52bdf3c0d14600e48f0c329c62c4db6c65 (patch) | |
tree | e834d1ed2d175a42c1b134cece3c881b1a5948e8 | |
parent | d849aae7a61c4c945230c6af051e8c9d5a071380 (diff) | |
download | YAGE-61bf6d52bdf3c0d14600e48f0c329c62c4db6c65.tar.gz YAGE-61bf6d52bdf3c0d14600e48f0c329c62c4db6c65.zip |
Refactoring comments and adding component groups
-rw-r--r-- | yage/entity/entity.h | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/yage/entity/entity.h b/yage/entity/entity.h index 26d391b5..2f086bea 100644 --- a/yage/entity/entity.h +++ b/yage/entity/entity.h @@ -15,86 +15,109 @@ namespace yage { class Space; -class ComponentPool; +class ComponentGroup; typedef unsigned int Entity; -/** - * Manages entities in a space. +/** Manages entities in a space. */ class EntityManager { public: - /** - * Default instance of an EntityManager. + /** Default instance of an EntityManager. */ EntityManager() = default; - /** - * Creates an instance of the entity manager, which refers back to the space - * it was created in and belongs to. + /** Creates an instance of the entity manager, which refers back to the + * space it was created in and belongs to. * * @param space Current space that the EntityManager belongs to. */ EntityManager(Space *space); - /** - * Creates an instance of the entitiy manager with an initial size. + /** Creates an instance of the entitiy manager with an initial size. * - * @param space Current space that the EntityManager belongs to. - * @param n Initial size of the EntityManager. + * @param space Current space that the EntityManager belongs to. @param n + * Initial size of the EntityManager. */ EntityManager(Space *space, std::size_t n); - /** - * Creates an Entity and returns the handle to the entity, which can then be - * used by the user to do operations on it. + /** Creates an Entity and returns the handle to the entity, which can then + * be used by the user to do operations on it. * * @return The handle to the entity that was created in the space. */ Entity createEntity(); - /** - * Delete an entity. + /** Delete an entity. */ void deleteEntity(Entity entity); private: - /** - * The next available handle to give to the user. + /** The next available handle to give to the user. */ Entity next_entity_ = 0; - /** - * The space that the entity manager belongs to. + /** The space that the entity manager belongs to. */ Space *space_ = nullptr; - /** - * The entities in the current space. + /** The entities in the current space. */ std::vector<Entity> entities_; - std::vector<std::unique_ptr<ComponentPool>> components; + /** Component list of different component groups, that then contain the + * different components for the entities. + */ + std::vector<std::unique_ptr<ComponentGroup>> components; }; +/** Base component used to store components. + * + * Should not be inherited from when declaring a new component. Instead, the + * Component<Derived> should be used. + */ class BaseComponent { public: + /** Group used to register a specific component internally with the entity + * manager. + */ typedef unsigned Group; protected: static Group group_id_counter_; }; +/** The main component that is used to make a component from a defined struct. + * + * A component should only be declared as a struct and should not contain any + * data itself. + */ template <typename Derived> class Component : public BaseComponent { private: + friend class EntityManager; + BaseComponent::Group group(); }; -class ComponentPool { +/** Contains a list of all components that belong to a sepecific group, these + * are then stored in the main entity manager. + */ +class ComponentGroup { private: + friend class EntityManager; + std::vector<BaseComponent *> components_; }; +// Template definitions + +template <typename Derived> +BaseComponent::Group Component<Derived>::group() +{ + static Group group_id = group_id_counter_++; + return group_id; +} + } // namespace yage |