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.14 by gregl, Fri Dec 12 11:13:15 1997 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     2       /* 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  
20 VIEW    dvw;                    /* our current display view */
21
27   char    *progname;              /* global argv[0] */
28  
29 < #define RDY_SRV 01
25 < #define RDY_DEV 02
29 > FILE    *sstdin, *sstdout;      /* server's standard input and output */
30  
31 + #define RDY_SRV         01
32 + #define RDY_DEV         02
33 + #define RDY_SIN         04
34  
35 +
36   main(argc, argv)
37   int     argc;
38   char    *argv[];
39   {
40 +        extern int      eputs();
41          int     rdy, inp, res = 0, pause = 0;
42  
43          progname = argv[0];
44 <        if (argc != 2)
44 >        if (argc < 3)
45                  error(USER, "bad command line arguments");
46                                          /* open our device */
47          dev_open(argv[1]);
48 +                                        /* open server process i/o */
49 +        sstdout = fdopen(atoi(argv[2]), "w");
50 +        if (argc < 4 || (inp = atoi(argv[3])) < 0)
51 +                sstdin = NULL;
52 +        else
53 +                sstdin = fdopen(inp, "r");
54 +                                        /* set command error vector */
55 +        erract[COMMAND].pf = eputs;
56                                          /* enter main loop */
57          do {
58                  rdy = disp_wait();
59 <                if (rdy & RDY_DEV) {            /* get user input */
59 >                if (rdy & RDY_DEV) {            /* user input from driver */
60                          inp = dev_input();
61 <                        if (inp & DEV_NEWVIEW)
61 >                        if (inp & DFL(DC_SETVIEW))
62                                  new_view(&odev.v);
63 <                        if (inp & DEV_SHUTDOWN)
64 <                                serv_request(DR_SHUTDOWN, 0, NULL);
65 <                        if (inp & DEV_REDRAW) {
66 <                                beam_sync();
67 <                                imm_mode = 1;   /* preempt updates */
51 <                        }
52 <                        if (inp & DEV_WAIT)
63 >                        if (inp & DFL(DC_GETVIEW))
64 >                                printview();
65 >                        if (inp & DFL(DC_LASTVIEW))
66 >                                new_view(NULL);
67 >                        if (inp & DFL(DC_PAUSE))
68                                  pause = 1;
69 <                        if (inp & DEV_RESUME) {
69 >                        if (inp & DFL(DC_RESUME)) {
70                                  serv_request(DR_NOOP, 0, NULL);
71                                  pause = 0;
72                          }
73 +                        if (inp & DFL(DC_REDRAW))
74 +                                imm_mode = beam_sync() > 0;
75 +                        if (inp & DFL(DC_KILL))
76 +                                serv_request(DR_KILL, 0, NULL);
77 +                        if (inp & DFL(DC_CLOBBER))
78 +                                serv_request(DR_CLOBBER, 0, NULL);
79 +                        if (inp & DFL(DC_RESTART))
80 +                                serv_request(DR_RESTART, 0, NULL);
81 +                        if (inp & DFL(DC_QUIT))
82 +                                serv_request(DR_SHUTDOWN, 0, NULL);
83                  }
84 <                if (rdy & RDY_SRV) {            /* get server result */
84 >                if (rdy & RDY_SIN)              /* user input from sstdin */
85 >                        switch (usr_input()) {
86 >                        case DC_PAUSE:
87 >                                pause = 1;
88 >                                break;
89 >                        case DC_RESUME:
90 >                                serv_request(DR_NOOP, 0, NULL);
91 >                                pause = 0;
92 >                                break;
93 >                        }
94 >                if (rdy & RDY_SRV) {            /* process server result */
95                          res = serv_result();
96                          if (pause && res != DS_SHUTDOWN) {
97                                  serv_request(DR_ATTEN, 0, NULL);
# Line 81 | Line 116 | disp_wait()                    /* wait for more input */
116                                  /* see if we can avoid select call */
117          if (imm_mode || stdin->_cnt > 0)
118                  return(RDY_SRV);
119 +        if (sstdin != NULL && sstdin->_cnt > 0)
120 +                return(RDY_SIN);
121          if (dev_flush())
122                  return(RDY_DEV);
123                                  /* make the call */
# Line 89 | Line 126 | disp_wait()                    /* wait for more input */
126          FD_SET(0, &errset);
127          FD_SET(odev.ifd, &readset);
128          FD_SET(odev.ifd, &errset);
129 <        n = odev.ifd + 1;
129 >        n = odev.ifd+1;
130 >        if (sstdin != NULL) {
131 >                FD_SET(fileno(sstdin), &readset);
132 >                if (fileno(sstdin) >= n)
133 >                        n = fileno(sstdin) + 1;
134 >        }
135          n = select(n, &readset, NULL, &errset, NULL);
136          if (n < 0) {
137                  if (errno == EINTR)
# Line 101 | Line 143 | disp_wait()                    /* wait for more input */
143                  flgs |= RDY_SRV;
144          if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset))
145                  flgs |= RDY_DEV;
146 +        if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset))
147 +                flgs |= RDY_SIN;
148          return(flgs);
149   }
150  
# Line 150 | Line 194 | register PACKHEAD      *p;
194                  hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r);
195                  d = hddepth(hdlist[p->hd], packra(p)[i].d);
196                  VSUM(wp, ro, rd, d);            /* might be behind viewpoint */
197 <                dev_value(packra(p)[i].v, wp);
197 >                dev_value(packra(p)[i].v, wp, rd);
198          }
199   }
200  
201  
202   new_view(v)                     /* change view parameters */
203 < VIEW    *v;
203 > register VIEW   *v;
204   {
205 +        static VIEW     viewhist[VIEWHISTLEN];
206 +        static unsigned nhist;
207          char    *err;
208 +                                /* restore previous view? */
209 +        if (v == NULL) {
210 +                if (nhist < 2) {
211 +                        error(COMMAND, "no previous view");
212 +                        return;
213 +                }
214 +                nhist--;        /* get one before last setting */
215 +                v = viewhist + ((nhist-1)%VIEWHISTLEN);
216 +        } else if ((err = setview(v)) != NULL) {
217 +                error(COMMAND, err);
218 +                return;
219 +        }
220 + again:
221 +        if (v->type == VT_PAR) {
222 +                error(COMMAND, "cannot handle parallel views");
223 +                return;
224 +        }
225 +        if (!dev_view(v))       /* update display driver */
226 +                goto again;
227 +        dev_flush();            /* update screen */
228 +        if (!beam_view(v))      /* update beam list */
229 +                goto again;
230 +                                /* record new view */
231 +        if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
232 +                copystruct(viewhist + (nhist%VIEWHISTLEN), v);
233 +                nhist++;
234 +        }
235 + }
236  
237 <        if ((err = setview(v)) != NULL)
238 <                error(INTERNAL, err);
239 <        dev_view(v);                    /* update display driver */
240 <        beam_view(&dvw, v);             /* update beam list */
241 <        copystruct(&dvw, v);            /* record new view */
237 >
238 > int
239 > usr_input()                     /* get user input and process it */
240 > {
241 >        VIEW    vparams;
242 >        char    cmd[128];
243 >        register char   *args;
244 >        register int    i;
245 >
246 >        if (fgets(cmd, sizeof(cmd), sstdin) == NULL)
247 >                return(DC_QUIT);
248 >        for (args = cmd; *args && !isspace(*args); args++)
249 >                ;
250 >        while (isspace(*args))
251 >                *args++ = '\0';
252 >        if (!*cmd)
253 >                return(DC_RESUME);
254 >        if (*args && args[i=strlen(args)-1] == '\n')
255 >                args[i] = '\0';
256 >        for (i = 0; i < DC_NCMDS; i++)
257 >                if (!strcmp(cmd, cmdlist[i]))
258 >                        break;
259 >        if (i >= DC_NCMDS) {
260 >                sprintf(errmsg, "unknown command: %s", cmd);
261 >                error(COMMAND, errmsg);
262 >                return(-1);
263 >        }
264 >        switch (i) {
265 >        case DC_SETVIEW:                /* set the view */
266 >                copystruct(&vparams, &odev.v);
267 >                if (!sscanview(&vparams, args))
268 >                        error(COMMAND, "missing view options");
269 >                else
270 >                        new_view(&vparams);
271 >                break;
272 >        case DC_GETVIEW:                /* print the current view */
273 >                printview();
274 >                break;
275 >        case DC_LASTVIEW:               /* restore previous view */
276 >                new_view(NULL);
277 >                break;
278 >        case DC_PAUSE:                  /* pause the current calculation */
279 >        case DC_RESUME:                 /* resume the calculation */
280 >                /* handled in main() */
281 >                break;
282 >        case DC_REDRAW:                 /* redraw from server */
283 >                imm_mode = beam_sync() > 0;
284 >                break;
285 >        case DC_KILL:                   /* kill rtrace process(es) */
286 >                serv_request(DR_KILL, 0, NULL);
287 >                break;
288 >        case DC_CLOBBER:                /* clobber holodeck */
289 >                serv_request(DR_CLOBBER, 0, NULL);
290 >                break;
291 >        case DC_RESTART:                /* restart rtrace */
292 >                serv_request(DR_RESTART, 0, NULL);
293 >                break;
294 >        case DC_QUIT:                   /* quit request */
295 >                serv_request(DR_SHUTDOWN, 0, NULL);
296 >                break;
297 >        default:
298 >                error(CONSISTENCY, "bad command id in usr_input");
299 >        }
300 >        return(i);
301   }
302  
303  
304 + printview()                     /* print our current view to server stdout */
305 + {
306 +        fputs(VIEWSTR, sstdout);
307 +        fprintview(&odev.v, sstdout);
308 +        fputc('\n', sstdout);
309 +        fflush(sstdout);
310 + }
311 +
312 +
313   int
314   serv_result()                   /* get next server result and process it */
315   {
# Line 205 | Line 347 | serv_result()                  /* get next server result and process
347          case DS_STARTIMM:
348          case DS_ENDIMM:
349                  imm_mode = msg.type==DS_STARTIMM;
350 +                if (msg.type == DS_ENDIMM)
351 +                        dev_flush();            /* update display NOW */
352                  /* fall through */
353          case DS_ACKNOW:
354          case DS_SHUTDOWN:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines