C++ WinRT - How to convert C++CX Array<> template to WinRT?

吃可爱长大的小学妹 提交于 2020-02-07 03:35:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!