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  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  , myIsClutterEntityColumn(0xFFFFFFFF)
79  {
80  }
81 
82  UNDEFINED_RETURNVALUE_ACCESSOR_MUTATOR(bool, isClutterEntity, IsClutterEntity)
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  mutable boost::signals2::signal<void(bool oldIsClutter, bool newIsClutter)> signal_isClutterChanged;
96 
97  protected:
100  };
101 
103  template <typename T_BaseComponent>
105  {
106  public:
109 
111  const DtEntityStateComponentData& frameState() const { return this->myData; };
112  DtEntityStateComponentData& frameState() { return this->myData; };
113 
114  const bool& isLocal() const;
115  void setIsLocal(const bool&);
116 
117  const DtString& globalId() const;
118  void setGlobalId(const DtString&);
119 
120  const DtUUID& uuid() const;
121  void setUUID(const DtUUID&);
122 
123  const bool isClutterEntity() const;
124  void setIsClutterEntity(const bool&);
125 
126  const DtString& markingText() const;
127  void setMarkingText(const DtString&);
128 
129  const DtForceType forceType() const;
130  void setForceType(const DtForceType&);
131 
132  const UInt32 appearanceBits() const;
133  void setAppearanceBits(const UInt32&);
134 
135  const DtEntityType entityType() const { return DtEntityType(objectType()); };
136  const DtObjectType objectType() const;
137  void setEntityType(const DtObjectType&);
138  void setEntityType(const DtEntityType& t) { setEntityType(DtObjectType(t.kind() == 11 ? 3 : 1, t)); };
139 
140  const DtEntityIdentifier& entityId() const;
141  void setEntityId(const DtEntityIdentifier&);
142 
143  const UInt32 capabilities() const;
144  void setCapabilities(const UInt32&);
145 
146  const DtEntityType guise() const;
147  void setGuise(const DtEntityType&);
148 
150  const DtUUID& superior() const;
151  void setSuperior(const DtUUID&);
152 
153  virtual void setAppearance(const DtAppearance& app);
154 
156  virtual void makeWritable();
157 
159  virtual void makeReadOnly();
160 
161  protected:
162  LOM::WriteEntityRepository myWriteEntityStateRepository;
166  };
167 
169 
171  template <typename T_BaseComponent>
173  {
174  public:
177 
179  const DtEntityStateComponentData& frameState() const { return this->myData; };
180 
181  const bool& isLocal() const;
182  const DtString& globalId() const;
183  const DtUUID& uuid() const;
184  const DtString& markingText() const;
185  const DtForceType forceType() const;
186  const DtEntityType entityType() const { return DtEntityType(objectType()); };
187  const DtObjectType objectType() const;
188  const DtEntityIdentifier& entityId() const;
189  const UInt32 appearanceBits() const;
190  const bool isClutterEntity() const;
191  const UInt32 capabilities() const;
192  const DtEntityType guise() const;
193 
194  const DtUUID& superior() const;
195 
199  void addAttachment(const DtUUID&);
200  void removeAttachment(const DtUUID&);
201  const std::set<DtUUID> attachments() const;
203 
204  bool checkForUpdatedItems();
205 
206  protected:
207  const DtUUID _uuid() const;
208  const DtString _markingText() const;
209  const DtEntityIdentifier _entityId() const;
210 
211  bool checkEntityIdChanged();
212  bool checkUUIDChanged();
213  bool checkForceChanged();
214  bool checkMarkingTextChanged();
215  bool checkDamageStateChanged();
216  bool checkIsClutterChanged();
217 
218  void handleDataUpdated(const std::vector<UInt32>& attributesUpdated);
219  void completeSetup();
220 
223  {
224  this->myData = data;
225  }
226 
227  protected:
228  friend class DtStateDataManager;
229  void setSuperior(const DtUUID&);
230 
231  protected:
232  LOM::ReadEntityRepository myReadEntityStateRepository;
237  unsigned int myCallbackHandle;
239 
240  std::set<DtUUID> myAttachments;
241  mutable tbb::spin_rw_mutex myAttachmentsMutex;
242  boost::signals2::scoped_connection myCompleteSetupConnection;
243  tbb::spin_mutex myCompleteSetupMutex;
245  };
246 
248 
252  {
253  public:
256 
257  bool isDoubleBuffered() { return true; };
258  const DtFrameStateInterface* currentFrameState() const { return &myCurrentFrameState; }
259  virtual DtFrameStateInterface* nextFrameState() { return &myNextFrameState; };
260  virtual const DtFrameStateInterface* nextFrameState() const { return &myNextFrameState; };
261 
262  void updateDataStorage();
263 
265  {
266  myCurrentFrameState.updateStateData(sd);
267  myNextFrameState.updateStateData(sd);
268  }
269 
270  static void addAdditionalTableColumns(Legion::SimulationDatabase*);
271 
272  virtual void initializeFromParameters(const DtVrfObjectParameters* params);
273 
274  Legion::WriteStateInstance writeStateInstance() override { return myWriteEntityStateRepository; };
275 
277  virtual void convertToRemote();
278 
280  virtual void convertToLocal();
281 
282  virtual void addAdditionalStateComponents() override;
283 
284  virtual void aboutToBeDeleted() override
285  {
287  myCurrentFrameState.aboutToBeDeleted();
288  myNextFrameState.aboutToBeDeleted();
289  }
290 
291  protected:
294  LOM::WriteEntityRepository myWriteEntityStateRepository;
295  };
296 
300 }
301 
302 #define _ENTITY_STATE_COMPONENT 1
303 #include "vrfStateData/entityStateComponent.inl"
2) Define the next frame class. This will be used for write access.
Definition: entityStateComponent.h:104
UUID is a unique ID wrapper class.
Definition: uuid.h:59
boost::signals2::signal< void(const DtFrameStateInterface *)> signal_attachmentsChanged
Definition: entityStateComponent.h:93
unsigned int myCallbackHandle
Definition: entityStateComponent.h:237
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:162
const DtEntityType entityType() const
Definition: entityStateComponent.h:186
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:111
Definition: stateDataTypes.h:23
DtString myMarkingText
Definition: entityStateComponent.h:62
tbb::spin_mutex myCompleteSetupMutex
Definition: entityStateComponent.h:243
DtEntityStateComponentCurrentFrameTemplate< DtEntityStateComponent > DtEntityStateComponentCurrentFrame
Definition: entityStateComponent.h:247
bool myIsClutterEntity
Definition: entityStateComponent.h:238
int myForceId
Definition: entityStateComponent.h:235
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 current frames...
Definition: entityStateComponent.h:70
DtStateData * myStateData
Definition: entityStateComponent.h:233
Definition: stateComponent.h:266
The DtSimulatedObjectStateComponent is an interface that all main components (those that are consider...
Definition: simulatedObjectStateComponent.h:21
UInt32 myIsClutterEntityColumn
Definition: entityStateComponent.h:99
DtEntityStateComponentData(const DtEntityStateComponentData &orig)
Definition: entityStateComponent.h:34
bool isDoubleBuffered()
Definition: entityStateComponent.h:257
boost::signals2::scoped_connection myCompleteSetupConnection
Definition: entityStateComponent.h:242
boost::signals2::signal< void(const DtUUID &oldSuperior, const DtUUID &newSuperior)> signal_superiorChanged
Definition: entityStateComponent.h:94
boost::signals2::signal< void(bool oldIsClutter, bool newIsClutter)> signal_isClutterChanged
Definition: entityStateComponent.h:95
virtual const DtFrameStateInterface * nextFrameState() const
Definition: entityStateComponent.h:260
const DtEntityStateComponentData & frameState() const
Current frame state only can access current frame buffers. This ensures thread safety.
Definition: entityStateComponent.h:179
void updateStateData(DtStateData *sd)
Implement to update data storage to the new state data.
Definition: entityStateComponent.h:264
Definition: entityStateComponent.h:25
void advanceFrame(const DtEntityStateComponentData &data)
Definition: entityStateComponent.h:222
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:251
std::set< DtUUID > myAttachments
Definition: entityStateComponent.h:240
virtual void aboutToBeDeleted() override
Definition: entityStateComponent.h:284
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:339
DtEntityStateComponentData()
Definition: entityStateComponent.h:29
#define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent)
Definition: stateComponent.h:228
3) Define the current frame class. This will be used for read access.
Definition: entityStateComponent.h:172
DtString myGlobalId
Definition: entityStateComponent.h:61
DtEntityStateComponentNextFrame myNextFrameState
Definition: entityStateComponent.h:293
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:379
DtUUID mySuperior
Definition: entityStateComponent.h:234
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:232
UInt32 myUUIDColumn
Definition: entityStateComponent.h:98
#define UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(Type, Member, Set)
Definition: doubleBufferedDataStorage.h:57
LOM::WriteEntityRepository myWriteEntityStateRepository
Definition: entityStateComponent.h:294
#define DEFINE_ACCESSOR_MUTATOR(ReturnType, Accessor, Mutator)
Definition: doubleBufferedDataStorage.h:23
DtEntityStateComponentData myData
Definition: entityStateComponent.h:165
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:299
DtEntityStateComponentData myData
Definition: entityStateComponent.h:244
DtEntityStateComponentCurrentFrame myCurrentFrameState
Definition: entityStateComponent.h:292
DtEntityStateComponentNextFrameTemplate< DtEntityStateComponent > DtEntityStateComponentNextFrame
Definition: entityStateComponent.h:168
Legion::WriteStateInstance writeStateInstance() override
Definition: entityStateComponent.h:274
#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:112
virtual void setEntityType(const DtObjectType &ot)
Definition: entityStateComponent.h:88
void setEntityType(const DtEntityType &t)
Definition: entityStateComponent.h:138
DtStateData * myStateData
Definition: entityStateComponent.h:163
int myDamageState
Definition: entityStateComponent.h:236
DtEntityStateComponentData & operator=(const DtEntityStateComponentData &rhs)
Definition: entityStateComponent.h:43
virtual DtFrameStateInterface * nextFrameState()
Definition: entityStateComponent.h:259
bool myIsLocal
Definition: entityStateComponent.h:65
const DtFrameStateInterface * currentFrameState() const
Definition: entityStateComponent.h:258
DtUUID mySuperior
Definition: entityStateComponent.h:164
This is a simple base class that will be used to return a pointer to current or next frame state...
Definition: stateComponent.h:291
tbb::spin_rw_mutex myAttachmentsMutex
Definition: entityStateComponent.h:241
const DtEntityType entityType() const
Definition: entityStateComponent.h:135
This class holds the state data that represents each simulation object in the system.
Definition: stateDataManager.h:73

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)