Browse Source

unify GVD better

David Rose 19 years ago
parent
commit
8b32c56bd6

+ 25 - 0
panda/src/grutil/rigidBodyCombiner.I

@@ -16,3 +16,28 @@
 //
 //
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
+
+////////////////////////////////////////////////////////////////////
+//     Function: RigidBodyCombiner::VDUnifier::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE RigidBodyCombiner::VDUnifier::
+VDUnifier(const VertexTransform *transform, const GeomVertexData *orig) :
+  _transform(transform),
+  _orig(orig)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: RigidBodyCombiner::VDUnifier::operator <
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE bool RigidBodyCombiner::VDUnifier::
+operator < (const RigidBodyCombiner::VDUnifier &other) const {
+  if (_transform != other._transform) {
+    return _transform < other._transform;
+  }
+  return _orig < other._orig;
+}

+ 14 - 1
panda/src/grutil/rigidBodyCombiner.cxx

@@ -96,6 +96,7 @@ void RigidBodyCombiner::
 collect() {
 collect() {
   _internal_root = new GeomNode(get_name());
   _internal_root = new GeomNode(get_name());
   _internal_transforms.clear();
   _internal_transforms.clear();
+  _vd_table.clear();
 
 
   Children cr = get_children();
   Children cr = get_children();
   int num_children = cr.get_num_children();
   int num_children = cr.get_num_children();
@@ -103,6 +104,8 @@ collect() {
     r_collect(cr.get_child(i), RenderState::make_empty(), NULL);
     r_collect(cr.get_child(i), RenderState::make_empty(), NULL);
   }
   }
 
 
+  _vd_table.clear();
+
   SceneGraphReducer gr;
   SceneGraphReducer gr;
   gr.apply_attribs(_internal_root);
   gr.apply_attribs(_internal_root);
   gr.collect_vertex_data(_internal_root, ~(SceneGraphReducer::CVD_format | SceneGraphReducer::CVD_name | SceneGraphReducer::CVD_animation_type));
   gr.collect_vertex_data(_internal_root, ~(SceneGraphReducer::CVD_format | SceneGraphReducer::CVD_name | SceneGraphReducer::CVD_animation_type));
@@ -224,7 +227,14 @@ r_collect(PandaNode *node, const RenderState *state,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PT(GeomVertexData) RigidBodyCombiner::
 PT(GeomVertexData) RigidBodyCombiner::
 convert_vd(const VertexTransform *transform, const GeomVertexData *orig) {
 convert_vd(const VertexTransform *transform, const GeomVertexData *orig) {
-  // TODO: unify this operation for unique transform/data combinations.
+  // First, unify this operation for unique transform/data
+  // combinations.  If we encounter a given GeomVertexData more than
+  // once under the same transform, we should return exactly the same
+  // GeomVertexData.
+  VDTable::iterator vdti = _vd_table.find(VDUnifier(transform, orig));
+  if (vdti != _vd_table.end()) {
+    return (*vdti).second;
+  }
 
 
   PT(GeomVertexFormat) format = new GeomVertexFormat(*orig->get_format());
   PT(GeomVertexFormat) format = new GeomVertexFormat(*orig->get_format());
   if (!orig->get_format()->has_column(InternalName::get_transform_blend())) {
   if (!orig->get_format()->has_column(InternalName::get_transform_blend())) {
@@ -254,5 +264,8 @@ convert_vd(const VertexTransform *transform, const GeomVertexData *orig) {
     // case, we'll have to adjust it.  TODO.
     // case, we'll have to adjust it.  TODO.
   }
   }
 
 
+  // Store the result for the next time.
+  _vd_table[VDUnifier(transform, orig)] = new_data;
+
   return new_data;
   return new_data;
 }
 }

+ 14 - 0
panda/src/grutil/rigidBodyCombiner.h

@@ -80,6 +80,20 @@ private:
   typedef pvector< PT(NodeVertexTransform) > Transforms;
   typedef pvector< PT(NodeVertexTransform) > Transforms;
   Transforms _internal_transforms;
   Transforms _internal_transforms;
 
 
+  class VDUnifier {
+  public:
+    INLINE VDUnifier(const VertexTransform *transform, 
+                     const GeomVertexData *orig);
+    INLINE bool operator < (const VDUnifier &other) const;
+
+    const VertexTransform *_transform;
+    const GeomVertexData *_orig;
+  };
+
+  typedef pmap<VDUnifier, PT(GeomVertexData) > VDTable;
+  VDTable _vd_table;
+
+
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {
     return _type_handle;
     return _type_handle;