ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/RtraceSimulManager.h
(Generate patch)

Comparing ray/src/rt/RtraceSimulManager.h (file contents):
Revision 2.1 by greg, Wed Feb 8 17:41:48 2023 UTC vs.
Revision 2.8 by greg, Thu May 2 22:10:43 2024 UTC

# Line 16 | Line 16
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 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();
57 >        int                     Cleanup(bool everything = false);
58   };
59  
60   /// Flags to control rendering operations
# Line 60 | Line 69 | class RtraceSimulManager : public RadSimulManager {
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:
# Line 73 | Line 84 | class RtraceSimulManager : public RadSimulManager {
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 = castonly ? 1 : GetNCores();
93 >                                        if (nt == NThreads()) return nt;
94 >                                        if (FlushQueue() < 0) return 0;
95 >                                        return RadSimulManager::SetThreadCount(nt);
96 >                                }
97                                  /// Add ray bundle to queue w/ optional 1st ray ID
98          int                     EnqueueBundle(const FVECT orig_direc[], int n,
99                                                  RNUMBER rID0 = 0);
# Line 81 | Line 101 | class RtraceSimulManager : public RadSimulManager {
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
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() {
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines