diff --git a/TODO.md b/TODO.md index 6b35761..c30438e 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,6 @@ - Reverse engineer FSUIPC .NET onRunway Check - Update OSXCross Docker image to SDK 11 -- Implement ARM64 arch for Plugin \ No newline at end of file +- Implement ARM64 arch for Plugin +- Refactor SimDatabase to be a class + - Requires new Airport class +- Refactor Config to be a class \ No newline at end of file diff --git a/file/gate.cpp b/file/gate.cpp index db8d1f3..818eb6c 100644 --- a/file/gate.cpp +++ b/file/gate.cpp @@ -18,8 +18,8 @@ namespace file void Gate::toFile(std::ofstream &out) const { writeString(out, this->designator); - write(out, this->center); - write(out, this->radius); + writecenter)>(out, this->center); + writeradius)>(out, this->radius); } } // namespace simdata } // namespace file diff --git a/file/include/recording/recording.h b/file/include/recording/recording.h index 06e4a79..38465d9 100644 --- a/file/include/recording/recording.h +++ b/file/include/recording/recording.h @@ -2,9 +2,10 @@ #define GERMANAIRLINESVA_FILE_RECORDING_H #include -#include +#include #include +#include "constants.h" #include "recordingEntry.h" namespace germanairlinesva @@ -28,14 +29,14 @@ namespace file class Recording { private: - std::uint64_t count = 0; - std::vector file{'V', 'G', 'A', 'R', '\0', 1}; + std::vector entries; public: - void addSegment(const RecordingEntry &segment); - - inline const std::uint8_t *getBinaryData() const { return file.data(); } - inline std::size_t getBinaryLength() const { return file.size(); } + template inline void addEntry(Args &&...args) + { + this->entries.emplace_back(std::forward(args)...); + } + void toFile(std::string fileName) const; }; } // namespace recording } // namespace file diff --git a/file/include/recording/recordingEntry.h b/file/include/recording/recordingEntry.h index a6f64ec..e0c2145 100644 --- a/file/include/recording/recordingEntry.h +++ b/file/include/recording/recordingEntry.h @@ -2,10 +2,11 @@ #define GERMANAIRLINESVA_FILE_RECORDINGENTRY_H #include -#include +#include #include #include "geodata.hpp" +#include "helpers.hpp" namespace germanairlinesva { @@ -22,11 +23,10 @@ namespace file class RecordingEntry { private: - std::uint32_t time = 0; - std::uint16_t altitude = 0; - std::uint16_t groundSpeed = 0; + std::uint32_t time; + std::uint16_t altitude; + std::uint16_t groundSpeed; struct germanairlinesva::geodata::point coordinates; - std::vector file; public: RecordingEntry() = default; @@ -35,8 +35,7 @@ namespace file std::uint16_t groundSpeed, struct germanairlinesva::geodata::point coordinates); - inline const std::uint8_t *getBinaryData() const { return file.data(); } - inline std::size_t getBinaryLength() const { return file.size(); } + void toFile(std::ofstream &out) const; friend inline bool operator==(const RecordingEntry &lhs, const RecordingEntry &rhs) diff --git a/file/include/simdata/gate.h b/file/include/simdata/gate.h index 046cec4..d6034b2 100644 --- a/file/include/simdata/gate.h +++ b/file/include/simdata/gate.h @@ -2,7 +2,6 @@ #define GERMANAIRLINESVA_FILE_GATE_H #include -#include #include #include #include diff --git a/file/logbookEntry.cpp b/file/logbookEntry.cpp index ae91c0f..f6bbee8 100644 --- a/file/logbookEntry.cpp +++ b/file/logbookEntry.cpp @@ -83,21 +83,21 @@ namespace file writeString(out, this->outTime, 5); writeString(out, this->onTime, 5); writeString(out, this->onBlockTime, 5); - write(out, this->totalFlightTime); - write(out, this->taxiOutFuel); - write(out, this->inFlightFuel); - write(out, this->taxiInFuel); - write(out, this->totalFuel); - write(out, this->taxiOutDistance); - write(out, this->inFlightDistance); - write(out, this->taxiInDistance); - write(out, this->totalDistance); - write(out, this->maxLandingRate); - write(out, this->touchdowns); - write(out, this->maxLandingGees); + writetotalFlightTime)>(out, this->totalFlightTime); + writetaxiOutFuel)>(out, this->taxiOutFuel); + writeinFlightFuel)>(out, this->inFlightFuel); + writetaxiInFuel)>(out, this->taxiInFuel); + writetotalFuel)>(out, this->totalFuel); + writetaxiOutDistance)>(out, this->taxiOutDistance); + writeinFlightDistance)>(out, this->inFlightDistance); + writetaxiInDistance)>(out, this->taxiInDistance); + writetotalDistance)>(out, this->totalDistance); + writemaxLandingRate)>(out, this->maxLandingRate); + writetouchdowns)>(out, this->touchdowns); + writemaxLandingGees)>(out, this->maxLandingGees); writeString(out, this->recordingFilename); - write(out, this->points); - write(out, this->flags); + writepoints)>(out, this->points); + writeflags)>(out, this->flags); } } // namespace logbook } // namespace file diff --git a/file/php/testRecording.php b/file/php/testRecording.php index d98286f..13b0e9d 100644 --- a/file/php/testRecording.php +++ b/file/php/testRecording.php @@ -2,5 +2,5 @@ require "Recording.php"; -$r = new germanairlinesva_recording\Recording("/mnt/f/X-Plane 12/Resources/plugins/GAConnector/recordings/flight.rec"); +$r = new germanairlinesva_recording\Recording("/mnt/f/X-Plane 11/Resources/plugins/GAConnector/recordings/flight.rec"); print_r($r->geoJSON()); diff --git a/file/recording.cpp b/file/recording.cpp index 973c21d..5c2e243 100644 --- a/file/recording.cpp +++ b/file/recording.cpp @@ -6,13 +6,16 @@ namespace file { namespace recording { - void Recording::addSegment(const RecordingEntry &segment) + void Recording::toFile(std::string fileName) const { - file.resize(file.size() + segment.getBinaryLength()); - std::uint8_t *bufPtr = - 6 + file.data() + count * segment.getBinaryLength(); - std::memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength()); - count++; + std::ofstream out(XPLANE_PLUGIN_DIRECTORY RECORDING_DIRECTORY + fileName, + std::fstream::binary); + char header[] = {'V', 'G', 'A', 'R', '\0', 1}; + out.write(header, 6); + for (const RecordingEntry &entry : this->entries) { + entry.toFile(out); + } + out.close(); } } // namespace recording } // namespace file diff --git a/file/recordingEntry.cpp b/file/recordingEntry.cpp index 39c20ea..efb4ae4 100644 --- a/file/recordingEntry.cpp +++ b/file/recordingEntry.cpp @@ -17,20 +17,15 @@ namespace file this->altitude = altitude; this->groundSpeed = groundSpeed; this->coordinates = coordinates; - - file = std::vector( - sizeof(this->time) + sizeof(this->altitude) + - sizeof(this->groundSpeed) + sizeof(this->coordinates), - 0); - std::uint8_t *bufPtr = file.data(); - std::memcpy(bufPtr, &this->time, sizeof(this->time)); - bufPtr += sizeof(this->time); - std::memcpy(bufPtr, &this->altitude, sizeof(this->altitude)); - bufPtr += sizeof(this->altitude); - std::memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed)); - bufPtr += sizeof(this->groundSpeed); - std::memcpy(bufPtr, &this->coordinates, sizeof(this->coordinates)); }; + + void RecordingEntry::toFile(std::ofstream &out) const + { + writetime)>(out, this->time); + writealtitude)>(out, this->altitude); + writegroundSpeed)>(out, this->groundSpeed); + writecoordinates)>(out, this->coordinates); + } } // namespace recording } // namespace file } // namespace germanairlinesva \ No newline at end of file diff --git a/file/runway.cpp b/file/runway.cpp index 0ccc253..4c82f84 100644 --- a/file/runway.cpp +++ b/file/runway.cpp @@ -47,10 +47,10 @@ namespace file void Runway::toFile(std::ofstream &out) const { writeString(out, this->designator); - write(out, this->bounds); - write(out, this->width); - write(out, this->length); - write(out, this->trueHeading); + writebounds)>(out, this->bounds); + writewidth)>(out, this->width); + writelength)>(out, this->length); + writetrueHeading)>(out, this->trueHeading); } } // namespace simdata } // namespace file diff --git a/xplugin/main.cpp b/xplugin/main.cpp index 526dc1c..072ee9d 100644 --- a/xplugin/main.cpp +++ b/xplugin/main.cpp @@ -217,11 +217,7 @@ PLUGIN_API void XPluginStop(void) serverThread.join(); recordingThread.join(); - std::ofstream out(XPLANE_PLUGIN_DIRECTORY RECORDING_DIRECTORY "flight.rec", - std::fstream::binary); - out.write(reinterpret_cast(p.getBinaryData()), - (std::streamsize)p.getBinaryLength()); - out.close(); + p.toFile("flight.rec"); } PLUGIN_API void XPluginDisable(void) {} @@ -318,7 +314,7 @@ void recordingWorker() {copy.lat, copy.lon}); if (strcmp(copy.path, "") != 0 && copy.pause && lastPath != currentPath) { - p.addSegment(currentPath); + p.addEntry(currentPath); lastPath = currentPath; }