23 TypeHandle CollisionHandlerEvent::_type_handle;
41 if (collide_cat.is_spam()) {
45 _last_colliding.swap(_current_colliding);
46 _current_colliding.clear();
55 nassertv(entry !=
nullptr);
59 bool inserted = _current_colliding.insert(entry).second;
61 if (collide_cat.is_spam()) {
65 <<
", inserted = " << inserted <<
"\n";
80 if (collide_cat.is_spam()) {
83 <<
"current_colliding has " << _current_colliding.size()
84 <<
" entries, last_colliding has " << _last_colliding.size()
88 Colliding::iterator ca, cb;
90 ca = _current_colliding.begin();
91 cb = _last_colliding.begin();
94 while (ca != _current_colliding.end() && cb != _last_colliding.end()) {
95 if (order(*ca, *cb)) {
98 throw_event_for(_in_patterns, *ca);
100 }
else if (order(*cb, *ca)) {
103 throw_event_for(_out_patterns, *cb);
107 throw_event_for(_again_patterns, *cb);
113 while (ca != _current_colliding.end()) {
116 throw_event_for(_in_patterns, *ca);
120 while (cb != _last_colliding.end()) {
123 throw_event_for(_out_patterns, *cb);
143 _last_colliding.clear();
144 _current_colliding.clear();
159 void CollisionHandlerEvent::
160 throw_event_for(
const vector_string &patterns,
CollisionEntry *entry) {
161 vector_string::const_iterator pi;
162 for (pi = patterns.begin(); pi != patterns.end(); ++pi) {
163 throw_event_pattern(*pi, entry);
170 void CollisionHandlerEvent::
171 throw_event_pattern(
const string &pattern,
CollisionEntry *entry) {
172 if (pattern.empty()) {
177 for (
size_t p = 0; p < pattern.size(); ++p) {
178 if (pattern[p] ==
'%') {
180 if (p + 1 < pattern.size() && pattern[p + 1] ==
'(') {
182 size_t close = pattern.find(
')', p + 2);
183 if (close != string::npos) {
184 key = pattern.substr(p + 2, close - (p + 2));
191 string cmd = pattern.substr(p + 1, 2);
196 }
else if (cmd ==
"in") {
201 }
else if (cmd ==
"fs") {
203 (!entry->
get_from()->is_tangible() ?
'i' :
't');
205 }
else if (cmd ==
"is") {
209 }
else if (cmd ==
"ig") {
213 }
else if (cmd ==
"fh") {
218 }
else if (cmd ==
"fx") {
223 }
else if (cmd ==
"ih") {
228 }
else if (cmd ==
"ix") {
233 }
else if (cmd ==
"ft") {
236 }
else if (cmd ==
"it") {
243 <<
"Invalid symbol in event_pattern: %" << cmd <<
"\n";
250 if (!event.empty()) {
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal.
get_from_node_path
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
An optional parameter associated with an event.
void flush()
Same as clear() except "out" events are thrown.
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool has_into() const
Returns true if the "into" solid is, in fact, a CollisionSolid, and its pointer is known (in which ca...
get_into_node_path
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
void clear()
Empties the list of elements that all colliders are known to be colliding with.
get_from_node
Returns the node that contains the CollisionSolid that triggered this collision.
Defines a single collision event.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CollisionHandlerEvent()
The default CollisionHandlerEvent will throw no events.
get_into_node
Returns the node that contains the CollisionSolid that was collided into.
get_into
Returns the CollisionSolid pointer for the particular solid was collided into.
get_from
Returns the CollisionSolid pointer for the particular solid that triggered this collision.
TypeHandle is the identifier used to differentiate C++ class types.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.