ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/holofile.c
(Generate patch)

Comparing ray/src/hd/holofile.c (file contents):
Revision 3.8 by gregl, Tue Nov 11 11:31:54 1997 UTC vs.
Revision 3.10 by gregl, Thu Dec 11 11:29:35 1997 UTC

# Line 435 | Line 435 | register int   i;
435                          nchanged += hdfreebeam(hdlist[i], 0);
436                  return(nchanged);
437          }
438 +        if (hp->fd < 0)                 /* check for recursive error */
439 +                return(-1);
440          if (i == 0) {                   /* clear entire holodeck */
441                  nchanged = 0;
442 <                for (i = 1; i <= nbeams(hp); i++)
443 <                        nchanged += hdfreebeam(hp, i);
442 >                for (i = nbeams(hp); i > 0; i--)
443 >                        if (hp->bl[i] != NULL)
444 >                                nchanged += hdfreebeam(hp, i);
445                  return(nchanged);
446          }
447          if (i < 1 | i > nbeams(hp))
# Line 453 | Line 456 | register int   i;
456                  if (lseek(hp->fd, hp->bi[i].fo, 0) < 0)
457                          error(SYSTEM, "cannot seek on holodeck file");
458                  n = hp->bl[i]->nrm * sizeof(RAYVAL);
459 <                if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n)
459 >                if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) {
460 >                        hp->fd = -1;            /* avoid recursive error */
461                          error(SYSTEM, "write error in hdfreebeam");
462 +                }
463          }
464          blglob(hp)->nrm -= hp->bl[i]->nrm;
465          free((char *)hp->bl[i]);                /* free memory */
# Line 463 | Line 468 | register int   i;
468   }
469  
470  
471 + int
472 + hdkillbeam(hp, i)               /* delete beam from holodeck */
473 + register HOLO   *hp;
474 + register int    i;
475 + {
476 +        static BEAM     emptybeam;
477 +        int     nchanged, n;
478 +
479 +        if (hp == NULL) {               /* clobber all holodecks */
480 +                nchanged = 0;
481 +                for (i = 0; hdlist[i] != NULL; i++)
482 +                        nchanged += hdkillbeam(hdlist[i], 0);
483 +                return(nchanged);
484 +        }
485 +        if (i == 0) {                   /* clobber entire holodeck */
486 +                nchanged = 0;
487 +                for (i = nbeams(hp); i > 0; i--)
488 +                        if (hp->bi[i].nrd > 0 || hp->bl[i] != NULL)
489 +                                nchanged += hdkillbeam(hp, i);
490 + #ifdef DEBUG
491 +                if (biglob(hp)->nrd != 0 | blglob(hp)->nrm != 0)
492 +                        error(CONSISTENCY, "bad beam count in hdkillbeam");
493 + #endif
494 +                return(nchanged);
495 +        }
496 +        if (i < 1 | i > nbeams(hp))
497 +                error(CONSISTENCY, "bad beam index to hdkillbeam");
498 +        if (hp->bl[i] != NULL) {        /* free memory */
499 +                blglob(hp)->nrm -= nchanged = hp->bl[i]->nrm;
500 +                free((char *)hp->bl[i]);
501 +        } else
502 +                nchanged = hp->bi[i].nrd;
503 +        if (hp->bi[i].nrd) {            /* free file fragment */
504 +                hp->bl[i] = &emptybeam;
505 +                hdgetbi(hp, i);
506 +        }
507 +        hp->bl[i] = NULL;
508 +        return(nchanged);
509 + }
510 +
511 +
512   hdlrulist(ha, ba, n, hp)        /* add beams from holodeck to LRU list */
513   register HOLO   *ha[];                  /* section list (NULL terminated) */
514   register int    ba[];                   /* beam index to go with section */
# Line 476 | Line 522 | register HOLO  *hp;                    /* section we're adding from */
522                  ;
523          nents = j;
524                                          /* insert each beam from hp */
525 <        for (i = nbeams(hp); i > 0; i-- ) {
525 >        for (i = nbeams(hp); i > 0; i--) {
526                  if (hp->bl[i] == NULL)          /* check if loaded */
527                          continue;
528                  if ((j = ++nents) > n)          /* grow list if we can */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines