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  UserStateComponent = 64
106  };
107 
108  public:
109 
113 
114  virtual ~DtStateComponent();
115 
116  virtual void advanceFrame();
117 
118  virtual void setCoordinateSystem( const Coordinate_System* );
119 
120  virtual StateComponentType typeWithCreator() const = 0;
121  virtual StateComponentType componentType() const = 0;
122 
123  mutable boost::signals2::signal<void(DtStateComponent*)> signal_stateComponentAboutToBeDeleted;
124  mutable boost::signals2::signal<void(DtStateComponent*)> signal_componentModified;
125 
127  virtual void setStateData( DtStateData* );
128 
130  virtual void setPublishingOnLegionNetwork( bool );
132  {
133  return myPublishingOnLegionNetwork;
134  }
135 
136  virtual void setIsRemoteComponent( bool b )
137  {
138  myIsRemoteComponent = b;
139  }
140 
142  virtual void convertToRemote();
143 
145  virtual void convertToLocal();
146 
147  bool isRemoteComponent() const
148  {
149  return myIsRemoteComponent;
150  }
151 
153  virtual void initializeFromParameters( const DtVrfObjectParameters* );
154 
156  virtual void completeSetup();
157 
158  virtual void aboutToBeDeleted();
159 
161  virtual void setId( UInt64 id );
162 
163  virtual UInt64 id() const
164  {
165  return myId;
166  }
167 
168  bool advancedFrame() const
169  {
170  return myAdvancedFrame;
171  }
172 
174  virtual void firstFrameAdvance();
175 
177  UInt64 stateId() const;
178 
180  UInt64 legionGlobalId() const;
181 
182  const DtStateData* stateData() const
183  {
184  return myStateData;
185  }
186 
187  bool cleared() const
188  {
189  return myCleared;
190  }
191 
193  {
194  return myStateData;
195  }
196 
198  {
199  return myCoordinateSystem;
200  }
201 
203  virtual bool forceAdvance() { return false; };
204 
207  virtual bool isDoubleBuffered() const;
208  virtual const DtFrameStateInterface* currentFrameState() const { throw DtUnimplementedMethod("const DtFrameStateInterface* currentFrameState() const is not implemented."); };
209  virtual DtFrameStateInterface* nextFrameState() { throw DtUnimplementedMethod("DtFrameStateInterface* nextFrameState() is not implemented."); };
210  virtual const DtFrameStateInterface* nextFrameState() const { throw DtUnimplementedMethod("const DtFrameStateInterface* nextFrameState() const is not implemented."); };
211  virtual Legion::WriteStateInstance writeStateInstance() { throw DtUnimplementedMethod("Legion::WriteStateInstance writeStateInstance() is not implemented."); };
212  virtual void addAdditionalStateComponents() {};
213 
216 
217  virtual const char* stringType() const = 0;
218 
219  protected:
220 
225  bool myCleared;
228 
229  };
230 
231  #define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent) \
232  constexpr static DtStateComponent::StateComponentType theComponentType = CreatedComponent; \
233  constexpr static const char* StringType() { return #CreatedComponent; } \
234  virtual DtStateComponent::StateComponentType typeWithCreator() const { return TypeWithCreator(); }; \
235  virtual DtStateComponent::StateComponentType componentType() const override { return ComponentType(); }; \
236  virtual const char* stringType() const override { return #CreatedComponent; }; \
237  static DtStateComponent::StateComponentType TypeWithCreator() { return (DtStateComponent::StateComponentType)((unsigned int)(theComponentCreatorType << 16) | theComponentType); }; \
238  static void SetCreatorType(UInt32 type) { theComponentCreatorType = type; }; \
239  constexpr static DtStateComponent::StateComponentType ComponentType() { return theComponentType; }; \
240  static UInt32 CreatorType() { return theComponentCreatorType; }; \
241  protected: \
242  static UInt32 theComponentCreatorType; \
243  public:
244 
245  #define DEFINE_STATE_COMPONENT_HELPER(Component) \
246  static const char* StringType() { return #Component; } \
247  virtual DtStateComponent::StateComponentType typeWithCreator() const { return Component::TypeWithCreator(); }; \
248  virtual DtStateComponent::StateComponentType componentType() const override { return Component::ComponentType(); }; \
249  virtual DtStateComponent::StateComponentType setCreatorType(UInt32 type) const { return SetCreatorType(type); }; \
250  virtual const char* stringType() const { return #Component; }; \
251  constexpr static DtStateComponent::StateComponentType TypeWithCreator() { return Component::TypeWithCreator(); }; \
252  constexpr static DtStateComponent::StateComponentType ComponentType() { return Component::ComponentType(); }; \
253  static UInt32 SetCreatorType(UInt32 type) { Component::SetCreatorType(type); return type; };
254 
257  {
258  public:
259  virtual DtStateComponent* create( DtStateData * ) = 0;
260  virtual DtStateComponent::StateComponentType setCreatorType( UInt32 ) const = 0;
261  virtual DtStateComponent::StateComponentType componentType() const = 0;
262  virtual DtStateComponent::StateComponentType typeWithCreator() const = 0;
263  virtual void registerLegionComponent( Legion::SimulationDatabase* ) = 0;
264  virtual void addAdditionalTableColumns( Legion::SimulationDatabase* ) = 0;
265  virtual bool autoCreateForRemoteObject() const = 0;
266  };
267 
268  template <typename T_StateComponent, bool T_AutoCreateForRemoteObject = true>
270  {
271  public:
272  DEFINE_STATE_COMPONENT_HELPER(T_StateComponent)
273  virtual DtStateComponent* create( DtStateData* sd ) override { return new T_StateComponent( sd ); };
274 
275  virtual void registerLegionComponent(Legion::SimulationDatabase* db) override
276  {
277  T_StateComponent::registerLegionComponent(db);
278  }
279 
280  virtual void addAdditionalTableColumns(Legion::SimulationDatabase* db) override
281  {
282  T_StateComponent::addAdditionalTableColumns(db);
283  }
284 
285  virtual bool autoCreateForRemoteObject() const override
286  {
287  return T_AutoCreateForRemoteObject;
288  }
289  };
290 
295  {
296  private:
297 
299  DtFrameStateInterface& operator = ( const DtFrameStateInterface& rhs );
300 
301  public:
302 
304 
305  virtual ~DtFrameStateInterface();
306 
307  void setIsWritable(bool b) { myIsWritable = b; };
308  bool isWritable() const { return myIsWritable; };
309 
310  UInt64 stateId() const { return myStateId; };
311  UInt64 legionGlobalId() const { return myLegionId; };
312  void setLegionGlobalId( UInt64 d ) { myLegionId = d; };
313  virtual bool isModified() const { return myIsModified; };
314  virtual void clearModified() { myIsModified = false; };
315  virtual void markModified();
316 
317  virtual DtStateComponent::StateComponentType type() const { return componentType(); };
318  virtual DtStateComponent::StateComponentType componentType() const = 0;
319 
320  virtual const char* stringType() const = 0;
321 
322 
323  void setId( UInt64 id ) { myId = id; };
324  virtual UInt64 id() const { return myId; };
325 
326  virtual void updateStateData( DtStateData* sd );
327 
329  virtual Legion::ReadStateInstance readStateInstance() const { throw DtUnimplementedMethod("void readStateInstance() const is not implemented."); };
330  virtual Legion::WriteStateInstance writeStateInstance() { throw DtUnimplementedMethod("void writeStateInstance() const is not implemented."); };
331 
333  {
334  signal_componentModified( this );
335  }
336 
337  bool cleared() const
338  {
339  return myCleared;
340  }
341 
342  bool advancedFrame() const
343  {
344  return myAdvancedFrame;
345  }
346 
347  virtual void frameAdvanced()
348  {
349  myAdvancedFrame = true;
350  }
351 
353  virtual void convertToRemote();
354 
356  virtual void convertToLocal();
357  virtual void aboutToBeDeleted();
358 
359  mutable boost::signals2::signal<void (DtFrameStateInterface*)> signal_stateComponentAboutToBeDeleted;
360  mutable boost::signals2::signal<void (const DtFrameStateInterface*)> signal_componentModified;
361 
362  protected:
363 
365  virtual void makeWritable() { throw DtUnimplementedMethod("void makeWritable() const is not implemented."); };
366 
368  virtual void makeReadOnly() { throw DtUnimplementedMethod("void makeReadOnly() const is not implemented."); };
369 
370  protected:
371  bool myIsModified;
376  bool myCleared;
379  };
380 
381 
383  template <typename T_Component>
385  {
386  public:
387 
388  DEFINE_STATE_COMPONENT_HELPER( T_Component )
389 
391  : DtStateComponent(sd)
392  {
393  }
394 
395  virtual void setId(UInt64 id) override
396  {
398 
399  if (nextFrameState())
400  {
401  nextFrameState()->setId(id);
402  }
403 
404  if (currentFrameState())
405  {
406  const_cast<DtFrameStateInterface*>(currentFrameState())->setId(id);
407  }
408  }
409 
410  virtual void setStateData(DtStateData* sd) override
411  {
412  if (myStateData != sd)
413  {
415 
416  updateStateData(sd);
417  }
418  }
419 
420  virtual bool isDoubleBuffered() const override { return true; };
421 
423  virtual bool forceAdvance() override { return false; };
424  virtual void advanceFrame() override
425  {
426  myAdvancedFrame = true;
427 
428  if ( nextFrameState()->isModified() || forceAdvance() )
429  {
431  const_cast<DtFrameStateInterface*>( currentFrameState() )->markModified();
434  signal_componentModified( this );
435  }
436  else
437  {
439  const_cast<DtFrameStateInterface*>(currentFrameState())->clearModified();
440  }
441 
443  const_cast<DtFrameStateInterface*>(currentFrameState())->frameAdvanced();
444  }
445 
446  static void registerLegionComponent( Legion::SimulationDatabase* ) {};
447  static void addAdditionalTableColumns( Legion::SimulationDatabase* ) {};
448 
450  virtual void updateDataStorage() = 0;
451 
453  virtual void updateStateData(DtStateData*) = 0;
454 
455  };
456 
457 }
unsigned int StateComponentType
Definition: stateComponent.h:56
virtual bool forceAdvance()
Override to force an advance, even if not modified.
Definition: stateComponent.h:203
const DtStateData * stateData() const
Definition: stateComponent.h:182
Instances of DtVrfObjectParameters are the readable/writeable objects that contain the information ne...
Definition: vrfObjectParameters.h:64
void emitComponentUpdated()
Definition: stateComponent.h:332
void setLegionGlobalId(UInt64 d)
Definition: stateComponent.h:312
void setId(UInt64 id)
Definition: stateComponent.h:323
virtual const DtFrameStateInterface * currentFrameState() const
Definition: stateComponent.h:208
Definition: stateDataTypes.h:23
const Coordinate_System * coordinateSystem() const
Definition: stateComponent.h:197
virtual void advanceFrame() override
Definition: stateComponent.h:424
virtual void addAdditionalTableColumns(Legion::SimulationDatabase *db) override
Definition: stateComponent.h:280
UInt64 stateId() const
Definition: stateComponent.h:310
bool myAdvancedFrame
Definition: stateComponent.h:377
virtual Legion::WriteStateInstance writeStateInstance()
Definition: stateComponent.h:211
bool myAdvancedFrame
Definition: stateComponent.h:227
virtual void setIsRemoteComponent(bool b)
Definition: stateComponent.h:136
unsigned int UInt32
Definition: stateDataTypes.h:18
Definition: stateComponent.h:269
static void registerLegionComponent(Legion::SimulationDatabase *)
Definition: stateComponent.h:446
virtual Legion::WriteStateInstance writeStateInstance()
Definition: stateComponent.h:330
virtual void removeAdditionalStateComponents()
Override this method to destroy any allocated legion extensions that need to be destroyed.
Definition: stateComponent.h:215
virtual bool isDoubleBuffered() const override
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:420
boost::signals2::signal< void(const DtFrameStateInterface *)> signal_componentModified
Definition: stateComponent.h:360
virtual void frameAdvanced()
Definition: stateComponent.h:347
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
bool myPublishingOnLegionNetwork
Definition: stateComponent.h:226
bool publishingOnLegionNetwork() const
Definition: stateComponent.h:131
unsigned long long UInt64
Definition: stateDataTypes.h:17
bool isWritable() const
Definition: stateComponent.h:308
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:168
virtual bool autoCreateForRemoteObject() const override
Definition: stateComponent.h:285
boost::signals2::signal< void(DtFrameStateInterface *)> signal_stateComponentAboutToBeDeleted
Definition: stateComponent.h:359
boost::signals2::signal< void(DtStateComponent *)> signal_stateComponentAboutToBeDeleted
Definition: stateComponent.h:123
virtual void makeWritable()
Override to make component writable.
Definition: stateComponent.h:365
virtual UInt64 id() const
Definition: stateComponent.h:324
bool cleared() const
Definition: stateComponent.h:337
Definition: coordSystem.h:54
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:398
#define DEFINE_STATE_COMPONENT_HELPER(Component)
Definition: stateComponent.h:245
UInt64 legionGlobalId() const
Definition: stateComponent.h:311
bool myIsWritable
Definition: stateComponent.h:375
DtStateData * stateData()
Definition: stateComponent.h:192
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:384
DtStateData * myStateData
Definition: stateComponent.h:222
UInt64 myStateId
Definition: stateComponent.h:373
virtual DtStateComponent::StateComponentType type() const
Definition: stateComponent.h:317
virtual void updateDataStorage()=0
Implement to update data storage. Called from advanceFrame.
virtual bool isModified() const
Definition: stateComponent.h:313
The creator that is used to create a state component.
Definition: stateComponent.h:256
StateComponentTypeEnum
List of all current state components. User components start at the UserStateComponent enum...
Definition: stateComponent.h:59
virtual const DtFrameStateInterface * nextFrameState() const
Definition: stateComponent.h:210
virtual void setId(UInt64 id) override
If this component is part of a list and needs to be uniquely identified, this wil be that unique id...
Definition: stateComponent.h:395
bool myCleared
Definition: stateComponent.h:225
Definition: stateComponent.h:52
virtual void registerLegionComponent(Legion::SimulationDatabase *db) override
Definition: stateComponent.h:275
bool isRemoteComponent() const
Definition: stateComponent.h:147
void setIsWritable(bool b)
Definition: stateComponent.h:307
UInt64 myLegionId
Definition: stateComponent.h:374
virtual void clearModified()
Definition: stateComponent.h:314
virtual Legion::ReadStateInstance readStateInstance() const
If supported, the read or write state legion instance of this component.
Definition: stateComponent.h:329
bool advancedFrame() const
Definition: stateComponent.h:342
#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:163
virtual void updateStateData(DtStateData *)=0
Implement to update data storage to the new state data.
const Coordinate_System * myCoordinateSystem
Definition: stateComponent.h:223
bool myCleared
Definition: stateComponent.h:376
virtual DtStateComponent * create(DtStateData *sd) override
Definition: stateComponent.h:273
virtual void addAdditionalStateComponents()
Definition: stateComponent.h:212
DtStateData * myStateData
Definition: stateComponent.h:378
virtual DtFrameStateInterface * nextFrameState()
Definition: stateComponent.h:209
bool cleared() const
Definition: stateComponent.h:187
virtual bool forceAdvance() override
Override to force an advance, even if not modified.
Definition: stateComponent.h:423
static void addAdditionalTableColumns(Legion::SimulationDatabase *)
Definition: stateComponent.h:447
This is a simple base class that will be used to return a pointer to current or next frame state...
Definition: stateComponent.h:294
UInt64 myId
Definition: stateComponent.h:372
UInt64 myId
Definition: stateComponent.h:221
bool myIsRemoteComponent
Definition: stateComponent.h:224
virtual void setStateData(DtStateData *sd) override
Call with care. This will only succeed if the current state data is nullptr, else it will no-op...
Definition: stateComponent.h:410
boost::signals2::signal< void(DtStateComponent *)> signal_componentModified
Definition: stateComponent.h:124
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 Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)