]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/object.cpp
Use emplace_back when a new object is being constructed
[libs/gl.git] / source / render / object.cpp
index ccc7b97ecdd0086db8f6b6029fc9546e94b82771..65e9a7ef083fc52db1f899906b7febaed96264a5 100644 (file)
@@ -17,19 +17,31 @@ namespace GL {
 const Matrix Object::identity_matrix;
 
 Object::Object():
-       lods(1),
-       lod0_watched(false)
+       lods(1)
 { }
 
 Object::Object(const Mesh *m, const Technique *t):
-       lods(1),
-       lod0_watched(false)
+       Object()
 {
        set_mesh(m);
        set_technique(t);
 }
 
-// TODO should have copy-c'tor to set watch on lod0 mesh if necessary
+Object::Object(const Object &other):
+       lods(other.lods),
+       bounding_sphere(other.bounding_sphere)
+{
+       if(other.lod0_watched)
+               watch_lod0();
+}
+
+Object::Object(Object &&other):
+       lods(move(other.lods)),
+       bounding_sphere(move(other.bounding_sphere))
+{
+       if(other.lod0_watched)
+               watch_lod0();
+}
 
 Object::~Object()
 {
@@ -61,15 +73,20 @@ void Object::set_mesh(unsigned i, const Mesh *m)
        lod0_watched = false;
 
        if(i==0 && m)
-               if(ResourceManager *rm = m->get_manager())
-               {
-                       rm->observe_resource(*m, *this);
-                       lod0_watched = true;
-               }
+               watch_lod0();
 
        update_bounding_sphere();
 }
 
+void Object::watch_lod0()
+{
+       if(ResourceManager *rm = lods[0].mesh->get_manager())
+       {
+               rm->observe_resource(*lods[0].mesh, *this);
+               lod0_watched = true;
+       }
+}
+
 void Object::update_bounding_sphere()
 {
        vector<Vector3> points;
@@ -95,7 +112,7 @@ void Object::update_bounding_sphere()
                for(unsigned j=0; j<n_vertices; ++j)
                {
                        const float *v = reinterpret_cast<const float *>(vertices[j]+offset);
-                       points.push_back(Vector3(v[0], v[1], (three ? v[2] : 0.0f)));
+                       points.emplace_back(v[0], v[1], (three ? v[2] : 0.0f));
                }
        }