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.14 by greg, Mon Sep 16 19:18:32 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 >        char *                  header;                 // header (less intro and format)
27 >        int                     hlen;                   // header string length
28 > protected:
29 >                                // Assign ray to subthread (fails if NThreads()<2)
30 >        bool                    SplitRay(RAY *r);
31   public:
32                                  RadSimulManager(const char *octn = NULL) {
33 +                                        header = NULL; hlen = 0;
34                                          LoadOctree(octn);
28                                        nThreads = 1;
35                                  }
36                                  ~RadSimulManager() {
37                                          Cleanup();
38                                  }
39                                  /// Load octree and prepare renderer
40          bool                    LoadOctree(const char *octn);
41 +                                /// Prepare header from previous input (or clear)
42 +                                /// Normally called during octree load
43 +        bool                    NewHeader(const char *inspec=NULL);
44 +                                /// Add a line to header (adds newline if none)
45 +        bool                    AddHeader(const char *str);
46 +                                /// Append program line to header
47 +        bool                    AddHeader(int ac, char *av[]);
48 +                                /// Get header lines or empty string
49 +        const char *            GetHeadStr() const {
50 +                                        return hlen ? header : "";
51 +                                }
52 +                                /// Look for specific header keyword, return value
53 +        const char *            GetHeadStr(const char *key, bool inOK = false) const;
54 +                                /// How many cores are available?
55 +        static int              GetNCores();
56                                  /// Set number of computation threads (0 => #cores)
57          int                     SetThreadCount(int nt = 0);
58                                  /// Check thread count (1 means no multi-threading)
59          int                     NThreads() const {
60 <                                        return nThreads;
60 >                                        return ray_pnprocs + !ray_pnprocs;
61                                  }
62                                  /// How many threads are currently unoccupied?
63          int                     ThreadsAvailable() const;
64                                  /// Are we ready?
65          bool                    Ready() const {
66 <                                        return (octname && nsceneobjs > 0);
66 >                                        return (octname && nobjects > 0);
67                                  }
68 +                                /// Process a ray (in subthread), optional result
69 +        bool                    ProcessRay(RAY *r);
70 +                                /// Wait for next result (or fail)
71 +        bool                    WaitResult(RAY *r);
72                                  /// Close octree, free data, return status
73 <        int                     Cleanup();
73 >        int                     Cleanup(bool everything = false);
74   };
75  
76   /// Flags to control rendering operations
# Line 60 | Line 85 | class RtraceSimulManager : public RadSimulManager {
85          int                     curFlags;       // current operating flags
86                                  // Call-back for global ray-tracing context
87          static void             RTracer(RAY *r);
88 +                                // Call-back for FIFO
89 +        static int              Rfifout(RAY *r);
90                                  // Check for changes to render flags, etc.
91          bool                    UpdateMode();
92   protected:
# Line 73 | Line 100 | class RtraceSimulManager : public RadSimulManager {
100                                          SetCookedCall(cb, cd);
101                                          traceCall = NULL; tcData = NULL;
102                                  }
103 <                                ~RtraceSimulManager() {}
103 >                                ~RtraceSimulManager() {
104 >                                        FlushQueue();
105 >                                }
106 >                                /// Set number of computation threads (0 => #cores)
107 >        int                     SetThreadCount(int nt = 0) {
108 >                                        if (nt <= 0) nt = castonly ? 1 : GetNCores();
109 >                                        if (nt == NThreads()) return nt;
110 >                                        if (nt < NThreads() && FlushQueue() < 0) return 0;
111 >                                        return RadSimulManager::SetThreadCount(nt);
112 >                                }
113                                  /// Add ray bundle to queue w/ optional 1st ray ID
114          int                     EnqueueBundle(const FVECT orig_direc[], int n,
115                                                  RNUMBER rID0 = 0);
# Line 81 | Line 117 | class RtraceSimulManager : public RadSimulManager {
117          bool                    EnqueueRay(const FVECT org, const FVECT dir,
118                                                  RNUMBER rID = 0) {
119                                          if (dir == org+1)
120 <                                                return EnqueueBundle((const FVECT *)org, 1, rID);
120 >                                                return(EnqueueBundle((const FVECT *)org, 1, rID) > 0);
121                                          FVECT   orgdir[2];
122                                          VCOPY(orgdir[0], org); VCOPY(orgdir[1], dir);
123 <                                        return EnqueueBundle(orgdir, 1, rID);
123 >                                        return(EnqueueBundle(orgdir, 1, rID) > 0);
124                                  }
125 <                                /// Set/change cooked ray callback & FIFO flag
125 >                                /// Set/change cooked ray callback
126          void                    SetCookedCall(RayReportCall *cb, void *cd = NULL) {
127                                          if (cookedCall && (cookedCall != cb) | (ccData != cd))
128                                                  FlushQueue();
129                                          cookedCall = cb;
130 <                                        ccData = cd;
130 >                                        ccData = cb ? cd : NULL;
131                                  }
132                                  /// Set/change trace callback
133          void                    SetTraceCall(RayReportCall *cb, void *cd = NULL) {
134                                          traceCall = cb;
135 <                                        tcData = cd;
135 >                                        tcData = cb ? cd : NULL;
136                                  }
137                                  /// Are we ready?
138          bool                    Ready() const {
139                                          return (cookedCall != NULL) | (traceCall != NULL) &&
140                                                  RadSimulManager::Ready();
141                                  }
142 <                                /// Finish pending rays and complete callbacks
143 <        bool                    FlushQueue();
142 >                                /// Finish pending rays and complete callbacks (return #sent)
143 >        int                     FlushQueue();
144                                  /// Close octree, free data, return status
145 <        int                     Cleanup() {
145 >        int                     Cleanup(bool everything = false) {
146                                          SetCookedCall(NULL);
147                                          SetTraceCall(NULL);
148                                          rtFlags = 0;
149                                          UpdateMode();
150                                          lastRayID = 0;
151 <                                        return RadSimulManager::Cleanup();
151 >                                        return RadSimulManager::Cleanup(everything);
152                                  }
153   };
154  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines