]> git.mxchange.org Git - flightgear.git/blob - src/Airports/airportdynamicsmanager.cxx
Interim windows build fix
[flightgear.git] / src / Airports / airportdynamicsmanager.cxx
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 <zakalawe@mac.com>
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         throw sg_exception("dynamicsForICAO: Invalid ICAO:" + icao);
80     FGAirportDynamicsRef d(new FGAirportDynamics(apt));
81
82     XMLLoader::load(d.ptr());
83     d->init();
84
85     FGRunwayPreference rwyPrefs(apt);
86     XMLLoader::load(&rwyPrefs);
87     d->setRwyUse(rwyPrefs);
88
89     m_dynamics[icao] = d;
90     return d;
91 }
92
93 FGAirportDynamicsRef AirportDynamicsManager::find(const std::string &icao)
94 {
95     AirportDynamicsManager* instance = static_cast<AirportDynamicsManager*>(globals->get_subsystem("airport-dynamics"));
96     if (!instance)
97         return FGAirportDynamicsRef();
98
99     return instance->dynamicsForICAO(icao);
100 }
101
102 FGAirportDynamicsRef AirportDynamicsManager::find(const FGAirportRef& apt)
103 {
104     return find(apt->ident());
105 }
106
107 } // of namespace flightgear