summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/GameObjects/GameObject.h
blob: a9ddbd7f3c00e04c31179232d786599f1411d487 (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
47
48
49
50
51
52
53
54
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H


#include "Game/Components/Component.h"
#include "Game/TypeMap.h"
#include <memory>
#include "Graphics/global.h"

class GameObject
{
public:
    GameObject();
    ~GameObject(){
        std::cout << "deleting" << std::endl;
    }

    template <typename T>
    void addComponent(std::unique_ptr<T> &&component){
        m_components.put<T>(std::forward<std::unique_ptr<T>>(component));
    }

    template <typename T>
    bool hasComponent(){
        return m_components.contains<T>();
    }

    template <class T>
    T* getComponent(){
        auto comp = m_components.find<T>();
        assert(comp != m_components.end());
        return static_cast<T*>(comp->second.get());
    }

    template <class T>
    void removeComponent(){
//        auto comp = m_components.find<T>();
//        assert(comp != m_components.end());
        m_components.remove<T>();
    }



private:
    void setPlayerPos();
    void makePlayer();

    TypeMap<std::unique_ptr<Component>> m_components;
    std::shared_ptr<Shape> m_object;
    std::shared_ptr<ModelTransform> m_object_mt;

};

#endif // GAMEOBJECT_H