From 7086723c67113e6db5bf3ebde137b0396945bfba Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 10 Dec 2003 00:31:07 +0000 Subject: [PATCH] throw on-floor events only for topmost object --- panda/src/collide/collisionHandlerEvent.h | 2 +- panda/src/collide/collisionHandlerFloor.cxx | 13 ++++++++++++- panda/src/collide/collisionHandlerPhysical.cxx | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/panda/src/collide/collisionHandlerEvent.h b/panda/src/collide/collisionHandlerEvent.h index a7d3d91f86..51e6248543 100644 --- a/panda/src/collide/collisionHandlerEvent.h +++ b/panda/src/collide/collisionHandlerEvent.h @@ -67,7 +67,7 @@ PUBLISHED: void clear(); -private: +protected: void throw_event_for(const vector_string &patterns, CollisionEntry *entry); void throw_event_pattern(const string &pattern, CollisionEntry *entry); diff --git a/panda/src/collide/collisionHandlerFloor.cxx b/panda/src/collide/collisionHandlerFloor.cxx index e9e66291e7..8fa1a363a2 100644 --- a/panda/src/collide/collisionHandlerFloor.cxx +++ b/panda/src/collide/collisionHandlerFloor.cxx @@ -60,6 +60,11 @@ bool CollisionHandlerFloor:: handle_entries() { bool okflag = true; + // Reset the set of things our parent class CollisionHandlerEvent + // recorded a collision with. We'll only consider ourselves + // collided with the topmost object for each from_entry. + _current_colliding.clear(); + FromEntries::const_iterator fi; for (fi = _from_entries.begin(); fi != _from_entries.end(); ++fi) { const NodePath &from_node_path = (*fi).first; @@ -81,6 +86,7 @@ handle_entries() { // Get the maximum height for all collisions with this node. bool got_max = false; float max_height = 0.0f; + CollisionEntry *max_entry = NULL; Entries::const_iterator ei; for (ei = entries.begin(); ei != entries.end(); ++ei) { @@ -99,10 +105,15 @@ handle_entries() { if (!got_max || height > max_height) { got_max = true; max_height = height; + max_entry = entry; } } } - + + // Record a collision with the topmost element for the + // CollisionHandlerEvent base class. + _current_colliding.insert(max_entry); + // Now set our height accordingly. float adjust = max_height + _offset; if (!IS_THRESHOLD_ZERO(adjust, 0.001)) { diff --git a/panda/src/collide/collisionHandlerPhysical.cxx b/panda/src/collide/collisionHandlerPhysical.cxx index d3d6eea49c..e784290fa3 100644 --- a/panda/src/collide/collisionHandlerPhysical.cxx +++ b/panda/src/collide/collisionHandlerPhysical.cxx @@ -83,9 +83,10 @@ add_entry(CollisionEntry *entry) { //////////////////////////////////////////////////////////////////// bool CollisionHandlerPhysical:: end_group() { + bool result = handle_entries(); CollisionHandlerEvent::end_group(); - return handle_entries(); + return result; } ////////////////////////////////////////////////////////////////////