Bläddra i källkod

fix pgraph collisions

David Rose 24 år sedan
förälder
incheckning
fe30a13f72

+ 4 - 4
panda/src/collide/qpcollisionHandlerPhysical.cxx

@@ -130,7 +130,7 @@ end_group() {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: qpCollisionHandlerPhysical::add_collider
+//     Function: qpCollisionHandlerPhysical::add_collider_drive
 //       Access: Public
 //  Description: Adds a new collider to the list with a qpDriveInterface
 //               pointer that needs to be told about the collider's
@@ -138,12 +138,12 @@ end_group() {
 //               new qpDriveInterface pointer.
 ////////////////////////////////////////////////////////////////////
 void qpCollisionHandlerPhysical::
-add_collider(qpCollisionNode *node, qpDriveInterface *drive_interface) {
+add_collider_drive(qpCollisionNode *node, qpDriveInterface *drive_interface) {
   _colliders[node].set_drive_interface(drive_interface);
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: qpCollisionHandlerPhysical::add_collider
+//     Function: qpCollisionHandlerPhysical::add_collider_node
 //       Access: Public
 //  Description: Adds a new collider to the list with a PandaNode
 //               pointer that will be updated with the collider's
@@ -151,7 +151,7 @@ add_collider(qpCollisionNode *node, qpDriveInterface *drive_interface) {
 //               new PandaNode pointer.
 ////////////////////////////////////////////////////////////////////
 void qpCollisionHandlerPhysical::
-add_collider(qpCollisionNode *node, PandaNode *target) {
+add_collider_node(qpCollisionNode *node, PandaNode *target) {
   _colliders[node].set_node(target);
 }
 

+ 2 - 2
panda/src/collide/qpcollisionHandlerPhysical.h

@@ -45,8 +45,8 @@ public:
   virtual bool end_group();
 
 PUBLISHED:
-  void add_collider(qpCollisionNode *node, qpDriveInterface *drive_interface);
-  void add_collider(qpCollisionNode *node, PandaNode *target);
+  void add_collider_drive(qpCollisionNode *node, qpDriveInterface *drive_interface);
+  void add_collider_node(qpCollisionNode *node, PandaNode *target);
   bool remove_collider(qpCollisionNode *node);
   bool has_collider(qpCollisionNode *node) const;
   void clear_colliders();

+ 1 - 1
panda/src/collide/qpcollisionTraverser.cxx

@@ -236,7 +236,7 @@ traverse(const qpNodePath &root) {
     (*hi).first->begin_group();
   }
 
-  //  r_traverse(root.node(), level_state);
+  r_traverse(root.node(), level_state);
 
   hi = _handlers.begin();
   while (hi != _handlers.end()) {

+ 2 - 0
panda/src/egg2pg/Sources.pp

@@ -15,6 +15,7 @@
     computedVerticesMaker.I computedVerticesMaker.h \
     computedVerticesMakerEntity.I computedVerticesMakerEntity.h \
     config_egg2pg.h \
+    deferredNodeProperty.h \
     eggBinner.h \
     eggLoaderBase.h \
     qpeggLoader.h \
@@ -26,6 +27,7 @@
     qpcharacterMaker.cxx \
     computedVerticesMaker.cxx \
     config_egg2pg.cxx \
+    deferredNodeProperty.cxx \
     eggBinner.cxx \
     qpeggLoader.cxx \
     qpload_egg_file.cxx

+ 95 - 0
panda/src/egg2pg/deferredNodeProperty.cxx

@@ -0,0 +1,95 @@
+// Filename: deferredNodeProperty.cxx
+// Created by:  drose (20Mar02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "deferredNodeProperty.h"
+
+#include "qpcollisionNode.h"
+#include "pandaNode.h"
+
+////////////////////////////////////////////////////////////////////
+//     Function: DeferredNodeProperty::Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+DeferredNodeProperty::
+DeferredNodeProperty() {
+  _flags = 0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DeferredNodeProperty::Copy Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+DeferredNodeProperty::
+DeferredNodeProperty(const DeferredNodeProperty &copy) :
+  _flags(copy._flags),
+  _from_collide_mask(copy._from_collide_mask),
+  _into_collide_mask(copy._into_collide_mask)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DeferredNodeProperty::Copy Assignment
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+void DeferredNodeProperty::
+operator = (const DeferredNodeProperty &copy) {
+  _flags = copy._flags;
+  _from_collide_mask = copy._from_collide_mask;
+  _into_collide_mask = copy._into_collide_mask;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DeferredNodeProperty::compose
+//       Access: Public
+//  Description: Composes this state with the next one encountered on
+//               a lower node during the apply traversal.
+////////////////////////////////////////////////////////////////////
+void DeferredNodeProperty::
+compose(const DeferredNodeProperty &other) {
+  _flags |= other._flags;
+
+  if ((other._flags & F_has_from_collide_mask) != 0) {
+    _from_collide_mask = other._from_collide_mask;
+  }
+
+  if ((other._flags & F_has_into_collide_mask) != 0) {
+    _into_collide_mask = other._into_collide_mask;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DeferredNodeProperty::apply_to_node
+//       Access: Public
+//  Description: Applies whatever state is appropriate to the node.
+////////////////////////////////////////////////////////////////////
+void DeferredNodeProperty::
+apply_to_node(PandaNode *node) {
+  if (node->is_of_type(qpCollisionNode::get_class_type())) {
+    qpCollisionNode *cnode = DCAST(qpCollisionNode, node);
+    if ((_flags & F_has_from_collide_mask) != 0) {
+      cnode->set_from_collide_mask(_from_collide_mask);
+    }
+    if ((_flags & F_has_into_collide_mask) != 0) {
+      cnode->set_into_collide_mask(_into_collide_mask);
+    }
+  }
+}
+

+ 66 - 0
panda/src/egg2pg/deferredNodeProperty.h

@@ -0,0 +1,66 @@
+// Filename: deferredNodeProperty.h
+// Created by:  drose (20Mar02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef DEFERREDNODEPROPERTY_H
+#define DEFERREDNODEPROPERTY_H
+
+#include "pandabase.h"
+
+#include "collideMask.h"
+#include "pmap.h"
+
+class PandaNode;
+
+///////////////////////////////////////////////////////////////////
+//       Class : DeferredNodeProperty
+// Description : This class keeps track of all the state we must make
+//               note of during the graph traversal, but cannot apply
+//               immediately.  An instance of this class may be
+//               assigned to nodes as they are created, and then later,
+//               after the geometry has been created, the graph will
+//               be traversed again and the state will be applied.
+//
+//               This class is only local to this package; it is not
+//               exported.
+////////////////////////////////////////////////////////////////////
+class DeferredNodeProperty {
+public:
+  DeferredNodeProperty();
+  DeferredNodeProperty(const DeferredNodeProperty &copy);
+  void operator = (const DeferredNodeProperty &copy);
+
+  void compose(const DeferredNodeProperty &other);
+
+  void apply_to_node(PandaNode *node);
+
+
+public:
+  enum Flags {
+    F_has_from_collide_mask   = 0x0001,
+    F_has_into_collide_mask   = 0x0002,
+  };
+
+  int _flags;
+  CollideMask _from_collide_mask;
+  CollideMask _into_collide_mask;
+};
+
+typedef pmap<PandaNode *, DeferredNodeProperty> DeferredNodes;
+
+
+#endif

+ 1 - 0
panda/src/egg2pg/egg2pg_composite1.cxx

@@ -2,3 +2,4 @@
 #include "characterMaker.cxx"
 #include "qpcharacterMaker.cxx"
 #include "computedVerticesMaker.cxx"
+#include "config_egg2pg.cxx"

+ 1 - 1
panda/src/egg2pg/egg2pg_composite2.cxx

@@ -1,4 +1,4 @@
-#include "config_egg2pg.cxx"
+#include "deferredNodeProperty.cxx"
 #include "eggBinner.cxx"
 #include "qpeggLoader.cxx"
 #include "qpload_egg_file.cxx"

+ 29 - 19
panda/src/egg2pg/qpeggLoader.cxx

@@ -125,7 +125,7 @@ qpEggLoader(const EggData &data) :
 ////////////////////////////////////////////////////////////////////
 void qpEggLoader::
 build_graph() {
-  //  _deferred_arcs.clear();
+  _deferred_nodes.clear();
 
   // First, bin up the LOD nodes.
   EggBinner binner;
@@ -141,7 +141,7 @@ build_graph() {
 
   reparent_decals();
 
-  //  apply_deferred_arcs(_root);
+  apply_deferred_nodes(_root, DeferredNodeProperty());
 }
 
 
@@ -1453,31 +1453,29 @@ create_group_arc(EggGroup *egg_group, PandaNode *parent, PandaNode *node) {
     _decals.insert(node);
   }
 
-  /*
   // If the group specified some property that should propagate down
-  // to the leaves, we have to remember this arc and apply the
+  // to the leaves, we have to remember this node and apply the
   // property later, after we've created the actual geometry.
-  DeferredArcProperty def;
+  DeferredNodeProperty def;
   if (egg_group->has_collide_mask()) {
     def._from_collide_mask = egg_group->get_collide_mask();
     def._into_collide_mask = egg_group->get_collide_mask();
     def._flags |=
-      DeferredArcProperty::F_has_from_collide_mask |
-      DeferredArcProperty::F_has_into_collide_mask;
+      DeferredNodeProperty::F_has_from_collide_mask |
+      DeferredNodeProperty::F_has_into_collide_mask;
   }
   if (egg_group->has_from_collide_mask()) {
     def._from_collide_mask = egg_group->get_from_collide_mask();
-    def._flags |= DeferredArcProperty::F_has_from_collide_mask;
+    def._flags |= DeferredNodeProperty::F_has_from_collide_mask;
   }
   if (egg_group->has_into_collide_mask()) {
     def._into_collide_mask = egg_group->get_into_collide_mask();
-    def._flags |= DeferredArcProperty::F_has_into_collide_mask;
+    def._flags |= DeferredNodeProperty::F_has_into_collide_mask;
   }
 
   if (def._flags != 0) {
-    _deferred_arcs[arc] = def;
+    _deferred_nodes[node] = def;
   }
-  */
 
   return node;
 }
@@ -1884,19 +1882,31 @@ create_collision_polygons(qpCollisionNode *cnode, EggPolygon *egg_poly,
 }
 
 
-/*
 ////////////////////////////////////////////////////////////////////
-//     Function: qpEggLoader::apply_deferred_arcs
+//     Function: qpEggLoader::apply_deferred_nodes
 //       Access: Private
 //  Description: Walks back over the tree and applies the
-//               DeferredArcProperties that were saved up along the
+//               DeferredNodeProperties that were saved up along the
 //               way.
 ////////////////////////////////////////////////////////////////////
 void qpEggLoader::
-apply_deferred_arcs(Node *root) {
-  DeferredArcTraverser trav(_deferred_arcs);
+apply_deferred_nodes(PandaNode *node, const DeferredNodeProperty &prop) {
+  DeferredNodeProperty next_prop(prop);
 
-  df_traverse(root, trav, NullAttribWrapper(), DeferredArcProperty(),
-              PandaNode::get_class_type());
+  // Do we have a DeferredNodeProperty associated with this node?
+  DeferredNodes::const_iterator dni;
+  dni = _deferred_nodes.find(node);
+
+  if (dni != _deferred_nodes.end()) {
+    const DeferredNodeProperty &def = (*dni).second;
+    next_prop.compose(def);
+  }
+
+  // Now apply the accumulated state to the node.
+  next_prop.apply_to_node(node);
+
+  int num_children = node->get_num_children();
+  for (int i = 0; i < num_children; i++) {
+    apply_deferred_nodes(node->get_child(i), next_prop);
+  }
 }
-*/

+ 4 - 9
panda/src/egg2pg/qpeggLoader.h

@@ -21,6 +21,8 @@
 
 #include "pandabase.h"
 
+#include "eggLoaderBase.h"
+#include "deferredNodeProperty.h"
 #include "eggData.h"
 #include "eggTexture.h"
 #include "pt_EggTexture.h"
@@ -35,8 +37,6 @@
 #include "indirectCompareTo.h"
 #include "textureAttrib.h"
 
-#include "eggLoaderBase.h"
-
 class EggNode;
 class EggBin;
 class EggTable;
@@ -121,10 +121,7 @@ private:
                                  EggGroup *parent_group,
                                  EggGroup::CollideFlags flags);
 
-  /*
-  void apply_deferred_arcs(PandaNode *root);
-  */
-
+  void apply_deferred_nodes(PandaNode *node, const DeferredNodeProperty &prop);
 
   Builder _builder;
 
@@ -138,9 +135,7 @@ private:
   typedef pset<PandaNode *> Decals;
   Decals _decals;
 
-  /*
-  DeferredArcs _deferred_arcs;
-  */
+  DeferredNodes _deferred_nodes;
 
 public:
   PT(PandaNode) _root;

+ 2 - 0
panda/src/pgraph/workingNodePath.I

@@ -28,6 +28,7 @@
 INLINE WorkingNodePath::
 WorkingNodePath(const qpNodePath &start) {
   nassertv(!start.is_empty());
+  _next = (WorkingNodePath *)NULL;
   _start = start._head;
   _node = start.node();
 }
@@ -43,6 +44,7 @@ WorkingNodePath(const qpNodePath &start) {
 INLINE WorkingNodePath::
 WorkingNodePath(const WorkingNodePath &parent, PandaNode *child) {
   _next = &parent;
+  _start = (qpNodePathComponent *)NULL;
   _node = child;
 }
 

+ 0 - 26
panda/src/tform/qpdriveInterface.I

@@ -498,29 +498,3 @@ INLINE bool qpDriveInterface::
 get_force_mouse() const {
   return _force_mouse;
 }
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: qpDriveInterface::set_mat
-//       Access: Published
-//  Description: Stores the indicated transform in the qpDriveInterface.
-//               This is a transform in global space, regardless of
-//               the rel_to node.
-////////////////////////////////////////////////////////////////////
-INLINE void qpDriveInterface::
-set_mat(const LMatrix4f &mat) {
-  _mat = mat;
-  reextract();
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: qpDriveInterface::get_mat
-//       Access: Published
-//  Description: Fills mat with the net transformation applied by the
-//               current state.
-////////////////////////////////////////////////////////////////////
-INLINE const LMatrix4f &qpDriveInterface::
-get_mat() const {
-  return _mat;
-}

+ 25 - 0
panda/src/tform/qpdriveInterface.cxx

@@ -202,6 +202,31 @@ set_force_roll(float force_roll) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: qpDriveInterface::set_mat
+//       Access: Published
+//  Description: Stores the indicated transform in the qpDriveInterface.
+//               This is a transform in global space, regardless of
+//               the rel_to node.
+////////////////////////////////////////////////////////////////////
+void qpDriveInterface::
+set_mat(const LMatrix4f &mat) {
+  _mat = mat;
+  reextract();
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: qpDriveInterface::get_mat
+//       Access: Published
+//  Description: Returns the net transformation applied by the
+//               current state.
+////////////////////////////////////////////////////////////////////
+const LMatrix4f &qpDriveInterface::
+get_mat() const {
+  return _mat;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: qpDriveInterface::force_dgraph
 //       Access: Public