Blitz3D Xbox controller not working?

Started by hosch, June 04, 2020, 13:52:15

Previous topic - Next topic

hosch

Hi,

I've uploaded a testbuild of my current game jam game in the worklogs section: https://www.syntaxbomb.com/index.php/topic,7913.15.html

A friend of mine tried it out and reported that his Xbox controller wasn't working with the game. Mine is.

Did any of you encounter this problem before? Could you play the test build and see, if your controller works?

Thanks!

Dan

I'v got an PDP Wired Xbox one controller.


The controler is not working in this game.

(At first it did, but then i realized that the "Antimicro joy2key" was running, which i use to run older not compatible games with the controller)


If you like, i have here an program, which i used for another project, to set up the keyboard/joypad keys, and it is working with my joypad:


AppTitle "Keyboard checker"
Screen 320,200,2
SetBuffer BackBuffer()

Global key_down=208,key_up=200,key_left=203,key_right=205,key_btn=29,key_btn1=157,JoyPort=0,JoyButton=1
Global Key_ValueCheck[8],Key_Menu$[7]
Repeat
Key_Change()
Delay 100
Cls
Color $ff,$ff,$ff
Text 1,10,key_up
Text 1,20,key_down
Text 1,30,key_left
Text 1,40,key_right
Text 1,50,key_btn
Text 1,60,key_btn1
Text 1,70,JoyPort
Text 1,80,JoyButton
FlushKeys
Flip
Delay 500
WaitKey()
While KeyDown(57) : Delay 1 : Flip : Wend
FlushKeys
Until KeyDown(1)

Function Key_Change()
Local kleft,kup,kright,kdown,kb1,kb2,menu=1,x,y,xloop,menudelay=MilliSecs(),s,t,duplicate=0,quit,J_Btn
SetBuffer BackBuffer()

Key_Menu[1]="Up"
Key_Menu[2]="Down"
Key_Menu[3]="Left"
Key_Menu[4]="Right"
Key_Menu[5]="Btn1"
Key_Menu[6]="Btn2"
Key_Menu[7]="Joy Port:Btn"

Key_ValueCheck[1]=key_up
Key_ValueCheck[2]=key_down
Key_ValueCheck[3]=key_left
Key_ValueCheck[4]=key_right
Key_ValueCheck[5]=key_btn
Key_ValueCheck[6]=key_btn1
Key_ValueCheck[7]=JoyPort
Key_ValueCheck[8]=JoyButton
quit=0
Repeat
Cls
Color $ff,$ff,$ff
Line 0,30,320,30
Line 0,170,320,170
Text 1,2,"Change the Keyboard Bindings"
Text 55,14,"(Arrow Up+Down, Return to select)"
Text 1,170,"Press esc to return without saving"
If duplicate=0
Text 1,183,"Press space to save and exit"
Else
Text 1,183,"The bindings won't be saved!"
EndIf
Text 120,33,"Key Name      Value"
Color $ff,$ff,0
Line 120,45,272,45
Line 120,150,272,150
If duplicate>0 Then Color $ff,0,0 : Text 120,155,"Duplicate found"
If KeyDown(208) And MilliSecs()-menudelay>250 Then menu=menu+(menu<7)  : menudelay=MilliSecs()
If KeyDown(200) And MilliSecs()-menudelay>250 Then menu=menu-(menu>1)  : menudelay=MilliSecs() 

For xloop=1 To 7
Color $ff,$ff,$ff
If BitState(duplicate,xloop)=1 Then Color $ff,0,0
If xloop=menu
Color $0,$ff,$0
If BitState(duplicate,xloop)=1 Then Color $00,$80,$00
EndIf

If xloop<7
Text 120,32+(15*xloop),LSet(Key_Menu[xloop],12)+" = "+Key_ValueCheck[xloop]
Else
Text 120,32+(15*xloop),LSet(Key_Menu[xloop],12)+" = "+Key_ValueCheck[7]+":"+Key_ValueCheck[8]
EndIf
Next

kup=KeyDown(Key_ValueCheck[1]) Or (JoyHat(Key_ValueCheck[7])=0)
kdown=KeyDown(Key_ValueCheck[2]) Or (JoyHat(Key_ValueCheck[7])=180)
kleft=KeyDown(Key_ValueCheck[3]) Or (JoyHat(Key_ValueCheck[7])=270)
kright=KeyDown(Key_ValueCheck[4]) Or (JoyHat(Key_ValueCheck[7])=90)
J_Btn=JoyDown(Key_ValueCheck[8],Key_ValueCheck[7])
kb1=KeyDown(Key_ValueCheck[5]) Or J_Btn
kb2=KeyDown(Key_ValueCheck[6]) Or J_Btn

Color $ff,$ff,$ff
Rect 10,80,30,30,kleft ;Left
Rect 40,50,30,30,kup ;Up
Rect 70,80,30,30,kright ;Right
Rect 40,110,30,30,kdown ;Down
Oval 75,40,30,30,kb1 ;B1
Oval 75,120,30,30,kb2 ;B1a

If KeyDown(28)
If menu<7 Then While KeyDown(28): Delay 1 : Flip : Wend : FlushKeys : Goto Getthekey
If menu=7 Then Goto getthejoypadbtn
EndIf

.back
Flip (1)
Delay 1
If KeyDown(1) Then quit=1 ;Esc
If KeyDown(57) Then quit=2 ;Space
Until quit>0

If duplicate>0 Then quit=1
If quit=1 Then While KeyDown(1):Delay 1:Flip:Wend: Return
If quit=2 Then While KeyDown(57):Delay 1:Flip:Wend

Goto setthekeysback ;Exit of the function

.Getthekey
Color $ff,$ff,$ff
s=0
menudelay=MilliSecs()
Repeat ;Keyboard routine
Cls
t=Int((MilliSecs()-menudelay)*0.001)
Text 0,0,"Press the desired key for "
Text 0,20,">"+Key_Menu[menu]+"<"
Text 0,40,"Returning at 10 : "+(t)
For x=1 To 255
If KeyDown(1)=1 Then s=1
If x>1 And KeyDown(x)=1 Then While KeyDown(x) : Delay 1 : Wend : Key_ValueCheck[menu]=x : s=1 : Exit
Next
Flip
Until s=1 Or t=>10

While KeyDown(1) : Delay 1 : Flip : Wend : FlushKeys
menudelay=MilliSecs()

duplicate=0
For x=1 To 6 ;Duplicate checker
For y=1 To 6
If x<>y
If Key_ValueCheck[x]=Key_ValueCheck[y] Then duplicate=BitSet(duplicate,y)
EndIf
Next
Next

Goto back

.getthejoypadbtn
s=0
menudelay=MilliSecs()
Repeat ;Joypad routine
Cls
t=Int((MilliSecs()-menudelay)*0.001)
Text 0,0,"Press the Jump button on your joypad "
Text 0,40,"Returning at 10 : "+(t)
For x=0 To 10 ;Joystick Port number
For y=0 To 20 ;Joystick buttons
If KeyDown(1)=1 Then s=1
If JoyDown(y)<>0 Then While JoyDown(y)<>0 : Delay 1 : Wend : Key_ValueCheck[7]=x :Key_ValueCheck[8]=y: s=1 : Exit
Next
Next
Flip
Until s=1 Or t=>10

While KeyDown(1) : Delay 1 : Flip : Wend : FlushKeys
menudelay=MilliSecs()
Goto back

.setthekeysback
key_up=Key_ValueCheck[1]
key_down=Key_ValueCheck[2]
key_left=Key_ValueCheck[3]
key_right=Key_ValueCheck[4]
key_btn=Key_ValueCheck[5]
key_btn1=Key_ValueCheck[6]
JoyPort=Key_ValueCheck[7]
JoyButton=Key_ValueCheck[8]
End Function

Function Screen(x,y,zoom#=1)
If x<64 Then x=64
If y<64 Then y=64
    bits=32
Graphics x*zoom,y*zoom,bits,2
Graphics x,y,bits,3
End Function

Function BitState(a,b)
;a = variable
;b = bit number to Check (1 is the 1st bit)
Return Mid(Bin$(a),Len(Bin$(a))-(b-1),1)
End Function

Function BitSet(a,b)
Local y,x
;a = variable
;b = bit number to set (reminder: bit #1 is the rightmost bit: %101001110[1] <- )
y=1
For x=0 To b
If x<=1
y=x
Else
y=y*2
EndIf
Next
Return y Or a
End Function


It would be nice, if you could compile it with your bb version and upload it.
65536 GOTO Back2Basic

hosch

Hi,

thanks for your feedback. I was afraid, it wouldn't work with a Xbox controller. Seems to be a Xinput issue. Would you be so kind and test, if you get any controller response with the program I am supplying in my attachment?

Sure, I will see/have a look what I can do with your code. Unfortunately I am a bit under time constraints due to it being a jam game, but I will check it out.

STEVIE G

Does it use the analogs? What joy commands are you using to detect them? I think joyx and joyy cover one stick and joyhat the other. On my ps pad  left stick is joyx and joyy but right is joy roll and joyu or something like that.  You should be ok using joyx and joyy on any pad but not joyhat.

hosch

#4
Quote from: STEVIE G on June 04, 2020, 16:08:47
Does it use the analogs? What joy commands are you using to detect them? I think joyx and joyy cover one stick and joyhat the other. On my ps pad  left stick is joyx and joyy but right is joy roll and joyu or something like that.  You should be ok using joyx and joyy on any pad but not joyhat.

I am using JoyXDir/JoyYDir and Joyhit. Looks like I need to use JoyX, right?

But I've investigated further. He is telling me, that his gamepad *apparently* isn't even recognized by Blitz3D. I am checking beforehand, if a joystick is connected (with JoyType) and the result of this check determines, if a gamepad can be used. Seems like the check fails. He lives a bit far from me, so I can't really check it myself unfortunately.

Dan

#5
Hi,

Quote from: hosch on June 04, 2020, 16:00:05
Seems to be a Xinput issue. Would you be so kind and test, if you get any controller response with the program I am supplying in my attachment?

Sorry, the attached program does not react to the joypad.


edit: I'v started the example code for the JoyType() command, from the blitzbasic help, and it does report an digital Joystick.

Can you paste the code from the xbox360.zip ?
65536 GOTO Back2Basic

hosch

#6
Yes, of course. It wasn't made be me - it is from the internet and public domain and the author stated, it would handle a Xbox 360 controller.

Graphics 1920,1080,32,1
SetBuffer BackBuffer()
;XBox 360 controller library for Blitz3D by Earok (Earok.Net)

;I declare this code to be in the public domain





;This library provides complete XBox 360 controller support except for the following limitations:

;1. No force feedback support

;2. Left and Right triggers cancel each other out. Holding them both down is the same as holding neither down.

;3. No support for the center glowing button



;Constants defining every XBox 360 button, just pass these to the standard joyhit, joydown functions etc.

Const x360_button_a = 1

Const x360_button_b = 2

Const x360_button_x = 3

Const x360_button_y = 4

Const x360_button_lb = 5

Const x360_button_rb = 6

Const x360_button_back = 7

Const x360_button_start = 8

Const x360_button_lts = 9

Const x360_button_rts = 10



;Uncomment the next line to run an example controller application

DemoProgram()
;


;This trims out small values from not quite centered analogue sticks and triggers.  You don't need to call this from your game.

;Alter trim value to adjust the "dead zone" from the stick/trigger center.

Const x360_trim_value# = 0.20

Function x360_Trim#(value#)



If(Abs(value#) > x360_trim_value#) Return value#



End Function



;Returns the left trigger value

Function x360_LTrigger#(port=0)



If (JoyZ(port) > x360_trim_value#) Return x360_Trim#(JoyZ(port))



End Function



;Returns the right trigger value

Function x360_RTrigger#(port=0)



If JoyZ(port) < (0 - x360_trim_value) Return x360_Trim#(JoyZ(port)) * -1



End Function



;Returns the X value on the D-Pad

Function x360_DPadX(port=0)



If JoyHat(port) > -1 Then Return x360_Trim#(Sin(JoyHat(port)))



End Function



;Returns the Y value on the D-Pad

Function x360_DPadY(port=0)



If JoyHat(port) > -1 Then Return -x360_Trim#(Cos(JoyHat(port)))



End Function



;Returns the X value on the Left Thumbstick

Function x360_LeftStickX#(port=0)



Return x360_Trim#(JoyX(port))



End Function



;Returns the Y value on the Left Thumbstick

Function x360_LeftStickY#(port=0)



Return x360_Trim#(JoyY(port))



End Function



;Returns the X value on the Right Thumbstick

Function x360_RightStickX#(port=0)



Return x360_Trim#(Sin(JoyPitch(port) / 2))



End Function



;Returns the Y value on the Right Thumbstick

Function x360_RightStickY#(port=0)



Return x360_Trim#(Sin(JoyYaw(port) / 2))



End Function



;Demo application For Xbox 360 controller support

Function DemoProgram()



Local ButtonDefs$[11]

ButtonDefs[0] = "None"

ButtonDefs[1] = "A"

ButtonDefs[2] = "B"

ButtonDefs[3] = "X"

ButtonDefs[4] = "Y"

ButtonDefs[5] = "Left Shoulder"

ButtonDefs[6] = "Right Shoulder"

ButtonDefs[7] = "Back"

ButtonDefs[8] = "Start"

ButtonDefs[9] = "Left Thumbstick"

ButtonDefs[10] = "Right Thumbstick"



While Not KeyHit(1)



Cls()



Text 0,00,"Stick Left X: " + x360_LeftStickX()

Text 0,20,"Stick Left Y: " + x360_LeftStickY()

Text 0,40,"Stick Right X: " + x360_RightStickX()

Text 0,60,"Stick Right Y: " + x360_RightStickY()

Text 0,80,"Left Trigger: " + x360_LTrigger()

Text 0,100,"Right Trigger: " + x360_RTrigger()

Text 0,120,"DPad X: " + x360_DPadX()

Text 0,140,"DPad Y: " + x360_DPadY()



lastpressed = GetJoy()

If lastpressed > 0 Then press = lastpressed

Text 0,160,"Button Pressed: " + ButtonDefs[press]

Text 0,200,"Press Escape to quit"



Flip()



Wend
EndGraphics
End


End Function


I wish I knew what is the issue, I can't release like that  :'(

hosch

#7
Quote from: Dan on June 04, 2020, 14:37:32
I'v got an PDP Wired Xbox one controller.


The controler is not working in this game.

(At first it did, but then i realized that the "Antimicro joy2key" was running, which i use to run older not compatible games with the controller)


If you like, i have here an program, which i used for another project, to set up the keyboard/joypad keys, and it is working with my joypad:

It would be nice, if you could compile it with your bb version and upload it.

Here you go, this is the compiled version of your code. It doesn't seem to detect *my* gamepad now :))

Edit: Oh no, I was mistaken, it works with my gamepad!

Dan

Ok, i'v attached the compiled version of the code. It works here, but your compiled version does not.

The Keyboard Checker does not work here, it shows the up key as being always pressed.

I guess it is up to the blitzbasic version ...
65536 GOTO Back2Basic

hosch

Quote from: Dan on June 04, 2020, 20:55:34
Ok, i'v attached the compiled version of the code. It works here, but your compiled version does not.

The Keyboard Checker does not work here, it shows the up key as being always pressed.

I guess it is up to the blitzbasic version ...

Oh my. Which version are you using? I am using a version that had directplay removed, I believe.

Dan

#10
I'm using the 1108 from blitzbasic.com

and the version from https://blitzresearch.itch.io/blitz3d works too.

(p.s. if you want to test it, then make a backup, before installing the version from itch.io)
65536 GOTO Back2Basic

hosch

#11
Thanks for your reply. I've uploaded a build made with the version from itch.io at the end of the worklog page:
https://www.syntaxbomb.com/index.php/topic,7913.15.html

It would be very nice of you, if you could try again. What is strange is, that it doesn't even trigger the request for directplay (your build did). Damn  ???

I will buy a Xbox 360/Xinput controller today, so I don't have to annoy you guys anymore  :D

Dan

#12
Hmm, the Game still does not respond to the joypad.

I have noticed that both games (the .exe) have the same crc (if you check both downloads) ?! They are basically identical.
65536 GOTO Back2Basic

Dan

#13
iv tested the bb joypad commands, and these work with my xbox controller:


While Not KeyHit(1)
jyaw#=JoyYaw()
jpitch#=JoyPitch()
Cls
Text 0,0,"Joy X Direction: " + JoyXDir() + " Y= " + JoyYDir()
Text 0,10,"Joy X Value: " + JoyX() + " - Joy Y Value:" + JoyY()
Text 0,20,"Joy Z Value: " + JoyZ()
Text 0,30,"Joy Hat: " +JoyHat()
Text 0,40,"JoyYaw(): "+jyaw#
Text 0,50,"JoyPitch(): "+jpitch#

Wend

65536 GOTO Back2Basic

hosch

Very strange. Does the game detect the Joypad at all? In the options menu it should show a red questionmark, if it doesn't.

I can't seem to figure out what's wrong.

Did I code it wrong?

If p1_use_gamepad = True Then
Select JoyType(0)
Case 0
p1_use_gamepad = False
p2_use_gamepad = False
p1_gamepad_connected = False
p2_gamepad_connected = False
Case 1,2
Select JoyType(1)
Case 0
p2_use_gamepad = False
p2_gamepad_connected = False
p1_gamepad_connected = True
; DebugLog "NO JOYSTICK ON PORT 1! PLAYER 2 USE KEYBOARD!"
Case 1,2
p2_use_gamepad = True
p1_gamepad_connected = True
p2_gamepad_connected = True
; DebugLog "JOYSTICK ON PORT 1! ALL PLAYERS USE GAMEPAD!"
End Select
End Select
End If


Would you be willing/able to supply the version from blitzbasic.com that you built the other program with? I'm losing my mind over here  :o