Atoms Crowd  7.0.0
AgentsSimulation.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/AgentGroup.h>
12 #include <Atoms/SimulationEvent.h>
13 #include <Atoms/Physx/AtomsPhysx.h>
14 #include <vector>
15 #include <mutex>
16 
17 namespace Atoms
18 {
20 
23  class ATOMS_EXPORT AgentsSimulation
24  {
25  public:
26 
29 
32 
34 
37 
39 
41  void initFrame();
42 
44 
46  void computeFrame();
47 
49 
51  void endFrame();
52 
54 
56  void endSimulation();
57 
59 
62 
63  // Dynamics
64  void initDynamics(double scale = 1.0, bool debug = false);
65 
67 
70 
72 
75  void addAgentGroup(AtomsPtr<AgentGroup>& aGroup);
76 
78 
81  AtomsPtr<AgentGroup> agentGroup(unsigned int i);
82 
84  unsigned int numAgentGroups();
85 
87  void agentGroupsByTag(const std::string& tag, std::vector<AgentGroup*>& groups);
88 
90 
93  void removeAgentGroup(AtomsPtr<AgentGroup>& aGroup);
94 
96  std::vector<std::string> agentGroupNames() const;
97 
99 
102  void addSimulationEvent(AtomsPtr<SimulationEvent>& simEvent, bool replace=true);
103 
105 
108  void addAnimationClipEvent(AtomsPtr<SimulationEvent>& simEvent, bool replace = true);
109 
111 
114  void addAgentTypeEvent(AtomsPtr<SimulationEvent>& simEvent, bool replace = true);
115 
117 
120  void removeSimulationEvent(AtomsPtr<SimulationEvent>& simEvent);
121 
123 
126  void removeSimulationEvent(const std::string& name);
127 
129  void moveSimulationEvent(AtomsPtr<SimulationEvent>& simEvent, unsigned int position, short type = SimulationEvent::kNative | SimulationEvent::kScript);
130 
132  void moveSimulationEvent(const std::string& name, unsigned int position, short type = SimulationEvent::kNative | SimulationEvent::kScript);
133 
135  std::vector<std::string> simulationEventNames(short type = SimulationEvent::kAll) const;
136 
138  std::vector<std::string> animationClipEventNames(short type = SimulationEvent::kAnimClipNative | SimulationEvent::kAnimClipScript) const;
139 
141  std::vector<std::string> agentTypeEventNames(short type = SimulationEvent::kAgentTypeNative | SimulationEvent::kAgentTypeScript) const;
142 
144  AtomsPtr<SimulationEvent> simulationEvent(const std::string& name);
145 
147  void clear();
148 #ifndef ATOMS_UNREAL
151 #endif
153  void setDynamicEnabled(bool value);
154 
156  bool isDynamicEnabled() const;
157 
158  private:
159 
160  std::vector<AtomsPtr<AgentGroup>> m_agentGroups;
161 
162  std::vector<AtomsPtr<AgentGroup>> m_agentGroupsOrder;
163 
164  std::list<AtomsPtr<SimulationEvent>> m_events;
165 
166 #ifndef ATOMS_UNREAL
168  AtomsPhysx m_physx;
169 #endif
171  mutable std::recursive_mutex m_mutex;
172 
173  bool m_dynamicEnabled;
174 
175  bool m_status;
176  };
177 }
Agent simulation.
Definition: AgentsSimulation.h:24
void addAgentTypeEvent(AtomsPtr< SimulationEvent > &simEvent, bool replace=true)
Adds a simulation event.
std::vector< std::string > agentGroupNames() const
Gets all agent group names.
unsigned int numAgentGroups()
Get number of agent groups.
std::vector< std::string > agentTypeEventNames(short type=SimulationEvent::kAgentTypeNative|SimulationEvent::kAgentTypeScript) const
Gets all agent type events.
std::vector< std::string > animationClipEventNames(short type=SimulationEvent::kAnimClipNative|SimulationEvent::kAnimClipScript) const
Gets all animation clip events.
void resetSimulation()
Reset simulation.
AgentsSimulation()
Constructor.
void endFrame()
End frame.
void setDynamicEnabled(bool value)
Enable or disable physx solver.
void endSimulation()
End simulation.
void addSimulationEvent(AtomsPtr< SimulationEvent > &simEvent, bool replace=true)
Adds a simulation event.
void computeFrame()
Compute frame.
void initSimulation()
Init simulation.
~AgentsSimulation()
Destructor.
void addAnimationClipEvent(AtomsPtr< SimulationEvent > &simEvent, bool replace=true)
Adds a simulation event.
std::vector< std::string > simulationEventNames(short type=SimulationEvent::kAll) const
Gets all simulation events.
AtomsPtr< AgentGroup > agentGroup(unsigned int i)
Gets an agent group.
void agentGroupsByTag(const std::string &tag, std::vector< AgentGroup * > &groups)
Fill the groups vector with all the agent group that have the tag name.
void initFrame()
Init Frame.
void computeDynamics()
Compute dynamics.
void removeSimulationEvent(AtomsPtr< SimulationEvent > &simEvent)
Removes a simulation event.
void removeAgentGroup(AtomsPtr< AgentGroup > &aGroup)
Removes an agent group.
void moveSimulationEvent(const std::string &name, unsigned int position, short type=SimulationEvent::kNative|SimulationEvent::kScript)
Moves the simulation event.
void moveSimulationEvent(AtomsPtr< SimulationEvent > &simEvent, unsigned int position, short type=SimulationEvent::kNative|SimulationEvent::kScript)
Moves the simulation event.
bool isDynamicEnabled() const
Return if the physx solver is enabled.
void addAgentGroup(AtomsPtr< AgentGroup > &aGroup)
Adds an agent group.
void clear()
Remove all the events and agent groups from this simulation.
AtomsPtr< SimulationEvent > simulationEvent(const std::string &name)
Gets the simulation event with the given name.
void removeSimulationEvent(const std::string &name)
Removes a simulation event.
AtomsPhysx & physx()
Return the physx object.
Definition: AtomsPhysx.h:40
Atoms namespace.
Definition: Agent.h:29