2018-11-04 14:48:03 -05:00
|
|
|
use crate::console;
|
2016-04-09 04:56:55 -04:00
|
|
|
use std::marker::PhantomData;
|
Update to glutin 0.22.0-alpha5, remove wasm_stub (#260)
Update from glutin 0.21.x fork to glutin 0.22.0-alpha5 and corresponding
compatible version of winit. This removes our custom temporary wasm_stub
branches, back to mainline glutin and winit, and is a step towards WebAssembly
compatibility, most importantly merging the game loop and event loops as
required by winit _which now supports wasm_. Not yet functional on the web
because other web dependencies have to be added, see #171 and #34, but native
functionality is preserved.
* Update for 0.22 glutin API changes:
* Move game logic into event loop, run() replacing poll_events()
* Specify fullscreen Borderless mode
* Pass generic parameter of Event through handle_window_event
* hidpi_factor() replaces get_hidpi_factor()
* with_inner_size() replaces with_dimensions()
* No longer need to unwrap() LogicalSize
* set_cursor_grab/visible() replaces grab/hide_cursor()
* Fix modifiers deprecated warnings by destructuring only event fields we use, ignoring the rest with '..'
* Remove unnecessary mutability from events_loop
* Listen for ModifiersChanged event, fixing deprecated modifiers field
* Change to stdweb for web backend, replacing web-sys
* Pin to glutin =0.22.0-alpha5 and winit =0.20.0-alpha6
2020-01-05 20:56:32 -05:00
|
|
|
use glutin::event::VirtualKeyCode;
|
2016-04-09 04:56:55 -04:00
|
|
|
// Might just rename this to settings.rs
|
|
|
|
|
|
|
|
pub const R_MAX_FPS: console::CVar<i64> = console::CVar {
|
|
|
|
ty: PhantomData,
|
|
|
|
name: "r_max_fps",
|
|
|
|
description: "fps_max caps the maximum FPS for the rendering engine",
|
|
|
|
mutable: true,
|
|
|
|
serializable: true,
|
|
|
|
default: &|| 60,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const R_FOV: console::CVar<i64> = console::CVar {
|
|
|
|
ty: PhantomData,
|
|
|
|
name: "r_fov",
|
|
|
|
description: "Setting for controlling the client field of view",
|
|
|
|
mutable: true,
|
|
|
|
serializable: true,
|
|
|
|
default: &|| 90,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const R_VSYNC: console::CVar<bool> = console::CVar {
|
|
|
|
ty: PhantomData,
|
|
|
|
name: "r_vsync",
|
|
|
|
description: "Toggle to enable/disable vsync",
|
|
|
|
mutable: true,
|
|
|
|
serializable: true,
|
2016-04-16 16:57:38 -04:00
|
|
|
default: &|| false,
|
2016-04-09 04:56:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const CL_MASTER_VOLUME: console::CVar<i64> = console::CVar {
|
|
|
|
ty: PhantomData,
|
|
|
|
name: "cl_master_volume",
|
|
|
|
description: "Main volume control",
|
|
|
|
mutable: true,
|
|
|
|
serializable: true,
|
|
|
|
default: &|| 100,
|
|
|
|
};
|
|
|
|
|
|
|
|
macro_rules! create_keybind {
|
|
|
|
($keycode:ident, $name:expr, $description:expr) => (console::CVar {
|
|
|
|
ty: PhantomData,
|
|
|
|
name: $name,
|
|
|
|
description: $description,
|
|
|
|
mutable: true,
|
|
|
|
serializable: true,
|
Use glutin to replace sdl2 (#35)
* Add glutin dependency
* Create a glutin window
* Use the glutin window, basics work
* Store DPI factor on game object, update on Resized
* Use physical size for rendering only. Fixes UI scaled too small
Fixes https://github.com/iceiix/steven/pull/35#issuecomment-442683373
See also https://github.com/iceiix/steven/issues/22
* Begin adding mouse input events
* Listen for DeviceEvents
* Call hover_at on mouse motion
* Listen for CursorMoved window event, hovering works
Glutin has separate WindowEvent::CursorMoved and
DeviceEvent::MouseMotion events, for absolute cursor and relative mouse
motion, respectively, instead of SDL's Event::MouseMotion for both.
* Use tuple pattern matching instead of nested if for MouseInput
* Implement left clicking
* Use grab_cursor() to capture the cursor
* Hide the cursor when grabbing
* Implement MouseWheel event
* Listen for keyboard input, escape key release
* Keyboard input: console toggling, glutin calls backquote 'grave'
* Implement fullscreen in glutin, updates https://github.com/iceiix/steven/pull/31
* Update settings for glutin VirtualKeyCode
* Keyboard controls (note: must clear conf.cfg to use correct bindings)
* Move DeviceEvent match arm up higher for clarity
* Remove SDL
* Pass physical dimensions to renderer tick so blit_framebuffer can use full size but the ui is still sized logically.
* Listen for DeviceEvent::Text
* Implement text input using ReceivedCharacter window event, works
https://github.com/iceiix/steven/pull/35#issuecomment-443247267
* Request specific version of OpenGL, version 3.2
* Request OpenGL 3.2 but fallback to OpenGL ES 2.0 if available (not tested)
* Set core profile and depth 24-bits, stencil 0-bits
* Allow changing vsync, but require restarting (until https://github.com/tomaka/glutin/issues/693)
* Clarify specific Rust version requirement
* Import glutin::* in handle_window_event() to avoid overly repetitive code
* Linux in VM fix: manually calculate delta in MouseMotion
For the third issue on https://github.com/iceiix/steven/pull/35#issuecomment-443084458
https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM
* Heuristic to detect absolute/relative MouseMotion from delta:(xrel, yrel); use a higher scaling factor
* Add clipboard pasting with clipboard crate instead of sdl2
https://github.com/iceiix/steven/pull/35#issuecomment-443307295
2018-11-30 14:35:35 -05:00
|
|
|
default: &|| VirtualKeyCode::$keycode as i64
|
2016-04-09 04:56:55 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const CL_KEYBIND_FORWARD: console::CVar<i64> = create_keybind!(W, "cl_keybind_forward", "Keybinding for moving forward");
|
|
|
|
pub const CL_KEYBIND_BACKWARD: console::CVar<i64> = create_keybind!(S, "cl_keybind_backward", "Keybinding for moving backward");
|
|
|
|
pub const CL_KEYBIND_LEFT: console::CVar<i64> = create_keybind!(A, "cl_keybind_left", "Keybinding for moving the left");
|
|
|
|
pub const CL_KEYBIND_RIGHT: console::CVar<i64> = create_keybind!(D, "cl_keybind_right", "Keybinding for moving to the right");
|
|
|
|
pub const CL_KEYBIND_OPEN_INV: console::CVar<i64> = create_keybind!(E, "cl_keybind_open_inv", "Keybinding for opening the inventory");
|
|
|
|
pub const CL_KEYBIND_SNEAK: console::CVar<i64> = create_keybind!(LShift, "cl_keybind_sneak", "Keybinding for sneaking");
|
Use glutin to replace sdl2 (#35)
* Add glutin dependency
* Create a glutin window
* Use the glutin window, basics work
* Store DPI factor on game object, update on Resized
* Use physical size for rendering only. Fixes UI scaled too small
Fixes https://github.com/iceiix/steven/pull/35#issuecomment-442683373
See also https://github.com/iceiix/steven/issues/22
* Begin adding mouse input events
* Listen for DeviceEvents
* Call hover_at on mouse motion
* Listen for CursorMoved window event, hovering works
Glutin has separate WindowEvent::CursorMoved and
DeviceEvent::MouseMotion events, for absolute cursor and relative mouse
motion, respectively, instead of SDL's Event::MouseMotion for both.
* Use tuple pattern matching instead of nested if for MouseInput
* Implement left clicking
* Use grab_cursor() to capture the cursor
* Hide the cursor when grabbing
* Implement MouseWheel event
* Listen for keyboard input, escape key release
* Keyboard input: console toggling, glutin calls backquote 'grave'
* Implement fullscreen in glutin, updates https://github.com/iceiix/steven/pull/31
* Update settings for glutin VirtualKeyCode
* Keyboard controls (note: must clear conf.cfg to use correct bindings)
* Move DeviceEvent match arm up higher for clarity
* Remove SDL
* Pass physical dimensions to renderer tick so blit_framebuffer can use full size but the ui is still sized logically.
* Listen for DeviceEvent::Text
* Implement text input using ReceivedCharacter window event, works
https://github.com/iceiix/steven/pull/35#issuecomment-443247267
* Request specific version of OpenGL, version 3.2
* Request OpenGL 3.2 but fallback to OpenGL ES 2.0 if available (not tested)
* Set core profile and depth 24-bits, stencil 0-bits
* Allow changing vsync, but require restarting (until https://github.com/tomaka/glutin/issues/693)
* Clarify specific Rust version requirement
* Import glutin::* in handle_window_event() to avoid overly repetitive code
* Linux in VM fix: manually calculate delta in MouseMotion
For the third issue on https://github.com/iceiix/steven/pull/35#issuecomment-443084458
https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM
* Heuristic to detect absolute/relative MouseMotion from delta:(xrel, yrel); use a higher scaling factor
* Add clipboard pasting with clipboard crate instead of sdl2
https://github.com/iceiix/steven/pull/35#issuecomment-443307295
2018-11-30 14:35:35 -05:00
|
|
|
pub const CL_KEYBIND_SPRINT: console::CVar<i64> = create_keybind!(LControl, "cl_keybind_sprint", "Keybinding for sprinting");
|
2016-04-09 04:56:55 -04:00
|
|
|
pub const CL_KEYBIND_JUMP: console::CVar<i64> = create_keybind!(Space, "cl_keybind_jump", "Keybinding for jumping");
|
|
|
|
|
2019-01-26 16:00:19 -05:00
|
|
|
pub const DOUBLE_JUMP_MS: u32 = 100;
|
|
|
|
|
2016-04-21 06:40:50 -04:00
|
|
|
pub fn register_vars(vars: &mut console::Vars) {
|
|
|
|
vars.register(R_MAX_FPS);
|
|
|
|
vars.register(R_FOV);
|
|
|
|
vars.register(R_VSYNC);
|
|
|
|
vars.register(CL_MASTER_VOLUME);
|
|
|
|
vars.register(CL_KEYBIND_FORWARD);
|
|
|
|
vars.register(CL_KEYBIND_BACKWARD);
|
|
|
|
vars.register(CL_KEYBIND_LEFT);
|
|
|
|
vars.register(CL_KEYBIND_RIGHT);
|
|
|
|
vars.register(CL_KEYBIND_OPEN_INV);
|
|
|
|
vars.register(CL_KEYBIND_SNEAK);
|
|
|
|
vars.register(CL_KEYBIND_SPRINT);
|
|
|
|
vars.register(CL_KEYBIND_JUMP);
|
2016-04-09 04:56:55 -04:00
|
|
|
}
|
|
|
|
|
Use glutin to replace sdl2 (#35)
* Add glutin dependency
* Create a glutin window
* Use the glutin window, basics work
* Store DPI factor on game object, update on Resized
* Use physical size for rendering only. Fixes UI scaled too small
Fixes https://github.com/iceiix/steven/pull/35#issuecomment-442683373
See also https://github.com/iceiix/steven/issues/22
* Begin adding mouse input events
* Listen for DeviceEvents
* Call hover_at on mouse motion
* Listen for CursorMoved window event, hovering works
Glutin has separate WindowEvent::CursorMoved and
DeviceEvent::MouseMotion events, for absolute cursor and relative mouse
motion, respectively, instead of SDL's Event::MouseMotion for both.
* Use tuple pattern matching instead of nested if for MouseInput
* Implement left clicking
* Use grab_cursor() to capture the cursor
* Hide the cursor when grabbing
* Implement MouseWheel event
* Listen for keyboard input, escape key release
* Keyboard input: console toggling, glutin calls backquote 'grave'
* Implement fullscreen in glutin, updates https://github.com/iceiix/steven/pull/31
* Update settings for glutin VirtualKeyCode
* Keyboard controls (note: must clear conf.cfg to use correct bindings)
* Move DeviceEvent match arm up higher for clarity
* Remove SDL
* Pass physical dimensions to renderer tick so blit_framebuffer can use full size but the ui is still sized logically.
* Listen for DeviceEvent::Text
* Implement text input using ReceivedCharacter window event, works
https://github.com/iceiix/steven/pull/35#issuecomment-443247267
* Request specific version of OpenGL, version 3.2
* Request OpenGL 3.2 but fallback to OpenGL ES 2.0 if available (not tested)
* Set core profile and depth 24-bits, stencil 0-bits
* Allow changing vsync, but require restarting (until https://github.com/tomaka/glutin/issues/693)
* Clarify specific Rust version requirement
* Import glutin::* in handle_window_event() to avoid overly repetitive code
* Linux in VM fix: manually calculate delta in MouseMotion
For the third issue on https://github.com/iceiix/steven/pull/35#issuecomment-443084458
https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM
* Heuristic to detect absolute/relative MouseMotion from delta:(xrel, yrel); use a higher scaling factor
* Add clipboard pasting with clipboard crate instead of sdl2
https://github.com/iceiix/steven/pull/35#issuecomment-443307295
2018-11-30 14:35:35 -05:00
|
|
|
#[derive(Hash, PartialEq, Eq, Debug)]
|
2016-04-09 04:56:55 -04:00
|
|
|
pub enum Stevenkey {
|
|
|
|
Forward,
|
|
|
|
Backward,
|
|
|
|
Left,
|
|
|
|
Right,
|
|
|
|
OpenInv,
|
|
|
|
Sneak,
|
|
|
|
Sprint,
|
|
|
|
Jump,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Stevenkey {
|
|
|
|
pub fn values() -> Vec<Stevenkey> {
|
|
|
|
vec!(Stevenkey::Forward, Stevenkey::Backward, Stevenkey::Left,
|
|
|
|
Stevenkey::Right, Stevenkey::OpenInv, Stevenkey::Sneak,
|
|
|
|
Stevenkey::Sprint, Stevenkey::Jump)
|
|
|
|
}
|
|
|
|
|
Use glutin to replace sdl2 (#35)
* Add glutin dependency
* Create a glutin window
* Use the glutin window, basics work
* Store DPI factor on game object, update on Resized
* Use physical size for rendering only. Fixes UI scaled too small
Fixes https://github.com/iceiix/steven/pull/35#issuecomment-442683373
See also https://github.com/iceiix/steven/issues/22
* Begin adding mouse input events
* Listen for DeviceEvents
* Call hover_at on mouse motion
* Listen for CursorMoved window event, hovering works
Glutin has separate WindowEvent::CursorMoved and
DeviceEvent::MouseMotion events, for absolute cursor and relative mouse
motion, respectively, instead of SDL's Event::MouseMotion for both.
* Use tuple pattern matching instead of nested if for MouseInput
* Implement left clicking
* Use grab_cursor() to capture the cursor
* Hide the cursor when grabbing
* Implement MouseWheel event
* Listen for keyboard input, escape key release
* Keyboard input: console toggling, glutin calls backquote 'grave'
* Implement fullscreen in glutin, updates https://github.com/iceiix/steven/pull/31
* Update settings for glutin VirtualKeyCode
* Keyboard controls (note: must clear conf.cfg to use correct bindings)
* Move DeviceEvent match arm up higher for clarity
* Remove SDL
* Pass physical dimensions to renderer tick so blit_framebuffer can use full size but the ui is still sized logically.
* Listen for DeviceEvent::Text
* Implement text input using ReceivedCharacter window event, works
https://github.com/iceiix/steven/pull/35#issuecomment-443247267
* Request specific version of OpenGL, version 3.2
* Request OpenGL 3.2 but fallback to OpenGL ES 2.0 if available (not tested)
* Set core profile and depth 24-bits, stencil 0-bits
* Allow changing vsync, but require restarting (until https://github.com/tomaka/glutin/issues/693)
* Clarify specific Rust version requirement
* Import glutin::* in handle_window_event() to avoid overly repetitive code
* Linux in VM fix: manually calculate delta in MouseMotion
For the third issue on https://github.com/iceiix/steven/pull/35#issuecomment-443084458
https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM
* Heuristic to detect absolute/relative MouseMotion from delta:(xrel, yrel); use a higher scaling factor
* Add clipboard pasting with clipboard crate instead of sdl2
https://github.com/iceiix/steven/pull/35#issuecomment-443307295
2018-11-30 14:35:35 -05:00
|
|
|
pub fn get_by_keycode(keycode: VirtualKeyCode, vars: &console::Vars) -> Option<Stevenkey> {
|
2016-04-09 04:56:55 -04:00
|
|
|
for steven_key in Stevenkey::values() {
|
2016-04-21 06:40:50 -04:00
|
|
|
if keycode as i64 == *vars.get(steven_key.get_cvar()) {
|
2016-04-09 04:56:55 -04:00
|
|
|
return Some(steven_key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_cvar(&self) -> console::CVar<i64> {
|
|
|
|
match *self {
|
|
|
|
Stevenkey::Forward => CL_KEYBIND_FORWARD,
|
|
|
|
Stevenkey::Backward => CL_KEYBIND_BACKWARD,
|
|
|
|
Stevenkey::Left => CL_KEYBIND_LEFT,
|
|
|
|
Stevenkey::Right => CL_KEYBIND_RIGHT,
|
|
|
|
Stevenkey::OpenInv => CL_KEYBIND_OPEN_INV,
|
|
|
|
Stevenkey::Sneak => CL_KEYBIND_SNEAK,
|
|
|
|
Stevenkey::Sprint => CL_KEYBIND_SPRINT,
|
|
|
|
Stevenkey::Jump => CL_KEYBIND_JUMP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|