Panda3D
 All Classes Functions Variables Enumerations
collisionHandlerEvent.h
00001 // Filename: collisionHandlerEvent.h
00002 // Created by:  drose (16Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef COLLISIONHANDLEREVENT_H
00016 #define COLLISIONHANDLEREVENT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "collisionHandler.h"
00021 #include "collisionNode.h"
00022 #include "collisionEntry.h"
00023 
00024 #include "vector_string.h"
00025 #include "pointerTo.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : CollisionHandlerEvent
00029 // Description : A specialized kind of CollisionHandler that throws an
00030 //               event for each collision detected.  The event thrown
00031 //               may be based on the name of the moving object or the
00032 //               struck object, or both.  The first parameter of the
00033 //               event will be a pointer to the CollisionEntry that
00034 //               triggered it.
00035 ////////////////////////////////////////////////////////////////////
00036 class EXPCL_PANDA_COLLIDE CollisionHandlerEvent : public CollisionHandler {
00037 PUBLISHED:
00038   CollisionHandlerEvent();
00039 
00040 public:
00041   virtual void begin_group();
00042   virtual void add_entry(CollisionEntry *entry);
00043   virtual bool end_group();
00044 
00045 PUBLISHED:
00046   INLINE void clear_in_patterns();
00047   INLINE void add_in_pattern(const string &in_pattern);
00048   INLINE void set_in_pattern(const string &in_pattern);
00049   INLINE int get_num_in_patterns() const;
00050   INLINE string get_in_pattern(int n) const;
00051   MAKE_SEQ(get_in_patterns, get_num_in_patterns, get_in_pattern);
00052 
00053   INLINE void clear_again_patterns();
00054   INLINE void add_again_pattern(const string &again_pattern);
00055   INLINE void set_again_pattern(const string &again_pattern);
00056   INLINE int get_num_again_patterns() const;
00057   INLINE string get_again_pattern(int n) const;
00058   MAKE_SEQ(get_again_patterns, get_num_again_patterns, get_again_pattern);
00059 
00060   INLINE void clear_out_patterns();
00061   INLINE void add_out_pattern(const string &out_pattern);
00062   INLINE void set_out_pattern(const string &out_pattern);
00063   INLINE int get_num_out_patterns() const;
00064   INLINE string get_out_pattern(int n) const;
00065   MAKE_SEQ(get_out_patterns, get_num_out_patterns, get_out_pattern);
00066 
00067   void clear();
00068   void flush();
00069 
00070 protected:
00071   void throw_event_for(const vector_string &patterns, CollisionEntry *entry);
00072   void throw_event_pattern(const string &pattern, CollisionEntry *entry);
00073 
00074   vector_string _in_patterns;
00075   vector_string _again_patterns;
00076   vector_string _out_patterns;
00077 
00078   int _index;
00079 
00080   class SortEntries {
00081   public:
00082     INLINE bool
00083     operator () (const PT(CollisionEntry) &a,
00084                  const PT(CollisionEntry) &b) const;
00085     INLINE void operator = (const SortEntries &other);
00086   };
00087 
00088   typedef pset<PT(CollisionEntry), SortEntries> Colliding;
00089   Colliding _current_colliding;
00090   Colliding _last_colliding;
00091 
00092 public:
00093   static TypeHandle get_class_type() {
00094     return _type_handle;
00095   }
00096   static void init_type() {
00097     CollisionHandler::init_type();
00098     register_type(_type_handle, "CollisionHandlerEvent",
00099                   CollisionHandler::get_class_type());
00100   }
00101   virtual TypeHandle get_type() const {
00102     return get_class_type();
00103   }
00104   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00105 
00106 private:
00107   static TypeHandle _type_handle;
00108 };
00109 
00110 #include "collisionHandlerEvent.I"
00111 
00112 #endif
00113 
00114 
00115 
 All Classes Functions Variables Enumerations