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.16 by greg, Wed Oct 23 23:40:41 2024 UTC

# Line 13 | Line 13
13   #define RtraceSimulManager_h
14  
15   #include "ray.h"
16 + #include "abitmap.h"
17  
18   extern char *   octname;        // global octree name
19  
20 < /// Ray reporting callback method
20 < typedef void    RayReportCall(RAY *r, void *cd);
20 > extern int      castonly;       // doing ray-casting only?
21  
22 + /// Ray reporting callback method -- returns # successfully reported, -1 to abort
23 + typedef int     RayReportCall(RAY *r, void *cd);
24 +
25   /// Multi-threaded simulation manager base class
26   class RadSimulManager {
27 <        int                     nThreads;       // number of active threads
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);
28                                        nThreads = 1;
36                                  }
37                                  ~RadSimulManager() {
38                                          Cleanup();
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)
62          int                     SetThreadCount(int nt = 0);
63                                  /// Check thread count (1 means no multi-threading)
64          int                     NThreads() const {
65 <                                        return nThreads;
65 >                                        return ray_pnprocs + !ray_pnprocs;
66                                  }
67                                  /// How many threads are currently unoccupied?
68          int                     ThreadsAvailable() const;
69                                  /// Are we ready?
70          bool                    Ready() const {
71 <                                        return (octname && nsceneobjs > 0);
71 >                                        return (octname && nobjects > 0);
72                                  }
73 +                                /// Process a ray (in subthread), optional result
74 +        bool                    ProcessRay(RAY *r);
75 +                                /// Wait for next result (or fail)
76 +        bool                    WaitResult(RAY *r);
77                                  /// Close octree, free data, return status
78 <        int                     Cleanup();
78 >        int                     Cleanup(bool everything = false);
79   };
80  
81   /// Flags to control rendering operations
# Line 58 | Line 88 | class RtraceSimulManager : public RadSimulManager {
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
95 +        static int              Rfifout(RAY *r);
96                                  // Check for changes to render flags, etc.
97          bool                    UpdateMode();
98   protected:
# Line 73 | Line 106 | class RtraceSimulManager : public RadSimulManager {
106                                          SetCookedCall(cb, cd);
107                                          traceCall = NULL; tcData = NULL;
108                                  }
109 <                                ~RtraceSimulManager() {}
109 >                                ~RtraceSimulManager() {
110 >                                        FlushQueue();
111 >                                }
112 >                                /// Set number of computation threads (0 => #cores)
113 >        int                     SetThreadCount(int nt = 0) {
114 >                                        if (nt <= 0) nt = castonly ? 1 : GetNCores();
115 >                                        if (nt == NThreads()) return nt;
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
120          int                     EnqueueBundle(const FVECT orig_direc[], int n,
121                                                  RNUMBER rID0 = 0);
# Line 81 | Line 123 | class RtraceSimulManager : public RadSimulManager {
123          bool                    EnqueueRay(const FVECT org, const FVECT dir,
124                                                  RNUMBER rID = 0) {
125                                          if (dir == org+1)
126 <                                                return EnqueueBundle((const FVECT *)org, 1, rID);
126 >                                                return(EnqueueBundle((const FVECT *)org, 1, rID) > 0);
127                                          FVECT   orgdir[2];
128                                          VCOPY(orgdir[0], org); VCOPY(orgdir[1], dir);
129 <                                        return EnqueueBundle(orgdir, 1, rID);
129 >                                        return(EnqueueBundle(orgdir, 1, rID) > 0);
130                                  }
131 <                                /// Set/change cooked ray callback & FIFO flag
131 >                                /// Set/change cooked ray callback
132          void                    SetCookedCall(RayReportCall *cb, void *cd = NULL) {
133                                          if (cookedCall && (cookedCall != cb) | (ccData != cd))
134                                                  FlushQueue();
135                                          cookedCall = cb;
136 <                                        ccData = cd;
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 = cd;
141 >                                        tcData = cb ? cd : NULL;
142                                  }
143                                  /// Are we ready?
144          bool                    Ready() const {
145                                          return (cookedCall != NULL) | (traceCall != NULL) &&
146                                                  RadSimulManager::Ready();
147                                  }
148 <                                /// Finish pending rays and complete callbacks
149 <        bool                    FlushQueue();
148 >                                /// Finish pending rays and complete callbacks (return #sent)
149 >        int                     FlushQueue();
150                                  /// Close octree, free data, return status
151 <        int                     Cleanup() {
151 >        int                     Cleanup(bool everything = false) {
152                                          SetCookedCall(NULL);
153                                          SetTraceCall(NULL);
154                                          rtFlags = 0;
155                                          UpdateMode();
156                                          lastRayID = 0;
157 <                                        return RadSimulManager::Cleanup();
157 >                                        return RadSimulManager::Cleanup(everything);
158                                  }
159   };
160  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines