aboutsummaryrefslogtreecommitdiff
path: root/include/entity/Entity.hpp
blob: 853da3a2f844158d8e42b1f057f76c01f2c98db1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include "MeshInstance.hpp"
#include "../types.hpp"

#include <glm/gtc/type_ptr.hpp>

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];
    };
}