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.12 by gregl, Thu Dec 11 09:37:43 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_PUTVIEW)
62 +                                printview();
63                          if (inp & DEV_NEWVIEW)
64                                  new_view(&odev.v);
65 +                        if (inp & DEV_LASTVIEW)
66 +                                new_view(NULL);
67                          if (inp & DEV_SHUTDOWN)
68                                  serv_request(DR_SHUTDOWN, 0, NULL);
69 <                        if (inp & DEV_REDRAW) {
70 <                                beam_sync();
50 <                                imm_mode = 1;   /* preempt updates */
51 <                        }
69 >                        if (inp & DEV_REDRAW)
70 >                                imm_mode = beam_sync() > 0;
71                          if (inp & DEV_WAIT)
72                                  pause = 1;
73                          if (inp & DEV_RESUME) {
# Line 56 | Line 75 | char   *argv[];
75                                  pause = 0;
76                          }
77                  }
78 <                if (rdy & RDY_SRV) {            /* get server result */
78 >                if (rdy & RDY_SIN)              /* user input from sstdin */
79 >                        switch (usr_input()) {
80 >                        case DC_PAUSE:
81 >                                pause = 1;
82 >                                break;
83 >                        case DC_RESUME:
84 >                                serv_request(DR_NOOP, 0, NULL);
85 >                                pause = 0;
86 >                                break;
87 >                        }
88 >                if (rdy & RDY_SRV) {            /* process server result */
89                          res = serv_result();
90                          if (pause && res != DS_SHUTDOWN) {
91                                  serv_request(DR_ATTEN, 0, NULL);
# Line 81 | Line 110 | disp_wait()                    /* wait for more input */
110                                  /* see if we can avoid select call */
111          if (imm_mode || stdin->_cnt > 0)
112                  return(RDY_SRV);
113 +        if (sstdin != NULL && sstdin->_cnt > 0)
114 +                return(RDY_SIN);
115          if (dev_flush())
116                  return(RDY_DEV);
117                                  /* make the call */
# Line 89 | Line 120 | disp_wait()                    /* wait for more input */
120          FD_SET(0, &errset);
121          FD_SET(odev.ifd, &readset);
122          FD_SET(odev.ifd, &errset);
123 <        n = odev.ifd + 1;
123 >        n = odev.ifd+1;
124 >        if (sstdin != NULL) {
125 >                FD_SET(fileno(sstdin), &readset);
126 >                if (fileno(sstdin) >= n)
127 >                        n = fileno(sstdin) + 1;
128 >        }
129          n = select(n, &readset, NULL, &errset, NULL);
130          if (n < 0) {
131                  if (errno == EINTR)
# Line 101 | Line 137 | disp_wait()                    /* wait for more input */
137                  flgs |= RDY_SRV;
138          if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset))
139                  flgs |= RDY_DEV;
140 +        if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset))
141 +                flgs |= RDY_SIN;
142          return(flgs);
143   }
144  
# Line 150 | Line 188 | register PACKHEAD      *p;
188                  hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r);
189                  d = hddepth(hdlist[p->hd], packra(p)[i].d);
190                  VSUM(wp, ro, rd, d);            /* might be behind viewpoint */
191 <                dev_value(packra(p)[i].v, wp);
191 >                dev_value(packra(p)[i].v, wp, rd);
192          }
193   }
194  
195  
196   new_view(v)                     /* change view parameters */
197 < VIEW    *v;
197 > register VIEW   *v;
198   {
199 +        static VIEW     viewhist[VIEWHISTLEN];
200 +        static unsigned nhist;
201          char    *err;
202 +                                /* restore previous view? */
203 +        if (v == NULL) {
204 +                if (nhist < 2) {
205 +                        error(COMMAND, "no previous view");
206 +                        return;
207 +                }
208 +                nhist--;        /* get one before last setting */
209 +                v = viewhist + ((nhist-1)%VIEWHISTLEN);
210 +        } else if ((err = setview(v)) != NULL) {
211 +                error(COMMAND, err);
212 +                return;
213 +        }
214 + again:
215 +        if (v->type == VT_PAR) {
216 +                error(COMMAND, "cannot handle parallel views");
217 +                return;
218 +        }
219 +        if (!dev_view(v))       /* update display driver */
220 +                goto again;
221 +        dev_flush();            /* update screen */
222 +        if (!beam_view(v))      /* update beam list */
223 +                goto again;
224 +                                /* record new view */
225 +        if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
226 +                copystruct(viewhist + (nhist%VIEWHISTLEN), v);
227 +                nhist++;
228 +        }
229 + }
230  
231 <        if ((err = setview(v)) != NULL)
232 <                error(INTERNAL, err);
233 <        dev_view(v);                    /* update display driver */
234 <        beam_view(&dvw, v);             /* update beam list */
235 <        copystruct(&dvw, v);            /* record new view */
231 >
232 > int
233 > usr_input()                     /* get user input and process it */
234 > {
235 >        VIEW    vparams;
236 >        char    cmd[128];
237 >        register char   *args;
238 >        register int    i;
239 >
240 >        if (fgets(cmd, sizeof(cmd), sstdin) == NULL)
241 >                return(DC_QUIT);
242 >        for (args = cmd; *args && !isspace(*args); args++)
243 >                ;
244 >        while (isspace(*args))
245 >                *args++ = '\0';
246 >        if (!*cmd)
247 >                return(DC_RESUME);
248 >        if (*args && args[i=strlen(args)-1] == '\n')
249 >                args[i] = '\0';
250 >        for (i = 0; i < DC_NCMDS; i++)
251 >                if (!strcmp(cmd, cmdlist[i]))
252 >                        break;
253 >        if (i >= DC_NCMDS) {
254 >                sprintf(errmsg, "unknown command: %s", cmd);
255 >                error(COMMAND, errmsg);
256 >                return(-1);
257 >        }
258 >        switch (i) {
259 >        case DC_SETVIEW:                /* set the view */
260 >                copystruct(&vparams, &odev.v);
261 >                if (!sscanview(&vparams, args))
262 >                        error(COMMAND, "missing view options");
263 >                else
264 >                        new_view(&vparams);
265 >                break;
266 >        case DC_GETVIEW:                /* print the current view */
267 >                printview();
268 >                break;
269 >        case DC_LASTVIEW:               /* restore previous view */
270 >                new_view(NULL);
271 >                break;
272 >        case DC_PAUSE:                  /* pause the current calculation */
273 >        case DC_RESUME:                 /* resume the calculation */
274 >                /* handled in main() */
275 >                break;
276 >        case DC_QUIT:                   /* quit request */
277 >                serv_request(DR_SHUTDOWN, 0, NULL);
278 >                break;
279 >        default:
280 >                error(CONSISTENCY, "bad command id in usr_input");
281 >        }
282 >        return(i);
283   }
284  
285  
286 + printview()                     /* print our current view to server stdout */
287 + {
288 +        fputs(VIEWSTR, sstdout);
289 +        fprintview(&odev.v, sstdout);
290 +        fputc('\n', sstdout);
291 +        fflush(sstdout);
292 + }
293 +
294 +
295   int
296   serv_result()                   /* get next server result and process it */
297   {
# Line 205 | Line 329 | serv_result()                  /* get next server result and process
329          case DS_STARTIMM:
330          case DS_ENDIMM:
331                  imm_mode = msg.type==DS_STARTIMM;
332 +                if (msg.type == DS_ENDIMM)
333 +                        dev_flush();            /* update display NOW */
334                  /* fall through */
335          case DS_ACKNOW:
336          case DS_SHUTDOWN:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines