1 |
greg |
1.6 |
/* Copyright (c) 1990 Regents of the University of California */ |
2 |
greg |
1.1 |
|
3 |
|
|
#ifndef lint |
4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
|
#endif |
6 |
|
|
|
7 |
|
|
/* |
8 |
|
|
* instance.c - routines for octree objects. |
9 |
|
|
* |
10 |
|
|
* 11/10/88 |
11 |
|
|
*/ |
12 |
|
|
|
13 |
|
|
#include "standard.h" |
14 |
|
|
|
15 |
|
|
#include "object.h" |
16 |
|
|
|
17 |
|
|
#include "instance.h" |
18 |
|
|
|
19 |
|
|
static SCENE *slist = NULL; /* list of loaded octrees */ |
20 |
|
|
|
21 |
|
|
|
22 |
|
|
SCENE * |
23 |
|
|
getscene(sname, flags) /* load octree sname */ |
24 |
|
|
char *sname; |
25 |
|
|
int flags; |
26 |
|
|
{ |
27 |
|
|
extern char *libpath; |
28 |
|
|
char *pathname; |
29 |
|
|
register SCENE *sc; |
30 |
|
|
|
31 |
greg |
1.5 |
flags &= ~(IO_FILES|IO_INFO); /* not allowed */ |
32 |
greg |
1.1 |
for (sc = slist; sc != NULL; sc = sc->next) |
33 |
|
|
if (!strcmp(sname, sc->name)) { |
34 |
|
|
if ((sc->ldflags & flags) == flags) |
35 |
|
|
return(sc); /* loaded */ |
36 |
|
|
break; /* load the rest */ |
37 |
|
|
} |
38 |
|
|
if (sc == NULL) { |
39 |
|
|
sc = (SCENE *)malloc(sizeof(SCENE)); |
40 |
|
|
if (sc == NULL) |
41 |
|
|
error(SYSTEM, "out of memory in getscene"); |
42 |
|
|
sc->name = savestr(sname); |
43 |
|
|
sc->ldflags = 0; |
44 |
|
|
sc->next = slist; |
45 |
|
|
slist = sc; |
46 |
|
|
} |
47 |
greg |
1.3 |
if ((pathname = getpath(sname, libpath, R_OK)) == NULL) { |
48 |
greg |
1.1 |
sprintf(errmsg, "cannot find octree file \"%s\"", sname); |
49 |
|
|
error(USER, errmsg); |
50 |
|
|
} |
51 |
|
|
readoct(pathname, flags & ~sc->ldflags, &sc->scube, NULL); |
52 |
|
|
sc->ldflags |= flags; |
53 |
|
|
return(sc); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
INSTANCE * |
58 |
|
|
getinstance(o, flags) /* get instance structure */ |
59 |
|
|
register OBJREC *o; |
60 |
|
|
int flags; |
61 |
|
|
{ |
62 |
|
|
register INSTANCE *in; |
63 |
|
|
|
64 |
|
|
if ((in = (INSTANCE *)o->os) == NULL) { |
65 |
|
|
if ((in = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL) |
66 |
|
|
error(SYSTEM, "out of memory in getinstance"); |
67 |
|
|
if (o->oargs.nsargs < 1) |
68 |
|
|
objerror(o, USER, "bad # of arguments"); |
69 |
greg |
1.6 |
if (fullxf(&in->x, o->oargs.nsargs-1, |
70 |
greg |
1.1 |
o->oargs.sarg+1) != o->oargs.nsargs-1) |
71 |
|
|
objerror(o, USER, "bad transform"); |
72 |
greg |
1.6 |
if (in->x.f.sca < 0.0) |
73 |
|
|
in->x.f.sca = -in->x.f.sca; |
74 |
|
|
if (in->x.b.sca < 0.0) |
75 |
|
|
in->x.b.sca = -in->x.b.sca; |
76 |
greg |
1.1 |
in->obj = NULL; |
77 |
greg |
1.2 |
o->os = (char *)in; |
78 |
greg |
1.1 |
} |
79 |
|
|
if (in->obj == NULL || (in->obj->ldflags & flags) != flags) |
80 |
|
|
in->obj = getscene(o->oargs.sarg[0], flags); |
81 |
|
|
return(in); |
82 |
|
|
} |
83 |
greg |
1.7 |
|
84 |
|
|
|
85 |
|
|
freeinstance(o) /* free memory associated with instance */ |
86 |
|
|
OBJREC *o; |
87 |
|
|
{ |
88 |
greg |
1.8 |
if (o->os == NULL) |
89 |
|
|
return; |
90 |
greg |
1.7 |
free(o->os); |
91 |
greg |
1.8 |
o->os = NULL; |
92 |
greg |
1.7 |
} |