Skip to content

Commit

Permalink
Merge pull request #30 from TwinFan/next
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
TwinFan authored Dec 23, 2020
2 parents 162220f + 9662265 commit 6567f79
Show file tree
Hide file tree
Showing 141 changed files with 4,136 additions and 1,846 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.localized
.image
.vs/
.vscode/

# Build directories
build/
Expand Down
13 changes: 13 additions & 0 deletions XPMP2-Remote/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ void RemoteAC::Update (const XPMP2::RemoteAcDetailTy& _acDetails)
drawInfo.heading = _acDetails.GetHeading();
drawInfo.roll = _acDetails.GetRoll();
aiPrio = _acDetails.aiPrio;

// Info texts
std::memset(&acInfoTexts, 0, sizeof(acInfoTexts));
#define memcpy_min(to,from) std::memcpy(to,from,std::min(sizeof(from),sizeof(to)))
memcpy_min(acInfoTexts.tailNum, _acDetails.tailNum);
memcpy_min(acInfoTexts.icaoAcType, _acDetails.icaoType);
memcpy_min(acInfoTexts.manufacturer, _acDetails.manufacturer);
memcpy_min(acInfoTexts.model, _acDetails.model);
memcpy_min(acInfoTexts.icaoAirline, _acDetails.icaoOp);
memcpy_min(acInfoTexts.airline, _acDetails.airline);
memcpy_min(acInfoTexts.flightNum, _acDetails.flightNum);
memcpy_min(acInfoTexts.aptFrom, _acDetails.aptFrom);
memcpy_min(acInfoTexts.aptTo, _acDetails.aptTo);

// Don't render local planes (the local plugin does already),
// or if explicitely instructed so by the sender
Expand Down
55 changes: 34 additions & 21 deletions XPMP2-Remote/XPMP2-Remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,29 @@ int CBIntPrefsFunc (const char *, [[maybe_unused]] const char * item, int defaul
}

//
// MARK: Menu functionality
// MARK: Menu / Command functionality
//

XPLMMenuID hMenu = nullptr; ///< menu id of our plugin's menu
XPLMMenuID hSenders = nullptr; ///< menu id of the Senders submenu
int numSendersInMenu = 0; ///< how many lines to we currently server in the menu?

// menu indexes, also serving as menu item references
// menu indexes
constexpr std::uintptr_t MENU_ACTIVE = 0;
constexpr std::uintptr_t MENU_TCAS = 1;
constexpr std::uintptr_t MENU_SENDER = 2;

/// Command definition per menu item
struct CmdMenuDefTy {
const char* cmdName = nullptr; ///< command's name
const char* menuName = nullptr; ///< (initial) menu item's name
const char* description = nullptr; ///< human-readable command description
XPLMCommandRef hCmd = nullptr; ///< command reference assigned by X-Plane
} CMD_MENU_DEF[2] = {
{ "XPMP2-Remote/Activate", "Active", "Toggle if Remote Client is active" },
{ "XPMP2-Remote/TCAS", "TCAS Control", "Toggle if Remote Client shall have TCAS control" },
};

/// Sets all menu checkmarks according to current status
void MenuUpdateCheckmarks ()
{
Expand Down Expand Up @@ -174,32 +185,31 @@ void MenuUpdateSenders ()


/// Callback function for menu
void MenuCallback (void* /*inMenuRef*/, void* inItemRef)
int CmdCallback (XPLMCommandRef cmdRef, XPLMCommandPhase inPhase, void*)
{
// entry point into plugin...catch exceptions latest here
try {
switch (reinterpret_cast<std::uintptr_t>(inItemRef))
{
// Toggle activation of plugin
case MENU_ACTIVE:
if (inPhase == xplm_CommandBegin) {
if (cmdRef == CMD_MENU_DEF[0].hCmd) {
// Toggle activation of plugin
ClientToggleActive();
break;

// Toggle TCAS/AI status
case MENU_TCAS:
}
else if (cmdRef == CMD_MENU_DEF[1].hCmd) {
// Toggle TCAS/AI status
if (XPMPHasControlOfAIAircraft())
ClientReleaseAI();
else
ClientTryGetAI();
break;
}

// Update check marks...things might have changed
MenuUpdateCheckmarks();
}

// Update check marks...things might have changed
MenuUpdateCheckmarks();
}
catch (const std::exception& e) {
LOG_MSG(logFATAL, ERR_EXCEPTION, e.what());
}
return 1;
}

//
Expand Down Expand Up @@ -252,7 +262,7 @@ PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc)

LOG_MSG(logMSG, "%s %.2f starting up...", REMOTE_CLIENT_NAME, REMOTE_CLIENT_VER);

std::strcpy(outName, REMOTE_CLIENT_NAME);
std::snprintf(outName, 255, "%s %.2f", REMOTE_CLIENT_NAME, REMOTE_CLIENT_VER);
std::strcpy(outSig, XPMP2::REMOTE_SIGNATURE);
std::strcpy(outDesc, "Remote Client displaying traffic generated by XPMP2-based plugins on the network");

Expand Down Expand Up @@ -291,7 +301,7 @@ PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc)

// Create the menu for the plugin
int my_slot = XPLMAppendMenuItem(XPLMFindPluginsMenu(), REMOTE_CLIENT_NAME, NULL, 0);
hMenu = XPLMCreateMenu(REMOTE_CLIENT_NAME, XPLMFindPluginsMenu(), my_slot, MenuCallback, NULL);
hMenu = XPLMCreateMenu(REMOTE_CLIENT_NAME, XPLMFindPluginsMenu(), my_slot, NULL, NULL);

// No CSL models installed?
if (XPMPGetNumberOfInstalledModels() <= 0) {
Expand All @@ -302,13 +312,16 @@ PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc)
return 1;
}

// Define "proper" menu
XPLMAppendMenuItem(hMenu, "Active", (void*)MENU_ACTIVE, 0);
XPLMAppendMenuItem(hMenu, "TCAS Control", (void*)MENU_TCAS, 0);
// Define "proper" command and menu items
for (CmdMenuDefTy& cmdDef: CMD_MENU_DEF) {
cmdDef.hCmd = XPLMCreateCommand(cmdDef.cmdName, cmdDef.description);
XPLMRegisterCommandHandler(cmdDef.hCmd, CmdCallback, 1, NULL);
XPLMAppendMenuItemWithCommand(hMenu, cmdDef.menuName, cmdDef.hCmd);
}

// The Senders submenu lists connected plugins with IP address and number of aircraft
XPLMAppendMenuItem(hMenu, "Senders", (void*)MENU_SENDER, 0);
hSenders = XPLMCreateMenu("Senders", hMenu, MENU_SENDER, MenuCallback, (void*)MENU_SENDER);
hSenders = XPLMCreateMenu("Senders", hMenu, MENU_SENDER, NULL, NULL);
XPLMAppendMenuItem(hSenders, "(none)", (void*)MENU_SENDER, 0);

MenuUpdateCheckmarks();
Expand Down
11 changes: 10 additions & 1 deletion XPMP2-Remote/XPMP2-Remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include <memory>
#include <atomic>
#include <mutex>
#include <algorithm>

// X-Plane SDK
#include "XPLMDataAccess.h"
Expand All @@ -93,14 +94,22 @@
#include "Utilities.h"
#include "Client.h"

// Windows: I prefer the proper SDK variants of min and max
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif

//
// MARK: Constants
//

constexpr const char* REMOTE_CLIENT_NAME = "XPMP2 Remote Client"; ///< Plugin name
constexpr const char* REMOTE_CLIENT_LOG = "XPMP2_RC"; ///< ID used in own log entries
constexpr const char* REMOTE_CLIENT_LOG2 = "RC"; ///< Short ID used in XPMP2 log entries
constexpr float REMOTE_CLIENT_VER = 1.00f;
constexpr float REMOTE_CLIENT_VER = 1.10f;

//
// MARK: Globals
Expand Down
26 changes: 26 additions & 0 deletions XPMP2-Remote/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,32 @@ <h3>Resulting Directory Structure</h3>

<h1>Release Notes</h1>

<h2>v1.1</h2>

<h3>v1.10</h3>

<P>For updating coming from v1.00
<ul>
<li>copy <code>lin|mac|win_x64/XPMP2-Remote.xpl</code>.
</ul>
</p>

<P>Change log:</P>

<ul>
<li>ADDED <a href="https://github.com/TwinFan/XPMP2/issues/28">#28</a>
commands <code>XPMP2-Remote/Activate</code> and
<code>XPMP2-Remote/TCAS</code> for menu items
<i>Activate</i> and <i>TCAS Control</i>
to bind keyboard shortcuts to them or trigger them via CMND network message.</li>
<li>ADDED <a href="https://github.com/TwinFan/XPMP2/issues/26">#26</a> and
<a href="https://github.com/TwinFan/XPMP2/issues/27">#27</a>
remote support for the set of
<a href="https://twinfan.github.io/XPMP2/SharedDataRefs.html">textual shared dataRefs</a>.</li>
<li>ADDED <a href="https://github.com/TwinFan/XPMP2/issues/29">#29</a>
signature and notarization to the Mac version.</li>
</ul>

<h2>v1.0</h2>

<h3>v1.00</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ class Aircraft {

private:
bool bDestroyInst = false; ///< Instance to be destroyed in next flight loop callback?

#if defined(DEBUG) || defined(DEBUG_CTD_DOMOVE)
/// @brief Number of dataRefs at the moment we call XPLMInstanceSetPosition
/// @see https://github.com/TwinFan/XPMP2/issues/23
/// @note Temporary validation to track down why in some rare cases X-Plane crashes later in the XPLMInstanceSetPosition call
size_t numDataRefsDuringCreateInstance = 0;
#endif
public:
/// @brief Constructor creates a new aircraft object, which will be managed and displayed
/// @exception XPMP2::XPMP2Error Mode S id invalid or duplicate, no model found during model matching
Expand Down Expand Up @@ -351,6 +356,9 @@ class Aircraft {
/// Is this plane to be rendered?
bool IsRendered () const { return bRender && IsVisible(); }

/// Are instances created for this aircraft?
bool IsInstanciated () const { return !listInst.empty(); }

/// Distance to camera [m]
float GetCameraDist () const { return camDist; }
/// Bearing from camera [°]
Expand Down
19 changes: 14 additions & 5 deletions XPMP2-Sample/lib/XPMP2.framework/Versions/1.0/Headers/XPMPRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct RemoteMsgSettingsTy : public RemoteMsgBaseTy {
//

/// A/C detail message version number
constexpr std::uint8_t RMT_VER_AC_DETAIL = 0;
constexpr std::uint8_t RMT_VER_AC_DETAIL = 1;
/// A/C details, packed into an array message
struct RemoteAcDetailTy {
std::uint32_t modeS_id; ///< plane's unique id at the sender side (might differ remotely in case of duplicates)
Expand All @@ -199,8 +199,17 @@ struct RemoteAcDetailTy {
bool bValid : 1; ///< is this object valid? (Will be reset in case of exceptions)
bool bVisible : 1; ///< Shall this plane be drawn at the moment?
bool bRender : 1; ///< Shall the CSL model be drawn in 3D world?

std::uint8_t filler[3]; ///< yet unused

// selectively taken from XPMPInfoTexts_t and packed:
char tailNum[10]; ///< registration, tail number
char manufacturer[40]; ///< a/c manufacturer, human readable
char model[40]; ///< a/c model, human readable
char airline[40]; ///< airline, human readable
char flightNum [10]; ///< flight number
char aptFrom [5]; ///< Origin airport (ICAO)
char aptTo [5]; ///< Destination airport (ICAO)

std::uint8_t filler[5]; ///< yet unused

///< Array of _packed_ dataRef values for CSL model animation
std::uint8_t v[XPMP2::V_COUNT]; // 42
Expand Down Expand Up @@ -381,8 +390,8 @@ struct RemoteMsgAcRemoveTy : public RemoteMsgBaseTy {
// A few static validations just to make sure that no compiler fiddles with my network message layout.
static_assert(sizeof(RemoteMsgBaseTy) == 8, "RemoteMsgBaseTy doesn't have expected size");
static_assert(sizeof(RemoteMsgSettingsTy) == 40, "RemoteMsgSettingsTy doesn't have expected size");
static_assert(sizeof(RemoteAcDetailTy) == 94+42, "RemoteAcDetailTy doesn't have expected size");
static_assert(sizeof(RemoteMsgAcDetailTy) == 102+42, "RemoteMsgAcDetailTy doesn't have expected size");
static_assert(sizeof(RemoteAcDetailTy) == 246+42, "RemoteAcDetailTy doesn't have expected size");
static_assert(sizeof(RemoteMsgAcDetailTy) == 254+42, "RemoteMsgAcDetailTy doesn't have expected size");
static_assert(sizeof(RemoteAcPosUpdateTy) == 20, "RemoteAcPosUpdateTy doesn't have expected size");
static_assert(sizeof(RemoteMsgAcPosUpdateTy)== 28, "RemoteMsgAcPosUpdateTy doesn't have expected size");
static_assert(sizeof(RemoteAcAnimTy) == 8, "RemoteAcAnimTy doesn't have expected size");
Expand Down
36 changes: 30 additions & 6 deletions XPMP2-Sample/lib/XPMP2.framework/Versions/1.0/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,46 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>19H114</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<string>XPMP2</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<string>com.twinfan.XPMP2</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<string>XPMP2</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>1.0</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>12C33</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>11.1</string>
<key>DTSDKBuild</key>
<string>20C63</string>
<key>DTSDKName</key>
<string>macosx11.1</string>
<key>DTXcode</key>
<string>1230</string>
<key>DTXcodeBuild</key>
<string>12C33</string>
<key>LSMinimumSystemVersion</key>
<string>10.12</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 B. Hoppe. All rights reserved.</string>
</dict>
Expand Down
Binary file modified XPMP2-Sample/lib/XPMP2.framework/Versions/1.0/XPMP2
Binary file not shown.
Binary file modified XPMP2-Sample/lib/XPMP2.lib
Binary file not shown.
Binary file modified XPMP2-Sample/lib/libXPMP2.a
Binary file not shown.
6 changes: 6 additions & 0 deletions XPMP2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,13 @@
buildSettings = {
CLANG_ENABLE_MODULES = NO;
CLANG_ENABLE_OBJC_ARC = NO;
CODE_SIGN_IDENTITY = "Developer ID Application";
DEFINES_MODULE = NO;
DEPLOYMENT_LOCATION = YES;
DSTROOT = "$(XPLANE11_ROOT)/Resources/plugins/$(TARGET_NAME)";
DYLIB_COMPATIBILITY_VERSION = "";
DYLIB_CURRENT_VERSION = "";
ENABLE_HARDENED_RUNTIME = YES;
EXECUTABLE_EXTENSION = xpl;
EXECUTABLE_PREFIX = "";
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -794,6 +796,7 @@
INFOPLIST_FILE = "";
INSTALL_PATH = mac_x64;
MACH_O_TYPE = mh_bundle;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
OTHER_LDFLAGS = (
"$(OTHER_LDFLAGS)",
"-Wl,-exported_symbol",
Expand All @@ -817,11 +820,13 @@
buildSettings = {
CLANG_ENABLE_MODULES = NO;
CLANG_ENABLE_OBJC_ARC = NO;
CODE_SIGN_IDENTITY = "Developer ID Application";
DEFINES_MODULE = NO;
DEPLOYMENT_LOCATION = YES;
DSTROOT = "$(XPLANE11_ROOT)/Resources/plugins/$(TARGET_NAME)";
DYLIB_COMPATIBILITY_VERSION = "";
DYLIB_CURRENT_VERSION = "";
ENABLE_HARDENED_RUNTIME = YES;
EXECUTABLE_EXTENSION = xpl;
EXECUTABLE_PREFIX = "";
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -835,6 +840,7 @@
INFOPLIST_FILE = "";
INSTALL_PATH = mac_x64;
MACH_O_TYPE = mh_bundle;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
OTHER_LDFLAGS = (
"$(OTHER_LDFLAGS)",
"-Wl,-exported_symbol",
Expand Down
11 changes: 11 additions & 0 deletions docs/SharedDataRefs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ of type `xplmType_Data` as suggested by FSTramp.
This information is offered to 3rd party plugins,
which want to show (information of) AI planes like camera or map plugins.

[DRE](https://developer.x-plane.com/tools/datarefeditor/) and
[DRT](https://forums.x-plane.org/index.php?/forums/topic/82960-datareftool-is-an-improved-datarefeditor-open-source-better-search-change-detection/)
are informed about these dataRef names as soon as the first aircraft
is created. So you can use either to have a peek.

## Information offered by XPMP2-based Plugin

The names of the shared dataRefs follow the naming conventions known
Expand All @@ -32,6 +37,12 @@ then fill the appropriate field in the `XPMP2::Aircraft::acInfoTexts` structure.
`plane#_flightnum` | `flightNum` | Flight number
`plane#_apt_from` | `aptFrom` | Origin airport
`plane#_apt_to` | `aptTo` | Destination airport
`plane#_cslModel` | n/a | CSL Model name *)

*) `_cslModel` differs from the others in that it is _not_ related to live flight
information but to the way the plane is rendered by the XPMP2-based plugin.
It returns the CSL model used as returned by `XPMP2::Aircraft::GetModelName()`,
that is: last folder name plus model id.

## Usage by 3rd-Party Plugins

Expand Down
Loading

0 comments on commit 6567f79

Please sign in to comment.