From 81ee4fbd16b472892b67b35ea85956423a2247ed Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 4 May 2014 10:47:49 +0300 Subject: [PATCH] Convert Catalogue to a Collection Since this involves changing the key from ArticleNumber to std::string, existing layout and state files need to be adjusted by hand. --- locos.dat | 20 ++-- source/3d/catalogue.cpp | 36 +++---- source/3d/catalogue.h | 17 +++- source/designer/extendtool.cpp | 23 +++-- source/engineer/newtraindialog.cpp | 9 +- source/engineer/newvehicledialog.cpp | 17 ++-- source/libr2c2/catalogue.cpp | 69 +++++--------- source/libr2c2/catalogue.h | 32 ++----- source/libr2c2/layout.cpp | 24 ++--- source/libr2c2/layout.h | 8 +- source/libr2c2/signaltype.h | 2 +- source/libr2c2/terraintype.h | 2 +- source/libr2c2/tracktype.cpp | 11 ++- source/libr2c2/tracktype.h | 6 +- source/libr2c2/train.cpp | 7 +- source/libr2c2/train.h | 2 +- source/libr2c2/vehicletype.h | 2 +- source/network/server.cpp | 6 +- source/shoppinglist/main.cpp | 40 ++++---- terrain.dat | 4 +- tracks.dat | 136 +++++++++++++-------------- wagons.dat | 40 ++++---- 22 files changed, 249 insertions(+), 264 deletions(-) diff --git a/locos.dat b/locos.dat index 3547d51..bd3fdc2 100644 --- a/locos.dat +++ b/locos.dat @@ -1,6 +1,6 @@ scale 1 87; -vehicle \39230 +vehicle "39230" { name "BR 23"; locomotive true; @@ -31,7 +31,7 @@ vehicle \39230 }; }; -vehicle \29820-02 +vehicle "29820-02" { name "BR 50"; locomotive true; @@ -282,7 +282,7 @@ vehicle \29820-02 }; }; -vehicle \29530-01 +vehicle "29530-01" { name "BR 86"; locomotive true; @@ -313,7 +313,7 @@ vehicle \29530-01 }; }; -vehicle \36850 +vehicle "36850" { name "BR 185"; locomotive true; @@ -343,7 +343,7 @@ vehicle \36850 }; }; -vehicle \37225-02 +vehicle "37225-02" { name "BR 194"; locomotive true; @@ -377,7 +377,7 @@ vehicle \37225-02 }; }; -vehicle \39410 +vehicle "39410" { name "BR E 41"; locomotive true; @@ -410,7 +410,7 @@ vehicle \39410 }; }; -vehicle \37574-01 +vehicle "37574-01" { name "BR E 03"; locomotive true; @@ -445,7 +445,7 @@ vehicle \37574-01 }; }; -vehicle \37504 +vehicle "37504" { // XXX The power car is really in the middle, but that configuration isn't supported yet name "BR 420 S-bahn"; @@ -480,7 +480,7 @@ vehicle \37504 }; }; -vehicle \37851 +vehicle "37851" { name "BR 150"; locomotive true; @@ -512,7 +512,7 @@ vehicle \37851 }; }; -vehicle \37968 +vehicle "37968" { name "BR 96"; locomotive true; diff --git a/source/3d/catalogue.cpp b/source/3d/catalogue.cpp index d84e2d0..f06356b 100644 --- a/source/3d/catalogue.cpp +++ b/source/3d/catalogue.cpp @@ -16,12 +16,6 @@ Catalogue3D::Catalogue3D(Catalogue &c): src.add_directory("."); src.add_directory("data"); add_source(src); - - catalogue.signal_object_added.connect(sigc::mem_fun(this, &Catalogue3D::object_added)); - - const Catalogue::ObjectMap &objs = catalogue.get_all(); - for(Catalogue::ObjectMap::const_iterator i=objs.begin(); i!=objs.end(); ++i) - object_added(*i->second); } Catalogue3D::~Catalogue3D() @@ -30,19 +24,24 @@ Catalogue3D::~Catalogue3D() delete i->second; } -void Catalogue3D::object_added(const ObjectType &ot) +const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot) { + ObjectMap::iterator i = objects.find(&ot); + if(i!=objects.end()) + return *i->second; + + ObjectType3D *ot3d = 0; if(const TrackType *tt = dynamic_cast(&ot)) - { - objects[&ot] = new TrackType3D(*this, *tt); - const TrackAppearance &appearance = tt->get_appearance(); - if(!endpoint_meshes.count(&appearance)) - build_endpoint_mesh(appearance); - } + ot3d = new TrackType3D(*this, *tt); else if(const SignalType *st = dynamic_cast(&ot)) - objects[&ot] = new SignalType3D(*this, *st); + ot3d = new SignalType3D(*this, *st); else if(const VehicleType *vt = dynamic_cast(&ot)) - objects[&ot] = new VehicleType3D(*this, *vt); + ot3d = new VehicleType3D(*this, *vt); + else + throw key_error(&ot); + + objects[&ot] = ot3d; + return *ot3d; } const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot) const @@ -50,8 +49,12 @@ const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot) const return *get_item(objects, &ot); } -void Catalogue3D::build_endpoint_mesh(const TrackAppearance &appearance) +const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance) { + EndpointMap::iterator i = endpoint_meshes.find(&appearance); + if(i!=endpoint_meshes.end()) + return *i->second; + const Profile &ballast_profile = appearance.get_ballast_profile(); const Vector &ballast_min = ballast_profile.get_min_coords(); const Vector &ballast_max = ballast_profile.get_max_coords(); @@ -76,6 +79,7 @@ void Catalogue3D::build_endpoint_mesh(const TrackAppearance &appearance) bld.end(); endpoint_meshes[&appearance] = mesh; + return *mesh; } const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance) const diff --git a/source/3d/catalogue.h b/source/3d/catalogue.h index 07f1535..d82529f 100644 --- a/source/3d/catalogue.h +++ b/source/3d/catalogue.h @@ -15,28 +15,35 @@ class ObjectType3D; class Catalogue3D: public Msp::GL::Resources { private: + typedef std::map ObjectMap; + typedef std::map EndpointMap; + Catalogue &catalogue; Msp::DataFile::DirectorySource src; - std::map objects; - std::map endpoint_meshes; + ObjectMap objects; + EndpointMap endpoint_meshes; public: Catalogue3D(Catalogue &); ~Catalogue3D(); const Catalogue &get_catalogue() const { return catalogue; } -private: - void object_added(const ObjectType &); -public: + + const ObjectType3D &get_3d(const ObjectType &); const ObjectType3D &get_3d(const ObjectType &) const; template const typename TypeMap3D::Type3D &get_3d(const T &ot) const { return dynamic_cast::Type3D &>(get_3d(static_cast(ot))); } + template + const typename TypeMap3D::Type3D &get_3d(const T &ot) + { return dynamic_cast::Type3D &>(get_3d(static_cast(ot))); } + private: void build_endpoint_mesh(const TrackAppearance &); public: + const Msp::GL::Mesh &get_endpoint_mesh(const TrackAppearance &); const Msp::GL::Mesh &get_endpoint_mesh(const TrackAppearance &) const; }; diff --git a/source/designer/extendtool.cpp b/source/designer/extendtool.cpp index aac7672..c31c09f 100644 --- a/source/designer/extendtool.cpp +++ b/source/designer/extendtool.cpp @@ -26,19 +26,18 @@ ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const s set_done(false); } - const Catalogue::ObjectMap &object_types = designer.get_catalogue().get_all(); - for(Catalogue::ObjectMap::const_iterator i=object_types.begin(); i!=object_types.end(); ++i) - if(const TrackType *tt = dynamic_cast(i->second)) - { - const vector &parts = tt->get_parts(); - if(parts.size()!=1) - continue; - if(parts.front().is_curved() || parts.front().is_dead_end()) - continue; + list track_types = designer.get_catalogue().get_list(); + for(list::iterator i=track_types.begin(); i!=track_types.end(); ++i) + { + const vector &parts = (*i)->get_parts(); + if(parts.size()!=1) + continue; + if(parts.front().is_curved() || parts.front().is_dead_end()) + continue; - types_by_length[parts.front().get_length()] = tt; - max_preference = max(max_preference, tt->get_autofit_preference()); - } + types_by_length[parts.front().get_length()] = *i; + max_preference = max(max_preference, (*i)->get_autofit_preference()); + } } ExtendTool::~ExtendTool() diff --git a/source/engineer/newtraindialog.cpp b/source/engineer/newtraindialog.cpp index ef9fbf8..e0b4e1a 100644 --- a/source/engineer/newtraindialog.cpp +++ b/source/engineer/newtraindialog.cpp @@ -42,11 +42,10 @@ NewTrainDialog::NewTrainDialog(Engineer &e): drp_protocol->set_selected_index(0); - const Catalogue::ObjectMap &obj_types = engineer.get_layout().get_catalogue().get_all(); - for(Catalogue::ObjectMap::const_iterator i=obj_types.begin(); i!=obj_types.end(); ++i) - if(const VehicleType *vt = dynamic_cast(i->second)) - if(vt->is_locomotive()) - loco_types.append(vt); + list veh_types = engineer.get_layout().get_catalogue().get_list(); + for(list::iterator i=veh_types.begin(); i!=veh_types.end(); ++i) + if((*i)->is_locomotive()) + loco_types.append(*i); } void NewTrainDialog::prefill(const Driver::DetectedLocomotive &loco) diff --git a/source/engineer/newvehicledialog.cpp b/source/engineer/newvehicledialog.cpp index de4d14a..e9c537e 100644 --- a/source/engineer/newvehicledialog.cpp +++ b/source/engineer/newvehicledialog.cpp @@ -37,15 +37,14 @@ NewVehicleDialog::NewVehicleDialog(Train &t): dynamic_cast(get_item(widgets, "btn_add"))->signal_clicked.connect(sigc::mem_fun(this, &NewVehicleDialog::add_clicked)); - const Catalogue::ObjectMap &obj_types = train.get_layout().get_catalogue().get_all(); - for(Catalogue::ObjectMap::const_iterator i=obj_types.begin(); i!=obj_types.end(); ++i) - if(const VehicleType *vt = dynamic_cast(i->second)) - { - if(vt->is_locomotive()) - loco_types.append(vt); - else - wagon_types.append(vt); - } + list veh_types = train.get_layout().get_catalogue().get_list(); + for(list::iterator i=veh_types.begin(); i!=veh_types.end(); ++i) + { + if((*i)->is_locomotive()) + loco_types.append(*i); + else + wagon_types.append(*i); + } } void NewVehicleDialog::toggle_list(bool show, GLtk::List *lst) diff --git a/source/libr2c2/catalogue.cpp b/source/libr2c2/catalogue.cpp index 572423a..cfd5d64 100644 --- a/source/libr2c2/catalogue.cpp +++ b/source/libr2c2/catalogue.cpp @@ -15,28 +15,17 @@ namespace R2C2 { Catalogue::Catalogue(): scale(1), layout(*this) -{ } - -Catalogue::~Catalogue() -{ - for(ObjectMap::iterator i=objects.begin(); i!=objects.end(); ++i) - delete i->second; -} - -void Catalogue::add(ObjectType &object) { - insert_unique(objects, object.get_article_number(), &object); - signal_object_added.emit(object); -} - -const ObjectType &Catalogue::get(const ArticleNumber &art_nr) const -{ - return *get_item(objects, art_nr); + add_type(); + add_type(); + add_type(); + add_type(); } Catalogue::Loader::Loader(Catalogue &c): - DataFile::ObjectLoader(c) + Collection::Loader(c), + cat(c) { add("layout", &Loader::layout); add("scale", &Loader::scale); @@ -49,57 +38,49 @@ Catalogue::Loader::Loader(Catalogue &c): void Catalogue::Loader::layout() { - load_sub(obj.layout); + load_sub(cat.layout); } void Catalogue::Loader::scale(float n, float d) { - obj.scale = n/d; + cat.scale = n/d; } -void Catalogue::Loader::signal(ArticleNumber art_nr) +void Catalogue::Loader::signal(const string &n) { - if(obj.objects.count(art_nr)) - throw key_error(art_nr); - - RefPtr sig = new SignalType(art_nr); + RefPtr sig = new SignalType(n); load_sub(*sig); - obj.add(*sig.release()); + cat.add(n, sig.get()); + sig.release(); } -void Catalogue::Loader::terrain(ArticleNumber art_nr) +void Catalogue::Loader::terrain(const string &n) { - if(obj.objects.count(art_nr)) - throw key_error(art_nr); - - RefPtr ter = new TerrainType(art_nr); + RefPtr ter = new TerrainType(n); load_sub(*ter); - obj.add(*ter.release()); + cat.add(n, ter.get()); + ter.release(); } -void Catalogue::Loader::track(ArticleNumber art_nr) +void Catalogue::Loader::track(const string &n) { - if(obj.objects.count(art_nr)) - throw key_error(art_nr); - - RefPtr trk = new TrackType(art_nr, obj.appearance); + RefPtr trk = new TrackType(n, &cat.appearance); load_sub(*trk); - obj.add(*trk.release()); + cat.add(n, trk.get()); + trk.release(); } void Catalogue::Loader::track_appearance() { - load_sub(obj.appearance); + load_sub(cat.appearance); } -void Catalogue::Loader::vehicle(ArticleNumber art_nr) +void Catalogue::Loader::vehicle(const string &n) { - if(obj.objects.count(art_nr)) - throw key_error(art_nr); - - RefPtr veh = new VehicleType(art_nr); + RefPtr veh = new VehicleType(n); load_sub(*veh); - obj.add(*veh.release()); + cat.add(n, veh.get()); + veh.release(); } } // namespace R2C2 diff --git a/source/libr2c2/catalogue.h b/source/libr2c2/catalogue.h index 92d1149..e8a4744 100644 --- a/source/libr2c2/catalogue.h +++ b/source/libr2c2/catalogue.h @@ -2,7 +2,7 @@ #define LIBR2C2_CATALOGUE_H_ #include -#include +#include #include "articlenumber.h" #include "layout.h" #include "trackappearance.h" @@ -11,47 +11,35 @@ namespace R2C2 { class ObjectType; -class Catalogue +class Catalogue: public Msp::DataFile::Collection { public: - class Loader: public Msp::DataFile::ObjectLoader + class Loader: public Msp::DataFile::Collection::Loader { + private: + Catalogue &cat; + public: Loader(Catalogue &); private: void layout(); void scale(float, float); - void signal(ArticleNumber); - void terrain(ArticleNumber); - void track(ArticleNumber); + void signal(const std::string &); + void terrain(const std::string &); + void track(const std::string &); void track_appearance(); - void vehicle(ArticleNumber); + void vehicle(const std::string &); }; - typedef std::map ObjectMap; - - sigc::signal signal_object_added; - private: float scale; TrackAppearance appearance; - ObjectMap objects; Layout layout; public: Catalogue(); - ~Catalogue(); float get_scale() const { return scale; } - - void add(ObjectType &); - const ObjectType &get(const ArticleNumber &) const; - const ObjectMap &get_all() const { return objects; } - - template - const T &get(const ArticleNumber &an) const - { return dynamic_cast(get(an)); } - Layout &get_layout() { return layout; } }; diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index 43ce921..0901382 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -420,7 +420,7 @@ void Layout::save(const string &fn) const for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { DataFile::Statement st("track"); - st.append((*i)->get_type().get_article_number()); + st.append(catalogue.get_name(&(*i)->get_type())); (*i)->save(st.sub); writer.write(st); } @@ -429,7 +429,7 @@ void Layout::save(const string &fn) const for(set::const_iterator i=signals.begin(); i!=signals.end(); ++i) { DataFile::Statement st("signal"); - st.append((*i)->get_type().get_article_number()); + st.append(catalogue.get_name(&(*i)->get_type())); (*i)->save(st.sub); writer.write(st); } @@ -438,7 +438,7 @@ void Layout::save(const string &fn) const for(set::const_iterator i=terrains.begin(); i!=terrains.end(); ++i) { DataFile::Statement st("terrain"); - st.append((*i)->get_type().get_article_number()); + st.append(catalogue.get_name(&(*i)->get_type())); (*i)->save(st.sub); writer.write(st); } @@ -490,7 +490,7 @@ void Layout::save_dynamic(const string &fn) const for(map::const_iterator i=trains.begin(); i!=trains.end(); ++i) { DataFile::Statement st("train"); - st.append(i->second->get_locomotive_type().get_article_number()); + st.append(catalogue.get_name(&i->second->get_locomotive_type())); st.append(i->second->get_address()); st.append(i->second->get_protocol()); i->second->save(st.sub); @@ -594,21 +594,21 @@ void Layout::Loader::route() load_sub(*rte); } -void Layout::Loader::signal(ArticleNumber art_nr) +void Layout::Loader::signal(const string &n) { - Signal *sig = new Signal(obj, obj.catalogue.get(art_nr)); + Signal *sig = new Signal(obj, obj.catalogue.get(n)); load_sub(*sig); } -void Layout::Loader::terrain(ArticleNumber art_nr) +void Layout::Loader::terrain(const string &n) { - Terrain *ter = new Terrain(obj, obj.catalogue.get(art_nr)); + Terrain *ter = new Terrain(obj, obj.catalogue.get(n)); load_sub(*ter); } -void Layout::Loader::track(ArticleNumber art_nr) +void Layout::Loader::track(const string &n) { - Track *trk = new Track(obj, obj.catalogue.get(art_nr)); + Track *trk = new Track(obj, obj.catalogue.get(n)); load_sub(*trk); const set &tracks = obj.objects.get(); for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) @@ -616,9 +616,9 @@ void Layout::Loader::track(ArticleNumber art_nr) trk->link_to(**i); } -void Layout::Loader::train(ArticleNumber art_nr, unsigned addr, const std::string &proto) +void Layout::Loader::train(const string &n, unsigned addr, const std::string &proto) { - Train *trn = new Train(obj, obj.catalogue.get(art_nr), addr, proto); + Train *trn = new Train(obj, obj.catalogue.get(n), addr, proto); load_sub(*trn); } diff --git a/source/libr2c2/layout.h b/source/libr2c2/layout.h index 41de73d..887b2d1 100644 --- a/source/libr2c2/layout.h +++ b/source/libr2c2/layout.h @@ -36,10 +36,10 @@ public: void beamgate(); void clock(); void route(); - void signal(ArticleNumber); - void terrain(ArticleNumber); - void track(ArticleNumber); - void train(ArticleNumber, unsigned, const std::string &); + void signal(const std::string &); + void terrain(const std::string &); + void track(const std::string &); + void train(const std::string &, unsigned, const std::string &); void turnout(unsigned, unsigned); void zone(); }; diff --git a/source/libr2c2/signaltype.h b/source/libr2c2/signaltype.h index 97de833..be3857a 100644 --- a/source/libr2c2/signaltype.h +++ b/source/libr2c2/signaltype.h @@ -37,7 +37,7 @@ private: std::string object; public: - SignalType(const ArticleNumber &); + SignalType(const ArticleNumber & = ArticleNumber()); const IndicationList &get_indications() const { return indications; } const std::string &get_object() const { return object; } diff --git a/source/libr2c2/terraintype.h b/source/libr2c2/terraintype.h index f0013ad..8bd59ea 100644 --- a/source/libr2c2/terraintype.h +++ b/source/libr2c2/terraintype.h @@ -37,7 +37,7 @@ private: float elevation_granularity; public: - TerrainType(const ArticleNumber &); + TerrainType(const ArticleNumber & = ArticleNumber()); unsigned get_n_surface_types() const { return surface_types.size(); } const SurfaceType &get_surface_type(unsigned) const; diff --git a/source/libr2c2/tracktype.cpp b/source/libr2c2/tracktype.cpp index 3c6876b..c2740f1 100644 --- a/source/libr2c2/tracktype.cpp +++ b/source/libr2c2/tracktype.cpp @@ -8,16 +8,23 @@ using namespace Msp; namespace R2C2 { -TrackType::TrackType(const ArticleNumber &an, const TrackAppearance &ta): +TrackType::TrackType(const ArticleNumber &an, const TrackAppearance *ta): ObjectType(an), appearance(ta), state_bits(0), autofit_preference(1) { } +const TrackAppearance &TrackType::get_appearance() const +{ + if(!appearance) + throw logic_error("no appearance"); + return *appearance; +} + float TrackType::get_gauge() const { - return appearance.get_gauge(); + return get_appearance().get_gauge(); } float TrackType::get_total_length() const diff --git a/source/libr2c2/tracktype.h b/source/libr2c2/tracktype.h index 9d167d1..2a11613 100644 --- a/source/libr2c2/tracktype.h +++ b/source/libr2c2/tracktype.h @@ -41,7 +41,7 @@ public: }; private: - const TrackAppearance &appearance; + const TrackAppearance *appearance; std::vector parts; std::vector endpoints; unsigned state_bits; @@ -49,9 +49,9 @@ private: std::string object; public: - TrackType(const ArticleNumber &, const TrackAppearance &); + TrackType(const ArticleNumber & = ArticleNumber(), const TrackAppearance * = 0); - const TrackAppearance &get_appearance() const { return appearance; } + const TrackAppearance &get_appearance() const; float get_gauge() const; float get_total_length() const; float get_path_length(int) const; diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index b670d41..6ba8684 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -385,9 +385,10 @@ void Train::save(list &st) const { st.push_back((DataFile::Statement("name"), name)); + const Catalogue &cat = layout.get_catalogue(); for(vector::const_iterator i=vehicles.begin(); i!=vehicles.end(); ++i) if(i!=vehicles.begin()) - st.push_back((DataFile::Statement("vehicle"), (*i)->get_type().get_article_number())); + st.push_back((DataFile::Statement("vehicle"), cat.get_name(&(*i)->get_type()))); if(speed_quantizer) { @@ -623,9 +624,9 @@ void Train::Loader::timetable() load_sub(*ttbl, obj.layout); } -void Train::Loader::vehicle(ArticleNumber art_nr) +void Train::Loader::vehicle(const string &n) { - const VehicleType &vtype = obj.layout.get_catalogue().get(art_nr); + const VehicleType &vtype = obj.layout.get_catalogue().get(n); Vehicle *veh = new Vehicle(obj.layout, vtype); obj.vehicles.back()->attach_back(*veh); obj.vehicles.push_back(veh); diff --git a/source/libr2c2/train.h b/source/libr2c2/train.h index 6d9a20f..113af0e 100644 --- a/source/libr2c2/train.h +++ b/source/libr2c2/train.h @@ -36,7 +36,7 @@ public: void quantized_speed(); void router(); void timetable(); - void vehicle(ArticleNumber); + void vehicle(const std::string &); }; sigc::signal signal_name_changed; diff --git a/source/libr2c2/vehicletype.h b/source/libr2c2/vehicletype.h index 789aeb3..4a4d725 100644 --- a/source/libr2c2/vehicletype.h +++ b/source/libr2c2/vehicletype.h @@ -180,7 +180,7 @@ private: float max_speed; public: - VehicleType(const ArticleNumber &); + VehicleType(const ArticleNumber & = ArticleNumber()); bool is_locomotive() const { return locomotive; } unsigned get_max_function() const; diff --git a/source/network/server.cpp b/source/network/server.cpp index aced6f7..a892ded 100644 --- a/source/network/server.cpp +++ b/source/network/server.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "libr2c2/catalogue.h" #include "libr2c2/driver.h" #include "libr2c2/route.h" #include "libr2c2/train.h" @@ -74,7 +75,7 @@ void Server::train_added(Train &train) TrainInfoPacket pkt; pkt.address = train.get_address(); - pkt.loco_type = train.get_locomotive_type().get_article_number().str(); + pkt.loco_type = layout.get_catalogue().get_name(&train.get_locomotive_type()); pkt.name = train.get_name(); send(pkt); @@ -169,6 +170,7 @@ void Server::Connection::handshake_done() comm.send(pkt); } + const Catalogue &cat = server.layout.get_catalogue(); const map &trains = server.layout.get_trains(); for(map::const_iterator i=trains.begin(); i!=trains.end(); ++i) { @@ -177,7 +179,7 @@ void Server::Connection::handshake_done() { TrainInfoPacket pkt; pkt.address = train.get_address(); - pkt.loco_type = train.get_locomotive_type().get_article_number().str(); + pkt.loco_type = cat.get_name(&train.get_locomotive_type()); pkt.name = train.get_name(); comm.send(pkt); } diff --git a/source/shoppinglist/main.cpp b/source/shoppinglist/main.cpp index 4ebd956..276a4c7 100644 --- a/source/shoppinglist/main.cpp +++ b/source/shoppinglist/main.cpp @@ -4,11 +4,9 @@ #include #include #include -#include "libr2c2/articlenumber.h" using namespace std; using namespace Msp; -using namespace R2C2; class ShoppingList: public RegisteredApplication { @@ -20,7 +18,7 @@ private: private: ShoppingList &sl; - void track(ArticleNumber, int); + void track(const string &, int); }; class LayoutLoader: public DataFile::Loader @@ -30,11 +28,11 @@ private: private: ShoppingList &sl; - void track(ArticleNumber); + void track(const string &); }; - map inventory; - map layout; + map inventory; + map layout; public: ShoppingList(int, char **); @@ -59,37 +57,37 @@ ShoppingList::ShoppingList(int argc, char **argv) int ShoppingList::main() { IO::print("// Need to get:\n"); - for(map::iterator i=layout.begin(); i!=layout.end(); ++i) + for(map::iterator i=layout.begin(); i!=layout.end(); ++i) { - map::iterator j=inventory.find(i->first); + map::iterator j=inventory.find(i->first); if(j!=inventory.end()) { if(j->secondsecond) - IO::print("track \\%d %d;\n", i->first, i->second-j->second); + IO::print("track \"%s\" %d;\n", i->first, i->second-j->second); } else - IO::print("track \\%d %d;\n", i->first, i->second); + IO::print("track \"%s\" %d;\n", i->first, i->second); } IO::print("// Pre-existing:\n"); - for(map::iterator i=layout.begin(); i!=layout.end(); ++i) + for(map::iterator i=layout.begin(); i!=layout.end(); ++i) { - map::iterator j=inventory.find(i->first); + map::iterator j=inventory.find(i->first); if(j!=inventory.end()) - IO::print("track \\%d %d;\n", i->first, min(i->second, j->second)); + IO::print("track \"%s\" %d;\n", i->first, min(i->second, j->second)); } IO::print("// Unused:\n"); - for(map::iterator i=inventory.begin(); i!=inventory.end(); ++i) + for(map::iterator i=inventory.begin(); i!=inventory.end(); ++i) { - map::iterator j=layout.find(i->first); + map::iterator j=layout.find(i->first); if(j!=layout.end()) { if(j->secondsecond) - IO::print("track \\%d %d;\n", i->first, i->second-j->second); + IO::print("track \"%s\" %d;\n", i->first, i->second-j->second); } else - IO::print("track \\%d %d;\n", i->first, i->second); + IO::print("track \"%s\" %d;\n", i->first, i->second); } return 0; @@ -118,9 +116,9 @@ ShoppingList::InventoryLoader::InventoryLoader(ShoppingList &s): add("track", &InventoryLoader::track); } -void ShoppingList::InventoryLoader::track(ArticleNumber art_nr, int count) +void ShoppingList::InventoryLoader::track(const string &n, int count) { - sl.inventory[art_nr] += count; + sl.inventory[n] += count; } @@ -136,7 +134,7 @@ ShoppingList::LayoutLoader::LayoutLoader(ShoppingList &s): add("zone"); } -void ShoppingList::LayoutLoader::track(ArticleNumber art_nr) +void ShoppingList::LayoutLoader::track(const string &n) { - ++sl.layout[art_nr]; + ++sl.layout[n]; } diff --git a/terrain.dat b/terrain.dat index e32551d..073c5b7 100644 --- a/terrain.dat +++ b/terrain.dat @@ -1,4 +1,4 @@ -terrain \100001 +terrain "100001" { surface { @@ -10,7 +10,7 @@ terrain \100001 layout { - terrain \100001 + terrain "100001" { position 0.1519720 0.2448861 0.000000; rotation 0.000000; diff --git a/tracks.dat b/tracks.dat index 9122457..057b40a 100644 --- a/tracks.dat +++ b/tracks.dat @@ -42,7 +42,7 @@ track_appearance // Straight -track \24064 +track "24064" { description "Straight, 64.3mm (R3-R4-R5)"; part @@ -51,7 +51,7 @@ track \24064 }; }; -track \24071 +track "24071" { description "Straight, 70.8mm (for slim turnouts)"; part @@ -61,7 +61,7 @@ track \24071 autofit_preference 0; }; -track \24077 +track "24077" { description "Straight, 77.5mm (R1-R2-R3)"; part @@ -71,7 +71,7 @@ track \24077 autofit_preference 2; }; -track \24094 +track "24094" { description "Straight, 94.2mm"; part @@ -81,7 +81,7 @@ track \24094 autofit_preference 2; }; -track \24172 +track "24172" { description "Straight, 171.7mm"; part @@ -91,7 +91,7 @@ track \24172 autofit_preference 2; }; -track \24188 +track "24188" { description "Straight, 188.3mm (turnout length)"; part @@ -101,7 +101,7 @@ track \24188 autofit_preference 2; }; -track \24229 +track "24229" { description "Straight, 229.3mm"; part @@ -110,7 +110,7 @@ track \24229 }; }; -track \24236 +track "24236" { description "Straight, 236.1mm (slim turnout length)"; part @@ -119,7 +119,7 @@ track \24236 }; }; -track \24360 +track "24360" { description "Straight, 360mm"; part @@ -130,7 +130,7 @@ track \24360 // Curves, R1 -track \24107 +track "24107" { description "Curve, R1 = 360mm, 7.5°"; part @@ -140,7 +140,7 @@ track \24107 }; }; -track \24115 +track "24115" { description "Curve, R1 = 360mm, 15°"; part @@ -150,7 +150,7 @@ track \24115 }; }; -track \24130 +track "24130" { description "Curve, R1 = 360mm, 30°"; part @@ -162,7 +162,7 @@ track \24130 // Curves, R2 -track \24206 +track "24206" { description "Curve, R2 = 437.5mm, 5.7° (turnout to 30°)"; part @@ -172,7 +172,7 @@ track \24206 }; }; -track \24207 +track "24207" { description "Curve, R2 = 437.5mm, 7.5°"; part @@ -182,7 +182,7 @@ track \24207 }; }; -track \24215 +track "24215" { description "Curve, R2 = 437.5mm, 15°"; part @@ -192,7 +192,7 @@ track \24215 }; }; -track \24224 +track "24224" { description "Curve, R2 = 437.5mm, 24.3° (turnout)"; part @@ -202,7 +202,7 @@ track \24224 }; }; -track \24230 +track "24230" { description "Curve, R2 = 437.5mm, 30°"; part @@ -214,7 +214,7 @@ track \24230 // Curves, R3 -track \24330 +track "24330" { description "Curve, R3 = 515mm, 30°"; part @@ -226,7 +226,7 @@ track \24330 // Curves, R4 -track \24430 +track "24430" { description "Curve, R4 = 579.3mm, 30°"; part @@ -238,7 +238,7 @@ track \24430 // Curves, R5 -track \24530 +track "24530" { description "Curve, R5 = 643.6mm, 30°"; part @@ -250,7 +250,7 @@ track \24530 // Curves, slim turnout -track \24912 +track "24912" { description "Curve, R = 1114.6mm, 12.1° (slim turnout)"; part @@ -262,7 +262,7 @@ track \24912 // Curved turnouts, R1 -track \24671 +track "24671" { description "Curved turnout, left"; part @@ -285,7 +285,7 @@ track \24671 }; }; -track \24672 +track "24672" { description "Curved turnout, right"; part @@ -310,7 +310,7 @@ track \24672 // Turnouts, R2 -track \24611 +track "24611" { description "Turnout, left"; part @@ -326,7 +326,7 @@ track \24611 }; }; -track \24612 +track "24612" { description "Turnout, right"; part @@ -342,7 +342,7 @@ track \24612 }; }; -track \24630 +track "24630" { description "Turnout, 3-way"; part @@ -364,7 +364,7 @@ track \24630 }; }; -track \24624 +track "24624" { description "Turnout, double slip"; state_bits 1; @@ -396,7 +396,7 @@ track \24624 // Slim turnouts -track \24711 +track "24711" { description "Slim turnout, left"; part @@ -412,7 +412,7 @@ track \24711 }; }; -track \24712 +track "24712" { description "Slim turnout, right"; part @@ -430,7 +430,7 @@ track \24712 // Crossings -track \24640 +track "24640" { description "Crossing, 24.3°"; part @@ -444,7 +444,7 @@ track \24640 }; }; -track \24649 +track "24649" { description "Crossing, 48.6°"; part @@ -458,7 +458,7 @@ track \24649 }; }; -track \24740 +track "24740" { description "Slim crossing, 12.1°"; part @@ -474,7 +474,7 @@ track \24740 // Specials -track \24977 +track "24977" { description "Bumper"; object "bumper.object"; @@ -487,7 +487,7 @@ track \24977 // Signals -signal \7039 +signal "7039" { indication "Hp1" { @@ -511,172 +511,172 @@ layout position -0.3876098 0.3496740 0.000000; rotation 1.570800; }; - track \24115 + track "24115" { position 0.0806517 0.139002 0; rotation 2.22529; }; - track \24612 + track "24612" { position -0.310086 -0.38055 0; rotation 1.5708; }; - track \24172 + track "24172" { position -0.232565 -0.0797749 0; rotation 1.5708; }; - track \24611 + track "24611" { position -0.387608 -0.380475 0; rotation 1.5708; }; - track \24130 + track "24130" { position 0.155044 -0.08015 0; rotation 1.5708; }; - track \24230 + track "24230" { position 0.232566 -0.0802249 0; rotation 1.5708; }; - track \24107 + track "24107" { position -0.0249545 0.231617 0; rotation 2.61799; }; - track \24224 + track "24224" { position -0.465131 -0.38055 0; rotation 1.5708; }; - track \24330 + track "24330" { position 0.310088 -0.0803 0; rotation 1.5708; }; - track \24215 + track "24215" { position 0.142158 0.186105 0; rotation 2.2253; }; - track \24207 + track "24207" { position 0.0138165 0.298658 0; rotation 2.61799; }; - track \24711 + track "24711" { position 0.374455 -0.381008 0; rotation 1.5708; }; - track \24530 + track "24530" { position 0.438821 -0.0809179 0; rotation 1.5708; }; - track \24430 + track "24430" { position 0.374455 -0.080609 0; rotation 1.5708; }; - track \24630 + track "24630" { position -0.19005 -0.380551 0; rotation 1.5708; }; - track \24712 + track "24712" { position 0.438821 -0.381316 0; rotation 1.5708; }; - track \24624 + track "24624" { position -0.0775215 -0.380625 0; rotation 1.5708; }; - track \24640 + track "24640" { position -0.232565 0.185972 0; rotation 1.5708; }; - track \24671 + track "24671" { position 0.0775225 -0.380624 0; rotation 1.5708; }; - track \24977 + track "24977" { position -0.465131 0.186196 0; rotation 1.5708; }; - track \24672 + track "24672" { position 0.155044 -0.380699 0; rotation 1.5708; }; - track \24649 + track "24649" { position -0.348827 0.194312 0; rotation 1.99491; }; - track \24064 + track "24064" { position 0.0775223 -0.080075 0; rotation 1.5708; }; - track \24077 + track "24077" { position -0.0775215 -0.079925 0; rotation 1.5708; }; - track \24229 + track "24229" { position -0.387609 -0.079626 0; rotation 1.5708; }; - track \24071 + track "24071" { position 2.56295e-07 -0.0799999 0; rotation 1.5708; }; - track \24094 + track "24094" { position -0.155042 -0.07985 0; rotation 1.5708; }; - track \24188 + track "24188" { position -0.310087 -0.0797 0; rotation 1.5708; }; - track \24236 + track "24236" { position -0.465131 -0.0795509 0; rotation 1.5708; }; - track \24912 + track "24912" { position 0.310088 -0.380699 0; rotation 1.5708; }; - track \24206 + track "24206" { position -0.446223 -0.161726 0; rotation 2.0944; }; - track \24740 + track "24740" { position -0.112537 0.138174 0; rotation 1.5708; }; - track \24360 + track "24360" { position -0.542646 -0.0794758 0; rotation 1.5708; }; - signal \7039 + signal "7039" { position -0.5020055 0.3153508 0.000000; rotation 1.570800; diff --git a/wagons.dat b/wagons.dat index 4f0592c..6e11068 100644 --- a/wagons.dat +++ b/wagons.dat @@ -1,6 +1,6 @@ scale 1 87; -vehicle \46274 +vehicle "46274" { name "Saar Railroad Gmhs 54"; @@ -15,7 +15,7 @@ vehicle \46274 axle { position -31; wheel_diameter 10; }; }; -vehicle \29820-02b +vehicle "29820-02b" { name "BR 50 tender"; @@ -42,7 +42,7 @@ vehicle \29820-02b }; }; -vehicle \4442 +vehicle "4442" { name "Z"; @@ -57,7 +57,7 @@ vehicle \4442 axle { position -31; wheel_diameter 10; }; }; -vehicle \29859b +vehicle "29859b" { name "Zas"; @@ -82,7 +82,7 @@ vehicle \29859b }; }; -vehicle \100004 +vehicle "100004" { name "Omm 52"; @@ -97,7 +97,7 @@ vehicle \100004 axle { position -31; wheel_diameter 10; }; }; -vehicle \47001 +vehicle "47001" { name "Rs 684"; @@ -124,7 +124,7 @@ vehicle \47001 }; }; -vehicle \48943 +vehicle "48943" { name "BTr 10"; @@ -139,7 +139,7 @@ vehicle \48943 axle { position -23; wheel_diameter 10; }; }; -vehicle \43222 +vehicle "43222" { name "B4üw 38 \"Schürzenwagen\""; @@ -164,7 +164,7 @@ vehicle \43222 }; }; -vehicle \39230b +vehicle "39230b" { name "BR 23 tender"; @@ -189,7 +189,7 @@ vehicle \39230b }; }; -vehicle \43800 +vehicle "43800" { name "B4nzb 64 \"Silberling\""; @@ -217,7 +217,7 @@ vehicle \43800 }; }; -vehicle \47072 +vehicle "47072" { name "Sgns 691"; @@ -244,7 +244,7 @@ vehicle \47072 }; }; -vehicle \4624 +vehicle "4624" { name "Fals-u 176"; @@ -271,7 +271,7 @@ vehicle \4624 }; }; -vehicle \4423 +vehicle "4423" { name "Kklm 505"; @@ -286,7 +286,7 @@ vehicle \4423 axle { position -31; wheel_diameter 10; }; }; -vehicle \4410 +vehicle "4410" { name "Gs 210"; @@ -301,7 +301,7 @@ vehicle \4410 axle { position -31; wheel_diameter 10; }; }; -vehicle \46977 +vehicle "46977" { name "Rlmmso 56"; @@ -316,7 +316,7 @@ vehicle \46977 axle { position -46; wheel_diameter 10; }; }; -vehicle \4699 +vehicle "4699" { name "Pwg 14"; @@ -331,7 +331,7 @@ vehicle \4699 axle { position -25; wheel_diameter 10; }; }; -vehicle \46717 +vehicle "46717" { name "Railway crane"; @@ -347,7 +347,7 @@ vehicle \46717 axle { position -21.5; wheel_diameter 10; }; }; -vehicle \4690 +vehicle "4690" { name "Eaos 106"; @@ -375,7 +375,7 @@ vehicle \4690 }; }; -vehicle \37504b +vehicle "37504b" { // XXX The power car is really in the middle, but that configuration isn't supported yet name "BR 421 S-bahn"; @@ -404,7 +404,7 @@ vehicle \37504b }; }; -vehicle \37504c +vehicle "37504c" { // XXX Better solution would be to allow flipping of vehicles name "BR 420 S-bahn"; -- 2.45.2