Panda3D
 All Classes Functions Variables Enumerations
collisionHandlerEvent.I
1 // Filename: collisionHandlerEvent.I
2 // Created by: drose (16Mar02)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: CollisionHandlerEvent::SortEntries::operator ()
18 // Access: Public
19 // Description: Orders the CollisionEntries in the set so that there
20 // is one entry for each node/node intersection
21 // detected.
22 ////////////////////////////////////////////////////////////////////
23 INLINE bool CollisionHandlerEvent::SortEntries::
24 operator () (const PT(CollisionEntry) &a,
25  const PT(CollisionEntry) &b) const {
26  int compare_from = a->get_from_node_path().compare_to(b->get_from_node_path());
27  if (compare_from != 0) {
28  return compare_from < 0;
29  }
30  return a->get_into_node_path() < b->get_into_node_path();
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: CollisionHandlerEvent::SortEntries::operator =
35 // Access: Public
36 // Description: The assignment operator does absolutely nothing,
37 // since this is just a function object class that
38 // stores no data. We define it just to quiet up g++ in
39 // -Wall mode.
40 ////////////////////////////////////////////////////////////////////
41 INLINE void CollisionHandlerEvent::SortEntries::
42 operator = (const CollisionHandlerEvent::SortEntries &) {
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: CollisionHandlerEvent::clear_in_patterns
47 // Access: Public
48 // Description: Removes all of the previously-added in patterns. See
49 // add_in_pattern.
50 ////////////////////////////////////////////////////////////////////
51 INLINE void CollisionHandlerEvent::
53  _in_patterns.clear();
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: CollisionHandlerEvent::add_in_pattern
58 // Access: Public
59 // Description: Adds a pattern string to the list of events that will
60 // be generated in response to a collision. The pattern
61 // string describes how the event name will be composed.
62 // It is a string that may contain any of the following:
63 //
64 // %fn - the name of the "from" object's node
65 // %in - the name of the "into" object's node
66 // %fs - 't' if "from" is tangible, 'i' if intangible
67 // %is - 't' if "into" is tangible, 'i' if intangible
68 // %ig - 'c' if the collision is into a
69 // CollisionNode, 'g' if it is a geom.
70 //
71 // %(tag)fh - generate event only if "from" node has
72 // the indicated net tag.
73 // %(tag)fx - generate event only if "from" node does
74 // not have the indicated net tag.
75 // %(tag)ih - generate event only if "into" node has
76 // the indicated net tag.
77 // %(tag)ix - generate event only if "into" node does
78 // not have the indicated net tag.
79 // %(tag)ft - the indicated net tag value of the "from" node.
80 // %(tag)it - the indicated net tag value of the "into" node.
81 //
82 // Parentheses in the above are literal and should be
83 // included in the actual pattern.
84 //
85 // The event name will be based on the in_pattern
86 // string specified here, with all occurrences of the
87 // above strings replaced with the corresponding values.
88 //
89 // In general, the in_pattern event is thrown on the
90 // first detection of a collision between two particular
91 // nodes. In subsequent passes, as long as a collision
92 // between those two nodes continues to be detected each
93 // frame, the again_pattern is thrown. The first frame
94 // in which the collision is no longer detected, the
95 // out_pattern event is thrown.
96 ////////////////////////////////////////////////////////////////////
97 INLINE void CollisionHandlerEvent::
98 add_in_pattern(const string &in_pattern) {
99  _in_patterns.push_back(in_pattern);
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function: CollisionHandlerEvent::set_in_pattern
104 // Access: Public
105 // Description: This method is deprecated; it completely replaces all
106 // the in patterns that have previously been set with
107 // the indicated pattern.
108 ////////////////////////////////////////////////////////////////////
109 INLINE void CollisionHandlerEvent::
110 set_in_pattern(const string &in_pattern) {
112  add_in_pattern(in_pattern);
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: CollisionHandlerEvent::get_num_in_patterns
117 // Access: Public
118 // Description: Returns the number of in pattern strings that have
119 // been added.
120 ////////////////////////////////////////////////////////////////////
121 INLINE int CollisionHandlerEvent::
123  return _in_patterns.size();
124 }
125 
126 ////////////////////////////////////////////////////////////////////
127 // Function: CollisionHandlerEvent::get_in_pattern
128 // Access: Public
129 // Description: Returns the nth pattern string that indicates how the
130 // event names are generated for each collision
131 // detected. See add_in_pattern().
132 ////////////////////////////////////////////////////////////////////
133 INLINE string CollisionHandlerEvent::
134 get_in_pattern(int n) const {
135  nassertr(n >= 0 && n < (int)_in_patterns.size(), string());
136  return _in_patterns[n];
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: CollisionHandlerEvent::clear_again_patterns
141 // Access: Public
142 // Description: Removes all of the previously-added in patterns. See
143 // add_again_pattern.
144 ////////////////////////////////////////////////////////////////////
145 INLINE void CollisionHandlerEvent::
147  _again_patterns.clear();
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: CollisionHandlerEvent::add_again_pattern
152 // Access: Public
153 // Description: Adds the pattern string that indicates how the event
154 // names are generated when a collision between two
155 // particular nodes is *still* detected. This event is
156 // thrown each consecutive time a collision between two
157 // particular nodes is detected, starting with the
158 // second time.
159 //
160 // In general, the in_pattern event is thrown on the
161 // first detection of a collision between two particular
162 // nodes. In subsequent passes, as long as a collision
163 // between those two nodes continues to be detected each
164 // frame, the again_pattern is thrown. The first frame
165 // in which the collision is no longer detected, the
166 // out_pattern event is thrown.
167 ////////////////////////////////////////////////////////////////////
168 INLINE void CollisionHandlerEvent::
169 add_again_pattern(const string &again_pattern) {
170  _again_patterns.push_back(again_pattern);
171 }
172 
173 ////////////////////////////////////////////////////////////////////
174 // Function: CollisionHandlerEvent::set_again_pattern
175 // Access: Public
176 // Description: This method is deprecated; it completely replaces all
177 // the in patterns that have previously been set with
178 // the indicated pattern.
179 ////////////////////////////////////////////////////////////////////
180 INLINE void CollisionHandlerEvent::
181 set_again_pattern(const string &again_pattern) {
183  add_again_pattern(again_pattern);
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: CollisionHandlerEvent::get_num_again_patterns
188 // Access: Public
189 // Description: Returns the number of in pattern strings that have
190 // been added.
191 ////////////////////////////////////////////////////////////////////
192 INLINE int CollisionHandlerEvent::
194  return _again_patterns.size();
195 }
196 
197 ////////////////////////////////////////////////////////////////////
198 // Function: CollisionHandlerEvent::get_again_pattern
199 // Access: Public
200 // Description: Returns the nth pattern string that indicates how the
201 // event names are generated for each collision
202 // detected. See add_again_pattern().
203 ////////////////////////////////////////////////////////////////////
204 INLINE string CollisionHandlerEvent::
205 get_again_pattern(int n) const {
206  nassertr(n >= 0 && n < (int)_again_patterns.size(), string());
207  return _again_patterns[n];
208 }
209 
210 ////////////////////////////////////////////////////////////////////
211 // Function: CollisionHandlerEvent::clear_out_patterns
212 // Access: Public
213 // Description: Removes all of the previously-added in patterns. See
214 // add_out_pattern.
215 ////////////////////////////////////////////////////////////////////
216 INLINE void CollisionHandlerEvent::
218  _out_patterns.clear();
219 }
220 
221 ////////////////////////////////////////////////////////////////////
222 // Function: CollisionHandlerEvent::add_out_pattern
223 // Access: Public
224 // Description: Adds the pattern string that indicates how the event
225 // names are generated when a collision between two
226 // particular nodes is *no longer* detected.
227 //
228 // In general, the in_pattern event is thrown on the
229 // first detection of a collision between two particular
230 // nodes. In subsequent passes, as long as a collision
231 // between those two nodes continues to be detected each
232 // frame, the again_pattern is thrown. The first frame
233 // in which the collision is no longer detected, the
234 // out_pattern event is thrown.
235 ////////////////////////////////////////////////////////////////////
236 INLINE void CollisionHandlerEvent::
237 add_out_pattern(const string &out_pattern) {
238  _out_patterns.push_back(out_pattern);
239 }
240 
241 ////////////////////////////////////////////////////////////////////
242 // Function: CollisionHandlerEvent::set_out_pattern
243 // Access: Public
244 // Description: This method is deprecated; it completely replaces all
245 // the in patterns that have previously been set with
246 // the indicated pattern.
247 ////////////////////////////////////////////////////////////////////
248 INLINE void CollisionHandlerEvent::
249 set_out_pattern(const string &out_pattern) {
251  add_out_pattern(out_pattern);
252 }
253 
254 ////////////////////////////////////////////////////////////////////
255 // Function: CollisionHandlerEvent::get_num_out_patterns
256 // Access: Public
257 // Description: Returns the number of in pattern strings that have
258 // been added.
259 ////////////////////////////////////////////////////////////////////
260 INLINE int CollisionHandlerEvent::
262  return _out_patterns.size();
263 }
264 
265 ////////////////////////////////////////////////////////////////////
266 // Function: CollisionHandlerEvent::get_out_pattern
267 // Access: Public
268 // Description: Returns the nth pattern string that indicates how the
269 // event names are generated for each collision
270 // detected. See add_out_pattern().
271 ////////////////////////////////////////////////////////////////////
272 INLINE string CollisionHandlerEvent::
273 get_out_pattern(int n) const {
274  nassertr(n >= 0 && n < (int)_out_patterns.size(), string());
275  return _out_patterns[n];
276 }
int compare_to(const NodePath &other) const
Returns a number less than zero if this NodePath sorts before the other one, greater than zero if it ...
Definition: nodePath.I:2412
void add_out_pattern(const string &out_pattern)
Adds the pattern string that indicates how the event names are generated when a collision between two...
int get_num_again_patterns() const
Returns the number of in pattern strings that have been added.
string get_out_pattern(int n) const
Returns the nth pattern string that indicates how the event names are generated for each collision de...
void add_again_pattern(const string &again_pattern)
Adds the pattern string that indicates how the event names are generated when a collision between two...
void set_in_pattern(const string &in_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
void clear_in_patterns()
Removes all of the previously-added in patterns.
int get_num_out_patterns() const
Returns the number of in pattern strings that have been added.
string get_again_pattern(int n) const
Returns the nth pattern string that indicates how the event names are generated for each collision de...
Defines a single collision event.
void set_again_pattern(const string &again_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
int get_num_in_patterns() const
Returns the number of in pattern strings that have been added.
void set_out_pattern(const string &out_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
NodePath get_into_node_path() const
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
NodePath get_from_node_path() const
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
void clear_out_patterns()
Removes all of the previously-added in patterns.
void clear_again_patterns()
Removes all of the previously-added in patterns.
string get_in_pattern(int n) const
Returns the nth pattern string that indicates how the event names are generated for each collision de...
void add_in_pattern(const string &in_pattern)
Adds a pattern string to the list of events that will be generated in response to a collision...