| 16 |
|
|
| 17 |
|
extern char * octname; // global octree name |
| 18 |
|
|
| 19 |
< |
/// Ray reporting callback method |
| 20 |
< |
typedef void RayReportCall(RAY *r, void *cd); |
| 19 |
> |
extern int castonly; // doing ray-casting only? |
| 20 |
|
|
| 21 |
+ |
/// Ray reporting callback method -- returns # successfully reported, -1 to abort |
| 22 |
+ |
typedef int RayReportCall(RAY *r, void *cd); |
| 23 |
+ |
|
| 24 |
|
/// Multi-threaded simulation manager base class |
| 25 |
|
class RadSimulManager { |
| 24 |
– |
int nThreads; // number of active threads |
| 26 |
|
protected: |
| 27 |
|
// Assign ray to subthread (fails if NThreads()<2) |
| 28 |
|
bool SplitRay(RAY *r); |
| 29 |
|
public: |
| 30 |
|
RadSimulManager(const char *octn = NULL) { |
| 31 |
|
LoadOctree(octn); |
| 31 |
– |
nThreads = 1; |
| 32 |
|
} |
| 33 |
|
~RadSimulManager() { |
| 34 |
|
Cleanup(); |
| 41 |
|
int SetThreadCount(int nt = 0); |
| 42 |
|
/// Check thread count (1 means no multi-threading) |
| 43 |
|
int NThreads() const { |
| 44 |
< |
return nThreads; |
| 44 |
> |
return ray_pnprocs + !ray_pnprocs; |
| 45 |
|
} |
| 46 |
|
/// How many threads are currently unoccupied? |
| 47 |
|
int ThreadsAvailable() const; |
| 48 |
|
/// Are we ready? |
| 49 |
|
bool Ready() const { |
| 50 |
< |
return (octname && nsceneobjs > 0); |
| 50 |
> |
return (octname && nobjects > 0); |
| 51 |
|
} |
| 52 |
|
/// Process a ray (in subthread), optional result |
| 53 |
|
bool ProcessRay(RAY *r); |
| 69 |
|
int curFlags; // current operating flags |
| 70 |
|
// Call-back for global ray-tracing context |
| 71 |
|
static void RTracer(RAY *r); |
| 72 |
+ |
// Call-back for FIFO |
| 73 |
+ |
static int Rfifout(RAY *r); |
| 74 |
|
// Check for changes to render flags, etc. |
| 75 |
|
bool UpdateMode(); |
| 76 |
|
protected: |
| 75 |
– |
// Add a ray result to FIFO, flushing what we can |
| 76 |
– |
int QueueResult(const RAY &ra); |
| 77 |
|
RNUMBER lastRayID; // last ray ID assigned |
| 78 |
|
public: |
| 79 |
|
int rtFlags; // operation (RT*) flags |
| 89 |
|
} |
| 90 |
|
/// Set number of computation threads (0 => #cores) |
| 91 |
|
int SetThreadCount(int nt = 0) { |
| 92 |
< |
if (nt <= 0) nt = GetNCores(); |
| 92 |
> |
if (nt <= 0) nt = castonly ? 1 : GetNCores(); |
| 93 |
|
if (nt == NThreads()) return nt; |
| 94 |
< |
FlushQueue(); |
| 94 |
> |
if (FlushQueue() < 0) return 0; |
| 95 |
|
return RadSimulManager::SetThreadCount(nt); |
| 96 |
|
} |
| 97 |
|
/// Add ray bundle to queue w/ optional 1st ray ID |
| 106 |
|
VCOPY(orgdir[0], org); VCOPY(orgdir[1], dir); |
| 107 |
|
return(EnqueueBundle(orgdir, 1, rID) > 0); |
| 108 |
|
} |
| 109 |
< |
/// Set/change cooked ray callback & FIFO flag |
| 109 |
> |
/// Set/change cooked ray callback |
| 110 |
|
void SetCookedCall(RayReportCall *cb, void *cd = NULL) { |
| 111 |
|
if (cookedCall && (cookedCall != cb) | (ccData != cd)) |
| 112 |
|
FlushQueue(); |
| 113 |
|
cookedCall = cb; |
| 114 |
< |
ccData = cd; |
| 114 |
> |
ccData = cb ? cd : NULL; |
| 115 |
|
} |
| 116 |
|
/// Set/change trace callback |
| 117 |
|
void SetTraceCall(RayReportCall *cb, void *cd = NULL) { |
| 118 |
|
traceCall = cb; |
| 119 |
< |
tcData = cd; |
| 119 |
> |
tcData = cb ? cd : NULL; |
| 120 |
|
} |
| 121 |
|
/// Are we ready? |
| 122 |
|
bool Ready() const { |