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 *hdofn[HDMAX+1]; /* holodeck section octree list */ |
28 |
+ |
|
29 |
|
char cmdlist[DC_NCMDS][8] = DC_INIT; |
30 |
|
|
31 |
|
int imm_mode = 0; /* bundles are being delivered immediately */ |
90 |
|
inp = dev_input(); |
91 |
|
if (inp & DFL(DC_SETVIEW)) |
92 |
|
new_view(&odev.v); |
93 |
+ |
else if (inp & DFL(DC_LASTVIEW)) |
94 |
+ |
new_view(NULL); |
95 |
+ |
if (inp & DFL(DC_REDRAW)) |
96 |
+ |
imm_mode = beam_sync(1) > 0; |
97 |
|
if (inp & DFL(DC_GETVIEW)) |
98 |
|
printview(); |
99 |
< |
if (inp & DFL(DC_LASTVIEW)) |
100 |
< |
new_view(NULL); |
99 |
> |
if (inp & DFL(DC_FOCUS)) |
100 |
> |
set_focus(odev_args); |
101 |
|
if (inp & DFL(DC_KILL)) { |
102 |
|
serv_request(DR_KILL, 0, NULL); |
103 |
|
pause = 0; |
114 |
|
} |
115 |
|
if (inp & DFL(DC_PAUSE)) |
116 |
|
pause = 1; |
107 |
– |
if (inp & DFL(DC_REDRAW)) |
108 |
– |
imm_mode = beam_sync(1) > 0; |
117 |
|
if (inp & DFL(DC_QUIT)) |
118 |
|
serv_request(DR_SHUTDOWN, 0, NULL); |
119 |
|
} |
120 |
< |
if (rdy & RDY_SIN) /* user input from sstdin */ |
120 |
> |
if (rdy & RDY_SIN && !imm_mode) /* user input from sstdin */ |
121 |
|
switch (usr_input()) { |
122 |
|
case DC_PAUSE: |
123 |
|
pause = 1; |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
< |
add_holo(hdg) /* register a new holodeck section */ |
198 |
> |
add_holo(hdg, ofn) /* register a new holodeck section */ |
199 |
|
HDGRID *hdg; |
200 |
+ |
char *ofn; |
201 |
|
{ |
202 |
|
VIEW nv; |
203 |
|
double d; |
212 |
|
error(SYSTEM, "out of memory in add_holo"); |
213 |
|
bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID)); |
214 |
|
hdcompgrid(hdlist[hd]); |
215 |
+ |
hdofn[hd] = savestr(ofn); |
216 |
|
if (hd) |
217 |
|
return; |
218 |
|
/* set initial viewpoint */ |
267 |
|
static VIEW viewhist[VIEWHISTLEN]; |
268 |
|
static unsigned nhist; |
269 |
|
VIEW *dv; |
270 |
< |
int i, res[2]; |
270 |
> |
int i, res[2], *slist; |
271 |
|
char *err; |
272 |
|
/* restore previous view? */ |
273 |
|
if (v == NULL) { |
283 |
|
error(COMMAND, err); |
284 |
|
return; |
285 |
|
} |
286 |
+ |
if (!dev_view(v)) /* notify display driver */ |
287 |
+ |
goto again; |
288 |
|
if (v->type == VT_PAR) { |
289 |
|
error(COMMAND, "cannot handle parallel views"); |
290 |
|
return; |
291 |
|
} |
292 |
< |
if (!dev_view(v)) /* notify display driver */ |
293 |
< |
goto again; |
294 |
< |
dev_flush(); /* update screen */ |
283 |
< |
beam_init(0); /* compute new beam set */ |
284 |
< |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
285 |
< |
if (!beam_view(dv, res[0], res[1])) { |
292 |
> |
beam_init(odev.firstuse); /* compute new beam set */ |
293 |
> |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) { |
294 |
> |
if ((slist = beam_view(dv, res[0], res[1])) == NULL) { |
295 |
|
if (!nhist) { |
296 |
|
error(COMMAND, "invalid starting view"); |
297 |
|
return; |
298 |
|
} |
299 |
|
copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); |
300 |
< |
goto again; |
300 |
> |
goto again; /* poss. overloading dev_section()? */ |
301 |
|
} |
302 |
< |
beam_sync(0); /* update server */ |
302 |
> |
DCHECK(*slist < 0, WARNING, "no visible sections in new_view"); |
303 |
> |
while (*slist >= 0) |
304 |
> |
dev_section(hdofn[*slist++]); |
305 |
> |
} |
306 |
> |
dev_section(NULL); /* end section list */ |
307 |
> |
dev_flush(); /* update display */ |
308 |
> |
/* update server */ |
309 |
> |
imm_mode = beam_sync(odev.firstuse) > 0; |
310 |
|
/* record new view */ |
311 |
|
if (v < viewhist || v >= viewhist+VIEWHISTLEN) { |
312 |
|
copystruct(viewhist + (nhist%VIEWHISTLEN), v); |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
+ |
set_focus(args) /* set focus frame */ |
319 |
+ |
char *args; |
320 |
+ |
{ |
321 |
+ |
double hcent, vcent, hsiz, vsiz; |
322 |
+ |
VIEW *dv, vwfocus; |
323 |
+ |
int i, res[2]; |
324 |
+ |
|
325 |
+ |
i = sscanf(args, "%lf %lf %lf %lf", &hcent, &vcent, &hsiz, &vsiz); |
326 |
+ |
if (i < 2 || hcent < 0 || hcent > 1 || vcent < 0 || vcent > 1) { |
327 |
+ |
beam_init(0); /* restore view */ |
328 |
+ |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
329 |
+ |
beam_view(dv, res[0], res[1]); |
330 |
+ |
beam_sync(0); /* update server */ |
331 |
+ |
return; |
332 |
+ |
} |
333 |
+ |
if (i < 4 || hsiz <= hcent || hsiz > 1 || vsiz <= vcent || vsiz > 1) |
334 |
+ |
hsiz = vsiz = FSIZDEF; /* gave center only */ |
335 |
+ |
else { |
336 |
+ |
hsiz -= hcent; hcent += 0.5*hsiz; /* gave min and max */ |
337 |
+ |
vsiz -= vcent; vcent += 0.5*vsiz; |
338 |
+ |
} |
339 |
+ |
beam_init(0); /* add basic views */ |
340 |
+ |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
341 |
+ |
beam_view(dv, res[0]>>4, res[1]>>4); |
342 |
+ |
copystruct(&vwfocus, &odev.v); /* add focus view */ |
343 |
+ |
switch (odev.v.type) { |
344 |
+ |
case VT_PER: |
345 |
+ |
vwfocus.horiz = 2.*180./PI*atan( |
346 |
+ |
hsiz * tan(PI/180./2.*odev.v.horiz) ); |
347 |
+ |
vwfocus.vert = 2.*180./PI*atan( |
348 |
+ |
vsiz * tan(PI/180./2.*odev.v.vert) ); |
349 |
+ |
break; |
350 |
+ |
case VT_PAR: |
351 |
+ |
case VT_ANG: |
352 |
+ |
vwfocus.horiz = hsiz * odev.v.horiz; |
353 |
+ |
vwfocus.vert = vsiz * odev.v.vert; |
354 |
+ |
break; |
355 |
+ |
case VT_HEM: |
356 |
+ |
vwfocus.horiz = 2.*180./PI*asin( |
357 |
+ |
hsiz * sin(PI/180./2.*odev.v.horiz) ); |
358 |
+ |
vwfocus.vert = 2.*180./PI*asin( |
359 |
+ |
vsiz * sin(PI/180./2.*odev.v.vert) ); |
360 |
+ |
break; |
361 |
+ |
case VT_CYL: |
362 |
+ |
vwfocus.horiz = hsiz * odev.v.horiz; |
363 |
+ |
vwfocus.vert = 2.*180./PI*atan( |
364 |
+ |
vsiz * tan(PI/180./2.*odev.v.vert) ); |
365 |
+ |
break; |
366 |
+ |
default: |
367 |
+ |
error(INTERNAL, "bad view type in set_focus"); |
368 |
+ |
} |
369 |
+ |
vwfocus.hoff = (odev.v.hoff + hcent - 0.5)/hsiz; |
370 |
+ |
vwfocus.voff = (odev.v.voff + vcent - 0.5)/vsiz; |
371 |
+ |
setview(&vwfocus); |
372 |
+ |
beam_view(&vwfocus, (int)(3*odev.hres*hsiz)+100, |
373 |
+ |
(int)(3*odev.vres*vsiz)+100); |
374 |
+ |
beam_sync(0); /* update server */ |
375 |
+ |
} |
376 |
+ |
|
377 |
+ |
|
378 |
|
int |
379 |
|
usr_input() /* get user input and process it */ |
380 |
|
{ |
417 |
|
case DC_LASTVIEW: /* restore previous view */ |
418 |
|
new_view(NULL); |
419 |
|
break; |
420 |
+ |
case DC_FOCUS: /* set focus frame */ |
421 |
+ |
set_focus(args); |
422 |
+ |
break; |
423 |
|
case DC_PAUSE: /* pause the current calculation */ |
424 |
|
case DC_RESUME: /* resume the calculation */ |
425 |
|
/* handled in main() */ |
486 |
|
disp_bundle((PACKHEAD *)buf); |
487 |
|
break; |
488 |
|
case DS_ADDHOLO: |
489 |
< |
if (msg.nbytes != sizeof(HDGRID)) |
489 |
> |
if (msg.nbytes <= sizeof(HDGRID)) |
490 |
|
error(INTERNAL, "bad holodeck record from server"); |
491 |
< |
add_holo((HDGRID *)buf); |
491 |
> |
add_holo((HDGRID *)buf, buf+sizeof(HDGRID)); |
492 |
|
break; |
493 |
|
case DS_OUTSECT: |
494 |
|
do_outside = 1; |
500 |
|
case DS_STARTIMM: |
501 |
|
case DS_ENDIMM: |
502 |
|
#ifdef DEBUG |
503 |
< |
if (imm_mode != (msg.type==DS_STARTIMM)) { |
503 |
> |
{ |
504 |
|
time_t tnow = time(NULL); |
505 |
< |
if (imm_mode) timm += tnow - tmodesw; |
506 |
< |
else tadd += tnow - tmodesw; |
505 |
> |
if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw; |
506 |
> |
else timm += tnow - tmodesw; |
507 |
|
tmodesw = tnow; |
508 |
|
} |
509 |
|
#endif |
510 |
< |
imm_mode = msg.type==DS_STARTIMM; |
510 |
> |
if (!(imm_mode = msg.type==DS_STARTIMM)) |
511 |
> |
dev_flush(); |
512 |
|
goto noargs; |
513 |
|
case DS_ACKNOW: |
514 |
|
case DS_SHUTDOWN: |
538 |
|
MSGHEAD msg; |
539 |
|
int m; |
540 |
|
/* consistency checks */ |
541 |
< |
#ifdef DEBUG |
542 |
< |
if (nbytes < 0 || nbytes > 0 & p == NULL) |
463 |
< |
error(CONSISTENCY, "bad buffer handed to serv_request"); |
464 |
< |
#endif |
541 |
> |
DCHECK(nbytes < 0 || nbytes > 0 & p == NULL, |
542 |
> |
CONSISTENCY, "bad buffer handed to serv_request"); |
543 |
|
/* get server's attention for big request */ |
544 |
|
if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) { |
545 |
|
serv_request(DR_ATTEN, 0, NULL); |