yuv422 / cosmo-engine

A new game engine to play the MS-DOS game "Cosmo's Cosmic Adventure" on modern systems
GNU General Public License v2.0
58 stars 12 forks source link

Input: Add SDL_GameController Backend #15

Closed Ryzee119 closed 4 years ago

Ryzee119 commented 4 years ago

I wrote a SDL_GameController backend for a port I am working on.

I appreciate there is probably many ways of doing this so will leave up to the author of this repo if they would like to merge or they had something else in mind. Happy to make changes if requested.

Benefits of this way:

Current the mapping is as follows but happy to change based on feedback

What it doesn't do:

I have tested with my wired Xbox360 controller.

This will potentially close issue #12

BeWorld2018 commented 4 years ago

hi

Work fine, thanks. Maybe you can add Axis, i create it working in game only (not use your function) if (event.type == SDL_CONTROLLERAXISMOTION) { switch (event.caxis.axis) { case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_RIGHTX: if (event.caxis.value < -16384) { left_key_pressed = 1; } else { left_key_pressed = 0; } if (event.caxis.value > 16384) { right_key_pressed = 1; } else { right_key_pressed = 0; } break; case SDL_CONTROLLER_AXIS_LEFTY: case SDL_CONTROLLER_AXIS_RIGHTY: if (event.caxis.value < -16384) { input_up_key_pressed = 1; } else { input_up_key_pressed = 0; } if (event.caxis.value > 16384) { down_key_pressed = 1; } else { down_key_pressed = 0; } break; } } You can close gamepad and maybe SubSystem for better integration ?

void gamepad_shutdown() {
    if (gamepad != NULL) {
        SDL_GameControllerClose(gamepad );
    }
        SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
}

thanks

Ryzee119 commented 4 years ago

Thanks :smile: I'll add the deinit for sure and see what the best way of integrating the axis code is. I should be able to use your code snippet or close to it

yuv422 commented 4 years ago

Hi Ryzee119, I'm currently working on controller support too. So I probably won't merge this PR. I'm refactoring the input handling a bit to get rid of key repeat and to implement controller mapping via the redefine menu.

Ryzee119 commented 4 years ago

No problem. Thanks for your work on this awesome game :)

I'll keep an eye out for future updates