VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
statePropertiesStateComponent.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2021 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
13 #include <vrfutil/rwUUID.h>
14 #include "vrfutil/echelonId.h"
15 #include <vlutil/vlTime.h>
16 #include "legionDataStore/writeStateInstance.h"
17 #include "legionDataStore/readStateInstance.h"
18 #include "legionDataStore/view.h"
19 #include "vrfOM/sets/readStatePropertiesRepository.hpp"
20 #include "vrfOM/sets/writeStatePropertiesRepository.hpp"
21 
22 namespace makVrf
23 {
24  class DtStatePropertiesStateComponentDataStore;
25 
28  {
31  : myStateProperties("state-properties")
32  , myStatePropertiesUpdated(false)
33  , myParameterProperties(new DtRwProperties("parameter-properties"))
34  {
35  }
36 
39  : myStateProperties(orig.myStateProperties)
40  , myStatePropertiesUpdated(orig.myStatePropertiesUpdated)
41  , myParameterProperties(orig.myParameterProperties)
42  {
43  }
44 
47  {
48  myParameterProperties = rhs.myParameterProperties;
49  myStateProperties = rhs.myStateProperties;
50  myStatePropertiesUpdated = true;
51 
52  return *this;
53  }
54 
57  {
58  myStatePropertiesUpdated = false;
59  }
60 
63  {
64  myStatePropertiesUpdated = true;
65  }
66 
70  {
71  myStateProperties.clearVariables();
72  std::vector<DtReaderWriterRegistryData*>::const_iterator itr = other.registry().registryData().begin();
73  std::vector<DtReaderWriterRegistryData*>::const_iterator end = other.registry().registryData().end();
74  for(; itr != end; ++itr)
75  {
76  const DtPropertyInterface* iface = dynamic_cast<const DtPropertyInterface*>((*itr)->readerWriter());
77 
78  if (!iface || iface->isPublished())
79  {
80  const DtReaderWriter* otherRw = (*itr)->readerWriter();
82  otherRw, &myStateProperties.registry());
83  }
84  }
85  }
86 
88  const DtRwProperties& parameterProperties() const { return *(myParameterProperties.get()); };
90  DtRwProperties& parameterProperties() { return *(myParameterProperties.get()); };
91 
92  DEFINE_REF_ACCESSORS(DtRwProperties, stateProperties, StateProperties)
93  DEFINE_ACCESSOR_MUTATOR(bool, statePropertiesUpdated, StatePropertiesUpdated)
94 
95  protected:
97  DtRwProperties myStateProperties;
99  bool myStatePropertiesUpdated;
101  std::shared_ptr<DtRwProperties> myParameterProperties;
102  };
103 
107  {
108  public:
110  typedef std::map<DtString, DtString> ExtendedData;
112 
113 
116  : DtFrameStateInterface(storage)
117  {
118  }
119 
121  UNDEFINED_RETURNREF_ACCESSOR(bool, statePropertiesUpdated)
122  UNDEFINED_RETURNREF_ACCESSORS(DtRwProperties, parameterProperties)
123  UNDEFINED_METHOD(void, setParameterProperties, const DtRwProperties&)
124 
125  virtual void setStateProperties(const DtRwProperties&) { throw DtUnimplementedMethod("setStateProperties(const DtRwProperties& key) is not implemented for this class"); };
126  };
127 
130  {
131  public:
135  virtual ~DtStatePropertiesStateComponentNextFrame() override;
136 
138  const DtStatePropertiesStateComponentData& frameState() const { return myData; };
140 
142  virtual const DtRwProperties& stateProperties() const override;
144  virtual DtRwProperties& stateProperties() override;
147  virtual void setStateProperties(const DtRwProperties&) override;
148 
150  virtual const bool& statePropertiesUpdated() const override;
151 
153  virtual const DtRwProperties& parameterProperties() const override;
155  virtual DtRwProperties& parameterProperties() override;
158  virtual void setParameterProperties(const DtRwProperties&) override;
160  virtual bool isModified() const override;
161 
163  virtual void makeWritable() override;
164 
166  virtual void makeReadOnly() override;
167 
170  {
171  return myStatePropertiesModified;
172  }
173 
176  {
177  myStatePropertiesModified = false;
178  }
179 
181  void setPublishingOnLegionNetwork(bool);
182 
185  void updateLegionNetwork(double newTime);
186 
189  {
190  return myLastTimeStatePropertiesUpdated;
191  }
192 
194  void markUpdated();
195 
196  protected:
198  VRF::WriteStatePropertiesRepository myWriteStatePropertiesRepository;
204  std::map<std::string, Legion::InstanceHandle> myLegionStateProperties;
208  double myLastTimeStatePropertiesUpdated = 0.;
209  };
210 
213  {
214  public:
219 
221  const DtStatePropertiesStateComponentData& frameState() const { return myData; };
222 
224  virtual const DtRwProperties& stateProperties() const override;
226  virtual const bool& statePropertiesUpdated() const override;
228  virtual const DtRwProperties& parameterProperties() const override;
229 
232  virtual bool findReadComponent();
234  virtual bool readComponentValid() const;
235 
238  void setPublishingOnLegionNetwork(bool);
239 
242  {
243  return myStatePropertiesModifiedByLegion;
244  }
245 
248  {
249  myStatePropertiesModifiedByLegion = false;
250  }
251 
252  protected:
255  void handleStatePropertiesUpdated();
256 
257  protected:
263  bool updateOnlyModifiedStatePropertiesSince(const DtRwProperties& source, double since);
267  {
268  myData.parameterProperties() = data.parameterProperties();
269  }
270 
271  protected:
273  VRF::ReadStatePropertiesRepository myReadStatePropertiesRepository;
275  unsigned int myCallbackHandle;
279  std::map<std::string, double> myLastTimeUpdated;
284  };
285 
289  {
290  public:
296 
298  bool isDoubleBuffered() { return true; };
300  virtual const DtFrameStateInterface* currentFrameState() const override { return &myCurrentFrameState; }
302  virtual DtFrameStateInterface* nextFrameState() override { return &myNextFrameState; };
304  virtual const DtFrameStateInterface* nextFrameState() const override { return &myNextFrameState; };
305 
307  virtual void updateDataStorage() override;
308 
311  virtual void updateStateData(DtStateData* sd) override
312  {
313  myCurrentFrameState.updateStateData(sd);
314  myNextFrameState.updateStateData(sd);
315  }
316 
318  virtual bool forceAdvance() override;
319 
322  virtual void initializeFromParameters(const DtVrfObjectParameters* params) override;
323 
325  virtual void aboutToBeDeleted() override
326  {
328  myCurrentFrameState.aboutToBeDeleted();
329  myNextFrameState.aboutToBeDeleted();
330  }
331 
333  virtual void setPublishingOnLegionNetwork(bool) override;
334 
335  protected:
342  };
343 
347 }
void copyOnlPublishedStateProperties(const DtRwProperties &other)
Copies only the published state properties from other into this object.
Definition: statePropertiesStateComponent.h:69
Instances of DtVrfObjectParameters are the readable/writeable objects that contain the information ne...
Definition: vrfObjectParameters.h:64
DtStatePropertiesStateComponentData()
Constructs a default instance with empty state and parameter properties.
Definition: statePropertiesStateComponent.h:30
1) Define the interface class that will be used to represent the next and curent frames. The UNDEFINED_ macros are convenience macros that will define methods that throw exceptions (until they are implemented)
Definition: statePropertiesStateComponent.h:106
std::map< std::string, double > myLastTimeUpdated
Map from property name to the last time it was updated from Legion.
Definition: statePropertiesStateComponent.h:279
std::map< DtString, DtString > ExtendedData
Map type used for extended data key/value pairs.
Definition: statePropertiesStateComponent.h:110
DtStatePropertiesStateComponentNextFrame myNextFrameState
The next frame state (write access).
Definition: statePropertiesStateComponent.h:339
Exception thrown when a required method has not been implemented.
Definition: stateDataTypes.h:30
bool statePropertiesModified() const
Returns true if state properties have been modified in the next frame.
Definition: statePropertiesStateComponent.h:169
Holds the actual data for one frame of state properties associated with a simulated object...
Definition: statePropertiesStateComponent.h:27
#define UNDEFINED_METHOD(Type, Method,...)
Defines a virtual non-const method with variadic parameters that throws DtUnimplementedMethod, requiring an override in a derived class.
Definition: doubleBufferedDataStorage.h:138
bool myStatePropertiesModified
Flag indicating state properties were modified in the next frame.
Definition: statePropertiesStateComponent.h:200
2) Define the next frame class. This will be used for write access.
Definition: statePropertiesStateComponent.h:129
VRF::WriteStatePropertiesRepository myWriteStatePropertiesRepository
Legion write repository for state properties.
Definition: statePropertiesStateComponent.h:198
double lastTimeStatePropertiesUpdated() const
Returns the simulation time at which state properties were last updated.
Definition: statePropertiesStateComponent.h:188
VRF::ReadStatePropertiesRepository myReadStatePropertiesRepository
Legion read repository for state properties.
Definition: statePropertiesStateComponent.h:273
Default creator implementation for a state component type. T_StateComponent is the concrete component...
Definition: stateComponent.h:326
const DtStatePropertiesStateComponentData & frameState() const
Next frame access write access. Ensure this is only used in a single thread (i.e.a controller thread)...
Definition: statePropertiesStateComponent.h:138
void clearStatePropertiesModifiedByLegion()
Clears the flag indicating state properties were modified by the Legion network.
Definition: statePropertiesStateComponent.h:247
const std::vector< DtReaderWriterRegistryData * > & registryData() const
Definition: readerWriterRegistry.h:161
unsigned int myCallbackHandle
Handle for the Legion instance updated callback.
Definition: statePropertiesStateComponent.h:275
Definition: readerWriter.h:85
DtStatePropertiesStateComponentCurrentFrame myCurrentFrameState
The current frame state (read access).
Definition: statePropertiesStateComponent.h:337
#define UNDEFINED_RETURNREF_ACCESSORS(ReturnType, Member)
Defines both const and non-const virtual reference accessors that throw DtUnimplementedMethod, requiring overrides in a derived class.
Definition: doubleBufferedDataStorage.h:74
Contains the DtUUID class declaration.
#define UNDEFINED_RETURNREF_ACCESSOR(ReturnType, Member)
Defines a virtual const reference accessor that throws DtUnimplementedMethod, marking the method as r...
Definition: doubleBufferedDataStorage.h:60
virtual void updateStateData(DtStateData *sd) override
Updates the state data pointer for both current and next frame states.
Definition: statePropertiesStateComponent.h:311
void clearStatePropertiesUpdated()
Clears the flag indicating state properties were updated this frame.
Definition: statePropertiesStateComponent.h:56
Interface class used to define minimal interface for a property. The DtPropertyInterface class provid...
Definition: propertyInterface.h:53
virtual DtReaderWriter * cloneReaderWriter(const DtString &name, const DtReaderWriter *sourceRw, DtReaderWriterRegistry *parentRegistry) const
Creates a clone of the RW object to create a clone of the specified object. The object will first be ...
static DtReaderWriterFactory * factory()
virtual const DtFrameStateInterface * nextFrameState() const override
Returns the next frame state interface (const).
Definition: statePropertiesStateComponent.h:304
DtStatePropertiesStateComponentData & frameState()
Definition: statePropertiesStateComponent.h:139
3) Define the current frame class. This will be used for read access.
Definition: statePropertiesStateComponent.h:212
virtual DtFrameStateInterface * nextFrameState() override
Returns the next frame state interface (mutable).
Definition: statePropertiesStateComponent.h:302
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:513
void clearStatePropertiesModified()
Clears the state properties modified flag.
Definition: statePropertiesStateComponent.h:175
const DtReaderWriterRegistry & registry() const
Collection of child DtReaderWriter nodes owned by this object.
Definition: readerWriter.h:492
#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
virtual const DtFrameStateInterface * currentFrameState() const override
Returns the current frame state interface (const).
Definition: statePropertiesStateComponent.h:300
DtStatePropertiesStateComponentData myData
The next frame data storage.
Definition: statePropertiesStateComponent.h:206
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:489
const DtStatePropertiesStateComponentData & frameState() const
Current frame state only can access current frame buffers. This ensures thread safety.
Definition: statePropertiesStateComponent.h:221
std::map< std::string, Legion::InstanceHandle > myLegionStateProperties
Map from property name to Legion instance handle.
Definition: statePropertiesStateComponent.h:204
virtual void aboutToBeDeleted()
Called when the component is about to be deleted; emits signal_stateComponentAboutToBeDeleted.
virtual void aboutToBeDeleted() override
Called before the component is deleted; propagates to both frame states.
Definition: statePropertiesStateComponent.h:325
const char * source
Definition: lz4.h:442
void advanceFrame(const DtStatePropertiesStateComponentData &data)
Advances the current frame by copying parameter properties from data.
Definition: statePropertiesStateComponent.h:266
virtual bool isPublished() const =0
Whether this property should be published.
#define DEFINE_REF_ACCESSORS(ReturnType, Method, Member)
Defines const and non-const reference accessors for a member variable.
Definition: doubleBufferedDataStorage.h:17
#define DEFINE_ACCESSOR_MUTATOR(ReturnType, Accessor, Mutator)
Defines a const reference accessor and an inline setter for a member variable.
Definition: doubleBufferedDataStorage.h:37
bool myStatePropertiesModifiedByLegion
Flag indicating state properties were modified by an incoming Legion update.
Definition: statePropertiesStateComponent.h:281
const DtRwProperties & parameterProperties() const
Returns the parameter properties (const).
Definition: statePropertiesStateComponent.h:88
bool statePropertiesModifiedByLegion() const
Returns true if state properties were modified by an incoming Legion network update.
Definition: statePropertiesStateComponent.h:241
DtStatePropertiesStateComponentData & operator=(const DtStatePropertiesStateComponentData &rhs)
Assignment operator. Copies member data and marks state properties as updated.
Definition: statePropertiesStateComponent.h:46
bool myFoundComponent
Tracks whether the Legion read component has been successfully located.
Definition: statePropertiesStateComponent.h:341
DtStatePropertiesStateComponentData myData
The current frame data storage.
Definition: statePropertiesStateComponent.h:283
bool isDoubleBuffered()
Returns true, indicating this component uses double-buffered storage.
Definition: statePropertiesStateComponent.h:298
#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
bool myPublishOnLegionNetwork
Flag indicating whether to publish on the Legion network.
Definition: statePropertiesStateComponent.h:277
A list of properties. A DtPropertyInterface object that is a specialized version of DtRwVariableBindi...
Definition: rwProperties.h:122
void statePropertiesWereUpdated()
Marks state properties as having been updated this frame.
Definition: statePropertiesStateComponent.h:62
DtRwProperties & parameterProperties()
Returns the parameter properties (mutable).
Definition: statePropertiesStateComponent.h:90
Contains the DtStateComponent class declaration.
bool myPublishOnLegionNetwork
Flag indicating whether to publish on the Legion network.
Definition: statePropertiesStateComponent.h:202
DtRwProperties myStateProperties
The state properties container.
Definition: statePropertiesStateComponent.h:90
4) Define the state component that will contain the wrappers to the next and current frame states tha...
Definition: statePropertiesStateComponent.h:288
virtual DtSymbolString name() const
Accessor for name of this readable/writable object.
DtStateComponentCreator< DtStatePropertiesStateComponentImplementation > DtStatePropertiesStateComponentCreator
5) Define the creator. This will need to be registered with the REGISTER_STATE_COMPONENT macro in the...
Definition: statePropertiesStateComponent.h:346
Base interface for accessing current or next frame state in a double-buffered state component...
Definition: stateComponent.h:354
DtStatePropertiesStateComponentData(const DtStatePropertiesStateComponentData &orig)
Copy constructor.
Definition: statePropertiesStateComponent.h:38
std::shared_ptr< DtRwProperties > myParameterProperties
The parameter properties, shared across copies.
Definition: statePropertiesStateComponent.h:101

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)