swift
interpolator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_SIMULATION_INTERPOLATION_INTERPOLATOR_H
7 #define SWIFT_MISC_SIMULATION_INTERPOLATION_INTERPOLATOR_H
8 
9 #include <QString>
10 #include <QStringList>
11 #include <QTimer>
12 #include <QtGlobal>
13 
17 #include "misc/aviation/callsign.h"
28 #include "misc/statusmessagelist.h"
29 #include "misc/swiftmiscexport.h"
30 
31 namespace swift::misc::simulation
32 {
33  class CInterpolationLogger;
34  class CInterpolatorLinear;
35  class CInterpolatorSpline;
36 
44  protected CInterpolationSetupAware,
45  protected CRemoteAircraftAware
46  {
47  public:
49  static const QStringList &getLogCategories();
50 
52  const aviation::CAircraftSituation &getLastInterpolatedSituation() const { return m_lastSituation; }
53 
59  CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoch,
61  uint32_t aircraftNumber);
62 
65  void attachLogger(CInterpolationLogger *logger) { m_logger = logger; }
66 
68  bool hasAttachedLogger() const { return m_logger; }
69 
71  QString getInterpolatorInfo() const;
72 
75  void resetLastInterpolation();
76 
79  void initCorrespondingModel(const CAircraftModel &model = {});
80 
82  void markAsUnitTest();
83 
85  int getInvalidSituationsCount() const { return m_invalidSituations; }
86 
88  const CStatusMessageList &getInterpolationMessages() const { return m_interpolationMessages; }
89 
91  bool hasInterpolationMessages() const { return !m_interpolationMessages.isEmpty(); }
92 
93  protected:
95  CInterpolator(const aviation::CCallsign &callsign, ISimulationEnvironmentProvider *simEnvProvider,
96  IInterpolationSetupProvider *setupProvider, IRemoteAircraftProvider *remoteProvider,
97  CInterpolationLogger *logger);
98 
100  const physical_quantities::CLength &getModelCG() const { return m_model.getCG(); }
101 
103  bool doLogging() const;
104 
107 
108  // values for current interpolation step
109  qint64 m_currentTimeMsSinceEpoch = -1;
110  qint64 m_lastInvalidLogTs = -1;
120  int m_partsToSituationInterpolationRatio =
121  2;
122  int m_partsToSituationGuessingRatio = 5;
123  int m_invalidSituations = 0;
125 
128  physical_quantities::CLength m_currentSceneryOffset {
130  };
131 
132  qint64 m_situationsLastModified { -1 };
133  qint64 m_situationsLastModifiedUsed { -1 };
134  int m_interpolatedSituationsCounter {
135  0
136  };
137 
138  private:
139  CInterpolationLogger *m_logger = nullptr;
140  QTimer m_initTimer;
141  bool m_unitTest = false;
142 
148  bool initIniterpolationStepData(qint64 currentTimeSinceEpoch,
149  const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber);
150 
152  aviation::CAircraftSituation initInterpolatedSituation(const aviation::CAircraftSituation &oldSituation,
153  const aviation::CAircraftSituation &newSituation) const;
154 
156  aviation::CAircraftSituation getInterpolatedSituation();
157 
159  aviation::CAircraftParts getInterpolatedParts();
160 
162  aviation::CAircraftParts getInterpolatedOrGuessedParts(int aircraftNumber);
163 
165  static aviation::CAircraftParts guessParts(const aviation::CAircraftSituation &situation,
167  const simulation::CAircraftModel &model);
168 
170  void logParts(const aviation::CAircraftParts &parts, int partsNo, bool empty) const;
171 
175  remoteAircraftSituationsAndChange(const CInterpolationAndRenderingSetupPerCallsign &setup);
176 
178  physical_quantities::CLength getAndFetchModelCG(const physical_quantities::CLength &dbCG);
179 
185  static bool presetGroundElevation(aviation::CAircraftSituation &situationToPreset,
186  const aviation::CAircraftSituation &oldSituation,
187  const aviation::CAircraftSituation &newSituation,
188  const aviation::CAircraftSituationChange &change);
189 
191  void deferredInit();
192 
194  const swift::misc::aviation::CAircraftParts &logAndReturnNullParts(const QString &info, bool log);
195 
197  virtual const IInterpolant &getInterpolant(SituationLog &log) = 0;
198  };
199 } // namespace swift::misc::simulation
200 // namespace
201 #endif // SWIFT_MISC_SIMULATION_INTERPOLATION_INTERPOLATOR_H
Status messages, e.g. from Core -> GUI.
Value object encapsulating information of aircraft's parts.
Definition: aircraftparts.h:26
static const CAircraftParts & null()
NULL parts object.
Value object about changes in situations.
Value object encapsulating information of an aircraft's situation.
static const CAircraftSituation & null()
Null situation.
Value object encapsulating information of a callsign.
Definition: callsign.h:30
Physical unit length (length)
Definition: length.h:18
Aircraft model (used by another pilot, my models on disk)
Definition: aircraftmodel.h:71
Value object for interpolator and rendering per callsign.
Record internal state of interpolator for debugging.
Class which can be directly used to access an.
Base class for interpolating (calculate positions inbetween updates). One instance is responsible for...
Definition: interpolator.h:46
bool hasInterpolationMessages() const
Do we have interpolation messages.
Definition: interpolator.h:91
const physical_quantities::CLength & getModelCG() const
Center of gravity.
Definition: interpolator.h:100
CInterpolationStatus m_currentInterpolationStatus
this step's situation status
Definition: interpolator.h:116
CInterpolationAndRenderingSetupPerCallsign m_currentSetup
used setup
Definition: interpolator.h:115
CPartsStatus m_currentPartsStatus
this step's parts status
Definition: interpolator.h:117
void attachLogger(CInterpolationLogger *logger)
Attach an observer to read the interpolator's state for debugging.
Definition: interpolator.h:65
aviation::CAircraftSituationChange m_pastSituationsChange
situations change of provider (i.e.
Definition: interpolator.h:114
CStatusMessageList m_interpolationMessages
interpolation messages
Definition: interpolator.h:124
CPartsStatus m_lastPartsStatus
status for last parts, used when last parts are re-used because of m_partsToSituationInterpolationRat...
Definition: interpolator.h:118
aviation::CAircraftSituationList m_currentSituations
current situations obtained by remoteAircraftSituationsAndChange
Definition: interpolator.h:112
const aviation::CCallsign m_callsign
corresponding callsign
Definition: interpolator.h:105
virtual const IInterpolant & getInterpolant(SituationLog &log)=0
Get the interpolant for the given time point.
const aviation::CAircraftSituation & getLastInterpolatedSituation() const
Latest interpolation result.
Definition: interpolator.h:52
bool hasAttachedLogger() const
Is logger attached?
Definition: interpolator.h:68
const CStatusMessageList & getInterpolationMessages() const
Interpolation messages.
Definition: interpolator.h:88
CAircraftModel m_model
corresponding model (required for CG)
Definition: interpolator.h:106
int getInvalidSituationsCount() const
Get count of invalid situations.
Definition: interpolator.h:85
Class which can be directly used to access an.
Class which can be directly used to access an.
Direct in memory access to interpolation setup, normally implemented by simulator.
Direct thread safe in memory access to remote aircraft.
Log entry for situation interpolation.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.