diff options
Diffstat (limited to 'engine-ocean/Game/GameObjects')
-rw-r--r-- | engine-ocean/Game/GameObjects/GameObject.cpp | 27 | ||||
-rw-r--r-- | engine-ocean/Game/GameObjects/GameObject.h | 54 |
2 files changed, 81 insertions, 0 deletions
diff --git a/engine-ocean/Game/GameObjects/GameObject.cpp b/engine-ocean/Game/GameObjects/GameObject.cpp new file mode 100644 index 0000000..0c7bce8 --- /dev/null +++ b/engine-ocean/Game/GameObjects/GameObject.cpp @@ -0,0 +1,27 @@ +#include "gameobject.h" +#include "Game/Components/DrawComponent.h" + +//GameObject::GameObject(std::shared_ptr<Shape> object, std::shared_ptr<ModelTransform> object_mt) +//{ +// m_object = object; +// m_object_mt = object_mt; +//} + +GameObject::GameObject(){ + +} + +//GameObject::~GameObject(){ + +//} + +//void GameObject::addMaterial(std::string material_name, std::string material_filepath){ +// getComponent<DrawComponent>()->addMaterial("mouse", "/Users/jesswan/Desktop/cs1950u/cs1950u-jjesswan/Resources/Images/mouse.png"); +//} + +//void GameObject::addComps(){ +// addComponent<DrawComponent>(m_object); +// getComponent<DrawComponent>()->addMaterial("mouse", "/Users/jesswan/Desktop/cs1950u/cs1950u-jjesswan/Resources/Images/mouse.png"); +//} + + diff --git a/engine-ocean/Game/GameObjects/GameObject.h b/engine-ocean/Game/GameObjects/GameObject.h new file mode 100644 index 0000000..a9ddbd7 --- /dev/null +++ b/engine-ocean/Game/GameObjects/GameObject.h @@ -0,0 +1,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 |