| 51 |
|
} RAYPAR; |
| 52 |
|
|
| 53 |
|
static int openholo(char *fname, int append); |
| 54 |
< |
static void addray(RAYPAR *rp); |
| 54 |
> |
static int addray(RAYPAR *rp); |
| 55 |
|
static int readval(RREAL *v, int n, FILE *fp); |
| 56 |
|
static void readrays(FILE *fp); |
| 57 |
|
static int writeval(RREAL *v, int n, FILE *fp); |
| 228 |
|
return(n); |
| 229 |
|
} |
| 230 |
|
|
| 231 |
< |
void |
| 231 |
> |
int |
| 232 |
|
addray( /* add a ray to our output holodeck */ |
| 233 |
|
RAYPAR *rp |
| 234 |
|
) |
| 241 |
|
double d0, d1; |
| 242 |
|
unsigned dc; |
| 243 |
|
RAYVAL *rv; |
| 244 |
+ |
int nsects = 0; |
| 245 |
|
/* check each output section */ |
| 246 |
|
for (sn = nholosects; sn--; ) { |
| 247 |
|
hp = hdlist[sn]; |
| 272 |
|
rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1]; |
| 273 |
|
rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1]; |
| 274 |
|
copycolr(rv->v, rp->cv); |
| 275 |
+ |
++nsects; |
| 276 |
|
} |
| 277 |
+ |
return nsects; |
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
/* Read n-vector from file stream */ |
| 328 |
|
static void |
| 329 |
|
readrays(FILE *fp) |
| 330 |
|
{ |
| 331 |
+ |
unsigned long nread=0, ngood=0; |
| 332 |
+ |
|
| 333 |
|
if (iofmt != 'a') |
| 334 |
|
SET_FILE_BINARY(fp); |
| 335 |
|
#ifdef getc_unlocked |
| 384 |
|
if (!flags) /* got nothing, so may be normal EOF */ |
| 385 |
|
return; |
| 386 |
|
} |
| 387 |
+ |
++nread; |
| 388 |
|
if (flags & (BAD_DIR|BAD_LEN)) |
| 389 |
|
continue; /* just a bad ray is all -- skip */ |
| 390 |
|
if (!(flags & GOT_VAL)) |
| 402 |
|
} else |
| 403 |
|
goto missingData; |
| 404 |
|
} |
| 405 |
< |
addray(&ryp); /* add our ray to holodeck */ |
| 405 |
> |
ngood += (addray(&ryp) > 0); /* add our ray to holodeck */ |
| 406 |
|
} |
| 407 |
|
return; |
| 408 |
|
missingData: |
| 409 |
< |
sprintf(errmsg, "insufficient data in -i%s", rspec); |
| 409 |
> |
sprintf(errmsg, "insufficient data or read error with -i%s after %lu rays read (%lu used)", |
| 410 |
> |
rspec, nread, ngood); |
| 411 |
|
error(USER, errmsg); |
| 412 |
|
} |
| 413 |
|
|
| 485 |
|
return 0; /* write error? */ |
| 486 |
|
} |
| 487 |
|
|
| 488 |
+ |
static BEAMI *beamdir; |
| 489 |
+ |
|
| 490 |
+ |
static int |
| 491 |
+ |
bpcmp( /* compare beam positions on disk */ |
| 492 |
+ |
const void *b1p, |
| 493 |
+ |
const void *b2p |
| 494 |
+ |
) |
| 495 |
+ |
{ |
| 496 |
+ |
off_t pdif = beamdir[*(int *)b1p].fo - beamdir[*(int *)b2p].fo; |
| 497 |
+ |
|
| 498 |
+ |
if (pdif > 0L) return(1); |
| 499 |
+ |
if (pdif < 0L) return(-1); |
| 500 |
+ |
return(0); |
| 501 |
+ |
} |
| 502 |
+ |
|
| 503 |
|
/* Write all rays from holodeck to stream */ |
| 504 |
|
static void |
| 505 |
|
writerays(FILE *fp) |
| 520 |
|
#endif |
| 521 |
|
for (sn = 0; sn < nholosects; sn++) { /* write each holodeck section */ |
| 522 |
|
HOLO *hp = hdlist[sn]; |
| 523 |
< |
for (bi = nbeams(hp); bi > 0; bi--) { |
| 524 |
< |
BEAM *bp = hdgetbeam(hp, bi); |
| 523 |
> |
int nb = nbeams(hp); /* sort beams by file location */ |
| 524 |
> |
int *bq = (int *)malloc(nb*sizeof(int)); |
| 525 |
> |
if (!bq) |
| 526 |
> |
error(SYSTEM, "out of memory in writerays()"); |
| 527 |
> |
for (bi = nb; bi--; ) bq[bi] = bi+1; |
| 528 |
> |
beamdir = hp->bi; |
| 529 |
> |
qsort(bq, nb, sizeof(*bq), bpcmp); |
| 530 |
> |
for (bi = 0; bi < nb; bi++) { |
| 531 |
> |
BEAM *bp = hdgetbeam(hp, bq[bi]); |
| 532 |
|
if (!bp) /* empty beam? */ |
| 533 |
|
continue; |
| 534 |
< |
hdbcoord(gc, hp, bi); /* else write rays */ |
| 534 |
> |
hdbcoord(gc, hp, bq[bi]); |
| 535 |
|
rv = hdbray(bp); |
| 536 |
|
for (k = bp->nrm; k--; rv++) { |
| 537 |
|
ryp.d = hdray(ryp.ro, ryp.rd, hp, gc, rv->r); |
| 541 |
|
ryp.d = 0.; |
| 542 |
|
ryp.d = hddepth(hp, rv->d) - ryp.d; |
| 543 |
|
copycolr(ryp.cv, rv->v); |
| 544 |
< |
if (!write_ray(&ryp, fp)) |
| 544 |
> |
if (!write_ray(&ryp, fp)) { |
| 545 |
> |
free(bq); |
| 546 |
|
goto writError; |
| 547 |
+ |
} |
| 548 |
|
} |
| 549 |
< |
hdfreebeam(hp, bi); |
| 549 |
> |
hdfreebeam(hp, bq[bi]); |
| 550 |
|
} |
| 551 |
+ |
free(bq); |
| 552 |
|
} |
| 553 |
|
if (fflush(fp) != EOF) |
| 554 |
|
return; |
| 556 |
|
error(SYSTEM, "error writing holodeck rays"); |
| 557 |
|
} |
| 558 |
|
|
| 527 |
– |
static BEAMI *beamdir; |
| 528 |
– |
|
| 559 |
|
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 |
| 560 |
|
addclump( /* transfer the given clump and free */ |
| 561 |
|
HOLO *hp, |
| 562 |
|
int *bq, |
| 571 |
|
BEAM *bp; |
| 572 |
|
/* sort based on file position */ |
| 573 |
|
beamdir = hp->bi; |
| 574 |
< |
qsort((char *)bq, nb, sizeof(*bq), bpcmp); |
| 574 |
> |
qsort(bq, nb, sizeof(*bq), bpcmp); |
| 575 |
|
/* transfer each beam */ |
| 576 |
|
for (i = 0; i < nb; i++) { |
| 577 |
|
bp = hdgetbeam(hp, bq[i]); |
| 753 |
|
|
| 754 |
|
void |
| 755 |
|
eputs( /* put error message to stderr */ |
| 756 |
< |
char *s |
| 756 |
> |
const char *s |
| 757 |
|
) |
| 758 |
|
{ |
| 759 |
|
static int midline = 0; |