--- ray/src/common/instance.c 1990/12/15 15:01:37 1.6 +++ ray/src/common/instance.c 1993/02/02 13:24:50 2.3 @@ -16,6 +16,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "instance.h" +#define IO_ILLEGAL (IO_FILES|IO_INFO) + static SCENE *slist = NULL; /* list of loaded octrees */ @@ -28,7 +30,7 @@ int flags; char *pathname; register SCENE *sc; - flags &= ~(IO_FILES|IO_INFO); /* not allowed */ + flags &= ~IO_ILLEGAL; /* not allowed */ for (sc = slist; sc != NULL; sc = sc->next) if (!strcmp(sname, sc->name)) { if ((sc->ldflags & flags) == flags) @@ -41,6 +43,11 @@ int flags; error(SYSTEM, "out of memory in getscene"); sc->name = savestr(sname); sc->ldflags = 0; + sc->scube.cutree = EMPTY; + sc->scube.cuorg[0] = sc->scube.cuorg[1] = + sc->scube.cuorg[2] = 0.; + sc->scube.cusize = 0.; + sc->firstobj = sc->nobjs = 0; sc->next = slist; slist = sc; } @@ -48,7 +55,12 @@ int flags; sprintf(errmsg, "cannot find octree file \"%s\"", sname); error(USER, errmsg); } - readoct(pathname, flags & ~sc->ldflags, &sc->scube, NULL); + flags &= ~sc->ldflags; /* skip what's already loaded */ + if (flags & IO_SCENE) + sc->firstobj = nobjects; + readoct(pathname, flags, &sc->scube, NULL); + if (flags & IO_SCENE) + sc->nobjs = nobjects - sc->firstobj; sc->ldflags |= flags; return(sc); } @@ -61,6 +73,7 @@ int flags; { register INSTANCE *in; + flags &= ~IO_ILLEGAL; /* not allowed */ if ((in = (INSTANCE *)o->os) == NULL) { if ((in = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL) error(SYSTEM, "out of memory in getinstance"); @@ -79,4 +92,14 @@ int flags; if (in->obj == NULL || (in->obj->ldflags & flags) != flags) in->obj = getscene(o->oargs.sarg[0], flags); return(in); +} + + +freeinstance(o) /* free memory associated with instance */ +OBJREC *o; +{ + if (o->os == NULL) + return; + free(o->os); + o->os = NULL; }