--- ray/src/hd/rhdisp.c 1998/12/18 11:56:10 3.37 +++ ray/src/hd/rhdisp.c 2003/07/21 22:30:18 3.48 @@ -1,18 +1,17 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhdisp.c,v 3.48 2003/07/21 22:30:18 schorsch Exp $"; #endif - /* * Holodeck display process. */ +#include +#include + #include "rholo.h" #include "rhdisp.h" #include "rhdriver.h" #include "selcall.h" -#include #ifndef VIEWHISTLEN #define VIEWHISTLEN 4 /* number of remembered views */ @@ -22,9 +21,18 @@ static char SCCSid[] = "$SunId$ SGI"; #define FSIZDEF 0.125 /* default focus frame size */ #endif +#if defined(freebsd) +#define fbufcnt(f) ((f)->_r) +#elif defined(__GNUC__) +#define fbufcnt(f) ((f)->_IO_read_end - (f)->_IO_read_ptr) +#else +#define fbufcnt(f) ((f)->_cnt) +#endif + HOLO *hdlist[HDMAX+1]; /* global holodeck list */ -char *hdofn[HDMAX+1]; /* holodeck section octree list */ +char *hdgfn[HDMAX]; /* holodeck section geometry list */ +char *hdpfn[HDMAX]; /* section portal list */ char cmdlist[DC_NCMDS][8] = DC_INIT; @@ -39,7 +47,6 @@ char *progname; /* global argv[0] */ FILE *sstdin, *sstdout; /* server's standard input and output */ #ifdef DEBUG -#include extern time_t time(); static time_t tmodesw; static time_t timm, tadd; @@ -55,7 +62,6 @@ main(argc, argv) int argc; char *argv[]; { - extern int eputs(); int rdy, inp, res = 0, pause = 0; progname = argv[0]; @@ -154,10 +160,12 @@ disp_wait() /* wait for more input */ int n; register int i; /* see if we can avoid select call */ + if (hdlist[0] == NULL) + return(RDY_SRV); /* initialize first */ flgs = 0; /* flag what's ready already */ - if (imm_mode || stdin->_cnt > 0) + if (imm_mode || fbufcnt(stdin) > 0) flgs |= RDY_SRV; - if (sstdin != NULL && sstdin->_cnt > 0) + if (sstdin != NULL && fbufcnt(sstdin) > 0) flgs |= RDY_SIN; if (odev.inpready) flgs |= RDY_DEV; @@ -195,9 +203,9 @@ disp_wait() /* wait for more input */ } -add_holo(hdg, ofn) /* register a new holodeck section */ +add_holo(hdg, gfn, pfn) /* register a new holodeck section */ HDGRID *hdg; -char *ofn; +char *gfn, *pfn; { VIEW nv; double d; @@ -210,13 +218,14 @@ char *ofn; hdlist[hd] = (HOLO *)malloc(sizeof(HOLO)); if (hdlist[hd] == NULL) error(SYSTEM, "out of memory in add_holo"); - bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID)); + memcpy((void *)hdlist[hd], (void *)hdg, sizeof(HDGRID)); hdcompgrid(hdlist[hd]); - hdofn[hd] = savestr(ofn); + hdgfn[hd] = savestr(gfn); + hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL; if (hd) return; /* set initial viewpoint */ - copystruct(&nv, &odev.v); + nv = odev.v; VSUM(nv.vp, hdlist[0]->orig, hdlist[0]->xv[0], 0.5); VSUM(nv.vp, nv.vp, hdlist[0]->xv[1], 0.5); VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5); @@ -267,7 +276,8 @@ register VIEW *v; static VIEW viewhist[VIEWHISTLEN]; static unsigned nhist; VIEW *dv; - int i, res[2], *slist; + int i, res[2]; + int16 *slist; char *err; /* restore previous view? */ if (v == NULL) { @@ -296,20 +306,20 @@ again: error(COMMAND, "invalid starting view"); return; } - copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); + *v = *(viewhist + ((nhist-1)%VIEWHISTLEN)); goto again; /* poss. overloading dev_section()? */ } DCHECK(*slist < 0, WARNING, "no visible sections in new_view"); - while (*slist >= 0) - dev_section(hdofn[*slist++]); + for ( ; *slist >= 0; slist++) + dev_section(hdgfn[*slist], hdpfn[*slist]); } - dev_section(NULL); /* end section list */ + dev_section(NULL,NULL); /* end section list */ dev_flush(); /* update display */ /* update server */ imm_mode = beam_sync(odev.firstuse) > 0; /* record new view */ if (v < viewhist || v >= viewhist+VIEWHISTLEN) { - copystruct(viewhist + (nhist%VIEWHISTLEN), v); + *(viewhist + (nhist%VIEWHISTLEN)) = *v; nhist++; } } @@ -339,7 +349,7 @@ char *args; beam_init(0); /* add basic views */ for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) beam_view(dv, res[0]>>4, res[1]>>4); - copystruct(&vwfocus, &odev.v); /* add focus view */ + vwfocus = odev.v; /* add focus view */ switch (odev.v.type) { case VT_PER: vwfocus.horiz = 2.*180./PI*atan( @@ -405,7 +415,7 @@ usr_input() /* get user input and process it */ } switch (i) { case DC_SETVIEW: /* set the view */ - copystruct(&vparams, &odev.v); + vparams = odev.v; if (!sscanview(&vparams, args)) error(COMMAND, "missing view options"); else @@ -471,7 +481,8 @@ serv_result() /* get next server result and process if (buf == NULL) buf = (char *)malloc(bufsiz=msg.nbytes); else - buf = (char *)realloc(buf, bufsiz=msg.nbytes); + buf = (char *)realloc((void *)buf, + bufsiz=msg.nbytes); if (buf == NULL) error(SYSTEM, "out of memory in serv_result"); } @@ -486,9 +497,10 @@ serv_result() /* get next server result and process disp_bundle((PACKHEAD *)buf); break; case DS_ADDHOLO: - if (msg.nbytes <= sizeof(HDGRID)) + if (msg.nbytes < sizeof(HDGRID)+2) error(INTERNAL, "bad holodeck record from server"); - add_holo((HDGRID *)buf, buf+sizeof(HDGRID)); + add_holo((HDGRID *)buf, buf+sizeof(HDGRID), + buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1); break; case DS_OUTSECT: do_outside = 1; @@ -499,6 +511,8 @@ serv_result() /* get next server result and process break; case DS_STARTIMM: case DS_ENDIMM: + if (!(imm_mode = msg.type==DS_STARTIMM)) + dev_flush(); #ifdef DEBUG { time_t tnow = time(NULL); @@ -507,8 +521,6 @@ serv_result() /* get next server result and process tmodesw = tnow; } #endif - if (!(imm_mode = msg.type==DS_STARTIMM)) - dev_flush(); goto noargs; case DS_ACKNOW: case DS_SHUTDOWN: @@ -557,6 +569,7 @@ char *p; } +void eputs(s) /* put error message to stderr */ register char *s; { @@ -576,10 +589,13 @@ register char *s; } +void quit(code) /* clean up and exit */ int code; { + if (code) + exit(code); if (odev.v.type) dev_close(); - exit(code); + exit(0); }