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.11 by gregl, Tue Dec 9 17:12: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   HOLO    *hdlist[HDMAX+1];       /* global holodeck list */
18  
19 + char    cmdlist[DC_NCMDS][8] = DC_INIT;
20 +
21   int     imm_mode = 0;           /* bundles are being delivered immediately */
22  
20 VIEW    dvw;                    /* our current display view */
21
23   char    *progname;              /* global argv[0] */
24  
25 < #define SERV_READY      01
25 < #define DEV_READY       02
25 > FILE    *sstdin, *sstdout;      /* server's standard input and output */
26  
27 + #define RDY_SRV         01
28 + #define RDY_DEV         02
29 + #define RDY_SIN         04
30  
31 +
32   main(argc, argv)
33   int     argc;
34   char    *argv[];
35   {
36 <        int     rdy, inp, res = 0;
36 >        extern int      eputs();
37 >        int     rdy, inp, res = 0, pause = 0;
38  
39          progname = argv[0];
40 <        if (argc != 2)
40 >        if (argc < 3)
41                  error(USER, "bad command line arguments");
42                                          /* open our device */
43          dev_open(argv[1]);
44 +                                        /* open server process i/o */
45 +        sstdout = fdopen(atoi(argv[2]), "w");
46 +        if (argc < 4 || (inp = atoi(argv[3])) < 0)
47 +                sstdin = NULL;
48 +        else
49 +                sstdin = fdopen(inp, "r");
50 +                                        /* set command error vector */
51 +        erract[COMMAND].pf = eputs;
52                                          /* enter main loop */
53          do {
54                  rdy = disp_wait();
55 <                while (rdy & DEV_READY) {
56 <                        inp = dev_input();      /* take residual action here */
55 >                if (rdy & RDY_DEV) {            /* user input from driver */
56 >                        inp = dev_input();
57 >                        if (inp & DEV_PUTVIEW)
58 >                                printview();
59                          if (inp & DEV_NEWVIEW)
60                                  new_view(&odev.v);
61                          if (inp & DEV_SHUTDOWN)
62                                  serv_request(DR_SHUTDOWN, 0, NULL);
63 +                        if (inp & DEV_REDRAW) {
64 +                                imm_mode = 1;   /* preempt updates */
65 +                                beam_sync();
66 +                        }
67                          if (inp & DEV_WAIT)
68 <                                serv_request(DR_ATTEN, 0, NULL);
69 <                        else
70 <                                rdy &= ~DEV_READY;
68 >                                pause = 1;
69 >                        if (inp & DEV_RESUME) {
70 >                                serv_request(DR_NOOP, 0, NULL);
71 >                                pause = 0;
72 >                        }
73                  }
74 <                if (rdy & SERV_READY) {
75 <                        res = serv_result();    /* processes result, also */
76 <                        if (res == DS_ACKNOW)
74 >                if (rdy & RDY_SIN)              /* user input from sstdin */
75 >                        switch (usr_input()) {
76 >                        case DC_PAUSE:
77 >                                pause = 1;
78 >                                break;
79 >                        case DC_RESUME:
80                                  serv_request(DR_NOOP, 0, NULL);
81 +                                pause = 0;
82 +                                break;
83 +                        }
84 +                if (rdy & RDY_SRV) {            /* process server result */
85 +                        res = serv_result();
86 +                        if (pause && res != DS_SHUTDOWN) {
87 +                                serv_request(DR_ATTEN, 0, NULL);
88 +                                while ((res = serv_result()) != DS_ACKNOW &&
89 +                                                res != DS_SHUTDOWN)
90 +                                        ;
91 +                        }
92                  }
93          } while (res != DS_SHUTDOWN);
94                                          /* all done */
# Line 70 | Line 105 | disp_wait()                    /* wait for more input */
105          register int    i;
106                                  /* see if we can avoid select call */
107          if (imm_mode || stdin->_cnt > 0)
108 <                return(SERV_READY);
108 >                return(RDY_SRV);
109 >        if (sstdin != NULL && sstdin->_cnt > 0)
110 >                return(RDY_SIN);
111          if (dev_flush())
112 <                return(DEV_READY);
112 >                return(RDY_DEV);
113                                  /* make the call */
114          FD_ZERO(&readset); FD_ZERO(&errset);
115          FD_SET(0, &readset);
116          FD_SET(0, &errset);
117          FD_SET(odev.ifd, &readset);
118          FD_SET(odev.ifd, &errset);
119 <        n = odev.ifd + 1;
119 >        n = odev.ifd+1;
120 >        if (sstdin != NULL) {
121 >                FD_SET(fileno(sstdin), &readset);
122 >                if (fileno(sstdin) >= n)
123 >                        n = fileno(sstdin) + 1;
124 >        }
125          n = select(n, &readset, NULL, &errset, NULL);
126          if (n < 0) {
127                  if (errno == EINTR)
# Line 88 | Line 130 | disp_wait()                    /* wait for more input */
130          }
131          flgs = 0;               /* flag what's ready */
132          if (FD_ISSET(0, &readset) || FD_ISSET(0, &errset))
133 <                flgs |= SERV_READY;
133 >                flgs |= RDY_SRV;
134          if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset))
135 <                flgs |= DEV_READY;
135 >                flgs |= RDY_DEV;
136 >        if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset))
137 >                flgs |= RDY_SIN;
138          return(flgs);
139   }
140  
# Line 140 | Line 184 | register PACKHEAD      *p;
184                  hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r);
185                  d = hddepth(hdlist[p->hd], packra(p)[i].d);
186                  VSUM(wp, ro, rd, d);            /* might be behind viewpoint */
187 <                dev_value(packra(p)[i].v, wp);
187 >                dev_value(packra(p)[i].v, wp, rd);
188          }
189   }
190  
# Line 150 | Line 194 | VIEW   *v;
194   {
195          char    *err;
196  
197 <        if ((err = setview(v)) != NULL)
198 <                error(INTERNAL, err);
199 <        dev_view(v);                    /* update display driver */
200 <        beam_view(&dvw, v);             /* update beam list */
201 <        copystruct(&dvw, v);            /* record new view */
197 >        do {
198 >                if ((err = setview(v)) != NULL) {
199 >                        error(COMMAND, err);
200 >                        return;
201 >                }
202 >                if (v->type == VT_PAR) {
203 >                        error(COMMAND, "cannot handle parallel views");
204 >                        return;
205 >                }
206 >                dev_view(v);            /* update display driver */
207 >                dev_flush();            /* update screen */
208 >        } while (!beam_view(v));        /* update beam list */
209   }
210  
211  
212   int
213 + usr_input()                     /* get user input and process it */
214 + {
215 +        VIEW    vparams;
216 +        char    cmd[128];
217 +        register char   *args;
218 +        register int    i;
219 +
220 +        if (fgets(cmd, sizeof(cmd), sstdin) == NULL)
221 +                return(DC_QUIT);
222 +        for (args = cmd; *args && !isspace(*args); args++)
223 +                ;
224 +        while (isspace(*args))
225 +                *args++ = '\0';
226 +        if (!*cmd)
227 +                return(DC_RESUME);
228 +        if (*args && args[i=strlen(args)-1] == '\n')
229 +                args[i] = '\0';
230 +        for (i = 0; i < DC_NCMDS; i++)
231 +                if (!strcmp(cmd, cmdlist[i]))
232 +                        break;
233 +        if (i >= DC_NCMDS) {
234 +                sprintf(errmsg, "unknown command: %s", cmd);
235 +                error(COMMAND, errmsg);
236 +                return(-1);
237 +        }
238 +        switch (i) {
239 +        case DC_SETVIEW:                /* set the view */
240 +                copystruct(&vparams, &odev.v);
241 +                if (!sscanview(&vparams, args))
242 +                        error(COMMAND, "missing view options");
243 +                else
244 +                        new_view(&vparams);
245 +                break;
246 +        case DC_GETVIEW:                /* print the current view */
247 +                printview();
248 +                break;
249 +        case DC_PAUSE:                  /* pause the current calculation */
250 +        case DC_RESUME:                 /* resume the calculation */
251 +                /* handled in main() */
252 +                break;
253 +        case DC_QUIT:                   /* quit request */
254 +                serv_request(DR_SHUTDOWN, 0, NULL);
255 +                break;
256 +        default:
257 +                error(CONSISTENCY, "bad command id in usr_input");
258 +        }
259 +        return(i);
260 + }
261 +
262 +
263 + printview()                     /* print our current view to server stdout */
264 + {
265 +        fputs(VIEWSTR, sstdout);
266 +        fprintview(&odev.v, sstdout);
267 +        fputc('\n', sstdout);
268 +        fflush(sstdout);
269 + }
270 +
271 +
272 + int
273   serv_result()                   /* get next server result and process it */
274   {
275          static char     *buf = NULL;
# Line 195 | Line 306 | serv_result()                  /* get next server result and process
306          case DS_STARTIMM:
307          case DS_ENDIMM:
308                  imm_mode = msg.type==DS_STARTIMM;
309 +                if (msg.type == DS_ENDIMM)
310 +                        dev_flush();            /* update display NOW */
311                  /* fall through */
312          case DS_ACKNOW:
313          case DS_SHUTDOWN:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines