13 |
|
#define RtraceSimulManager_h |
14 |
|
|
15 |
|
#include "ray.h" |
16 |
+ |
#include "abitmap.h" |
17 |
|
|
18 |
|
extern char * octname; // global octree name |
19 |
|
|
24 |
|
|
25 |
|
/// Multi-threaded simulation manager base class |
26 |
|
class RadSimulManager { |
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); |
32 |
|
public: |
33 |
|
RadSimulManager(const char *octn = NULL) { |
34 |
+ |
header = NULL; hlen = 0; |
35 |
|
LoadOctree(octn); |
36 |
|
} |
37 |
|
~RadSimulManager() { |
39 |
|
} |
40 |
|
/// Load octree and prepare renderer |
41 |
|
bool LoadOctree(const char *octn); |
42 |
+ |
/// Prepare header from previous input (or clear) |
43 |
+ |
/// Normally called during octree load |
44 |
+ |
bool NewHeader(const char *inspec = NULL); |
45 |
+ |
/// Add a line to header (adds newline if none) |
46 |
+ |
bool AddHeader(const char *str); |
47 |
+ |
/// Append program line to header |
48 |
+ |
bool AddHeader(int ac, char *av[]); |
49 |
+ |
/// Get current header length in bytes |
50 |
+ |
int GetHeadLen() const { |
51 |
+ |
return hlen; |
52 |
+ |
} |
53 |
+ |
/// Get header lines or empty string |
54 |
+ |
const char * GetHeadStr() const { |
55 |
+ |
return hlen ? header : ""; |
56 |
+ |
} |
57 |
+ |
/// Look for specific header keyword, return value |
58 |
+ |
const char * GetHeadStr(const char *key, bool inOK = false) const; |
59 |
|
/// How many cores are available? |
60 |
|
static int GetNCores(); |
61 |
|
/// Set number of computation threads (0 => #cores) |
88 |
|
RayReportCall * traceCall; // call for every ray in tree |
89 |
|
void * tcData; // client data for traced rays |
90 |
|
int curFlags; // current operating flags |
91 |
+ |
ABitMap srcFollowed; // source flags changed |
92 |
|
// Call-back for global ray-tracing context |
93 |
|
static void RTracer(RAY *r); |
94 |
|
// Call-back for FIFO |
113 |
|
int SetThreadCount(int nt = 0) { |
114 |
|
if (nt <= 0) nt = castonly ? 1 : GetNCores(); |
115 |
|
if (nt == NThreads()) return nt; |
116 |
< |
if (FlushQueue() < 0) return 0; |
116 |
> |
if (nt < NThreads() && FlushQueue() < 0) return 0; |
117 |
|
return RadSimulManager::SetThreadCount(nt); |
118 |
|
} |
119 |
|
/// Add ray bundle to queue w/ optional 1st ray ID |
135 |
|
cookedCall = cb; |
136 |
|
ccData = cb ? cd : NULL; |
137 |
|
} |
138 |
< |
/// Set/change trace callback |
138 |
> |
/// Set/change trace callback (before threading) |
139 |
|
void SetTraceCall(RayReportCall *cb, void *cd = NULL) { |
140 |
|
traceCall = cb; |
141 |
|
tcData = cb ? cd : NULL; |
149 |
|
int FlushQueue(); |
150 |
|
/// Close octree, free data, return status |
151 |
|
int Cleanup(bool everything = false) { |
130 |
– |
FlushQueue(); |
152 |
|
SetCookedCall(NULL); |
153 |
|
SetTraceCall(NULL); |
154 |
|
rtFlags = 0; |