1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
24 |
|
|
25 |
|
int imm_mode = 0; /* bundles are being delivered immediately */ |
26 |
|
|
27 |
+ |
int do_outside = 0; /* render from outside sections */ |
28 |
+ |
|
29 |
|
char *progname; /* global argv[0] */ |
30 |
|
|
31 |
|
FILE *sstdin, *sstdout; /* server's standard input and output */ |
32 |
|
|
33 |
+ |
#ifdef DEBUG |
34 |
+ |
#include <sys/types.h> |
35 |
+ |
extern time_t time(); |
36 |
+ |
static time_t tmodesw; |
37 |
+ |
static time_t timm, tadd; |
38 |
+ |
static long nimmrays, naddrays; |
39 |
+ |
#endif |
40 |
+ |
|
41 |
|
#define RDY_SRV 01 |
42 |
|
#define RDY_DEV 02 |
43 |
|
#define RDY_SIN 04 |
63 |
|
sstdin = fdopen(inp, "r"); |
64 |
|
/* set command error vector */ |
65 |
|
erract[COMMAND].pf = eputs; |
66 |
+ |
#ifdef DEBUG |
67 |
+ |
tmodesw = time(NULL); |
68 |
+ |
#endif |
69 |
|
/* enter main loop */ |
70 |
|
do { |
71 |
|
rdy = disp_wait(); |
72 |
+ |
if (rdy & RDY_SRV) { /* process server result */ |
73 |
+ |
res = serv_result(); |
74 |
+ |
if (pause && res != DS_SHUTDOWN) { |
75 |
+ |
serv_request(DR_ATTEN, 0, NULL); |
76 |
+ |
while ((res = serv_result()) != DS_ACKNOW && |
77 |
+ |
res != DS_SHUTDOWN) |
78 |
+ |
; |
79 |
+ |
} |
80 |
+ |
} |
81 |
|
if (rdy & RDY_DEV) { /* user input from driver */ |
82 |
|
inp = dev_input(); |
83 |
|
if (inp & DFL(DC_SETVIEW)) |
93 |
|
if (inp & DFL(DC_PAUSE)) |
94 |
|
pause = 1; |
95 |
|
if (inp & DFL(DC_REDRAW)) |
96 |
< |
imm_mode = beam_sync() > 0; |
96 |
> |
imm_mode = beam_sync(1) > 0; |
97 |
|
if (inp & DFL(DC_KILL)) { |
98 |
|
serv_request(DR_KILL, 0, NULL); |
99 |
|
pause = 0; |
120 |
|
pause = 0; |
121 |
|
break; |
122 |
|
} |
101 |
– |
if (rdy & RDY_SRV) { /* process server result */ |
102 |
– |
res = serv_result(); |
103 |
– |
if (pause && res != DS_SHUTDOWN) { |
104 |
– |
serv_request(DR_ATTEN, 0, NULL); |
105 |
– |
while ((res = serv_result()) != DS_ACKNOW && |
106 |
– |
res != DS_SHUTDOWN) |
107 |
– |
; |
108 |
– |
} |
109 |
– |
} |
123 |
|
} while (res != DS_SHUTDOWN); |
124 |
+ |
#ifdef DEBUG |
125 |
+ |
if (timm && nimmrays) |
126 |
+ |
fprintf(stderr, |
127 |
+ |
"%s: %.1f rays recalled/second (%ld rays total)\n", |
128 |
+ |
progname, (double)nimmrays/timm, nimmrays); |
129 |
+ |
if (tadd && naddrays) |
130 |
+ |
fprintf(stderr, |
131 |
+ |
"%s: %.1f rays calculated/second (%ld rays total)\n", |
132 |
+ |
progname, (double)naddrays/tadd, naddrays); |
133 |
+ |
#endif |
134 |
|
/* all done */ |
135 |
|
quit(0); |
136 |
|
} |
159 |
|
n = odev.ifd+1; |
160 |
|
if (sstdin != NULL) { |
161 |
|
FD_SET(fileno(sstdin), &readset); |
162 |
+ |
FD_SET(fileno(sstdin), &errset); |
163 |
|
if (fileno(sstdin) >= n) |
164 |
|
n = fileno(sstdin) + 1; |
165 |
|
} |
174 |
|
flgs |= RDY_SRV; |
175 |
|
if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset)) |
176 |
|
flgs |= RDY_DEV; |
177 |
< |
if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset)) |
177 |
> |
if (sstdin != NULL && (FD_ISSET(fileno(sstdin), &readset) || |
178 |
> |
FD_ISSET(fileno(sstdin), &errset))) |
179 |
|
flgs |= RDY_SIN; |
180 |
|
return(flgs); |
181 |
|
} |
185 |
|
HDGRID *hdg; |
186 |
|
{ |
187 |
|
VIEW nv; |
188 |
+ |
double d; |
189 |
|
register int hd; |
190 |
|
|
191 |
|
for (hd = 0; hd < HDMAX && hdlist[hd] != NULL; hd++) |
206 |
|
VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5); |
207 |
|
fcross(nv.vdir, hdlist[0]->xv[1], hdlist[0]->xv[2]); |
208 |
|
VCOPY(nv.vup, hdlist[0]->xv[2]); |
209 |
+ |
if (do_outside) { |
210 |
+ |
normalize(nv.vdir); |
211 |
+ |
d = VLEN(hdlist[0]->xv[1]); |
212 |
+ |
d += VLEN(hdlist[0]->xv[2]); |
213 |
+ |
VSUM(nv.vp, nv.vp, nv.vdir, -d); |
214 |
+ |
} |
215 |
|
new_view(&nv); |
216 |
|
} |
217 |
|
|
235 |
|
VSUM(wp, ro, rd, d); /* might be behind viewpoint */ |
236 |
|
dev_value(packra(p)[i].v, wp, rd); |
237 |
|
} |
238 |
+ |
#ifdef DEBUG |
239 |
+ |
if (imm_mode) nimmrays += p->nr; |
240 |
+ |
else naddrays += p->nr; |
241 |
+ |
#endif |
242 |
|
} |
243 |
|
|
244 |
|
|
247 |
|
{ |
248 |
|
static VIEW viewhist[VIEWHISTLEN]; |
249 |
|
static unsigned nhist; |
250 |
+ |
VIEW *dv; |
251 |
+ |
int i, res[2]; |
252 |
|
char *err; |
253 |
|
/* restore previous view? */ |
254 |
|
if (v == NULL) { |
268 |
|
error(COMMAND, "cannot handle parallel views"); |
269 |
|
return; |
270 |
|
} |
271 |
< |
if (!dev_view(v)) /* update display driver */ |
271 |
> |
if (!dev_view(v)) /* notify display driver */ |
272 |
|
goto again; |
273 |
|
dev_flush(); /* update screen */ |
274 |
< |
if (!beam_view(v)) /* update beam list */ |
275 |
< |
goto again; |
274 |
> |
beam_init(); /* compute new beam set */ |
275 |
> |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
276 |
> |
if (!beam_view(dv, res[0], res[1])) { |
277 |
> |
if (!nhist) { |
278 |
> |
error(COMMAND, "invalid starting view"); |
279 |
> |
return; |
280 |
> |
} |
281 |
> |
copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); |
282 |
> |
goto again; |
283 |
> |
} |
284 |
> |
beam_sync(0); /* update server */ |
285 |
|
/* record new view */ |
286 |
|
if (v < viewhist || v >= viewhist+VIEWHISTLEN) { |
287 |
|
copystruct(viewhist + (nhist%VIEWHISTLEN), v); |
294 |
|
usr_input() /* get user input and process it */ |
295 |
|
{ |
296 |
|
VIEW vparams; |
297 |
< |
char cmd[128]; |
297 |
> |
char cmd[256]; |
298 |
|
register char *args; |
299 |
|
register int i; |
300 |
|
|
301 |
< |
if (fgets(cmd, sizeof(cmd), sstdin) == NULL) |
302 |
< |
return(DC_QUIT); |
301 |
> |
if (fgets(cmd, sizeof(cmd), sstdin) == NULL) { |
302 |
> |
fclose(sstdin); |
303 |
> |
sstdin = NULL; |
304 |
> |
return(0); |
305 |
> |
} |
306 |
|
for (args = cmd; *args && !isspace(*args); args++) |
307 |
|
; |
308 |
|
while (isspace(*args)) |
338 |
|
/* handled in main() */ |
339 |
|
break; |
340 |
|
case DC_REDRAW: /* redraw from server */ |
341 |
< |
imm_mode = beam_sync() > 0; |
341 |
> |
imm_mode = beam_sync(1) > 0; |
342 |
> |
dev_clear(); |
343 |
|
break; |
344 |
|
case DC_KILL: /* kill rtrace process(es) */ |
345 |
|
serv_request(DR_KILL, 0, NULL); |
403 |
|
error(INTERNAL, "bad holodeck record from server"); |
404 |
|
add_holo((HDGRID *)buf); |
405 |
|
break; |
406 |
+ |
case DS_OUTSECT: |
407 |
+ |
do_outside = 1; |
408 |
+ |
break; |
409 |
|
case DS_STARTIMM: |
410 |
|
case DS_ENDIMM: |
411 |
+ |
#ifdef DEBUG |
412 |
+ |
if (imm_mode != (msg.type==DS_STARTIMM)) { |
413 |
+ |
time_t tnow = time(NULL); |
414 |
+ |
if (imm_mode) timm += tnow - tmodesw; |
415 |
+ |
else tadd += tnow - tmodesw; |
416 |
+ |
tmodesw = tnow; |
417 |
+ |
} |
418 |
+ |
#endif |
419 |
|
imm_mode = msg.type==DS_STARTIMM; |
420 |
|
/* fall through */ |
421 |
|
case DS_ACKNOW: |