Kohi Game Engine
hierarchy_graph.h File Reference

Go to the source code of this file.

Data Structures

struct  hierarchy_graph_view_node
 
struct  hierarchy_graph_view
 
struct  hierarchy_graph
 

Typedefs

typedef struct hierarchy_graph_view_node hierarchy_graph_view_node
 
typedef struct hierarchy_graph_view hierarchy_graph_view
 
typedef struct hierarchy_graph hierarchy_graph
 

Functions

KAPI b8 hierarchy_graph_create (hierarchy_graph *out_graph)
 Creates a new hierarchy graph, used to manage parent-child relationships with any kind of resource via the use of handles and handles to xforms. More...
 
KAPI void hierarchy_graph_destroy (hierarchy_graph *graph)
 Destroys the given hierarchy graph, releasing all resources. FIXME: This should also optionally release xforms if requested to do so. It currently does not. More...
 
KAPI void hierarchy_graph_update (hierarchy_graph *graph)
 Performs internal update routines on the hierarchy, which includes rebuilding the internal view tree. More...
 
KAPI khandle hierarchy_graph_xform_handle_get (const hierarchy_graph *graph, khandle node_handle)
 Obtains the xform handle of the node provided. Will return an invalid handle if the node (or an xform for it) does not exist. More...
 
KAPI b8 hierarchy_graph_xform_local_matrix_get (const hierarchy_graph *graph, khandle node_handle, mat4 *out_matrix)
 Attempts to get the local transformation matrix for the given hierarchy node, if it exists and has a transform. More...
 
KAPI khandle hierarchy_graph_parent_handle_get (const hierarchy_graph *graph, khandle node_handle)
 Obtains the handle of the parent of the node provided. Will return an invalid handle if the node does not exist or if it has no parent. More...
 
KAPI khandle hierarchy_graph_parent_xform_handle_get (const hierarchy_graph *graph, khandle node_handle)
 Obtains the xform handle of the parent of node provided. Will return an invalid handle if the node, its parent, or an xform for it does not exist. More...
 
KAPI khandle hierarchy_graph_root_add (hierarchy_graph *graph)
 Adds a new node to the root of the graph. Returns the handle to the new node. More...
 
KAPI khandle hierarchy_graph_root_add_with_xform (hierarchy_graph *graph, khandle xform_handle)
 Adds a new node to the root of the graph and assigns the given xform handle to it. Returns the handle to the new node. More...
 
KAPI khandle hierarchy_graph_child_add (hierarchy_graph *graph, khandle parent_node_handle)
 Adds a new node to the given parent node within the graph. Returns the handle to the new node. More...
 
KAPI khandle hierarchy_graph_child_add_with_xform (hierarchy_graph *graph, khandle parent_node_handle, khandle xform_handle)
 Adds a new node to the given parent node within the graph and assigns the given xform handle to it. Returns the handle to the new node. More...
 
KAPI u32 hierarchy_graph_child_count_get (const hierarchy_graph *graph, khandle parent_node_handle)
 Attempts to get the number of child nodes of the given parent node. More...
 
KAPI b8 hierarchy_graph_child_get_by_index (const hierarchy_graph *graph, khandle parent_node_handle, u32 index, khandle *out_handle)
 Attempts to get a handle to a child node of the given parent node, at the provided index. More...
 
KAPI void hierarchy_graph_node_remove (hierarchy_graph *graph, khandle *node_handle, b8 release_xform)
 Removes the given node from the hierarchy. This automatically handles reorganization of the hierarchy upon removal (i.e. children, if they exist, are moved to this node's parent or the root). Also invalidates the given handle. Optionally releases the xform. More...
 
KAPI quat hierarchy_graph_world_rotation_get (const hierarchy_graph *graph, khandle node_handle)
 Obtains the world rotation for the given node. Returns identity quaternion if xform (or node itself) does not exist. More...
 
KAPI vec3 hierarchy_graph_world_position_get (const hierarchy_graph *graph, khandle node_handle)
 Obtains the world position for the given node. Returns a zero vector if xform (or node itself) does not exist. More...
 
KAPI vec3 hierarchy_graph_world_scale_get (const hierarchy_graph *graph, khandle node_handle)
 Obtains the world scale for the given node. Returns {1, 1, 1} if xform (or node itself) does not exist. More...
 

Typedef Documentation

◆ hierarchy_graph

◆ hierarchy_graph_view

◆ hierarchy_graph_view_node

Function Documentation

◆ hierarchy_graph_child_add()

KAPI khandle hierarchy_graph_child_add ( hierarchy_graph graph,
khandle  parent_node_handle 
)

Adds a new node to the given parent node within the graph. Returns the handle to the new node.

Parameters
graphA pointer to the graph to add the node to.
parent_node_handleThe handle to the node to add the new child node to.
Returns
A copy of the handle to the new node.

◆ hierarchy_graph_child_add_with_xform()

KAPI khandle hierarchy_graph_child_add_with_xform ( hierarchy_graph graph,
khandle  parent_node_handle,
khandle  xform_handle 
)

Adds a new node to the given parent node within the graph and assigns the given xform handle to it. Returns the handle to the new node.

Parameters
graphA pointer to the graph to add the node to.
parent_node_handleThe handle to the node to add the new child node to.
xform_handleThe handle to the xform to use when adding the node.
Returns
A copy of the handle to the new node.

◆ hierarchy_graph_child_count_get()

KAPI u32 hierarchy_graph_child_count_get ( const hierarchy_graph graph,
khandle  parent_node_handle 
)

Attempts to get the number of child nodes of the given parent node.

Parameters
graphA pointer to the graph to search.
parent_node_handleThe handle to the parent node.
Returns
The number of children under the parent. Can also return 0 if the parent was not found.

◆ hierarchy_graph_child_get_by_index()

KAPI b8 hierarchy_graph_child_get_by_index ( const hierarchy_graph graph,
khandle  parent_node_handle,
u32  index,
khandle out_handle 
)

Attempts to get a handle to a child node of the given parent node, at the provided index.

Parameters
graphA pointer to the graph to search.
parent_node_handleThe handle to the node to search.
out_handleA pointer to hold the found handle if successful.
Returns
True if a handle was found at the index; otherwise false.

◆ hierarchy_graph_create()

KAPI b8 hierarchy_graph_create ( hierarchy_graph out_graph)

Creates a new hierarchy graph, used to manage parent-child relationships with any kind of resource via the use of handles and handles to xforms.

Parameters
out_graphA pointer to hold the newly-created graph.
Returns
True if successful; otherwise false.

◆ hierarchy_graph_destroy()

KAPI void hierarchy_graph_destroy ( hierarchy_graph graph)

Destroys the given hierarchy graph, releasing all resources. FIXME: This should also optionally release xforms if requested to do so. It currently does not.

Parameters
graphA pointer to the graph to be destroyed.

◆ hierarchy_graph_node_remove()

KAPI void hierarchy_graph_node_remove ( hierarchy_graph graph,
khandle node_handle,
b8  release_xform 
)

Removes the given node from the hierarchy. This automatically handles reorganization of the hierarchy upon removal (i.e. children, if they exist, are moved to this node's parent or the root). Also invalidates the given handle. Optionally releases the xform.

Parameters
graphA pointer to the graph to remove the node from.
node_handleA pointer to the handle of the node to be removed. Handle is invalidated upon completion.
release_xformIndicates if the associated xform (assuming there is one) should also be released.

◆ hierarchy_graph_parent_handle_get()

KAPI khandle hierarchy_graph_parent_handle_get ( const hierarchy_graph graph,
khandle  node_handle 
)

Obtains the handle of the parent of the node provided. Will return an invalid handle if the node does not exist or if it has no parent.

Parameters
graphA constant pointer to the graph to examine.
node_handleThe handle to the node to examine.
Returns
Either a handle to a node, or an invalid handle if the node (or it's parent) doesn't exist.

◆ hierarchy_graph_parent_xform_handle_get()

KAPI khandle hierarchy_graph_parent_xform_handle_get ( const hierarchy_graph graph,
khandle  node_handle 
)

Obtains the xform handle of the parent of node provided. Will return an invalid handle if the node, its parent, or an xform for it does not exist.

Parameters
graphA constant pointer to the graph to examine.
node_handleThe handle to the node to examine.
Returns
Either a handle to an xform, or an invalid handle if the node, its parent, or an xform for the parent doesn't exist.

◆ hierarchy_graph_root_add()

KAPI khandle hierarchy_graph_root_add ( hierarchy_graph graph)

Adds a new node to the root of the graph. Returns the handle to the new node.

Parameters
graphA pointer to the graph to add the node to.
Returns
A copy of the handle to the new node.

◆ hierarchy_graph_root_add_with_xform()

KAPI khandle hierarchy_graph_root_add_with_xform ( hierarchy_graph graph,
khandle  xform_handle 
)

Adds a new node to the root of the graph and assigns the given xform handle to it. Returns the handle to the new node.

Parameters
graphA pointer to the graph to add the node to.
xform_handleThe handle to the xform to use when adding the node.
Returns
A copy of the handle to the new node.

◆ hierarchy_graph_update()

KAPI void hierarchy_graph_update ( hierarchy_graph graph)

Performs internal update routines on the hierarchy, which includes rebuilding the internal view tree.

Parameters
graphA pointer to the graph to update.

◆ hierarchy_graph_world_position_get()

KAPI vec3 hierarchy_graph_world_position_get ( const hierarchy_graph graph,
khandle  node_handle 
)

Obtains the world position for the given node. Returns a zero vector if xform (or node itself) does not exist.

Parameters
graphA constant pointer to the hierarchy graph to traverse.
node_handleThe handle to the node to examine.
Returns
The world position.

◆ hierarchy_graph_world_rotation_get()

KAPI quat hierarchy_graph_world_rotation_get ( const hierarchy_graph graph,
khandle  node_handle 
)

Obtains the world rotation for the given node. Returns identity quaternion if xform (or node itself) does not exist.

Parameters
graphA constant pointer to the hierarchy graph to traverse.
node_handleThe handle to the node to examine.
Returns
The world rotation.

◆ hierarchy_graph_world_scale_get()

KAPI vec3 hierarchy_graph_world_scale_get ( const hierarchy_graph graph,
khandle  node_handle 
)

Obtains the world scale for the given node. Returns {1, 1, 1} if xform (or node itself) does not exist.

Parameters
graphA constant pointer to the hierarchy graph to traverse.
node_handleThe handle to the node to examine.
Returns
The world scale.

◆ hierarchy_graph_xform_handle_get()

KAPI khandle hierarchy_graph_xform_handle_get ( const hierarchy_graph graph,
khandle  node_handle 
)

Obtains the xform handle of the node provided. Will return an invalid handle if the node (or an xform for it) does not exist.

Parameters
graphA constant pointer to the graph to examine.
node_handleThe handle to the node to examine.
Returns
Either a handle to an xform, or an invalid handle if the node (or an xform for it) doesn't exist.

◆ hierarchy_graph_xform_local_matrix_get()

KAPI b8 hierarchy_graph_xform_local_matrix_get ( const hierarchy_graph graph,
khandle  node_handle,
mat4 out_matrix 
)

Attempts to get the local transformation matrix for the given hierarchy node, if it exists and has a transform.

Parameters
graphA pointer to the graph to examine.
node_handleThe handle to the node to examine.
out_matrixA constant pointer to hold the matrix. Required.
Returns
True if the node exists and has an existing xform; otherwise false.