ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhdisp.c
(Generate patch)

Comparing ray/src/hd/rhdisp.c (file contents):
Revision 3.4 by gregl, Fri Nov 21 16:10:17 1997 UTC vs.
Revision 3.22 by gregl, Tue Jan 6 05:26:20 1998 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
12   #include "rhdisp.h"
13   #include "rhdriver.h"
14   #include "selcall.h"
15 + #include <ctype.h>
16  
17 + #ifndef VIEWHISTLEN
18 + #define VIEWHISTLEN     4       /* number of remembered views */
19 + #endif
20 +
21   HOLO    *hdlist[HDMAX+1];       /* global holodeck list */
22  
23 + char    cmdlist[DC_NCMDS][8] = DC_INIT;
24 +
25   int     imm_mode = 0;           /* bundles are being delivered immediately */
26  
27 < VIEW    dvw;                    /* our current display view */
27 > int     do_outside = 0;         /* render from outside sections */
28  
29   char    *progname;              /* global argv[0] */
30  
31 < #define RDY_SRV 01
25 < #define RDY_DEV 02
31 > FILE    *sstdin, *sstdout;      /* server's standard input and output */
32  
33 + #ifdef DEBUG
34 + #include <sys/types.h>
35 + extern time_t   time();
36 + static time_t   tmodesw;
37 + static time_t   timm, tadd;
38 + static long     nimmrays, naddrays;
39 + #endif
40  
41 + #define RDY_SRV         01
42 + #define RDY_DEV         02
43 + #define RDY_SIN         04
44 +
45 +
46   main(argc, argv)
47   int     argc;
48   char    *argv[];
49   {
50 +        extern int      eputs();
51          int     rdy, inp, res = 0, pause = 0;
52  
53          progname = argv[0];
54 <        if (argc != 2)
54 >        if (argc < 3)
55                  error(USER, "bad command line arguments");
56                                          /* open our device */
57          dev_open(argv[1]);
58 +                                        /* open server process i/o */
59 +        sstdout = fdopen(atoi(argv[2]), "w");
60 +        if (argc < 4 || (inp = atoi(argv[3])) < 0)
61 +                sstdin = NULL;
62 +        else
63 +                sstdin = fdopen(inp, "r");
64 +                                        /* set command error vector */
65 +        erract[COMMAND].pf = eputs;
66 + #ifdef DEBUG
67 +        tmodesw = time(NULL);
68 + #endif
69                                          /* enter main loop */
70          do {
71                  rdy = disp_wait();
72 <                if (rdy & RDY_DEV) {            /* get user input */
43 <                        inp = dev_input();
44 <                        if (inp & DEV_NEWVIEW)
45 <                                new_view(&odev.v);
46 <                        if (inp & DEV_SHUTDOWN)
47 <                                serv_request(DR_SHUTDOWN, 0, NULL);
48 <                        if (inp & DEV_REDRAW) {
49 <                                beam_sync();
50 <                                imm_mode = 1;   /* preempt updates */
51 <                        }
52 <                        if (inp & DEV_WAIT)
53 <                                pause = 1;
54 <                        if (inp & DEV_RESUME) {
55 <                                serv_request(DR_NOOP, 0, NULL);
56 <                                pause = 0;
57 <                        }
58 <                }
59 <                if (rdy & RDY_SRV) {            /* get server result */
72 >                if (rdy & RDY_SRV) {            /* process server result */
73                          res = serv_result();
74                          if (pause && res != DS_SHUTDOWN) {
75                                  serv_request(DR_ATTEN, 0, NULL);
# Line 65 | Line 78 | char   *argv[];
78                                          ;
79                          }
80                  }
81 +                if (rdy & RDY_DEV) {            /* user input from driver */
82 +                        inp = dev_input();
83 +                        if (inp & DFL(DC_SETVIEW))
84 +                                new_view(&odev.v);
85 +                        if (inp & DFL(DC_GETVIEW))
86 +                                printview();
87 +                        if (inp & DFL(DC_LASTVIEW))
88 +                                new_view(NULL);
89 +                        if (inp & DFL(DC_RESUME)) {
90 +                                serv_request(DR_NOOP, 0, NULL);
91 +                                pause = 0;
92 +                        }
93 +                        if (inp & DFL(DC_PAUSE))
94 +                                pause = 1;
95 +                        if (inp & DFL(DC_REDRAW))
96 +                                imm_mode = beam_sync() > 0;
97 +                        if (inp & DFL(DC_KILL)) {
98 +                                serv_request(DR_KILL, 0, NULL);
99 +                                pause = 0;
100 +                        }
101 +                        if (inp & DFL(DC_CLOBBER))
102 +                                serv_request(DR_CLOBBER, 0, NULL);
103 +                        if (inp & DFL(DC_RESTART)) {
104 +                                serv_request(DR_RESTART, 0, NULL);
105 +                                pause = 0;
106 +                        }
107 +                        if (inp & DFL(DC_QUIT))
108 +                                serv_request(DR_SHUTDOWN, 0, NULL);
109 +                }
110 +                if (rdy & RDY_SIN)              /* user input from sstdin */
111 +                        switch (usr_input()) {
112 +                        case DC_PAUSE:
113 +                                pause = 1;
114 +                                break;
115 +                        case DC_RESUME:
116 +                                serv_request(DR_NOOP, 0, NULL);
117 +                                /* fall through */
118 +                        case DC_KILL:
119 +                        case DC_RESTART:
120 +                                pause = 0;
121 +                                break;
122 +                        }
123          } while (res != DS_SHUTDOWN);
124 + #ifdef DEBUG
125 +        if (timm && nimmrays)
126 +                fprintf(stderr,
127 +                        "%s: %.1f rays recalled/second (%ld rays total)\n",
128 +                                progname, (double)nimmrays/timm, nimmrays);
129 +        if (tadd && naddrays)
130 +                fprintf(stderr,
131 +                        "%s: %.1f rays calculated/second (%ld rays total)\n",
132 +                                progname, (double)naddrays/tadd, naddrays);
133 + #endif
134                                          /* all done */
135          quit(0);
136   }
# Line 81 | Line 146 | disp_wait()                    /* wait for more input */
146                                  /* see if we can avoid select call */
147          if (imm_mode || stdin->_cnt > 0)
148                  return(RDY_SRV);
149 +        if (sstdin != NULL && sstdin->_cnt > 0)
150 +                return(RDY_SIN);
151          if (dev_flush())
152                  return(RDY_DEV);
153                                  /* make the call */
# Line 89 | Line 156 | disp_wait()                    /* wait for more input */
156          FD_SET(0, &errset);
157          FD_SET(odev.ifd, &readset);
158          FD_SET(odev.ifd, &errset);
159 <        n = odev.ifd + 1;
159 >        n = odev.ifd+1;
160 >        if (sstdin != NULL) {
161 >                FD_SET(fileno(sstdin), &readset);
162 >                if (fileno(sstdin) >= n)
163 >                        n = fileno(sstdin) + 1;
164 >        }
165          n = select(n, &readset, NULL, &errset, NULL);
166          if (n < 0) {
167                  if (errno == EINTR)
# Line 101 | Line 173 | disp_wait()                    /* wait for more input */
173                  flgs |= RDY_SRV;
174          if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset))
175                  flgs |= RDY_DEV;
176 +        if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset))
177 +                flgs |= RDY_SIN;
178          return(flgs);
179   }
180  
# Line 109 | Line 183 | add_holo(hdg)                  /* register a new holodeck section */
183   HDGRID  *hdg;
184   {
185          VIEW    nv;
186 +        double  d;
187          register int    hd;
188  
189          for (hd = 0; hd < HDMAX && hdlist[hd] != NULL; hd++)
# Line 129 | Line 204 | HDGRID *hdg;
204          VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5);
205          fcross(nv.vdir, hdlist[0]->xv[1], hdlist[0]->xv[2]);
206          VCOPY(nv.vup, hdlist[0]->xv[2]);
207 +        if (do_outside) {
208 +                normalize(nv.vdir);
209 +                d = VLEN(hdlist[0]->xv[1]);
210 +                d += VLEN(hdlist[0]->xv[2]);
211 +                VSUM(nv.vp, nv.vp, nv.vdir, -d);
212 +        }
213          new_view(&nv);
214   }
215  
# Line 150 | Line 231 | register PACKHEAD      *p;
231                  hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r);
232                  d = hddepth(hdlist[p->hd], packra(p)[i].d);
233                  VSUM(wp, ro, rd, d);            /* might be behind viewpoint */
234 <                dev_value(packra(p)[i].v, wp);
234 >                dev_value(packra(p)[i].v, wp, rd);
235          }
236 + #ifdef DEBUG
237 +        if (imm_mode) nimmrays += p->nr;
238 +        else naddrays += p->nr;
239 + #endif
240   }
241  
242  
243   new_view(v)                     /* change view parameters */
244 < VIEW    *v;
244 > register VIEW   *v;
245   {
246 +        static VIEW     viewhist[VIEWHISTLEN];
247 +        static unsigned nhist;
248          char    *err;
249 +                                /* restore previous view? */
250 +        if (v == NULL) {
251 +                if (nhist > 1)          /* get one before last setting */
252 +                        nhist--;
253 +                else                    /* else go to end of list */
254 +                        while (nhist < VIEWHISTLEN && viewhist[nhist].type)
255 +                                nhist++;
256 +                v = viewhist + ((nhist-1)%VIEWHISTLEN);
257 +        } else
258 + again:
259 +        if ((err = setview(v)) != NULL) {
260 +                error(COMMAND, err);
261 +                return;
262 +        }
263 +        if (v->type == VT_PAR) {
264 +                error(COMMAND, "cannot handle parallel views");
265 +                return;
266 +        }
267 +        if (!dev_view(v))       /* update display driver */
268 +                goto again;
269 +        dev_flush();            /* update screen */
270 +        if (!beam_view(v))      /* update beam list */
271 +                goto again;
272 +                                /* record new view */
273 +        if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
274 +                copystruct(viewhist + (nhist%VIEWHISTLEN), v);
275 +                nhist++;
276 +        }
277 + }
278  
279 <        if ((err = setview(v)) != NULL)
280 <                error(INTERNAL, err);
281 <        dev_view(v);                    /* update display driver */
282 <        beam_view(&dvw, v);             /* update beam list */
283 <        copystruct(&dvw, v);            /* record new view */
279 >
280 > int
281 > usr_input()                     /* get user input and process it */
282 > {
283 >        VIEW    vparams;
284 >        char    cmd[128];
285 >        register char   *args;
286 >        register int    i;
287 >
288 >        if (fgets(cmd, sizeof(cmd), sstdin) == NULL)
289 >                return(DC_QUIT);
290 >        for (args = cmd; *args && !isspace(*args); args++)
291 >                ;
292 >        while (isspace(*args))
293 >                *args++ = '\0';
294 >        if (!*cmd)
295 >                return(DC_RESUME);
296 >        if (*args && args[i=strlen(args)-1] == '\n')
297 >                args[i] = '\0';
298 >        for (i = 0; i < DC_NCMDS; i++)
299 >                if (!strcmp(cmd, cmdlist[i]))
300 >                        break;
301 >        if (i >= DC_NCMDS) {
302 >                sprintf(errmsg, "unknown command: %s", cmd);
303 >                error(COMMAND, errmsg);
304 >                return(-1);
305 >        }
306 >        switch (i) {
307 >        case DC_SETVIEW:                /* set the view */
308 >                copystruct(&vparams, &odev.v);
309 >                if (!sscanview(&vparams, args))
310 >                        error(COMMAND, "missing view options");
311 >                else
312 >                        new_view(&vparams);
313 >                break;
314 >        case DC_GETVIEW:                /* print the current view */
315 >                printview();
316 >                break;
317 >        case DC_LASTVIEW:               /* restore previous view */
318 >                new_view(NULL);
319 >                break;
320 >        case DC_PAUSE:                  /* pause the current calculation */
321 >        case DC_RESUME:                 /* resume the calculation */
322 >                /* handled in main() */
323 >                break;
324 >        case DC_REDRAW:                 /* redraw from server */
325 >                imm_mode = beam_sync() > 0;
326 >                dev_clear();
327 >                break;
328 >        case DC_KILL:                   /* kill rtrace process(es) */
329 >                serv_request(DR_KILL, 0, NULL);
330 >                break;
331 >        case DC_CLOBBER:                /* clobber holodeck */
332 >                serv_request(DR_CLOBBER, 0, NULL);
333 >                break;
334 >        case DC_RESTART:                /* restart rtrace */
335 >                serv_request(DR_RESTART, 0, NULL);
336 >                break;
337 >        case DC_QUIT:                   /* quit request */
338 >                serv_request(DR_SHUTDOWN, 0, NULL);
339 >                break;
340 >        default:
341 >                error(CONSISTENCY, "bad command id in usr_input");
342 >        }
343 >        return(i);
344   }
345  
346  
347 + printview()                     /* print our current view to server stdout */
348 + {
349 +        fputs(VIEWSTR, sstdout);
350 +        fprintview(&odev.v, sstdout);
351 +        fputc('\n', sstdout);
352 +        fflush(sstdout);
353 + }
354 +
355 +
356   int
357   serv_result()                   /* get next server result and process it */
358   {
# Line 202 | Line 387 | serv_result()                  /* get next server result and process
387                          error(INTERNAL, "bad holodeck record from server");
388                  add_holo((HDGRID *)buf);
389                  break;
390 +        case DS_OUTSECT:
391 +                do_outside = 1;
392 +                break;
393          case DS_STARTIMM:
394          case DS_ENDIMM:
395 + #ifdef DEBUG
396 +                if (imm_mode != (msg.type==DS_STARTIMM)) {
397 +                        time_t  tnow = time(NULL);
398 +                        if (imm_mode) timm += tnow - tmodesw;
399 +                        else tadd += tnow - tmodesw;
400 +                        tmodesw = tnow;
401 +                }
402 + #endif
403                  imm_mode = msg.type==DS_STARTIMM;
404                  /* fall through */
405          case DS_ACKNOW:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines