Panda3D
collisionHandlerEvent.h
1 // Filename: collisionHandlerEvent.h
2 // Created by: drose (16Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef COLLISIONHANDLEREVENT_H
16 #define COLLISIONHANDLEREVENT_H
17 
18 #include "pandabase.h"
19 
20 #include "collisionHandler.h"
21 #include "collisionNode.h"
22 #include "collisionEntry.h"
23 
24 #include "vector_string.h"
25 #include "pointerTo.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : CollisionHandlerEvent
29 // Description : A specialized kind of CollisionHandler that throws an
30 // event for each collision detected. The event thrown
31 // may be based on the name of the moving object or the
32 // struck object, or both. The first parameter of the
33 // event will be a pointer to the CollisionEntry that
34 // triggered it.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDA_COLLIDE CollisionHandlerEvent : public CollisionHandler {
37 PUBLISHED:
39 
40 public:
41  virtual void begin_group();
42  virtual void add_entry(CollisionEntry *entry);
43  virtual bool end_group();
44 
45 PUBLISHED:
46  INLINE void clear_in_patterns();
47  INLINE void add_in_pattern(const string &in_pattern);
48  INLINE void set_in_pattern(const string &in_pattern);
49  INLINE int get_num_in_patterns() const;
50  INLINE string get_in_pattern(int n) const;
51  MAKE_SEQ(get_in_patterns, get_num_in_patterns, get_in_pattern);
52 
53  INLINE void clear_again_patterns();
54  INLINE void add_again_pattern(const string &again_pattern);
55  INLINE void set_again_pattern(const string &again_pattern);
56  INLINE int get_num_again_patterns() const;
57  INLINE string get_again_pattern(int n) const;
58  MAKE_SEQ(get_again_patterns, get_num_again_patterns, get_again_pattern);
59 
60  INLINE void clear_out_patterns();
61  INLINE void add_out_pattern(const string &out_pattern);
62  INLINE void set_out_pattern(const string &out_pattern);
63  INLINE int get_num_out_patterns() const;
64  INLINE string get_out_pattern(int n) const;
65  MAKE_SEQ(get_out_patterns, get_num_out_patterns, get_out_pattern);
66 
67  void clear();
68  void flush();
69 
70 protected:
71  void throw_event_for(const vector_string &patterns, CollisionEntry *entry);
72  void throw_event_pattern(const string &pattern, CollisionEntry *entry);
73 
74  vector_string _in_patterns;
75  vector_string _again_patterns;
76  vector_string _out_patterns;
77 
78  int _index;
79 
80  class SortEntries {
81  public:
82  INLINE bool
83  operator () (const PT(CollisionEntry) &a,
84  const PT(CollisionEntry) &b) const;
85  INLINE void operator = (const SortEntries &other);
86  };
87 
89  Colliding _current_colliding;
90  Colliding _last_colliding;
91 
92 public:
93  static TypeHandle get_class_type() {
94  return _type_handle;
95  }
96  static void init_type() {
97  CollisionHandler::init_type();
98  register_type(_type_handle, "CollisionHandlerEvent",
99  CollisionHandler::get_class_type());
100  }
101  virtual TypeHandle get_type() const {
102  return get_class_type();
103  }
104  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
105 
106 private:
107  static TypeHandle _type_handle;
108 };
109 
110 #include "collisionHandlerEvent.I"
111 
112 #endif
113 
114 
115 
The abstract interface to a number of classes that decide what to do when a collision is detected...
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal...
Defines a single collision event.
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
A specialized kind of CollisionHandler that throws an event for each collision detected.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85