]> git.tdb.fi Git - r2c2.git/blob - source/3d/vehicletype.cpp
Do not render unplaced vehicles
[r2c2.git] / source / 3d / vehicletype.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <msp/gl/meshbuilder.h>
9 #include <msp/gl/vector.h>
10 #include "catalogue.h"
11 #include "vehicletype.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 namespace Marklin {
17
18 VehicleType3D::VehicleType3D(Catalogue3D &, const VehicleType &vt):
19         body_object(0),
20         bogie_objects(vt.get_bogies().size())
21 {
22         body_object = get_object(vt.get_object());
23
24         for(unsigned i=0; i<bogie_objects.size(); ++i)
25                 bogie_objects[i] = get_object(vt.get_bogies()[i].object);
26 }
27
28 VehicleType3D::~VehicleType3D()
29 {
30         for(map<string, GL::Object *>::iterator i=objects.begin(); i!=objects.end(); ++i)
31                 delete i->second;
32 }
33
34 const GL::Object *VehicleType3D::get_axle_object(unsigned) const
35 {
36         return 0;
37 }
38
39 const GL::Object *VehicleType3D::get_bogie_object(unsigned i) const
40 {
41         if(i>=bogie_objects.size())
42                 throw InvalidParameterValue("Bogie index out of range");
43         return bogie_objects[i];
44 }
45
46 const GL::Object *VehicleType3D::get_bogie_axle_object(unsigned, unsigned) const
47 {
48         return 0;
49 }
50
51 GL::Object *VehicleType3D::get_object(const string &name)
52 {
53         if(name.empty())
54                 return 0;
55
56         GL::Object *&ptr = objects[name];
57         if(!ptr)
58         {
59                 ptr = new GL::Object;
60                 DataFile::load(*ptr, name);
61         }
62         return ptr;
63 }
64
65 } // namespace Marklin