Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
manager.h
1#ifndef OE_SCENE_MANAGER_H
2#define OE_SCENE_MANAGER_H
3
4#include "../common.h"
5
6#include <vector>
7#include <map>
8
9#include "node.h"
10#include "camera.h"
11#include "component/scene.h"
12
13namespace oe::scene
14{
20 class Manager : public oe::component::HasComponents<Manager, SceneComponent>
21 {
22 public:
23
30
38 Manager(const Camera& camera);
39
44 template <typename T = Node, typename... Args>
45 T& addNode(Args&&... args)
46 {
47 std::shared_ptr<T> result = std::make_shared<T>(std::forward<Args>(args)...);
48 result->_manager = this;
49
50 _nodes.push_back(result);
51
52 T* ptr = result.get();
53
54 _root_nodes.push_back(ptr);
55
56 _notify_components_of_node_add(*result);
57
58 return *result;
59 }
60
66 template <typename T = Node, typename... Args>
67 T& addNamedNode(const std::string& name, Args&&... args)
68 {
69 T& result = addNode<T>(std::forward<Args>(args)...);
70 result.name = name;
71
72 return result;
73 }
74
81 void addChildNodeToParent(Node& child, Node* parent);
82
88 void deleteNode(Node& node);
89
93 const std::vector<std::shared_ptr<Node>>& getAllNodes() const;
94
98 const std::vector<Node*>& getRootNodes() const
99 {
100 return _root_nodes;
101 }
102
108 template <typename T = Node>
109 T* search(const std::string path, const std::string separator = "/") const
110 {
111 for (auto it : _root_nodes)
112 {
113 T* result = it->search<T>(path, separator);
114
115 if (result != nullptr)
116 return result;
117 }
118
119 return nullptr;
120 }
121
126
130 void setCamera(Camera& camera);
131
137 void setCamera(Node& node);
138
144 void setCamera(Node& node, const std::string& component_name);
145
151 template <typename ComponentType>
152 void setCameraFromComponent(ComponentType& component)
153 {
154 setCamera(component.getCamera());
155 }
156
161
166
173 void addNodeInGroup(Node& node, const NodeType type);
174
178 std::vector<Node*> getNodesByType(const NodeType type) const;
179
185 void removeNodeFromGroup(Node& node, const NodeType type);
186
193
208 void update(const double delta, const int8_t flags = 0);
209
210 private:
211 std::map<NodeType, std::vector<Node*>> _node_types;
212
213 std::vector<Node*> _root_nodes;
214
215 std::vector<std::shared_ptr<Node>> _nodes;
216
217 Camera _default_camera;
218
219 std::reference_wrapper<Camera> _camera;
220
221 void _notify_components_of_node_add(Node& node);
222 void _notify_components_of_node_remove(Node& node);
223 };
224}
225
226#endif
Util class to add components handling to an entity.
Definition component.h:311
The "eye of the scene".
Definition camera.h:33
Scene manager.
Definition manager.h:21
void removeNodeFromAllGroups(Node &node)
Remove node from all of its groups.
void setCamera(Node &node, const std::string &component_name)
Set scene camera using a node's named camera component.
void resetCameraToDefault()
Reset scene camera to the default camera.
void setCamera(Node &node)
Set scene camera using a node's camera component.
Manager()
Default Constructor.
std::vector< Node * > getNodesByType(const NodeType type) const
Get nodes belonging to a type (For exemple nodes that need to be in specific pass)
Camera & getCamera()
Get currently bound scene camera.
void addChildNodeToParent(Node &child, Node *parent)
Attach a child node to a parent one.
void removeNodeFromGroup(Node &node, const NodeType type)
Remove node from specified group.
T * search(const std::string path, const std::string separator="/") const
Search for a node using a name path.
Definition manager.h:109
const std::vector< std::shared_ptr< Node > > & getAllNodes() const
Get all nodes in the scene.
T & addNamedNode(const std::string &name, Args &&... args)
Generate a new root node in the the scene.
Definition manager.h:67
Manager(const Camera &camera)
Constructor where Camera settings are filled from a reference one.
T & addNode(Args &&... args)
Generate a new root node in the the scene.
Definition manager.h:45
void addNodeInGroup(Node &node, const NodeType type)
Add a node in a group (For example nodes that need to be in specific pass)
void deleteNode(Node &node)
Remove a node from the scene.
void setCamera(Camera &camera)
Set scene camera.
void update(const double delta, const int8_t flags=0)
Update the scene.
Camera & getDefaultCamera()
Get a reference to the default camera.
const std::vector< Node * > & getRootNodes() const
Get root nodes of the scene.
Definition manager.h:98
void setCameraFromComponent(ComponentType &component)
Set scene camera using a component providing a camera.
Definition manager.h:152
Definition node.h:31
Scene related management (Render-agnostic Geometry, Manger, etc...)
Definition debug.h:19