mirror of
				https://github.com/RetroDECK/ES-DE.git
				synced 2025-04-10 19:15:13 +00:00 
			
		
		
		
	Added joystick identification support for those who have multiple joysticks.
If you'd like to use this, please remove ~/.emulationstation/es_input.cfg and reconfigure.
This commit is contained in:
		
							parent
							
								
									7795dd729d
								
							
						
					
					
						commit
						f87b6c48d7
					
				|  | @ -1,3 +1,8 @@ | ||||||
|  | September 14 | ||||||
|  | -Joystick names are now saved during input configuration to es_input.cfg. | ||||||
|  | -When loading an input config, if JOYNAME is defined, load the first joystick with that name. If it is not present, load the first joystick (old behavior). | ||||||
|  | -Joysticks should re-initialize properly with SDL on the desktop configuration. | ||||||
|  | 
 | ||||||
| September 10 | September 10 | ||||||
| -Fixed multiple extensions breaking things. | -Fixed multiple extensions breaking things. | ||||||
| -Added Makefile.x86 for building on a desktop (acquire OpenGL context through SDL instead of EGL). | -Added Makefile.x86 for building on a desktop (acquire OpenGL context through SDL instead of EGL). | ||||||
|  |  | ||||||
|  | @ -190,6 +190,8 @@ void InputManager::loadConfig() | ||||||
| 
 | 
 | ||||||
| 	std::ifstream file(path.c_str()); | 	std::ifstream file(path.c_str()); | ||||||
| 
 | 
 | ||||||
|  | 	std::string joystickName = ""; | ||||||
|  | 
 | ||||||
| 	while(file.good()) | 	while(file.good()) | ||||||
| 	{ | 	{ | ||||||
| 		std::string line; | 		std::string line; | ||||||
|  | @ -208,12 +210,17 @@ void InputManager::loadConfig() | ||||||
| 
 | 
 | ||||||
| 		while(std::getline(stream, token[tokNum], ' ')) | 		while(std::getline(stream, token[tokNum], ' ')) | ||||||
| 		{ | 		{ | ||||||
| 			if(tokNum >= 3) |  | ||||||
| 			{ |  | ||||||
| 				std::cerr << "Error - input config line \"" << line << "\" has more than three tokens!\n"; |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
| 			tokNum++; | 			tokNum++; | ||||||
|  | 
 | ||||||
|  | 			//JOYNAME can have spaces
 | ||||||
|  | 			if(tokNum == 1 && token[0] == "JOYNAME") | ||||||
|  | 			{ | ||||||
|  | 				std::getline(stream, token[1]); | ||||||
|  | 				break; | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			if(tokNum >= 3) | ||||||
|  | 				break; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -226,6 +233,9 @@ void InputManager::loadConfig() | ||||||
| 		}else if(token[0] == "AXISNEG") | 		}else if(token[0] == "AXISNEG") | ||||||
| 		{ | 		{ | ||||||
| 			joystickAxisNegMap[atoi(token[1].c_str())] = (InputButton)atoi(token[2].c_str()); | 			joystickAxisNegMap[atoi(token[1].c_str())] = (InputButton)atoi(token[2].c_str()); | ||||||
|  | 		}else if(token[0] == "JOYNAME") | ||||||
|  | 		{ | ||||||
|  | 			joystickName = token[1]; | ||||||
| 		}else{ | 		}else{ | ||||||
| 			std::cerr << "Invalid input type - " << token[0] << "\n"; | 			std::cerr << "Invalid input type - " << token[0] << "\n"; | ||||||
| 			return; | 			return; | ||||||
|  | @ -233,9 +243,23 @@ void InputManager::loadConfig() | ||||||
| 
 | 
 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	//if any joystick is plugged in
 | ||||||
| 	if(SDL_NumJoysticks() > 0) | 	if(SDL_NumJoysticks() > 0) | ||||||
| 	{ | 	{ | ||||||
| 		SDL_JoystickOpen(0); | 		if(!joystickName.empty()) | ||||||
|  | 		{ | ||||||
|  | 			for(int i = 0; i < SDL_NumJoysticks(); i++) | ||||||
|  | 			{ | ||||||
|  | 				if(strcmp(SDL_JoystickName(i), joystickName.c_str()) == 0) | ||||||
|  | 				{ | ||||||
|  | 					std::cout << "opening joystick " << joystickName << "\n"; | ||||||
|  | 					SDL_JoystickOpen(i); | ||||||
|  | 					break; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		}else{ | ||||||
|  | 			SDL_JoystickOpen(0);  //if we don't have a specific joystick in mind, take the first
 | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include GLHEADER | #include GLHEADER | ||||||
| #include "Font.h" | #include "Font.h" | ||||||
| #include <SDL/SDL.h> | #include <SDL/SDL.h> | ||||||
|  | #include "InputManager.h" | ||||||
| 
 | 
 | ||||||
| namespace Renderer | namespace Renderer | ||||||
| { | { | ||||||
|  | @ -34,6 +35,9 @@ namespace Renderer | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		//we need to reload input too since SDL shut down
 | ||||||
|  | 		InputManager::loadConfig(); | ||||||
|  | 
 | ||||||
| 		//usually display width/height are not specified, i.e. zero, which SDL automatically takes as "native resolution"
 | 		//usually display width/height are not specified, i.e. zero, which SDL automatically takes as "native resolution"
 | ||||||
| 		//so, since other things rely on the size of the screen (damn currently unnormalized coordinate system), we set it here
 | 		//so, since other things rely on the size of the screen (damn currently unnormalized coordinate system), we set it here
 | ||||||
| 		//even though the system was already initialized
 | 		//even though the system was already initialized
 | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ GuiInputConfig::GuiInputConfig() | ||||||
| 		mDone = true; | 		mDone = true; | ||||||
| 		return; | 		return; | ||||||
| 	}else{ | 	}else{ | ||||||
| 		std::cout << "Opening joystick \"" << SDL_JoystickName(0) << "\"\n"; | 		std::cout << "Opening joystick \"" << SDL_JoystickName(0) << "\" for configuration...\n"; | ||||||
| 		mJoystick = SDL_JoystickOpen(0); | 		mJoystick = SDL_JoystickOpen(0); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | @ -44,10 +44,11 @@ void GuiInputConfig::onRender() | ||||||
| 	Renderer::drawCenteredText("POV hats (some D-Pads) are automatically mapped to directions.", 0, height, 0x000000); | 	Renderer::drawCenteredText("POV hats (some D-Pads) are automatically mapped to directions.", 0, height, 0x000000); | ||||||
| 	Renderer::drawCenteredText("You can press a keyboard key to skip any input.", 0, height * 2, 0x000000); | 	Renderer::drawCenteredText("You can press a keyboard key to skip any input.", 0, height * 2, 0x000000); | ||||||
| 	Renderer::drawCenteredText("If you want to remap later, just delete ~/.es_input.cfg.", 0, height * 3, 0x000000); | 	Renderer::drawCenteredText("If you want to remap later, just delete ~/.es_input.cfg.", 0, height * 3, 0x000000); | ||||||
|  | 	Renderer::drawCenteredText("This interface only configures the first joystick plugged in.", 0, height * 4, 0x000000); | ||||||
| 	Renderer::drawCenteredText("Remember - you'll need to set up your emulator separately!", 0, Renderer::getScreenHeight() - height, 0x000000); | 	Renderer::drawCenteredText("Remember - you'll need to set up your emulator separately!", 0, Renderer::getScreenHeight() - height, 0x000000); | ||||||
| 
 | 
 | ||||||
| 	if(mDone) | 	if(mDone) | ||||||
| 		Renderer::drawCenteredText("All done! Press a keyboard key to continue.", 0, height * 5, 0x00BB00); | 		Renderer::drawCenteredText("All done! Press a keyboard key to save.", 0, height * 5, 0x00BB00); | ||||||
| 	else | 	else | ||||||
| 		Renderer::drawCenteredText("Please press the axis/button for " + sInputs[mInputNum], 0, height * 5, 0x00C000); | 		Renderer::drawCenteredText("Please press the axis/button for " + sInputs[mInputNum], 0, height * 5, 0x00C000); | ||||||
| } | } | ||||||
|  | @ -116,6 +117,9 @@ void GuiInputConfig::writeConfig() | ||||||
| 
 | 
 | ||||||
| 	std::ofstream file(path.c_str()); | 	std::ofstream file(path.c_str()); | ||||||
| 
 | 
 | ||||||
|  | 	if(SDL_JoystickName(0)) | ||||||
|  | 		file << "JOYNAME " << SDL_JoystickName(0) << "\n"; | ||||||
|  | 
 | ||||||
| 	typedef std::map<int, InputManager::InputButton>::iterator it_type; | 	typedef std::map<int, InputManager::InputButton>::iterator it_type; | ||||||
| 	for(it_type iter = mButtonMap.begin(); iter != mButtonMap.end(); iter++) | 	for(it_type iter = mButtonMap.begin(); iter != mButtonMap.end(); iter++) | ||||||
| 	{ | 	{ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Aloshi
						Aloshi