aboutsummaryrefslogtreecommitdiff
path: root/source/GameObject.hpp
blob: 750ae4a48f35ba98dac7b35309498b9c94d93d17 (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
#pragma once

#include "EditorCoreAPI.hpp"
#include "GameObjectTypeTag.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<EditorGameObjectAttachment, EditorGameObjectAttachmentDeleter> 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();

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

	// 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);
};