--- ray/src/common/instance.c 2003/11/14 17:22:06 2.10 +++ ray/src/common/instance.c 2024/12/12 20:04:46 2.14 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: instance.c,v 2.10 2003/11/14 17:22:06 schorsch Exp $"; +static const char RCSid[] = "$Id: instance.c,v 2.14 2024/12/12 20:04:46 greg Exp $"; #endif /* * instance.c - routines for octree objects. @@ -10,6 +10,7 @@ static const char RCSid[] = "$Id: instance.c,v 2.10 20 #include "rtmath.h" #include "rterror.h" #include "rtio.h" +#include "paths.h" #include "octree.h" #include "object.h" @@ -21,37 +22,34 @@ static SCENE *slist = NULL; /* list of loaded octree SCENE * -getscene(sname, flags) /* get new octree reference */ -char *sname; -int flags; +getscene( /* get new octree reference */ + char *sname, + int flags +) { char *pathname; - register SCENE *sc; + SCENE *sc; flags &= ~IO_ILLEGAL; /* not allowed */ for (sc = slist; sc != NULL; sc = sc->next) if (!strcmp(sname, sc->name)) break; - if (sc == NULL) { - sc = (SCENE *)malloc(sizeof(SCENE)); + if (sc == NULL) { /* new instance? */ + sc = (SCENE *)calloc(1, sizeof(SCENE)); if (sc == NULL) error(SYSTEM, "out of memory in getscene"); sc->name = savestr(sname); - sc->nref = 0; - 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; } + sc->nref++; /* bump reference count */ + if (!(flags &= ~sc->ldflags)) /* nothing to load? */ + return(sc); if ((pathname = getpath(sname, getrlibpath(), R_OK)) == NULL) { sprintf(errmsg, "cannot find octree file \"%s\"", sname); - error(USER, errmsg); + error(SYSTEM, errmsg); } - flags &= ~sc->ldflags; /* skip what's already loaded */ if (flags & IO_SCENE) sc->firstobj = nobjects; if (flags) @@ -59,17 +57,17 @@ int flags; if (flags & IO_SCENE) sc->nobjs = nobjects - sc->firstobj; sc->ldflags |= flags; - sc->nref++; /* increase reference count */ return(sc); } INSTANCE * -getinstance(o, flags) /* get instance structure */ -register OBJREC *o; -int flags; +getinstance( /* get instance structure */ + OBJREC *o, + int flags +) { - register INSTANCE *ins; + INSTANCE *ins; flags &= ~IO_ILLEGAL; /* not allowed */ if ((ins = (INSTANCE *)o->os) == NULL) { @@ -87,9 +85,9 @@ int flags; ins->obj = NULL; o->os = (char *)ins; } - if (ins->obj == NULL) + if (ins->obj == NULL) { ins->obj = getscene(o->oargs.sarg[0], flags); - else if ((flags &= ~ins->obj->ldflags)) { + } else if ((flags &= ~ins->obj->ldflags)) { if (flags & IO_SCENE) ins->obj->firstobj = nobjects; if (flags) @@ -104,18 +102,18 @@ int flags; void -freescene(sc) /* release a scene reference */ -SCENE *sc; +freescene( /* release a scene reference */ + SCENE *sc +) { SCENE shead; - register SCENE *scp; + SCENE *scp; if (sc == NULL) return; if (sc->nref <= 0) error(CONSISTENCY, "unreferenced scene in freescene"); - sc->nref--; - if (sc->nref) /* still in use? */ + if (--sc->nref) /* still in use? */ return; shead.next = slist; /* else remove from our list */ for (scp = &shead; scp->next != NULL; scp = scp->next) @@ -130,17 +128,18 @@ SCENE *sc; freestr(sc->name); /* free memory */ octfree(sc->scube.cutree); freeobjects(sc->firstobj, sc->nobjs); - free((void *)sc); + free(sc); } void -freeinstance(o) /* free memory associated with instance */ -OBJREC *o; +freeinstance( /* free memory associated with instance */ + OBJREC *o +) { if (o->os == NULL) return; freescene((*(INSTANCE *)o->os).obj); - free((void *)o->os); + free(o->os); o->os = NULL; }