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.2 by gregl, Thu Nov 20 18:05:57 1997 UTC vs.
Revision 3.25 by gwlarson, Fri May 22 08:30:40 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# 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 + double  eyesepdist = 1;         /* eye separation distance */
30 +
31   char    *progname;              /* global argv[0] */
32  
33 < #define SERV_READY      01
25 < #define DEV_READY       02
33 > FILE    *sstdin, *sstdout;      /* server's standard input and output */
34  
35 + #ifdef DEBUG
36 + #include <sys/types.h>
37 + extern time_t   time();
38 + static time_t   tmodesw;
39 + static time_t   timm, tadd;
40 + static long     nimmrays, naddrays;
41 + #endif
42  
43 + #define RDY_SRV         01
44 + #define RDY_DEV         02
45 + #define RDY_SIN         04
46 +
47 +
48   main(argc, argv)
49   int     argc;
50   char    *argv[];
51   {
52 <        int     rdy, inp, res = 0;
52 >        extern int      eputs();
53 >        int     rdy, inp, res = 0, pause = 0;
54  
55          progname = argv[0];
56 <        if (argc != 2)
56 >        if (argc < 3)
57                  error(USER, "bad command line arguments");
58                                          /* open our device */
59          dev_open(argv[1]);
60 +                                        /* open server process i/o */
61 +        sstdout = fdopen(atoi(argv[2]), "w");
62 +        if (argc < 4 || (inp = atoi(argv[3])) < 0)
63 +                sstdin = NULL;
64 +        else
65 +                sstdin = fdopen(inp, "r");
66 +                                        /* set command error vector */
67 +        erract[COMMAND].pf = eputs;
68 + #ifdef DEBUG
69 +        tmodesw = time(NULL);
70 + #endif
71                                          /* enter main loop */
72          do {
73                  rdy = disp_wait();
74 <                while (rdy & DEV_READY) {
75 <                        inp = dev_input();      /* take residual action here */
76 <                        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_WAIT)
74 >                if (rdy & RDY_SRV) {            /* process server result */
75 >                        res = serv_result();
76 >                        if (pause && res != DS_SHUTDOWN) {
77                                  serv_request(DR_ATTEN, 0, NULL);
78 <                        else
79 <                                rdy &= ~DEV_READY;
78 >                                while ((res = serv_result()) != DS_ACKNOW &&
79 >                                                res != DS_SHUTDOWN)
80 >                                        ;
81 >                        }
82                  }
83 <                if (rdy & SERV_READY) {
84 <                        res = serv_result();    /* processes result, also */
85 <                        if (res == DS_ACKNOW)
83 >                if (rdy & RDY_DEV) {            /* user input from driver */
84 >                        inp = dev_input();
85 >                        if (inp & DFL(DC_SETVIEW))
86 >                                new_view(&odev.v);
87 >                        if (inp & DFL(DC_GETVIEW))
88 >                                printview();
89 >                        if (inp & DFL(DC_LASTVIEW))
90 >                                new_view(NULL);
91 >                        if (inp & DFL(DC_RESUME)) {
92                                  serv_request(DR_NOOP, 0, NULL);
93 +                                pause = 0;
94 +                        }
95 +                        if (inp & DFL(DC_PAUSE))
96 +                                pause = 1;
97 +                        if (inp & DFL(DC_REDRAW))
98 +                                imm_mode = beam_sync(1) > 0;
99 +                        if (inp & DFL(DC_KILL)) {
100 +                                serv_request(DR_KILL, 0, NULL);
101 +                                pause = 0;
102 +                        }
103 +                        if (inp & DFL(DC_CLOBBER))
104 +                                serv_request(DR_CLOBBER, 0, NULL);
105 +                        if (inp & DFL(DC_RESTART)) {
106 +                                serv_request(DR_RESTART, 0, NULL);
107 +                                pause = 0;
108 +                        }
109 +                        if (inp & DFL(DC_QUIT))
110 +                                serv_request(DR_SHUTDOWN, 0, NULL);
111                  }
112 +                if (rdy & RDY_SIN)              /* user input from sstdin */
113 +                        switch (usr_input()) {
114 +                        case DC_PAUSE:
115 +                                pause = 1;
116 +                                break;
117 +                        case DC_RESUME:
118 +                                serv_request(DR_NOOP, 0, NULL);
119 +                                /* fall through */
120 +                        case DC_KILL:
121 +                        case DC_RESTART:
122 +                                pause = 0;
123 +                                break;
124 +                        }
125          } while (res != DS_SHUTDOWN);
126 + #ifdef DEBUG
127 +        if (timm && nimmrays)
128 +                fprintf(stderr,
129 +                        "%s: %.1f rays recalled/second (%ld rays total)\n",
130 +                                progname, (double)nimmrays/timm, nimmrays);
131 +        if (tadd && naddrays)
132 +                fprintf(stderr,
133 +                        "%s: %.1f rays calculated/second (%ld rays total)\n",
134 +                                progname, (double)naddrays/tadd, naddrays);
135 + #endif
136                                          /* all done */
137          quit(0);
138   }
# Line 70 | Line 147 | disp_wait()                    /* wait for more input */
147          register int    i;
148                                  /* see if we can avoid select call */
149          if (imm_mode || stdin->_cnt > 0)
150 <                return(SERV_READY);
150 >                return(RDY_SRV);
151 >        if (sstdin != NULL && sstdin->_cnt > 0)
152 >                return(RDY_SIN);
153          if (dev_flush())
154 <                return(DEV_READY);
154 >                return(RDY_DEV);
155                                  /* make the call */
156          FD_ZERO(&readset); FD_ZERO(&errset);
157          FD_SET(0, &readset);
158          FD_SET(0, &errset);
159          FD_SET(odev.ifd, &readset);
160          FD_SET(odev.ifd, &errset);
161 <        n = odev.ifd + 1;
161 >        n = odev.ifd+1;
162 >        if (sstdin != NULL) {
163 >                FD_SET(fileno(sstdin), &readset);
164 >                FD_SET(fileno(sstdin), &errset);
165 >                if (fileno(sstdin) >= n)
166 >                        n = fileno(sstdin) + 1;
167 >        }
168          n = select(n, &readset, NULL, &errset, NULL);
169          if (n < 0) {
170                  if (errno == EINTR)
# Line 88 | Line 173 | disp_wait()                    /* wait for more input */
173          }
174          flgs = 0;               /* flag what's ready */
175          if (FD_ISSET(0, &readset) || FD_ISSET(0, &errset))
176 <                flgs |= SERV_READY;
176 >                flgs |= RDY_SRV;
177          if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset))
178 <                flgs |= DEV_READY;
178 >                flgs |= RDY_DEV;
179 >        if (sstdin != NULL && (FD_ISSET(fileno(sstdin), &readset) ||
180 >                                FD_ISSET(fileno(sstdin), &errset)))
181 >                flgs |= RDY_SIN;
182          return(flgs);
183   }
184  
# Line 99 | Line 187 | add_holo(hdg)                  /* register a new holodeck section */
187   HDGRID  *hdg;
188   {
189          VIEW    nv;
190 +        double  d;
191          register int    hd;
192  
193          for (hd = 0; hd < HDMAX && hdlist[hd] != NULL; hd++)
# Line 119 | Line 208 | HDGRID *hdg;
208          VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5);
209          fcross(nv.vdir, hdlist[0]->xv[1], hdlist[0]->xv[2]);
210          VCOPY(nv.vup, hdlist[0]->xv[2]);
211 +        if (do_outside) {
212 +                normalize(nv.vdir);
213 +                d = VLEN(hdlist[0]->xv[1]);
214 +                d += VLEN(hdlist[0]->xv[2]);
215 +                VSUM(nv.vp, nv.vp, nv.vdir, -d);
216 +        }
217          new_view(&nv);
218   }
219  
# Line 140 | Line 235 | register PACKHEAD      *p;
235                  hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r);
236                  d = hddepth(hdlist[p->hd], packra(p)[i].d);
237                  VSUM(wp, ro, rd, d);            /* might be behind viewpoint */
238 <                dev_value(packra(p)[i].v, wp);
238 >                dev_value(packra(p)[i].v, wp, rd);
239          }
240 + #ifdef DEBUG
241 +        if (imm_mode) nimmrays += p->nr;
242 +        else naddrays += p->nr;
243 + #endif
244   }
245  
246  
247   new_view(v)                     /* change view parameters */
248 < VIEW    *v;
248 > register VIEW   *v;
249   {
250 +        static VIEW     viewhist[VIEWHISTLEN];
251 +        static unsigned nhist;
252 +        VIEW    *dv;
253 +        int     i, res[2];
254          char    *err;
255 +                                /* restore previous view? */
256 +        if (v == NULL) {
257 +                if (nhist > 1)          /* get one before last setting */
258 +                        nhist--;
259 +                else                    /* else go to end of list */
260 +                        while (nhist < VIEWHISTLEN && viewhist[nhist].type)
261 +                                nhist++;
262 +                v = viewhist + ((nhist-1)%VIEWHISTLEN);
263 +        } else
264 + again:
265 +        if ((err = setview(v)) != NULL) {
266 +                error(COMMAND, err);
267 +                return;
268 +        }
269 +        if (v->type == VT_PAR) {
270 +                error(COMMAND, "cannot handle parallel views");
271 +                return;
272 +        }
273 +        if (!dev_view(v))       /* notify display driver */
274 +                goto again;
275 +        dev_flush();            /* update screen */
276 +        beam_init();            /* compute new beam set */
277 +        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
278 +                if (!beam_view(dv, res[0], res[1])) {
279 +                        if (!nhist) {
280 +                                error(COMMAND, "invalid starting view");
281 +                                return;
282 +                        }
283 +                        copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN));
284 +                        goto again;
285 +                }
286 +        beam_sync(0);           /* update server */
287 +                                /* record new view */
288 +        if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
289 +                copystruct(viewhist + (nhist%VIEWHISTLEN), v);
290 +                nhist++;
291 +        }
292 + }
293  
294 <        if ((err = setview(v)) != NULL)
295 <                error(INTERNAL, err);
296 <        dev_view(v);                    /* update display driver */
297 <        beam_view(&dvw, v);             /* update beam list */
298 <        copystruct(&dvw, v);            /* record new view */
294 >
295 > int
296 > usr_input()                     /* get user input and process it */
297 > {
298 >        VIEW    vparams;
299 >        char    cmd[256];
300 >        register char   *args;
301 >        register int    i;
302 >
303 >        if (fgets(cmd, sizeof(cmd), sstdin) == NULL) {
304 >                fclose(sstdin);
305 >                sstdin = NULL;
306 >                return(0);
307 >        }
308 >        for (args = cmd; *args && !isspace(*args); args++)
309 >                ;
310 >        while (isspace(*args))
311 >                *args++ = '\0';
312 >        if (!*cmd)
313 >                return(DC_RESUME);
314 >        if (*args && args[i=strlen(args)-1] == '\n')
315 >                args[i] = '\0';
316 >        for (i = 0; i < DC_NCMDS; i++)
317 >                if (!strcmp(cmd, cmdlist[i]))
318 >                        break;
319 >        if (i >= DC_NCMDS) {
320 >                sprintf(errmsg, "unknown command: %s", cmd);
321 >                error(COMMAND, errmsg);
322 >                return(-1);
323 >        }
324 >        switch (i) {
325 >        case DC_SETVIEW:                /* set the view */
326 >                copystruct(&vparams, &odev.v);
327 >                if (!sscanview(&vparams, args))
328 >                        error(COMMAND, "missing view options");
329 >                else
330 >                        new_view(&vparams);
331 >                break;
332 >        case DC_GETVIEW:                /* print the current view */
333 >                printview();
334 >                break;
335 >        case DC_LASTVIEW:               /* restore previous view */
336 >                new_view(NULL);
337 >                break;
338 >        case DC_PAUSE:                  /* pause the current calculation */
339 >        case DC_RESUME:                 /* resume the calculation */
340 >                /* handled in main() */
341 >                break;
342 >        case DC_REDRAW:                 /* redraw from server */
343 >                imm_mode = beam_sync(1) > 0;
344 >                dev_clear();
345 >                break;
346 >        case DC_KILL:                   /* kill rtrace process(es) */
347 >                serv_request(DR_KILL, 0, NULL);
348 >                break;
349 >        case DC_CLOBBER:                /* clobber holodeck */
350 >                serv_request(DR_CLOBBER, 0, NULL);
351 >                break;
352 >        case DC_RESTART:                /* restart rtrace */
353 >                serv_request(DR_RESTART, 0, NULL);
354 >                break;
355 >        case DC_QUIT:                   /* quit request */
356 >                serv_request(DR_SHUTDOWN, 0, NULL);
357 >                break;
358 >        default:
359 >                error(CONSISTENCY, "bad command id in usr_input");
360 >        }
361 >        return(i);
362   }
363  
364  
365 + printview()                     /* print our current view to server stdout */
366 + {
367 +        fputs(VIEWSTR, sstdout);
368 +        fprintview(&odev.v, sstdout);
369 +        fputc('\n', sstdout);
370 +        fflush(sstdout);
371 + }
372 +
373 +
374   int
375   serv_result()                   /* get next server result and process it */
376   {
# Line 192 | Line 405 | serv_result()                  /* get next server result and process
405                          error(INTERNAL, "bad holodeck record from server");
406                  add_holo((HDGRID *)buf);
407                  break;
408 +        case DS_OUTSECT:
409 +                do_outside = 1;
410 +                break;
411 +        case DS_EYESEP:
412 +                if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY)
413 +                        error(INTERNAL, "bad eye separation from server");
414 +                break;
415          case DS_STARTIMM:
416          case DS_ENDIMM:
417 + #ifdef DEBUG
418 +                if (imm_mode != (msg.type==DS_STARTIMM)) {
419 +                        time_t  tnow = time(NULL);
420 +                        if (imm_mode) timm += tnow - tmodesw;
421 +                        else tadd += tnow - tmodesw;
422 +                        tmodesw = tnow;
423 +                }
424 + #endif
425                  imm_mode = msg.type==DS_STARTIMM;
426                  /* fall through */
427          case DS_ACKNOW:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines