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 |
|
*/ |
7 |
|
|
8 |
+ |
#include <string.h> |
9 |
+ |
#include <ctype.h> |
10 |
+ |
|
11 |
|
#include "rholo.h" |
12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
#include "selcall.h" |
15 |
– |
#include <ctype.h> |
15 |
|
|
16 |
|
#ifndef VIEWHISTLEN |
17 |
|
#define VIEWHISTLEN 4 /* number of remembered views */ |
21 |
|
#define FSIZDEF 0.125 /* default focus frame size */ |
22 |
|
#endif |
23 |
|
|
24 |
+ |
#if defined(freebsd) |
25 |
+ |
#define fbufcnt(f) ((f)->_r) |
26 |
+ |
#elif defined(__GNUC__) |
27 |
+ |
#define fbufcnt(f) ((f)->_IO_read_end - (f)->_IO_read_ptr) |
28 |
+ |
#else |
29 |
+ |
#define fbufcnt(f) ((f)->_cnt) |
30 |
+ |
#endif |
31 |
+ |
|
32 |
|
HOLO *hdlist[HDMAX+1]; /* global holodeck list */ |
33 |
|
|
34 |
< |
char *hdofn[HDMAX+1]; /* holodeck section octree list */ |
34 |
> |
char *hdgfn[HDMAX]; /* holodeck section geometry list */ |
35 |
> |
char *hdpfn[HDMAX]; /* section portal list */ |
36 |
|
|
37 |
|
char cmdlist[DC_NCMDS][8] = DC_INIT; |
38 |
|
|
47 |
|
FILE *sstdin, *sstdout; /* server's standard input and output */ |
48 |
|
|
49 |
|
#ifdef DEBUG |
42 |
– |
#include <sys/types.h> |
50 |
|
extern time_t time(); |
51 |
|
static time_t tmodesw; |
52 |
|
static time_t timm, tadd; |
62 |
|
int argc; |
63 |
|
char *argv[]; |
64 |
|
{ |
58 |
– |
extern int eputs(); |
65 |
|
int rdy, inp, res = 0, pause = 0; |
66 |
|
|
67 |
|
progname = argv[0]; |
160 |
|
int n; |
161 |
|
register int i; |
162 |
|
/* see if we can avoid select call */ |
163 |
+ |
if (hdlist[0] == NULL) |
164 |
+ |
return(RDY_SRV); /* initialize first */ |
165 |
|
flgs = 0; /* flag what's ready already */ |
166 |
< |
if (imm_mode || stdin->_cnt > 0) |
166 |
> |
if (imm_mode || fbufcnt(stdin) > 0) |
167 |
|
flgs |= RDY_SRV; |
168 |
< |
if (sstdin != NULL && sstdin->_cnt > 0) |
168 |
> |
if (sstdin != NULL && fbufcnt(sstdin) > 0) |
169 |
|
flgs |= RDY_SIN; |
170 |
|
if (odev.inpready) |
171 |
|
flgs |= RDY_DEV; |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
< |
add_holo(hdg, ofn) /* register a new holodeck section */ |
206 |
> |
add_holo(hdg, gfn, pfn) /* register a new holodeck section */ |
207 |
|
HDGRID *hdg; |
208 |
< |
char *ofn; |
208 |
> |
char *gfn, *pfn; |
209 |
|
{ |
210 |
|
VIEW nv; |
211 |
|
double d; |
218 |
|
hdlist[hd] = (HOLO *)malloc(sizeof(HOLO)); |
219 |
|
if (hdlist[hd] == NULL) |
220 |
|
error(SYSTEM, "out of memory in add_holo"); |
221 |
< |
bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID)); |
221 |
> |
memcpy((void *)hdlist[hd], (void *)hdg, sizeof(HDGRID)); |
222 |
|
hdcompgrid(hdlist[hd]); |
223 |
< |
hdofn[hd] = savestr(ofn); |
223 |
> |
hdgfn[hd] = savestr(gfn); |
224 |
> |
hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL; |
225 |
|
if (hd) |
226 |
|
return; |
227 |
|
/* set initial viewpoint */ |
276 |
|
static VIEW viewhist[VIEWHISTLEN]; |
277 |
|
static unsigned nhist; |
278 |
|
VIEW *dv; |
279 |
< |
int i, res[2], *slist; |
279 |
> |
int i, res[2]; |
280 |
> |
int16 *slist; |
281 |
|
char *err; |
282 |
|
/* restore previous view? */ |
283 |
|
if (v == NULL) { |
310 |
|
goto again; /* poss. overloading dev_section()? */ |
311 |
|
} |
312 |
|
DCHECK(*slist < 0, WARNING, "no visible sections in new_view"); |
313 |
< |
while (*slist >= 0) |
314 |
< |
dev_section(hdofn[*slist++]); |
313 |
> |
for ( ; *slist >= 0; slist++) |
314 |
> |
dev_section(hdgfn[*slist], hdpfn[*slist]); |
315 |
|
} |
316 |
< |
dev_section(NULL); /* end section list */ |
316 |
> |
dev_section(NULL,NULL); /* end section list */ |
317 |
|
dev_flush(); /* update display */ |
318 |
|
/* update server */ |
319 |
|
imm_mode = beam_sync(odev.firstuse) > 0; |
481 |
|
if (buf == NULL) |
482 |
|
buf = (char *)malloc(bufsiz=msg.nbytes); |
483 |
|
else |
484 |
< |
buf = (char *)realloc(buf, bufsiz=msg.nbytes); |
484 |
> |
buf = (char *)realloc((void *)buf, |
485 |
> |
bufsiz=msg.nbytes); |
486 |
|
if (buf == NULL) |
487 |
|
error(SYSTEM, "out of memory in serv_result"); |
488 |
|
} |
497 |
|
disp_bundle((PACKHEAD *)buf); |
498 |
|
break; |
499 |
|
case DS_ADDHOLO: |
500 |
< |
if (msg.nbytes <= sizeof(HDGRID)) |
500 |
> |
if (msg.nbytes < sizeof(HDGRID)+2) |
501 |
|
error(INTERNAL, "bad holodeck record from server"); |
502 |
< |
add_holo((HDGRID *)buf, buf+sizeof(HDGRID)); |
502 |
> |
add_holo((HDGRID *)buf, buf+sizeof(HDGRID), |
503 |
> |
buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1); |
504 |
|
break; |
505 |
|
case DS_OUTSECT: |
506 |
|
do_outside = 1; |
511 |
|
break; |
512 |
|
case DS_STARTIMM: |
513 |
|
case DS_ENDIMM: |
514 |
+ |
if (!(imm_mode = msg.type==DS_STARTIMM)) |
515 |
+ |
dev_flush(); |
516 |
|
#ifdef DEBUG |
517 |
|
{ |
518 |
|
time_t tnow = time(NULL); |
521 |
|
tmodesw = tnow; |
522 |
|
} |
523 |
|
#endif |
510 |
– |
if (!(imm_mode = msg.type==DS_STARTIMM)) |
511 |
– |
dev_flush(); |
524 |
|
goto noargs; |
525 |
|
case DS_ACKNOW: |
526 |
|
case DS_SHUTDOWN: |
569 |
|
} |
570 |
|
|
571 |
|
|
572 |
+ |
void |
573 |
|
eputs(s) /* put error message to stderr */ |
574 |
|
register char *s; |
575 |
|
{ |
589 |
|
} |
590 |
|
|
591 |
|
|
592 |
+ |
void |
593 |
|
quit(code) /* clean up and exit */ |
594 |
|
int code; |
595 |
|
{ |
596 |
+ |
if (code) |
597 |
+ |
exit(code); |
598 |
|
if (odev.v.type) |
599 |
|
dev_close(); |
600 |
< |
exit(code); |
600 |
> |
exit(0); |
601 |
|
} |