From ace71d7670722621e0c7694bff35117767587bf1 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Sat, 24 Sep 2022 00:54:34 +0200 Subject: [PATCH] Header only SImDatabase --- .vscode/c_cpp_properties.json | 3 + TODO.md | 1 + build.sh | 5 + file/config.cpp | 47 ---- file/gate.cpp | 41 ---- file/include/config/config.h | 42 ---- file/include/config/config.hpp | 73 ++++++ file/include/simdata/{gate.h => gate.hpp} | 30 ++- file/include/simdata/{runway.h => runway.hpp} | 49 +++- file/include/simdata/simDatabase.h | 76 ------- file/include/simdata/simDatabase.hpp | 183 +++++++++++++++ file/include/simdata/simdataXP.h | 42 ---- .../simdata/simdataXP.hpp} | 215 +++++++++--------- file/logbook.cpp | 6 +- file/recording.cpp | 2 +- file/runway.cpp | 55 ----- file/simDatabase.cpp | 121 ---------- utilities/include/constants.h | 8 +- xplugin/CMakeLists.txt | 3 + xplugin/include/main.h | 5 +- 20 files changed, 451 insertions(+), 556 deletions(-) delete mode 100644 file/config.cpp delete mode 100644 file/gate.cpp delete mode 100644 file/include/config/config.h create mode 100644 file/include/config/config.hpp rename file/include/simdata/{gate.h => gate.hpp} (62%) rename file/include/simdata/{runway.h => runway.hpp} (53%) delete mode 100644 file/include/simdata/simDatabase.h create mode 100644 file/include/simdata/simDatabase.hpp delete mode 100644 file/include/simdata/simdataXP.h rename file/{simdataXP.cpp => include/simdata/simdataXP.hpp} (90%) delete mode 100644 file/runway.cpp delete mode 100644 file/simDatabase.cpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index de09383..b69ed40 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,6 +6,7 @@ ], "defines": [ "LIN", + "XP", "XPLM200", "XPLM210" ], @@ -20,6 +21,7 @@ ], "defines": [ "IBM", + "XP", "XPLM200", "XPLM210" ], @@ -35,6 +37,7 @@ ], "defines": [ "APL", + "XP", "XPLM200", "XPLM210" ], diff --git a/TODO.md b/TODO.md index 6ba5199..5ba3acd 100644 --- a/TODO.md +++ b/TODO.md @@ -2,3 +2,4 @@ - Potentially revert to Header only File lib (NO LINKING) - Update OSXCross Docker image to SDK 11 - Implement ARM64 arch for Plugin +- Implement Logbook PHP diff --git a/build.sh b/build.sh index 908865e..51087ef 100755 --- a/build.sh +++ b/build.sh @@ -27,6 +27,10 @@ case $1 in \cp -rf /opt/llvm-mingw/x86_64-w64-mingw32/bin/libc++.dll X-Plane/GAConnector/64 \cp -rf /opt/llvm-mingw/x86_64-w64-mingw32/bin/libunwind.dll X-Plane/GAConnector/64 ;; + *) + echo "Unknown platform, choose one of mac, lin, win64, win32" + exit 22 + ;; esac make -j @@ -38,6 +42,7 @@ fi if [ "$1" = "mac" ] && [ "$DEBUG" = "1" ] then + echo "Building dSYM" /opt/osxcross/target/bin/osxcross-llvm-dsymutil X-Plane/GAConnector/mac.xpl fi diff --git a/file/config.cpp b/file/config.cpp deleted file mode 100644 index 13992e0..0000000 --- a/file/config.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "config/config.h" - -namespace germanairlinesva -{ -namespace file -{ - namespace config - { - void Config::writeFile() const - { - std::ofstream out(XPLANE_PLUGIN_DIRECTORY CONFIG); - out << "scenery=" << this->scenery << "\n"; - out << "user=" << this->user << "\n"; - out << "token=" << this->token << "\n"; - out.close(); - } - - Config::Config() - { - std::ifstream in(XPLANE_PLUGIN_DIRECTORY CONFIG); - std::string line; - while (std::getline(in, line)) { - std::vector fields = util::split(line, '='); - if (fields.size() >= 2) { - util::trim(fields[0]); - util::trim(fields[1]); - if (fields[0] == "scenery") { - this->scenery = fields[1]; - } else if (fields[0] == "user") { - this->user = fields[1]; - } else if (fields[0] == "token") { - this->token = fields[1]; - } - } - } - in.close(); - } - - void Config::updateScenery(std::string scenery) - { - this->scenery = scenery; - - this->writeFile(); - } - } // namespace config -} // namespace file -} // namespace germanairlinesva \ No newline at end of file diff --git a/file/gate.cpp b/file/gate.cpp deleted file mode 100644 index 4c3b04b..0000000 --- a/file/gate.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "simdata/gate.h" - -namespace germanairlinesva -{ -namespace file -{ - namespace simdata - { - Gate::Gate(std::string designator, - double latitude, - double longitude, - std::uint8_t radius) - { - this->designator = designator; - this->center = {latitude, longitude}; - this->radius = radius; - } - - Gate::Gate(std::string designator, - struct geodata::point center, - std::uint8_t radius) - { - this->designator = designator; - this->center = center; - this->radius = radius; - } - - void Gate::toFile(std::ofstream &out) const - { - writeString(out, this->designator); - writecenter)>(out, this->center); - writeradius)>(out, this->radius); - } - - bool Gate::contains(geodata::point coordinates) const - { - return geodata::distanceEarthP(this->center, coordinates); - } - } // namespace simdata -} // namespace file -} // namespace germanairlinesva \ No newline at end of file diff --git a/file/include/config/config.h b/file/include/config/config.h deleted file mode 100644 index 5d66b3f..0000000 --- a/file/include/config/config.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef GERMANAIRLINESVA_FILE_CONFIG_H -#define GERMANAIRLINESVA_FILE_CONFIG_H - -#include - -#include -#include -#include -#include - -#include "constants.h" -#include "util.hpp" - -namespace germanairlinesva -{ -namespace file -{ - namespace config - { - class Config - { - private: - std::string user; - std::string scenery; - std::string token; - - void writeFile() const; - - public: - Config(); - - void updateScenery(std::string scenery); - - inline const std::string getUser() const { return this->user; } - inline const std::string getScenery() const { return this->scenery; } - inline const std::string getToken() const { return this->token; } - }; - } // namespace config -} // namespace file -} // namespace germanairlinesva - -#endif diff --git a/file/include/config/config.hpp b/file/include/config/config.hpp new file mode 100644 index 0000000..84eca7e --- /dev/null +++ b/file/include/config/config.hpp @@ -0,0 +1,73 @@ +#ifndef GERMANAIRLINESVA_FILE_CONFIG_H +#define GERMANAIRLINESVA_FILE_CONFIG_H + +#include + +#include +#include +#include +#include + +#include "constants.h" +#include "util.hpp" + +namespace germanairlinesva +{ +namespace file +{ + namespace config + { + class Config + { + private: + std::string user; + std::string scenery; + std::string token; + + inline void writeFile() const + { + std::ofstream out(BASE_DIRECTORY CONFIG); + out << "scenery=" << this->scenery << "\n"; + out << "user=" << this->user << "\n"; + out << "token=" << this->token << "\n"; + out.close(); + } + + public: + inline Config() + { + std::ifstream in(BASE_DIRECTORY CONFIG); + std::string line; + while (std::getline(in, line)) { + std::vector fields = util::split(line, '='); + if (fields.size() >= 2) { + util::trim(fields[0]); + util::trim(fields[1]); + if (fields[0] == "scenery") { + this->scenery = fields[1]; + } else if (fields[0] == "user") { + this->user = fields[1]; + } else if (fields[0] == "token") { + this->token = fields[1]; + } + } + } + in.close(); + } + + inline void updateScenery(std::string scenery) + { + this->scenery = scenery; + + this->writeFile(); + } + + inline const std::string getUser() const { return this->user; } + inline const std::string getScenery() const { return this->scenery; } + inline const std::string getToken() const { return this->token; } + }; + } // namespace config +} // namespace file +} // namespace germanairlinesva + +#endif diff --git a/file/include/simdata/gate.h b/file/include/simdata/gate.hpp similarity index 62% rename from file/include/simdata/gate.h rename to file/include/simdata/gate.hpp index 248a460..fcd169b 100644 --- a/file/include/simdata/gate.h +++ b/file/include/simdata/gate.hpp @@ -37,17 +37,29 @@ namespace file public: // From X-Plane or MakeRwys - Gate(std::string designator, - double latitude, - double longitude, - std::uint8_t radius); + inline Gate(std::string designator, + double latitude, + double longitude, + std::uint8_t radius) + : designator(designator), center({latitude, longitude}), + radius(radius){}; // From Database - Gate(std::string designator, - struct geodata::point center, - std::uint8_t radius); + inline Gate(std::string designator, + struct geodata::point center, + std::uint8_t radius) + : designator(designator), center(center), radius(radius){}; - void toFile(std::ofstream &out) const; - bool contains(geodata::point coordinates) const; + inline void toFile(std::ofstream &out) const + { + writeString(out, this->designator); + writecenter)>(out, this->center); + writeradius)>(out, this->radius); + } + + inline bool contains(geodata::point coordinates) const + { + return geodata::distanceEarthP(this->center, coordinates); + } inline const std::string to_string() const { diff --git a/file/include/simdata/runway.h b/file/include/simdata/runway.hpp similarity index 53% rename from file/include/simdata/runway.h rename to file/include/simdata/runway.hpp index 6cb1609..984d601 100644 --- a/file/include/simdata/runway.h +++ b/file/include/simdata/runway.hpp @@ -40,20 +40,45 @@ namespace file public: // From X-Plane or MakeRwys - Runway(std::string designator, - double latitudeStart, - double longitudeStart, - double latitudeEnd, - double longitudeEnd, - double width); + inline Runway(std::string designator, + double latitudeStart, + double longitudeStart, + double latitudeEnd, + double longitudeEnd, + double width) + : designator(designator), width(width) + { + this->length = geodata::distanceEarthD(latitudeStart, + longitudeStart, + latitudeEnd, + longitudeEnd); + this->trueHeading = geodata::bearingDD(latitudeStart, + longitudeStart, + latitudeEnd, + longitudeEnd); + this->bounds = + geodata::calculateBoxDD({latitudeStart, longitudeStart}, + {latitudeEnd, longitudeEnd}, + this->trueHeading, + this->width); + }; // From database - Runway(std::string designator, - struct geodata::box bounds, - std::uint8_t width, - std::uint16_t length, - double trueHeading); + inline Runway(std::string designator, + struct geodata::box bounds, + std::uint8_t width, + std::uint16_t length, + double trueHeading) + : designator(designator), bounds(bounds), width(width), + length(length), trueHeading(trueHeading){}; - void toFile(std::ofstream &out) const; + inline void toFile(std::ofstream &out) const + { + writeString(out, this->designator); + writebounds)>(out, this->bounds); + writewidth)>(out, this->width); + writelength)>(out, this->length); + writetrueHeading)>(out, this->trueHeading); + } inline const std::string to_string() const { diff --git a/file/include/simdata/simDatabase.h b/file/include/simdata/simDatabase.h deleted file mode 100644 index c471810..0000000 --- a/file/include/simdata/simDatabase.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef GERMANAIRLINESVA_FILE_SIMDATABASE_H -#define GERMANAIRLINESVA_FILE_SIMDATABASE_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config/config.h" -#include "constants.h" -#include "simdata/gate.h" -#include "simdata/runway.h" -#include "simdata/simdataXP.h" - -/* - * Header - * - * CHAR[5] | UINT8 - * --------+-------- - * VGAS | VERSION - */ -/* - * Airport - * - * UINT8 | CHAR[] | UINT16 | GATE[] | UINT8 | RUNWAY[] - * --------+--------+----------+--------+---------+--------- - * STRLEN | ICAO | NUMGATES | GATES | NUMRWYS | RUNWAYS - */ - -namespace germanairlinesva -{ -namespace file -{ - namespace simdata - { - class SimDatabase - { - private: - std::map, std::vector>> - airports; - - void fromFile(); - void readVersion1(std::ifstream &in); - - public: - SimDatabase(int xPlaneVersion, - const char *hash, - std::unique_ptr &configuration, - std::function toLog); - - void toFile() const; - - inline std::size_t getCount() const { return this->airports.size(); } - inline const std::pair, - const std::vector> - operator[](std::string key) - { - auto it = this->airports.find(key); - if (it != this->airports.end()) { - return this->airports[key]; - } else { - return std::pair, std::vector>(); - } - } - }; - } // namespace simdata -} // namespace file -} // namespace germanairlinesva - -#endif diff --git a/file/include/simdata/simDatabase.hpp b/file/include/simdata/simDatabase.hpp new file mode 100644 index 0000000..73e264a --- /dev/null +++ b/file/include/simdata/simDatabase.hpp @@ -0,0 +1,183 @@ +#ifndef GERMANAIRLINESVA_FILE_SIMDATABASE_H +#define GERMANAIRLINESVA_FILE_SIMDATABASE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config/config.hpp" +#include "constants.h" +#include "simdata/gate.hpp" +#include "simdata/runway.hpp" +#include "simdata/simdataXP.hpp" + +/* + * Header + * + * CHAR[5] | UINT8 + * --------+-------- + * VGAS | VERSION + */ +/* + * Airport + * + * UINT8 | CHAR[] | UINT16 | GATE[] | UINT8 | RUNWAY[] + * --------+--------+----------+--------+---------+--------- + * STRLEN | ICAO | NUMGATES | GATES | NUMRWYS | RUNWAYS + */ + +namespace germanairlinesva +{ +namespace file +{ + namespace simdata + { + class SimDatabase + { + private: + std::map, std::vector>> + airports; + + inline void readVersion1(std::ifstream &in) + { + std::uint16_t numAirports = read(in); + + for (int i = 0; i < numAirports; i++) { + // ICAO + std::string icao = readString(in); + // Gates + std::uint16_t numGates = read(in); + for (int j = 0; j < numGates; j++) { + std::string designator = readString(in); + struct geodata::point center = read(in); + std::uint8_t radius = read(in); + + this->airports[icao].first.emplace_back(designator, + center, + radius); + } + // Runways + std::uint8_t numRunways = read(in); + for (int j = 0; j < numRunways; j++) { + std::string designator = readString(in); + // Center + struct geodata::box bounds = read(in); + std::uint8_t width = read(in); + std::uint16_t length = read(in); + double trueHeading = read(in); + + this->airports[icao].second.emplace_back(designator, + bounds, + width, + length, + trueHeading); + } + } + + in.close(); + } + + inline void fromFile() + { + std::ifstream in(BASE_DIRECTORY SIMDATABASE, std::ifstream::binary); + + // File Header + std::string ident = readString(in, 5); + if (ident.compare("VGAS") != 0) { + throw std::invalid_argument("Wrong file"); + } + std::uint8_t version = read(in); + + if (version == 1) { + this->readVersion1(in); + } + } + + public: + inline SimDatabase(int xPlaneVersion, + const char *hash, + std::unique_ptr &configuration, + std::function toLog) + { + if (strcmp(configuration->getScenery().c_str(), hash) != 0 || + !util::fileExists(BASE_DIRECTORY SIMDATABASE)) { +#ifdef XP + scan(xPlaneVersion < 12000 ? XPLANE11_BASE_SCENERY + : XPLANE12_BASE_SCENERY, + XPLANE_CUSTOM_SCENERY, + BASE_DIRECTORY "log.txt", + airports); +#else + toLog("ESP SCAN WILL BE HERE"); +#endif + + configuration->updateScenery(hash); + this->toFile(); + + toLog("Sim Database updated"); + } else { + this->fromFile(); + + toLog("Sim Database loaded"); + } + } + + inline void toFile() const + { + std::ofstream out(BASE_DIRECTORY SIMDATABASE, std::fstream::binary); + + // File Header, Last member is version + std::uint8_t header[] = {'V', 'G', 'A', 'S', '\0', 1}; + out.write(reinterpret_cast(header), 6); + // Num Airports + write(out, airports.size()); + // Airport + for (const std::pair< + const std::string, + std::pair, std::vector>> &airport : + airports) { + std::string icao = airport.first; + const std::vector gates = airport.second.first; + const std::vector runways = airport.second.second; + // ICAO + writeString(out, icao); + // Gates + write(out, gates.size()); + for (const Gate &gate : gates) { + gate.toFile(out); + } + // Runways + write(out, runways.size()); + for (const Runway &runway : runways) { + runway.toFile(out); + } + } + out.close(); + } + + inline std::size_t getCount() const { return this->airports.size(); } + + inline const std::pair, + const std::vector> + operator[](std::string key) + { + auto it = this->airports.find(key); + if (it != this->airports.end()) { + return this->airports[key]; + } else { + return std::pair, std::vector>(); + } + } + }; + } // namespace simdata +} // namespace file +} // namespace germanairlinesva + +#endif diff --git a/file/include/simdata/simdataXP.h b/file/include/simdata/simdataXP.h deleted file mode 100644 index 8d7c1d2..0000000 --- a/file/include/simdata/simdataXP.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef GERMANAIRLINESVA_FILE_SIMDATAXP_H -#define GERMANAIRLINESVA_FILE_SIMDATAXP_H - -#include -#include -#include - -#include "simdata/gate.h" -#include "simdata/runway.h" -#include "simdata/simDatabase.h" -#include "util.hpp" - -namespace germanairlinesva -{ -namespace file -{ - namespace simdata - { - int scan( - const std::string defaultFile, - const std::string sceneryPack, - const std::string logFile, - std::map, std::vector>> - &airports); - - void makeAirport( - const std::string &kind, - std::ifstream &infile, - std::map, std::vector>> - &airports, - std::ofstream &logfile); - void makeGate15(std::vector &gates, - const std::vector &fields); - void makeRunway(std::vector &runways, - const std::vector &fields); - void makeGate1300(std::vector &gates, - const std::vector &fields); - } // namespace simdata -} // namespace file -} // namespace germanairlinesva - -#endif \ No newline at end of file diff --git a/file/simdataXP.cpp b/file/include/simdata/simdataXP.hpp similarity index 90% rename from file/simdataXP.cpp rename to file/include/simdata/simdataXP.hpp index ecefe16..0428343 100644 --- a/file/simdataXP.cpp +++ b/file/include/simdata/simdataXP.hpp @@ -1,4 +1,13 @@ -#include "simdata/simdataXP.h" +#ifndef GERMANAIRLINESVA_FILE_SIMDATAXP_H +#define GERMANAIRLINESVA_FILE_SIMDATAXP_H + +#include +#include +#include + +#include "simdata/gate.hpp" +#include "simdata/runway.hpp" +#include "util.hpp" namespace germanairlinesva { @@ -6,68 +15,55 @@ namespace file { namespace simdata { - int scan( - const std::string defaultFile, - const std::string sceneryPack, - const std::string logFile, - std::map, std::vector>> - &airports) + inline void makeGate15(std::vector &gates, + const std::vector &fields) { - std::ifstream base(defaultFile); - if (!base.good()) { - return 1; + std::string gateName; + for (size_t j = 4; j < fields.size() - 1; j++) { + gateName += fields[j] + " "; } - std::ifstream custom(sceneryPack); - if (!custom.good()) { - base.close(); - return 2; - } - std::ofstream logfile(logFile, std::fstream::trunc); - if (!logfile.good()) { - base.close(); - custom.close(); - return 3; - } - - // Default - logfile << " " << defaultFile << std::endl; - makeAirport("DEFAULT", base, airports, logfile); - base.close(); - - std::string line; - size_t pos; - std::vector packs; - while (std::getline(custom, line)) { - if ((pos = line.find("SCENERY_PACK")) != std::string::npos) { - std::string path = util::rtrim_copy(line.substr(pos + 13)) + - "Earth nav data/apt.dat"; - packs.emplace_back(path); - } - } - std::reverse(packs.begin(), packs.end()); - - for (std::string const &path : packs) { - std::ifstream pack(path); - if (pack.good()) { - logfile << " " << path << std::endl; - makeAirport("CUSTOM", pack, airports, logfile); - pack.close(); - } else { - pack.close(); - logfile << "" - << "Could not find " << path << std::endl; - } - } - - logfile << std::endl - << " Total airports: " << airports.size() << std::endl; - - custom.close(); - logfile.close(); - return 0; + gateName += fields.back(); + gateName = std::regex_replace(gateName, std::regex{","}, "0"); + gates.emplace_back(gateName, + std::stod(fields[1]), + std::stod(fields[2]), + 40); } - void makeAirport( + inline void makeRunway(std::vector &runways, + const std::vector &fields) + { + runways.emplace_back(fields[8], + std::stod(fields[9]), + std::stod(fields[10]), + std::stod(fields[18]), + std::stod(fields[19]), + std::stod(fields[1])); + runways.emplace_back(fields[17], + std::stod(fields[18]), + std::stod(fields[19]), + std::stod(fields[9]), + std::stod(fields[10]), + std::stod(fields[1])); + } + + inline void makeGate1300(std::vector &gates, + const std::vector &fields) + { + std::string gateName; + for (size_t j = 6; j < fields.size() - 1; j++) { + gateName += fields[j] + " "; + } + gateName += fields.back(); + gateName = std::regex_replace(gateName, std::regex{","}, "0"); + + gates.emplace_back(gateName, + std::stod(fields[1]), + std::stod(fields[2]), + 40); + } + + inline void makeAirport( const std::string &kind, std::ifstream &infile, std::map, std::vector>> @@ -144,53 +140,68 @@ namespace file << validCount << " are valid" << std::endl; } - void makeGate15(std::vector &gates, - const std::vector &fields) + inline int scan( + const std::string defaultFile, + const std::string sceneryPack, + const std::string logFile, + std::map, std::vector>> + &airports) { - std::string gateName; - for (size_t j = 4; j < fields.size() - 1; j++) { - gateName += fields[j] + " "; + std::ifstream base(defaultFile); + if (!base.good()) { + return 1; } - gateName += fields.back(); - gateName = std::regex_replace(gateName, std::regex{","}, "0"); - gates.emplace_back(gateName, - std::stod(fields[1]), - std::stod(fields[2]), - 40); - } - - void makeRunway(std::vector &runways, - const std::vector &fields) - { - runways.emplace_back(fields[8], - std::stod(fields[9]), - std::stod(fields[10]), - std::stod(fields[18]), - std::stod(fields[19]), - std::stod(fields[1])); - runways.emplace_back(fields[17], - std::stod(fields[18]), - std::stod(fields[19]), - std::stod(fields[9]), - std::stod(fields[10]), - std::stod(fields[1])); - } - - void makeGate1300(std::vector &gates, - const std::vector &fields) - { - std::string gateName; - for (size_t j = 6; j < fields.size() - 1; j++) { - gateName += fields[j] + " "; + std::ifstream custom(sceneryPack); + if (!custom.good()) { + base.close(); + return 2; + } + std::ofstream logfile(logFile, std::fstream::trunc); + if (!logfile.good()) { + base.close(); + custom.close(); + return 3; } - gateName += fields.back(); - gateName = std::regex_replace(gateName, std::regex{","}, "0"); - gates.emplace_back(gateName, - std::stod(fields[1]), - std::stod(fields[2]), - 40); + // Default + logfile << " " << defaultFile << std::endl; + makeAirport("DEFAULT", base, airports, logfile); + base.close(); + + std::string line; + size_t pos; + std::vector packs; + while (std::getline(custom, line)) { + if ((pos = line.find("SCENERY_PACK")) != std::string::npos) { + std::string path = util::rtrim_copy(line.substr(pos + 13)) + + "Earth nav data/apt.dat"; + packs.emplace_back(path); + } + } + std::reverse(packs.begin(), packs.end()); + + for (std::string const &path : packs) { + std::ifstream pack(path); + if (pack.good()) { + logfile << " " << path << std::endl; + makeAirport("CUSTOM", pack, airports, logfile); + pack.close(); + } else { + pack.close(); + logfile << "" + << "Could not find " << path << std::endl; + } + } + + logfile << std::endl + << " Total airports: " << airports.size() << std::endl; + + custom.close(); + logfile.close(); + return 0; } } // namespace simdata } // namespace file -} // namespace germanairlinesva \ No newline at end of file +} // namespace germanairlinesva + +#endif \ No newline at end of file diff --git a/file/logbook.cpp b/file/logbook.cpp index ed4cd08..d65bd76 100644 --- a/file/logbook.cpp +++ b/file/logbook.cpp @@ -8,14 +8,14 @@ namespace file { Logbook::Logbook() { - if (util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) { + if (util::fileExists(BASE_DIRECTORY LOGBOOK)) { this->fromFile(); } } void Logbook::fromFile() { - std::ifstream in(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::ifstream::binary); + std::ifstream in(BASE_DIRECTORY LOGBOOK, std::ifstream::binary); // File Header std::string ident = readString(in, 5); @@ -96,7 +96,7 @@ namespace file void Logbook::toFile() const { - std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::fstream::binary); + std::ofstream out(BASE_DIRECTORY LOGBOOK, std::fstream::binary); char header[] = {'V', 'G', 'A', 'L', '\0', 1}; out.write(header, 6); for (const LogbookEntry &entry : this->entries) { diff --git a/file/recording.cpp b/file/recording.cpp index 5c2e243..87bcdb4 100644 --- a/file/recording.cpp +++ b/file/recording.cpp @@ -8,7 +8,7 @@ namespace file { void Recording::toFile(std::string fileName) const { - std::ofstream out(XPLANE_PLUGIN_DIRECTORY RECORDING_DIRECTORY + fileName, + std::ofstream out(BASE_DIRECTORY RECORDING_DIRECTORY + fileName, std::fstream::binary); char header[] = {'V', 'G', 'A', 'R', '\0', 1}; out.write(header, 6); diff --git a/file/runway.cpp b/file/runway.cpp deleted file mode 100644 index 82a5e6e..0000000 --- a/file/runway.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "simdata/runway.h" - -namespace germanairlinesva -{ -namespace file -{ - namespace simdata - { - Runway::Runway(std::string designator, - double latitudeStart, - double longitudeStart, - double latitudeEnd, - double longitudeEnd, - double width) - { - this->designator = designator; - this->width = width; - this->length = geodata::distanceEarthD(latitudeStart, - longitudeStart, - latitudeEnd, - longitudeEnd); - this->trueHeading = geodata::bearingDD(latitudeStart, - longitudeStart, - latitudeEnd, - longitudeEnd); - this->bounds = geodata::calculateBoxDD({latitudeStart, longitudeStart}, - {latitudeEnd, longitudeEnd}, - this->trueHeading, - this->width); - } - - Runway::Runway(std::string designator, - struct geodata::box bounds, - std::uint8_t width, - std::uint16_t length, - double trueHeading) - { - this->designator = designator; - this->bounds = bounds; - this->width = width; - this->length = length; - this->trueHeading = trueHeading; - } - - void Runway::toFile(std::ofstream &out) const - { - writeString(out, this->designator); - writebounds)>(out, this->bounds); - writewidth)>(out, this->width); - writelength)>(out, this->length); - writetrueHeading)>(out, this->trueHeading); - } - } // namespace simdata -} // namespace file -} // namespace germanairlinesva \ No newline at end of file diff --git a/file/simDatabase.cpp b/file/simDatabase.cpp deleted file mode 100644 index 4012cbb..0000000 --- a/file/simDatabase.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include "simdata/simDatabase.h" - -namespace germanairlinesva -{ -namespace file -{ - namespace simdata - { - SimDatabase::SimDatabase(int xPlaneVersion, - const char *hash, - std::unique_ptr &configuration, - std::function toLog) - { - if (strcmp(configuration->getScenery().c_str(), hash) != 0 || - !util::fileExists(XPLANE_PLUGIN_DIRECTORY SIMDATABASE)) { - scan(xPlaneVersion < 12000 ? XPLANE11_BASE_SCENERY - : XPLANE12_BASE_SCENERY, - XPLANE_CUSTOM_SCENERY, - XPLANE_PLUGIN_DIRECTORY "log.txt", - airports); - - configuration->updateScenery(hash); - this->toFile(); - - toLog("Sim Database updated"); - } else { - this->fromFile(); - - toLog("Sim Database loaded"); - } - } - - void SimDatabase::fromFile() - { - std::ifstream in(XPLANE_PLUGIN_DIRECTORY SIMDATABASE, - std::ifstream::binary); - - // File Header - std::string ident = readString(in, 5); - if (ident.compare("VGAS") != 0) { - throw std::invalid_argument("Wrong file"); - } - std::uint8_t version = read(in); - - if (version == 1) { - this->readVersion1(in); - } - } - - void SimDatabase::readVersion1(std::ifstream &in) - { - std::uint16_t numAirports = read(in); - - for (int i = 0; i < numAirports; i++) { - // ICAO - std::string icao = readString(in); - // Gates - std::uint16_t numGates = read(in); - for (int j = 0; j < numGates; j++) { - std::string designator = readString(in); - struct geodata::point center = read(in); - std::uint8_t radius = read(in); - - this->airports[icao].first.emplace_back(designator, center, radius); - } - // Runways - std::uint8_t numRunways = read(in); - for (int j = 0; j < numRunways; j++) { - std::string designator = readString(in); - // Center - struct geodata::box bounds = read(in); - std::uint8_t width = read(in); - std::uint16_t length = read(in); - double trueHeading = read(in); - - this->airports[icao].second.emplace_back(designator, - bounds, - width, - length, - trueHeading); - } - } - - in.close(); - } - - void SimDatabase::toFile() const - { - std::ofstream out(XPLANE_PLUGIN_DIRECTORY SIMDATABASE, - std::fstream::binary); - - // File Header, Last member is version - std::uint8_t header[] = {'V', 'G', 'A', 'S', '\0', 1}; - out.write(reinterpret_cast(header), 6); - // Num Airports - write(out, airports.size()); - // Airport - for (const std::pair, std::vector>> - &airport : airports) { - std::string icao = airport.first; - const std::vector gates = airport.second.first; - const std::vector runways = airport.second.second; - // ICAO - writeString(out, icao); - // Gates - write(out, gates.size()); - for (const Gate &gate : gates) { - gate.toFile(out); - } - // Runways - write(out, runways.size()); - for (const Runway &runway : runways) { - runway.toFile(out); - } - } - out.close(); - } - } // namespace simdata -} // namespace file -} // namespace germanairlinesva \ No newline at end of file diff --git a/utilities/include/constants.h b/utilities/include/constants.h index f114534..8c0f777 100644 --- a/utilities/include/constants.h +++ b/utilities/include/constants.h @@ -1,9 +1,13 @@ #ifndef GERMANAIRLINESVA_GACONNECTOR_CONSTANTS_H #define GERMANAIRLINESVA_GACONNECTOR_CONSTANTS_H -#define XPLANE_CUSTOM_SCENERY "Custom Scenery/scenery_packs.ini" -#define XPLANE_PLUGIN_DIRECTORY "Resources/plugins/GAConnector/" +#ifdef XP +#define BASE_DIRECTORY "Resources/plugins/GAConnector/" +#else +#define BASE_DIRECTORY "./" +#endif +#define XPLANE_CUSTOM_SCENERY "Custom Scenery/scenery_packs.ini" #define XPLANE11_BASE_SCENERY \ "Resources/default scenery/default apt dat/Earth nav data/apt.dat" #define XPLANE12_BASE_SCENERY \ diff --git a/xplugin/CMakeLists.txt b/xplugin/CMakeLists.txt index e7b7e10..a090c05 100644 --- a/xplugin/CMakeLists.txt +++ b/xplugin/CMakeLists.txt @@ -55,6 +55,7 @@ if(APPLE) target_compile_definitions(germanairlinesva_xplugin PUBLIC APL + XP ) target_compile_options(germanairlinesva_xplugin PRIVATE "SHELL:-arch x86_64" @@ -76,6 +77,7 @@ elseif(UNIX) target_compile_definitions(germanairlinesva_xplugin PUBLIC LIN + XP ) target_compile_options(germanairlinesva_xplugin PRIVATE -nodefaultlibs @@ -90,6 +92,7 @@ elseif(WIN32) target_compile_definitions(germanairlinesva_xplugin PUBLIC IBM + XP ) if(DEBUG) target_compile_options(germanairlinesva_xplugin PRIVATE diff --git a/xplugin/include/main.h b/xplugin/include/main.h index 01aa904..727c205 100644 --- a/xplugin/include/main.h +++ b/xplugin/include/main.h @@ -1,12 +1,11 @@ #ifndef GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H #define GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H -#include "config/config.h" +#include "config/config.hpp" #include "constants.h" #include "logbook/logbook.h" #include "recording/recording.h" -#include "simdata/simDatabase.h" -#include "simdata/simdataXP.h" +#include "simdata/simDatabase.hpp" #include "util.hpp" #include "websocket.h"