41 if (collide_cat.is_spam()) {
45 _last_colliding.swap(_current_colliding);
46 _current_colliding.clear();
55 nassertv(entry !=
nullptr);
59 bool inserted = _current_colliding.insert(entry).second;
61 if (collide_cat.is_spam()) {
65 <<
", inserted = " << inserted <<
"\n";
80 if (collide_cat.is_spam()) {
83 <<
"current_colliding has " << _current_colliding.size()
84 <<
" entries, last_colliding has " << _last_colliding.size()
88 Colliding::iterator ca, cb;
90 ca = _current_colliding.begin();
91 cb = _last_colliding.begin();
94 while (ca != _current_colliding.end() && cb != _last_colliding.end()) {
95 if (order(*ca, *cb)) {
98 throw_event_for(_in_patterns, *ca);
100 }
else if (order(*cb, *ca)) {
103 throw_event_for(_out_patterns, *cb);
107 throw_event_for(_again_patterns, *cb);
113 while (ca != _current_colliding.end()) {
116 throw_event_for(_in_patterns, *ca);
120 while (cb != _last_colliding.end()) {
123 throw_event_for(_out_patterns, *cb);
143 _last_colliding.clear();
144 _current_colliding.clear();
162 for (
const std::string &pattern : _in_patterns) {
167 for (
const std::string &pattern : _again_patterns) {
172 for (
const std::string &pattern : _out_patterns) {
183 _in_patterns.clear();
185 for (
size_t i = 0; i < num_in_patterns; ++i) {
189 _again_patterns.clear();
190 size_t num_again_patterns = scan.
get_uint32();
191 for (
size_t i = 0; i < num_again_patterns; ++i) {
195 _out_patterns.clear();
197 for (
size_t i = 0; i < num_out_patterns; ++i) {
205void CollisionHandlerEvent::
206throw_event_for(
const vector_string &patterns,
CollisionEntry *entry) {
207 vector_string::const_iterator pi;
208 for (pi = patterns.begin(); pi != patterns.end(); ++pi) {
209 throw_event_pattern(*pi, entry);
216void CollisionHandlerEvent::
217throw_event_pattern(
const string &pattern,
CollisionEntry *entry) {
218 if (pattern.empty()) {
223 for (
size_t p = 0; p < pattern.size(); ++p) {
224 if (pattern[p] ==
'%') {
226 if (p + 1 < pattern.size() && pattern[p + 1] ==
'(') {
228 size_t close = pattern.find(
')', p + 2);
229 if (close != string::npos) {
230 key = pattern.substr(p + 2, close - (p + 2));
237 string cmd = pattern.substr(p + 1, 2);
242 }
else if (cmd ==
"in") {
247 }
else if (cmd ==
"fs") {
249 (!entry->
get_from()->is_tangible() ?
'i' :
't');
251 }
else if (cmd ==
"is") {
255 }
else if (cmd ==
"ig") {
259 }
else if (cmd ==
"fh") {
264 }
else if (cmd ==
"fx") {
269 }
else if (cmd ==
"ih") {
274 }
else if (cmd ==
"ix") {
279 }
else if (cmd ==
"ft") {
282 }
else if (cmd ==
"it") {
289 <<
"Invalid symbol in event_pattern: %" << cmd <<
"\n";
296 if (!event.empty()) {
Defines a single collision event.
get_from_node
Returns the node that contains the CollisionSolid that triggered this collision.
get_into
Returns the CollisionSolid pointer for the particular solid was collided into.
bool has_into() const
Returns true if the "into" solid is, in fact, a CollisionSolid, and its pointer is known (in which ca...
get_from_node_path
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
get_into_node_path
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
get_into_node
Returns the node that contains the CollisionSolid that was collided into.
get_from
Returns the CollisionSolid pointer for the particular solid that triggered this collision.
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...
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...
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
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.
void flush()
Same as clear() except "out" events are thrown.
CollisionHandlerEvent()
The default CollisionHandlerEvent will throw no events.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
void read_datagram(DatagramIterator &source)
Restores the object state from the given datagram, previously obtained using __getstate__.
void clear()
Empties the list of elements that all colliders are known to be colliding with.
void write_datagram(Datagram &destination) const
Serializes this object, to implement pickle support.
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal.
A class to retrieve the individual data elements previously stored in a Datagram.
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
std::string get_string()
Extracts a variable-length string.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
An optional parameter associated with an event.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.