22 |
|
|
23 |
|
|
24 |
|
SCENE * |
25 |
< |
getscene(sname, flags) /* get new octree reference */ |
26 |
< |
char *sname; |
27 |
< |
int flags; |
25 |
> |
getscene( /* get new octree reference */ |
26 |
> |
char *sname, |
27 |
> |
int flags |
28 |
> |
) |
29 |
|
{ |
30 |
|
char *pathname; |
31 |
< |
register SCENE *sc; |
31 |
> |
SCENE *sc; |
32 |
|
|
33 |
|
flags &= ~IO_ILLEGAL; /* not allowed */ |
34 |
|
for (sc = slist; sc != NULL; sc = sc->next) |
35 |
|
if (!strcmp(sname, sc->name)) |
36 |
|
break; |
37 |
< |
if (sc == NULL) { |
38 |
< |
sc = (SCENE *)malloc(sizeof(SCENE)); |
37 |
> |
if (sc == NULL) { /* new instance? */ |
38 |
> |
sc = (SCENE *)calloc(1, sizeof(SCENE)); |
39 |
|
if (sc == NULL) |
40 |
|
error(SYSTEM, "out of memory in getscene"); |
41 |
|
sc->name = savestr(sname); |
41 |
– |
sc->nref = 0; |
42 |
– |
sc->ldflags = 0; |
42 |
|
sc->scube.cutree = EMPTY; |
44 |
– |
sc->scube.cuorg[0] = sc->scube.cuorg[1] = |
45 |
– |
sc->scube.cuorg[2] = 0.; |
46 |
– |
sc->scube.cusize = 0.; |
47 |
– |
sc->firstobj = sc->nobjs = 0; |
43 |
|
sc->next = slist; |
44 |
|
slist = sc; |
45 |
|
} |
46 |
+ |
sc->nref++; /* bump reference count */ |
47 |
+ |
if (!(flags &= ~sc->ldflags)) /* nothing to load? */ |
48 |
+ |
return(sc); |
49 |
|
if ((pathname = getpath(sname, getrlibpath(), R_OK)) == NULL) { |
50 |
|
sprintf(errmsg, "cannot find octree file \"%s\"", sname); |
51 |
< |
error(USER, errmsg); |
51 |
> |
error(SYSTEM, errmsg); |
52 |
|
} |
55 |
– |
flags &= ~sc->ldflags; /* skip what's already loaded */ |
53 |
|
if (flags & IO_SCENE) |
54 |
|
sc->firstobj = nobjects; |
55 |
|
if (flags) |
57 |
|
if (flags & IO_SCENE) |
58 |
|
sc->nobjs = nobjects - sc->firstobj; |
59 |
|
sc->ldflags |= flags; |
63 |
– |
sc->nref++; /* increase reference count */ |
60 |
|
return(sc); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
INSTANCE * |
65 |
< |
getinstance(o, flags) /* get instance structure */ |
66 |
< |
register OBJREC *o; |
67 |
< |
int flags; |
65 |
> |
getinstance( /* get instance structure */ |
66 |
> |
OBJREC *o, |
67 |
> |
int flags |
68 |
> |
) |
69 |
|
{ |
70 |
< |
register INSTANCE *ins; |
70 |
> |
INSTANCE *ins; |
71 |
|
|
72 |
|
flags &= ~IO_ILLEGAL; /* not allowed */ |
73 |
|
if ((ins = (INSTANCE *)o->os) == NULL) { |
85 |
|
ins->obj = NULL; |
86 |
|
o->os = (char *)ins; |
87 |
|
} |
88 |
< |
if (ins->obj == NULL) |
88 |
> |
if (ins->obj == NULL) { |
89 |
|
ins->obj = getscene(o->oargs.sarg[0], flags); |
90 |
< |
else if ((flags &= ~ins->obj->ldflags)) { |
90 |
> |
} else if ((flags &= ~ins->obj->ldflags)) { |
91 |
|
if (flags & IO_SCENE) |
92 |
|
ins->obj->firstobj = nobjects; |
93 |
|
if (flags) |
102 |
|
|
103 |
|
|
104 |
|
void |
105 |
< |
freescene(sc) /* release a scene reference */ |
106 |
< |
SCENE *sc; |
105 |
> |
freescene( /* release a scene reference */ |
106 |
> |
SCENE *sc |
107 |
> |
) |
108 |
|
{ |
109 |
|
SCENE shead; |
110 |
< |
register SCENE *scp; |
110 |
> |
SCENE *scp; |
111 |
|
|
112 |
|
if (sc == NULL) |
113 |
|
return; |
114 |
|
if (sc->nref <= 0) |
115 |
|
error(CONSISTENCY, "unreferenced scene in freescene"); |
116 |
< |
sc->nref--; |
119 |
< |
if (sc->nref) /* still in use? */ |
116 |
> |
if (--sc->nref) /* still in use? */ |
117 |
|
return; |
118 |
|
shead.next = slist; /* else remove from our list */ |
119 |
|
for (scp = &shead; scp->next != NULL; scp = scp->next) |
128 |
|
freestr(sc->name); /* free memory */ |
129 |
|
octfree(sc->scube.cutree); |
130 |
|
freeobjects(sc->firstobj, sc->nobjs); |
131 |
< |
free((void *)sc); |
131 |
> |
free(sc); |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
void |
136 |
< |
freeinstance(o) /* free memory associated with instance */ |
137 |
< |
OBJREC *o; |
136 |
> |
freeinstance( /* free memory associated with instance */ |
137 |
> |
OBJREC *o |
138 |
> |
) |
139 |
|
{ |
140 |
|
if (o->os == NULL) |
141 |
|
return; |
142 |
|
freescene((*(INSTANCE *)o->os).obj); |
143 |
< |
free((void *)o->os); |
143 |
> |
free(o->os); |
144 |
|
o->os = NULL; |
145 |
|
} |