Thinkofname/steven

Mouse controls broken on Linux, unable to look up

Opened this issue · 4 comments

Hello I am intrigued by this project and am trying to set up a working environment to use it (I'll include details below, had to be sure to use old project versions for compatibility), Steven compiles and runs on Ubuntu Linux 18.04.1 and I can connect to a server, but.... the player is stuck looking at the ground:

screen shot 2018-09-27 at 8 05 21 pm

The keyboard controls operate well, and the mouse can be moved left/right to rotate, but moving the mouse up or down doesn't let the player look up or down (I think this is yaw?). Up/down mouse movements just rotate the player as well.

Configuration: Ubuntu 18.04.1 Linux following steps on https://github.com/Thinkofname/steven/wiki/Compiling-and-or-running#compiling-on-linux
Running in VMware Fusion 11.0.0 (note: required for OpenGL 3.3, cannot use VirtualBox because it only supports OpenGL 2.1, similar error as in #65)
Installed dependencies as follows:

# use compatible nightly rust
rustup install nightly-2017-05-14
rustup default nightly-2017-05-14

sudo apt install -y gcc
# problem: openssl 1.1.0 is incompatible, DH struct see https://issues.apache.org/jira/browse/PROTON-1381
#sudo apt install -y libssl-dev
pushd ..
wget http://www.openssl.org/source/openssl-1.0.0a.tar.gz
tar -xf openssl-1.0.0a.tar.gz
cd openssl-1.0.0a
sudo apt install -y make
./config
# workaround broken pod2man errors
echo =pod > doc/apps/cms.pod
echo =pod > doc/apps/genpkey.pod
echo =pod > doc/apps/openssl.pod
echo =pod > doc/apps/smime.pod
echo =pod > doc/crypto/X509_STORE_CTX_get_error.pod
echo =pod > doc/ssl/SSL_COMP_add_compression_method.pod
echo =pod > doc/ssl/SSL_CTX_add_session.pod
echo =pod > doc/ssl/SSL_CTX_load_verify_locations.pod
echo =pod > doc/ssl/SSL_CTX_set_client_CA_list.pod
echo =pod > doc/ssl/SSL_CTX_set_session_id_context.pod
echo =pod > doc/ssl/SSL_CTX_set_ssl_version.pod
echo =pod > doc/ssl/SSL_CTX_use_psk_identity_hint.pod
echo =pod > doc/ssl/SSL_accept.pod
echo =pod > doc/ssl/SSL_clear.pod
echo =pod > doc/ssl/SSL_connect.pod
echo =pod > doc/ssl/SSL_do_handshake.pod
echo =pod > doc/ssl/SSL_read.pod
echo =pod > doc/ssl/SSL_session_reused.pod
echo =pod > doc/ssl/SSL_set_fd.pod
echo =pod > doc/ssl/SSL_set_session.pod
echo =pod > doc/ssl/SSL_shutdown.pod
echo =pod > doc/ssl/SSL_write.pod
sudo make install
export OPENSSL_INCLUDE_DIR=/usr/local/ssl/include
export OPENSSL_LIB_DIR=/usr/local/ssl/lib64
popd
sudo apt install libsdl2-dev -y

# build
cargo build --release

Maybe an incompatibility with a newer version of SDL2? If it matters this is the version of libsdl2-dev I am using from the Ubuntu repository:

$ apt show libsdl2-dev
Package: libsdl2-dev
Version: 2.0.8+dfsg1-1ubuntu1.18.04.1
Priority: optional
Section: universe/libdevel
Source: libsdl2
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian SDL packages maintainers <pkg-sdl-maintainers@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 4,298 kB

I haven't touched this project in a long time so I'm kinda surprised you even got it to compile. Its possible the mouse issue is from the VM not the game (due to relative movements) but its hard for me to say.

I got it to compile but it wasn't easy :) I tried to replicate the environment available circa 2017, but may have missed something. The problem doesn't occur with the same version of sdl2 (2.0.8, albeit not "2.0.8+dfsg1-1ubuntu1.18.04.1") on macOS so it could very well be a VM problem, or something specific to Linux or Ubuntu or their window manager or SDL patches... if I add logging to see what is going on in the MouseMotion event:

diff --git a/src/main.rs b/src/main.rs
index 46345c1..013a871 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -301,6 +301,7 @@ fn handle_window_event(window: &sdl2::video::Window,
         Event::Quit{..} => game.should_close = true,
 
         Event::MouseMotion{x, y, xrel, yrel, ..} => {
+println!("MouseMotion x={} y={} xrel={} yrel={}", x, y, xrel,  yrel);
             let (width, height) = window.size();
             if game.focused {
                 if !mouse.relative_mouse_mode() {
@@ -312,6 +313,7 @@ fn handle_window_event(window: &sdl2::video::Window,
                     let rotation = game.server.entities.get_component_mut(player, game.server.rotation).unwrap();
                     rotation.yaw -= rx;
                     rotation.pitch -= ry;
+println!("yaw -= {}, pitch -= {}  new yaw={}, pitch={}", rx, ry, rotation.yaw, rotation.pitch);
                     if rotation.pitch < (PI/2.0) + 0.01 {
                         rotation.pitch = (PI/2.0) + 0.01;
                     }

curiously the relative motions are extremely high, causing very negative yaw and pitch:

MouseMotion x=853 y=479 xrel=12564 yrel=62057
yaw -= 6.2819685901570494, pitch -= 31.02834485827571  new yaw=-17471.054212063395, pitch=-29.447548531480813
MouseMotion x=853 y=479 xrel=12694 yrel=61977
yaw -= 6.346968265158674, pitch -= 30.98834505827471  new yaw=-17477.401180328554, pitch=-29.407548731479814
MouseMotion x=853 y=479 xrel=12760 yrel=61977
yaw -= 6.379968100159499, pitch -= 30.98834505827471  new yaw=-17483.781148428712, pitch=-29.407548731479814

compared to more reasonable small integer relative xrel/yrel on mac (haven't tested on Windows yet):

yaw -= -0.0014999925000374998, pitch -= -0.0024999875000624996  new yaw=-4.129624054683908, pitch=3.6352860543462566
MouseMotion x=228 y=386 xrel=-2 yrel=-5
yaw -= -0.0009999950000249998, pitch -= -0.0024999875000624996  new yaw=-4.128624059683883, pitch=3.637786041846319
MouseMotion x=227 y=384 xrel=-1 yrel=-2
yaw -= -0.0004999975000124999, pitch -= -0.0009999950000249998  new yaw=-4.12812406218387, pitch=3.638786036846344
MouseMotion x=227 y=382 xrel=0 yrel=-2
yaw -= 0, pitch -= -0.0009999950000249998  new yaw=-4.12812406218387, pitch=3.6397860318463686
MouseMotion x=227 y=381 xrel=0 yrel=-1
yaw -= 0, pitch -= -0.0004999975000124999  new yaw=-4.12812406218387, pitch=3.640286029346381

Found this unresolved bug report: https://bugzilla.libsdl.org/show_bug.cgi?id=2150 SDL_SetRelativeMouseMode broken on Linux (SDL_SetWindowGrab broken only in VMs)

Translating the workaround to Rust, this seems to fix the problem:

diff --git a/src/main.rs b/src/main.rs
index 46345c1..1ae69ce 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -193,6 +193,7 @@ fn main() {
                             .resizable()
                             .build()
                             .expect("Could not create sdl window.");
+    sdl2::hint::set_with_priority("SDL_MOUSE_RELATIVE_MODE_WARP", "1", sdl2::hint::Hint::Override);
     let gl_attr = sdl_video.gl_attr();
     gl_attr.set_stencil_size(0);
     gl_attr.set_depth_size(24);