18 |
|
#define VIEWHISTLEN 4 /* number of remembered views */ |
19 |
|
#endif |
20 |
|
|
21 |
+ |
#ifndef FSIZDEF |
22 |
+ |
#define FSIZDEF 0.125 /* default focus frame size */ |
23 |
+ |
#endif |
24 |
+ |
|
25 |
|
HOLO *hdlist[HDMAX+1]; /* global holodeck list */ |
26 |
|
|
27 |
+ |
char *hdgfn[HDMAX]; /* holodeck section geometry list */ |
28 |
+ |
char *hdpfn[HDMAX]; /* section portal list */ |
29 |
+ |
|
30 |
|
char cmdlist[DC_NCMDS][8] = DC_INIT; |
31 |
|
|
32 |
|
int imm_mode = 0; /* bundles are being delivered immediately */ |
91 |
|
inp = dev_input(); |
92 |
|
if (inp & DFL(DC_SETVIEW)) |
93 |
|
new_view(&odev.v); |
94 |
< |
if (inp & DFL(DC_GETVIEW)) |
88 |
< |
printview(); |
89 |
< |
if (inp & DFL(DC_LASTVIEW)) |
94 |
> |
else if (inp & DFL(DC_LASTVIEW)) |
95 |
|
new_view(NULL); |
91 |
– |
if (inp & DFL(DC_RESUME)) { |
92 |
– |
serv_request(DR_NOOP, 0, NULL); |
93 |
– |
pause = 0; |
94 |
– |
} |
95 |
– |
if (inp & DFL(DC_PAUSE)) |
96 |
– |
pause = 1; |
96 |
|
if (inp & DFL(DC_REDRAW)) |
97 |
|
imm_mode = beam_sync(1) > 0; |
98 |
+ |
if (inp & DFL(DC_GETVIEW)) |
99 |
+ |
printview(); |
100 |
+ |
if (inp & DFL(DC_FOCUS)) |
101 |
+ |
set_focus(odev_args); |
102 |
|
if (inp & DFL(DC_KILL)) { |
103 |
|
serv_request(DR_KILL, 0, NULL); |
104 |
|
pause = 0; |
109 |
|
serv_request(DR_RESTART, 0, NULL); |
110 |
|
pause = 0; |
111 |
|
} |
112 |
+ |
if (inp & DFL(DC_RESUME)) { |
113 |
+ |
serv_request(DR_NOOP, 0, NULL); |
114 |
+ |
pause = 0; |
115 |
+ |
} |
116 |
+ |
if (inp & DFL(DC_PAUSE)) |
117 |
+ |
pause = 1; |
118 |
|
if (inp & DFL(DC_QUIT)) |
119 |
|
serv_request(DR_SHUTDOWN, 0, NULL); |
120 |
|
} |
121 |
< |
if (rdy & RDY_SIN) /* user input from sstdin */ |
121 |
> |
if (rdy & RDY_SIN && !imm_mode) /* user input from sstdin */ |
122 |
|
switch (usr_input()) { |
123 |
|
case DC_PAUSE: |
124 |
|
pause = 1; |
155 |
|
int n; |
156 |
|
register int i; |
157 |
|
/* see if we can avoid select call */ |
158 |
+ |
flgs = 0; /* flag what's ready already */ |
159 |
|
if (imm_mode || stdin->_cnt > 0) |
160 |
< |
return(RDY_SRV); |
160 |
> |
flgs |= RDY_SRV; |
161 |
|
if (sstdin != NULL && sstdin->_cnt > 0) |
162 |
< |
return(RDY_SIN); |
163 |
< |
if (dev_flush()) |
162 |
> |
flgs |= RDY_SIN; |
163 |
> |
if (odev.inpready) |
164 |
> |
flgs |= RDY_DEV; |
165 |
> |
if (flgs) /* got something? */ |
166 |
> |
return(flgs); |
167 |
> |
if (dev_flush()) /* else flush output & check keyboard+mouse */ |
168 |
|
return(RDY_DEV); |
169 |
< |
/* make the call */ |
169 |
> |
/* if nothing, we need to call select */ |
170 |
|
FD_ZERO(&readset); FD_ZERO(&errset); |
171 |
|
FD_SET(0, &readset); |
172 |
|
FD_SET(0, &errset); |
185 |
|
return(0); |
186 |
|
error(SYSTEM, "select call failure in disp_wait"); |
187 |
|
} |
174 |
– |
flgs = 0; /* flag what's ready */ |
188 |
|
if (FD_ISSET(0, &readset) || FD_ISSET(0, &errset)) |
189 |
|
flgs |= RDY_SRV; |
190 |
|
if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset)) |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
< |
add_holo(hdg) /* register a new holodeck section */ |
199 |
> |
add_holo(hdg, gfn, pfn) /* register a new holodeck section */ |
200 |
|
HDGRID *hdg; |
201 |
+ |
char *gfn, *pfn; |
202 |
|
{ |
203 |
|
VIEW nv; |
204 |
|
double d; |
213 |
|
error(SYSTEM, "out of memory in add_holo"); |
214 |
|
bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID)); |
215 |
|
hdcompgrid(hdlist[hd]); |
216 |
+ |
hdgfn[hd] = savestr(gfn); |
217 |
+ |
hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL; |
218 |
|
if (hd) |
219 |
|
return; |
220 |
|
/* set initial viewpoint */ |
269 |
|
static VIEW viewhist[VIEWHISTLEN]; |
270 |
|
static unsigned nhist; |
271 |
|
VIEW *dv; |
272 |
< |
int i, res[2]; |
272 |
> |
int i, res[2], *slist; |
273 |
|
char *err; |
274 |
|
/* restore previous view? */ |
275 |
|
if (v == NULL) { |
285 |
|
error(COMMAND, err); |
286 |
|
return; |
287 |
|
} |
288 |
+ |
if (!dev_view(v)) /* notify display driver */ |
289 |
+ |
goto again; |
290 |
|
if (v->type == VT_PAR) { |
291 |
|
error(COMMAND, "cannot handle parallel views"); |
292 |
|
return; |
293 |
|
} |
294 |
< |
if (!dev_view(v)) /* notify display driver */ |
295 |
< |
goto again; |
296 |
< |
dev_flush(); /* update screen */ |
279 |
< |
beam_init(0); /* compute new beam set */ |
280 |
< |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
281 |
< |
if (!beam_view(dv, res[0], res[1])) { |
294 |
> |
beam_init(odev.firstuse); /* compute new beam set */ |
295 |
> |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) { |
296 |
> |
if ((slist = beam_view(dv, res[0], res[1])) == NULL) { |
297 |
|
if (!nhist) { |
298 |
|
error(COMMAND, "invalid starting view"); |
299 |
|
return; |
300 |
|
} |
301 |
|
copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); |
302 |
< |
goto again; |
302 |
> |
goto again; /* poss. overloading dev_section()? */ |
303 |
|
} |
304 |
< |
beam_sync(0); /* update server */ |
304 |
> |
DCHECK(*slist < 0, WARNING, "no visible sections in new_view"); |
305 |
> |
for ( ; *slist >= 0; slist++) |
306 |
> |
dev_section(hdgfn[*slist], hdpfn[*slist]); |
307 |
> |
} |
308 |
> |
dev_section(NULL,NULL); /* end section list */ |
309 |
> |
dev_flush(); /* update display */ |
310 |
> |
/* update server */ |
311 |
> |
imm_mode = beam_sync(odev.firstuse) > 0; |
312 |
|
/* record new view */ |
313 |
|
if (v < viewhist || v >= viewhist+VIEWHISTLEN) { |
314 |
|
copystruct(viewhist + (nhist%VIEWHISTLEN), v); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
+ |
set_focus(args) /* set focus frame */ |
321 |
+ |
char *args; |
322 |
+ |
{ |
323 |
+ |
double hcent, vcent, hsiz, vsiz; |
324 |
+ |
VIEW *dv, vwfocus; |
325 |
+ |
int i, res[2]; |
326 |
+ |
|
327 |
+ |
i = sscanf(args, "%lf %lf %lf %lf", &hcent, &vcent, &hsiz, &vsiz); |
328 |
+ |
if (i < 2 || hcent < 0 || hcent > 1 || vcent < 0 || vcent > 1) { |
329 |
+ |
beam_init(0); /* restore view */ |
330 |
+ |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
331 |
+ |
beam_view(dv, res[0], res[1]); |
332 |
+ |
beam_sync(0); /* update server */ |
333 |
+ |
return; |
334 |
+ |
} |
335 |
+ |
if (i < 4 || hsiz <= hcent || hsiz > 1 || vsiz <= vcent || vsiz > 1) |
336 |
+ |
hsiz = vsiz = FSIZDEF; /* gave center only */ |
337 |
+ |
else { |
338 |
+ |
hsiz -= hcent; hcent += 0.5*hsiz; /* gave min and max */ |
339 |
+ |
vsiz -= vcent; vcent += 0.5*vsiz; |
340 |
+ |
} |
341 |
+ |
beam_init(0); /* add basic views */ |
342 |
+ |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
343 |
+ |
beam_view(dv, res[0]>>4, res[1]>>4); |
344 |
+ |
copystruct(&vwfocus, &odev.v); /* add focus view */ |
345 |
+ |
switch (odev.v.type) { |
346 |
+ |
case VT_PER: |
347 |
+ |
vwfocus.horiz = 2.*180./PI*atan( |
348 |
+ |
hsiz * tan(PI/180./2.*odev.v.horiz) ); |
349 |
+ |
vwfocus.vert = 2.*180./PI*atan( |
350 |
+ |
vsiz * tan(PI/180./2.*odev.v.vert) ); |
351 |
+ |
break; |
352 |
+ |
case VT_PAR: |
353 |
+ |
case VT_ANG: |
354 |
+ |
vwfocus.horiz = hsiz * odev.v.horiz; |
355 |
+ |
vwfocus.vert = vsiz * odev.v.vert; |
356 |
+ |
break; |
357 |
+ |
case VT_HEM: |
358 |
+ |
vwfocus.horiz = 2.*180./PI*asin( |
359 |
+ |
hsiz * sin(PI/180./2.*odev.v.horiz) ); |
360 |
+ |
vwfocus.vert = 2.*180./PI*asin( |
361 |
+ |
vsiz * sin(PI/180./2.*odev.v.vert) ); |
362 |
+ |
break; |
363 |
+ |
case VT_CYL: |
364 |
+ |
vwfocus.horiz = hsiz * odev.v.horiz; |
365 |
+ |
vwfocus.vert = 2.*180./PI*atan( |
366 |
+ |
vsiz * tan(PI/180./2.*odev.v.vert) ); |
367 |
+ |
break; |
368 |
+ |
default: |
369 |
+ |
error(INTERNAL, "bad view type in set_focus"); |
370 |
+ |
} |
371 |
+ |
vwfocus.hoff = (odev.v.hoff + hcent - 0.5)/hsiz; |
372 |
+ |
vwfocus.voff = (odev.v.voff + vcent - 0.5)/vsiz; |
373 |
+ |
setview(&vwfocus); |
374 |
+ |
beam_view(&vwfocus, (int)(3*odev.hres*hsiz)+100, |
375 |
+ |
(int)(3*odev.vres*vsiz)+100); |
376 |
+ |
beam_sync(0); /* update server */ |
377 |
+ |
} |
378 |
+ |
|
379 |
+ |
|
380 |
|
int |
381 |
|
usr_input() /* get user input and process it */ |
382 |
|
{ |
390 |
|
sstdin = NULL; |
391 |
|
return(-1); |
392 |
|
} |
393 |
< |
if (!*cmd) |
393 |
> |
if (*cmd == '\n') |
394 |
|
return(DC_RESUME); |
395 |
|
for (args = cmd; *args && !isspace(*args); args++) |
396 |
|
; |
419 |
|
case DC_LASTVIEW: /* restore previous view */ |
420 |
|
new_view(NULL); |
421 |
|
break; |
422 |
+ |
case DC_FOCUS: /* set focus frame */ |
423 |
+ |
set_focus(args); |
424 |
+ |
break; |
425 |
|
case DC_PAUSE: /* pause the current calculation */ |
426 |
|
case DC_RESUME: /* resume the calculation */ |
427 |
|
/* handled in main() */ |
488 |
|
disp_bundle((PACKHEAD *)buf); |
489 |
|
break; |
490 |
|
case DS_ADDHOLO: |
491 |
< |
if (msg.nbytes != sizeof(HDGRID)) |
491 |
> |
if (msg.nbytes < sizeof(HDGRID)+2) |
492 |
|
error(INTERNAL, "bad holodeck record from server"); |
493 |
< |
add_holo((HDGRID *)buf); |
493 |
> |
add_holo((HDGRID *)buf, buf+sizeof(HDGRID), |
494 |
> |
buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1); |
495 |
|
break; |
496 |
|
case DS_OUTSECT: |
497 |
|
do_outside = 1; |
503 |
|
case DS_STARTIMM: |
504 |
|
case DS_ENDIMM: |
505 |
|
#ifdef DEBUG |
506 |
< |
if (imm_mode != (msg.type==DS_STARTIMM)) { |
506 |
> |
{ |
507 |
|
time_t tnow = time(NULL); |
508 |
< |
if (imm_mode) timm += tnow - tmodesw; |
509 |
< |
else tadd += tnow - tmodesw; |
508 |
> |
if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw; |
509 |
> |
else timm += tnow - tmodesw; |
510 |
|
tmodesw = tnow; |
511 |
|
} |
512 |
|
#endif |
513 |
< |
imm_mode = msg.type==DS_STARTIMM; |
513 |
> |
if (!(imm_mode = msg.type==DS_STARTIMM)) |
514 |
> |
dev_flush(); |
515 |
|
goto noargs; |
516 |
|
case DS_ACKNOW: |
517 |
|
case DS_SHUTDOWN: |
540 |
|
{ |
541 |
|
MSGHEAD msg; |
542 |
|
int m; |
543 |
+ |
/* consistency checks */ |
544 |
+ |
DCHECK(nbytes < 0 || nbytes > 0 & p == NULL, |
545 |
+ |
CONSISTENCY, "bad buffer handed to serv_request"); |
546 |
|
/* get server's attention for big request */ |
547 |
|
if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) { |
548 |
|
serv_request(DR_ATTEN, 0, NULL); |
582 |
|
quit(code) /* clean up and exit */ |
583 |
|
int code; |
584 |
|
{ |
585 |
+ |
if (code) |
586 |
+ |
exit(code); |
587 |
|
if (odev.v.type) |
588 |
|
dev_close(); |
589 |
< |
exit(code); |
589 |
> |
exit(0); |
590 |
|
} |