| 400 |
|
} |
| 401 |
|
return; |
| 402 |
|
missingData: |
| 403 |
< |
sprintf(errmsg, "insufficient data in -i%s", rspec); |
| 403 |
> |
sprintf(errmsg, "insufficient data or read error for -i%s", rspec); |
| 404 |
|
error(USER, errmsg); |
| 405 |
|
} |
| 406 |
|
|
| 478 |
|
return 0; /* write error? */ |
| 479 |
|
} |
| 480 |
|
|
| 481 |
+ |
static BEAMI *beamdir; |
| 482 |
+ |
|
| 483 |
+ |
static int |
| 484 |
+ |
bpcmp( /* compare beam positions on disk */ |
| 485 |
+ |
const void *b1p, |
| 486 |
+ |
const void *b2p |
| 487 |
+ |
) |
| 488 |
+ |
{ |
| 489 |
+ |
off_t pdif = beamdir[*(int *)b1p].fo - beamdir[*(int *)b2p].fo; |
| 490 |
+ |
|
| 491 |
+ |
if (pdif > 0L) return(1); |
| 492 |
+ |
if (pdif < 0L) return(-1); |
| 493 |
+ |
return(0); |
| 494 |
+ |
} |
| 495 |
+ |
|
| 496 |
|
/* Write all rays from holodeck to stream */ |
| 497 |
|
static void |
| 498 |
|
writerays(FILE *fp) |
| 513 |
|
#endif |
| 514 |
|
for (sn = 0; sn < nholosects; sn++) { /* write each holodeck section */ |
| 515 |
|
HOLO *hp = hdlist[sn]; |
| 516 |
< |
for (bi = nbeams(hp); bi > 0; bi--) { |
| 517 |
< |
BEAM *bp = hdgetbeam(hp, bi); |
| 516 |
> |
int nb = nbeams(hp); /* sort beams by file location */ |
| 517 |
> |
int *bq = (int *)malloc(nb*sizeof(int)); |
| 518 |
> |
if (!bq) |
| 519 |
> |
error(SYSTEM, "out of memory in writerays()"); |
| 520 |
> |
for (bi = nb; bi--; ) bq[bi] = bi+1; |
| 521 |
> |
beamdir = hp->bi; |
| 522 |
> |
qsort(bq, nb, sizeof(*bq), bpcmp); |
| 523 |
> |
for (bi = 0; bi < nb; bi++) { |
| 524 |
> |
BEAM *bp = hdgetbeam(hp, bq[bi]); |
| 525 |
|
if (!bp) /* empty beam? */ |
| 526 |
|
continue; |
| 527 |
< |
hdbcoord(gc, hp, bi); /* else write rays */ |
| 527 |
> |
hdbcoord(gc, hp, bq[bi]); |
| 528 |
|
rv = hdbray(bp); |
| 529 |
|
for (k = bp->nrm; k--; rv++) { |
| 530 |
|
ryp.d = hdray(ryp.ro, ryp.rd, hp, gc, rv->r); |
| 534 |
|
ryp.d = 0.; |
| 535 |
|
ryp.d = hddepth(hp, rv->d) - ryp.d; |
| 536 |
|
copycolr(ryp.cv, rv->v); |
| 537 |
< |
if (!write_ray(&ryp, fp)) |
| 537 |
> |
if (!write_ray(&ryp, fp)) { |
| 538 |
> |
free(bq); |
| 539 |
|
goto writError; |
| 540 |
+ |
} |
| 541 |
|
} |
| 542 |
< |
hdfreebeam(hp, bi); |
| 542 |
> |
hdfreebeam(hp, bq[bi]); |
| 543 |
|
} |
| 544 |
+ |
free(bq); |
| 545 |
|
} |
| 546 |
|
if (fflush(fp) != EOF) |
| 547 |
|
return; |
| 549 |
|
error(SYSTEM, "error writing holodeck rays"); |
| 550 |
|
} |
| 551 |
|
|
| 527 |
– |
static BEAMI *beamdir; |
| 528 |
– |
|
| 552 |
|
static int |
| 530 |
– |
bpcmp( /* compare beam positions on disk */ |
| 531 |
– |
const void *b1p, |
| 532 |
– |
const void *b2p |
| 533 |
– |
) |
| 534 |
– |
{ |
| 535 |
– |
off_t pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo; |
| 536 |
– |
|
| 537 |
– |
if (pdif > 0L) return(1); |
| 538 |
– |
if (pdif < 0L) return(-1); |
| 539 |
– |
return(0); |
| 540 |
– |
} |
| 541 |
– |
|
| 542 |
– |
static int |
| 553 |
|
addclump( /* transfer the given clump and free */ |
| 554 |
|
HOLO *hp, |
| 555 |
|
int *bq, |
| 564 |
|
BEAM *bp; |
| 565 |
|
/* sort based on file position */ |
| 566 |
|
beamdir = hp->bi; |
| 567 |
< |
qsort((char *)bq, nb, sizeof(*bq), bpcmp); |
| 567 |
> |
qsort(bq, nb, sizeof(*bq), bpcmp); |
| 568 |
|
/* transfer each beam */ |
| 569 |
|
for (i = 0; i < nb; i++) { |
| 570 |
|
bp = hdgetbeam(hp, bq[i]); |
| 746 |
|
|
| 747 |
|
void |
| 748 |
|
eputs( /* put error message to stderr */ |
| 749 |
< |
char *s |
| 749 |
> |
const char *s |
| 750 |
|
) |
| 751 |
|
{ |
| 752 |
|
static int midline = 0; |