--- ray/src/hd/rhdisp.c 1998/01/04 18:37:10 3.20 +++ ray/src/hd/rhdisp.c 1998/07/13 17:55:51 3.27 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -26,10 +26,20 @@ int imm_mode = 0; /* bundles are being delivered imme int do_outside = 0; /* render from outside sections */ +double eyesepdist = 1; /* eye separation distance */ + 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 @@ -55,6 +65,9 @@ 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(); @@ -82,7 +95,7 @@ char *argv[]; if (inp & DFL(DC_PAUSE)) pause = 1; if (inp & DFL(DC_REDRAW)) - imm_mode = beam_sync() > 0; + imm_mode = beam_sync(1) > 0; if (inp & DFL(DC_KILL)) { serv_request(DR_KILL, 0, NULL); pause = 0; @@ -110,6 +123,16 @@ char *argv[]; break; } } 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); } @@ -138,6 +161,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; } @@ -152,7 +176,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); } @@ -212,6 +237,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 } @@ -220,6 +249,8 @@ register VIEW *v; { static VIEW viewhist[VIEWHISTLEN]; static unsigned nhist; + VIEW *dv; + int i, res[2]; char *err; /* restore previous view? */ if (v == NULL) { @@ -239,11 +270,20 @@ again: 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(0); /* 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); @@ -256,26 +296,28 @@ 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(-1); + } + if (!*cmd) + return(DC_RESUME); for (args = cmd; *args && !isspace(*args); args++) ; while (isspace(*args)) *args++ = '\0'; - if (!*cmd) - return(DC_RESUME); if (*args && args[i=strlen(args)-1] == '\n') args[i] = '\0'; for (i = 0; i < DC_NCMDS; i++) if (!strcmp(cmd, cmdlist[i])) break; if (i >= DC_NCMDS) { - sprintf(errmsg, "unknown command: %s", cmd); - error(COMMAND, errmsg); + dev_auxcom(cmd, args); return(-1); } switch (i) { @@ -297,7 +339,8 @@ usr_input() /* get user input and process it */ /* handled in main() */ break; case DC_REDRAW: /* redraw from server */ - imm_mode = beam_sync() > 0; + imm_mode = beam_sync(1) > 0; + dev_clear(); break; case DC_KILL: /* kill rtrace process(es) */ serv_request(DR_KILL, 0, NULL); @@ -364,8 +407,20 @@ serv_result() /* get next server result and process case DS_OUTSECT: do_outside = 1; break; + case DS_EYESEP: + if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY) + error(INTERNAL, "bad eye separation from server"); + 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; /* fall through */ case DS_ACKNOW: