From a2d709404d50cb755ef20829241e4ae51301e19a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 29 Apr 2014 08:32:22 +0300 Subject: [PATCH] Use GL::Resources and DirectorySource in Catalogue3D --- source/3d/catalogue.cpp | 40 +++------------------------------------ source/3d/catalogue.h | 16 ++++------------ source/3d/vehicletype.cpp | 1 + 3 files changed, 8 insertions(+), 49 deletions(-) diff --git a/source/3d/catalogue.cpp b/source/3d/catalogue.cpp index c02b7e6..2f932d6 100644 --- a/source/3d/catalogue.cpp +++ b/source/3d/catalogue.cpp @@ -1,9 +1,5 @@ #include -#include #include -#include -#include -#include #include "catalogue.h" #include "signaltype.h" #include "tracktype.h" @@ -17,11 +13,9 @@ namespace R2C2 { Catalogue3D::Catalogue3D(Catalogue &c): catalogue(c) { - add_type().creator(&Catalogue3D::create); - add_type().creator(&Catalogue3D::create); - add_type().creator(&Catalogue3D::create2); - add_type().creator(&Catalogue3D::create); - add_type().creator(&Catalogue3D::create2); + src.add_directory("."); + src.add_directory("data"); + add_source(src); catalogue.signal_object_added.connect(sigc::mem_fun(this, &Catalogue3D::object_added)); @@ -89,32 +83,4 @@ const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance return *get_item(endpoint_meshes, &appearance); } -FS::Path Catalogue3D::locate_file(const string &name) -{ - if(FS::exists(name)) - return name; - - FS::Path path = FS::Path("data")/name; - if(FS::exists(path)) - return path; - - throw runtime_error("Can't locate "+name); -} - -template -T *Catalogue3D::create(const string &name) -{ - RefPtr obj = new T; - DataFile::load(*obj, locate_file(name).str()); - return obj.release(); -} - -template -T *Catalogue3D::create2(const string &name) -{ - RefPtr obj = new T; - DataFile::load(*obj, locate_file(name).str(), *this); - return obj.release(); -} - } // namespace R2C2 diff --git a/source/3d/catalogue.h b/source/3d/catalogue.h index ea41828..07f1535 100644 --- a/source/3d/catalogue.h +++ b/source/3d/catalogue.h @@ -2,9 +2,9 @@ #define R2C2_3D_CATALOGUE_H_ #include -#include -#include +#include #include +#include #include "libr2c2/catalogue.h" #include "typemap.h" @@ -12,10 +12,11 @@ namespace R2C2 { class ObjectType3D; -class Catalogue3D: public Msp::DataFile::Collection +class Catalogue3D: public Msp::GL::Resources { private: Catalogue &catalogue; + Msp::DataFile::DirectorySource src; std::map objects; std::map endpoint_meshes; @@ -37,15 +38,6 @@ private: void build_endpoint_mesh(const TrackAppearance &); public: const Msp::GL::Mesh &get_endpoint_mesh(const TrackAppearance &) const; - -private: - Msp::FS::Path locate_file(const std::string &); - - template - T *create(const std::string &); - - template - T *create2(const std::string &); }; } diff --git a/source/3d/vehicletype.cpp b/source/3d/vehicletype.cpp index c663609..34f2be6 100644 --- a/source/3d/vehicletype.cpp +++ b/source/3d/vehicletype.cpp @@ -1,3 +1,4 @@ +#include #include #include #include -- 2.43.0