src/Utils/IoPoller.cpp
// update the `IoPoller`: should be called once per frame
update the `IoPoller`: should be called once per frame
update the ` IoPoller ` : should be called once per frame
void osc::IoPoller::onUpdate()
{
    DisplaySize = App::cur().dims();
    auto curTicks = App::cur().getTicks();
    double dTicks = static_cast<double>(curTicks - Ticks);
    DeltaTime = static_cast<float>(dTicks/static_cast<double>(TickFrequency));
    Ticks = curTicks;
    auto mouseState = App::cur().getMouseState();
    MousePressed[0] = _mousePressedEvents[0] || mouseState.LeftDown;
    MousePressed[1] = _mousePressedEvents[1] || mouseState.RightDown;
    MousePressed[2] = _mousePressedEvents[2] || mouseState.MiddleDown;
    MousePosPrevious = MousePos;
    MousePos = mouseState.pos;
    MouseDelta = glm::vec2{glm::ivec2{MousePos - MousePosPrevious}};
     if the caller wants to set the mouse position, then it should be
     set. However, to ensure that Delta == Cur-Prev, we need to create
     a "fake"  *prev* that behaves "as if" the mouse moved from some
     location to the warp location
    if (WantMousePosWarpTo && App::cur().isWindowFocused())
    {
        App::cur().warpMouseInWindow(MousePosWarpTo);
        MousePos = MousePosWarpTo;
        MousePosPrevious = MousePosWarpTo - MouseDelta;
        WantMousePosWarpTo = false;
    }
     (KeysDown, Shift-/Ctrl-/Alt-Down handled by events)
     KeysDownDurationPrev
    std::copy(KeysDownDuration.begin(), KeysDownDuration.end(), KeysDownDurationPrev.begin());
     KeysDownDuration
    for (size_t i = 0; i < KeysDown.size(); ++i)
    {
        if (!KeysDown[i])
        {
            KeysDownDuration[i] = -1.0f;
        }
        else
        {
            KeysDownDuration[i] = KeysDownDuration[i] < 0.0f ? 0.0f : KeysDownDuration[i] + DeltaTime;
        }
    }
}
void osc :: IoPoller :: onUpdate ( ) { DisplaySize = App :: cur ( ) . dims ( ) ; auto curTicks = App :: cur ( ) . getTicks ( ) ; double dTicks = static_cast < double > ( curTicks - Ticks ) ; DeltaTime = static_cast < float > ( dTicks / static_cast < double > ( TickFrequency ) ) ; Ticks = curTicks ; auto mouseState = App :: cur ( ) . getMouseState ( ) ; MousePressed [ 0 ] = _mousePressedEvents [ 0 ] || mouseState . LeftDown ; MousePressed [ 1 ] = _mousePressedEvents [ 1 ] || mouseState . RightDown ; MousePressed [ 2 ] = _mousePressedEvents [ 2 ] || mouseState . MiddleDown ; MousePosPrevious = MousePos ; MousePos = mouseState . pos ; MouseDelta = glm :: vec2 { glm :: ivec2 { MousePos - MousePosPrevious } } ; if ( WantMousePosWarpTo && App :: cur ( ) . isWindowFocused ( ) ) { App :: cur ( ) . warpMouseInWindow ( MousePosWarpTo ) ; MousePos = MousePosWarpTo ; MousePosPrevious = MousePosWarpTo - MouseDelta ; WantMousePosWarpTo = false ; } std :: copy ( KeysDownDuration . begin ( ) , KeysDownDuration . end ( ) , KeysDownDurationPrev . begin ( ) ) ; for ( size_t i = 0 ; i < KeysDown . size ( ) ; ++ i ) { if ( ! KeysDown [ i ] ) { KeysDownDuration [ i ] = -1.0f ; } else { KeysDownDuration [ i ] = KeysDownDuration [ i ] < 0.0f ? 0.0f : KeysDownDuration [ i ] + DeltaTime ; } } }
update the `IoPoller`: should be called once per frame
update the ` IoPoller ` : should be called once per frame
// Ticks, (IO ctor: TickFrequency), DeltaTime // MousePos, MousePosPrevious, MousePosDelta, MousePressed // (edge-case) // // if the caller wants to set the mouse position, then it should be // set. However, to ensure that Delta == Cur-Prev, we need to create // a "fake"  *prev* that behaves "as if" the mouse moved from some // location to the warp location // (KeysDown, Shift-/Ctrl-/Alt-Down handled by events) // KeysDownDurationPrev // KeysDownDuration