• Advertisement
Sign in to follow this  

Interrupt handling very slow

This topic is 1261 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

when I scroll very fast, I have the problem that the interrupt handling is too slow. When I scroll in the opposite direction, it takes a long time (up to some seconds) until the camera moves in the opposite direction. Does anyone knows how to solve this issue?

LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
{
    switch(umessage)
    {
        // Check if the window is being destroyed.
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }

        // Check if the window is being closed.
        case WM_CLOSE:
        {
            PostQuitMessage(0);        
            return 0;
        }

        

        // All other messages pass to the message handler in the system class.
        default:
        {
            return ApplicationHandle->MessageHandler(hwnd, umessage, wparam, lparam);
        }
    }
}
LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
{
    if(umsg == WM_MOUSEWHEEL)
        {
            //MessageBox(m_hwnd, L"Mouse wheel", L"Test", MB_OK);
            

            short x = (short)HIWORD(wparam);
            m_Application->HandleInterrupt(MOUSEWHEEL_ROTATED,x);
 
        }
    return DefWindowProc(hwnd, umsg, wparam, lparam);
}
void ApplicationClass::HandleInterrupt(int buttonID, int param1){
    //WaitForSingleObject(InterruptMutex,INFINITE);
    if(buttonID==MOUSEWHEEL_ROTATED){
        if(param1<0){
            targetCameraDistance+=0.5f;
            if(targetCameraDistance>=m_settings->maxCameraDistance){
            targetCameraDistance=m_settings->maxCameraDistance;
            }
        }
        if(param1>0){
            targetCameraDistance-=0.5f;
            if(targetCameraDistance<=0){
            targetCameraDistance=0;
            }
        }
    }
    //ReleaseMutex(InterruptMutex);
}

Do I need the Mutex when handling interrupts?

 

Greetings,

Magogan

Edited by Magogan

Share this post


Link to post
Share on other sites
Advertisement

I noticed a lot of people make mistake of using if(PeekMessage(&message, 0, 0, 0, PM_REMOVE)) instead of while(...) inside game loop, this might be source of the problem.

Share this post


Link to post
Share on other sites

No, I just used the WndProc function, but it seems that it is too slow for my purposes. PeekMessage seems to be fast enough. Now it works :D

Share this post


Link to post
Share on other sites

Magogan, post the code of your message loop.

That's probably where the problem lies. (As others have pointed out already)

Share this post


Link to post
Share on other sites

I have fixed the message loop and now it should work.

 

void SystemClass::Run()
{
    MSG msg;
    bool done, result;


    ZeroMemory(&msg, sizeof(MSG));
    
    done = false;
    while(!done)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
            
            if(msg.message == WM_QUIT){
                done = true;
            }
            else if(msg.message == WM_MOUSEWHEEL){
                short x = (short)HIWORD(msg.wParam);
                m_Application->HandleInterrupt(MOUSEWHEEL_ROTATED,x);
            }
        }
        else
        {
            
            result = Frame();
            if(!result)
            {
                done = true;
            }
        }

    }

    return;
}

Share this post


Link to post
Share on other sites

Seems reasonable, although the use of an if-then confused me a bit. Mine looks like:

    while(msg.message != WM_QUIT)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        doGameLoopStuff();
    }

Guess no difference really though.

 

Why are you manually handling WM_MOUSEWHEEL like that? Does it not get passed to your WndProc like every other message? My concern is you are processing that message twice each time it is issued, based on this and your previous code.

Edited by Aardvajk

Share this post


Link to post
Share on other sites
One thing I noticed is that you aren't quite correctly handling the parameter of WM_MOUSEWHEEL.

You're correctly checking for negative or positive values to determine direction, but the value is important too. As the documentation states, the value is in multiples of WHEEL_DELTA, so the larger the value, the larger your response should be. Otherwise the mousewheel will feel slow or laggy as your game doesn't respond to how fast the user is scrolling the wheel.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement