Skip to content

Commit

Permalink
[WASimClient] Use local Key Event ID mapping lookup instead of remote…
Browse files Browse the repository at this point in the history
… query; Requires MSFS 2024 SDK installed; Clean up includes.
  • Loading branch information
mpaperno committed Nov 28, 2024
1 parent caad3aa commit e460925
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
indent_style=tab
indent_size = 2
insert_final_newline=true
cpp_include_cleanup_excluded_files = MSFS_EventsEnum.h
20 changes: 15 additions & 5 deletions src/WASimClient/WASimClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ prior written authorization from the authors.

#include <chrono>
#include <condition_variable>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <filesystem>
#include <fstream>
#include <future>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
Expand All @@ -38,6 +35,7 @@ prior written authorization from the authors.
#include <string>
#include <sstream>
#include <thread>
#include <unordered_map>

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
Expand All @@ -46,11 +44,13 @@ prior written authorization from the authors.
#define LOGFAULT_THREAD_NAME WSMCMND_CLIENT_NAME

#include "client/WASimClient.h"
//#include "private/wasimclient_p.h"
#include "utilities.h"
#include "SimConnectHelper.h"
#include "inipp.h"

#include "MSFS_EventsEnum.h" // from MSFS2024_SDK, for key_events.h
#include "key_events.h"

namespace WASimCommander::Client
{

Expand Down Expand Up @@ -2004,6 +2004,16 @@ HRESULT WASimClient::list(LookupItemType itemsType)

HRESULT WASimClient::lookup(LookupItemType itemType, const std::string &itemName, int32_t *piResult)
{
// Short-circuit Key Event ID lookups from local source
if (itemType == LookupItemType::KeyEventId) {
const int32_t keyId = Utilities::getKeyEventId(itemName);
if (keyId < 0)
LOG_DBG << "Key Event named " << quoted(itemName) << " was not found in local lookup table.";
else if (!!piResult)
*piResult = keyId;
return keyId < 0 ? E_FAIL : S_OK;
}

if (itemName.length() >= STRSZ_CMD) {
LOG_ERR << "Item name length " << itemName.length() << " is greater then maximum size of " << STRSZ_CMD-1 << " bytes.";
return E_INVALIDARG;
Expand Down
10 changes: 5 additions & 5 deletions src/WASimClient/WASimClient.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir);$(SolutionDir)\shared;$(MSFS_SDK)\SimConnect SDK\include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir);$(SolutionDir)\shared;$(MSFS_SDK)SimConnect SDK\include;$(MSFS2024_SDK)WASM\include\MSFS\Types;$(IncludePath)</IncludePath>
<LibraryPath>$(MSFS_SDK)\SimConnect SDK\lib\static;$(LibraryPath)</LibraryPath>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
<CopyLocalProjectReference>true</CopyLocalProjectReference>
<TargetName>$(ProjectName)_d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir);$(SolutionDir)\shared;$(MSFS_SDK)\SimConnect SDK\include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir);$(SolutionDir)\shared;$(MSFS_SDK)SimConnect SDK\include;$(MSFS2024_SDK)WASM\include\MSFS\Types;$(IncludePath)</IncludePath>
<LibraryPath>$(MSFS_SDK)\SimConnect SDK\lib\static;$(LibraryPath)</LibraryPath>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
<CopyLocalProjectReference>true</CopyLocalProjectReference>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-DLL|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir);$(SolutionDir)\shared;$(MSFS_SDK)\SimConnect SDK\include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir);$(SolutionDir)\shared;$(MSFS_SDK)SimConnect SDK\include;$(MSFS2024_SDK)WASM\include\MSFS\Types;$(IncludePath)</IncludePath>
<LibraryPath>$(MSFS_SDK)\SimConnect SDK\lib\static;$(LibraryPath)</LibraryPath>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
<CopyLocalProjectReference>true</CopyLocalProjectReference>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-DLL|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir);$(SolutionDir)\shared;$(MSFS_SDK)\SimConnect SDK\include;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir);$(SolutionDir)\shared;$(MSFS_SDK)SimConnect SDK\include;$(MSFS2024_SDK)WASM\include\MSFS\Types;$(IncludePath)</IncludePath>
<LibraryPath>$(MSFS_SDK)\SimConnect SDK\lib\static;$(LibraryPath)</LibraryPath>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
<CopyLocalProjectReference>true</CopyLocalProjectReference>
Expand Down Expand Up @@ -252,10 +252,10 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\client\enums.h" />
<ClInclude Include="..\include\client\enums_impl.h" />
<ClInclude Include="..\include\client\exports.h" />
<ClInclude Include="..\include\client\structs.h" />
<ClInclude Include="..\include\client\WASimClient.h" />
<ClInclude Include="..\include\enums.h" />
<ClInclude Include="..\include\enums_impl.h" />
<ClInclude Include="..\include\global.h" />
<ClInclude Include="..\include\WASimCommander.h" />
Expand Down

0 comments on commit e460925

Please sign in to comment.