16 #include "collisionHandlerEvent.h"
17 #include "config_collide.h"
19 #include "eventParameter.h"
20 #include "throw_event.h"
23 TypeHandle CollisionHandlerEvent::_type_handle;
46 if (collide_cat.is_spam()) {
50 _last_colliding.swap(_current_colliding);
51 _current_colliding.clear();
66 bool inserted = _current_colliding.insert(entry).second;
68 if (collide_cat.is_spam()) {
72 <<
", inserted = " << inserted <<
"\n";
90 if (collide_cat.is_spam()) {
93 <<
"current_colliding has " << _current_colliding.size()
94 <<
" entries, last_colliding has " << _last_colliding.size()
98 Colliding::iterator ca, cb;
100 ca = _current_colliding.begin();
101 cb = _last_colliding.begin();
104 while (ca != _current_colliding.end() && cb != _last_colliding.end()) {
105 if (order(*ca, *cb)) {
108 throw_event_for(_in_patterns, *ca);
110 }
else if (order(*cb, *ca)) {
113 throw_event_for(_out_patterns, *cb);
117 throw_event_for(_again_patterns, *cb);
123 while (ca != _current_colliding.end()) {
126 throw_event_for(_in_patterns, *ca);
130 while (cb != _last_colliding.end()) {
133 throw_event_for(_out_patterns, *cb);
157 _last_colliding.clear();
158 _current_colliding.clear();
178 void CollisionHandlerEvent::
179 throw_event_for(
const vector_string &patterns,
CollisionEntry *entry) {
180 vector_string::const_iterator pi;
181 for (pi = patterns.begin(); pi != patterns.end(); ++pi) {
182 throw_event_pattern(*pi, entry);
191 void CollisionHandlerEvent::
192 throw_event_pattern(
const string &pattern,
CollisionEntry *entry) {
193 if (pattern.empty()) {
198 for (
size_t p = 0; p < pattern.
size(); ++p) {
199 if (pattern[p] ==
'%') {
201 if (p + 1 < pattern.size() && pattern[p + 1] ==
'(') {
203 size_t close = pattern.find(
')', p + 2);
204 if (close != string::npos) {
205 key = pattern.substr(p + 2, close - (p + 2));
212 string cmd = pattern.substr(p + 1, 2);
217 }
else if (cmd ==
"in") {
222 }
else if (cmd ==
"fs") {
226 }
else if (cmd ==
"is") {
230 }
else if (cmd ==
"ig") {
234 }
else if (cmd ==
"fh") {
239 }
else if (cmd ==
"fx") {
244 }
else if (cmd ==
"ih") {
249 }
else if (cmd ==
"ix") {
254 }
else if (cmd ==
"ft") {
257 }
else if (cmd ==
"it") {
264 <<
"Invalid symbol in event_pattern: %" << cmd <<
"\n";
271 if (!event.empty()) {
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal...
CollisionNode * get_from_node() const
Returns the node that contains the CollisionSolid that triggered this collision.
string get_net_tag(const string &key) const
Returns the tag value that has been defined on this node, or the nearest ancestor node...
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.
const CollisionSolid * get_from() const
Returns the CollisionSolid pointer for the particular solid that triggered this collision.
void clear()
Empties the list of elements that all colliders are known to be colliding with.
bool has_net_tag(const string &key) const
Returns true if the indicated tag value has been defined on this node or on any ancestor node...
Defines a single collision event.
const CollisionSolid * get_into() const
Returns the CollisionSolid pointer for the particular solid was collided into.
PandaNode * get_into_node() const
Returns the node that contains the CollisionSolid that was collided into.
bool is_tangible() const
Returns whether the solid is considered 'tangible' or not.
CollisionHandlerEvent()
The default CollisionHandlerEvent will throw no events.
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...
TypeHandle is the identifier used to differentiate C++ class types.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
bool has_into() const
Returns true if the "into" solid is, in fact, a CollisionSolid, and its pointer is known (in which ca...
static int size()
Returns 3: the number of components of a LVecBase3.