-
Notifications
You must be signed in to change notification settings - Fork 12
Added DirectInput support. #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The gamepads are polled into the indices [4..] so it doesn't break backwards compatibility.
|
Thanks for creating a MR for DInput, i really appreciate that! I looked at the source and it needs a bit of work to make it production ready:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DInput needs to be separate from XInput, using both is dangerous and may be unstable using the same controller on both api's. Also it should not break backwards compability and XInput is preferred over DInput. Therefore adding a backend type enum and its own states is a better approach.
I can prepare that for you if you want, but i would do that in its own branch on master.
Also ensure that namings are correct everywhere, so it doesn't collide with other api's, especially for IID constants or other defines.
Fore more details see the comments for certain code blocks.
| fplClearStruct(outStates); | ||
| for (DWORD controllerIndex = 0; controllerIndex < XUSER_MAX_COUNT; ++controllerIndex) { | ||
| XINPUT_STATE controllerState = fplZeroInit; | ||
| auto rv = xinputState->xinputApi.XInputGetState(controllerIndex, &controllerState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No auto! Its not a C++ library!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. bad habbit.
| #if defined(FPL_PLATFORM_WINDOWS) | ||
| #include <xinput.h> // XUSER_MAX_COUNT | ||
| #else | ||
| #define XUSER_MAX_COUNT 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not include XInput here, just change the FPL_MAX_GAMEPAD_STATE_COUNT to 8, so it is sufficient for XInput or DInput gamepad backends.
Also seperate both states, xinput has its own states and dinputs has its own states, even though indexing it with 4 was a good idea. But i would rather have them separate, see my other comments below.
| #define DIRECTINPUT_VERSION 0x0800 | ||
| #endif | ||
| #include <dinput.h> | ||
| #if defined(FPL_IMPLEMENTATION) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use win32 video software backend as an example, how the implementation is defines and where it is located.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand that. Can you give me some pointers?
| ctrl->device->Acquire(); | ||
| ctrl->instanceGuid = instance->guidInstance; | ||
| ctrl->productGuid = instance->guidProduct; | ||
| wcsncpy_s(ctrl->name, instance->tszProductName, _TRUNCATE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use WCSNCPY, use fplWideStringToUTF8String() or (fplUTF8StringToWideString) instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do.
|
I started a new branch, that origins from develop that prepares for having multiple game controller backends: It will be similar to the video/audio backend system, but much easier to implement because it has just a couple of functions and states. I will comment here, when this system is merged in the develop branch. |
|
After thinking it through, it is a very good idea to support both XInput and DInput using 0-3 for XInput and 4-11 for direct input. The spacing is special in FPL, because i want to save as much as "chars" as possible. There are a lot of indentation in FPL going on - therefore i use a single tab character \t instead of 2/4/6 space characters (this saves a lot of memory!). Also each editor has its own number of spaces to visualize a tab-control, which is another reason why i use tabs instead. Regarding the formatting of FPL, i use visual studio 2022 C++ formatting rules which i adjusted a bit, because i don't like certain defaults in there. But i don't auto format everything, just a couple of selected lines! Occasionally i run the VC++ auto formatter to clean up over the full source, but even the current master would have a ton of changes when i do that. Maybe i will create formatting guideline document for the FPL code style, so we can create a .EditorConfig or .clang-format file from that. Each global variable is defined as "fpl_globalvar" and has the prefix "fpl__global_whateverTheNameIs". |
|
I added a .editorconfig file. Feel free to generate a clang-format config for that. https://github.com/f1nalspace/final_game_tech/blob/develop/.editorconfig Also i reformatted FPL in the develop branch. So it matches that editor config. |
f1nalspace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked out your pull request into a new branch, but i can't compile it. There are just too many errors to fix. So i extracted the DInput part and put it directly into the develop branch.
Will report back when this is done, so we can close that pull request.
|
Sorry for generating so much work. I'm quite new to git etc. Make sure you check the joypad name in DirectInput. I think I didn't map it at all and it's a nullptr. (I had no need for it in my project). With Visual Studio 2022, when you add a .clang-format file, Visual Studio will automatically use it for reformating, when you save the file. |
The gamepads are polled into the indices [4..]
so it doesn't break backwards compatibility.