home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / RAYCAST.ZIP / RAYVB.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-19  |  2.5 KB  |  100 lines

  1. #include "ray.h"
  2. #include "rayrt.h"
  3. #include <stddef.h>
  4.  
  5. #define VB_NULL -1
  6.  
  7. extern "C" vb_node_index vb_next_free_node, vb_start_node;
  8.  
  9. extern "C" vb_node * bounds;
  10.  
  11. inline vb_node * VB_GetFirstNode()
  12. {
  13.    return (bounds + vb_start_node);
  14. }
  15.  
  16. inline void VB_InitList()
  17. {
  18.    vb_next_free_node=0; vb_start_node=0;
  19.    bounds[0].left=0;
  20.    bounds[0].right=WINDOW_WIDTH;
  21.    bounds[0].next_node=VB_NULL; bounds[0].back_node=VB_NULL;
  22. }
  23.  
  24. inline vb_node_index VB_AllocateNode()
  25. {
  26.    vb_next_free_node++;
  27.    return vb_next_free_node;
  28. }
  29.  
  30. inline vb_node * VB_GetNextNode(vb_node * base)
  31. {
  32.    if (base->next_node==VB_NULL) {
  33.       return NULL;
  34.    } else {
  35.       return (bounds + (base->next_node));
  36.    } /* endif */
  37.  
  38. }
  39.  
  40. inline vb_node * VB_DeleteNode(vb_node * delete_node)
  41. {
  42.  
  43.    if (delete_node->back_node == VB_NULL) {
  44.       vb_start_node=delete_node->next_node;
  45.       if (vb_start_node == VB_NULL) 
  46.          return NULL;
  47.       else return (bounds+vb_start_node);
  48.    } else {
  49.       if (delete_node->next_node == VB_NULL) {
  50.          bounds[delete_node->back_node].next_node=VB_NULL;
  51.          return NULL;
  52.       } else {
  53.       bounds[delete_node->back_node].next_node=delete_node->next_node;
  54.       bounds[delete_node->next_node].back_node=delete_node->back_node;
  55.       return bounds+delete_node->next_node;
  56.       }
  57.    } /* endif */
  58.  
  59. }
  60.  
  61. inline void VB_AttachNode(vb_node * base_node, vb_node_index next_node)
  62. {
  63.    short base_node_index=(short)(base_node-bounds);
  64.    if (next_node!=NULL)
  65.       bounds[next_node].back_node=base_node_index;
  66.    base_node->next_node=next_node;
  67. }
  68.  
  69. // Cut a section out of visible boundaries. Precondition: start>=end
  70.  
  71. inline void VB_CoverSection(vb_node * & base_node, SHORT start, SHORT end)
  72. {
  73.    if ((start > base_node->right) || (end <= base_node->left)) 
  74.      return;
  75.    if (start <= base_node->left) {
  76.       if (end >= base_node->right) {
  77.          base_node=VB_DeleteNode(base_node);
  78.       } else {
  79.          base_node->left=end;
  80.       } /* endif */
  81.       return;
  82.    } /* endif */
  83.    if (end >= base_node->right) {
  84.       base_node->right=start; 
  85.       return;
  86.    } /* endif */
  87.    vb_node_index next_node=VB_AllocateNode();
  88.    VB_AttachNode((bounds + next_node), base_node->next_node);
  89.    VB_AttachNode(base_node, next_node);
  90.    bounds[next_node].left=end;
  91.    bounds[next_node].right=base_node->right;
  92.    base_node->right=start;
  93.    base_node=bounds+next_node;
  94. }
  95.  
  96. inline BOOL VB_EmptyList()
  97. {
  98.    return ((vb_start_node == VB_NULL) ? TRUE : FALSE);
  99. }
  100.