Panda3D

Loading...
Searching...
No Matches
collisionHandlerEvent.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file collisionHandlerEvent.h
10 * @author drose
11 * @date 2002-03-16
12 */
13
14#ifndef COLLISIONHANDLEREVENT_H
15#define COLLISIONHANDLEREVENT_H
16
17#include "pandabase.h"
18
19#include "collisionHandler.h"
20#include "collisionNode.h"
21#include "collisionEntry.h"
22
23#include "vector_string.h"
24#include "pointerTo.h"
25#include "extension.h"
26
27/**
28 * A specialized kind of CollisionHandler that throws an event for each
29 * collision detected. The event thrown may be based on the name of the
30 * moving object or the struck object, or both. The first parameter of the
31 * event will be a pointer to the CollisionEntry that triggered it.
32 */
33 class EXPCL_PANDA_COLLIDE CollisionHandlerEvent : public CollisionHandler {
34PUBLISHED:
35 CollisionHandlerEvent();
36
37 public:
38 virtual void begin_group();
39 virtual void add_entry(CollisionEntry *entry);
40 virtual bool end_group();
41
42PUBLISHED:
43 INLINE void clear_in_patterns();
44 INLINE void add_in_pattern(const std::string &in_pattern);
45 INLINE void set_in_pattern(const std::string &in_pattern);
46 INLINE int get_num_in_patterns() const;
47 INLINE std::string get_in_pattern(int n) const;
48 MAKE_SEQ(get_in_patterns, get_num_in_patterns, get_in_pattern);
49
50 INLINE void clear_again_patterns();
51 INLINE void add_again_pattern(const std::string &again_pattern);
52 INLINE void set_again_pattern(const std::string &again_pattern);
53 INLINE int get_num_again_patterns() const;
54 INLINE std::string get_again_pattern(int n) const;
55 MAKE_SEQ(get_again_patterns, get_num_again_patterns, get_again_pattern);
56
57 INLINE void clear_out_patterns();
58 INLINE void add_out_pattern(const std::string &out_pattern);
59 INLINE void set_out_pattern(const std::string &out_pattern);
60 INLINE int get_num_out_patterns() const;
61 INLINE std::string get_out_pattern(int n) const;
62 MAKE_SEQ(get_out_patterns, get_num_out_patterns, get_out_pattern);
63
64 MAKE_SEQ_PROPERTY(in_patterns, get_num_in_patterns, get_in_pattern);
65 MAKE_SEQ_PROPERTY(again_patterns, get_num_again_patterns, get_again_pattern);
66 MAKE_SEQ_PROPERTY(out_patterns, get_num_out_patterns, get_out_pattern);
67
68 void clear();
69 void flush();
70
71 // These help implement Python pickle support.
72 EXTENSION(PyObject *__reduce__(PyObject *self) const);
73 EXTENSION(void __setstate__(PyObject *self, vector_uchar data));
74
75 void write_datagram(Datagram &destination) const;
76 void read_datagram(DatagramIterator &source);
77
78 protected:
79 void throw_event_for(const vector_string &patterns, CollisionEntry *entry);
80 void throw_event_pattern(const std::string &pattern, CollisionEntry *entry);
81
82 vector_string _in_patterns;
83 vector_string _again_patterns;
84 vector_string _out_patterns;
85
86 int _index;
87
88 class SortEntries {
89 public:
90 INLINE bool
91 operator () (const PT(CollisionEntry) &a,
92 const PT(CollisionEntry) &b) const;
93 INLINE void operator = (const SortEntries &other);
94 };
95
96 typedef pset<PT(CollisionEntry), SortEntries> Colliding;
97 Colliding _current_colliding;
98 Colliding _last_colliding;
99
100 public:
101 static TypeHandle get_class_type() {
102 return _type_handle;
103 }
104 static void init_type() {
105 CollisionHandler::init_type();
106 register_type(_type_handle, "CollisionHandlerEvent",
107 CollisionHandler::get_class_type());
108 }
109 virtual TypeHandle get_type() const {
110 return get_class_type();
111 }
112 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
113
114 private:
115 static TypeHandle _type_handle;
116};
117
118#include "collisionHandlerEvent.I"
119
120#endif
CollisionEntry
Defines a single collision event.
Definition collisionEntry.h:42
CollisionHandlerEvent::set_out_pattern
void set_out_pattern(const std::string &out_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
Definition collisionHandlerEvent.I:195
CollisionHandlerEvent::add_out_pattern
void add_out_pattern(const std::string &out_pattern)
Adds the pattern string that indicates how the event names are generated when a collision between two...
Definition collisionHandlerEvent.I:184
CollisionHandlerEvent::get_num_again_patterns
get_num_again_patterns
Returns the number of in pattern strings that have been added.
Definition collisionHandlerEvent.h:55
CollisionHandlerEvent::clear_again_patterns
void clear_again_patterns()
Removes all of the previously-added in patterns.
Definition collisionHandlerEvent.I:114
CollisionHandlerEvent::get_again_pattern
get_again_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
Definition collisionHandlerEvent.h:55
CollisionHandlerEvent::clear_out_patterns
void clear_out_patterns()
Removes all of the previously-added in patterns.
Definition collisionHandlerEvent.I:169
CollisionHandlerEvent::add_again_pattern
void add_again_pattern(const std::string &again_pattern)
Adds the pattern string that indicates how the event names are generated when a collision between two...
Definition collisionHandlerEvent.I:131
CollisionHandlerEvent::get_out_pattern
get_out_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
Definition collisionHandlerEvent.h:62
CollisionHandlerEvent::get_num_in_patterns
get_num_in_patterns
Returns the number of in pattern strings that have been added.
Definition collisionHandlerEvent.h:48
CollisionHandlerEvent::add_in_pattern
void add_in_pattern(const std::string &in_pattern)
Adds a pattern string to the list of events that will be generated in response to a collision.
Definition collisionHandlerEvent.I:76
CollisionHandlerEvent::clear_in_patterns
void clear_in_patterns()
Removes all of the previously-added in patterns.
Definition collisionHandlerEvent.I:41
CollisionHandlerEvent::flush
void flush()
Same as clear() except "out" events are thrown.
Definition collisionHandlerEvent.cxx:151
CollisionHandlerEvent::set_in_pattern
void set_in_pattern(const std::string &in_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
Definition collisionHandlerEvent.I:87
CollisionHandlerEvent::CollisionHandlerEvent
CollisionHandlerEvent()
The default CollisionHandlerEvent will throw no events.
Definition collisionHandlerEvent.cxx:31
CollisionHandlerEvent::get_in_pattern
get_in_pattern
Returns the nth pattern string that indicates how the event names are generated for each collision de...
Definition collisionHandlerEvent.h:48
CollisionHandlerEvent::read_datagram
void read_datagram(DatagramIterator &source)
Restores the object state from the given datagram, previously obtained using __getstate__.
Definition collisionHandlerEvent.cxx:182
CollisionHandlerEvent::set_again_pattern
void set_again_pattern(const std::string &again_pattern)
This method is deprecated; it completely replaces all the in patterns that have previously been set w...
Definition collisionHandlerEvent.I:142
CollisionHandlerEvent::clear
void clear()
Empties the list of elements that all colliders are known to be colliding with.
Definition collisionHandlerEvent.cxx:142
CollisionHandlerEvent::get_num_out_patterns
get_num_out_patterns
Returns the number of in pattern strings that have been added.
Definition collisionHandlerEvent.h:62
CollisionHandlerEvent::write_datagram
void write_datagram(Datagram &destination) const
Serializes this object, to implement pickle support.
Definition collisionHandlerEvent.cxx:160
CollisionHandler::end_group
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal.
Definition collisionHandler.cxx:53
CollisionHandler::begin_group
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
Definition collisionHandler.cxx:32
CollisionHandler::add_entry
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
Definition collisionHandler.cxx:40
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
collisionEntry.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
collisionHandlerEvent.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
collisionHandler.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
collisionNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
extension.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22
vector_string.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.