--- ray/src/hd/rholo4.c 1997/12/12 11:13:17 3.13 +++ ray/src/hd/rholo4.c 1998/11/24 17:05:36 3.22 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -13,9 +13,13 @@ static char SCCSid[] = "$SunId$ SGI"; #include #ifndef HDSUF -#define HDSUF ".hdisp" +#define HDSUF ".hdi" #endif +#ifndef FNONBLK +#define FNONBLK O_NONBLOCK +#endif + static int inp_flags; static int dpd[3]; static FILE *dpout; @@ -53,6 +57,15 @@ char *dname; if (readinp) close(atoi(fd0)); close(atoi(fd1)); + /* check if outside */ + if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS)) + disp_result(DS_OUTSECT, 0, NULL); + /* send eye separation if specified */ + if (vdef(EYESEP)) { + char fbuf[32]; + sprintf(fbuf, "%.9e", vflt(EYESEP)); + disp_result(DS_EYESEP, strlen(fbuf)+1, fbuf); + } /* write out hologram grids */ for (i = 0; hdlist[i] != NULL; i++) disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); @@ -96,10 +109,12 @@ int block; return(2); /* acceptable failure */ } if (msg.nbytes) { /* get the message body */ + if (msg.nbytes < 0) + error(INTERNAL, "anti-message from display process"); buf = (char *)malloc(msg.nbytes); if (buf == NULL) error(SYSTEM, "out of memory in disp_check"); - if (fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) + if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) goto fcntlerr; if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes) goto readerr; @@ -113,20 +128,27 @@ int block; case DR_NEWSET: /* new calculation set */ if (msg.nbytes % sizeof(PACKHEAD)) error(INTERNAL, "bad DR_NEWSET from display process"); - disp_result(DS_STARTIMM, 0, NULL); + if (msg.nbytes) + disp_result(DS_STARTIMM, 0, NULL); bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); - disp_result(DS_ENDIMM, 0, NULL); - disp_flush(); + if (msg.nbytes) { + disp_result(DS_ENDIMM, 0, NULL); + disp_flush(); + } break; case DR_ADDSET: /* add to calculation set */ + if (!msg.nbytes) + break; if (msg.nbytes % sizeof(PACKHEAD)) error(INTERNAL, "bad DR_ADDSET from display process"); disp_result(DS_STARTIMM, 0, NULL); bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); disp_result(DS_ENDIMM, 0, NULL); - disp_check(0); /* hack -- delete usu. follows add */ + disp_flush(); break; case DR_ADJSET: /* adjust calculation set members */ + if (!msg.nbytes) + break; if (msg.nbytes % sizeof(PACKHEAD)) error(INTERNAL, "bad DR_ADJSET from display process"); disp_result(DS_STARTIMM, 0, NULL); @@ -135,10 +157,17 @@ int block; disp_flush(); break; case DR_DELSET: /* delete from calculation set */ + if (!msg.nbytes) + break; if (msg.nbytes % sizeof(PACKHEAD)) error(INTERNAL, "bad DR_DELSET from display process"); bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); break; + case DR_VIEWPOINT: /* set target eye position */ + if (msg.nbytes != sizeof(VIEWPOINT)) + error(INTERNAL, "bad DR_VIEWPOINT from display process"); + copystruct(&myeye, (VIEWPOINT *)buf); + break; case DR_ATTEN: /* block for priority request */ if (msg.nbytes) error(INTERNAL, "bad DR_ATTEN from display process"); @@ -148,21 +177,17 @@ int block; case DR_KILL: /* kill computation process(es) */ if (msg.nbytes) error(INTERNAL, "bad DR_KILL from display process"); - if (nprocs > 0) { - done_packets(flush_queue()); - if (end_rtrace()) - error(WARNING, "bad status returned by rtrace"); - } else + if (nprocs > 0) + done_rtrace(); + else error(WARNING, "no rtrace process to kill"); break; case DR_RESTART: /* restart computation process(es) */ if (msg.nbytes) error(INTERNAL, "bad DR_RESTART from display process"); - if (ncprocs > nprocs) { - checkrad(); - if (start_rtrace() < 1) - error(WARNING, "cannot restart rtrace"); - } else if (nprocs > 0) + if (ncprocs > nprocs) + new_rtrace(); + else if (nprocs > 0) error(WARNING, "rtrace already runnning"); else error(WARNING, "holodeck not open for writing"); @@ -215,7 +240,11 @@ int type, nbytes; char *p; { MSGHEAD msg; - + /* consistency checks */ +#ifdef DEBUG + if (nbytes < 0 || nbytes > 0 & p == NULL) + error(CONSISTENCY, "bad buffer handed to disp_result"); +#endif if (dpout == NULL) return; msg.type = type;