1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Holodeck display process. |
6 |
|
*/ |
19 |
|
#define FSIZDEF 0.125 /* default focus frame size */ |
20 |
|
#endif |
21 |
|
|
22 |
+ |
#if defined(freebsd) |
23 |
+ |
#define fbufcnt(f) ((f)->_r) |
24 |
+ |
#elif defined(__GNUC__) |
25 |
+ |
#define fbufcnt(f) ((f)->_IO_read_end - (f)->_IO_read_ptr) |
26 |
+ |
#else |
27 |
+ |
#define fbufcnt(f) ((f)->_cnt) |
28 |
+ |
#endif |
29 |
+ |
|
30 |
|
HOLO *hdlist[HDMAX+1]; /* global holodeck list */ |
31 |
|
|
32 |
+ |
char *hdgfn[HDMAX]; /* holodeck section geometry list */ |
33 |
+ |
char *hdpfn[HDMAX]; /* section portal list */ |
34 |
+ |
|
35 |
|
char cmdlist[DC_NCMDS][8] = DC_INIT; |
36 |
|
|
37 |
|
int imm_mode = 0; /* bundles are being delivered immediately */ |
45 |
|
FILE *sstdin, *sstdout; /* server's standard input and output */ |
46 |
|
|
47 |
|
#ifdef DEBUG |
40 |
– |
#include <sys/types.h> |
48 |
|
extern time_t time(); |
49 |
|
static time_t tmodesw; |
50 |
|
static time_t timm, tadd; |
60 |
|
int argc; |
61 |
|
char *argv[]; |
62 |
|
{ |
56 |
– |
extern int eputs(); |
63 |
|
int rdy, inp, res = 0, pause = 0; |
64 |
|
|
65 |
|
progname = argv[0]; |
94 |
|
inp = dev_input(); |
95 |
|
if (inp & DFL(DC_SETVIEW)) |
96 |
|
new_view(&odev.v); |
97 |
+ |
else if (inp & DFL(DC_LASTVIEW)) |
98 |
+ |
new_view(NULL); |
99 |
+ |
if (inp & DFL(DC_REDRAW)) |
100 |
+ |
imm_mode = beam_sync(1) > 0; |
101 |
|
if (inp & DFL(DC_GETVIEW)) |
102 |
|
printview(); |
93 |
– |
if (inp & DFL(DC_LASTVIEW)) |
94 |
– |
new_view(NULL); |
103 |
|
if (inp & DFL(DC_FOCUS)) |
104 |
|
set_focus(odev_args); |
105 |
|
if (inp & DFL(DC_KILL)) { |
118 |
|
} |
119 |
|
if (inp & DFL(DC_PAUSE)) |
120 |
|
pause = 1; |
113 |
– |
if (inp & DFL(DC_REDRAW)) |
114 |
– |
imm_mode = beam_sync(1) > 0; |
121 |
|
if (inp & DFL(DC_QUIT)) |
122 |
|
serv_request(DR_SHUTDOWN, 0, NULL); |
123 |
|
} |
158 |
|
int n; |
159 |
|
register int i; |
160 |
|
/* see if we can avoid select call */ |
161 |
+ |
if (hdlist[0] == NULL) |
162 |
+ |
return(RDY_SRV); /* initialize first */ |
163 |
|
flgs = 0; /* flag what's ready already */ |
164 |
< |
if (imm_mode || stdin->_cnt > 0) |
164 |
> |
if (imm_mode || fbufcnt(stdin) > 0) |
165 |
|
flgs |= RDY_SRV; |
166 |
< |
if (sstdin != NULL && sstdin->_cnt > 0) |
166 |
> |
if (sstdin != NULL && fbufcnt(sstdin) > 0) |
167 |
|
flgs |= RDY_SIN; |
168 |
|
if (odev.inpready) |
169 |
|
flgs |= RDY_DEV; |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
< |
add_holo(hdg) /* register a new holodeck section */ |
204 |
> |
add_holo(hdg, gfn, pfn) /* register a new holodeck section */ |
205 |
|
HDGRID *hdg; |
206 |
+ |
char *gfn, *pfn; |
207 |
|
{ |
208 |
|
VIEW nv; |
209 |
|
double d; |
218 |
|
error(SYSTEM, "out of memory in add_holo"); |
219 |
|
bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID)); |
220 |
|
hdcompgrid(hdlist[hd]); |
221 |
+ |
hdgfn[hd] = savestr(gfn); |
222 |
+ |
hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL; |
223 |
|
if (hd) |
224 |
|
return; |
225 |
|
/* set initial viewpoint */ |
275 |
|
static unsigned nhist; |
276 |
|
VIEW *dv; |
277 |
|
int i, res[2]; |
278 |
+ |
int2 *slist; |
279 |
|
char *err; |
280 |
|
/* restore previous view? */ |
281 |
|
if (v == NULL) { |
291 |
|
error(COMMAND, err); |
292 |
|
return; |
293 |
|
} |
294 |
+ |
if (!dev_view(v)) /* notify display driver */ |
295 |
+ |
goto again; |
296 |
|
if (v->type == VT_PAR) { |
297 |
|
error(COMMAND, "cannot handle parallel views"); |
298 |
|
return; |
299 |
|
} |
300 |
< |
if (!dev_view(v)) /* notify display driver */ |
301 |
< |
goto again; |
302 |
< |
dev_flush(); /* update screen */ |
289 |
< |
beam_init(0); /* compute new beam set */ |
290 |
< |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
291 |
< |
if (!beam_view(dv, res[0], res[1])) { |
300 |
> |
beam_init(odev.firstuse); /* compute new beam set */ |
301 |
> |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) { |
302 |
> |
if ((slist = beam_view(dv, res[0], res[1])) == NULL) { |
303 |
|
if (!nhist) { |
304 |
|
error(COMMAND, "invalid starting view"); |
305 |
|
return; |
306 |
|
} |
307 |
|
copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); |
308 |
< |
goto again; |
309 |
< |
} |
308 |
> |
goto again; /* poss. overloading dev_section()? */ |
309 |
> |
} |
310 |
> |
DCHECK(*slist < 0, WARNING, "no visible sections in new_view"); |
311 |
> |
for ( ; *slist >= 0; slist++) |
312 |
> |
dev_section(hdgfn[*slist], hdpfn[*slist]); |
313 |
> |
} |
314 |
> |
dev_section(NULL,NULL); /* end section list */ |
315 |
> |
dev_flush(); /* update display */ |
316 |
|
/* update server */ |
317 |
< |
imm_mode = beam_sync(0) > 0; |
317 |
> |
imm_mode = beam_sync(odev.firstuse) > 0; |
318 |
|
/* record new view */ |
319 |
|
if (v < viewhist || v >= viewhist+VIEWHISTLEN) { |
320 |
|
copystruct(viewhist + (nhist%VIEWHISTLEN), v); |
494 |
|
disp_bundle((PACKHEAD *)buf); |
495 |
|
break; |
496 |
|
case DS_ADDHOLO: |
497 |
< |
if (msg.nbytes != sizeof(HDGRID)) |
497 |
> |
if (msg.nbytes < sizeof(HDGRID)+2) |
498 |
|
error(INTERNAL, "bad holodeck record from server"); |
499 |
< |
add_holo((HDGRID *)buf); |
499 |
> |
add_holo((HDGRID *)buf, buf+sizeof(HDGRID), |
500 |
> |
buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1); |
501 |
|
break; |
502 |
|
case DS_OUTSECT: |
503 |
|
do_outside = 1; |
508 |
|
break; |
509 |
|
case DS_STARTIMM: |
510 |
|
case DS_ENDIMM: |
511 |
+ |
if (!(imm_mode = msg.type==DS_STARTIMM)) |
512 |
+ |
dev_flush(); |
513 |
|
#ifdef DEBUG |
514 |
|
{ |
515 |
|
time_t tnow = time(NULL); |
518 |
|
tmodesw = tnow; |
519 |
|
} |
520 |
|
#endif |
501 |
– |
if (!(imm_mode = msg.type==DS_STARTIMM)) |
502 |
– |
dev_flush(); |
521 |
|
goto noargs; |
522 |
|
case DS_ACKNOW: |
523 |
|
case DS_SHUTDOWN: |
547 |
|
MSGHEAD msg; |
548 |
|
int m; |
549 |
|
/* consistency checks */ |
550 |
< |
#ifdef DEBUG |
551 |
< |
if (nbytes < 0 || nbytes > 0 & p == NULL) |
534 |
< |
error(CONSISTENCY, "bad buffer handed to serv_request"); |
535 |
< |
#endif |
550 |
> |
DCHECK(nbytes < 0 || nbytes > 0 & p == NULL, |
551 |
> |
CONSISTENCY, "bad buffer handed to serv_request"); |
552 |
|
/* get server's attention for big request */ |
553 |
|
if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) { |
554 |
|
serv_request(DR_ATTEN, 0, NULL); |
566 |
|
} |
567 |
|
|
568 |
|
|
569 |
+ |
void |
570 |
|
eputs(s) /* put error message to stderr */ |
571 |
|
register char *s; |
572 |
|
{ |
586 |
|
} |
587 |
|
|
588 |
|
|
589 |
+ |
void |
590 |
|
quit(code) /* clean up and exit */ |
591 |
|
int code; |
592 |
|
{ |
593 |
+ |
if (code) |
594 |
+ |
exit(code); |
595 |
|
if (odev.v.type) |
596 |
|
dev_close(); |
597 |
< |
exit(code); |
597 |
> |
exit(0); |
598 |
|
} |