2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # `data`
  2. Fundamental functions for various data structures used in the project.
  3. ## `list`
  4. A doubly-linked list is used on certain parts of the game, such as the memory pool's entries of currently allocated game
  5. objects.
  6. Here is how to properly use a list:
  7. ```c
  8. #include <stdbool.h>
  9. #include "IZ_list.h"
  10. // find predicates
  11. bool FindNodeWithValueOne(IZ_ListNode**, unsigned long long, IZ_List*);
  12. bool FindNodeWithValueTwo(IZ_ListNode**, unsigned long long, IZ_List*);
  13. int main() {
  14. IZ_List list;
  15. // important to initialize lists first, else there may be garbage data in the list members.
  16. IZ_ListInitialize(&list);
  17. // lists should accept any type of value (void*), so the implementor is free to use whatever type they want
  18. int node1_value = 1;
  19. IZ_ListAppendNode(&list, &node1_value, NULL);
  20. int node2_value = 2;
  21. IZ_ListAppendNode(&list, &node2_value, NULL);
  22. // pass predicate functions for finding nodes
  23. ListNode* find_node = NULL;
  24. IZ_ListFindFirstNode(&list, &FindNodeWithValueTwo, &find_node);
  25. if (find_node != NULL) {
  26. printf("Found node with value 2!\n");
  27. }
  28. ListNode* delete_node;
  29. IZ_ListFindFirstNode(&list, &FindNodeWithValueOne, &delete_node);
  30. // deletions are done only on one node at a time
  31. IZ_ListDeleteNode(delete_node);
  32. // teardown takes care of de-allocating nodes and making sure data cannot be accessed sensibly anymore.
  33. IZ_ListTeardown(&list);
  34. return 0;
  35. }
  36. bool FindNodeWithValueOne(IZ_ListNode** node, unsigned long long index, IZ_List* list) {
  37. return (*node)->value == 1;
  38. }
  39. bool FindNodeWithValueTwo(IZ_ListNode** node, unsigned long long index, IZ_List* list) {
  40. return (*node)->value == 2;
  41. }
  42. ```