VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
stateComponent.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2022 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
14 
15 #include <legionDataStore/writeStateInstance.h>
16 #include <legionDataStore/readStateInstance.h>
17 
18 #include <boost/signals2.hpp>
19 
20 #include <vlutil/vlPrint.h>
21 
22 #include <limits>
23 
24 
28 
29 class Coordinate_System;
30 
31 namespace LOM
32 {
33  class WriteEntityRepository;
34  class ReadEntityRepository;
35 }
36 
37 namespace Legion
38 {
39  class SimulationDatabase;
40 }
41 
42 class DtAppearance;
44 
45 namespace makVrf
46 {
47  class DtStateComponent;
48  class DtStateData;
49  class DtFrameStateInterface;
50 
52  {
53  public:
54 
55  typedef unsigned int StateComponentType;
56 
59  {
60  Undefined = -1,
61  SimulatedObjectStateComponent = 0,
62  EntityStateComponent = SimulatedObjectStateComponent,
63  EnvironmentalStateComponent = SimulatedObjectStateComponent,
64  AggregateStateComponent = SimulatedObjectStateComponent,
65  MetocServiceStateComponent = SimulatedObjectStateComponent,
66  LocationStateComponent = 1,
67  EntityLocationStateComponent = LocationStateComponent,
68  EnvironmentalLocationStateComponent = LocationStateComponent,
69  HumanStateComponent = 2,
70  ArticulatedPartStateComponent = 3,
71  VrfStateComponent = 4,
72  StatePropertiesStateComponent = 5,
73  VrfGeometryStateComponent = 6,
74  SubordinateManagerStateComponent = 7,
75  RangeItemsStateComponent = 8,
76  CloudLayerStateComponent = 9,
77  GlobalEnvironmentStateComponent = 10,
78  WeatherStateComponent = 11,
79  LaserDesignatorStateComponent = 12,
80  EmitterSystemStateComponent = 13,
81  IffStateComponent = 14,
82  ActiveSonarStateComponent = 15,
83  UnderwaterAcousticsStateComponent = 16,
84  SensorFieldOfViewStateComponent = 17,
85  RadioTransmitterStateComponent = 18,
86  TaskVisualizationStateComponent = 19,
87  TacticalSmokeStateComponent = 20,
88  DynamicTerrainStateComponent = 21,
89  RadioReceiverStateComponent = 22,
90  WindCorridorStateComponent = 23,
91  AirTurbulenceStateComponent = 24,
92  NavAidRadioTransmitterStateComponent = 25,
93  UserStateComponent = 64
94  };
95 
96  public:
97 
101 
102  virtual ~DtStateComponent();
103 
104  virtual void advanceFrame();
105 
106  virtual void setCoordinateSystem( const Coordinate_System* );
107 
108  virtual StateComponentType typeWithCreator() const = 0;
109  virtual StateComponentType componentType() const = 0;
110 
111  mutable boost::signals2::signal<void(DtStateComponent*)> signal_stateComponentAboutToBeDeleted;
112  mutable boost::signals2::signal<void(DtStateComponent*)> signal_componentModified;
113 
115  virtual void setStateData( DtStateData* );
116 
118  virtual void setPublishingOnLegionNetwork( bool );
120  {
121  return myPublishingOnLegionNetwork;
122  }
123 
124  void setIsRemoteComponent( bool b )
125  {
126  myIsRemoteComponent = b;
127  }
128 
130  virtual void convertToRemote();
131 
133  virtual void convertToLocal();
134 
135  bool isRemoteComponent() const
136  {
137  return myIsRemoteComponent;
138  }
139 
141  virtual void initializeFromParameters( const DtVrfObjectParameters* );
142 
144  virtual void completeSetup();
145 
146  virtual void aboutToBeDeleted();
147 
149  virtual void setId( UInt64 id );
150 
151  virtual UInt64 id() const
152  {
153  return myId;
154  }
155 
156  bool advancedFrame() const
157  {
158  return myAdvancedFrame;
159  }
160 
162  virtual void firstFrameAdvance();
163 
165  UInt64 stateId() const;
166 
168  UInt64 legionGlobalId() const;
169 
170  const DtStateData* stateData() const
171  {
172  return myStateData;
173  }
174 
175  bool cleared() const
176  {
177  return myCleared;
178  }
179 
181  {
182  return myStateData;
183  }
184 
186  {
187  return myCoordinateSystem;
188  }
189 
191  virtual bool forceAdvance() { return false; };
192 
195  virtual bool isDoubleBuffered() const;
196  virtual const DtFrameStateInterface* currentFrameState() const { throw DtUnimplementedMethod("const DtFrameStateInterface* currentFrameState() const is not implemented."); };
197  virtual DtFrameStateInterface* nextFrameState() { throw DtUnimplementedMethod("DtFrameStateInterface* nextFrameState() is not implemented."); };
198  virtual const DtFrameStateInterface* nextFrameState() const { throw DtUnimplementedMethod("const DtFrameStateInterface* nextFrameState() const is not implemented."); };
199  virtual Legion::WriteStateInstance writeStateInstance() { throw DtUnimplementedMethod("Legion::WriteStateInstance writeStateInstance() is not implemented."); };
200  virtual void addAdditionalStateComponents() {};
201 
204 
205  virtual const char* stringType() const = 0;
206 
207  protected:
208 
213  bool myCleared;
216 
217  };
218 
219  #define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent) \
220  static const DtStateComponent::StateComponentType theComponentType = CreatedComponent; \
221  static const char* StringType() { return #CreatedComponent; } \
222  virtual DtStateComponent::StateComponentType typeWithCreator() const { return TypeWithCreator(); }; \
223  virtual DtStateComponent::StateComponentType componentType() const { return ComponentType(); }; \
224  virtual const char* stringType() const { return #CreatedComponent; }; \
225  static DtStateComponent::StateComponentType TypeWithCreator() { return (DtStateComponent::StateComponentType)((unsigned int)(theComponentCreatorType << 16) | theComponentType); }; \
226  static void SetCreatorType(UInt32 type) { theComponentCreatorType = type; }; \
227  static DtStateComponent::StateComponentType ComponentType() { return theComponentType; }; \
228  static UInt32 CreatorType() { return theComponentCreatorType; }; \
229  protected: \
230  static UInt32 theComponentCreatorType; \
231  public:
232 
233  #define DEFINE_STATE_COMPONENT_HELPER(Component) \
234  static const char* StringType() { return #Component; } \
235  virtual DtStateComponent::StateComponentType typeWithCreator() const { return Component::TypeWithCreator(); }; \
236  virtual DtStateComponent::StateComponentType componentType() const { return Component::ComponentType(); }; \
237  virtual DtStateComponent::StateComponentType setCreatorType(UInt32 type) const { return SetCreatorType(type); }; \
238  virtual const char* stringType() const { return #Component; }; \
239  static DtStateComponent::StateComponentType TypeWithCreator() { return Component::TypeWithCreator(); }; \
240  static DtStateComponent::StateComponentType ComponentType() { return Component::ComponentType(); }; \
241  static UInt32 SetCreatorType(UInt32 type) { Component::SetCreatorType(type); return type; };
242 
245  {
246  public:
247  virtual DtStateComponent* create( DtStateData * ) = 0;
248  virtual DtStateComponent::StateComponentType setCreatorType( UInt32 ) const = 0;
249  virtual DtStateComponent::StateComponentType componentType() const = 0;
250  virtual DtStateComponent::StateComponentType typeWithCreator() const = 0;
251  virtual void registerLegionComponent( Legion::SimulationDatabase* ) = 0;
252  virtual void addAdditionalTableColumns( Legion::SimulationDatabase* ) = 0;
253  virtual bool autoCreateForRemoteObject() const = 0;
254  };
255 
256  template <typename T_StateComponent, bool T_AutoCreateForRemoteObject = true>
258  {
259  public:
260  DEFINE_STATE_COMPONENT_HELPER( T_StateComponent )
261  virtual DtStateComponent* create( DtStateData* sd ) { return new T_StateComponent( sd ); };
262 
263  virtual void registerLegionComponent( Legion::SimulationDatabase* db )
264  {
265  T_StateComponent::registerLegionComponent( db );
266  }
267 
268  virtual void addAdditionalTableColumns( Legion::SimulationDatabase* db )
269  {
270  T_StateComponent::addAdditionalTableColumns( db );
271  }
272 
273  virtual bool autoCreateForRemoteObject() const
274  {
275  return T_AutoCreateForRemoteObject;
276  }
277  };
278 
283  {
284  private:
285 
287  DtFrameStateInterface& operator = ( const DtFrameStateInterface& rhs );
288 
289  public:
290 
292 
293  virtual ~DtFrameStateInterface();
294 
295  void setIsWritable(bool b) { myIsWritable = b; };
296  bool isWritable() const { return myIsWritable; };
297 
298  UInt64 stateId() const { return myStateId; };
299  UInt64 legionGlobalId() const { return myLegionId; };
300  void setLegionGlobalId( UInt64 d ) { myLegionId = d; };
301  bool isModified() const { return myIsModified; };
302  void clearModified() { myIsModified = false; };
303  void markModified() { myIsModified = true; };
304 
305  virtual DtStateComponent::StateComponentType type() const { return componentType(); };
306  virtual DtStateComponent::StateComponentType componentType() const = 0;
307 
308  void setId( UInt64 id ) { myId = id; };
309  virtual UInt64 id() const { return myId; };
310 
311  virtual void updateStateData( DtStateData* sd );
312 
314  virtual Legion::ReadStateInstance readStateInstance() const { throw DtUnimplementedMethod("void readStateInstance() const is not implemented."); };
315  virtual Legion::WriteStateInstance writeStateInstance() { throw DtUnimplementedMethod("void writeStateInstance() const is not implemented."); };
316 
318  {
319  signal_componentModified( this );
320  }
321 
322  bool cleared() const
323  {
324  return myCleared;
325  }
326 
327  bool advancedFrame() const
328  {
329  return myAdvancedFrame;
330  }
331 
332  virtual void frameAdvanced()
333  {
334  myAdvancedFrame = true;
335  }
336 
338  virtual void convertToRemote();
339 
341  virtual void convertToLocal();
342  virtual void aboutToBeDeleted();
343 
344  mutable boost::signals2::signal<void (DtFrameStateInterface*)> signal_stateComponentAboutToBeDeleted;
345  mutable boost::signals2::signal<void (const DtFrameStateInterface*)> signal_componentModified;
346 
347  protected:
348 
350  virtual void makeWritable() { throw DtUnimplementedMethod("void makeWritable() const is not implemented."); };
351 
353  virtual void makeReadOnly() { throw DtUnimplementedMethod("void makeReadOnly() const is not implemented."); };
354 
355  protected:
356 
357  bool myIsModified;
362  bool myCleared;
364 
365  };
366 
367 
369  template <typename T_Component>
371  {
372  public:
373 
374  DEFINE_STATE_COMPONENT_HELPER( T_Component )
375 
377  : DtStateComponent( sd )
378  {
379  }
380 
381  virtual void setId( UInt64 id )
382  {
384 
385  if ( nextFrameState() )
386  {
387  nextFrameState()->setId( id );
388  }
389 
390  if ( currentFrameState() )
391  {
392  const_cast<DtFrameStateInterface*>(currentFrameState())->setId( id );
393  }
394  }
395 
396  virtual void setStateData( DtStateData* sd )
397  {
398  if ( myStateData != sd )
399  {
401 
402  updateStateData( sd );
403  }
404  }
405 
406  virtual bool isDoubleBuffered() const { return true; };
407 
409  virtual bool forceAdvance() { return false; };
410  virtual void advanceFrame()
411  {
412  myAdvancedFrame = true;
413 
414  if ( nextFrameState()->isModified() || forceAdvance() )
415  {
417  const_cast<DtFrameStateInterface*>( currentFrameState() )->markModified();
420  signal_componentModified( this );
421  }
422  else
423  {
425  const_cast<DtFrameStateInterface*>(currentFrameState())->clearModified();
426  }
427 
429  const_cast<DtFrameStateInterface*>(currentFrameState())->frameAdvanced();
430  }
431 
432  static void registerLegionComponent( Legion::SimulationDatabase* ) {};
433  static void addAdditionalTableColumns( Legion::SimulationDatabase* ) {};
434 
436  virtual void updateDataStorage() = 0;
437 
439  virtual void updateStateData(DtStateData*) = 0;
440 
441  };
442 
443 }
virtual bool forceAdvance()
Override to force an advance, even if not modified.
Definition: stateComponent.h:191
const DtStateData * stateData() const
Definition: stateComponent.h:170
Instances of DtVrfObjectParameters are the readable/writeable objects that contain the information ne...
Definition: vrfObjectParameters.h:63
unsigned int UInt32
Definition: stateDataTypes.h:18
void emitComponentUpdated()
Definition: stateComponent.h:317
void setLegionGlobalId(UInt64 d)
Definition: stateComponent.h:300
void setId(UInt64 id)
Definition: stateComponent.h:308
virtual const DtFrameStateInterface * currentFrameState() const
Definition: stateComponent.h:196
Definition: stateDataTypes.h:23
const Coordinate_System * coordinateSystem() const
Definition: stateComponent.h:185
virtual bool forceAdvance()
Override to force an advance, even if not modified.
Definition: stateComponent.h:409
UInt64 stateId() const
Definition: stateComponent.h:298
bool myAdvancedFrame
Definition: stateComponent.h:363
virtual Legion::WriteStateInstance writeStateInstance()
Definition: stateComponent.h:199
bool myAdvancedFrame
Definition: stateComponent.h:215
unsigned int StateComponentType
Definition: stateComponent.h:55
virtual void registerLegionComponent(Legion::SimulationDatabase *db)
Definition: stateComponent.h:263
Definition: stateComponent.h:257
static void registerLegionComponent(Legion::SimulationDatabase *)
Definition: stateComponent.h:432
virtual Legion::WriteStateInstance writeStateInstance()
Definition: stateComponent.h:315
virtual void removeAdditionalStateComponents()
Override this method to destroy any allocated legion extensions that need to be destroyed.
Definition: stateComponent.h:203
boost::signals2::signal< void(const DtFrameStateInterface *)> signal_componentModified
Definition: stateComponent.h:345
virtual void frameAdvanced()
Definition: stateComponent.h:332
virtual void setId(UInt64 id)
If this component is part of a list and needs to be uniquely identified, this wil be that unique id...
Definition: stateComponent.h:381
bool myPublishingOnLegionNetwork
Definition: stateComponent.h:214
bool publishingOnLegionNetwork() const
Definition: stateComponent.h:119
bool isWritable() const
Definition: stateComponent.h:296
virtual void setId(UInt64 id)
If this component is part of a list and needs to be uniquely identified, this wil be that unique id...
bool advancedFrame() const
Definition: stateComponent.h:156
virtual void advanceFrame()
Definition: stateComponent.h:410
void clearModified()
Definition: stateComponent.h:302
virtual void setStateData(DtStateData *sd)
Call with care. This will only succeed if the current state data is nullptr, else it will no-op...
Definition: stateComponent.h:396
boost::signals2::signal< void(DtFrameStateInterface *)> signal_stateComponentAboutToBeDeleted
Definition: stateComponent.h:344
boost::signals2::signal< void(DtStateComponent *)> signal_stateComponentAboutToBeDeleted
Definition: stateComponent.h:111
virtual void makeWritable()
Override to make component writable.
Definition: stateComponent.h:350
void setIsRemoteComponent(bool b)
Definition: stateComponent.h:124
virtual UInt64 id() const
Definition: stateComponent.h:309
bool cleared() const
Definition: stateComponent.h:322
Definition: coordSystem.h:54
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:336
#define DEFINE_STATE_COMPONENT_HELPER(Component)
Definition: stateComponent.h:233
void markModified()
Definition: stateComponent.h:303
UInt64 legionGlobalId() const
Definition: stateComponent.h:299
virtual bool autoCreateForRemoteObject() const
Definition: stateComponent.h:273
bool myIsWritable
Definition: stateComponent.h:361
DtStateData * stateData()
Definition: stateComponent.h:180
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:370
DtStateData * myStateData
Definition: stateComponent.h:210
UInt64 myStateId
Definition: stateComponent.h:359
virtual DtStateComponent::StateComponentType type() const
Definition: stateComponent.h:305
virtual void updateDataStorage()=0
Implement to update data storage. Called from advanceFrame.
The creator that is used to create a state component.
Definition: stateComponent.h:244
virtual void addAdditionalTableColumns(Legion::SimulationDatabase *db)
Definition: stateComponent.h:268
StateComponentTypeEnum
List of all current state components. User components start at the UserStateComponent enum...
Definition: stateComponent.h:58
virtual DtStateComponent * create(DtStateData *sd)
Definition: stateComponent.h:261
virtual const DtFrameStateInterface * nextFrameState() const
Definition: stateComponent.h:198
bool myCleared
Definition: stateComponent.h:213
Definition: stateComponent.h:51
bool isRemoteComponent() const
Definition: stateComponent.h:135
void setIsWritable(bool b)
Definition: stateComponent.h:295
UInt64 myLegionId
Definition: stateComponent.h:360
virtual Legion::ReadStateInstance readStateInstance() const
If supported, the read or write state legion instance of this component.
Definition: stateComponent.h:314
bool advancedFrame() const
Definition: stateComponent.h:327
#define DT_DLL_vrfStateData
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfStateDataDefines.h:26
virtual UInt64 id() const
Definition: stateComponent.h:151
virtual void updateStateData(DtStateData *)=0
Implement to update data storage to the new state data.
const Coordinate_System * myCoordinateSystem
Definition: stateComponent.h:211
virtual bool isDoubleBuffered() const
Returns true if this item implements the nextFrameState()/currentFrameState methods. If this returns false and you call the nextFrameState()/currentFrameState an exception will be thrown.
Definition: stateComponent.h:406
bool myCleared
Definition: stateComponent.h:362
virtual void addAdditionalStateComponents()
Definition: stateComponent.h:200
virtual DtFrameStateInterface * nextFrameState()
Definition: stateComponent.h:197
bool cleared() const
Definition: stateComponent.h:175
static void addAdditionalTableColumns(Legion::SimulationDatabase *)
Definition: stateComponent.h:433
This is a simple base class that will be used to return a pointer to current or next frame state...
Definition: stateComponent.h:282
UInt64 myId
Definition: stateComponent.h:358
UInt64 myId
Definition: stateComponent.h:209
bool myIsRemoteComponent
Definition: stateComponent.h:212
bool isModified() const
Definition: stateComponent.h:301
boost::signals2::signal< void(DtStateComponent *)> signal_componentModified
Definition: stateComponent.h:112
virtual void setStateData(DtStateData *)
Call with care. This will only succeed if the current state data is nullptr, else it will no-op...

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)