From 1dfb45e133c04d7e8d38fb35ea5109e6a3565c14 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 29 Jun 2013 20:37:18 -0500 Subject: [PATCH] Print all Log messages to cout with --debug set. Added startPolling and stopPolling to InputManager. --- src/InputManager.cpp | 25 ++++++++++++++++++++++--- src/InputManager.h | 3 +++ src/Log.cpp | 3 ++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/InputManager.cpp b/src/InputManager.cpp index e3490e207..168787a9f 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -28,7 +28,7 @@ bool InputDevice::operator==(const InputDevice & b) const InputManager::InputManager(Window* window) : mWindow(window), mJoysticks(NULL), mInputConfigs(NULL), mKeyboardInputConfig(NULL), mPrevAxisValues(NULL), - mNumJoysticks(0), mNumPlayers(0), devicePollingTimer(nullptr) + mNumJoysticks(0), mNumPlayers(0), devicePollingTimer(NULL) { } @@ -164,14 +164,31 @@ void InputManager::init() SDL_JoystickEventState(SDL_ENABLE); //start timer for input device polling - devicePollingTimer = SDL_AddTimer(POLLING_INTERVAL, devicePollingCallback, (void *)this); + startPolling(); loadConfig(); } +void InputManager::startPolling() +{ + if(devicePollingTimer != NULL) + return; + + devicePollingTimer = SDL_AddTimer(POLLING_INTERVAL, devicePollingCallback, (void *)this); +} + +void InputManager::stopPolling() +{ + if(devicePollingTimer == NULL) + return; + + SDL_RemoveTimer(devicePollingTimer); + devicePollingTimer = NULL; +} + void InputManager::deinit() { - SDL_RemoveTimer(devicePollingTimer); + stopPolling(); SDL_JoystickEventState(SDL_DISABLE); @@ -380,6 +397,8 @@ void InputManager::loadConfig() LOG(LogInfo) << "No input configs loaded. Loading default keyboard config."; loadDefaultConfig(); } + + LOG(LogInfo) << "Loaded InputConfig data for " << getNumPlayers() << " devices."; } //used in an "emergency" where no configs could be loaded from the inputmanager config file diff --git a/src/InputManager.h b/src/InputManager.h index 921a29fa5..e0cef8b61 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -77,6 +77,9 @@ public: bool parseEvent(const SDL_Event& ev); InputConfig* getInputConfigByPlayer(int player); + + void startPolling(); + void stopPolling(); }; #endif diff --git a/src/Log.cpp b/src/Log.cpp index fe3c50c6c..0e8522601 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -65,6 +65,7 @@ Log::~Log() fprintf(getOutput(), "%s", os.str().c_str()); //if it's an error, also print to console - if(messageLevel == LogError) + //print all messages if using --debug + if(messageLevel == LogError || reportingLevel >= LogDebug) fprintf(stderr, "%s", os.str().c_str()); }