Force engine joypad connection recheck...

Posted By: Anonymous

Force engine joypad connection recheck... - 06/18/13 18:08

Link to OP Link to OP in Starting with Gamestudio

I have a controller and would like to force a 'connected' recheck if the controller is turn-on/connected after the game starts. Currently joypads are only detected if attached/active before the game app starts. This is inconvenient to game players who learn that the game is joypad-able in the game options and then must restart the game to use the joypad.

I hope that this post is clear.

Thanks
Mal
Posted By: jcl

Re: Force engine joypad connection recheck... - 06/19/13 10:31

Yes, that makes sense. We'll add an option to initialize the joystick driver at runtime.
Posted By: Anonymous

Re: Force engine joypad connection recheck... - 06/19/13 15:58

Thank jcl. That will be a big help.
Posted By: Superku

Re: Force engine joypad connection recheck... - 05/15/14 13:52

Took me a while to find this thread but can you please try to add this functionality in the next months? Thanks!
Posted By: DLively

Re: Force engine joypad connection recheck... - 05/15/14 18:50

Yes this would be a great feature to have added ^_^
Posted By: Superku

Re: Force engine joypad connection recheck... - 09/30/14 10:10

Mr. Lotter, please see my previous post!
Posted By: Reconnoiter

Re: Force engine joypad connection recheck... - 09/30/14 15:48

I second that, please add it.
Posted By: Anonymous

Re: Force engine joypad connection recheck... - 10/12/14 04:21

Ha ha... My goodness. Talk about a dropped promise. Use the current work arounds
1) use a engine that adds simple features.Wasn't there an update after my request?
2) Don't use a controller. After all most pc games still don't include stable controller support.

Oh whats that? Most game on pc now offer it! Steam is building a whole market around controller input! But I love my mouse and keyboard! It is not annoying at all to restart my game because I got up to piss!

Sorry jcl, but blindly ingoring my only real request in years feels like a snub and a giggle.
Posted By: JibbSmart

Re: Force engine joypad connection recheck... - 10/12/14 07:49

Hey Malice, I managed to do it with Windows functions in KarBOOM before I switched to Unity:

Originally Posted By: JibbSmart
Basically, using the right windows function, you can poll all connected joysticks at any time, regardless of when they were connected.

OK, so, my code is a mess, and it's hard to be sure, but this will hopefully be helpful:

Code:
#include <windows.h>

UINT __stdcall joyGetPosEx(UINT, long);
#define PRAGMA_API joyGetPosEx;winmm!joyGetPosEx

#define JOYSTICK_SIZE 52
#define JOYSTICK_INDICES 13
#define JOYSTICK_XPOS 2
#define JOYSTICK_YPOS 3
#define JOYSTICK_ZPOS 4
#define JOYSTICK_RPOS 5
#define JOYSTICK_UPOS 6
#define JOYSTICK_VPOS 7
#define JOYSTICK_BUTTONS 8
#define JOYSTICK_POV 10
#define HALF_JOY 32768

DWORD joystick[JOYSTICK_INDICES];

function getJoy(int i) {
	// get joystick info and put it in our global array
	joystick[0] = JOYSTICK_SIZE;
	joystick[1] = JOY_RETURNALL;
	var r = joyGetPosEx(i, (void*)joystick);
	if (hasZAxis[i] == 0) {
		joystick[JOYSTICK_ZPOS] = HALF_JOY; // cancel out z axis when not available
	}
	return r;
}

function joyButton(int i) {
	i--;
	if (joystick[JOYSTICK_BUTTONS] & (1<<i))
		return 1;
	else
		return 0;
}

#define MIN_JOY 0.1
#define MAX_JOY 0.9

function joyNormalize(var value) {
	// here I can define a min and max value -- min gets scaled to zero, and max gets scaled to 1
	value = (value - HALF_JOY) / HALF_JOY;
	value -= sign(value) * minv(abs(value), MIN_JOY); // scale down zero
	value /= MAX_JOY - MIN_JOY; // scale up
	return clamp(value, -1, 1);
}


The important thing is joyGetPosEx (helpful reading material on its parameters here), a windows function (hence the need for #include <windows.h>).
So, if I recall correctly, it goes something like this...

Calling getJoy(n) will poll the nth joystick, populating the global array "joystick" (that DWORD array) with all the details of that joystick, if it is connected.

So, joystick[JOYSTICK_XPOS] will get you the raw x-axis position of the left stick. joyNormalize(joystick[JOYSTICK_XPOS]) will give it to you from -1 to +1, with a deadzone and a clamp on the top defined by MIN_JOY and MAX_JOY, respectively.

The buttons are all flags - individual bits - set in element 8 in the array (JOYSTICK_BUTTONS), so I have a function that lets you check if button i on the last-polled joystick (with getJoy) is being pressed: joyButton(i).

KarBOOM's kars will start each frame by calling "getJoy" and whatever number their joystick is. Then joyButton(i) and any use of joystick[] gives them information about their joystick. If getJoy gets called with a different joystick number before they're done with it for this frame, they'll start getting the wrong values. So you COULD change it to populate a different array for each joystick, which might simplify things.

Hopefully nothing's missing, and I hope that's helpful! I haven't looked at this stuff in a really long time. I understand I've been a bit vague - it's been a big day and I'm tired tongue But feel free to ask if anything isn't clear laugh


Superku apparently had problems with it, though, with some buttons not being responsive.
Posted By: Anonymous

Re: Force engine joypad connection recheck... - 10/12/14 19:00

@JibbSmart, thank you for this information.

Lite-c was the death of the real idea behind this engine. When I came into the loop, I was sold on a idea of very low coding was needed. Sure they claimed click-together. But I knew before joining, that was an over claim. The real claim was only having to master the scripting language. Which I have worked a long time to understand and be good at the 3dgs API(or so I will call everything covered in the manual).

When Lite-C was introduced, I stop hearing "This will be updated in the features...", instead as a user I was told time and time again, "You'll have to go outside the 3dgs API to do that." Lite-C gave the devs the ability to tell users that they were not going to update the features, but instead the users needed to learn to code beyond the 3dgs API.
e.g.
Q:Can you add file menus to 3dgs?
A:You can do this through the Windows API.
Q:Can you add rechecking for a joystick?
A: You can do this through the Windows API.

The expansions in to the Windows API and C libs is great for many programs. But it wasn't just a bad editor that drove people way. When you tell me all I have to do is learn the 3dgs API and then refuse to add things, because I now need to master and understand higher APIs, that is what drives all the users like me away.

I am fairly good at coding in this engine, and can not be called a Unity click-no-think game maker. And that is the promise I made when joining this engine. I do not need a Unity editor to make games, I need a robust scripting language that is regularly updated.

The facts are, many users here are far beyond the scripting level and the user that are not are being punished. The ability to reach beyond 3dgs into Windows and other libs for 'advanced' reasons is not excuse to stop developing the base API.

My request was made over a year ago, and if JibbSmart's answer works, there is no reason that a simple handful of commands can not be placed in the engine API for me -The User Mastering 3gds scripting and 3dgs API! Let the engine do the work in Windows API and give me a nice simple 3dgs command set.

That is the promise made to the buyers of this engine and the promise failed. We can build level and models in 3dsmax,We can paint in Gimp, we can mix sound in audacity, we can code and debug in Sed, we can adjust things and compile in Wed. All are old tools but still functioning.

The 3gds package meets all it's promises with these old tools, but the promise that the engine scripting would be updated so I would not need to learn beyond it's scripting for most thing is a failed promise. The replay shouldn't be "This is a simple thing you can do with the Windows API." That should never be the replay. Instead if it is a simple thing, than simply add it to the 3dgs API! Because I was promised only to need the higher API access for 'Advanced things' not SIMPLE!

If the devs want to chase cross platform compilers and direct-x 2020super tech, or other such things. That is great. But you have a handful of high level users left crying to you about these things, while your core user base vanished because they could not even get a recheck for a joystick. There were many click-and-make user who ran day one of the Unity march(ratchet). But since then you have lost 1000's of 3dgs script strong user like me.

I can rant for ever and I deserve to, to many years I have said little and hope for much.
Posted By: Superku

Re: Force engine joypad connection recheck... - 10/12/14 20:51

Originally Posted By: JibbSmart
Superku apparently had problems with it, though, with some buttons not being responsive.

Exactly, this is what I wrote/ experienced:

Quote:
Hm the control sticks (of my PS4) controller seem to work fine but the buttons don't. Every let's say 4 seconds the input is delayed (the state of at least one button changes too slowly, it takes about one second more than with joy_1,...).
If you have not experienced this don't worry, I will try to figure this out myself or go back to the joy_ implementation.

I cannot recreate this misbehavior right now though so there may have been some mistake on my side and its implementation. However, I am not sure what could have caused such an issue (which is what throws me off of the joyGetPosEx approach right now, I'd hate to deliver a game with sporadically unresponsive controls).
Posted By: JibbSmart

Re: Force engine joypad connection recheck... - 10/13/14 09:03

Originally Posted By: Superku
I'd hate to deliver a game with sporadically unresponsive controls
Yeah, fair enough!
© 2024 lite-C Forums