Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Style cleanup, absl, abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
pierr3 committed Dec 30, 2023
1 parent cea45f6 commit 1da9dd3
Show file tree
Hide file tree
Showing 32 changed files with 1,013 additions and 1,005 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ForEachMacros:
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
Expand Down Expand Up @@ -158,7 +158,7 @@ RemoveBracesLLVM: false
RequiresClausePosition: OwnLine
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortIncludes: CaseInsensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
Expand Down
61 changes: 38 additions & 23 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,45 @@ Checks: >
-bugprone-narrowing-conversions,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result
-unused-includes
HeaderFilterRegex: "(google/cloud/|generator/).*\\.h$"

CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: aNy_CasE }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
- { key: readability-identifier-naming.ClassMemberSuffix, value: _ }
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantPrefix, value: k }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: k }
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
- { key: readability-identifier-naming.GlobalConstantPrefix, value: k }
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
- { key: readability-identifier-naming.MemberConstantPrefix, value: k }
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
- { key: readability-identifier-naming.StaticConstantPrefix, value: k }
- { key: readability-implicit-bool-conversion.AllowIntegerConditions, value: 1 }
- { key: readability-implicit-bool-conversion.AllowPointerConditions, value: 1 }
- { key: readability-function-cognitive-complexity.IgnoreMacros, value: 1 }
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- {
key: readability-identifier-naming.TemplateParameterCase,
value: CamelCase,
}
- { key: readability-identifier-naming.FunctionCase, value: aNy_CasE }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
- { key: readability-identifier-naming.ClassMemberCase, value: CamelCase }
- { key: readability-identifier-naming.ClassMemberPrefix, value: m }
- { key: readability-identifier-naming.PrivateMemberCase, value: CamelCase }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: p }
- { key: readability-identifier-naming.ProtectedMemberCase, value: CamelCase }
- { key: readability-identifier-naming.ProtectedMemberPrefix, value: p }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantPrefix, value: k }
- {
key: readability-identifier-naming.ConstexprVariableCase,
value: CamelCase,
}
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: k }
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
- { key: readability-identifier-naming.GlobalConstantPrefix, value: k }
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
- { key: readability-identifier-naming.MemberConstantPrefix, value: k }
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
- { key: readability-identifier-naming.StaticConstantPrefix, value: k }
- {
key: readability-implicit-bool-conversion.AllowIntegerConditions,
value: 1,
}
- {
key: readability-implicit-bool-conversion.AllowPointerConditions,
value: 1,
}
- { key: readability-function-cognitive-complexity.IgnoreMacros, value: 1 }
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Diagnostics:
UnusedIncludes: None
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

add_definitions(-DCPPHTTPLIB_OPENSSL_SUPPORT=1)

# Clang preferences

set(CMAKE_COMPILE_WARNING_AS_ERROR ON)


# Read the VERSION file
file(READ "VERSION" VERSION_CONTENT)
string(REGEX MATCHALL "[0-9]+" VERSION_NUMBERS "${VERSION_CONTENT}")
Expand Down Expand Up @@ -63,6 +68,7 @@ find_package(unofficial-http-parser REQUIRED)
find_package(restinio CONFIG REQUIRED)
find_path(NEARGYE_SEMVER_INCLUDE_DIRS "neargye/semver.hpp")
find_package(Threads REQUIRED)
find_package(absl CONFIG REQUIRED)
find_package(SFML COMPONENTS system window graphics audio CONFIG REQUIRED)

set(APPLE_EXTRA_LIBS "")
Expand Down Expand Up @@ -161,6 +167,7 @@ target_link_libraries(vector_audio
restinio::restinio
httplib::httplib
Threads::Threads
absl::strings
${OPENGL_LIBRARY})

if (WIN32)
Expand Down
37 changes: 19 additions & 18 deletions include/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
#include "afv-native/atcClientWrapper.h"
#include "afv-native/event.h"
#include "config.h"
#include "data_file_handler.h"
#include "imgui.h"
#include "imgui_internal.h"
#include "imgui_stdlib.h"
#include "modals/settings.h"
#include "ns/airport.h"
#include "radioSimulation.h"
#include "shared.h"
#include "style.h"
#include <SFML/Audio.hpp>
#include "util.h"

#include <algorithm>
#include <data_file_handler.h>
#include <cstddef>
#include <fstream>
#include <functional>
#include <httplib.h>
Expand All @@ -20,7 +23,12 @@
#include <memory>
#include <numeric>
#include <restinio/all.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Window/Joystick.hpp>
#include <shared_mutex>
#include <spdlog/spdlog.h>
#include <string>
#include <thread>
#include <utility>
Expand All @@ -38,34 +46,27 @@ class App {

void errorModal(std::string message);

afv_native::api::atcClient* mClient_;
restinio::running_server_handle_t<restinio::default_traits_t> mSDKServer_;
afv_native::api::atcClient* pClient;
restinio::running_server_handle_t<restinio::default_traits_t> pSDKServer;

void eventCallback(
afv_native::ClientEventType evt, void* data, void* data2);
void buildSDKServer();

void disconnectAndCleanup();

void playErrorSound()
{
if (!disconnect_warning_sound_available) {
return;
}
// Load the warning sound for disconnection
sound_player_.play();
};
void playErrorSound();

// Used in another thread
static void loadAirportsDatabaseAsync();

bool showErrorModal_ = false;
std::string lastErrorModalMessage_;
bool pShowErrorModal = false;
std::string pLastErrorModalMessage;

std::unique_ptr<vector_audio::vatsim::DataHandler> dataHandler_;
std::unique_ptr<vector_audio::vatsim::DataHandler> pDataHandler;

bool manuallyDisconnected_ = false;
sf::SoundBuffer disconnect_warning_soundbuffer_;
sf::Sound sound_player_;
bool pManuallyDisconnected = false;
sf::SoundBuffer pDisconnectWarningSoundbuffer;
sf::Sound pSoundPlayer;
};
}
13 changes: 7 additions & 6 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/spdlog.h"
#include <SFML/Config.hpp>

#include <filesystem>
#include <iostream>
#include <mutex>
#include <SFML/Config.hpp>
#include <string>
#include <thread>
#include <toml.hpp>
#include <mutex>

namespace vector_audio {

class Configuration {
public:
static toml::value config_;
static toml::value mConfig;

static inline std::string config_file_name_ = "config.toml";
static inline std::string airports_db_file_path_ = "airports.json";
static inline std::string mConfigFileName = "config.toml";
static inline std::string mAirportsDBFilePath = "airports.json";

static void build_config();

Expand All @@ -29,7 +30,7 @@ class Configuration {
static std::string get_linux_config_folder();
static std::filesystem::path get_config_folder_path();

inline static std::mutex config_writer_lock_;
inline static std::mutex mConfigWriterLock;

static void build_logger();

Expand Down
54 changes: 28 additions & 26 deletions include/data_file_handler.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#pragma once
#include "shared.h"
#include "util.h"

#include <absl/strings/match.h>
#include <absl/strings/str_split.h>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <exception>
#include <httplib.h>
#include <memory>
#include <mutex>
#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>
#include <random>
#include <regex>
#include <spdlog/spdlog.h>
#include <string>
#include <thread>
#include <algorithm>

#include <random>
#include <utility>

#include "shared.h"
#include "util.h"
#include <httplib.h>
#include <vector>

namespace vector_audio::vatsim {
using namespace std::chrono_literals;
Expand All @@ -28,18 +30,18 @@ class DataHandler {
virtual ~DataHandler()
{
{
std::unique_lock<std::mutex> lk(m_);
keep_running_ = false;
std::unique_lock<std::mutex> lk(pDfMutex);
pKeepRunning = false;
}
cv_.notify_one();
pCv.notify_one();

if (workerThread_->joinable())
workerThread_->join();
if (pWorkerThread->joinable())
pWorkerThread->join();
};

bool isSlurperAvailable() const { return this->slurperAvailable_; }
bool isSlurperAvailable() const { return this->pSlurperAvailable; }

bool isDatafileAvailable() const { return this->dataFileAvailable_; }
bool isDatafileAvailable() const { return this->pDataFileAvailable; }

bool getConnectionStatusWithSlurper();

Expand All @@ -49,19 +51,19 @@ class DataHandler {
const std::string& callsign, double& latitude, double& longitude);

private:
std::regex regex_;
std::unique_ptr<std::thread> workerThread_;
std::atomic<bool> keep_running_ = true;
std::condition_variable cv_;
std::mutex m_;
std::regex pRegexp;
std::unique_ptr<std::thread> pWorkerThread;
std::atomic<bool> pKeepRunning = true;
std::condition_variable pCv;
std::mutex pDfMutex;

std::string datafile_host_;
std::string datafile_url_;
std::string pDatafileHost;
std::string pDatafileUrl;

bool slurperAvailable_ = false;
bool dataFileAvailable_ = false;
bool had_one_disconnect_ = false;
bool yx_ = false;
bool pSlurperAvailable = false;
bool pDataFileAvailable = false;
bool pHadOneDisconnect = false;
bool pYx = false;

static std::string downloadString(httplib::Client& cli, std::string url);

Expand All @@ -70,7 +72,7 @@ class DataHandler {
bool getLatestDatafileURL();

bool getPilotPositionWithSlurper(
const std::string& callsign, double& latitude, double& longitude);
const std::string& callsign, double& latitude, double& longitude) const;

bool getPilotPositionWithDatafile(
const std::string& callsign, double& latitude, double& longitude);
Expand Down
10 changes: 6 additions & 4 deletions include/modals/settings.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#pragma once
#include "afv-native/atcClientWrapper.h"
#include "config.h"
#include "data_file_handler.h"
#include "imgui.h"
#include "imgui_internal.h"
#include "shared.h"
#include "util.h"
#include <string>
#include "style.h"
#include "util.h"

#include <imgui_stdlib.h>
#include <SFML/System/String.hpp>
#include <SFML/Window/Keyboard.hpp>

#include <string>

namespace vector_audio::modals {
class Settings {
public:
static void render(afv_native::api::atcClient* mClient, const std::function<void()>& playAlertSound);
static void render(afv_native::api::atcClient* mClient,
const std::function<void()>& playAlertSound);
};
}
5 changes: 3 additions & 2 deletions include/ns/airport.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ namespace ns {

class Airport {
public:
// Although we have more data available, we don't actually need it, so ignoring for now
// Although we have more data available, we don't actually need it, so
// ignoring for now
std::string icao;
int elevation;
double lat;
double lon;

// Store all the loaded airports
static inline std::map<std::string, Airport> All;
static inline std::map<std::string, Airport> mAll;
};
}
Loading

0 comments on commit 1da9dd3

Please sign in to comment.