Skip to content

Commit

Permalink
Feature perform (#55)
Browse files Browse the repository at this point in the history
* Reduce code analysis warnings

* Remove NullData constants

- Pass simulation records by value

* Use struct instead of class for private data

* Use qDebug() << "" instead of qDebug("")

* Pre-allocate vector capacity

- Return std::vector by value

* Return vectors by value

- Revert arguments back to "const &"
- Also refer to: https://raw.githubusercontent.com/CppCon/CppCon2014/
master/Presentations/Back%20to%20the%20Basics!
%20Essentials%20of%20Modern%20C%2B%2B%20Style/Back%20to%20the%20Basics!
%20Essentials%20of%20Modern%20C%2B%2B%20Style%20-%20Herb%20Sutter%20-
%20CppCon%202014.pdf
- -> Slide 24

* Move data will invalidate data ("null" data)

* Return aircraft vector by value

* Return by value (copy ellision)

* Return data by value (WIP)

- Won't compile

* Use const pimpl

- Refer to "Lifetime Safety... By Default: Making Code Leak-Free by
Construction", Herb Sutter, CppCon 2016
- WIP (won't compile)

* Refactoring (WIP)

* C++-14-ify type traits

* Use return value optimisation (RVO)

* Fix mutual shared pointer dependencies (graph edges)

- In the (academic) case when the module graph should have cycles
- Which would be possible if two (or seval) modules defined "after"
dependencies for each other (which would be a "configuration bug")

* Remove const from values returned by value

* Value-based aircraft list

- Drop QObject inheritance
- WIP: Refactor signals (won't compile)

* Move waypoint / aircraft info signals

- Compiles again
- TODO: Explictly emit signals (from services)

* Move ctor: initialise private data

* Thread-safe acccess to singletons

- Not that we have multiple threads just yet...
- ... but you never know :)

* Rename LogbookManager to PersistenceManager

- To avoid confusion with Logbook (the model)

* Replace "other" with "rhs"

* Refactoring (won't compile)

* FIX: Update Flight information dialog when loading flight

* Restore method names

* Bump version to 0.13

* Rule of zero / five #1

* Rule of zero / five #2

* Rule of zero / five #3

* Rule of zero / five #4

* Update

* Constant strings

* Fix compilation (Windows)
  • Loading branch information
till213 authored Oct 8, 2022
1 parent 8f195ba commit b91cba9
Show file tree
Hide file tree
Showing 345 changed files with 3,336 additions and 3,898 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.13.0

### Bug Fixes
- The various tabs in the Flight information dialog (Description, Aircraft, Conditions and Flight Plan) are now properly updated when importing a flight or loading a flight from the logbook

### Under The Hood
- Rule of Zero, copy-and-swap [[Back to Basics: RAII and the Rule of Zero - Arthur O'Dwyer - CppCon 2019](https://www.youtube.com/watch?v=7Qgd9B1KuMQ)]
- Thread-safe access to singletons [[Back to Basics: Concurrency - Arthur O'Dwyer - CppCon 2020](https://www.youtube.com/watch?v=F6Ipn7gCOsY)]
- Value-based aircraft list (CPU cache optimisation)
- Small performance optimisations (e.g. return value optimisation)

## 0.12.0

### New Features
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(APP_NAME "SkyDolly")

project(
${APP_NAME}
VERSION 0.12.0
VERSION 0.13.0
DESCRIPTION "Sky Dolly - The Black Sheep for Your Flight Recordings"
HOMEPAGE_URL "https://github.com/till213/SkyDolly"
LANGUAGES CXX
Expand Down
674 changes: 337 additions & 337 deletions i18n/SkyDolly_de_DE.ts

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions src/Flight/include/Flight/Analytics.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Sky Dolly - The Black Sheep for Your Flight Recordings
*
* Copyright (c) Oliver Knoll
Expand Down Expand Up @@ -36,7 +36,7 @@
class Aircraft;
struct PositionData;

class AnalyticsPrivate;
struct AnalyticsPrivate;

/*!
* Provides basic flight path & events analytics.
Expand All @@ -46,6 +46,10 @@ class FLIGHT_API Analytics
public:

Analytics(const Aircraft &aircraft);
Analytics(const Analytics &rhs) = delete;
Analytics(Analytics &&rhs);
Analytics &operator=(const Analytics &rhs) = delete;
Analytics &operator=(Analytics &&rhs);
~Analytics();

/*!
Expand All @@ -54,12 +58,11 @@ class FLIGHT_API Analytics
* still on the ground). The movement is purely calculated based on the distance
* between the positions.
*
* \return the heading of the first aircraft movement; PositionData::NullData if
* no positions exist
* \return the heading of the first aircraft movement
*/
const std::pair<std::int64_t, double> firstMovementHeading() const noexcept;
std::pair<std::int64_t, double> firstMovementHeading() const noexcept;

const PositionData &closestPosition(double latitude, double longitude) const noexcept;
PositionData closestPosition(double latitude, double longitude) const noexcept;

private:
std::unique_ptr<AnalyticsPrivate> d;
Expand Down
8 changes: 6 additions & 2 deletions src/Flight/include/Flight/FlightAugmentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "FlightLib.h"

class Aircraft;
class FlightAugmentationPrivate;
struct FlightAugmentationPrivate;

/*!
* Augments flight data with attitude and velocity, for instance.
Expand Down Expand Up @@ -69,7 +69,11 @@ class FLIGHT_API FlightAugmentation
Q_DECLARE_FLAGS(Aspects, Aspect)

FlightAugmentation(Procedures procedures = Procedure::All, Aspects aspects = Aspect::All) noexcept;
~FlightAugmentation() noexcept;
FlightAugmentation(const FlightAugmentation &rhs) = delete;
FlightAugmentation(FlightAugmentation &&rhs);
FlightAugmentation &operator=(const FlightAugmentation &rhs) = delete;
FlightAugmentation &operator=(FlightAugmentation &&rhs);
~FlightAugmentation();

void setProcedures(Procedures procedures) noexcept;
Procedures getProcedures() const noexcept;
Expand Down
35 changes: 13 additions & 22 deletions src/Flight/src/Analytics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <cstdint>

#include <QtGlobal>
#ifdef DEBUG
#include <QDebug>
#endif

#include <Kernel/SkyMath.h>
#include <Kernel/Convert.h>
Expand All @@ -50,9 +53,8 @@ namespace {
};
}

class AnalyticsPrivate
struct AnalyticsPrivate
{
public:
AnalyticsPrivate(const Aircraft &theAircraft)
: aircraft(theAircraft)
{}
Expand All @@ -64,20 +66,13 @@ class AnalyticsPrivate

Analytics::Analytics(const Aircraft &aircraft)
: d(std::make_unique<AnalyticsPrivate>(aircraft))
{
#ifdef DEBUG
qDebug("Analytics::~Analytics: CREATED");
#endif
}
{}

Analytics::~Analytics()
{
#ifdef DEBUG
qDebug("Analytics::~Analytics: DELETED");
#endif
}
Analytics::Analytics(Analytics &&rhs) = default;
Analytics &Analytics::operator=(Analytics &&rhs) = default;
Analytics::~Analytics() = default;

const std::pair<std::int64_t, double> Analytics::firstMovementHeading() const noexcept
std::pair<std::int64_t, double> Analytics::firstMovementHeading() const noexcept
{
std::pair<std::int64_t, double> result;
Position &position = d->aircraft.getPosition();
Expand All @@ -101,23 +96,19 @@ const std::pair<std::int64_t, double> Analytics::firstMovementHeading() const no
return result;
}

const PositionData &Analytics::closestPosition(double latitude, double longitude) const noexcept
PositionData Analytics::closestPosition(double latitude, double longitude) const noexcept
{
PositionData positionData;
double minimumDistance = std::numeric_limits<double>::max();
const PositionData *closestPositionData {nullptr};

Position &position = d->aircraft.getPosition();
for (const PositionData &pos : position) {
const double distance = SkyMath::geodesicDistance(SkyMath::Coordinate(latitude, longitude),
SkyMath::Coordinate(pos.latitude, pos.longitude));
if (minimumDistance > distance) {
closestPositionData = &pos;
positionData = pos;
minimumDistance = distance;
}
}
if (closestPositionData != nullptr) {
return *closestPositionData;
} else {
return PositionData::NullData;
}
return positionData;
}
18 changes: 5 additions & 13 deletions src/Flight/src/FlightAugmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ namespace {
constexpr double MaxBankAngle = 25;
}

class FlightAugmentationPrivate
struct FlightAugmentationPrivate
{
public:
FlightAugmentationPrivate(FlightAugmentation::Procedures theProcedures, FlightAugmentation::Aspects theAspects)
: procedures(theProcedures),
aspects(theAspects)
Expand All @@ -74,18 +73,11 @@ class FlightAugmentationPrivate

FlightAugmentation::FlightAugmentation(Procedures procedures, Aspects aspects) noexcept
: d(std::make_unique<FlightAugmentationPrivate>(procedures, aspects))
{
#ifdef DEBUG
qDebug("FlightAugmentation::~FlightAugmentation: CREATED");
#endif
}
{}

FlightAugmentation::~FlightAugmentation() noexcept
{
#ifdef DEBUG
qDebug("FlightAugmentation::~FlightAugmentation: DELETED");
#endif
}
FlightAugmentation::FlightAugmentation(FlightAugmentation &&rhs) = default;
FlightAugmentation &FlightAugmentation::operator=(FlightAugmentation &&rhs) = default;
FlightAugmentation::~FlightAugmentation() = default;

void FlightAugmentation::setProcedures(Procedures procedures) noexcept
{
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ target_sources(${LIBRARY_NAME}
include/Kernel/Convert.h src/Convert.cpp
include/Kernel/Enum.h
include/Kernel/File.h src/File.cpp
include/Kernel/FlightSimulator.h src/FlightSimulator.cpp
include/Kernel/FlightSimulator.h
include/Kernel/Name.h
include/Kernel/PositionParser.h src/PositionParser.cpp
include/Kernel/Replay.h
Expand Down
24 changes: 16 additions & 8 deletions src/Kernel/include/Kernel/Const.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#ifndef CONST_H
#define CONST_H

#include <string_view>

namespace Const {
constexpr char LogbookExtension[] = ".sdlog";

constexpr char BackupNeverSymId[] = "NEVER";
constexpr char BackupNowSymId[] = "NOW";
constexpr char BackupMonthlySymId[] = "MONTH";
constexpr char BackupWeeklySymId[] = "WEEK";
constexpr char BackupDailySymId[] = "DAY";
constexpr char BackupAlwaysSymId[] = "ALWAYS";

/*!
* An invalid ID indicates that the object has not yet been (successfully) persisted.
*/
constexpr std::int64_t InvalidId {-1};

constexpr const char *LogbookExtension {".sdlog"};

constexpr const char *BackupNeverSymId = "NEVER";
constexpr const char *BackupNowSymId = "NOW";
constexpr const char *BackupMonthlySymId = "MONTH";
constexpr const char *BackupWeeklySymId = "WEEK";
constexpr const char *BackupDailySymId = "DAY";
constexpr const char *BackupAlwaysSymId = "ALWAYS";
}

#endif // CONST_H
14 changes: 11 additions & 3 deletions src/Kernel/include/Kernel/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <memory>
#include <exception>

#ifdef DEBUG
#include <QDebug>
#endif

#include <GeographicLib/Geoid.hpp>

#include "KernelLib.h"
Expand All @@ -45,7 +49,11 @@ class KERNEL_API Convert final
public:

Convert() noexcept;
~Convert() noexcept;
Convert(const Convert &rhs) = delete;
Convert(Convert &&rhs);
Convert &operator=(const Convert &rhs) = delete;
Convert &operator=(Convert &&rhs);
~Convert();

/*!
* Converts the \c height height above WGS84 reference ellipsoid to height above the earth
Expand Down Expand Up @@ -79,7 +87,7 @@ class KERNEL_API Convert final
catch (const std::exception &ex) {
heightAboveGeoid = height;
#ifdef DEBUG
qDebug("Convert::wgs84ToEgmGeoid: caught exception: %s", ex.what());
qDebug() << "Convert::wgs84ToEgmGeoid: caught exception: %s", ex.what();
#endif
}
} else {
Expand Down Expand Up @@ -120,7 +128,7 @@ class KERNEL_API Convert final
catch (const std::exception &ex) {
heightAboveEllipsoid = height;
#ifdef DEBUG
qDebug("Convert::egmToWgs84Ellipsoid: caught exception: %s", ex.what());
qDebug() << "Convert::egmToWgs84Ellipsoid: caught exception:" << ex.what();
#endif
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/include/Kernel/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Enum
template<typename E>
constexpr auto toUnderlyingType(E e) noexcept
{
return static_cast<typename std::underlying_type<E>::type>(e);
return static_cast<std::underlying_type_t<E>>(e);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/Kernel/include/Kernel/FlightSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
class KERNEL_API FlightSimulator final
{
public:
FlightSimulator() noexcept;

enum struct Id {
None,
Expand All @@ -49,15 +48,13 @@ class KERNEL_API FlightSimulator final
static inline const QString FlightSimulatorNamePrepar3Dv5 {QStringLiteral("Prepar3Dv5")};

static inline Id nameToId(QStringView name) noexcept {
Id id;
Id id {Id::None};
if (name == FlightSimulatorNameAll) {
id = Id::All;
} else if (name == FlightSimulatorNameMSFS) {
id = Id::FS2020;
} else if (name == FlightSimulatorNamePrepar3Dv5) {
id = Id::Prepar3Dv5;
} else {
id = Id::None;
}
return id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/include/Kernel/PositionParser.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Sky Dolly - The Black Sheep for your Flight Recordings
* Sky Dolly - The Black Sheep for Your Flight Recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
Expand Down
13 changes: 8 additions & 5 deletions src/Kernel/include/Kernel/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#include "SampleRate.h"
#include "KernelLib.h"

class SettingsPrivate;
class Version;
struct SettingsPrivate;

/*!
* The application settings. These settings are persisted to user configuration
Expand All @@ -54,6 +54,11 @@ class KERNEL_API Settings final : public QObject
Q_OBJECT
public:

Settings(const Settings &rhs) = delete;
Settings(Settings &&rhs) = delete;
Settings &operator=(const Settings &rhs) = delete;
Settings &operator=(Settings &&rhs) = delete;

/*!
* Returns the singleton Settings instance.
*
Expand Down Expand Up @@ -798,13 +803,11 @@ public slots:
*/
void changed();

protected:
~Settings() noexcept override;

private:
std::unique_ptr<SettingsPrivate> d;
const std::unique_ptr<SettingsPrivate> d;

Settings() noexcept;
~Settings() final;

void frenchConnection() noexcept;

Expand Down
Loading

0 comments on commit b91cba9

Please sign in to comment.