Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
Write-Error "InputWeave.GameInput 套件 SHA256 不符。Expected=$expected Actual=$actual"
}

$expectedCommit = "89b148669ffe58d9927495ed0d89f9997bf4962a"
$expectedCommit = "da4ff730a1d52a8f4d21d43aba7408c59b50a7a2"
$inspectDir = Join-Path $env:RUNNER_TEMP "inputweave-gameinput-package"
if (Test-Path $inspectDir) {
Remove-Item -LiteralPath $inspectDir -Recurse -Force
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
Write-Error "InputWeave.GameInput 套件 SHA256 不符。Expected=$expected Actual=$actual"
}

$expectedCommit = "89b148669ffe58d9927495ed0d89f9997bf4962a"
$expectedCommit = "da4ff730a1d52a8f4d21d43aba7408c59b50a7a2"
$inspectDir = Join-Path $env:RUNNER_TEMP "inputweave-gameinput-package"
if (Test-Path $inspectDir) {
Remove-Item -LiteralPath $inspectDir -Recurse -Force
Expand Down Expand Up @@ -255,13 +255,13 @@ jobs:
Add-Content -Path $noticePath -Encoding utf8 -Value '## InputWeave.GameInput'
Add-Content -Path $noticePath -Encoding utf8 -Value ''
Add-Content -Path $noticePath -Encoding utf8 -Value '- 套件:InputWeave.GameInput 0.0.1'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 來源:https://github.com/rubujo/InputWeave.GameInput/tree/89b148669ffe58d9927495ed0d89f9997bf4962a'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 來源:https://github.com/rubujo/InputWeave.GameInput/tree/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 作者:https://github.com/rubujo'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 貢獻者:https://github.com/rubujo/InputWeave.GameInput/graphs/contributors'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 封裝來源:https://github.com/rubujo/InputWeave.GameInput/commit/89b148669ffe58d9927495ed0d89f9997bf4962a'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 封裝來源:https://github.com/rubujo/InputWeave.GameInput/commit/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 套件檔案:eng/nuget/InputWeave.GameInput.0.0.1.nupkg'
Add-Content -Path $noticePath -Encoding utf8 -Value '- SHA256: 3342051977f6f1b91f2a18acfc224456320264dd67633ed4bc41c8188c9fcdb7'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 授權:Creative Commons CC0 1.0 Universal(SPDX:CC0-1.0);詳見本 Licenses 目錄中的 InputWeave.GameInput_LICENSE.txt 與 https://github.com/rubujo/InputWeave.GameInput/blob/89b148669ffe58d9927495ed0d89f9997bf4962a/LICENSE。'
Add-Content -Path $noticePath -Encoding utf8 -Value '- SHA256: 41aca5564e443497179313e02c0b1365d040386fcb1acc2cd106e1799253ce0b'
Add-Content -Path $noticePath -Encoding utf8 -Value '- 授權:Creative Commons CC0 1.0 Universal(SPDX:CC0-1.0);詳見本 Licenses 目錄中的 InputWeave.GameInput_LICENSE.txt 與 https://github.com/rubujo/InputWeave.GameInput/blob/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2/LICENSE。'

- name: 產生執行檔的雜湊值(SHA256)
shell: pwsh
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ Remove-Item Env:INPUTBOX_RUN_UI_TESTS -ErrorAction SilentlyContinue

- [.NET Runtime](https://github.com/dotnet/runtime):由 [Microsoft](https://github.com/microsoft) 及其 [貢獻者](https://github.com/dotnet/runtime/graphs/contributors) 開發並採用 [**MIT License**](https://github.com/dotnet/runtime/blob/main/LICENSE.TXT) 授權,作為本應用程式之底層執行環境,相關第三方聲明請參閱 [**THIRD-PARTY-NOTICES**](https://github.com/dotnet/runtime/blob/main/THIRD-PARTY-NOTICES.TXT)。
- [Windows Forms(WinForms)](https://github.com/dotnet/winforms):由 [Microsoft](https://github.com/microsoft) 及其 [貢獻者](https://github.com/dotnet/winforms/graphs/contributors) 開發並採用 [**MIT License**](https://github.com/dotnet/winforms/blob/main/LICENSE.TXT) 授權,提供桌面視窗圖形介面基礎架構,相關第三方聲明請參閱 [**THIRD-PARTY-NOTICES**](https://github.com/dotnet/winforms/blob/main/THIRD-PARTY-NOTICES.TXT)。
- [InputWeave.GameInput 0.0.1](https://github.com/rubujo/InputWeave.GameInput/tree/89b148669ffe58d9927495ed0d89f9997bf4962a):由 [rubujo](https://github.com/rubujo) 及其 [貢獻者](https://github.com/rubujo/InputWeave.GameInput/graphs/contributors) 開發並採用 [**CC0 1.0 Universal**](https://github.com/rubujo/InputWeave.GameInput/blob/89b148669ffe58d9927495ed0d89f9997bf4962a/LICENSE) 授權,提供 GameInput 執行階段、用戶端、裝置、讀取狀態與震動控制介面。套件固定於本儲存庫的 NuGet 來源 `eng/nuget/InputWeave.GameInput.0.0.1.nupkg`,封裝來源為 [`89b148669ffe58d9927495ed0d89f9997bf4962a`](https://github.com/rubujo/InputWeave.GameInput/commit/89b148669ffe58d9927495ed0d89f9997bf4962a),套件 SHA256 為 `3342051977f6f1b91f2a18acfc224456320264dd67633ed4bc41c8188c9fcdb7`。
- [InputWeave.GameInput 0.0.1](https://github.com/rubujo/InputWeave.GameInput/tree/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2):由 [rubujo](https://github.com/rubujo) 及其 [貢獻者](https://github.com/rubujo/InputWeave.GameInput/graphs/contributors) 開發並採用 [**CC0 1.0 Universal**](https://github.com/rubujo/InputWeave.GameInput/blob/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2/LICENSE) 授權,提供 GameInput 執行階段、用戶端、裝置、讀取狀態與震動控制介面。套件固定於本儲存庫的 NuGet 來源 `eng/nuget/InputWeave.GameInput.0.0.1.nupkg`,封裝來源為 [`da4ff730a1d52a8f4d21d43aba7408c59b50a7a2`](https://github.com/rubujo/InputWeave.GameInput/commit/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2),套件 SHA256 為 `41aca5564e443497179313e02c0b1365d040386fcb1acc2cd106e1799253ce0b`。
- [Microsoft.Extensions.DependencyInjection.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection.Abstractions):由 [Microsoft](https://github.com/microsoft) 及其 [貢獻者](https://github.com/dotnet/runtime/graphs/contributors) 於 [.NET Runtime](https://github.com/dotnet/runtime) 儲存庫開發並採用 [**MIT License**](https://github.com/dotnet/runtime/blob/main/LICENSE.TXT) 授權,作為 InputWeave.GameInput 的相依套件,提供相依性插入(Dependency Injection)抽象介面。
- [Microsoft GameInput Redistributable](https://www.nuget.org/packages/Microsoft.GameInput):由 Microsoft 提供,作為選用的 GameInput 執行階段可轉散發套件。正式發佈 ZIP 檔會隨附 `redist/GameInputRedist.msi` 供使用者手動安裝;本應用程式不會自動安裝。手動安裝 `redist/GameInputRedist.msi` 即表示使用者需遵守 [Microsoft.GameInput 授權條款](https://www.nuget.org/packages/Microsoft.GameInput/3.5.278/License);相關授權與 NOTICE 檔案位於 `Licenses/Microsoft.GameInput_LICENSE.txt` 與 `Licenses/Microsoft.GameInput_NOTICE.txt`,且該可轉散發安裝程式不屬於本專案 CC0 授權範圍。
- [Microsoft GameInput Redistributable](https://www.nuget.org/packages/Microsoft.GameInput):由 Microsoft 提供,作為選用的 GameInput 執行階段可轉散發套件。正式發佈 ZIP 檔會隨附 `redist/GameInputRedist.msi` 供使用者手動安裝;本應用程式不會自動安裝。手動安裝 `redist/GameInputRedist.msi` 即表示使用者需遵守 [Microsoft.GameInput 授權條款](https://www.nuget.org/packages/Microsoft.GameInput/4.0.306/License);相關授權與 NOTICE 檔案位於 `Licenses/Microsoft.GameInput_LICENSE.txt` 與 `Licenses/Microsoft.GameInput_NOTICE.txt`,且該可轉散發安裝程式不屬於本專案 CC0 授權範圍。

本專案的詳細條款與免責聲明,請參閱隨附之 [**LICENSE**](LICENSE) 文件;發佈檔 `Licenses/` 資料夾內含 `ThirdPartyNotices.txt`(NuGet 套件授權聲明清單)、`InputWeave.GameInput_LICENSE.txt`、`Microsoft.GameInput_LICENSE.txt`、`Microsoft.GameInput_NOTICE.txt`,以及各元件完整授權文字;[Microsoft.GameInput 3.5.278 線上授權頁](https://www.nuget.org/packages/Microsoft.GameInput/3.5.278/License) 另可於 NuGet 查閱。
本專案的詳細條款與免責聲明,請參閱隨附之 [**LICENSE**](LICENSE) 文件;發佈檔 `Licenses/` 資料夾內含 `ThirdPartyNotices.txt`(NuGet 套件授權聲明清單)、`InputWeave.GameInput_LICENSE.txt`、`Microsoft.GameInput_LICENSE.txt`、`Microsoft.GameInput_NOTICE.txt`,以及各元件完整授權文字;[Microsoft.GameInput 4.0.306 線上授權頁](https://www.nuget.org/packages/Microsoft.GameInput/4.0.306/License) 另可於 NuGet 查閱。
Binary file modified eng/nuget/InputWeave.GameInput.0.0.1.nupkg
Binary file not shown.
2 changes: 1 addition & 1 deletion eng/nuget/InputWeave.GameInput.0.0.1.nupkg.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3342051977f6f1b91f2a18acfc224456320264dd67633ed4bc41c8188c9fcdb7 InputWeave.GameInput.0.0.1.nupkg
41aca5564e443497179313e02c0b1365d040386fcb1acc2cd106e1799253ce0b InputWeave.GameInput.0.0.1.nupkg
8 changes: 4 additions & 4 deletions eng/nuget/InputWeave.GameInput_LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
InputWeave.GameInput 0.0.1
===========================

來源: https://github.com/rubujo/InputWeave.GameInput/tree/89b148669ffe58d9927495ed0d89f9997bf4962a
來源: https://github.com/rubujo/InputWeave.GameInput/tree/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2
作者: https://github.com/rubujo
貢獻者: https://github.com/rubujo/InputWeave.GameInput/graphs/contributors
封裝來源: https://github.com/rubujo/InputWeave.GameInput/commit/89b148669ffe58d9927495ed0d89f9997bf4962a
封裝來源: https://github.com/rubujo/InputWeave.GameInput/commit/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2
套件檔案: eng/nuget/InputWeave.GameInput.0.0.1.nupkg
套件 SHA256: 3342051977f6f1b91f2a18acfc224456320264dd67633ed4bc41c8188c9fcdb7
套件 SHA256: 41aca5564e443497179313e02c0b1365d040386fcb1acc2cd106e1799253ce0b
授權名稱: Creative Commons CC0 1.0 Universal
授權識別碼 (SPDX): CC0-1.0
授權檔案: https://github.com/rubujo/InputWeave.GameInput/blob/89b148669ffe58d9927495ed0d89f9997bf4962a/LICENSE
授權檔案: https://github.com/rubujo/InputWeave.GameInput/blob/da4ff730a1d52a8f4d21d43aba7408c59b50a7a2/LICENSE

InputWeave.GameInput 採用 Creative Commons CC0 1.0 Universal 公眾領域貢獻宣告。
在法律允許的最大範圍內,作者已將此套件的著作權與相關權利貢獻至全球公眾領域。
Expand Down
44 changes: 22 additions & 22 deletions src/InputBox/Core/Input/GameInputGamepadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ private async Task PollingLoopAsync(CancellationToken cancellationToken, TaskCom
}

_gameInput = GameInputClient.Create();
_gameInput.SetFocusPolicy(GameInputFocusPolicy.GameInputDefaultFocusPolicy);
_gameInput.EnableBackgroundInput(false);

GameInputRuntimeInfo runtimeInfo = GameInputRuntime.GetInfo();
LoggerService.LogInfo($"GameInputRuntime/InputWeave loader={runtimeInfo.LoaderPolicy} available={runtimeInfo.IsAvailable} moduleKind={runtimeInfo.LoadedModuleKind} modulePath={runtimeInfo.LoadedModulePath} version={runtimeInfo.FileVersion}");
Expand All @@ -868,14 +868,15 @@ private async Task PollingLoopAsync(CancellationToken cancellationToken, TaskCom
_deviceCallbackReg = _gameInput.RegisterDeviceCallback(
null!,
GameInputKind.GameInputKindGamepad,
GameInputDeviceStatus.GameInputDeviceConnected,
GameInputEnumerationKind.GameInputNoEnumeration,
(_, _, _, _) =>
(deviceEvent, _) =>
{
_needsRefresh = true;
if (deviceEvent is GameInputDeviceEvent.GameInputDeviceEventConnected or GameInputDeviceEvent.GameInputDeviceEventDisconnected)
{
_needsRefresh = true;

// 記錄觸發當下的時間。
Interlocked.Exchange(ref _refreshRequestedTicks, Stopwatch.GetTimestamp());
// 記錄觸發當下的時間。
Interlocked.Exchange(ref _refreshRequestedTicks, Stopwatch.GetTimestamp());
}
});
}

Expand Down Expand Up @@ -1114,13 +1115,13 @@ private void RecordReadFailure(Exception ex)
/// <summary>
/// 記錄 GameInput 裝置狀態診斷資料。
/// </summary>
private void RecordDeviceStatus(GameInputDeviceStatus status)
private void RecordDeviceStatus(bool isConnected)
{
lock (_gameInputDiagnosticsLock)
{
_lastReadDeviceStatus = Convert.ToUInt32(status);
_lastReadDeviceStatus = isConnected ? 1u : 0u;

if ((status & GameInputDeviceStatus.GameInputDeviceConnected) == 0)
if (!isConnected)
{
_deviceUnavailableRefreshCount++;
}
Expand All @@ -1136,7 +1137,7 @@ private static uint TryGetDeviceStatusValue(GameInputDevice device)
{
try
{
return Convert.ToUInt32(device.Status);
return device.IsConnected() ? 1u : 0u;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1239,10 +1240,10 @@ private void Poll()

try
{
GameInputDeviceStatus status = dev.Status;
RecordDeviceStatus(status);
bool isConnected = dev.IsConnected();
RecordDeviceStatus(isConnected);

if ((status & GameInputDeviceStatus.GameInputDeviceConnected) == 0)
if (!isConnected)
{
Debug.WriteLine("[GameInput] 目前裝置狀態已非 Connected,立即重新整理裝置清單。");
LogGameInputDiagnosticsSnapshot("device-status-non-connected");
Expand Down Expand Up @@ -1758,8 +1759,7 @@ private void TryFindDevice()

// 執行一次完整的列舉。
IReadOnlyList<GameInputDevice> devices = gameInput.EnumerateDevices(
GameInputKind.GameInputKindGamepad,
GameInputDeviceStatus.GameInputDeviceConnected);
GameInputKind.GameInputKindGamepad);
Comment thread
perditavojo marked this conversation as resolved.
Resolved

// 1. 釋放清單中已不再存在或已非 Connected 的舊裝置代理(Zero-allocation 替換 LINQ Any)。
for (int i = _allDevices.Count - 1; i >= 0; i--)
Expand Down Expand Up @@ -1930,7 +1930,7 @@ private static bool IsDeviceConnected(GameInputDevice device)
{
try
{
return IsConnectedStatus(device.Status);
return IsConnectedStatus(device.IsConnected());
}
catch (Exception ex)
{
Expand All @@ -1941,12 +1941,12 @@ private static bool IsDeviceConnected(GameInputDevice device)
}

/// <summary>
/// 判斷 GameInput 裝置狀態是否包含 Connected 旗標。
/// 判斷 GameInput 裝置狀態是否連線。
/// </summary>
/// <param name="status">GameInput 裝置狀態旗標。</param>
/// <returns>若包含 Connected 則回傳 true。</returns>
private static bool IsConnectedStatus(GameInputDeviceStatus status)
=> (status & GameInputDeviceStatus.GameInputDeviceConnected) != 0;
/// <param name="isConnected">GameInput 裝置連線狀態。</param>
/// <returns>若連線則回傳 true。</returns>
private static bool IsConnectedStatus(bool isConnected)
=> isConnected;

/// <summary>
/// 掃描目前是否有其他正在活動的裝置,若有則切換
Expand Down
2 changes: 1 addition & 1 deletion src/InputBox/InputBox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

<ItemGroup>
<PackageReference Include="InputWeave.GameInput" Version="0.0.1" />
<PackageReference Include="Microsoft.GameInput" Version="4.0.302" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.GameInput" Version="4.0.306" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 6 additions & 8 deletions tests/InputBox.Tests/GameInputDirectUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public void RequiredInputWeaveGamepadApi_Surface_IsAvailable()
Assert.NotNull(typeof(GameInputRuntime).GetMethod(nameof(GameInputRuntime.TryProbe), BindingFlags.Public | BindingFlags.Static));
Assert.NotNull(typeof(GameInputRuntime).GetMethod(nameof(GameInputRuntime.GetInfo), BindingFlags.Public | BindingFlags.Static));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.Create), BindingFlags.Public | BindingFlags.Static));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.SetFocusPolicy), [typeof(GameInputFocusPolicy)]));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.EnumerateDevices), [typeof(GameInputKind), typeof(GameInputDeviceStatus)]));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.EnableBackgroundInput), [typeof(bool)]));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.EnumerateDevices), [typeof(GameInputKind)]));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.GetCurrentGamepad), [typeof(GameInputDevice)]));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.RegisterReadingCallback), [typeof(GameInputDevice), typeof(GameInputKind), typeof(GameInputReadingHandler)]));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.RegisterDeviceCallback), [typeof(GameInputDevice), typeof(GameInputKind), typeof(GameInputDeviceStatus), typeof(GameInputEnumerationKind), typeof(GameInputDeviceHandler)]));
Assert.NotNull(typeof(GameInputDevice).GetProperty(nameof(GameInputDevice.Status)));
Assert.NotNull(typeof(GameInputClient).GetMethod(nameof(GameInputClient.RegisterDeviceCallback), [typeof(GameInputDevice), typeof(GameInputKind), typeof(GameInputDeviceEventHandler)]));
Assert.NotNull(typeof(GameInputDevice).GetMethod(nameof(GameInputDevice.IsConnected), Type.EmptyTypes));
Assert.NotNull(typeof(GameInputDevice).GetMethod(nameof(GameInputDevice.GetDeviceInfoSnapshot), Type.EmptyTypes));
Assert.NotNull(typeof(GameInputDevice).GetMethod(nameof(GameInputDevice.SetRumbleState), [typeof(GameInputRumbleParams).MakeByRefType()]));
}
Expand All @@ -39,8 +39,6 @@ public void GameInputCallbackParameters_AreFunctionPointers()
{
AssertCallbackParameterUsesNativeFunctionPointerBridge("RegisterReadingCallback");
AssertCallbackParameterUsesNativeFunctionPointerBridge("RegisterDeviceCallback");
AssertCallbackParameterUsesNativeFunctionPointerBridge("RegisterSystemButtonCallback");
AssertCallbackParameterUsesNativeFunctionPointerBridge("RegisterKeyboardLayoutCallback");
}

/// <summary>
Expand Down Expand Up @@ -222,15 +220,15 @@ private static GameInputDeviceInfoSnapshot CreateDeviceInfoSnapshot(
string displayName,
string pnpPath)
{
GameInputDeviceInfo nativeInfo = new()
GameInputDeviceIdentity identity = new()
{
VendorId = vendorId,
ProductId = productId,
SupportedInput = GameInputKind.GameInputKindGamepad
};

return CreateInstance<GameInputDeviceInfoSnapshot>(
nativeInfo,
identity,
displayName,
pnpPath,
null,
Expand Down
4 changes: 2 additions & 2 deletions tests/InputBox.Tests/GamepadControllerPauseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ public void IsConnectedStatus_GameInputDeviceStatus_FiltersUnavailableDevices()
BindingFlags.Static | BindingFlags.NonPublic)
?? throw new InvalidOperationException("找不到 GameInputGamepadController.IsConnectedStatus。");

Assert.True((bool)method.Invoke(null, [GameInputDeviceStatus.GameInputDeviceConnected])!);
Assert.False((bool)method.Invoke(null, [(GameInputDeviceStatus)0])!);
Assert.True((bool)method.Invoke(null, [true])!);
Assert.False((bool)method.Invoke(null, [false])!);
}

/// <summary>
Expand Down
Loading
Loading