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.25 by gwlarson, Fri May 22 08:30:40 1998 UTC vs.
Revision 3.40 by gwlarson, Thu Mar 4 10:14:52 1999 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines