Kohi Game Engine
hierarchy_graph.h
Go to the documentation of this file.
1 
18 #ifndef _XFORM_GRAPH_H_
19 #define _XFORM_GRAPH_H_
20 
21 #include <identifiers/khandle.h>
22 #include <math/math_types.h>
23 
24 struct frame_data;
25 
26 typedef struct hierarchy_graph_view_node {
29 
30  // An index into the view's nodes array. INVALID_ID if no parent.
32 
33  // darray An array of indices into the view's nodes array.
36 
37 typedef struct hierarchy_graph_view {
38  // darray A collective list of all view nodes.
40  // darray An array of indices into the nodes array.
43 
44 // LEFTOFF: This node structure and the graph below should
45 // likely be opaque to the outside. External references should
46 // only deal with handles and nothing more.
47 // A separate, read-only external "view" tree structure could be
48 // provided to anything that needs to know about the heirachy (i.e. an editor).
49 
50 typedef struct hierarchy_graph {
52  // Node indices. Populated nodes will match index in the array. Invalid handle = empty slot.
54  // Parent indices in the internal node array.
56  // Levels within the hierarchy. 0 = a root node.
57  // NOTE: might just keep this in debug builds only, but it might
58  // be useful for something.
60  // Flags to mark the node as dirty.
62 
63  // Handles to the transforms.
64  // NOTE: This can be an invalid handle, meaning that this node
65  // does not have a transform. This allows nodes to exist in the hierarchy
66  // which do not have transforms (i.e. a skybox doesn't need one).
68 
69  // A view of the tree.
72 
81 
89 
97 
107 
117 
127 
137 
145 
154 
163 
174 
183 
192 KAPI b8 hierarchy_graph_child_get_by_index(const hierarchy_graph* graph, khandle parent_node_handle, u32 index, khandle* out_handle);
193 
203 KAPI void hierarchy_graph_node_remove(hierarchy_graph* graph, khandle* node_handle, b8 release_xform);
204 
213 
222 
231 
232 #endif
#define KAPI
Import/export qualifier.
Definition: defines.h:205
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
unsigned char u8
Unsigned 8-bit integer.
Definition: defines.h:19
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.
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.
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 exis...
struct hierarchy_graph hierarchy_graph
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) ...
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...
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....
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,...
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.
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 vi...
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....
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...
KAPI void hierarchy_graph_update(hierarchy_graph *graph)
Performs internal update routines on the hierarchy, which includes rebuilding the internal view tree.
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 n...
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.
struct hierarchy_graph_view_node hierarchy_graph_view_node
struct hierarchy_graph_view hierarchy_graph_view
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...
KAPI void hierarchy_graph_destroy(hierarchy_graph *graph)
Destroys the given hierarchy graph, releasing all resources. FIXME: This should also optionally relea...
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 ...
A global handle system for Kohi. Handles are used to obtain various resources using a unique handle i...
Contains various math types required for the engine.
Engine-level current frame-specific data.
Definition: frame_data.h:11
Definition: hierarchy_graph.h:26
u32 parent_index
Definition: hierarchy_graph.h:31
khandle xform_handle
Definition: hierarchy_graph.h:28
u32 * children
Definition: hierarchy_graph.h:34
khandle node_handle
Definition: hierarchy_graph.h:27
Definition: hierarchy_graph.h:37
hierarchy_graph_view_node * nodes
Definition: hierarchy_graph.h:39
u32 * root_indices
Definition: hierarchy_graph.h:41
Definition: hierarchy_graph.h:50
khandle * node_handles
Definition: hierarchy_graph.h:53
b8 * dirty_flags
Definition: hierarchy_graph.h:61
hierarchy_graph_view view
Definition: hierarchy_graph.h:70
u32 nodes_allocated
Definition: hierarchy_graph.h:51
u8 * levels
Definition: hierarchy_graph.h:59
u32 * parent_indices
Definition: hierarchy_graph.h:55
khandle * xform_handles
Definition: hierarchy_graph.h:67
A handle is a unique identifier used a system in the engine to avoid using raw pointers where possibl...
Definition: khandle.h:25
a 4x4 matrix, typically used to represent object transformations.
Definition: math_types.h:195
A 3-element vector.
Definition: math_types.h:49
A 4-element vector.
Definition: math_types.h:89