ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/instance.c
(Generate patch)

Comparing ray/src/common/instance.c (file contents):
Revision 2.4 by greg, Thu Apr 14 04:44:47 1994 UTC vs.
Revision 2.7 by greg, Tue Mar 4 05:49:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1990 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  instance.c - routines for octree objects.
9 *
10 *      11/10/88
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "standard.h"
11  
12 + #include  "octree.h"
13 +
14   #include  "object.h"
15  
16   #include  "instance.h"
# Line 26 | Line 25 | getscene(sname, flags)                 /* load octree sname */
25   char  *sname;
26   int  flags;
27   {
29        extern char  *getlibpath();
28          char  *pathname;
29          register SCENE  *sc;
30  
31          flags &= ~IO_ILLEGAL;           /* not allowed */
32          for (sc = slist; sc != NULL; sc = sc->next)
33                  if (!strcmp(sname, sc->name)) {
34 <                        if ((sc->ldflags & flags) == flags)
34 >                        if ((sc->ldflags & flags) == flags) {
35 >                                sc->nref++;
36                                  return(sc);             /* loaded */
37 +                        }
38                          break;                  /* load the rest */
39                  }
40          if (sc == NULL) {
# Line 42 | Line 42 | int  flags;
42                  if (sc == NULL)
43                          error(SYSTEM, "out of memory in getscene");
44                  sc->name = savestr(sname);
45 +                sc->nref = 1;
46                  sc->ldflags = 0;
47                  sc->scube.cutree = EMPTY;
48                  sc->scube.cuorg[0] = sc->scube.cuorg[1] =
# Line 71 | Line 72 | getinstance(o, flags)                  /* get instance structure */
72   register OBJREC  *o;
73   int  flags;
74   {
75 <        register INSTANCE  *in;
75 >        register INSTANCE  *ins;
76  
77          flags &= ~IO_ILLEGAL;           /* not allowed */
78 <        if ((in = (INSTANCE *)o->os) == NULL) {
79 <                if ((in = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL)
78 >        if ((ins = (INSTANCE *)o->os) == NULL) {
79 >                if ((ins = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL)
80                          error(SYSTEM, "out of memory in getinstance");
81                  if (o->oargs.nsargs < 1)
82                          objerror(o, USER, "bad # of arguments");
83 <                if (fullxf(&in->x, o->oargs.nsargs-1,
83 >                if (fullxf(&ins->x, o->oargs.nsargs-1,
84                                  o->oargs.sarg+1) != o->oargs.nsargs-1)
85                          objerror(o, USER, "bad transform");
86 <                if (in->x.f.sca < 0.0)
87 <                        in->x.f.sca = -in->x.f.sca;
88 <                if (in->x.b.sca < 0.0)
89 <                        in->x.b.sca = -in->x.b.sca;
90 <                in->obj = NULL;
91 <                o->os = (char *)in;
86 >                if (ins->x.f.sca < 0.0) {
87 >                        ins->x.f.sca = -ins->x.f.sca;
88 >                        ins->x.b.sca = -ins->x.b.sca;
89 >                }
90 >                ins->obj = NULL;
91 >                o->os = (char *)ins;
92          }
93 <        if (in->obj == NULL || (in->obj->ldflags & flags) != flags)
94 <                in->obj = getscene(o->oargs.sarg[0], flags);
95 <        return(in);
93 >        if (ins->obj == NULL || (ins->obj->ldflags & flags) != flags)
94 >                ins->obj = getscene(o->oargs.sarg[0], flags);
95 >        return(ins);
96   }
97  
98  
99 + void
100 + freescene(sc)           /* release a scene reference */
101 + SCENE *sc;
102 + {
103 +        SCENE  shead;
104 +        register SCENE  *scp;
105 +
106 +        if (sc == NULL)
107 +                return;
108 +        if (sc->nref <= 0)
109 +                error(CONSISTENCY, "unreferenced scene in freescene");
110 +        sc->nref--;
111 +        if (sc->nref)                   /* still in use? */
112 +                return;
113 +        shead.next = slist;             /* else remove from our list */
114 +        for (scp = &shead; scp->next != NULL; scp = scp->next)
115 +                if (scp->next == sc) {
116 +                        scp->next = sc->next;
117 +                        sc->next = NULL;
118 +                        break;
119 +                }
120 +        if (sc->next != NULL)           /* can't be in list anymore */
121 +                error(CONSISTENCY, "unlisted scene in freescene");
122 +        slist = shead.next;
123 +        freestr(sc->name);              /* free memory */
124 +        octfree(sc->scube.cutree);
125 +        freeobjects(sc->firstobj, sc->nobjs);
126 +        free((void *)sc);
127 + }
128 +
129 +
130 + void
131   freeinstance(o)         /* free memory associated with instance */
132   OBJREC  *o;
133   {
134          if (o->os == NULL)
135                  return;
136 <        free(o->os);
136 >        freescene((*(INSTANCE *)o->os).obj);
137 >        free((void *)o->os);
138          o->os = NULL;
139   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines