Panda3D
physxTriggerReport.cxx
1 // Filename: physxTriggerReport.cxx
2 // Created by: enn0x (19Sep09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "physxTriggerReport.h"
16 
17 #include "event.h"
18 #include "eventQueue.h"
19 #include "eventParameter.h"
20 
21 PStatCollector PhysxTriggerReport::_pcollector("App:PhysX:Trigger Reporting");
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: PhysxTriggerReport::enable
25 // Access: Public
26 // Description:
27 ////////////////////////////////////////////////////////////////////
28 void PhysxTriggerReport::
29 enable() {
30 
31  _enabled = true;
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: PhysxTriggerReport::disable
36 // Access: Public
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 void PhysxTriggerReport::
40 disable() {
41 
42  _enabled = false;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: PhysxTriggerReport::is_enabled
47 // Access: Public
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 bool PhysxTriggerReport::
51 is_enabled() const {
52 
53  return _enabled;
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: PhysxTriggerReport::onTrigger
58 // Access: Public
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 void PhysxTriggerReport::
62 onTrigger(NxShape &triggerShape, NxShape &otherShape, NxTriggerFlag status) {
63 
64  if (!_enabled) {
65  return;
66  }
67 
68  _pcollector.start();
69 
70  Event *event;
71  if (status & NX_TRIGGER_ON_ENTER) {
72  event = new Event("physx-trigger-enter");
73  }
74  else if (status & NX_TRIGGER_ON_LEAVE) {
75  event = new Event("physx-trigger-leave");
76  }
77  else if (status & NX_TRIGGER_ON_STAY) {
78  event = new Event("physx-trigger-stay");
79  }
80  else {
81  return;
82  }
83 
84  PT(PhysxShape) pTriggerShape = (PhysxShape *)triggerShape.userData;
85  PT(PhysxShape) pOtherShape = (PhysxShape *)otherShape.userData;
86  event->add_parameter(EventParameter(pTriggerShape));
87  event->add_parameter(EventParameter(pOtherShape));
88 
89  EventQueue::get_global_event_queue()->queue_event(event);
90 
91  _pcollector.stop();
92 }
93 
An optional parameter associated with an event.
Abstract base class for shapes.
Definition: physxShape.h:41
static EventQueue * get_global_event_queue()
Returns a pointer to the one global EventQueue object.
Definition: eventQueue.I:24
A lightweight class that represents a single element that may be timed and/or counted via stats...
A named event, possibly with parameters.
Definition: event.h:36