GLBasic forum

Main forum => GLBasic - en => Topic started by: spacefractal on 2022-Nov-08

Title: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-08
Those who have Swicth Pro controller. Can you checking which buttons that does that.

Etc im need the name of it, and how and which axis the right controller and the both analoge triggers does.

Im purchased such of one you can see, but that controller did not have the analoge trigger, but a digital trigger instead (not a issue in such a game that is not racing really). Im wasent aware of that of course, but im implementated this feature of course.

Im do believe they follow the ps layout button wise, not xbox. Then im will update my GameInput thing for Windows.
Title: Re: What is the name of the Switch Pro Controllers (Windows)?
Post by: bigsofty on 2022-Nov-09
I have some 8Bitdo Pro 2 Wired USB Controllers for Switch, these results any use?
Title: Re: What is the name of the Switch Pro Controllers (Windows)?
Post by: spacefractal on 2022-Nov-09
Just give me the screen like the above one.

Anyway im think found a method im can detect, its using a xbox or a ps4/switch laylout....

Code (glbasic) Select

self.code$[i]="standard"
IF RIGHT$(self.NAMES$[i],1)="s" OR INSTR(self.NAMES$[i],"switch")>-1 OR INSTR(self.NAMES$[i],"pro controller")>-1
self.code$[i]="switch"
self.digi[i]=-1
ENDIF

IF INSTR(self.NAMES$[i],"ps4")>-1 OR INSTR(self.NAMES$[i],"ps3")>-1
self.code$[i]="ps4"
ENDIF

IF INSTR(self.NAMES$[i],"xbox")>-1 OR INSTR(self.NAMES$[i],"360")>-1
self.code$[i]="xbox"
ENDIF

IF self.code$[i]="standard"
LOCAL result=GETJOYBUTTON(i-1, 6)+(GETJOYRX(i-1)+1)/2
IF result<0.4 OR result>0.6 THEN self.code$[i]="ps4/switch"
ENDIF


GETJOYBUTTON(i-1, 6)+(GETJOYRX(i-1)+1)/2 gave 0.5 on a xbox controller and 0.0 on a ps4 controller or if its dont have such a left trigger.
Title: Re: What is the name of the Switch Pro Controllers (Windows)?
Post by: bigsofty on 2022-Nov-10
Out of house till tomorrow night but maybe this database of controller mappings may help?

https://github.com/gabomdq/SDL_GameControllerDB
Title: Re: What is the name of the Switch Pro Controllers (Windows)?
Post by: spacefractal on 2022-Nov-10
This is a good database. The only issue is im in this case need to find out how to get the GUID code of that controller. When its possible, im could actuelly implement that one in the GameInput API instead that one im using (only contains official xbox, ps4 and switch controllers).
Title: Re: What is the name of the Switch Pro Controllers (Windows)?
Post by: spacefractal on 2022-Nov-10
except not getting the GUID code, its acuelly easy to implement the style of the data used in the database and also a better way to remap later (binding).

Also its looked like the HORIPAD S switch controller as im is not in the database.... damn :-).
Title: Re: What is the name of the Switch Pro Controllers (Windows)?
Post by: spacefractal on 2022-Nov-10
Im consider im should a little seperate remapping utilty you can uses for the game, rather than doing it from ingame. In that way GameInput could automatic tacle that rather than the game needs to do the same.

Howover can somebody draw a nice controller image that resemple a controller that could been used from a big compony, which should should like a generic controller.

Something like this in the same resolution, but without colors and antialasing:
https://opengameart.org/content/generic-gamepad-template

Then im will give it a try. Im also could do same kind of utility for key binding as well.

By now the utilty would been Windows only (but im will include the source code of course).
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: bigsofty on 2022-Nov-11
This guys got quite a few vector art based ones...

https://zacksly.itch.io/

There CC By 3.00 license, so you can share if credit is given.

Oh and here is the 8bitdo Pro 2...
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-11
Looks different than me. This cause its very important to also possible to remap on controllers, so you can support them all, regaardless thier configuration.

etc im will improve GameInput and clean its vastly up and also would been possible to remap keyboard too with the utility in same method with a String. etc a was seen as axis, while b was a button, then im uses k for a keyboard button....

Etc im will uses a screen like it.

PS. IM guess its could been looks much better.
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: bigsofty on 2022-Nov-11
Looks good.   :good:

Yeah, my 8bit do pro 2 wired is not in the controller database either(even though Valve uses this DB for Steam) but my Xbox One controller is.

Better to cycle through a diagram of a generic joypad, highlighting buttons and asking the user to press(or skip) the equivalent button on their controller, to make custom templates. Maybe setup some of the more popular ones by name by default. Xbox, Ps4 for example.
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-12
its would been something like that, but of course with only the input a game would need.

Also that string based system did caused the code to been vastly shorted with fewer lines, since only the init and a function take care most of it really.

Also im will also see how im can save the code for a controller, so people a least could tweak it, even there is no remapping feature in a Windows game.

Today im implemented keyboard keys as well. On Android, its would been keyboard only of course as this would been easier its should, that way im impleneted using KEY(), while its why a outout is from 0-128 rather than 0-1.

But all in all, its totally impossible to support every gampad, but 99% of times, remapping should do the job. That is the main goal here. This time the utility should do this for you as well. even for each player.

btw, for standard, its of course ps4, switch and xbox. the main layout would been  after ps4, not xbox. The main thing here, its depend how the trigger is used (on Ps4, 3 axis returns -1 on 3 axis, while a xbox does do that).
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: bigsofty on 2022-Nov-13
Interesting, sounds good. I have been using my basic controller library for a while now. Unfortunately this thread has highlighted some shortcomings in my own approach...  :'( Seriously though, it will be interesting to see what you finally come up with Spacefractal.
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-13
getting more code today. Etc im choosen to uses the digital button and not the analoge trigger on a switch/ps4 for to get more combatible as possible. Those controllers sends 2 inputs, the analoge and a digital one. Im just choosen to take advance of that in this case. Most of time, we dont using the analoge trigger anyway, except its a racing game.....

Also im did a another SCANCODE, like INKEY$, which can been used per player here today (this include both keyboard and controllers). Its seens the button one on the analoge trigger might invoke before the analoge one. This is just to been aware when doing a remapping lol.

Also..... some controllers has AB and XY swapped. Im should do code for that as well as a user selectable. But the game can both disable and enable it. Like using it in menus, but not ingame.

Sooner or later im will also release the code as well. Property later next week.
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: bigsofty on 2022-Nov-14
One small suggestion, as my old lib does it this way, is for each button to buffer each button scan. This would be a list of the button states, discarding the very earliest states in the list, I save the last 2 seconds, of button scans.

This would allow more history of key presses. Examining the list for certain action.

Easy to see if the user is holding down a button, say for in my case a secondary fire mode with a large single shot.
Check for combos, double presses, or even triple presses. Up and down, in quick succession.
Check if he is cheating with an auto fire 🤪

You can obviously do it in the game code but this way abstracts the usual fluff of having to set flags outside the lib.

Good luck with the lib, I've decided to rewrite mine because of some of the points raised here, which is a good thing!  :good:


Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-15
im is not intersered for any button combos as this is not what a controller api, like that one im doing is. This is what a game that using the api should do. All im want to do is make sure the remapping is easy as possible and let api do the job when remapped.

etc im started on the remapping, and do something like this when a user call it:
Code (glbasic) Select

LOCAL result=GameInput.Remap_ScanCode(1, "a:Face Bottom,b:Face Right:,x:Face Left,y:Face Up")
LOCAL status$=GameInput.RemapStatus$


the result would simply just return TRUE when finished or the user quit. Api does the rest. That include keyboard and joypad. (number 1 is a player).

btw need to deal with the stick. Some controllers might not have a stick, but only a dpad. Those that only have a dpad might have reduced number of buttons. So you can quit/end it anytime. So first you should do is move the stick..... im havent implemented it yet.
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-15
Code (glbasic) Select

Remap on a [ps4 fun controller]|Hold [Down] with your primary [Left Stick/Pad]
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Face Bottom] Button|wait [5] to end mapping
Remap on a [ps4 fun controller]|Hold [Face Bottom] Button|wait [4] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Face Right] Button|wait [5] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Face Left] Button|wait [5] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Face Up] Button|wait [5] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Back Left Top] Button|wait [5] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Back Right Top] Button|wait [5] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Back Left Bottom] Button|wait [5] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Back Right Bottom] Button|wait [5] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
Remap on a [ps4 fun controller]|Hold [Dpad Down] Button|wait [5] to end mapping
Remap on a [ps4 fun controller]|Hold [Dpad Down] Button|wait [4] to end mapping
Remap Controller: [ps4 fun controller]|Dont touch any Sticks/buttons
FINISH


Also if dpad was used as a stick, the stick will been skipped (only uses as a hat), as im asume the controller dont have such of one.

Would works like this. Currectly working from logcat. Still working on it. Should show Key rather than button when on keyboard. hihi.
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: bigsofty on 2022-Nov-15
Yeah, logically you can just treat the keyboard as a controller but with a lot of buttons.  :S Confusing the matter slightly is that of international keyboards, where KEY() does not equate to a certain ascii character. So any game default keyboard have to take this into consideration when informing the user what key to press for what action.

Looking good so far Spacefractal!  :good:
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-16
Im should here possible to return which key that is used for a partical button, then up to the game to uses it.

Anyway, far from all glbasic games uses a fulll game controller. Most games only uses few input, so you dont need to remap a full controller, if its not needed by the game.

etc example a stick/dpad and 2 buttons.

Same with keyboard. Games that uses all buttons, would property been a keyboard/mouse game. Mouse is not used by the gameinput.

Powerup Elevation is example a case im dont uses gameinput for the keyboard (can been checked), if a player is a keyboard or not. This is due nature of the game.
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-16
now im is forced to break the sdl style database, so im could extends it a bit, when you doing remapping. etc example combination of keyboard and arcade controller. The way we using on Android is also a little bit different as we need to scan the controller using KEY() anyway. No idea how its worked with android sdl throught.

The only one that is fixed by now on keyboard, that is the ESCAPE button. That is allways on Back. Im is still missing to do a example, get a interface to start/finish it, get the save done. But the main thing, the main thing seens working, a least on Windows.

Its would look like this when doing on a keyboard:
Code (glbasic) Select

Remap Your [Keyboard]|Press [Movement Down] key
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press [Movement Right] key|wait 10 to finish
Glbasic ImageLoad: Graphics/preview2.png
Remap Your [Keyboard]|Press [Movement Right] key|wait 10 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press [Movement Left] key|wait 10 to finish
Remap Your [Keyboard]|Press [Movement Left] key|wait 10 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press [Movement Up] key|wait 10 to finish
Remap Your [Keyboard]|Press [Movement Up] key|wait 10 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press The [Jump] key|wait 10 to finish
Remap Your [Keyboard]|Press The [Jump] key|wait 9 to finish
Remap Your [Keyboard]|Press The [Jump] key|wait 8 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press The [Turn] key|wait 10 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press [Cursor Down] key|wait 10 to finish
Remap Your [Keyboard]|Press [Cursor Down] key|wait 9 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press [Cursor Right] key|wait 10 to finish
Remap Your [Keyboard]|Press [Cursor Right] key|wait 10 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press [Cursor Left] key|wait 10 to finish
Remap Your [Keyboard]|Press [Cursor Left] key|wait 10 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard
Remap Your [Keyboard]|Press [Cursor Up] key|wait 10 to finish
Remap Your [Keyboard]|Dont touch any keys on your keyboard


The cursor keys was actuelly just a test, not need in that game, lol. hihi.
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-16
and this one should been much easier to integrate than the old GameInput remapping system, which was qutie costumesome and actuelly limited.

In the old system, you was more or less needed to integrate that by you self, which is not need now, only require to call a init, and checking a string and checks when its finished.... that it.

Something like this:
Code (glbasic) Select

LOCAL result=GameInput.Remap_ScanCode(0, "back:back/pause|*,start:start|*,leftx:Left Stick|Movement,a:Face Bottom|Jump,b:Face Right|Turn,x:Face Left|*,y:Face Up|*,leftshoulder:Back Left Top|*,rightshoulder:Back Right Top|*,LeftTrigger:Back Left Bottom|*,RightTrigger:Back Right Bottom|*,dpdown:Dpad Down|*,rightx:Right Stick|Cursor,dpright:Dpad Right|*,dpup:DPad Up|*,dpleft:DPad Left|*,leftstick:Left Stick|*,rightstick:Right Stick|*")
IF result=TRUE
DEPRINT(GameInput.Remapping$) // only for testing
DEPRINT("FINISH")
ELSE
DEPRINT(GameInput.RemapStatus$) // the output.
ENDIF


Still missing a way to init it (its start right way as its does now, not intended).
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: bigsofty on 2022-Nov-17
Looks good, I like the nice short syntax.

I haven't used Android for years though, so I cant comment on do's and dont's for that input system I'm afraid.  :noggin:
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-17
Android threat gamepads as keyboard and is even worse than the Windows does. You newer know which keys a button send. This was the main thing why im changed KEY() to use float rather than integer as its was needed for Android as im remember.

Im also reouted the sticks to been KEY(241) to 256 as well, and does also support multiple players (keys 0-255, 256-511 and so on).
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: erico on 2022-Nov-17
Great work! I recall trying to add psx joys were terrible :D
Title: Re: Updating GameInput API (previous wanted to check Switch)
Post by: spacefractal on 2022-Nov-20
Im have annonced with full source code:
https://www.glbasic.com/forum/index.php?topic=11566.0


Yep PS4 and xbox has some differents. also if you checking the sld list, some controllers has id all the place, which is why im chossen to have a better remap system as main focus rather than implement the database.

Except some standard configuration.