X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fglobals.cxx;h=af4e693459bce2da14c45ce1e1ebd9342388142d;hb=38226af24ec01e8f0a20d7fd73ef838a69f6ef25;hp=a7023045d22d409d35adbc945ac8712b3ddfbc6a;hpb=740195dc63f1fc8b6857c079f55d4ce0d5fcf7ff;p=flightgear.git diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index a7023045d..af4e69345 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -34,10 +34,11 @@ #include #include #include +#include +#include #include #include -#include #include #include #include @@ -45,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -57,7 +57,53 @@ #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 + } + + // test against the aircraft-dir property + const char* aircraftDir = fgGetString("/sim/aircraft-dir"); + string_list aircraftDirPieces(sgPathBranchSplit(aircraftDir)); + if (!aircraftDirPieces.empty() && (aircraftDirPieces.back() == pieces[1])) { + // current aircraft-dir matches resource aircraft + SGPath r(aircraftDir); + for (unsigned int i=2; iget_aircraft_paths()); + string_list::const_iterator it = dirs.begin(); + for (; it != dirs.end(); ++it) { + SGPath p(*it, res); + if (p.exists()) { + SG_LOG(SG_IO, SG_DEBUG, "found path:" << aResource << " in aircraft dir: " << *it); + return p; + } + } // of aircraft path iteration + + return SGPath(); // not found + } +}; + //////////////////////////////////////////////////////////////////////// // Implementation of FGGlobals. //////////////////////////////////////////////////////////////////////// @@ -77,8 +123,6 @@ FGGlobals::FGGlobals() : soundmgr( new SGSoundMgr ), sim_time_sec( 0.0 ), fg_root( "" ), - warp( 0 ), - warp_delta( 0 ), time_params( NULL ), ephem( NULL ), mag( NULL ), @@ -86,7 +130,6 @@ FGGlobals::FGGlobals() : route_mgr( NULL ), current_panel( NULL ), ATC_mgr( NULL ), - AI_mgr( NULL ), controls( NULL ), viewmgr( NULL ), commands( SGCommandMgr::instance() ), @@ -103,10 +146,10 @@ FGGlobals::FGGlobals() : dmelist( NULL ), tacanlist( NULL ), carrierlist( NULL ), - channellist( NULL ), - airwaynet( NULL ), - multiplayer_mgr( NULL ) + channellist( NULL ) { + simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider()); + simgear::PropertyObjectBase::setDefaultRoot(props); } @@ -114,23 +157,24 @@ FGGlobals::FGGlobals() : FGGlobals::~FGGlobals() { delete renderer; + renderer = NULL; + // The AIModels manager performs a number of actions upon // Shutdown that implicitly assume that other subsystems // are still operational (Due to the dynamic allocation and // deallocation of AIModel objects. To ensure we can safely // shut down all subsystems, make sure we take down the // AIModels system first. - subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("ai_model"); - // FGInput (FGInputEvent) and FGDialog calls get_subsystem() in their destructors, - // which is not safe since some subsystem are already deleted but can be referred. - // So these subsystems must be deleted prior to deleting subsystem_mgr unless - // ~SGSubsystemGroup and SGSubsystemMgr::get_subsystem are changed not to refer to - // deleted subsystems. - subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("input"); - subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("gui"); + SGSubsystem* ai = subsystem_mgr->remove("ai_model"); + if (ai) { + ai->unbind(); + delete ai; + } + + subsystem_mgr->shutdown(); subsystem_mgr->unbind(); delete subsystem_mgr; - delete event_mgr; + delete time_params; delete mag; delete matlib; @@ -138,16 +182,11 @@ FGGlobals::~FGGlobals() delete current_panel; delete ATC_mgr; - delete AI_mgr; + controls->unbind(); delete controls; - delete viewmgr; -// delete commands; - delete acmodel; - delete model_mgr; delete channel_options_list; delete initial_waypoints; - delete tile_mgr; delete scenery; delete fontcache; @@ -158,8 +197,6 @@ FGGlobals::~FGGlobals() delete tacanlist; delete carrierlist; delete channellist; - delete airwaynet; - delete multiplayer_mgr; soundmgr->unbind(); delete soundmgr; @@ -188,6 +225,9 @@ void FGGlobals::set_fg_root (const string &root) { n = n->getChild("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) @@ -242,7 +282,15 @@ void FGGlobals::append_aircraft_path(const std::string& path) return; } + unsigned int index = fg_aircraft_dirs.size(); fg_aircraft_dirs.push_back(path); + +// make aircraft dirs available to Nasal + SGPropertyNode* sim = fgGetNode("/sim", true); + sim->removeChild("fg-aircraft", index, false); + SGPropertyNode* n = sim->getChild("fg-aircraft", index, true); + n->setStringValue(path); + n->setAttribute(SGPropertyNode::WRITE, false); } void FGGlobals::append_aircraft_paths(const std::string& path) @@ -255,60 +303,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 * @@ -359,6 +359,21 @@ FGGlobals::saveInitialState () if (!copyProperties(props, initial_state)) SG_LOG(SG_GENERAL, SG_ALERT, "Error saving initial state"); + + // delete various properties from the initial state, since we want to + // preserve their values even if doing a restore + + SGPropertyNode* sim = initial_state->getChild("sim"); + sim->removeChild("presets"); + SGPropertyNode* simStartup = sim->getChild("startup"); + simStartup->removeChild("xsize"); + simStartup->removeChild("ysize"); + + SGPropertyNode* cameraGroupNode = sim->getNode("rendering/camera-group"); + if (cameraGroupNode) { + cameraGroupNode->removeChild("camera"); + cameraGroupNode->removeChild("gui"); + } } @@ -372,14 +387,6 @@ FGGlobals::restoreInitialState () return; } - SGPropertyNode *currentPresets = new SGPropertyNode; - SGPropertyNode *targetNode = fgGetNode( "/sim/presets" ); - - // stash the /sim/presets tree - if ( !copyProperties(targetNode, currentPresets) ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Failed to save /sim/presets subtree" ); - } - if ( copyProperties(initial_state, props) ) { SG_LOG( SG_GENERAL, SG_INFO, "Initial state restored successfully" ); } else { @@ -387,13 +394,6 @@ FGGlobals::restoreInitialState () "Some errors restoring initial state (read-only props?)" ); } - // recover the /sim/presets tree - if ( !copyProperties(currentPresets, targetNode) ) { - SG_LOG( SG_GENERAL, SG_ALERT, - "Failed to restore /sim/presets subtree" ); - } - - delete currentPresets; } FGViewer * @@ -402,4 +402,24 @@ FGGlobals::get_current_view () const return viewmgr->get_current_view(); } +long int FGGlobals::get_warp() const +{ + return fgGetInt("/sim/time/warp"); +} + +void FGGlobals::set_warp( long int w ) +{ + fgSetInt("/sim/time/warp", w); +} + +long int FGGlobals::get_warp_delta() const +{ + return fgGetInt("/sim/time/warp-delta"); +} + +void FGGlobals::set_warp_delta( long int d ) +{ + fgSetInt("/sim/time/warp-delta", d); +} + // end of globals.cxx