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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines