Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Oxmyx

Jerky movements with >50 fps

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

I have a serious problem which I haven''t been able to solve: My engine runs smoothly, yet input data coming from DirectInput is terribly delayed, which makes it impossible to control the viewport with the mouse (it''s a first person game). I''m reading buffered mouse data from the DI Device as shown in the SDK tutorial, so I don''t think that''s the fault. In the main menu of my game the mouse moves sometimes perfectly smooth, and sometimes delayed and jerky. I haven''t been able to find out the reason for this behaviour. Yet I noticed something: When I play, say, a mp3 file using MediaPlayer in the background, the mouse moves jerky. I don''t know if this has anything to do with it, since it clearly doesn''t have anything to do with low framerates (the menu runs with over 500 fps). When I load the game and the mouse controls the viewport, viewport changes are jerky all the time (the rest of the game and all animations run smoothly). Sometimes the reaction time to mouse movements is greater than one second. Does anybody have any idea of what''s causing this behaviour?

Share this post


Link to post
Share on other sites
Advertisement
I remember half life used to have problems like this sometimes, and it was down to DirectSound. There was a workaround, but I can''t remember what it is. Maybe Google could help. All I can suggest is to make sure you have the latest drivers and that they are DirectX compatible. Sorry I can''t help further.

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

Share this post


Link to post
Share on other sites
I get the same results on other machines. Any chance that it may have something to do with buffered instead of immediate mouse data?

This is how I initialize DI:


function InitDirectInput(hInst: HINST; hWnd: HWND): HRESULT;
var
hr: HRESULT;
begin
hr := DirectInput8Create(hInst, DIRECTINPUT_VERSION,
IID_IDirectInput8, Pointer(g_pDI), nil);
if FAILED(hr) then begin
Result:= E_FAIL;
Exit;
end;

hr := g_pDI.CreateDevice(GUID_SysMouse, g_pDIMouse, nil);
if FAILED(hr) then begin
Result := E_FAIL;
Exit;
end;

hr := g_pDIMouse.SetDataFormat(c_dfDIMouse);
if FAILED(hr) then begin
Result := E_FAIL;
Exit;
end;

hr := g_pDIMouse.SetCooperativeLevel(hWnd, DISCL_FOREGROUND or DISCL_EXCLUSIVE);
if FAILED(hr) then begin
Result := E_FAIL;
Exit;
end;

dipdw.diph.dwSize := sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize := sizeof(DIPROPHEADER);
dipdw.diph.dwObj := 0;
dipdw.diph.dwHow := DIPH_DEVICE;
dipdw.dwData := 16;

hr := g_pDIMouse.SetProperty(DIPROP_BUFFERSIZE, dipdw.diph);
if FAILED(hr) then begin
Result := E_FAIL;
Exit;
end;

hr := g_pDIMouse.Acquire();
if FAILED(hr) then begin
Result := E_FAIL;
Exit
end;

Result:= S_OK;
end;


This is how I read mouse data:


procedure GetMouseData();
var
hr: HRESULT;
od: DIDEVICEOBJECTDATA;
dwElements: DWORD;
begin
dwElements := 1;
od.dwData := 0;
od.dwOfs := 0;

case g_pDIMouse.GetDeviceData(sizeof(DIDEVICEOBJECTDATA), @od, dwElements, 0) of
DIERR_NOTACQUIRED:
begin
hr := g_pDIMouse.Acquire();
end;

DIERR_INPUTLOST:
begin
hr := g_pDIMouse.Acquire();
end;

DI_OK:
begin
case od.dwOfs of
DIMOFS_X:
begin
UpdateCursorPosition(LongInt(od.dwData), 0);
end;
DIMOFS_Y:
begin
UpdateCursorPosition(0, LongInt(od.dwData));
end;
DIMOFS_BUTTON0:
begin
if bMouseBtn0 = True then bMouseBtn0 := False
else bMouseBtn0 := True;
end;
DIMOFS_BUTTON1:
begin
if bMouseBtn1 = True then bMouseBtn1 := False
else bMouseBtn1 := True;
end;
end; //case

end;
end; //case

end;


[edited by - Oxmyx on June 2, 2004 8:25:31 AM]

Share this post


Link to post
Share on other sites
I''ve tried it with immediate mouse data, now it works. Has it any disadvantage to use immediate data instead of buffered data for a first-person shooter?

Share this post


Link to post
Share on other sites
I have that 2 but only with the keyboard input, the mouse still runs smooth. I have this problem for a few weeks now and I dont know what the cause is, I havent changed a thing. My programs starts with 250+ fps and after 1sec it drops down to 130 and the movement is very jerky. Mousemove it still smooth though...

Share this post


Link to post
Share on other sites
Hehehe! There are reasons not to write games using exclusively Microsoft technology! Check out www.Clanlib.org, their mouse routines work very well in my games.

Share this post


Link to post
Share on other sites
AFAIK Unbuffered mouse is what most video games use. You are, after all, polling the mouse between 50-100 times a second, why spend the overhead for buffering and stuff... the user will not be able to click and unclick a mouse fast enough for the button press to be missed. The buffering software is polling internally to be able to produce a buffered view of the mouse actions and it is probably polling at a rate higher than necessary, if its causing things to run poorly.

Share this post


Link to post
Share on other sites
I''d look into your interaction with Windows. Ie. if you are simply looping and not handling messages as most people do it *can* totally mess some things up, especially with DirectInput.

MAKE SURE that you are being nice to Windows, or weird things can happen. Even if you have to use the ON_IDLE handler, this is sometimes better than other more messy setups.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!