From 796fd0f7aaebde7cff873b3ac96182edf2c82c99 Mon Sep 17 00:00:00 2001 From: Jason Watkins Date: Fri, 1 May 2015 09:01:21 -0700 Subject: [PATCH] Fix for Linux builds --- xpcPlugin/CMakeLists.txt | 4 +- xpcPlugin/DataManager.cpp | 387 +++++++++++++++++++++------------- xpcPlugin/DataManager.h | 174 +++++++-------- xpcPlugin/DataMaps.cpp | 74 +------ xpcPlugin/Message.cpp | 2 +- xpcPlugin/MessageHandlers.cpp | 150 +++++++------ xpcPlugin/MessageHandlers.h | 6 +- xpcPlugin/UDPSocket.cpp | 5 +- xpcPlugin/XPCPlugin.cpp | 4 +- 9 files changed, 414 insertions(+), 392 deletions(-) diff --git a/xpcPlugin/CMakeLists.txt b/xpcPlugin/CMakeLists.txt index 0f889fd..ca964b5 100644 --- a/xpcPlugin/CMakeLists.txt +++ b/xpcPlugin/CMakeLists.txt @@ -20,7 +20,7 @@ add_library(xpc64 SHARED XPCPlugin.cpp MessageHandlers.cpp UDPSocket.cpp) set_target_properties(xpc64 PROPERTIES PREFIX "" SUFFIX ".xpl") -set_target_properties(xpc64 PROPERTIES COMPILE_FLAGS "-std=gnu++11" LINK_FLAGS "-shared -rdynamic -nodefaultlibs -undefined_warning") +set_target_properties(xpc64 PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-shared -rdynamic -nodefaultlibs -undefined_warning -m64") add_library(xpc32 SHARED XPCPlugin.cpp DataManager.cpp @@ -31,7 +31,7 @@ add_library(xpc32 SHARED XPCPlugin.cpp MessageHandlers.cpp UDPSocket.cpp) set_target_properties(xpc32 PROPERTIES PREFIX "" SUFFIX ".xpl") -set_target_properties(xpc32 PROPERTIES COMPILE_FLAGS "-std=gnu++11 -m32" LINK_FLAGS "-shared -rdynamic -nodefaultlibs -undefined_warning -m32") +set_target_properties(xpc32 PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-shared -rdynamic -nodefaultlibs -undefined_warning -m32") # Switch install targets when uncommenting the 32 bit line above. install(TARGETS xpc64 DESTINATION XPlaneConnect/64 RENAME lin.xpl) diff --git a/xpcPlugin/DataManager.cpp b/xpcPlugin/DataManager.cpp index 3f3541e..15335ec 100644 --- a/xpcPlugin/DataManager.cpp +++ b/xpcPlugin/DataManager.cpp @@ -15,193 +15,290 @@ // without specific prior written permission from the authors or // Laminar Research, respectively. #include "DataManager.h" +#include "DataMaps.h" #include "Log.h" #include "XPLMDataAccess.h" #include "XPLMGraphics.h" #include -#include - -namespace std -{ - // Note: This is required for unordered_map - template <> - struct hash - { - size_t operator()(const XPC::DREF & x) const - { - return static_cast(x); - } - }; -} +#include +#include namespace XPC { using namespace std; - static unordered_map drefs; - static unordered_map mdrefs[20]; - static unordered_map sdrefs; + static map drefs; + static map mdrefs[20]; + static map sdrefs; void DataManager::Initialize() { - drefs = unordered_map( - { - { DREF::None, XPLMFindDataRef("sim/test/test_float") }, + drefs.insert(make_pair(DREF_None, XPLMFindDataRef("sim/test/test_float"))); - { DREF::Pause, XPLMFindDataRef("sim/operation/override/override_planepath") }, - { DREF::PauseAI, XPLMFindDataRef("sim/operation/override/override_plane_ai_autopilot") }, + drefs.insert(make_pair(DREF_Pause, XPLMFindDataRef("sim/operation/override/override_planepath"))); + drefs.insert(make_pair(DREF_PauseAI, XPLMFindDataRef("sim/operation/override/override_plane_ai_autopilot"))); - { DREF::TotalRuntime, XPLMFindDataRef("sim/time/total_running_time_sec") }, - { DREF::TotalFlighttime, XPLMFindDataRef("sim/time/total_flight_time_sec") }, - { DREF::TimerElapsedtime, XPLMFindDataRef("sim/time/timer_elapsed_time_sec") }, + drefs.insert(make_pair(DREF_TotalRuntime, XPLMFindDataRef("sim/time/total_running_time_sec"))); + drefs.insert(make_pair(DREF_TotalFlighttime, XPLMFindDataRef("sim/time/total_flight_time_sec"))); + drefs.insert(make_pair(DREF_TimerElapsedtime, XPLMFindDataRef("sim/time/timer_elapsed_time_sec"))); - { DREF::IndicatedAirspeed, XPLMFindDataRef("sim/flightmodel/position/indicated_airspeed") }, - { DREF::TrueAirspeed, XPLMFindDataRef("sim/flightmodel/position/true_airspeed") }, - { DREF::GroundSpeed, XPLMFindDataRef("sim/flightmodel/position/groundspeed") }, + drefs.insert(make_pair(DREF_IndicatedAirspeed, XPLMFindDataRef("sim/flightmodel/position/indicated_airspeed"))); + drefs.insert(make_pair(DREF_TrueAirspeed, XPLMFindDataRef("sim/flightmodel/position/true_airspeed"))); + drefs.insert(make_pair(DREF_GroundSpeed, XPLMFindDataRef("sim/flightmodel/position/groundspeed"))); - { DREF::MachNumber, XPLMFindDataRef("sim/flightmodel/misc/machno") }, - { DREF::GForceNormal, XPLMFindDataRef("sim/flightmodel2/misc/gforce_normal") }, - { DREF::GForceAxial, XPLMFindDataRef("sim/flightmodel2/misc/gforce_axial") }, - { DREF::GForceSide, XPLMFindDataRef("sim/flightmodel2/misc/gforce_side") }, + drefs.insert(make_pair(DREF_MachNumber, XPLMFindDataRef("sim/flightmodel/misc/machno"))); + drefs.insert(make_pair(DREF_GForceNormal, XPLMFindDataRef("sim/flightmodel2/misc/gforce_normal"))); + drefs.insert(make_pair(DREF_GForceAxial, XPLMFindDataRef("sim/flightmodel2/misc/gforce_axial"))); + drefs.insert(make_pair(DREF_GForceSide, XPLMFindDataRef("sim/flightmodel2/misc/gforce_side"))); - { DREF::BarometerSealevelInHg, XPLMFindDataRef("sim/weather/barometer_sealevel_inhg") }, - { DREF::TemperaturSealevelC, XPLMFindDataRef("sim/weather/temperature_sealevel_c") }, - { DREF::WindSpeedKts, XPLMFindDataRef("sim/cockpit2/gauges/indicators/wind_speed_kts") }, + drefs.insert(make_pair(DREF_BarometerSealevelInHg, XPLMFindDataRef("sim/weather/barometer_sealevel_inhg"))); + drefs.insert(make_pair(DREF_TemperaturSealevelC, XPLMFindDataRef("sim/weather/temperature_sealevel_c"))); + drefs.insert(make_pair(DREF_WindSpeedKts, XPLMFindDataRef("sim/cockpit2/gauges/indicators/wind_speed_kts"))); - { DREF::YokePitch, XPLMFindDataRef("sim/joystick/yoke_pitch_ratio") }, - { DREF::YokeRoll, XPLMFindDataRef("sim/joystick/yoke_roll_ratio") }, - { DREF::YokeHeading, XPLMFindDataRef("sim/joystick/yoke_heading_ratio") }, + drefs.insert(make_pair(DREF_YokePitch, XPLMFindDataRef("sim/joystick/yoke_pitch_ratio"))); + drefs.insert(make_pair(DREF_YokeRoll, XPLMFindDataRef("sim/joystick/yoke_roll_ratio"))); + drefs.insert(make_pair(DREF_YokeHeading, XPLMFindDataRef("sim/joystick/yoke_heading_ratio"))); - { DREF::Elevator, XPLMFindDataRef("sim/cockpit2/controls/yoke_pitch_ratio") }, - { DREF::Aileron, XPLMFindDataRef("sim/cockpit2/controls/yoke_roll_ratio") }, - { DREF::Rudder, XPLMFindDataRef("sim/cockpit2/controls/yoke_heading_ratio") }, + drefs.insert(make_pair(DREF_Elevator, XPLMFindDataRef("sim/cockpit2/controls/yoke_pitch_ratio"))); + drefs.insert(make_pair(DREF_Aileron, XPLMFindDataRef("sim/cockpit2/controls/yoke_roll_ratio"))); + drefs.insert(make_pair(DREF_Rudder, XPLMFindDataRef("sim/cockpit2/controls/yoke_heading_ratio"))); - { DREF::FlapSetting, XPLMFindDataRef("sim/flightmodel/controls/flaprqst") }, - { DREF::FlapActual, XPLMFindDataRef("sim/flightmodel/controls/flaprat") }, + drefs.insert(make_pair(DREF_FlapSetting, XPLMFindDataRef("sim/flightmodel/controls/flaprqst"))); + drefs.insert(make_pair(DREF_FlapActual, XPLMFindDataRef("sim/flightmodel/controls/flaprat"))); - { DREF::GearDeploy, XPLMFindDataRef("sim/aircraft/parts/acf_gear_deploy") }, - { DREF::GearHandle, XPLMFindDataRef("sim/cockpit/switches/gear_handle_status") }, - { DREF::BrakeParking, XPLMFindDataRef("sim/flightmodel/controls/parkbrakel") }, - { DREF::BrakeLeft, XPLMFindDataRef("sim/cockpit2/controls/left_brake_ratio") }, - { DREF::BrakeRight, XPLMFindDataRef("sim/cockpit2/controls/right_brake_ratio") }, + drefs.insert(make_pair(DREF_GearDeploy, XPLMFindDataRef("sim/aircraft/parts/acf_gear_deploy"))); + drefs.insert(make_pair(DREF_GearHandle, XPLMFindDataRef("sim/cockpit/switches/gear_handle_status"))); + drefs.insert(make_pair(DREF_BrakeParking, XPLMFindDataRef("sim/flightmodel/controls/parkbrakel"))); + drefs.insert(make_pair(DREF_BrakeLeft, XPLMFindDataRef("sim/cockpit2/controls/left_brake_ratio"))); + drefs.insert(make_pair(DREF_BrakeRight, XPLMFindDataRef("sim/cockpit2/controls/right_brake_ratio"))); - { DREF::M, XPLMFindDataRef("sim/flightmodel/position/M") }, - { DREF::L, XPLMFindDataRef("sim/flightmodel/position/L") }, - { DREF::N, XPLMFindDataRef("sim/flightmodel/position/N") }, + drefs.insert(make_pair(DREF_M, XPLMFindDataRef("sim/flightmodel/position/M"))); + drefs.insert(make_pair(DREF_L, XPLMFindDataRef("sim/flightmodel/position/L"))); + drefs.insert(make_pair(DREF_N, XPLMFindDataRef("sim/flightmodel/position/N"))); - { DREF::QRad, XPLMFindDataRef("sim/flightmodel/position/Qrad") }, - { DREF::PRad, XPLMFindDataRef("sim/flightmodel/position/Prad") }, - { DREF::RRad, XPLMFindDataRef("sim/flightmodel/position/Rrad") }, - { DREF::Q, XPLMFindDataRef("sim/flightmodel/position/Q") }, - { DREF::P, XPLMFindDataRef("sim/flightmodel/position/P") }, - { DREF::R, XPLMFindDataRef("sim/flightmodel/position/R") }, + drefs.insert(make_pair(DREF_QRad, XPLMFindDataRef("sim/flightmodel/position/Qrad"))); + drefs.insert(make_pair(DREF_PRad, XPLMFindDataRef("sim/flightmodel/position/Prad"))); + drefs.insert(make_pair(DREF_RRad, XPLMFindDataRef("sim/flightmodel/position/Rrad"))); + drefs.insert(make_pair(DREF_Q, XPLMFindDataRef("sim/flightmodel/position/Q"))); + drefs.insert(make_pair(DREF_P, XPLMFindDataRef("sim/flightmodel/position/P"))); + drefs.insert(make_pair(DREF_R, XPLMFindDataRef("sim/flightmodel/position/R"))); - { DREF::Pitch, XPLMFindDataRef("sim/flightmodel/position/theta") }, - { DREF::Roll, XPLMFindDataRef("sim/flightmodel/position/phi") }, - { DREF::HeadingTrue, XPLMFindDataRef("sim/flightmodel/position/psi") }, - { DREF::HeadingMag, XPLMFindDataRef("sim/flightmodel/position/magpsi") }, - { DREF::Quaternion, XPLMFindDataRef("sim/flightmodel/position/q") }, + drefs.insert(make_pair(DREF_Pitch, XPLMFindDataRef("sim/flightmodel/position/theta"))); + drefs.insert(make_pair(DREF_Roll, XPLMFindDataRef("sim/flightmodel/position/phi"))); + drefs.insert(make_pair(DREF_HeadingTrue, XPLMFindDataRef("sim/flightmodel/position/psi"))); + drefs.insert(make_pair(DREF_HeadingMag, XPLMFindDataRef("sim/flightmodel/position/magpsi"))); + drefs.insert(make_pair(DREF_Quaternion, XPLMFindDataRef("sim/flightmodel/position/q"))); - { DREF::AngleOfAttack, XPLMFindDataRef("sim/flightmodel/position/alpha") }, - { DREF::Sideslip, XPLMFindDataRef("sim/cockpit2/gauges/indicators/sideslip_degrees") }, - { DREF::HPath, XPLMFindDataRef("sim/flightmodel/position/hpath") }, - { DREF::VPath, XPLMFindDataRef("sim/flightmodel/position/vpath") }, + drefs.insert(make_pair(DREF_AngleOfAttack, XPLMFindDataRef("sim/flightmodel/position/alpha"))); + drefs.insert(make_pair(DREF_Sideslip, XPLMFindDataRef("sim/cockpit2/gauges/indicators/sideslip_degrees"))); + drefs.insert(make_pair(DREF_HPath, XPLMFindDataRef("sim/flightmodel/position/hpath"))); + drefs.insert(make_pair(DREF_VPath, XPLMFindDataRef("sim/flightmodel/position/vpath"))); - { DREF::VPath, XPLMFindDataRef("sim/flightmodel/position/magnetic_variation") }, + drefs.insert(make_pair(DREF_VPath, XPLMFindDataRef("sim/flightmodel/position/magnetic_variation"))); - { DREF::Latitude, XPLMFindDataRef("sim/flightmodel/position/latitude") }, - { DREF::Longitude, XPLMFindDataRef("sim/flightmodel/position/longitude") }, - { DREF::AGL, XPLMFindDataRef("sim/flightmodel/position/y_agl") }, - { DREF::Elevation, XPLMFindDataRef("sim/flightmodel/position/elevation") }, + drefs.insert(make_pair(DREF_Latitude, XPLMFindDataRef("sim/flightmodel/position/latitude"))); + drefs.insert(make_pair(DREF_Longitude, XPLMFindDataRef("sim/flightmodel/position/longitude"))); + drefs.insert(make_pair(DREF_AGL, XPLMFindDataRef("sim/flightmodel/position/y_agl"))); + drefs.insert(make_pair(DREF_Elevation, XPLMFindDataRef("sim/flightmodel/position/elevation"))); - { DREF::LocalX, XPLMFindDataRef("sim/flightmodel/position/local_x") }, - { DREF::LocalY, XPLMFindDataRef("sim/flightmodel/position/local_y") }, - { DREF::LocalZ, XPLMFindDataRef("sim/flightmodel/position/local_z") }, - { DREF::LocalVX, XPLMFindDataRef("sim/flightmodel/position/local_vx") }, - { DREF::LocalVY, XPLMFindDataRef("sim/flightmodel/position/local_vy") }, - { DREF::LocalVZ, XPLMFindDataRef("sim/flightmodel/position/local_vz") }, + drefs.insert(make_pair(DREF_LocalX, XPLMFindDataRef("sim/flightmodel/position/local_x"))); + drefs.insert(make_pair(DREF_LocalY, XPLMFindDataRef("sim/flightmodel/position/local_y"))); + drefs.insert(make_pair(DREF_LocalZ, XPLMFindDataRef("sim/flightmodel/position/local_z"))); + drefs.insert(make_pair(DREF_LocalVX, XPLMFindDataRef("sim/flightmodel/position/local_vx"))); + drefs.insert(make_pair(DREF_LocalVY, XPLMFindDataRef("sim/flightmodel/position/local_vy"))); + drefs.insert(make_pair(DREF_LocalVZ, XPLMFindDataRef("sim/flightmodel/position/local_vz"))); - { DREF::ThrottleSet, XPLMFindDataRef("sim/flightmodel/engine/ENGN_thro") }, - { DREF::ThrottleActual, XPLMFindDataRef("sim/flightmodel2/engines/throttle_used_ratio") }, + drefs.insert(make_pair(DREF_ThrottleSet, XPLMFindDataRef("sim/flightmodel/engine/ENGN_thro"))); + drefs.insert(make_pair(DREF_ThrottleActual, XPLMFindDataRef("sim/flightmodel2/engines/throttle_used_ratio"))); - { DREF::MP1Lat, XPLMFindDataRef("sim/multiplayer/position/plane1_lat") }, - { DREF::MP2Lat, XPLMFindDataRef("sim/multiplayer/position/plane2_lat") }, - { DREF::MP3Lat, XPLMFindDataRef("sim/multiplayer/position/plane3_lat") }, - { DREF::MP4Lat, XPLMFindDataRef("sim/multiplayer/position/plane4_lat") }, - { DREF::MP5Lat, XPLMFindDataRef("sim/multiplayer/position/plane5_lat") }, - { DREF::MP6Lat, XPLMFindDataRef("sim/multiplayer/position/plane6_lat") }, - { DREF::MP7Lat, XPLMFindDataRef("sim/multiplayer/position/plane7_lat") }, + drefs.insert(make_pair(DREF_MP1Lat, XPLMFindDataRef("sim/multiplayer/position/plane1_lat"))); + drefs.insert(make_pair(DREF_MP2Lat, XPLMFindDataRef("sim/multiplayer/position/plane2_lat"))); + drefs.insert(make_pair(DREF_MP3Lat, XPLMFindDataRef("sim/multiplayer/position/plane3_lat"))); + drefs.insert(make_pair(DREF_MP4Lat, XPLMFindDataRef("sim/multiplayer/position/plane4_lat"))); + drefs.insert(make_pair(DREF_MP5Lat, XPLMFindDataRef("sim/multiplayer/position/plane5_lat"))); + drefs.insert(make_pair(DREF_MP6Lat, XPLMFindDataRef("sim/multiplayer/position/plane6_lat"))); + drefs.insert(make_pair(DREF_MP7Lat, XPLMFindDataRef("sim/multiplayer/position/plane7_lat"))); - { DREF::MP1Lon, XPLMFindDataRef("sim/multiplayer/position/plane1_lon") }, - { DREF::MP2Lon, XPLMFindDataRef("sim/multiplayer/position/plane2_lon") }, - { DREF::MP3Lon, XPLMFindDataRef("sim/multiplayer/position/plane3_lon") }, - { DREF::MP4Lon, XPLMFindDataRef("sim/multiplayer/position/plane4_lon") }, - { DREF::MP5Lon, XPLMFindDataRef("sim/multiplayer/position/plane5_lon") }, - { DREF::MP6Lon, XPLMFindDataRef("sim/multiplayer/position/plane6_lon") }, - { DREF::MP7Lon, XPLMFindDataRef("sim/multiplayer/position/plane7_lon") }, + drefs.insert(make_pair(DREF_MP1Lon, XPLMFindDataRef("sim/multiplayer/position/plane1_lon"))); + drefs.insert(make_pair(DREF_MP2Lon, XPLMFindDataRef("sim/multiplayer/position/plane2_lon"))); + drefs.insert(make_pair(DREF_MP3Lon, XPLMFindDataRef("sim/multiplayer/position/plane3_lon"))); + drefs.insert(make_pair(DREF_MP4Lon, XPLMFindDataRef("sim/multiplayer/position/plane4_lon"))); + drefs.insert(make_pair(DREF_MP5Lon, XPLMFindDataRef("sim/multiplayer/position/plane5_lon"))); + drefs.insert(make_pair(DREF_MP6Lon, XPLMFindDataRef("sim/multiplayer/position/plane6_lon"))); + drefs.insert(make_pair(DREF_MP7Lon, XPLMFindDataRef("sim/multiplayer/position/plane7_lon"))); - { DREF::MP1Alt, XPLMFindDataRef("sim/multiplayer/position/plane1_el") }, - { DREF::MP2Alt, XPLMFindDataRef("sim/multiplayer/position/plane2_el") }, - { DREF::MP3Alt, XPLMFindDataRef("sim/multiplayer/position/plane3_el") }, - { DREF::MP4Alt, XPLMFindDataRef("sim/multiplayer/position/plane4_el") }, - { DREF::MP5Alt, XPLMFindDataRef("sim/multiplayer/position/plane5_el") }, - { DREF::MP6Alt, XPLMFindDataRef("sim/multiplayer/position/plane6_el") }, - { DREF::MP7Alt, XPLMFindDataRef("sim/multiplayer/position/plane7_el") }, - }); + drefs.insert(make_pair(DREF_MP1Alt, XPLMFindDataRef("sim/multiplayer/position/plane1_el"))); + drefs.insert(make_pair(DREF_MP2Alt, XPLMFindDataRef("sim/multiplayer/position/plane2_el"))); + drefs.insert(make_pair(DREF_MP3Alt, XPLMFindDataRef("sim/multiplayer/position/plane3_el"))); + drefs.insert(make_pair(DREF_MP4Alt, XPLMFindDataRef("sim/multiplayer/position/plane4_el"))); + drefs.insert(make_pair(DREF_MP5Alt, XPLMFindDataRef("sim/multiplayer/position/plane5_el"))); + drefs.insert(make_pair(DREF_MP6Alt, XPLMFindDataRef("sim/multiplayer/position/plane6_el"))); + drefs.insert(make_pair(DREF_MP7Alt, XPLMFindDataRef("sim/multiplayer/position/plane7_el"))); char multi[256]; for (int i = 1; i < 20; i++) { sprintf(multi, "sim/multiplayer/position/plane%i_x", i); - mdrefs[i][DREF::LocalX] = XPLMFindDataRef(multi); + mdrefs[i][DREF_LocalX] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_y", i); - mdrefs[i][DREF::LocalY] = XPLMFindDataRef(multi); + mdrefs[i][DREF_LocalY] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_z", i); - mdrefs[i][DREF::LocalZ] = XPLMFindDataRef(multi); + mdrefs[i][DREF_LocalZ] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_lat", i); - mdrefs[i][DREF::Latitude] = XPLMFindDataRef(multi); + mdrefs[i][DREF_Latitude] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_lon", i); - mdrefs[i][DREF::Longitude] = XPLMFindDataRef(multi); + mdrefs[i][DREF_Longitude] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_el", i); - mdrefs[i][DREF::Elevation] = XPLMFindDataRef(multi); + mdrefs[i][DREF_Elevation] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_the", i); - mdrefs[i][DREF::Pitch] = XPLMFindDataRef(multi); + mdrefs[i][DREF_Pitch] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_phi", i); - mdrefs[i][DREF::Roll] = XPLMFindDataRef(multi); + mdrefs[i][DREF_Roll] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_psi", i); - mdrefs[i][DREF::HeadingTrue] = XPLMFindDataRef(multi); + mdrefs[i][DREF_HeadingTrue] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_gear_deploy", i); - mdrefs[i][DREF::GearDeploy] = XPLMFindDataRef(multi); + mdrefs[i][DREF_GearDeploy] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_flap_ratio", i); - mdrefs[i][DREF::FlapSetting] = XPLMFindDataRef(multi); // Can't set the actual flap setting on npc aircraft - mdrefs[i][DREF::FlapActual] = XPLMFindDataRef(multi); + mdrefs[i][DREF_FlapSetting] = XPLMFindDataRef(multi); // Can't set the actual flap setting on npc aircraft + mdrefs[i][DREF_FlapActual] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_flap_ratio2", i); - mdrefs[i][DREF::FlapActual2] = XPLMFindDataRef(multi); + mdrefs[i][DREF_FlapActual2] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_spoiler_ratio", i); - mdrefs[i][DREF::Spoiler] = XPLMFindDataRef(multi); + mdrefs[i][DREF_Spoiler] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_speedbrake_ratio", i); - mdrefs[i][DREF::BrakeSpeed] = XPLMFindDataRef(multi); + mdrefs[i][DREF_BrakeSpeed] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_slat_ratio", i); - mdrefs[i][DREF::Slats] = XPLMFindDataRef(multi); + mdrefs[i][DREF_Slats] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_wing_sweep", i); - mdrefs[i][DREF::Sweep] = XPLMFindDataRef(multi); + mdrefs[i][DREF_Sweep] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_throttle", i); - mdrefs[i][DREF::ThrottleActual] = XPLMFindDataRef(multi); + mdrefs[i][DREF_ThrottleActual] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_yolk_pitch", i); - mdrefs[i][DREF::YokePitch] = XPLMFindDataRef(multi); + mdrefs[i][DREF_YokePitch] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_yolk_roll", i); - mdrefs[i][DREF::YokeRoll] = XPLMFindDataRef(multi); + mdrefs[i][DREF_YokeRoll] = XPLMFindDataRef(multi); sprintf(multi, "sim/multiplayer/position/plane%i_yolk_yaw", i); - mdrefs[i][DREF::YokeHeading] = XPLMFindDataRef(multi); + mdrefs[i][DREF_YokeHeading] = XPLMFindDataRef(multi); } + + // Row 0: Frame Rates + // Row 1: Times + XPData[1][1] = DREF_TotalRuntime; + XPData[1][2] = DREF_TotalFlighttime; + XPData[1][3] = DREF_TimerElapsedtime; + // Row 2: Sim stats + // Row 3: Velocities + XPData[3][0] = DREF_IndicatedAirspeed; + XPData[3][2] = DREF_TrueAirspeed; + XPData[3][4] = DREF_GroundSpeed; + // Row 4: Mach, VVI, G-Loads + XPData[4][0] = DREF_MachNumber; + XPData[4][4] = DREF_GForceNormal; + XPData[4][5] = DREF_GForceAxial; + XPData[4][6] = DREF_GForceSide; + // Row 5: Atmosphere: Weather + XPData[5][0] = DREF_BarometerSealevelInHg; + XPData[5][1] = DREF_TemperaturSealevelC; + XPData[5][3] = DREF_WindSpeedKts; + // Row 6: Atmosphere: Aircraft + // Row 7: System Pressures + // Row 8: Joystick + XPData[8][0] = DREF_YokePitch; + XPData[8][1] = DREF_YokeRoll; + XPData[8][2] = DREF_YokeHeading; + // Row 9: Other Flight Controls + // Row 10: Art stab ail/elv/rud + // Row 11: Control Surfaces + XPData[11][0] = DREF_Elevator; + XPData[11][1] = DREF_Aileron; + XPData[11][2] = DREF_Rudder; + // Row 12: Wing Sweep/Trust Vec + // Row 13: trip/flap/slat/s-brakes + XPData[13][3] = DREF_FlapSetting; + XPData[13][4] = DREF_FlapActual; + // Row 14: Gear, Brakes + XPData[14][0] = DREF_GearDeploy; + XPData[14][1] = DREF_BrakeParking; + XPData[14][2] = DREF_BrakeLeft; + XPData[14][3] = DREF_BrakeRight; + XPData[14][7] = DREF_GearHandle; + // Row 15: MNR (Angular Moments) + XPData[15][0] = DREF_M; + XPData[15][1] = DREF_L; + XPData[15][2] = DREF_N; + // Row 16: PQR (Angular Velocities) + XPData[16][0] = DREF_QRad; + XPData[16][1] = DREF_PRad; + XPData[16][2] = DREF_RRad; + XPData[16][3] = DREF_Q; + XPData[16][4] = DREF_P; + XPData[16][5] = DREF_R; + // Row 17: Orientation: pitch, roll, yaw, heading + XPData[17][0] = DREF_Pitch; + XPData[17][1] = DREF_Roll; + XPData[17][2] = DREF_HeadingTrue; + XPData[17][3] = DREF_HeadingMag; + XPData[17][4] = DREF_Quaternion; + // Row 18: Orientation: alpha beta hpath vpath slip + XPData[18][0] = DREF_AngleOfAttack; + XPData[18][1] = DREF_Sideslip; + XPData[18][2] = DREF_HPath; + XPData[18][3] = DREF_VPath; + XPData[18][4] = DREF_Sideslip; + // Row 19: Mag Compass + XPData[19][0] = DREF_HeadingMag; + XPData[19][1] = DREF_MagneticVariation; + // Row 20: Global Position + XPData[20][0] = DREF_Latitude; + XPData[20][1] = DREF_Longitude; + XPData[20][2] = DREF_Elevation; + XPData[20][3] = DREF_AGL; + // Row 21: Local Position, Velocity + XPData[21][0] = DREF_LocalX; + XPData[21][1] = DREF_LocalY; + XPData[21][2] = DREF_LocalZ; + XPData[21][3] = DREF_LocalVX; + XPData[21][4] = DREF_LocalVY; + XPData[21][5] = DREF_LocalVZ; + // Row 22: All Planes: Lat + XPData[22][0] = DREF_Latitude; + XPData[22][1] = DREF_MP1Lat; + XPData[22][2] = DREF_MP2Lat; + XPData[22][3] = DREF_MP3Lat; + XPData[22][4] = DREF_MP4Lat; + XPData[22][5] = DREF_MP5Lat; + XPData[22][6] = DREF_MP6Lat; + XPData[22][7] = DREF_MP7Lat; + // Row 23: All Planes: Lon + XPData[23][0] = DREF_Longitude; + XPData[23][1] = DREF_MP1Lon; + XPData[23][2] = DREF_MP2Lon; + XPData[23][3] = DREF_MP3Lon; + XPData[23][4] = DREF_MP4Lon; + XPData[23][5] = DREF_MP5Lon; + XPData[23][6] = DREF_MP6Lon; + XPData[23][7] = DREF_MP7Lon; + // Row 22: All Planes: Alt + XPData[24][0] = DREF_AGL; + XPData[24][1] = DREF_MP1Alt; + XPData[24][2] = DREF_MP2Alt; + XPData[24][3] = DREF_MP3Alt; + XPData[24][4] = DREF_MP4Alt; + XPData[24][5] = DREF_MP5Alt; + XPData[24][6] = DREF_MP6Alt; + XPData[24][7] = DREF_MP7Alt; + // Row 25: Throttle Command + XPData[25][0] = DREF_ThrottleSet; + // Row 26: Throttle Actual + XPData[26][0] = DREF_ThrottleActual; } int DataManager::Get(string dref, float values[], int size) { XPLMDataRef& xdref = sdrefs[dref]; - if (xdref == nullptr) + if (xdref == NULL) { xdref = XPLMFindDataRef(dref.c_str()); } @@ -430,7 +527,7 @@ namespace XPC void DataManager::Set(string dref, float values[], int size) { XPLMDataRef& xdref = sdrefs[dref]; - if (xdref == nullptr) + if (xdref == NULL) { xdref = XPLMFindDataRef(dref.c_str()); } @@ -591,15 +688,15 @@ namespace XPC if (aircraft == 0) // Own aircraft { - Set(DREF::GearHandle, (int)gear); + Set(DREF_GearHandle, (int)gear); if (immediate) { - Set(DREF::GearDeploy, gearArray, 10); + Set(DREF_GearDeploy, gearArray, 10); } } else // Multiplayer aircraft { - Set(DREF::GearDeploy, gearArray, 10, aircraft); + Set(DREF_GearDeploy, gearArray, 10, aircraft); } } @@ -618,29 +715,29 @@ namespace XPC if (pos[0] < -997.9 && pos[0] > -999.1) { - pos[0] = (float)GetDouble(DREF::Latitude, aircraft); + pos[0] = (float)GetDouble(DREF_Latitude, aircraft); } if (pos[1] < -997.9 && pos[1] > -999.1) { - pos[1] = (float)GetDouble(DREF::Longitude, aircraft); + pos[1] = (float)GetDouble(DREF_Longitude, aircraft); } if (pos[2] < -997.9 && pos[2] > -999.1) { - pos[2] = (float)GetDouble(DREF::Elevation, aircraft); + pos[2] = (float)GetDouble(DREF_Elevation, aircraft); } double local[3]; XPLMWorldToLocal(pos[0], pos[1], pos[2], &local[0], &local[1], &local[2]); // If the sim is paused, setting global position won't update the // local position, so set them just in case. - Set(DREF::LocalX, local[0], aircraft); - Set(DREF::LocalY, local[1], aircraft); - Set(DREF::LocalZ, local[2], aircraft); + Set(DREF_LocalX, local[0], aircraft); + Set(DREF_LocalY, local[1], aircraft); + Set(DREF_LocalZ, local[2], aircraft); // If the sim is unpaused, this will override the above settings. // TODO: Are these setable when paused? Are these necessary? - Set(DREF::Latitude, (double)pos[0], aircraft); - Set(DREF::Longitude, (double)pos[1], aircraft); - Set(DREF::Elevation, (double)pos[2], aircraft); + Set(DREF_Latitude, (double)pos[0], aircraft); + Set(DREF_Longitude, (double)pos[1], aircraft); + Set(DREF_Elevation, (double)pos[2], aircraft); } void DataManager::SetOrientation(float orient[3], char aircraft) @@ -659,24 +756,24 @@ namespace XPC if (orient[0] < -997.9 && orient[0] > -999.1) { - orient[0] = GetFloat(DREF::Pitch, aircraft); + orient[0] = GetFloat(DREF_Pitch, aircraft); } if (orient[1] < -997.9 && orient[1] > -999.1) { - orient[1] = GetFloat(DREF::Roll, aircraft); + orient[1] = GetFloat(DREF_Roll, aircraft); } if (orient[2] < -997.9 && orient[2] > -999.1) { - orient[2] = GetFloat(DREF::HeadingTrue, aircraft); + orient[2] = GetFloat(DREF_HeadingTrue, aircraft); } // If the sim is paused, setting the quaternion won't update these values, // so we set them here just in case. This also covers multiplayer aircraft, // which we can't set the quaternion on. - Set(DREF::Pitch, orient[0], aircraft); - Set(DREF::Roll, orient[1], aircraft); - Set(DREF::HeadingTrue, orient[2], aircraft); + Set(DREF_Pitch, orient[0], aircraft); + Set(DREF_Roll, orient[1], aircraft); + Set(DREF_HeadingTrue, orient[2], aircraft); if (aircraft == 0) // Player aircraft { // Convert to Quaternions @@ -694,7 +791,7 @@ namespace XPC // If the sim is un-paused, this will overwrite the pitch/roll/yaw // values set above. - Set(DREF::Quaternion, q, 4); + Set(DREF_Quaternion, q, 4); } } @@ -715,7 +812,7 @@ namespace XPC value = (float)fmaxl(value, 0); value = (float)fminl(value, 1); - Set(DREF::FlapSetting, value); - Set(DREF::FlapActual, value); + Set(DREF_FlapSetting, value); + Set(DREF_FlapActual, value); } } \ No newline at end of file diff --git a/xpcPlugin/DataManager.h b/xpcPlugin/DataManager.h index 44e2b65..ca85d9a 100644 --- a/xpcPlugin/DataManager.h +++ b/xpcPlugin/DataManager.h @@ -8,131 +8,131 @@ namespace XPC { /// Represents named datarefs used by X-Plane Connect - enum class DREF : unsigned long + enum DREF { - None = 0, + DREF_None = 0, - Pause, - PauseAI, + DREF_Pause, + DREF_PauseAI, // Times - TotalRuntime = 100, - TotalFlighttime, - TimerElapsedtime, + DREF_TotalRuntime = 100, + DREF_TotalFlighttime, + DREF_TimerElapsedtime, // Velocities - IndicatedAirspeed = 300, - TrueAirspeed, - GroundSpeed, + DREF_IndicatedAirspeed = 300, + DREF_TrueAirspeed, + DREF_GroundSpeed, // Mach, VVI, G-loads - MachNumber = 400, - GForceNormal, - GForceAxial, - GForceSide, + DREF_MachNumber = 400, + DREF_GForceNormal, + DREF_GForceAxial, + DREF_GForceSide, // Atmosphere: Weather - BarometerSealevelInHg = 500, - TemperaturSealevelC, - WindSpeedKts, + DREF_BarometerSealevelInHg = 500, + DREF_TemperaturSealevelC, + DREF_WindSpeedKts, // Joystick - YokePitch = 800, - YokeRoll, - YokeHeading, + DREF_YokePitch = 800, + DREF_YokeRoll, + DREF_YokeHeading, // Control Surfaces - Elevator = 1100, - Aileron, - Rudder, + DREF_Elevator = 1100, + DREF_Aileron, + DREF_Rudder, // Flaps - FlapSetting = 1300, - FlapActual, + DREF_FlapSetting = 1300, + DREF_FlapActual, // Gear & Brakes - GearDeploy = 1400, - GearHandle, - BrakeParking, - BrakeLeft, - BrakeRight, + DREF_GearDeploy = 1400, + DREF_GearHandle, + DREF_BrakeParking, + DREF_BrakeLeft, + DREF_BrakeRight, // MNR (Angular Moments) - M = 1500, - L, - N, + DREF_M = 1500, + DREF_L, + DREF_N, //PQR (Angular Velocities) - QRad = 1600, - PRad, - RRad, - Q, - P, - R, + DREF_QRad = 1600, + DREF_PRad, + DREF_RRad, + DREF_Q, + DREF_P, + DREF_R, // Orientation: pitch, roll, yaw, heading - Pitch = 1700, - Roll, - HeadingTrue, - HeadingMag, - Quaternion, + DREF_Pitch = 1700, + DREF_Roll, + DREF_HeadingTrue, + DREF_HeadingMag, + DREF_Quaternion, // Orientation: alpha beta hpath vpath slip - AngleOfAttack = 1800, - Sideslip, - HPath, - VPath, + DREF_AngleOfAttack = 1800, + DREF_Sideslip, + DREF_HPath, + DREF_VPath, - MagneticVariation = 1901, + DREF_MagneticVariation = 1901, // Global Position - Latitude = 2000, - Longitude, - Elevation, - AGL, + DREF_Latitude = 2000, + DREF_Longitude, + DREF_Elevation, + DREF_AGL, // Local Postion & Velocity - LocalX = 2100, - LocalY, - LocalZ, - LocalVX, - LocalVY, - LocalVZ, + DREF_LocalX = 2100, + DREF_LocalY, + DREF_LocalZ, + DREF_LocalVX, + DREF_LocalVY, + DREF_LocalVZ, - ThrottleSet = 2200, - ThrottleActual = 2300, + DREF_ThrottleSet = 2200, + DREF_ThrottleActual = 2300, // Multiplayer Aircraft - FlapActual2, - Spoiler, - BrakeSpeed, - Sweep, - Slats, + DREF_FlapActual2, + DREF_Spoiler, + DREF_BrakeSpeed, + DREF_Sweep, + DREF_Slats, // Mulitplayer positon - MP1Lat, - MP2Lat, - MP3Lat, - MP4Lat, - MP5Lat, - MP6Lat, - MP7Lat, + DREF_MP1Lat, + DREF_MP2Lat, + DREF_MP3Lat, + DREF_MP4Lat, + DREF_MP5Lat, + DREF_MP6Lat, + DREF_MP7Lat, - MP1Lon, - MP2Lon, - MP3Lon, - MP4Lon, - MP5Lon, - MP6Lon, - MP7Lon, + DREF_MP1Lon, + DREF_MP2Lon, + DREF_MP3Lon, + DREF_MP4Lon, + DREF_MP5Lon, + DREF_MP6Lon, + DREF_MP7Lon, - MP1Alt, - MP2Alt, - MP3Alt, - MP4Alt, - MP5Alt, - MP6Alt, - MP7Alt, + DREF_MP1Alt, + DREF_MP2Alt, + DREF_MP3Alt, + DREF_MP4Alt, + DREF_MP5Alt, + DREF_MP6Alt, + DREF_MP7Alt, }; /// Marshals data between the plugin and X-Plane. diff --git a/xpcPlugin/DataMaps.cpp b/xpcPlugin/DataMaps.cpp index e0dc087..977194e 100644 --- a/xpcPlugin/DataMaps.cpp +++ b/xpcPlugin/DataMaps.cpp @@ -4,77 +4,5 @@ namespace XPC { - DREF XPData[134][8] - { - {}, // Row 0: Frame Rates - { // Row 1: Times - DREF::None, DREF::TotalRuntime, DREF::TotalFlighttime, DREF::TimerElapsedtime, - }, - {}, // Row 2: Sim stats - { // Row 3: Velocities - DREF::IndicatedAirspeed, DREF::None, DREF::TrueAirspeed, DREF::GroundSpeed - }, - { // Row 4: Mach, VVI, G-Loads - DREF::MachNumber, DREF::None, DREF::None, DREF::None, - DREF::GForceNormal, DREF::GForceAxial, DREF::GForceSide - }, - { // Row 5: Atmosphere: Weather - DREF::BarometerSealevelInHg, DREF::TemperaturSealevelC, DREF::None, DREF::WindSpeedKts - }, - {}, // Row 6: Atmosphere: Aircraft - {}, // Row 7: System Pressures - { // Row 8: Joystick - DREF::YokePitch, DREF::YokeRoll, DREF::YokeHeading - }, - {}, // Row 9: Other Flight Controls - {}, // Row 10: Art stab ail/elv/rud - { // Row 11: Control Surfaces - DREF::Elevator, DREF::Aileron, DREF::Rudder - }, - {}, // Row 12: Wing Sweep/Trust Vec - { // Row 13: trip/flap/slat/s-brakes - DREF::None, DREF::None, DREF::None, DREF::FlapSetting, DREF::FlapActual - }, - { // Row 14: Gear, Braks - DREF::GearDeploy, DREF::BrakeParking, DREF::BrakeLeft, DREF::BrakeRight, - DREF::None, DREF::None, DREF::None, - DREF::GearHandle - }, - { // Row 15: MNR (Angular Moments) - DREF::M, DREF::L, DREF::N - }, - { // Row 16: PQR (Angular Velocities) - DREF::QRad, DREF::PRad, DREF::RRad, DREF::Q, DREF::P, DREF::R - }, - { // Row 17: Orientation: pitch, roll, yaw, heading - DREF::Pitch, DREF::Roll, DREF::HeadingTrue, DREF::HeadingMag, DREF::Quaternion - }, - { // Row 18: Orientation: alpha beta hpath vpath slip - DREF::AngleOfAttack, DREF::Sideslip, DREF::HPath, DREF::VPath, DREF::Sideslip - }, - { // Row 19: Mag Compass - DREF::HeadingMag, DREF::MagneticVariation - }, - { // Row 20: Global Position - DREF::Latitude, DREF::Longitude, DREF::Elevation, DREF::AGL - }, - { // Row 21: Local Position, Velocity - DREF::LocalX, DREF::LocalY, DREF::LocalZ, DREF::LocalVX, DREF::LocalVY, DREF::LocalVZ - }, - { // Row 22: All Planes: Lat - DREF::Latitude, DREF::MP1Lat, DREF::MP2Lat, DREF::MP3Lat, DREF::MP4Lat, DREF::MP5Lat, DREF::MP6Lat, DREF::MP7Lat - }, - { // Row 23: All Planes: Lon - DREF::Longitude, DREF::MP1Lon, DREF::MP2Lon, DREF::MP3Lon, DREF::MP4Lon, DREF::MP5Lon, DREF::MP6Lon, DREF::MP7Lon - }, - { // Row 24: All Planes: Alt - DREF::AGL, DREF::MP1Alt, DREF::MP2Alt, DREF::MP3Alt, DREF::MP4Alt, DREF::MP5Alt, DREF::MP6Alt, DREF::MP7Alt - }, - { // Row 25: Throttle Command - DREF::ThrottleSet - }, - { // Row 26: Throttle Actual - DREF::ThrottleActual - } - }; + DREF XPData[134][8] = { DREF_None }; } \ No newline at end of file diff --git a/xpcPlugin/Message.cpp b/xpcPlugin/Message.cpp index 312231c..0fb081a 100644 --- a/xpcPlugin/Message.cpp +++ b/xpcPlugin/Message.cpp @@ -41,7 +41,7 @@ namespace XPC { if (size == 0) { - return nullptr; + return NULL; } return buffer; } diff --git a/xpcPlugin/MessageHandlers.cpp b/xpcPlugin/MessageHandlers.cpp index 7629aca..784ebee 100644 --- a/xpcPlugin/MessageHandlers.cpp +++ b/xpcPlugin/MessageHandlers.cpp @@ -11,43 +11,8 @@ namespace XPC { - std::unordered_map MessageHandlers::connections; - std::unordered_map MessageHandlers::handlers( - { - // Common messages - { "CONN", MessageHandlers::HandleConn }, - { "CTRL", MessageHandlers::HandleCtrl }, - { "DATA", MessageHandlers::HandleData }, - { "DREF", MessageHandlers::HandleDref }, - { "GETD", MessageHandlers::HandleGetD }, - { "POSI", MessageHandlers::HandlePosi }, - { "SIMU", MessageHandlers::HandleSimu }, - { "TEXT", MessageHandlers::HandleText }, - { "WYPT", MessageHandlers::HandleWypt }, - // Not implemented messages - { "VIEW", MessageHandlers::HandleUnknown }, - // X-Plane data messages - { "DSEL", MessageHandlers::HandleXPlaneData }, - { "USEL", MessageHandlers::HandleXPlaneData }, - { "DCOC", MessageHandlers::HandleXPlaneData }, - { "UCOC", MessageHandlers::HandleXPlaneData }, - { "MOUS", MessageHandlers::HandleXPlaneData }, - { "CHAR", MessageHandlers::HandleXPlaneData }, - { "MENU", MessageHandlers::HandleXPlaneData }, - { "SOUN", MessageHandlers::HandleXPlaneData }, - { "FAIL", MessageHandlers::HandleXPlaneData }, - { "RECO", MessageHandlers::HandleXPlaneData }, - { "PAPT", MessageHandlers::HandleXPlaneData }, - { "VEHN", MessageHandlers::HandleXPlaneData }, - { "VEH1", MessageHandlers::HandleXPlaneData }, - { "VEHA", MessageHandlers::HandleXPlaneData }, - { "GSET", MessageHandlers::HandleXPlaneData }, - { "OBJN", MessageHandlers::HandleXPlaneData }, - { "OBJL", MessageHandlers::HandleXPlaneData }, - { "GSET", MessageHandlers::HandleXPlaneData }, - { "ISET", MessageHandlers::HandleXPlaneData }, - { "BOAT", MessageHandlers::HandleXPlaneData }, - }); + std::map MessageHandlers::connections; + std::map MessageHandlers::handlers; std::string MessageHandlers::connectionKey; MessageHandlers::ConnectionInfo MessageHandlers::connection; @@ -60,6 +25,43 @@ namespace XPC void MessageHandlers::HandleMessage(Message& msg) { + if (handlers.size() == 0) + { + // Common messages + handlers.insert(std::make_pair("CONN", MessageHandlers::HandleConn)); + handlers.insert(std::make_pair("CTRL", MessageHandlers::HandleCtrl)); + handlers.insert(std::make_pair("DATA", MessageHandlers::HandleData)); + handlers.insert(std::make_pair("DREF", MessageHandlers::HandleDref)); + handlers.insert(std::make_pair("GETD", MessageHandlers::HandleGetD)); + handlers.insert(std::make_pair("POSI", MessageHandlers::HandlePosi)); + handlers.insert(std::make_pair("SIMU", MessageHandlers::HandleSimu)); + handlers.insert(std::make_pair("TEXT", MessageHandlers::HandleText)); + handlers.insert(std::make_pair("WYPT", MessageHandlers::HandleWypt)); + // Not implemented messages + handlers.insert(std::make_pair("VIEW", MessageHandlers::HandleUnknown)); + // X-Plane data messages + handlers.insert(std::make_pair("DSEL", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("USEL", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("DCOC", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("UCOC", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("MOUS", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("CHAR", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("MENU", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("SOUN", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("FAIL", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("RECO", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("PAPT", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("VEHN", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("VEH1", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("VEHA", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("GSET", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("OBJN", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("OBJL", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("GSET", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("ISET", MessageHandlers::HandleXPlaneData)); + handlers.insert(std::make_pair("BOAT", MessageHandlers::HandleXPlaneData)); + } + // Make sure we really have a message to handle. std::string head = msg.GetHead(); if (head == "") @@ -74,18 +76,16 @@ namespace XPC #if LOG_VERBOSITY > 4 Log::FormatLine("[MSGH] Handling message from %s", connectionKey.c_str()); #endif - auto conn = connections.find(connectionKey); + std::map::iterator conn = connections.find(connectionKey); if (conn == connections.end()) // New connection { - connection = MessageHandlers::ConnectionInfo - { - // If this is a new connection, that means we just added an elment - // to connections. As long as we never remove elements, the size of - // connections will serve as a unique id. - static_cast(connections.size()), - sourceaddr, - 0 - }; + connection = MessageHandlers::ConnectionInfo(); + // If this is a new connection, that means we just added an elment + // to connections. As long as we never remove elements, the size of + // connections will serve as a unique id. + connection.id = static_cast(connections.size()); + connection.addr = sourceaddr; + connection.getdCount = 0; connections[connectionKey] = connection; #if LOG_VERBOSITY > 2 Log::FormatLine("[MSGH] New connection. ID=%u, Remote=%s", connection.id, connectionKey.c_str()); @@ -102,7 +102,7 @@ namespace XPC // Check if there is a handler for this message type. If so, execute // that handler. Otherwise, execute the unknown message handler. - auto iter = handlers.find(head); + std::map::iterator iter = handlers.find(head); if (iter != handlers.end()) { MessageHandler handler = (*iter).second; @@ -197,11 +197,11 @@ namespace XPC thrArray[i] = thr; } - DataManager::Set(DREF::YokePitch, pitch, aircraft); - DataManager::Set(DREF::YokeRoll, roll, aircraft); - DataManager::Set(DREF::YokeHeading, yaw, aircraft); - DataManager::Set(DREF::ThrottleSet, thrArray, 8, aircraft); - DataManager::Set(DREF::ThrottleActual, thrArray, 8, aircraft); + DataManager::Set(DREF_YokePitch, pitch, aircraft); + DataManager::Set(DREF_YokeRoll, roll, aircraft); + DataManager::Set(DREF_YokeHeading, yaw, aircraft); + DataManager::Set(DREF_ThrottleSet, thrArray, 8, aircraft); + DataManager::Set(DREF_ThrottleActual, thrArray, 8, aircraft); if (aircraft == 0) { DataManager::Set("sim/flightmodel/engine/ENGN_thro_override", thrArray, 1); @@ -212,7 +212,7 @@ namespace XPC } if (flaps < -999.5 || flaps > -997.5) { - DataManager::Set(DREF::FlapSetting, flaps, aircraft); + DataManager::Set(DREF_FlapSetting, flaps, aircraft); } } @@ -269,9 +269,9 @@ namespace XPC { case 3: // Velocity { - float theta = DataManager::GetFloat(DREF::Pitch); - float alpha = savedAlpha != -998 ? savedAlpha : DataManager::GetFloat(DREF::AngleOfAttack); - float hpath = savedHPath != -998 ? savedHPath : DataManager::GetFloat(DREF::HPath); + float theta = DataManager::GetFloat(DREF_Pitch); + float alpha = savedAlpha != -998 ? savedAlpha : DataManager::GetFloat(DREF_AngleOfAttack); + float hpath = savedHPath != -998 ? savedHPath : DataManager::GetFloat(DREF_HPath); if (alpha != alpha || hpath != hpath) { #if LOG_VERBOSITY > 0 @@ -286,21 +286,19 @@ namespace XPC float v = values[i][ind[j]]; if (v != -998) { - DataManager::Set(DREF::LocalVX, v*cos((theta - alpha)*deg2rad)*sin(hpath*deg2rad)); - DataManager::Set(DREF::LocalVY, v*sin((theta - alpha)*deg2rad)); - DataManager::Set(DREF::LocalVZ, -v*cos((theta - alpha)*deg2rad)*cos(hpath*deg2rad)); + DataManager::Set(DREF_LocalVX, v*cos((theta - alpha)*deg2rad)*sin(hpath*deg2rad)); + DataManager::Set(DREF_LocalVY, v*sin((theta - alpha)*deg2rad)); + DataManager::Set(DREF_LocalVZ, -v*cos((theta - alpha)*deg2rad)*cos(hpath*deg2rad)); } } break; } case 17: // Orientation { - float orient[3] - { - values[i][1], - values[i][2], - values[i][3] - }; + float orient[3]; + orient[0] = values[i][1]; + orient[1] = values[i][2]; + orient[2] = values[i][3]; DataManager::SetOrientation(orient); break; } @@ -325,12 +323,10 @@ namespace XPC } case 20: // Position { - float pos[3] - { - values[i][2], - values[i][3], - values[i][4] - }; + float pos[3]; + pos[0] = values[i][2]; + pos[1] = values[i][3]; + pos[2] = values[i][4]; DataManager::SetPosition(pos); break; } @@ -348,7 +344,7 @@ namespace XPC { thr[j] = values[i][1]; } - DataManager::Set(DREF::ThrottleSet, thr, 8); + DataManager::Set(DREF_ThrottleSet, thr, 8); break; } default: // Non-Special dataRefs @@ -368,7 +364,7 @@ namespace XPC } DREF dref = XPData[dataRef][j]; - if (dref == DREF::None) + if (dref == DREF_None) { // TODO: Send single line instead! HandleXPlaneData(msg); @@ -477,11 +473,11 @@ namespace XPC { // Enable AI for the aircraft we are setting float ai[20]; - std::size_t result = DataManager::GetFloatArray(DREF::PauseAI, ai, 20); + std::size_t result = DataManager::GetFloatArray(DREF_PauseAI, ai, 20); if (result == 20) // Only set values if they were retrieved successfully. { ai[aircraft] = 1; - DataManager::Set(DREF::PauseAI, ai, 0, 20); + DataManager::Set(DREF_PauseAI, ai, 0, 20); } } @@ -508,7 +504,7 @@ namespace XPC { value[i] = buffer[5]; } - DataManager::Set(DREF::Pause, value, 20); + DataManager::Set(DREF_Pause, value, 20); #if LOG_VERBOSITY > 2 if (buffer[5] == 0) diff --git a/xpcPlugin/MessageHandlers.h b/xpcPlugin/MessageHandlers.h index 749c00c..4881dee 100644 --- a/xpcPlugin/MessageHandlers.h +++ b/xpcPlugin/MessageHandlers.h @@ -5,7 +5,7 @@ #include "Message.h" #include -#include +#include namespace XPC { @@ -57,8 +57,8 @@ namespace XPC std::string getdRequest[255]; } ConnectionInfo; - static std::unordered_map connections; - static std::unordered_map handlers; + static std::map connections; + static std::map handlers; static std::string connectionKey; // The current connection ip:port string static ConnectionInfo connection; // The current connection record static UDPSocket* sock; // Outgoing network socket diff --git a/xpcPlugin/UDPSocket.cpp b/xpcPlugin/UDPSocket.cpp index da65e2b..ed4710d 100644 --- a/xpcPlugin/UDPSocket.cpp +++ b/xpcPlugin/UDPSocket.cpp @@ -4,6 +4,7 @@ #include "UDPSocket.h" #include +#include namespace XPC { @@ -163,7 +164,7 @@ namespace XPC inet_ntop(AF_INET, &sin->sin_addr, ip, INET6_ADDRSTRLEN); int len = strnlen(ip, INET6_ADDRSTRLEN); ip[len++] = ':'; - sprintf(ip + len, "%u", ntohs((*sin).sin_port)); + std::sprintf(ip + len, "%u", ntohs((*sin).sin_port)); break; } case AF_INET6: @@ -172,7 +173,7 @@ namespace XPC inet_ntop(AF_INET6, &sin->sin6_addr, ip, INET6_ADDRSTRLEN); int len = strnlen(ip, INET6_ADDRSTRLEN); ip[len++] = ':'; - sprintf(ip + len, "%u", ntohs((*sin).sin6_port)); + std::sprintf(ip + len, "%u", ntohs((*sin).sin6_port)); break; } default: diff --git a/xpcPlugin/XPCPlugin.cpp b/xpcPlugin/XPCPlugin.cpp index d8ff645..3f00db3 100755 --- a/xpcPlugin/XPCPlugin.cpp +++ b/xpcPlugin/XPCPlugin.cpp @@ -73,7 +73,7 @@ #define RECVPORT 49009 // Port that the plugin receives commands on #define OPS_PER_CYCLE 20 // Max Number of operations per cycle -XPC::UDPSocket* sock = nullptr; +XPC::UDPSocket* sock = NULL; double start,lap; static double timeConvert = 0.0; @@ -125,7 +125,7 @@ PLUGIN_API void XPluginDisable(void) { // Close sockets delete sock; - sock = nullptr; + sock = NULL; // Stop rendering messages to screen. XPC::Drawing::ClearMessage();