23 |
|
class RadSimulManager { |
24 |
|
int nThreads; // number of active threads |
25 |
|
protected: |
26 |
< |
/// How many cores are there? |
27 |
< |
static int GetNCores(); |
26 |
> |
// Assign ray to subthread (fails if NThreads()<2) |
27 |
> |
bool SplitRay(RAY *r); |
28 |
|
public: |
29 |
|
RadSimulManager(const char *octn = NULL) { |
30 |
|
LoadOctree(octn); |
35 |
|
} |
36 |
|
/// Load octree and prepare renderer |
37 |
|
bool LoadOctree(const char *octn); |
38 |
+ |
/// How many cores are there? |
39 |
+ |
static int GetNCores(); |
40 |
|
/// Set number of computation threads (0 => #cores) |
41 |
|
int SetThreadCount(int nt = 0); |
42 |
|
/// Check thread count (1 means no multi-threading) |
49 |
|
bool Ready() const { |
50 |
|
return (octname && nsceneobjs > 0); |
51 |
|
} |
52 |
+ |
/// Process a ray (in subthread), optional result |
53 |
+ |
bool ProcessRay(RAY *r); |
54 |
+ |
/// Wait for next result (or fail) |
55 |
+ |
bool WaitResult(RAY *r); |
56 |
|
/// Close octree, free data, return status |
57 |
< |
int Cleanup(); |
57 |
> |
int Cleanup(bool everything = false); |
58 |
|
}; |
59 |
|
|
60 |
|
/// Flags to control rendering operations |
72 |
|
// Check for changes to render flags, etc. |
73 |
|
bool UpdateMode(); |
74 |
|
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 |
84 |
|
SetCookedCall(cb, cd); |
85 |
|
traceCall = NULL; tcData = NULL; |
86 |
|
} |
87 |
< |
~RtraceSimulManager() {} |
87 |
> |
~RtraceSimulManager() { |
88 |
> |
FlushQueue(); |
89 |
> |
} |
90 |
|
/// Set number of computation threads (0 => #cores) |
91 |
|
int SetThreadCount(int nt = 0) { |
92 |
|
if (nt <= 0) nt = GetNCores(); |
101 |
|
bool EnqueueRay(const FVECT org, const FVECT dir, |
102 |
|
RNUMBER rID = 0) { |
103 |
|
if (dir == org+1) |
104 |
< |
return EnqueueBundle((const FVECT *)org, 1, rID); |
104 |
> |
return(EnqueueBundle((const FVECT *)org, 1, rID) > 0); |
105 |
|
FVECT orgdir[2]; |
106 |
|
VCOPY(orgdir[0], org); VCOPY(orgdir[1], dir); |
107 |
< |
return EnqueueBundle(orgdir, 1, rID); |
107 |
> |
return(EnqueueBundle(orgdir, 1, rID) > 0); |
108 |
|
} |
109 |
|
/// Set/change cooked ray callback & FIFO flag |
110 |
|
void SetCookedCall(RayReportCall *cb, void *cd = NULL) { |
123 |
|
return (cookedCall != NULL) | (traceCall != NULL) && |
124 |
|
RadSimulManager::Ready(); |
125 |
|
} |
126 |
< |
/// Finish pending rays and complete callbacks |
127 |
< |
bool FlushQueue(); |
126 |
> |
/// Finish pending rays and complete callbacks (return #sent) |
127 |
> |
int FlushQueue(); |
128 |
|
/// Close octree, free data, return status |
129 |
< |
int Cleanup() { |
129 |
> |
int Cleanup(bool everything = false) { |
130 |
|
SetCookedCall(NULL); |
131 |
|
SetTraceCall(NULL); |
132 |
|
rtFlags = 0; |
133 |
|
UpdateMode(); |
134 |
|
lastRayID = 0; |
135 |
< |
return RadSimulManager::Cleanup(); |
135 |
> |
return RadSimulManager::Cleanup(everything); |
136 |
|
} |
137 |
|
}; |
138 |
|
|