From: James Turner Date: Mon, 6 Sep 2010 08:13:10 +0000 (+0100) Subject: Use the new Simgear ResourceManager to resolve paths. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a7a2cb393a0259f4f16d905974fe25b25759a909;p=flightgear.git Use the new Simgear ResourceManager to resolve paths. --- diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index bfa51f72f..031b91607 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -56,7 +57,36 @@ #include "fg_props.hxx" #include "fg_io.hxx" - + class AircraftResourceProvider : public simgear::ResourceProvider +{ +public: + AircraftResourceProvider() : + simgear::ResourceProvider(simgear::ResourceManager::PRIORITY_HIGH) + { + } + + virtual SGPath resolve(const std::string& aResource, SGPath&) const + { + string_list pieces(sgPathBranchSplit(aResource)); + if ((pieces.size() < 3) || (pieces.front() != "Aircraft")) { + return SGPath(); // not an Aircraft path + } + + const char* aircraftDir = fgGetString("/sim/aircraft-dir"); + string_list aircraftDirPieces(sgPathBranchSplit(aircraftDir)); + if (aircraftDirPieces.empty() || (aircraftDirPieces.back() != pieces[1])) { + return SGPath(); // current aircraft-dir does not match resource aircraft + } + + SGPath r(aircraftDir); + for (unsigned int i=2; igetChild("fg-root", 0, true); n->setStringValue(fg_root.c_str()); n->setAttribute(SGPropertyNode::WRITE, false); + + simgear::ResourceManager::instance()->addBasePath(fg_root, + simgear::ResourceManager::PRIORITY_DEFAULT); } void FGGlobals::set_fg_scenery (const string &scenery) @@ -243,6 +276,9 @@ void FGGlobals::append_aircraft_path(const std::string& path) unsigned int index = fg_aircraft_dirs.size(); fg_aircraft_dirs.push_back(path); + simgear::ResourceManager::instance()->addBasePath(path, + simgear::ResourceManager::PRIORITY_NORMAL); + // make aircraft dirs available to Nasal SGPropertyNode* sim = fgGetNode("/sim", true); sim->removeChild("fg-aircraft", index, false); @@ -261,60 +297,12 @@ void FGGlobals::append_aircraft_paths(const std::string& path) SGPath FGGlobals::resolve_aircraft_path(const std::string& branch) const { - string_list pieces(sgPathBranchSplit(branch)); - if ((pieces.size() < 3) || (pieces.front() != "Aircraft")) { - SG_LOG(SG_AIRCRAFT, SG_ALERT, "resolve_aircraft_path: bad path:" << branch); - return SGPath(); - } - -// check current aircraft dir first (takes precedence, allows Generics to be -// over-riden - const char* aircraftDir = fgGetString("/sim/aircraft-dir"); - string_list aircraftDirPieces(sgPathBranchSplit(aircraftDir)); - if (!aircraftDirPieces.empty() && (aircraftDirPieces.back() == pieces[1])) { - SGPath r(aircraftDir); - - for (unsigned int i=2; ifindPath(branch); } SGPath FGGlobals::resolve_maybe_aircraft_path(const std::string& branch) const { - if (branch.find("Aircraft/") == 0) { - return resolve_aircraft_path(branch); - } else { - SGPath r(fg_root); - r.append(branch); - return r; - } + return simgear::ResourceManager::instance()->findPath(branch); } FGRenderer * diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 7fbc9d7e4..894dd0010 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -391,7 +391,6 @@ static void fgIdleFunction ( void ) { globals->set_matlib( new SGMaterialLib ); simgear::SGModelLib::init(globals->get_fg_root()); simgear::SGModelLib::setPropRoot(globals->get_props()); - simgear::SGModelLib::setResolveFunc(resolve_path); simgear::SGModelLib::setPanelFunc(load_panel); ////////////////////////////////////////////////////////////////////