Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding INPUT_BUTTONS
#1
Wink 
Hello! I need more keys for my application and wish to keep using the supplied Window.

For instance I needed to take control of ESC key so I asked mark and he pointed me towards Window.c, 663, I commented that and assigned INPUT_START to ESC and voila! TLN_DefineInputKey(PLAYER1,INPUT_START,SDLK_ESCAPE);

ESC is mine again.

So now I need more keys but I noticed bizarre errors when a certain number of buttons is reached. For instance:

Code:
TLN_DefineInputKey(PLAYER1,INPUT_BUTTON7,SDLK_KP_7);
TLN_DefineInputKey(PLAYER1,INPUT_BUTTON8,SDLK_KP_8);
TLN_DefineInputKey(PLAYER1,INPUT_BUTTON9,SDLK_KP_9);
TLN_DefineInputKey(PLAYER1,INPUT_BUTTON_KP_4,SDLK_KP_4);
TLN_DefineInputKey(PLAYER1,INPUT_BUTTON_KP_5,SDLK_KP_5);
TLN_DefineInputKey(PLAYER1,INPUT_BUTTON_KP_6,SDLK_KP_6);
TLN_DefineInputKey(PLAYER1,INPUT_BUTTON_KP_2,SDLK_KP_2);

The first buttons added worked great, but I started to have problems on INPUT_BUTTON_KP_4 (keypad), it didn't work, furthermore KEYPAD 2 took the behaviour of INPUT_BUTTON8 and ESC stopped working.

I think the culprit is here: (540 Window.c)

Code:
static void SetInput (TLN_Player player, TLN_Input input){
    player_inputs[player].inputs |= (1 << input);
    last_key = input;
}

I would like a little explanation of that shift << and the operator |= to get what is happening here and be able to add INPUT_BUTTONS add leisure and associate with the SDLK keys that I wish.

Thanks for your time and patience.
Reply
#2
Hello! Sorry for the delay answering.

The limitation is here: Window.c, line 61 defines the input as a bitmask of 16 bits:

Code:
uint16_t inputs;

This allows a total of 16 unique inputs per player, including directions and action buttons. A cheap way would be to just upgrade the line this way:

Code:
uint32_t inputs;

this would allow for a total of 32 unique inputs per player. More than 32 inputs would require another paradigm. I hope this helps you!
Reply
#3
Thank you very much Marc!

That was exactly what I needed.

I hope to post a video of our game with Tilengine in one month or two, hopefully.

I will keep you informed!!!
Reply
#4
You're welcome, and I hope to see your work soon!
Reply
#5
Still having some trouble.

Changed this as well:
Code:
#define MAX_INPUTS    32

I think this changes as well:

Code:
void TLN_DefineInputKey (TLN_Player player, TLN_Input input, uint32_t keycode){

    player_inputs[player].keycodes[input & 0x1F] = keycode;

}

instead of [input & 0xF]. Because 0xF --> 15 and 0x1F --> 31

But at you sure this shift doesn't change?

I'm pretty sure the culprit is this shift: 1 << input

Code:
player_inputs[player].inputs |= (1 << input);

I traced all the flow of the program until this. Desperately and without knowing what I was doing I tried without the shift or other numbers or other shifting directions but it doesn't work,

I don't quite understand what is going on with that specific shift Sad Could you please be so kind tell me how this 1 << input changes as well to allow for 32 inputs max?

I appreciate your help a lot. Thank you for your time and patience.
Reply
#6
Sorry about that! I've just realized that I was wrong, or at least it's a bit more complex than the quick response I gave yesterday.

You're right about your proposed changes on #define MAX_INPUTS being 32 and the input mask going from 0xf to 0x1f. What's missing here is that the TLN_GetInput() function expects a bitmask of the input identifier encoded in the lower 4 bits, and the player identifier encoded in the next two bits. This function isn't aware of the change to the number of bits used for input has increased, displacing the position used by the player identifier.

I'll revise this one and push an update, stay tuned.
Reply
#7
Thank you very much!

Ok, I will aware for the update! Smile
Reply
#8
Hi!

I've just pushed Release 2.1.2 with up to 32 inputs per player and redefinable inputs for window close and CRT toggle:
http://tilengine.org/forum/showthread.php?tid=239

Now you can reassing the ESC and BACKSPACE keys for your own tasks, and/or disable the keybindings for those predefined functions.
Reply
#9
Hey! Awesome!!! Thank you very much marc!! Biggrin
Reply
#10
This update should be really useful. I realize that 16 inputs per player might seem like a lot. But in this modern age of extremely complex controllers, it doesn't quite provide as many as a developer would like. 32 should allow for a number of possibilities.

The original JAMMA standard only called for one joystick and three buttons per player. The famous Street Fighter II wiring harness was tacked on to allow the needed extra buttons to bring the total up to six per player. We have certainly become spoiled in our era of multiple analog sticks per controller.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)