1 // util.cxx - general-purpose utility functions.
2 // Copyright (C) 2002 Curtis L. Olson - curt@me.umn.edu
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.
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.
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.
21 #include <simgear/compiler.h>
28 #include <simgear/debug/logstream.hxx>
31 #include "fg_props.hxx"
32 #include "globals.hxx"
35 #if defined(FG_NETWORK_OLK)
36 #include <NetworkOLK/network.h>
41 fgDefaultWeatherValue (const char * propname, double value)
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);
50 branch = fgGetNode("/environment/config/aloft", true);
51 entries = branch->getChildren("entry");
52 for (i = 0; i < entries.size(); i++)
53 entries[i]->setDoubleValue(propname, value);
60 SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status);
62 #if defined(FG_NETWORK_OLK)
63 if (fgGetBool("/sim/networking/network-olk"))
64 fgd_send_com("8", FGFS_host);
67 globals->get_io()->shutdown_all();
72 // Originally written by Alex Perry.
74 fgGetLowPass (double current, double target, double timeratio)
76 if ( timeratio < 0.0 ) {
77 if ( timeratio < -1.0 ) {
78 // time went backwards; kill the filter
81 // ignore mildly negative time
83 } else if ( timeratio < 0.2 ) {
84 // Normal mode of operation; fast
85 // approximation to exp(-timeratio)
86 current = current * (1.0 - timeratio) + target * timeratio;
87 } else if ( timeratio > 5.0 ) {
88 // Huge time step; assume filter has settled
91 // Moderate time step; non linear response
92 double keep = exp(-timeratio);
93 current = current * keep + target * (1.0 - keep);