]> Shamusworld >> Repos - architektonas/blobdiff - src/object.cpp
Fixed duplicate Connection issue.
[architektonas] / src / object.cpp
index ca065dcdc77832daa41192d3d7496739d68a193e..09d52bf3357b02165410e82e4200877421eddb7e 100644 (file)
@@ -145,22 +145,24 @@ printf("Object: Destroyed!\n");
 // them here. :-)
 /*virtual*/ void Object::Connect(Object * obj, double parameter)
 {
-       connected.push_back(Connection(obj, parameter));
+       // Check to see if this connection is already in our list...
+       Connection c(obj, parameter);
+       std::vector<Connection>::iterator i;
+
+       for(i=connected.begin(); i!=connected.end(); i++)
+       {
+               // Bail out if this connection is already present...
+               if (*i == c)
+                       return;
+       }
+
+       // Connection is a new one, add it in...
+       connected.push_back(c);
 }
 
 
 /*virtual*/ void Object::Disconnect(Object * obj, double parameter)
 {
-#if 0
-       for(uint i=0; i<connected.size(); i++)
-       {
-               if (connected[i].object == obj && connected[i].t == parameter)
-               {
-                       connected.erase(connected.begin() + i);
-                       return;
-               }
-       }
-#else
        std::vector<Connection>::iterator i;
 
        for(i=connected.begin(); i!=connected.end(); i++)
@@ -171,25 +173,11 @@ printf("Object: Destroyed!\n");
                        return;
                }
        }
-#endif
 }
 
 
 /*virtual*/ void Object::DisconnectAll(Object * obj)
 {
-#if 0
-       // According the std::vector docs, only items at position i and beyond are
-       // invalidated, everything before i is still valid. So we use that here.
-       for(uint i=0; i<connected.size();)
-       {
-               // If we found our object, erase it from the vector but don't advance
-               // the iterator. Otherwise, advance the iterator. :-)
-               if (connected[i].object == obj)
-                       connected.erase(connected.begin() + i);
-               else
-                       i++;
-       }
-#else
        std::vector<Connection>::iterator i;
 
        for(i=connected.begin(); i!=connected.end(); )
@@ -199,7 +187,6 @@ printf("Object: Destroyed!\n");
                else
                        i++;
        }
-#endif
 }