aboutsummaryrefslogtreecommitdiff
path: root/source/GameObject.hpp
blob: e1e6dd14a1108d7907de20075a413b95cffe3ea5 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once

#include "EditorAttachment.hpp"
#include "GameObjectTags.hpp"
#include "Material.hpp"
#include "Mesh.hpp"
#include "PodVector.hpp"

#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <vector>

class GameWorld;
class GameObject {
public: // NOTE: public for editors
	std::unique_ptr<EditorAttachment> mEditorAttachment = nullptr;
	GameWorld* mWorld = nullptr;
	GameObject* mParent = nullptr;
	PodVector<GameObject*> mChildren;
	glm::quat mRot{};
	glm::vec3 mPos{};

public:
	static void FreeRecursive(GameObject* object);

	// TODO allow moving between worlds
	explicit GameObject(GameWorld* world);
	virtual ~GameObject();

	GameObject(const GameObject&) = delete;
	GameObject& operator=(const GameObject&) = delete;
	GameObject(GameObject&&) = default;
	GameObject& operator=(GameObject&&) = default;

	GameWorld* GetWorld() const;
	GameObject* GetParent() const;
	const PodVector<GameObject*>& GetChildren() const;
	void AddChild(GameObject* child);
	GameObject* RemoveChild(int index);
	GameObject* RemoveChild(GameObject* child);
	PodVector<GameObject*> RemoveAllChildren();

	EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); }
	void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); }

	const glm::vec3& GetPos();
	void SetPos(const glm::vec3& pos);

	const glm::quat& GetRotation() const;
	void SetRotation(const glm::quat& rotation);

	// Tag
	virtual Tags::GameObjectMemoryManagement GetMemoryManagement() const;
	virtual Tags::GameObjectType GetTypeTag() const;

	// Visuals
	virtual const Material* GetMeshMaterial() const;
	virtual const GpuMesh* GetMesh() const;

	// Lifetime hooks
	virtual void Awaken();
	virtual void Resleep();
	virtual void Update();

protected:
	void SetParent(GameObject* parent);
};