Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joystick or controls #135

Open
Noisk8 opened this issue Nov 21, 2018 · 5 comments
Open

joystick or controls #135

Noisk8 opened this issue Nov 21, 2018 · 5 comments

Comments

@Noisk8
Copy link

Noisk8 commented Nov 21, 2018

Is it possible to change the controls or use a joystick?
what would be the proper way to include SDL_joystick in the ActorController.cpp and .h file?

@pjasicek
Copy link
Owner

Uh, haven't seen the code for quite some time :) But here goes:

  1. Create some new config option in config.xml file, e.g. true and save it to BaseGameApp::m_GlobalOptions at startup with default value for this being false.

  2. In these methods:

ActorController::Update
ActorController::VOnKeyDown
ActorController::VOnKeyUp

Implement custom logic based on the key which is being handled.

  • In ActorController::Update you should handle keys which are polled every frame - e.g. get position of the joystick and translate it to move/climb/jump speed/direction
  • In ActorController:VOnKeyDown/VOnKeyUp handle events - like when you press a joystick button and want to shoot or attack - this is handled here

Someone added some "alternate" controls via some pull request which enabled controlling of claw via WASD and shotting/attack through mouse buttons. This is distinguished by e.g. this line:

https://github.com/pjasicek/OpenClaw/blob/master/OpenClaw/ActorController.cpp#L55

Hope this helps.

@Noisk8
Copy link
Author

Noisk8 commented Nov 22, 2018

Thanks to see if I understand, I am not clear how to do the config.xml file, I use linux and see that there is a config file linux

the line would be something like this?

(SDL_GetScancodeFromKey(key) == SDL_SCANCODE_LALT || SDL_GetScancodeFromKey(key) == SDL_CONTROLLER_BUTTON_A )

@pjasicek
Copy link
Owner

Well I looked at the "Controller" abstraction code by SDL and it is not that simple at all. Game Controller input is handled by a different subsystem so it is handled differently than keyboard. You can look here for more details:

http://lazyfoo.net/tutorials/SDL/19_gamepads_and_joysticks/index.php

In the engine startup routine you would have to add initialization of the SDL Game Controller and keep the reference to the controller somewhere in the g_pApp. Then when processing input you would have to check for any game controller events and handle them accordingly.

@mialy
Copy link

mialy commented Feb 9, 2019

Here are 3 commits for my basic implementation of controller support: https://github.com/mialy/OpenClaw/commits/controllers

I'm really bad at C/C++, and what stops me even more is I was unable run build on Windows with Visual Studio (Linux works though) . Still, implementation supports Xbox One S controller + some other NES-like, but with fixed buttons, meaning if button "1" in your controller is identified as "menu" and not "A" or "X" button, you have bad luck. My plan was to implement key mapping in C# launcher, but now I haven't much time.
I'm glad, If this code could helps somebody.

@Noisk8
Copy link
Author

Noisk8 commented Mar 4, 2019

If I connect my joystick is activated the menu controls? or just activates the buttons automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants