Nameless Engine
Loading...
Searching...
No Matches
ne::World Class Reference

#include <World.h>

Public Member Functions

 World (const World &)=delete
 
Worldoperator= (const World &)=delete
 
 World (World &&)=delete
 
Worldoperator= (World &&)=delete
 
 ~World ()
 
size_t getTotalSpawnedNodeCount ()
 
void destroyWorld ()
 
CalledEveryFrameNodesgetCalledEveryFrameNodes ()
 
std::pair< std::recursive_mutex, std::unordered_set< Node * > > * getReceivingInputNodes ()
 
sgc::GcPtr< NodegetRootNode ()
 
size_t getCalledEveryFrameNodeCount ()
 
float getWorldTimeInSeconds () const
 
size_t getWorldSize () const
 
bool isNodeSpawned (size_t iNodeId)
 

Static Public Member Functions

static std::unique_ptr< WorldcreateWorld (GameManager *pGameManager, size_t iWorldSize=Globals::getDefaultWorldSize())
 
static std::variant< std::unique_ptr< World >, ErrorloadNodeTreeAsWorld (GameManager *pGameManager, const std::filesystem::path &pathToNodeTree, size_t iWorldSize=Globals::getDefaultWorldSize())
 

Private Member Functions

 World (GameManager *pGameManager, sgc::GcPtr< Node > pRootNode, size_t iWorldSize)
 
void onNodeSpawned (Node *pNode)
 
void onNodeDespawned (Node *pNode)
 
void onSpawnedNodeChangedIsCalledEveryFrame (Node *pNode)
 
void onSpawnedNodeChangedIsReceivingInput (Node *pNode)
 
void addNodeToCalledEveryFrameArrays (Node *pNode)
 
bool removeNodeFromCalledEveryFrameArrays (Node *pNode)
 
bool removeNodeFromReceivingInputArray (Node *pNode)
 

Private Attributes

GameManagerpGameManager = nullptr
 
std::pair< std::recursive_mutex, bool > mtxIsDestroyed
 
std::pair< std::mutex, sgc::GcPtr< Node > > mtxRootNode
 
CalledEveryFrameNodes calledEveryFrameNodes
 
std::pair< std::recursive_mutex, std::unordered_set< Node * > > mtxReceivingInputNodes
 
std::pair< std::recursive_mutex, std::unordered_map< size_t, Node * > > mtxSpawnedNodes
 
std::atomic< size_t > iTotalSpawnedNodeCount {0}
 
const size_t iWorldSize = 0
 
std::chrono::steady_clock::time_point timeWhenWorldCreated
 

Friends

class Node
 

Detailed Description

Owns world's root node.

Warning
destroyWorld must be explicitly called before destroying this object.

Constructor & Destructor Documentation

◆ ~World()

ne::World::~World ( )

Checks that world is destructed correctly (see destroyWorld) and logs in case of error.

◆ World()

ne::World::World ( GameManager pGameManager,
sgc::GcPtr< Node pRootNode,
size_t  iWorldSize 
)
private

Creates a new world with the specified root node.

Parameters
pGameManagerGameManager object that owns this world.
pRootNodeWorld's root node.
iWorldSizeWorld size in game units. Must be power of 2 (128, 256, 512, 1024, 2048, etc.).

Member Function Documentation

◆ addNodeToCalledEveryFrameArrays()

void ne::World::addNodeToCalledEveryFrameArrays ( Node pNode)
private

Adds the specified node to the arrays of "called every frame" nodes (see calledEveryFrameNodes).

Parameters
pNodeNode to add.

◆ createWorld()

std::unique_ptr< World > ne::World::createWorld ( GameManager pGameManager,
size_t  iWorldSize = Globals::getDefaultWorldSize() 
)
static

Creates a new world that contains only one node - root node.

Parameters
pGameManagerGameManager object that owns this world.
iWorldSizeSize of the world in game units. Must be power of 2 (128, 256, 512, 1024, 2048, etc.). World size needs to be specified for internal purposes such as Directional Light shadow map size. You don't need to care why we need this information, you only need to know that if you leave world bounds lighting or physics may be incorrect (the editor or engine will warn you if something is leaving world bounds, pay attention to the logs).
Returns
Pointer to the new world instance.

◆ destroyWorld()

void ne::World::destroyWorld ( )

Clears pointer to the root node which should cause the world to recursively be despawned and destroyed.

Warning
Node despawn process will queue a bunch of deferred tasks that will notify world about nodes being despawned. Make sure to execute all deferred tasks after calling this function and before destroying this object.

◆ getCalledEveryFrameNodeCount()

size_t ne::World::getCalledEveryFrameNodeCount ( )

Returns the current amount of spawned nodes that are marked as "should be called every frame".

Returns
Amount of spawned nodes that should be called every frame.

◆ getCalledEveryFrameNodes()

CalledEveryFrameNodes * ne::World::getCalledEveryFrameNodes ( )

Returns a pointer to array of nodes that should be called every frame (use with mutex).

Returns
Pointer to array of nodes (use with mutex).

◆ getReceivingInputNodes()

std::pair< std::recursive_mutex, std::unordered_set< Node * > > * ne::World::getReceivingInputNodes ( )

Returns a pointer to array of nodes that receive input (use with mutex).

Returns
Pointer to array of nodes (use with mutex).

◆ getRootNode()

sgc::GcPtr< Node > ne::World::getRootNode ( )

Returns a pointer to world's root node.

Returns
nullptr if world is being destroyed, otherwise pointer to world's root node.

◆ getTotalSpawnedNodeCount()

size_t ne::World::getTotalSpawnedNodeCount ( )

Returns total amount of currently spawned nodes.

Returns
Total nodes spawned right now.

◆ getWorldSize()

size_t ne::World::getWorldSize ( ) const

Returns world size in game units.

Returns
World size.

◆ getWorldTimeInSeconds()

float ne::World::getWorldTimeInSeconds ( ) const

Returns time since world creation (in seconds).

Returns
Time since world creation (in seconds).

◆ isNodeSpawned()

bool ne::World::isNodeSpawned ( size_t  iNodeId)

Tells if a node with the specified ID is currently spawned or not.

Parameters
iNodeIdID of the node to check.
Returns
true if the node is spawned, false otherwise.

◆ loadNodeTreeAsWorld()

std::variant< std::unique_ptr< World >, Error > ne::World::loadNodeTreeAsWorld ( GameManager pGameManager,
const std::filesystem::path &  pathToNodeTree,
size_t  iWorldSize = Globals::getDefaultWorldSize() 
)
static

Loads and deserializes a node tree to be used as a new world.

Node tree's root node will be used as world's root node.

Parameters
pGameManagerGameManager object that owns this world.
pathToNodeTreePath to the file that contains a node tree to load, the ".toml" extension will be automatically added if not specified.
iWorldSizeSize of the world in game units. Must be power of 2 (128, 256, 512, 1024, 2048, etc.). World size needs to be specified for internal purposes such as Directional Light shadow map size. You don't need to care why we need this information, you only need to know that if you leave world bounds lighting or physics may be incorrect (the editor or engine will warn you if something is leaving world bounds, pay attention to the logs).
Returns
Error if failed to deserialize the node tree, otherwise pointer to the new world instance.

◆ onNodeDespawned()

void ne::World::onNodeDespawned ( Node pNode)
private

Called from Node to notify the World about a node being despawned.

Parameters
pNodeNode that is being despawned.

◆ onNodeSpawned()

void ne::World::onNodeSpawned ( Node pNode)
private

Called from Node to notify the World about a new node being spawned.

Parameters
pNodeNode that is being spawned.

◆ onSpawnedNodeChangedIsCalledEveryFrame()

void ne::World::onSpawnedNodeChangedIsCalledEveryFrame ( Node pNode)
private

Called from Node to notify the World about a spawned node changed its "is called every frame" setting.

Warning
Should be called AFTER the node has changed its setting and the new state should not be changed while this function is running.
Parameters
pNodeNode that is changing its setting.

◆ onSpawnedNodeChangedIsReceivingInput()

void ne::World::onSpawnedNodeChangedIsReceivingInput ( Node pNode)
private

Called from Node to notify the World about a spawned node changed its "is receiving input" setting.

Warning
Should be called AFTER the node has changed its setting and the new state should not be changed while this function is running.
Parameters
pNodeNode that is changing its setting.

◆ removeNodeFromCalledEveryFrameArrays()

bool ne::World::removeNodeFromCalledEveryFrameArrays ( Node pNode)
private

Looks if the specified node exists in the arrays of "called every frame" nodes and removes the node from the arrays (see calledEveryFrameNodes).

Parameters
pNodeNode to remove.
Returns
true if the specified node was found and removed, false otherwise.

◆ removeNodeFromReceivingInputArray()

bool ne::World::removeNodeFromReceivingInputArray ( Node pNode)
private

Looks if the specified node exists in the array of "receiving input" nodes and removes the node from the array (see mtxReceivingInputNodes).

Parameters
pNodeNode to remove.
Returns
true if the specified node was found and removed, false otherwise.

Member Data Documentation

◆ calledEveryFrameNodes

CalledEveryFrameNodes ne::World::calledEveryFrameNodes
private

Array of currently spawned nodes that are marked as "should be called every frame".

◆ iTotalSpawnedNodeCount

std::atomic<size_t> ne::World::iTotalSpawnedNodeCount {0}
private

Total amount of nodes spawned.

◆ iWorldSize

const size_t ne::World::iWorldSize = 0
private

World size in game units.

◆ mtxIsDestroyed

std::pair<std::recursive_mutex, bool> ne::World::mtxIsDestroyed
private

Whether the world is destroyed (or being destroyed) and should not be used or not.

◆ mtxReceivingInputNodes

std::pair<std::recursive_mutex, std::unordered_set<Node*> > ne::World::mtxReceivingInputNodes
private

Array of currently spawned nodes that receive input.

◆ mtxRootNode

std::pair<std::mutex, sgc::GcPtr<Node> > ne::World::mtxRootNode
private

World's root node.

◆ mtxSpawnedNodes

std::pair<std::recursive_mutex, std::unordered_map<size_t, Node*> > ne::World::mtxSpawnedNodes
private

Stores pairs of "Node ID" - "Spawned Node".

◆ pGameManager

GameManager* ne::World::pGameManager = nullptr
private

Do not delete. Owner GameManager object.

◆ timeWhenWorldCreated

std::chrono::steady_clock::time_point ne::World::timeWhenWorldCreated
private

Time when world was created.


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