VR-Forces 5.0.2 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  typedef unsigned long long SimStateID;
28 
30  : myUUID(DtUUID::nullUUID())
31  , myIsLocal(false)
32  {};
33 
35  : myGlobalId(orig.myGlobalId)
36  , myUUID(orig.myUUID)
37  , myMarkingText(orig.myMarkingText)
38  , myEntityId(orig.myEntityId)
39  , myIsLocal(orig.myIsLocal)
40  {
41  }
42 
44  {
45  myGlobalId = rhs.myGlobalId;
46  myUUID = rhs.myUUID;
47  myEntityId = rhs.myEntityId;
48  myMarkingText = rhs.myMarkingText;
49  myIsLocal = rhs.myIsLocal;
50 
51  return *this;
52  }
53 
54  DEFINE_ACCESSOR_MUTATOR(DtString, globalId, GlobalId)
55  DEFINE_ACCESSOR_MUTATOR(DtEntityIdentifier, entityId, EntityId)
56  DEFINE_ACCESSOR_MUTATOR(DtUUID, uuid, UUID)
57  DEFINE_ACCESSOR_MUTATOR(DtString, markingText, MarkingText)
58  DEFINE_ACCESSOR_MUTATOR(bool, isLocal, IsLocal)
59 
60  protected:
61  DtString myGlobalId;
62  DtString myMarkingText;
63  DtEntityIdentifier myEntityId;
64  DtUUID myUUID;
65  bool myIsLocal;
66  };
67 
71  {
72  public:
74 
76  : DtSimulatedObjectStateComponent(storage)
77  , myUUIDColumn(0xFFFFFFFF)
78  , myIsBackgroundEntityColumn(0xFFFFFFFF)
79  {
80  }
81 
82  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(bool, isBackgroundEntity, IsBackgroundEntity)
83  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(UInt32, capabilities, Capabilities)
84  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(DtEntityType, guise, Guise)
85  UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(DtUUID, superior, Superior)
86 
87  virtual const std::set<DtUUID> attachments() const { throw DtUnimplementedMethod("std::set<DtUUID> attachments() is not implemented for this class."); };
88  virtual void setEntityType(const DtObjectType& ot) { throw DtUnimplementedMethod("void setEntityType(const DtObjectType& ot) is not implemented for this class."); };
89  virtual void addAttachment(const DtUUID&) { throw DtUnimplementedMethod("void addAttachment(const DtUUID&) is not implemented for this class."); };
90  virtual void removeAttachment(const DtUUID&) { throw DtUnimplementedMethod("void removeAttachment(const DtUUID&) is not implemented for this class."); };
91 
92  mutable boost::signals2::signal<void (int oldState, int newState, makVrf::SimStateID)> signal_damageStateChanged;
93  mutable boost::signals2::signal<void (const DtFrameStateInterface*)> signal_attachmentsChanged;
94  mutable boost::signals2::signal<void (const DtUUID& oldSuperior, const DtUUID& newSuperior)> signal_superiorChanged;
95 
96  protected:
99  };
100 
102  template <typename T_BaseComponent>
104  {
105  public:
108 
110  const DtEntityStateComponentData& frameState() const { return this->myData; };
111  DtEntityStateComponentData& frameState() { return this->myData; };
112 
113  const bool& isLocal() const;
114  void setIsLocal(const bool&);
115 
116  const DtString& globalId() const;
117  void setGlobalId(const DtString&);
118 
119  const DtUUID& uuid() const;
120  void setUUID(const DtUUID&);
121 
122  const bool isBackgroundEntity() const;
123  void setIsBackgroundEntity(const bool&);
124 
125  const DtString& markingText() const;
126  void setMarkingText(const DtString&);
127 
128  const DtForceType forceType() const;
129  void setForceType(const DtForceType&);
130 
131  const UInt32 appearanceBits() const;
132  void setAppearanceBits(const UInt32&);
133 
134  const DtEntityType entityType() const { return DtEntityType(objectType()); };
135  const DtObjectType objectType() const;
136  void setEntityType(const DtObjectType&);
137  void setEntityType(const DtEntityType& t) { setEntityType(DtObjectType(t.kind() == 11 ? 3 : 1, t)); };
138 
139  const DtEntityIdentifier& entityId() const;
140  void setEntityId(const DtEntityIdentifier&);
141 
142  const UInt32 capabilities() const;
143  void setCapabilities(const UInt32&);
144 
145  const DtEntityType guise() const;
146  void setGuise(const DtEntityType&);
147 
149  const DtUUID& superior() const;
150  void setSuperior(const DtUUID&);
151 
152  virtual void setAppearance(const DtAppearance& app);
153 
155  virtual void makeWritable();
156 
158  virtual void makeReadOnly();
159 
160  protected:
161  LOM::WriteEntityRepository myWriteEntityStateRepository;
165  };
166 
168 
170  template <typename T_BaseComponent>
172  {
173  public:
176 
178  const DtEntityStateComponentData& frameState() const { return this->myData; };
179 
180  const bool& isLocal() const;
181  const DtString& globalId() const;
182  const DtUUID& uuid() const;
183  const DtString& markingText() const;
184  const DtForceType forceType() const;
185  const DtEntityType entityType() const { return DtEntityType(objectType()); };
186  const DtObjectType objectType() const;
187  const DtEntityIdentifier& entityId() const;
188  const UInt32 appearanceBits() const;
189  const bool isBackgroundEntity() const;
190  const UInt32 capabilities() const;
191  const DtEntityType guise() const;
192 
193  const DtUUID& superior() const;
194 
198  void addAttachment(const DtUUID&);
199  void removeAttachment(const DtUUID&);
200  const std::set<DtUUID> attachments() const;
202 
203  bool checkForUpdatedItems();
204 
205  protected:
206  const DtUUID _uuid() const;
207  const DtString _markingText() const;
208  const DtEntityIdentifier _entityId() const;
209 
210  bool checkEntityIdChanged();
211  bool checkUUIDChanged();
212  bool checkForceChanged();
213  bool checkMarkingTextChanged();
214  bool checkDamageStateChanged();
215 
216  void handleDataUpdated(const std::vector<UInt32>& attributesUpdated);
217  void completeSetup();
218 
221  {
222  this->myData = data;
223  }
224 
225  protected:
226  friend class DtStateDataManager;
227  void setSuperior(const DtUUID&);
228 
229  protected:
230  LOM::ReadEntityRepository myReadEntityStateRepository;
235  unsigned int myCallbackHandle;
236 
237  std::set<DtUUID> myAttachments;
238  mutable tbb::spin_rw_mutex myAttachmentsMutex;
239  boost::signals2::scoped_connection myCompleteSetupConnection;
240  tbb::spin_mutex myCompleteSetupMutex;
242  };
243 
245 
249  {
250  public:
253 
254  bool isDoubleBuffered() { return true; };
255  const DtFrameStateInterface* currentFrameState() const { return &myCurrentFrameState; }
256  virtual DtFrameStateInterface* nextFrameState() { return &myNextFrameState; };
257  virtual const DtFrameStateInterface* nextFrameState() const { return &myNextFrameState; };
258 
259  void updateDataStorage();
260 
262  {
263  myCurrentFrameState.updateStateData(sd);
264  myNextFrameState.updateStateData(sd);
265  }
266 
267  static void addAdditionalTableColumns(Legion::SimulationDatabase*);
268 
269  virtual void initializeFromParameters(const DtVrfObjectParameters* params);
270 
271  Legion::WriteStateInstance writeStateInstance() override { return myWriteEntityStateRepository; };
272 
274  virtual void convertToRemote();
275 
277  virtual void convertToLocal();
278 
279  virtual void addAdditionalStateComponents() override;
280 
281  virtual void aboutToBeDeleted() override
282  {
284  myCurrentFrameState.aboutToBeDeleted();
285  myNextFrameState.aboutToBeDeleted();
286  }
287 
288  protected:
291  LOM::WriteEntityRepository myWriteEntityStateRepository;
292  };
293 
297 }
298 
299 #define _ENTITY_STATE_COMPONENT 1
300 #include "vrfStateData/entityStateComponent.inl"
2) Define the next frame class. This will be used for write access.
Definition: entityStateComponent.h:103
UUID is a unique ID wrapper class.
Definition: rwUUID.h:229
boost::signals2::signal< void(const DtFrameStateInterface *)> signal_attachmentsChanged
Definition: entityStateComponent.h:93
unsigned int myCallbackHandle
Definition: entityStateComponent.h:235
Instances of DtVrfObjectParameters are the readable/writeable objects that contain the information ne...
Definition: vrfObjectParameters.h:63
unsigned int UInt32
Definition: stateDataTypes.h:18
LOM::WriteEntityRepository myWriteEntityStateRepository
Definition: entityStateComponent.h:161
const DtEntityType entityType() const
Definition: entityStateComponent.h:185
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:110
Definition: stateDataTypes.h:23
DtString myMarkingText
Definition: entityStateComponent.h:62
tbb::spin_mutex myCompleteSetupMutex
Definition: entityStateComponent.h:240
DtEntityStateComponentCurrentFrameTemplate< DtEntityStateComponent > DtEntityStateComponentCurrentFrame
Definition: entityStateComponent.h:244
int myForceId
Definition: entityStateComponent.h:233
Definition: stateComponent.h:62
virtual void addAttachment(const DtUUID &)
Definition: entityStateComponent.h:89
1) Define the interface class that will be used to represent the next and curent frames. The UNDEFINED_ macros are convenience macros that will define methods that throw exceptions (until they are implemented)
Definition: entityStateComponent.h:70
DtStateData * myStateData
Definition: entityStateComponent.h:231
Definition: stateComponent.h:257
The DtSimulatedObjectStateComponent is an interface that all main components (those that are consider...
Definition: simulatedObjectStateComponent.h:21
DtEntityStateComponentData(const DtEntityStateComponentData &orig)
Definition: entityStateComponent.h:34
bool isDoubleBuffered()
Definition: entityStateComponent.h:254
boost::signals2::signal< void(const DtUUID &oldSuperior, const DtUUID &newSuperior)> signal_superiorChanged
Definition: entityStateComponent.h:94
boost::signals2::scoped_connection myCompleteSetupConnection
Definition: entityStateComponent.h:239
virtual const DtFrameStateInterface * nextFrameState() const
Definition: entityStateComponent.h:257
const DtEntityStateComponentData & frameState() const
Current frame state only can access current frame buffers. This ensures thread safety.
Definition: entityStateComponent.h:178
void updateStateData(DtStateData *sd)
Implement to update data storage to the new state data.
Definition: entityStateComponent.h:261
Definition: entityStateComponent.h:25
void advanceFrame(const DtEntityStateComponentData &data)
Definition: entityStateComponent.h:220
Definition: objectType.h:27
4) Define the state component that will contain the wrappers to the next and current frame states tha...
Definition: entityStateComponent.h:248
std::set< DtUUID > myAttachments
Definition: entityStateComponent.h:237
virtual void aboutToBeDeleted() override
Definition: entityStateComponent.h:281
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:336
DtEntityStateComponentData()
Definition: entityStateComponent.h:29
#define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent)
Definition: stateComponent.h:219
3) Define the current frame class. This will be used for read access.
Definition: entityStateComponent.h:171
DtString myGlobalId
Definition: entityStateComponent.h:61
DtEntityStateComponentNextFrame myNextFrameState
Definition: entityStateComponent.h:290
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:370
DtUUID mySuperior
Definition: entityStateComponent.h:232
DtEntityIdentifier myEntityId
Definition: entityStateComponent.h:63
#define UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(Type, Member, Set)
Definition: doubleBufferedDataStorage.h:53
virtual void aboutToBeDeleted()
LOM::ReadEntityRepository myReadEntityStateRepository
Definition: entityStateComponent.h:230
UInt32 myUUIDColumn
Definition: entityStateComponent.h:97
#define UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(Type, Member, Set)
Definition: doubleBufferedDataStorage.h:57
LOM::WriteEntityRepository myWriteEntityStateRepository
Definition: entityStateComponent.h:291
#define DEFINE_ACCESSOR_MUTATOR(ReturnType, Accessor, Mutator)
Definition: doubleBufferedDataStorage.h:23
DtEntityStateComponentData myData
Definition: entityStateComponent.h:164
unsigned long long SimStateID
Definition: entityStateComponent.h:27
DtStateComponentCreator< DtEntityStateComponentImplementation > DtEntityStateComponentCreator
5) Define the creator. This will need to be registered with the REGISTER_STATE_COMPONENT macro in the...
Definition: entityStateComponent.h:296
DtEntityStateComponentData myData
Definition: entityStateComponent.h:241
DtEntityStateComponentCurrentFrame myCurrentFrameState
Definition: entityStateComponent.h:289
DtEntityStateComponentNextFrameTemplate< DtEntityStateComponent > DtEntityStateComponentNextFrame
Definition: entityStateComponent.h:167
Legion::WriteStateInstance writeStateInstance() override
Definition: entityStateComponent.h:271
#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:64
DtEntityStateComponentData & frameState()
Definition: entityStateComponent.h:111
virtual void setEntityType(const DtObjectType &ot)
Definition: entityStateComponent.h:88
void setEntityType(const DtEntityType &t)
Definition: entityStateComponent.h:137
DtStateData * myStateData
Definition: entityStateComponent.h:162
int myDamageState
Definition: entityStateComponent.h:234
DtEntityStateComponentData & operator=(const DtEntityStateComponentData &rhs)
Definition: entityStateComponent.h:43
virtual DtFrameStateInterface * nextFrameState()
Definition: entityStateComponent.h:256
bool myIsLocal
Definition: entityStateComponent.h:65
const DtFrameStateInterface * currentFrameState() const
Definition: entityStateComponent.h:255
UInt32 myIsBackgroundEntityColumn
Definition: entityStateComponent.h:98
DtUUID mySuperior
Definition: entityStateComponent.h:163
This is a simple base class that will be used to return a pointer to current or next frame state...
Definition: stateComponent.h:282
tbb::spin_rw_mutex myAttachmentsMutex
Definition: entityStateComponent.h:238
const DtEntityType entityType() const
Definition: entityStateComponent.h:134
This class holds the state data that represents each simulation object in the system.
Definition: stateDataManager.h:71

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)