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.4 by greg, Wed Aug 2 00:04:31 2023 UTC vs.
Revision 2.9 by greg, Sat Aug 3 01:54:46 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   protected:
28                                  // Assign ray to subthread (fails if NThreads()<2)
29          bool                    SplitRay(RAY *r);
30   public:
31                                  RadSimulManager(const char *octn = NULL) {
32 +                                        header = NULL;
33                                          LoadOctree(octn);
31                                        nThreads = 1;
34                                  }
35                                  ~RadSimulManager() {
36                                          Cleanup();
37                                  }
38                                  /// Load octree and prepare renderer
39          bool                    LoadOctree(const char *octn);
40 <                                /// How many cores are there?
40 >                                /// Prepare header from previous input (or clear)
41 >                                /// Normally called during octree load
42 >        bool                    NewHeader(const char *fname=NULL);
43 >                                /// Add a string to header (adds newline if none)
44 >        bool                    AddHeader(const char *str);
45 >                                /// Append program line to header
46 >        bool                    AddHeader(int ac, const char *av[]);
47 >                                /// Get header lines if any
48 >        const char *            GetHeader() const {
49 >                                        return header;
50 >                                }
51 >                                /// How many cores are available?
52          static int              GetNCores();
53                                  /// Set number of computation threads (0 => #cores)
54          int                     SetThreadCount(int nt = 0);
55                                  /// Check thread count (1 means no multi-threading)
56          int                     NThreads() const {
57 <                                        return nThreads;
57 >                                        return ray_pnprocs + !ray_pnprocs;
58                                  }
59                                  /// How many threads are currently unoccupied?
60          int                     ThreadsAvailable() const;
61                                  /// Are we ready?
62          bool                    Ready() const {
63 <                                        return (octname && nsceneobjs > 0);
63 >                                        return (octname && nobjects > 0);
64                                  }
65                                  /// Process a ray (in subthread), optional result
66          bool                    ProcessRay(RAY *r);
# Line 69 | Line 82 | class RtraceSimulManager : public RadSimulManager {
82          int                     curFlags;       // current operating flags
83                                  // Call-back for global ray-tracing context
84          static void             RTracer(RAY *r);
85 +                                // Call-back for FIFO
86 +        static int              Rfifout(RAY *r);
87                                  // Check for changes to render flags, etc.
88          bool                    UpdateMode();
89   protected:
75                                // Add a ray result to FIFO, flushing what we can
76        int                     QueueResult(const RAY &ra);
90          RNUMBER                 lastRayID;      // last ray ID assigned
91   public:
92          int                     rtFlags;        // operation (RT*) flags
# Line 89 | Line 102 | class RtraceSimulManager : public RadSimulManager {
102                                  }
103                                  /// Set number of computation threads (0 => #cores)
104          int                     SetThreadCount(int nt = 0) {
105 <                                        if (nt <= 0) nt = GetNCores();
105 >                                        if (nt <= 0) nt = castonly ? 1 : GetNCores();
106                                          if (nt == NThreads()) return nt;
107 <                                        FlushQueue();
107 >                                        if (FlushQueue() < 0) return 0;
108                                          return RadSimulManager::SetThreadCount(nt);
109                                  }
110                                  /// Add ray bundle to queue w/ optional 1st ray ID
# Line 106 | Line 119 | class RtraceSimulManager : public RadSimulManager {
119                                          VCOPY(orgdir[0], org); VCOPY(orgdir[1], dir);
120                                          return(EnqueueBundle(orgdir, 1, rID) > 0);
121                                  }
122 <                                /// Set/change cooked ray callback & FIFO flag
122 >                                /// Set/change cooked ray callback
123          void                    SetCookedCall(RayReportCall *cb, void *cd = NULL) {
124                                          if (cookedCall && (cookedCall != cb) | (ccData != cd))
125                                                  FlushQueue();
126                                          cookedCall = cb;
127 <                                        ccData = cd;
127 >                                        ccData = cb ? cd : NULL;
128                                  }
129                                  /// Set/change trace callback
130          void                    SetTraceCall(RayReportCall *cb, void *cd = NULL) {
131                                          traceCall = cb;
132 <                                        tcData = cd;
132 >                                        tcData = cb ? cd : NULL;
133                                  }
134                                  /// Are we ready?
135          bool                    Ready() const {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines