1#ifndef OE_SCENE_MANAGER_H
2#define OE_SCENE_MANAGER_H
44 .id_node = _next_node_id++
47 _nodes.push_back(node);
75 for (
auto& it : _nodes)
77 if (it.scene_data.id_node == id_node)
97 for (
auto& it : _nodes)
99 if (it.scene_data.id_node == id_node)
116 if (node.
scene !=
this) [[unlikely]]
118 throw std::invalid_argument(
"Node not part of the current scene!");
122 for (
const auto child : node->children)
129 _nodes.erase(std::remove_if(
132 [&node](Node& n) { return n.scene_data == node; }
141 std::vector<NodePtr> result;
143 result.reserve(_nodes.size());
145 for (
auto& it: _nodes)
147 result.push_back(it.scene_data);
158 std::vector<NodePtr> result;
160 for (
const Node& node : _nodes)
164 result.push_back(node.scene_data);
176 NodePtr search(
const std::string path,
const std::string separator =
"/")
const
185 for (
auto it : root_nodes)
203 template <
typename ComponentType>
214 camera = &default_camera;
225 if (node.
scene !=
this) [[unlikely]]
227 throw std::invalid_argument(
"Node not part of the current scene!");
230 if (_node_types.count(type) == 0)
232 _node_types[type] = {};
235 _node_types[type].push_back(node);
243 if (_node_types.count(type) == 0)
248 return _node_types.at(type);
258 if (node.
scene !=
this) [[unlikely]]
260 throw std::invalid_argument(
"Node not part of the current scene!");
263 if (_node_types.count(type) == 0)
268 auto& nodes_by_this_type = _node_types[type];
270 auto it = std::find(nodes_by_this_type.begin(), nodes_by_this_type.end(), node);
272 if (it == nodes_by_this_type.end())
277 nodes_by_this_type.erase(it);
287 for (
auto& it : _node_types)
306 std::map<NodeType, std::vector<NodePtr>> _node_types;
307 std::vector<Node> _nodes;
309 std::atomic<uint64_t> _next_node_id = 1;
The "eye of the scene".
Definition camera.h:31
Scene node.
Definition node.h:30
NodePtr searchFromThisNode(const std::string &path, const std::string &separator) noexcept
search starting from this node
std::string name
Name, used as identifier for search.
Definition node.h:256
NodePtr scene_data
Scene pointer to this node.
Definition node.h:239
const std::vector< NodePtr > getRootNodes() const
Get root nodes of the scene.
Definition scene.h:156
void resetCameraToDefault()
Reset scene camera to the default camera.
Definition scene.h:212
NodePtr search(const std::string path, const std::string separator="/") const
Search for a node using a name path.
Definition scene.h:176
void setCameraFromComponent(ComponentType &component)
Set scene camera using a component providing a camera.
Definition scene.h:204
void removeNodeFromAllGroups(NodePtr node)
Remove node from all of its groups.
Definition scene.h:285
NodePtr addNode()
Generate a new root node in the the scene.
Definition scene.h:40
void addNodeInGroup(NodePtr node, const NodeType type)
Add a node in a group (For example nodes that need to be in specific pass).
Definition scene.h:223
const Node * getNodeById(uint64_t id_node) const
Get pointer to a node from its id.
Definition scene.h:93
NodePtr addNamedNode(const std::string &name)
Generate a new root node in the the scene and set a name.
Definition scene.h:56
const std::vector< NodePtr > getAllNodes() const
Get all nodes in the scene.
Definition scene.h:139
Scene(const Camera &camera)
Constructor where Camera settings are filled from a reference one.
Node * getNodeById(uint64_t id_node)
Get pointer to a node from its id.
Definition scene.h:71
Scene()
Default Constructor.
void * user_data
Custom user data, you can use it to store flags / pointer / physics / etc... related to this scene.
Definition scene.h:303
void removeNodeFromGroup(NodePtr node, const NodeType type)
Remove node from specified group.
Definition scene.h:256
std::vector< NodePtr > getNodesByType(const NodeType type) const
Get nodes belonging to a type (For exemple nodes that need to be in specific pass).
Definition scene.h:241
Scene / node components (camera, lighting, ...).
Definition debug.h:17
Scene related management (Render-agnostic Geometry, Manger, etc...).
Definition debug.h:19
Wrapper to a node reference to use pointers to node even if the actual node moves in memory.
Definition node_ptr.h:19
SceneType * scene
Scene containing the Node.
Definition node_ptr.h:59