]> git.mxchange.org Git - flightgear.git/blob - src/Main/util.cxx
Move the texture loader to SimGear
[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 <math.h>
22
23 #include <simgear/debug/logstream.hxx>
24
25 #include "fg_io.hxx"
26 #include "fg_props.hxx"
27 #include "globals.hxx"
28 #include "util.hxx"
29
30 #if defined(FG_NETWORK_OLK)
31 #include <NetworkOLK/network.h>
32 #endif
33
34
35 void
36 fgExit (int status)
37 {
38     SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status);
39
40 #if defined(FG_NETWORK_OLK)
41     if (fgGetBool("/sim/networking/network-olk"))
42         fgd_send_com("8", FGFS_host);
43 #endif
44
45     globals->get_io()->shutdown_all();
46     exit(status);
47 }
48
49
50 // Originally written by Alex Perry.
51 double
52 fgGetLowPass (double current, double target, double timeratio)
53 {
54     if ( timeratio < 0.0 ) {
55         if ( timeratio < -1.0 ) {
56                                 // time went backwards; kill the filter
57                 current = target;
58         } else {
59                                 // ignore mildly negative time
60         }
61     } else if ( timeratio < 0.2 ) {
62                                 // Normal mode of operation; fast
63                                 // approximation to exp(-timeratio)
64         current = current * (1.0 - timeratio) + target * timeratio;
65     } else if ( timeratio > 5.0 ) {
66                                 // Huge time step; assume filter has settled
67         current = target;
68     } else {
69                                 // Moderate time step; non linear response
70         double keep = exp(-timeratio);
71         current = current * keep + target * (1.0 - keep);
72     }
73
74     return current;
75 }
76
77 // end of util.cxx
78