VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
entityStateComponent.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
10 #include <vlpi/disEnums.h>
11 #include <legionStandardOM/sets/writeEntityRepository.hpp>
12 #include "legionStandardOM/sets/readEntityRepository.hpp"
13 #include "legionDataStore/view.h"
14 #include <tbb/spin_mutex.h>
15 
16 namespace LOM
17 {
18  class ReadEntityRepository;
19 }
20 
21 class DtAppearance;
22 
23 namespace makVrf
24 {
31  {
32  using SimStateID = unsigned long long;
33 
39  : myUUID(DtUUID::nullUUID())
40  , myIsLocal(false)
41  , myCheckForNameReservation(true)
42  {};
43 
47  : myGlobalId(orig.myGlobalId)
48  , myUUID(orig.myUUID)
49  , myMarkingText(orig.myMarkingText)
50  , myCallsign(orig.myCallsign)
51  , myEntityId(orig.myEntityId)
52  , myIsLocal(orig.myIsLocal)
53  , myUserData(orig.myUserData)
54  , myOrbatId(orig.myOrbatId)
55  , myCheckForNameReservation(orig.myCheckForNameReservation)
56  , mySimEngineAddress(orig.mySimEngineAddress)
57  , mySidc(orig.mySidc)
58  {
59  }
60 
65  {
66  myGlobalId = rhs.myGlobalId;
67  myUUID = rhs.myUUID;
68  myEntityId = rhs.myEntityId;
69  myMarkingText = rhs.myMarkingText;
70  myCallsign = rhs.myCallsign;
71  myIsLocal = rhs.myIsLocal;
72  myOrbatId = rhs.myOrbatId;
73  myUserData = rhs.myUserData;
74  mySimEngineAddress = rhs.mySimEngineAddress;
75  myCheckForNameReservation = rhs.myCheckForNameReservation;
76  mySidc = rhs.mySidc;
77 
78  return *this;
79  }
80 
82  DEFINE_ACCESSOR_MUTATOR(DtString, globalId, GlobalId)
84  DEFINE_ACCESSOR_MUTATOR(DtEntityIdentifier, entityId, EntityId)
86  DEFINE_ACCESSOR_MUTATOR(DtUUID, uuid, UUID)
88  DEFINE_ACCESSOR_MUTATOR(DtString, markingText, MarkingText)
90  DEFINE_ACCESSOR_MUTATOR(DtString, callsign, Callsign)
92  DEFINE_ACCESSOR_MUTATOR(bool, isLocal, IsLocal)
94  DEFINE_ACCESSOR_MUTATOR(unsigned long long, userData, UserData)
96  DEFINE_ACCESSOR_MUTATOR(unsigned long long, orbatId, OrbatId)
98  DEFINE_ACCESSOR_MUTATOR(bool, checkForNameReservation, CheckForNameReservation)
103  DEFINE_ACCESSOR_MUTATOR(DtSimulationAddress, simEngineAddress, SimEngineAddress)
105  DEFINE_ACCESSOR_MUTATOR(DtString, sidc, Sidc)
106 
107  protected:
109  DtString myGlobalId;
111  DtString mySidc;
113  DtString myMarkingText;
115  DtString myCallsign;
117  DtEntityIdentifier myEntityId;
119  DtUUID myUUID;
121  bool myIsLocal;
123  unsigned long long myUserData = 0;
125  unsigned long long myOrbatId = 0;
127  bool myCheckForNameReservation;
129  DtSimulationAddress mySimEngineAddress;
130  };
131 
142  {
143  public:
145 
146 
149  : DtSimulatedObjectStateComponent(storage)
150  , myUUIDColumn(0xFFFFFFFF)
151  , myIsClutterEntityColumn(0xFFFFFFFF)
152  {
153  }
154 
156  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(bool, isClutterEntity, IsClutterEntity)
158  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(UInt32, capabilities, Capabilities)
160  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(DtEntityType, guise, Guise)
162  UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(DtUUID, superior, Superior)
164  UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(DtString, callsign, Callsign)
165 
166 
167  virtual const std::set<DtUUID> attachments() const { throw DtUnimplementedMethod("std::set<DtUUID> attachments() is not implemented for this class."); };
171  virtual void setEntityType(const DtEntityType& ot) override { throw DtUnimplementedMethod("void setEntityType(const DtEntityType& ot) is not implemented for this class."); };
174  virtual void addAttachment(const DtUUID&) { throw DtUnimplementedMethod("void addAttachment(const DtUUID&) is not implemented for this class."); };
177  virtual void removeAttachment(const DtUUID&) { throw DtUnimplementedMethod("void removeAttachment(const DtUUID&) is not implemented for this class."); };
178 
184  mutable boost::signals2::signal<void (int oldState, int newState, makVrf::SimStateID)> signal_damageStateChanged;
185 
189  mutable boost::signals2::signal<void (const DtFrameStateInterface*)> signal_attachmentsChanged;
190 
195  mutable boost::signals2::signal<void(const DtUUID& oldSuperior, const DtUUID& newSuperior)> signal_superiorChanged;
196 
201  mutable boost::signals2::signal<void(bool oldIsClutter, bool newIsClutter)> signal_isClutterChanged;
202 
208  mutable boost::signals2::signal<void(const DtString&, const DtString&, makVrf::SimStateID)> signal_callsignChanged;
209 
210  protected:
215  };
216 
226  template <typename T_BaseComponent>
228  {
229  public:
234 
239  const DtEntityStateComponentData& frameState() const { return this->myData; };
244  DtEntityStateComponentData& frameState() { return this->myData; };
245 
247  const bool& isLocal() const;
250  void setIsLocal(const bool&);
251 
253  const bool& checkForNameReservation() const;
256  void setCheckForNameReservation(const bool&);
257 
259  const DtString& globalId() const;
262  void setGlobalId(const DtString&);
263 
268  const DtUUID& uuid() const;
271  void setUUID(const DtUUID&);
272 
274  const bool isClutterEntity() const;
277  void setIsClutterEntity(const bool&);
278 
280  virtual const DtString& sidc() const override;
282  virtual void setSidc(const DtString&) override;
283 
285  const DtString& markingText() const;
288  void setMarkingText(const DtString&);
289 
291  const DtString& callsign() const;
294  void setCallsign(const DtString&);
295 
297  const DtForceType forceType() const;
300  void setForceType(const DtForceType&);
301 
303  const UInt32 appearanceBits() const;
309  void setAppearanceBits(const UInt32&);
310 
312  const DtEntityType entityType() const { return objectType(); };
314  const DtEntityType objectType() const;
317  void setEntityType(const DtEntityType&);
318 
320  const DtEntityIdentifier& entityId() const;
323  void setEntityId(const DtEntityIdentifier&);
324 
326  const UInt32 capabilities() const;
329  void setCapabilities(const UInt32&);
330 
332  const DtEntityType guise() const;
335  void setGuise(const DtEntityType&);
336 
341  const DtUUID& superior() const;
344  void setSuperior(const DtUUID&);
345 
347  const unsigned long long userLongLongData() const;
350  void setUserLongLongData(const unsigned long long&);
351 
353  const unsigned long long orbatId() const;
356  void setOrbatId(const unsigned long long&);
357 
362  const DtSimulationAddress simEngineAddress() const override;
365  void setSimEngineAddress(const DtSimulationAddress&) override;
366 
369  virtual void setAppearance(const DtAppearance& app);
370 
376  virtual void makeWritable();
377 
381  virtual void makeReadOnly();
382 
383  protected:
385  LOM::WriteEntityRepository myWriteEntityStateRepository;
390  };
391 
393 
403  template <typename T_BaseComponent>
405  {
406  public:
415 
420  const DtEntityStateComponentData& frameState() const { return this->myData; };
421 
423  const bool& isLocal() const;
425  const bool& checkForNameReservation() const;
427  const DtString& globalId() const;
429  const DtUUID& uuid() const;
434  const DtString& markingText() const;
436  virtual const DtString& sidc() const override;
438  const DtString& callsign() const;
440  const DtForceType forceType() const;
442  const DtEntityType entityType() const { return DtEntityType(objectType()); };
444  const DtEntityType objectType() const;
446  const DtEntityIdentifier& entityId() const;
448  const UInt32 appearanceBits() const;
450  const bool isClutterEntity() const;
452  const UInt32 capabilities() const;
454  const DtEntityType guise() const;
456  const unsigned long long userLongLongData() const;
458  const unsigned long long orbatId() const;
463  const DtSimulationAddress simEngineAddress() const override;
464 
466  const DtUUID& superior() const;
467 
473  void addAttachment(const DtUUID&);
476  void removeAttachment(const DtUUID&);
479  const std::set<DtUUID> attachments() const;
481 
489  bool checkForUpdatedItems();
490 
491  protected:
497  const DtUUID _uuid() const;
503  const DtString _markingText() const;
506  const DtEntityIdentifier _entityId() const;
507 
510  bool checkEntityIdChanged();
513  bool checkUUIDChanged();
516  bool checkForceChanged();
519  bool checkMarkingTextChanged();
522  bool checkDamageStateChanged();
525  bool checkIsClutterChanged();
526 
533  void handleDataUpdated(const std::vector<UInt32>& attributesUpdated);
534 
542  void completeSetup();
543 
548  {
549  this->myData = data;
550  }
551 
552  protected:
553  friend class DtStateDataManager;
556  void setSuperior(const DtUUID&);
557 
558  protected:
560  LOM::ReadEntityRepository myReadEntityStateRepository;
568  unsigned int myCallbackHandle;
571 
573  std::set<DtUUID> myAttachments;
575  mutable tbb::spin_rw_mutex myAttachmentsMutex;
577  boost::signals2::scoped_connection myCompleteSetupConnection;
579  tbb::spin_mutex myCompleteSetupMutex;
582  };
583 
585 
597  {
598  public:
605 
607  virtual ~DtEntityStateComponentImplementation() override;
608 
610  bool isDoubleBuffered() { return true; };
612  virtual const DtFrameStateInterface* currentFrameState() const override { return &myCurrentFrameState; }
614  virtual DtFrameStateInterface* nextFrameState() override { return &myNextFrameState; };
616  virtual const DtFrameStateInterface* nextFrameState() const override { return &myNextFrameState; };
617 
624  virtual void updateDataStorage() override;
625 
628  virtual void updateStateData(DtStateData* sd) override
629  {
630  myCurrentFrameState.updateStateData(sd);
631  myNextFrameState.updateStateData(sd);
632  }
633 
640  static void addAdditionalTableColumns(Legion::SimulationDatabase*);
641 
644  virtual void initializeFromParameters(const DtVrfObjectParameters* params) override;
645 
647  virtual Legion::WriteStateInstance writeStateInstance() override { return myWriteEntityStateRepository; };
648 
653  virtual void convertToRemote() override;
654 
659  virtual void convertToLocal() override;
660 
662  virtual void addAdditionalStateComponents() override;
663 
665  virtual void aboutToBeDeleted() override
666  {
668  myCurrentFrameState.aboutToBeDeleted();
669  myNextFrameState.aboutToBeDeleted();
670  }
671 
672  protected:
678  LOM::WriteEntityRepository myWriteEntityStateRepository;
679  };
680 
685 }
686 
687 #define _ENTITY_STATE_COMPONENT 1
688 #include "vrfStateData/entityStateComponent.inl"
Write-access (next-frame) entity state component template.
Definition: entityStateComponent.h:227
UUID is a unique ID wrapper class.
Definition: uuid.h:59
boost::signals2::signal< void(const DtFrameStateInterface *)> signal_attachmentsChanged
Emitted when the set of attached entities changes.
Definition: entityStateComponent.h:189
unsigned int myCallbackHandle
Handle returned by the Legion instance-updated callback registration; 0 if not registered.
Definition: entityStateComponent.h:568
Instances of DtVrfObjectParameters are the readable/writeable objects that contain the information ne...
Definition: vrfObjectParameters.h:64
LOM::WriteEntityRepository myWriteEntityStateRepository
Legion write-access repository for this entity&#39;s attribute set.
Definition: entityStateComponent.h:385
const DtEntityType entityType() const
Returns the DIS entity type (alias for objectType()).
Definition: entityStateComponent.h:442
const DtEntityStateComponentData & frameState() const
Returns the next-frame state data block (const overload).
Definition: entityStateComponent.h:239
Exception thrown when a required method has not been implemented.
Definition: stateDataTypes.h:30
DtString myMarkingText
DIS-style marking text (max 32 chars as enforced by Legion).
Definition: entityStateComponent.h:113
tbb::spin_mutex myCompleteSetupMutex
Mutex serialising concurrent calls to completeSetup().
Definition: entityStateComponent.h:579
unsigned long long myOrbatId
Order-of-Battle identifier; not reflected on the network.
Definition: entityStateComponent.h:125
bool myCheckForNameReservation
When true, HLA name reservation must complete before the object is published.
Definition: entityStateComponent.h:127
bool myIsClutterEntity
Cached clutter-entity flag for change detection.
Definition: entityStateComponent.h:570
int myForceId
Cached DIS force type for change detection.
Definition: entityStateComponent.h:564
Definition: stateComponent.h:63
virtual void addAttachment(const DtUUID &)
Records that uuid is attached to this entity.
Definition: entityStateComponent.h:174
Abstract base interface for the entity state component.
Definition: entityStateComponent.h:141
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
The DtSimulatedObjectStateComponent is an interface that all main components (those that are consider...
Definition: simulatedObjectStateComponent.h:21
UInt32 myIsClutterEntityColumn
Legion attribute column index for the ClutterEntity field; 0xFFFFFFFF until initialised.
Definition: entityStateComponent.h:214
DtEntityStateComponentData(const DtEntityStateComponentData &orig)
Copy constructor. Performs a member-wise deep copy of orig.
Definition: entityStateComponent.h:46
bool isDoubleBuffered()
Returns true; this component uses double-buffered state.
Definition: entityStateComponent.h:610
boost::signals2::scoped_connection myCompleteSetupConnection
Scoped connection to signal_firstFrameAdvance used to defer completeSetup().
Definition: entityStateComponent.h:577
boost::signals2::signal< void(const DtUUID &oldSuperior, const DtUUID &newSuperior)> signal_superiorChanged
Emitted when the superior (parent) entity UUID changes.
Definition: entityStateComponent.h:195
boost::signals2::signal< void(bool oldIsClutter, bool newIsClutter)> signal_isClutterChanged
Emitted when the clutter-entity flag changes.
Definition: entityStateComponent.h:201
virtual void setEntityType(const DtEntityType &ot) override
Sets the DIS entity type.
Definition: entityStateComponent.h:171
const DtEntityStateComponentData & frameState() const
Returns the current-frame state data block.
Definition: entityStateComponent.h:420
DtString mySidc
Visual Sidc code.
Definition: entityStateComponent.h:111
Plain-old-data container for all serializable entity state fields.
Definition: entityStateComponent.h:30
void advanceFrame(const DtEntityStateComponentData &data)
Copies data into the current-frame cache (called by updateDataStorage()).
Definition: entityStateComponent.h:547
Double-buffered entity state component implementation.
Definition: entityStateComponent.h:596
std::set< DtUUID > myAttachments
Thread-safe set of UUIDs of currently attached entities.
Definition: entityStateComponent.h:573
virtual void aboutToBeDeleted() override
Notifies both frame states that the component is about to be destroyed.
Definition: entityStateComponent.h:665
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:513
DtEntityStateComponentData()
Constructs a default-initialized data block.
Definition: entityStateComponent.h:38
#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
Read-only (current-frame) entity state component template.
Definition: entityStateComponent.h:404
virtual Legion::WriteStateInstance writeStateInstance() override
Returns the Legion write state instance handle for this entity.
Definition: entityStateComponent.h:647
DtString myGlobalId
Accessor/mutator for the network-layer global object identifier string.
Definition: entityStateComponent.h:109
boost::signals2::signal< void(const DtString &, const DtString &, makVrf::SimStateID)> signal_callsignChanged
Emitted when the entity&#39;s callsign changes.
Definition: entityStateComponent.h:208
DtEntityStateComponentNextFrame myNextFrameState
Next-frame (write-access) entity state.
Definition: entityStateComponent.h:676
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:489
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
DtUUID mySuperior
UUID of the superior (parent) entity; updated each frame if changed.
Definition: entityStateComponent.h:562
DtEntityIdentifier myEntityId
DIS entity identifier (site / host / entity number).
Definition: entityStateComponent.h:117
#define UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(Type, Member, Set)
Defines an undefined virtual by-value accessor and an undefined virtual setter, both throwing DtUnimp...
Definition: doubleBufferedDataStorage.h:103
virtual void aboutToBeDeleted()
Called when the component is about to be deleted; emits signal_stateComponentAboutToBeDeleted.
unsigned long long SimStateID
Definition: entityStateComponent.h:32
LOM::ReadEntityRepository myReadEntityStateRepository
Legion read-access repository for this entity&#39;s attribute set.
Definition: entityStateComponent.h:560
virtual const DtFrameStateInterface * currentFrameState() const override
Returns the current-frame state interface (read-only).
Definition: entityStateComponent.h:612
UInt32 myUUIDColumn
Legion attribute column index for the UUID field; 0xFFFFFFFF until initialised.
Definition: entityStateComponent.h:212
virtual void updateStateData(DtStateData *sd) override
Propagates a new DtStateData pointer into both frame states.
Definition: entityStateComponent.h:628
#define UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(Type, Member, Set)
Defines an undefined virtual const-reference accessor and an undefined virtual setter, both throwing DtUnimplementedMethod and requiring overrides in a derived class.
Definition: doubleBufferedDataStorage.h:112
LOM::WriteEntityRepository myWriteEntityStateRepository
Legion write repository owned by this implementation instance.
Definition: entityStateComponent.h:678
#define DEFINE_ACCESSOR_MUTATOR(ReturnType, Accessor, Mutator)
Defines a const reference accessor and an inline setter for a member variable.
Definition: doubleBufferedDataStorage.h:37
DtEntityStateComponentData myData
Cached copy of the entity state data for this frame.
Definition: entityStateComponent.h:389
DtStateComponentCreator< DtEntityStateComponentImplementation > DtEntityStateComponentCreator
Factory type that creates DtEntityStateComponentImplementation instances.
Definition: entityStateComponent.h:684
DtEntityStateComponentData myData
Cached copy of the entity state data for the current frame.
Definition: entityStateComponent.h:581
DtEntityStateComponentCurrentFrame myCurrentFrameState
Current-frame (read-only) entity state.
Definition: entityStateComponent.h:674
DtString myCallsign
Optional callsign; stored independently from the Legion data store.
Definition: entityStateComponent.h:115
virtual DtFrameStateInterface * nextFrameState() override
Returns the next-frame state interface (read-write).
Definition: entityStateComponent.h:614
DtSimulationAddress mySimEngineAddress
Simulation engine address (site/host); defaults to the entity identifier&#39;s simulation address...
Definition: entityStateComponent.h:129
#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
DtUUID myUUID
Simulation-wide UUID; backed by a raw byte array in the Legion data store.
Definition: entityStateComponent.h:119
DtEntityStateComponentData & frameState()
Returns the next-frame state data block (mutable overload).
Definition: entityStateComponent.h:244
int myDamageState
Cached damage state for change detection.
Definition: entityStateComponent.h:566
DtEntityStateComponentData & operator=(const DtEntityStateComponentData &rhs)
Assignment operator. Performs a member-wise deep copy of rhs.
Definition: entityStateComponent.h:64
unsigned long long myUserData
Application-defined 64-bit integer user payload; not reflected on the network.
Definition: entityStateComponent.h:123
virtual const DtFrameStateInterface * nextFrameState() const override
Returns the next-frame state interface (read-only overload).
Definition: entityStateComponent.h:616
bool myIsLocal
true when this entity is locally owned and published by this simulation process.
Definition: entityStateComponent.h:121
DtUUID mySuperior
UUID of the superior (parent) entity; not double-buffered.
Definition: entityStateComponent.h:387
Base interface for accessing current or next frame state in a double-buffered state component...
Definition: stateComponent.h:354
tbb::spin_rw_mutex myAttachmentsMutex
Mutex protecting myAttachments from concurrent access.
Definition: entityStateComponent.h:575
const DtEntityType entityType() const
Returns the DIS entity type (alias for objectType()).
Definition: entityStateComponent.h:312
This class holds the state data that represents each simulation object in the system.
Definition: stateDataManager.h:76

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)