ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo4.c
Revision: 3.22
Committed: Tue Nov 24 17:05:36 1998 UTC (25 years, 5 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.21: +5 -0 lines
Log Message:
added eyepoint vicinity restriction for interactive samples

File Contents

# User Rev Content
1 gwlarson 3.19 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2 gregl 3.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Holodeck display process communication
9     */
10    
11     #include "rholo.h"
12     #include "rhdisp.h"
13 gregl 3.2 #include <sys/uio.h>
14 gregl 3.1
15 gregl 3.2 #ifndef HDSUF
16 gregl 3.16 #define HDSUF ".hdi"
17 gregl 3.2 #endif
18 gregl 3.1
19 gwlarson 3.21 #ifndef FNONBLK
20     #define FNONBLK O_NONBLOCK
21     #endif
22    
23 gregl 3.2 static int inp_flags;
24     static int dpd[3];
25 gregl 3.5 static FILE *dpout;
26 gregl 3.2
27    
28     disp_open(dname) /* open the named display driver */
29 gregl 3.1 char *dname;
30     {
31 gregl 3.11 char dpath[128], fd0[8], fd1[8], *cmd[5];
32 gregl 3.2 int i;
33 gregl 3.11 /* get full display program name */
34 gregl 3.2 #ifdef DEVPATH
35     sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF);
36     #else
37     sprintf(dpath, "dev/%s%s", dname, HDSUF);
38     #endif
39 gregl 3.11 /* dup stdin and stdout */
40     if (readinp)
41     sprintf(fd0, "%d", dup(0));
42     else
43     strcpy(fd0, "-1");
44     sprintf(fd1, "%d", dup(1));
45     /* start the display process */
46     cmd[0] = dpath;
47     cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0;
48     cmd[4] = NULL;
49     i = open_process(dpd, cmd);
50 gregl 3.6 if (i <= 0)
51 gregl 3.2 error(USER, "cannot start display process");
52 gregl 3.11 if ((dpout = fdopen(dpd[1], "w")) == NULL)
53 gregl 3.5 error(SYSTEM, "cannot associate FILE with display pipe");
54 gregl 3.11 dpd[1] = -1; /* causes ignored error in close_process() */
55 gregl 3.2 inp_flags = 0;
56 gregl 3.11 /* close dup'ed stdin and stdout */
57     if (readinp)
58     close(atoi(fd0));
59     close(atoi(fd1));
60 gregl 3.17 /* check if outside */
61     if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS))
62     disp_result(DS_OUTSECT, 0, NULL);
63 gwlarson 3.18 /* send eye separation if specified */
64     if (vdef(EYESEP)) {
65     char fbuf[32];
66     sprintf(fbuf, "%.9e", vflt(EYESEP));
67     disp_result(DS_EYESEP, strlen(fbuf)+1, fbuf);
68     }
69 gregl 3.2 /* write out hologram grids */
70     for (i = 0; hdlist[i] != NULL; i++)
71     disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]);
72 gregl 3.5 disp_flush();
73 gregl 3.1 }
74    
75    
76 gregl 3.2 disp_packet(p) /* display a packet */
77 gregl 3.4 register PACKHEAD *p;
78 gregl 3.2 {
79 gregl 3.4 disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p);
80 gregl 3.2 }
81    
82    
83 gregl 3.1 disp_check(block) /* check display process */
84     int block;
85     {
86 gregl 3.2 MSGHEAD msg;
87     int n;
88     char *buf = NULL;
89    
90 gregl 3.6 if (dpout == NULL)
91 gregl 3.2 return(-1);
92 gregl 3.5 /* flush display output */
93     disp_flush();
94 gregl 3.3 /* check read blocking */
95 gregl 3.2 if (block != (inp_flags == 0)) {
96     inp_flags = block ? 0 : FNONBLK;
97     if (fcntl(dpd[0], F_SETFL, inp_flags) < 0)
98     goto fcntlerr;
99     }
100     /* read message header */
101     n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD));
102     if (n != sizeof(MSGHEAD)) {
103 gregl 3.10 if (n >= 0) {
104     dpout = NULL;
105 gregl 3.2 error(USER, "display process died");
106 gregl 3.10 }
107 gregl 3.2 if (errno != EAGAIN & errno != EINTR)
108     goto readerr;
109 gregl 3.3 return(2); /* acceptable failure */
110 gregl 3.2 }
111     if (msg.nbytes) { /* get the message body */
112 gwlarson 3.20 if (msg.nbytes < 0)
113     error(INTERNAL, "anti-message from display process");
114 gregl 3.2 buf = (char *)malloc(msg.nbytes);
115     if (buf == NULL)
116     error(SYSTEM, "out of memory in disp_check");
117 gwlarson 3.19 if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0)
118 gregl 3.2 goto fcntlerr;
119     if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes)
120     goto readerr;
121     }
122     switch (msg.type) { /* take appropriate action */
123 gregl 3.12 case DR_BUNDLE: /* new bundle to calculate */
124 gregl 3.2 if (msg.nbytes != sizeof(PACKHEAD))
125     error(INTERNAL, "bad DR_BUNDLE from display process");
126     bundle_set(BS_ADD, (PACKHEAD *)buf, 1);
127     break;
128 gregl 3.12 case DR_NEWSET: /* new calculation set */
129 gregl 3.2 if (msg.nbytes % sizeof(PACKHEAD))
130     error(INTERNAL, "bad DR_NEWSET from display process");
131 gwlarson 3.19 if (msg.nbytes)
132     disp_result(DS_STARTIMM, 0, NULL);
133 gregl 3.2 bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
134 gwlarson 3.19 if (msg.nbytes) {
135     disp_result(DS_ENDIMM, 0, NULL);
136     disp_flush();
137     }
138 gregl 3.2 break;
139 gregl 3.12 case DR_ADDSET: /* add to calculation set */
140 gwlarson 3.19 if (!msg.nbytes)
141     break;
142 gregl 3.2 if (msg.nbytes % sizeof(PACKHEAD))
143     error(INTERNAL, "bad DR_ADDSET from display process");
144     disp_result(DS_STARTIMM, 0, NULL);
145     bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
146     disp_result(DS_ENDIMM, 0, NULL);
147 gregl 3.15 disp_flush();
148 gregl 3.2 break;
149 gregl 3.12 case DR_ADJSET: /* adjust calculation set members */
150 gwlarson 3.19 if (!msg.nbytes)
151     break;
152 gregl 3.9 if (msg.nbytes % sizeof(PACKHEAD))
153     error(INTERNAL, "bad DR_ADJSET from display process");
154     disp_result(DS_STARTIMM, 0, NULL);
155     bundle_set(BS_ADJ, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
156     disp_result(DS_ENDIMM, 0, NULL);
157     disp_flush();
158     break;
159 gregl 3.12 case DR_DELSET: /* delete from calculation set */
160 gwlarson 3.19 if (!msg.nbytes)
161     break;
162 gregl 3.2 if (msg.nbytes % sizeof(PACKHEAD))
163     error(INTERNAL, "bad DR_DELSET from display process");
164     bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
165     break;
166 gwlarson 3.22 case DR_VIEWPOINT: /* set target eye position */
167     if (msg.nbytes != sizeof(VIEWPOINT))
168     error(INTERNAL, "bad DR_VIEWPOINT from display process");
169     copystruct(&myeye, (VIEWPOINT *)buf);
170     break;
171 gregl 3.12 case DR_ATTEN: /* block for priority request */
172 gregl 3.2 if (msg.nbytes)
173     error(INTERNAL, "bad DR_ATTEN from display process");
174     /* send acknowledgement */
175     disp_result(DS_ACKNOW, 0, NULL);
176 gregl 3.3 return(disp_check(1)); /* block on following request */
177 gregl 3.13 case DR_KILL: /* kill computation process(es) */
178     if (msg.nbytes)
179     error(INTERNAL, "bad DR_KILL from display process");
180 gregl 3.14 if (nprocs > 0)
181     done_rtrace();
182     else
183 gregl 3.13 error(WARNING, "no rtrace process to kill");
184     break;
185     case DR_RESTART: /* restart computation process(es) */
186     if (msg.nbytes)
187     error(INTERNAL, "bad DR_RESTART from display process");
188 gregl 3.14 if (ncprocs > nprocs)
189     new_rtrace();
190     else if (nprocs > 0)
191 gregl 3.13 error(WARNING, "rtrace already runnning");
192     else
193     error(WARNING, "holodeck not open for writing");
194     break;
195     case DR_CLOBBER: /* clobber holodeck */
196     if (msg.nbytes)
197     error(INTERNAL, "bad DR_CLOBBER from display process");
198     if (!force || !ncprocs)
199     error(WARNING, "request to clobber holodeck denied");
200     else {
201     error(WARNING, "clobbering holodeck contents");
202     hdclobber(NULL);
203     }
204     break;
205 gregl 3.12 case DR_SHUTDOWN: /* shut down program */
206 gregl 3.2 if (msg.nbytes)
207     error(INTERNAL, "bad DR_SHUTDOWN from display process");
208     return(0); /* zero return signals shutdown */
209 gregl 3.12 case DR_NOOP: /* do nothing */
210 gregl 3.7 break;
211 gregl 3.2 default:
212     error(INTERNAL, "unrecognized request from display process");
213     }
214 gregl 3.3 if (msg.nbytes) /* clean up */
215 gregl 3.2 free(buf);
216     return(1); /* normal return value */
217     fcntlerr:
218     error(SYSTEM, "cannot change display blocking mode");
219     readerr:
220     error(SYSTEM, "error reading from display process");
221 gregl 3.1 }
222    
223    
224 gregl 3.2 int
225     disp_close() /* close our display process */
226 gregl 3.1 {
227 gregl 3.2 int rval;
228    
229 gregl 3.6 if (dpout == NULL)
230 gregl 3.2 return(-1);
231     disp_result(DS_SHUTDOWN, 0, NULL);
232 gregl 3.5 fclose(dpout);
233     dpout = NULL;
234 gregl 3.2 return(close_process(dpd));
235     }
236    
237    
238 gregl 3.5 disp_result(type, nbytes, p) /* queue result message to display process */
239 gregl 3.2 int type, nbytes;
240     char *p;
241     {
242     MSGHEAD msg;
243 gwlarson 3.20 /* consistency checks */
244     #ifdef DEBUG
245     if (nbytes < 0 || nbytes > 0 & p == NULL)
246     error(CONSISTENCY, "bad buffer handed to disp_result");
247     #endif
248 gregl 3.6 if (dpout == NULL)
249     return;
250 gregl 3.2 msg.type = type;
251     msg.nbytes = nbytes;
252 gregl 3.5 fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout);
253     if (nbytes > 0)
254     fwrite(p, 1, nbytes, dpout);
255     }
256    
257    
258     disp_flush() /* flush output to display */
259     {
260     if (fflush(dpout) < 0)
261     error(SYSTEM, "error writing to the display process");
262 gregl 3.1 }