Skip to content

Commit

Permalink
Replaced OIS with OgreBites input + SDL (not functional yet)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ohlidalp committed Dec 28, 2022
1 parent b25c8ee commit 0d2a1d7
Show file tree
Hide file tree
Showing 23 changed files with 582 additions and 733 deletions.
28 changes: 0 additions & 28 deletions cmake/DependenciesConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 43 additions & 30 deletions source/main/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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);
Expand All @@ -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>() == 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>() == 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);

Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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<AppState>() == RoR::AppState::SIMULATION)
{
Expand Down
34 changes: 15 additions & 19 deletions source/main/AppContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#include "Application.h"
#include "ForceFeedback.h"

#include <Bites/OgreApplicationContext.h>
#include <Bites/OgreWindowEventUtilities.h>
#include <Bites/OgreInput.h>
#include <Ogre.h>
#include <OIS.h>


namespace RoR {

Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions source/main/gameplay/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions source/main/gameplay/RecoveryMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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())
Expand Down
15 changes: 11 additions & 4 deletions source/main/gameplay/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "Language.h"
#include "Utils.h"

#include <SDL2/SDL_mouse.h>

using namespace Ogre;
using namespace RoR;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -298,4 +303,6 @@ void Replay::UpdateInputEvents()
}
}
}

prevMouseX = mouseX;
}
1 change: 1 addition & 0 deletions source/main/gameplay/Replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Replay : public ZeroedMemoryAllocator
int writeIndex;
int firstRun;
unsigned long curFrameTime;
int prevMouseX = 0;

// malloc'ed
node_simple_t* nodes;
Expand Down
Loading

0 comments on commit 0d2a1d7

Please sign in to comment.