Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Scene.hpp
Go to the documentation of this file.
1/*
2Copyright (C) 2014-2019,2021,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_SCENE_H
17#define AEONGAMES_SCENE_H
25#include <memory>
26#include <vector>
27#include <string>
28#include <functional>
29
30namespace AeonGames
31{
32 class SceneMsg;
33 class Node;
34 class Renderer;
39 class Scene
40 {
41 public:
42 // Deleted Methods (avoid copy and copy construction)
43 Scene& operator= ( const Scene& ) = delete;
44 Scene ( const Scene& ) = delete;
46 DLL explicit Scene(); // "Explicit Scene"... chuckle
48 DLL ~Scene();
51 DLL void Load ( uint32_t aId );
54 DLL void Load ( const std::string& aFilename );
58 DLL void Load ( const void* aBuffer, size_t aBufferSize );
61 DLL void SetName ( const char* aName );
64 DLL const char* const GetName() const;
68 DLL Node* Add ( std::unique_ptr<Node> aNode );
73 DLL Node* Insert ( size_t aIndex, std::unique_ptr<Node> aNode );
77 DLL std::unique_ptr<Node> Remove ( Node* aNode );
81 DLL std::unique_ptr<Node> RemoveByIndex ( size_t aIndex );
84 DLL size_t GetChildrenCount() const;
88 DLL Node* GetChild ( size_t aIndex ) const;
92 DLL size_t GetChildIndex ( const Node* aNode ) const;
96 DLL const Node& operator[] ( const std::size_t index ) const;
100 DLL Node& operator[] ( const std::size_t index );
103 DLL void Update ( const double delta );
107 DLL void BroadcastMessage ( uint32_t aMessageType, const void* aMessageData );
110 DLL void LoopTraverseDFSPreOrder ( const std::function<void ( Node& ) >& aAction );
114 DLL void LoopTraverseDFSPreOrder (
115 const std::function<void ( Node& ) >& aPreamble,
116 const std::function<void ( Node& ) >& aPostamble );
119 DLL void LoopTraverseDFSPreOrder ( const std::function<void ( const Node& ) >& aAction ) const;
122 DLL void LoopTraverseDFSPostOrder ( const std::function<void ( Node& ) >& aAction );
125 DLL void LoopTraverseDFSPostOrder ( const std::function<void ( const Node& ) >& aAction ) const;
128 DLL void RecursiveTraverseDFSPreOrder ( const std::function<void ( Node& ) >& aAction );
131 DLL void RecursiveTraverseDFSPostOrder ( const std::function<void ( Node& ) >& aAction );
135 DLL Node* Find ( const std::function<bool ( const Node& ) >& aUnaryPredicate ) const;
139 DLL std::string Serialize ( bool aAsBinary = true ) const;
142 DLL void Deserialize ( const std::string& aSerializedScene );
148 DLL void SetCamera ( Node* aNode );
151 DLL void SetCamera ( uint32_t aNodeId );
154 DLL void SetCamera ( const std::string& aNodeName );
157 DLL const Node* GetCamera() const;
160 DLL void SetViewMatrix ( const Matrix4x4& aMatrix );
163 DLL const Matrix4x4& GetViewMatrix() const;
167 DLL void SetFieldOfView ( float aFieldOfView );
170 DLL void SetNear ( float aNear );
173 DLL void SetFar ( float aFar );
176 DLL float GetFieldOfView() const;
179 DLL float GetNear() const;
182 DLL float GetFar() const;
183 private:
184 friend class Node;
185 Matrix4x4 mViewMatrix{};
186 float mFieldOfView{60.0f};
187 float mNear{1.0f};
188 float mFar{1600.0f};
189 std::string mName{};
191 std::vector<std::unique_ptr<Node >> mNodes{};
192#if 0
201 std::vector<std::unique_ptr<Node >> mNodeStorage{};
202#endif
203 Node* mCamera {};
204 };
205}
206#endif
Header for 4x4 matrix class.
#define LoopTraverseDFSPreOrder(...)
Macro generating LoopTraverseDFSPreOrder implementations for const and non-const variants.
Definition Node.cpp:425
Platform-specific macros, includes, and DLL export/import definitions.
4 by 4 matrix in colum mayor order.
Definition Matrix4x4.hpp:35
Scene graph node representing an entity in the game world.
Definition Node.hpp:54
Abstract base class for rendering backends.
Definition Renderer.hpp:44
DLL void BroadcastMessage(uint32_t aMessageType, const void *aMessageData)
Broadcast a message to all nodes in the scene.
Definition Scene.cpp:192
DLL void Deserialize(const std::string &aSerializedScene)
Deserialize a scene from a string.
Definition Scene.cpp:427
DLL const Node * GetCamera() const
Get the current camera node.
Definition Scene.cpp:107
DLL void RecursiveTraverseDFSPostOrder(const std::function< void(Node &) > &aAction)
Recursive depth-first post-order traversal of all nodes in the scene.
Definition Scene.cpp:268
DLL float GetNear() const
Get the near clipping plane distance.
Definition Scene.cpp:131
DLL void SetNear(float aNear)
Set the near clipping plane distance.
Definition Scene.cpp:117
DLL std::unique_ptr< Node > RemoveByIndex(size_t aIndex)
Remove a top-level node by index.
Definition Scene.cpp:360
DLL void RecursiveTraverseDFSPreOrder(const std::function< void(Node &) > &aAction)
Recursive depth-first pre-order traversal of all nodes in the scene.
Definition Scene.cpp:260
DLL void LoopTraverseDFSPostOrder(const std::function< void(Node &) > &aAction)
Iterative depth-first post-order traversal of all nodes in the scene.
Definition Scene.cpp:232
DLL ~Scene()
Destructor.
Definition Scene.cpp:52
DLL void SetFieldOfView(float aFieldOfView)
Set the vertical field of view.
Definition Scene.cpp:112
DLL float GetFar() const
Get the far clipping plane distance.
Definition Scene.cpp:135
DLL void SetCamera(Node *aNode)
Set rendering camera.
Definition Scene.cpp:92
DLL void SetName(const char *aName)
Set the scene name.
Definition Scene.cpp:82
DLL Node * Insert(size_t aIndex, std::unique_ptr< Node > aNode)
Insert a top-level node at a specific index.
Definition Scene.cpp:276
DLL void SetFar(float aFar)
Set the far clipping plane distance.
Definition Scene.cpp:122
DLL const char *const GetName() const
Get the scene name.
Definition Scene.cpp:87
DLL void Load(uint32_t aId)
Load a scene from a resource identified by id.
Definition Scene.cpp:64
DLL float GetFieldOfView() const
Get the vertical field of view.
Definition Scene.cpp:127
DLL Scene()
Construct an empty scene.
Definition Scene.cpp:46
DLL size_t GetChildIndex(const Node *aNode) const
Get the index of a top-level child node.
Definition Scene.cpp:160
DLL std::string Serialize(bool aAsBinary=true) const
Serialize the scene to a string.
Definition Scene.cpp:374
DLL const Node & operator[](const std::size_t index) const
Access a top-level child node by index (const).
Definition Scene.cpp:174
DLL size_t GetChildrenCount() const
Get the number of top-level child nodes.
Definition Scene.cpp:150
DLL Node * Add(std::unique_ptr< Node > aNode)
Add a top-level node to the scene.
Definition Scene.cpp:310
DLL const Matrix4x4 & GetViewMatrix() const
Get the current view matrix.
Definition Scene.cpp:145
DLL void Update(const double delta)
Update all nodes in the scene.
Definition Scene.cpp:184
DLL void SetViewMatrix(const Matrix4x4 &aMatrix)
Set the view matrix directly.
Definition Scene.cpp:140
DLL Node * Find(const std::function< bool(const Node &) > &aUnaryPredicate) const
Find the first node matching a predicate via depth-first search.
Definition Scene.cpp:248
DLL Node * GetChild(size_t aIndex) const
Get a top-level child node by index.
Definition Scene.cpp:155
DLL std::unique_ptr< Node > Remove(Node *aNode)
Remove a top-level node by pointer.
Definition Scene.cpp:336
<- This is here just for the literals
Definition AABB.hpp:31