]> git.mxchange.org Git - flightgear.git/blob - src/Main/util.cxx
Fix the nmea and garmin output to a) fake a GSA sentence, b) fix a y2k bug
[flightgear.git] / src / Main / util.cxx
1 // util.cxx - general-purpose utility functions.
2 // Copyright (C) 2002  Curtis L. Olson  - curt@me.umn.edu
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 //
18 // $Id$
19
20
21 #include <simgear/compiler.h>
22
23 #include <math.h>
24
25 #include <vector>
26 SG_USING_STD(vector);
27
28 #include <simgear/debug/logstream.hxx>
29
30 #include "fg_io.hxx"
31 #include "fg_props.hxx"
32 #include "globals.hxx"
33 #include "util.hxx"
34
35
36 void
37 fgDefaultWeatherValue (const char * propname, double value)
38 {
39     unsigned int i;
40
41     SGPropertyNode * branch = fgGetNode("/environment/config/boundary", true);
42     vector<SGPropertyNode_ptr> entries = branch->getChildren("entry");
43     for (i = 0; i < entries.size(); i++) {
44         entries[i]->setDoubleValue(propname, value);
45     }
46
47     branch = fgGetNode("/environment/config/aloft", true);
48     entries = branch->getChildren("entry");
49     for (i = 0; i < entries.size(); i++) {
50         entries[i]->setDoubleValue(propname, value);
51     }
52 }
53
54
55 void
56 fgExit (int status)
57 {
58     SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status);
59
60     globals->get_io()->shutdown_all();
61     exit(status);
62 }
63
64
65 // Originally written by Alex Perry.
66 double
67 fgGetLowPass (double current, double target, double timeratio)
68 {
69     if ( timeratio < 0.0 ) {
70         if ( timeratio < -1.0 ) {
71                                 // time went backwards; kill the filter
72                 current = target;
73         } else {
74                                 // ignore mildly negative time
75         }
76     } else if ( timeratio < 0.2 ) {
77                                 // Normal mode of operation; fast
78                                 // approximation to exp(-timeratio)
79         current = current * (1.0 - timeratio) + target * timeratio;
80     } else if ( timeratio > 5.0 ) {
81                                 // Huge time step; assume filter has settled
82         current = target;
83     } else {
84                                 // Moderate time step; non linear response
85         double keep = exp(-timeratio);
86         current = current * keep + target * (1.0 - keep);
87     }
88
89     return current;
90 }
91
92 // end of util.cxx
93