# graph_node_macros.h ## Overview
Macros used for tagging blocks of code for the `generate-graph-nodes` utility. `generate-graph-nodes` searches all files matching the pattern `*graph_nodes*.c`for these macros and generates interface code for all functions inside a `GGN_BEGIN/GGN_END` macro pair. This interface code is generated into an `*.inl` file with the same name as the original file, and is usually included in the `*.c` file with an `#include` directive. The additional macros in this file can be used to further specify how functions and parameters should be interpreted by the graph system. For example, you can mark parameters as optional, give them custom types and names, etc. These macros apply to the next node function only (i.e. they are stateless). Example: ~~~c GGN_BEGIN("Sample/Math/Float") GGN_GEN_REGISTER_FUNCTION() GGN_NODE_QUERY() static inline void sample_float_square(float a, float *res) { *res = a * a; } GGN_END() #include "graph_nodes.inl" TM_DLL_EXPORT void tm_load_plugin(struct tm_api_registry_api *reg, bool load) { // This is auto generated from the graph node generator, you just need to call it. generated__register_graph_nodes(reg, load); } ~~~
## Index
`GGN_BEGIN()`
`GGN_END()`
`GGN_GEN_REGISTER_FUNCTION()`
`GGN_NODE_QUERY()`
`GGN_NODE_DISPLAY_NAME()`
`GGN_NODE_HANDLE_CUSTOM_DEFAULT_VALUES()`

Parameter macros
`GGN_PARAM_TOOLTIP()`
`GGN_PARAM_OPTIONAL()`
`GGN_PARAM_DEFAULT_VALUE()`
`GGN_PARAM_EDIT_TYPE()`
`GGN_PARAM_CONNECTOR()`
## API
### `GGN_BEGIN()`
~~~c #define GGN_BEGIN(category) ~~~ Begins a new block of functions to be exposed to the graph interpreter. For each function in the block, a `*_node_f` function wrapper will be generated that converts graph wire data to the parameter types expected by the function. In addition, a `tm_graph_component_node_type_i` struct will be generated that describes the node. The block is ended by the `GGN_END()` macro. All the nodes in the block will be given the specified `category`. If you want nodes with different categories in the same `.c` file, you should use multiple `GGN_BEGIN/GGN_END` pairs.
### `GGN_END()`
~~~c #define GGN_END() ~~~ Ends a node definition block started by `GGN_BEGIN()`.
### `GGN_GEN_REGISTER_FUNCTION()`
~~~c #define GGN_GEN_REGISTER_FUNCTION() ~~~ If this macro is used inside any `GGN_BEGIN/GGN_END` block, a function for registering all the nodes in the file with the API registry will automatically be generated. The name of the function will be `generated__register_<FILENAME>`.
### `GGN_NODE_QUERY()`
~~~c #define GGN_NODE_QUERY() ~~~ The `GGN_NODE_QUERY()` macro marks this node as a Query node. Query nodes are triggered automatically when their output is requested. Nodes that aren't query nodes need to be triggered by an explicit event.
### `GGN_NODE_DISPLAY_NAME()`
~~~c #define GGN_NODE_DISPLAY_NAME(display_name) ~~~ Generated nodes will by default have the same name as the function that implements them. Using this macro before the node definition will give the node a different "display name" -- i.e. the name that will be shown for the node in the graph editor. The node will still use the function name in the save files. Note that changing the "display name" of a node is harmless, but changing its actual name (the name of the function) will break compatibility with old save files.
### `GGN_NODE_HANDLE_CUSTOM_DEFAULT_VALUES()`
~~~c #define GGN_NODE_HANDLE_CUSTOM_DEFAULT_VALUES(function) ~~~ Optional. Defines a `tm_graph_node_type_i->handle_custom_default_values()` function that will be used to initialize the Truth object used for editing the connector value from the specified `GGN_PARAM_DEFAULT_VALUE()` value.

Parameter macros

### `GGN_PARAM_TOOLTIP()`
~~~c #define GGN_PARAM_TOOLTIP(parameter, tooltip) ~~~ Specifies a toolip associated with the `parameter`. The macro automatically adds `TM_LOCALIZE_LATER()` around your text.
### `GGN_PARAM_OPTIONAL()`
~~~c #define GGN_PARAM_OPTIONAL(parameter) ~~~ Specifies that `parameter` is optional.
### `GGN_PARAM_DEFAULT_VALUE()`
~~~c #define GGN_PARAM_DEFAULT_VALUE(parameter, value) ~~~ Specify a default value for `parameter`. This default value will be used if an optional parameter is not given an explicit value.
### `GGN_PARAM_EDIT_TYPE()`
~~~c #define GGN_PARAM_EDIT_TYPE(parameter, type) ~~~ Specifies that `parameter` should be considered to be of `type` in the editor. This is used when you want to give the graph editor more information about the parameter's `type` than what is available from the parameter type in the function definition. As an example, a `tm_vec3_t` can represent either a *position* or a *scale*. Using: ~~~c GGN_PARAM_EDIT_TYPE(position, POSITION); ~~~ Clarifies that we are taking about a `TM_TT_TYPE__POSITION` parameter. (`TM_TT_TYPE_` is automatically prepended to the type specified with `GGN_PARAM_EDIT_TYPE`.)
### `GGN_PARAM_CONNECTOR()`
~~~c #define GGN_PARAM_CONNECTOR(parameter, connector) ~~~ Specifies the display name for the `parameter`s connector. By default, the text shown on the connector will be the same as the name of the parameter, but sometimes you may want to use a different name: ~~~c GGN_PARAM_CONNECTOR(b, "bool"); GGN_PARAM_CONNECTOR(true_res, "true res"); GGN_PARAM_CONNECTOR(false_res, "false res"); static inline void bool_to_float(bool b, float true_res, float false_res, float *res) ~~~ In this case we can't give the parameters the name `bool` or `true res`, because they are not valid C identifiers, but by using the `GGN_PARAM_CONNECTOR()` macro we can ensure that the connectors still get the desired names.