]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/vehicletype.cpp
Derive application classes from RegisteredApplication
[r2c2.git] / source / 3d / vehicletype.cpp
index 2ddd34db08cc4515753f1eeb3171acee973e57d2..427c29fe91664aa98030487f19d299128531a187 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #include <msp/gl/meshbuilder.h>
 #include <msp/gl/technique.h>
 #include <msp/gl/texture2d.h>
@@ -31,7 +24,7 @@ T get(const map<string, string> &params, const string &key, T def = T())
 
 namespace R2C2 {
 
-VehicleType3D::VehicleType3D(const Catalogue3D &c, const VehicleType &t):
+VehicleType3D::VehicleType3D(Catalogue3D &c, const VehicleType &t):
        catalogue(c),
        type(t),
        body_object(0),
@@ -39,7 +32,7 @@ VehicleType3D::VehicleType3D(const Catalogue3D &c, const VehicleType &t):
 {
        body_object = get_object(type.get_object());
 
-       const vector<VehicleType::Axle> &axles = type.get_axles();
+       const vector<VehicleType::Axle> &axles = type.get_fixed_axles();
        for(vector<VehicleType::Axle>::const_iterator i=axles.begin(); i!=axles.end(); ++i)
                axle_objects[0].push_back(get_object(i->object));
 
@@ -63,33 +56,33 @@ VehicleType3D::~VehicleType3D()
                delete i->second;
 }
 
-const GL::Object *VehicleType3D::get_axle_object(unsigned i) const
+const GL::Object *VehicleType3D::get_fixed_axle_object(unsigned i) const
 {
        if(i>=axle_objects[0].size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType3D::get_fixed_axle_object");
        return axle_objects[0][i];
 }
 
 const GL::Object *VehicleType3D::get_bogie_object(unsigned i) const
 {
        if(i>=bogie_objects.size())
-               throw InvalidParameterValue("Bogie index out of range");
+               throw out_of_range("VehicleType3D::get_bogie_object");
        return bogie_objects[i];
 }
 
 const GL::Object *VehicleType3D::get_bogie_axle_object(unsigned i, unsigned j) const
 {
        if(i>=bogie_objects.size())
-               throw InvalidParameterValue("Bogie index out of range");
+               throw out_of_range("VehicleType3D::get_bogie_axle_object");
        if(j>=axle_objects[i+1].size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType3D::get_bogie_axle_object");
        return axle_objects[i+1][j];
 }
 
 const GL::Object *VehicleType3D::get_rod_object(unsigned i) const
 {
        if(i>=rod_objects.size())
-               throw InvalidParameterValue("Rod index out of range");
+               throw out_of_range("VehicleType3D::get_rod_object");
        return rod_objects[i];
 }
 
@@ -107,9 +100,9 @@ GL::Object *VehicleType3D::get_object(const string &name)
                        string kind = name.substr(1, colon-1);
 
                        map<string, string> params;
-                       params["length"] = lexical_cast(type.get_length()*1000);
-                       params["width"] = lexical_cast(type.get_width()*1000);
-                       params["height"] = lexical_cast(type.get_height()*1000);
+                       params["length"] = lexical_cast<string>(type.get_length()*1000);
+                       params["width"] = lexical_cast<string>(type.get_width()*1000);
+                       params["height"] = lexical_cast<string>(type.get_height()*1000);
                        if(colon!=string::npos)
                        {
                                string::size_type start = colon+1;
@@ -144,10 +137,7 @@ GL::Object *VehicleType3D::get_object(const string &name)
                        }
                }
                else
-               {
-                       ptr = new GL::Object;
-                       DataFile::load(*ptr, name);
-               }
+                       return catalogue.get<GL::Object>(name);
        }
        return ptr;
 }