Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <unordered_map>
- #define TOTOAL_ENTITIES 1000000
- enum class ComponentType { Position, Sprite, Collider };
- struct PositionComponent
- {
- float x, y, z;
- PositionComponent(float x, float y, float z) :
- x(x), y(y), z(z)
- {
- }
- };
- struct SpriteComponent
- {
- float r, g, b, a;
- SpriteComponent(float r, float g, float b, float a) :
- r(r), g(g), b(b), a(a)
- {
- }
- };
- struct ColliderComponent
- {
- float width, height;
- ColliderComponent(float width, float height) :
- width(width), height(height), b(b), a(a)
- {
- }
- };
- struct Entity
- {
- int index;
- };
- struct ComponentTable
- {
- std::unordered_map<ComponentType, int> componentTypes;
- };
- struct EntityManager
- {
- static int currentEntityID;
- static int currentPositionID;
- static int currentSpriteID;
- static int currentColliderID;
- std::vector<ComponentTable> componentsTable;
- std::vector<PositionComponent> positions;
- std::vector<SpriteComponent> sprites;
- std::vector<ColliderComponent> colliders;
- EntityManager()
- {
- componentsTable.resize(TOTOAL_ENTITIES);
- }
- void AddPositionComponent(const Entity& entity)
- {
- positions.emplace_back(PositionComponent(1, 2, 3));
- componentsTable[entity.index].componentTypes.insert({ ComponentType::Position, positions.size() - 1 });
- }
- void AddSpriteComponent(const Entity& entity)
- {
- sprites.emplace_back(SpriteComponent(1.0f, 0.0f, 0.0f, 0.0f));
- componentsTable[entity.index].componentTypes.insert({ ComponentType::Sprite, sprites.size() - 1 });
- }
- void AddColliderComponent(const Entity& entity)
- {
- colliders.emplace_back(ColliderComponent(100, 200));
- componentsTable[entity.index].componentTypes.insert({ ComponentType::Collider, colliders.size() - 1 });
- }
- };
- int EntityManager::currentEntityID = 0;
- int EntityManager::currentPositionID = 0;
- int EntityManager::currentSpriteID = 0;
- int EntityManager::currentColliderID = 0;
- int main()
- {
- EntityManager em;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement