PDA

View Full Version : DInput in 0.9



kbluck
09-22-2008, 09:57 PM
I'm curious about the status of DirectInput on 0.9. I noticed that it is included in various Win32-related modules, which is a bummer because it makes clanDisplay depend on the dX SDK. Not a big deal --- well, actually, a 400mb deal :) but annoying for people who think they're not going to need anything from DirectX because they're using message input and OpenGL.

So, I was wondering if there's any plans in the works to either remove it altogether, or to split it into the DX target modules as a variant input context provider.

If not, I might look at doing so.

--- Kevin

Magnus Norddahl
09-22-2008, 11:23 PM
I'm not entirely sure what to do about DirectX in clanDisplay. I consider the DirectX dependency as fairly low priority because downloading the SDK isn't that big a deal (Windows game developers are used to needing DX). Its only during deployment that it can be a bit annoying to needing to bundle the redistributable.

My bigger worry with DirectInput is that it seems unclear what Microsoft's long term plans are in this area. For some reason they didn't use DirectInput for their XBOX, and the library they wrote for it only targets their own console controller.

I suspect that perhaps you do not need a library like DirectInput anymore, since HID devices probably follow some standard that means you can use the WM_INPUT and RAWINPUT stuff added in Windows XP. I haven't researched this much though, just noticed these messages one of the days I was MSDN surfing.

I actually think that if I was to improve this part of ClanLib, I would probably try research WM_INPUT to see if I can drop this dependency. DirectInput smells badly of something Microsoft is about to deprecate, and I'm so dead tired of having all my code bases constantly deprecated by Microsoft that I'd rather use a low level API than risk having to read up on yet another API that only lasts a couple of years.

rombust
09-23-2008, 07:06 AM
A while ago, during porting the ClanLib 0.8 Joystick example to 0.9 (Now deleted) - I added support code to 0.9 Win32 target.

This was required for win32 to automatically poll the directinput device.

This is how it worked:
In "CL_Win32Window::create_new_window()"

RAWINPUTDEVICE Rid[1];
Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;
Rid[0].usUsage = HID_USAGE_GENERIC_JOYSTICK;
Rid[0].dwFlags = RIDEV_INPUTSINK;
Rid[0].hwndTarget = hwnd;
RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]));
Was added, so that window events are thrown
(Note: I was not sure if HID_USAGE_GENERIC_GAMEPAD was also required.)

In "CL_Win32Window::window_proc()"

case WM_INPUT:
received_joystick_input();
return true;

Which is called when input occurs.
In "CL_Win32Window::received_joystick_input()", this function only calls ic.poll()
which polls all the input context devices.. Note - the mouse and keyboard poll() functions are empty

And "CL_InputDeviceProvider_DirectInput::poll()" calls directinput_device->Poll();

Reading the MSDN documentation, you should be able to obtain the joystick information (without using DirectInput) by directly using the WM_INPUT message. (See http://msdn.microsoft.com/en-us/library/ms645543.aspx )

Magnus Norddahl
09-23-2008, 06:47 PM
OK, so there is not really a reason to use DirectInput anymore. It is safer and better to interface the HID standards than any MS library, I think. Hardware people don't change their standards as often as MS does. :)