From 0d2a1d755d82726db9c903fa5153a96c77c9bb47 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 10 Dec 2022 16:05:05 +0100 Subject: [PATCH] Replaced OIS with OgreBites input + SDL (not functional yet) Status: builds and runs OK, but there is no input. This is a brainless 1:1 replacement of OIS API and events with SDL API and OgreBites input events. I preserved our (very outdated) DearIMGUI integration. All our (quite convoluted) input processing stayed mostly intact. Only mouse/keyboard input is handled, joysticks + controllers + forcefeedback are temporarily disabled. --- cmake/DependenciesConfig.cmake | 28 - source/main/AppContext.cpp | 73 ++- source/main/AppContext.h | 34 +- source/main/CMakeLists.txt | 1 - source/main/gameplay/Character.cpp | 4 +- source/main/gameplay/RecoveryMode.cpp | 8 +- source/main/gameplay/Replay.cpp | 15 +- source/main/gameplay/Replay.h | 1 + source/main/gameplay/SceneMouse.cpp | 32 +- source/main/gameplay/SceneMouse.h | 15 +- source/main/gfx/camera/CameraManager.cpp | 115 ++-- source/main/gfx/camera/CameraManager.h | 16 +- source/main/gui/GUIManager.cpp | 7 +- source/main/gui/OverlayWrapper.cpp | 31 +- source/main/gui/OverlayWrapper.h | 9 +- source/main/gui/imgui/OgreImGui.cpp | 132 +++-- source/main/gui/imgui/OgreImGui.h | 15 +- source/main/phc.h | 3 +- source/main/terrain/TerrainEditor.cpp | 8 +- source/main/utils/ForceFeedback.cpp | 17 +- source/main/utils/ForceFeedback.h | 7 +- source/main/utils/InputEngine.cpp | 681 ++++++++--------------- source/main/utils/InputEngine.h | 63 +-- 23 files changed, 582 insertions(+), 733 deletions(-) diff --git a/cmake/DependenciesConfig.cmake b/cmake/DependenciesConfig.cmake index 1f164dcb8b..24d0269e6e 100644 --- a/cmake/DependenciesConfig.cmake +++ b/cmake/DependenciesConfig.cmake @@ -36,34 +36,6 @@ add_external_lib( FIND_PACKAGE_OPTIONS CONFIG ) - -# TTTTTTTTTTTTTTTTTTTTTTT OOOOOOOOO DDDDDDDDDDDDD OOOOOOOOO -# T:::::::::::::::::::::T OO:::::::::OO D::::::::::::DDD OO:::::::::OO -# T:::::::::::::::::::::T OO:::::::::::::OO D:::::::::::::::DD OO:::::::::::::OO -# T:::::TT:::::::TT:::::TO:::::::OOO:::::::ODDD:::::DDDDD:::::D O:::::::OOO:::::::O -# TTTTTT T:::::T TTTTTTO::::::O O::::::O D:::::D D:::::D O::::::O O::::::O -# T:::::T O:::::O O:::::O D:::::D D:::::DO:::::O O:::::O -# T:::::T O:::::O O:::::O D:::::D D:::::DO:::::O O:::::O -# T:::::T O:::::O O:::::O D:::::D D:::::DO:::::O O:::::O -# T:::::T O:::::O O:::::O D:::::D D:::::DO:::::O O:::::O -# T:::::T O:::::O O:::::O D:::::D D:::::DO:::::O O:::::O -# T:::::T O:::::O O:::::O D:::::D D:::::DO:::::O O:::::O -# T:::::T O::::::O O::::::O D:::::D D:::::D O::::::O O::::::O -# TT:::::::TT O:::::::OOO:::::::ODDD:::::DDDDD:::::D O:::::::OOO:::::::O -# T:::::::::T OO:::::::::::::OO D:::::::::::::::DD OO:::::::::::::OO -# T:::::::::T OO:::::::::OO D::::::::::::DDD OO:::::::::OO -# TTTTTTTTTTT OOOOOOOOO DDDDDDDDDDDDD OOOOOOOOO -# -# TODO: Needs to reverted back to "ois/1.4@rigsofrods/custom", but this package as to be updated first - -add_external_lib( - OIS - ois/1.5.1@anotherfoxguy/stable - REQUIRED - PKG_CONFIG "ois >= 1.4" - FIND_PACKAGE -) - add_external_lib( MyGUI mygui/3.4.1@anotherfoxguy/stable diff --git a/source/main/AppContext.cpp b/source/main/AppContext.cpp index c633529d78..d326f4e36c 100644 --- a/source/main/AppContext.cpp +++ b/source/main/AppContext.cpp @@ -62,9 +62,6 @@ using namespace RoR; bool AppContext::SetUpInput() { App::CreateInputEngine(); - App::GetInputEngine()->SetMouseListener(this); - App::GetInputEngine()->SetKeyboardListener(this); - App::GetInputEngine()->SetJoystickListener(this); if (App::io_ffb_enabled->getBool()) { @@ -73,7 +70,7 @@ bool AppContext::SetUpInput() return true; } -bool AppContext::mouseMoved(const OIS::MouseEvent& arg) // overrides OIS::MouseListener +bool AppContext::mouseMoved(const OgreBites::MouseMotionEvent& arg) // overrides OgreBites::InputListener { App::GetGuiManager()->WakeUpGUI(); App::GetGuiManager()->GetImGui().InjectMouseMoved(arg); @@ -97,59 +94,64 @@ bool AppContext::mouseMoved(const OIS::MouseEvent& arg) // overrides OIS::MouseL return true; } -bool AppContext::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID _id) // overrides OIS::MouseListener +bool AppContext::mouseWheelRolled(const OgreBites::MouseWheelEvent& arg) { App::GetGuiManager()->WakeUpGUI(); - App::GetGuiManager()->GetImGui().InjectMousePressed(arg, _id); + App::GetGuiManager()->GetImGui().InjectMouseWheelRolled(arg); + + if (!ImGui::GetIO().WantCaptureMouse) // true if mouse is over any window + { + App::GetCameraManager()->mouseWheelRolled(arg); + } + + return true; +} + +bool AppContext::mousePressed(const OgreBites::MouseButtonEvent& arg) // overrides OgreBites::InputListener +{ + App::GetGuiManager()->WakeUpGUI(); + App::GetGuiManager()->GetImGui().InjectMousePressed(arg); if (!ImGui::GetIO().WantCaptureMouse) // true if mouse is over any window { bool handled = false; if (App::GetOverlayWrapper()) { - handled = App::GetOverlayWrapper()->mousePressed(arg, _id); // update the old airplane / autopilot gui + handled = App::GetOverlayWrapper()->mousePressed(arg); // update the old airplane / autopilot gui } if (!handled && App::app_state->getEnum() == AppState::SIMULATION) { - App::GetGameContext()->GetSceneMouse().mousePressed(arg, _id); - App::GetCameraManager()->mousePressed(arg, _id); + App::GetGameContext()->GetSceneMouse().mousePressed(arg); + App::GetCameraManager()->mousePressed(arg); } } - else - { - App::GetInputEngine()->ProcessMouseEvent(arg); - } return true; } -bool AppContext::mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID _id) // overrides OIS::MouseListener +bool AppContext::mouseReleased(const OgreBites::MouseButtonEvent& arg) // overrides OgreBites::InputListener { App::GetGuiManager()->WakeUpGUI(); - App::GetGuiManager()->GetImGui().InjectMouseReleased(arg, _id); + App::GetGuiManager()->GetImGui().InjectMouseReleased(arg); if (!ImGui::GetIO().WantCaptureMouse) // true if mouse is over any window { bool handled = false; if (App::GetOverlayWrapper()) { - handled = App::GetOverlayWrapper()->mouseReleased(arg, _id); // update the old airplane / autopilot gui + handled = App::GetOverlayWrapper()->mouseReleased(arg); // update the old airplane / autopilot gui } if (!handled && App::app_state->getEnum() == AppState::SIMULATION) { - App::GetGameContext()->GetSceneMouse().mouseReleased(arg, _id); + App::GetGameContext()->GetSceneMouse().mouseReleased(arg); } } - else - { - App::GetInputEngine()->ProcessMouseEvent(arg); - } return true; } -bool AppContext::keyPressed(const OIS::KeyEvent& arg) +bool AppContext::keyPressed(const OgreBites::KeyboardEvent& arg) { App::GetGuiManager()->GetImGui().InjectKeyPressed(arg); @@ -162,7 +164,7 @@ bool AppContext::keyPressed(const OIS::KeyEvent& arg) return true; } -bool AppContext::keyReleased(const OIS::KeyEvent& arg) +bool AppContext::keyReleased(const OgreBites::KeyboardEvent& arg) { App::GetGuiManager()->GetImGui().InjectKeyReleased(arg); @@ -171,7 +173,7 @@ bool AppContext::keyReleased(const OIS::KeyEvent& arg) { App::GetInputEngine()->ProcessKeyRelease(arg); } - else if (App::GetInputEngine()->isKeyDownEffective(arg.key)) + else if (App::GetInputEngine()->isKeyDownEffective(arg.keysym.sym)) { // If capturing is requested, still pass release events for already-pressed keys. App::GetInputEngine()->ProcessKeyRelease(arg); @@ -180,15 +182,26 @@ bool AppContext::keyReleased(const OIS::KeyEvent& arg) return true; } -bool AppContext::buttonPressed(const OIS::JoyStickEvent& arg, int) { App::GetInputEngine()->ProcessJoystickEvent(arg); return true; } -bool AppContext::buttonReleased(const OIS::JoyStickEvent& arg, int) { App::GetInputEngine()->ProcessJoystickEvent(arg); return true; } -bool AppContext::axisMoved(const OIS::JoyStickEvent& arg, int) { App::GetInputEngine()->ProcessJoystickEvent(arg); return true; } -bool AppContext::sliderMoved(const OIS::JoyStickEvent& arg, int) { App::GetInputEngine()->ProcessJoystickEvent(arg); return true; } -bool AppContext::povMoved(const OIS::JoyStickEvent& arg, int) { App::GetInputEngine()->ProcessJoystickEvent(arg); return true; } +bool AppContext::buttonPressed(const OgreBites::ButtonEvent& arg) +{ + //FIXME-SDL App::GetInputEngine()->ProcessJoystickEvent(arg); + return true; +} + +bool AppContext::buttonReleased(const OgreBites::ButtonEvent& arg) +{ + //FIXME-SDL App::GetInputEngine()->ProcessJoystickEvent(arg); + return true; +} + +bool AppContext::axisMoved(const OgreBites::AxisEvent& arg) +{ + App::GetInputEngine()->ProcessJoystickEvent(arg); + return true; +} void AppContext::windowResized(Ogre::RenderWindow* rw) { - App::GetInputEngine()->windowResized(rw); // Update mouse area App::GetOverlayWrapper()->windowResized(); if (App::sim_state->getEnum() == RoR::AppState::SIMULATION) { diff --git a/source/main/AppContext.h b/source/main/AppContext.h index 94318a2bd3..318643cc5d 100644 --- a/source/main/AppContext.h +++ b/source/main/AppContext.h @@ -29,9 +29,11 @@ #include "Application.h" #include "ForceFeedback.h" +#include #include +#include #include -#include + namespace RoR { @@ -41,9 +43,8 @@ namespace RoR { /// Central setup and event handler for input/windowing/rendering. /// Inspired by OgreBites::ApplicationContext. class AppContext: public OgreBites::WindowEventListener, - public OIS::MouseListener, - public OIS::KeyListener, - public OIS::JoyStickListener + public OgreBites::InputListener, + public OgreBites::ApplicationContext { public: // Startup (in order) @@ -71,21 +72,16 @@ class AppContext: public OgreBites::WindowEventListener, virtual void windowResized(Ogre::RenderWindow* rw) override; virtual void windowFocusChange(Ogre::RenderWindow* rw) override; - // OIS::MouseListener - virtual bool mouseMoved(const OIS::MouseEvent& arg) override; - virtual bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id) override; - virtual bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id) override; - - // OIS::KeyListener - virtual bool keyPressed(const OIS::KeyEvent& arg) override; - virtual bool keyReleased(const OIS::KeyEvent& arg) override; - - // OIS::JoyStickListener - virtual bool buttonPressed(const OIS::JoyStickEvent& arg, int button) override; - virtual bool buttonReleased(const OIS::JoyStickEvent& arg, int button) override; - virtual bool axisMoved(const OIS::JoyStickEvent& arg, int axis) override; - virtual bool sliderMoved(const OIS::JoyStickEvent& arg, int) override; - virtual bool povMoved(const OIS::JoyStickEvent& arg, int) override; + // OgreBites::InputListener + virtual bool mouseMoved(const OgreBites::MouseMotionEvent& arg) override; + virtual bool mouseWheelRolled(const OgreBites::MouseWheelEvent& evt) override; + virtual bool mousePressed(const OgreBites::MouseButtonEvent& arg) override; + virtual bool mouseReleased(const OgreBites::MouseButtonEvent& arg) override; + virtual bool keyPressed(const OgreBites::KeyboardEvent& arg) override; + virtual bool keyReleased(const OgreBites::KeyboardEvent& arg) override; + virtual bool buttonPressed(const OgreBites::ButtonEvent& arg) override; + virtual bool buttonReleased(const OgreBites::ButtonEvent& arg) override; + virtual bool axisMoved(const OgreBites::AxisEvent& arg) override; // Rendering and window management void SetRenderWindowIcon(Ogre::RenderWindow* rw); diff --git a/source/main/CMakeLists.txt b/source/main/CMakeLists.txt index c2a7b6f05a..7d860a8edf 100644 --- a/source/main/CMakeLists.txt +++ b/source/main/CMakeLists.txt @@ -383,7 +383,6 @@ set(CMAKE_THREAD_PREFER_PTHREAD YES) target_link_libraries(${BINNAME} PRIVATE Threads::Threads OGRE::OGRE - OIS::OIS fmt::fmt MyGUI::MyGUI RapidJSON::RapidJSON diff --git a/source/main/gameplay/Character.cpp b/source/main/gameplay/Character.cpp index b1e732b1d1..4bfb7b2248 100644 --- a/source/main/gameplay/Character.cpp +++ b/source/main/gameplay/Character.cpp @@ -256,7 +256,7 @@ void Character::update(float dt) tmpJoy = RoR::App::GetInputEngine()->getEventValue(EV_CHARACTER_RIGHT); if (tmpJoy > 0.0f) { - float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.1f : 1.0f; + float scale = RoR::App::GetInputEngine()->isKeyDown(SDLK_LALT) ? 0.1f : 1.0f; setRotation(m_character_rotation + dt * 2.0f * scale * Radian(tmpJoy)); if (!isswimming && not_walking) { @@ -268,7 +268,7 @@ void Character::update(float dt) tmpJoy = RoR::App::GetInputEngine()->getEventValue(EV_CHARACTER_LEFT); if (tmpJoy > 0.0f) { - float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.1f : 1.0f; + float scale = RoR::App::GetInputEngine()->isKeyDown(SDLK_LALT) ? 0.1f : 1.0f; setRotation(m_character_rotation - dt * scale * 2.0f * Radian(tmpJoy)); if (!isswimming && not_walking) { diff --git a/source/main/gameplay/RecoveryMode.cpp b/source/main/gameplay/RecoveryMode.cpp index f2b67a324e..f69ec753c6 100644 --- a/source/main/gameplay/RecoveryMode.cpp +++ b/source/main/gameplay/RecoveryMode.cpp @@ -101,9 +101,9 @@ void RecoveryMode::UpdateInputEvents(float dt) if (translation != Ogre::Vector3::ZERO || rotation != 0.0f) { - float scale = App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.1f : 1.0f; - scale *= App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) ? 3.0f : 1.0f; - scale *= App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL) ? 10.0f : 1.0f; + float scale = App::GetInputEngine()->isKeyDown(SDLK_LALT) ? 0.1f : 1.0f; + scale *= App::GetInputEngine()->isKeyDown(SDLK_LSHIFT) ? 3.0f : 1.0f; + scale *= App::GetInputEngine()->isKeyDown(SDLK_LCTRL) ? 10.0f : 1.0f; Ogre::Vector3 rotation_center = App::GetGameContext()->GetPlayerActor()->getRotationCenter(); @@ -124,7 +124,7 @@ void RecoveryMode::UpdateInputEvents(float dt) m_advanced_vehicle_repair_timer = 0.0f; } - else if (App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE)) + else if (App::GetInputEngine()->isKeyDownValueBounce(OgreBites::SDLK_SPACE)) { App::GetGameContext()->GetPlayerActor()->requestAngleSnap(45); if (App::sim_soft_reset_mode->getBool()) diff --git a/source/main/gameplay/Replay.cpp b/source/main/gameplay/Replay.cpp index b2fbc779b2..d8dd86c657 100644 --- a/source/main/gameplay/Replay.cpp +++ b/source/main/gameplay/Replay.cpp @@ -29,6 +29,8 @@ #include "Language.h" #include "Utils.h" +#include + using namespace Ogre; using namespace RoR; @@ -248,6 +250,9 @@ void Replay::replayStepActor() void Replay::UpdateInputEvents() { + int mouseX = 0; + SDL_GetMouseState(&mouseX, nullptr); + if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_TOGGLE_REPLAY_MODE)) { if (m_actor->ar_state == ActorState::LOCAL_REPLAY) @@ -275,17 +280,17 @@ void Replay::UpdateInputEvents() this->ar_replay_pos -= 10; } - if (App::GetInputEngine()->isKeyDown(OIS::KC_LMENU)) + if (App::GetInputEngine()->isKeyDown(SDLK_LALT)) { if (this->ar_replay_pos <= 0 && this->ar_replay_pos >= -this->getNumFrames()) { - if (App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) || App::GetInputEngine()->isKeyDown(OIS::KC_RSHIFT)) + if (App::GetInputEngine()->isKeyDown(SDLK_LSHIFT) || App::GetInputEngine()->isKeyDown(SDLK_RSHIFT)) { - this->ar_replay_pos += App::GetInputEngine()->getMouseState().X.rel * 1.5f; + this->ar_replay_pos += (mouseX - prevMouseX) * 1.5f; } else { - this->ar_replay_pos += App::GetInputEngine()->getMouseState().X.rel * 0.05f; + this->ar_replay_pos += (mouseX - prevMouseX) * 0.05f; } if (this->ar_replay_pos > 0) { @@ -298,4 +303,6 @@ void Replay::UpdateInputEvents() } } } + + prevMouseX = mouseX; } diff --git a/source/main/gameplay/Replay.h b/source/main/gameplay/Replay.h index b6a8ff3c7c..75fc816fef 100644 --- a/source/main/gameplay/Replay.h +++ b/source/main/gameplay/Replay.h @@ -67,6 +67,7 @@ class Replay : public ZeroedMemoryAllocator int writeIndex; int firstRun; unsigned long curFrameTime; + int prevMouseX = 0; // malloc'ed node_simple_t* nodes; diff --git a/source/main/gameplay/SceneMouse.cpp b/source/main/gameplay/SceneMouse.cpp index 8d67cb8e99..1b18b79d77 100644 --- a/source/main/gameplay/SceneMouse.cpp +++ b/source/main/gameplay/SceneMouse.cpp @@ -110,15 +110,16 @@ void SceneMouse::reset() mouseGrabState = 0; } -bool SceneMouse::mouseMoved(const OIS::MouseEvent& _arg) +bool SceneMouse::mouseMoved(const OgreBites::MouseMotionEvent& _arg) { - const OIS::MouseState ms = _arg.state; + m_mouse_x = _arg.x; + m_mouse_y = _arg.y; // experimental mouse hack - if (ms.buttonDown(OIS::MB_Left) && mouseGrabState == 0) + if (App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_LEFT) && mouseGrabState == 0) { - lastMouseY = ms.Y.abs; - lastMouseX = ms.X.abs; + lastMouseY = m_mouse_y; + lastMouseX = m_mouse_x; Ray mouseRay = getMouseRay(); @@ -169,15 +170,15 @@ bool SceneMouse::mouseMoved(const OIS::MouseEvent& _arg) } } } - else if (ms.buttonDown(OIS::MB_Left) && mouseGrabState == 1) + else if (App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_LEFT) && mouseGrabState == 1) { // force applying and so forth happens in update() - lastMouseY = ms.Y.abs; - lastMouseX = ms.X.abs; + lastMouseY = m_mouse_y; + lastMouseX = m_mouse_x; // not fixed return false; } - else if (!ms.buttonDown(OIS::MB_Left) && mouseGrabState == 1) + else if (!App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_LEFT) && mouseGrabState == 1) { releaseMousePick(); // not fixed @@ -217,16 +218,15 @@ void SceneMouse::UpdateVisuals() } } -bool SceneMouse::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) +bool SceneMouse::mousePressed(const OgreBites::MouseButtonEvent& _arg) { - if (App::sim_state->getEnum() == SimState::PAUSED) { return true; } // Do nothing when paused - const OIS::MouseState ms = _arg.state; + if (App::sim_state->getEnum() == SimState::PAUSED) { return true; } // Do nothing when paused - if (ms.buttonDown(OIS::MB_Middle)) + if (App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_MIDDLE)) { - lastMouseY = ms.Y.abs; - lastMouseX = ms.X.abs; + lastMouseY = m_mouse_y; + lastMouseX = m_mouse_x; Ray mouseRay = getMouseRay(); if (App::sim_state->getEnum() == SimState::EDITOR_MODE) @@ -293,7 +293,7 @@ bool SceneMouse::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _i return true; } -bool SceneMouse::mouseReleased(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) +bool SceneMouse::mouseReleased(const OgreBites::MouseButtonEvent& _arg) { if (App::sim_state->getEnum() == SimState::PAUSED) { return true; } // Do nothing when paused diff --git a/source/main/gameplay/SceneMouse.h b/source/main/gameplay/SceneMouse.h index 3684472d12..0b4582c5c9 100644 --- a/source/main/gameplay/SceneMouse.h +++ b/source/main/gameplay/SceneMouse.h @@ -28,9 +28,9 @@ #include "Application.h" #include "SimData.h" -#include -#include + + #include namespace RoR { @@ -41,9 +41,9 @@ class SceneMouse SceneMouse(); - bool mouseMoved(const OIS::MouseEvent& _arg); - bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); - bool mouseReleased(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); + bool mouseMoved(const OgreBites::MouseMotionEvent& _arg); + bool mousePressed(const OgreBites::MouseButtonEvent& _arg); + bool mouseReleased(const OgreBites::MouseButtonEvent& _arg); void InitializeVisuals(); void UpdateSimulation(); @@ -62,6 +62,11 @@ class SceneMouse Ogre::Vector3 lastgrabpos; int lastMouseX, lastMouseY; + // Cached mouse state from OgreBites::InputListener, to minimize code changes + int m_mouse_x = 0; + int m_mouse_y = 0; + // END cached + void releaseMousePick(); Ogre::Ray getMouseRay(); void reset(); diff --git a/source/main/gfx/camera/CameraManager.cpp b/source/main/gfx/camera/CameraManager.cpp index 84fa135453..2f975cbac2 100644 --- a/source/main/gfx/camera/CameraManager.cpp +++ b/source/main/gfx/camera/CameraManager.cpp @@ -39,6 +39,8 @@ #include "PerVehicleCameraContext.h" #include "Water.h" +#include + using namespace Ogre; using namespace RoR; @@ -531,7 +533,7 @@ void CameraManager::ResetAllBehaviors() this->SwitchBehaviorOnVehicleChange(CAMERA_BEHAVIOR_INVALID, nullptr); } -bool CameraManager::mouseMoved(const OIS::MouseEvent& _arg) +bool CameraManager::mouseMoved(const OgreBites::MouseMotionEvent& _arg) { if (App::sim_state->getEnum() == SimState::PAUSED) @@ -546,11 +548,10 @@ bool CameraManager::mouseMoved(const OIS::MouseEvent& _arg) return false; if (!m_charactercam_is_3rdperson) { - const OIS::MouseState ms = _arg.state; Radian angle = App::GetGameContext()->GetPlayerCharacter()->getRotation(); - m_cam_rot_y += Degree(ms.Y.rel * 0.13f); - angle += Degree(ms.X.rel * 0.13f); + m_cam_rot_y += Degree(_arg.yrel * 0.13f); + angle += Degree(_arg.xrel * 0.13f); m_cam_rot_y = Radian(std::min(+Math::HALF_PI * 0.65f, m_cam_rot_y.valueRadians())); m_cam_rot_y = Radian(std::max(m_cam_rot_y.valueRadians(), -Math::HALF_PI * 0.9f)); @@ -564,15 +565,14 @@ bool CameraManager::mouseMoved(const OIS::MouseEvent& _arg) return CameraManager::CameraBehaviorOrbitMouseMoved(_arg); } - case CAMERA_BEHAVIOR_STATIC: return CameraBehaviorStaticMouseMoved(_arg); + case CAMERA_BEHAVIOR_STATIC: return false; case CAMERA_BEHAVIOR_VEHICLE: return CameraBehaviorOrbitMouseMoved(_arg); case CAMERA_BEHAVIOR_VEHICLE_SPLINE: return this->CameraBehaviorVehicleSplineMouseMoved(_arg); case CAMERA_BEHAVIOR_VEHICLE_CINECAM: return CameraBehaviorOrbitMouseMoved(_arg); case CAMERA_BEHAVIOR_FREE: { - const OIS::MouseState ms = _arg.state; - App::GetCameraManager()->GetCameraNode()->yaw(Degree(-ms.X.rel * 0.13f), Ogre::Node::TS_WORLD); - App::GetCameraManager()->GetCameraNode()->pitch(Degree(-ms.Y.rel * 0.13f)); + App::GetCameraManager()->GetCameraNode()->yaw(Degree(-_arg.xrel * 0.13f), Ogre::Node::TS_WORLD); + App::GetCameraManager()->GetCameraNode()->pitch(Degree(-_arg.yrel * 0.13f)); App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::HIDDEN); @@ -586,11 +586,35 @@ bool CameraManager::mouseMoved(const OIS::MouseEvent& _arg) } } -bool CameraManager::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) +bool CameraManager::mouseWheelRolled(const OgreBites::MouseWheelEvent& _arg) { - const OIS::MouseState ms = _arg.state; + if (App::sim_state->getEnum() == SimState::PAUSED) + { + return true; // Do nothing when paused + } - if (ms.buttonDown(OIS::MB_Right) && _id == OIS::MB_Middle) + switch (m_current_behavior) + { + case CAMERA_BEHAVIOR_CHARACTER: { + if (!App::GetGameContext()->GetPlayerCharacter()) + return false; + if (!m_charactercam_is_3rdperson) + { + return true; + } + return CameraManager::CameraBehaviorStaticMouseWheelRolled(_arg); + } + case CAMERA_BEHAVIOR_STATIC: return this->CameraBehaviorStaticMouseWheelRolled(_arg); + case CAMERA_BEHAVIOR_VEHICLE: + case CAMERA_BEHAVIOR_VEHICLE_CINECAM: return CameraBehaviorOrbitMouseWheelRolled(_arg); + default: return false; + } +} + +bool CameraManager::mousePressed(const OgreBites::MouseButtonEvent& _arg) +{ + if (App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_RIGHT) + && App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_MIDDLE)) { ResetCurrentBehavior(); } @@ -599,9 +623,9 @@ bool CameraManager::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID { case CAMERA_BEHAVIOR_CHARACTER: return false; case CAMERA_BEHAVIOR_STATIC: return false; - case CAMERA_BEHAVIOR_VEHICLE: return this->CameraBehaviorVehicleMousePressed(_arg, _id); - case CAMERA_BEHAVIOR_VEHICLE_SPLINE: return this->CameraBehaviorVehicleMousePressed(_arg, _id); - case CAMERA_BEHAVIOR_VEHICLE_CINECAM: return this->CameraBehaviorVehicleMousePressed(_arg, _id); + case CAMERA_BEHAVIOR_VEHICLE: return this->CameraBehaviorVehicleMousePressed(_arg); + case CAMERA_BEHAVIOR_VEHICLE_SPLINE: return this->CameraBehaviorVehicleMousePressed(_arg); + case CAMERA_BEHAVIOR_VEHICLE_CINECAM: return this->CameraBehaviorVehicleMousePressed(_arg); case CAMERA_BEHAVIOR_FREE: return false; case CAMERA_BEHAVIOR_FIXED: return false; case CAMERA_BEHAVIOR_ISOMETRIC: return false; @@ -797,14 +821,13 @@ void CameraManager::UpdateCameraBehaviorStatic() App::GetCameraManager()->GetCamera()->setFOVy(Radian(fov)); } -bool CameraManager::CameraBehaviorStaticMouseMoved(const OIS::MouseEvent& _arg) +bool CameraManager::CameraBehaviorStaticMouseWheelRolled(const OgreBites::MouseWheelEvent& _arg) { - const OIS::MouseState ms = _arg.state; - if (ms.buttonDown(OIS::MB_Right)) + if (App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_RIGHT)) { - float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.00002f : 0.0002f; - m_staticcam_fov_exponent += ms.Z.rel * scale; + float scale = RoR::App::GetInputEngine()->isKeyDown(SDLK_LALT) ? 0.00002f : 0.0002f; + m_staticcam_fov_exponent += _arg.y * scale; m_staticcam_fov_exponent = Math::Clamp(m_staticcam_fov_exponent, 0.8f, 1.50f); App::gfx_static_cam_fov_exp->setVal(m_staticcam_fov_exponent); return true; @@ -855,7 +878,7 @@ void CameraManager::CameraBehaviorOrbitUpdate() ResetCurrentBehavior(); } - if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_RSHIFT) && RoR::App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE)) + if (RoR::App::GetInputEngine()->isKeyDown(SDLK_RSHIFT) && RoR::App::GetInputEngine()->isKeyDownValueBounce(OgreBites::SDLK_SPACE)) { m_cam_limit_movement = !m_cam_limit_movement; if (m_cam_limit_movement) @@ -931,16 +954,26 @@ void CameraManager::CameraBehaviorOrbitUpdate() App::GetCameraManager()->GetCameraNode()->lookAt(m_cam_look_at_smooth, Ogre::Node::TS_WORLD); } -bool CameraManager::CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg) +bool CameraManager::CameraBehaviorOrbitMouseMoved(const OgreBites::MouseMotionEvent& _arg) +{ + + if (App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_RIGHT)) + { + m_cam_rot_x += Degree(_arg.xrel * 0.13f); + m_cam_rot_y += Degree(-_arg.yrel * 0.13f); + return true; + } + + return false; +} + +bool CameraManager::CameraBehaviorOrbitMouseWheelRolled(const OgreBites::MouseWheelEvent& _arg) { - const OIS::MouseState ms = _arg.state; - if (ms.buttonDown(OIS::MB_Right)) + if (App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_RIGHT)) { - float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.002f : 0.02f; - m_cam_rot_x += Degree(ms.X.rel * 0.13f); - m_cam_rot_y += Degree(-ms.Y.rel * 0.13f); - m_cam_dist += -ms.Z.rel * scale; + float scale = RoR::App::GetInputEngine()->isKeyDown(SDLK_LALT) ? 0.002f : 0.02f; + m_cam_dist += -_arg.y * scale; return true; } @@ -965,17 +998,17 @@ void CameraManager::UpdateCameraBehaviorFree() Vector3 mTrans(Vector3::ZERO); Real cct_trans_scale(m_cct_trans_scale * 5.0f * m_cct_dt); - if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) || RoR::App::GetInputEngine()->isKeyDown(OIS::KC_RSHIFT)) + if (RoR::App::GetInputEngine()->isKeyDown(SDLK_LSHIFT) || RoR::App::GetInputEngine()->isKeyDown(SDLK_RSHIFT)) { cct_rot_scale *= 3.0f; cct_trans_scale *= 5.0f; } - if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL)) + if (RoR::App::GetInputEngine()->isKeyDown(SDLK_LCTRL)) { cct_rot_scale *= 6.0f; cct_trans_scale *= 10.0f; } - if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU)) + if (RoR::App::GetInputEngine()->isKeyDown(SDLK_LALT)) { cct_rot_scale *= 0.2f; cct_trans_scale *= 0.2f; @@ -1069,11 +1102,10 @@ void CameraManager::CameraBehaviorVehicleReset() m_cam_dist = m_cam_dist_min * 1.5f + 2.0f; } -bool CameraManager::CameraBehaviorVehicleMousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) +bool CameraManager::CameraBehaviorVehicleMousePressed(const OgreBites::MouseButtonEvent& _arg) { - const OIS::MouseState ms = _arg.state; - if ( ms.buttonDown(OIS::MB_Middle) && RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) ) + if ( App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_MIDDLE) && RoR::App::GetInputEngine()->isKeyDown(SDLK_LSHIFT) ) { if ( m_cct_player_actor && m_cct_player_actor->ar_custom_camera_node != NODENUM_INVALID) { @@ -1134,7 +1166,7 @@ void CameraManager::CameraBehaviorVehicleSplineUpdate() m_cam_look_at = m_splinecam_spline->interpolate(m_splinecam_spline_pos); - if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) && RoR::App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE)) + if (RoR::App::GetInputEngine()->isKeyDown(SDLK_LSHIFT) && RoR::App::GetInputEngine()->isKeyDownValueBounce(OgreBites::SDLK_SPACE)) { m_splinecam_auto_tracking = !m_splinecam_auto_tracking; if (m_splinecam_auto_tracking) @@ -1165,29 +1197,28 @@ void CameraManager::CameraBehaviorVehicleSplineUpdate() CameraManager::CameraBehaviorOrbitUpdate(); } -bool CameraManager::CameraBehaviorVehicleSplineMouseMoved( const OIS::MouseEvent& _arg) +bool CameraManager::CameraBehaviorVehicleSplineMouseMoved( const OgreBites::MouseMotionEvent& _arg) { - const OIS::MouseState ms = _arg.state; m_cam_ratio = 1.0f / (m_cct_dt * 4.0f); - if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL) && ms.buttonDown(OIS::MB_Right)) + if (RoR::App::GetInputEngine()->isKeyDown(SDLK_LCTRL) && App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_RIGHT)) { - Real splinePosDiff = ms.X.rel * std::max(0.00005f, m_splinecam_spline_len * 0.0000001f); + Real splinePosDiff = _arg.xrel * std::max(0.00005f, m_splinecam_spline_len * 0.0000001f); - if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) || RoR::App::GetInputEngine()->isKeyDown(OIS::KC_RSHIFT)) + if (RoR::App::GetInputEngine()->isKeyDown(SDLK_LSHIFT) || RoR::App::GetInputEngine()->isKeyDown(SDLK_RSHIFT)) { splinePosDiff *= 3.0f; } - if (RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU)) + if (RoR::App::GetInputEngine()->isKeyDown(SDLK_LALT)) { splinePosDiff *= 0.1f; } m_splinecam_spline_pos += splinePosDiff; - if (ms.X.rel > 0 && m_splinecam_spline_pos > 0.99f) + if (_arg.xrel > 0 && m_splinecam_spline_pos > 0.99f) { if (m_splinecam_spline_closed) { @@ -1198,7 +1229,7 @@ bool CameraManager::CameraBehaviorVehicleSplineMouseMoved( const OIS::MouseEven // u - turn } } - else if (ms.X.rel < 0 && m_splinecam_spline_pos < 0.01f) + else if (_arg.xrel < 0 && m_splinecam_spline_pos < 0.01f) { if (m_splinecam_spline_closed) { diff --git a/source/main/gfx/camera/CameraManager.h b/source/main/gfx/camera/CameraManager.h index e520ec44f6..8ccf354c68 100644 --- a/source/main/gfx/camera/CameraManager.h +++ b/source/main/gfx/camera/CameraManager.h @@ -23,7 +23,7 @@ #include "Application.h" -#include + #include namespace RoR { @@ -67,11 +67,13 @@ class CameraManager void NotifyVehicleChanged(Actor* new_vehicle); void CameraBehaviorOrbitReset(); - bool CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg); + bool CameraBehaviorOrbitMouseMoved(const OgreBites::MouseMotionEvent& _arg); + bool CameraBehaviorOrbitMouseWheelRolled(const OgreBites::MouseWheelEvent& _arg); void CameraBehaviorOrbitUpdate(); - bool mouseMoved(const OIS::MouseEvent& _arg); - bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); + bool mouseMoved(const OgreBites::MouseMotionEvent& _arg); + bool mousePressed(const OgreBites::MouseButtonEvent& _arg); + bool mouseWheelRolled(const OgreBites::MouseWheelEvent& _arg); void ResetAllBehaviors(); void ReCreateCameraNode(); //!< Needed since we call `Ogre::SceneManager::ClearScene()` after end of sim. session @@ -89,14 +91,14 @@ class CameraManager void ResetCurrentBehavior(); void DeactivateCurrentBehavior(); void UpdateCameraBehaviorStatic(); - bool CameraBehaviorStaticMouseMoved(const OIS::MouseEvent& _arg); + bool CameraBehaviorStaticMouseWheelRolled(const OgreBites::MouseWheelEvent& _arg); void UpdateCameraBehaviorFree(); void UpdateCameraBehaviorFixed(); void UpdateCameraBehaviorVehicle(); void CameraBehaviorVehicleReset(); - bool CameraBehaviorVehicleMousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); + bool CameraBehaviorVehicleMousePressed(const OgreBites::MouseButtonEvent& _arg); void CameraBehaviorVehicleSplineUpdate(); - bool CameraBehaviorVehicleSplineMouseMoved(const OIS::MouseEvent& _arg); + bool CameraBehaviorVehicleSplineMouseMoved(const OgreBites::MouseMotionEvent& _arg); void CameraBehaviorVehicleSplineReset(); void CameraBehaviorVehicleSplineCreateSpline(); void CameraBehaviorVehicleSplineUpdateSpline(); diff --git a/source/main/gui/GUIManager.cpp b/source/main/gui/GUIManager.cpp index 0981f84e66..f1583a962d 100644 --- a/source/main/gui/GUIManager.cpp +++ b/source/main/gui/GUIManager.cpp @@ -302,12 +302,11 @@ void GUIManager::UpdateMouseCursorVisibility() void GUIManager::NewImGuiFrame(float dt) { ImGuiIO& io = ImGui::GetIO(); - OIS::Keyboard* kb = App::GetInputEngine()->GetOisKeyboard(); // Read keyboard modifiers inputs - io.KeyCtrl = kb->isKeyDown(OIS::KC_LCONTROL); - io.KeyShift = kb->isKeyDown(OIS::KC_LSHIFT); - io.KeyAlt = kb->isKeyDown(OIS::KC_LMENU); + io.KeyCtrl = App::GetInputEngine()->isKeyDown(SDLK_LCTRL); + io.KeyShift = App::GetInputEngine()->isKeyDown(SDLK_LSHIFT); + io.KeyAlt = App::GetInputEngine()->isKeyDown(SDLK_LALT); io.KeySuper = false; // Call IMGUI diff --git a/source/main/gui/OverlayWrapper.cpp b/source/main/gui/OverlayWrapper.cpp index 106eba4f28..c9086f3ba1 100644 --- a/source/main/gui/OverlayWrapper.cpp +++ b/source/main/gui/OverlayWrapper.cpp @@ -493,32 +493,30 @@ void OverlayWrapper::updateStats(bool detailed) } } -bool OverlayWrapper::mouseMoved(const OIS::MouseEvent& _arg) +bool OverlayWrapper::mouseChanged() { if (!m_aerial_dashboard.needles_overlay->isVisible()) return false; bool res = false; - const OIS::MouseState ms = _arg.state; + Actor* player_actor = App::GetGameContext()->GetPlayerActor(); if (!player_actor) return res; - float mouseX = ms.X.abs / (float)ms.width; - float mouseY = ms.Y.abs / (float)ms.height; - - // TODO: fix: when the window is scaled, the findElementAt doesn not seem to pick up the correct element :-\ + const Ogre::Vector2 mouseNorm = App::GetInputEngine()->getMouseNormalizedScreenPos(); - if (player_actor->ar_driveable == AIRPLANE && ms.buttonDown(OIS::MB_Left)) + if (player_actor->ar_driveable == AIRPLANE + && App::GetInputEngine()->isMouseButtonDown(OgreBites::BUTTON_LEFT)) { const int num_engines = std::min(4, player_actor->ar_num_aeroengines); - OverlayElement* element = m_aerial_dashboard.needles_overlay->findElementAt(mouseX, mouseY); + OverlayElement* element = m_aerial_dashboard.needles_overlay->findElementAt(mouseNorm.x, mouseNorm.y); if (element) { res = true; - float thr_value = 1.0f - ((mouseY - thrtop - throffset) / thrheight); + float thr_value = 1.0f - ((mouseNorm.y - thrtop - throffset) / thrheight); for (int i = 0; i < num_engines; ++i) { if (element == m_aerial_dashboard.engines[i].thr_element) @@ -528,7 +526,7 @@ bool OverlayWrapper::mouseMoved(const OIS::MouseEvent& _arg) } } - element = m_aerial_dashboard.dash_overlay->findElementAt(mouseX, mouseY); + element = m_aerial_dashboard.dash_overlay->findElementAt(mouseNorm.x, mouseNorm.y); if (element) { res = true; @@ -633,14 +631,19 @@ bool OverlayWrapper::mouseMoved(const OIS::MouseEvent& _arg) return res; } -bool OverlayWrapper::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) +bool OverlayWrapper::mouseMoved(const OgreBites::MouseMotionEvent& arg) +{ + return this->mouseChanged(); +} + +bool OverlayWrapper::mousePressed(const OgreBites::MouseButtonEvent& arg) { - return mouseMoved(_arg); + return this->mouseChanged(); } -bool OverlayWrapper::mouseReleased(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) +bool OverlayWrapper::mouseReleased(const OgreBites::MouseButtonEvent& arg) { - return mouseMoved(_arg); + return this->mouseChanged(); } void OverlayWrapper::UpdatePressureOverlay(RoR::GfxActor* ga) diff --git a/source/main/gui/OverlayWrapper.h b/source/main/gui/OverlayWrapper.h index 755861b80f..80c70e3fa3 100644 --- a/source/main/gui/OverlayWrapper.h +++ b/source/main/gui/OverlayWrapper.h @@ -30,7 +30,7 @@ #include "Application.h" #include -#include +#include namespace RoR { @@ -129,9 +129,9 @@ class OverlayWrapper : public ZeroedMemoryAllocator void windowResized(); void resizeOverlay(LoadedOverlay & overlay); - bool mouseMoved(const OIS::MouseEvent& _arg); - bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); - bool mouseReleased(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); + bool mouseMoved(const OgreBites::MouseMotionEvent& arg); + bool mousePressed(const OgreBites::MouseButtonEvent& arg); + bool mouseReleased(const OgreBites::MouseButtonEvent& arg); float mTimeUntilNextToggle; void UpdatePressureOverlay(RoR::GfxActor* ga); @@ -163,6 +163,7 @@ class OverlayWrapper : public ZeroedMemoryAllocator void placeNeedle(Ogre::SceneNode *node, float x, float y, float len); void updateStats(bool detailed=false); void showPressureOverlay(bool show); + bool mouseChanged(); Ogre::OverlayElement *loadOverlayElement(Ogre::String name); diff --git a/source/main/gui/imgui/OgreImGui.cpp b/source/main/gui/imgui/OgreImGui.cpp index 9e1cf0a279..d658c0c085 100644 --- a/source/main/gui/imgui/OgreImGui.cpp +++ b/source/main/gui/imgui/OgreImGui.cpp @@ -34,6 +34,52 @@ using namespace RoR; +// Based on OGRE 13.5.3, file Components\Bites\src\OgreImGuiInputListener.cpp +// returning int instead of ImGuiKey because our outdated DearIMGUI doesn't have `ImGuiKey_None` +static int SDL2KeycodeToImGuiKey(int keycode) +{ + switch (keycode) + { + case '\t': return ImGuiKey_Tab; + case SDLK_LEFT: return ImGuiKey_LeftArrow; + case SDLK_RIGHT: return ImGuiKey_RightArrow; + case SDLK_UP: return ImGuiKey_UpArrow; + case SDLK_DOWN: return ImGuiKey_DownArrow; + case SDLK_PAGEUP: return ImGuiKey_PageUp; + case SDLK_PAGEDOWN: return ImGuiKey_PageDown; + case SDLK_HOME: return ImGuiKey_Home; + case SDLK_END: return ImGuiKey_End; + case SDLK_INSERT: return ImGuiKey_Insert; + case SDLK_DELETE: return ImGuiKey_Delete; + case '\b': return ImGuiKey_Backspace; + case SDLK_SPACE: return ImGuiKey_Space; + case SDLK_RETURN: return ImGuiKey_Enter; + case SDLK_ESCAPE: return ImGuiKey_Escape; + + case SDLK_KP_0: return ImGuiKey_KeyPad0; + case SDLK_KP_1: return ImGuiKey_KeyPad1; + case SDLK_KP_2: return ImGuiKey_KeyPad2; + case SDLK_KP_3: return ImGuiKey_KeyPad3; + case SDLK_KP_4: return ImGuiKey_KeyPad4; + case SDLK_KP_5: return ImGuiKey_KeyPad5; + case SDLK_KP_6: return ImGuiKey_KeyPad6; + case SDLK_KP_7: return ImGuiKey_KeyPad7; + case SDLK_KP_8: return ImGuiKey_KeyPad8; + case SDLK_KP_9: return ImGuiKey_KeyPad9; + + case 'a': return ImGuiKey_A; + case 'c': return ImGuiKey_C; + case 'v': return ImGuiKey_V; + case 'x': return ImGuiKey_X; + case 'y': return ImGuiKey_Y; + case 'z': return ImGuiKey_Z; + + case '/': return ImGuiKey_Slash; // Heh, apparently newer DearIMGUI added the same key we hacked-in :) + + } + return -1; +} + void OgreImGui::Init() { m_imgui_overlay = std::unique_ptr(new Ogre::ImGuiOverlay()); @@ -43,37 +89,7 @@ void OgreImGui::Init() // Disable 'imgui.ini' - we don't need to persist window positions. io.IniFilename = nullptr; - // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. - io.KeyMap[ImGuiKey_Tab] = OIS::KC_TAB; - io.KeyMap[ImGuiKey_LeftArrow] = OIS::KC_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = OIS::KC_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = OIS::KC_UP; - io.KeyMap[ImGuiKey_DownArrow] = OIS::KC_DOWN; - io.KeyMap[ImGuiKey_PageUp] = OIS::KC_PGUP; - io.KeyMap[ImGuiKey_PageDown] = OIS::KC_PGDOWN; - io.KeyMap[ImGuiKey_Home] = OIS::KC_HOME; - io.KeyMap[ImGuiKey_End] = OIS::KC_END; - io.KeyMap[ImGuiKey_Delete] = OIS::KC_DELETE; - io.KeyMap[ImGuiKey_Backspace] = OIS::KC_BACK; - io.KeyMap[ImGuiKey_Enter] = OIS::KC_RETURN; - io.KeyMap[ImGuiKey_Escape] = OIS::KC_ESCAPE; - io.KeyMap[ImGuiKey_A] = OIS::KC_A; - io.KeyMap[ImGuiKey_C] = OIS::KC_C; - io.KeyMap[ImGuiKey_V] = OIS::KC_V; - io.KeyMap[ImGuiKey_X] = OIS::KC_X; - io.KeyMap[ImGuiKey_Y] = OIS::KC_Y; - io.KeyMap[ImGuiKey_Z] = OIS::KC_Z; - io.KeyMap[ImGuiKey_KeyPad0] = OIS::KC_NUMPAD0; - io.KeyMap[ImGuiKey_KeyPad1] = OIS::KC_NUMPAD1; - io.KeyMap[ImGuiKey_KeyPad2] = OIS::KC_NUMPAD2; - io.KeyMap[ImGuiKey_KeyPad3] = OIS::KC_NUMPAD3; - io.KeyMap[ImGuiKey_KeyPad4] = OIS::KC_NUMPAD4; - io.KeyMap[ImGuiKey_KeyPad5] = OIS::KC_NUMPAD5; - io.KeyMap[ImGuiKey_KeyPad6] = OIS::KC_NUMPAD6; - io.KeyMap[ImGuiKey_KeyPad7] = OIS::KC_NUMPAD7; - io.KeyMap[ImGuiKey_KeyPad8] = OIS::KC_NUMPAD8; - io.KeyMap[ImGuiKey_KeyPad9] = OIS::KC_NUMPAD9; - io.KeyMap[ImGuiKey_Slash] = OIS::KC_SLASH; + // NOTE: Setting up `io.KeyMap` isn't possible with SDL2 because the values must be 0-512 and SDL's Keycodes are bitmasks which are much larger. // Load font m_imgui_overlay->addFont("rigsofrods/fonts/Roboto-Medium", @@ -85,49 +101,79 @@ void OgreImGui::Init() m_imgui_overlay->show(); } -void OgreImGui::InjectMouseMoved( const OIS::MouseEvent &arg ) +void OgreImGui::InjectMouseMoved(const OgreBites::MouseMotionEvent& arg) { + ImGuiIO& io = ImGui::GetIO(); + io.MousePos.x = arg.x; + io.MousePos.y = arg.y; +} + +void OgreImGui::InjectMouseWheelRolled(const OgreBites::MouseWheelEvent& arg) +{ ImGuiIO& io = ImGui::GetIO(); + io.MouseWheel = Ogre::Math::Clamp((float)arg.y, -1 / 3.f, 1 / 3.f); +} + - io.MousePos.x = arg.state.X.abs; - io.MousePos.y = arg.state.Y.abs; - io.MouseWheel = Ogre::Math::Clamp((float)arg.state.Z.rel, -1/3.f, 1/3.f); +// map sdl2 mouse buttons to imgui (copypasted from OgreImGuiInputListener.cpp) +static int sdl2imgui(int b) +{ + switch (b) + { + case 2: + return 2; + case 3: + return 1; + default: + return b - 1; + } } -void OgreImGui::InjectMousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) +void OgreImGui::InjectMousePressed(const OgreBites::MouseButtonEvent& arg) { ImGuiIO& io = ImGui::GetIO(); + int id = sdl2imgui(arg.button); if (id<5) { io.MouseDown[id] = true; } } -void OgreImGui::InjectMouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) +void OgreImGui::InjectMouseReleased(const OgreBites::MouseButtonEvent& arg) { ImGuiIO& io = ImGui::GetIO(); + int id = sdl2imgui(arg.button); if (id<5) { io.MouseDown[id] = false; } } -void OgreImGui::InjectKeyPressed( const OIS::KeyEvent &arg ) +void OgreImGui::InjectKeyPressed(const OgreBites::KeyboardEvent& arg) { ImGuiIO& io = ImGui::GetIO(); - io.KeysDown[arg.key] = true; + int key = SDL2KeycodeToImGuiKey(arg.keysym.sym); + if (key != -1) + { + io.KeysDown[key] = true; + } +} - if (arg.text>0) +void OgreImGui::InjectKeyReleased(const OgreBites::KeyboardEvent& arg) +{ + ImGuiIO& io = ImGui::GetIO(); + int key = SDL2KeycodeToImGuiKey(arg.keysym.sym); + if (key != -1) { - io.AddInputCharacter((unsigned short)arg.text); + io.KeysDown[key] = false; } } -void OgreImGui::InjectKeyReleased( const OIS::KeyEvent &arg ) +void OgreImGui::InjectTextInput(const OgreBites::TextInputEvent& arg) { ImGuiIO& io = ImGui::GetIO(); - io.KeysDown[arg.key] = false; + io.AddInputCharactersUTF8(arg.chars); } void OgreImGui::renderQueueStarted(Ogre::uint8 queueGroupId, diff --git a/source/main/gui/imgui/OgreImGui.h b/source/main/gui/imgui/OgreImGui.h index d0f0560f51..e8773bcf55 100644 --- a/source/main/gui/imgui/OgreImGui.h +++ b/source/main/gui/imgui/OgreImGui.h @@ -29,8 +29,7 @@ #include #include -#include -#include +#include #include // DearIMGUI math functions, copypasted from @@ -57,11 +56,13 @@ class OgreImGui: public Ogre::RenderQueueListener void Init(); // Input-injecting functions - void InjectMouseMoved( const OIS::MouseEvent &arg ); - void InjectMousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ); - void InjectMouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ); - void InjectKeyPressed( const OIS::KeyEvent &arg ); - void InjectKeyReleased( const OIS::KeyEvent &arg ); + void InjectMouseMoved(const OgreBites::MouseMotionEvent& arg); + void InjectMouseWheelRolled(const OgreBites::MouseWheelEvent& arg); + void InjectMousePressed(const OgreBites::MouseButtonEvent& arg); + void InjectMouseReleased(const OgreBites::MouseButtonEvent& arg); + void InjectKeyPressed(const OgreBites::KeyboardEvent& arg); + void InjectKeyReleased(const OgreBites::KeyboardEvent& arg); + void InjectTextInput(const OgreBites::TextInputEvent& arg); // Ogre::RenderQueueListener virtual void renderQueueStarted(Ogre::uint8 queueGroupId, diff --git a/source/main/phc.h b/source/main/phc.h index 9f06bbfdfb..4cd1cd68f2 100644 --- a/source/main/phc.h +++ b/source/main/phc.h @@ -32,8 +32,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -41,6 +41,7 @@ #include #include #include +#include #ifdef USE_SOCKETW diff --git a/source/main/terrain/TerrainEditor.cpp b/source/main/terrain/TerrainEditor.cpp index e2ab00bd15..a80c3a138a 100644 --- a/source/main/terrain/TerrainEditor.cpp +++ b/source/main/terrain/TerrainEditor.cpp @@ -142,7 +142,7 @@ void TerrainEditor::UpdateInputEvents(float dt) std::string ssmsg = _L("Rotating: ") + axis; App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, ssmsg, "information.png"); } - if (App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE)) + if (App::GetInputEngine()->isKeyDownValueBounce(OgreBites::SDLK_SPACE)) { m_object_tracking = !m_object_tracking; std::string ssmsg = m_object_tracking ? _L("Enabled object tracking") : _L("Disabled object tracking"); @@ -211,9 +211,9 @@ void TerrainEditor::UpdateInputEvents(float dt) if (translation != Vector3::ZERO || rotation != 0.0f) { - float scale = App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.1f : 1.0f; - scale *= App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) ? 3.0f : 1.0f; - scale *= App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL) ? 10.0f : 1.0f; + float scale = App::GetInputEngine()->isKeyDown(SDLK_LALT) ? 0.1f : 1.0f; + scale *= App::GetInputEngine()->isKeyDown(SDLK_LSHIFT) ? 3.0f : 1.0f; + scale *= App::GetInputEngine()->isKeyDown(SDLK_LCTRL) ? 10.0f : 1.0f; object_list[m_object_index].position += translation * scale * dt; sn->setPosition(object_list[m_object_index].position); diff --git a/source/main/utils/ForceFeedback.cpp b/source/main/utils/ForceFeedback.cpp index 6e4e0e22ab..6235ec5cb3 100644 --- a/source/main/utils/ForceFeedback.cpp +++ b/source/main/utils/ForceFeedback.cpp @@ -27,13 +27,14 @@ #include "GameContext.h" #include "InputEngine.h" -#include + #include namespace RoR { void ForceFeedback::Setup() { + /* FIXME-SDL using namespace Ogre; m_device = App::GetInputEngine()->getForceFeedbackDevice(); if (!m_device) @@ -45,13 +46,19 @@ void ForceFeedback::Setup() m_device->setAutoCenterMode(false); m_device->setMasterGain(0.0); + */ + //do not load effect now, its too early } void ForceFeedback::SetForces(float roll, float pitch, float wspeed, float dircommand, float stress) { + /* FIXME-SDL + if (!m_device) { return; } + + //LOG(String("ForceFeedback: R=")+TOSTRING(roll)+" D="+TOSTRING(dir)+" S="+TOSTRING(wspeed)+" H="+TOSTRING(stress)); if (!m_hydro_effect) { @@ -88,22 +95,27 @@ void ForceFeedback::SetForces(float roll, float pitch, float wspeed, float dirco hydroConstForce->level = ff; //-10K to +10k } m_device->modify(m_hydro_effect); + + */ } void ForceFeedback::SetEnabled(bool b) { + /* FIXME-SDL if (!m_device) { return; } - + if (b != m_enabled) { float gain = (b) ? App::io_ffb_master_gain->getFloat() : 0.f; m_device->setMasterGain(gain); } m_enabled = b; + */ } void ForceFeedback::Update() { + /* FIXME-SDL if (!m_device) { App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_WARNING, @@ -123,6 +135,7 @@ void ForceFeedback::Update() player_actor->ar_hydro_dir_command, player_actor->GetFFbHydroForces()); } + */ } } // namespace RoR diff --git a/source/main/utils/ForceFeedback.h b/source/main/utils/ForceFeedback.h index b32fa79250..053e2f3620 100644 --- a/source/main/utils/ForceFeedback.h +++ b/source/main/utils/ForceFeedback.h @@ -21,8 +21,7 @@ #pragma once -// Forward decl. -namespace OIS { class ForceFeedback; class Effect; } + namespace RoR { @@ -42,8 +41,8 @@ class ForceFeedback /// -hydro beam stress, the ideal data source for FF wheels void SetForces(float roll, float pitch, float wspeed, float dircommand, float stress); - OIS::ForceFeedback* m_device = nullptr; - OIS::Effect* m_hydro_effect = nullptr; + //FIXME-SDL OIS::ForceFeedback* m_device = nullptr; + //FIXME-SDL OIS::Effect* m_hydro_effect = nullptr; bool m_enabled = false; /// Disables FF when not in vehicle }; diff --git a/source/main/utils/InputEngine.cpp b/source/main/utils/InputEngine.cpp index 4b00042a2d..02ba5e1b56 100644 --- a/source/main/utils/InputEngine.cpp +++ b/source/main/utils/InputEngine.cpp @@ -28,11 +28,11 @@ #include "Language.h" #include +#include +#include using namespace RoR; -const char* mOISDeviceType[6] = {"Unknown Device", "Keyboard", "Mouse", "JoyStick", "Tablet", "Other Device"}; - InputEvent eventInfo[] = { // Common: generic {"COMMON_ACCELERATE_SIMULATION", EV_COMMON_ACCELERATE_SIMULATION, "Keyboard CTRL+EQUALS", _LC("InputEvent", "accelerate the simulation")}, @@ -395,102 +395,22 @@ InputEvent eventInfo[] = { #define strnlen(str,len) strlen(str) #endif -//Use this define to signify OIS will be used as a DLL -//(so that dll import/export macros are in effect) -#define OIS_DYNAMIC_LIB -#include - -#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX -#include -//#include -#endif - using namespace std; using namespace Ogre; -using namespace OIS; const std::string InputEngine::DEFAULT_MAPFILE = "input.map"; InputEngine::InputEngine() : free_joysticks(0) - , mForceFeedback(0) - , mInputManager(0) - , mKeyboard(0) - , mMouse(0) , uniqueCounter(0) { - for (int i = 0; i < MAX_JOYSTICKS; i++) - mJoy[i] = 0; - - LOG("*** Loading OIS ***"); - initAllKeys(); setup(); - windowResized(App::GetAppContext()->GetRenderWindow()); -} - -InputEngine::~InputEngine() -{ - destroy(); -} - -void InputEngine::destroy() -{ - if (mInputManager) - { - LOG("*** Terminating OIS ***"); - if (mMouse) - { - mInputManager->destroyInputObject(mMouse); - mMouse = 0; - } - if (mKeyboard) - { - mInputManager->destroyInputObject(mKeyboard); - mKeyboard = 0; - } - if (mJoy) - { - for (int i = 0; i < MAX_JOYSTICKS; i++) - { - if (!mJoy[i]) - continue; - mInputManager->destroyInputObject(mJoy[i]); - mJoy[i] = 0; - } - } - - OIS::InputManager::destroyInputSystem(mInputManager); - mInputManager = 0; - } } void InputEngine::setup() { - size_t hWnd = 0; - App::GetAppContext()->GetRenderWindow()->getCustomAttribute("WINDOW", &hWnd); - - LOG("*** Initializing OIS ***"); - - //try to delete old ones first (linux can only handle one at a time) - destroy(); - ParamList pl; - pl.insert(OIS::ParamList::value_type("WINDOW", TOSTRING(hWnd))); - if (App::io_input_grab_mode->getEnum() != RoR::IoInputGrabMode::ALL) - { -#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX - pl.insert(OIS::ParamList::value_type("x11_mouse_hide", "true")); - pl.insert(OIS::ParamList::value_type("XAutoRepeatOn", "false")); - pl.insert(OIS::ParamList::value_type("x11_mouse_grab", "false")); - pl.insert(OIS::ParamList::value_type("x11_keyboard_grab", "false")); -#else - pl.insert(OIS::ParamList::value_type("w32_mouse", "DISCL_FOREGROUND")); - pl.insert(OIS::ParamList::value_type("w32_mouse", "DISCL_NONEXCLUSIVE")); - pl.insert(OIS::ParamList::value_type("w32_keyboard", "DISCL_FOREGROUND")); - pl.insert(OIS::ParamList::value_type("w32_keyboard", "DISCL_NONEXCLUSIVE")); -#endif // LINUX - } #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 if (App::io_input_grab_mode->getEnum() != IoInputGrabMode::ALL) @@ -499,89 +419,6 @@ void InputEngine::setup() } #endif - mInputManager = OIS::InputManager::createInputSystem(pl); - - //Print debugging information - unsigned int v = mInputManager->getVersionNumber(); - LOG("OIS Version: " + TOSTRING(v>>16) + String(".") + TOSTRING((v>>8) & 0x000000FF) + String(".") + TOSTRING(v & 0x000000FF)); - LOG("+ Release Name: " + mInputManager->getVersionName()); - LOG("+ Manager: " + mInputManager->inputSystemName()); - LOG("+ Total Keyboards: " + TOSTRING(mInputManager->getNumberOfDevices(OISKeyboard))); - LOG("+ Total Mice: " + TOSTRING(mInputManager->getNumberOfDevices(OISMouse))); - LOG("+ Total JoySticks: " + TOSTRING(mInputManager->getNumberOfDevices(OISJoyStick))); - - //List all devices - OIS::DeviceList deviceList = mInputManager->listFreeDevices(); - for (OIS::DeviceList::iterator i = deviceList.begin(); i != deviceList.end(); ++i) - LOG("* Device: " + String(mOISDeviceType[i->first]) + String(" Vendor: ") + i->second); - - //Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) - mKeyboard = 0; - - try - { - mKeyboard = static_cast(mInputManager->createInputObject(OISKeyboard, true)); - mKeyboard->setTextTranslation(OIS::Keyboard::Unicode); - } - catch (OIS::Exception& ex) - { - LOG(String("Exception raised on keyboard creation: ") + String(ex.eText)); - } - - - try - { - //This demo uses at most 10 joysticks - use old way to create (i.e. disregard vendor) - int numSticks = std::min(mInputManager->getNumberOfDevices(OISJoyStick), 10); - free_joysticks = 0; - for (int i = 0; i < numSticks; ++i) - { - mJoy[i] = (JoyStick*)mInputManager->createInputObject(OISJoyStick, true); - free_joysticks++; - //create force feedback too - //here, we take the first device we can get, but we could take a device index - if (!mForceFeedback) - mForceFeedback = (OIS::ForceFeedback*)mJoy[i]->queryInterface(OIS::Interface::ForceFeedback); - - LOG("Creating Joystick " + TOSTRING(i + 1) + " (" + mJoy[i]->vendor() + ")"); - LOG("* Axes: " + TOSTRING(mJoy[i]->getNumberOfComponents(OIS_Axis))); - LOG("* Sliders: " + TOSTRING(mJoy[i]->getNumberOfComponents(OIS_Slider))); - LOG("* POV/HATs: " + TOSTRING(mJoy[i]->getNumberOfComponents(OIS_POV))); - LOG("* Buttons: " + TOSTRING(mJoy[i]->getNumberOfComponents(OIS_Button))); - LOG("* Vector3: " + TOSTRING(mJoy[i]->getNumberOfComponents(OIS_Vector3))); - } - } - catch (OIS::Exception& ex) - { - LOG(String("Exception raised on joystick creation: ") + String(ex.eText)); - } - - try - { - mMouse = static_cast(mInputManager->createInputObject(OISMouse, true)); - } - catch (OIS::Exception& ex) - { - LOG(String("Exception raised on mouse creation: ") + String(ex.eText)); - } - - - if (free_joysticks) - { - for (int i = 0; i < free_joysticks; i++) - joyState[i] = mJoy[i]->getJoyStickState(); - } - - // set the mouse to the middle of the screen, hackish! -#if _WIN32 - // under linux, this will not work and the cursor will never reach (0,0) - if (mMouse && RoR::App::GetAppContext()->GetRenderWindow()) - { - OIS::MouseState& mutableMouseState = const_cast(mMouse->getMouseState()); - mutableMouseState.X.abs = RoR::App::GetAppContext()->GetRenderWindow()->getWidth() * 0.5f; - mutableMouseState.Y.abs = RoR::App::GetAppContext()->GetRenderWindow()->getHeight() * 0.5f; - } -#endif // _WIN32 // load default mappings this->loadConfigFile(-1); @@ -594,18 +431,13 @@ void InputEngine::setup() completeMissingEvents(); } -OIS::MouseState InputEngine::getMouseState() -{ - return mMouse->getMouseState(); -} - -String InputEngine::getKeyNameForKeyCode(OIS::KeyCode keycode) +String InputEngine::getKeyNameForKeyCode(SDL_Keycode keycode) { - if (keycode == KC_LSHIFT || keycode == KC_RSHIFT) + if (keycode & KMOD_SHIFT) return "SHIFT"; - if (keycode == KC_LCONTROL || keycode == KC_RCONTROL) + if (keycode & KMOD_CTRL) return "CTRL"; - if (keycode == KC_LMENU || keycode == KC_RMENU) + if (keycode & KMOD_ALT) return "ALT"; for (allit = allkeys.begin(); allit != allkeys.end(); allit++) { @@ -617,79 +449,37 @@ String InputEngine::getKeyNameForKeyCode(OIS::KeyCode keycode) void InputEngine::Capture() { - mKeyboard->capture(); - mMouse->capture(); - - for (int i = 0; i < free_joysticks; i++) - { - if (mJoy[i]) - { - mJoy[i]->capture(); - } - } -} - -void InputEngine::windowResized(Ogre::RenderWindow* rw) -{ - //update mouse area - unsigned int width, height; - int left, top; - rw->getMetrics(width, height, left, top); - const OIS::MouseState& ms = mMouse->getMouseState(); - ms.width = width; - ms.height = height; -} - -void InputEngine::SetKeyboardListener(OIS::KeyListener* keyboard_listener) -{ - ROR_ASSERT(mKeyboard != nullptr); - mKeyboard->setEventCallback(keyboard_listener); -} - -void InputEngine::SetMouseListener(OIS::MouseListener* mouse_listener) -{ - ROR_ASSERT(mMouse != nullptr); - mMouse->setEventCallback(mouse_listener); -} - -void InputEngine::SetJoystickListener(OIS::JoyStickListener* obj) -{ - for (int i = 0; i < free_joysticks; i++) - { - mJoy[i]->setEventCallback(obj); - } + App::GetAppContext()->pollEvents(); } /* --- Joystick Events ------------------------------------------ */ -void InputEngine::ProcessJoystickEvent(const OIS::JoyStickEvent& arg) +void InputEngine::ProcessJoystickEvent(const OgreBites::AxisEvent& arg) { + /* FIXME-SDL int i = arg.device->getID(); if (i < 0 || i >= MAX_JOYSTICKS) i = 0; joyState[i] = arg.state; + */ } /* --- Key Events ------------------------------------------ */ -void InputEngine::ProcessKeyPress(const OIS::KeyEvent& arg) +void InputEngine::ProcessKeyPress(const OgreBites::KeyboardEvent& arg) { - keyState[arg.key] = 1; + keyState[arg.keysym.sym] = true; } -void InputEngine::ProcessKeyRelease(const OIS::KeyEvent& arg) +void InputEngine::ProcessKeyRelease(const OgreBites::KeyboardEvent& arg) { - keyState[arg.key] = 0; + keyState[arg.keysym.sym] = false; } -/* --- Mouse Events ------------------------------------------ */ -void InputEngine::ProcessMouseEvent(const OIS::MouseEvent& arg) -{ - mouseState = arg.state; -} + /* --- Custom Methods ------------------------------------------ */ void InputEngine::resetKeys() { - for (std::map::iterator iter = keyState.begin(); iter != keyState.end(); ++iter) + for (auto iter = keyState.begin(); iter != keyState.end(); ++iter) { iter->second = false; } @@ -919,31 +709,29 @@ float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSo // check for modificators if (t.explicite) { - if (t.ctrl != (keyState[KC_LCONTROL] || keyState[KC_RCONTROL])) + if (t.ctrl != (keyState[SDLK_LCTRL] || keyState[SDLK_RCTRL])) break; - if (t.shift != (keyState[KC_LSHIFT] || keyState[KC_RSHIFT])) + if (t.shift != (keyState[SDLK_LSHIFT] || keyState[SDLK_RSHIFT])) break; - if (t.alt != (keyState[KC_LMENU] || keyState[KC_RMENU])) + if (t.alt != (keyState[SDLK_LALT] || keyState[SDLK_RALT])) break; } else { - if (t.ctrl && !(keyState[KC_LCONTROL] || keyState[KC_RCONTROL])) + if (t.ctrl && !(keyState[SDLK_LCTRL] || keyState[SDLK_RCTRL])) break; - if (t.shift && !(keyState[KC_LSHIFT] || keyState[KC_RSHIFT])) + if (t.shift && !(keyState[SDLK_LSHIFT] || keyState[SDLK_RSHIFT])) break; - if (t.alt && !(keyState[KC_LMENU] || keyState[KC_RMENU])) + if (t.alt && !(keyState[SDLK_LALT] || keyState[SDLK_RALT])) break; } value = 1; break; case ET_MouseButton: - //if (t.mouseButtonNumber == 0) - // TODO: FIXME - value = mouseState.buttonDown(MB_Left); + value = this->isMouseButtonDown(OgreBites::BUTTON_LEFT) || this->isMouseButtonDown(OgreBites::BUTTON_RIGHT); break; case ET_JoystickButton: - { + {/* FIXME-SDL if (t.joystickNumber > free_joysticks || !mJoy[t.joystickNumber]) { value = 0; @@ -958,10 +746,11 @@ float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSo continue; } value = joyState[t.joystickNumber].mButtons[t.joystickButtonNumber]; + */ } break; case ET_JoystickPov: - { + { /*FIXME-SDL if (t.joystickNumber > free_joysticks || !mJoy[t.joystickNumber]) { value = 0; @@ -979,6 +768,7 @@ float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSo value = 1; else value = 0; + */ } break; } @@ -987,6 +777,7 @@ float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSo { switch (t.eventtype) { + /* FIXME-SDL, unused?? case ET_MouseAxisX: value = mouseState.X.abs / 32767; break; @@ -996,10 +787,12 @@ float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSo case ET_MouseAxisZ: value = mouseState.Z.abs / 32767; break; + */ case ET_JoystickAxisRel: case ET_JoystickAxisAbs: { + /* FIXME-SDL if (t.joystickNumber > free_joysticks || !mJoy[t.joystickNumber]) { value = 0; @@ -1073,11 +866,13 @@ float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSo else value = 0; } + */ } break; case ET_JoystickSliderX: case ET_JoystickSliderY: { + /* FIXME-SDL if (t.joystickNumber > free_joysticks || !mJoy[t.joystickNumber]) { value = 0; @@ -1090,6 +885,7 @@ float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSo value = (value + 1) / 2; // full axis if (t.joystickSliderReverse) value = 1.0 - value; // reversed + */ } break; } @@ -1101,19 +897,22 @@ float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSo return returnValue; } -bool InputEngine::isKeyDown(OIS::KeyCode key) +bool InputEngine::isKeyDown(OgreBites::Keycode mod) { - if (!mKeyboard) - return false; - return this->mKeyboard->isKeyDown(key); + return (SDL_GetModState() & mod) != 0; +} + +bool InputEngine::isMouseButtonDown(OgreBites::ButtonType btn) +{ + return (SDL_GetMouseState(nullptr, nullptr) & btn) != 0; } -bool InputEngine::isKeyDownEffective(OIS::KeyCode mod) +bool InputEngine::isKeyDownEffective(SDL_Keycode mod) { return this->keyState[mod]; } -bool InputEngine::isKeyDownValueBounce(OIS::KeyCode mod, float time) +bool InputEngine::isKeyDownValueBounce(SDL_Keycode mod, float time) { if (event_times[-mod] > 0) return false; @@ -1317,12 +1116,12 @@ bool InputEngine::processLine(const char* line, int deviceID) char keycodes[256] = {}; char keycodes_work[256] = {}; - OIS::KeyCode key = KC_UNASSIGNED; + SDL_Keycode key = SDLK_UNKNOWN; sscanf(line, "%s %s %s", eventName, evtype, keycodes); // separate all keys and construct the key combination //LOG("try to add key: " + String(eventName)+","+ String(evtype)+","+String(keycodes)); - strncpy(keycodes_work, keycodes, 255); + std::strncpy(keycodes_work, keycodes, 255); keycodes_work[255] = '\0'; char* token = strtok(keycodes_work, delimiters); @@ -1346,7 +1145,7 @@ bool InputEngine::processLine(const char* line, int deviceID) #ifndef NOOGRE LOG("unknown key: " + string(keycodes)); #endif - key = KC_UNASSIGNED; + key = SDLK_UNKNOWN; } else { @@ -1368,11 +1167,11 @@ bool InputEngine::processLine(const char* line, int deviceID) t_key.keyCode = key; t_key.explicite = expl; - strncpy(t_key.configline, keycodes, 128); - strncpy(t_key.group, getEventGroup(eventName).c_str(), 128); - strncpy(t_key.tmp_eventname, eventName, 128); + std::strncpy(t_key.configline, keycodes, 128); + std::strncpy(t_key.group, getEventGroup(eventName).c_str(), 128); + std::strncpy(t_key.tmp_eventname, eventName, 128); - strncpy(t_key.comments, cur_comment.c_str(), 1024); + std::strncpy(t_key.comments, cur_comment.c_str(), 1024); addEvent(eventID, t_key); return true; @@ -1392,17 +1191,17 @@ bool InputEngine::processLine(const char* line, int deviceID) t_joy.joystickButtonNumber = buttonNo; if (!strcmp(tmp2, "!NEW!")) { - strncpy(t_joy.configline, tmp2, 128); + std::strncpy(t_joy.configline, tmp2, 128); } else { char tmp[256] = {}; sprintf(tmp, "%d", buttonNo); - strncpy(t_joy.configline, tmp, 128); + std::strncpy(t_joy.configline, tmp, 128); } - strncpy(t_joy.group, getEventGroup(eventName).c_str(), 128); - strncpy(t_joy.tmp_eventname, eventName, 128); - strncpy(t_joy.comments, cur_comment.c_str(), 1024); + std::strncpy(t_joy.group, getEventGroup(eventName).c_str(), 128); + std::strncpy(t_joy.tmp_eventname, eventName, 128); + std::strncpy(t_joy.comments, cur_comment.c_str(), 1024); cur_comment = ""; addEvent(eventID, t_joy); return true; @@ -1478,10 +1277,10 @@ bool InputEngine::processLine(const char* line, int deviceID) t_joy.joystickAxisReverse = reverse; t_joy.joystickAxisNumber = axisNo; t_joy.joystickNumber = (deviceID == -1 ? joyNo : deviceID); - strncpy(t_joy.configline, options, 128); - strncpy(t_joy.group, getEventGroup(eventName).c_str(), 128); - strncpy(t_joy.tmp_eventname, eventName, 128); - strncpy(t_joy.comments, cur_comment.c_str(), 1024); + std::strncpy(t_joy.configline, options, 128); + std::strncpy(t_joy.group, getEventGroup(eventName).c_str(), 128); + std::strncpy(t_joy.tmp_eventname, eventName, 128); + std::strncpy(t_joy.comments, cur_comment.c_str(), 1024); cur_comment = ""; addEvent(eventID, t_joy); //LOG("added axis: " + TOSTRING(axisNo)); @@ -1511,6 +1310,7 @@ bool InputEngine::processLine(const char* line, int deviceID) if (eventID == -1) return false; + /* FIXME-SDL int direction = OIS::Pov::Centered; if (!strcmp(dir, "North")) direction = OIS::Pov::North; @@ -1536,13 +1336,14 @@ bool InputEngine::processLine(const char* line, int deviceID) t_pov.joystickPovNumber = povNumber; t_pov.joystickPovDirection = direction; - strncpy(t_pov.group, getEventGroup(eventName).c_str(), 128); - strncpy(t_pov.tmp_eventname, eventName, 128); - strncpy(t_pov.comments, cur_comment.c_str(), 1024); - strncpy(t_pov.configline, dir, 128); + std::strncpy(t_pov.group, getEventGroup(eventName).c_str(), 128); + std::strncpy(t_pov.tmp_eventname, eventName, 128); + std::strncpy(t_pov.comments, cur_comment.c_str(), 1024); + std::strncpy(t_pov.configline, dir, 128); cur_comment = ""; addEvent(eventID, t_pov); //LOG("added axis: " + TOSTRING(axisNo)); + */ return true; } case ET_JoystickSliderX: @@ -1558,7 +1359,7 @@ bool InputEngine::processLine(const char* line, int deviceID) bool reverse = false; char tmp[256] = {}; - strncpy(tmp, options, 255); + std::strncpy(tmp, options, 255); tmp[255] = '\0'; char* token = strtok(tmp, delimiters); while (token != NULL) @@ -1583,10 +1384,10 @@ bool InputEngine::processLine(const char* line, int deviceID) t_slider.joystickSliderReverse = reverse; // TODO: add region support to sliders! t_slider.joystickSliderRegion = 0; - strncpy(t_slider.configline, options, 128); - strncpy(t_slider.group, getEventGroup(eventName).c_str(), 128); - strncpy(t_slider.tmp_eventname, eventName, 128); - strncpy(t_slider.comments, cur_comment.c_str(), 1024); + std::strncpy(t_slider.configline, options, 128); + std::strncpy(t_slider.group, getEventGroup(eventName).c_str(), 128); + std::strncpy(t_slider.tmp_eventname, eventName, 128); + std::strncpy(t_slider.comments, cur_comment.c_str(), 1024); cur_comment = ""; addEvent(eventID, t_slider); //LOG("added axis: " + TOSTRING(axisNo)); @@ -1599,6 +1400,7 @@ bool InputEngine::processLine(const char* line, int deviceID) int InputEngine::getCurrentJoyButton(int& joystickNumber, int& button) { + /* FIXME-SDL for (int j = 0; j < free_joysticks; j++) { for (int i = 0; i < (int)joyState[j].mButtons.size(); i++) @@ -1610,12 +1412,13 @@ int InputEngine::getCurrentJoyButton(int& joystickNumber, int& button) return 1; } } - } + }*/ return 0; } int InputEngine::getCurrentPovValue(int& joystickNumber, int& pov, int& povdir) { + /* FIXME-SDL for (int j = 0; j < free_joysticks; j++) { for (int i = 0; i < MAX_JOYSTICK_POVS; i++) @@ -1628,17 +1431,17 @@ int InputEngine::getCurrentPovValue(int& joystickNumber, int& pov, int& povdir) return 1; } } - } + }*/ return 0; } Ogre::Vector2 InputEngine::getMouseNormalizedScreenPos() { - OIS::MouseState const& mstate = mMouse->getMouseState(); - Ogre::Vector2 res; - res.x = static_cast(mstate.X.abs) / static_cast(mstate.width); - res.y = static_cast(mstate.Y.abs) / static_cast(mstate.height); - return res; + int x = 0, y = 0; + SDL_GetMouseState(&x, &y); + return Ogre::Vector2( + static_cast(x) / ImGui::GetIO().DisplaySize.x, + static_cast(y) / ImGui::GetIO().DisplaySize.y); } event_trigger_t InputEngine::newEvent() @@ -1648,42 +1451,27 @@ event_trigger_t InputEngine::newEvent() return res; } -int InputEngine::getJoyComponentCount(OIS::ComponentType type, int joystickNumber) -{ - if (joystickNumber > free_joysticks || !mJoy[joystickNumber]) - return 0; - return mJoy[joystickNumber]->getNumberOfComponents(type); -} - std::string InputEngine::getJoyVendor(int joystickNumber) { - if (joystickNumber > free_joysticks || !mJoy[joystickNumber]) + // FIXME return "unknown"; - return mJoy[joystickNumber]->vendor(); -} -JoyStickState* InputEngine::getCurrentJoyState(int joystickNumber) -{ - if (joystickNumber > free_joysticks) - return 0; - return &joyState[joystickNumber]; } int InputEngine::getCurrentKeyCombo(String* combo) { - std::map::iterator i; int keyCounter = 0; int modCounter = 0; // list all modificators first - for (i = keyState.begin(); i != keyState.end(); i++) + for (auto i = keyState.begin(); i != keyState.end(); i++) { if (i->second) { - if (i->first != KC_LSHIFT && i->first != KC_RSHIFT && i->first != KC_LCONTROL && i->first != KC_RCONTROL && i->first != KC_LMENU && i->first != KC_RMENU) + if (i->first != SDLK_LSHIFT && i->first != SDLK_RSHIFT && i->first != SDLK_LCTRL && i->first != SDLK_RCTRL && i->first != SDLK_LALT && i->first != SDLK_RALT) continue; modCounter++; - String keyName = getKeyNameForKeyCode((OIS::KeyCode)i->first); + String keyName = getKeyNameForKeyCode(i->first); if (*combo == "") *combo = keyName; else @@ -1692,13 +1480,13 @@ int InputEngine::getCurrentKeyCombo(String* combo) } // now list all keys - for (i = keyState.begin(); i != keyState.end(); i++) + for (auto i = keyState.begin(); i != keyState.end(); i++) { if (i->second) { - if (i->first == KC_LSHIFT || i->first == KC_RSHIFT || i->first == KC_LCONTROL || i->first == KC_RCONTROL || i->first == KC_LMENU || i->first == KC_RMENU) + if (i->first == SDLK_LSHIFT || i->first == SDLK_RSHIFT || i->first == SDLK_LCTRL || i->first == SDLK_RCTRL || i->first == SDLK_LALT || i->first == SDLK_RALT) continue; - String keyName = getKeyNameForKeyCode((OIS::KeyCode)i->first); + String keyName = getKeyNameForKeyCode(i->first); if (*combo == "") *combo = keyName; else @@ -1724,7 +1512,7 @@ String InputEngine::getEventGroup(String eventName) { const char delimiters[] = "_"; char tmp[256] = {}; - strncpy(tmp, eventName.c_str(), 255); + std::strncpy(tmp, eventName.c_str(), 255); tmp[255] = '\0'; char* token = strtok(tmp, delimiters); while (token != NULL) @@ -1830,7 +1618,7 @@ bool InputEngine::loadConfigFile(int deviceID) { ROR_ASSERT(deviceID < free_joysticks); - String deviceStr = mJoy[deviceID]->vendor(); + String deviceStr; // FIXME-SDL = mJoy[deviceID]->vendor(); // care about unsuitable chars String repl = "\\/ #@?!$%^&*()+=-><.:'|\";"; @@ -2007,161 +1795,162 @@ String InputEngine::eventIDToDescription(int eventID) void InputEngine::initAllKeys() { - allkeys["0"] = KC_0; - allkeys["1"] = KC_1; - allkeys["2"] = KC_2; - allkeys["3"] = KC_3; - allkeys["4"] = KC_4; - allkeys["5"] = KC_5; - allkeys["6"] = KC_6; - allkeys["7"] = KC_7; - allkeys["8"] = KC_8; - allkeys["9"] = KC_9; - allkeys["A"] = KC_A; - allkeys["ABNT_C1"] = KC_ABNT_C1; - allkeys["ABNT_C2"] = KC_ABNT_C2; - allkeys["ADD"] = KC_ADD; - allkeys["APOSTROPHE"] = KC_APOSTROPHE; - allkeys["APPS"] = KC_APPS; - allkeys["AT"] = KC_AT; - allkeys["AX"] = KC_AX; - allkeys["B"] = KC_B; - allkeys["BACK"] = KC_BACK; - allkeys["BACKSLASH"] = KC_BACKSLASH; - allkeys["C"] = KC_C; - allkeys["CALCULATOR"] = KC_CALCULATOR; - allkeys["CAPITAL"] = KC_CAPITAL; - allkeys["COLON"] = KC_COLON; - allkeys["COMMA"] = KC_COMMA; - allkeys["CONVERT"] = KC_CONVERT; - allkeys["D"] = KC_D; - allkeys["DECIMAL"] = KC_DECIMAL; - allkeys["DELETE"] = KC_DELETE; - allkeys["DIVIDE"] = KC_DIVIDE; - allkeys["DOWN"] = KC_DOWN; - allkeys["E"] = KC_E; - allkeys["END"] = KC_END; - allkeys["EQUALS"] = KC_EQUALS; - allkeys["ESCAPE"] = KC_ESCAPE; - allkeys["F"] = KC_F; - allkeys["F1"] = KC_F1; - allkeys["F10"] = KC_F10; - allkeys["F11"] = KC_F11; - allkeys["F12"] = KC_F12; - allkeys["F13"] = KC_F13; - allkeys["F14"] = KC_F14; - allkeys["F15"] = KC_F15; - allkeys["F2"] = KC_F2; - allkeys["F3"] = KC_F3; - allkeys["F4"] = KC_F4; - allkeys["F5"] = KC_F5; - allkeys["F6"] = KC_F6; - allkeys["F7"] = KC_F7; - allkeys["F8"] = KC_F8; - allkeys["F9"] = KC_F9; - allkeys["G"] = KC_G; - allkeys["GRAVE"] = KC_GRAVE; - allkeys["H"] = KC_H; - allkeys["HOME"] = KC_HOME; - allkeys["I"] = KC_I; - allkeys["INSERT"] = KC_INSERT; - allkeys["J"] = KC_J; - allkeys["K"] = KC_K; - allkeys["KANA"] = KC_KANA; - allkeys["KANJI"] = KC_KANJI; - allkeys["L"] = KC_L; - allkeys["LBRACKET"] = KC_LBRACKET; - allkeys["LCONTROL"] = KC_LCONTROL; - allkeys["LEFT"] = KC_LEFT; - allkeys["LMENU"] = KC_LMENU; - allkeys["LSHIFT"] = KC_LSHIFT; - allkeys["LWIN"] = KC_LWIN; - allkeys["M"] = KC_M; - allkeys["MAIL"] = KC_MAIL; - allkeys["MEDIASELECT"] = KC_MEDIASELECT; - allkeys["MEDIASTOP"] = KC_MEDIASTOP; - allkeys["MINUS"] = KC_MINUS; - allkeys["MULTIPLY"] = KC_MULTIPLY; - allkeys["MUTE"] = KC_MUTE; - allkeys["MYCOMPUTER"] = KC_MYCOMPUTER; - allkeys["N"] = KC_N; - allkeys["NEXTTRACK"] = KC_NEXTTRACK; - allkeys["NOCONVERT"] = KC_NOCONVERT; - allkeys["NUMLOCK"] = KC_NUMLOCK; - allkeys["NUMPAD0"] = KC_NUMPAD0; - allkeys["NUMPAD1"] = KC_NUMPAD1; - allkeys["NUMPAD2"] = KC_NUMPAD2; - allkeys["NUMPAD3"] = KC_NUMPAD3; - allkeys["NUMPAD4"] = KC_NUMPAD4; - allkeys["NUMPAD5"] = KC_NUMPAD5; - allkeys["NUMPAD6"] = KC_NUMPAD6; - allkeys["NUMPAD7"] = KC_NUMPAD7; - allkeys["NUMPAD8"] = KC_NUMPAD8; - allkeys["NUMPAD9"] = KC_NUMPAD9; - allkeys["NUMPADCOMMA"] = KC_NUMPADCOMMA; - allkeys["NUMPADENTER"] = KC_NUMPADENTER; - allkeys["NUMPADEQUALS"] = KC_NUMPADEQUALS; - allkeys["O"] = KC_O; - allkeys["OEM_102"] = KC_OEM_102; - allkeys["P"] = KC_P; - allkeys["PAUSE"] = KC_PAUSE; - allkeys["PERIOD"] = KC_PERIOD; - allkeys["PGDOWN"] = KC_PGDOWN; - allkeys["PGUP"] = KC_PGUP; - allkeys["PLAYPAUSE"] = KC_PLAYPAUSE; - allkeys["POWER"] = KC_POWER; - allkeys["PREVTRACK"] = KC_PREVTRACK; - allkeys["Q"] = KC_Q; - allkeys["R"] = KC_R; - allkeys["RBRACKET"] = KC_RBRACKET; - allkeys["RCONTROL"] = KC_RCONTROL; - allkeys["RETURN"] = KC_RETURN; - allkeys["RIGHT"] = KC_RIGHT; - allkeys["RMENU"] = KC_RMENU; - allkeys["RSHIFT"] = KC_RSHIFT; - allkeys["RWIN"] = KC_RWIN; - allkeys["S"] = KC_S; - allkeys["SCROLL"] = KC_SCROLL; - allkeys["SEMICOLON"] = KC_SEMICOLON; - allkeys["SLASH"] = KC_SLASH; - allkeys["SLEEP"] = KC_SLEEP; - allkeys["SPACE"] = KC_SPACE; - allkeys["STOP"] = KC_STOP; - allkeys["SUBTRACT"] = KC_SUBTRACT; - allkeys["SYSRQ"] = KC_SYSRQ; - allkeys["T"] = KC_T; - allkeys["TAB"] = KC_TAB; - allkeys["U"] = KC_U; - allkeys["UNDERLINE"] = KC_UNDERLINE; - allkeys["UNLABELED"] = KC_UNLABELED; - allkeys["UP"] = KC_UP; - allkeys["V"] = KC_V; - allkeys["VOLUMEDOWN"] = KC_VOLUMEDOWN; - allkeys["VOLUMEUP"] = KC_VOLUMEUP; - allkeys["W"] = KC_W; - allkeys["WAKE"] = KC_WAKE; - allkeys["WEBBACK"] = KC_WEBBACK; - allkeys["WEBFAVORITES"] = KC_WEBFAVORITES; - allkeys["WEBFORWARD"] = KC_WEBFORWARD; - allkeys["WEBHOME"] = KC_WEBHOME; - allkeys["WEBREFRESH"] = KC_WEBREFRESH; - allkeys["WEBSEARCH"] = KC_WEBSEARCH; - allkeys["WEBSTOP"] = KC_WEBSTOP; - allkeys["X"] = KC_X; - allkeys["Y"] = KC_Y; - allkeys["YEN"] = KC_YEN; - allkeys["Z"] = KC_Z; + // see SDL_keycode.h + + allkeys["0"] = SDLK_0; + allkeys["1"] = SDLK_1; + allkeys["2"] = SDLK_2; + allkeys["3"] = SDLK_3; + allkeys["4"] = SDLK_4; + allkeys["5"] = SDLK_5; + allkeys["6"] = SDLK_6; + allkeys["7"] = SDLK_7; + allkeys["8"] = SDLK_8; + allkeys["9"] = SDLK_9; + allkeys["A"] = SDLK_a; + allkeys["ABNT_C1"] = SDLK_APP1; // ?? + allkeys["ABNT_C2"] = SDLK_APP2; // ?? + allkeys["ADD"] = SDLK_PLUS; + allkeys["APOSTROPHE"] = SDLK_QUOTE; + allkeys["APPS"] = SDLK_APPLICATION; + allkeys["AT"] = SDLK_AT; + allkeys["AX"] = SDLK_HASH; // ?? + allkeys["B"] = SDLK_b; + allkeys["BACK"] = SDLK_BACKSPACE; + allkeys["BACKSLASH"] = SDLK_BACKSLASH; + allkeys["C"] = SDLK_c; + allkeys["CALCULATOR"] = SDLK_CALCULATOR; + //allkeys["CAPITAL"] = KC_CAPITAL; + allkeys["COLON"] = SDLK_COLON; + allkeys["COMMA"] = SDLK_COMMA; + //allkeys["CONVERT"] = KC_CONVERT; + allkeys["D"] = SDLK_d; + //allkeys["DECIMAL"] = KC_DECIMAL; + allkeys["DELETE"] = SDLK_DELETE; + allkeys["DIVIDE"] = SDLK_SLASH; + allkeys["DOWN"] = SDLK_DOWN; + allkeys["E"] = SDLK_e; + allkeys["END"] = SDLK_END; + allkeys["EQUALS"] = SDLK_EQUALS; + allkeys["ESCAPE"] = SDLK_ESCAPE; + allkeys["F"] = SDLK_f; + allkeys["F1"] = SDLK_F1; + allkeys["F10"] = SDLK_F10; + allkeys["F11"] = SDLK_F11; + allkeys["F12"] = SDLK_F12; + allkeys["F13"] = SDLK_F13; + allkeys["F14"] = SDLK_F14; + allkeys["F15"] = SDLK_F15; + allkeys["F2"] = SDLK_F2; + allkeys["F3"] = SDLK_F3; + allkeys["F4"] = SDLK_F4; + allkeys["F5"] = SDLK_F5; + allkeys["F6"] = SDLK_F6; + allkeys["F7"] = SDLK_F7; + allkeys["F8"] = SDLK_F8; + allkeys["F9"] = SDLK_F9; + allkeys["G"] = SDLK_g; + allkeys["GRAVE"] = SDLK_BACKQUOTE; + allkeys["H"] = SDLK_h; + allkeys["HOME"] = SDLK_HOME; + allkeys["I"] = SDLK_i; + allkeys["INSERT"] = SDLK_INSERT; + allkeys["J"] = SDLK_j; + allkeys["K"] = SDLK_k; + //allkeys["KANA"] - no SDL KeyCode, should we use scancodes? - SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LANG3); // See SDL_scancode.h + //allkeys["KANJI"] - no SDL KeyCode, should we use scancodes? - SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LANG2); // ?? - See SDL_scancode.h + allkeys["L"] = SDLK_l; + allkeys["LBRACKET"] = SDLK_LEFTBRACKET; + allkeys["LCONTROL"] = SDLK_LCTRL; + allkeys["LEFT"] = SDLK_LEFT; + allkeys["LMENU"] = SDLK_LALT; + allkeys["LSHIFT"] = SDLK_LSHIFT; + allkeys["LWIN"] = SDLK_LGUI; // ?? + allkeys["M"] = SDLK_m; + allkeys["MAIL"] = SDLK_MAIL; + allkeys["MEDIASELECT"] = SDLK_MEDIASELECT; + allkeys["MEDIASTOP"] = SDLK_AUDIOSTOP; + allkeys["MINUS"] = SDLK_MINUS; + allkeys["MULTIPLY"] = SDLK_ASTERISK; + allkeys["MUTE"] = SDLK_MUTE; + allkeys["MYCOMPUTER"] = SDLK_COMPUTER; + allkeys["N"] = SDLK_n; + allkeys["NEXTTRACK"] = SDLK_AUDIONEXT; + //allkeys["NOCONVERT"] = KC_NOCONVERT; + allkeys["NUMLOCK"] = SDLK_NUMLOCKCLEAR; + allkeys["NUMPAD0"] = SDLK_KP_0; + allkeys["NUMPAD1"] = SDLK_KP_1; + allkeys["NUMPAD2"] = SDLK_KP_2; + allkeys["NUMPAD3"] = SDLK_KP_3; + allkeys["NUMPAD4"] = SDLK_KP_4; + allkeys["NUMPAD5"] = SDLK_KP_5; + allkeys["NUMPAD6"] = SDLK_KP_6; + allkeys["NUMPAD7"] = SDLK_KP_7; + allkeys["NUMPAD8"] = SDLK_KP_8; + allkeys["NUMPAD9"] = SDLK_KP_9; + allkeys["NUMPADCOMMA"] = SDLK_KP_PERIOD; + allkeys["NUMPADENTER"] = SDLK_KP_ENTER; + allkeys["NUMPADEQUALS"] = SDLK_KP_EQUALS; + allkeys["O"] = SDLK_o; + //allkeys["OEM_102"] = KC_OEM_102; + allkeys["P"] = SDLK_p; + allkeys["PAUSE"] = SDLK_PAUSE; + allkeys["PERIOD"] = SDLK_PERIOD; + allkeys["PGDOWN"] = SDLK_PAGEDOWN; + allkeys["PGUP"] = SDLK_PAGEUP; + allkeys["PLAYPAUSE"] = SDLK_PAUSE; + allkeys["POWER"] = SDLK_POWER; + allkeys["PREVTRACK"] = SDLK_AUDIOPREV; + allkeys["Q"] = SDLK_q; + allkeys["R"] = SDLK_r; + allkeys["RBRACKET"] = SDLK_RIGHTBRACKET; + allkeys["RCONTROL"] = SDLK_RCTRL; + allkeys["RETURN"] = SDLK_RETURN; + allkeys["RIGHT"] = SDLK_RIGHT; + allkeys["RMENU"] = SDLK_RALT; + allkeys["RSHIFT"] = SDLK_RSHIFT; + allkeys["RWIN"] = SDLK_RGUI; // ?? + allkeys["S"] = SDLK_s; + allkeys["SCROLL"] = SDLK_SCROLLLOCK; + allkeys["SEMICOLON"] = SDLK_SEMICOLON; + allkeys["SLASH"] = SDLK_SLASH; + allkeys["SLEEP"] = SDLK_SLEEP; + allkeys["SPACE"] = SDLK_SPACE; + allkeys["STOP"] = SDLK_STOP; + allkeys["SUBTRACT"] = SDLK_MINUS; + allkeys["SYSRQ"] = SDLK_PRINTSCREEN; + allkeys["T"] = SDLK_t; + allkeys["TAB"] = SDLK_TAB; + allkeys["U"] = SDLK_u; + allkeys["UNDERLINE"] = SDLK_UNDERSCORE; + //allkeys["UNLABELED"] = KC_UNLABELED; + allkeys["UP"] = SDLK_UP; + allkeys["V"] = SDLK_v; + allkeys["VOLUMEDOWN"] = SDLK_VOLUMEDOWN; + allkeys["VOLUMEUP"] = SDLK_VOLUMEUP; + allkeys["W"] = SDLK_w; + allkeys["WAKE"] = SDLK_POWER; + allkeys["WEBBACK"] = SDLK_AC_BACK; + allkeys["WEBFAVORITES"] = SDLK_AC_BOOKMARKS; + allkeys["WEBFORWARD"] = SDLK_AC_FORWARD; + allkeys["WEBHOME"] = SDLK_AC_HOME; + allkeys["WEBREFRESH"] = SDLK_AC_REFRESH; + allkeys["WEBSEARCH"] = SDLK_AC_SEARCH; + allkeys["WEBSTOP"] = SDLK_AC_STOP; + allkeys["X"] = SDLK_x; + allkeys["Y"] = SDLK_y; + //allkeys["YEN"] - no SDL KeyCode, should we use scancodes? - SDL_SCANCODE_INTERNATIONAL3 // See SDL_scancode.h + allkeys["Z"] = SDLK_z; } String InputEngine::getKeyForCommand(int eventID) { - std::map>::iterator it = events.find(eventID); + EventMap::iterator it = events.find(eventID); if (it == events.end()) return String(); if (it->second.empty()) return String(); - std::vector::iterator it2 = it->second.begin(); - return getKeyNameForKeyCode((OIS::KeyCode)it2->keyCode); + return this->getKeyNameForKeyCode(it->second.front().keyCode); } diff --git a/source/main/utils/InputEngine.h b/source/main/utils/InputEngine.h index e07e2fcfa0..fdc8b15c63 100644 --- a/source/main/utils/InputEngine.h +++ b/source/main/utils/InputEngine.h @@ -29,12 +29,7 @@ #include "Application.h" #include "ForceFeedback.h" -#include "OISEvents.h" -#include "OISForceFeedback.h" -#include "OISInputManager.h" -#include "OISJoyStick.h" -#include "OISKeyboard.h" -#include "OISMouse.h" +#include #define MAX_JOYSTICKS 10 #define MAX_JOYSTICK_POVS 4 @@ -416,13 +411,11 @@ struct event_trigger_t enum eventtypes eventtype; int configDeviceID; //!< For which device (which config file) was this binding defined? // keyboard - int keyCode; + SDL_Keycode keyCode; bool explicite; bool ctrl; bool shift; bool alt; - //mouse - int mouseButtonNumber; //joystick buttons int joystickNumber; int joystickButtonNumber; @@ -457,30 +450,23 @@ class InputEngine : public ZeroedMemoryAllocator public: typedef std::vector TriggerVec; typedef std::map EventMap; + typedef std::map KeyCodeMap; + typedef std::map KeyStateMap; static const std::string DEFAULT_MAPFILE; //!< = "input.map"; static const int DEFAULT_MAPFILE_DEVICEID = -1; //!< virtual device ID for "input.map" entries static const int BUILTIN_MAPPING_DEVICEID = -2; //!< virtual device ID for builtin defaults InputEngine(); - ~InputEngine(); - - // Setup - - void SetKeyboardListener(OIS::KeyListener* obj); - OIS::Keyboard* GetOisKeyboard() { return mKeyboard; } - void SetMouseListener(OIS::MouseListener* obj); - void SetJoystickListener(OIS::JoyStickListener* obj); - void destroy(); + ~InputEngine() {}; // Input processing void Capture(); void updateKeyBounces(float dt); - void ProcessMouseEvent(const OIS::MouseEvent& arg); - void ProcessKeyPress(const OIS::KeyEvent& arg); - void ProcessKeyRelease(const OIS::KeyEvent& arg); - void ProcessJoystickEvent(const OIS::JoyStickEvent& arg); + void ProcessKeyPress(const OgreBites::KeyboardEvent& arg); + void ProcessKeyRelease(const OgreBites::KeyboardEvent& arg); + void ProcessJoystickEvent(const OgreBites::AxisEvent& arg); void resetKeys(); // Event info @@ -494,7 +480,6 @@ class InputEngine : public ZeroedMemoryAllocator Ogre::String getEventDefaultConfig(int eventID); bool isEventDefined(int eventID); int getKeboardKeyForCommand(int eventID); //!< Returns -1 if not Keyboard - int getJoyComponentCount(OIS::ComponentType type, int joystickNumber); std::string getJoyVendor(int joystickNumber); int getNumJoysticks() { return free_joysticks; } EventMap& getEvents() { return events; }; @@ -525,14 +510,13 @@ class InputEngine : public ZeroedMemoryAllocator bool isEventAnalog(int eventID); bool getEventBoolValueBounce(int eventID, float time = 0.2f); float getEventBounceTime(int eventID); - bool isKeyDownEffective(OIS::KeyCode mod); //!< Reads RoR internal buffer - bool isKeyDownValueBounce(OIS::KeyCode mod, float time = 0.2f); + bool isKeyDownEffective(SDL_Keycode mod); //!< Reads RoR internal buffer + bool isKeyDownValueBounce(SDL_Keycode, float time = 0.2f); // Direct input device states - OIS::JoyStickState* getCurrentJoyState(int joystickNumber); - OIS::MouseState getMouseState(); - bool isKeyDown(OIS::KeyCode mod); //!< Asks OIS directly + bool isKeyDown(OgreBites::Keycode mod); //!< Asks SDL directly; only works for modifier keys. + bool isMouseButtonDown(OgreBites::ButtonType btn); //!< Asks SDL directly int getCurrentKeyCombo(Ogre::String* combo); //!< Returns number of non-modifier keys pressed (or modifier count as negative number). int getCurrentJoyButton(int& joystickNumber, int& button); int getCurrentPovValue(int& joystickNumber, int& pov, int& povdir); @@ -544,32 +528,19 @@ class InputEngine : public ZeroedMemoryAllocator static int resolveEventName(Ogre::String eventName); static Ogre::String eventIDToName(int eventID); static Ogre::String eventIDToDescription(int eventID); - std::string getKeyNameForKeyCode(OIS::KeyCode keycode); - - - // Misc - - void windowResized(Ogre::RenderWindow* rw); - OIS::ForceFeedback* getForceFeedbackDevice() { return mForceFeedback; }; + std::string getKeyNameForKeyCode(SDL_Keycode keycode); protected: //OIS Input devices - OIS::InputManager* mInputManager; - OIS::Mouse* mMouse; - OIS::Keyboard* mKeyboard; - OIS::JoyStick* mJoy[MAX_JOYSTICKS]; int free_joysticks; //!< Number of detected game controllers - OIS::ForceFeedback* mForceFeedback; int uniqueCounter; // this stores the key/button/axis values - std::map keyState; - OIS::JoyStickState joyState[MAX_JOYSTICKS]; - OIS::MouseState mouseState; + KeyStateMap keyState; // define event aliases - std::map> events; + EventMap events; std::map event_times; std::string m_loaded_configs[MAX_JOYSTICKS]; bool loadMapping(Ogre::String fileName, int deviceID); @@ -578,8 +549,8 @@ class InputEngine : public ZeroedMemoryAllocator void initAllKeys(); void setup(); - std::map allkeys; - std::map::iterator allit; + KeyCodeMap allkeys; + KeyCodeMap::iterator allit; float deadZone(float axis, float dz); float axisLinearity(float axisValue, float linearity);