aboutsummaryrefslogtreecommitdiff
path: root/mwe/ecs-homemade/inc/ComponentManager.h
blob: cfc5f20a5c009ae4ebc92d490763c078496ded66 (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
#pragma once

#include "Components.h"
#include <cstdint>
#include <unordered_map>
#include <vector>
#include <typeindex>
#include <memory>
#include <any>

class ComponentManager {
public:
	static ComponentManager& GetInstance();

	ComponentManager(const ComponentManager&) = delete;
    ComponentManager(ComponentManager&&) = delete;
    ComponentManager& operator=(const ComponentManager&) = delete;
    ComponentManager& operator=(ComponentManager&&) = delete;

	template <typename T>
	void AddComponent(T* component, std::uint32_t id);
	template <typename T>
    T* GetComponent(std::uint32_t id);
	template <typename T>
	std::vector<std::uint32_t> GetAllComponentIDs();
	template <typename T>
	std::vector<T*> GetAllComponentPointer();

private:
    static ComponentManager mInstance;

    ComponentManager();

	std::unordered_map<std::type_index, std::vector<Component*>> mComponents;	//TODO: Make this not only work with Component* OR add extra checks at templated methodes!!!
};

#include "ComponentManager.hpp"