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  */
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  */
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  * @deprecated Use add_in_pattern() instead.
85  */
87 set_in_pattern(const std::string &in_pattern) {
89  add_in_pattern(in_pattern);
90 }
91 
92 /**
93  * Returns the number of in pattern strings that have been added.
94  */
95 INLINE int CollisionHandlerEvent::
96 get_num_in_patterns() const {
97  return _in_patterns.size();
98 }
99 
100 /**
101  * Returns the nth pattern string that indicates how the event names are
102  * generated for each collision detected. See add_in_pattern().
103  */
104 INLINE std::string CollisionHandlerEvent::
105 get_in_pattern(int n) const {
106  nassertr(n >= 0 && n < (int)_in_patterns.size(), std::string());
107  return _in_patterns[n];
108 }
109 
110 /**
111  * Removes all of the previously-added in patterns. See add_again_pattern.
112  */
115  _again_patterns.clear();
116 }
117 
118 /**
119  * Adds the pattern string that indicates how the event names are generated
120  * when a collision between two particular nodes is *still* detected. This
121  * event is thrown each consecutive time a collision between two particular
122  * nodes is detected, starting with the second time.
123  *
124  * In general, the in_pattern event is thrown on the first detection of a
125  * collision between two particular nodes. In subsequent passes, as long as a
126  * collision between those two nodes continues to be detected each frame, the
127  * again_pattern is thrown. The first frame in which the collision is no
128  * longer detected, the out_pattern event is thrown.
129  */
131 add_again_pattern(const std::string &again_pattern) {
132  _again_patterns.push_back(again_pattern);
133 }
134 
135 /**
136  * This method is deprecated; it completely replaces all the in patterns that
137  * have previously been set with the indicated pattern.
138  *
139  * @deprecated Use add_again_pattern() instead.
140  */
142 set_again_pattern(const std::string &again_pattern) {
144  add_again_pattern(again_pattern);
145 }
146 
147 /**
148  * Returns the number of in pattern strings that have been added.
149  */
150 INLINE int CollisionHandlerEvent::
151 get_num_again_patterns() const {
152  return _again_patterns.size();
153 }
154 
155 /**
156  * Returns the nth pattern string that indicates how the event names are
157  * generated for each collision detected. See add_again_pattern().
158  */
159 INLINE std::string CollisionHandlerEvent::
160 get_again_pattern(int n) const {
161  nassertr(n >= 0 && n < (int)_again_patterns.size(), std::string());
162  return _again_patterns[n];
163 }
164 
165 /**
166  * Removes all of the previously-added in patterns. See add_out_pattern.
167  */
170  _out_patterns.clear();
171 }
172 
173 /**
174  * Adds the pattern string that indicates how the event names are generated
175  * when a collision between two particular nodes is *no longer* detected.
176  *
177  * In general, the in_pattern event is thrown on the first detection of a
178  * collision between two particular nodes. In subsequent passes, as long as a
179  * collision between those two nodes continues to be detected each frame, the
180  * again_pattern is thrown. The first frame in which the collision is no
181  * longer detected, the out_pattern event is thrown.
182  */
184 add_out_pattern(const std::string &out_pattern) {
185  _out_patterns.push_back(out_pattern);
186 }
187 
188 /**
189  * This method is deprecated; it completely replaces all the in patterns that
190  * have previously been set with the indicated pattern.
191  *
192  * @deprecated Use add_out_pattern() instead.
193  */
195 set_out_pattern(const std::string &out_pattern) {
197  add_out_pattern(out_pattern);
198 }
199 
200 /**
201  * Returns the number of in pattern strings that have been added.
202  */
203 INLINE int CollisionHandlerEvent::
204 get_num_out_patterns() const {
205  return _out_patterns.size();
206 }
207 
208 /**
209  * Returns the nth pattern string that indicates how the event names are
210  * generated for each collision detected. See add_out_pattern().
211  */
212 INLINE std::string CollisionHandlerEvent::
213 get_out_pattern(int n) const {
214  nassertr(n >= 0 && n < (int)_out_patterns.size(), std::string());
215  return _out_patterns[n];
216 }
Defines a single collision event.
get_from_node_path
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
get_into_node_path
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
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 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_num_again_patterns
Returns the number of in pattern strings that have been added.
void clear_again_patterns()
Removes all of the previously-added in patterns.
get_again_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
void clear_out_patterns()
Removes all of the previously-added in patterns.
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_out_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
get_num_in_patterns
Returns the number of in pattern strings that have been added.
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 clear_in_patterns()
Removes all of the previously-added in patterns.
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...
get_in_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
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_num_out_patterns
Returns the number of in pattern strings that have been added.