Project: 3D Craft -- Node data structures

As any student in computer science can tell you, linked lists of things come in really handy. Especially when you don't know ahead of time how many of the things you will need. The use of linked lists in high performance graphics however is somewhat controversial. On the one hand they provide an easy way to express dynamically extensible lists of things like vertices, on the other hand they are a bit slower to access than fixed arrays. Because of this performance hit many people believe that they have no place in an engine that expects to get the maximum rendering performance out of the system.

My philosophy on nodes is simple, they make my life easier and that is good. They make the code more flexible and that is good. They slow things down a bit, and that is bad, but since I started this project the speed of my "desktop" system has doubled, so being a bit slower is irrelevant.

Finally, the current node system creates both singly and doubly linked lists as well as sorted binary search trees with the same node structure, however there are different function calls for BSTs vs lists. This will be corrected in a later release by adding typing information to the node structure.


The following functions operated on nodes

p3dc_NODE *p3dc_new_node( void *payload, char *name, int flags )

This function allocates a new node (possibly recovering it from the node free list) and assigns its d pointer to the payload and, if name is non-null, malloc's a string to hold a copy of the name. Initially the type is unknown. The only supported flag at the moment is P3DC_NODE_FREEPAYLOAD that causes the payload pointer to be freed with a called to either p3dc_free_type or p3dc_free_list (if its type is P3DC_LIST).

void p3dc_free_node( p3dc_NODE *node )

This function frees the node passed to it, if the node has an allocated name it frees that as well. If the free_payload flag is true, it frees the payload pointer as well. If the type of node being freed is a list then p3dc_free_list is called on that node.