| 1 | greg | 2.1 | /* Copyright (c) 1992 Regents of the University of California */ | 
| 2 |  |  |  | 
| 3 |  |  | #ifndef lint | 
| 4 |  |  | static char SCCSid[] = "$SunId$ LBL"; | 
| 5 |  |  | #endif | 
| 6 |  |  |  | 
| 7 |  |  | /* | 
| 8 |  |  | * Free memory associated with object(s) | 
| 9 |  |  | */ | 
| 10 |  |  |  | 
| 11 |  |  | #include "standard.h" | 
| 12 |  |  | #include "object.h" | 
| 13 |  |  | #include "otypes.h" | 
| 14 |  |  |  | 
| 15 |  |  |  | 
| 16 |  |  | int | 
| 17 |  |  | free_os(op)                     /* free unneeded memory for object */ | 
| 18 |  |  | register OBJREC *op; | 
| 19 |  |  | { | 
| 20 |  |  | if (op->os == NULL) | 
| 21 |  |  | return(0); | 
| 22 |  |  | if (hasfunc(op->otype)) { | 
| 23 |  |  | freefunc(op); | 
| 24 |  |  | return(1); | 
| 25 |  |  | } | 
| 26 |  |  | switch (op->otype) { | 
| 27 |  |  | case OBJ_FACE:          /* polygon */ | 
| 28 |  |  | freeface(op); | 
| 29 |  |  | return(1); | 
| 30 |  |  | case OBJ_CONE:          /* cone */ | 
| 31 |  |  | case OBJ_RING:          /* disk */ | 
| 32 |  |  | case OBJ_CYLINDER:      /* cylinder */ | 
| 33 |  |  | case OBJ_CUP:           /* inverted cone */ | 
| 34 |  |  | case OBJ_TUBE:          /* inverted cylinder */ | 
| 35 |  |  | freecone(op); | 
| 36 |  |  | return(1); | 
| 37 |  |  | case OBJ_INSTANCE:      /* octree instance */ | 
| 38 |  |  | freeinstance(op); | 
| 39 |  |  | return(1); | 
| 40 |  |  | case PAT_BTEXT:         /* monochromatic text */ | 
| 41 |  |  | case PAT_CTEXT:         /* colored text */ | 
| 42 |  |  | case MIX_TEXT:          /* mixing text */ | 
| 43 |  |  | freetext(op); | 
| 44 |  |  | return(1); | 
| 45 |  |  | case MAT_CLIP:          /* clipping surface */ | 
| 46 |  |  | free(op->os); | 
| 47 |  |  | op->os = NULL; | 
| 48 |  |  | return(1); | 
| 49 |  |  | case MAT_SPOT:          /* spot light source */ | 
| 50 |  |  | return(0); | 
| 51 |  |  | default: | 
| 52 |  |  | #ifdef DEBUG | 
| 53 |  |  | objerror(op, WARNING, "cannot free structure"); | 
| 54 |  |  | #endif | 
| 55 |  |  | return(0); | 
| 56 |  |  | } | 
| 57 |  |  | } | 
| 58 |  |  |  | 
| 59 |  |  |  | 
| 60 |  |  | int | 
| 61 | greg | 2.2 | free_objs(on, no)               /* free some object structures */ | 
| 62 | greg | 2.1 | register OBJECT on; | 
| 63 |  |  | OBJECT  no; | 
| 64 |  |  | { | 
| 65 |  |  | int     nfreed; | 
| 66 |  |  | register OBJREC *op; | 
| 67 |  |  |  | 
| 68 |  |  | for (nfreed = 0; no-- > 0; on++) { | 
| 69 |  |  | op = objptr(on); | 
| 70 | greg | 2.2 | if (op->os != NULL) | 
| 71 | greg | 2.1 | nfreed += free_os(op); | 
| 72 |  |  | } | 
| 73 |  |  | return(nfreed); | 
| 74 |  |  | } | 
| 75 |  |  |  | 
| 76 |  |  |  | 
| 77 |  |  | free_objmem()                   /* free all object cache memory */ | 
| 78 |  |  | { | 
| 79 | greg | 2.2 | free_objs(0, nobjects); | 
| 80 | greg | 2.1 | freedata(NULL); | 
| 81 |  |  | freefont(NULL); | 
| 82 |  |  | } |