From 1156c0f58b01ff080b9d9ede15b449a845df6654 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 11 Mar 2020 01:52:27 +0100 Subject: Starting on entity system... --- include/entity/Entity.hpp | 46 +++++++++++++++++++++++++++++++++++++++++ include/entity/MeshInstance.hpp | 8 +++++++ 2 files changed, 54 insertions(+) create mode 100644 include/entity/Entity.hpp create mode 100644 include/entity/MeshInstance.hpp (limited to 'include/entity') diff --git a/include/entity/Entity.hpp b/include/entity/Entity.hpp new file mode 100644 index 0000000..853da3a --- /dev/null +++ b/include/entity/Entity.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include "MeshInstance.hpp" +#include "../types.hpp" + +#include + +namespace amalgine { + const int NUM_ENTITIES = 1024; // Should always be a power a multiple of 16, to utilize compiler auto-vectorization + + using Entity = int; + const Entity INVALID_ENTITY = -1; + + using EntityMaskType = u64; + enum EntityMask : EntityMaskType { + ENTITY_MASK_NONE = 0, + ENTITY_MASK_TRANSFORMATION = 1 << 0, + ENTITY_MASK_VELOCITY = 1 << 1, + ENTITY_MASK_MESH_COMPONENT = 1 << 2 + }; + + class EntityWorld { + public: + EntityWorld(); + + // Returns @INVALID_ENTITY on failure + // O(n) + Entity create_entity(EntityMask type); + // O(1) + void remove_entity(Entity entity); + + glm::mat4& get_transformation(Entity entity); + glm::vec3& get_velocity(Entity entity); + MeshInstance& get_mesh_instance(Entity entity); + + + void update(); + private: + EntityMask mask[NUM_ENTITIES]; + + // Components + glm::mat4 transformation[NUM_ENTITIES]; + glm::vec3 velocity[NUM_ENTITIES]; + MeshInstance mesh_instance[NUM_ENTITIES]; + }; +} \ No newline at end of file diff --git a/include/entity/MeshInstance.hpp b/include/entity/MeshInstance.hpp new file mode 100644 index 0000000..004c1c7 --- /dev/null +++ b/include/entity/MeshInstance.hpp @@ -0,0 +1,8 @@ +#pragma once + +namespace amalgine { + class MeshInstance { + public: + void update(); + }; +} \ No newline at end of file -- cgit v1.2.3