Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Utils.hpp
Go to the documentation of this file.
1/**************************************************************************
2 * Relationship v0.0.0
3 *
4 * Relationship is a software package, part of the Engine².
5 *
6 * This file is part of the EngineSquared project that is under GPL-3.0 License.
7 * Copyright © 2024 by @EngineSquared, All rights reserved.
8 *
9 * EngineSquared is a free software: you can redistribute it and/or modify
10 * it under the terms of the GPL-3.0 License as published by the
11 * Free Software Foundation. See the GPL-3.0 License for more details.
12 *
13 * @file Utils.hpp
14 * @brief utility functions for the Relationship component
15 *
16 * This file contains the declaration of the utility functions for the Relationship component.
17 *
18 * @author @miou-zora
19 * @version 0.0.0
20 * @date 18-02-2024
21 **************************************************************************/
22
23#pragma once
24
26
34auto SetChildOf(Engine::Entity child, Engine::Entity parent) -> void;
35
43auto IsChildOf(Engine::Entity child, Engine::Entity parent) -> bool;
44
50auto RemoveParent(Engine::Entity child) -> void;
51
58auto GetParent(Engine::Entity child) -> std::optional<Engine::Entity>;
59
60template <typename TFunc> auto ForEachChild(Engine::Entity parent, TFunc func) -> void
61{
64 if (!parentRS)
65 {
66 Log::Warning(fmt::format("Entity({}) has no Relationship component in ForEachChild", parent));
67 return;
68 }
69
70 auto currentChildOpt = parentRS->first;
71 while (currentChildOpt.has_value())
72 {
73 Engine::Entity currentChild = currentChildOpt.value();
74 func(currentChild);
75 const Relationship::Component::Relationship *currentChildRS =
77 if (!currentChildRS)
78 {
79 break;
80 }
81 currentChildOpt = currentChildRS->next;
82 }
83}
84} // namespace Relationship::Utils
Wrapper class providing a convenient interface for entity manipulation with the Core....
Definition Entity.hpp:20
decltype(auto) TryGetComponent()
Try to get a component of type TComponent from the entity. It returns a pointer to the component if i...
Definition Entity.hpp:137
void Warning(const T &msg) noexcept
Definition Logger.hpp:49
Definition Utils.hpp:27
auto IsChildOf(Engine::Entity child, Engine::Entity parent) -> bool
Definition Utils.cpp:30
auto ForEachChild(Engine::Entity parent, TFunc func) -> void
Definition Utils.hpp:60
auto GetParent(Engine::Entity child) -> std::optional< Engine::Entity >
Definition Utils.cpp:75
auto SetChildOf(Engine::Entity child, Engine::Entity parent) -> void
Definition Utils.cpp:5
auto RemoveParent(Engine::Entity child) -> void
Definition Utils.cpp:37
Definition Relationship.hpp:31
std::optional< Engine::Entity > next
Definition Relationship.hpp:39
std::optional< Engine::Entity > first
Definition Relationship.hpp:35