diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-20 21:28:00 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-20 21:28:00 +0100 |
commit | d849aae7a61c4c945230c6af051e8c9d5a071380 (patch) | |
tree | aad0b48821f11dd49fe6a2be67d016f9e5f5443c /yage/entity/entity.h | |
parent | 97448eb557d23138e6a460f496d981ced56b59c9 (diff) | |
download | YAGE-d849aae7a61c4c945230c6af051e8c9d5a071380.tar.gz YAGE-d849aae7a61c4c945230c6af051e8c9d5a071380.zip |
Component pool now in entities
Diffstat (limited to 'yage/entity/entity.h')
-rw-r--r-- | yage/entity/entity.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/yage/entity/entity.h b/yage/entity/entity.h new file mode 100644 index 00000000..26d391b5 --- /dev/null +++ b/yage/entity/entity.h @@ -0,0 +1,100 @@ +/** --------------------------------------------------------------------------- + * @file: entity.h + * + * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#pragma once + +#include <vector> +#include <memory> + +namespace yage +{ + +class Space; +class ComponentPool; + +typedef unsigned int Entity; + +/** + * Manages entities in a space. + */ +class EntityManager +{ +public: + /** + * 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. + * + * @param space Current space that the EntityManager belongs to. + */ + EntityManager(Space *space); + + /** + * 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. + */ + 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. + * + * @return The handle to the entity that was created in the space. + */ + Entity createEntity(); + + /** + * Delete an entity. + */ + void deleteEntity(Entity entity); + +private: + /** + * The next available handle to give to the user. + */ + Entity next_entity_ = 0; + + /** + * The space that the entity manager belongs to. + */ + Space *space_ = nullptr; + + /** + * The entities in the current space. + */ + std::vector<Entity> entities_; + + std::vector<std::unique_ptr<ComponentPool>> components; +}; + +class BaseComponent { +public: + typedef unsigned Group; + +protected: + static Group group_id_counter_; +}; + +template <typename Derived> +class Component : public BaseComponent { +private: + BaseComponent::Group group(); +}; + +class ComponentPool { +private: + std::vector<BaseComponent *> components_; +}; + +} // namespace yage |