Browse Source

copy constructors, other minor refinements

David Rose 20 years ago
parent
commit
4cc9dba771

+ 6 - 6
panda/src/gobj/geom.I

@@ -147,9 +147,9 @@ modify_primitive(int i) {
 //               returning the result.  See
 //               GeomPrimitive::decompose().
 ////////////////////////////////////////////////////////////////////
-INLINE CPT(Geom) Geom::
+INLINE PT(Geom) Geom::
 decompose() const {
-  PT(Geom) new_geom = new Geom(*this);
+  PT(Geom) new_geom = make_copy();
   new_geom->decompose_in_place();
   return new_geom;
 }
@@ -161,9 +161,9 @@ decompose() const {
 //               returning the result.  See
 //               GeomPrimitive::rotate().
 ////////////////////////////////////////////////////////////////////
-INLINE CPT(Geom) Geom::
+INLINE PT(Geom) Geom::
 rotate() const {
-  PT(Geom) new_geom = new Geom(*this);
+  PT(Geom) new_geom = make_copy();
   new_geom->rotate_in_place();
   return new_geom;
 }
@@ -177,9 +177,9 @@ rotate() const {
 //               the Geom contains both triangle strips and triangle
 //               fans.
 ////////////////////////////////////////////////////////////////////
-INLINE CPT(Geom) Geom::
+INLINE PT(Geom) Geom::
 unify() const {
-  PT(Geom) new_geom = new Geom(*this);
+  PT(Geom) new_geom = make_copy();
   new_geom->unify_in_place();
   return new_geom;
 }

+ 3 - 3
panda/src/gobj/geom.h

@@ -83,9 +83,9 @@ PUBLISHED:
   void remove_primitive(int i);
   void clear_primitives();
 
-  INLINE CPT(Geom) decompose() const;
-  INLINE CPT(Geom) rotate() const;
-  INLINE CPT(Geom) unify() const;
+  INLINE PT(Geom) decompose() const;
+  INLINE PT(Geom) rotate() const;
+  INLINE PT(Geom) unify() const;
 
   void decompose_in_place();
   void rotate_in_place();

+ 25 - 13
panda/src/gobj/geomTristrips.cxx

@@ -161,21 +161,27 @@ decompose_impl() const {
       ++vi;
       bool reversed = false;
       while (vi < end) {
-        triangles->add_vertex(v0);
         int v2 = get_vertex(vi);
         ++vi;
         if (reversed) {
-          triangles->add_vertex(v2);
-          triangles->add_vertex(v1);
+          if (v0 != v1 && v0 != v2 && v1 != v2) {
+            triangles->add_vertex(v0);
+            triangles->add_vertex(v2);
+            triangles->add_vertex(v1);
+            triangles->close_primitive();
+          }
           reversed = false;
         } else {
-          triangles->add_vertex(v1);
-          triangles->add_vertex(v2);
+          if (v0 != v1 && v0 != v2 && v1 != v2) {
+            triangles->add_vertex(v0);
+            triangles->add_vertex(v1);
+            triangles->add_vertex(v2);
+            triangles->close_primitive();
+          }
           reversed = true;
         }
         v0 = v1;
         v1 = v2;
-        triangles->close_primitive();
       }
       ++li;
     }
@@ -197,21 +203,27 @@ decompose_impl() const {
       ++vi;
       bool reversed = false;
       while (vi < end) {
+        int v2 = get_vertex(vi);
         if (reversed) {
-          triangles->add_vertex(v1);
-          triangles->add_vertex(v0);
+          if (v0 != v1 && v0 != v2 && v1 != v2) {
+            triangles->add_vertex(v1);
+            triangles->add_vertex(v0);
+            triangles->add_vertex(v2);
+            triangles->close_primitive();
+          }
           reversed = false;
         } else {
-          triangles->add_vertex(v0);
-          triangles->add_vertex(v1);
+          if (v0 != v1 && v0 != v2 && v1 != v2) {
+            triangles->add_vertex(v0);
+            triangles->add_vertex(v1);
+            triangles->add_vertex(v2);
+            triangles->close_primitive();
+          }
           reversed = true;
         }
-        int v2 = get_vertex(vi);
         ++vi;
-        triangles->add_vertex(v2);
         v0 = v1;
         v1 = v2;
-        triangles->close_primitive();
       }
       ++li;
     }

+ 37 - 0
panda/src/gobj/geomVertexReader.I

@@ -88,6 +88,43 @@ GeomVertexReader(const GeomVertexArrayData *array_data, int column) :
   set_column(column);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GeomVertexReader::Copy Constructor
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE GeomVertexReader::
+GeomVertexReader(const GeomVertexReader &copy) :
+  _vertex_data(copy._vertex_data),
+  _array(copy._array),
+  _array_data(copy._array_data),
+  _packer(copy._packer),
+  _stride(copy._stride),
+  _pointer_begin(copy._pointer_begin),
+  _pointer_end(copy._pointer_end),
+  _pointer(copy._pointer),
+  _start_row(copy._start_row)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GeomVertexReader::Copy Assignment Operator
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE void GeomVertexReader::
+operator = (const GeomVertexReader &copy) {
+  _vertex_data = copy._vertex_data;
+  _array = copy._array;
+  _array_data = copy._array_data;
+  _packer = copy._packer;
+  _stride = copy._stride;
+  _pointer_begin = copy._pointer_begin;
+  _pointer_end = copy._pointer_end;
+  _pointer = copy._pointer;
+  _start_row = copy._start_row;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomVertexReader::Destructor
 //       Access: Published

+ 5 - 3
panda/src/gobj/geomVertexReader.h

@@ -61,12 +61,14 @@ class EXPCL_PANDA GeomVertexReader : public GeomEnums {
 PUBLISHED:
   INLINE GeomVertexReader(const GeomVertexData *vertex_data);
   INLINE GeomVertexReader(const GeomVertexData *vertex_data,
-                            const string &name);
+                          const string &name);
   INLINE GeomVertexReader(const GeomVertexData *vertex_data,
-                            const InternalName *name);
+                          const InternalName *name);
   INLINE GeomVertexReader(const GeomVertexArrayData *array_data);
   INLINE GeomVertexReader(const GeomVertexArrayData *array_data, 
-                            int column);
+                          int column);
+  INLINE GeomVertexReader(const GeomVertexReader &copy);
+  INLINE void operator = (const GeomVertexReader &copy);
   INLINE ~GeomVertexReader();
 
   INLINE const GeomVertexData *get_vertex_data() const;

+ 23 - 0
panda/src/gobj/geomVertexRewriter.I

@@ -87,6 +87,29 @@ GeomVertexRewriter(GeomVertexArrayData *array_data, int column) :
   set_column(column);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GeomVertexRewriter::Copy Constructor
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE GeomVertexRewriter::
+GeomVertexRewriter(const GeomVertexRewriter &copy) :
+  GeomVertexWriter(copy),
+  GeomVertexReader(copy)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GeomVertexRewriter::Copy Assignment Operator
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE void GeomVertexRewriter::
+operator = (const GeomVertexRewriter &copy) {
+  GeomVertexWriter::operator = (copy);
+  GeomVertexReader::operator = (copy);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomVertexRewriter::Destructor
 //       Access: Published

+ 5 - 3
panda/src/gobj/geomVertexRewriter.h

@@ -44,12 +44,14 @@ class EXPCL_PANDA GeomVertexRewriter : public GeomVertexWriter, public GeomVerte
 PUBLISHED:
   INLINE GeomVertexRewriter(GeomVertexData *vertex_data);
   INLINE GeomVertexRewriter(GeomVertexData *vertex_data,
-                              const string &name);
+                            const string &name);
   INLINE GeomVertexRewriter(GeomVertexData *vertex_data,
-                              const InternalName *name);
+                            const InternalName *name);
   INLINE GeomVertexRewriter(GeomVertexArrayData *array_data);
   INLINE GeomVertexRewriter(GeomVertexArrayData *array_data, 
-                              int column);
+                            int column);
+  INLINE GeomVertexRewriter(const GeomVertexRewriter &copy);
+  INLINE void operator = (const GeomVertexRewriter &copy);
   INLINE ~GeomVertexRewriter();
 
   INLINE GeomVertexData *get_vertex_data() const;

+ 37 - 0
panda/src/gobj/geomVertexWriter.I

@@ -87,6 +87,43 @@ GeomVertexWriter(GeomVertexArrayData *array_data, int column) :
   set_column(column);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GeomVertexWriter::Copy Constructor
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE GeomVertexWriter::
+GeomVertexWriter(const GeomVertexWriter &copy) :
+  _vertex_data(copy._vertex_data),
+  _array(copy._array),
+  _array_data(copy._array_data),
+  _packer(copy._packer),
+  _stride(copy._stride),
+  _pointer_begin(copy._pointer_begin),
+  _pointer_end(copy._pointer_end),
+  _pointer(copy._pointer),
+  _start_row(copy._start_row)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GeomVertexWriter::Copy Assignment Operator
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE void GeomVertexWriter::
+operator = (const GeomVertexWriter &copy) {
+  _vertex_data = copy._vertex_data;
+  _array = copy._array;
+  _array_data = copy._array_data;
+  _packer = copy._packer;
+  _stride = copy._stride;
+  _pointer_begin = copy._pointer_begin;
+  _pointer_end = copy._pointer_end;
+  _pointer = copy._pointer;
+  _start_row = copy._start_row;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomVertexWriter::Destructor
 //       Access: Published

+ 5 - 3
panda/src/gobj/geomVertexWriter.h

@@ -74,12 +74,14 @@ class EXPCL_PANDA GeomVertexWriter : public GeomEnums {
 PUBLISHED:
   INLINE GeomVertexWriter(GeomVertexData *vertex_data);
   INLINE GeomVertexWriter(GeomVertexData *vertex_data,
-                            const string &name);
+                          const string &name);
   INLINE GeomVertexWriter(GeomVertexData *vertex_data,
-                            const InternalName *name);
+                          const InternalName *name);
   INLINE GeomVertexWriter(GeomVertexArrayData *array_data);
   INLINE GeomVertexWriter(GeomVertexArrayData *array_data, 
-                            int column);
+                          int column);
+  INLINE GeomVertexWriter(const GeomVertexWriter &copy);
+  INLINE void operator = (const GeomVertexWriter &copy);
   INLINE ~GeomVertexWriter();
 
   INLINE GeomVertexData *get_vertex_data() const;