Panda3D
collisionHandlerEvent.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file collisionHandlerEvent.I
10  * @author drose
11  * @date 2002-03-16
12  */
13 
14 /**
15  * Orders the CollisionEntries in the set so that there is one entry for each
16  * node/node intersection detected.
17  */
18 INLINE bool CollisionHandlerEvent::SortEntries::
19 operator () (const PT(CollisionEntry) &a,
20  const PT(CollisionEntry) &b) const {
21  int compare_from = a->get_from_node_path().compare_to(b->get_from_node_path());
22  if (compare_from != 0) {
23  return compare_from < 0;
24  }
25  return a->get_into_node_path() < b->get_into_node_path();
26 }
27 
28 /**
29  * The assignment operator does absolutely nothing, since this is just a
30  * function object class that stores no data. We define it just to quiet up
31  * g++ in -Wall mode.
32  */
33 INLINE void CollisionHandlerEvent::SortEntries::
34 operator = (const CollisionHandlerEvent::SortEntries &) {
35 }
36 
37 /**
38  * Removes all of the previously-added in patterns. See add_in_pattern.
39  */
40 INLINE void CollisionHandlerEvent::
42  _in_patterns.clear();
43 }
44 
45 /**
46  * Adds a pattern string to the list of events that will be generated in
47  * response to a collision. The pattern string describes how the event name
48  * will be composed. It is a string that may contain any of the following:
49  *
50  * %fn - the name of the "from" object's node %in - the name of the "into"
51  * object's node %fs - 't' if "from" is tangible, 'i' if intangible %is -
52  * 't' if "into" is tangible, 'i' if intangible %ig - 'c' if the collision is
53  * into a CollisionNode, 'g' if it is a geom.
54  *
55  * %(tag)fh - generate event only if "from" node has the indicated net tag.
56  * %(tag)fx - generate event only if "from" node does not have the indicated
57  * net tag. %(tag)ih - generate event only if "into" node has the indicated
58  * net tag. %(tag)ix - generate event only if "into" node does not have the
59  * indicated net tag. %(tag)ft - the indicated net tag value of the "from"
60  * node. %(tag)it - the indicated net tag value of the "into" node.
61  *
62  * Parentheses in the above are literal and should be included in the actual
63  * pattern.
64  *
65  * The event name will be based on the in_pattern string specified here, with
66  * all occurrences of the above strings replaced with the corresponding
67  * values.
68  *
69  * In general, the in_pattern event is thrown on the first detection of a
70  * collision between two particular nodes. In subsequent passes, as long as a
71  * collision between those two nodes continues to be detected each frame, the
72  * again_pattern is thrown. The first frame in which the collision is no
73  * longer detected, the out_pattern event is thrown.
74  */
75 INLINE void CollisionHandlerEvent::
76 add_in_pattern(const std::string &in_pattern) {
77  _in_patterns.push_back(in_pattern);
78 }
79 
80 /**
81  * This method is deprecated; it completely replaces all the in patterns that
82  * have previously been set with the indicated pattern.
83  */
84 INLINE void CollisionHandlerEvent::
85 set_in_pattern(const std::string &in_pattern) {
87  add_in_pattern(in_pattern);
88 }
89 
90 /**
91  * Returns the number of in pattern strings that have been added.
92  */
93 INLINE int CollisionHandlerEvent::
94 get_num_in_patterns() const {
95  return _in_patterns.size();
96 }
97 
98 /**
99  * Returns the nth pattern string that indicates how the event names are
100  * generated for each collision detected. See add_in_pattern().
101  */
102 INLINE std::string CollisionHandlerEvent::
103 get_in_pattern(int n) const {
104  nassertr(n >= 0 && n < (int)_in_patterns.size(), std::string());
105  return _in_patterns[n];
106 }
107 
108 /**
109  * Removes all of the previously-added in patterns. See add_again_pattern.
110  */
111 INLINE void CollisionHandlerEvent::
113  _again_patterns.clear();
114 }
115 
116 /**
117  * Adds the pattern string that indicates how the event names are generated
118  * when a collision between two particular nodes is *still* detected. This
119  * event is thrown each consecutive time a collision between two particular
120  * nodes is detected, starting with the second time.
121  *
122  * In general, the in_pattern event is thrown on the first detection of a
123  * collision between two particular nodes. In subsequent passes, as long as a
124  * collision between those two nodes continues to be detected each frame, the
125  * again_pattern is thrown. The first frame in which the collision is no
126  * longer detected, the out_pattern event is thrown.
127  */
128 INLINE void CollisionHandlerEvent::
129 add_again_pattern(const std::string &again_pattern) {
130  _again_patterns.push_back(again_pattern);
131 }
132 
133 /**
134  * This method is deprecated; it completely replaces all the in patterns that
135  * have previously been set with the indicated pattern.
136  */
137 INLINE void CollisionHandlerEvent::
138 set_again_pattern(const std::string &again_pattern) {
140  add_again_pattern(again_pattern);
141 }
142 
143 /**
144  * Returns the number of in pattern strings that have been added.
145  */
146 INLINE int CollisionHandlerEvent::
147 get_num_again_patterns() const {
148  return _again_patterns.size();
149 }
150 
151 /**
152  * Returns the nth pattern string that indicates how the event names are
153  * generated for each collision detected. See add_again_pattern().
154  */
155 INLINE std::string CollisionHandlerEvent::
156 get_again_pattern(int n) const {
157  nassertr(n >= 0 && n < (int)_again_patterns.size(), std::string());
158  return _again_patterns[n];
159 }
160 
161 /**
162  * Removes all of the previously-added in patterns. See add_out_pattern.
163  */
164 INLINE void CollisionHandlerEvent::
166  _out_patterns.clear();
167 }
168 
169 /**
170  * Adds the pattern string that indicates how the event names are generated
171  * when a collision between two particular nodes is *no longer* detected.
172  *
173  * In general, the in_pattern event is thrown on the first detection of a
174  * collision between two particular nodes. In subsequent passes, as long as a
175  * collision between those two nodes continues to be detected each frame, the
176  * again_pattern is thrown. The first frame in which the collision is no
177  * longer detected, the out_pattern event is thrown.
178  */
179 INLINE void CollisionHandlerEvent::
180 add_out_pattern(const std::string &out_pattern) {
181  _out_patterns.push_back(out_pattern);
182 }
183 
184 /**
185  * This method is deprecated; it completely replaces all the in patterns that
186  * have previously been set with the indicated pattern.
187  */
188 INLINE void CollisionHandlerEvent::
189 set_out_pattern(const std::string &out_pattern) {
191  add_out_pattern(out_pattern);
192 }
193 
194 /**
195  * Returns the number of in pattern strings that have been added.
196  */
197 INLINE int CollisionHandlerEvent::
198 get_num_out_patterns() const {
199  return _out_patterns.size();
200 }
201 
202 /**
203  * Returns the nth pattern string that indicates how the event names are
204  * generated for each collision detected. See add_out_pattern().
205  */
206 INLINE std::string CollisionHandlerEvent::
207 get_out_pattern(int n) const {
208  nassertr(n >= 0 && n < (int)_out_patterns.size(), std::string());
209  return _out_patterns[n];
210 }
void add_again_pattern(const std::string &again_pattern)
Adds the pattern string that indicates how the event names are generated when a collision between two...
get_from_node_path
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
void add_in_pattern(const std::string &in_pattern)
Adds a pattern string to the list of events that will be generated in response to a collision.
void set_again_pattern(const std::string &again_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
get_into_node_path
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
void clear_in_patterns()
Removes all of the previously-added in patterns.
get_out_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
get_again_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
Defines a single collision event.
void add_out_pattern(const std::string &out_pattern)
Adds the pattern string that indicates how the event names are generated when a collision between two...
get_in_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
void set_in_pattern(const std::string &in_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
void set_out_pattern(const std::string &out_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
void clear_out_patterns()
Removes all of the previously-added in patterns.
void clear_again_patterns()
Removes all of the previously-added in patterns.