--- ray/src/common/instance.c 1990/12/15 15:01:37 1.6 +++ ray/src/common/instance.c 1994/04/14 04:44:47 2.4 @@ -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 */ @@ -24,11 +26,11 @@ getscene(sname, flags) /* load octree sname */ char *sname; int flags; { - extern char *libpath; + extern char *getlibpath(); 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,14 +43,24 @@ 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; } - if ((pathname = getpath(sname, libpath, R_OK)) == NULL) { + if ((pathname = getpath(sname, getlibpath(), R_OK)) == NULL) { 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; }