00001 // Filename: collisionHandlerEvent.h 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef COLLISIONHANDLEREVENT_H 00020 #define COLLISIONHANDLEREVENT_H 00021 00022 #include "pandabase.h" 00023 00024 #include "collisionHandler.h" 00025 #include "collisionNode.h" 00026 #include "collisionEntry.h" 00027 00028 #include "pointerTo.h" 00029 00030 /////////////////////////////////////////////////////////////////// 00031 // Class : CollisionHandlerEvent 00032 // Description : A specialized kind of CollisionHandler that throws an 00033 // event for each collision detected. The event thrown 00034 // may be based on the name of the moving object or the 00035 // struck object, or both. The first parameter of the 00036 // event will be a pointer to the CollisionEntry that 00037 // triggered it. 00038 //////////////////////////////////////////////////////////////////// 00039 class EXPCL_PANDA CollisionHandlerEvent : public CollisionHandler { 00040 PUBLISHED: 00041 CollisionHandlerEvent(); 00042 00043 public: 00044 virtual void begin_group(); 00045 virtual void add_entry(CollisionEntry *entry); 00046 virtual bool end_group(); 00047 00048 PUBLISHED: 00049 INLINE void set_in_pattern(const string &pattern); 00050 INLINE string get_in_pattern() const; 00051 INLINE void set_again_pattern(const string &pattern); 00052 INLINE string get_again_pattern() const; 00053 INLINE void set_out_pattern(const string &pattern); 00054 INLINE string get_out_pattern() const; 00055 00056 void clear(); 00057 00058 private: 00059 void throw_event_pattern(const string &pattern, CollisionEntry *entry); 00060 00061 string _in_pattern; 00062 string _again_pattern; 00063 string _out_pattern; 00064 00065 int _index; 00066 00067 class SortEntries { 00068 public: 00069 INLINE bool 00070 operator () (const PT(CollisionEntry) &a, 00071 const PT(CollisionEntry) &b) const; 00072 INLINE void operator = (const SortEntries &other); 00073 }; 00074 00075 typedef pset<PT(CollisionEntry), SortEntries> Colliding; 00076 Colliding _current_colliding; 00077 Colliding _last_colliding; 00078 00079 public: 00080 static TypeHandle get_class_type() { 00081 return _type_handle; 00082 } 00083 static void init_type() { 00084 CollisionHandler::init_type(); 00085 register_type(_type_handle, "CollisionHandlerEvent", 00086 CollisionHandler::get_class_type()); 00087 } 00088 virtual TypeHandle get_type() const { 00089 return get_class_type(); 00090 } 00091 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00092 00093 private: 00094 static TypeHandle _type_handle; 00095 }; 00096 00097 #include "collisionHandlerEvent.I" 00098 00099 #endif 00100 00101 00102