Minor code cleanup

celladd
Digmaster 10 years ago committed by scrawl
parent 61d73d186d
commit 1e4a845b6f

@ -379,6 +379,9 @@ configure_file(${OpenMW_SOURCE_DIR}/files/opencs.ini
configure_file(${OpenMW_SOURCE_DIR}/files/opencs/defaultfilters configure_file(${OpenMW_SOURCE_DIR}/files/opencs/defaultfilters
"${OpenMW_BINARY_DIR}/resources/defaultfilters" COPYONLY) "${OpenMW_BINARY_DIR}/resources/defaultfilters" COPYONLY)
configure_file(${OpenMW_SOURCE_DIR}/files/gamecontrollerdb.txt
"${OpenMW_BINARY_DIR}/gamecontrollerdb.txt")
if (NOT WIN32 AND NOT APPLE) if (NOT WIN32 AND NOT APPLE)
configure_file(${OpenMW_SOURCE_DIR}/files/openmw.desktop configure_file(${OpenMW_SOURCE_DIR}/files/openmw.desktop
"${OpenMW_BINARY_DIR}/openmw.desktop") "${OpenMW_BINARY_DIR}/openmw.desktop")

@ -46,10 +46,14 @@ namespace MWBase
///Actions available for binding to controller buttons ///Actions available for binding to controller buttons
virtual std::vector<int> getActionControllerSorting() = 0; virtual std::vector<int> getActionControllerSorting() = 0;
virtual int getNumActions() = 0; virtual int getNumActions() = 0;
///If keyboard is true, only pay attention to keyboard events. If false, only pay attention to cntroller events (excluding esc) ///If keyboard is true, only pay attention to keyboard events. If false, only pay attention to controller events (excluding esc)
virtual void enableDetectingBindingMode (int action, bool keyboard) = 0; virtual void enableDetectingBindingMode (int action, bool keyboard) = 0;
virtual void resetToDefaultKeyBindings() = 0; virtual void resetToDefaultKeyBindings() = 0;
virtual void resetToDefaultControllerBindings() = 0; virtual void resetToDefaultControllerBindings() = 0;
/// Returns if the last used input device was a joystick or a keyboard
/// @return true if joystick, false otherwise
virtual bool joystickLastUsed() = 0;
}; };
} }

@ -124,6 +124,7 @@ namespace MWInput
, mAttemptJump(false) , mAttemptJump(false)
, mControlsDisabled(false) , mControlsDisabled(false)
, mJoystickLastUsed(false) , mJoystickLastUsed(false)
, mDetectingKeyboard(false)
{ {
Ogre::RenderWindow* window = ogre.getWindow (); Ogre::RenderWindow* window = ogre.getWindow ();
@ -135,8 +136,7 @@ namespace MWInput
mInputManager->setControllerEventCallback(this); mInputManager->setControllerEventCallback(this);
std::string file = userFileExists ? userFile : ""; std::string file = userFileExists ? userFile : "";
std::string controllerdb = Settings::Manager::getString("gamecontrollerdb file", "Input"); mInputBinder = new ICS::InputControlSystem(file, true, this, NULL, A_Last);
mInputBinder = new ICS::InputControlSystem(file, true, this, NULL, controllerdb, A_Last);
adjustMouseRegion (window->getWidth(), window->getHeight()); adjustMouseRegion (window->getWidth(), window->getHeight());
loadKeyDefaults(); loadKeyDefaults();
@ -154,6 +154,42 @@ namespace MWInput
mControlSwitch["playermagic"] = true; mControlSwitch["playermagic"] = true;
mControlSwitch["playerviewswitch"] = true; mControlSwitch["playerviewswitch"] = true;
mControlSwitch["vanitymode"] = true; mControlSwitch["vanitymode"] = true;
/* Joystick Init */
//Load controller mappings
#if SDL_VERSION_ATLEAST(2,0,2)
Files::ConfigurationManager cfgMgr;
std::string db = cfgMgr.getLocalPath().string() + "/gamecontrollerdb.txt";
if(boost::filesystem::exists(db))
{
int res = SDL_GameControllerAddMappingsFromFile(db.c_str());
if(res == -1)
{
//ICS_LOG(std::string("Error loading controller bindings: ")+SDL_GetError());
}
else
{
//ICS_LOG(std::string("Loaded ")+boost::lexical_cast<std::string>(res)+" Game controller bindings");
}
}
#endif
//Open all presently connected sticks
int numSticks = SDL_NumJoysticks();
for(int i = 0; i < numSticks; i++)
{
if(SDL_IsGameController(i))
{
SDL_ControllerDeviceEvent evt;
evt.which = i;
controllerAdded(evt);
}
else
{
//ICS_LOG(std::string("Unusable controller plugged in: ")+SDL_JoystickNameForIndex(i));
}
}
} }
void InputManager::clear() void InputManager::clear()

@ -4,6 +4,7 @@
#include "../mwgui/mode.hpp" #include "../mwgui/mode.hpp"
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
#include <components/files/configurationmanager.hpp>
#include "../mwbase/inputmanager.hpp" #include "../mwbase/inputmanager.hpp"
#include <extern/sdl4ogre/sdlinputwrapper.hpp> #include <extern/sdl4ogre/sdlinputwrapper.hpp>
@ -41,6 +42,11 @@ namespace MyGUI
class MouseButton; class MouseButton;
} }
namespace Files
{
struct ConfigurationManager;
}
#include <extern/oics/ICSChannelListener.h> #include <extern/oics/ICSChannelListener.h>
#include <extern/oics/ICSInputControlSystem.h> #include <extern/oics/ICSInputControlSystem.h>
@ -85,8 +91,6 @@ namespace MWInput
virtual std::string getActionDescription (int action); virtual std::string getActionDescription (int action);
virtual std::string getActionKeyBindingName (int action); virtual std::string getActionKeyBindingName (int action);
virtual std::string getActionControllerBindingName (int action); virtual std::string getActionControllerBindingName (int action);
virtual std::string sdlControllerAxisToString(int axis);
virtual std::string sdlControllerButtonToString(int button);
virtual int getNumActions() { return A_Last; } virtual int getNumActions() { return A_Last; }
virtual std::vector<int> getActionKeySorting(); virtual std::vector<int> getActionKeySorting();
virtual std::vector<int> getActionControllerSorting(); virtual std::vector<int> getActionControllerSorting();
@ -94,6 +98,8 @@ namespace MWInput
virtual void resetToDefaultKeyBindings(); virtual void resetToDefaultKeyBindings();
virtual void resetToDefaultControllerBindings(); virtual void resetToDefaultControllerBindings();
virtual bool joystickLastUsed() {return mJoystickLastUsed;}
public: public:
virtual void keyPressed(const SDL_KeyboardEvent &arg ); virtual void keyPressed(const SDL_KeyboardEvent &arg );
virtual void keyReleased( const SDL_KeyboardEvent &arg ); virtual void keyReleased( const SDL_KeyboardEvent &arg );
@ -181,6 +187,9 @@ namespace MWInput
void adjustMouseRegion(int width, int height); void adjustMouseRegion(int width, int height);
MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button); MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button);
virtual std::string sdlControllerAxisToString(int axis);
virtual std::string sdlControllerButtonToString(int button);
void resetIdleTime(); void resetIdleTime();
void updateIdleTime(float dt); void updateIdleTime(float dt);
@ -201,8 +210,6 @@ namespace MWInput
void quickLoad(); void quickLoad();
void quickSave(); void quickSave();
bool isAReverse(int action);
void quickKey (int index); void quickKey (int index);
void showQuickKeysMenu(); void showQuickKeysMenu();

@ -268,15 +268,21 @@ namespace MWScript
std::string InterpreterContext::getActionBinding(const std::string& action) const std::string InterpreterContext::getActionBinding(const std::string& action) const
{ {
std::vector<int> actions = MWBase::Environment::get().getInputManager()->getActionKeySorting (); MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
std::vector<int> actions = input->getActionKeySorting ();
for (std::vector<int>::const_iterator it = actions.begin(); it != actions.end(); ++it) for (std::vector<int>::const_iterator it = actions.begin(); it != actions.end(); ++it)
{ {
std::string desc = MWBase::Environment::get().getInputManager()->getActionDescription (*it); std::string desc = input->getActionDescription (*it);
if(desc == "") if(desc == "")
continue; continue;
if(desc == action) if(desc == action)
return MWBase::Environment::get().getInputManager()->getActionKeyBindingName (*it); {
if(input->joystickLastUsed())
return input->getActionControllerBindingName(*it);
else
return input->getActionKeyBindingName (*it);
}
} }
return "None"; return "None";

@ -30,7 +30,7 @@ namespace ICS
{ {
InputControlSystem::InputControlSystem(std::string file, bool active InputControlSystem::InputControlSystem(std::string file, bool active
, DetectingBindingListener* detectingBindingListener , DetectingBindingListener* detectingBindingListener
, InputControlSystemLog* log, std::string controllerdb, size_t channelCount) , InputControlSystemLog* log, size_t channelCount)
: mFileName(file) : mFileName(file)
, mDetectingBindingListener(detectingBindingListener) , mDetectingBindingListener(detectingBindingListener)
, mDetectingBindingControl(NULL) , mDetectingBindingControl(NULL)
@ -275,40 +275,6 @@ namespace ICS
delete xmlDoc; delete xmlDoc;
} }
/* Joystick Init */
//Load controller mappings
#if SDL_VERSION_ATLEAST(2,0,2)
if(!controllerdb.empty())
{
int res = SDL_GameControllerAddMappingsFromFile(controllerdb.c_str());
if(res == -1)
{
ICS_LOG(std::string("Error loading controller bindings: ")+SDL_GetError());
}
else
{
ICS_LOG(std::string("Loaded ")+boost::lexical_cast<std::string>(res)+" Game controller bindings");
}
}
#endif
//Open all presently connected sticks
int numSticks = SDL_NumJoysticks();
for(int i = 0; i < numSticks; i++)
{
if(SDL_IsGameController(i))
{
SDL_ControllerDeviceEvent evt;
evt.which = i;
controllerAdded(evt);
}
else
{
ICS_LOG(std::string("Unusable controller plugged in: ")+SDL_JoystickNameForIndex(i));
}
}
ICS_LOG(" - InputControlSystem Created - "); ICS_LOG(" - InputControlSystem Created - ");
} }

@ -74,8 +74,7 @@ namespace ICS
InputControlSystem(std::string file = "", bool active = true InputControlSystem(std::string file = "", bool active = true
, DetectingBindingListener* detectingBindingListener = NULL , DetectingBindingListener* detectingBindingListener = NULL
, InputControlSystemLog* log = NULL, std::string controllerdb = "" , InputControlSystemLog* log = NULL, size_t channelCount = 16);
, size_t channelCount = 16);
~InputControlSystem(); ~InputControlSystem();
std::string getFileName(){ return mFileName; }; std::string getFileName(){ return mFileName; };

@ -49,12 +49,6 @@ set(MATERIAL_FILES
mygui.shaderset mygui.shaderset
) )
set(ETC_FILES
gamecontrollerdb.txt
)
copy_all_files(${CMAKE_CURRENT_SOURCE_DIR}/water "${OpenMW_BINARY_DIR}/resources/water/" "${WATER_FILES}") copy_all_files(${CMAKE_CURRENT_SOURCE_DIR}/water "${OpenMW_BINARY_DIR}/resources/water/" "${WATER_FILES}")
copy_all_files(${CMAKE_CURRENT_SOURCE_DIR}/materials "${OpenMW_BINARY_DIR}/resources/materials/" "${MATERIAL_FILES}") copy_all_files(${CMAKE_CURRENT_SOURCE_DIR}/materials "${OpenMW_BINARY_DIR}/resources/materials/" "${MATERIAL_FILES}")
copy_all_files(${CMAKE_CURRENT_SOURCE_DIR} "${OpenMW_BINARY_DIR}/resources/" "${ETC_FILES}")

Loading…
Cancel
Save