--- ray/src/hd/rholo2.c 2003/07/07 17:21:51 3.25 +++ ray/src/hd/rholo2.c 2025/01/23 19:07:35 3.32 @@ -1,10 +1,12 @@ #ifndef lint -static const char RCSid[] = "$Id: rholo2.c,v 3.25 2003/07/07 17:21:51 greg Exp $"; +static const char RCSid[] = "$Id: rholo2.c,v 3.32 2025/01/23 19:07:35 greg Exp $"; #endif /* * Rtrace support routines for holodeck rendering */ +#include + #include "rholo.h" #include "paths.h" #include "random.h" @@ -20,15 +22,21 @@ struct gclim { double gmin[2], gmax[2]; /* grid coordinate limits */ }; /* a grid coordinate range */ +static void initeyelim(struct gclim *gcl, HOLO *hp, GCOORD *gc); +static void groweyelim(struct gclim *gcl, GCOORD *gc, + double r0, double r1, int tight); +static int clipeyelim(short rrng[2][2], struct gclim *gcl); -static -initeyelim(gcl, hp, gc) /* initialize grid coordinate limits */ -register struct gclim *gcl; -register HOLO *hp; -GCOORD *gc; + +static void +initeyelim( /* initialize grid coordinate limits */ + struct gclim *gcl, + HOLO *hp, + GCOORD *gc +) { - register RREAL *v; - register int i; + RREAL *v; + int i; if (hp != NULL) { hdgrid(gcl->egp, gcl->hp = hp, myeye.vpt); @@ -38,18 +46,20 @@ GCOORD *gc; gcl->erg2 *= (1./3.) * myeye.rng*myeye.rng; } if (gc != NULL) - copystruct(&gcl->gc, gc); + gcl->gc = *gc; gcl->gmin[0] = gcl->gmin[1] = FHUGE; gcl->gmax[0] = gcl->gmax[1] = -FHUGE; } -static -groweyelim(gcl, gc, r0, r1, tight) /* grow grid limits about eye point */ -register struct gclim *gcl; -GCOORD *gc; -double r0, r1; -int tight; +static void +groweyelim( /* grow grid limits about eye point */ + struct gclim *gcl, + GCOORD *gc, + double r0, + double r1, + int tight +) { FVECT gp, ab; double ab2, od, cfact; @@ -97,7 +107,7 @@ int tight; f = wallpos*(wallpos*sqcoef[gw] + licoef[gw]) + cnst; for (i = 0; i < 2; i++) { if (i) { /* swap x and y coefficients */ - register double t; + double t; t = a; a = c; c = t; t = d; d = e; e = t; } @@ -106,7 +116,7 @@ int tight; d*(c*d-b*e) + f*b*b); while (n-- > 0) { if (gc->w>>1 == gi[i] && - (gc->w&1) ^ root[n] < gp[gc->w>>1]) { + (gc->w&1) ^ (root[n] < gp[gc->w>>1])) { if (gc->w&1) gcl->gmin[i] = -FHUGE; else @@ -132,7 +142,7 @@ int tight; n = quadratic(root, a, b*yex+d, yex*(yex*c+e)+f); while (n-- > 0) { if (gc->w>>1 == gi[i] && - (gc->w&1) ^ root[n] < gp[gc->w>>1]) + (gc->w&1) ^ (root[n] < gp[gc->w>>1])) continue; if (root[n] < gcl->gmin[i]) gcl->gmin[i] = root[n]; @@ -145,12 +155,13 @@ int tight; static int -clipeyelim(rrng, gcl) /* clip eye limits to grid cell */ -register short rrng[2][2]; -register struct gclim *gcl; +clipeyelim( /* clip eye limits to grid cell */ + short rrng[2][2], + struct gclim *gcl +) { int incell = 1; - register int i; + int i; for (i = 0; i < 2; i++) { if (gcl->gmin[i] < gcl->gc.i[i]) @@ -170,9 +181,11 @@ register struct gclim *gcl; } -packrays(rod, p) /* pack ray origins and directions */ -register float *rod; -register PACKET *p; +void +packrays( /* pack ray origins and directions */ + float *rod, + PACKET *p +) { #if 0 double dist2sum = 0.; @@ -185,7 +198,7 @@ register PACKET *p; GCOORD gc[2]; FVECT ro, rd; double d; - register int i; + int i; if (!hdbcoord(gc, hdlist[p->hd], p->bi)) error(CONSISTENCY, "bad beam index in packrays"); @@ -203,10 +216,8 @@ register PACKET *p; retry: if (useyelim) { initeyelim(&eyelim, NULL, gc+1); - p->ra[i].r[0][0] = (int)(frandom()*rrng0[0][1]) - + rrng0[0][0]; - p->ra[i].r[0][1] = (int)(frandom()*rrng0[1][1]) - + rrng0[1][0]; + p->ra[i].r[0][0] = irandom(rrng0[0][1]) + rrng0[0][0]; + p->ra[i].r[0][1] = irandom(rrng0[1][1]) + rrng0[1][0]; groweyelim(&eyelim, gc, (1./256.)*(p->ra[i].r[0][0]+.5), (1./256.)*(p->ra[i].r[0][1]+.5), 1); @@ -219,15 +230,13 @@ register PACKET *p; #endif goto retry; } - p->ra[i].r[1][0] = (int)(frandom()*rrng1[0][1]) - + rrng1[0][0]; - p->ra[i].r[1][1] = (int)(frandom()*rrng1[1][1]) - + rrng1[1][0]; + p->ra[i].r[1][0] = irandom(rrng1[0][1]) + rrng1[0][0]; + p->ra[i].r[1][1] = irandom(rrng1[1][1]) + rrng1[1][0]; } else { - p->ra[i].r[0][0] = frandom() * 256.; - p->ra[i].r[0][1] = frandom() * 256.; - p->ra[i].r[1][0] = frandom() * 256.; - p->ra[i].r[1][1] = frandom() * 256.; + p->ra[i].r[0][0] = random() & 0xff; + p->ra[i].r[0][1] = random() & 0xff; + p->ra[i].r[1][0] = random() & 0xff; + p->ra[i].r[1][1] = random() & 0xff; } d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r); #if 0 @@ -252,12 +261,14 @@ register PACKET *p; } -donerays(p, rvl) /* encode finished ray computations */ -register PACKET *p; -register float *rvl; +void +donerays( /* encode finished ray computations */ + PACKET *p, + float *rvl +) { double d; - register int i; + int i; for (i = 0; i < p->nr; i++) { setcolr(p->ra[i].v, rvl[0], rvl[1], rvl[2]); @@ -272,7 +283,7 @@ register float *rvl; int -done_rtrace() /* clean up and close rtrace calculation */ +done_rtrace(void) /* clean up and close rtrace calculation */ { int status; /* already closed? */ @@ -293,7 +304,8 @@ done_rtrace() /* clean up and close rtrace calculati } -new_rtrace() /* restart rtrace calculation */ +void +new_rtrace(void) /* restart rtrace calculation */ { char combuf[128]; @@ -304,7 +316,8 @@ new_rtrace() /* restart rtrace calculation */ if (vdef(TIME)) /* reset end time */ endtime = starttime + vflt(TIME)*3600. + .5; if (vdef(RIF)) { /* rerun rad to update octree */ - sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF)); + sprintf(combuf, "rad -v 0 -s -w -N %d %s", + ncprocs, vval(RIF)); if (system(combuf)) error(WARNING, "error running rad"); } @@ -317,15 +330,16 @@ new_rtrace() /* restart rtrace calculation */ } -getradfile() /* run rad and get needed variables */ +int +getradfile(void) /* run rad and get needed variables */ { static short mvar[] = {OCTREE,EYESEP,-1}; static char tf1[] = TEMPLATE; char tf2[64]; char combuf[256]; - char *pippt; - register int i; - register char *cp; + char *pippt = NULL; + int i; + char *cp; /* check if rad file specified */ if (!vdef(RIF)) return(0); @@ -333,8 +347,8 @@ getradfile() /* run rad and get needed variables */ mktemp(tf1); sprintf(tf2, "%s.rif", tf1); sprintf(combuf, - "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", - vval(RIF), tf1); + "rad -v 0 -s -e -w -N %d %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", + ncprocs, vval(RIF), tf1); cp = combuf; while (*cp){ if (*cp == '|') pippt = cp; @@ -359,14 +373,17 @@ getradfile() /* run rad and get needed variables */ loadvars(tf2); /* load variables */ unlink(tf2); } - rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ + /* get rtrace options */ + rtargc += wordfile(rtargv+rtargc, MAXRTARGC-rtargc, tf1); unlink(tf1); /* clean up */ return(1); } -report(t) /* report progress so far */ -time_t t; +void +report( /* report progress so far */ + time_t t +) { static time_t seconds2go = 1000000;