Joystick disconected = huge slowdown !

BlitzMax Forums/BlitzMax Programming/Joystick disconected = huge slowdown !

Armitage 1982(Posted 2008) [#1]
Today I discovered a strange new bug.

My game use a joystick for additional player.
This is hard coded for the moment and only use joyY(), joyX() and joyDown() each frame

In order to try my game somewhere else I disconnected my serial gravis joypad.

Without this joypad plug into my computer my game run at 8fps while +100 when plugged-in !!

Don't know if it's a normal behaviour for blitzMax but it's not a good thing through...


jkrankie(Posted 2008) [#2]
i had this problem when i had joycount() in the main loop. maybe you're doing the same?

Cheers
Charlie


Armitage 1982(Posted 2008) [#3]
Thanks
Unfortunately I did not use joycount() at all :(
Only
2x JoyX()
2x joyY()
and 2x JoyDown()


Brucey(Posted 2008) [#4]
It's probably the internal call to SampleJoy that is killing it.

Can't you rather use a flag instead to say whether a joystick is "live" or not? Then you can skip joystick checks when false... or something similar.


iprice(Posted 2008) [#5]
I've recently added joystick routines into my game without any obvious slowdown whether a pad is connected or not. And I haven't used a JoyCount() either, just Joyx(0) etc.

Can you post a bit of code?


TaskMaster(Posted 2008) [#6]
If there is no joystick connected, then don't make calls to the joystick.


VicViper(Posted 2008) [#7]
I had the same problem.

Joycount returns the number of joysticks. If you test joystick input without joystics in your computer, sometimes slowdown.

I solved it put a if in the joysticks's actions:

if ( joycount()>0 )
'test joysticks inputs
endif

All the joysticks test input between this if conditional :
if ( joycount() > 0 )
......
......
......
endif

Sorry for my bad english.


TaskMaster(Posted 2008) [#8]
Only check joycount() when the program starts. Don't keep checking it over and over.


VicViper(Posted 2008) [#9]
You can do this :)

'Start program
if joycount() > 0 JoyExist = true


'loop game

if JoyExist
'Test Joyinputs
endif


VP(Posted 2008) [#10]
If you don't test joycount() on a regular basis, you can't test for the situation where the player disconnects the pad in the middle of a game.

Can't you just add some logic to test joycount() once a second, or does the call to joycount() give such a big hit that it will cause an immediate stutter when called?


plash(Posted 2008) [#11]
If calling commands that try to interact with a joystick that isn't plugged in is slowing you down you should use a timer of like 8 seconds to look for new joysticks (as the JoyExist variable).


Gabriel(Posted 2008) [#12]
Clearly, it's a bit like pinging a website. If the answer is no, it can take a long time to get that answer, because you have to wait for it to timeout. Perhaps there is some way to adjust the timeout? I don't think I'd like that solution much, but maybe as a last resort.

If you don't test joycount() on a regular basis, you can't test for the situation where the player disconnects the pad in the middle of a game.

Isn't there some kind of message from the operating system which would be thrown when you insert a joystick? I mean even if it's only generic, like some kind of input device or even a generic peripheral, it would be much better to only poll once after that even, rather than all the time.


TaskMaster(Posted 2008) [#13]
If you have to tell your user that he unplugged his joystick, he doesn't need to be playing. :)


Ginger Tea(Posted 2008) [#14]
If you have to tell your user that he unplugged his joystick, he doesn't need to be playing. :)


break away cables and flat batteries?


TaskMaster(Posted 2008) [#15]
And if the game quits responding, wouldn't you check your cable and batteries? If your cable breaks away and you do not know it, then you are a knucklehead.

If you are just trying to be nice and have your program recognize it and pause, I guess that makes sense. I hadn't thought about that.


Ginger Tea(Posted 2008) [#16]
what does the xbox say in each case?
ive not had my pc connected 360 wired pad yank out (yet) as its not had far to go, (and ive not used it in an age so its in my bag of bits) but if its plugged in at the back (bad idea for a pad) would you even see the end?

there should be an automatic game pause written in for such occurances and not let someone die cos they cant move