VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
subsurfaceStateComponent.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2023 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
12 #include <vrfutil/rwWindLevels.h>
13 #include <tbb/spin_rw_mutex.h>
14 
15 namespace makVrf
16 {
17 
20  {
23  : myDepth(0.)
24  , myPermeability(0.)
25  , myThickness(0.)
26  , myPriority(0)
27  {
28 
29  };
35  DtVrfSubsurfaceLayer(double depth, double thickness, double permeability, int priority)
36  : myDepth(depth)
37  , myThickness(thickness)
38  , myPermeability(permeability)
39  , myPriority(priority)
40  {
41 
42  };
46  {
47  *this = orig;
48  };
49 
54  {
55  {
56  myDepth = orig.myDepth;
57  myPermeability = orig.myPermeability;
58  myPriority = orig.myPriority;
59  myThickness = orig.myThickness;
60  }
61  return *this;
62  };
63 
67  bool operator<(const DtVrfSubsurfaceLayer& other) const
68  {
69  return myDepth < other.myDepth;
70  };
71 
75  bool operator==(const DtVrfSubsurfaceLayer& other) const
76  {
77  return (myDepth == other.myDepth
78  && myPriority == other.myPriority
79  && myThickness == other.myThickness
80  && myPermeability == other.myPermeability);
81  };
85  bool operator!=(const DtVrfSubsurfaceLayer& other) const
86  {
87  return !(*this == other);
88  };
89  ACCESSOR_MUTATOR_MEMBER(double, depth, Depth);
90  ACCESSOR_MUTATOR_MEMBER(double, thickness, Thickness);
91  ACCESSOR_MUTATOR_MEMBER(double, permeability, Permeability);
92  ACCESSOR_MUTATOR_MEMBER(int, priority, Priority);
93  };
94 
96  typedef std::multiset<DtVrfSubsurfaceLayer> DtVrfSubsurfaceLayerSet;
97 
98 
101  {
104  : myUnderwaterVisibility(0.)
105  , mySubsurfaceLayers()
106  , myAmbientWaterTemperature(0.)
107  , myPriority(0)
108  {};
109 
113  {
114  *this = orig;
115  };
116 
121  {
122  {
123  myUnderwaterVisibility = orig.myUnderwaterVisibility;
124  mySubsurfaceLayers = orig.mySubsurfaceLayers;
125  myAmbientWaterTemperature = orig.myAmbientWaterTemperature;
126  myPriority = orig.myPriority;
127  }
128  return *this;
129  };
130 
131  ACCESSOR_MUTATOR_MEMBER(double, underwaterVisibility, UnderwaterVisibility);
132  ACCESSOR_MUTATOR_MEMBER(DtVrfSubsurfaceLayerSet, subsurfaceLayers, SubsurfaceLayers);
133  ACCESSOR_MUTATOR_MEMBER(double, ambientWaterTemperature, AmbientWaterTemperature);
134  ACCESSOR_MUTATOR_MEMBER(unsigned int, priority, Priority);
135  };
136 
140  {
141  public:
143 
144 
147  : DtFrameStateInterface(storage)
148  {
149  }
150 
151  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, underwaterVisibility, UnderwaterVisibility);
152  UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(DtVrfSubsurfaceLayerSet, subsurfaceLayers, SubsurfaceLayers);
153  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer1Depth, ThermoclineLayer1Depth);
154  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer1Thickness, ThermoclineLayer1Thickness);
155  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer1Permeability, ThermoclineLayer1Permeability);
156  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer2Depth, ThermoclineLayer2Depth);
157  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer2Thickness, ThermoclineLayer2Thickness);
158  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer2Permeability, ThermoclineLayer2Permeability);
159  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer3Depth, ThermoclineLayer3Depth);
160  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer3Thickness, ThermoclineLayer3Thickness);
161  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer3Permeability, ThermoclineLayer3Permeability);
162  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer4Depth, ThermoclineLayer4Depth);
163  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer4Thickness, ThermoclineLayer4Thickness);
164  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer4Permeability, ThermoclineLayer4Permeability);
165  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer5Depth, ThermoclineLayer5Depth);
166  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer5Thickness, ThermoclineLayer5Thickness);
167  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, thermoclineLayer5Permeability, ThermoclineLayer5Permeability);
168  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(double, ambientWaterTemperature, AmbientWaterTemperature);
169  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(int, priority, Priority);
170 
173  virtual void addSubsurfaceLayer(const DtVrfSubsurfaceLayer& layerToAdd) { throw DtUnimplementedMethod("addSubsurfaceLayer is not implemented by this class."); };
176  virtual void removeSubsurfaceLayer(const DtVrfSubsurfaceLayer& layerToRemove) { throw DtUnimplementedMethod("removeSubsurfaceLayer is not implemented by this class."); };
177 
180  void setIsRemoteComponent(bool b) { myIsRemoteComponent = b; };
181 
182  protected:
184  bool myIsRemoteComponent = false;
185  };
186 
191 #define THERMOCLINE_GETTER(number, Accessor, Setter) \
192  const double thermoclineLayer##number####Setter() const override \
193  { \
194  const unsigned indexToUse = number - 1; \
195  DtVrfSubsurfaceLayer dummy; \
196  thermoclineLayer(indexToUse, dummy); \
197  return dummy.Accessor(); \
198  };
199 
205 #define THERMOCLINE_SETTER(number, Accessor, Setter) \
206  void setThermoclineLayer##number####Setter( const double& Accessor ) override \
207  { \
208  const unsigned indexToUse = number - 1; \
209  DtVrfSubsurfaceLayer dummy; \
210  thermoclineLayer(indexToUse, dummy); \
211  if (dummy.Accessor() != Accessor) \
212  { \
213  dummy.set##Setter(Accessor); \
214  markModified(); \
215  setThermoclineLayerByIndex(dummy, indexToUse); \
216  } \
217  };
218 
223 #define THERMOCLINE_SETTER_GETTER(number, Accessor, Setter) \
224  THERMOCLINE_GETTER(number, Accessor, Setter); \
225  THERMOCLINE_SETTER(number, Accessor, Setter);
226 
227 
228 
234 #define NEXTFRAME_ACCESSOR_MUTATOR_(MemberType, Accessor, MutatorAndMember) \
235  public: \
236  const MemberType Accessor() const override { return frameState().Accessor(); }; \
237  void set##MutatorAndMember(const MemberType& v) override { if (frameState().Accessor() != v) { markModified(); frameState().set##MutatorAndMember(v); } };
238 
240  class DT_DLL_vrfStateData DtSubsurfaceStateComponentNextFrame : public DtStateComponentNextFrameTemplate< DtSubsurfaceStateComponent, DtSubsurfaceStateComponentData >
241  {
242  public:
247  {
248 
249  };
252 
253  NEXTFRAME_ACCESSOR_MUTATOR(double, underwaterVisibility, UnderwaterVisibility);
254  NEXTFRAME_ACCESSOR_BY_REF_MUTATOR(DtVrfSubsurfaceLayerSet, subsurfaceLayers, SubsurfaceLayers);
255  NEXTFRAME_ACCESSOR_MUTATOR(double, ambientWaterTemperature, AmbientWaterTemperature);
256  NEXTFRAME_ACCESSOR_MUTATOR(int, priority, Priority);
257 
258  THERMOCLINE_SETTER_GETTER(1, depth, Depth);
259  THERMOCLINE_SETTER_GETTER(1, thickness, Thickness);
260  THERMOCLINE_SETTER_GETTER(1, permeability, Permeability);
261 
262  THERMOCLINE_SETTER_GETTER(2, depth, Depth);
263  THERMOCLINE_SETTER_GETTER(2, thickness, Thickness);
264  THERMOCLINE_SETTER_GETTER(2, permeability, Permeability);
265 
266  THERMOCLINE_SETTER_GETTER(3, depth, Depth);
267  THERMOCLINE_SETTER_GETTER(3, thickness, Thickness);
268  THERMOCLINE_SETTER_GETTER(3, permeability, Permeability);
269 
270  THERMOCLINE_SETTER_GETTER(4, depth, Depth);
271  THERMOCLINE_SETTER_GETTER(4, thickness, Thickness);
272  THERMOCLINE_SETTER_GETTER(4, permeability, Permeability);
273 
274  THERMOCLINE_SETTER_GETTER(5, depth, Depth);
275  THERMOCLINE_SETTER_GETTER(5, thickness, Thickness);
276  THERMOCLINE_SETTER_GETTER(5, permeability, Permeability);
277 
281  virtual void addSubsurfaceLayer(const DtVrfSubsurfaceLayer& layerToAdd) override;
285  virtual void removeSubsurfaceLayer(const DtVrfSubsurfaceLayer& layerToAdd) override;
286  protected:
291  bool thermoclineLayer(unsigned int index, DtVrfSubsurfaceLayer& layer) const;
296  bool removeThermoclineLayer(unsigned int index, DtVrfSubsurfaceLayer& layer);
300  void setThermoclineLayerByIndex(DtVrfSubsurfaceLayer layer, unsigned int index);
301 
302  protected:
304  mutable tbb::spin_rw_mutex myMutex;
305  };
306 
308  class DT_DLL_vrfStateData DtSubsurfaceStateComponentCurrentFrame : public DtStateComponentCurrentFrameTemplate< DtSubsurfaceStateComponent, DtSubsurfaceStateComponentNextFrame, DtSubsurfaceStateComponentData>
309  {
310  public:
315  {
316  };
317 
318  CURRENTFRAME_ACCESSOR(double, underwaterVisibility, UnderwaterVisibility);
319  CURRENTFRAME_ACCESSOR_BY_REF(DtVrfSubsurfaceLayerSet, subsurfaceLayers, SubsurfaceLayers);
320  CURRENTFRAME_ACCESSOR(double, ambientWaterTemperature, AmbientWaterTemperature);
321  CURRENTFRAME_ACCESSOR(int, priority, Priority);
322 
323 
324 
325  THERMOCLINE_GETTER(1, depth, Depth);
326  THERMOCLINE_GETTER(1, thickness, Thickness);
327  THERMOCLINE_GETTER(1, permeability, Permeability);
328 
329  THERMOCLINE_GETTER(2, depth, Depth);
330  THERMOCLINE_GETTER(2, thickness, Thickness);
331  THERMOCLINE_GETTER(2, permeability, Permeability);
332 
333  THERMOCLINE_GETTER(3, depth, Depth);
334  THERMOCLINE_GETTER(3, thickness, Thickness);
335  THERMOCLINE_GETTER(3, permeability, Permeability);
336 
337  THERMOCLINE_GETTER(4, depth, Depth);
338  THERMOCLINE_GETTER(4, thickness, Thickness);
339  THERMOCLINE_GETTER(4, permeability, Permeability);
340 
341  THERMOCLINE_GETTER(5, depth, Depth);
342  THERMOCLINE_GETTER(5, thickness, Thickness);
343  THERMOCLINE_GETTER(5, permeability, Permeability);
344 
345  protected:
350  bool thermoclineLayer(unsigned int index, DtVrfSubsurfaceLayer& layer) const;
351  };
352 
356 
360 
361 }
Exception thrown when a required method has not been implemented.
Definition: stateDataTypes.h:30
virtual void removeSubsurfaceLayer(const DtVrfSubsurfaceLayer &layerToRemove)
Removes a subsurface layer. Must be overridden by a concrete subclass.
Definition: subsurfaceStateComponent.h:176
bool operator==(const DtVrfSubsurfaceLayer &other) const
Equality comparison. All properties must match for layers to be considered equal. ...
Definition: subsurfaceStateComponent.h:75
DtVrfSubsurfaceLayer(const DtVrfSubsurfaceLayer &orig)
Copy constructor.
Definition: subsurfaceStateComponent.h:45
Template for the next-frame (writable) portion of a double-buffered state component. Frame-state access is intended for single-threaded use from a controller thread.
Definition: stateComponentImplementationTemplate.h:87
Default creator implementation for a state component type. T_StateComponent is the concrete component...
Definition: stateComponent.h:326
#define NEXTFRAME_ACCESSOR_BY_REF_MUTATOR(MemberType, Accessor, MutatorAndMember)
Declares a public next-frame accessor (by const reference) and next-frame mutator pair...
Definition: stateComponentImplementationTemplate.h:72
DtSubsurfaceStateComponentData()
Default constructor. Initializes all data members to zero.
Definition: subsurfaceStateComponent.h:103
virtual ~DtSubsurfaceStateComponentNextFrame() override
Destructor.
Definition: subsurfaceStateComponent.h:251
#define THERMOCLINE_GETTER(number, Accessor, Setter)
Generates a const getter for a thermocline layer property at the given 1-based layer number...
Definition: subsurfaceStateComponent.h:191
0) Define the State Component Data. This struct replaces the legion stuff
Definition: subsurfaceStateComponent.h:100
#define CURRENTFRAME_ACCESSOR_BY_REF(MemberType, Accessor, MutatorAndMember)
Declares a read-only current-frame accessor (by const reference). The MutatorAndMember parameter is u...
Definition: stateComponentImplementationTemplate.h:81
#define CURRENTFRAME_ACCESSOR(MemberType, Accessor, MutatorAndMember)
Declares a read-only current-frame accessor (by value). The MutatorAndMember parameter is unused...
Definition: stateComponentImplementationTemplate.h:77
bool operator<(const DtVrfSubsurfaceLayer &other) const
Less-than comparison based on depth, used for ordering in the multiset.
Definition: subsurfaceStateComponent.h:67
Template that combines a current-frame and next-frame sub-component into a fully double-buffered stat...
Definition: stateComponentImplementationTemplate.h:111
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:513
#define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent)
Macro to define all required static and virtual state component type methods. Place in the public sec...
Definition: stateComponent.h:272
#define NEXTFRAME_ACCESSOR_MUTATOR(MemberType, Accessor, MutatorAndMember)
Declares a public next-frame accessor (by value) and next-frame mutator pair.
Definition: stateComponentImplementationTemplate.h:62
DtSubsurfaceStateComponentCurrentFrame(DtStateData *sd)
Constructs a current-frame state component backed by the given state data storage.
Definition: subsurfaceStateComponent.h:313
2) Define the next frame class. This will be used for write access.
Definition: subsurfaceStateComponent.h:240
1) Define the interface class that will be used to represent the next and current frames...
Definition: subsurfaceStateComponent.h:139
DtVrfSubsurfaceLayer()
Default constructor. Initializes all values to zero.
Definition: subsurfaceStateComponent.h:22
#define UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(Type, Member, Set)
Defines an undefined virtual by-value accessor and an undefined virtual setter, both throwing DtUnimp...
Definition: doubleBufferedDataStorage.h:103
DtSubsurfaceStateComponentNextFrame(DtStateData *sd)
Constructs a next-frame state component backed by the given state data storage.
Definition: subsurfaceStateComponent.h:245
DtStateComponentCreator< DtSubsurfaceStateComponentImplementation > DtSubsurfaceStateComponentCreator
5) Define the creator. This will need to be registered with the REGISTER_STATE_COMPONENT macro in the...
Definition: subsurfaceStateComponent.h:359
bool operator!=(const DtVrfSubsurfaceLayer &other) const
Inequality comparison.
Definition: subsurfaceStateComponent.h:85
virtual void addSubsurfaceLayer(const DtVrfSubsurfaceLayer &layerToAdd)
Adds a subsurface layer. Must be overridden by a concrete subclass.
Definition: subsurfaceStateComponent.h:173
DtVrfSubsurfaceLayer(double depth, double thickness, double permeability, int priority)
Constructs a subsurface layer with the specified properties.
Definition: subsurfaceStateComponent.h:35
#define UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(Type, Member, Set)
Defines an undefined virtual const-reference accessor and an undefined virtual setter, both throwing DtUnimplementedMethod and requiring overrides in a derived class.
Definition: doubleBufferedDataStorage.h:112
Represents a single subsurface (thermocline) layer defined by depth, thickness, permeability, and priority.
Definition: subsurfaceStateComponent.h:19
#define ACCESSOR_MUTATOR_MEMBER(MemberType, Accessor, MutatorAndMember)
Declares a public accessor (by value and reference), a public mutator, and a protected member field...
Definition: stateComponentImplementationTemplate.h:30
DtSubsurfaceStateComponentData & operator=(const DtSubsurfaceStateComponentData &orig)
Assignment operator.
Definition: subsurfaceStateComponent.h:120
#define DT_DLL_vrfStateData
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfStateDataDefines.h:29
std::multiset< DtVrfSubsurfaceLayer > DtVrfSubsurfaceLayerSet
An ordered multiset of subsurface layers, sorted by depth via operator&lt;.
Definition: subsurfaceStateComponent.h:96
#define THERMOCLINE_SETTER_GETTER(number, Accessor, Setter)
Convenience macro that generates both a getter and a setter for a thermocline layer property...
Definition: subsurfaceStateComponent.h:223
3) Define the current frame class. This will be used for read access.
Definition: subsurfaceStateComponent.h:308
tbb::spin_rw_mutex myMutex
Read-write mutex protecting concurrent access to next-frame state data.
Definition: subsurfaceStateComponent.h:304
DtSubsurfaceStateComponentData(const DtSubsurfaceStateComponentData &orig)
Copy constructor.
Definition: subsurfaceStateComponent.h:112
Contains the DtStateComponent class declaration.
Base interface for accessing current or next frame state in a double-buffered state component...
Definition: stateComponent.h:354
Template for the current-frame (read-only) view of a double-buffered state component. Exposes promoted current-frame data through read-only accessors.
Definition: stateComponentImplementationTemplate.h:176
ACCESSOR_MUTATOR_MEMBER(double, depth, Depth)
DtVrfSubsurfaceLayer & operator=(const DtVrfSubsurfaceLayer &orig)
Assignment operator.
Definition: subsurfaceStateComponent.h:53
void setIsRemoteComponent(bool b)
Sets whether this component represents a remotely controlled entity.
Definition: subsurfaceStateComponent.h:180

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)