Explorar el Código

better NodePath interfaces for set_collide_mask()

David Rose hace 21 años
padre
commit
895b553cdb

+ 9 - 3
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);
 }
 
 ////////////////////////////////////////////////////////////////////

+ 8 - 5
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);
   }
 }
 

+ 4 - 2
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<Texture *> Textures;
   Texture *r_find_texture(PandaNode *node, const RenderState *state,

+ 41 - 0
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

+ 4 - 0
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);