1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: freeobjmem.c,v 2.6 2003/07/10 03:47:00 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* Free memory associated with object(s) |
6 |
* |
7 |
* External symbols declared in ray.h |
8 |
*/ |
9 |
|
10 |
#include "copyright.h" |
11 |
|
12 |
#include "ray.h" |
13 |
#include "otypes.h" |
14 |
#include "rtotypes.h" |
15 |
#include "face.h" |
16 |
#include "cone.h" |
17 |
#include "instance.h" |
18 |
#include "data.h" |
19 |
#include "font.h" |
20 |
#include "func.h" |
21 |
#include "mesh.h" |
22 |
|
23 |
|
24 |
extern int |
25 |
free_os( /* free unneeded memory for object */ |
26 |
register OBJREC *op |
27 |
) |
28 |
{ |
29 |
if (op->os == NULL) |
30 |
return(0); |
31 |
if (hasfunc(op->otype)) { |
32 |
freefunc(op); |
33 |
return(1); |
34 |
} |
35 |
switch (op->otype) { |
36 |
case OBJ_FACE: /* polygon */ |
37 |
freeface(op); |
38 |
return(1); |
39 |
case OBJ_CONE: /* cone */ |
40 |
case OBJ_RING: /* disk */ |
41 |
case OBJ_CYLINDER: /* cylinder */ |
42 |
case OBJ_CUP: /* inverted cone */ |
43 |
case OBJ_TUBE: /* inverted cylinder */ |
44 |
freecone(op); |
45 |
return(1); |
46 |
case OBJ_INSTANCE: /* octree instance */ |
47 |
freeinstance(op); |
48 |
return(1); |
49 |
case OBJ_MESH: /* mesh instance */ |
50 |
freemeshinst(op); |
51 |
return(1); |
52 |
case PAT_BTEXT: /* monochromatic text */ |
53 |
case PAT_CTEXT: /* colored text */ |
54 |
case MIX_TEXT: /* mixing text */ |
55 |
freetext(op); |
56 |
return(1); |
57 |
case MAT_CLIP: /* clipping surface */ |
58 |
case MAT_SPOT: /* spot light source */ |
59 |
free((void *)op->os); |
60 |
op->os = NULL; |
61 |
return(1); |
62 |
} |
63 |
#ifdef DEBUG |
64 |
objerror(op, WARNING, "cannot free structure"); |
65 |
#endif |
66 |
return(0); |
67 |
} |
68 |
|
69 |
|
70 |
extern int |
71 |
free_objs( /* free some object structures */ |
72 |
register OBJECT on, |
73 |
OBJECT no |
74 |
) |
75 |
{ |
76 |
int nfreed; |
77 |
register OBJREC *op; |
78 |
|
79 |
for (nfreed = 0; no-- > 0; on++) { |
80 |
op = objptr(on); |
81 |
if (op->os != NULL) |
82 |
nfreed += free_os(op); |
83 |
} |
84 |
return(nfreed); |
85 |
} |
86 |
|
87 |
|
88 |
extern void |
89 |
free_objmem(void) /* free all object cache memory */ |
90 |
{ |
91 |
free_objs(0, nobjects); |
92 |
freedata(NULL); |
93 |
freefont(NULL); |
94 |
} |