diff --git a/src/InputManager.cpp b/src/InputManager.cpp index ef8e12f2a..a1b85a37d 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -11,6 +11,7 @@ SDL_Event* InputManager::lastEvent = NULL; std::map InputManager::joystickButtonMap, InputManager::joystickAxisPosMap, InputManager::joystickAxisNegMap; std::map InputManager::axisState; InputManager::InputButton InputManager::hatState = InputManager::UNKNOWN; +std::string InputManager::joystickName = ""; int InputManager::deadzone = 28000; @@ -204,7 +205,7 @@ void InputManager::loadConfig() std::ifstream file(path.c_str()); - std::string joystickName = ""; + joystickName = ""; while(file.good()) { @@ -257,6 +258,13 @@ void InputManager::loadConfig() } + LOG(LogDebug) << "Finished loading input config"; + + openJoystick(); +} + +void InputManager::openJoystick() +{ //if any joystick is plugged in if(SDL_NumJoysticks() > 0) { @@ -282,12 +290,12 @@ void InputManager::loadConfig() LOG(LogWarning) << " could not find named joystick! You could try manually removing the joystick name entry in the input config file."; } }else{ - LOG(LogDebug) << " opening first joystick"; + LOG(LogDebug) << " opening first joystick (no name saved)"; SDL_JoystickOpen(0); //if we don't have a specific joystick in mind, take the first } }else{ - LOG(LogDebug) << " no joysticks detected by SDL_NumJoysticks(), input loaded but no joystick opened"; + LOG(LogDebug) << " no joysticks detected by SDL_NumJoysticks(), so no joystick opened"; } } diff --git a/src/InputManager.h b/src/InputManager.h index 2b62c6334..09d2b7f8d 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -15,6 +15,7 @@ namespace InputManager { void unregisterComponent(GuiComponent* comp); void loadConfig(); + void openJoystick(); //enum for identifying input, regardless of configuration enum InputButton { UNKNOWN, UP, DOWN, LEFT, RIGHT, BUTTON1, BUTTON2, MENU, SELECT, PAGEUP, PAGEDOWN}; @@ -30,6 +31,7 @@ namespace InputManager { extern std::map joystickAxisPosMap, joystickAxisNegMap; extern std::map axisState; extern InputButton hatState; + extern std::string joystickName; } #endif diff --git a/src/Log.cpp b/src/Log.cpp index 1dda4f434..eaf84eae2 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -4,7 +4,7 @@ #include LogLevel Log::reportingLevel = LogInfo; -FILE* Log::file = fopen(getLogPath().c_str(), "w"); +FILE* Log::file = NULL; //fopen(getLogPath().c_str(), "w"); LogLevel Log::getReportingLevel() { @@ -22,6 +22,11 @@ void Log::setReportingLevel(LogLevel level) reportingLevel = level; } +void Log::open() +{ + file = fopen(getLogPath().c_str(), "w"); +} + std::ostringstream& Log::get(LogLevel level) { os << "lvl" << level << ": \t"; @@ -49,6 +54,13 @@ FILE* Log::getOutput() Log::~Log() { os << std::endl; + + if(getOutput() == NULL) + { + std::cerr << "ERROR - tried to write to log file before it was open!\n"; + return; + } + fprintf(getOutput(), "%s", os.str().c_str()); //if it's an error, also print to console diff --git a/src/Log.h b/src/Log.h index 687c61245..901b364ee 100644 --- a/src/Log.h +++ b/src/Log.h @@ -23,6 +23,7 @@ public: static std::string getLogPath(); static void flush(); + static void open(); static void close(); protected: std::ostringstream os; diff --git a/src/Renderer_init_rpi.cpp b/src/Renderer_init_rpi.cpp index 6920c169f..849dbc531 100644 --- a/src/Renderer_init_rpi.cpp +++ b/src/Renderer_init_rpi.cpp @@ -44,10 +44,6 @@ namespace Renderer return false; } - //have to reload config to re-open SDL joysticks - InputManager::loadConfig(); - - LOG(LogInfo) << "Creating surface..."; diff --git a/src/Renderer_init_sdlgl.cpp b/src/Renderer_init_sdlgl.cpp index e636b78c4..b3306e3ba 100644 --- a/src/Renderer_init_sdlgl.cpp +++ b/src/Renderer_init_sdlgl.cpp @@ -40,9 +40,6 @@ namespace Renderer 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" //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 diff --git a/src/SystemData.cpp b/src/SystemData.cpp index bcd537f68..41f719b08 100644 --- a/src/SystemData.cpp +++ b/src/SystemData.cpp @@ -8,6 +8,7 @@ #include "Renderer.h" #include "AudioManager.h" #include "Log.h" +#include "InputManager.h" std::vector SystemData::sSystemVector; @@ -88,6 +89,7 @@ void SystemData::launchGame(GameData* game) } Renderer::init(0, 0); + InputManager::openJoystick(); AudioManager::init(); //re-enable SDL joystick events diff --git a/src/main.cpp b/src/main.cpp index 54708114c..8e369b63b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,6 +82,18 @@ int main(int argc, char* argv[]) bool running = true; + //make sure the config directory exists + std::string home = getenv("HOME"); + std::string configDir = home + "/.emulationstation"; + if(!fs::exists(configDir)) + { + std::cout << "Creating config directory \"" << configDir << "\"\n"; + fs::create_directory(configDir); + } + + //start the logger + Log::open(); + //the renderer also takes care of setting up SDL for input and sound bool renderInit = Renderer::init(width, height); if(!renderInit) @@ -98,15 +110,6 @@ int main(int argc, char* argv[]) SDL_JoystickEventState(SDL_ENABLE); - //make sure the config directory exists - std::string home = getenv("HOME"); - std::string configDir = home + "/.emulationstation"; - if(!fs::exists(configDir)) - { - std::cout << "Creating config directory \"" << configDir << "\"\n"; - fs::create_directory(configDir); - } - //try loading the system config file if(!fs::exists(SystemData::getConfigPath())) //if it doesn't exist, create the example and quit