Debian Codegraph @

src/Airports/airportdynamicsmanager.cxx

raw symbols SCIP
1 // airportdynamicsmanager.cxx - manager for dynamic (changeable)
2 // part of airport state
3 //
4 // Written by James Turner, started December 2015
5 //
6 // Copyright (C) 2015 James Turner <[email protected]>
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 #include "airportdynamicsmanager.hxx"
23
24 #include <simgear/structure/exception.hxx>
25
26 #include "airport.hxx"
27 #include "xmlloader.hxx"
28 #include "dynamics.hxx"
29 #include "runwayprefs.hxx"
30
31 #include <Main/globals.hxx>
32
33 namespace flightgear
34 {
35
36 AirportDynamicsManager::AirportDynamicsManager()
37 {
38
39 }
40
41
42 AirportDynamicsManager::~AirportDynamicsManager()
43 {
44
45
46 }
47
48 void AirportDynamicsManager::init()
49 {
50
51
52 }
53
54 void AirportDynamicsManager::shutdown()
55 {
56 m_dynamics.clear();
57 }
58
59 void AirportDynamicsManager::update(double dt)
60 {
61 SG_UNUSED(dt);
62 }
63
64 void AirportDynamicsManager::reinit()
65 {
66 shutdown();
67 init();
68 }
69
70 FGAirportDynamicsRef AirportDynamicsManager::dynamicsForICAO(const std::string &icao)
71 {
72 ICAODynamicsDict::iterator it = m_dynamics.find(icao);
73 if (it != m_dynamics.end()) {
74 return it->second;
75 }
76
77 FGAirportRef apt(FGAirport::findByIdent(icao));
78 if (!apt)
79 return FGAirportDynamicsRef();
80
81 FGAirportDynamicsRef d(new FGAirportDynamics(apt));
82 d->init();
83
84 FGRunwayPreference rwyPrefs(apt);
85 XMLLoader::load(&rwyPrefs);
86 d->setRwyUse(rwyPrefs);
87
88 m_dynamics[icao] = d;
89 return d;
90 }
91
92 FGAirportDynamicsRef AirportDynamicsManager::find(const std::string &icao)
93 {
94 if (icao.empty())
95 return FGAirportDynamicsRef();
96
97 auto instance = globals->get_subsystem<AirportDynamicsManager>();
98 if (!instance)
99 return FGAirportDynamicsRef();
100
101 return instance->dynamicsForICAO(icao);
102 }
103
104 FGAirportDynamicsRef AirportDynamicsManager::find(const FGAirportRef& apt)
105 {
106 if (!apt)
107 return {};
108
109 return find(apt->ident());
110 }
111
112 // Register the subsystem.
113 SGSubsystemMgr::Registrant<AirportDynamicsManager> registrantAirportDynamicsManager;
114
115 } // of namespace flightgear