• Advertisement
Sign in to follow this  

Why does mouse movments effect my game? (C++)

This topic is 3385 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

Ok, I am having a hard time understanding this and find how to fix it, its kinda like am I the only one who has this problem, kinda thing. Ok, I have a mouse handler function where it centers the mouse on the screen and calculates the player model position. If I move the mouse with the mouse handler function disabled the game seems to speed up my objects in the game. With or with out the Mouse Handler and the time performance calculation for the objects it seems they speed up still. I don't have any other function getting mouse input except that, but if I use the keyboard to move the player model position it seems that everything seems smooth and fine with out mouse movement. Can someone assists please? I'm scratching my head on this and yes I tested this problem on different computers and OSes and they do have the same issue. Project: C++, Win32, OpenGL, Fmod, VS2008, Vista Thanks, Andrew. [Edited by - ajm113 on January 15, 2009 10:33:42 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Codeka
Can you post the code for your main game loop?

Yeah sure, anything for fixing this bug, wasn't sure if someone can recall how they fixed it at the top of there heads.


while(!bQuit)
{
Render();
if(PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
{
if(WM_QUIT == message.message) {
bQuit = true;

}else{
TranslateMessage(&message);
DispatchMessage(&message);
}
}else{
Frame();
}
}


//etc ...


void Core::Frame() {


if(m_GameState == GS_PLAY) {
m_dTimeDelta = (*this.*GetDeltaTime) ();

if(m_dTimeDelta > 0.250) {
m_dTimeDelta = 0.250;
}

m_dTimeGame = m_dTimeGame + (float)m_dTimeDelta;

if( !UpdateGame() ) {
bQuit = true;
return;
}


CountFPS();
return;
}





UpdateGame just has the CheckKeyboard, Controller status. If the controller is not connected use the mouse handler.

Then after those functions are called I call SwapBuffers function.

Let me know if you need anything else to know to sort this out.

Share this post


Link to post
Share on other sites
When you move the mouse, your window gets a constant stream of WM_MOUSEMOVE messages.

Since you are only calling Frame() when PeekMessage() returns false, a constant stream of messages will halt this.

I'd do this in my main loop:


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

Frame();
}


so that Frame() gets called regardless of whether there are messages to process or not.

Share this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused

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

Frame();
}



That's also not a very good way to do it, because then you end up filling up your event queue with a bunch of messages. If you're only processing 30 frames per second, it means your app can only pump 30 messages per second as well.

ajm113: Your problem is similar to the game loop above, except you're calling Render every loop, but not Frame. Presumably, Render is what renders the game to the screen, and Frame is what updates the logic and so on.

If your Render runs at 30 FPS (or whatever) that means that if you've got more than 30 windows messages coming in per second, your Frame will never get call. If you've got (say) 25 windows messages coming in, then you'll only call Frame once every 25 calls to Render.

I would put the call to Render inside the else as well and see how that goes.

Share this post


Link to post
Share on other sites

Why not:



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

Frame();
Render()
}



a) you process every message that entered on queue AFTER the last frame.
b) after updating your gamestate based on that input, you call Frame to update data.
c) You render it


Any flaw?

Share this post


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

  • Advertisement