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 auto dragTarget() -> void;
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 onSceneStart(const std::string& sceneName) -> void override;
75 auto onSceneExit(const std::string& sceneName) -> void override;
76 auto for_each(std::function<void(GameObject&)> func) -> void override;
77 auto for_each(std::function<void(const GameObject&)> func) const -> void override;
78 auto load(const Stream& stream) -> void override;
79 auto save(Stream& stream) const -> void override;
80 auto getParent() const -> Node* override;
81
87 auto dragAndDrop() -> void;
88
97 auto isDescendantOf(const Node* potentialParent) const -> bool;
98
102 auto moveParent() -> void;
103
110 [[nodiscard]] auto addChild(std::unique_ptr<GameObject> newChild) -> bool override;
111
112
117 auto setShouldUpdate(bool _shouldUpdate) -> void override;
118
119
124 auto setShouldRender(bool _shouldRender) -> void override;
125
126
131 auto setShouldReceiveMessages(bool _shouldReceiveMessages) -> void override;
132
133#pragma endregion
134
135#pragma region node_functions
136
143 template <typename type>
144 auto GetData(gobj::Type typeId) const -> type*
145 {
146 assert(data->isType(typeId));
147 return static_cast<type*>(&(*data));
148 }
149
157 template <typename type>
158 [[nodiscard]] auto ExtractData(gobj::Type typeId) -> std::unique_ptr<type>
159 {
160 assert(data->isType(typeId));
161 return std::unique_ptr<type>(dynamic_cast<type*>(data.release()));
162 }
163
169 auto getDataAsGameObj() const -> GameObject*;
170
171
176 auto add(std::unique_ptr<Node> child) -> bool;
177
182 auto dataType() const -> gobj::Type;
183
190 auto find(const std::function<bool(GameObject&)>& predicate) -> GameObject*;
191
192
199 auto findDirect(const std::function<bool(GameObject&)>& predicate) -> GameObject*;
200
206 auto deRegisterRecursively() const -> void;
207
212 auto pop() -> std::unique_ptr<Node>;
213
217 auto deleteDestroyedChildren() -> void;
218
219
220#pragma endregion
221
222 friend auto to_json(json& j, const Node& n) -> void;
223 friend auto from_json(const json& j, Node& n) -> void;
224
225#pragma region GetItrFunctions
226 template <typename T>
228 {
229
230 }
231
232
233 // Later I think I need to make an iterator to find nodes
234 // and whatnot, but right now it isn't used, so it is disabled with a flag
235#pragma endregion
236
237#pragma region NodeIterator
238#define NodeIteratorImplemented 0
239#if NodeIteratorImplemented
240 class Itr
241 {
242 Node*
243 Node* node;
244
245 public:
246 static_assert(std::bidirectional_iterator<Itr>);
247 // typedef std::iterator_traits<> std::output_iterator_tag;
248 // typedef std:: GameObject;
249 // typedef std::difference_type unsigned int;
250 // typedef std::pointer GameObject*;
251 // typedef std::reference GameObject;
252 Itr(Node* node)
253 {
254
255 }
256
257 Itr& operator++()
258 {
259
260 }
261
262 };
263#endif
264
265#pragma endregion
266
267protected:
268 auto getChildren() const -> std::shared_ptr<std::vector<GameObject*>> override;
269 auto GetChildren() const;
270
271private:
272 std::unique_ptr<GameObject> data;
274
275
276};
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:39
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:507
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:484
auto getParent() const -> Node *override
Definition Node.cpp:360
auto GetData(gobj::Type typeId) const -> type *
Gets a pointer to the data held by a node.
Definition Node.h:144
auto setShouldReceiveMessages(bool _shouldReceiveMessages) -> void override
set whether the Node, its data, and its children should receiveMessages
Definition Node.cpp:396
Node(Node &&other) noexcept=delete
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Node.cpp:316
auto onUpdate(float dt) -> void override
called once every frame.
Definition Node.cpp:299
~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:246
auto findDirect(const std::function< bool(GameObject &)> &predicate) -> GameObject *
Finds a GameObject somewhere in the nodes direct children.
Definition Node.cpp:466
std::unique_ptr< GameObject > data
Definition Node.h:272
auto setShouldUpdate(bool _shouldUpdate) -> void override
set whether the Node, its data, and its children should update every frame
Definition Node.cpp:378
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Node.cpp:312
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:528
auto add(std::unique_ptr< Node > child) -> bool
Gives a node a new Child node.
Definition Node.cpp:410
auto for_each(std::function< void(GameObject &)> func) -> void override
applies a function to every child.
Definition Node.cpp:337
auto addChild(std::unique_ptr< GameObject > newChild) -> bool override
Adds a child to a Node.
Definition Node.cpp:366
auto GetChildren() const
Definition Node.cpp:550
auto onSceneStart(const std::string &sceneName) -> void override
Hook that is called before the first frame a scene is run, but after the entire scene is loaded into ...
Definition Node.cpp:322
ChildrenHandeler< Node > children
Definition Node.h:273
auto pop() -> std::unique_ptr< Node >
removes this Node from its parent, handing ownership to the caller
Definition Node.cpp:507
auto ExtractData(gobj::Type typeId) -> std::unique_ptr< type >
removes the data from the node, and relenquishes ownership of it.
Definition Node.h:158
auto dragTarget() -> void
Definition Node.cpp:184
auto dataItr() -> GameObject *
Definition Node.h:227
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:537
auto isDescendantOf(const Node *potentialParent) const -> bool
helper function to determine if a node is a descendant of another node.
Definition Node.cpp:229
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Node.cpp:355
auto dragAndDrop() -> void
wrapper function around the drag and drop source functionality in ImGui.
Definition Node.cpp:211
auto onSceneExit(const std::string &sceneName) -> void override
Hook that is called right before a scene is unloaded To receive the hook, simply override the functio...
Definition Node.cpp:329
auto setShouldRender(bool _shouldRender) -> void override
set whether the Node, its data, and its children should render every frame
Definition Node.cpp:387
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:421
auto update(float dt) -> void override
called once every frame.
Definition Node.cpp:285
auto render() -> void override
called every frame after update has been called for every object.
Definition Node.cpp:303
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Node.cpp:97
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Node.cpp:347
auto deleteDestroyedChildren() -> void
delete all the children of the node that are destroyed
Definition Node.cpp:512
auto getDataAsGameObj() const -> GameObject *
gives a GameObject* to the data held by the node.
Definition Node.cpp:405
friend auto to_json(json &j, const Node &n) -> void
Definition Node.cpp:517
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:430
auto operator=(Node &&other) noexcept -> Node &=delete
namespace for things relating to GameObject, other than GameObject itself
Definition Entity.h:309
Type
Definition GameObject.h:45