3 // Written by James Turner, started December 2012.
5 // Copyright (C) 2012 James Turner - zakalawe (at) mac com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 ///////////////////////////////////////////////////////////////////////////////
23 #ifndef FG_AIRCRAFT_FLIGHT_HISTORY_HXX
24 #define FG_AIRCRAFT_FLIGHT_HISTORY_HXX
26 #include <simgear/structure/subsystem_mgr.hxx>
27 #include <simgear/props/props.hxx>
28 #include <simgear/math/SGMath.hxx>
31 #include <memory> // for std::auto_ptr
33 typedef std::vector<SGGeod> SGGeodVec;
36 * record the history of the aircraft's movements, making it available
37 * as a contiguous block. This can be used to show the historical flight-path
38 * over a long period of time (unlike the replay system), but only a small,
39 * fixed set of properties are recorded. (Positioned and orientation, but
40 * not velocity, acceleration, control inputs, or so on)
42 class FGFlightHistory : public SGSubsystem
46 virtual ~FGFlightHistory();
49 virtual void shutdown();
50 virtual void reinit();
51 virtual void update(double dt);
54 * retrieve the path, collapsing segments shorter than
55 * the specified minimum length
57 SGGeodVec pathForHistory(double minEdgeLengthM = 50.0) const;
60 * @class A single data sample in the history system.
66 /// heading, pitch and roll can be recorded at lower precision
67 /// than a double - actually 16 bits might be sufficient
68 float heading, pitch, roll;
72 static const int SAMPLE_BUCKET_WIDTH = 1024;
75 * Bucket is a fixed-size container of samples. This is a crude slab
76 * allocation of samples, in chunks defined by the width constant above.
77 * Keep in mind that even with a 1Hz sample frequency, we use less than
78 * 200kbytes per hour - avoiding continous malloc traffic, or expensive
79 * std::vector reallocations, is the key factor here.
84 Sample samples[SAMPLE_BUCKET_WIDTH];
87 double m_lastCaptureTime;
88 double m_sampleInterval; ///< sample interval in seconds
89 /// our store of samples (in buckets). The last bucket is partially full,
90 /// with the number of valid samples indicated by m_validSampleCount
91 std::vector<SampleBucket*> m_buckets;
93 /// number of valid samples in the final bucket
94 unsigned int m_validSampleCount;
96 SGPropertyNode_ptr m_weightOnWheels;
97 SGPropertyNode_ptr m_enabled;
100 size_t m_maxMemoryUseBytes;
102 void allocateNewBucket();
107 size_t currentMemoryUseBytes() const;