Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
AeonGames::Scene Class Reference

Scene class. Scene is the container for all elements in a game level, takes care of collision, rendering and updates to all elements therein. More...

#include <aeongames/Scene.hpp>

Collaboration diagram for AeonGames::Scene:
Collaboration graph

Public Member Functions

Scene & operator= (const Scene &)=delete
 Scene (const Scene &)=delete
DLL Scene ()
 Construct an empty scene.
DLL ~Scene ()
 Destructor.
DLL void Load (uint32_t aId)
 Load a scene from a resource identified by id.
DLL void Load (const std::string &aFilename)
 Load a scene from a file.
DLL void Load (const void *aBuffer, size_t aBufferSize)
 Load a scene from a memory buffer.
DLL void SetName (const char *aName)
 Set the scene name.
DLL const char *const GetName () const
 Get the scene name.
DLL Node * Add (std::unique_ptr< Node > aNode)
 Add a top-level node to the scene.
DLL Node * Insert (size_t aIndex, std::unique_ptr< Node > aNode)
 Insert a top-level node at a specific index.
DLL std::unique_ptr< Node > Remove (Node *aNode)
 Remove a top-level node by pointer.
DLL std::unique_ptr< Node > RemoveByIndex (size_t aIndex)
 Remove a top-level node by index.
DLL size_t GetChildrenCount () const
 Get the number of top-level child nodes.
DLL Node * GetChild (size_t aIndex) const
 Get a top-level child node by index.
DLL size_t GetChildIndex (const Node *aNode) const
 Get the index of a top-level child node.
DLL const Node & operator[] (const std::size_t index) const
 Access a top-level child node by index (const).
DLL Node & operator[] (const std::size_t index)
 Access a top-level child node by index.
DLL void Update (const double delta)
 Update all nodes in the scene.
DLL void BroadcastMessage (uint32_t aMessageType, const void *aMessageData)
 Broadcast a message to all nodes in the scene.
DLL void LoopTraverseDFSPreOrder (const std::function< void(Node &) > &aAction)
 Iterative depth-first pre-order traversal of all nodes in the scene.
DLL void LoopTraverseDFSPreOrder (const std::function< void(Node &) > &aPreamble, const std::function< void(Node &) > &aPostamble)
 Iterative depth-first pre-order traversal with separate preamble and postamble actions.
DLL void LoopTraverseDFSPreOrder (const std::function< void(const Node &) > &aAction) const
 Iterative depth-first pre-order traversal (const version).
DLL void LoopTraverseDFSPostOrder (const std::function< void(Node &) > &aAction)
 Iterative depth-first post-order traversal of all nodes in the scene.
DLL void LoopTraverseDFSPostOrder (const std::function< void(const Node &) > &aAction) const
 Iterative depth-first post-order traversal (const version).
DLL void RecursiveTraverseDFSPreOrder (const std::function< void(Node &) > &aAction)
 Recursive depth-first pre-order traversal of all nodes in the scene.
DLL void RecursiveTraverseDFSPostOrder (const std::function< void(Node &) > &aAction)
 Recursive depth-first post-order traversal of all nodes in the scene.
DLL Node * Find (const std::function< bool(const Node &) > &aUnaryPredicate) const
 Find the first node matching a predicate via depth-first search.
DLL std::string Serialize (bool aAsBinary=true) const
 Serialize the scene to a string.
DLL void Deserialize (const std::string &aSerializedScene)
 Deserialize a scene from a string.
DLL void SetFieldOfView (float aFieldOfView)
 Set the vertical field of view.
DLL void SetNear (float aNear)
 Set the near clipping plane distance.
DLL void SetFar (float aFar)
 Set the far clipping plane distance.
DLL float GetFieldOfView () const
 Get the vertical field of view.
DLL float GetNear () const
 Get the near clipping plane distance.
DLL float GetFar () const
 Get the far clipping plane distance.
Camera Data
DLL void SetCamera (Node *aNode)
 Set rendering camera.
DLL void SetCamera (uint32_t aNodeId)
 Set rendering camera by node id.
DLL void SetCamera (const std::string &aNodeName)
 Set rendering camera by node name.
DLL const Node * GetCamera () const
 Get the current camera node.
DLL void SetViewMatrix (const Matrix4x4 &aMatrix)
 Set the view matrix directly.
DLL const Matrix4x4GetViewMatrix () const
 Get the current view matrix.

Friends

class Node

Detailed Description

Scene class. Scene is the container for all elements in a game level, takes care of collision, rendering and updates to all elements therein.

Definition at line 39 of file Scene.hpp.

Constructor & Destructor Documentation

◆ Scene()

AeonGames::Scene::Scene ( )
explicit

Construct an empty scene.

Todo
implement Linear Octrees: https://geidav.wordpress.com/2014/08/18/advanced-octrees-2-node-representations/

Definition at line 46 of file Scene.cpp.

◆ ~Scene()

AeonGames::Scene::~Scene ( )

Destructor.

Definition at line 52 of file Scene.cpp.

Member Function Documentation

◆ Add()

Node * AeonGames::Scene::Add ( std::unique_ptr< Node > aNode)

Add a top-level node to the scene.

Parameters
aNodeUnique pointer to the node.
Returns
Raw pointer to the added node.

Definition at line 310 of file Scene.cpp.

◆ BroadcastMessage()

void AeonGames::Scene::BroadcastMessage ( uint32_t aMessageType,
const void * aMessageData )

Broadcast a message to all nodes in the scene.

Parameters
aMessageTypeType identifier for the message.
aMessageDataPointer to message-specific data.

Definition at line 192 of file Scene.cpp.

◆ Deserialize()

void AeonGames::Scene::Deserialize ( const std::string & aSerializedScene)

Deserialize a scene from a string.

Parameters
aSerializedSceneThe serialized scene data.

Definition at line 427 of file Scene.cpp.

◆ Find()

Node * AeonGames::Scene::Find ( const std::function< bool(const Node &) > & aUnaryPredicate) const

Find the first node matching a predicate via depth-first search.

Parameters
aUnaryPredicateCallable returning true for the desired node.
Returns
Pointer to the matching node, or nullptr if none found.

Definition at line 248 of file Scene.cpp.

◆ GetCamera()

const Node * AeonGames::Scene::GetCamera ( ) const

Get the current camera node.

Returns
Pointer to the camera node, or nullptr if unset.

Definition at line 107 of file Scene.cpp.

◆ GetChild()

Node * AeonGames::Scene::GetChild ( size_t aIndex) const

Get a top-level child node by index.

Parameters
aIndexIndex of the child.
Returns
Pointer to the child node.

Definition at line 155 of file Scene.cpp.

◆ GetChildIndex()

size_t AeonGames::Scene::GetChildIndex ( const Node * aNode) const

Get the index of a top-level child node.

Parameters
aNodePointer to the node to look up.
Returns
Index of the node within the top-level children.

Definition at line 160 of file Scene.cpp.

◆ GetChildrenCount()

size_t AeonGames::Scene::GetChildrenCount ( ) const

Get the number of top-level child nodes.

Returns
Child count.

Definition at line 150 of file Scene.cpp.

◆ GetFar()

float AeonGames::Scene::GetFar ( ) const

Get the far clipping plane distance.

Returns
Far plane distance.

Definition at line 135 of file Scene.cpp.

◆ GetFieldOfView()

float AeonGames::Scene::GetFieldOfView ( ) const

Get the vertical field of view.

Returns
Field of view in degrees.

Definition at line 127 of file Scene.cpp.

◆ GetName()

const char *const AeonGames::Scene::GetName ( ) const

Get the scene name.

Returns
Pointer to the null-terminated name string.

Definition at line 87 of file Scene.cpp.

◆ GetNear()

float AeonGames::Scene::GetNear ( ) const

Get the near clipping plane distance.

Returns
Near plane distance.

Definition at line 131 of file Scene.cpp.

◆ GetViewMatrix()

const Matrix4x4 & AeonGames::Scene::GetViewMatrix ( ) const

Get the current view matrix.

Returns
Const reference to the view matrix.

Definition at line 145 of file Scene.cpp.

◆ Insert()

Node * AeonGames::Scene::Insert ( size_t aIndex,
std::unique_ptr< Node > aNode )

Insert a top-level node at a specific index.

Parameters
aIndexPosition at which to insert.
aNodeUnique pointer to the node.
Returns
Raw pointer to the inserted node.

Definition at line 276 of file Scene.cpp.

◆ Load() [1/3]

void AeonGames::Scene::Load ( const std::string & aFilename)

Load a scene from a file.

Parameters
aFilenamePath to the scene file.

Definition at line 60 of file Scene.cpp.

◆ Load() [2/3]

void AeonGames::Scene::Load ( const void * aBuffer,
size_t aBufferSize )

Load a scene from a memory buffer.

Parameters
aBufferPointer to the data buffer.
aBufferSizeSize of the buffer in bytes.

Definition at line 77 of file Scene.cpp.

◆ Load() [3/3]

void AeonGames::Scene::Load ( uint32_t aId)

Load a scene from a resource identified by id.

Parameters
aIdResource identifier.

Definition at line 64 of file Scene.cpp.

◆ LoopTraverseDFSPostOrder() [1/2]

void AeonGames::Scene::LoopTraverseDFSPostOrder ( const std::function< void(const Node &) > & aAction) const

Iterative depth-first post-order traversal (const version).

Parameters
aActionCallable invoked for each node.

Definition at line 240 of file Scene.cpp.

◆ LoopTraverseDFSPostOrder() [2/2]

void AeonGames::Scene::LoopTraverseDFSPostOrder ( const std::function< void(Node &) > & aAction)

Iterative depth-first post-order traversal of all nodes in the scene.

Parameters
aActionCallable invoked for each node.

Definition at line 232 of file Scene.cpp.

◆ LoopTraverseDFSPreOrder() [1/3]

void AeonGames::Scene::LoopTraverseDFSPreOrder ( const std::function< void(const Node &) > & aAction) const

Iterative depth-first pre-order traversal (const version).

Parameters
aActionCallable invoked for each node.

Definition at line 224 of file Scene.cpp.

◆ LoopTraverseDFSPreOrder() [2/3]

void AeonGames::Scene::LoopTraverseDFSPreOrder ( const std::function< void(Node &) > & aAction)

Iterative depth-first pre-order traversal of all nodes in the scene.

Parameters
aActionCallable invoked for each node.

Definition at line 206 of file Scene.cpp.

◆ LoopTraverseDFSPreOrder() [3/3]

void AeonGames::Scene::LoopTraverseDFSPreOrder ( const std::function< void(Node &) > & aPreamble,
const std::function< void(Node &) > & aPostamble )

Iterative depth-first pre-order traversal with separate preamble and postamble actions.

Parameters
aPreambleCallable invoked upon entering each node.
aPostambleCallable invoked upon leaving each node.

Definition at line 214 of file Scene.cpp.

◆ operator[]() [1/2]

Node & AeonGames::Scene::operator[] ( const std::size_t index)

Access a top-level child node by index.

Parameters
indexIndex of the child.
Returns
Reference to the child node.

Definition at line 179 of file Scene.cpp.

◆ operator[]() [2/2]

const Node & AeonGames::Scene::operator[] ( const std::size_t index) const

Access a top-level child node by index (const).

Parameters
indexIndex of the child.
Returns
Const reference to the child node.

Definition at line 174 of file Scene.cpp.

◆ RecursiveTraverseDFSPostOrder()

void AeonGames::Scene::RecursiveTraverseDFSPostOrder ( const std::function< void(Node &) > & aAction)

Recursive depth-first post-order traversal of all nodes in the scene.

Parameters
aActionCallable invoked for each node.

Definition at line 268 of file Scene.cpp.

◆ RecursiveTraverseDFSPreOrder()

void AeonGames::Scene::RecursiveTraverseDFSPreOrder ( const std::function< void(Node &) > & aAction)

Recursive depth-first pre-order traversal of all nodes in the scene.

Parameters
aActionCallable invoked for each node.

Definition at line 260 of file Scene.cpp.

◆ Remove()

std::unique_ptr< Node > AeonGames::Scene::Remove ( Node * aNode)

Remove a top-level node by pointer.

Parameters
aNodePointer to the node to remove.
Returns
Unique pointer to the removed node, or nullptr if not found.

Definition at line 336 of file Scene.cpp.

◆ RemoveByIndex()

std::unique_ptr< Node > AeonGames::Scene::RemoveByIndex ( size_t aIndex)

Remove a top-level node by index.

Parameters
aIndexIndex of the node to remove.
Returns
Unique pointer to the removed node.

Definition at line 360 of file Scene.cpp.

◆ Serialize()

std::string AeonGames::Scene::Serialize ( bool aAsBinary = true) const

Serialize the scene to a string.

Parameters
aAsBinaryIf true, serialize as binary protobuf; otherwise as text.
Returns
The serialized scene data.

Definition at line 374 of file Scene.cpp.

◆ SetCamera() [1/3]

void AeonGames::Scene::SetCamera ( const std::string & aNodeName)

Set rendering camera by node name.

Parameters
aNodeNameName of the camera node.

Definition at line 102 of file Scene.cpp.

◆ SetCamera() [2/3]

void AeonGames::Scene::SetCamera ( Node * aNode)

Set rendering camera.

Parameters
aNodepointer to the node for which camera location and orientation will be extracted.
Todo
Need a way to uniquely identify nodes for messaging and camera assignment.

Definition at line 92 of file Scene.cpp.

◆ SetCamera() [3/3]

void AeonGames::Scene::SetCamera ( uint32_t aNodeId)

Set rendering camera by node id.

Parameters
aNodeIdIdentifier of the camera node.

Definition at line 97 of file Scene.cpp.

◆ SetFar()

void AeonGames::Scene::SetFar ( float aFar)

Set the far clipping plane distance.

Parameters
aFarFar plane distance.

Definition at line 122 of file Scene.cpp.

◆ SetFieldOfView()

void AeonGames::Scene::SetFieldOfView ( float aFieldOfView)

Set the vertical field of view.

Parameters
aFieldOfViewField of view in degrees.

Definition at line 112 of file Scene.cpp.

◆ SetName()

void AeonGames::Scene::SetName ( const char * aName)

Set the scene name.

Parameters
aNameNull-terminated name string.

Definition at line 82 of file Scene.cpp.

◆ SetNear()

void AeonGames::Scene::SetNear ( float aNear)

Set the near clipping plane distance.

Parameters
aNearNear plane distance.

Definition at line 117 of file Scene.cpp.

◆ SetViewMatrix()

void AeonGames::Scene::SetViewMatrix ( const Matrix4x4 & aMatrix)

Set the view matrix directly.

Parameters
aMatrixThe new view matrix.

Definition at line 140 of file Scene.cpp.

◆ Update()

void AeonGames::Scene::Update ( const double delta)

Update all nodes in the scene.

Parameters
deltaElapsed time in seconds since the last update.

Definition at line 184 of file Scene.cpp.

◆ Node

friend class Node
friend

Definition at line 184 of file Scene.hpp.


The documentation for this class was generated from the following files: