home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Peter's Final Project / src / face.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  2.8 KB  |  157 lines  |  [TEXT/KAHL]

  1. /*
  2.  *  Peter's Final Project -- A texture mapping demonstration
  3.  *  © 1995, Peter Mattis
  4.  *
  5.  *  E-mail:
  6.  *  petm@soda.csua.berkeley.edu
  7.  *
  8.  *  Snail-mail:
  9.  *   Peter Mattis
  10.  *   557 Fort Laramie Dr.
  11.  *   Sunnyvale, CA 94087
  12.  *
  13.  *  Avaible from:
  14.  *  http://www.csua.berkeley.edu/~petm/final.html
  15.  *
  16.  *  This program is free software; you can redistribute it and/or modify
  17.  *  it under the terms of the GNU General Public License as published by
  18.  *  the Free Software Foundation; either version 2 of the License, or
  19.  *  (at your option) any later version.
  20.  *
  21.  *  This program is distributed in the hope that it will be useful,
  22.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24.  *  GNU General Public License for more details.
  25.  *
  26.  *  You should have received a copy of the GNU General Public License
  27.  *  along with this program; if not, write to the Free Software
  28.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29.  */
  30.  
  31. #include <assert.h>
  32. #include "face.h"
  33. #include "sys.stuff.h"
  34.  
  35. /*
  36.  * Keep a list of free faces for fast allocation.
  37.  * Keep track of the memory used by faces.
  38.  */
  39.  
  40. static FACES free_faces_list = NULL;
  41. static long face_mem = 0;
  42.  
  43. /*
  44.  * Make a face object and initialize its values to something decent.
  45.  */
  46.  
  47. FACE
  48. make_face ()
  49. {
  50.     FACES faces;
  51.     FACE face;
  52.  
  53.     if (free_faces_list)
  54.     {
  55.         faces = free_faces_list;
  56.         face = faces_first (faces);
  57.         free_faces_list = faces_rest (free_faces_list);
  58.         free_list (faces);
  59.     }
  60.     else
  61.     {
  62.         face_mem += sizeof (_FACE);
  63.  
  64.         face = (FACE) ALLOC (sizeof (_FACE));
  65.     }
  66.  
  67.     set_face_points (face, NULL);
  68.     set_face_normal (face, NULL);
  69.     set_face_texture_o (face, NULL);
  70.     set_face_texture_u (face, NULL);
  71.     set_face_texture_v (face, NULL);
  72.     set_face_intensity (face, 0);
  73.     set_face_texture (face, NULL);
  74.     set_face_obstructs (face, FALSE);
  75.  
  76.     return face;
  77. }
  78.  
  79. /*
  80.  * Free a face by placing it on the free list.
  81.  */
  82.  
  83. void
  84. free_face (f)
  85.     FACE f;
  86. {
  87.     LIST temp;
  88.  
  89.     temp = make_list ();
  90.     set_list_datum (temp, f);
  91.     set_list_next (temp, free_faces_list);
  92.     free_faces_list = temp;
  93. }
  94.  
  95. /*
  96.  * Append a face to a list of faces.
  97.  */
  98.  
  99. FACES
  100. faces_append_face (set, f)
  101.     FACES set;
  102.     FACE f;
  103. {
  104.     LIST n;
  105.  
  106.     n = make_list ();
  107.     set_list_datum (n, f);
  108.     set_list_next (n, NULL);
  109.     
  110.     return (FACES) list_append_list ((LIST) set, n);
  111. }
  112.  
  113. /*
  114.  * Prepend a face to a list of faces.
  115.  */
  116.  
  117. FACES
  118. faces_prepend_face (set, f)
  119.     FACES set;
  120.     FACE f;
  121. {
  122.     LIST n;
  123.  
  124.     n = make_list ();
  125.     set_list_datum (n, f);
  126.     set_list_next (n, NULL);
  127.     
  128.     return (FACES) list_prepend_list ((LIST) set, n);
  129. }
  130.  
  131. /*
  132.  * Free a list of faces.
  133.  */
  134.  
  135. void
  136. free_faces (set)
  137.     FACES set;
  138. {
  139.     if (set == NULL)
  140.         return;
  141.  
  142.     free_faces (faces_rest (set));
  143.  
  144.     set_faces_rest (set, free_faces_list);
  145.     free_faces_list = set;
  146. }
  147.  
  148. /*
  149.  * Return the face memory usage.
  150.  */
  151.  
  152. long
  153. face_mem_usage ()
  154. {
  155.     return face_mem;
  156. }
  157.