stevenarella/src/main.rs

860 lines
30 KiB
Rust
Raw Permalink Normal View History

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.
#![recursion_limit = "300"]
#![allow(clippy::too_many_arguments)] // match standard gl functions with many arguments
#![allow(clippy::many_single_char_names)] // short variable names provide concise clarity
#![allow(clippy::float_cmp)] // float comparison used to check if changed
2016-03-26 10:24:26 -04:00
use instant::{Duration, Instant};
use log::{error, info, warn};
2020-12-19 16:27:58 -05:00
use std::fs;
extern crate steven_shared as shared;
2016-03-19 20:29:35 -04:00
use structopt::StructOpt;
extern crate steven_protocol;
2016-03-23 17:07:49 -04:00
pub mod ecs;
use steven_protocol::format;
use steven_protocol::nbt;
use steven_protocol::protocol;
2015-09-17 11:04:25 -04:00
pub mod gl;
use steven_protocol::types;
pub mod auth;
pub mod chunk_builder;
pub mod console;
pub mod entity;
pub mod model;
2015-09-17 11:04:25 -04:00
pub mod render;
pub mod resources;
2015-09-23 15:16:25 -04:00
pub mod screen;
2016-03-18 18:24:30 -04:00
pub mod server;
pub mod settings;
pub mod ui;
2016-03-18 18:24:30 -04:00
pub mod world;
2015-09-17 11:04:25 -04:00
use crate::protocol::mojang;
Add support for compiling WebAssembly wasm32-unknown-unknown target (#92) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten https://github.com/aweinstock314/rust-clipboard/pull/62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: https://github.com/rustgd/collision-rs/issues/106 error[E0046]: not all trait items implemented, missing: `encode` --> github.com-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.com-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for https://github.com/Frommi/miniz_oxide/issues/42 * Update to official clipboard crate since https://github.com/aweinstock314/rust-clipboard/pull/62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm https://github.com/iceiix/glutin/pull/1 * Update winit dependency of glutin to git master https://github.com/iceiix/winit/pull/2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor https://github.com/iceiix/glutin/pull/1/commits/97797352b5242436cb82d8ecfb44242b69766e4c
2019-03-03 11:32:36 -05:00
use cfg_if::cfg_if;
use std::cell::RefCell;
2015-09-28 18:37:14 -04:00
use std::marker::PhantomData;
use std::rc::Rc;
2016-03-20 08:04:02 -04:00
use std::sync::mpsc;
use std::sync::{Arc, Mutex, RwLock};
use std::thread;
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>>,
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,
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>>>,
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_ctrl_pressed: bool,
is_logo_pressed: bool,
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
is_fullscreen: bool,
default_protocol_version: i32,
2016-03-20 08:04:02 -04:00
}
impl Game {
pub fn connect_to(&mut self, address: &str) {
let (protocol_version, forge_mods, fml_network_version) =
2021-07-31 22:05:03 -04:00
match protocol::Conn::new(address, self.default_protocol_version)
.and_then(|conn| conn.do_status())
{
Ok(res) => {
info!(
"Detected server protocol version {}",
res.0.version.protocol
);
(
res.0.version.protocol,
res.0.forge_mods,
res.0.fml_network_version,
)
}
Err(err) => {
warn!(
"Error pinging server {} to get protocol version: {:?}, defaulting to {}",
address, err, self.default_protocol_version
);
(self.default_protocol_version, vec![], None)
}
};
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();
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 || {
tx.send(server::Server::connect(
resources,
profile,
&address,
protocol_version,
forge_mods,
fml_network_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() {
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))));
2016-04-07 20:41:26 -04:00
}
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();
self.focused = true;
self.server.remove(&mut self.renderer);
2016-03-20 08:04:02 -04:00
self.server = val;
}
2016-03-20 08:04:02 -04:00
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)
}
2016-03-20 08:04:02 -04:00
};
self.screen_sys
.replace_screen(Box::new(screen::ServerList::new(Some(msg))));
2016-03-20 08:04:02 -04:00
}
}
}
}
if clear_reply {
self.connect_reply = None;
}
}
2015-09-28 18:37:14 -04:00
}
#[derive(StructOpt, Debug)]
#[structopt(name = "Stevenarella")]
struct Opt {
/// Server to connect to
#[structopt(short = "s", long = "server")]
server: Option<String>,
/// Username for offline servers
#[structopt(short = "u", long = "username")]
username: Option<String>,
/// Log decoded packets received from network
#[structopt(short = "n", long = "network-debug")]
network_debug: bool,
2020-12-19 16:27:58 -05:00
/// Parse a network packet from a file
#[structopt(short = "N", long = "network-parse-packet")]
network_parse_packet: Option<String>,
/// Protocol version to use in the autodetection ping
#[structopt(short = "p", long = "default-protocol-version")]
default_protocol_version: Option<String>,
}
Add support for compiling WebAssembly wasm32-unknown-unknown target (#92) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten https://github.com/aweinstock314/rust-clipboard/pull/62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: https://github.com/rustgd/collision-rs/issues/106 error[E0046]: not all trait items implemented, missing: `encode` --> github.com-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.com-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for https://github.com/Frommi/miniz_oxide/issues/42 * Update to official clipboard crate since https://github.com/aweinstock314/rust-clipboard/pull/62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm https://github.com/iceiix/glutin/pull/1 * Update winit dependency of glutin to git master https://github.com/iceiix/winit/pull/2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor https://github.com/iceiix/glutin/pull/1/commits/97797352b5242436cb82d8ecfb44242b69766e4c
2019-03-03 11:32:36 -05:00
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
extern crate console_error_panic_hook;
pub use console_error_panic_hook::set_once as set_panic_hook;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
#[wasm_bindgen]
pub fn main() { main2(); }
} else {
#[inline]
pub fn main() { main2(); }
}
}
fn init_config_dir() {
if std::path::Path::new("conf.cfg").exists() {
return;
}
if let Some(mut path) = dirs::config_dir() {
path.push("Stevenarella");
if !path.exists() {
std::fs::create_dir_all(path.clone()).unwrap();
}
std::env::set_current_dir(path).unwrap();
}
}
fn main2() {
#[cfg(target_arch = "wasm32")]
Add support for compiling WebAssembly wasm32-unknown-unknown target (#92) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten https://github.com/aweinstock314/rust-clipboard/pull/62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: https://github.com/rustgd/collision-rs/issues/106 error[E0046]: not all trait items implemented, missing: `encode` --> github.com-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.com-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for https://github.com/Frommi/miniz_oxide/issues/42 * Update to official clipboard crate since https://github.com/aweinstock314/rust-clipboard/pull/62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm https://github.com/iceiix/glutin/pull/1 * Update winit dependency of glutin to git master https://github.com/iceiix/winit/pull/2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor https://github.com/iceiix/glutin/pull/1/commits/97797352b5242436cb82d8ecfb44242b69766e4c
2019-03-03 11:32:36 -05:00
set_panic_hook();
init_config_dir();
let opt = Opt::from_args();
2015-09-29 17:33:24 -04:00
let con = Arc::new(Mutex::new(console::Console::new()));
let proxy = console::ConsoleProxy::new(con.clone());
log::set_boxed_logger(Box::new(proxy)).unwrap();
log::set_max_level(log::LevelFilter::Trace);
info!("Starting steven");
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let (vars, mut vsync) = {
let mut vars = console::Vars::new();
vars.register(CL_BRAND);
console::register_vars(&mut vars);
auth::register_vars(&mut vars);
settings::register_vars(&mut vars);
vars.load_config();
vars.save_config();
con.lock().unwrap().configure(&vars);
let vsync = *vars.get(settings::R_VSYNC);
(Rc::new(vars), vsync)
};
2015-10-01 15:07:27 -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 web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let events_loop = winit::event_loop::EventLoop::new();
let window_builder = winit::window::WindowBuilder::new()
.with_title("Stevenarella")
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
.with_inner_size(winit::dpi::LogicalSize::new(854.0, 480.0));
#[cfg(target_arch = "wasm32")]
let (context, shader_version, dpi_factor, winit_window) = {
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let winit_window = window_builder.build(&events_loop).unwrap();
let dpi_factor = winit_window.scale_factor();
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
use winit::platform::web::WindowExtWebSys;
let canvas = winit_window.canvas();
let html_window = web_sys::window().unwrap();
let document = html_window.document().unwrap();
let body = document.body().unwrap();
body.append_child(&canvas)
.expect("Append canvas to HTML body");
let canvas = canvas.dyn_into::<web_sys::HtmlCanvasElement>().unwrap();
let webgl2_context = canvas
.get_context("webgl2")
WebGL fixes after disabling threaded chunk builder (#451) At this point, the UI renders in the browser through WebGL, with no GL errors. Progress towards #446 🕸️ Web support * main: enable render loop on wasm, disable events_loop on wasm for now Allow for testing rendering on WebGL * chunk_builder: disable on wasm due to no threads on wasm Chunks will not be correctly rendered, but other parts of the program now can be tested instead of crashing in std::thread * chunk_frag: glBindFragDataLocation is only on native, WebGL 2 uses in-shader specification layout(location=), which works on native in OpenGL 4.1 but we're on OpenGL 3.2 - see https://www.khronos.org/opengl/wiki/Fragment_Shader#Output_buffers * std_or_web: always fail File::open() to avoid servers.json empty string JSON parse failing * www: update installation instructions * render: fix apparent TEXTURE_MAX_LEVEL -> TEXTURE_MAG_FILTER typo * render: correct type for internalFormat DEPTH_COMPONENT24 Valid combinations of format, type, and internalFormat are listed at https://www.khronos.org/registry/OpenGL/specs/es/3.0/es_spec_3.0.pdf#page=124&zoom=100,168,206. We had UNSIGNED_BYTE for DEPTH_COMPONENT24, but only UNSIGNED_INT is a valid type for this internal format. Fixes texImage: Mismatched internalFormat and format/type: 0x81a6 and 0x1902/0x1401 and fixes the subsequent GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT error. * render: gl::MULTISAMPLE (0x809d) is not available on WebGL Fixes WebGL warning: enabled: cap: Invalid enum value <enum 0x809d> 0.bootstrap.js line 11 > eval:851:21 * gl: replace set_float_multi_raw with a safer set_float_multi Removes use of passing raw pointers in set_float_multi_raw parameters Instead, casts raw pointers to flatten, similar to set_matrix_multi Fixes uniform setter: (uniform colorMul[0]) values length (1) must be a positive integer multiple of size of <enum 0x8b52>. * render: model: send BYTE to id attrib, fixes type mismatch Fixes drawElementsInstanced: Vertex attrib 0 requires data of type INT, but is being supplied with type UINT
2020-12-31 17:35:30 -05:00
.expect("Failed to get WebGL2 context")
.expect("Failed to create WebGL2 context, is WebGL2 support enabled? (https://get.webgl.org/webgl2/)")
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
.dyn_into::<web_sys::WebGl2RenderingContext>()
.unwrap();
(
glow::Context::from_webgl2_context(webgl2_context),
"#version 300 es", // WebGL 2
dpi_factor,
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
winit_window,
)
};
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
#[cfg(not(target_arch = "wasm32"))]
let (context, shader_version, dpi_factor, glutin_window) = {
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let glutin_window = glutin::ContextBuilder::new()
.with_stencil_buffer(0)
.with_depth_buffer(24)
.with_gl(glutin::GlRequest::GlThenGles {
opengl_version: (3, 2),
opengles_version: (3, 0),
})
.with_gl_profile(glutin::GlProfile::Core)
.with_vsync(vsync)
.build_windowed(window_builder, &events_loop)
.expect("Could not create glutin window.");
let dpi_factor = glutin_window.window().scale_factor();
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let glutin_window = unsafe {
glutin_window
.make_current()
.expect("Could not set current context.")
};
let context = unsafe {
glow::Context::from_loader_function(|s| glutin_window.get_proc_address(s) as *const _)
};
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let shader_version = match glutin_window.get_api() {
glutin::Api::OpenGl => "#version 150", // OpenGL 3.2
glutin::Api::OpenGlEs => "#version 300 es", // OpenGL ES 3.0 (similar to WebGL 2)
glutin::Api::WebGl => {
panic!("unexpectedly received WebGl API with glutin, expected to use glow codepath")
}
};
(context, shader_version, dpi_factor, glutin_window)
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
};
gl::init(context);
info!("Shader version: {}", shader_version);
let renderer = render::Renderer::new(resource_manager.clone(), shader_version);
let ui_container = ui::Container::new();
2015-09-17 11:04:25 -04:00
let mut last_frame = Instant::now();
2015-09-17 11:04:25 -04:00
2015-09-23 15:16:25 -04:00
let mut screen_sys = screen::ScreenSystem::new();
if opt.server.is_none() {
#[cfg(not(target_arch = "wasm32"))]
{
screen_sys.add_screen(Box::new(screen::Login::new(vars.clone())));
}
Add support for compiling WebAssembly wasm32-unknown-unknown target (#92) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten https://github.com/aweinstock314/rust-clipboard/pull/62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: https://github.com/rustgd/collision-rs/issues/106 error[E0046]: not all trait items implemented, missing: `encode` --> github.com-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.com-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for https://github.com/Frommi/miniz_oxide/issues/42 * Update to official clipboard crate since https://github.com/aweinstock314/rust-clipboard/pull/62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm https://github.com/iceiix/glutin/pull/1 * Update winit dependency of glutin to git master https://github.com/iceiix/winit/pull/2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor https://github.com/iceiix/glutin/pull/1/commits/97797352b5242436cb82d8ecfb44242b69766e4c
2019-03-03 11:32:36 -05:00
#[cfg(target_arch = "wasm32")]
{
screen_sys.add_screen(Box::new(screen::ServerList::new(None)));
}
Add support for compiling WebAssembly wasm32-unknown-unknown target (#92) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten https://github.com/aweinstock314/rust-clipboard/pull/62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: https://github.com/rustgd/collision-rs/issues/106 error[E0046]: not all trait items implemented, missing: `encode` --> github.com-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.com-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for https://github.com/Frommi/miniz_oxide/issues/42 * Update to official clipboard crate since https://github.com/aweinstock314/rust-clipboard/pull/62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm https://github.com/iceiix/glutin/pull/1 * Update winit dependency of glutin to git master https://github.com/iceiix/winit/pull/2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor https://github.com/iceiix/glutin/pull/1/commits/97797352b5242436cb82d8ecfb44242b69766e4c
2019-03-03 11:32:36 -05:00
}
2015-09-19 14:08:28 -04:00
if let Some(username) = opt.username {
vars.set(auth::CL_USERNAME, username);
}
2016-03-19 12:32:13 -04:00
let textures = renderer.get_textures();
let default_protocol_version = protocol::versions::protocol_name_to_protocol_version(
2022-10-24 05:21:33 -04:00
opt.default_protocol_version.unwrap_or_default(),
);
2015-09-28 18:37:14 -04:00
let mut game = Game {
server: server::Server::dummy_server(resource_manager.clone()),
focused: false,
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,
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,
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_ctrl_pressed: false,
is_logo_pressed: false,
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
is_fullscreen: false,
default_protocol_version,
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
if opt.network_debug {
protocol::enable_network_debug();
}
2020-12-19 16:27:58 -05:00
if let Some(filename) = opt.network_parse_packet {
let data = fs::read(filename).unwrap();
protocol::try_parse_packet(data, default_protocol_version);
return;
}
if opt.server.is_some() {
game.connect_to(&opt.server.unwrap());
}
let mut last_resource_version = 0;
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
#[cfg(target_arch = "wasm32")]
let winit_window = Rc::new(RefCell::new(winit_window));
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let game = Rc::new(RefCell::new(game));
let ui_container = Rc::new(RefCell::new(ui_container));
#[cfg(target_arch = "wasm32")]
{
let winit_window = Rc::clone(&winit_window);
let game = Rc::clone(&game);
let ui_container = Rc::clone(&ui_container);
// Based on https://github.com/grovesNL/glow/blob/2d42c5b105d979efe764191b5b1ce78fab99ffcf/src/web_sys.rs#L3258
fn request_animation_frame(f: &Closure<dyn FnMut(f64)>) {
web_sys::window()
.unwrap()
.request_animation_frame(f.as_ref().unchecked_ref())
.unwrap();
}
let f = Rc::new(RefCell::new(None));
let mut last_timestamp = None;
let mut running = true;
*f.borrow_mut() = Some(Closure::wrap(Box::new({
let f = f.clone();
move |timestamp: f64| {
let dt = last_timestamp.map_or(Duration::from_secs(0), |last_timestamp: f64| {
let dt_ms = (timestamp - last_timestamp).max(0.0);
let dt_secs = dt_ms / 1000.0;
Duration::from_secs_f64(dt_secs)
});
last_timestamp = Some(timestamp);
let winit_window = winit_window.borrow_mut();
let mut game = game.borrow_mut();
let mut ui_container = ui_container.borrow_mut();
tick_all(
&winit_window,
&mut game,
&mut ui_container,
&mut last_frame,
&mut resui,
&mut last_resource_version,
&mut vsync,
);
println!("render_loop");
if !running {
let _ = f.borrow_mut().take();
return;
}
request_animation_frame(f.borrow().as_ref().unwrap());
}
}) as Box<dyn FnMut(f64)>));
request_animation_frame(f.borrow().as_ref().unwrap());
}
#[cfg(target_arch = "wasm32")]
let winit_window = Rc::clone(&winit_window);
let game = Rc::clone(&game);
let ui_container = Rc::clone(&ui_container);
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
events_loop.run(move |event, _event_loop, control_flow| {
#[cfg(target_arch = "wasm32")]
let winit_window = winit_window.borrow_mut();
#[cfg(not(target_arch = "wasm32"))]
let winit_window = glutin_window.window();
let mut game = game.borrow_mut();
let mut ui_container = ui_container.borrow_mut();
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
#[cfg(target_arch = "wasm32")]
{
*control_flow = winit::event_loop::ControlFlow::Wait;
}
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
#[cfg(not(target_arch = "wasm32"))]
{
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
*control_flow = winit::event_loop::ControlFlow::Poll;
}
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
#[cfg(not(target_arch = "wasm32"))]
if let winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::Resized(physical_size),
..
} = event
{
glutin_window.resize(physical_size);
}
2016-03-19 13:34:12 -04:00
#[allow(clippy::needless_borrow)] // needless for native, not for web
if !handle_window_event(&winit_window, &mut game, &mut ui_container, event) {
return;
}
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
#[cfg(not(target_arch = "wasm32"))]
{
tick_all(
2021-07-31 22:05:03 -04:00
winit_window,
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
&mut game,
&mut ui_container,
&mut last_frame,
&mut resui,
&mut last_resource_version,
&mut vsync,
);
glutin_window
.swap_buffers()
.expect("Failed to swap GL buffers");
}
2015-09-07 16:11:00 -04:00
if game.should_close {
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
*control_flow = winit::event_loop::ControlFlow::Exit;
}
});
2015-09-07 16:11:00 -04:00
}
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
fn tick_all(
window: &winit::window::Window,
game: &mut Game,
ui_container: &mut ui::Container,
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
last_frame: &mut Instant,
resui: &mut resources::ManagerUI,
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
last_resource_version: &mut usize,
vsync: &mut bool,
) {
let now = Instant::now();
let diff = now.duration_since(*last_frame);
*last_frame = now;
let frame_time = 1e9f64 / 60.0;
let delta = (diff.subsec_nanos() as f64) / frame_time;
let physical_size = window.inner_size();
let (physical_width, physical_height) = physical_size.into();
let (width, height) = physical_size.to_logical::<f64>(game.dpi_factor).into();
let version = {
let try_res = game.resource_manager.try_write();
if let Ok(mut res) = try_res {
res.tick(resui, ui_container, delta);
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
res.version()
} else {
// TODO: why does game.resource_manager.write() sometimes deadlock?
//warn!("Failed to obtain mutable reference to resource manager!");
*last_resource_version
}
};
*last_resource_version = version;
let vsync_changed = *game.vars.get(settings::R_VSYNC);
if *vsync != vsync_changed {
error!("Changing vsync currently requires restarting");
game.should_close = true;
// TODO: after https://github.com/tomaka/glutin/issues/693 Allow changing vsync on a Window
//vsync = vsync_changed;
}
let fps_cap = *game.vars.get(settings::R_MAX_FPS);
game.tick(delta);
game.server.tick(&mut game.renderer, delta);
// Check if window is valid, it might be minimized
if physical_width == 0 || physical_height == 0 {
return;
}
game.renderer.update_camera(physical_width, physical_height);
game.server.world.compute_render_list(&mut game.renderer);
game.chunk_builder
.tick(&mut game.server.world, &mut game.renderer, version);
game.screen_sys
.tick(delta, &mut game.renderer, ui_container);
/* TODO: open console for chat messages
if let Some(received_chat_at) = game.server.received_chat_at {
if Instant::now().duration_since(received_chat_at).as_secs() < 5 {
game.console.lock().unwrap().activate()
// TODO: automatically deactivate the console after inactivity
}
}
*/
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
game.console
.lock()
.unwrap()
.tick(ui_container, &game.renderer, delta, width);
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
ui_container.tick(&mut game.renderer, delta, width, height);
game.renderer.tick(
&mut game.server.world,
delta,
width as u32,
height as u32,
physical_width,
physical_height,
);
if fps_cap > 0 && !*vsync {
let frame_time = now.elapsed();
let sleep_interval = Duration::from_millis(1000 / fps_cap as u64);
if frame_time < sleep_interval {
thread::sleep(sleep_interval - frame_time);
}
}
}
fn handle_window_event<T>(
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
window: &winit::window::Window,
game: &mut Game,
ui_container: &mut ui::Container,
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
event: winit::event::Event<T>,
) -> bool {
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
use winit::event::*;
let cursor_grab_mode = if cfg!(target_os = "macos") {
winit::window::CursorGrabMode::Locked
} else {
winit::window::CursorGrabMode::Confined
};
2015-09-07 16:11:00 -04:00
match event {
Event::MainEventsCleared => return true,
Event::DeviceEvent {
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.set_cursor_grab(cursor_grab_mode).unwrap();
window.set_cursor_visible(false);
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-04-07 20:41:26 -04:00
}
} else {
window
.set_cursor_grab(winit::window::CursorGrabMode::None)
.unwrap();
window.set_cursor_visible(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
Event::WindowEvent { event, .. } => {
match event {
WindowEvent::ModifiersChanged(modifiers_state) => {
game.is_ctrl_pressed = modifiers_state.ctrl();
game.is_logo_pressed = modifiers_state.logo();
}
WindowEvent::CloseRequested => game.should_close = true,
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
game.dpi_factor = scale_factor;
}
2015-10-01 15:07:27 -04:00
WindowEvent::ReceivedCharacter(codepoint) => {
if !game.focused && !game.is_ctrl_pressed && !game.is_logo_pressed {
ui_container.key_type(game, codepoint);
}
#[cfg(target_os = "macos")]
if game.is_logo_pressed && codepoint == 'q' {
game.should_close = 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
WindowEvent::MouseInput { state, button, .. } => match (state, button) {
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
(ElementState::Released, MouseButton::Left) => {
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let physical_size = window.inner_size();
let (width, height) =
physical_size.to_logical::<f64>(game.dpi_factor).into();
if game.server.is_connected()
&& !game.focused
&& !game.screen_sys.is_current_closable()
{
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.focused = true;
window.set_cursor_grab(cursor_grab_mode).unwrap();
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
window.set_cursor_visible(false);
2020-06-29 21:06:51 -04:00
} else if !game.focused {
#[cfg(not(target_arch = "wasm32"))]
// TODO: after Pointer Lock https://github.com/rust-windowing/winit/issues/1674
window
.set_cursor_grab(winit::window::CursorGrabMode::None)
.unwrap();
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
window.set_cursor_visible(true);
2020-06-29 21:06:51 -04:00
ui_container.click_at(
game,
game.last_mouse_x,
game.last_mouse_y,
width,
height,
);
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
}
2022-09-24 04:46:44 -04:00
if game.focused {
game.server.on_left_mouse_button(false);
}
}
(ElementState::Pressed, MouseButton::Left) => {
if game.focused {
game.server.on_left_mouse_button(true);
}
}
(ElementState::Released, MouseButton::Right) => {
if game.focused {
game.server.on_right_mouse_button(false);
game.server.on_right_click(&mut game.renderer);
}
}
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
(ElementState::Pressed, MouseButton::Right) => {
if game.focused {
2022-09-24 04:46:44 -04:00
game.server.on_right_mouse_button(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
game.server.on_right_click(&mut game.renderer);
}
}
(_, _) => (),
},
WindowEvent::CursorMoved { position, .. } => {
let (x, y) = position.to_logical::<f64>(game.dpi_factor).into();
game.last_mouse_x = x;
game.last_mouse_y = y;
if !game.focused {
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
let physical_size = window.inner_size();
let (width, height) =
physical_size.to_logical::<f64>(game.dpi_factor).into();
ui_container.hover_at(game, x, y, width, height);
}
2016-04-09 04:56:55 -04:00
}
WindowEvent::MouseWheel { delta, .. } => {
// 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);
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 { input, .. } => {
match (input.state, input.virtual_keycode) {
(ElementState::Released, Some(VirtualKeyCode::Escape)) => {
if game.focused {
window
.set_cursor_grab(winit::window::CursorGrabMode::None)
.unwrap();
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
window.set_cursor_visible(true);
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.set_cursor_grab(cursor_grab_mode).unwrap();
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
window.set_cursor_visible(false);
game.focused = true;
game.screen_sys.pop_screen();
}
}
(ElementState::Pressed, Some(VirtualKeyCode::Grave)) => {
game.console.lock().unwrap().toggle();
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
}
(ElementState::Pressed, Some(VirtualKeyCode::F11)) => {
if !game.is_fullscreen {
// TODO: support options for exclusive and simple fullscreen
// see https://docs.rs/glutin/0.22.0-alpha5/glutin/window/struct.Window.html#method.set_fullscreen
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
window.set_fullscreen(Some(winit::window::Fullscreen::Borderless(
window.current_monitor(),
)));
} else {
Use web-sys for web backend (#444) A small step for #446 🕸️ Web support, use web-sys to interface to the web. Previously, we would try to use glutin on the web, which is not supported; now glutin is only used on native: fixes #171 could not find Context in platform_impl. winit is still used on both, but the GL context is created with web-sys and glow (on the web), and created with glutin and used with glow (on native). stdweb is no longer used, being replaced by web-sys. Substantial refactoring to allow reusing the code between web/native: * settings: use VirtualKeyCode from winit, not reexported from glutin * std_or_web: remove broken localstoragefs/stdweb, add File placeholder * render: disable skin_thread on wasm since we don't have threads * gl: use glow types in gl wrapper (integers in native, but Web*Key in web) * gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't * gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web * gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper * glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2 * shaders: add explicit float/int type conversions, required for WebGL * shaders: specify mediump precision, required for WebGL * shaders: specify fragment shader output locations for WebGL * main: refactor handle_window_event to take a winit window, not glutin context * main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this) * main: use winit events in handle_window_event not reexported glutin events * main: refactor game loop handling into tick_all() * main: create winit window for WebGL, and use winit_window from glutin * main: restore console_error_panic_hook, mistakingly removed in (#260) * main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web * www: index.js: fix wasm import path * www: npm update, npm audit fix * www: update readme to link to status on #446 🕸️ Web support
2020-12-26 16:42:37 -05:00
window.set_fullscreen(None);
}
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.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 = game.is_ctrl_pressed || game.is_logo_pressed;
ui_container.key_press(game, key, true, ctrl_pressed);
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
}
}
(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 = game.is_ctrl_pressed;
ui_container.key_press(game, key, false, ctrl_pressed);
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
}
}
(_, 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
}
false
2015-09-07 16:11:00 -04:00
}