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.24 by gwlarson, Thu May 14 13:06:32 1998 UTC vs.
Revision 3.41 by gwlarson, Mon Mar 8 17:31:49 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1998 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ SGI";
18   #define VIEWHISTLEN     4       /* number of remembered views */
19   #endif
20  
21 + #ifndef FSIZDEF
22 + #define FSIZDEF         0.125   /* default focus frame size */
23 + #endif
24 +
25   HOLO    *hdlist[HDMAX+1];       /* global holodeck list */
26  
27 + char    *hdgfn[HDMAX];          /* holodeck section geometry list */
28 + char    *hdpfn[HDMAX];          /* section portal list */
29 +
30   char    cmdlist[DC_NCMDS][8] = DC_INIT;
31  
32   int     imm_mode = 0;           /* bundles are being delivered immediately */
33  
34   int     do_outside = 0;         /* render from outside sections */
35  
36 + double  eyesepdist = 1;         /* eye separation distance */
37 +
38   char    *progname;              /* global argv[0] */
39  
40   FILE    *sstdin, *sstdout;      /* server's standard input and output */
41  
42   #ifdef DEBUG
34 #include <sys/types.h>
43   extern time_t   time();
44   static time_t   tmodesw;
45   static time_t   timm, tadd;
# Line 82 | Line 90 | char   *argv[];
90                          inp = dev_input();
91                          if (inp & DFL(DC_SETVIEW))
92                                  new_view(&odev.v);
93 <                        if (inp & DFL(DC_GETVIEW))
86 <                                printview();
87 <                        if (inp & DFL(DC_LASTVIEW))
93 >                        else if (inp & DFL(DC_LASTVIEW))
94                                  new_view(NULL);
89                        if (inp & DFL(DC_RESUME)) {
90                                serv_request(DR_NOOP, 0, NULL);
91                                pause = 0;
92                        }
93                        if (inp & DFL(DC_PAUSE))
94                                pause = 1;
95                          if (inp & DFL(DC_REDRAW))
96                                  imm_mode = beam_sync(1) > 0;
97 +                        if (inp & DFL(DC_GETVIEW))
98 +                                printview();
99 +                        if (inp & DFL(DC_FOCUS))
100 +                                set_focus(odev_args);
101                          if (inp & DFL(DC_KILL)) {
102                                  serv_request(DR_KILL, 0, NULL);
103                                  pause = 0;
# Line 104 | Line 108 | char   *argv[];
108                                  serv_request(DR_RESTART, 0, NULL);
109                                  pause = 0;
110                          }
111 +                        if (inp & DFL(DC_RESUME)) {
112 +                                serv_request(DR_NOOP, 0, NULL);
113 +                                pause = 0;
114 +                        }
115 +                        if (inp & DFL(DC_PAUSE))
116 +                                pause = 1;
117                          if (inp & DFL(DC_QUIT))
118                                  serv_request(DR_SHUTDOWN, 0, NULL);
119                  }
120 <                if (rdy & RDY_SIN)              /* user input from sstdin */
120 >                if (rdy & RDY_SIN && !imm_mode) /* user input from sstdin */
121                          switch (usr_input()) {
122                          case DC_PAUSE:
123                                  pause = 1;
# Line 144 | Line 154 | disp_wait()                    /* wait for more input */
154          int     n;
155          register int    i;
156                                  /* see if we can avoid select call */
157 +        if (hdlist[0] == NULL)
158 +                return(RDY_SRV);        /* initialize first */
159 +        flgs = 0;               /* flag what's ready already */
160          if (imm_mode || stdin->_cnt > 0)
161 <                return(RDY_SRV);
161 >                flgs |= RDY_SRV;
162          if (sstdin != NULL && sstdin->_cnt > 0)
163 <                return(RDY_SIN);
164 <        if (dev_flush())
163 >                flgs |= RDY_SIN;
164 >        if (odev.inpready)
165 >                flgs |= RDY_DEV;
166 >        if (flgs)               /* got something? */
167 >                return(flgs);
168 >        if (dev_flush())        /* else flush output & check keyboard+mouse */
169                  return(RDY_DEV);
170 <                                /* make the call */
170 >                                /* if nothing, we need to call select */
171          FD_ZERO(&readset); FD_ZERO(&errset);
172          FD_SET(0, &readset);
173          FD_SET(0, &errset);
# Line 169 | Line 186 | disp_wait()                    /* wait for more input */
186                          return(0);
187                  error(SYSTEM, "select call failure in disp_wait");
188          }
172        flgs = 0;               /* flag what's ready */
189          if (FD_ISSET(0, &readset) || FD_ISSET(0, &errset))
190                  flgs |= RDY_SRV;
191          if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset))
# Line 181 | Line 197 | disp_wait()                    /* wait for more input */
197   }
198  
199  
200 < add_holo(hdg)                   /* register a new holodeck section */
200 > add_holo(hdg, gfn, pfn)         /* register a new holodeck section */
201   HDGRID  *hdg;
202 + char    *gfn, *pfn;
203   {
204          VIEW    nv;
205          double  d;
# Line 197 | Line 214 | HDGRID *hdg;
214                  error(SYSTEM, "out of memory in add_holo");
215          bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID));
216          hdcompgrid(hdlist[hd]);
217 +        hdgfn[hd] = savestr(gfn);
218 +        hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL;
219          if (hd)
220                  return;
221                                          /* set initial viewpoint */
# Line 232 | Line 251 | register PACKHEAD      *p;
251          for (i = p->nr; i--; ) {
252                  hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r);
253                  d = hddepth(hdlist[p->hd], packra(p)[i].d);
254 <                VSUM(wp, ro, rd, d);            /* might be behind viewpoint */
255 <                dev_value(packra(p)[i].v, wp, rd);
254 >                if (d < .99*FHUGE) {
255 >                        VSUM(wp, ro, rd, d);    /* might be behind viewpoint */
256 >                        dev_value(packra(p)[i].v, rd, wp);
257 >                } else
258 >                        dev_value(packra(p)[i].v, rd, NULL);
259          }
260   #ifdef DEBUG
261          if (imm_mode) nimmrays += p->nr;
# Line 249 | Line 271 | register VIEW  *v;
271          static unsigned nhist;
272          VIEW    *dv;
273          int     i, res[2];
274 +        int2    *slist;
275          char    *err;
276                                  /* restore previous view? */
277          if (v == NULL) {
# Line 264 | Line 287 | again:
287                  error(COMMAND, err);
288                  return;
289          }
290 +        if (!dev_view(v))       /* notify display driver */
291 +                goto again;
292          if (v->type == VT_PAR) {
293                  error(COMMAND, "cannot handle parallel views");
294                  return;
295          }
296 <        if (!dev_view(v))       /* notify display driver */
297 <                goto again;
298 <        dev_flush();            /* update screen */
274 <        beam_init();            /* compute new beam set */
275 <        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
276 <                if (!beam_view(dv, res[0], res[1])) {
296 >        beam_init(odev.firstuse);       /* compute new beam set */
297 >        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) {
298 >                if ((slist = beam_view(dv, res[0], res[1])) == NULL) {
299                          if (!nhist) {
300                                  error(COMMAND, "invalid starting view");
301                                  return;
302                          }
303                          copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN));
304 <                        goto again;
304 >                        goto again;     /* poss. overloading dev_section()? */
305                  }
306 <        beam_sync(0);           /* update server */
306 >                DCHECK(*slist < 0, WARNING, "no visible sections in new_view");
307 >                for ( ; *slist >= 0; slist++)
308 >                        dev_section(hdgfn[*slist], hdpfn[*slist]);
309 >        }
310 >        dev_section(NULL,NULL); /* end section list */
311 >        dev_flush();            /* update display */
312 >                                /* update server */
313 >        imm_mode = beam_sync(odev.firstuse) > 0;
314                                  /* record new view */
315          if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
316                  copystruct(viewhist + (nhist%VIEWHISTLEN), v);
# Line 290 | Line 319 | again:
319   }
320  
321  
322 + set_focus(args)                 /* set focus frame */
323 + char    *args;
324 + {
325 +        double  hcent, vcent, hsiz, vsiz;
326 +        VIEW    *dv, vwfocus;
327 +        int     i, res[2];
328 +
329 +        i = sscanf(args, "%lf %lf %lf %lf", &hcent, &vcent, &hsiz, &vsiz);
330 +        if (i < 2 || hcent < 0 || hcent > 1 || vcent < 0 || vcent > 1) {
331 +                beam_init(0);                           /* restore view */
332 +                for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
333 +                        beam_view(dv, res[0], res[1]);
334 +                beam_sync(0);                           /* update server */
335 +                return;
336 +        }
337 +        if (i < 4 || hsiz <= hcent || hsiz > 1 || vsiz <= vcent || vsiz > 1)
338 +                hsiz = vsiz = FSIZDEF;                  /* gave center only */
339 +        else {
340 +                hsiz -= hcent; hcent += 0.5*hsiz;       /* gave min and max */
341 +                vsiz -= vcent; vcent += 0.5*vsiz;
342 +        }
343 +        beam_init(0);                                   /* add basic views */
344 +        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
345 +                beam_view(dv, res[0]>>4, res[1]>>4);
346 +        copystruct(&vwfocus, &odev.v);                  /* add focus view */
347 +        switch (odev.v.type) {
348 +        case VT_PER:
349 +                vwfocus.horiz = 2.*180./PI*atan(
350 +                                hsiz * tan(PI/180./2.*odev.v.horiz) );
351 +                vwfocus.vert = 2.*180./PI*atan(
352 +                                vsiz * tan(PI/180./2.*odev.v.vert) );
353 +                break;
354 +        case VT_PAR:
355 +        case VT_ANG:
356 +                vwfocus.horiz = hsiz * odev.v.horiz;
357 +                vwfocus.vert = vsiz * odev.v.vert;
358 +                break;
359 +        case VT_HEM:
360 +                vwfocus.horiz = 2.*180./PI*asin(
361 +                                hsiz * sin(PI/180./2.*odev.v.horiz) );
362 +                vwfocus.vert = 2.*180./PI*asin(
363 +                                vsiz * sin(PI/180./2.*odev.v.vert) );
364 +                break;
365 +        case VT_CYL:
366 +                vwfocus.horiz = hsiz * odev.v.horiz;
367 +                vwfocus.vert = 2.*180./PI*atan(
368 +                                vsiz * tan(PI/180./2.*odev.v.vert) );
369 +                break;
370 +        default:
371 +                error(INTERNAL, "bad view type in set_focus");
372 +        }
373 +        vwfocus.hoff = (odev.v.hoff + hcent - 0.5)/hsiz;
374 +        vwfocus.voff = (odev.v.voff + vcent - 0.5)/vsiz;
375 +        setview(&vwfocus);
376 +        beam_view(&vwfocus, (int)(3*odev.hres*hsiz)+100,
377 +                        (int)(3*odev.vres*vsiz)+100);
378 +        beam_sync(0);                                   /* update server */
379 + }
380 +
381 +
382   int
383   usr_input()                     /* get user input and process it */
384   {
# Line 301 | Line 390 | usr_input()                    /* get user input and process it */
390          if (fgets(cmd, sizeof(cmd), sstdin) == NULL) {
391                  fclose(sstdin);
392                  sstdin = NULL;
393 <                return(0);
393 >                return(-1);
394          }
395 +        if (*cmd == '\n')
396 +                return(DC_RESUME);
397          for (args = cmd; *args && !isspace(*args); args++)
398                  ;
399          while (isspace(*args))
400                  *args++ = '\0';
310        if (!*cmd)
311                return(DC_RESUME);
401          if (*args && args[i=strlen(args)-1] == '\n')
402                  args[i] = '\0';
403          for (i = 0; i < DC_NCMDS; i++)
404                  if (!strcmp(cmd, cmdlist[i]))
405                          break;
406          if (i >= DC_NCMDS) {
407 <                sprintf(errmsg, "unknown command: %s", cmd);
319 <                error(COMMAND, errmsg);
407 >                dev_auxcom(cmd, args);
408                  return(-1);
409          }
410          switch (i) {
# Line 333 | Line 421 | usr_input()                    /* get user input and process it */
421          case DC_LASTVIEW:               /* restore previous view */
422                  new_view(NULL);
423                  break;
424 +        case DC_FOCUS:                  /* set focus frame */
425 +                set_focus(args);
426 +                break;
427          case DC_PAUSE:                  /* pause the current calculation */
428          case DC_RESUME:                 /* resume the calculation */
429                  /* handled in main() */
# Line 399 | Line 490 | serv_result()                  /* get next server result and process
490                  disp_bundle((PACKHEAD *)buf);
491                  break;
492          case DS_ADDHOLO:
493 <                if (msg.nbytes != sizeof(HDGRID))
493 >                if (msg.nbytes < sizeof(HDGRID)+2)
494                          error(INTERNAL, "bad holodeck record from server");
495 <                add_holo((HDGRID *)buf);
495 >                add_holo((HDGRID *)buf, buf+sizeof(HDGRID),
496 >                        buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1);
497                  break;
498          case DS_OUTSECT:
499                  do_outside = 1;
500 +                goto noargs;
501 +        case DS_EYESEP:
502 +                if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY)
503 +                        error(INTERNAL, "bad eye separation from server");
504                  break;
505          case DS_STARTIMM:
506          case DS_ENDIMM:
507 +                if (!(imm_mode = msg.type==DS_STARTIMM))
508 +                        dev_flush();
509   #ifdef DEBUG
510 <                if (imm_mode != (msg.type==DS_STARTIMM)) {
510 >                {
511                          time_t  tnow = time(NULL);
512 <                        if (imm_mode) timm += tnow - tmodesw;
513 <                        else tadd += tnow - tmodesw;
512 >                        if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw;
513 >                        else timm += tnow - tmodesw;
514                          tmodesw = tnow;
515                  }
516   #endif
517 <                imm_mode = msg.type==DS_STARTIMM;
420 <                /* fall through */
517 >                goto noargs;
518          case DS_ACKNOW:
519          case DS_SHUTDOWN:
520 <                if (msg.nbytes) {
424 <                        sprintf(errmsg,
425 <                                "unexpected body with server message %d",
426 <                                        msg.type);
427 <                        error(INTERNAL, errmsg);
428 <                }
429 <                break;
520 >                goto noargs;
521          default:
522                  error(INTERNAL, "unrecognized result from server process");
523          }
524          return(msg.type);               /* return message type */
525 + noargs:
526 +        if (msg.nbytes) {
527 +                sprintf(errmsg, "unexpected body with server message %d",
528 +                                msg.type);
529 +                error(INTERNAL, errmsg);
530 +        }
531 +        return(msg.type);
532   readerr:
533          if (feof(stdin))
534                  error(SYSTEM, "server process died");
# Line 444 | Line 542 | char   *p;
542   {
543          MSGHEAD msg;
544          int     m;
545 +                                /* consistency checks */
546 +        DCHECK(nbytes < 0 || nbytes > 0 & p == NULL,
547 +                        CONSISTENCY, "bad buffer handed to serv_request");
548                                  /* get server's attention for big request */
549          if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) {
550                  serv_request(DR_ATTEN, 0, NULL);
# Line 483 | Line 584 | register char  *s;
584   quit(code)                      /* clean up and exit */
585   int     code;
586   {
587 +        if (code)
588 +                exit(code);
589          if (odev.v.type)
590                  dev_close();
591 <        exit(code);
591 >        exit(0);
592   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines