Atoms Crowd  7.0.0
Agent.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <Atoms/Globals.h>
11 #include <Atoms/AgentType.h>
12 #include <AtomsCore/Pose.h>
13 #include <AtomsCore/Metadata/MapMetadata.h>
14 #include <AtomsCore/Metadata/Vector3Metadata.h>
15 #include <AtomsCore/Metadata/IntMetadata.h>
16 #include <AtomsCore/Metadata/BoolMetadata.h>
17 #include <AtomsCore/Metadata/DoubleMetadata.h>
18 #include <AtomsCore/Metadata/StringMetadata.h>
19 #include <AtomsCore/Metadata/MatrixArrayMetadata.h>
20 #include <AtomsCore/Metadata/QuaternionMetadata.h>
21 #include <AtomsCore/Metadata/FloatArrayMetadata.h>
22 #include <AtomsCore/Metadata/Vector3ArrayMetadata.h>
23 #include <AtomsCore/Serialiser.h>
24 #include <Atoms/Graph/AgentBehaviourNetwork.h>
25 #include <Atoms/ContextSteering.h>
26 #include <mutex>
27 
28 namespace Atoms
29 {
31  {
32 
33  };
34 
36  class AgentsPool;
37 
39 
43  class ATOMS_EXPORT Agent
44  {
45  public:
46 
48  ~Agent();
49 
51 
54  inline const AgentTypeCPtr& agentType() const;
55 
57 
60  void setAgentType(AgentTypeCPtr agentType);
61 
63 
66  inline AtomsCore::Pose& pose();
67 
69 
72  inline const AtomsCore::Pose& pose() const;
73 
75  inline void setPose(const AtomsCore::Pose& value);
76 
78 
82  void computePose(double simTime = 0.0);
83 
85 
88  inline AtomsCore::MapMetadata& metadata();
89 
91 
94  inline const AtomsCore::MapMetadata& metadata() const;
95 
97  inline void setMetadata(const AtomsCore::MapMetadata& value);
98 
100  /*
101  \return The agent behaviour network
102  */
103  inline AgentBehaviourNetwork& network();
104 
106  size_t memSize() const;
107 
110 
113 
115  /*
116  \return The agent bounding box
117  */
118  inline AtomsCore::Box3 boundingBox() const;
119 
121  /*
122  \param box The agent bounding box
123  */
124  inline void setBoundingBox(const AtomsCore::Box3& box);
125 
127  inline AtomsCore::Rand48& random();
128 
130  void reset();
131 
133  inline size_t profileTime() const;
134 
136  inline size_t profileThreadId() const;
137 
139  inline void setProfileThreadBatch(size_t value);
140 
142  inline size_t profileThreadBatch() const;
143 
145  void lock();
146 
148  void unlock();
149 
151  std::mutex& mutex();
152 
154  void transform(const AtomsMath::Matrix& transformMatrix, bool affectPosition = true, bool affectDirection = true, bool affectGroundHeight = true);
155 
156  inline ContextSteeringData& contextSteeringData();
157 
158  inline const ContextSteeringData& contextSteeringData() const;
159 
160  inline const bool hasValidContextSteeringData() const;
161 
162  void initializeMetadataPointers();
163 
164  void setNavigationData(AtomsPtr<AgentNavigationData>& data);
165 
166  void removeNavigationData();
167 
168  AtomsPtr<AgentNavigationData>& navigationData();
169 
170  public:
171 
172  AtomsPtr<AtomsCore::IntMetadata>& groupId();
173  AtomsPtr<AtomsCore::StringMetadata>& groupIdStr();
174  AtomsPtr<AtomsCore::IntMetadata>& id();
175  AtomsPtr<AtomsCore::Vector3Metadata>& position();
176  AtomsPtr<AtomsCore::Vector3Metadata>& scale();
177  AtomsPtr<AtomsCore::QuaternionMetadata>& rotation();
178  AtomsPtr<AtomsCore::Vector3Metadata>& direction();
179  AtomsPtr<AtomsCore::Vector3Metadata>& prevDirection();
180  AtomsPtr<AtomsCore::Vector3Metadata>& up();
181  AtomsPtr<AtomsCore::Vector3Metadata>& velocity();
182  AtomsPtr<AtomsCore::Vector3Metadata>& gravity();
183  AtomsPtr<AtomsCore::DoubleMetadata>& birth();
184  AtomsPtr<AtomsCore::IntMetadata>& state();
185  AtomsPtr<AtomsCore::IntMetadata>& currentState();
186  AtomsPtr<AtomsCore::IntMetadata>& active();
187  AtomsPtr<AtomsCore::DoubleMetadata>& frameRate();
188  AtomsPtr<AtomsCore::DoubleMetadata>& frameRateOverride();
189  AtomsPtr<AtomsCore::BoolMetadata>& disableIk();
190  AtomsPtr<AtomsCore::BoolMetadata>& disableFootLock();
191  AtomsPtr<AtomsCore::IntMetadata>& syncLevel();
192  AtomsPtr<AtomsCore::IntMetadata>& animationMode();
193  AtomsPtr<AtomsCore::Metadata>& animState();
194  AtomsPtr<AtomsCore::BoolMetadata>& forceClipTransition();
195  AtomsPtr<AtomsCore::BoolMetadata>& visible();
196  AtomsPtr<AtomsCore::DoubleMetadata>& linearVelocity();
197  AtomsPtr<AtomsCore::DoubleMetadata>& angularVelocity();
198  AtomsPtr<AtomsCore::DoubleMetadata>& frameAngularVelocity();
199  AtomsPtr<AtomsCore::BoolMetadata>& locomotionActive();
200  AtomsPtr<AtomsCore::Vector3Metadata>& velocityOverride();
201  AtomsPtr<AtomsCore::BoolMetadata>& useVelocityOverride();
202 #ifdef ATOMS_UNREAL
203  AtomsPtr<AtomsCore::IntMetadata>& _atypeid();
204  AtomsPtr<AtomsCore::BoolMetadata>& _culled();
205  AtomsPtr<AtomsCore::MatrixArrayMetadata>& _wm();
206  AtomsPtr<AtomsCore::DoubleMetadata>& maxSimDistance(double defaultValue);
207  AtomsPtr<AtomsCore::FloatArrayMetadata>& perInstanceMetadata();
208 #endif
209  AtomsPtr<AtomsCore::IntMetadata>& minLod();
210  AtomsPtr<AtomsCore::Vector3Metadata>& _navtp();
211  AtomsPtr<AtomsCore::Vector3ArrayMetadata>& _navfp();
212  AtomsPtr<AtomsCore::Vector3Metadata>& previousPos();
213 
214  AtomsPtr<const AtomsCore::IntMetadata> groupId() const;
215  AtomsPtr<const AtomsCore::StringMetadata> groupIdStr() const;
216  AtomsPtr<const AtomsCore::IntMetadata> id() const;
217  AtomsPtr<const AtomsCore::Vector3Metadata> position() const;
218  AtomsPtr<const AtomsCore::Vector3Metadata> scale() const;
219  AtomsPtr<const AtomsCore::QuaternionMetadata> rotation() const;
220  AtomsPtr<const AtomsCore::Vector3Metadata> direction() const;
221  AtomsPtr<const AtomsCore::Vector3Metadata> prevDirection() const;
222  AtomsPtr<const AtomsCore::Vector3Metadata> up() const;
223  AtomsPtr<const AtomsCore::Vector3Metadata> velocity() const;
224  AtomsPtr<const AtomsCore::Vector3Metadata> gravity() const;
225  AtomsPtr<const AtomsCore::DoubleMetadata> birth() const;
226  AtomsPtr<const AtomsCore::IntMetadata> state() const;
227  AtomsPtr<const AtomsCore::IntMetadata> currentState() const;
228  AtomsPtr<const AtomsCore::IntMetadata> active() const;
229  AtomsPtr<const AtomsCore::DoubleMetadata> frameRate() const;
230  AtomsPtr<const AtomsCore::DoubleMetadata> frameRateOverride() const;
231  AtomsPtr<const AtomsCore::BoolMetadata> disableIk() const;
232  AtomsPtr<const AtomsCore::BoolMetadata> disableFootLock() const;
233  AtomsPtr<const AtomsCore::IntMetadata> syncLevel() const;
234  AtomsPtr<const AtomsCore::IntMetadata> animationMode() const;
235  AtomsPtr<const AtomsCore::Metadata> animState() const;
236  AtomsPtr<const AtomsCore::BoolMetadata> forceClipTransition() const;
237  AtomsPtr<const AtomsCore::BoolMetadata> visible() const;
238  AtomsPtr<const AtomsCore::DoubleMetadata> linearVelocity() const;
239  AtomsPtr<const AtomsCore::DoubleMetadata> angularVelocity() const;
240  AtomsPtr<const AtomsCore::DoubleMetadata> frameAngularVelocity() const;
241  AtomsPtr<const AtomsCore::BoolMetadata> locomotionActive() const;
242  AtomsPtr<const AtomsCore::Vector3Metadata> velocityOverride() const;
243  AtomsPtr<const AtomsCore::BoolMetadata> useVelocityOverride() const;
244  AtomsPtr<const AtomsCore::Vector3Metadata> _navtp() const;
245  AtomsPtr<const AtomsCore::Vector3ArrayMetadata> _navfp() const;
246 
247  private:
248 
249  AtomsPtr<AtomsCore::IntMetadata> m_groupIdPtr;
250  AtomsPtr<AtomsCore::StringMetadata> m_groupIdStrPtr;
251  AtomsPtr<AtomsCore::IntMetadata> m_idPtr;
252  AtomsPtr<AtomsCore::Vector3Metadata> m_positionPtr;
253  AtomsPtr<AtomsCore::Vector3Metadata> m_scalePtr;
254  AtomsPtr<AtomsCore::QuaternionMetadata> m_rotationPtr;
255  AtomsPtr<AtomsCore::Vector3Metadata> m_directionPtr;
256  AtomsPtr<AtomsCore::Vector3Metadata> m_prevDirectionPtr;
257  AtomsPtr<AtomsCore::Vector3Metadata> m_upPtr;
258  AtomsPtr<AtomsCore::Vector3Metadata> m_velocityPtr;
259  AtomsPtr<AtomsCore::Vector3Metadata> m_gravityPtr;
260  AtomsPtr<AtomsCore::DoubleMetadata> m_birthPtr;
261  AtomsPtr<AtomsCore::IntMetadata> m_statePtr;
262  AtomsPtr<AtomsCore::IntMetadata> m_currentStatePtr;
263  AtomsPtr<AtomsCore::IntMetadata> m_activePtr;
264  AtomsPtr<AtomsCore::DoubleMetadata> m_frameRatePtr;
265  AtomsPtr<AtomsCore::DoubleMetadata> m_frameRateOverridePtr;
266  AtomsPtr<AtomsCore::BoolMetadata> m_disableIkPtr;
267  AtomsPtr<AtomsCore::BoolMetadata> m_disableFootLockPtr;
268  AtomsPtr<AtomsCore::IntMetadata> m_syncLevelPtr;
269  AtomsPtr<AtomsCore::IntMetadata> m_animationModePtr;
270  AtomsPtr<AtomsCore::Metadata> m_animStatePtr;
271  AtomsPtr<AtomsCore::BoolMetadata> m_forceClipTransitionPtr;
272  AtomsPtr<AtomsCore::BoolMetadata> m_visiblePtr;
273  AtomsPtr<AtomsCore::DoubleMetadata> m_linearVelocityPtr;
274  AtomsPtr<AtomsCore::DoubleMetadata> m_angularVelocityPtr;
275  AtomsPtr<AtomsCore::DoubleMetadata> m_frameAngularVelocity;
276  AtomsPtr<AtomsCore::BoolMetadata> m_locomotionActivePtr;
277  AtomsPtr<AtomsCore::Vector3Metadata> m_velocityOverridePtr;
278  AtomsPtr<AtomsCore::BoolMetadata> m_useVelocityOverridePtr;
279 #ifdef ATOMS_UNREAL
280  AtomsPtr<AtomsCore::IntMetadata> m_atypeidPtr;
281  AtomsPtr<AtomsCore::BoolMetadata> m_culledPtr;
282  AtomsPtr<AtomsCore::MatrixArrayMetadata> m_wmPtr;
283  AtomsPtr<AtomsCore::DoubleMetadata> m_maxSimDistancePtr;
284  AtomsPtr<AtomsCore::FloatArrayMetadata> m_perInstanceMetadata;
285 #endif
286  AtomsPtr<AtomsCore::IntMetadata> m_minLod;
287  AtomsPtr<AtomsCore::Vector3Metadata> m_navtpPtr;
288  AtomsPtr<AtomsCore::Vector3ArrayMetadata> m_navfpPtr;
289  AtomsPtr<AgentNavigationData> m_navData;
290  AtomsPtr<AtomsCore::Vector3Metadata> m_previousPosPtr;
291 
292  private:
293 
295 
299  explicit Agent(AgentTypeCPtr agentType = nullptr);
300 
302  Agent(const Agent&);
303 
305  Agent& operator=(const Agent&);
306 
308  AgentBehaviourNetwork m_network;
309 
311  AtomsCore::Pose m_pose;
312 
314  AtomsCore::MapMetadata m_metadata;
315 
317  AgentTypeCPtr m_agentType;
318 
320  AtomsCore::Box3 m_boundingBox;
321 
323  AtomsCore::Rand48 m_random;
324 
326  size_t m_profileTime;
327 
329  size_t m_profileThreadId;
330 
332  size_t m_profileThreadBatch;
333 
334  std::mutex m_mutex;
335 
336  std::unique_ptr<ContextSteeringData> m_contextSteering;
337 
338  friend class AgentsPool;
339 
340  };
341 }
342 
343 namespace AtomsCore
344 {
345  ATOMS_EXPORT AtomsCore::Archive& operator<<(AtomsCore::Archive& os, const Atoms::Agent& agent);
346 
347  ATOMS_EXPORT AtomsCore::Archive& operator >> (AtomsCore::Archive& is, Atoms::Agent& agent);
348 }
349 #include "Agent.impl.h"
Agent behaviour network.
Definition: AgentBehaviourNetwork.h:29
Agent.
Definition: Agent.h:44
~Agent()
Destructor.
void computeBoundingBox()
Computes the agent bounding box.
void computeMeshBoundingBox()
Compute the bounding box using the skinned meshes.
void lock()
lock the agent mutex
void reset()
Reset the agent.
size_t memSize() const
Gets the memory size of this agent.
void transform(const AtomsMath::Matrix &transformMatrix, bool affectPosition=true, bool affectDirection=true, bool affectGroundHeight=true)
Transform the agent by the given matrix.
void unlock()
unlock the agent mutex
std::mutex & mutex()
Agent mutex.
void setAgentType(AgentTypeCPtr agentType)
Sets the agent type.
void computePose(double simTime=0.0)
Computes the agent pose.
Definition: Agent.h:31
Agents pool.
Definition: AgentsPool.h:24
Definition: ContextSteering.h:16
Archive class.
Definition: Serialiser.h:29
MapMetadata class.
Definition: MapMetadata.h:24
Pose class.
Definition: Pose.h:32
AtomsCore namespace.
Definition: Agent.h:344
AtomsMath::Box3 Box3
Bounding box class.
Definition: AtomsMath.h:74
Atoms namespace.
Definition: Agent.h:29
AtomsPtr< const AgentType > AgentTypeCPtr
Agent type const pointer.
Definition: AgentType.h:21