FlightGear next
FlightHistory.hxx
Go to the documentation of this file.
1/*
2 * SPDX-FileName: FlightHistory.hxx
3 * SPDX-FileCopyrightText: Copyright (C) 2012 James Turner - zakalawe (at) mac com
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#pragma once
8
9#include <vector>
10
11#include <simgear/math/SGMath.hxx>
12#include <simgear/props/props.hxx>
13#include <simgear/structure/subsystem_mgr.hxx>
14
15typedef std::vector<SGGeod> SGGeodVec;
16
17class PagedPathForHistory : public SGReferenced
18{
19public:
23 time_t last_seen;
24};
25
26typedef SGSharedPtr<PagedPathForHistory> PagedPathForHistory_ptr;
27
28const unsigned int SAMPLE_BUCKET_WIDTH = 1024;
29
37class FGFlightHistory : public SGSubsystem
38{
39public:
41 virtual ~FGFlightHistory();
42
43 // Subsystem API.
44 void init() override;
45 void reinit() override;
46 void shutdown() override;
47 void update(double dt) override;
48
49 // Subsystem identification.
50 static const char* staticSubsystemClassId() { return "history"; }
51
52 PagedPathForHistory_ptr pagedPathForHistory(size_t max_entries, size_t newerThan = 0) const;
57 SGGeodVec pathForHistory(double minEdgeLengthM = 50.0) const;
58
62
63 void clear();
64
65private:
69 class Sample
70 {
71 public:
72 SGGeod position;
75 float heading, pitch, roll;
76 size_t simTimeMSec;
77 };
78
79
87 class SampleBucket
88 {
89 public:
90 Sample samples[SAMPLE_BUCKET_WIDTH];
91 };
92
93 double m_lastCaptureTime{0.0};
94 double m_sampleInterval;
97 std::vector<SampleBucket*> m_buckets;
98
100 unsigned int m_validSampleCount;
101
102 SGPropertyNode_ptr m_weightOnWheels;
103 SGPropertyNode_ptr m_enabled;
104
105 bool m_lastWoW{false};
106 size_t m_maxMemoryUseBytes{0};
107
108 void allocateNewBucket();
109
110 void capture();
111
112 size_t currentMemoryUseBytes() const;
113};
const unsigned int SAMPLE_BUCKET_WIDTH
std::vector< SGGeod > SGGeodVec
SGSharedPtr< PagedPathForHistory > PagedPathForHistory_ptr
SGGeodVec pathForHistory(double minEdgeLengthM=50.0) const
retrieve the path, collapsing segments shorter than the specified minimum length
void update(double dt) override
static const char * staticSubsystemClassId()
void reinit() override
virtual ~FGFlightHistory()
PagedPathForHistory_ptr pagedPathForHistory(size_t max_entries, size_t newerThan=0) const
void clear()
clear the history
void shutdown() override
void init() override
virtual ~PagedPathForHistory()