Atoms Crowd  4.1.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 
90  void removeAgentGroup(AtomsPtr<AgentGroup>& aGroup);
91 
93  std::vector<std::string> agentGroupNames() const;
94 
96 
99  void addSimulationEvent(AtomsPtr<SimulationEvent>& simEvent, bool replace=true);
100 
102 
105  void addAnimationClipEvent(AtomsPtr<SimulationEvent>& simEvent, bool replace = true);
106 
108 
111  void addAgentTypeEvent(AtomsPtr<SimulationEvent>& simEvent, bool replace = true);
112 
114 
117  void removeSimulationEvent(AtomsPtr<SimulationEvent>& simEvent);
118 
120 
123  void removeSimulationEvent(const std::string& name);
124 
126  void moveSimulationEvent(AtomsPtr<SimulationEvent>& simEvent, unsigned int position, short type = SimulationEvent::kNative | SimulationEvent::kScript);
127 
129  void moveSimulationEvent(const std::string& name, unsigned int position, short type = SimulationEvent::kNative | SimulationEvent::kScript);
130 
132  std::vector<std::string> simulationEventNames(short type = SimulationEvent::kAll) const;
133 
135  std::vector<std::string> animationClipEventNames(short type = SimulationEvent::kAnimClipNative | SimulationEvent::kAnimClipScript) const;
136 
138  std::vector<std::string> agentTypeEventNames(short type = SimulationEvent::kAgentTypeNative | SimulationEvent::kAgentTypeScript) const;
139 
141  AtomsPtr<SimulationEvent> simulationEvent(const std::string& name);
142 
144  void clear();
145 #ifndef ATOMS_UNREAL
146  AtomsPhysx& physx();
148 #endif
149  void setDynamicEnabled(bool value);
151 
153  bool isDynamicEnabled() const;
154 
155  private:
156 
157  std::vector<AtomsPtr<AgentGroup>> m_agentGroups;
158 
159  std::vector<AtomsPtr<AgentGroup>> m_agentGroupsOrder;
160 
161  std::list<AtomsPtr<SimulationEvent>> m_events;
162 
163 #ifndef ATOMS_UNREAL
164  AtomsPhysx m_physx;
166 #endif
167  mutable std::recursive_mutex m_mutex;
169 
170  bool m_dynamicEnabled;
171 
172  bool m_status;
173  };
174 }
Atoms::AgentsSimulation::clear
void clear()
Remove all the events and agent groups from this simulation.
Atoms::AgentsSimulation::removeSimulationEvent
void removeSimulationEvent(const std::string &name)
Removes a simulation event.
Atoms::AgentsSimulation::simulationEvent
AtomsPtr< SimulationEvent > simulationEvent(const std::string &name)
Gets the simulation event with the given name.
Atoms::AgentsSimulation::resetSimulation
void resetSimulation()
Reset simulation.
Atoms::AgentsSimulation::AgentsSimulation
AgentsSimulation()
Constructor.
Atoms::AgentsSimulation::endSimulation
void endSimulation()
End simulation.
Atoms::AgentsSimulation::agentTypeEventNames
std::vector< std::string > agentTypeEventNames(short type=SimulationEvent::kAgentTypeNative|SimulationEvent::kAgentTypeScript) const
Gets all agent type events.
Atoms::AgentsSimulation::removeSimulationEvent
void removeSimulationEvent(AtomsPtr< SimulationEvent > &simEvent)
Removes a simulation event.
Atoms::AgentsSimulation::numAgentGroups
unsigned int numAgentGroups()
Get number of agent groups.
Atoms::AgentsSimulation
Agent simulation.
Definition: AgentsSimulation.h:24
Atoms::AgentsSimulation::agentGroup
AtomsPtr< AgentGroup > agentGroup(unsigned int i)
Gets an agent group.
Atoms::AgentsSimulation::~AgentsSimulation
~AgentsSimulation()
Destructor.
Atoms::AgentsSimulation::initSimulation
void initSimulation()
Init simulation.
Atoms::AgentsSimulation::agentGroupNames
std::vector< std::string > agentGroupNames() const
Gets all agent group names.
Atoms::AgentsSimulation::computeFrame
void computeFrame()
Compute frame.
Atoms::AgentsSimulation::removeAgentGroup
void removeAgentGroup(AtomsPtr< AgentGroup > &aGroup)
Removes an agent group.
Atoms
Atoms namespace.
Definition: Agent.h:28
Atoms::AgentsSimulation::endFrame
void endFrame()
End frame.
Atoms::AgentsSimulation::moveSimulationEvent
void moveSimulationEvent(AtomsPtr< SimulationEvent > &simEvent, unsigned int position, short type=SimulationEvent::kNative|SimulationEvent::kScript)
Moves the simulation event.
Atoms::AgentsSimulation::addSimulationEvent
void addSimulationEvent(AtomsPtr< SimulationEvent > &simEvent, bool replace=true)
Adds a simulation event.
Atoms::AgentsSimulation::animationClipEventNames
std::vector< std::string > animationClipEventNames(short type=SimulationEvent::kAnimClipNative|SimulationEvent::kAnimClipScript) const
Gets all animation clip events.
Atoms::AgentsSimulation::moveSimulationEvent
void moveSimulationEvent(const std::string &name, unsigned int position, short type=SimulationEvent::kNative|SimulationEvent::kScript)
Moves the simulation event.
Atoms::AgentsSimulation::simulationEventNames
std::vector< std::string > simulationEventNames(short type=SimulationEvent::kAll) const
Gets all simulation events.
Atoms::AtomsPhysx
Definition: AtomsPhysx.h:40
Atoms::AgentsSimulation::computeDynamics
void computeDynamics()
Compute dynamics.
Atoms::AgentsSimulation::isDynamicEnabled
bool isDynamicEnabled() const
Return if the physx solver is enabled.
Atoms::AgentsSimulation::addAnimationClipEvent
void addAnimationClipEvent(AtomsPtr< SimulationEvent > &simEvent, bool replace=true)
Adds a simulation event.
Atoms::AgentsSimulation::addAgentTypeEvent
void addAgentTypeEvent(AtomsPtr< SimulationEvent > &simEvent, bool replace=true)
Adds a simulation event.
Atoms::AgentsSimulation::addAgentGroup
void addAgentGroup(AtomsPtr< AgentGroup > &aGroup)
Adds an agent group.
Atoms::AgentsSimulation::initFrame
void initFrame()
Init Frame.