Panda3D
|
00001 // Filename: collisionHandlerEvent.I 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: CollisionHandlerEvent::SortEntries::operator () 00018 // Access: Public 00019 // Description: Orders the CollisionEntries in the set so that there 00020 // is one entry for each node/node intersection 00021 // detected. 00022 //////////////////////////////////////////////////////////////////// 00023 INLINE bool CollisionHandlerEvent::SortEntries:: 00024 operator () (const PT(CollisionEntry) &a, 00025 const PT(CollisionEntry) &b) const { 00026 int compare_from = a->get_from_node_path().compare_to(b->get_from_node_path()); 00027 if (compare_from != 0) { 00028 return compare_from < 0; 00029 } 00030 return a->get_into_node_path() < b->get_into_node_path(); 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: CollisionHandlerEvent::SortEntries::operator = 00035 // Access: Public 00036 // Description: The assignment operator does absolutely nothing, 00037 // since this is just a function object class that 00038 // stores no data. We define it just to quiet up g++ in 00039 // -Wall mode. 00040 //////////////////////////////////////////////////////////////////// 00041 INLINE void CollisionHandlerEvent::SortEntries:: 00042 operator = (const CollisionHandlerEvent::SortEntries &) { 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: CollisionHandlerEvent::clear_in_patterns 00047 // Access: Public 00048 // Description: Removes all of the previously-added in patterns. See 00049 // add_in_pattern. 00050 //////////////////////////////////////////////////////////////////// 00051 INLINE void CollisionHandlerEvent:: 00052 clear_in_patterns() { 00053 _in_patterns.clear(); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: CollisionHandlerEvent::add_in_pattern 00058 // Access: Public 00059 // Description: Adds a pattern string to the list of events that will 00060 // be generated in response to a collision. The pattern 00061 // string describes how the event name will be composed. 00062 // It is a string that may contain any of the following: 00063 // 00064 // %fn - the name of the "from" object's node 00065 // %in - the name of the "into" object's node 00066 // %fs - 't' if "from" is tangible, 'i' if intangible 00067 // %is - 't' if "into" is tangible, 'i' if intangible 00068 // %ig - 'c' if the collision is into a 00069 // CollisionNode, 'g' if it is a geom. 00070 // 00071 // %(tag)fh - generate event only if "from" node has 00072 // the indicated net tag. 00073 // %(tag)fx - generate event only if "from" node does 00074 // not have the indicated net tag. 00075 // %(tag)ih - generate event only if "into" node has 00076 // the indicated net tag. 00077 // %(tag)ix - generate event only if "into" node does 00078 // not have the indicated net tag. 00079 // %(tag)ft - the indicated net tag value of the "from" node. 00080 // %(tag)it - the indicated net tag value of the "into" node. 00081 // 00082 // Parentheses in the above are literal and should be 00083 // included in the actual pattern. 00084 // 00085 // The event name will be based on the in_pattern 00086 // string specified here, with all occurrences of the 00087 // above strings replaced with the corresponding values. 00088 // 00089 // In general, the in_pattern event is thrown on the 00090 // first detection of a collision between two particular 00091 // nodes. In subsequent passes, as long as a collision 00092 // between those two nodes continues to be detected each 00093 // frame, the again_pattern is thrown. The first frame 00094 // in which the collision is no longer detected, the 00095 // out_pattern event is thrown. 00096 //////////////////////////////////////////////////////////////////// 00097 INLINE void CollisionHandlerEvent:: 00098 add_in_pattern(const string &in_pattern) { 00099 _in_patterns.push_back(in_pattern); 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: CollisionHandlerEvent::set_in_pattern 00104 // Access: Public 00105 // Description: This method is deprecated; it completely replaces all 00106 // the in patterns that have previously been set with 00107 // the indicated pattern. 00108 //////////////////////////////////////////////////////////////////// 00109 INLINE void CollisionHandlerEvent:: 00110 set_in_pattern(const string &in_pattern) { 00111 clear_in_patterns(); 00112 add_in_pattern(in_pattern); 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: CollisionHandlerEvent::get_num_in_patterns 00117 // Access: Public 00118 // Description: Returns the number of in pattern strings that have 00119 // been added. 00120 //////////////////////////////////////////////////////////////////// 00121 INLINE int CollisionHandlerEvent:: 00122 get_num_in_patterns() const { 00123 return _in_patterns.size(); 00124 } 00125 00126 //////////////////////////////////////////////////////////////////// 00127 // Function: CollisionHandlerEvent::get_in_pattern 00128 // Access: Public 00129 // Description: Returns the nth pattern string that indicates how the 00130 // event names are generated for each collision 00131 // detected. See add_in_pattern(). 00132 //////////////////////////////////////////////////////////////////// 00133 INLINE string CollisionHandlerEvent:: 00134 get_in_pattern(int n) const { 00135 nassertr(n >= 0 && n < (int)_in_patterns.size(), string()); 00136 return _in_patterns[n]; 00137 } 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: CollisionHandlerEvent::clear_again_patterns 00141 // Access: Public 00142 // Description: Removes all of the previously-added in patterns. See 00143 // add_again_pattern. 00144 //////////////////////////////////////////////////////////////////// 00145 INLINE void CollisionHandlerEvent:: 00146 clear_again_patterns() { 00147 _again_patterns.clear(); 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function: CollisionHandlerEvent::add_again_pattern 00152 // Access: Public 00153 // Description: Adds the pattern string that indicates how the event 00154 // names are generated when a collision between two 00155 // particular nodes is *still* detected. This event is 00156 // thrown each consecutive time a collision between two 00157 // particular nodes is detected, starting with the 00158 // second time. 00159 // 00160 // In general, the in_pattern event is thrown on the 00161 // first detection of a collision between two particular 00162 // nodes. In subsequent passes, as long as a collision 00163 // between those two nodes continues to be detected each 00164 // frame, the again_pattern is thrown. The first frame 00165 // in which the collision is no longer detected, the 00166 // out_pattern event is thrown. 00167 //////////////////////////////////////////////////////////////////// 00168 INLINE void CollisionHandlerEvent:: 00169 add_again_pattern(const string &again_pattern) { 00170 _again_patterns.push_back(again_pattern); 00171 } 00172 00173 //////////////////////////////////////////////////////////////////// 00174 // Function: CollisionHandlerEvent::set_again_pattern 00175 // Access: Public 00176 // Description: This method is deprecated; it completely replaces all 00177 // the in patterns that have previously been set with 00178 // the indicated pattern. 00179 //////////////////////////////////////////////////////////////////// 00180 INLINE void CollisionHandlerEvent:: 00181 set_again_pattern(const string &again_pattern) { 00182 clear_again_patterns(); 00183 add_again_pattern(again_pattern); 00184 } 00185 00186 //////////////////////////////////////////////////////////////////// 00187 // Function: CollisionHandlerEvent::get_num_again_patterns 00188 // Access: Public 00189 // Description: Returns the number of in pattern strings that have 00190 // been added. 00191 //////////////////////////////////////////////////////////////////// 00192 INLINE int CollisionHandlerEvent:: 00193 get_num_again_patterns() const { 00194 return _again_patterns.size(); 00195 } 00196 00197 //////////////////////////////////////////////////////////////////// 00198 // Function: CollisionHandlerEvent::get_again_pattern 00199 // Access: Public 00200 // Description: Returns the nth pattern string that indicates how the 00201 // event names are generated for each collision 00202 // detected. See add_again_pattern(). 00203 //////////////////////////////////////////////////////////////////// 00204 INLINE string CollisionHandlerEvent:: 00205 get_again_pattern(int n) const { 00206 nassertr(n >= 0 && n < (int)_again_patterns.size(), string()); 00207 return _again_patterns[n]; 00208 } 00209 00210 //////////////////////////////////////////////////////////////////// 00211 // Function: CollisionHandlerEvent::clear_out_patterns 00212 // Access: Public 00213 // Description: Removes all of the previously-added in patterns. See 00214 // add_out_pattern. 00215 //////////////////////////////////////////////////////////////////// 00216 INLINE void CollisionHandlerEvent:: 00217 clear_out_patterns() { 00218 _out_patterns.clear(); 00219 } 00220 00221 //////////////////////////////////////////////////////////////////// 00222 // Function: CollisionHandlerEvent::add_out_pattern 00223 // Access: Public 00224 // Description: Adds the pattern string that indicates how the event 00225 // names are generated when a collision between two 00226 // particular nodes is *no longer* detected. 00227 // 00228 // In general, the in_pattern event is thrown on the 00229 // first detection of a collision between two particular 00230 // nodes. In subsequent passes, as long as a collision 00231 // between those two nodes continues to be detected each 00232 // frame, the again_pattern is thrown. The first frame 00233 // in which the collision is no longer detected, the 00234 // out_pattern event is thrown. 00235 //////////////////////////////////////////////////////////////////// 00236 INLINE void CollisionHandlerEvent:: 00237 add_out_pattern(const string &out_pattern) { 00238 _out_patterns.push_back(out_pattern); 00239 } 00240 00241 //////////////////////////////////////////////////////////////////// 00242 // Function: CollisionHandlerEvent::set_out_pattern 00243 // Access: Public 00244 // Description: This method is deprecated; it completely replaces all 00245 // the in patterns that have previously been set with 00246 // the indicated pattern. 00247 //////////////////////////////////////////////////////////////////// 00248 INLINE void CollisionHandlerEvent:: 00249 set_out_pattern(const string &out_pattern) { 00250 clear_out_patterns(); 00251 add_out_pattern(out_pattern); 00252 } 00253 00254 //////////////////////////////////////////////////////////////////// 00255 // Function: CollisionHandlerEvent::get_num_out_patterns 00256 // Access: Public 00257 // Description: Returns the number of in pattern strings that have 00258 // been added. 00259 //////////////////////////////////////////////////////////////////// 00260 INLINE int CollisionHandlerEvent:: 00261 get_num_out_patterns() const { 00262 return _out_patterns.size(); 00263 } 00264 00265 //////////////////////////////////////////////////////////////////// 00266 // Function: CollisionHandlerEvent::get_out_pattern 00267 // Access: Public 00268 // Description: Returns the nth pattern string that indicates how the 00269 // event names are generated for each collision 00270 // detected. See add_out_pattern(). 00271 //////////////////////////////////////////////////////////////////// 00272 INLINE string CollisionHandlerEvent:: 00273 get_out_pattern(int n) const { 00274 nassertr(n >= 0 && n < (int)_out_patterns.size(), string()); 00275 return _out_patterns[n]; 00276 }