2016-03-16 14:25:35 -04:00
|
|
|
// Copyright 2016 Matthew Collins
|
2015-09-17 11:21:56 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-03-25 13:30:29 -04:00
|
|
|
#![recursion_limit="300"]
|
2016-03-26 10:24:26 -04:00
|
|
|
|
2018-09-30 02:11:47 -04:00
|
|
|
use std::time::{Instant, Duration};
|
2018-11-30 19:41:27 -05:00
|
|
|
use log::{info, warn};
|
2016-04-03 15:53:40 -04:00
|
|
|
extern crate steven_shared as shared;
|
2016-03-19 20:29:35 -04:00
|
|
|
|
2016-03-18 18:24:30 -04:00
|
|
|
#[macro_use]
|
|
|
|
pub mod macros;
|
2016-03-23 17:07:49 -04:00
|
|
|
|
2016-03-17 18:18:25 -04:00
|
|
|
pub mod ecs;
|
2015-09-17 11:04:25 -04:00
|
|
|
pub mod protocol;
|
|
|
|
pub mod format;
|
|
|
|
pub mod nbt;
|
|
|
|
pub mod item;
|
|
|
|
pub mod gl;
|
|
|
|
pub mod types;
|
|
|
|
pub mod resources;
|
|
|
|
pub mod render;
|
2015-09-18 17:02:08 -04:00
|
|
|
pub mod ui;
|
2015-09-23 15:16:25 -04:00
|
|
|
pub mod screen;
|
2016-04-09 04:56:55 -04:00
|
|
|
pub mod settings;
|
2015-09-28 18:37:14 -04:00
|
|
|
pub mod console;
|
2016-03-18 18:24:30 -04:00
|
|
|
pub mod server;
|
|
|
|
pub mod world;
|
2016-03-19 12:32:13 -04:00
|
|
|
pub mod chunk_builder;
|
2016-03-20 16:17:21 -04:00
|
|
|
pub mod auth;
|
2016-03-24 11:39:57 -04:00
|
|
|
pub mod model;
|
2016-03-26 18:21:47 -04:00
|
|
|
pub mod entity;
|
2015-09-17 11:04:25 -04:00
|
|
|
|
2015-09-29 17:33:24 -04:00
|
|
|
use std::sync::{Arc, RwLock, Mutex};
|
2016-04-21 06:40:50 -04:00
|
|
|
use std::rc::Rc;
|
2015-09-28 18:37:14 -04:00
|
|
|
use std::marker::PhantomData;
|
2016-03-20 08:04:02 -04:00
|
|
|
use std::thread;
|
|
|
|
use std::sync::mpsc;
|
2018-11-04 14:48:03 -05:00
|
|
|
use crate::protocol::mojang;
|
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
|
|
|
use glutin;
|
|
|
|
use glutin::GlContext;
|
2015-09-07 16:11:00 -04:00
|
|
|
|
2015-09-28 18:37:14 -04:00
|
|
|
const CL_BRAND: console::CVar<String> = console::CVar {
|
|
|
|
ty: PhantomData,
|
|
|
|
name: "cl_brand",
|
2015-10-07 14:36:59 -04:00
|
|
|
description: "cl_brand has the value of the clients current 'brand'. e.g. \"Steven\" or \
|
|
|
|
\"Vanilla\"",
|
2015-09-28 18:37:14 -04:00
|
|
|
mutable: false,
|
2015-10-01 15:07:27 -04:00
|
|
|
serializable: false,
|
2016-03-16 15:11:50 -04:00
|
|
|
default: &|| "Steven".to_owned(),
|
2015-09-28 18:37:14 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
pub struct Game {
|
|
|
|
renderer: render::Renderer,
|
|
|
|
screen_sys: screen::ScreenSystem,
|
|
|
|
resource_manager: Arc<RwLock<resources::Manager>>,
|
2015-09-29 17:33:24 -04:00
|
|
|
console: Arc<Mutex<console::Console>>,
|
2016-04-21 06:40:50 -04:00
|
|
|
vars: Rc<console::Vars>,
|
2015-10-01 15:07:27 -04:00
|
|
|
should_close: bool,
|
2016-03-18 18:24:30 -04:00
|
|
|
|
|
|
|
server: server::Server,
|
2016-03-21 13:51:25 -04:00
|
|
|
focused: bool,
|
2016-03-19 12:32:13 -04:00
|
|
|
chunk_builder: chunk_builder::ChunkBuilder,
|
2016-03-20 08:04:02 -04:00
|
|
|
|
|
|
|
connect_reply: Option<mpsc::Receiver<Result<server::Server, protocol::Error>>>,
|
2018-11-30 19:41:27 -05:00
|
|
|
protocol_version: i32,
|
|
|
|
|
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
|
|
|
dpi_factor: f64,
|
|
|
|
last_mouse_x: f64,
|
|
|
|
last_mouse_y: f64,
|
|
|
|
last_mouse_xrel: f64,
|
|
|
|
last_mouse_yrel: f64,
|
|
|
|
is_fullscreen: bool,
|
2016-03-20 08:04:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Game {
|
|
|
|
pub fn connect_to(&mut self, address: &str) {
|
2018-11-30 19:41:27 -05:00
|
|
|
// Read saved server protocol version from ping response TODO: get from memory?
|
|
|
|
use std::fs;
|
|
|
|
let file = match fs::File::open("server_versions.json") {
|
|
|
|
Ok(val) => val,
|
|
|
|
Err(_) => return,
|
|
|
|
};
|
|
|
|
let server_versions_info: serde_json::Value = serde_json::from_reader(file).unwrap();
|
|
|
|
let protocol_version = {
|
|
|
|
if let Some(v) = server_versions_info.get(address) {
|
|
|
|
v.as_i64().unwrap() as i32
|
|
|
|
} else {
|
2018-12-03 17:22:47 -05:00
|
|
|
warn!("Server protocol version not known for {} (no ping response?), defaulting to {}", address, protocol::SUPPORTED_PROTOCOLS[0]);
|
|
|
|
protocol::SUPPORTED_PROTOCOLS[0]
|
2018-11-30 19:41:27 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.protocol_version = protocol_version;
|
2016-03-20 08:04:02 -04:00
|
|
|
let (tx, rx) = mpsc::channel();
|
|
|
|
self.connect_reply = Some(rx);
|
|
|
|
let address = address.to_owned();
|
|
|
|
let resources = self.resource_manager.clone();
|
2016-04-21 06:40:50 -04:00
|
|
|
let profile = mojang::Profile {
|
|
|
|
username: self.vars.get(auth::CL_USERNAME).clone(),
|
|
|
|
id: self.vars.get(auth::CL_UUID).clone(),
|
|
|
|
access_token: self.vars.get(auth::AUTH_TOKEN).clone(),
|
|
|
|
};
|
2016-03-20 08:04:02 -04:00
|
|
|
thread::spawn(move || {
|
2018-11-30 19:41:27 -05:00
|
|
|
tx.send(server::Server::connect(resources, profile, &address, protocol_version)).unwrap();
|
2016-03-20 08:04:02 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-21 08:56:38 -04:00
|
|
|
pub fn tick(&mut self, delta: f64) {
|
|
|
|
if !self.server.is_connected() {
|
2016-03-27 12:08:38 -04:00
|
|
|
self.renderer.camera.yaw += 0.005 * delta;
|
|
|
|
if self.renderer.camera.yaw > ::std::f64::consts::PI * 2.0 {
|
|
|
|
self.renderer.camera.yaw = 0.0;
|
2016-03-21 08:56:38 -04:00
|
|
|
}
|
|
|
|
}
|
2016-04-07 20:41:26 -04:00
|
|
|
|
|
|
|
if let Some(disconnect_reason) = self.server.disconnect_reason.take() {
|
|
|
|
self.screen_sys.replace_screen(Box::new(screen::ServerList::new(
|
|
|
|
Some(disconnect_reason)
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
if !self.server.is_connected() {
|
|
|
|
self.focused = false;
|
|
|
|
}
|
|
|
|
|
2016-03-20 08:04:02 -04:00
|
|
|
let mut clear_reply = false;
|
|
|
|
if let Some(ref recv) = self.connect_reply {
|
|
|
|
if let Ok(server) = recv.try_recv() {
|
|
|
|
clear_reply = true;
|
|
|
|
match server {
|
|
|
|
Ok(val) => {
|
|
|
|
self.screen_sys.pop_screen();
|
2016-03-21 13:51:25 -04:00
|
|
|
self.focused = true;
|
2016-03-27 12:08:38 -04:00
|
|
|
self.server.remove(&mut self.renderer);
|
2016-03-20 08:04:02 -04:00
|
|
|
self.server = val;
|
|
|
|
},
|
|
|
|
Err(err) => {
|
|
|
|
let msg = match err {
|
|
|
|
protocol::Error::Disconnect(val) => val,
|
|
|
|
err => {
|
|
|
|
let mut msg = format::TextComponent::new(&format!("{}", err));
|
|
|
|
msg.modifier.color = Some(format::Color::Red);
|
|
|
|
format::Component::Text(msg)
|
|
|
|
},
|
|
|
|
};
|
|
|
|
self.screen_sys.replace_screen(Box::new(screen::ServerList::new(
|
|
|
|
Some(msg)
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if clear_reply {
|
|
|
|
self.connect_reply = None;
|
|
|
|
}
|
|
|
|
}
|
2015-09-28 18:37:14 -04:00
|
|
|
}
|
|
|
|
|
2015-09-07 16:11:00 -04:00
|
|
|
fn main() {
|
2015-09-29 17:33:24 -04:00
|
|
|
let con = Arc::new(Mutex::new(console::Console::new()));
|
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
|
|
|
let (vars, vsync) = {
|
2016-04-21 06:40:50 -04:00
|
|
|
let mut vars = console::Vars::new();
|
|
|
|
vars.register(CL_BRAND);
|
|
|
|
auth::register_vars(&mut vars);
|
|
|
|
settings::register_vars(&mut vars);
|
|
|
|
vars.load_config();
|
|
|
|
vars.save_config();
|
|
|
|
let vsync = *vars.get(settings::R_VSYNC);
|
|
|
|
(Rc::new(vars), vsync)
|
2016-04-10 17:05:05 -04:00
|
|
|
};
|
2015-10-01 15:07:27 -04:00
|
|
|
|
2015-09-29 17:33:24 -04:00
|
|
|
let proxy = console::ConsoleProxy::new(con.clone());
|
2015-10-01 15:07:27 -04:00
|
|
|
|
2018-10-28 22:45:57 -04:00
|
|
|
log::set_boxed_logger(Box::new(proxy)).unwrap();
|
2018-09-30 19:36:00 -04:00
|
|
|
log::set_max_level(log::LevelFilter::Trace);
|
2015-09-29 17:33:24 -04:00
|
|
|
|
|
|
|
info!("Starting steven");
|
2015-09-28 18:37:14 -04:00
|
|
|
|
2016-04-24 18:22:10 -04:00
|
|
|
let (res, mut resui) = resources::Manager::new();
|
|
|
|
let resource_manager = Arc::new(RwLock::new(res));
|
2015-09-17 11:04:25 -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
|
|
|
let mut events_loop = glutin::EventsLoop::new();
|
|
|
|
let window_builder = glutin::WindowBuilder::new()
|
|
|
|
.with_title("Steven")
|
|
|
|
.with_dimensions(glutin::dpi::LogicalSize::new(854.0, 480.0));
|
|
|
|
let context = glutin::ContextBuilder::new()
|
|
|
|
.with_stencil_buffer(0)
|
|
|
|
.with_depth_buffer(24)
|
|
|
|
.with_gl(glutin::GlRequest::GlThenGles{opengl_version: (3, 2), opengles_version: (2, 0)})
|
|
|
|
.with_gl_profile(glutin::GlProfile::Core)
|
|
|
|
.with_vsync(vsync);
|
|
|
|
let mut window = glutin::GlWindow::new(window_builder, context, &events_loop)
|
|
|
|
.expect("Could not create glutin window.");
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
window.make_current().expect("Could not set current context.");
|
|
|
|
}
|
2016-04-10 17:05:05 -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
|
|
|
gl::init(&window);
|
2016-04-10 17:05:05 -04:00
|
|
|
|
2015-09-28 18:37:14 -04:00
|
|
|
let renderer = render::Renderer::new(resource_manager.clone());
|
2015-09-18 17:02:08 -04:00
|
|
|
let mut ui_container = ui::Container::new();
|
2015-09-17 11:04:25 -04:00
|
|
|
|
2018-09-30 02:11:47 -04:00
|
|
|
let mut last_frame = Instant::now();
|
|
|
|
let frame_time = 1e9f64 / 60.0;
|
2015-09-17 11:04:25 -04:00
|
|
|
|
2015-09-23 15:16:25 -04:00
|
|
|
let mut screen_sys = screen::ScreenSystem::new();
|
2016-04-21 06:40:50 -04:00
|
|
|
screen_sys.add_screen(Box::new(screen::Login::new(vars.clone())));
|
2015-09-19 14:08:28 -04:00
|
|
|
|
2016-03-19 12:32:13 -04:00
|
|
|
let textures = renderer.get_textures();
|
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
|
|
|
let dpi_factor = window.get_current_monitor().get_hidpi_factor();
|
2015-09-28 18:37:14 -04:00
|
|
|
let mut game = Game {
|
2016-04-21 06:40:50 -04:00
|
|
|
server: server::Server::dummy_server(resource_manager.clone()),
|
2016-03-21 13:51:25 -04:00
|
|
|
focused: false,
|
2018-11-04 16:43:30 -05:00
|
|
|
renderer,
|
|
|
|
screen_sys,
|
2016-03-24 11:39:57 -04:00
|
|
|
resource_manager: resource_manager.clone(),
|
2015-09-28 18:37:14 -04:00
|
|
|
console: con,
|
2018-11-04 16:43:30 -05:00
|
|
|
vars,
|
2015-10-01 15:07:27 -04:00
|
|
|
should_close: false,
|
2016-03-24 11:39:57 -04:00
|
|
|
chunk_builder: chunk_builder::ChunkBuilder::new(resource_manager, textures),
|
2016-03-20 08:04:02 -04:00
|
|
|
connect_reply: None,
|
2018-12-03 17:22:47 -05:00
|
|
|
protocol_version: protocol::SUPPORTED_PROTOCOLS[0],
|
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
|
|
|
dpi_factor,
|
|
|
|
last_mouse_x: 0.0,
|
|
|
|
last_mouse_y: 0.0,
|
|
|
|
last_mouse_xrel: 0.0,
|
|
|
|
last_mouse_yrel: 0.0,
|
|
|
|
is_fullscreen: false,
|
2015-09-28 18:37:14 -04:00
|
|
|
};
|
2016-04-07 20:41:26 -04:00
|
|
|
game.renderer.camera.pos = cgmath::Point3::new(0.5, 13.2, 0.5);
|
2015-09-28 18:37:14 -04:00
|
|
|
|
2015-10-01 15:07:27 -04:00
|
|
|
while !game.should_close {
|
|
|
|
|
2018-09-30 02:11:47 -04:00
|
|
|
let now = Instant::now();
|
|
|
|
let diff = now.duration_since(last_frame);
|
2015-09-17 11:04:25 -04:00
|
|
|
last_frame = now;
|
2018-09-30 02:11:47 -04:00
|
|
|
let delta = (diff.subsec_nanos() as f64) / frame_time;
|
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
|
|
|
let (width, height) = window.get_inner_size().unwrap().into();
|
|
|
|
let (physical_width, physical_height) = window.get_inner_size().unwrap().to_physical(game.dpi_factor).into();
|
2015-09-17 11:04:25 -04:00
|
|
|
|
2016-04-24 18:22:10 -04:00
|
|
|
let version = {
|
|
|
|
let mut res = game.resource_manager.write().unwrap();
|
|
|
|
res.tick(&mut resui, &mut ui_container, delta);
|
|
|
|
res.version()
|
|
|
|
};
|
|
|
|
|
2016-04-21 06:40:50 -04:00
|
|
|
let vsync_changed = *game.vars.get(settings::R_VSYNC);
|
|
|
|
if vsync != vsync_changed {
|
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
|
|
|
println!("Changing vsync currently requires restarting");
|
|
|
|
break;
|
|
|
|
// TODO: after https://github.com/tomaka/glutin/issues/693 Allow changing vsync on a Window
|
|
|
|
//vsync = vsync_changed;
|
2016-04-21 06:40:50 -04:00
|
|
|
}
|
|
|
|
let fps_cap = *game.vars.get(settings::R_MAX_FPS);
|
2016-04-10 17:05:05 -04:00
|
|
|
|
2016-03-21 08:56:38 -04:00
|
|
|
game.tick(delta);
|
2016-03-21 10:05:13 -04:00
|
|
|
game.server.tick(&mut game.renderer, delta);
|
2016-03-19 13:34:12 -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
|
|
|
game.renderer.update_camera(physical_width, physical_height);
|
2016-03-24 17:47:11 -04:00
|
|
|
game.server.world.compute_render_list(&mut game.renderer);
|
2016-03-29 15:53:41 -04:00
|
|
|
game.chunk_builder.tick(&mut game.server.world, &mut game.renderer, version);
|
2016-03-19 12:32:13 -04:00
|
|
|
|
2015-09-28 18:37:14 -04:00
|
|
|
game.screen_sys.tick(delta, &mut game.renderer, &mut ui_container);
|
2015-10-07 14:36:59 -04:00
|
|
|
game.console
|
|
|
|
.lock()
|
|
|
|
.unwrap()
|
2016-04-24 07:22:04 -04:00
|
|
|
.tick(&mut ui_container, &game.renderer, delta, width as f64);
|
2015-09-28 18:37:14 -04:00
|
|
|
ui_container.tick(&mut game.renderer, delta, width as f64, height as f64);
|
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
|
|
|
game.renderer.tick(&mut game.server.world, delta, width, height, physical_width, physical_height);
|
2015-10-01 15:07:27 -04:00
|
|
|
|
2016-04-10 17:05:05 -04:00
|
|
|
|
|
|
|
if fps_cap > 0 && !vsync {
|
2018-09-30 02:11:47 -04:00
|
|
|
let frame_time = now.elapsed();
|
|
|
|
let sleep_interval = Duration::from_millis(1000 / fps_cap as u64);
|
2016-04-10 17:05:05 -04:00
|
|
|
if frame_time < sleep_interval {
|
2018-09-30 02:11:47 -04:00
|
|
|
thread::sleep(sleep_interval - frame_time);
|
2016-04-10 17:05:05 -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
|
|
|
window.swap_buffers().expect("Failed to swap GL buffers");
|
2015-09-07 16:11:00 -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
|
|
|
events_loop.poll_events(|event| {
|
2018-11-20 22:42:36 -05:00
|
|
|
handle_window_event(&mut window, &mut game, &mut ui_container, event);
|
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
|
|
|
});
|
2015-09-07 16:11:00 -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
|
|
|
fn handle_window_event(window: &mut glutin::GlWindow,
|
2015-10-07 14:36:59 -04:00
|
|
|
game: &mut Game,
|
|
|
|
ui_container: &mut ui::Container,
|
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
|
|
|
event: glutin::Event) {
|
|
|
|
use glutin::*;
|
2015-09-07 16:11:00 -04:00
|
|
|
match event {
|
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
|
|
|
Event::DeviceEvent{event, ..} => match event {
|
|
|
|
DeviceEvent::MouseMotion{delta:(xrel, yrel)} => {
|
|
|
|
let (rx, ry) =
|
|
|
|
if xrel > 1000.0 || yrel > 1000.0 {
|
|
|
|
// Heuristic for if we were passed an absolute value instead of relative
|
|
|
|
// Workaround https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM
|
|
|
|
// Note SDL2 had a hint to handle this scenario:
|
|
|
|
// sdl2::hint::set_with_priority("SDL_MOUSE_RELATIVE_MODE_WARP", "1", &sdl2::hint::Hint::Override);
|
|
|
|
let s = 8000.0 + 0.01;
|
|
|
|
((xrel - game.last_mouse_xrel) / s, (yrel - game.last_mouse_yrel) / s)
|
|
|
|
} else {
|
|
|
|
let s = 2000.0 + 0.01;
|
|
|
|
(xrel / s, yrel / s)
|
|
|
|
};
|
|
|
|
|
|
|
|
game.last_mouse_xrel = xrel;
|
|
|
|
game.last_mouse_yrel = yrel;
|
|
|
|
|
|
|
|
use std::f64::consts::PI;
|
|
|
|
|
|
|
|
if game.focused {
|
|
|
|
window.grab_cursor(true).unwrap();
|
|
|
|
window.hide_cursor(true);
|
|
|
|
if let Some(player) = game.server.player {
|
|
|
|
let rotation = game.server.entities.get_component_mut(player, game.server.rotation).unwrap();
|
|
|
|
rotation.yaw -= rx;
|
|
|
|
rotation.pitch -= ry;
|
|
|
|
if rotation.pitch < (PI/2.0) + 0.01 {
|
|
|
|
rotation.pitch = (PI/2.0) + 0.01;
|
|
|
|
}
|
|
|
|
if rotation.pitch > (PI/2.0)*3.0 - 0.01 {
|
|
|
|
rotation.pitch = (PI/2.0)*3.0 - 0.01;
|
|
|
|
}
|
2016-03-27 12:08:38 -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
|
|
|
} else {
|
|
|
|
window.grab_cursor(false).unwrap();
|
|
|
|
window.hide_cursor(false);
|
2016-04-07 20:41:26 -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
|
|
|
},
|
|
|
|
|
|
|
|
_ => ()
|
|
|
|
},
|
|
|
|
|
|
|
|
Event::WindowEvent{event, ..} => match event {
|
|
|
|
WindowEvent::CloseRequested => game.should_close = true,
|
|
|
|
WindowEvent::Resized(logical_size) => {
|
|
|
|
game.dpi_factor = window.get_hidpi_factor();
|
|
|
|
window.resize(logical_size.to_physical(game.dpi_factor));
|
|
|
|
},
|
2015-10-01 15:07:27 -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
|
|
|
WindowEvent::ReceivedCharacter(codepoint) => {
|
|
|
|
if !game.focused {
|
|
|
|
ui_container.key_type(game, codepoint);
|
2016-04-08 06:44:23 -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
|
|
|
},
|
|
|
|
|
|
|
|
WindowEvent::MouseInput{device_id: _, state, button, modifiers: _} => {
|
|
|
|
match (state, button) {
|
|
|
|
(ElementState::Released, MouseButton::Left) => {
|
|
|
|
let (width, height) = window.get_inner_size().unwrap().into();
|
|
|
|
|
|
|
|
if game.server.is_connected() && !game.focused && !game.screen_sys.is_current_closable() {
|
|
|
|
game.focused = true;
|
|
|
|
window.grab_cursor(true).unwrap();
|
|
|
|
window.hide_cursor(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if !game.focused {
|
|
|
|
window.grab_cursor(false).unwrap();
|
|
|
|
window.hide_cursor(false);
|
|
|
|
ui_container.click_at(game, game.last_mouse_x, game.last_mouse_y, width, height);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(ElementState::Pressed, MouseButton::Right) => {
|
|
|
|
if game.focused {
|
|
|
|
game.server.on_right_click(&mut game.renderer);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(_, _) => ()
|
2016-04-08 06:44:23 -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
|
|
|
},
|
|
|
|
WindowEvent::CursorMoved{device_id: _, position, modifiers: _} => {
|
|
|
|
let (x, y) = position.into();
|
|
|
|
game.last_mouse_x = x;
|
|
|
|
game.last_mouse_y = y;
|
|
|
|
|
|
|
|
if !game.focused {
|
|
|
|
let (width, height) = window.get_inner_size().unwrap().into();
|
|
|
|
ui_container.hover_at(game, x, y, width, height);
|
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
|
|
|
},
|
|
|
|
WindowEvent::MouseWheel{device_id: _, delta, phase: _, modifiers: _} => {
|
|
|
|
// TODO: line vs pixel delta? does pixel scrolling (e.g. touchpad) need scaling?
|
|
|
|
match delta {
|
|
|
|
MouseScrollDelta::LineDelta(x, y) => {
|
|
|
|
game.screen_sys.on_scroll(x.into(), y.into());
|
|
|
|
},
|
|
|
|
MouseScrollDelta::PixelDelta(position) => {
|
|
|
|
let (x, y) = position.into();
|
|
|
|
game.screen_sys.on_scroll(x, y);
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
WindowEvent::KeyboardInput{device_id: _, input} => {
|
|
|
|
match (input.state, input.virtual_keycode) {
|
|
|
|
(ElementState::Released, Some(VirtualKeyCode::Escape)) => {
|
|
|
|
if game.focused {
|
|
|
|
window.grab_cursor(false).unwrap();
|
|
|
|
window.hide_cursor(false);
|
|
|
|
game.focused = false;
|
|
|
|
game.screen_sys.replace_screen(Box::new(screen::SettingsMenu::new(game.vars.clone(), true)));
|
|
|
|
} else if game.screen_sys.is_current_closable() {
|
|
|
|
window.grab_cursor(true).unwrap();
|
|
|
|
window.hide_cursor(true);
|
|
|
|
game.focused = true;
|
|
|
|
game.screen_sys.pop_screen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(ElementState::Pressed, Some(VirtualKeyCode::Grave)) => {
|
|
|
|
game.console.lock().unwrap().toggle();
|
|
|
|
},
|
|
|
|
(ElementState::Pressed, Some(VirtualKeyCode::F11)) => {
|
|
|
|
if game.is_fullscreen {
|
|
|
|
window.set_fullscreen(Some(window.get_current_monitor()));
|
|
|
|
} else {
|
|
|
|
window.set_fullscreen(None);
|
|
|
|
}
|
|
|
|
|
|
|
|
game.is_fullscreen = !game.is_fullscreen;
|
|
|
|
},
|
|
|
|
(ElementState::Pressed, Some(key)) => {
|
|
|
|
if game.focused {
|
|
|
|
if let Some(steven_key) = settings::Stevenkey::get_by_keycode(key, &game.vars) {
|
|
|
|
game.server.key_press(true, steven_key);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let ctrl_pressed = input.modifiers.ctrl;
|
|
|
|
ui_container.key_press(game, key, true, ctrl_pressed);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(ElementState::Released, Some(key)) => {
|
|
|
|
if game.focused {
|
|
|
|
if let Some(steven_key) = settings::Stevenkey::get_by_keycode(key, &game.vars) {
|
|
|
|
game.server.key_press(false, steven_key);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let ctrl_pressed = input.modifiers.ctrl;
|
|
|
|
ui_container.key_press(game, key, false, ctrl_pressed);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(_, None) => ()
|
2016-03-25 09:15:35 -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
|
|
|
},
|
|
|
|
_ => ()
|
|
|
|
},
|
|
|
|
|
2015-10-07 14:36:59 -04:00
|
|
|
_ => (),
|
2015-09-07 16:11:00 -04:00
|
|
|
}
|
|
|
|
}
|