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 #include <vlpi/simulationAddress.h>
22 
23 #include <limits>
24 
25 
29 
30 class Coordinate_System;
31 
32 namespace LOM
33 {
34  class WriteEntityRepository;
35  class ReadEntityRepository;
36 }
37 
38 namespace Legion
39 {
40  class SimulationDatabase;
41 }
42 
43 class DtAppearance;
45 
46 namespace makVrf
47 {
48  class DtStateComponent;
49  class DtStateData;
50  class DtFrameStateInterface;
51 
53  {
54  public:
55 
56  using StateComponentType = unsigned int;
57 
60  {
61  Undefined = -1
62  , SimulatedObjectStateComponent = 0
63  , EntityStateComponent = SimulatedObjectStateComponent
64  , EnvironmentalStateComponent = SimulatedObjectStateComponent
65  , AggregateStateComponent = SimulatedObjectStateComponent
66  , MetocServiceStateComponent = SimulatedObjectStateComponent
67  , AerodromeStateComponent = SimulatedObjectStateComponent
68  , SpotReportStateComponent = SimulatedObjectStateComponent
69  , OrbatStateComponent = SimulatedObjectStateComponent
70  , LocationStateComponent = 1
71  , EntityLocationStateComponent = LocationStateComponent
72  , EnvironmentalLocationStateComponent = LocationStateComponent
73  , StaticLocationStateComponent = LocationStateComponent
74  , HumanStateComponent = 2
75  , ArticulatedPartStateComponent = 3
76  , VrfStateComponent = 4
77  , StatePropertiesStateComponent = 5
78  , VrfGeometryStateComponent = 6
79  , SubordinateManagerStateComponent = 7
80  , RangeItemsStateComponent = 8
81  , CloudLayerStateComponent = 9
82  , TimeAndDateStateComponent = 10
83  , WeatherStateComponent = 11
84  , LaserDesignatorStateComponent = 12
85  , EmitterSystemStateComponent = 13
86  , IffStateComponent = 14
87  , ActiveSonarStateComponent = 15
88  , UnderwaterAcousticsStateComponent = 16
89  , SensorFieldOfViewStateComponent = 17
90  , RadioTransmitterStateComponent = 18
91  , TaskVisualizationStateComponent = 19
92  , TacticalSmokeStateComponent = 20
93  , DynamicTerrainStateComponent = 21
94  , RadioReceiverStateComponent = 22
95  , WindCorridorStateComponent = 23
96  , AirTurbulenceStateComponent = 24
97  , NavAidRadioTransmitterStateComponent = 25
98  , AisDataStateComponent = 26
99  , AircraftLightingStateComponent = 27
100  , LandSurfaceStateComponent = 28
101  , WaterSurfaceStateComponent = 29
102  , TroposphereStateComponent = 30
103  , SubsurfaceStateComponent = 31
104  , GroundVehicleLightingStateComponent = 32
105  , LaserLightStateComponent = 33
106  , SearchLightStateComponent = 34
107  , UserStateComponent = 64
108  };
109 
110  public:
111 
115 
116  virtual ~DtStateComponent();
117 
119  virtual void advanceFrame();
120 
123  virtual void setCoordinateSystem( const Coordinate_System* );
124 
127  virtual StateComponentType typeWithCreator() const = 0;
130  virtual StateComponentType componentType() const = 0;
131 
133  mutable boost::signals2::signal<void(DtStateComponent*)> signal_stateComponentAboutToBeDeleted;
135  mutable boost::signals2::signal<void(DtStateComponent*)> signal_componentModified;
136 
139  virtual void setStateData( DtStateData* );
140 
142  virtual void setPublishingOnLegionNetwork( bool );
145  {
146  return myPublishingOnLegionNetwork;
147  }
148 
151  virtual void setIsRemoteComponent( bool b )
152  {
153  myIsRemoteComponent = b;
154  }
155 
157  virtual void convertToRemote();
158 
160  virtual void convertToLocal();
161 
163  bool isRemoteComponent() const
164  {
165  return myIsRemoteComponent;
166  }
167 
170  virtual void initializeFromParameters( const DtVrfObjectParameters* );
171 
173  virtual void completeSetup();
174 
176  virtual void aboutToBeDeleted();
177 
180  virtual void setId( UInt64 id );
181 
183  virtual UInt64 id() const
184  {
185  return myId;
186  }
187 
189  bool advancedFrame() const
190  {
191  return myAdvancedFrame;
192  }
193 
195  virtual void firstFrameAdvance();
196 
198  UInt64 stateId() const;
199 
201  UInt64 legionGlobalId() const;
202 
204  const DtStateData* stateData() const
205  {
206  return myStateData;
207  }
208 
210  bool cleared() const
211  {
212  return myCleared;
213  }
214 
217  {
218  return myStateData;
219  }
220 
223  {
224  return myCoordinateSystem;
225  }
226 
228  virtual bool forceAdvance() { return false; };
229 
232  virtual bool isDoubleBuffered() const;
234  virtual const DtFrameStateInterface* currentFrameState() const { throw DtUnimplementedMethod("const DtFrameStateInterface* currentFrameState() const is not implemented."); };
236  virtual DtFrameStateInterface* nextFrameState() { throw DtUnimplementedMethod("DtFrameStateInterface* nextFrameState() is not implemented."); };
238  virtual const DtFrameStateInterface* nextFrameState() const { throw DtUnimplementedMethod("const DtFrameStateInterface* nextFrameState() const is not implemented."); };
240  virtual Legion::WriteStateInstance writeStateInstance() { throw DtUnimplementedMethod("Legion::WriteStateInstance writeStateInstance() is not implemented."); };
242  virtual void addAdditionalStateComponents() {};
243 
246 
249  virtual const char* stringType() const = 0;
250 
251  protected:
252 
262  bool myCleared;
267 
268  };
269 
272  #define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent) \
273  constexpr static DtStateComponent::StateComponentType theComponentType = CreatedComponent; \
274  constexpr static const char* StringType() { return #CreatedComponent; } \
275  virtual DtStateComponent::StateComponentType typeWithCreator() const { return TypeWithCreator(); }; \
276  virtual DtStateComponent::StateComponentType componentType() const override { return ComponentType(); }; \
277  virtual const char* stringType() const override { return #CreatedComponent; }; \
278  static DtStateComponent::StateComponentType TypeWithCreator() { return (DtStateComponent::StateComponentType)((unsigned int)(theComponentCreatorType << 16) | theComponentType); }; \
279  static void SetCreatorType(UInt32 type) { theComponentCreatorType = type; }; \
280  constexpr static DtStateComponent::StateComponentType ComponentType() { return theComponentType; }; \
281  static UInt32 CreatorType() { return theComponentCreatorType; }; \
282  protected: \
283  static UInt32 theComponentCreatorType; \
284  public:
285 
288  #define DEFINE_STATE_COMPONENT_HELPER(Component) \
289  static const char* StringType() { return #Component; } \
290  virtual DtStateComponent::StateComponentType typeWithCreator() const { return Component::TypeWithCreator(); }; \
291  virtual DtStateComponent::StateComponentType componentType() const override { return Component::ComponentType(); }; \
292  virtual DtStateComponent::StateComponentType setCreatorType(UInt32 type) const { return SetCreatorType(type); }; \
293  virtual const char* stringType() const { return #Component; }; \
294  constexpr static DtStateComponent::StateComponentType TypeWithCreator() { return Component::TypeWithCreator(); }; \
295  constexpr static DtStateComponent::StateComponentType ComponentType() { return Component::ComponentType(); }; \
296  static UInt32 SetCreatorType(UInt32 type) { Component::SetCreatorType(type); return type; };
297 
300  {
301  public:
305  virtual DtStateComponent* create( DtStateData * ) = 0;
308  virtual DtStateComponent::StateComponentType setCreatorType( UInt32 ) const = 0;
310  virtual DtStateComponent::StateComponentType componentType() const = 0;
312  virtual DtStateComponent::StateComponentType typeWithCreator() const = 0;
315  virtual void registerLegionComponent( Legion::SimulationDatabase* ) = 0;
318  virtual void addAdditionalTableColumns( Legion::SimulationDatabase* ) = 0;
320  virtual bool autoCreateForRemoteObject() const = 0;
321  };
322 
325  template <typename T_StateComponent, bool T_AutoCreateForRemoteObject = true>
327  {
328  public:
329  DEFINE_STATE_COMPONENT_HELPER(T_StateComponent)
331  virtual DtStateComponent* create( DtStateData* sd ) override { return new T_StateComponent( sd ); };
332 
334  virtual void registerLegionComponent(Legion::SimulationDatabase* db) override
335  {
336  T_StateComponent::registerLegionComponent(db);
337  }
338 
340  virtual void addAdditionalTableColumns(Legion::SimulationDatabase* db) override
341  {
342  T_StateComponent::addAdditionalTableColumns(db);
343  }
344 
346  virtual bool autoCreateForRemoteObject() const override
347  {
348  return T_AutoCreateForRemoteObject;
349  }
350  };
351 
355  {
356  private:
357 
359  DtFrameStateInterface& operator = ( const DtFrameStateInterface& rhs );
360 
361  public:
362 
364 
365  virtual ~DtFrameStateInterface();
366 
369  void setIsWritable(bool b) { myIsWritable = b; };
371  bool isWritable() const { return myIsWritable; };
372 
374  UInt64 stateId() const { return myStateId; };
376  UInt64 legionGlobalId() const { return myLegionId; };
379  void setLegionGlobalId( UInt64 d ) { myLegionId = d; };
381  virtual bool isModified() const { return myIsModified; };
383  virtual void clearModified() { myIsModified = false; };
385  virtual void markModified();
386 
388  virtual DtStateComponent::StateComponentType type() const { return componentType(); };
391  virtual DtStateComponent::StateComponentType componentType() const = 0;
392 
394  virtual const char* stringType() const = 0;
395 
396 
399  void setId( UInt64 id ) { myId = id; };
401  virtual UInt64 id() const { return myId; };
402 
405  virtual void updateStateData( DtStateData* sd );
406 
408  virtual Legion::ReadStateInstance readStateInstance() const { throw DtUnimplementedMethod("void readStateInstance() const is not implemented."); };
409  virtual Legion::WriteStateInstance writeStateInstance() { throw DtUnimplementedMethod("void writeStateInstance() const is not implemented."); };
410 
413  {
414  signal_componentModified( this );
415  }
416 
417  void setMarkedForRemoval(bool b)
418  {
419  myMarkedForRemoval = b;
420  }
421 
422  bool markedForRemoval() const
423  {
424  return myMarkedForRemoval;
425  }
426 
428  bool cleared() const
429  {
430  return myCleared;
431  }
432 
434  bool advancedFrame() const
435  {
436  return myAdvancedFrame;
437  }
438 
440  virtual void frameAdvanced()
441  {
442  myAdvancedFrame = true;
443  }
444 
446  virtual void convertToRemote();
447 
449  virtual void convertToLocal();
451  virtual void aboutToBeDeleted();
452 
454  mutable boost::signals2::signal<void (DtFrameStateInterface*)> signal_stateComponentAboutToBeDeleted;
456  mutable boost::signals2::signal<void (const DtFrameStateInterface*)> signal_componentModified;
457 
458  protected:
459 
461  virtual void makeWritable() { throw DtUnimplementedMethod("void makeWritable() const is not implemented."); };
462 
464  virtual void makeReadOnly() { throw DtUnimplementedMethod("void makeReadOnly() const is not implemented."); };
465 
466  protected:
468  bool myIsModified;
478  bool myCleared;
481  bool myMarkedForRemoval = false;
484  };
485 
486 
488  template <typename T_Component>
490  {
491  public:
492 
493  DEFINE_STATE_COMPONENT_HELPER( T_Component )
494 
496  : DtStateComponent(sd)
497  {
498  }
499 
502  virtual void setId(UInt64 id) override
503  {
505 
506  if (nextFrameState())
507  {
508  nextFrameState()->setId(id);
509  }
510 
511  if (currentFrameState())
512  {
513  const_cast<DtFrameStateInterface*>(currentFrameState())->setId(id);
514  }
515  }
516 
519  virtual void setStateData(DtStateData* sd) override
520  {
521  if (myStateData != sd)
522  {
524 
525  updateStateData(sd);
526  }
527  }
528 
530  virtual bool isDoubleBuffered() const override { return true; };
531 
533  virtual bool forceAdvance() override { return false; };
535  virtual void advanceFrame() override
536  {
537  myAdvancedFrame = true;
538 
539  if ( nextFrameState()->isModified() || forceAdvance() )
540  {
542  const_cast<DtFrameStateInterface*>( currentFrameState() )->markModified();
545  signal_componentModified( this );
546  }
547  else
548  {
550  const_cast<DtFrameStateInterface*>(currentFrameState())->clearModified();
551  }
552 
554  const_cast<DtFrameStateInterface*>(currentFrameState())->frameAdvanced();
555  }
556 
558  static void registerLegionComponent( Legion::SimulationDatabase* ) {};
560  static void addAdditionalTableColumns( Legion::SimulationDatabase* ) {};
561 
563  virtual void updateDataStorage() = 0;
564 
566  virtual void updateStateData(DtStateData*) = 0;
567 
568  };
569 
570 }
unsigned int StateComponentType
Definition: stateComponent.h:56
virtual bool forceAdvance()
Override to force an advance, even if not modified.
Definition: stateComponent.h:228
const DtStateData * stateData() const
Returns a const pointer to the owning state data.
Definition: stateComponent.h:204
Instances of DtVrfObjectParameters are the readable/writeable objects that contain the information ne...
Definition: vrfObjectParameters.h:64
void emitComponentUpdated()
Emits the signal_componentModified signal to notify observers of a state change.
Definition: stateComponent.h:412
void setLegionGlobalId(UInt64 d)
Sets the Legion global entity ID for this state.
Definition: stateComponent.h:379
void setId(UInt64 id)
Sets the unique identifier for this frame state instance.
Definition: stateComponent.h:399
virtual const DtFrameStateInterface * currentFrameState() const
Returns the read-only current frame state. Throws if not double-buffered.
Definition: stateComponent.h:234
Exception thrown when a required method has not been implemented.
Definition: stateDataTypes.h:30
const Coordinate_System * coordinateSystem() const
Returns the coordinate system associated with this component.
Definition: stateComponent.h:222
virtual void advanceFrame() override
Advances the double-buffered state, swapping buffers if modified or if forceAdvance() returns true...
Definition: stateComponent.h:535
virtual void addAdditionalTableColumns(Legion::SimulationDatabase *db) override
Delegates additional table column registration to T_StateComponent.
Definition: stateComponent.h:340
UInt64 stateId() const
Returns the state ID of the owning entity.
Definition: stateComponent.h:374
bool myAdvancedFrame
True if this frame state has been advanced at least one frame.
Definition: stateComponent.h:480
virtual Legion::WriteStateInstance writeStateInstance()
Returns the Legion write state instance for this component. Throws if not supported.
Definition: stateComponent.h:240
bool myAdvancedFrame
True if this component has advanced at least one frame.
Definition: stateComponent.h:266
virtual void setIsRemoteComponent(bool b)
Sets whether this component represents a remote (non-authoritative) entity.
Definition: stateComponent.h:151
unsigned int UInt32
32-bit unsigned integer type.
Definition: stateDataTypes.h:21
Default creator implementation for a state component type. T_StateComponent is the concrete component...
Definition: stateComponent.h:326
void setMarkedForRemoval(bool b)
Definition: stateComponent.h:417
static void registerLegionComponent(Legion::SimulationDatabase *)
Default no-op Legion component registration. Override in subclasses as needed.
Definition: stateComponent.h:558
virtual Legion::WriteStateInstance writeStateInstance()
Definition: stateComponent.h:409
virtual void removeAdditionalStateComponents()
Override this method to destroy any allocated legion extensions that need to be destroyed.
Definition: stateComponent.h:245
virtual bool isDoubleBuffered() const override
Always returns true; this component is double-buffered.
Definition: stateComponent.h:530
boost::signals2::signal< void(const DtFrameStateInterface *)> signal_componentModified
Emitted when this frame state is modified.
Definition: stateComponent.h:456
virtual void frameAdvanced()
Called during frame advance to record that this state has been advanced.
Definition: stateComponent.h:440
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
bool myPublishingOnLegionNetwork
True if this component is publishing data on the Legion network.
Definition: stateComponent.h:264
bool publishingOnLegionNetwork() const
Returns whether this component is currently publishing on the Legion network.
Definition: stateComponent.h:144
unsigned long long UInt64
64-bit unsigned integer type.
Definition: stateDataTypes.h:19
bool isWritable() const
Returns true if this frame state instance is writable.
Definition: stateComponent.h:371
virtual void setId(UInt64 id)
Sets the unique identifier for this component within a list. Use -1 if not applicable.
bool advancedFrame() const
Returns true if this component has been advanced at least one frame.
Definition: stateComponent.h:189
virtual bool autoCreateForRemoteObject() const override
Returns T_AutoCreateForRemoteObject template parameter value.
Definition: stateComponent.h:346
boost::signals2::signal< void(DtFrameStateInterface *)> signal_stateComponentAboutToBeDeleted
Emitted just before this frame state is deleted.
Definition: stateComponent.h:454
boost::signals2::signal< void(DtStateComponent *)> signal_stateComponentAboutToBeDeleted
Emitted just before this component is deleted.
Definition: stateComponent.h:133
virtual void makeWritable()
Override to make component writable.
Definition: stateComponent.h:461
virtual UInt64 id() const
Returns the unique identifier of this frame state instance.
Definition: stateComponent.h:401
bool cleared() const
Returns true if aboutToBeDeleted() has been called on this frame state.
Definition: stateComponent.h:428
Definition: coordSystem.h:54
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:513
#define DEFINE_STATE_COMPONENT_HELPER(Component)
Macro to delegate state component type methods to an existing component type. Used in creator and tem...
Definition: stateComponent.h:288
UInt64 legionGlobalId() const
Returns the Legion global entity ID associated with this state.
Definition: stateComponent.h:376
bool myIsWritable
True if this frame state instance is writable (i.e., the next-frame instance).
Definition: stateComponent.h:476
DtStateData * stateData()
Returns a mutable pointer to the owning state data.
Definition: stateComponent.h:216
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:489
DtStateData * myStateData
Pointer to the owning state data object.
Definition: stateComponent.h:256
UInt64 myStateId
The state ID of the owning entity.
Definition: stateComponent.h:472
virtual DtStateComponent::StateComponentType type() const
Returns the component type identifier. Delegates to componentType().
Definition: stateComponent.h:388
virtual void updateDataStorage()=0
Implement to update data storage. Called from advanceFrame.
virtual bool isModified() const
Returns true if this frame state has been modified since the last advance.
Definition: stateComponent.h:381
The creator that is used to create a state component.
Definition: stateComponent.h:299
StateComponentTypeEnum
Enumeration of all built-in state component type IDs. User-defined components should start at UserSta...
Definition: stateComponent.h:59
virtual const DtFrameStateInterface * nextFrameState() const
Returns the read-only next frame state. Throws if not double-buffered.
Definition: stateComponent.h:238
virtual void setId(UInt64 id) override
Sets the unique identifier on this component and propagates it to both frame states.
Definition: stateComponent.h:502
bool myCleared
True if aboutToBeDeleted() has been called.
Definition: stateComponent.h:262
virtual void markModified()
Marks this frame state as modified and notifies the owning state data.
Definition: stateComponent.h:52
virtual void registerLegionComponent(Legion::SimulationDatabase *db) override
Delegates Legion component registration to T_StateComponent.
Definition: stateComponent.h:334
bool isRemoteComponent() const
Returns true if this component represents a remote (non-authoritative) entity.
Definition: stateComponent.h:163
void setIsWritable(bool b)
Sets whether this frame state instance is writable.
Definition: stateComponent.h:369
UInt64 myLegionId
The Legion global entity ID.
Definition: stateComponent.h:474
virtual void clearModified()
Clears the modified flag.
Definition: stateComponent.h:383
virtual Legion::ReadStateInstance readStateInstance() const
If supported, the read or write state legion instance of this component.
Definition: stateComponent.h:408
bool advancedFrame() const
Returns true if this frame state has been advanced at least one frame.
Definition: stateComponent.h:434
bool markedForRemoval() const
Definition: stateComponent.h:422
#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
virtual UInt64 id() const
Returns the unique identifier of this component, or -1 if not part of a list.
Definition: stateComponent.h:183
virtual void updateStateData(DtStateData *)=0
Implement to update data storage to the new state data.
const Coordinate_System * myCoordinateSystem
Coordinate system used for spatial calculations.
Definition: stateComponent.h:258
bool myCleared
True if aboutToBeDeleted() has been called.
Definition: stateComponent.h:478
virtual DtStateComponent * create(DtStateData *sd) override
Creates a new instance of T_StateComponent associated with the given state data.
Definition: stateComponent.h:331
virtual void addAdditionalStateComponents()
Override to create any additional state sub-components needed by this component.
Definition: stateComponent.h:242
DtStateData * myStateData
Pointer to the owning state data object.
Definition: stateComponent.h:483
virtual DtFrameStateInterface * nextFrameState()
Returns the writable next frame state. Throws if not double-buffered.
Definition: stateComponent.h:236
bool cleared() const
Returns true if this component has been cleared (aboutToBeDeleted has been called).
Definition: stateComponent.h:210
virtual bool forceAdvance() override
Override to force an advance, even if not modified.
Definition: stateComponent.h:533
static void addAdditionalTableColumns(Legion::SimulationDatabase *)
Default no-op for adding additional table columns. Override in subclasses as needed.
Definition: stateComponent.h:560
Base interface for accessing current or next frame state in a double-buffered state component...
Definition: stateComponent.h:354
UInt64 myId
Unique identifier for this frame state instance.
Definition: stateComponent.h:470
UInt64 myId
Unique identifier of this component within a list; -1 if not applicable.
Definition: stateComponent.h:254
bool myIsRemoteComponent
True if this component represents a remote (non-authoritative) entity.
Definition: stateComponent.h:260
virtual void setStateData(DtStateData *sd) override
Sets the owning state data and propagates the update to both double-buffered frame states...
Definition: stateComponent.h:519
boost::signals2::signal< void(DtStateComponent *)> signal_componentModified
Emitted when this component&#39;s state is modified during frame advance.
Definition: stateComponent.h:135
virtual void setStateData(DtStateData *)
Sets the owning state data. Only succeeds if the current state data is nullptr; otherwise a no-op...

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)