#include <World.h>
Owns world's root node.
- Warning
- destroyWorld must be explicitly called before destroying this object.
◆ ~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
-
pGameManager | GameManager object that owns this world. |
pRootNode | World's root node. |
iWorldSize | World size in game units. Must be power of 2 (128, 256, 512, 1024, 2048, etc.). |
◆ addNodeToCalledEveryFrameArrays()
void ne::World::addNodeToCalledEveryFrameArrays |
( |
Node * |
pNode | ) |
|
|
private |
Adds the specified node to the arrays of "called every frame" nodes (see calledEveryFrameNodes).
- Parameters
-
◆ addNodeToReceivingInputArray()
void ne::World::addNodeToReceivingInputArray |
( |
Node * |
pNode | ) |
|
|
private |
◆ createWorld()
Creates a new world that contains only one node - root node.
- Parameters
-
pGameManager | GameManager object that owns this world. |
iWorldSize | Size 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()
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
-
iNodeId | ID of the node to check. |
- Returns
true
if the node is spawned, false
otherwise.
◆ loadNodeTreeAsWorld()
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
-
pGameManager | GameManager object that owns this world. |
pathToNodeTree | Path to the file that contains a node tree to load, the ".toml" extension will be automatically added if not specified. |
iWorldSize | Size 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
-
pNode | Node 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
-
pNode | Node 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
-
pNode | Node 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
-
pNode | Node that is changing its setting. |
◆ removeNodeFromCalledEveryFrameArrays()
void 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
-
◆ removeNodeFromReceivingInputArray()
void 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
-
◆ calledEveryFrameNodes
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 |
◆ mtxSpawnedNodes
std::pair<std::recursive_mutex, std::unordered_map<size_t, Node*> > ne::World::mtxSpawnedNodes |
|
private |
Stores pairs of "Node ID" - "Spawned Node".
◆ pGameManager
◆ 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:
- src/engine_lib/private/game/World.h
- src/engine_lib/private/game/World.cpp