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 { |
26 |
< |
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); |
28 |
– |
nThreads = 1; |
32 |
|
} |
33 |
|
~RadSimulManager() { |
34 |
|
Cleanup(); |
35 |
|
} |
36 |
|
/// Load octree and prepare renderer |
37 |
|
bool LoadOctree(const char *octn); |
38 |
< |
/// How many cores are there? |
38 |
> |
/// How many cores are available? |
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) |
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); |
54 |
+ |
/// Wait for next result (or fail) |
55 |
+ |
bool WaitResult(RAY *r); |
56 |
|
/// Close octree, free data, return status |
57 |
|
int Cleanup(bool everything = false); |
58 |
|
}; |
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: |
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 { |
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(bool everything = false) { |
130 |
+ |
FlushQueue(); |
131 |
|
SetCookedCall(NULL); |
132 |
|
SetTraceCall(NULL); |
133 |
|
rtFlags = 0; |