13 |
|
#define RtraceSimulManager_h |
14 |
|
|
15 |
|
#include "ray.h" |
16 |
+ |
#include "abitmap.h" |
17 |
|
|
18 |
|
extern char * octname; // global octree name |
19 |
|
|
27 |
|
char * header; // header (less intro and format) |
28 |
|
int hlen; // header string length |
29 |
|
protected: |
30 |
< |
// Assign ray to subthread (fails if NThreads()<2) |
31 |
< |
bool SplitRay(RAY *r); |
30 |
> |
bool SplitRay(RAY *r) { |
31 |
> |
return (ray_pnprocs && ray_psend(r) > 0); |
32 |
> |
} |
33 |
|
public: |
34 |
|
RadSimulManager(const char *octn = NULL) { |
35 |
|
header = NULL; hlen = 0; |
42 |
|
bool LoadOctree(const char *octn); |
43 |
|
/// Prepare header from previous input (or clear) |
44 |
|
/// Normally called during octree load |
45 |
< |
bool NewHeader(const char *inspec=NULL); |
45 |
> |
bool NewHeader(const char *inspec = NULL); |
46 |
|
/// Add a line to header (adds newline if none) |
47 |
|
bool AddHeader(const char *str); |
48 |
|
/// Append program line to header |
49 |
|
bool AddHeader(int ac, char *av[]); |
50 |
+ |
/// Get current header length in bytes |
51 |
+ |
int GetHeadLen() const { |
52 |
+ |
return hlen; |
53 |
+ |
} |
54 |
|
/// Get header lines or empty string |
55 |
< |
const char * GetHeader() const { |
55 |
> |
const char * GetHeadStr() const { |
56 |
|
return hlen ? header : ""; |
57 |
|
} |
58 |
+ |
/// Look for specific header keyword, return value |
59 |
+ |
const char * GetHeadStr(const char *key, bool inOK = false) const; |
60 |
|
/// How many cores are available? |
61 |
|
static int GetNCores(); |
62 |
|
/// Set number of computation threads (0 => #cores) |
66 |
|
return ray_pnprocs + !ray_pnprocs; |
67 |
|
} |
68 |
|
/// How many threads are currently unoccupied? |
69 |
< |
int ThreadsAvailable() const; |
69 |
> |
int ThreadsAvailable() const { |
70 |
> |
return ray_pnprocs ? ray_pnidle : 1; |
71 |
> |
} |
72 |
|
/// Are we ready? |
73 |
|
bool Ready() const { |
74 |
|
return (octname && nobjects > 0); |
75 |
|
} |
76 |
|
/// Process a ray (in subthread), optional result |
77 |
< |
bool ProcessRay(RAY *r); |
77 |
> |
int ProcessRay(RAY *r); |
78 |
|
/// Wait for next result (or fail) |
79 |
|
bool WaitResult(RAY *r); |
80 |
|
/// Close octree, free data, return status |
91 |
|
RayReportCall * traceCall; // call for every ray in tree |
92 |
|
void * tcData; // client data for traced rays |
93 |
|
int curFlags; // current operating flags |
94 |
+ |
ABitMap srcFollowed; // source flags changed |
95 |
|
// Call-back for global ray-tracing context |
96 |
|
static void RTracer(RAY *r); |
97 |
|
// Call-back for FIFO |
123 |
|
int EnqueueBundle(const FVECT orig_direc[], int n, |
124 |
|
RNUMBER rID0 = 0); |
125 |
|
/// Enqueue a single ray w/ optional ray ID |
126 |
< |
bool EnqueueRay(const FVECT org, const FVECT dir, |
126 |
> |
int EnqueueRay(const FVECT org, const FVECT dir, |
127 |
|
RNUMBER rID = 0) { |
128 |
|
if (dir == org+1) |
129 |
|
return(EnqueueBundle((const FVECT *)org, 1, rID) > 0); |
130 |
|
FVECT orgdir[2]; |
131 |
|
VCOPY(orgdir[0], org); VCOPY(orgdir[1], dir); |
132 |
< |
return(EnqueueBundle(orgdir, 1, rID) > 0); |
132 |
> |
return EnqueueBundle(orgdir, 1, rID); |
133 |
|
} |
134 |
|
/// Set/change cooked ray callback |
135 |
|
void SetCookedCall(RayReportCall *cb, void *cd = NULL) { |
140 |
|
} |
141 |
|
/// Set/change trace callback |
142 |
|
void SetTraceCall(RayReportCall *cb, void *cd = NULL) { |
143 |
+ |
if (cb == traceCall) { |
144 |
+ |
if (cb) tcData = cd; |
145 |
+ |
return; |
146 |
+ |
} |
147 |
+ |
int nt = NThreads(); |
148 |
+ |
if (nt > 1) SetThreadCount(1); |
149 |
|
traceCall = cb; |
150 |
|
tcData = cb ? cd : NULL; |
151 |
+ |
if (nt > 1) SetThreadCount(nt); |
152 |
|
} |
153 |
|
/// Are we ready? |
154 |
|
bool Ready() const { |