]> git.mxchange.org Git - flightgear.git/blob - src/Airports/airportdynamicsmanager.cxx
Trying to bullet-proof the traffic code.
[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         return FGAirportDynamicsRef();
80
81     FGAirportDynamicsRef d(new FGAirportDynamics(apt));
82
83     XMLLoader::load(d.ptr());
84     d->init();
85
86     FGRunwayPreference rwyPrefs(apt);
87     XMLLoader::load(&rwyPrefs);
88     d->setRwyUse(rwyPrefs);
89
90     m_dynamics[icao] = d;
91     return d;
92 }
93
94 FGAirportDynamicsRef AirportDynamicsManager::find(const std::string &icao)
95 {
96     if (icao.empty())
97         return FGAirportDynamicsRef();
98
99     AirportDynamicsManager* instance = static_cast<AirportDynamicsManager*>(globals->get_subsystem("airport-dynamics"));
100     if (!instance)
101         return FGAirportDynamicsRef();
102
103     return instance->dynamicsForICAO(icao);
104 }
105
106 FGAirportDynamicsRef AirportDynamicsManager::find(const FGAirportRef& apt)
107 {
108     return find(apt->ident());
109 }
110
111 } // of namespace flightgear