AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
SimulationAddEventListener.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16#pragma once
17
18#include <agx/agx.h>
19#include <agx/ParticleSystem.h>
20#include <agxSDK/Simulation.h>
21#include <agx/Journal.h>
23
24namespace agx
25{
26 class RigidBody;
27}
28
29
30namespace agxSDK
31{
33
34
35 AGX_DECLARE_POINTER_TYPES(SimulationAddEventListener);
44 class AGXPHYSICS_EXPORT SimulationAddEventListener : public agxSDK::StepEventListener
45 {
46 private:
51 class ParticleStorageListener : public agxData::EntityStorage::EventListener
52 {
53
54 public:
55 ParticleStorageListener(SimulationAddEventListener& listener);
56
57 virtual void destroyCallback(agxData::EntityStorage* storage) override;
58 virtual void createInstanceCallback(agxData::EntityStorage* storage, agxData::EntityPtr instance) override;
59 virtual void createInstancesCallback(agxData::EntityStorage* storage, agxData::EntityRange range) override;
60 virtual void destroyInstanceCallback(agxData::EntityStorage* storage, agxData::EntityPtr instance) override;
61 virtual void destroyInstancesCallback(agxData::EntityStorage* storage, agxData::Array<agxData::EntityPtr> instances) override;
62 virtual void createInstancesCallback(agxData::EntityStorage* storage, agxData::Array<agxData::EntityPtr> instances) override;
63 virtual void destroyInstancesCallback(agxData::EntityStorage* storage, agxData::EntityRange instance) override;
64 virtual void permuteCallback(agxData::EntityStorage* storage, agxData::Array< agx::Index > permutation) override;
65
67 // Variables
69 protected:
70 SimulationAddEventListener& m_listener;
71 };
72
73 public:
74
78 SimulationAddEventListener();
79
83 size_t getNumberOfCreatedNss() const;
84
89 size_t getNumberOfCreatedParticles() const;
90
95 size_t getNumberOfActiveNss() const;
96
101 size_t getNumberOfActiveParticles() const;
102
106 bool getEnableParticleCreation();
107
111 bool getEnableNss();
112
116 bool hasReachedActiveNssLimit() const;
117
121 bool hasReachedEmittedNssLimit() const;
122
126 bool hasReachedActiveParticlesLimit() const;
127
131 bool hasReachedEmittedParticlesLimit() const;
132
137 bool isGranularBlocked();
138
142 size_t getMaxNumberOfActiveParticles() const;
143
147 size_t getMaxNumberOfEmittedParticles() const;
148
152 size_t getMaxNumberOfActiveNss() const;
153
157 size_t getMaxNumberOfEmittedNss() const;
158
162 void setMaxNumberOfActiveParticles(size_t max);
163
167 void setMaxNumberOfEmittedParticles(size_t max);
168
172 void setMaxNumberOfActiveNss(size_t max);
173
177 void setMaxNumberOfEmittedNss(size_t max);
178
179 virtual void addNotification() override;
180
181 virtual void removeNotification() override;
182
187 static agxSDK::SimulationAddEventListener* getListener(agxSDK::Simulation* simulation);
188
193 static bool validateAndWarnGranularLicenseLimits(agxSDK::Simulation* simulation);
194
198 void journalAttachedCallback(agxSDK::Simulation* simulation, agx::Journal* journal);
199
200 AGXSTREAM_DECLARE_SERIALIZABLE(agxSDK::SimulationAddEventListener);
201
202 protected:
206 virtual ~SimulationAddEventListener();
207
208 void addRigidBodyCallback(agxSDK::Simulation* sim, agx::RigidBody* body);
209
210 void removeRigidBodyCallback(agxSDK::Simulation* sim, agx::RigidBody* body);
211
212 void addGranularParticle(agxData::EntityPtr entity);
213
214 void removeGranularParticle();
215
216 void addGranularSystemCallback(agx::Component* parent, agx::Object* child);
217
218 void removeGranularSystemCallback(agx::Component* parent, agx::Object* child);
219
220 void journalJumpFrameCallback(agx::Journal* journal);
221
222 void granularSystemAdded(agx::ParticleSystem* particleSystem);
223
224 void granularSystemRemoved(agx::ParticleSystem* particleSystem);
225
226 private:
227 bool updateLicenseLimit();
228
229 bool hasLicenseLimitations();
230
231 void setLicenseLimit(size_t max, const std::string& limitName, size_t& limitValue);
232
233 void resetCounters();
234
235 private:
236
237 size_t m_numberEmittedBodies;
238 size_t m_numberActiveBodies;
239 size_t m_numberEmittedGranularParticles;
240 size_t m_numberActiveGranularParticles;
241
242 size_t m_maxEmittedPartcles;
243 size_t m_maxActivePartcles;
244 size_t m_maxEmittedNss;
245 size_t m_maxActiveNss;
246
247 // Callbacks for rigid body add/remove events
249 agxSDK::Simulation::RigidBodyEvent::CallbackType m_removeRigidBodyCallback;
250
251 // Callbacks on the simulation object to listen for add/remove of particle systems
252 agx::Component::ObjectEvent::CallbackType m_addGranularSystemCallback;
253 agx::Component::ObjectEvent::CallbackType m_removeGranularSystemCallback;
254
256
258
259 ParticleStorageListener m_particleStorageListener;
260
261 agx::ParticleSystemRef m_particleSystem;
262
263 bool m_doResetCounters;
264 };
265
266 AGX_FORCE_INLINE bool SimulationAddEventListener::isGranularBlocked()
267 {
268 return !getEnableNss() || !getEnableParticleCreation();
269 }
270
271 AGX_FORCE_INLINE size_t SimulationAddEventListener::getNumberOfCreatedNss() const
272 {
273 return m_numberEmittedBodies;
274 }
275
276 AGX_FORCE_INLINE size_t SimulationAddEventListener::getNumberOfCreatedParticles() const
277 {
278 return m_numberEmittedGranularParticles;
279 }
280
281 AGX_FORCE_INLINE size_t SimulationAddEventListener::getNumberOfActiveNss() const
282 {
283 return m_numberActiveBodies;
284 }
285
286 AGX_FORCE_INLINE size_t SimulationAddEventListener::getNumberOfActiveParticles() const
287 {
288 return m_numberActiveGranularParticles;
289 }
290
291 AGX_FORCE_INLINE size_t SimulationAddEventListener::getMaxNumberOfActiveParticles() const
292 {
293 return m_maxActivePartcles;
294 }
295
296 AGX_FORCE_INLINE size_t SimulationAddEventListener::getMaxNumberOfEmittedParticles() const
297 {
298 return m_maxEmittedPartcles;
299 }
300
301 AGX_FORCE_INLINE size_t SimulationAddEventListener::getMaxNumberOfActiveNss() const
302 {
303 return m_maxActiveNss;
304 }
305
306 AGX_FORCE_INLINE size_t SimulationAddEventListener::getMaxNumberOfEmittedNss() const
307 {
308 return m_maxEmittedNss;
309 }
310
312}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXPHYSICS_EXPORT
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition EntityPtr.h:52
Data storage for a collection of entity instances of a specified EntityModel.
Only use as member allocated variable.
Definition Value.h:285
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
A component is an object containing other objects, enabling hierarchical structuring.
Definition Component.h:39
T CallbackType
Definition Event.h:37
agx::Object is a refcounted object with a name.
Definition Object.h:59
A basic particle system that contains all the storages and buffers required for basic operation and a...
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
#define AGX_FORCE_INLINE
Definition macros.h:58
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.