31#define LOG_CHILDREN_HANDELER 0
40template <
class C = Component>
77 for (
auto& [key, pointer] : other.children)
81 auto copy = pointer->clone();
83 auto copyCast =
static_cast<C*
>(copy.release());
85 children[copyCast->getKey()] = (std::unique_ptr<C>(copyCast));
98 ,
children(std::move(other.children))
116 children = std::move(other.children);
140 constexpr auto pointer = 1;
146 , child->getFormattedName());
148 if (!child->getInternalParent())
150 hlg::Error(
"{} doesn't have a parent. Something is very wrong", child->getFormattedName());
153 if (key.getUUID() != child->getUUID())
155 hlg::Error(
"key uuid {} does not match {}", key.getUUID(), child->getFormattedName());
161 static auto to_erase = [](
auto& pair)
163 if (pair.second->destroyed())
165 hlg::Trace(
"{} was found to be destroyed, it will be removed"
166 , pair.second->getFormattedName()
168 return pair.second->destroyed();
190 for (
auto&& [key, child] :
children)
203 for (
auto&& child : std::views::values(
children))
205 child->checkAddToSceneHook();
213 *
this = stream.data();
219 stream.data() = *
this;
225 return std::make_unique<ChildrenHandeler>(*
this);
232 for (
auto&& [key, child] :
children)
234 child->setShouldUpdate(_shouldUpdate);
242 for (
auto&& [key, child] :
children)
244 child->setShouldRender(_shouldRender);
252 for (
auto&& [key, child] :
children)
254 child->setShouldReceiveMessages(_shouldReceiveMessages);
259 auto add(std::unique_ptr<C> newChild) ->
void
261 assert(newChild &&
"ChildHandler add was passed null unique_ptr");
262 children[newChild->getKey()] = std::move(newChild);
281 auto for_each(std::function<
void(
const C&)> func)
const ->
void
318 auto find(std::function<
bool(
C&)> predicate) ->
C*
321 constexpr auto obj_ptr = 1;
324 if (predicate(*get<obj_ptr>(child)))
328 return &*get<obj_ptr>(child);
353 auto result = std::make_shared<std::vector<GameObject*>>();
357 result->push_back(ptr.get());
372 assert(
false &&
"Tried to remove an object that doesn't exist");
373 hlg::Error(
"Tried to remove an object that doesn't exist");
375 auto& [mapKey, ptr] = *itrToPtr;
376 std::unique_ptr<C> pointer = std::move(ptr);
390 if (!(get<1>(child)->
parentTo(&parent)))
392 assert(0 &&
"Setting parents in children handeler");
398 template <
typename C>
400 template <
typename C>
419 j[
"GameObject"] = ch.getGameObjectJson();
420 for (
auto& child : ch.children)
422 j[
"children"].push_back(*(get<1>(child)));
438 assert(0 &&
"Children Handler with non-Node and non-Component");
439 ch.setGameObjectJson(j.at(
"GameObject"));
static FMOD_RESULT result
Definition AudioObject.cpp:27
sys::Json Stream
Definition AudioObject.h:20
auto BuildComponent(unsigned int comp, const json &j) -> Component *
Definition ChildrenHandeler.cpp:59
auto from_json(const json &j, ChildrenHandeler< C > &ch) -> void
Definition ChildrenHandeler.h:431
auto to_json(json &j, const ChildrenHandeler< C > &ch) -> void
Definition ChildrenHandeler.h:417
The base class for components, holding all of their shared All components should inherit from this.
the base class for the engine, most things inherit from this.
nlohmann::json json
Definition Json.cpp:19
auto render() -> void override
called every frame after update has been called for every object.
Definition ChildrenHandeler.h:187
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition ChildrenHandeler.h:201
auto operator=(ChildrenHandeler &&other) noexcept -> ChildrenHandeler &
move assignment operator
Definition ChildrenHandeler.h:109
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition ChildrenHandeler.h:182
std::map< Key, std::unique_ptr< C > > children
A map that olds unique pointers to child objects, and a key that organizes them.
Definition ChildrenHandeler.h:410
auto getChildrenRange() const -> std::shared_ptr< std::vector< GameObject * > >
A function designed for Paths to use, for getting a list of all children, in a manageable format.
Definition ChildrenHandeler.h:349
auto setShouldReceiveMessages(const bool _shouldReceiveMessages) -> void override
set whether the GameObject should Receive Messags, and whether all of it's children should receive me...
Definition ChildrenHandeler.h:248
~ChildrenHandeler() override=default
default dtor.
auto onUpdate(float dt) -> void override
called once every frame.
Definition ChildrenHandeler.h:176
auto add(std::unique_ptr< C > newChild) -> void
Definition ChildrenHandeler.h:259
auto setShouldRender(const bool _shouldRender) -> void override
set whether the GameObject should render every frame, and whether all of it's children should render ...
Definition ChildrenHandeler.h:238
auto showMenu() -> void override
Called before update each frame, for calling ImGui editor code relevant to the gameObject.
Definition ChildrenHandeler.h:127
auto find(std::function< bool(C &)> predicate) -> C *
Returns pointer to child object.
Definition ChildrenHandeler.h:318
auto for_each(std::function< void(const C &)> func) const -> void
applies a function to every child.
Definition ChildrenHandeler.h:281
ChildrenHandeler(ChildrenHandeler &&other) noexcept
Move Constructor.
Definition ChildrenHandeler.h:96
auto setParents(GameObject &parent) -> void
Set's all managed objects parent to one passed in.
Definition ChildrenHandeler.h:385
friend auto from_json(const json &j, ChildrenHandeler< C > &ch) -> void
Definition ChildrenHandeler.h:431
auto for_each(std::function< void(C &)> func) -> void
applies a function to every child.
Definition ChildrenHandeler.h:269
friend auto to_json(json &j, const ChildrenHandeler< C > &ch) -> void
Definition ChildrenHandeler.h:417
ChildrenHandeler(const ChildrenHandeler &other)
deep copy of ChildrenHandeler
Definition ChildrenHandeler.h:58
auto for_each(std::function< void(GameObject &)> func) -> void
applies a function to every child.
Definition ChildrenHandeler.h:293
auto count() -> size_t
Definition ChildrenHandeler.h:335
auto onRender() -> void override
called every frame after update has been called for every object.
Definition ChildrenHandeler.h:197
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition ChildrenHandeler.h:217
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition ChildrenHandeler.h:210
auto getChildren() const -> std::shared_ptr< std::vector< GameObject * > > override
gets a vector of a GameObjects public (i.e.
Definition ChildrenHandeler.h:340
auto setShouldUpdate(const bool _shouldUpdate) -> void override
set whether the GameObject should update every frame, and whether all of it's children should update ...
Definition ChildrenHandeler.h:228
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition ChildrenHandeler.h:223
auto for_each(std::function< void(const GameObject &)> func) const -> void override
applies a function to every child.
Definition ChildrenHandeler.h:305
auto operator=(const ChildrenHandeler &other) -> ChildrenHandeler &
Copy assignment operator.
Definition ChildrenHandeler.h:69
ChildrenHandeler()
default constructor for ChildrenHandeler
Definition ChildrenHandeler.h:47
auto pop(Key key) -> std::unique_ptr< C >
Removes a Child from the list, transferring ownership to the Caller.
Definition ChildrenHandeler.h:367
auto update(float dt) -> void override
called once every frame.
Definition ChildrenHandeler.h:135
Definition Component.h:28
a Key class to be used as a key when holding GameObjects (or unique pointers to game objects) in <key...
Definition GameObject.h:398
virtual auto update(float dt) -> void
called once every frame.
Definition GameObject.cpp:125
virtual auto setShouldReceiveMessages(const bool _shouldReceiveMessages) -> void
set whether the GameObject should Receive Messags, and whether all of it's children should receive me...
Definition GameObject.cpp:302
auto getFormattedName() const -> const std::string &
combines a GameObjects Type, Nickname, and UUID into one string, for use with logging.
Definition GameObject.cpp:240
friend Node
Definition GameObject.h:86
virtual auto setShouldUpdate(const bool _shouldUpdate) -> void
set whether the GameObject should update every frame, and whether all of it's children should update ...
Definition GameObject.cpp:290
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
virtual auto setShouldRender(const bool _shouldRender) -> void
set whether the GameObject should render every frame, and whether all of it's children should render ...
Definition GameObject.cpp:296
virtual auto parentTo(GameObject *newParent) -> bool
Sets the GameObject as a child of another GameObject.
Definition GameObject.cpp:184
virtual auto render() -> void
called every frame after update has been called for every object.
Definition GameObject.cpp:139
auto operator=(const GameObject &other) -> GameObject &
copy assignment operator
Definition GameObject.cpp:56
namespace for things relating to GameObject, other than GameObject itself
Definition Entity.h:229
@ Node
Definition GameObject.h:50
@ ChildrenHandler
Definition GameObject.h:51
auto Error(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:110
auto Debug(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:62
auto Trace(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:46