aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-06-15 20:00:39 +0100
committerYann Herklotz <ymherklotz@gmail.com>2018-06-15 20:00:39 +0100
commit98b8df435329df6ff3a19ad46f13c8f5bb22ca53 (patch)
treebfca8d4eba96d6857a926ab956e49b9f3c8a3649
parent2acf4bfcbb5c4b457590e0ce6336645bc3900d83 (diff)
downloadYAGE-98b8df435329df6ff3a19ad46f13c8f5bb22ca53.tar.gz
YAGE-98b8df435329df6ff3a19ad46f13c8f5bb22ca53.zip
Adding entity system
-rw-r--r--yage/entity/entity.h137
1 files changed, 30 insertions, 107 deletions
diff --git a/yage/entity/entity.h b/yage/entity/entity.h
index a032ad8a..01a47f5c 100644
--- a/yage/entity/entity.h
+++ b/yage/entity/entity.h
@@ -1,127 +1,50 @@
-/** ---------------------------------------------------------------------------
- * -*- c++ -*-
- * @file: entity.h
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
- * MIT License, see LICENSE file for more details.
- * ----------------------------------------------------------------------------
- */
-
-#pragma once
-
-#include <memory>
+#include <bitset>
#include <vector>
-namespace yage
-{
-
-class Space;
-class ComponentGroup;
-
+/**
+ * The entity is currently just an unsigned integer, which may change to a
+ * class in the future.
+ */
typedef unsigned int Entity;
-/** Manages entities in a space.
+/**
+ * The component mask represents all the components that the entity is
+ * currently attached to.
*/
-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);
+typedef std::bitset<64> ComponentMask;
- /** 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);
+class EntityManager;
- /** 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();
+class BaseSystem;
- /** Delete an entity.
- */
- void deleteEntity(Entity entity);
+template <typename T>
+class System;
-private:
- /** The next available handle to give to the user.
- */
- Entity next_entity_ = 0;
+class BaseComponent;
- /** The space that the entity manager belongs to.
- */
- Space *space_ = nullptr;
+template <typename T>
+class Component;
- /** The entities in the current space.
- */
- std::vector<Entity> entities_;
+class BaseComponentGroup;
- /** Component list of different component groups, that then contain the
- * different components for the entities.
- */
- std::vector<std::unique_ptr<ComponentGroup>> components;
-};
+template <typename T>
+class ComponentGroup;
-/** Base component used to store components.
- *
- * Should not be inherited from when declaring a new component. Instead, the
- * Component<Derived> should be used.
+/**
+ * Has to keep track of all the different entities and their current state.
+ *
+ * The key actions on an Entity are: deleting, creating.
*/
-class BaseComponent
+class EntityManager
{
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();
-};
+ Entity createEntity();
+ EntityManager &deleteEntity(Entity entity);
+ void addComponent(Entity entity, BaseComponent *component);
-/** 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;
+ Entity next_entity_;
- std::vector<BaseComponent *> components_;
+ std::vector<BaseComponentGroup *> component_group_;
+ std::vector<ComponentMask> component_masks_;
};
-
-// Template definitions
-
-template <typename Derived>
-BaseComponent::Group Component<Derived>::group()
-{
- static Group group_id = group_id_counter_++;
- return group_id;
-}
-
-} // namespace yage