]> git.mxchange.org Git - flightgear.git/blob - src/Main/util.cxx
Multiplayer client/server system -- Fix building MPS enabled binary
[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 #if defined(FG_NETWORK_OLK)
36 #include <NetworkOLK/network.h>
37 #endif
38
39
40 void
41 fgDefaultWeatherValue (const char * propname, double value)
42 {
43     unsigned int i;
44
45     SGPropertyNode * branch = fgGetNode("/environment/config/boundary", true);
46     vector<SGPropertyNode_ptr> entries = branch->getChildren("entry");
47     for (i = 0; i < entries.size(); i++) {
48         entries[i]->setDoubleValue(propname, value);
49     }
50
51     branch = fgGetNode("/environment/config/aloft", true);
52     entries = branch->getChildren("entry");
53     for (i = 0; i < entries.size(); i++) {
54         entries[i]->setDoubleValue(propname, value);
55     }
56 }
57
58
59 void
60 fgExit (int status)
61 {
62     SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status);
63
64 #if defined(FG_NETWORK_OLK)
65     if (fgGetBool("/sim/networking/network-olk"))
66         fgd_send_com("8", FGFS_host);
67 #endif
68
69     globals->get_io()->shutdown_all();
70     exit(status);
71 }
72
73
74 // Originally written by Alex Perry.
75 double
76 fgGetLowPass (double current, double target, double timeratio)
77 {
78     if ( timeratio < 0.0 ) {
79         if ( timeratio < -1.0 ) {
80                                 // time went backwards; kill the filter
81                 current = target;
82         } else {
83                                 // ignore mildly negative time
84         }
85     } else if ( timeratio < 0.2 ) {
86                                 // Normal mode of operation; fast
87                                 // approximation to exp(-timeratio)
88         current = current * (1.0 - timeratio) + target * timeratio;
89     } else if ( timeratio > 5.0 ) {
90                                 // Huge time step; assume filter has settled
91         current = target;
92     } else {
93                                 // Moderate time step; non linear response
94         double keep = exp(-timeratio);
95         current = current * keep + target * (1.0 - keep);
96     }
97
98     return current;
99 }
100
101 // end of util.cxx
102