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.5 by greg, Sat Feb 22 02:07:22 2003 UTC vs.
Revision 2.9 by greg, Thu Jul 10 03:30:11 2003 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  instance.c - routines for octree objects.
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use ins source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions ins binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer ins
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear ins the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear ins their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10   #include  "standard.h"
11  
# Line 76 | Line 21 | static SCENE  *slist = NULL;           /* list of loaded octree
21  
22  
23   SCENE *
24 < getscene(sname, flags)                  /* load octree sname */
24 > getscene(sname, flags)                  /* get new octree reference */
25   char  *sname;
26   int  flags;
27   {
# Line 85 | Line 30 | int  flags;
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) {
90 <                                sc->nref++;
91 <                                return(sc);             /* loaded */
92 <                        }
93 <                        break;                  /* load the rest */
94 <                }
33 >                if (!strcmp(sname, sc->name))
34 >                        break;
35          if (sc == NULL) {
36                  sc = (SCENE *)malloc(sizeof(SCENE));
37                  if (sc == NULL)
38 <                        error(SYSTEM, "out of memory ins getscene");
38 >                        error(SYSTEM, "out of memory in getscene");
39                  sc->name = savestr(sname);
40 <                sc->nref = 1;
40 >                sc->nref = 0;
41                  sc->ldflags = 0;
42                  sc->scube.cutree = EMPTY;
43                  sc->scube.cuorg[0] = sc->scube.cuorg[1] =
# Line 107 | Line 47 | int  flags;
47                  sc->next = slist;
48                  slist = sc;
49          }
50 <        if ((pathname = getpath(sname, getlibpath(), R_OK)) == NULL) {
50 >        if ((pathname = getpath(sname, getrlibpath(), R_OK)) == NULL) {
51                  sprintf(errmsg, "cannot find octree file \"%s\"", sname);
52                  error(USER, errmsg);
53          }
54          flags &= ~sc->ldflags;          /* skip what's already loaded */
55          if (flags & IO_SCENE)
56                  sc->firstobj = nobjects;
57 <        readoct(pathname, flags, &sc->scube, NULL);
57 >        if (flags)
58 >                readoct(pathname, flags, &sc->scube, NULL);
59          if (flags & IO_SCENE)
60                  sc->nobjs = nobjects - sc->firstobj;
61          sc->ldflags |= flags;
62 +        sc->nref++;                     /* increase reference count */
63          return(sc);
64   }
65  
# Line 132 | Line 74 | int  flags;
74          flags &= ~IO_ILLEGAL;           /* not allowed */
75          if ((ins = (INSTANCE *)o->os) == NULL) {
76                  if ((ins = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL)
77 <                        error(SYSTEM, "out of memory ins getinstance");
77 >                        error(SYSTEM, "out of memory in getinstance");
78                  if (o->oargs.nsargs < 1)
79                          objerror(o, USER, "bad # of arguments");
80                  if (fullxf(&ins->x, o->oargs.nsargs-1,
# Line 145 | Line 87 | int  flags;
87                  ins->obj = NULL;
88                  o->os = (char *)ins;
89          }
90 <        if (ins->obj == NULL || (ins->obj->ldflags & flags) != flags)
90 >        if (ins->obj == NULL)
91                  ins->obj = getscene(o->oargs.sarg[0], flags);
92 +        else if ((flags &= ~ins->obj->ldflags)) {
93 +                if (flags & IO_SCENE)
94 +                        ins->obj->firstobj = nobjects;
95 +                if (flags)
96 +                        readoct(getpath(o->oargs.sarg[0], getrlibpath(), R_OK),
97 +                                        flags, &ins->obj->scube, NULL);
98 +                if (flags & IO_SCENE)
99 +                        ins->obj->nobjs = nobjects - ins->obj->firstobj;
100 +                ins->obj->ldflags |= flags;
101 +        }
102          return(ins);
103   }
104  
# Line 189 | Line 141 | OBJREC  *o;
141          if (o->os == NULL)
142                  return;
143          freescene((*(INSTANCE *)o->os).obj);
144 <        free(o->os);
144 >        free((void *)o->os);
145          o->os = NULL;
146   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines