16 #ifndef AGXSDK_EVENTMANAGER_H
17 #define AGXSDK_EVENTMANAGER_H
45 enum ExecutePriority {
47 DEFAULT_PRIORITY = 50,
48 HIGHEST_PRIORITY = 100
55 enum CleanupSelectionMask {
57 CONTACT_LISTENERS = 0x2,
59 LISTENERS = STEP_LISTENERS | CONTACT_LISTENERS | GUI_LISTENERS,
60 CLEANUP_ALL = LISTENERS
64 EventManager(Simulation* simulation);
73 bool addStepEventListener(StepEventListener* listener,
int priority = DEFAULT_PRIORITY );
84 bool addContactEventListener(ContactEventListener* listener,
int priority = DEFAULT_PRIORITY );
91 bool addGuiEventListener(GuiEventListener* listener,
int priority = DEFAULT_PRIORITY );
96 bool addEventListener(EventListener* listener,
int priority = DEFAULT_PRIORITY );
101 void triggerContactEventListeners(
const agx::TimeStamp& timeStamp,
108 void triggerSeparationContactEventListeners (
const agx::TimeStamp& timeStamp,
142 void triggerPreCollideStepEvent(
const agx::TimeStamp& timeStamp );
163 bool removeEventListener(EventListener* listener);
169 bool triggerGuiEvent(
const GuiEvent& guiEvent );
175 void setEnableDetailedStatisticsReport(
bool enable );
180 bool getEnableDetailedStatisticsReport()
const;
182 template <
typename T>
186 PrioHolder( ): m_priority( 0 ) {}
187 PrioHolder( T obj,
int priority ) : m_obj( obj ), m_priority( priority ) {}
188 inline int priority()
const {
191 inline operator T () {
194 inline operator const T ()
const {
197 inline operator int ()
const {
200 inline T listener() {
203 inline const T listener()
const {
222 void cleanup( CleanupSelectionMask selection );
224 friend class Simulation;
229 typedef std::map< uint32_t, PrioHolder<StepEventListenerRef> > StepEventListeners;
230 typedef std::map< uint32_t, PrioHolder<ContactEventListenerRef> > ContactEventListeners;
231 typedef std::map< uint32_t, PrioHolder<GuiEventListenerRef> > GuiEventListeners;
235 bool checkPriorityForClass( EventListener* listener,
int priority );
237 void initSystemClassNameTable();
239 SystemClassNames m_systemClassNames;
241 template <
typename T1,
typename DATA1>
242 class ListenerQueueCache
248 typedef typename QueueType::iterator iterator;
250 ListenerQueueCache() : m_dirty( true ), m_needRebuild( true ) {}
255 void setNeedRebuild( ) {
256 m_needRebuild =
true;
261 m_needRebuild =
true;
265 bool isDirty()
const {
268 bool needRebuild()
const {
269 return m_needRebuild;
276 inline iterator
begin() {
277 return m_queue.begin();
279 inline iterator
end() {
280 return m_queue.end();
284 void build( T1& container) {
287 void build( T1& container,
bool doSort =
true ) {
290 if ( needRebuild() ) {
292 SortableVectorType sortVector;
293 sortVector.reserve( container.size() );
295 typename T1::iterator cit = container.begin();
296 for (
size_t i = 0; cit != container.end(); ++cit, ++i ) {
297 sortVector.push_back( std::make_pair(cit->second.listener().get(), cit->second.priority()) );
301 std::sort( sortVector.begin(), sortVector.end(), prioGreater<std::pair<DATA1, int> >() );
303 m_queue.reserve( sortVector.size() );
304 for (
size_t i = 0; i < sortVector.size(); i++) {
305 m_queue.push_back( sortVector[i].first );
309 m_needRebuild =
false;
319 bool operator()(
const T& _Left,
const T& _Right)
const {
320 return (_Left.second > _Right.second);
331 Simulation* m_simulation;
333 StepEventListeners m_step_listeners;
334 typedef ListenerQueueCache<StepEventListeners, StepEventListenerRef> StepEventListenerCache;
335 StepEventListenerCache m_step_listener_cache;
337 ContactEventListeners m_contact_listeners;
338 typedef ListenerQueueCache<ContactEventListeners, ContactEventListenerRef> ContactListenerCache;
339 ContactListenerCache m_contact_listener_cache;
341 GuiEventListeners m_gui_listeners;
342 typedef ListenerQueueCache<GuiEventListeners, GuiEventListenerRef > GuiEventListenerCache;
343 GuiEventListenerCache m_gui_listener_cache;
348 bool m_detailedStatisticsReport;
353 virtual ~EventManager();
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGXPHYSICS_EXPORT
An EventListener can be associated to a Simulation and triggered upon various events.
Inheritance with partial specialization due to bug with ref_ptr containers.
Base class providing referencing counted objects.
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
agx::Vector< EventListener * > EventListenerPtrVector
AGXTERRAIN_EXPORT void clear()
LinearProbingHashSetImplementation< KeyT, HashT >::iterator begin(LinearProbingHashSetImplementation< KeyT, HashT > &set)
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)