Brunot
Loading...
Searching...
No Matches
Node.h
Go to the documentation of this file.
1
13// ____ __ __ __
14// /\__ _\/\ \ /\ \/\ \
15// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
16// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
17// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
18// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
19// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
20
21#pragma once
22
23#include "GameObject.h"
24#include "ChildrenHandeler.h"
25#include <cassert>
26
27#include "System/Camera.h"
28#include "System/Logging.h"
29
30
31class Entity;
32
40class Node final : public GameObject
41{
42public:
43#pragma region Ctors dtors and assignments
44
49 explicit Node(std::unique_ptr<GameObject> gamobj);
50 ~Node() override = default;
51
52 // private: /// @todo:: make copy ctors private in node
53 Node(const Node& other);
54 auto operator=(const Node& other) -> Node&;
55 Node(Node&& other) noexcept = delete;
56 auto operator=(Node&& other) noexcept -> Node& = delete;
57
58#pragma endregion
59
60#pragma region overloaded functions
61
62 auto clone() const -> std::unique_ptr<GameObject> override;
63 auto showMenu() -> void override; // for debug ImGUI
64 void dragTarget();
65 auto update(float dt) -> void override;
66 auto onUpdate(float dt) -> void override;
67
68 auto endWindow() -> void override
69 {
70 }; // for debug ImGUI
71 auto render() -> void override;
72 auto onRender() -> void override;
73 auto onEnterEngine() -> void override;
74 auto for_each(std::function<void(GameObject&)> func) -> void override;
75 auto for_each(std::function<void(const GameObject&)> func) const -> void override;
76 auto load(Stream& stream) -> void override;
77 auto save(Stream& stream) const -> void override;
78 auto getParent() const -> Node* override;
79
85 auto dragAndDrop() -> void;
86
95 auto isDescendantOf(const Node* potentialParent) const -> bool;
96
100 auto moveParent() -> void;
101
108 [[nodiscard]] auto addChild(std::unique_ptr<GameObject> newChild) -> bool override;
109
110
115 auto setShouldUpdate(const bool _shouldUpdate) -> void override;
116
117
122 auto setShouldRender(const bool _shouldRender) -> void override;
123
124
129 auto setShouldReceiveMessages(const bool _shouldReceiveMessages) -> void override;
130
131#pragma endregion
132
133#pragma region node_functions
134
141 template <typename type>
142 auto GetData(gobj::Type typeId) const -> type*
143 {
144 assert(data->isType(typeId));
145 return static_cast<type*>(&(*data));
146 }
147
155 template <typename type>
156 [[nodiscard]] auto ExtractData(gobj::Type typeId) -> std::unique_ptr<type>
157 {
158 assert(data->isType(typeId));
159 return std::unique_ptr<type>(dynamic_cast<type*>(data.release()));
160 }
161
167 auto getDataAsGameObj() const -> GameObject*;
168
169
174 auto add(std::unique_ptr<Node> child) -> bool;
175
180 auto dataType() const -> gobj::Type;
181
182public:
189 auto find(const std::function<bool(GameObject&)>& predicate) -> GameObject*;
190
191
198 auto findDirect(const std::function<bool(GameObject&)>& predicate) -> GameObject*;
199
205 auto deRegisterRecursively() const -> void;
206
211 auto pop() -> std::unique_ptr<Node>;
212
213
214#pragma endregion
215
216 friend auto to_json(json& j, const Node& n) -> void;
217 friend auto from_json(const json& j, Node& n) -> void;
218
219#pragma region GetItrFunctions
220 template <typename T>
222 {
223
224 }
225
226
227 // Later I think I need to make an iterator to find nodes
228 // and whatnot, but right now it isn't used, so it is disabled with a flag
229#pragma endregion
230
231#pragma region NodeIterator
232#define NodeIteratorImplemented 0
233#if NodeIteratorImplemented
234 class Itr
235 {
236 Node*
237 Node* node;
238
239 public:
240 static_assert(std::bidirectional_iterator<Itr>);
241 // typedef std::iterator_traits<> std::output_iterator_tag;
242 // typedef std:: GameObject;
243 // typedef std::difference_type unsigned int;
244 // typedef std::pointer GameObject*;
245 // typedef std::reference GameObject;
246 Itr(Node* node)
247 {
248
249 }
250
251 Itr& operator++()
252 {
253
254 }
255
256 };
257#endif
258
259#pragma endregion
260
261protected:
262 auto getChildren() const -> std::shared_ptr<std::vector<GameObject*>> override;
263 auto GetChildren() const;
264
265private:
266 std::unique_ptr<GameObject> data;
268};
sys::Json Stream
Definition AudioObject.h:20
The class containing Json implemenation for building components.
the base class for the engine, most things inherit from this.
nlohmann::json json
Definition Json.cpp:19
Definition Entity.h:33
the base class for the engine, most things inherit from this.
Definition GameObject.h:77
friend ChildrenHandeler
Definition GameObject.h:87
friend Node
Definition GameObject.h:86
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
gobj::Type type
What type this GameObject is, for type checking, and safe casts.
Definition GameObject.h:490
Manages the heirarchical structure between Systems and Entities.
Definition Node.h:41
auto deRegisterRecursively() const -> void
Tell Messaging to remove all messages to this Node, it's data, and all of it's children,...
Definition Node.cpp:467
auto getParent() const -> Node *override
Definition Node.cpp:344
auto GetData(gobj::Type typeId) const -> type *
Gets a pointer to the data held by a node.
Definition Node.h:142
Node(Node &&other) noexcept=delete
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Node.cpp:315
auto onUpdate(float dt) -> void override
called once every frame.
Definition Node.cpp:298
~Node() override=default
auto moveParent() -> void
Holds the ImGui functionality for moving a node to a different parent in the Engine tree.
Definition Node.cpp:245
auto findDirect(const std::function< bool(GameObject &)> &predicate) -> GameObject *
Finds a GameObject somewhere in the nodes direct children.
Definition Node.cpp:449
std::unique_ptr< GameObject > data
Definition Node.h:266
auto setShouldReceiveMessages(const bool _shouldReceiveMessages) -> void override
set whether the Node, its data, and its children should receiveMessages
Definition Node.cpp:379
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Node.cpp:311
auto showMenu() -> void override
Called before update each frame, for calling ImGui editor code relevant to the gameObject.
Definition Node.cpp:102
friend auto from_json(const json &j, Node &n) -> void
Definition Node.cpp:506
auto setShouldUpdate(const bool _shouldUpdate) -> void override
set whether the Node, its data, and its children should update every frame
Definition Node.cpp:361
auto add(std::unique_ptr< Node > child) -> bool
Gives a node a new Child node.
Definition Node.cpp:393
auto for_each(std::function< void(GameObject &)> func) -> void override
applies a function to every child.
Definition Node.cpp:321
auto addChild(std::unique_ptr< GameObject > newChild) -> bool override
Adds a child to a Node.
Definition Node.cpp:349
auto GetChildren() const
Definition Node.cpp:528
ChildrenHandeler< Node > children
Definition Node.h:267
auto pop() -> std::unique_ptr< Node >
removes this Node from it's parent, handing ownership to the caller
Definition Node.cpp:490
auto ExtractData(gobj::Type typeId) -> std::unique_ptr< type >
removes the data from the node, and relenquishes ownership of it.
Definition Node.h:156
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Node.cpp:331
auto setShouldRender(const bool _shouldRender) -> void override
set whether the Node, its data, and its children should render every frame
Definition Node.cpp:370
auto dataItr() -> GameObject *
Definition Node.h:221
auto operator=(const Node &other) -> Node &
Definition Node.cpp:45
auto getChildren() const -> std::shared_ptr< std::vector< GameObject * > > override
gets a vector of a GameObjects public (i.e.
Definition Node.cpp:515
auto isDescendantOf(const Node *potentialParent) const -> bool
helper function to determine if a node is a descendant of another node.
Definition Node.cpp:228
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Node.cpp:339
auto dragAndDrop() -> void
wrapper function around the drag and drop source functionality in ImGui.
Definition Node.cpp:210
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Node.h:68
Node(std::unique_ptr< GameObject > gamobj)
Definition Node.cpp:27
auto dataType() const -> gobj::Type
Definition Node.cpp:404
auto update(float dt) -> void override
called once every frame.
Definition Node.cpp:284
auto render() -> void override
called every frame after update has been called for every object.
Definition Node.cpp:302
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Node.cpp:97
void dragTarget()
Definition Node.cpp:183
auto getDataAsGameObj() const -> GameObject *
gives a GameObject* to the data held by the node.
Definition Node.cpp:388
friend auto to_json(json &j, const Node &n) -> void
Definition Node.cpp:495
auto find(const std::function< bool(GameObject &)> &predicate) -> GameObject *
Finds a GameObject somewhere in the nodes lower (children, grandchildren, etc.) than the node.
Definition Node.cpp:413
auto operator=(Node &&other) noexcept -> Node &=delete
namespace for things relating to GameObject, other than GameObject itself
Definition Entity.h:229
Type
Definition GameObject.h:45