diff --git a/panda/src/collide/collisionHandlerEvent.I b/panda/src/collide/collisionHandlerEvent.I index 045ad796e6..735c7a1d41 100644 --- a/panda/src/collide/collisionHandlerEvent.I +++ b/panda/src/collide/collisionHandlerEvent.I @@ -50,6 +50,14 @@ operator = (const CollisionHandlerEvent::SortEntries &) { // The event name will be based on the in_pattern // string specified here, with all occurrences of the // above strings replaced with the corresponding values. +// +// In general, the in_pattern event is thrown on the +// first detection of a collision between two particular +// nodes. In subsequent passes, as long as a collision +// between those two nodes continues to be detected each +// frame, the again_pattern is thrown. The first frame +// in which the collision is no longer detected, the +// out_pattern event is thrown. //////////////////////////////////////////////////////////////////// INLINE void CollisionHandlerEvent:: set_in_pattern(const string &in_pattern) { @@ -68,6 +76,42 @@ get_in_pattern() const { return _in_pattern; } +//////////////////////////////////////////////////////////////////// +// Function: CollisionHandlerEvent::set_again_pattern +// Access: Public +// Description: Sets the pattern string that indicates how the event +// names are generated when a collision between two +// particular nodes is *still* detected. This event is +// each consecutive time a collision between two +// particular nodes is detected, starting with the +// second time. +// +// In general, the in_pattern event is thrown on the +// first detection of a collision between two particular +// nodes. In subsequent passes, as long as a collision +// between those two nodes continues to be detected each +// frame, the again_pattern is thrown. The first frame +// in which the collision is no longer detected, the +// out_pattern event is thrown. +//////////////////////////////////////////////////////////////////// +INLINE void CollisionHandlerEvent:: +set_again_pattern(const string &again_pattern) { + _again_pattern = again_pattern; +} + +//////////////////////////////////////////////////////////////////// +// Function: CollisionHandlerEvent::get_again_pattern +// Access: Public +// Description: Returns the pattern string that indicates how the +// event names are generated when a collision between +// two particular nodes is *still* detected. See +// set_again_pattern() and set_in_pattern(). +//////////////////////////////////////////////////////////////////// +INLINE string CollisionHandlerEvent:: +get_again_pattern() const { + return _again_pattern; +} + //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerEvent::set_out_pattern @@ -78,12 +122,11 @@ get_in_pattern() const { // // In general, the in_pattern event is thrown on the // first detection of a collision between two particular -// nodes. Thereafter, as long as a collision between -// those two nodes continues to be detected each frame, -// no further events (associated with this particular -// pair of nodes) are thrown. The first frame in which -// the collision is no longer detected, the out_pattern -// event is thrown. +// nodes. In subsequent passes, as long as a collision +// between those two nodes continues to be detected each +// frame, the again_pattern is thrown. The first frame +// in which the collision is no longer detected, the +// out_pattern event is thrown. //////////////////////////////////////////////////////////////////// INLINE void CollisionHandlerEvent:: set_out_pattern(const string &out_pattern) { diff --git a/panda/src/collide/collisionHandlerEvent.cxx b/panda/src/collide/collisionHandlerEvent.cxx index 84a6b41165..69d13ac161 100644 --- a/panda/src/collide/collisionHandlerEvent.cxx +++ b/panda/src/collide/collisionHandlerEvent.cxx @@ -105,6 +105,7 @@ end_group() { } else { // This element is in both b and a. It hasn't changed. + throw_event_pattern(_again_pattern, *cb); ++ca; ++cb; } @@ -125,6 +126,27 @@ end_group() { } } +//////////////////////////////////////////////////////////////////// +// Function: CollisionHandlerEvent::clear +// Access: Public +// Description: Empties the list of elements that all colliders are +// known to be colliding with. No "out" events will be +// thrown; if the same collision is detected next frame, +// a new "in" event will be thrown for each collision. +// +// This can be called each frame to defeat the +// persistant "in" event mechanism, which prevents the +// same "in" event from being thrown repeatedly. +// However, also see set_again_pattern(), which can be +// used to set the event that is thrown when a collision +// is detected for more than one consecutive frames. +//////////////////////////////////////////////////////////////////// +void CollisionHandlerEvent:: +clear() { + _last_colliding.clear(); + _current_colliding.clear(); +} + //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerEvent::throw_event_pattern // Access: Private diff --git a/panda/src/collide/collisionHandlerEvent.h b/panda/src/collide/collisionHandlerEvent.h index cf0a687dad..22c95d6a6c 100644 --- a/panda/src/collide/collisionHandlerEvent.h +++ b/panda/src/collide/collisionHandlerEvent.h @@ -35,13 +35,18 @@ public: PUBLISHED: INLINE void set_in_pattern(const string &pattern); INLINE string get_in_pattern() const; + INLINE void set_again_pattern(const string &pattern); + INLINE string get_again_pattern() const; INLINE void set_out_pattern(const string &pattern); INLINE string get_out_pattern() const; + void clear(); + private: void throw_event_pattern(const string &pattern, CollisionEntry *entry); string _in_pattern; + string _again_pattern; string _out_pattern; int _index;