From 895b553cdbbf0520bcb949a8a7f195b08287b930 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 23 Sep 2004 20:57:34 +0000 Subject: [PATCH] better NodePath interfaces for set_collide_mask() --- panda/src/pgraph/nodePath.I | 12 ++++++-- panda/src/pgraph/nodePath.cxx | 13 +++++--- panda/src/pgraph/nodePath.h | 6 ++-- panda/src/pgraph/nodePathCollection.cxx | 41 +++++++++++++++++++++++++ panda/src/pgraph/nodePathCollection.h | 4 +++ 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/panda/src/pgraph/nodePath.I b/panda/src/pgraph/nodePath.I index c8b382e5c7..aa07e1143a 100644 --- a/panda/src/pgraph/nodePath.I +++ b/panda/src/pgraph/nodePath.I @@ -1475,7 +1475,7 @@ get_collide_mask() const { // Access: Published // Description: Recursively applies the indicated CollideMask to the // into_collide_masks for all nodes at this level and -// below. +// below. Only nodes // // The default is to change all bits, but if // bits_to_change is not all bits on, then only the bits @@ -1484,9 +1484,15 @@ get_collide_mask() const { // subgraph. //////////////////////////////////////////////////////////////////// INLINE void NodePath:: -set_collide_mask(CollideMask new_mask, CollideMask bits_to_change) { +set_collide_mask(CollideMask new_mask, CollideMask bits_to_change, + TypeHandle node_type) { nassertv_always(!is_empty()); - r_set_collide_mask(node(), ~bits_to_change, new_mask & bits_to_change); + if (node_type == TypeHandle::none()) { + node_type = PandaNode::get_class_type(); + } + + r_set_collide_mask(node(), ~bits_to_change, new_mask & bits_to_change, + node_type); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index 4a5e907212..ea1b219678 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -4952,15 +4952,18 @@ r_force_recompute_bounds(PandaNode *node) { //////////////////////////////////////////////////////////////////// void NodePath:: r_set_collide_mask(PandaNode *node, - CollideMask and_mask, CollideMask or_mask) { - CollideMask into_collide_mask = node->get_into_collide_mask(); - into_collide_mask = (into_collide_mask & and_mask) | or_mask; - node->set_into_collide_mask(into_collide_mask); + CollideMask and_mask, CollideMask or_mask, + TypeHandle node_type) { + if (node->is_of_type(node_type)) { + CollideMask into_collide_mask = node->get_into_collide_mask(); + into_collide_mask = (into_collide_mask & and_mask) | or_mask; + node->set_into_collide_mask(into_collide_mask); + } PandaNode::Children cr = node->get_children(); int num_children = cr.get_num_children(); for (int i = 0; i < num_children; i++) { - r_set_collide_mask(cr.get_child(i), and_mask, or_mask); + r_set_collide_mask(cr.get_child(i), and_mask, or_mask, node_type); } } diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index 1414106ff5..f079648cfe 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -648,7 +648,8 @@ PUBLISHED: NodePath get_stashed_ancestor() const; INLINE CollideMask get_collide_mask() const; - INLINE void set_collide_mask(CollideMask new_mask, CollideMask bits_to_change = CollideMask::all_on()); + INLINE void set_collide_mask(CollideMask new_mask, CollideMask bits_to_change = CollideMask::all_on(), + TypeHandle node_type = TypeHandle::none()); // Comparison methods INLINE bool operator == (const NodePath &other) const; @@ -712,7 +713,8 @@ private: void r_force_recompute_bounds(PandaNode *node); void r_set_collide_mask(PandaNode *node, - CollideMask and_mask, CollideMask or_mask); + CollideMask and_mask, CollideMask or_mask, + TypeHandle node_type); typedef pset Textures; Texture *r_find_texture(PandaNode *node, const RenderState *state, diff --git a/panda/src/pgraph/nodePathCollection.cxx b/panda/src/pgraph/nodePathCollection.cxx index fbba390849..68f7c0e14c 100644 --- a/panda/src/pgraph/nodePathCollection.cxx +++ b/panda/src/pgraph/nodePathCollection.cxx @@ -380,6 +380,47 @@ detach() { } } +//////////////////////////////////////////////////////////////////// +// Function: NodePathCollection::get_collide_mask +// Access: Published +// Description: Returns the union of all of the into_collide_masks +// for nodes at this level and below. This is the same +// thing as node()->get_net_collide_mask(). +// +// If you want to return what the into_collide_mask of +// this node itself is, without regard to its children, +// use node()->get_into_collide_mask(). +//////////////////////////////////////////////////////////////////// +CollideMask NodePathCollection:: +get_collide_mask() const { + CollideMask collide_mask; + for (int i = 0; i < get_num_paths(); i++) { + collide_mask |= get_path(i).get_collide_mask(); + } + return collide_mask; +} + +//////////////////////////////////////////////////////////////////// +// Function: NodePathCollection::set_collide_mask +// Access: Published +// Description: Recursively applies the indicated CollideMask to the +// into_collide_masks for all nodes at this level and +// below. Only nodes +// +// The default is to change all bits, but if +// bits_to_change is not all bits on, then only the bits +// that are set in bits_to_change are modified, allowing +// this call to change only a subset of the bits in the +// subgraph. +//////////////////////////////////////////////////////////////////// +void NodePathCollection:: +set_collide_mask(CollideMask new_mask, CollideMask bits_to_change, + TypeHandle node_type) { + for (int i = 0; i < get_num_paths(); i++) { + get_path(i).set_collide_mask(new_mask, bits_to_change, node_type); + } +} + //////////////////////////////////////////////////////////////////// // Function: NodePathCollection::set_color // Access: Published diff --git a/panda/src/pgraph/nodePathCollection.h b/panda/src/pgraph/nodePathCollection.h index 41b7ac2afe..f025f55597 100644 --- a/panda/src/pgraph/nodePathCollection.h +++ b/panda/src/pgraph/nodePathCollection.h @@ -64,6 +64,10 @@ PUBLISHED: void unstash(); void detach(); + CollideMask get_collide_mask() const; + void set_collide_mask(CollideMask new_mask, CollideMask bits_to_change = CollideMask::all_on(), + TypeHandle node_type = TypeHandle::none()); + void set_color(float r, float g, float b, float a = 1.0, int priority = 0); void set_color(const Colorf &color, int priority = 0);