Browse Source

add set_vertex_membership, make map accessors non-inline

David Rose 22 years ago
parent
commit
ba4ec85c60

+ 32 - 0
panda/src/egg/eggGroup.cxx

@@ -505,6 +505,38 @@ get_vertex_membership(const EggVertex *vert) const {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggGroup::set_vertex_membership
+//       Access: Public
+//  Description: Explicitly sets the net membership of the indicated
+//               vertex in this group to the given value.
+////////////////////////////////////////////////////////////////////
+void EggGroup::
+set_vertex_membership(EggVertex *vert, double membership) {
+  if (membership == 0.0) {
+    unref_vertex(vert);
+    return;
+  }
+
+  VertexRef::iterator vri = _vref.find(vert);
+
+  if (vri != _vref.end()) {
+    // The vertex was already being reffed; just change its membership
+    // amount.
+    (*vri).second = membership;
+
+  } else {
+    // The vertex was not already reffed; ref it.
+    _vref[vert] = membership;
+
+    bool inserted = vert->_gref.insert(this).second;
+    // Did the group not exist previously in the vertex's gref list?
+    // If it was there already, we must be out of sync between
+    // vertices and groups.
+    nassertv(inserted);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggGroup::steal_vrefs
 //       Access: Public

+ 1 - 0
panda/src/egg/eggGroup.h

@@ -198,6 +198,7 @@ public:
   void unref_vertex(EggVertex *vert);
   void unref_all_vertices();
   double get_vertex_membership(const EggVertex *vert) const;
+  void set_vertex_membership(EggVertex *vert, double membership);
   void steal_vrefs(EggGroup *other);
 
   INLINE VertexRef::const_iterator vref_begin() const;

+ 0 - 92
panda/src/egg/eggVertex.I

@@ -206,98 +206,6 @@ get_external_index() const {
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: EggVertex::gref_begin
-//       Access: Public
-//  Description: Returns an iterator that can, in conjunction with
-//               gref_end(), be used to traverse the entire set of
-//               groups that reference this vertex.  Each iterator
-//               returns a pointer to a group.
-//
-//               This interface is not safe to use outside of
-//               PANDAEGG.DLL.
-////////////////////////////////////////////////////////////////////
-INLINE EggVertex::GroupRef::const_iterator EggVertex::
-gref_begin() const {
-  return _gref.begin();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: EggVertex::gref_end
-//       Access: Public
-//  Description: Returns an iterator that can, in conjunction with
-//               gref_begin(), be used to traverse the entire set of
-//               groups that reference this vertex.  Each iterator
-//               returns a pointer to a group.
-//
-//               This interface is not safe to use outside of
-//               PANDAEGG.DLL.
-////////////////////////////////////////////////////////////////////
-INLINE EggVertex::GroupRef::const_iterator EggVertex::
-gref_end() const {
-  return _gref.end();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: EggVertex::gref_size
-//       Access: Public
-//  Description: Returns the number of elements between gref_begin()
-//               and gref_end().
-//
-//               This interface is not safe to use outside of
-//               PANDAEGG.DLL.
-////////////////////////////////////////////////////////////////////
-INLINE EggVertex::GroupRef::size_type EggVertex::
-gref_size() const {
-  return _gref.size();
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: EggVertex::pref_begin
-//       Access: Public
-//  Description: Returns an iterator that can, in conjunction with
-//               pref_end(), be used to traverse the entire set of
-//               primitives that reference this vertex.  Each iterator
-//               returns a pointer to a primitive.
-//
-//               This interface is not safe to use outside of
-//               PANDAEGG.DLL.
-////////////////////////////////////////////////////////////////////
-INLINE EggVertex::PrimitiveRef::const_iterator EggVertex::
-pref_begin() const {
-  return _pref.begin();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: EggVertex::pref_end
-//       Access: Public
-//  Description: Returns an iterator that can, in conjunction with
-//               pref_begin(), be used to traverse the entire set of
-//               primitives that reference this vertex.  Each iterator
-//               returns a pointer to a primitive.
-//
-//               This interface is not safe to use outside of
-//               PANDAEGG.DLL.
-////////////////////////////////////////////////////////////////////
-INLINE EggVertex::PrimitiveRef::const_iterator EggVertex::
-pref_end() const {
-  return _pref.end();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: EggVertex::pref_size
-//       Access: Public
-//  Description: Returns the number of elements between pref_begin()
-//               and pref_end().
-//
-//               This interface is not safe to use outside of
-//               PANDAEGG.DLL.
-////////////////////////////////////////////////////////////////////
-INLINE EggVertex::GroupRef::size_type EggVertex::
-pref_size() const {
-  return _pref.size();
-}
 
 
 

+ 92 - 0
panda/src/egg/eggVertex.cxx

@@ -294,6 +294,52 @@ transform(const LMatrix4d &mat) {
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggVertex::gref_begin
+//       Access: Public
+//  Description: Returns an iterator that can, in conjunction with
+//               gref_end(), be used to traverse the entire set of
+//               groups that reference this vertex.  Each iterator
+//               returns a pointer to a group.
+//
+//               This interface is not safe to use outside of
+//               PANDAEGG.DLL.
+////////////////////////////////////////////////////////////////////
+EggVertex::GroupRef::const_iterator EggVertex::
+gref_begin() const {
+  return _gref.begin();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: EggVertex::gref_end
+//       Access: Public
+//  Description: Returns an iterator that can, in conjunction with
+//               gref_begin(), be used to traverse the entire set of
+//               groups that reference this vertex.  Each iterator
+//               returns a pointer to a group.
+//
+//               This interface is not safe to use outside of
+//               PANDAEGG.DLL.
+////////////////////////////////////////////////////////////////////
+EggVertex::GroupRef::const_iterator EggVertex::
+gref_end() const {
+  return _gref.end();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: EggVertex::gref_size
+//       Access: Public
+//  Description: Returns the number of elements between gref_begin()
+//               and gref_end().
+//
+//               This interface is not safe to use outside of
+//               PANDAEGG.DLL.
+////////////////////////////////////////////////////////////////////
+EggVertex::GroupRef::size_type EggVertex::
+gref_size() const {
+  return _gref.size();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggVertex::has_gref
 //       Access: Public
@@ -359,6 +405,52 @@ clear_grefs() {
   nassertv(_gref.empty());
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggVertex::pref_begin
+//       Access: Public
+//  Description: Returns an iterator that can, in conjunction with
+//               pref_end(), be used to traverse the entire set of
+//               primitives that reference this vertex.  Each iterator
+//               returns a pointer to a primitive.
+//
+//               This interface is not safe to use outside of
+//               PANDAEGG.DLL.
+////////////////////////////////////////////////////////////////////
+EggVertex::PrimitiveRef::const_iterator EggVertex::
+pref_begin() const {
+  return _pref.begin();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: EggVertex::pref_end
+//       Access: Public
+//  Description: Returns an iterator that can, in conjunction with
+//               pref_begin(), be used to traverse the entire set of
+//               primitives that reference this vertex.  Each iterator
+//               returns a pointer to a primitive.
+//
+//               This interface is not safe to use outside of
+//               PANDAEGG.DLL.
+////////////////////////////////////////////////////////////////////
+EggVertex::PrimitiveRef::const_iterator EggVertex::
+pref_end() const {
+  return _pref.end();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: EggVertex::pref_size
+//       Access: Public
+//  Description: Returns the number of elements between pref_begin()
+//               and pref_end().
+//
+//               This interface is not safe to use outside of
+//               PANDAEGG.DLL.
+////////////////////////////////////////////////////////////////////
+EggVertex::GroupRef::size_type EggVertex::
+pref_size() const {
+  return _pref.size();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggVertex::has_pref
 //       Access: Public

+ 6 - 6
panda/src/egg/eggVertex.h

@@ -84,17 +84,17 @@ public:
 
   void transform(const LMatrix4d &mat);
 
-  INLINE GroupRef::const_iterator gref_begin() const;
-  INLINE GroupRef::const_iterator gref_end() const;
-  INLINE GroupRef::size_type gref_size() const;
+  GroupRef::const_iterator gref_begin() const;
+  GroupRef::const_iterator gref_end() const;
+  GroupRef::size_type gref_size() const;
   bool has_gref(const EggGroup *group) const;
 
   void copy_grefs_from(const EggVertex &other);
   void clear_grefs();
 
-  INLINE PrimitiveRef::const_iterator pref_begin() const;
-  INLINE PrimitiveRef::const_iterator pref_end() const;
-  INLINE PrimitiveRef::size_type pref_size() const;
+  PrimitiveRef::const_iterator pref_begin() const;
+  PrimitiveRef::const_iterator pref_end() const;
+  PrimitiveRef::size_type pref_size() const;
   int has_pref(const EggPrimitive *prim) const;
 
 #ifndef NDEBUG