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.10 by gregl, Mon Dec 8 18:51:15 1997 UTC vs.
Revision 3.22 by gregl, Tue Jan 6 05:26:20 1998 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ SGI";
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 + int     do_outside = 0;         /* render from outside sections */
28 +
29   char    *progname;              /* global argv[0] */
30  
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
# Line 49 | Line 63 | char   *argv[];
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_SRV) {            /* process server result */
73 +                        res = serv_result();
74 +                        if (pause && res != DS_SHUTDOWN) {
75 +                                serv_request(DR_ATTEN, 0, NULL);
76 +                                while ((res = serv_result()) != DS_ACKNOW &&
77 +                                                res != DS_SHUTDOWN)
78 +                                        ;
79 +                        }
80 +                }
81                  if (rdy & RDY_DEV) {            /* user input from driver */
82                          inp = dev_input();
83 <                        if (inp & DEV_PUTVIEW)
58 <                                printview();
59 <                        if (inp & DEV_NEWVIEW)
83 >                        if (inp & DFL(DC_SETVIEW))
84                                  new_view(&odev.v);
85 <                        if (inp & DEV_SHUTDOWN)
86 <                                serv_request(DR_SHUTDOWN, 0, NULL);
87 <                        if (inp & DEV_REDRAW) {
88 <                                imm_mode = 1;   /* preempt updates */
89 <                                beam_sync();
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 & DEV_WAIT)
93 >                        if (inp & DFL(DC_PAUSE))
94                                  pause = 1;
95 <                        if (inp & DEV_RESUME) {
96 <                                serv_request(DR_NOOP, 0, NULL);
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()) {
# Line 78 | Line 114 | char   *argv[];
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                          }
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                }
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 143 | 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 163 | 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 186 | Line 233 | register PACKHEAD      *p;
233                  VSUM(wp, ro, rd, d);            /* might be behind viewpoint */
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 <
250 <        do {
251 <                if ((err = setview(v)) != NULL) {
252 <                        error(COMMAND, err);
253 <                        return;
254 <                }
255 <                if (v->type == VT_PAR) {
256 <                        error(COMMAND, "cannot handle parallel views");
257 <                        return;
258 <                }
259 <                dev_view(v);            /* update display driver */
260 <                dev_flush();            /* update screen */
261 <        } while (!beam_view(v));        /* update beam list */
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  
# Line 215 | Line 283 | usr_input()                    /* get user input and process it */
283          VIEW    vparams;
284          char    cmd[128];
285          register char   *args;
286 <        register int    cmdno;
286 >        register int    i;
287  
288          if (fgets(cmd, sizeof(cmd), sstdin) == NULL)
289                  return(DC_QUIT);
# Line 225 | Line 293 | usr_input()                    /* get user input and process it */
293                  *args++ = '\0';
294          if (!*cmd)
295                  return(DC_RESUME);
296 <        for (cmdno = 0; cmdno < DC_NCMDS; cmdno++)
297 <                if (!strcmp(cmd, cmdlist[cmdno]))
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 (cmdno >= DC_NCMDS) {
301 >        if (i >= DC_NCMDS) {
302                  sprintf(errmsg, "unknown command: %s", cmd);
303                  error(COMMAND, errmsg);
304                  return(-1);
305          }
306 <        switch (cmdno) {
306 >        switch (i) {
307          case DC_SETVIEW:                /* set the view */
308                  copystruct(&vparams, &odev.v);
309                  if (!sscanview(&vparams, args))
# Line 244 | Line 314 | usr_input()                    /* get user input and process it */
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(cmdno);
258 <                
343 >        return(i);
344   }
345  
346  
# Line 302 | 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;
308                if (msg.type == DS_ENDIMM)
309                        dev_flush();            /* update display NOW */
404                  /* fall through */
405          case DS_ACKNOW:
406          case DS_SHUTDOWN:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines