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.34 by gwlarson, Thu Nov 5 14:27:02 1998 UTC vs.
Revision 3.45 by greg, Tue May 13 17:58:33 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Holodeck display process.
6   */
# Line 18 | Line 15 | static char SCCSid[] = "$SunId$ SGI";
15   #define VIEWHISTLEN     4       /* number of remembered views */
16   #endif
17  
18 + #ifndef FSIZDEF
19 + #define FSIZDEF         0.125   /* default focus frame size */
20 + #endif
21 +
22 + #if defined(freebsd)
23 + #define fbufcnt(f)      ((f)->_r)
24 + #elif defined(__GNUC__)
25 + #define fbufcnt(f)      ((f)->_IO_read_end - (f)->_IO_read_ptr)
26 + #else
27 + #define fbufcnt(f)      ((f)->_cnt)
28 + #endif
29 +
30   HOLO    *hdlist[HDMAX+1];       /* global holodeck list */
31  
32 + char    *hdgfn[HDMAX];          /* holodeck section geometry list */
33 + char    *hdpfn[HDMAX];          /* section portal list */
34 +
35   char    cmdlist[DC_NCMDS][8] = DC_INIT;
36  
37   int     imm_mode = 0;           /* bundles are being delivered immediately */
# Line 33 | Line 45 | char   *progname;              /* global argv[0] */
45   FILE    *sstdin, *sstdout;      /* server's standard input and output */
46  
47   #ifdef DEBUG
36 #include <sys/types.h>
48   extern time_t   time();
49   static time_t   tmodesw;
50   static time_t   timm, tadd;
# Line 49 | Line 60 | main(argc, argv)
60   int     argc;
61   char    *argv[];
62   {
52        extern int      eputs();
63          int     rdy, inp, res = 0, pause = 0;
64  
65          progname = argv[0];
# Line 84 | Line 94 | char   *argv[];
94                          inp = dev_input();
95                          if (inp & DFL(DC_SETVIEW))
96                                  new_view(&odev.v);
97 +                        else if (inp & DFL(DC_LASTVIEW))
98 +                                new_view(NULL);
99 +                        if (inp & DFL(DC_REDRAW))
100 +                                imm_mode = beam_sync(1) > 0;
101                          if (inp & DFL(DC_GETVIEW))
102                                  printview();
103 <                        if (inp & DFL(DC_LASTVIEW))
104 <                                new_view(NULL);
103 >                        if (inp & DFL(DC_FOCUS))
104 >                                set_focus(odev_args);
105                          if (inp & DFL(DC_KILL)) {
106                                  serv_request(DR_KILL, 0, NULL);
107                                  pause = 0;
# Line 104 | Line 118 | char   *argv[];
118                          }
119                          if (inp & DFL(DC_PAUSE))
120                                  pause = 1;
107                        if (inp & DFL(DC_REDRAW))
108                                imm_mode = beam_sync(1) > 0;
121                          if (inp & DFL(DC_QUIT))
122                                  serv_request(DR_SHUTDOWN, 0, NULL);
123                  }
# Line 146 | Line 158 | disp_wait()                    /* wait for more input */
158          int     n;
159          register int    i;
160                                  /* see if we can avoid select call */
161 +        if (hdlist[0] == NULL)
162 +                return(RDY_SRV);        /* initialize first */
163          flgs = 0;               /* flag what's ready already */
164 <        if (imm_mode || stdin->_cnt > 0)
164 >        if (imm_mode || fbufcnt(stdin) > 0)
165                  flgs |= RDY_SRV;
166 <        if (sstdin != NULL && sstdin->_cnt > 0)
166 >        if (sstdin != NULL && fbufcnt(sstdin) > 0)
167                  flgs |= RDY_SIN;
168          if (odev.inpready)
169                  flgs |= RDY_DEV;
# Line 187 | Line 201 | disp_wait()                    /* wait for more input */
201   }
202  
203  
204 < add_holo(hdg)                   /* register a new holodeck section */
204 > add_holo(hdg, gfn, pfn)         /* register a new holodeck section */
205   HDGRID  *hdg;
206 + char    *gfn, *pfn;
207   {
208          VIEW    nv;
209          double  d;
# Line 201 | Line 216 | HDGRID *hdg;
216          hdlist[hd] = (HOLO *)malloc(sizeof(HOLO));
217          if (hdlist[hd] == NULL)
218                  error(SYSTEM, "out of memory in add_holo");
219 <        bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID));
219 >        bcopy((void *)hdg, (void *)hdlist[hd], sizeof(HDGRID));
220          hdcompgrid(hdlist[hd]);
221 +        hdgfn[hd] = savestr(gfn);
222 +        hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL;
223          if (hd)
224                  return;
225                                          /* set initial viewpoint */
# Line 258 | Line 275 | register VIEW  *v;
275          static unsigned nhist;
276          VIEW    *dv;
277          int     i, res[2];
278 +        int2    *slist;
279          char    *err;
280                                  /* restore previous view? */
281          if (v == NULL) {
# Line 273 | Line 291 | again:
291                  error(COMMAND, err);
292                  return;
293          }
294 +        if (!dev_view(v))       /* notify display driver */
295 +                goto again;
296          if (v->type == VT_PAR) {
297                  error(COMMAND, "cannot handle parallel views");
298                  return;
299          }
300 <        if (!dev_view(v))       /* notify display driver */
301 <                goto again;
302 <        dev_flush();            /* update screen */
283 <        beam_init(0);           /* compute new beam set */
284 <        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
285 <                if (!beam_view(dv, res[0], res[1])) {
300 >        beam_init(odev.firstuse);       /* compute new beam set */
301 >        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) {
302 >                if ((slist = beam_view(dv, res[0], res[1])) == NULL) {
303                          if (!nhist) {
304                                  error(COMMAND, "invalid starting view");
305                                  return;
306                          }
307                          copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN));
308 <                        goto again;
309 <                }      
308 >                        goto again;     /* poss. overloading dev_section()? */
309 >                }
310 >                DCHECK(*slist < 0, WARNING, "no visible sections in new_view");
311 >                for ( ; *slist >= 0; slist++)
312 >                        dev_section(hdgfn[*slist], hdpfn[*slist]);
313 >        }
314 >        dev_section(NULL,NULL); /* end section list */
315 >        dev_flush();            /* update display */
316                                  /* update server */
317 <        imm_mode = beam_sync(0) > 0;
317 >        imm_mode = beam_sync(odev.firstuse) > 0;
318                                  /* record new view */
319          if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
320                  copystruct(viewhist + (nhist%VIEWHISTLEN), v);
# Line 300 | Line 323 | again:
323   }
324  
325  
326 + set_focus(args)                 /* set focus frame */
327 + char    *args;
328 + {
329 +        double  hcent, vcent, hsiz, vsiz;
330 +        VIEW    *dv, vwfocus;
331 +        int     i, res[2];
332 +
333 +        i = sscanf(args, "%lf %lf %lf %lf", &hcent, &vcent, &hsiz, &vsiz);
334 +        if (i < 2 || hcent < 0 || hcent > 1 || vcent < 0 || vcent > 1) {
335 +                beam_init(0);                           /* restore view */
336 +                for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
337 +                        beam_view(dv, res[0], res[1]);
338 +                beam_sync(0);                           /* update server */
339 +                return;
340 +        }
341 +        if (i < 4 || hsiz <= hcent || hsiz > 1 || vsiz <= vcent || vsiz > 1)
342 +                hsiz = vsiz = FSIZDEF;                  /* gave center only */
343 +        else {
344 +                hsiz -= hcent; hcent += 0.5*hsiz;       /* gave min and max */
345 +                vsiz -= vcent; vcent += 0.5*vsiz;
346 +        }
347 +        beam_init(0);                                   /* add basic views */
348 +        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
349 +                beam_view(dv, res[0]>>4, res[1]>>4);
350 +        copystruct(&vwfocus, &odev.v);                  /* add focus view */
351 +        switch (odev.v.type) {
352 +        case VT_PER:
353 +                vwfocus.horiz = 2.*180./PI*atan(
354 +                                hsiz * tan(PI/180./2.*odev.v.horiz) );
355 +                vwfocus.vert = 2.*180./PI*atan(
356 +                                vsiz * tan(PI/180./2.*odev.v.vert) );
357 +                break;
358 +        case VT_PAR:
359 +        case VT_ANG:
360 +                vwfocus.horiz = hsiz * odev.v.horiz;
361 +                vwfocus.vert = vsiz * odev.v.vert;
362 +                break;
363 +        case VT_HEM:
364 +                vwfocus.horiz = 2.*180./PI*asin(
365 +                                hsiz * sin(PI/180./2.*odev.v.horiz) );
366 +                vwfocus.vert = 2.*180./PI*asin(
367 +                                vsiz * sin(PI/180./2.*odev.v.vert) );
368 +                break;
369 +        case VT_CYL:
370 +                vwfocus.horiz = hsiz * odev.v.horiz;
371 +                vwfocus.vert = 2.*180./PI*atan(
372 +                                vsiz * tan(PI/180./2.*odev.v.vert) );
373 +                break;
374 +        default:
375 +                error(INTERNAL, "bad view type in set_focus");
376 +        }
377 +        vwfocus.hoff = (odev.v.hoff + hcent - 0.5)/hsiz;
378 +        vwfocus.voff = (odev.v.voff + vcent - 0.5)/vsiz;
379 +        setview(&vwfocus);
380 +        beam_view(&vwfocus, (int)(3*odev.hres*hsiz)+100,
381 +                        (int)(3*odev.vres*vsiz)+100);
382 +        beam_sync(0);                                   /* update server */
383 + }
384 +
385 +
386   int
387   usr_input()                     /* get user input and process it */
388   {
# Line 342 | Line 425 | usr_input()                    /* get user input and process it */
425          case DC_LASTVIEW:               /* restore previous view */
426                  new_view(NULL);
427                  break;
428 +        case DC_FOCUS:                  /* set focus frame */
429 +                set_focus(args);
430 +                break;
431          case DC_PAUSE:                  /* pause the current calculation */
432          case DC_RESUME:                 /* resume the calculation */
433                  /* handled in main() */
# Line 393 | Line 479 | serv_result()                  /* get next server result and process
479                          if (buf == NULL)
480                                  buf = (char *)malloc(bufsiz=msg.nbytes);
481                          else
482 <                                buf = (char *)realloc(buf, bufsiz=msg.nbytes);
482 >                                buf = (char *)realloc((void *)buf,
483 >                                                bufsiz=msg.nbytes);
484                          if (buf == NULL)
485                                  error(SYSTEM, "out of memory in serv_result");
486                  }
# Line 408 | Line 495 | serv_result()                  /* get next server result and process
495                  disp_bundle((PACKHEAD *)buf);
496                  break;
497          case DS_ADDHOLO:
498 <                if (msg.nbytes != sizeof(HDGRID))
498 >                if (msg.nbytes < sizeof(HDGRID)+2)
499                          error(INTERNAL, "bad holodeck record from server");
500 <                add_holo((HDGRID *)buf);
500 >                add_holo((HDGRID *)buf, buf+sizeof(HDGRID),
501 >                        buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1);
502                  break;
503          case DS_OUTSECT:
504                  do_outside = 1;
# Line 421 | Line 509 | serv_result()                  /* get next server result and process
509                  break;
510          case DS_STARTIMM:
511          case DS_ENDIMM:
512 +                if (!(imm_mode = msg.type==DS_STARTIMM))
513 +                        dev_flush();
514   #ifdef DEBUG
515 <                if (imm_mode != (msg.type==DS_STARTIMM)) {
515 >                {
516                          time_t  tnow = time(NULL);
517 <                        if (imm_mode) timm += tnow - tmodesw;
518 <                        else tadd += tnow - tmodesw;
517 >                        if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw;
518 >                        else timm += tnow - tmodesw;
519                          tmodesw = tnow;
520                  }
521   #endif
432                if (!(imm_mode = msg.type==DS_STARTIMM))
433                        dev_flush();
522                  goto noargs;
523          case DS_ACKNOW:
524          case DS_SHUTDOWN:
# Line 460 | Line 548 | char   *p;
548          MSGHEAD msg;
549          int     m;
550                                  /* consistency checks */
551 < #ifdef DEBUG
552 <        if (nbytes < 0 || nbytes > 0 & p == NULL)
465 <                error(CONSISTENCY, "bad buffer handed to serv_request");
466 < #endif
551 >        DCHECK(nbytes < 0 || nbytes > 0 & p == NULL,
552 >                        CONSISTENCY, "bad buffer handed to serv_request");
553                                  /* get server's attention for big request */
554          if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) {
555                  serv_request(DR_ATTEN, 0, NULL);
# Line 481 | Line 567 | char   *p;
567   }
568  
569  
570 + void
571   eputs(s)                        /* put error message to stderr */
572   register char  *s;
573   {
# Line 500 | Line 587 | register char  *s;
587   }
588  
589  
590 + void
591   quit(code)                      /* clean up and exit */
592   int     code;
593   {
594 +        if (code)
595 +                exit(code);
596          if (odev.v.type)
597                  dev_close();
598 <        exit(code);
598 >        exit(0);
599   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines