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.15 by greg, Thu Oct 10 21:02:52 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 header lines or empty string
50 +        const char *            GetHeadStr() const {
51 +                                        return hlen ? header : "";
52 +                                }
53 +                                /// Look for specific header keyword, return value
54 +        const char *            GetHeadStr(const char *key, bool inOK = false) const;
55 +                                /// How many cores are available?
56 +        static int              GetNCores();
57                                  /// Set number of computation threads (0 => #cores)
58          int                     SetThreadCount(int nt = 0);
59                                  /// Check thread count (1 means no multi-threading)
60          int                     NThreads() const {
61 <                                        return nThreads;
61 >                                        return ray_pnprocs + !ray_pnprocs;
62                                  }
63                                  /// How many threads are currently unoccupied?
64          int                     ThreadsAvailable() const;
65                                  /// Are we ready?
66          bool                    Ready() const {
67 <                                        return (octname && nsceneobjs > 0);
67 >                                        return (octname && nobjects > 0);
68                                  }
69 +                                /// Process a ray (in subthread), optional result
70 +        bool                    ProcessRay(RAY *r);
71 +                                /// Wait for next result (or fail)
72 +        bool                    WaitResult(RAY *r);
73                                  /// Close octree, free data, return status
74 <        int                     Cleanup();
74 >        int                     Cleanup(bool everything = false);
75   };
76  
77   /// Flags to control rendering operations
# Line 58 | Line 84 | class RtraceSimulManager : public RadSimulManager {
84          RayReportCall *         traceCall;      // call for every ray in tree
85          void *                  tcData;         // client data for traced rays
86          int                     curFlags;       // current operating flags
87 +        ABitMap                 srcFollowed;    // source flags changed
88                                  // Call-back for global ray-tracing context
89          static void             RTracer(RAY *r);
90 +                                // Call-back for FIFO
91 +        static int              Rfifout(RAY *r);
92                                  // Check for changes to render flags, etc.
93          bool                    UpdateMode();
94   protected:
# Line 73 | Line 102 | class RtraceSimulManager : public RadSimulManager {
102                                          SetCookedCall(cb, cd);
103                                          traceCall = NULL; tcData = NULL;
104                                  }
105 <                                ~RtraceSimulManager() {}
105 >                                ~RtraceSimulManager() {
106 >                                        FlushQueue();
107 >                                }
108 >                                /// Set number of computation threads (0 => #cores)
109 >        int                     SetThreadCount(int nt = 0) {
110 >                                        if (nt <= 0) nt = castonly ? 1 : GetNCores();
111 >                                        if (nt == NThreads()) return nt;
112 >                                        if (nt < NThreads() && FlushQueue() < 0) return 0;
113 >                                        return RadSimulManager::SetThreadCount(nt);
114 >                                }
115                                  /// Add ray bundle to queue w/ optional 1st ray ID
116          int                     EnqueueBundle(const FVECT orig_direc[], int n,
117                                                  RNUMBER rID0 = 0);
# Line 81 | Line 119 | class RtraceSimulManager : public RadSimulManager {
119          bool                    EnqueueRay(const FVECT org, const FVECT dir,
120                                                  RNUMBER rID = 0) {
121                                          if (dir == org+1)
122 <                                                return EnqueueBundle((const FVECT *)org, 1, rID);
122 >                                                return(EnqueueBundle((const FVECT *)org, 1, rID) > 0);
123                                          FVECT   orgdir[2];
124                                          VCOPY(orgdir[0], org); VCOPY(orgdir[1], dir);
125 <                                        return EnqueueBundle(orgdir, 1, rID);
125 >                                        return(EnqueueBundle(orgdir, 1, rID) > 0);
126                                  }
127 <                                /// Set/change cooked ray callback & FIFO flag
127 >                                /// Set/change cooked ray callback
128          void                    SetCookedCall(RayReportCall *cb, void *cd = NULL) {
129                                          if (cookedCall && (cookedCall != cb) | (ccData != cd))
130                                                  FlushQueue();
131                                          cookedCall = cb;
132 <                                        ccData = cd;
132 >                                        ccData = cb ? cd : NULL;
133                                  }
134 <                                /// Set/change trace callback
134 >                                /// Set/change trace callback (before threading)
135          void                    SetTraceCall(RayReportCall *cb, void *cd = NULL) {
136                                          traceCall = cb;
137 <                                        tcData = cd;
137 >                                        tcData = cb ? cd : NULL;
138                                  }
139                                  /// Are we ready?
140          bool                    Ready() const {
141                                          return (cookedCall != NULL) | (traceCall != NULL) &&
142                                                  RadSimulManager::Ready();
143                                  }
144 <                                /// Finish pending rays and complete callbacks
145 <        bool                    FlushQueue();
144 >                                /// Finish pending rays and complete callbacks (return #sent)
145 >        int                     FlushQueue();
146                                  /// Close octree, free data, return status
147 <        int                     Cleanup() {
147 >        int                     Cleanup(bool everything = false) {
148                                          SetCookedCall(NULL);
149                                          SetTraceCall(NULL);
150                                          rtFlags = 0;
151                                          UpdateMode();
152                                          lastRayID = 0;
153 <                                        return RadSimulManager::Cleanup();
153 >                                        return RadSimulManager::Cleanup(everything);
154                                  }
155   };
156  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines