--- ray/src/hd/rhdisp.c 1997/12/11 09:37:43 3.12 +++ ray/src/hd/rhdisp.c 1998/05/14 13:06:32 3.24 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -15,7 +15,7 @@ static char SCCSid[] = "$SunId$ SGI"; #include #ifndef VIEWHISTLEN -#define VIEWHISTLEN 2 /* number of remembered views */ +#define VIEWHISTLEN 4 /* number of remembered views */ #endif HOLO *hdlist[HDMAX+1]; /* global holodeck list */ @@ -24,10 +24,20 @@ char cmdlist[DC_NCMDS][8] = DC_INIT; int imm_mode = 0; /* bundles are being delivered immediately */ +int do_outside = 0; /* render from outside sections */ + 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; +static long nimmrays, naddrays; +#endif + #define RDY_SRV 01 #define RDY_DEV 02 #define RDY_SIN 04 @@ -53,27 +63,49 @@ char *argv[]; sstdin = fdopen(inp, "r"); /* set command error vector */ erract[COMMAND].pf = eputs; +#ifdef DEBUG + tmodesw = time(NULL); +#endif /* enter main loop */ do { rdy = disp_wait(); + if (rdy & RDY_SRV) { /* process server result */ + res = serv_result(); + if (pause && res != DS_SHUTDOWN) { + serv_request(DR_ATTEN, 0, NULL); + while ((res = serv_result()) != DS_ACKNOW && + res != DS_SHUTDOWN) + ; + } + } if (rdy & RDY_DEV) { /* user input from driver */ inp = dev_input(); - if (inp & DEV_PUTVIEW) - printview(); - if (inp & DEV_NEWVIEW) + if (inp & DFL(DC_SETVIEW)) new_view(&odev.v); - if (inp & DEV_LASTVIEW) + if (inp & DFL(DC_GETVIEW)) + printview(); + if (inp & DFL(DC_LASTVIEW)) new_view(NULL); - if (inp & DEV_SHUTDOWN) - serv_request(DR_SHUTDOWN, 0, NULL); - if (inp & DEV_REDRAW) - imm_mode = beam_sync() > 0; - if (inp & DEV_WAIT) - pause = 1; - if (inp & DEV_RESUME) { + if (inp & DFL(DC_RESUME)) { serv_request(DR_NOOP, 0, NULL); pause = 0; } + if (inp & DFL(DC_PAUSE)) + pause = 1; + if (inp & DFL(DC_REDRAW)) + imm_mode = beam_sync(1) > 0; + if (inp & DFL(DC_KILL)) { + serv_request(DR_KILL, 0, NULL); + pause = 0; + } + if (inp & DFL(DC_CLOBBER)) + serv_request(DR_CLOBBER, 0, NULL); + if (inp & DFL(DC_RESTART)) { + serv_request(DR_RESTART, 0, NULL); + pause = 0; + } + if (inp & DFL(DC_QUIT)) + serv_request(DR_SHUTDOWN, 0, NULL); } if (rdy & RDY_SIN) /* user input from sstdin */ switch (usr_input()) { @@ -82,19 +114,23 @@ char *argv[]; break; case DC_RESUME: serv_request(DR_NOOP, 0, NULL); + /* fall through */ + case DC_KILL: + case DC_RESTART: pause = 0; break; } - if (rdy & RDY_SRV) { /* process server result */ - res = serv_result(); - if (pause && res != DS_SHUTDOWN) { - serv_request(DR_ATTEN, 0, NULL); - while ((res = serv_result()) != DS_ACKNOW && - res != DS_SHUTDOWN) - ; - } - } } while (res != DS_SHUTDOWN); +#ifdef DEBUG + if (timm && nimmrays) + fprintf(stderr, + "%s: %.1f rays recalled/second (%ld rays total)\n", + progname, (double)nimmrays/timm, nimmrays); + if (tadd && naddrays) + fprintf(stderr, + "%s: %.1f rays calculated/second (%ld rays total)\n", + progname, (double)naddrays/tadd, naddrays); +#endif /* all done */ quit(0); } @@ -123,6 +159,7 @@ disp_wait() /* wait for more input */ n = odev.ifd+1; if (sstdin != NULL) { FD_SET(fileno(sstdin), &readset); + FD_SET(fileno(sstdin), &errset); if (fileno(sstdin) >= n) n = fileno(sstdin) + 1; } @@ -137,7 +174,8 @@ disp_wait() /* wait for more input */ flgs |= RDY_SRV; if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset)) flgs |= RDY_DEV; - if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset)) + if (sstdin != NULL && (FD_ISSET(fileno(sstdin), &readset) || + FD_ISSET(fileno(sstdin), &errset))) flgs |= RDY_SIN; return(flgs); } @@ -147,6 +185,7 @@ add_holo(hdg) /* register a new holodeck section */ HDGRID *hdg; { VIEW nv; + double d; register int hd; for (hd = 0; hd < HDMAX && hdlist[hd] != NULL; hd++) @@ -167,6 +206,12 @@ HDGRID *hdg; VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5); fcross(nv.vdir, hdlist[0]->xv[1], hdlist[0]->xv[2]); VCOPY(nv.vup, hdlist[0]->xv[2]); + if (do_outside) { + normalize(nv.vdir); + d = VLEN(hdlist[0]->xv[1]); + d += VLEN(hdlist[0]->xv[2]); + VSUM(nv.vp, nv.vp, nv.vdir, -d); + } new_view(&nv); } @@ -190,6 +235,10 @@ register PACKHEAD *p; VSUM(wp, ro, rd, d); /* might be behind viewpoint */ dev_value(packra(p)[i].v, wp, rd); } +#ifdef DEBUG + if (imm_mode) nimmrays += p->nr; + else naddrays += p->nr; +#endif } @@ -198,29 +247,41 @@ register VIEW *v; { static VIEW viewhist[VIEWHISTLEN]; static unsigned nhist; + VIEW *dv; + int i, res[2]; char *err; /* restore previous view? */ if (v == NULL) { - if (nhist < 2) { - error(COMMAND, "no previous view"); - return; - } - nhist--; /* get one before last setting */ + if (nhist > 1) /* get one before last setting */ + nhist--; + else /* else go to end of list */ + while (nhist < VIEWHISTLEN && viewhist[nhist].type) + nhist++; v = viewhist + ((nhist-1)%VIEWHISTLEN); - } else if ((err = setview(v)) != NULL) { + } else +again: + if ((err = setview(v)) != NULL) { error(COMMAND, err); return; } -again: if (v->type == VT_PAR) { error(COMMAND, "cannot handle parallel views"); return; } - if (!dev_view(v)) /* update display driver */ + if (!dev_view(v)) /* notify display driver */ goto again; dev_flush(); /* update screen */ - if (!beam_view(v)) /* update beam list */ - goto again; + beam_init(); /* compute new beam set */ + for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) + if (!beam_view(dv, res[0], res[1])) { + if (!nhist) { + error(COMMAND, "invalid starting view"); + return; + } + copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); + goto again; + } + beam_sync(0); /* update server */ /* record new view */ if (v < viewhist || v >= viewhist+VIEWHISTLEN) { copystruct(viewhist + (nhist%VIEWHISTLEN), v); @@ -233,12 +294,15 @@ int usr_input() /* get user input and process it */ { VIEW vparams; - char cmd[128]; + char cmd[256]; register char *args; register int i; - if (fgets(cmd, sizeof(cmd), sstdin) == NULL) - return(DC_QUIT); + if (fgets(cmd, sizeof(cmd), sstdin) == NULL) { + fclose(sstdin); + sstdin = NULL; + return(0); + } for (args = cmd; *args && !isspace(*args); args++) ; while (isspace(*args)) @@ -273,6 +337,19 @@ usr_input() /* get user input and process it */ case DC_RESUME: /* resume the calculation */ /* handled in main() */ break; + case DC_REDRAW: /* redraw from server */ + imm_mode = beam_sync(1) > 0; + dev_clear(); + break; + case DC_KILL: /* kill rtrace process(es) */ + serv_request(DR_KILL, 0, NULL); + break; + case DC_CLOBBER: /* clobber holodeck */ + serv_request(DR_CLOBBER, 0, NULL); + break; + case DC_RESTART: /* restart rtrace */ + serv_request(DR_RESTART, 0, NULL); + break; case DC_QUIT: /* quit request */ serv_request(DR_SHUTDOWN, 0, NULL); break; @@ -326,11 +403,20 @@ serv_result() /* get next server result and process error(INTERNAL, "bad holodeck record from server"); add_holo((HDGRID *)buf); break; + case DS_OUTSECT: + do_outside = 1; + break; case DS_STARTIMM: case DS_ENDIMM: +#ifdef DEBUG + if (imm_mode != (msg.type==DS_STARTIMM)) { + time_t tnow = time(NULL); + if (imm_mode) timm += tnow - tmodesw; + else tadd += tnow - tmodesw; + tmodesw = tnow; + } +#endif imm_mode = msg.type==DS_STARTIMM; - if (msg.type == DS_ENDIMM) - dev_flush(); /* update display NOW */ /* fall through */ case DS_ACKNOW: case DS_SHUTDOWN: