SDL Joystick Revisions

Reporter: time-killer-games  |  Status: open  |  Last Modified: July 30, 2020, 04:41:12 PM

WIP
time-killer-games  
@fundies alright, i think I did everything you asked correctly, let me know if I didn't or if there's anything else you want done before I ping robert or josh to review and/or merge, I know you don't like macro definitions but that's usually how limits are handled such as PATH_MAX, etc. so I wanted to go with how that sort of thing is usually done. I can change it if you want.

#define JOYSTICK_MAX 16

This way, to change the max number of joysticks only one line needs to be changed. I'm not sure how to make it "not" hard-coded, because this is still technically hard coded but with a bigger number allowable, (i.e. number of gamepads GMS uses).

fundies  

@fundies alright, i think I did everything you asked correctly, let me know if I didn't or if there's anything else you want done before I ping robert or josh to review and/or merge, I know you don't like macro definitions but that's usually how limits are handled such as PATH_MAX, etc. so I wanted to go with how that sort of thing is usually done. I can change it if you want.

#define JOYSTICK_MAX 16

This way, to change the max number of joysticks only one line needs to be changed. I'm not sure how to make it "not" hard-coded, because this is still technically hard coded but with a bigger number allowable, (i.e. number of gamepads GMS uses).

I don't think you should hard code any value. You should be adding / removing joysticks from the vector when they are plugged / unplugged. I do this with gamepads here: https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Platforms/SDL/Event.cpp#L214

OR: You can also get a raw joystick from a gamepad using sdl's api iirc. This would eliminate need for the extra vector.

time-killer-games  

@fundies i think i found a way to do it that keeps all the changes to one file instead of editing the event handler source. not sure if you find that acceptable, just let me know whenever.
fundies  

@fundies i think i found a way to do it that keeps all the changes to one file instead of editing the event handler source. not sure if you find that acceptable, just let me know whenever.

I would prefer you do it where I suggested. The code for adding gamepads/joysticks should be in the same place. Also, joystick_max should not be needed at all now

time-killer-games  

@fundies alright i think i did it, (again), the more critiques the better, This is nearly the second or third time I ever touched the joystick code, it would be nice to have done right sooner than later. I want to make a habit of doing things correctly the first time going forward and use pull requests as an opportunity to improve my contributions instead of feeling nagged by code review which is counterproductive.
Please sign in to post comments, or you can view this issue on GitHub.