Refactor SimDatabase
This commit is contained in:
@@ -80,9 +80,6 @@ elseif(UNIX)
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-nodefaultlibs
|
||||
)
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
pthread
|
||||
)
|
||||
elseif(WIN32)
|
||||
message("Building for Windows ${BIT} into ${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}")
|
||||
|
||||
@@ -102,12 +99,6 @@ elseif(WIN32)
|
||||
-Wl,-pdb=
|
||||
)
|
||||
endif()
|
||||
target_link_options(germanairlinesva_xplugin PRIVATE
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
)
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
)
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/XPSDK/Libraries/Win/XPLM_64.lib
|
||||
)
|
||||
@@ -118,4 +109,5 @@ endif()
|
||||
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
ixwebsocket
|
||||
pthread
|
||||
)
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "constants.h"
|
||||
#include "logbook/logbook.h"
|
||||
#include "recording/recording.h"
|
||||
#include "simdata/simDatabase.h"
|
||||
#include "simdata/simdataXP.h"
|
||||
#include "simdata/simulatorDatabase.hpp"
|
||||
#include "util.hpp"
|
||||
#include "websocket.h"
|
||||
|
||||
|
||||
+19
-32
@@ -10,12 +10,9 @@ std::thread serverThread;
|
||||
std::thread recordingThread;
|
||||
std::atomic<bool> wantsExit;
|
||||
|
||||
germanairlinesva::file::config::Config configuration;
|
||||
std::map<std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
airports;
|
||||
germanairlinesva_websocket::Websocket *connector;
|
||||
std::unique_ptr<germanairlinesva::file::config::Config> configuration;
|
||||
std::unique_ptr<germanairlinesva::file::simdata::SimDatabase> database;
|
||||
std::unique_ptr<germanairlinesva_websocket::Websocket> connector;
|
||||
int xplaneVersion;
|
||||
|
||||
/* Datarefs */
|
||||
@@ -114,52 +111,39 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
roll = XPLMFindDataRef("sim/flightmodel/position/phi"); // FLOAT
|
||||
quaternion = XPLMFindDataRef("sim/flightmodel/position/q"); // FLOAT[4]
|
||||
|
||||
configuration = germanairlinesva::file::config::Config();
|
||||
configuration = std::make_unique<germanairlinesva::file::config::Config>();
|
||||
toLog("Config loaded");
|
||||
|
||||
try {
|
||||
connector = new germanairlinesva_websocket::Websocket(
|
||||
connector = std::make_unique<germanairlinesva_websocket::Websocket>(
|
||||
"wss://ws.hofmannnet.myhome-server.de:8000",
|
||||
configuration.getUser(),
|
||||
configuration->getUser(),
|
||||
toLog);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
toLog(e.what());
|
||||
return 0;
|
||||
}
|
||||
toLog("WebSocket started");
|
||||
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (germanairlinesva::util::generateMD5(XPLANE_CUSTOM_SCENERY, hash, toLog) ==
|
||||
0) {
|
||||
|
||||
if (strcmp(configuration.getScenery().c_str(), hash) != 0 ||
|
||||
!germanairlinesva::util::fileExists(
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE)) {
|
||||
scan(xplaneVersion < 12000 ? XPLANE11_BASE_SCENERY
|
||||
: XPLANE12_BASE_SCENERY,
|
||||
XPLANE_CUSTOM_SCENERY,
|
||||
XPLANE_PLUGIN_DIRECTORY "log.txt",
|
||||
airports);
|
||||
germanairlinesva::file::simdata::toFile(
|
||||
airports,
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
|
||||
configuration.updateScenery(hash);
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
airports = germanairlinesva::file::simdata::fromFile(
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
toLog("Sim Database loaded");
|
||||
}
|
||||
database = std::make_unique<germanairlinesva::file::simdata::SimDatabase>(
|
||||
xplaneVersion,
|
||||
hash,
|
||||
configuration,
|
||||
toLog);
|
||||
|
||||
toLog("Readback test of sim database using EDDF");
|
||||
auto ap = airports["EDDF"];
|
||||
auto ap = (*database)["EDDF"];
|
||||
for (const auto &it : ap.first) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
for (const auto &it : ap.second) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
toLog("Readback test of sim database using XXXX");
|
||||
auto ap2 = (*database)["XXXX"];
|
||||
ap2.first.size() == 0 ? toLog(" SUCCESS") : toLog(" ERROR");
|
||||
}
|
||||
|
||||
// Thread for sending data to websocket
|
||||
@@ -209,10 +193,13 @@ PLUGIN_API void XPluginStop(void)
|
||||
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
|
||||
/* End threads */
|
||||
wantsExit = true;
|
||||
delete connector;
|
||||
serverThread.join();
|
||||
recordingThread.join();
|
||||
|
||||
delete connector.release();
|
||||
delete database.release();
|
||||
delete configuration.release();
|
||||
|
||||
p.toFile("flight.rec");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user