问题
How to convert the following code to C++ WinRT ?
Platform::Array<bool>^ currentButtonReading =
ref new Platform::Array<bool>(buttonCount);
Platform::Array<GameControllerSwitchPosition>^ currentSwitchReading =
ref new Platform::Array<GameControllerSwitchPosition>(switchCount);
Platform::Array<double>^ currentAxisReading = ref new Platform::Array<double>(axisCount);
rawGameController->GetCurrentReading(
currentButtonReading,
currentSwitchReading,
currentAxisReading);
It is from the article:
https://docs.microsoft.com/en-us/windows/uwp/gaming/raw-game-controller
Please advise.
回答1:
Here is the answer after some study.
The C++ WinRT converted source:
struct _GAMEPAD
{
std::vector<RawGameController> db;
RawGameController controller{ nullptr };
std::array<bool, 16> abtn{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
array_view<bool> avbtn{ abtn };
std::array<double, 6> aaxi{ 0,0,0,0,0,0 };
array_view<double> avaxi{ aaxi };
array_view<GameControllerSwitchPosition> avswp{};
};
struct MainPage : MainPageT<MainPage>
{
...
_GAMEPAD m_gamepad;
...
};
int MainPage::OnProc ()
{
...
for (auto e : RawGameController::RawGameControllers() )
{
auto it = std::find( m_gamepad.db.begin(), m_gamepad.db.end(), e );
if (it == m_gamepad.db.end())
{
m_gamepad.db.insert( m_gamepad.db.begin()+m_io.gamepad, e );
m_io.gamepad++;
}
}
// assumed there is one gamepad.
n = m_io.gamepad - 1;
m_gamepad.controller = m_gamepad.db.at(n);
m_gamepad.controller.GetCurrentReading( m_gamepad.avbtn,
m_gamepad.avswp,
m_gamepad.avaxi);
...
}
Hopes, this help.
来源:https://stackoverflow.com/questions/56546230/c-winrt-how-to-convert-ccx-array-template-to-winrt