VR-Forces 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  AerodromeStateComponent = SimulatedObjectStateComponent,
67  LocationStateComponent = 1,
68  EntityLocationStateComponent = LocationStateComponent,
69  EnvironmentalLocationStateComponent = LocationStateComponent,
70  StaticLocationStateComponent = LocationStateComponent,
71  HumanStateComponent = 2,
72  ArticulatedPartStateComponent = 3,
73  VrfStateComponent = 4,
74  StatePropertiesStateComponent = 5,
75  VrfGeometryStateComponent = 6,
76  SubordinateManagerStateComponent = 7,
77  RangeItemsStateComponent = 8,
78  CloudLayerStateComponent = 9,
79  TimeAndDateStateComponent = 10,
80  WeatherStateComponent = 11,
81  LaserDesignatorStateComponent = 12,
82  EmitterSystemStateComponent = 13,
83  IffStateComponent = 14,
84  ActiveSonarStateComponent = 15,
85  UnderwaterAcousticsStateComponent = 16,
86  SensorFieldOfViewStateComponent = 17,
87  RadioTransmitterStateComponent = 18,
88  TaskVisualizationStateComponent = 19,
89  TacticalSmokeStateComponent = 20,
90  DynamicTerrainStateComponent = 21,
91  RadioReceiverStateComponent = 22,
92  WindCorridorStateComponent = 23,
93  AirTurbulenceStateComponent = 24,
94  NavAidRadioTransmitterStateComponent = 25,
95  AisDataStateComponent = 26,
96  AircraftLightingStateComponent = 27,
97  LandSurfaceStateComponent = 28,
98  WaterSurfaceStateComponent = 29,
99  TroposphereStateComponent = 30,
100  SubsurfaceStateComponent = 31,
101  GroundVehicleLightingStateComponent = 32,
102  UserStateComponent = 64
103  };
104 
105  public:
106 
110 
111  virtual ~DtStateComponent();
112 
113  virtual void advanceFrame();
114 
115  virtual void setCoordinateSystem( const Coordinate_System* );
116 
117  virtual StateComponentType typeWithCreator() const = 0;
118  virtual StateComponentType componentType() const = 0;
119 
120  mutable boost::signals2::signal<void(DtStateComponent*)> signal_stateComponentAboutToBeDeleted;
121  mutable boost::signals2::signal<void(DtStateComponent*)> signal_componentModified;
122 
124  virtual void setStateData( DtStateData* );
125 
127  virtual void setPublishingOnLegionNetwork( bool );
129  {
130  return myPublishingOnLegionNetwork;
131  }
132 
133  virtual void setIsRemoteComponent( bool b )
134  {
135  myIsRemoteComponent = b;
136  }
137 
139  virtual void convertToRemote();
140 
142  virtual void convertToLocal();
143 
144  bool isRemoteComponent() const
145  {
146  return myIsRemoteComponent;
147  }
148 
150  virtual void initializeFromParameters( const DtVrfObjectParameters* );
151 
153  virtual void completeSetup();
154 
155  virtual void aboutToBeDeleted();
156 
158  virtual void setId( UInt64 id );
159 
160  virtual UInt64 id() const
161  {
162  return myId;
163  }
164 
165  bool advancedFrame() const
166  {
167  return myAdvancedFrame;
168  }
169 
171  virtual void firstFrameAdvance();
172 
174  UInt64 stateId() const;
175 
177  UInt64 legionGlobalId() const;
178 
179  const DtStateData* stateData() const
180  {
181  return myStateData;
182  }
183 
184  bool cleared() const
185  {
186  return myCleared;
187  }
188 
190  {
191  return myStateData;
192  }
193 
195  {
196  return myCoordinateSystem;
197  }
198 
200  virtual bool forceAdvance() { return false; };
201 
204  virtual bool isDoubleBuffered() const;
205  virtual const DtFrameStateInterface* currentFrameState() const { throw DtUnimplementedMethod("const DtFrameStateInterface* currentFrameState() const is not implemented."); };
206  virtual DtFrameStateInterface* nextFrameState() { throw DtUnimplementedMethod("DtFrameStateInterface* nextFrameState() is not implemented."); };
207  virtual const DtFrameStateInterface* nextFrameState() const { throw DtUnimplementedMethod("const DtFrameStateInterface* nextFrameState() const is not implemented."); };
208  virtual Legion::WriteStateInstance writeStateInstance() { throw DtUnimplementedMethod("Legion::WriteStateInstance writeStateInstance() is not implemented."); };
209  virtual void addAdditionalStateComponents() {};
210 
213 
214  virtual const char* stringType() const = 0;
215 
216  protected:
217 
222  bool myCleared;
225 
226  };
227 
228  #define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent) \
229  static const DtStateComponent::StateComponentType theComponentType = CreatedComponent; \
230  static const char* StringType() { return #CreatedComponent; } \
231  virtual DtStateComponent::StateComponentType typeWithCreator() const { return TypeWithCreator(); }; \
232  virtual DtStateComponent::StateComponentType componentType() const { return ComponentType(); }; \
233  virtual const char* stringType() const { return #CreatedComponent; }; \
234  static DtStateComponent::StateComponentType TypeWithCreator() { return (DtStateComponent::StateComponentType)((unsigned int)(theComponentCreatorType << 16) | theComponentType); }; \
235  static void SetCreatorType(UInt32 type) { theComponentCreatorType = type; }; \
236  static DtStateComponent::StateComponentType ComponentType() { return theComponentType; }; \
237  static UInt32 CreatorType() { return theComponentCreatorType; }; \
238  protected: \
239  static UInt32 theComponentCreatorType; \
240  public:
241 
242  #define DEFINE_STATE_COMPONENT_HELPER(Component) \
243  static const char* StringType() { return #Component; } \
244  virtual DtStateComponent::StateComponentType typeWithCreator() const { return Component::TypeWithCreator(); }; \
245  virtual DtStateComponent::StateComponentType componentType() const { return Component::ComponentType(); }; \
246  virtual DtStateComponent::StateComponentType setCreatorType(UInt32 type) const { return SetCreatorType(type); }; \
247  virtual const char* stringType() const { return #Component; }; \
248  static DtStateComponent::StateComponentType TypeWithCreator() { return Component::TypeWithCreator(); }; \
249  static DtStateComponent::StateComponentType ComponentType() { return Component::ComponentType(); }; \
250  static UInt32 SetCreatorType(UInt32 type) { Component::SetCreatorType(type); return type; };
251 
254  {
255  public:
256  virtual DtStateComponent* create( DtStateData * ) = 0;
257  virtual DtStateComponent::StateComponentType setCreatorType( UInt32 ) const = 0;
258  virtual DtStateComponent::StateComponentType componentType() const = 0;
259  virtual DtStateComponent::StateComponentType typeWithCreator() const = 0;
260  virtual void registerLegionComponent( Legion::SimulationDatabase* ) = 0;
261  virtual void addAdditionalTableColumns( Legion::SimulationDatabase* ) = 0;
262  virtual bool autoCreateForRemoteObject() const = 0;
263  };
264 
265  template <typename T_StateComponent, bool T_AutoCreateForRemoteObject = true>
267  {
268  public:
269  DEFINE_STATE_COMPONENT_HELPER( T_StateComponent )
270  virtual DtStateComponent* create( DtStateData* sd ) { return new T_StateComponent( sd ); };
271 
272  virtual void registerLegionComponent( Legion::SimulationDatabase* db )
273  {
274  T_StateComponent::registerLegionComponent( db );
275  }
276 
277  virtual void addAdditionalTableColumns( Legion::SimulationDatabase* db )
278  {
279  T_StateComponent::addAdditionalTableColumns( db );
280  }
281 
282  virtual bool autoCreateForRemoteObject() const
283  {
284  return T_AutoCreateForRemoteObject;
285  }
286  };
287 
292  {
293  private:
294 
296  DtFrameStateInterface& operator = ( const DtFrameStateInterface& rhs );
297 
298  public:
299 
301 
302  virtual ~DtFrameStateInterface();
303 
304  void setIsWritable(bool b) { myIsWritable = b; };
305  bool isWritable() const { return myIsWritable; };
306 
307  UInt64 stateId() const { return myStateId; };
308  UInt64 legionGlobalId() const { return myLegionId; };
309  void setLegionGlobalId( UInt64 d ) { myLegionId = d; };
310  bool isModified() const { return myIsModified; };
311  void clearModified() { myIsModified = false; };
312  void markModified() { myIsModified = true; };
313 
314  virtual DtStateComponent::StateComponentType type() const { return componentType(); };
315  virtual DtStateComponent::StateComponentType componentType() const = 0;
316 
317  void setId( UInt64 id ) { myId = id; };
318  virtual UInt64 id() const { return myId; };
319 
320  virtual void updateStateData( DtStateData* sd );
321 
323  virtual Legion::ReadStateInstance readStateInstance() const { throw DtUnimplementedMethod("void readStateInstance() const is not implemented."); };
324  virtual Legion::WriteStateInstance writeStateInstance() { throw DtUnimplementedMethod("void writeStateInstance() const is not implemented."); };
325 
327  {
328  signal_componentModified( this );
329  }
330 
331  bool cleared() const
332  {
333  return myCleared;
334  }
335 
336  bool advancedFrame() const
337  {
338  return myAdvancedFrame;
339  }
340 
341  virtual void frameAdvanced()
342  {
343  myAdvancedFrame = true;
344  }
345 
347  virtual void convertToRemote();
348 
350  virtual void convertToLocal();
351  virtual void aboutToBeDeleted();
352 
353  mutable boost::signals2::signal<void (DtFrameStateInterface*)> signal_stateComponentAboutToBeDeleted;
354  mutable boost::signals2::signal<void (const DtFrameStateInterface*)> signal_componentModified;
355 
356  protected:
357 
359  virtual void makeWritable() { throw DtUnimplementedMethod("void makeWritable() const is not implemented."); };
360 
362  virtual void makeReadOnly() { throw DtUnimplementedMethod("void makeReadOnly() const is not implemented."); };
363 
364  protected:
365 
366  bool myIsModified;
371  bool myCleared;
373 
374  };
375 
376 
378  template <typename T_Component>
380  {
381  public:
382 
383  DEFINE_STATE_COMPONENT_HELPER( T_Component )
384 
386  : DtStateComponent( sd )
387  {
388  }
389 
390  virtual void setId( UInt64 id )
391  {
393 
394  if ( nextFrameState() )
395  {
396  nextFrameState()->setId( id );
397  }
398 
399  if ( currentFrameState() )
400  {
401  const_cast<DtFrameStateInterface*>(currentFrameState())->setId( id );
402  }
403  }
404 
405  virtual void setStateData( DtStateData* sd )
406  {
407  if ( myStateData != sd )
408  {
410 
411  updateStateData( sd );
412  }
413  }
414 
415  virtual bool isDoubleBuffered() const { return true; };
416 
418  virtual bool forceAdvance() { return false; };
419  virtual void advanceFrame()
420  {
421  myAdvancedFrame = true;
422 
423  if ( nextFrameState()->isModified() || forceAdvance() )
424  {
426  const_cast<DtFrameStateInterface*>( currentFrameState() )->markModified();
429  signal_componentModified( this );
430  }
431  else
432  {
434  const_cast<DtFrameStateInterface*>(currentFrameState())->clearModified();
435  }
436 
438  const_cast<DtFrameStateInterface*>(currentFrameState())->frameAdvanced();
439  }
440 
441  static void registerLegionComponent( Legion::SimulationDatabase* ) {};
442  static void addAdditionalTableColumns( Legion::SimulationDatabase* ) {};
443 
445  virtual void updateDataStorage() = 0;
446 
448  virtual void updateStateData(DtStateData*) = 0;
449 
450  };
451 
452 }
virtual bool forceAdvance()
Override to force an advance, even if not modified.
Definition: stateComponent.h:200
const DtStateData * stateData() const
Definition: stateComponent.h:179
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:326
void setLegionGlobalId(UInt64 d)
Definition: stateComponent.h:309
void setId(UInt64 id)
Definition: stateComponent.h:317
virtual const DtFrameStateInterface * currentFrameState() const
Definition: stateComponent.h:205
Definition: stateDataTypes.h:23
const Coordinate_System * coordinateSystem() const
Definition: stateComponent.h:194
virtual bool forceAdvance()
Override to force an advance, even if not modified.
Definition: stateComponent.h:418
UInt64 stateId() const
Definition: stateComponent.h:307
bool myAdvancedFrame
Definition: stateComponent.h:372
virtual Legion::WriteStateInstance writeStateInstance()
Definition: stateComponent.h:208
bool myAdvancedFrame
Definition: stateComponent.h:224
virtual void setIsRemoteComponent(bool b)
Definition: stateComponent.h:133
unsigned int StateComponentType
Definition: stateComponent.h:55
virtual void registerLegionComponent(Legion::SimulationDatabase *db)
Definition: stateComponent.h:272
Definition: stateComponent.h:266
static void registerLegionComponent(Legion::SimulationDatabase *)
Definition: stateComponent.h:441
virtual Legion::WriteStateInstance writeStateInstance()
Definition: stateComponent.h:324
virtual void removeAdditionalStateComponents()
Override this method to destroy any allocated legion extensions that need to be destroyed.
Definition: stateComponent.h:212
boost::signals2::signal< void(const DtFrameStateInterface *)> signal_componentModified
Definition: stateComponent.h:354
virtual void frameAdvanced()
Definition: stateComponent.h:341
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:390
bool myPublishingOnLegionNetwork
Definition: stateComponent.h:223
bool publishingOnLegionNetwork() const
Definition: stateComponent.h:128
bool isWritable() const
Definition: stateComponent.h:305
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:165
virtual void advanceFrame()
Definition: stateComponent.h:419
void clearModified()
Definition: stateComponent.h:311
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:405
boost::signals2::signal< void(DtFrameStateInterface *)> signal_stateComponentAboutToBeDeleted
Definition: stateComponent.h:353
boost::signals2::signal< void(DtStateComponent *)> signal_stateComponentAboutToBeDeleted
Definition: stateComponent.h:120
virtual void makeWritable()
Override to make component writable.
Definition: stateComponent.h:359
virtual UInt64 id() const
Definition: stateComponent.h:318
bool cleared() const
Definition: stateComponent.h:331
Definition: coordSystem.h:54
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:339
#define DEFINE_STATE_COMPONENT_HELPER(Component)
Definition: stateComponent.h:242
void markModified()
Definition: stateComponent.h:312
UInt64 legionGlobalId() const
Definition: stateComponent.h:308
virtual bool autoCreateForRemoteObject() const
Definition: stateComponent.h:282
bool myIsWritable
Definition: stateComponent.h:370
DtStateData * stateData()
Definition: stateComponent.h:189
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:379
DtStateData * myStateData
Definition: stateComponent.h:219
UInt64 myStateId
Definition: stateComponent.h:368
virtual DtStateComponent::StateComponentType type() const
Definition: stateComponent.h:314
virtual void updateDataStorage()=0
Implement to update data storage. Called from advanceFrame.
unsigned long long UInt64
Definition: stateDataTypes.h:17
The creator that is used to create a state component.
Definition: stateComponent.h:253
virtual void addAdditionalTableColumns(Legion::SimulationDatabase *db)
Definition: stateComponent.h:277
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:270
virtual const DtFrameStateInterface * nextFrameState() const
Definition: stateComponent.h:207
bool myCleared
Definition: stateComponent.h:222
Definition: stateComponent.h:51
bool isRemoteComponent() const
Definition: stateComponent.h:144
void setIsWritable(bool b)
Definition: stateComponent.h:304
UInt64 myLegionId
Definition: stateComponent.h:369
virtual Legion::ReadStateInstance readStateInstance() const
If supported, the read or write state legion instance of this component.
Definition: stateComponent.h:323
bool advancedFrame() const
Definition: stateComponent.h:336
#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:160
virtual void updateStateData(DtStateData *)=0
Implement to update data storage to the new state data.
const Coordinate_System * myCoordinateSystem
Definition: stateComponent.h:220
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:415
bool myCleared
Definition: stateComponent.h:371
virtual void addAdditionalStateComponents()
Definition: stateComponent.h:209
virtual DtFrameStateInterface * nextFrameState()
Definition: stateComponent.h:206
bool cleared() const
Definition: stateComponent.h:184
static void addAdditionalTableColumns(Legion::SimulationDatabase *)
Definition: stateComponent.h:442
This is a simple base class that will be used to return a pointer to current or next frame state...
Definition: stateComponent.h:291
UInt64 myId
Definition: stateComponent.h:367
UInt64 myId
Definition: stateComponent.h:218
bool myIsRemoteComponent
Definition: stateComponent.h:221
bool isModified() const
Definition: stateComponent.h:310
boost::signals2::signal< void(DtStateComponent *)> signal_componentModified
Definition: stateComponent.h:121
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 Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)