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 {
26  {
27  using SimStateID = unsigned long long;
28 
30  : myUUID(DtUUID::nullUUID())
31  , myIsLocal(false)
32  , myCheckForNameReservation(true)
33  {};
34 
36  : myGlobalId(orig.myGlobalId)
37  , myUUID(orig.myUUID)
38  , myMarkingText(orig.myMarkingText)
39  , myCallsign(orig.myCallsign)
40  , myEntityId(orig.myEntityId)
41  , myIsLocal(orig.myIsLocal)
42  , myUserData(orig.myUserData)
43  , myOrbatId(orig.myOrbatId)
44  , myCheckForNameReservation(orig.myCheckForNameReservation)
45  , mySimEngineAddress(orig.mySimEngineAddress)
46  {
47  }
48 
50  {
51  myGlobalId = rhs.myGlobalId;
52  myUUID = rhs.myUUID;
53  myEntityId = rhs.myEntityId;
54  myMarkingText = rhs.myMarkingText;
55  myCallsign = rhs.myCallsign;
56  myIsLocal = rhs.myIsLocal;
57  myOrbatId = rhs.myOrbatId;
58  myUserData = rhs.myUserData;
59  mySimEngineAddress = rhs.mySimEngineAddress;
60  myCheckForNameReservation = rhs.myCheckForNameReservation;
61 
62  return *this;
63  }
64 
65  DEFINE_ACCESSOR_MUTATOR(DtString, globalId, GlobalId)
66  DEFINE_ACCESSOR_MUTATOR(DtEntityIdentifier, entityId, EntityId)
67  DEFINE_ACCESSOR_MUTATOR(DtUUID, uuid, UUID)
68  DEFINE_ACCESSOR_MUTATOR(DtString, markingText, MarkingText)
69  DEFINE_ACCESSOR_MUTATOR(DtString, callsign, Callsign)
70  DEFINE_ACCESSOR_MUTATOR(bool, isLocal, IsLocal)
71  DEFINE_ACCESSOR_MUTATOR(unsigned long long, userData, UserData)
72  DEFINE_ACCESSOR_MUTATOR(unsigned long long, orbatId, OrbatId)
73  DEFINE_ACCESSOR_MUTATOR(bool, checkForNameReservation, CheckForNameReservation)
74  DEFINE_ACCESSOR_MUTATOR(DtSimulationAddress, simEngineAddress, SimEngineAddress)
75 
76  protected:
77  DtString myGlobalId;
78  DtString myMarkingText;
79  DtString myCallsign;
80  DtEntityIdentifier myEntityId;
81  DtUUID myUUID;
82  bool myIsLocal;
83  unsigned long long myUserData = 0;
84  unsigned long long myOrbatId = 0;
85  bool myCheckForNameReservation;
86  DtSimulationAddress mySimEngineAddress;
87  };
88 
92  {
93  public:
95 
97  : DtSimulatedObjectStateComponent(storage)
98  , myUUIDColumn(0xFFFFFFFF)
99  , myIsClutterEntityColumn(0xFFFFFFFF)
100  {
101  }
102 
103  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(bool, isClutterEntity, IsClutterEntity)
104  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(UInt32, capabilities, Capabilities)
105  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(DtEntityType, guise, Guise)
106  UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(DtUUID, superior, Superior)
108 
109  virtual const std::set<DtUUID> attachments() const { throw DtUnimplementedMethod("std::set<DtUUID> attachments() is not implemented for this class."); };
110  virtual void setEntityType(const DtEntityType& ot) override { throw DtUnimplementedMethod("void setEntityType(const DtEntityType& ot) is not implemented for this class."); };
111  virtual void addAttachment(const DtUUID&) { throw DtUnimplementedMethod("void addAttachment(const DtUUID&) is not implemented for this class."); };
112  virtual void removeAttachment(const DtUUID&) { throw DtUnimplementedMethod("void removeAttachment(const DtUUID&) is not implemented for this class."); };
113 
114  mutable boost::signals2::signal<void (int oldState, int newState, makVrf::SimStateID)> signal_damageStateChanged;
115  mutable boost::signals2::signal<void (const DtFrameStateInterface*)> signal_attachmentsChanged;
116  mutable boost::signals2::signal<void(const DtUUID& oldSuperior, const DtUUID& newSuperior)> signal_superiorChanged;
117  mutable boost::signals2::signal<void(bool oldIsClutter, bool newIsClutter)> signal_isClutterChanged;
118  mutable boost::signals2::signal<void(const DtString&, const DtString&, makVrf::SimStateID)> signal_callsignChanged;
119 
120  protected:
123  };
124 
126  template <typename T_BaseComponent>
128  {
129  public:
132 
134  const DtEntityStateComponentData& frameState() const { return this->myData; };
135  DtEntityStateComponentData& frameState() { return this->myData; };
136 
137  const bool& isLocal() const;
138  void setIsLocal(const bool&);
139 
140  const bool& checkForNameReservation() const;
141  void setCheckForNameReservation(const bool&);
142 
143  const DtString& globalId() const;
144  void setGlobalId(const DtString&);
145 
146  const DtUUID& uuid() const;
147  void setUUID(const DtUUID&);
148 
149  const bool isClutterEntity() const;
150  void setIsClutterEntity(const bool&);
151 
152  const DtString& markingText() const;
153  void setMarkingText(const DtString&);
154 
155  const DtString& callsign() const;
156  void setCallsign(const DtString&);
157 
158  const DtForceType forceType() const;
159  void setForceType(const DtForceType&);
160 
161  const UInt32 appearanceBits() const;
162  void setAppearanceBits(const UInt32&);
163 
164  const DtEntityType entityType() const { return objectType(); };
165  const DtEntityType objectType() const;
166  void setEntityType(const DtEntityType&);
167 
168  const DtEntityIdentifier& entityId() const;
169  void setEntityId(const DtEntityIdentifier&);
170 
171  const UInt32 capabilities() const;
172  void setCapabilities(const UInt32&);
173 
174  const DtEntityType guise() const;
175  void setGuise(const DtEntityType&);
176 
178  const DtUUID& superior() const;
179  void setSuperior(const DtUUID&);
180 
181  const unsigned long long userLongLongData() const;
182  void setUserLongLongData(const unsigned long long&);
183 
184  const unsigned long long orbatId() const;
185  void setOrbatId(const unsigned long long&);
186 
187  const DtSimulationAddress simEngineAddress() const override;
188  void setSimEngineAddress(const DtSimulationAddress&) override;
189 
190  virtual void setAppearance(const DtAppearance& app);
191 
193  virtual void makeWritable();
194 
196  virtual void makeReadOnly();
197 
198  protected:
199  LOM::WriteEntityRepository myWriteEntityStateRepository;
202  };
203 
205 
207  template <typename T_BaseComponent>
209  {
210  public:
213 
215  const DtEntityStateComponentData& frameState() const { return this->myData; };
216 
217  const bool& isLocal() const;
218  const bool& checkForNameReservation() const;
219  const DtString& globalId() const;
220  const DtUUID& uuid() const;
221  const DtString& markingText() const;
222  const DtString& callsign() const;
223  const DtForceType forceType() const;
224  const DtEntityType entityType() const { return DtEntityType(objectType()); };
225  const DtEntityType objectType() const;
226  const DtEntityIdentifier& entityId() const;
227  const UInt32 appearanceBits() const;
228  const bool isClutterEntity() const;
229  const UInt32 capabilities() const;
230  const DtEntityType guise() const;
231  const unsigned long long userLongLongData() const;
232  const unsigned long long orbatId() const;
233  const DtSimulationAddress simEngineAddress() const override;
234 
235  const DtUUID& superior() const;
236 
240  void addAttachment(const DtUUID&);
241  void removeAttachment(const DtUUID&);
242  const std::set<DtUUID> attachments() const;
244 
245  bool checkForUpdatedItems();
246 
247  protected:
248  const DtUUID _uuid() const;
249  const DtString _markingText() const;
250  const DtEntityIdentifier _entityId() const;
251 
252  bool checkEntityIdChanged();
253  bool checkUUIDChanged();
254  bool checkForceChanged();
255  bool checkMarkingTextChanged();
256  bool checkDamageStateChanged();
257  bool checkIsClutterChanged();
258 
259  void handleDataUpdated(const std::vector<UInt32>& attributesUpdated);
260  void completeSetup();
261 
264  {
265  this->myData = data;
266  }
267 
268  protected:
269  friend class DtStateDataManager;
270  void setSuperior(const DtUUID&);
271 
272  protected:
273  LOM::ReadEntityRepository myReadEntityStateRepository;
276  std::string myMarkingText;
278  unsigned int myCallbackHandle;
280 
281  std::set<DtUUID> myAttachments;
282  mutable tbb::spin_rw_mutex myAttachmentsMutex;
283  boost::signals2::scoped_connection myCompleteSetupConnection;
284  tbb::spin_mutex myCompleteSetupMutex;
286  };
287 
289 
293  {
294  public:
296  virtual ~DtEntityStateComponentImplementation() override;
297 
298  bool isDoubleBuffered() { return true; };
299  virtual const DtFrameStateInterface* currentFrameState() const override { return &myCurrentFrameState; }
300  virtual DtFrameStateInterface* nextFrameState() override { return &myNextFrameState; };
301  virtual const DtFrameStateInterface* nextFrameState() const override { return &myNextFrameState; };
302 
303  virtual void updateDataStorage() override;
304 
305  virtual void updateStateData(DtStateData* sd) override
306  {
307  myCurrentFrameState.updateStateData(sd);
308  myNextFrameState.updateStateData(sd);
309  }
310 
311  static void addAdditionalTableColumns(Legion::SimulationDatabase*);
312 
313  virtual void initializeFromParameters(const DtVrfObjectParameters* params) override;
314 
315  virtual Legion::WriteStateInstance writeStateInstance() override { return myWriteEntityStateRepository; };
316 
318  virtual void convertToRemote() override;
319 
321  virtual void convertToLocal() override;
322 
323  virtual void addAdditionalStateComponents() override;
324 
325  virtual void aboutToBeDeleted() override
326  {
328  myCurrentFrameState.aboutToBeDeleted();
329  myNextFrameState.aboutToBeDeleted();
330  }
331 
332  protected:
335  LOM::WriteEntityRepository myWriteEntityStateRepository;
336  };
337 
341 }
342 
343 #define _ENTITY_STATE_COMPONENT 1
344 #include "vrfStateData/entityStateComponent.inl"
2) Define the next frame class. This will be used for write access.
Definition: entityStateComponent.h:127
UUID is a unique ID wrapper class.
Definition: uuid.h:59
boost::signals2::signal< void(const DtFrameStateInterface *)> signal_attachmentsChanged
Definition: entityStateComponent.h:115
unsigned int myCallbackHandle
Definition: entityStateComponent.h:278
Instances of DtVrfObjectParameters are the readable/writeable objects that contain the information ne...
Definition: vrfObjectParameters.h:64
LOM::WriteEntityRepository myWriteEntityStateRepository
Definition: entityStateComponent.h:199
const DtEntityType entityType() const
Definition: entityStateComponent.h:224
const DtEntityStateComponentData & frameState() const
Next frame access write access. Ensure this is only used in a single thread (i.e.a controller thread)...
Definition: entityStateComponent.h:134
Definition: stateDataTypes.h:23
DtString myMarkingText
Definition: entityStateComponent.h:78
tbb::spin_mutex myCompleteSetupMutex
Definition: entityStateComponent.h:284
unsigned long long myOrbatId
Definition: entityStateComponent.h:84
bool myCheckForNameReservation
Definition: entityStateComponent.h:85
bool myIsClutterEntity
Definition: entityStateComponent.h:279
int myForceId
Definition: entityStateComponent.h:275
Definition: stateComponent.h:63
virtual void addAttachment(const DtUUID &)
Definition: entityStateComponent.h:111
1) Define the interface class that will be used to represent the next and current frames...
Definition: entityStateComponent.h:91
unsigned int UInt32
Definition: stateDataTypes.h:18
Definition: stateComponent.h:269
The DtSimulatedObjectStateComponent is an interface that all main components (those that are consider...
Definition: simulatedObjectStateComponent.h:21
UInt32 myIsClutterEntityColumn
Definition: entityStateComponent.h:122
DtEntityStateComponentData(const DtEntityStateComponentData &orig)
Definition: entityStateComponent.h:35
bool isDoubleBuffered()
Definition: entityStateComponent.h:298
boost::signals2::scoped_connection myCompleteSetupConnection
Definition: entityStateComponent.h:283
boost::signals2::signal< void(const DtUUID &oldSuperior, const DtUUID &newSuperior)> signal_superiorChanged
Definition: entityStateComponent.h:116
boost::signals2::signal< void(bool oldIsClutter, bool newIsClutter)> signal_isClutterChanged
Definition: entityStateComponent.h:117
virtual void setEntityType(const DtEntityType &ot) override
Definition: entityStateComponent.h:110
const DtEntityStateComponentData & frameState() const
Current frame state only can access current frame buffers. This ensures thread safety.
Definition: entityStateComponent.h:215
Definition: entityStateComponent.h:25
void advanceFrame(const DtEntityStateComponentData &data)
Definition: entityStateComponent.h:263
4) Define the state component that will contain the wrappers to the next and current frame states tha...
Definition: entityStateComponent.h:292
std::set< DtUUID > myAttachments
Definition: entityStateComponent.h:281
virtual void aboutToBeDeleted() override
Definition: entityStateComponent.h:325
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:398
DtEntityStateComponentData()
Definition: entityStateComponent.h:29
#define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent)
Definition: stateComponent.h:231
std::string myMarkingText
Definition: entityStateComponent.h:276
3) Define the current frame class. This will be used for read access.
Definition: entityStateComponent.h:208
virtual Legion::WriteStateInstance writeStateInstance() override
Definition: entityStateComponent.h:315
DtString myGlobalId
Definition: entityStateComponent.h:77
boost::signals2::signal< void(const DtString &, const DtString &, makVrf::SimStateID)> signal_callsignChanged
Definition: entityStateComponent.h:118
DtEntityStateComponentNextFrame myNextFrameState
Definition: entityStateComponent.h:334
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:384
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
DtUUID mySuperior
Definition: entityStateComponent.h:274
DtEntityIdentifier myEntityId
Definition: entityStateComponent.h:80
#define UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(Type, Member, Set)
Definition: doubleBufferedDataStorage.h:53
virtual void aboutToBeDeleted()
unsigned long long SimStateID
Definition: entityStateComponent.h:27
LOM::ReadEntityRepository myReadEntityStateRepository
Definition: entityStateComponent.h:273
virtual const DtFrameStateInterface * currentFrameState() const override
Definition: entityStateComponent.h:299
UInt32 myUUIDColumn
Definition: entityStateComponent.h:121
virtual void updateStateData(DtStateData *sd) override
Implement to update data storage to the new state data.
Definition: entityStateComponent.h:305
#define UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(Type, Member, Set)
Definition: doubleBufferedDataStorage.h:57
LOM::WriteEntityRepository myWriteEntityStateRepository
Definition: entityStateComponent.h:335
#define DEFINE_ACCESSOR_MUTATOR(ReturnType, Accessor, Mutator)
Definition: doubleBufferedDataStorage.h:23
DtEntityStateComponentData myData
Definition: entityStateComponent.h:201
DtStateComponentCreator< DtEntityStateComponentImplementation > DtEntityStateComponentCreator
5) Define the creator. This will need to be registered with the REGISTER_STATE_COMPONENT macro in the...
Definition: entityStateComponent.h:340
DtEntityStateComponentData myData
Definition: entityStateComponent.h:285
DtEntityStateComponentCurrentFrame myCurrentFrameState
Definition: entityStateComponent.h:333
DtString myCallsign
Definition: entityStateComponent.h:79
virtual DtFrameStateInterface * nextFrameState() override
Definition: entityStateComponent.h:300
DtSimulationAddress mySimEngineAddress
Definition: entityStateComponent.h:86
#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
DtUUID myUUID
Definition: entityStateComponent.h:81
DtEntityStateComponentData & frameState()
Definition: entityStateComponent.h:135
int myDamageState
Definition: entityStateComponent.h:277
DtEntityStateComponentData & operator=(const DtEntityStateComponentData &rhs)
Definition: entityStateComponent.h:49
unsigned long long myUserData
Definition: entityStateComponent.h:83
virtual const DtFrameStateInterface * nextFrameState() const override
Definition: entityStateComponent.h:301
bool myIsLocal
Definition: entityStateComponent.h:82
DtUUID mySuperior
Definition: entityStateComponent.h:200
This is a simple base class that will be used to return a pointer to current or next frame state...
Definition: stateComponent.h:294
tbb::spin_rw_mutex myAttachmentsMutex
Definition: entityStateComponent.h:282
const DtEntityType entityType() const
Definition: entityStateComponent.h:164
This class holds the state data that represents each simulation object in the system.
Definition: stateDataManager.h:73

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)