{"action":"created","issue":{"url":"https://api.github.com/repos/chocolate-doom/chocolate-doom/issues/897","repository_url":"https://api.github.com/repos/chocolate-doom/chocolate-doom","labels_url":"https://api.github.com/repos/chocolate-doom/chocolate-doom/issues/897/labels{/name}","comments_url":"https://api.github.com/repos/chocolate-doom/chocolate-doom/issues/897/comments","events_url":"https://api.github.com/repos/chocolate-doom/chocolate-doom/issues/897/events","html_url":"https://github.com/chocolate-doom/chocolate-doom/issues/897","id":216806779,"number":897,"title":"New joystick interface","user":{"login":"Wintermute0110","id":7764978,"avatar_url":"https://avatars0.githubusercontent.com/u/7764978?v=3","gravatar_id":"","url":"https://api.github.com/users/Wintermute0110","html_url":"https://github.com/Wintermute0110","followers_url":"https://api.github.com/users/Wintermute0110/followers","following_url":"https://api.github.com/users/Wintermute0110/following{/other_user}","gists_url":"https://api.github.com/users/Wintermute0110/gists{/gist_id}","starred_url":"https://api.github.com/users/Wintermute0110/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wintermute0110/subscriptions","organizations_url":"https://api.github.com/users/Wintermute0110/orgs","repos_url":"https://api.github.com/users/Wintermute0110/repos","events_url":"https://api.github.com/users/Wintermute0110/events{/privacy}","received_events_url":"https://api.github.com/users/Wintermute0110/received_events","type":"User","site_admin":false},"labels":[{"id":257673003,"url":"https://api.github.com/repos/chocolate-doom/chocolate-doom/labels/confirmed","name":"confirmed","color":"900C00","default":false},{"id":257755110,"url":"https://api.github.com/repos/chocolate-doom/chocolate-doom/labels/input","name":"input","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2017-03-24T14:44:19Z","updated_at":"2017-03-28T08:40:55Z","closed_at":null,"body":"I'm opening this issue to discuss about a new joystick interface to solve the problems of the current implementation. Recent merges #889, #890, #893 and #894 have improved considerably Chocolate Doom for users that only have a joystick/gamepad during play. However, there are still a few issues to be tackled:\r\n\r\n  1) The new merged code introduced a bug: when the game is saved using the joystick the weapon is fired (see #895). Simplifying a lot, the cause of this bug is that joystick generates an event on every tick, even \"empty\" events when no buttons are pressed and axes are centred. This has other effects: when Chocolate Doom is first started, if the user press Fire on the joystick the menu shows up but pressing fire again does not close it (you have to press Fire really quickly in order to close the menu). This does not happen during game play.\r\n\r\n  2) With the current implementation trigger axis cannot be used at all in Chocolate Doom (trigger axis are what corresponds to L2 and R2 in a XBox 360 gamepad).\r\n\r\n  3) There are some actions, like automap zoom-in and zoom-out, that the player may want to control from the gamepad.\r\n\r\n  4) Joystick hotplug is currently not supported.\r\n\r\n### What is the proposed solution\r\n\r\nI propose to create a redesigned joystick interface for Chocolate Doom based on the SDL2 joystick API with an improved design to solve all current issues and help introducing new features in the future if required. This is roughly what I want to do:\r\n\r\n 1) Since Choco only requires digital input from the joystick I propose to unify all joystick buttons, hats, axes and triggers into \"buttons\". For example, if any axis is moved beyond the dead zone is will be considered as a button press. This allows to map any button/axis to any action (like move left, open automap, etc.).\r\n\r\n    When the joystick status is read it will be saved into a `int jbuttons[MAXBUTTONS]` as `0` (button not pressed, axis centred) or `1` (button pressed, axis moved). To construct this array, buttons are placed first in the order they appear in SDL2 API, then axis, then hats. Hence, similar joysticks having the same joystick ID will always produce the same `jbuttons` array and then a precompiled database with known joysticks can be included in `chocolate-xxxx-setup`.\r\n\r\n  2) Some changes will be required in the  `chocolate-xxxx-setup` program to map the new scheme.\r\n\r\n  3) I plan to generate joysticks events only when such an event is produced and not in a continuous fashion like now. Some changes in the `X_Responder()` functions will be required.\r\n\r\n  4) At Chocolate initialisation joysticks will be scanned. If a joystick with a configured ID is found then it will be used. If no joystick is found, every tick the SDL API will be polled for SDL_CONNECT events. If a joystick is hot plugged its ID will be searched in the configured joystick and if it matches it will be used.\r\n\r\n### What decisions should be made?\r\n\r\n  1) Use SDL2 Joystick API or SDL2 Gamepad API? I think the current SDL2 Joystick API is fine for Choco. The only advantage of the SDL2 Gamepad API is that is presents a unified controller to applications and the mapping should be done in SDL2. However, a new mapping should be always done in Choco: for example, different user may want to use different axis to strafe.\r\n\r\n  2) Support for single joystick or multi-joystick? If we want to support several joysticks then a new configuration file will be needed to store the mappings of the known joysticks, like this:\r\n\r\n```\r\n[joystick_SDL_ID_1]\r\njoystick_fire = 0\r\njoystick_use = 1\r\n...\r\n[joystick_SDL_ID_2]\r\njoystick_fire = 0\r\n...\r\n```\r\n\r\n  3) Get rid of the SDL joystick number and just use the SDL ID? The SDL joystick number does not make sense anymore in the hotplug era. Even if the user has 2 identical joysticks it is not guaranteed that after a reboot joystick 0 will always be the same joystick as it was before. I think it's better to just use the joystick ID.\r\n\r\n### Summary\r\n\r\nIt's complicated to synthesise all my ideas into a single post so I will update it with your inputs and comments to have a place where all information about the new API is centralised.\r\n\r\nAlso, please tell me if you agree with this new gamepad interface so I can start the implementation ASAP.\r\n\r\n### Related issues\r\n\r\n#736, #737, #758, #759, #768, #895"},"comment":{"url":"https://api.github.com/repos/chocolate-doom/chocolate-doom/issues/comments/289702677","html_url":"https://github.com/chocolate-doom/chocolate-doom/issues/897#issuecomment-289702677","issue_url":"https://api.github.com/repos/chocolate-doom/chocolate-doom/issues/897","id":289702677,"user":{"login":"Wintermute0110","id":7764978,"avatar_url":"https://avatars0.githubusercontent.com/u/7764978?v=3","gravatar_id":"","url":"https://api.github.com/users/Wintermute0110","html_url":"https://github.com/Wintermute0110","followers_url":"https://api.github.com/users/Wintermute0110/followers","following_url":"https://api.github.com/users/Wintermute0110/following{/other_user}","gists_url":"https://api.github.com/users/Wintermute0110/gists{/gist_id}","starred_url":"https://api.github.com/users/Wintermute0110/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wintermute0110/subscriptions","organizations_url":"https://api.github.com/users/Wintermute0110/orgs","repos_url":"https://api.github.com/users/Wintermute0110/repos","events_url":"https://api.github.com/users/Wintermute0110/events{/privacy}","received_events_url":"https://api.github.com/users/Wintermute0110/received_events","type":"User","site_admin":false},"created_at":"2017-03-28T08:40:55Z","updated_at":"2017-03-28T08:40:55Z","body":"> We'd need to have the setup program use both APIs and let the user generate a gamepad entry via the setup program (existing interface); we will have to maintain an internal gamepad DB anyway (to cope with people using older SDL2 versions with a lesser-populated gamepad DB); we could write it out + user additions to a file next to the config files.\r\n\r\nHonestly, I do not understand why you are so willing to introduce an extra layer of complexity that is not really needed for Chocolate Doom. Why to have 2 layers or remappings when just one will be fine plus the additional complexity of using 2 APIs for the same function.\r\n\r\nI have an idea and hopefully everyone will agree: I can start the implementation in a branch of my Choco fork. I keep that branch rebased with `upstream/sdl2-branch` so it can be easily merged when finished. When the work is done and you see the results then you can add the gamepad API on top of the joystick API if you feel so (remember you will need to use **both** anyways)."}}
{"actor":{"display_login":"Wintermute0110"}}