]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/ATISmgr.cxx
Fix canvas gui size sometimes not initialized correct
[flightgear.git] / src / ATCDCL / ATISmgr.cxx
1 // ATISmgr.cxx - Implementation of FGATISMgr - a global Flightgear ATIS manager.
2 //
3 // Written by David Luff, started February 2002.
4 //
5 // Copyright (C) 2002  David C Luff - david.luff@nottingham.ac.uk
6 // Copyright (C) 2012  Thorsten Brehm
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 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include <simgear/misc/sg_path.hxx>
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/structure/exception.hxx>
29
30 #include <Main/fg_props.hxx>
31
32 #include "ATISmgr.hxx"
33 #include "atis.hxx"
34
35 FGATISMgr::FGATISMgr() :
36     _currentUnit(0),
37     _maxCommRadios(4)
38 #ifdef ENABLE_AUDIO_SUPPORT
39     ,useVoice(true),
40     voice(0)
41 #endif
42 {
43     globals->set_ATIS_mgr(this);
44 }
45
46 FGATISMgr::~FGATISMgr()
47 {
48     globals->set_ATIS_mgr(NULL);
49
50     for (unsigned int unit = 0;unit < _maxCommRadios; ++unit)
51     {
52         delete radios[unit];
53         radios[unit] = NULL;
54     }
55
56 #ifdef ENABLE_AUDIO_SUPPORT
57     delete voice;
58 #endif
59 }
60
61 void FGATISMgr::init()
62 {
63     for (unsigned int unit = 0;unit < _maxCommRadios; ++unit)
64     {
65         if (unit < _maxCommRadios/2)
66             radios.push_back(new FGATIS("comm", unit));
67         else
68             radios.push_back(new FGATIS("nav", unit - _maxCommRadios/2));
69     }
70 }
71
72 void FGATISMgr::reinit()
73 {
74 #ifdef ENABLE_AUDIO_SUPPORT
75     if ((voiceName != "")&&
76         (voiceName != fgGetString("/sim/atis/voice", "default")))
77     {
78         voiceName = fgGetString("/sim/atis/voice", "default");
79         delete voice;
80         voice = NULL;
81         useVoice = true;
82     }
83 #endif
84 }
85
86 void FGATISMgr::update(double dt)
87 {
88     // update only runs every now and then (1-2 per second)
89     if (++_currentUnit >= _maxCommRadios)
90         _currentUnit = 0;
91
92     FGATC* commRadio = radios[_currentUnit];
93     if (commRadio)
94         commRadio->update(dt * _maxCommRadios);
95 }
96
97 // Return a pointer to an appropriate voice for a given type of ATC
98 // creating the voice if necessary - i.e. make sure exactly one copy
99 // of every voice in use exists in memory.
100 //
101 // TODO - in the future this will get more complex and dole out country/airport
102 // specific voices, and possible make sure that the same voice doesn't get used
103 // at different airports in quick succession if a large enough selection are available.
104 FGATCVoice* FGATISMgr::GetVoicePointer(const atc_type& type)
105 {
106 #ifdef ENABLE_AUDIO_SUPPORT
107     // TODO - implement me better - maintain a list of loaded voices and other voices!!
108     if(useVoice)
109     {
110         switch(type)
111         {
112         case ATIS: case AWOS:
113             // Delayed loading for all available voices, needed because the
114             // sound manager might not be initialized (at all) at this point.
115             // For now we'll do one hard-wired one
116
117             /* I've loaded the voice even if /sim/sound/pause is true
118              *  since I know no way of forcing load of the voice if the user
119              *  subsequently switches /sim/sound/audible to true.
120              *  (which is the right thing to do -- CLO) :-)
121              */
122             if (!voice && fgGetBool("/sim/sound/working")) {
123                 voice = new FGATCVoice;
124                 voiceName = fgGetString("/sim/atis/voice", "default");
125                 try {
126                     useVoice = voice->LoadVoice(voiceName);
127                 } catch ( sg_io_exception & e) {
128                     SG_LOG(SG_ATC, SG_ALERT, "Unable to load voice '" << voiceName << "': "
129                                             << e.getFormattedMessage().c_str());
130                     useVoice = false;
131                     delete voice;
132                     voice = 0;
133                 }
134             }
135             return voice;
136         case TOWER:
137             return NULL;
138         case APPROACH:
139             return NULL;
140         case GROUND:
141             return NULL;
142         default:
143             return NULL;
144         }
145     }
146 #endif
147
148     return NULL;
149 }