Brenta Engine 1.2
Loading...
Searching...
No Matches
node.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <brenta/script.hpp>
9#include <brenta/transform.hpp>
10
11#include <tenno/memory.hpp>
12#include <tenno/vector.hpp>
13
14#include <glm/gtc/matrix_transform.hpp>
15
16namespace brenta
17{
18
19class NodeComponent;
20
21//
22// Node
23// ----
24//
25// Nodes are the highest abstraction to repserent the scene. Each
26// node has one parent and can have many children, creating a tree
27// or a graph.
28//
29// When a node updates itself, it also updates its childrens; this
30// propagates recursively down the tree. The same happens for drawing.
31//
32// The actual usefulness of a node cames with its components, which
33// provide specialized functionalities to the node. Each node also
34// has a lua script that it runs when it updates, to provide a more
35// dynamic and simple way to write the Node's logic.
36//
37class Node
38{
39public:
40
41 friend class Scene;
42
43 Transform transform;
44
45 Node() = default;
46
47 // Update logic (animations, movement, AI...)
48 void update(float delta_time);
49
50 // Render frame
51 void draw();
52
53private:
54
55 tenno::vector<tenno::shared_ptr<NodeComponent>> components;
56 std::optional<Script> script;
57
58 std::optional<tenno::weak_ptr<Node>> parent;
59 tenno::vector<tenno::shared_ptr<Node>> children;
60
61 glm::mat4 world_matrix = glm::mat4(1.0f);
62
63 void update_world_matrix();
64
65};
66
68{
69public:
70
71 friend class Scene;
72
73 tenno::weak_ptr<Node> owner;
74
75 virtual ~NodeComponent() = default;
76
77 virtual void update(float delta_time) = 0;
78 virtual void draw(const glm::mat4& world_matrix) = 0;
79
80};
81
82} // namespace brenta