| 20 |
|
* is desired, a negative value may be returned. |
| 21 |
|
* |
| 22 |
|
* The ray_fifo_in() call takes a ray that has been initialized in |
| 23 |
< |
* the same manner as for the ray_trace() call, i.e., the origin, |
| 24 |
< |
* direction, and maximum length have been assigned. The ray number |
| 25 |
< |
* will be set according to the number of rays traced since the |
| 23 |
> |
* the same manner as for the ray_pqueue() call, i.e., rayorigin() |
| 24 |
> |
* has been called and the origin, direction and maximum distance |
| 25 |
> |
* have all been assigned. However, the ray number will be reset |
| 26 |
> |
* by ray_fifo_in() according to the number of rays traced since the |
| 27 |
|
* last call to ray_fifo_flush(). This final call completes all |
| 28 |
|
* pending ray calculations and frees the FIFO buffer. If any of |
| 29 |
|
* the automatic calls to the ray_fifo_out callback return a |
| 36 |
|
#include "ray.h" |
| 37 |
|
#include <string.h> |
| 38 |
|
|
| 39 |
+ |
#ifndef MAXFIFO |
| 40 |
+ |
#define MAXFIFO 4096 /* clear FIFO past this */ |
| 41 |
+ |
#endif |
| 42 |
+ |
|
| 43 |
|
int (*ray_fifo_out)(RAY *r) = NULL; /* ray output callback */ |
| 44 |
|
|
| 45 |
|
static RAY *r_fifo_buf = NULL; /* circular FIFO out buffer */ |
| 59 |
|
int i; |
| 60 |
|
|
| 61 |
|
if (r_fifo_buf == NULL) |
| 62 |
< |
r_fifo_len = 1<<4; |
| 62 |
> |
r_fifo_len = 32; |
| 63 |
|
else |
| 64 |
< |
r_fifo_len <<= 1; |
| 64 |
> |
r_fifo_len = r_fifo_len*3/2; |
| 65 |
|
/* allocate new */ |
| 66 |
|
r_fifo_buf = (RAY *)calloc(r_fifo_len, sizeof(RAY)); |
| 67 |
|
if (r_fifo_buf == NULL) |
| 89 |
|
error(INTERNAL, "unexpected ray number in ray_fifo_push()"); |
| 90 |
|
|
| 91 |
|
if (r->rno > r_fifo_start) { /* insert into output queue */ |
| 92 |
< |
if (r->rno - r_fifo_start >= r_fifo_len) |
| 92 |
> |
while (r->rno - r_fifo_start >= r_fifo_len) |
| 93 |
|
ray_fifo_growbuf(); /* need more space */ |
| 94 |
|
*r_fifo(r->rno) = *r; |
| 95 |
|
if (r->rno >= r_fifo_end) |
| 124 |
|
if (incall++) |
| 125 |
|
error(INTERNAL, "recursive call to ray_fifo_in()"); |
| 126 |
|
|
| 127 |
< |
if (r_fifo_start >= 1L<<30) { /* reset our counters */ |
| 127 |
> |
/* need to reset our FIFO? */ |
| 128 |
> |
if ((r_fifo_start >= 1L<<30) | (r_fifo_len > MAXFIFO)) { |
| 129 |
|
if ((rv = ray_fifo_flush()) < 0) |
| 130 |
|
{--incall; return(-1);} |
| 131 |
|
rval += rv; |
| 132 |
|
} |
| 133 |
|
/* queue ray */ |
| 128 |
– |
rayorigin(r, PRIMARY, NULL, NULL); |
| 134 |
|
r->rno = r_fifo_next++; |
| 135 |
|
if ((rv = ray_pqueue(r)) < 0) |
| 136 |
|
{--incall; return(-1);} |