From 770e82cfd66dff05bf0f40eba10e9e9adc3957e0 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 18:03:54 -0800 Subject: [PATCH 001/137] Add glow dependency Using git revision for https://github.com/grovesNL/glow/commit/666a7529d0f48a05b32deb919668cd172b0adc94 Compatibility fix and pinning for glutin 0.22.0-alpha5, until >0.4.0 --- Cargo.lock | 20 ++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 21 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 858459bb..414baebe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -640,6 +640,18 @@ dependencies = [ "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "glow" +version = "0.4.0" +source = "git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94#666a7529d0f48a05b32deb919668cd172b0adc94" +dependencies = [ + "gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.33 (registry+https://github.com/rust-lang/crates.io-index)", + "slotmap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.56 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.33 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "glutin" version = "0.22.0-alpha5" @@ -1876,6 +1888,11 @@ name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "slotmap" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "smallvec" version = "0.6.13" @@ -2016,6 +2033,7 @@ dependencies = [ "clipboard 0.5.0 (git+https://github.com/aweinstock314/rust-clipboard?rev=07d080be58a361a5bbdb548fafe9449843d968be)", "collision 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "glow 0.4.0 (git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94)", "glutin 0.22.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2676,6 +2694,7 @@ dependencies = [ "checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd" "checksum gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a" "checksum gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a795170cbd85b5a7baa58d6d7525cae6a03e486859860c220f7ebbbdd379d0a" +"checksum glow 0.4.0 (git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94)" = "" "checksum glutin 0.22.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)" = "4f29f0d8e02e304b15a4464118387dcad1f543695057a60276a196311cc93452" "checksum glutin_egl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "772edef3b28b8ad41e4ea202748e65eefe8e5ffd1f4535f1219793dbb20b3d4c" "checksum glutin_emscripten_sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "245b3fdb08df6ffed7585365851f8404af9c7e2dd4b59f15262e968b6a95a0c7" @@ -2812,6 +2831,7 @@ dependencies = [ "checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" "checksum simple_asn1 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "57f6bbbcefb91c0dac9b27c91ba13bd2aa29a815fe980f5b1e07d523fbf7b350" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +"checksum slotmap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "759fd553261805f128e2900bf69ab3d034260bc338caf7f0ee54dbf035c85acd" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4" "checksum smithay-client-toolkit 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "93960e8975909fcb14cc755de93af2149d8b8f4eb368315537d40cfd0f324054" diff --git a/Cargo.toml b/Cargo.toml index 5bea3d84..d7c88281 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ cfg-if = "0.1.9" wasm-bindgen = "0.2.44" sha-1 = "0.8.1" glutin = "=0.22.0-alpha5" +glow = { git = "https://github.com/grovesNL/glow", rev = "666a7529d0f48a05b32deb919668cd172b0adc94" } byteorder = "1.3.2" serde = "1.0.104" serde_json = "1.0.44" From c11aa7a7060924c9e6fdf2061e19cddc1953d45f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 18:35:09 -0800 Subject: [PATCH 002/137] Create the glow context --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 03a3779e..e853346e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,7 @@ use std::thread; use std::sync::mpsc; use crate::protocol::mojang; use glutin; +use glow; const CL_BRAND: console::CVar = console::CVar { ty: PhantomData, @@ -248,7 +249,10 @@ fn main2() { window.make_current().expect("Could not set current context.") }; - gl::init(&window); + //gl::init(&window); + let context = glow::Context::from_loader_function(|s| { + window.get_proc_address(s) as *const _ + }); let renderer = render::Renderer::new(resource_manager.clone()); let mut ui_container = ui::Container::new(); From 52157dd4c5d0fe2cb141856737e2cce7f6f9f70b Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 18:35:58 -0800 Subject: [PATCH 003/137] Revert "Create the glow context" This reverts commit c11aa7a7060924c9e6fdf2061e19cddc1953d45f. --- src/main.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index e853346e..03a3779e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,6 @@ use std::thread; use std::sync::mpsc; use crate::protocol::mojang; use glutin; -use glow; const CL_BRAND: console::CVar = console::CVar { ty: PhantomData, @@ -249,10 +248,7 @@ fn main2() { window.make_current().expect("Could not set current context.") }; - //gl::init(&window); - let context = glow::Context::from_loader_function(|s| { - window.get_proc_address(s) as *const _ - }); + gl::init(&window); let renderer = render::Renderer::new(resource_manager.clone()); let mut ui_container = ui::Container::new(); From 157be48a8e30a7abe5d487e72d418ade08605def Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:29:13 -0800 Subject: [PATCH 004/137] Initialize glow in src/gl/mod.rs --- src/gl/mod.rs | 16 +++++++++++++--- src/main.rs | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index e306012d..2b68ce5c 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -extern crate steven_gl as gl; +//extern crate steven_gl as gl; use std::ops::BitOr; use std::ffi; @@ -20,10 +20,20 @@ use std::mem; use std::ptr; use std::ops::{Deref, DerefMut}; use log::{error, info}; +use glow as gl; + +static mut context: Option = None; /// Inits the gl library. This should be called once a context is ready. -pub fn init(vid: & glutin::WindowedContext) { - gl::load_with(|s| vid.get_proc_address(s) as *const _); +pub fn init(vid: & glutin::WindowedContext) -> glow::Context { + context = gl::Context::from_loader_function(|s| { + vid.get_proc_address(s) as *const _ + }); + context +} + +fn gl::-> glow::Context { + context.unwrap() } /// Dsed to specify how the vertices will be handled diff --git a/src/main.rs b/src/main.rs index 03a3779e..7a797759 100644 --- a/src/main.rs +++ b/src/main.rs @@ -248,7 +248,7 @@ fn main2() { window.make_current().expect("Could not set current context.") }; - gl::init(&window); + let gl = gl::init(&window); let renderer = render::Renderer::new(resource_manager.clone()); let mut ui_container = ui::Container::new(); From 137e5db411cf53a01a364a257b3b4c8db5a97664 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:31:39 -0800 Subject: [PATCH 005/137] Call gl methods on glow context perl -pe's/gl::([A-Z][a-z])/glow_context().$1/g' --- src/gl/mod.rs | 163 +++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 81 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 2b68ce5c..33848045 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -26,13 +26,14 @@ static mut context: Option = None; /// Inits the gl library. This should be called once a context is ready. pub fn init(vid: & glutin::WindowedContext) -> glow::Context { - context = gl::Context::from_loader_function(|s| { + let ctx = gl::Context::from_loader_function(|s| { vid.get_proc_address(s) as *const _ }); - context + context = Some(ctx); + ctx } -fn gl::-> glow::Context { +fn glow_context() -> glow::Context { context.unwrap() } @@ -52,26 +53,26 @@ pub const POINTS: DrawType = gl::POINTS; pub fn draw_arrays(ty: DrawType, offset: usize, count: usize) { unsafe { - gl::DrawArrays(ty, offset as i32, count as i32); + glow_context().DrawArrays(ty, offset as i32, count as i32); } } pub fn draw_elements(ty: DrawType, count: i32, dty: Type, offset: usize) { unsafe { - gl::DrawElements(ty, count, dty, offset as *const gl::types::GLvoid); + glow_context().DrawElements(ty, count, dty, offset as *const gl::types::GLvoid); } } pub fn multi_draw_elements(ty: DrawType, count: &[i32], dty: Type, offsets: &[usize]) { unsafe { - gl::MultiDrawElements(ty, count.as_ptr(), dty, offsets.as_ptr() as *const _, count.len() as i32); + glow_context().MultiDrawElements(ty, count.as_ptr(), dty, offsets.as_ptr() as *const _, count.len() as i32); } } /// Sets the size of the viewport of this context. pub fn viewport(x: i32, y: i32, w: i32, h: i32) { unsafe { - gl::Viewport(x, y, w, h); + glow_context().Viewport(x, y, w, h); } } @@ -79,7 +80,7 @@ pub fn viewport(x: i32, y: i32, w: i32, h: i32) { /// when Clear is called with the color flag. pub fn clear_color(r: f32, g: f32, b: f32, a: f32) { unsafe { - gl::ClearColor(r, g, b, a); + glow_context().ClearColor(r, g, b, a); } } @@ -113,11 +114,11 @@ impl BitOr for ClearFlags { /// Clears the buffers specified by the passed flags. pub fn clear(flags: ClearFlags) { - unsafe { gl::Clear(flags.internal()) } + unsafe { glow_context().Clear(flags.internal()) } } pub fn depth_mask(f: bool) { - unsafe { gl::DepthMask(f as u8); } + unsafe { glow_context().DepthMask(f as u8); } } /// `Func` is a function to be preformed on two values. @@ -132,7 +133,7 @@ pub const EQUAL: Func = gl::EQUAL; pub fn depth_func(f: Func) { unsafe { - gl::DepthFunc(f); + glow_context().DepthFunc(f); } } @@ -148,14 +149,14 @@ pub const MULTISAMPLE: Flag = gl::MULTISAMPLE; /// Enables the passed flag. pub fn enable(f: Flag) { unsafe { - gl::Enable(f); + glow_context().Enable(f); } } /// Disables the passed flag. pub fn disable(f: Flag) { unsafe { - gl::Disable(f); + glow_context().Disable(f); } } @@ -163,7 +164,7 @@ pub fn disable(f: Flag) { /// currently active one. pub fn active_texture(id: u32) { unsafe { - gl::ActiveTexture(gl::TEXTURE0 + id); + glow_context().ActiveTexture(gl::TEXTURE0 + id); } } @@ -177,13 +178,13 @@ pub const ZERO_FACTOR: Factor = gl::ZERO; /// Sets the factors to be used when blending. pub fn blend_func(s_factor: Factor, d_factor: Factor) { unsafe { - gl::BlendFunc(s_factor, d_factor); + glow_context().BlendFunc(s_factor, d_factor); } } pub fn blend_func_separate(s_factor_rgb: Factor, d_factor_rgb: Factor, s_factor_a: Factor, d_factor_a: Factor) { unsafe { - gl::BlendFuncSeparate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); + glow_context().BlendFuncSeparate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); } } @@ -195,7 +196,7 @@ pub const FRONT: Face = gl::FRONT; /// Sets the face to be culled by the gpu. pub fn cull_face(face: Face) { unsafe { - gl::CullFace(face); + glow_context().CullFace(face); } } @@ -208,7 +209,7 @@ pub const COUNTER_CLOCK_WISE: FaceDirection = gl::CCW; /// Sets the direction of vertices used to specify the /// front face (e.g. for culling). pub fn front_face(dir: FaceDirection) { - unsafe { gl::FrontFace(dir) } + unsafe { glow_context().FrontFace(dir) } } /// `Type` is a type of data used by various operations. @@ -268,7 +269,7 @@ impl Texture { pub fn new() -> Texture { let mut t = Texture(0); unsafe { - gl::GenTextures(1, &mut t.0); + glow_context().GenTextures(1, &mut t.0); } t } @@ -276,7 +277,7 @@ impl Texture { /// Binds the texture to the passed target. pub fn bind(&self, target: TextureTarget) { unsafe { - gl::BindTexture(target, self.0); + glow_context().BindTexture(target, self.0); } } @@ -287,7 +288,7 @@ impl Texture { ty: Type, pixels: &mut [u8]) { unsafe { - gl::GetTexImage(target, + glow_context().GetTexImage(target, level, format, ty, @@ -308,7 +309,7 @@ impl Texture { Some(val) => val.as_ptr() as *const gl::types::GLvoid, None => ptr::null(), }; - gl::TexImage2D(target, + glow_context().TexImage2D(target, level, format as i32, width as i32, @@ -332,7 +333,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - gl::TexSubImage2D(target, + glow_context().TexSubImage2D(target, level, x as i32, y as i32, @@ -359,7 +360,7 @@ impl Texture { Some(val) => val.as_ptr() as *const gl::types::GLvoid, None => ptr::null(), }; - gl::TexImage2D(target, + glow_context().TexImage2D(target, level, internal_format as i32, width as i32, @@ -381,7 +382,7 @@ impl Texture { fixed: bool) { unsafe { let result: &mut [i32] = &mut [0; 1]; - gl::GetIntegerv(gl::MAX_SAMPLES, &mut result[0]); + glow_context().GetIntegerv(gl::MAX_SAMPLES, &mut result[0]); let use_samples = if samples > result[0] { info!("glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", samples, result[0]); @@ -390,7 +391,7 @@ impl Texture { samples }; - gl::TexImage2DMultisample(target, + glow_context().TexImage2DMultisample(target, use_samples, format, width as i32, @@ -410,7 +411,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - gl::TexImage3D(target, + glow_context().TexImage3D(target, level, format as i32, width as i32, @@ -436,7 +437,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - gl::TexSubImage3D(target, + glow_context().TexSubImage3D(target, level, x as i32, y as i32, @@ -455,7 +456,7 @@ impl Texture { param: TextureParameter, value: TextureValue) { unsafe { - gl::TexParameteri(target, param, value); + glow_context().TexParameteri(target, param, value); } } } @@ -463,7 +464,7 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { - gl::DeleteTextures(1, &self.0); + glow_context().DeleteTextures(1, &self.0); } } } @@ -483,30 +484,30 @@ pub struct Program(u32); impl Program { pub fn new() -> Program { - Program(unsafe { gl::CreateProgram() }) + Program(unsafe { glow_context().CreateProgram() }) } pub fn attach_shader(&self, shader: Shader) { unsafe { - gl::AttachShader(self.0, shader.0); + glow_context().AttachShader(self.0, shader.0); } } pub fn link(&self) { unsafe { - gl::LinkProgram(self.0); + glow_context().LinkProgram(self.0); } } pub fn use_program(&self) { unsafe { - gl::UseProgram(self.0); + glow_context().UseProgram(self.0); } } pub fn uniform_location(&self, name: &str) -> Option { let u = unsafe { - gl::GetUniformLocation(self.0, ffi::CString::new(name).unwrap().as_ptr()) + glow_context().GetUniformLocation(self.0, ffi::CString::new(name).unwrap().as_ptr()) }; if u != -1 { Some(Uniform(u)) @@ -518,7 +519,7 @@ impl Program { pub fn attribute_location(&self, name: &str) -> Option { let a = unsafe { let name_c = ffi::CString::new(name).unwrap(); - gl::GetAttribLocation(self.0, name_c.as_ptr()) + glow_context().GetAttribLocation(self.0, name_c.as_ptr()) }; if a != -1 { Some(Attribute(a)) @@ -531,7 +532,7 @@ impl Program { impl Drop for Program { fn drop(&mut self) { unsafe { - gl::DeleteProgram(self.0); + glow_context().DeleteProgram(self.0); } } } @@ -540,13 +541,13 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { - Shader(unsafe { gl::CreateShader(ty) }) + Shader(unsafe { glow_context().CreateShader(ty) }) } pub fn set_source(&self, src: &str) { unsafe { let src_c = ffi::CString::new(src).unwrap(); - gl::ShaderSource(self.0, + glow_context().ShaderSource(self.0, 1, &src_c.as_ptr(), ptr::null()); @@ -555,14 +556,14 @@ impl Shader { pub fn compile(&self) { unsafe { - gl::CompileShader(self.0); + glow_context().CompileShader(self.0); } } pub fn get_parameter(&self, param: ShaderParameter) -> i32 { let mut ret: i32 = 0; unsafe { - gl::GetShaderiv(self.0, param, &mut ret); + glow_context().GetShaderiv(self.0, param, &mut ret); } ret } @@ -573,7 +574,7 @@ impl Shader { let mut data = Vec::::with_capacity(len as usize); unsafe { data.set_len(len as usize); - gl::GetShaderInfoLog(self.0, len, ptr::null_mut(), data.as_mut_ptr() as *mut i8); + glow_context().GetShaderInfoLog(self.0, len, ptr::null_mut(), data.as_mut_ptr() as *mut i8); } String::from_utf8(data).unwrap() } @@ -585,56 +586,56 @@ pub struct Uniform(i32); impl Uniform { pub fn set_int(&self, val: i32) { unsafe { - gl::Uniform1i(self.0, val); + glow_context().Uniform1i(self.0, val); } } pub fn set_int3(&self, x: i32, y: i32, z: i32) { unsafe { - gl::Uniform3i(self.0, x, y, z); + glow_context().Uniform3i(self.0, x, y, z); } } pub fn set_float(&self, val: f32) { unsafe { - gl::Uniform1f(self.0, val); + glow_context().Uniform1f(self.0, val); } } pub fn set_float2(&self, x: f32, y: f32) { unsafe { - gl::Uniform2f(self.0, x, y); + glow_context().Uniform2f(self.0, x, y); } } pub fn set_float3(&self, x: f32, y: f32, z: f32) { unsafe { - gl::Uniform3f(self.0, x, y, z); + glow_context().Uniform3f(self.0, x, y, z); } } pub fn set_float4(&self, x: f32, y: f32, z: f32, w: f32) { unsafe { - gl::Uniform4f(self.0, x, y, z, w); + glow_context().Uniform4f(self.0, x, y, z, w); } } pub fn set_float_mutli_raw(&self, data: *const f32, len: usize) { unsafe { - gl::Uniform4fv(self.0, len as i32, data); + glow_context().Uniform4fv(self.0, len as i32, data); } } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - gl::UniformMatrix4fv(self.0, 1, false as u8, m.as_ptr()); + glow_context().UniformMatrix4fv(self.0, 1, false as u8, m.as_ptr()); } } pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { unsafe { - gl::UniformMatrix4fv(self.0, m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe + glow_context().UniformMatrix4fv(self.0, m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe } } } @@ -645,19 +646,19 @@ pub struct Attribute(i32); impl Attribute { pub fn enable(&self) { unsafe { - gl::EnableVertexAttribArray(self.0 as u32); + glow_context().EnableVertexAttribArray(self.0 as u32); } } pub fn disable(&self) { unsafe { - gl::DisableVertexAttribArray(self.0 as u32); + glow_context().DisableVertexAttribArray(self.0 as u32); } } pub fn vertex_pointer(&self, size: i32, ty: Type, normalized: bool, stride: i32, offset: i32) { unsafe { - gl::VertexAttribPointer(self.0 as u32, + glow_context().VertexAttribPointer(self.0 as u32, size, ty, normalized as u8, @@ -668,7 +669,7 @@ impl Attribute { pub fn vertex_pointer_int(&self, size: i32, ty: Type, stride: i32, offset: i32) { unsafe { - gl::VertexAttribIPointer(self.0 as u32, + glow_context().VertexAttribIPointer(self.0 as u32, size, ty, stride, @@ -687,7 +688,7 @@ impl VertexArray { pub fn new() -> VertexArray { let mut va = VertexArray(0); unsafe { - gl::GenVertexArrays(1, &mut va.0); + glow_context().GenVertexArrays(1, &mut va.0); } va } @@ -697,7 +698,7 @@ impl VertexArray { /// this `VertexArray`. pub fn bind(&self) { unsafe { - gl::BindVertexArray(self.0); + glow_context().BindVertexArray(self.0); } } } @@ -705,7 +706,7 @@ impl VertexArray { impl Drop for VertexArray { fn drop(&mut self) { unsafe { - gl::DeleteVertexArrays(1, &self.0); + glow_context().DeleteVertexArrays(1, &self.0); } self.0 = 0; } @@ -747,7 +748,7 @@ impl Buffer { pub fn new() -> Buffer { let mut b = Buffer(0); unsafe { - gl::GenBuffers(1, &mut b.0); + glow_context().GenBuffers(1, &mut b.0); } b } @@ -757,13 +758,13 @@ impl Buffer { /// (Data, Map etc). pub fn bind(&self, target: BufferTarget) { unsafe { - gl::BindBuffer(target, self.0); + glow_context().BindBuffer(target, self.0); } } pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { unsafe { - gl::BufferData(target, + glow_context().BufferData(target, data.len() as isize, data.as_ptr() as *const gl::types::GLvoid, usage); @@ -772,7 +773,7 @@ impl Buffer { pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) { unsafe { - gl::BufferSubData(target, 0, data.len() as isize, data.as_ptr() as *const _); + glow_context().BufferSubData(target, 0, data.len() as isize, data.as_ptr() as *const _); } } @@ -786,7 +787,7 @@ impl Buffer { pub fn map(&self, target: BufferTarget, access: Access, length: usize) -> MappedBuffer { unsafe { MappedBuffer { - inner: Vec::from_raw_parts(gl::MapBuffer(target, access) as *mut u8, 0, length), + inner: Vec::from_raw_parts(glow_context().MapBuffer(target, access) as *mut u8, 0, length), target, } } @@ -796,7 +797,7 @@ impl Buffer { impl Drop for Buffer { fn drop(&mut self) { unsafe { - gl::DeleteBuffers(1, &self.0); + glow_context().DeleteBuffers(1, &self.0); } } } @@ -823,7 +824,7 @@ impl DerefMut for MappedBuffer { impl Drop for MappedBuffer { fn drop(&mut self) { unsafe { - gl::UnmapBuffer(self.target); + glow_context().UnmapBuffer(self.target); } mem::forget(mem::replace(&mut self.inner, Vec::new())); } @@ -841,7 +842,7 @@ pub struct Framebuffer(u32); pub fn check_framebuffer_status() { unsafe { - let status = gl::CheckFramebufferStatus(gl::FRAMEBUFFER); + let status = glow_context().CheckFramebufferStatus(gl::FRAMEBUFFER); let s = match status { gl::FRAMEBUFFER_UNDEFINED => "GL_FRAMEBUFFER_UNDEFINED", @@ -867,7 +868,7 @@ pub fn check_framebuffer_status() { pub fn check_gl_error() { unsafe { loop { - let err = gl::GetError(); + let err = glow_context().GetError(); if err == gl::NO_ERROR { break } @@ -881,32 +882,32 @@ impl Framebuffer { pub fn new() -> Framebuffer { let mut fb = Framebuffer(0); unsafe { - gl::GenFramebuffers(1, &mut fb.0); + glow_context().GenFramebuffers(1, &mut fb.0); } fb } pub fn bind(&self) { unsafe { - gl::BindFramebuffer(gl::FRAMEBUFFER, self.0); + glow_context().BindFramebuffer(gl::FRAMEBUFFER, self.0); } } pub fn bind_read(&self) { unsafe { - gl::BindFramebuffer(gl::READ_FRAMEBUFFER, self.0); + glow_context().BindFramebuffer(gl::READ_FRAMEBUFFER, self.0); } } pub fn bind_draw(&self) { unsafe { - gl::BindFramebuffer(gl::DRAW_FRAMEBUFFER, self.0); + glow_context().BindFramebuffer(gl::DRAW_FRAMEBUFFER, self.0); } } pub fn texture_2d(&self, attachment: Attachment, target: TextureTarget, tex: &Texture, level: i32) { unsafe { - gl::FramebufferTexture2D(gl::FRAMEBUFFER, attachment, target, tex.0, level); + glow_context().FramebufferTexture2D(gl::FRAMEBUFFER, attachment, target, tex.0, level); } } } @@ -914,32 +915,32 @@ impl Framebuffer { impl Drop for Framebuffer { fn drop(&mut self) { unsafe { - gl::DeleteFramebuffers(1, &self.0); + glow_context().DeleteFramebuffers(1, &self.0); } } } pub fn unbind_framebuffer() { unsafe { - gl::BindFramebuffer(gl::FRAMEBUFFER, 0); + glow_context().BindFramebuffer(gl::FRAMEBUFFER, 0); } } pub fn unbind_framebuffer_read() { unsafe { - gl::BindFramebuffer(gl::READ_FRAMEBUFFER, 0); + glow_context().BindFramebuffer(gl::READ_FRAMEBUFFER, 0); } } pub fn unbind_framebuffer_draw() { unsafe { - gl::BindFramebuffer(gl::DRAW_FRAMEBUFFER, 0); + glow_context().BindFramebuffer(gl::DRAW_FRAMEBUFFER, 0); } } pub fn draw_buffers(bufs: &[Attachment]) { unsafe { - gl::DrawBuffers( + glow_context().DrawBuffers( bufs.len() as i32, bufs.as_ptr() ); @@ -949,7 +950,7 @@ pub fn draw_buffers(bufs: &[Attachment]) { pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { unsafe { let name_c = ffi::CString::new(name).unwrap(); - gl::BindFragDataLocation(p.0, cn, name_c.as_ptr()); + glow_context().BindFragDataLocation(p.0, cn, name_c.as_ptr()); } } @@ -958,7 +959,7 @@ pub fn blit_framebuffer( dx0: i32, dy0: i32, dx1: i32, dy1: i32, mask: ClearFlags, filter: TextureValue) { unsafe { - gl::BlitFramebuffer( + glow_context().BlitFramebuffer( sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1, mask.internal(), filter as u32 @@ -968,7 +969,7 @@ pub fn blit_framebuffer( pub fn read_buffer(a: Attachment) { unsafe { - gl::ReadBuffer(a); + glow_context().ReadBuffer(a); } } @@ -977,6 +978,6 @@ pub const COLOR: TargetBuffer = gl::COLOR; pub fn clear_buffer(buffer: TargetBuffer, draw_buffer: i32, values: &[f32]) { unsafe { - gl::ClearBufferfv(buffer, draw_buffer, values.as_ptr()); + glow_context().ClearBufferfv(buffer, draw_buffer, values.as_ptr()); } } From adc86b0b902c70bb2f6c2ec5d769ae9fb972b29f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:36:02 -0800 Subject: [PATCH 006/137] glow uses camelcase cat src/gl/mod.rs|perl -pe'sub decamelize { my ($s) = @_; $s =~ s{(\w+)}{ ($a = $1) =~ s<(^[A-Z]|(?![a-z])[A-Z])>< "_" . lc $1 >eg; substr $a, 1; }eg; $s; } ; s/glow_context\(\)\.(\w+)/"glow_context().".decamelize($1)/ge'>/tmp/a https://gist.github.com/tyru/358703 --- src/gl/mod.rs | 156 +++++++++++++++++++++++++------------------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 33848045..fdd1ee54 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -53,26 +53,26 @@ pub const POINTS: DrawType = gl::POINTS; pub fn draw_arrays(ty: DrawType, offset: usize, count: usize) { unsafe { - glow_context().DrawArrays(ty, offset as i32, count as i32); + glow_context().draw_arrays(ty, offset as i32, count as i32); } } pub fn draw_elements(ty: DrawType, count: i32, dty: Type, offset: usize) { unsafe { - glow_context().DrawElements(ty, count, dty, offset as *const gl::types::GLvoid); + glow_context().draw_elements(ty, count, dty, offset as *const gl::types::GLvoid); } } pub fn multi_draw_elements(ty: DrawType, count: &[i32], dty: Type, offsets: &[usize]) { unsafe { - glow_context().MultiDrawElements(ty, count.as_ptr(), dty, offsets.as_ptr() as *const _, count.len() as i32); + glow_context().multi_draw_elements(ty, count.as_ptr(), dty, offsets.as_ptr() as *const _, count.len() as i32); } } /// Sets the size of the viewport of this context. pub fn viewport(x: i32, y: i32, w: i32, h: i32) { unsafe { - glow_context().Viewport(x, y, w, h); + glow_context().viewport(x, y, w, h); } } @@ -80,7 +80,7 @@ pub fn viewport(x: i32, y: i32, w: i32, h: i32) { /// when Clear is called with the color flag. pub fn clear_color(r: f32, g: f32, b: f32, a: f32) { unsafe { - glow_context().ClearColor(r, g, b, a); + glow_context().clear_color(r, g, b, a); } } @@ -114,11 +114,11 @@ impl BitOr for ClearFlags { /// Clears the buffers specified by the passed flags. pub fn clear(flags: ClearFlags) { - unsafe { glow_context().Clear(flags.internal()) } + unsafe { glow_context().clear(flags.internal()) } } pub fn depth_mask(f: bool) { - unsafe { glow_context().DepthMask(f as u8); } + unsafe { glow_context().depth_mask(f as u8); } } /// `Func` is a function to be preformed on two values. @@ -133,7 +133,7 @@ pub const EQUAL: Func = gl::EQUAL; pub fn depth_func(f: Func) { unsafe { - glow_context().DepthFunc(f); + glow_context().depth_func(f); } } @@ -149,14 +149,14 @@ pub const MULTISAMPLE: Flag = gl::MULTISAMPLE; /// Enables the passed flag. pub fn enable(f: Flag) { unsafe { - glow_context().Enable(f); + glow_context().enable(f); } } /// Disables the passed flag. pub fn disable(f: Flag) { unsafe { - glow_context().Disable(f); + glow_context().disable(f); } } @@ -164,7 +164,7 @@ pub fn disable(f: Flag) { /// currently active one. pub fn active_texture(id: u32) { unsafe { - glow_context().ActiveTexture(gl::TEXTURE0 + id); + glow_context().active_texture(gl::TEXTURE0 + id); } } @@ -178,13 +178,13 @@ pub const ZERO_FACTOR: Factor = gl::ZERO; /// Sets the factors to be used when blending. pub fn blend_func(s_factor: Factor, d_factor: Factor) { unsafe { - glow_context().BlendFunc(s_factor, d_factor); + glow_context().blend_func(s_factor, d_factor); } } pub fn blend_func_separate(s_factor_rgb: Factor, d_factor_rgb: Factor, s_factor_a: Factor, d_factor_a: Factor) { unsafe { - glow_context().BlendFuncSeparate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); + glow_context().blend_func_separate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); } } @@ -196,7 +196,7 @@ pub const FRONT: Face = gl::FRONT; /// Sets the face to be culled by the gpu. pub fn cull_face(face: Face) { unsafe { - glow_context().CullFace(face); + glow_context().cull_face(face); } } @@ -209,7 +209,7 @@ pub const COUNTER_CLOCK_WISE: FaceDirection = gl::CCW; /// Sets the direction of vertices used to specify the /// front face (e.g. for culling). pub fn front_face(dir: FaceDirection) { - unsafe { glow_context().FrontFace(dir) } + unsafe { glow_context().front_face(dir) } } /// `Type` is a type of data used by various operations. @@ -269,7 +269,7 @@ impl Texture { pub fn new() -> Texture { let mut t = Texture(0); unsafe { - glow_context().GenTextures(1, &mut t.0); + glow_context().gen_textures(1, &mut t.0); } t } @@ -277,7 +277,7 @@ impl Texture { /// Binds the texture to the passed target. pub fn bind(&self, target: TextureTarget) { unsafe { - glow_context().BindTexture(target, self.0); + glow_context().bind_texture(target, self.0); } } @@ -288,7 +288,7 @@ impl Texture { ty: Type, pixels: &mut [u8]) { unsafe { - glow_context().GetTexImage(target, + glow_context().get_tex_image(target, level, format, ty, @@ -309,7 +309,7 @@ impl Texture { Some(val) => val.as_ptr() as *const gl::types::GLvoid, None => ptr::null(), }; - glow_context().TexImage2D(target, + glow_context().tex_image2_d(target, level, format as i32, width as i32, @@ -333,7 +333,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - glow_context().TexSubImage2D(target, + glow_context().tex_sub_image2_d(target, level, x as i32, y as i32, @@ -360,7 +360,7 @@ impl Texture { Some(val) => val.as_ptr() as *const gl::types::GLvoid, None => ptr::null(), }; - glow_context().TexImage2D(target, + glow_context().tex_image2_d(target, level, internal_format as i32, width as i32, @@ -382,7 +382,7 @@ impl Texture { fixed: bool) { unsafe { let result: &mut [i32] = &mut [0; 1]; - glow_context().GetIntegerv(gl::MAX_SAMPLES, &mut result[0]); + glow_context().get_integerv(gl::MAX_SAMPLES, &mut result[0]); let use_samples = if samples > result[0] { info!("glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", samples, result[0]); @@ -391,7 +391,7 @@ impl Texture { samples }; - glow_context().TexImage2DMultisample(target, + glow_context().tex_image2_d_multisample(target, use_samples, format, width as i32, @@ -411,7 +411,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - glow_context().TexImage3D(target, + glow_context().tex_image3_d(target, level, format as i32, width as i32, @@ -437,7 +437,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - glow_context().TexSubImage3D(target, + glow_context().tex_sub_image3_d(target, level, x as i32, y as i32, @@ -456,7 +456,7 @@ impl Texture { param: TextureParameter, value: TextureValue) { unsafe { - glow_context().TexParameteri(target, param, value); + glow_context().tex_parameteri(target, param, value); } } } @@ -464,7 +464,7 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { - glow_context().DeleteTextures(1, &self.0); + glow_context().delete_textures(1, &self.0); } } } @@ -484,30 +484,30 @@ pub struct Program(u32); impl Program { pub fn new() -> Program { - Program(unsafe { glow_context().CreateProgram() }) + Program(unsafe { glow_context().create_program() }) } pub fn attach_shader(&self, shader: Shader) { unsafe { - glow_context().AttachShader(self.0, shader.0); + glow_context().attach_shader(self.0, shader.0); } } pub fn link(&self) { unsafe { - glow_context().LinkProgram(self.0); + glow_context().link_program(self.0); } } pub fn use_program(&self) { unsafe { - glow_context().UseProgram(self.0); + glow_context().use_program(self.0); } } pub fn uniform_location(&self, name: &str) -> Option { let u = unsafe { - glow_context().GetUniformLocation(self.0, ffi::CString::new(name).unwrap().as_ptr()) + glow_context().get_uniform_location(self.0, ffi::CString::new(name).unwrap().as_ptr()) }; if u != -1 { Some(Uniform(u)) @@ -519,7 +519,7 @@ impl Program { pub fn attribute_location(&self, name: &str) -> Option { let a = unsafe { let name_c = ffi::CString::new(name).unwrap(); - glow_context().GetAttribLocation(self.0, name_c.as_ptr()) + glow_context().get_attrib_location(self.0, name_c.as_ptr()) }; if a != -1 { Some(Attribute(a)) @@ -532,7 +532,7 @@ impl Program { impl Drop for Program { fn drop(&mut self) { unsafe { - glow_context().DeleteProgram(self.0); + glow_context().delete_program(self.0); } } } @@ -541,13 +541,13 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { - Shader(unsafe { glow_context().CreateShader(ty) }) + Shader(unsafe { glow_context().create_shader(ty) }) } pub fn set_source(&self, src: &str) { unsafe { let src_c = ffi::CString::new(src).unwrap(); - glow_context().ShaderSource(self.0, + glow_context().shader_source(self.0, 1, &src_c.as_ptr(), ptr::null()); @@ -556,14 +556,14 @@ impl Shader { pub fn compile(&self) { unsafe { - glow_context().CompileShader(self.0); + glow_context().compile_shader(self.0); } } pub fn get_parameter(&self, param: ShaderParameter) -> i32 { let mut ret: i32 = 0; unsafe { - glow_context().GetShaderiv(self.0, param, &mut ret); + glow_context().get_shaderiv(self.0, param, &mut ret); } ret } @@ -574,7 +574,7 @@ impl Shader { let mut data = Vec::::with_capacity(len as usize); unsafe { data.set_len(len as usize); - glow_context().GetShaderInfoLog(self.0, len, ptr::null_mut(), data.as_mut_ptr() as *mut i8); + glow_context().get_shader_info_log(self.0, len, ptr::null_mut(), data.as_mut_ptr() as *mut i8); } String::from_utf8(data).unwrap() } @@ -586,56 +586,56 @@ pub struct Uniform(i32); impl Uniform { pub fn set_int(&self, val: i32) { unsafe { - glow_context().Uniform1i(self.0, val); + glow_context().uniform1i(self.0, val); } } pub fn set_int3(&self, x: i32, y: i32, z: i32) { unsafe { - glow_context().Uniform3i(self.0, x, y, z); + glow_context().uniform3i(self.0, x, y, z); } } pub fn set_float(&self, val: f32) { unsafe { - glow_context().Uniform1f(self.0, val); + glow_context().uniform1f(self.0, val); } } pub fn set_float2(&self, x: f32, y: f32) { unsafe { - glow_context().Uniform2f(self.0, x, y); + glow_context().uniform2f(self.0, x, y); } } pub fn set_float3(&self, x: f32, y: f32, z: f32) { unsafe { - glow_context().Uniform3f(self.0, x, y, z); + glow_context().uniform3f(self.0, x, y, z); } } pub fn set_float4(&self, x: f32, y: f32, z: f32, w: f32) { unsafe { - glow_context().Uniform4f(self.0, x, y, z, w); + glow_context().uniform4f(self.0, x, y, z, w); } } pub fn set_float_mutli_raw(&self, data: *const f32, len: usize) { unsafe { - glow_context().Uniform4fv(self.0, len as i32, data); + glow_context().uniform4fv(self.0, len as i32, data); } } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - glow_context().UniformMatrix4fv(self.0, 1, false as u8, m.as_ptr()); + glow_context().uniform_matrix4fv(self.0, 1, false as u8, m.as_ptr()); } } pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { unsafe { - glow_context().UniformMatrix4fv(self.0, m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe + glow_context().uniform_matrix4fv(self.0, m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe } } } @@ -646,19 +646,19 @@ pub struct Attribute(i32); impl Attribute { pub fn enable(&self) { unsafe { - glow_context().EnableVertexAttribArray(self.0 as u32); + glow_context().enable_vertex_attrib_array(self.0 as u32); } } pub fn disable(&self) { unsafe { - glow_context().DisableVertexAttribArray(self.0 as u32); + glow_context().disable_vertex_attrib_array(self.0 as u32); } } pub fn vertex_pointer(&self, size: i32, ty: Type, normalized: bool, stride: i32, offset: i32) { unsafe { - glow_context().VertexAttribPointer(self.0 as u32, + glow_context().vertex_attrib_pointer(self.0 as u32, size, ty, normalized as u8, @@ -669,7 +669,7 @@ impl Attribute { pub fn vertex_pointer_int(&self, size: i32, ty: Type, stride: i32, offset: i32) { unsafe { - glow_context().VertexAttribIPointer(self.0 as u32, + glow_context().vertex_attrib_i_pointer(self.0 as u32, size, ty, stride, @@ -688,7 +688,7 @@ impl VertexArray { pub fn new() -> VertexArray { let mut va = VertexArray(0); unsafe { - glow_context().GenVertexArrays(1, &mut va.0); + glow_context().gen_vertex_arrays(1, &mut va.0); } va } @@ -698,7 +698,7 @@ impl VertexArray { /// this `VertexArray`. pub fn bind(&self) { unsafe { - glow_context().BindVertexArray(self.0); + glow_context().bind_vertex_array(self.0); } } } @@ -706,7 +706,7 @@ impl VertexArray { impl Drop for VertexArray { fn drop(&mut self) { unsafe { - glow_context().DeleteVertexArrays(1, &self.0); + glow_context().delete_vertex_arrays(1, &self.0); } self.0 = 0; } @@ -748,7 +748,7 @@ impl Buffer { pub fn new() -> Buffer { let mut b = Buffer(0); unsafe { - glow_context().GenBuffers(1, &mut b.0); + glow_context().gen_buffers(1, &mut b.0); } b } @@ -758,13 +758,13 @@ impl Buffer { /// (Data, Map etc). pub fn bind(&self, target: BufferTarget) { unsafe { - glow_context().BindBuffer(target, self.0); + glow_context().bind_buffer(target, self.0); } } pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { unsafe { - glow_context().BufferData(target, + glow_context().buffer_data(target, data.len() as isize, data.as_ptr() as *const gl::types::GLvoid, usage); @@ -773,7 +773,7 @@ impl Buffer { pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) { unsafe { - glow_context().BufferSubData(target, 0, data.len() as isize, data.as_ptr() as *const _); + glow_context().buffer_sub_data(target, 0, data.len() as isize, data.as_ptr() as *const _); } } @@ -787,7 +787,7 @@ impl Buffer { pub fn map(&self, target: BufferTarget, access: Access, length: usize) -> MappedBuffer { unsafe { MappedBuffer { - inner: Vec::from_raw_parts(glow_context().MapBuffer(target, access) as *mut u8, 0, length), + inner: Vec::from_raw_parts(glow_context().map_buffer(target, access) as *mut u8, 0, length), target, } } @@ -797,7 +797,7 @@ impl Buffer { impl Drop for Buffer { fn drop(&mut self) { unsafe { - glow_context().DeleteBuffers(1, &self.0); + glow_context().delete_buffers(1, &self.0); } } } @@ -824,7 +824,7 @@ impl DerefMut for MappedBuffer { impl Drop for MappedBuffer { fn drop(&mut self) { unsafe { - glow_context().UnmapBuffer(self.target); + glow_context().unmap_buffer(self.target); } mem::forget(mem::replace(&mut self.inner, Vec::new())); } @@ -842,7 +842,7 @@ pub struct Framebuffer(u32); pub fn check_framebuffer_status() { unsafe { - let status = glow_context().CheckFramebufferStatus(gl::FRAMEBUFFER); + let status = glow_context().check_framebuffer_status(gl::FRAMEBUFFER); let s = match status { gl::FRAMEBUFFER_UNDEFINED => "GL_FRAMEBUFFER_UNDEFINED", @@ -868,7 +868,7 @@ pub fn check_framebuffer_status() { pub fn check_gl_error() { unsafe { loop { - let err = glow_context().GetError(); + let err = glow_context().get_error(); if err == gl::NO_ERROR { break } @@ -882,32 +882,32 @@ impl Framebuffer { pub fn new() -> Framebuffer { let mut fb = Framebuffer(0); unsafe { - glow_context().GenFramebuffers(1, &mut fb.0); + glow_context().gen_framebuffers(1, &mut fb.0); } fb } pub fn bind(&self) { unsafe { - glow_context().BindFramebuffer(gl::FRAMEBUFFER, self.0); + glow_context().bind_framebuffer(gl::FRAMEBUFFER, self.0); } } pub fn bind_read(&self) { unsafe { - glow_context().BindFramebuffer(gl::READ_FRAMEBUFFER, self.0); + glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, self.0); } } pub fn bind_draw(&self) { unsafe { - glow_context().BindFramebuffer(gl::DRAW_FRAMEBUFFER, self.0); + glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, self.0); } } pub fn texture_2d(&self, attachment: Attachment, target: TextureTarget, tex: &Texture, level: i32) { unsafe { - glow_context().FramebufferTexture2D(gl::FRAMEBUFFER, attachment, target, tex.0, level); + glow_context().framebuffer_texture2_d(gl::FRAMEBUFFER, attachment, target, tex.0, level); } } } @@ -915,32 +915,32 @@ impl Framebuffer { impl Drop for Framebuffer { fn drop(&mut self) { unsafe { - glow_context().DeleteFramebuffers(1, &self.0); + glow_context().delete_framebuffers(1, &self.0); } } } pub fn unbind_framebuffer() { unsafe { - glow_context().BindFramebuffer(gl::FRAMEBUFFER, 0); + glow_context().bind_framebuffer(gl::FRAMEBUFFER, 0); } } pub fn unbind_framebuffer_read() { unsafe { - glow_context().BindFramebuffer(gl::READ_FRAMEBUFFER, 0); + glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, 0); } } pub fn unbind_framebuffer_draw() { unsafe { - glow_context().BindFramebuffer(gl::DRAW_FRAMEBUFFER, 0); + glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, 0); } } pub fn draw_buffers(bufs: &[Attachment]) { unsafe { - glow_context().DrawBuffers( + glow_context().draw_buffers( bufs.len() as i32, bufs.as_ptr() ); @@ -950,7 +950,7 @@ pub fn draw_buffers(bufs: &[Attachment]) { pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { unsafe { let name_c = ffi::CString::new(name).unwrap(); - glow_context().BindFragDataLocation(p.0, cn, name_c.as_ptr()); + glow_context().bind_frag_data_location(p.0, cn, name_c.as_ptr()); } } @@ -959,7 +959,7 @@ pub fn blit_framebuffer( dx0: i32, dy0: i32, dx1: i32, dy1: i32, mask: ClearFlags, filter: TextureValue) { unsafe { - glow_context().BlitFramebuffer( + glow_context().blit_framebuffer( sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1, mask.internal(), filter as u32 @@ -969,7 +969,7 @@ pub fn blit_framebuffer( pub fn read_buffer(a: Attachment) { unsafe { - glow_context().ReadBuffer(a); + glow_context().read_buffer(a); } } @@ -978,6 +978,6 @@ pub const COLOR: TargetBuffer = gl::COLOR; pub fn clear_buffer(buffer: TargetBuffer, draw_buffer: i32, values: &[f32]) { unsafe { - glow_context().ClearBufferfv(buffer, draw_buffer, values.as_ptr()); + glow_context().clear_bufferfv(buffer, draw_buffer, values.as_ptr()); } } From 14a65dde0d8ece25191ece2084f3aaa276460c4d Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:37:53 -0800 Subject: [PATCH 007/137] Import glow::HasContext trait, finds draw_elements etc. --- src/gl/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index fdd1ee54..5f7969e5 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -21,6 +21,7 @@ use std::ptr; use std::ops::{Deref, DerefMut}; use log::{error, info}; use glow as gl; +use glow::HasContext; static mut context: Option = None; From 83ebc444048d29367f512726396e7f4fe15d5838 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:45:35 -0800 Subject: [PATCH 008/137] Fix mismatched types, glow uses Option and &str instead of raw pointers 53 errors --- src/gl/mod.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 5f7969e5..561bbb90 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -119,7 +119,7 @@ pub fn clear(flags: ClearFlags) { } pub fn depth_mask(f: bool) { - unsafe { glow_context().depth_mask(f as u8); } + unsafe { glow_context().depth_mask(f); } } /// `Func` is a function to be preformed on two values. @@ -278,7 +278,7 @@ impl Texture { /// Binds the texture to the passed target. pub fn bind(&self, target: TextureTarget) { unsafe { - glow_context().bind_texture(target, self.0); + glow_context().bind_texture(target, Some(self.0)); } } @@ -485,7 +485,7 @@ pub struct Program(u32); impl Program { pub fn new() -> Program { - Program(unsafe { glow_context().create_program() }) + Program(unsafe { glow_context().create_program().expect("program creation failed") }) } pub fn attach_shader(&self, shader: Shader) { @@ -502,13 +502,13 @@ impl Program { pub fn use_program(&self) { unsafe { - glow_context().use_program(self.0); + glow_context().use_program(Some(self.0)); } } pub fn uniform_location(&self, name: &str) -> Option { let u = unsafe { - glow_context().get_uniform_location(self.0, ffi::CString::new(name).unwrap().as_ptr()) + glow_context().get_uniform_location(self.0, name) }; if u != -1 { Some(Uniform(u)) @@ -519,8 +519,7 @@ impl Program { pub fn attribute_location(&self, name: &str) -> Option { let a = unsafe { - let name_c = ffi::CString::new(name).unwrap(); - glow_context().get_attrib_location(self.0, name_c.as_ptr()) + glow_context().get_attrib_location(self.0, name) }; if a != -1 { Some(Attribute(a)) @@ -699,7 +698,7 @@ impl VertexArray { /// this `VertexArray`. pub fn bind(&self) { unsafe { - glow_context().bind_vertex_array(self.0); + glow_context().bind_vertex_array(Some(self.0)); } } } @@ -759,7 +758,7 @@ impl Buffer { /// (Data, Map etc). pub fn bind(&self, target: BufferTarget) { unsafe { - glow_context().bind_buffer(target, self.0); + glow_context().bind_buffer(target, Some(self.0)); } } @@ -890,19 +889,19 @@ impl Framebuffer { pub fn bind(&self) { unsafe { - glow_context().bind_framebuffer(gl::FRAMEBUFFER, self.0); + glow_context().bind_framebuffer(gl::FRAMEBUFFER, Some(self.0)); } } pub fn bind_read(&self) { unsafe { - glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, self.0); + glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, Some(self.0)); } } pub fn bind_draw(&self) { unsafe { - glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, self.0); + glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, Some(self.0)); } } @@ -923,19 +922,19 @@ impl Drop for Framebuffer { pub fn unbind_framebuffer() { unsafe { - glow_context().bind_framebuffer(gl::FRAMEBUFFER, 0); + glow_context().bind_framebuffer(gl::FRAMEBUFFER, Some(0)); } } pub fn unbind_framebuffer_read() { unsafe { - glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, 0); + glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, Some(0)); } } pub fn unbind_framebuffer_draw() { unsafe { - glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, 0); + glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, Some(0)); } } @@ -950,8 +949,7 @@ pub fn draw_buffers(bufs: &[Attachment]) { pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { unsafe { - let name_c = ffi::CString::new(name).unwrap(); - glow_context().bind_frag_data_location(p.0, cn, name_c.as_ptr()); + glow_context().bind_frag_data_location(p.0, cn, name) } } From ed17a0892289900340aced3f7a12f7b598b8d4be Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:50:30 -0800 Subject: [PATCH 009/137] Fix uniform_location, glow already returns Some(u32) --- src/gl/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 561bbb90..b4ea319b 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -510,7 +510,7 @@ impl Program { let u = unsafe { glow_context().get_uniform_location(self.0, name) }; - if u != -1 { + if let Some(u) = u { Some(Uniform(u)) } else { None From c6295bba28b9e0a44d155d05dfa61ba6a3e9de50 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:56:01 -0800 Subject: [PATCH 010/137] uniform_location: convert i32 to u32 for Uniform --- src/gl/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index b4ea319b..d9d22f2b 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -507,11 +507,13 @@ impl Program { } pub fn uniform_location(&self, name: &str) -> Option { + use std::convert::TryInto; + let u = unsafe { glow_context().get_uniform_location(self.0, name) }; if let Some(u) = u { - Some(Uniform(u)) + Some(Uniform(u.try_into().unwrap())) } else { None } From f8c9cb64bb1bff971550d9141db2dce5d830a0c8 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:57:02 -0800 Subject: [PATCH 011/137] Cast to i32 instead of TryInto (51 errors) --- src/gl/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index d9d22f2b..83982a12 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -507,13 +507,11 @@ impl Program { } pub fn uniform_location(&self, name: &str) -> Option { - use std::convert::TryInto; - let u = unsafe { glow_context().get_uniform_location(self.0, name) }; if let Some(u) = u { - Some(Uniform(u.try_into().unwrap())) + Some(Uniform(u as i32)) } else { None } From 145d5cb8579cbb222c173b8f9a0ec16a5706e263 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:57:54 -0800 Subject: [PATCH 012/137] Fix attribute_location (49 errors) --- src/gl/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 83982a12..ea2242a0 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -521,8 +521,8 @@ impl Program { let a = unsafe { glow_context().get_attrib_location(self.0, name) }; - if a != -1 { - Some(Attribute(a)) + if let Some(a) = a { + Some(Attribute(a as i32)) } else { None } From c27cdc8bef726e96de9b444c3861952506acdf5b Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 19:59:37 -0800 Subject: [PATCH 013/137] Fix shader creation Result u32 type (48) --- src/gl/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index ea2242a0..76fa755a 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -541,7 +541,7 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { - Shader(unsafe { glow_context().create_shader(ty) }) + Shader(unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) } pub fn set_source(&self, src: &str) { From bbc7db4b316688448d637cd084c2affc34c2e926 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:05:55 -0800 Subject: [PATCH 014/137] Fix passing GLvoid and 2d/3d, down to 40 errors --- src/gl/mod.rs | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 76fa755a..4273e579 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -60,7 +60,7 @@ pub fn draw_arrays(ty: DrawType, offset: usize, count: usize) { pub fn draw_elements(ty: DrawType, count: i32, dty: Type, offset: usize) { unsafe { - glow_context().draw_elements(ty, count, dty, offset as *const gl::types::GLvoid); + glow_context().draw_elements(ty, count, dty, offset as i32); } } @@ -293,7 +293,7 @@ impl Texture { level, format, ty, - pixels.as_mut_ptr() as *mut gl::types::GLvoid); + Some(pixels)); } } @@ -306,11 +306,7 @@ impl Texture { ty: Type, pix: Option<&[u8]>) { unsafe { - let ptr = match pix { - Some(val) => val.as_ptr() as *const gl::types::GLvoid, - None => ptr::null(), - }; - glow_context().tex_image2_d(target, + glow_context().tex_image_2d(target, level, format as i32, width as i32, @@ -318,7 +314,7 @@ impl Texture { 0, format, ty, - ptr + pix ); } } @@ -334,7 +330,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - glow_context().tex_sub_image2_d(target, + glow_context().tex_sub_image_2d(target, level, x as i32, y as i32, @@ -342,7 +338,7 @@ impl Texture { height as i32, format, ty, - pix.as_ptr() as *const _ + pix ); } } @@ -357,11 +353,7 @@ impl Texture { ty: Type, pix: Option<&[u8]>) { unsafe { - let ptr = match pix { - Some(val) => val.as_ptr() as *const gl::types::GLvoid, - None => ptr::null(), - }; - glow_context().tex_image2_d(target, + glow_context().tex_image_2d(target, level, internal_format as i32, width as i32, @@ -369,7 +361,7 @@ impl Texture { 0, format, ty, - ptr + pix ); } } @@ -392,7 +384,7 @@ impl Texture { samples }; - glow_context().tex_image2_d_multisample(target, + glow_context().tex_image_2d_multisample(target, use_samples, format, width as i32, @@ -412,7 +404,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - glow_context().tex_image3_d(target, + glow_context().tex_image_3d(target, level, format as i32, width as i32, @@ -421,7 +413,7 @@ impl Texture { 0, format, ty, - pix.as_ptr() as *const gl::types::GLvoid); + pix); } } @@ -438,7 +430,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - glow_context().tex_sub_image3_d(target, + glow_context().tex_sub_image_3d(target, level, x as i32, y as i32, @@ -448,7 +440,7 @@ impl Texture { depth as i32, format, ty, - pix.as_ptr() as *const gl::types::GLvoid); + pix); } } @@ -907,7 +899,7 @@ impl Framebuffer { pub fn texture_2d(&self, attachment: Attachment, target: TextureTarget, tex: &Texture, level: i32) { unsafe { - glow_context().framebuffer_texture2_d(gl::FRAMEBUFFER, attachment, target, tex.0, level); + glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, tex.0, level); } } } From 8f8ee7162b9e46e0f222464a73702d6ab1059377 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:08:34 -0800 Subject: [PATCH 015/137] Fix missing Options type mismatches (38) --- src/gl/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 4273e579..f4ef1837 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -413,7 +413,7 @@ impl Texture { 0, format, ty, - pix); + Some(pix)); } } @@ -899,7 +899,7 @@ impl Framebuffer { pub fn texture_2d(&self, attachment: Attachment, target: TextureTarget, tex: &Texture, level: i32) { unsafe { - glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, tex.0, level); + glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, Some(tex.0), level); } } } From 9ce92a9344afffd7e168141f5bfad59ce71db837 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:09:52 -0800 Subject: [PATCH 016/137] Offsets are i32 in glow, not GLvoid (36) --- src/gl/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index f4ef1837..a6095546 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -655,7 +655,7 @@ impl Attribute { ty, normalized as u8, stride, - offset as *const gl::types::GLvoid); + offset); } } @@ -665,7 +665,7 @@ impl Attribute { size, ty, stride, - offset as *const gl::types::GLvoid); + offset); } } } From 188993f87b1f36e23d3ba931ad3b0a71e7c1aff6 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:19:52 -0800 Subject: [PATCH 017/137] Fix clear_buffer using _f32_slice (35) --- src/gl/mod.rs | 5 +++-- src/render/mod.rs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a6095546..60a6d4ff 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -967,8 +967,9 @@ pub fn read_buffer(a: Attachment) { pub type TargetBuffer = u32; pub const COLOR: TargetBuffer = gl::COLOR; -pub fn clear_buffer(buffer: TargetBuffer, draw_buffer: i32, values: &[f32]) { +pub fn clear_buffer(buffer: TargetBuffer, draw_buffer: u32, values: &mut [f32]) { unsafe { - glow_context().clear_bufferfv(buffer, draw_buffer, values.as_ptr()); + // TODO: why does glow have &mut on clear buffer values, why would it change the color? + glow_context().clear_buffer_f32_slice(buffer, draw_buffer, values); } } diff --git a/src/render/mod.rs b/src/render/mod.rs index 291e9b07..4f789ba1 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -355,8 +355,8 @@ impl Renderer { trans.trans.bind(); gl::clear_color(0.0, 0.0, 0.0, 1.0); gl::clear(gl::ClearFlags::Color); - gl::clear_buffer(gl::COLOR, 0, &[0.0, 0.0, 0.0, 1.0]); - gl::clear_buffer(gl::COLOR, 1, &[0.0, 0.0, 0.0, 0.0]); + gl::clear_buffer(gl::COLOR, 0, &mut [0.0, 0.0, 0.0, 1.0]); + gl::clear_buffer(gl::COLOR, 1, &mut [0.0, 0.0, 0.0, 0.0]); gl::blend_func_separate(gl::ONE_FACTOR, gl::ONE_FACTOR, gl::ZERO_FACTOR, gl::ONE_MINUS_SRC_ALPHA); for (pos, info) in world.get_render_list().iter().rev() { From 4dbe2b2dc3047aa380825d654940b0154fcbae9e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:22:27 -0800 Subject: [PATCH 018/137] Delete methods are singular not plural (35, still type mismatched) --- src/gl/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 60a6d4ff..98f7dadb 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -457,7 +457,7 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { - glow_context().delete_textures(1, &self.0); + glow_context().delete_texture(1, &self.0); } } } @@ -698,7 +698,7 @@ impl VertexArray { impl Drop for VertexArray { fn drop(&mut self) { unsafe { - glow_context().delete_vertex_arrays(1, &self.0); + glow_context().delete_vertex_array(1, &self.0); } self.0 = 0; } @@ -789,7 +789,7 @@ impl Buffer { impl Drop for Buffer { fn drop(&mut self) { unsafe { - glow_context().delete_buffers(1, &self.0); + glow_context().delete_buffer(1, &self.0); } } } @@ -907,7 +907,7 @@ impl Framebuffer { impl Drop for Framebuffer { fn drop(&mut self) { unsafe { - glow_context().delete_framebuffers(1, &self.0); + glow_context().delete_framebuffer(1, &self.0); } } } From 34630c0863b27adab84782e6ede845273d65d46f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:27:05 -0800 Subject: [PATCH 019/137] glBufferData -> buffer_data_u8_slice --- src/gl/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 98f7dadb..019001f5 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -756,9 +756,8 @@ impl Buffer { pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { unsafe { - glow_context().buffer_data(target, - data.len() as isize, - data.as_ptr() as *const gl::types::GLvoid, + glow_context().buffer_data_u8_slice(target, + data, usage); } } From 7c9cb3c865d24ff8a4bf5c8764bd2b67402aa151 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:28:14 -0800 Subject: [PATCH 020/137] buffer_sub_data_u8_slice --- src/gl/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 019001f5..4d31849b 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -764,7 +764,7 @@ impl Buffer { pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) { unsafe { - glow_context().buffer_sub_data(target, 0, data.len() as isize, data.as_ptr() as *const _); + glow_context().buffer_sub_data_u8_slice(target, 0, data); } } From 0db120e19b6cc2d7b061aa2db36008c8f2d27659 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:43:04 -0800 Subject: [PATCH 021/137] Update more glow method wrapper names found by reviewing glow native platform (22) --- src/gl/mod.rs | 67 +++++++++++++++++++++---------------------- src/render/clouds.rs | 6 ++-- src/render/shaders.rs | 4 +-- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 4d31849b..583e53d8 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -66,6 +66,7 @@ pub fn draw_elements(ty: DrawType, count: i32, dty: Type, offset: usize) { pub fn multi_draw_elements(ty: DrawType, count: &[i32], dty: Type, offsets: &[usize]) { unsafe { + // TODO: gl.MultiDrawElements in glow? glow_context().multi_draw_elements(ty, count.as_ptr(), dty, offsets.as_ptr() as *const _, count.len() as i32); } } @@ -270,7 +271,8 @@ impl Texture { pub fn new() -> Texture { let mut t = Texture(0); unsafe { - glow_context().gen_textures(1, &mut t.0); + // TODO: return glow's Texture + glow_context().create_texture(); } t } @@ -289,7 +291,7 @@ impl Texture { ty: Type, pixels: &mut [u8]) { unsafe { - glow_context().get_tex_image(target, + glow_context().get_tex_image_u8_slice(target, level, format, ty, @@ -374,16 +376,16 @@ impl Texture { format: TextureFormat, fixed: bool) { unsafe { - let result: &mut [i32] = &mut [0; 1]; - glow_context().get_integerv(gl::MAX_SAMPLES, &mut result[0]); + let result: i32 = glow_context().get_parameter_i32(gl::MAX_SAMPLES); let use_samples = - if samples > result[0] { - info!("glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", samples, result[0]); - result[0] + if samples > result { + info!("glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", samples, result); + result } else { samples }; + // TODO: gl.TexImage2DMultisample in glow glow_context().tex_image_2d_multisample(target, use_samples, format, @@ -449,7 +451,7 @@ impl Texture { param: TextureParameter, value: TextureValue) { unsafe { - glow_context().tex_parameteri(target, param, value); + glow_context().tex_parameter_i32(target, param, value); } } } @@ -552,23 +554,14 @@ impl Shader { } } - pub fn get_parameter(&self, param: ShaderParameter) -> i32 { - let mut ret: i32 = 0; + pub fn get_shader_compile_status(&self) -> bool { unsafe { - glow_context().get_shaderiv(self.0, param, &mut ret); + glow_context().get_shader_compile_status(self.0) } - ret } pub fn get_info_log(&self) -> String { - let len = self.get_parameter(INFO_LOG_LENGTH); - - let mut data = Vec::::with_capacity(len as usize); - unsafe { - data.set_len(len as usize); - glow_context().get_shader_info_log(self.0, len, ptr::null_mut(), data.as_mut_ptr() as *mut i8); - } - String::from_utf8(data).unwrap() + glow_context().get_shader_info_log(self.0) } } @@ -578,56 +571,57 @@ pub struct Uniform(i32); impl Uniform { pub fn set_int(&self, val: i32) { unsafe { - glow_context().uniform1i(self.0, val); + glow_context().uniform_1_i32(self.0, val); } } pub fn set_int3(&self, x: i32, y: i32, z: i32) { unsafe { - glow_context().uniform3i(self.0, x, y, z); + glow_context().uniform_3_i32(self.0, x, y, z); } } pub fn set_float(&self, val: f32) { unsafe { - glow_context().uniform1f(self.0, val); + glow_context().uniform_1_f32(self.0, val); } } pub fn set_float2(&self, x: f32, y: f32) { unsafe { - glow_context().uniform2f(self.0, x, y); + glow_context().uniform_2_f32(self.0, x, y); } } pub fn set_float3(&self, x: f32, y: f32, z: f32) { unsafe { - glow_context().uniform3f(self.0, x, y, z); + glow_context().uniform_3_f32(self.0, x, y, z); } } pub fn set_float4(&self, x: f32, y: f32, z: f32, w: f32) { unsafe { - glow_context().uniform4f(self.0, x, y, z, w); + glow_context().uniform_4_f32(self.0, x, y, z, w); } } pub fn set_float_mutli_raw(&self, data: *const f32, len: usize) { unsafe { - glow_context().uniform4fv(self.0, len as i32, data); + // TODO: takes a slice, not a raw pointer + glow_context().uniform_4_f32_slice(self.0, len as i32, data); } } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - glow_context().uniform_matrix4fv(self.0, 1, false as u8, m.as_ptr()); + glow_context().uniform_matrix_4_f32_slice(self.0, 1, false as u8, m.as_ptr()); } } pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { unsafe { - glow_context().uniform_matrix4fv(self.0, m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe + glow_context().uniform_matrix_4_f32_slice(self.0, m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe } } } @@ -650,7 +644,7 @@ impl Attribute { pub fn vertex_pointer(&self, size: i32, ty: Type, normalized: bool, stride: i32, offset: i32) { unsafe { - glow_context().vertex_attrib_pointer(self.0 as u32, + glow_context().vertex_attrib_pointer_f32(self.0 as u32, size, ty, normalized as u8, @@ -661,7 +655,7 @@ impl Attribute { pub fn vertex_pointer_int(&self, size: i32, ty: Type, stride: i32, offset: i32) { unsafe { - glow_context().vertex_attrib_i_pointer(self.0 as u32, + glow_context().vertex_attrib_pointer_i32(self.0 as u32, size, ty, stride, @@ -680,7 +674,8 @@ impl VertexArray { pub fn new() -> VertexArray { let mut va = VertexArray(0); unsafe { - glow_context().gen_vertex_arrays(1, &mut va.0); + // TODO: return glow's VertexArray + glow_context().create_vertex_array(); } va } @@ -740,7 +735,8 @@ impl Buffer { pub fn new() -> Buffer { let mut b = Buffer(0); unsafe { - glow_context().gen_buffers(1, &mut b.0); + // TODO: returns glow's Buffer + glow_context().create_buffer(); } b } @@ -778,6 +774,7 @@ impl Buffer { pub fn map(&self, target: BufferTarget, access: Access, length: usize) -> MappedBuffer { unsafe { MappedBuffer { + // TODO: is there no gl.MapBuffer, only gl.MapBufferRange (map_buffer_range) in glow? inner: Vec::from_raw_parts(glow_context().map_buffer(target, access) as *mut u8, 0, length), target, } @@ -873,7 +870,8 @@ impl Framebuffer { pub fn new() -> Framebuffer { let mut fb = Framebuffer(0); unsafe { - glow_context().gen_framebuffers(1, &mut fb.0); + // TODO: return glow's Framebuffer + glow_context().create_framebuffer(); } fb } @@ -959,6 +957,7 @@ pub fn blit_framebuffer( pub fn read_buffer(a: Attachment) { unsafe { + // TODO: gl.ReadBuffer in glow? glow_context().read_buffer(a); } } diff --git a/src/render/clouds.rs b/src/render/clouds.rs index 420a5cdc..4a8b1375 100644 --- a/src/render/clouds.rs +++ b/src/render/clouds.rs @@ -47,7 +47,7 @@ impl Clouds { v.set_source(&vertex); v.compile(); - if v.get_parameter(gl::COMPILE_STATUS) == 0 { + if !v.get_shader_compile_status() { error!("Src: {}", vertex); panic!("Shader error: {}", v.get_info_log()); } else { @@ -62,7 +62,7 @@ impl Clouds { g.set_source(&geo); g.compile(); - if g.get_parameter(gl::COMPILE_STATUS) == 0 { + if !g.get_shader_compile_status() { error!("Src: {}", geo); panic!("Shader error: {}", g.get_info_log()); } else { @@ -77,7 +77,7 @@ impl Clouds { f.set_source(&fragment); f.compile(); - if f.get_parameter(gl::COMPILE_STATUS) == 0 { + if !f.get_shader_compile_status() { error!("Src: {}", fragment); panic!("Shader error: {}", f.get_info_log()); } else { diff --git a/src/render/shaders.rs b/src/render/shaders.rs index a50803c0..e52ba558 100644 --- a/src/render/shaders.rs +++ b/src/render/shaders.rs @@ -128,7 +128,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program { v.set_source(vertex); v.compile(); - if v.get_parameter(gl::COMPILE_STATUS) == 0 { + if !v.get_shader_compile_status() { error!("Src: {}", vertex); panic!("Shader error: {}", v.get_info_log()); } else { @@ -143,7 +143,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program { f.set_source(fragment); f.compile(); - if f.get_parameter(gl::COMPILE_STATUS) == 0 { + if !f.get_shader_compile_status() { error!("Src: {}", fragment); panic!("Shader error: {}", f.get_info_log()); } else { From 2fa74852257c04f0f28ed54cb54de486712e8503 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 5 Jan 2020 20:45:33 -0800 Subject: [PATCH 022/137] Found two more, tex_sub_image_2d/3d(_u8_slice) (20) --- src/gl/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 583e53d8..c4219d04 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -332,7 +332,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - glow_context().tex_sub_image_2d(target, + glow_context().tex_sub_image_2d_u8_slice(target, level, x as i32, y as i32, @@ -340,7 +340,7 @@ impl Texture { height as i32, format, ty, - pix + Some(pix) ); } } @@ -432,7 +432,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - glow_context().tex_sub_image_3d(target, + glow_context().tex_sub_image_3d_u8_slice(target, level, x as i32, y as i32, @@ -442,7 +442,7 @@ impl Texture { depth as i32, format, ty, - pix); + Some(pix)); } } From 6d8d80e1c0a1932ea3e4094e982248622ee2cad2 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 17:09:09 -0800 Subject: [PATCH 023/137] Remove unused multi_draw_elements, can be replaced by draw_elements in a loop and it has no WebGL equivalent (19) --- src/gl/mod.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index c4219d04..d643fb98 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -64,14 +64,7 @@ pub fn draw_elements(ty: DrawType, count: i32, dty: Type, offset: usize) { } } -pub fn multi_draw_elements(ty: DrawType, count: &[i32], dty: Type, offsets: &[usize]) { - unsafe { - // TODO: gl.MultiDrawElements in glow? - glow_context().multi_draw_elements(ty, count.as_ptr(), dty, offsets.as_ptr() as *const _, count.len() as i32); - } -} - -/// Sets the size of the viewport of this context. +// Sets the size of the viewport of this context. pub fn viewport(x: i32, y: i32, w: i32, h: i32) { unsafe { glow_context().viewport(x, y, w, h); From 547af6404994b16dc07e8349ed1299c132f456a9 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 17:29:56 -0800 Subject: [PATCH 024/137] glow implements glMapBufferRange --- src/gl/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index d643fb98..a55bf91d 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -767,8 +767,7 @@ impl Buffer { pub fn map(&self, target: BufferTarget, access: Access, length: usize) -> MappedBuffer { unsafe { MappedBuffer { - // TODO: is there no gl.MapBuffer, only gl.MapBufferRange (map_buffer_range) in glow? - inner: Vec::from_raw_parts(glow_context().map_buffer(target, access) as *mut u8, 0, length), + inner: Vec::from_raw_parts(glow_context().map_buffer_range(target, 0, length as i32, access) as *mut u8, 0, length), target, } } From 5d14a438213ad7871c882e56182c54ab7e82abfa Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 18:25:26 -0800 Subject: [PATCH 025/137] Remove unused read_buffer (17) --- src/gl/mod.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a55bf91d..8906afeb 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -947,13 +947,6 @@ pub fn blit_framebuffer( } } -pub fn read_buffer(a: Attachment) { - unsafe { - // TODO: gl.ReadBuffer in glow? - glow_context().read_buffer(a); - } -} - pub type TargetBuffer = u32; pub const COLOR: TargetBuffer = gl::COLOR; From 1bdd087453c09bb5906dbaf46f03440f2874b721 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 18:27:31 -0800 Subject: [PATCH 026/137] Comment out glRenderbufferStorageMultisample for now (16) --- src/gl/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 8906afeb..82bce796 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -378,7 +378,9 @@ impl Texture { samples }; - // TODO: gl.TexImage2DMultisample in glow + // TODO: switch to glRenderbufferStorageMultisample? + // from glTexImage2DMultisample which isn't in WebGL + /* glow_context().tex_image_2d_multisample(target, use_samples, format, @@ -386,6 +388,7 @@ impl Texture { height as i32, fixed as u8 ); + */ } } From 112f452326b7bb79630d648193234bd41c0e9832 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 18:31:25 -0800 Subject: [PATCH 027/137] glow's deletes automatically pass 1 and take no reference (12) --- src/gl/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 82bce796..1a26cfe7 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -455,7 +455,7 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { - glow_context().delete_texture(1, &self.0); + glow_context().delete_texture(self.0); } } } @@ -689,7 +689,7 @@ impl VertexArray { impl Drop for VertexArray { fn drop(&mut self) { unsafe { - glow_context().delete_vertex_array(1, &self.0); + glow_context().delete_vertex_array(self.0); } self.0 = 0; } @@ -780,7 +780,7 @@ impl Buffer { impl Drop for Buffer { fn drop(&mut self) { unsafe { - glow_context().delete_buffer(1, &self.0); + glow_context().delete_buffer(self.0); } } } @@ -899,7 +899,7 @@ impl Framebuffer { impl Drop for Framebuffer { fn drop(&mut self) { unsafe { - glow_context().delete_framebuffer(1, &self.0); + glow_context().delete_framebuffer(self.0); } } } From 382a6c4fd516521ced06d37b9fc343cc03f2b3da Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 18:33:23 -0800 Subject: [PATCH 028/137] shader_source() accepts &str directly; removes last of std::ptr --- src/gl/mod.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 1a26cfe7..1a723137 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -15,9 +15,7 @@ //extern crate steven_gl as gl; use std::ops::BitOr; -use std::ffi; use std::mem; -use std::ptr; use std::ops::{Deref, DerefMut}; use log::{error, info}; use glow as gl; @@ -536,11 +534,7 @@ impl Shader { pub fn set_source(&self, src: &str) { unsafe { - let src_c = ffi::CString::new(src).unwrap(); - glow_context().shader_source(self.0, - 1, - &src_c.as_ptr(), - ptr::null()); + glow_context().shader_source(self.0, src); } } From 863c987a98aacfce7a20cab94e12a380fa9ffead Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 18:37:28 -0800 Subject: [PATCH 029/137] Pass uniform Option (5) --- src/gl/mod.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 1a723137..309f5416 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -499,7 +499,7 @@ impl Program { glow_context().get_uniform_location(self.0, name) }; if let Some(u) = u { - Some(Uniform(u as i32)) + Some(Uniform(u)) } else { None } @@ -556,62 +556,62 @@ impl Shader { } #[derive(Clone, Copy)] -pub struct Uniform(i32); +pub struct Uniform(u32); impl Uniform { pub fn set_int(&self, val: i32) { unsafe { - glow_context().uniform_1_i32(self.0, val); + glow_context().uniform_1_i32(Some(&self.0), val); } } pub fn set_int3(&self, x: i32, y: i32, z: i32) { unsafe { - glow_context().uniform_3_i32(self.0, x, y, z); + glow_context().uniform_3_i32(Some(&self.0), x, y, z); } } pub fn set_float(&self, val: f32) { unsafe { - glow_context().uniform_1_f32(self.0, val); + glow_context().uniform_1_f32(Some(&self.0), val); } } pub fn set_float2(&self, x: f32, y: f32) { unsafe { - glow_context().uniform_2_f32(self.0, x, y); + glow_context().uniform_2_f32(Some(&self.0), x, y); } } pub fn set_float3(&self, x: f32, y: f32, z: f32) { unsafe { - glow_context().uniform_3_f32(self.0, x, y, z); + glow_context().uniform_3_f32(Some(&self.0), x, y, z); } } pub fn set_float4(&self, x: f32, y: f32, z: f32, w: f32) { unsafe { - glow_context().uniform_4_f32(self.0, x, y, z, w); + glow_context().uniform_4_f32(Some(&self.0), x, y, z, w); } } pub fn set_float_mutli_raw(&self, data: *const f32, len: usize) { unsafe { // TODO: takes a slice, not a raw pointer - glow_context().uniform_4_f32_slice(self.0, len as i32, data); + glow_context().uniform_4_f32_slice(Some(&self.0), len as i32, data); } } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - glow_context().uniform_matrix_4_f32_slice(self.0, 1, false as u8, m.as_ptr()); + glow_context().uniform_matrix_4_f32_slice(Some(&self.0), 1, false as u8, m.as_ptr()); } } pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { unsafe { - glow_context().uniform_matrix_4_f32_slice(self.0, m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe + glow_context().uniform_matrix_4_f32_slice(Some(&self.0), m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe } } } From d85b73f30eb9e91635580e5df0c88db3bff3ac65 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 18:49:58 -0800 Subject: [PATCH 030/137] Fix bool passing normalized parameter (4) --- src/gl/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 309f5416..9f9376b1 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -637,7 +637,7 @@ impl Attribute { glow_context().vertex_attrib_pointer_f32(self.0 as u32, size, ty, - normalized as u8, + normalized, stride, offset); } From 2c9dea3ff0dd92e88db9ff182a3cf0354e5a6e3f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 18:50:42 -0800 Subject: [PATCH 031/137] Fix draw_buffers parameter (3) --- src/gl/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 9f9376b1..a25dde06 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -918,10 +918,7 @@ pub fn unbind_framebuffer_draw() { pub fn draw_buffers(bufs: &[Attachment]) { unsafe { - glow_context().draw_buffers( - bufs.len() as i32, - bufs.as_ptr() - ); + glow_context().draw_buffers(bufs); } } From 1dcd2f7524b1c0a06b25c340924e4f6149cf0667 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 19:10:56 -0800 Subject: [PATCH 032/137] Comment out broken calls to uniform_4_f32_slice for now, to expose other bugs --- src/gl/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a25dde06..fa709aba 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -598,20 +598,22 @@ impl Uniform { pub fn set_float_mutli_raw(&self, data: *const f32, len: usize) { unsafe { // TODO: takes a slice, not a raw pointer - glow_context().uniform_4_f32_slice(Some(&self.0), len as i32, data); + //TODO glow_context().uniform_4_f32_slice(Some(&self.0), len as i32, data); } } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - glow_context().uniform_matrix_4_f32_slice(Some(&self.0), 1, false as u8, m.as_ptr()); + // TODO + //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), 1, false as u8, m.as_ptr()); } } pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { unsafe { - glow_context().uniform_matrix_4_f32_slice(Some(&self.0), m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe + // TODO + //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe } } } From e60a5a8d5d94f24037b0e1ba78c1a573e20b9f6a Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 19:12:22 -0800 Subject: [PATCH 033/137] Stop returning context from gl::init, unnecessary (3) --- src/gl/mod.rs | 12 ++++++------ src/main.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index fa709aba..6b294824 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -24,12 +24,12 @@ use glow::HasContext; static mut context: Option = None; /// Inits the gl library. This should be called once a context is ready. -pub fn init(vid: & glutin::WindowedContext) -> glow::Context { - let ctx = gl::Context::from_loader_function(|s| { - vid.get_proc_address(s) as *const _ - }); - context = Some(ctx); - ctx +pub fn init(vid: & glutin::WindowedContext) { + unsafe { + context = Some(gl::Context::from_loader_function(|s| { + vid.get_proc_address(s) as *const _ + })); + } } fn glow_context() -> glow::Context { diff --git a/src/main.rs b/src/main.rs index 7a797759..03a3779e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -248,7 +248,7 @@ fn main2() { window.make_current().expect("Could not set current context.") }; - let gl = gl::init(&window); + gl::init(&window); let renderer = render::Renderer::new(resource_manager.clone()); let mut ui_container = ui::Container::new(); From cd6c0abbf2af1b7cd6972f2e17e1245cab892e6c Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 19:13:19 -0800 Subject: [PATCH 034/137] Getting shader info is unsafe (2) --- src/gl/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 6b294824..a13aa267 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -551,7 +551,9 @@ impl Shader { } pub fn get_info_log(&self) -> String { - glow_context().get_shader_info_log(self.0) + unsafe { + glow_context().get_shader_info_log(self.0) + } } } From 2113a3706f7be6abd28703a16917c3453c917481 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 19:14:11 -0800 Subject: [PATCH 035/137] Unwrapping static mut is unsafe (1) --- src/gl/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a13aa267..8aefb7c3 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -33,7 +33,9 @@ pub fn init(vid: & glutin::WindowedContext) { } fn glow_context() -> glow::Context { - context.unwrap() + unsafe { + context.unwrap() + } } /// Dsed to specify how the vertices will be handled From 479360e3fb4bf312257a68d180e678d24d828839 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 Jan 2020 19:22:27 -0800 Subject: [PATCH 036/137] Use unsafe raw pointers for global mutable context --- src/gl/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 8aefb7c3..123029e2 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -21,20 +21,20 @@ use log::{error, info}; use glow as gl; use glow::HasContext; -static mut context: Option = None; +static mut context: *mut glow::Context = 0 as *mut glow::Context; /// Inits the gl library. This should be called once a context is ready. pub fn init(vid: & glutin::WindowedContext) { unsafe { - context = Some(gl::Context::from_loader_function(|s| { + context = &mut (gl::Context::from_loader_function(|s| { vid.get_proc_address(s) as *const _ - })); + })) as *mut glow::Context; } } -fn glow_context() -> glow::Context { +fn glow_context() -> &'static glow::Context { unsafe { - context.unwrap() + context.as_ref().unwrap() } } From f2b8167e815a7c1aa6f92d3699ffdf9a3350313c Mon Sep 17 00:00:00 2001 From: ice_iix Date: Wed, 8 Jan 2020 18:29:50 -0800 Subject: [PATCH 037/137] Fix initializing GL objects wrappers from glow wrappers --- src/gl/mod.rs | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 123029e2..0d5eea78 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -262,12 +262,7 @@ pub struct Texture(u32); impl Texture { // Allocates a new texture. pub fn new() -> Texture { - let mut t = Texture(0); - unsafe { - // TODO: return glow's Texture - glow_context().create_texture(); - } - t + Texture(unsafe { glow_context().create_texture().expect("create texture failed") }) } /// Binds the texture to the passed target. @@ -668,12 +663,7 @@ pub struct VertexArray(u32); impl VertexArray { /// Allocates a new `VertexArray`. pub fn new() -> VertexArray { - let mut va = VertexArray(0); - unsafe { - // TODO: return glow's VertexArray - glow_context().create_vertex_array(); - } - va + VertexArray(unsafe { glow_context().create_vertex_array().expect("create vertex array failed") }) } /// Marks the `VertexArray` as the currently active one, this @@ -729,12 +719,7 @@ pub struct Buffer(u32); impl Buffer { /// Allocates a new Buffer. pub fn new() -> Buffer { - let mut b = Buffer(0); - unsafe { - // TODO: returns glow's Buffer - glow_context().create_buffer(); - } - b + Buffer(unsafe { glow_context().create_buffer().expect("create buffer failed") }) } /// Makes the buffer the currently active one for the given target. @@ -863,12 +848,7 @@ pub fn check_gl_error() { impl Framebuffer { pub fn new() -> Framebuffer { - let mut fb = Framebuffer(0); - unsafe { - // TODO: return glow's Framebuffer - glow_context().create_framebuffer(); - } - fb + Framebuffer(unsafe { glow_context().create_framebuffer().expect("create framebuffer failed") }) } pub fn bind(&self) { From 84b877de0a6240d5c7e4070105cdceee92dfc8f2 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 10 Jan 2020 17:15:56 -0800 Subject: [PATCH 038/137] Unbinding framebuffers should use None, as it is an Option (although glow unwraps it to 0 anyways) --- src/gl/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 0d5eea78..bd5a1015 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -886,19 +886,19 @@ impl Drop for Framebuffer { pub fn unbind_framebuffer() { unsafe { - glow_context().bind_framebuffer(gl::FRAMEBUFFER, Some(0)); + glow_context().bind_framebuffer(gl::FRAMEBUFFER, None); } } pub fn unbind_framebuffer_read() { unsafe { - glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, Some(0)); + glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, None); } } pub fn unbind_framebuffer_draw() { unsafe { - glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, Some(0)); + glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, None); } } From ffd70225b91e0a59e28be9f8c7de35e6932f8076 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 10 Jan 2020 17:46:15 -0800 Subject: [PATCH 039/137] Log image_3d parameters: image_3d level=0, width=1024, height=1024, depth=1, format=6408, ty=5121, pix.len()=4194304 --- src/gl/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index bd5a1015..eb5b17ac 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -396,6 +396,7 @@ impl Texture { format: TextureFormat, ty: Type, pix: &[u8]) { + println!("image_3d level={}, width={}, height={}, depth={}, format={}, ty={}, pix.len()={}", level, width, height, depth, format, ty, pix.len()); unsafe { glow_context().tex_image_3d(target, level, From 6d1d8e596de4dc2ea1f9923b38f516ce7e6d6db2 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 10 Jan 2020 17:47:16 -0800 Subject: [PATCH 040/137] Uppercase global to fix warning --- src/gl/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index eb5b17ac..2e3c9ffd 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -21,12 +21,12 @@ use log::{error, info}; use glow as gl; use glow::HasContext; -static mut context: *mut glow::Context = 0 as *mut glow::Context; +static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; /// Inits the gl library. This should be called once a context is ready. pub fn init(vid: & glutin::WindowedContext) { unsafe { - context = &mut (gl::Context::from_loader_function(|s| { + CONTEXT = &mut (gl::Context::from_loader_function(|s| { vid.get_proc_address(s) as *const _ })) as *mut glow::Context; } @@ -34,7 +34,7 @@ pub fn init(vid: & glutin::WindowedContext) { fn glow_context() -> &'static glow::Context { unsafe { - context.as_ref().unwrap() + CONTEXT.as_ref().unwrap() } } From 63e80a4a839126e04c115e0142f1468fb422f409 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 10 Jan 2020 18:00:57 -0800 Subject: [PATCH 041/137] Remove steven_gl --- Cargo.lock | 21 ------------------- Cargo.toml | 4 ---- gl/Cargo.lock | 56 --------------------------------------------------- gl/Cargo.toml | 13 ------------ gl/build.rs | 19 ----------------- gl/src/lib.rs | 1 - src/gl/mod.rs | 2 -- 7 files changed, 116 deletions(-) delete mode 100644 gl/Cargo.lock delete mode 100644 gl/Cargo.toml delete mode 100644 gl/build.rs delete mode 100644 gl/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 305e8876..48e1e03e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -631,16 +631,6 @@ dependencies = [ "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "gl_generator" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "glow" version = "0.4.0" @@ -1999,15 +1989,6 @@ dependencies = [ "steven_shared 0.0.1", ] -[[package]] -name = "steven_gl" -version = "0.0.1" -dependencies = [ - "gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", - "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "steven_resources" version = "0.1.0" @@ -2046,7 +2027,6 @@ dependencies = [ "std_or_web 0.0.1", "stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "steven_blocks 0.0.1", - "steven_gl 0.0.1", "steven_resources 0.1.0", "steven_shared 0.0.1", "structopt 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2681,7 +2661,6 @@ dependencies = [ "checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" "checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd" "checksum gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a" -"checksum gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" "checksum glow 0.4.0 (git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94)" = "" "checksum glutin 0.22.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)" = "4f29f0d8e02e304b15a4464118387dcad1f543695057a60276a196311cc93452" "checksum glutin_egl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "772edef3b28b8ad41e4ea202748e65eefe8e5ffd1f4535f1219793dbb20b3d4c" diff --git a/Cargo.toml b/Cargo.toml index 6cf1e20c..7bf00ed2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,10 +52,6 @@ reqwest = { version = "0.10.0", features = [ "blocking" ]} stdweb = "0.4.20" winit = { version = "=0.20.0-alpha6", features = [ "stdweb" ]} -[dependencies.steven_gl] -path = "./gl" -version = "0" - [dependencies.steven_resources] path = "./resources" version = "0" diff --git a/gl/Cargo.lock b/gl/Cargo.lock deleted file mode 100644 index a04e2585..00000000 --- a/gl/Cargo.lock +++ /dev/null @@ -1,56 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "gl_generator" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "khronos_api" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.66" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "steven_gl" -version = "0.0.1" -dependencies = [ - "gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", - "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "xml-rs" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" -"checksum khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" -"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" -"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -"checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5" diff --git a/gl/Cargo.toml b/gl/Cargo.toml deleted file mode 100644 index e42b3388..00000000 --- a/gl/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "steven_gl" -version = "0.0.1" -authors = [ "Thinkofdeath " ] -edition = "2018" -build = "build.rs" - -[build-dependencies] -gl_generator = "0.14.0" -khronos_api = "3.1.0" - -[dependencies] -libc = "0.2.66" diff --git a/gl/build.rs b/gl/build.rs deleted file mode 100644 index 4cfe3d65..00000000 --- a/gl/build.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::env; -use std::fs::File; -use std::io::BufWriter; -use std::path::Path; -use gl_generator::{Registry, Api, Profile, Fallbacks, GlobalGenerator}; - -fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); - let dest = Path::new(&out_dir); - - let mut file = BufWriter::new(File::create(&dest.join("bindings.rs")).unwrap()); - Registry::new(Api::Gl, - (3, 2), - Profile::Core, - Fallbacks::All, - []) - .write_bindings(GlobalGenerator, &mut file) - .unwrap(); -} diff --git a/gl/src/lib.rs b/gl/src/lib.rs deleted file mode 100644 index 44ae78fc..00000000 --- a/gl/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 2e3c9ffd..a07d343e 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//extern crate steven_gl as gl; - use std::ops::BitOr; use std::mem; use std::ops::{Deref, DerefMut}; From 1c53b2f45cb164d8a87c1f1afbb95d6ecb0b7f8c Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 10 Jan 2020 18:23:43 -0800 Subject: [PATCH 042/137] Disable optimizations for now to help debugging --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7bf00ed2..e6501370 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ path = "src/main.rs" # Steven runs horrendously slow with no optimizations, and often freezes. # However, building with full -O3 optimizations takes too long for a debug build. # Use an -O1 optimization level strikes a good compromise between build and program performance. -opt-level = 1 +#opt-level = 1 [dependencies] cfg-if = "0.1.9" From 9d31c9c8ba1c5ef5ea4b5ea2872da1f731635711 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 10 Jan 2020 18:34:46 -0800 Subject: [PATCH 043/137] Remove println --- src/gl/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a07d343e..81df1ec0 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -394,7 +394,6 @@ impl Texture { format: TextureFormat, ty: Type, pix: &[u8]) { - println!("image_3d level={}, width={}, height={}, depth={}, format={}, ty={}, pix.len()={}", level, width, height, depth, format, ty, pix.len()); unsafe { glow_context().tex_image_3d(target, level, From b3bc6162bea6bac6bb78b6905fba71b7eca72316 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 11:18:52 -0800 Subject: [PATCH 044/137] Experiments with calling tex_image_3d earlier --- src/gl/mod.rs | 35 +++++++++++++++++++++++++++++++++++ src/main.rs | 2 ++ src/render/mod.rs | 2 ++ 3 files changed, 39 insertions(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 81df1ec0..7f31e1d6 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -27,11 +27,29 @@ pub fn init(vid: & glutin::WindowedContext) { CONTEXT = &mut (gl::Context::from_loader_function(|s| { vid.get_proc_address(s) as *const _ })) as *mut glow::Context; + + println!("FIRST tex_image_3d..."); + const ATLAS_SIZE: usize = 1024; + CONTEXT.as_ref().unwrap().tex_image_3d( + gl::TEXTURE_2D_ARRAY, + 0, + gl::RGBA as i32, // internal_format + ATLAS_SIZE as i32, + ATLAS_SIZE as i32, + 1, // depth + 0, // border + gl::RGBA, // format + gl::UNSIGNED_BYTE, // ty + Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels + ); +println!("returned"); +println!("CONTEXT = {:?}", CONTEXT); } } fn glow_context() -> &'static glow::Context { unsafe { + println!("glow_context = {:?}", CONTEXT); CONTEXT.as_ref().unwrap() } } @@ -395,6 +413,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { + /* glow_context().tex_image_3d(target, level, format as i32, @@ -405,6 +424,22 @@ impl Texture { format, ty, Some(pix)); + */ + println!("inner tex_image_3d"); + const ATLAS_SIZE: usize = 1024; + CONTEXT.as_ref().unwrap().tex_image_3d( + gl::TEXTURE_2D_ARRAY, + 0, + gl::RGBA as i32, // internal_format + ATLAS_SIZE as i32, + ATLAS_SIZE as i32, + 1, // depth + 0, // border + gl::RGBA, // format + gl::UNSIGNED_BYTE, // ty + Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels + ); + println!("returned 3"); } } diff --git a/src/main.rs b/src/main.rs index a88a2d85..7581e03c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -236,10 +236,12 @@ fn main2() { .with_title("Stevenarella") .with_inner_size(glutin::dpi::LogicalSize::new(854.0, 480.0)); let window = glutin::ContextBuilder::new() + /* .with_stencil_buffer(0) .with_depth_buffer(24) .with_gl(glutin::GlRequest::GlThenGles{opengl_version: (3, 2), opengles_version: (2, 0)}) .with_gl_profile(glutin::GlProfile::Core) + */ .with_vsync(vsync) .build_windowed(window_builder, &events_loop) .expect("Could not create glutin window."); diff --git a/src/render/mod.rs b/src/render/mod.rs index 4f789ba1..e468565a 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -161,6 +161,7 @@ impl Renderer { }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); + println!("about to call 2nd tex_image_3d"); tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, ATLAS_SIZE as u32, @@ -169,6 +170,7 @@ impl Renderer { gl::RGBA, gl::UNSIGNED_BYTE, &[0; ATLAS_SIZE * ATLAS_SIZE * 4]); + println!("returned 2"); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE); From 16a91ca0ff9b93695f151a825c36b066acb26385 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 11:42:01 -0800 Subject: [PATCH 045/137] Log thread ID to test multithreading hypothesis, both are on ThreadId(1) --- src/gl/mod.rs | 1 + src/render/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 7f31e1d6..b67de071 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -28,6 +28,7 @@ pub fn init(vid: & glutin::WindowedContext) { vid.get_proc_address(s) as *const _ })) as *mut glow::Context; + println!("main thread = {:?}", std::thread::current().id()); println!("FIRST tex_image_3d..."); const ATLAS_SIZE: usize = 1024; CONTEXT.as_ref().unwrap().tex_image_3d( diff --git a/src/render/mod.rs b/src/render/mod.rs index e468565a..da39294c 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -161,6 +161,7 @@ impl Renderer { }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); + println!("thread = {:?}", std::thread::current().id()); println!("about to call 2nd tex_image_3d"); tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, From 8e364288ec8ce8cfb95d7cb76ddbb143fe9861d1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 11:42:04 -0800 Subject: [PATCH 046/137] Revert "Log thread ID to test multithreading hypothesis, both are on ThreadId(1)" This reverts commit 16a91ca0ff9b93695f151a825c36b066acb26385. --- src/gl/mod.rs | 1 - src/render/mod.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index b67de071..7f31e1d6 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -28,7 +28,6 @@ pub fn init(vid: & glutin::WindowedContext) { vid.get_proc_address(s) as *const _ })) as *mut glow::Context; - println!("main thread = {:?}", std::thread::current().id()); println!("FIRST tex_image_3d..."); const ATLAS_SIZE: usize = 1024; CONTEXT.as_ref().unwrap().tex_image_3d( diff --git a/src/render/mod.rs b/src/render/mod.rs index da39294c..e468565a 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -161,7 +161,6 @@ impl Renderer { }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); - println!("thread = {:?}", std::thread::current().id()); println!("about to call 2nd tex_image_3d"); tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, From 5dce795ae1b508360747e2090f861195c1d683ea Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 12:51:01 -0800 Subject: [PATCH 047/137] Change repro function to not have any arguments so rust-lldb doesn't take forever to print the 1024-element pix array in the backtrace --- src/gl/mod.rs | 37 ++++++++++++++++++++----------------- src/render/mod.rs | 3 +++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 7f31e1d6..2f4184dc 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -403,6 +403,26 @@ impl Texture { } } + pub fn test_image_3d(&self) { + const ATLAS_SIZE: usize = 1024; + println!("inner tex_image_3d"); + unsafe { + CONTEXT.as_ref().unwrap().tex_image_3d( + gl::TEXTURE_2D_ARRAY, + 0, + gl::RGBA as i32, // internal_format + ATLAS_SIZE as i32, + ATLAS_SIZE as i32, + 1, // depth + 0, // border + gl::RGBA, // format + gl::UNSIGNED_BYTE, // ty + Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels + ); + } + println!("returned 3"); + } + pub fn image_3d(&self, target: TextureTarget, level: i32, @@ -413,7 +433,6 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { - /* glow_context().tex_image_3d(target, level, format as i32, @@ -424,22 +443,6 @@ impl Texture { format, ty, Some(pix)); - */ - println!("inner tex_image_3d"); - const ATLAS_SIZE: usize = 1024; - CONTEXT.as_ref().unwrap().tex_image_3d( - gl::TEXTURE_2D_ARRAY, - 0, - gl::RGBA as i32, // internal_format - ATLAS_SIZE as i32, - ATLAS_SIZE as i32, - 1, // depth - 0, // border - gl::RGBA, // format - gl::UNSIGNED_BYTE, // ty - Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels - ); - println!("returned 3"); } } diff --git a/src/render/mod.rs b/src/render/mod.rs index e468565a..a5bcc2c8 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -162,6 +162,8 @@ impl Renderer { let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); println!("about to call 2nd tex_image_3d"); + tex.test_image_3d(); + /* tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, ATLAS_SIZE as u32, @@ -170,6 +172,7 @@ impl Renderer { gl::RGBA, gl::UNSIGNED_BYTE, &[0; ATLAS_SIZE * ATLAS_SIZE * 4]); + */ println!("returned 2"); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); From 6cf00dca42e8e74f38643d1199c96fcc65ad81cd Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 13:14:02 -0800 Subject: [PATCH 048/137] Crashes after version read, doesn't crash beefore --- src/main.rs | 4 ++++ src/render/mod.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main.rs b/src/main.rs index 7581e03c..98566cf6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,6 +252,10 @@ fn main2() { gl::init(&window); + println!("main call test_image_3d"); + gl::Texture::new().test_image_3d(); + println!("return4"); + let renderer = render::Renderer::new(resource_manager.clone()); let mut ui_container = ui::Container::new(); diff --git a/src/render/mod.rs b/src/render/mod.rs index a5bcc2c8..a2261839 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -156,6 +156,8 @@ init_shader! { impl Renderer { pub fn new(res: Arc>) -> Renderer { + println!("\nabout to call 1st tex_image_3d"); + gl::Texture::new().test_image_3d(); let version = { res.read().unwrap().version() }; From d3b176f222f75f1f985a983941b813845c6acce2 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 13:56:35 -0800 Subject: [PATCH 049/137] Add more checks in resources, but now crashes before any of them --- src/resources.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/resources.rs b/src/resources.rs index 9ebad809..37f19d75 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -30,6 +30,7 @@ use zip; use crate::types::hash::FNVHash; use crate::ui; +use crate::gl; const RESOURCES_VERSION: &str = "1.12.2"; const VANILLA_CLIENT_URL: &str = "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"; @@ -101,6 +102,7 @@ impl Manager { /// Returns the 'version' of the manager. The version is /// increase everytime a pack is added or removed. pub fn version(&self) -> usize { + println!("4"); gl::Texture::new().test_image_3d(); self.version } @@ -419,10 +421,13 @@ impl Manager { } fn add_task_progress(progress: &Arc>, name: &str, file: &str, prog: u64) { + println!("2.1"); gl::Texture::new().test_image_3d(); let mut progress = progress.lock().unwrap(); + println!("2.2"); gl::Texture::new().test_image_3d(); for task in progress.tasks.iter_mut() .filter(|v| v.task_file == file) .filter(|v| v.task_name == name) { + println!("2.3"); gl::Texture::new().test_image_3d(); task.progress += prog as u64; } } @@ -502,8 +507,11 @@ struct ProgressRead<'a, T> { impl <'a, T: io::Read> io::Read for ProgressRead<'a, T> { fn read(&mut self, buf: &mut [u8]) -> io::Result { + println!("1"); gl::Texture::new().test_image_3d(); let size = self.read.read(buf)?; + println!("2"); gl::Texture::new().test_image_3d(); Manager::add_task_progress(self.progress, &self.task_name, &self.task_file, size as u64); + println!("3"); gl::Texture::new().test_image_3d(); Ok(size) } } From 17fc7fe3671d1274f04d911988d0d8d17c8d7cc0 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 13:56:38 -0800 Subject: [PATCH 050/137] Revert "Add more checks in resources, but now crashes before any of them" This reverts commit d3b176f222f75f1f985a983941b813845c6acce2. --- src/resources.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/resources.rs b/src/resources.rs index 37f19d75..9ebad809 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -30,7 +30,6 @@ use zip; use crate::types::hash::FNVHash; use crate::ui; -use crate::gl; const RESOURCES_VERSION: &str = "1.12.2"; const VANILLA_CLIENT_URL: &str = "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"; @@ -102,7 +101,6 @@ impl Manager { /// Returns the 'version' of the manager. The version is /// increase everytime a pack is added or removed. pub fn version(&self) -> usize { - println!("4"); gl::Texture::new().test_image_3d(); self.version } @@ -421,13 +419,10 @@ impl Manager { } fn add_task_progress(progress: &Arc>, name: &str, file: &str, prog: u64) { - println!("2.1"); gl::Texture::new().test_image_3d(); let mut progress = progress.lock().unwrap(); - println!("2.2"); gl::Texture::new().test_image_3d(); for task in progress.tasks.iter_mut() .filter(|v| v.task_file == file) .filter(|v| v.task_name == name) { - println!("2.3"); gl::Texture::new().test_image_3d(); task.progress += prog as u64; } } @@ -507,11 +502,8 @@ struct ProgressRead<'a, T> { impl <'a, T: io::Read> io::Read for ProgressRead<'a, T> { fn read(&mut self, buf: &mut [u8]) -> io::Result { - println!("1"); gl::Texture::new().test_image_3d(); let size = self.read.read(buf)?; - println!("2"); gl::Texture::new().test_image_3d(); Manager::add_task_progress(self.progress, &self.task_name, &self.task_file, size as u64); - println!("3"); gl::Texture::new().test_image_3d(); Ok(size) } } From 17fb0fd5043389e866b924bdcaac01c1e9a75eae Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 13:57:31 -0800 Subject: [PATCH 051/137] Skip setting version, crashes still in 'nabout to call 1st tex_image_3d' --- src/render/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index a2261839..2c185bec 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -158,9 +158,9 @@ impl Renderer { pub fn new(res: Arc>) -> Renderer { println!("\nabout to call 1st tex_image_3d"); gl::Texture::new().test_image_3d(); - let version = { + let version = 0; /*{ res.read().unwrap().version() - }; + };*/ let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); println!("about to call 2nd tex_image_3d"); From abbdc475c9ba00840b8c7cf3a4e2a840f12c94d2 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 13:57:38 -0800 Subject: [PATCH 052/137] Revert "Skip setting version, crashes still in 'nabout to call 1st tex_image_3d'" This reverts commit 17fb0fd5043389e866b924bdcaac01c1e9a75eae. --- src/render/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 2c185bec..a2261839 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -158,9 +158,9 @@ impl Renderer { pub fn new(res: Arc>) -> Renderer { println!("\nabout to call 1st tex_image_3d"); gl::Texture::new().test_image_3d(); - let version = 0; /*{ + let version = { res.read().unwrap().version() - };*/ + }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); println!("about to call 2nd tex_image_3d"); From 2d91fb1c7e2471d1e4b34e120ecb944e927c64f8 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:04:59 -0800 Subject: [PATCH 053/137] Call in a loop, no difference --- src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 98566cf6..f7329f3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,9 +252,11 @@ fn main2() { gl::init(&window); - println!("main call test_image_3d"); - gl::Texture::new().test_image_3d(); - println!("return4"); + for i in 0..10 { + println!("main call test_image_3d {}", i); + gl::Texture::new().test_image_3d(); + println!("return {}", i); + } let renderer = render::Renderer::new(resource_manager.clone()); let mut ui_container = ui::Container::new(); From 504a154c4eea5183d311d2c05397c1488f2bd0e4 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:08:36 -0800 Subject: [PATCH 054/137] Try a loop in gl::init, still crashes later: --- src/gl/mod.rs | 8 +++++--- src/main.rs | 6 ------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 2f4184dc..3a6063c5 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -28,7 +28,8 @@ pub fn init(vid: & glutin::WindowedContext) { vid.get_proc_address(s) as *const _ })) as *mut glow::Context; - println!("FIRST tex_image_3d..."); + for i in 0..10 { + println!("gl::init tex_image_3d... {}", i); const ATLAS_SIZE: usize = 1024; CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, @@ -42,8 +43,9 @@ pub fn init(vid: & glutin::WindowedContext) { gl::UNSIGNED_BYTE, // ty Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); -println!("returned"); -println!("CONTEXT = {:?}", CONTEXT); + println!("returned, {}", i); + println!("CONTEXT = {:?}", CONTEXT); + } } } diff --git a/src/main.rs b/src/main.rs index f7329f3e..7581e03c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,12 +252,6 @@ fn main2() { gl::init(&window); - for i in 0..10 { - println!("main call test_image_3d {}", i); - gl::Texture::new().test_image_3d(); - println!("return {}", i); - } - let renderer = render::Renderer::new(resource_manager.clone()); let mut ui_container = ui::Container::new(); From 000b958e49382dc3d28c268462d59fa7116ab3cd Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:09:17 -0800 Subject: [PATCH 055/137] Try calling glow_context(), no difference --- src/gl/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 3a6063c5..bc26a112 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -31,7 +31,7 @@ pub fn init(vid: & glutin::WindowedContext) { for i in 0..10 { println!("gl::init tex_image_3d... {}", i); const ATLAS_SIZE: usize = 1024; - CONTEXT.as_ref().unwrap().tex_image_3d( + glow_context().tex_image_3d( gl::TEXTURE_2D_ARRAY, 0, gl::RGBA as i32, // internal_format From 43ad70cbf3460d66025059714b75332a9eeddc02 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:11:06 -0800 Subject: [PATCH 056/137] Remove loop --- src/gl/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index bc26a112..80932cc5 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -28,8 +28,7 @@ pub fn init(vid: & glutin::WindowedContext) { vid.get_proc_address(s) as *const _ })) as *mut glow::Context; - for i in 0..10 { - println!("gl::init tex_image_3d... {}", i); + println!("gl::init tex_image_3d..."); const ATLAS_SIZE: usize = 1024; glow_context().tex_image_3d( gl::TEXTURE_2D_ARRAY, @@ -43,9 +42,8 @@ pub fn init(vid: & glutin::WindowedContext) { gl::UNSIGNED_BYTE, // ty Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); - println!("returned, {}", i); + println!("returned"); println!("CONTEXT = {:?}", CONTEXT); - } } } From fe1fac7b35bf04314c70a0e3c3fe74388a0f2765 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:13:25 -0800 Subject: [PATCH 057/137] Call in main, no crash --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7581e03c..3d1ecc31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,7 +252,12 @@ fn main2() { gl::init(&window); - let renderer = render::Renderer::new(resource_manager.clone()); + println!("main 2"); gl::Texture::new().test_image_3d(); println!("ok"); + let rm = resource_manager.clone(); + println!("main 3"); gl::Texture::new().test_image_3d(); println!("ok"); + + let renderer = render::Renderer::new(rm); + println!("main 4"); gl::Texture::new().test_image_3d(); println!("ok"); let mut ui_container = ui::Container::new(); let mut last_frame = Instant::now(); From 49d78ac1741b615ceaaaf7b7351c1768ddfa4974 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:16:05 -0800 Subject: [PATCH 058/137] Remove call in gl::init, now crashes after resource_manager.clone() --- src/gl/mod.rs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 80932cc5..15269010 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -27,23 +27,6 @@ pub fn init(vid: & glutin::WindowedContext) { CONTEXT = &mut (gl::Context::from_loader_function(|s| { vid.get_proc_address(s) as *const _ })) as *mut glow::Context; - - println!("gl::init tex_image_3d..."); - const ATLAS_SIZE: usize = 1024; - glow_context().tex_image_3d( - gl::TEXTURE_2D_ARRAY, - 0, - gl::RGBA as i32, // internal_format - ATLAS_SIZE as i32, - ATLAS_SIZE as i32, - 1, // depth - 0, // border - gl::RGBA, // format - gl::UNSIGNED_BYTE, // ty - Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels - ); - println!("returned"); - println!("CONTEXT = {:?}", CONTEXT); } } From 25b34bb79b7f0dccca74f096a7b91bcdf9086c76 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:24:05 -0800 Subject: [PATCH 059/137] Log drop texture --- src/gl/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 15269010..8996d728 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -469,6 +469,7 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { + println!("about to delete_texture {}", self.0); glow_context().delete_texture(self.0); } } From ac0877960cafd2359a9a8b06831605070830a376 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:26:17 -0800 Subject: [PATCH 060/137] Move test_image_3d out of Texture so not involved with Drop --- src/gl/mod.rs | 42 +++++++++++++++++++++--------------------- src/main.rs | 6 +++--- src/render/mod.rs | 4 ++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 8996d728..c1b44f21 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -258,6 +258,27 @@ pub const CLAMP_TO_EDGE: TextureValue = gl::CLAMP_TO_EDGE as TextureValue; /// `Texture` is a buffer of data used by fragment shaders. pub struct Texture(u32); +pub fn test_image_3d() { + const ATLAS_SIZE: usize = 1024; + println!("inner tex_image_3d"); + unsafe { + CONTEXT.as_ref().unwrap().tex_image_3d( + gl::TEXTURE_2D_ARRAY, + 0, + gl::RGBA as i32, // internal_format + ATLAS_SIZE as i32, + ATLAS_SIZE as i32, + 1, // depth + 0, // border + gl::RGBA, // format + gl::UNSIGNED_BYTE, // ty + Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels + ); + } + println!("returned 3"); +} + + impl Texture { // Allocates a new texture. pub fn new() -> Texture { @@ -386,26 +407,6 @@ impl Texture { } } - pub fn test_image_3d(&self) { - const ATLAS_SIZE: usize = 1024; - println!("inner tex_image_3d"); - unsafe { - CONTEXT.as_ref().unwrap().tex_image_3d( - gl::TEXTURE_2D_ARRAY, - 0, - gl::RGBA as i32, // internal_format - ATLAS_SIZE as i32, - ATLAS_SIZE as i32, - 1, // depth - 0, // border - gl::RGBA, // format - gl::UNSIGNED_BYTE, // ty - Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels - ); - } - println!("returned 3"); - } - pub fn image_3d(&self, target: TextureTarget, level: i32, @@ -469,7 +470,6 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { - println!("about to delete_texture {}", self.0); glow_context().delete_texture(self.0); } } diff --git a/src/main.rs b/src/main.rs index 3d1ecc31..94cde347 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,12 +252,12 @@ fn main2() { gl::init(&window); - println!("main 2"); gl::Texture::new().test_image_3d(); println!("ok"); + println!("main 2"); gl::test_image_3d(); println!("ok"); let rm = resource_manager.clone(); - println!("main 3"); gl::Texture::new().test_image_3d(); println!("ok"); + println!("main 3"); gl::test_image_3d(); println!("ok"); let renderer = render::Renderer::new(rm); - println!("main 4"); gl::Texture::new().test_image_3d(); println!("ok"); + println!("main 4"); gl::test_image_3d(); println!("ok"); let mut ui_container = ui::Container::new(); let mut last_frame = Instant::now(); diff --git a/src/render/mod.rs b/src/render/mod.rs index a2261839..63c70979 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -157,14 +157,14 @@ init_shader! { impl Renderer { pub fn new(res: Arc>) -> Renderer { println!("\nabout to call 1st tex_image_3d"); - gl::Texture::new().test_image_3d(); + gl::test_image_3d(); let version = { res.read().unwrap().version() }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); println!("about to call 2nd tex_image_3d"); - tex.test_image_3d(); + gl::test_image_3d(); /* tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, From a9bf1f3dc6a9652be358fb926c1262faea1733e6 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:35:44 -0800 Subject: [PATCH 061/137] Call main 3 before resource_manager.clone(), it still crashes --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 94cde347..241bbf25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,10 +253,9 @@ fn main2() { gl::init(&window); println!("main 2"); gl::test_image_3d(); println!("ok"); - let rm = resource_manager.clone(); println!("main 3"); gl::test_image_3d(); println!("ok"); - let renderer = render::Renderer::new(rm); + let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); gl::test_image_3d(); println!("ok"); let mut ui_container = ui::Container::new(); From 463c5eefa6eb7519bfef807ecebd0045e5740bc4 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:37:02 -0800 Subject: [PATCH 062/137] Loop in main, now it crashes on 2nd call --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 241bbf25..4764180b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,8 +252,11 @@ fn main2() { gl::init(&window); - println!("main 2"); gl::test_image_3d(); println!("ok"); - println!("main 3"); gl::test_image_3d(); println!("ok"); + for i in 0..10 { + println!("\nmain {}", i); + gl::test_image_3d(); + println!("ok {}", i); + } let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); gl::test_image_3d(); println!("ok"); From b3da6ab51affb3025db525be55430020e06014c6 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:44:12 -0800 Subject: [PATCH 063/137] Test creating and binding texture before glTexImage3D, crashes on 2nd creating --- src/gl/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index c1b44f21..cc838c14 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -262,6 +262,12 @@ pub fn test_image_3d() { const ATLAS_SIZE: usize = 1024; println!("inner tex_image_3d"); unsafe { + println!("creating texture"); + let t = CONTEXT.as_ref().unwrap().create_texture().unwrap(); + println!("\tt = {}", t); + println!("bind texture"); + CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); + println!("teximage3d\n"); CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, 0, @@ -275,7 +281,7 @@ pub fn test_image_3d() { Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); } - println!("returned 3"); + println!("returning\n"); } From e763ad313f407519ede511337d4b7c53d17d105d Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:57:21 -0800 Subject: [PATCH 064/137] Try storing pixels in vec in case related to memory deallocation, no effect --- src/gl/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index cc838c14..c778313f 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -261,6 +261,7 @@ pub struct Texture(u32); pub fn test_image_3d() { const ATLAS_SIZE: usize = 1024; println!("inner tex_image_3d"); + let mut v = vec![]; unsafe { println!("creating texture"); let t = CONTEXT.as_ref().unwrap().create_texture().unwrap(); @@ -268,6 +269,7 @@ pub fn test_image_3d() { println!("bind texture"); CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); println!("teximage3d\n"); + let pixels = &[0; ATLAS_SIZE * ATLAS_SIZE * 4]; CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, 0, @@ -278,8 +280,9 @@ pub fn test_image_3d() { 0, // border gl::RGBA, // format gl::UNSIGNED_BYTE, // ty - Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels + Some(pixels), // pixels ); + v.push(pixels); } println!("returning\n"); } From d7ecb9a9c1b0775986af6cdd9c077ebe005b3370 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:57:24 -0800 Subject: [PATCH 065/137] Revert "Try storing pixels in vec in case related to memory deallocation, no effect" This reverts commit e763ad313f407519ede511337d4b7c53d17d105d. --- src/gl/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index c778313f..cc838c14 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -261,7 +261,6 @@ pub struct Texture(u32); pub fn test_image_3d() { const ATLAS_SIZE: usize = 1024; println!("inner tex_image_3d"); - let mut v = vec![]; unsafe { println!("creating texture"); let t = CONTEXT.as_ref().unwrap().create_texture().unwrap(); @@ -269,7 +268,6 @@ pub fn test_image_3d() { println!("bind texture"); CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); println!("teximage3d\n"); - let pixels = &[0; ATLAS_SIZE * ATLAS_SIZE * 4]; CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, 0, @@ -280,9 +278,8 @@ pub fn test_image_3d() { 0, // border gl::RGBA, // format gl::UNSIGNED_BYTE, // ty - Some(pixels), // pixels + Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); - v.push(pixels); } println!("returning\n"); } From baf324b66114d2986fce1285c75aae08648dd183 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 14:59:48 -0800 Subject: [PATCH 066/137] Try to delete texture, and now it crashes there --- src/gl/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index cc838c14..b3877640 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -280,6 +280,8 @@ pub fn test_image_3d() { gl::UNSIGNED_BYTE, // ty Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); + println!("delete_texture"); + CONTEXT.as_ref().unwrap().delete_texture(t); } println!("returning\n"); } From b0f49dcbe48a462c8ff765402def3154770a665a Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:11:01 -0800 Subject: [PATCH 067/137] Passing pixels as None avoids the immediate crash, must be something to do with Some(array) --- src/gl/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index b3877640..b9997cdb 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -269,8 +269,8 @@ pub fn test_image_3d() { CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); println!("teximage3d\n"); CONTEXT.as_ref().unwrap().tex_image_3d( - gl::TEXTURE_2D_ARRAY, - 0, + gl::TEXTURE_2D_ARRAY, // target + 0, // level gl::RGBA as i32, // internal_format ATLAS_SIZE as i32, ATLAS_SIZE as i32, @@ -278,7 +278,8 @@ pub fn test_image_3d() { 0, // border gl::RGBA, // format gl::UNSIGNED_BYTE, // ty - Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels + None, // pixels + //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); println!("delete_texture"); CONTEXT.as_ref().unwrap().delete_texture(t); From 8d7d75679ab6cde3486d3ab42116f0ea7b5b9f6a Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:17:26 -0800 Subject: [PATCH 068/137] Disable all buffer-related functions --- src/gl/mod.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index b9997cdb..03bfb91e 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -267,6 +267,7 @@ pub fn test_image_3d() { println!("\tt = {}", t); println!("bind texture"); CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); + /* println!("teximage3d\n"); CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, // target @@ -281,6 +282,7 @@ pub fn test_image_3d() { None, // pixels //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); + */ println!("delete_texture"); CONTEXT.as_ref().unwrap().delete_texture(t); } @@ -312,7 +314,7 @@ impl Texture { level, format, ty, - Some(pixels)); + None /* TODO Some(pixels) */); } } @@ -333,7 +335,7 @@ impl Texture { 0, format, ty, - pix + None /* TODO pix */ ); } } @@ -357,7 +359,7 @@ impl Texture { height as i32, format, ty, - Some(pix) + None /* TODO Some(pix) */ ); } } @@ -380,7 +382,7 @@ impl Texture { 0, format, ty, - pix + None /* TODO pix */ ); } } @@ -435,7 +437,7 @@ impl Texture { 0, format, ty, - Some(pix)); + None /* Some(pix) */); } } @@ -462,7 +464,7 @@ impl Texture { depth as i32, format, ty, - Some(pix)); + None /* TODO Some(pix) */); } } @@ -761,17 +763,21 @@ impl Buffer { } pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { + /* TODO unsafe { glow_context().buffer_data_u8_slice(target, data, usage); } + */ } pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) { + /* TODO unsafe { glow_context().buffer_sub_data_u8_slice(target, 0, data); } + */ } /// Maps the memory in the buffer on the gpu to memory which the program @@ -932,9 +938,11 @@ pub fn unbind_framebuffer_draw() { } pub fn draw_buffers(bufs: &[Attachment]) { + /* TODO unsafe { glow_context().draw_buffers(bufs); } + */ } pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { From 7c505e885967eb5644390d62a3e9440da87fb456 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:18:57 -0800 Subject: [PATCH 069/137] Disable tex_parameter_i32, the next crash --- src/gl/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 03bfb91e..bd3982f4 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -472,9 +472,11 @@ impl Texture { target: TextureTarget, param: TextureParameter, value: TextureValue) { + /* TODO unsafe { glow_context().tex_parameter_i32(target, param, value); } + */ } } From 30009a33718463bffa67c8165302860fec549e45 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:21:12 -0800 Subject: [PATCH 070/137] Disable shader_source due to crash --- src/gl/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index bd3982f4..8cdeca88 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -563,9 +563,11 @@ impl Shader { } pub fn set_source(&self, src: &str) { + /* TODO unsafe { glow_context().shader_source(self.0, src); } + */ } pub fn compile(&self) { From 2abb715a15ff5c57fe0623dac25c11f4fd74e465 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:23:14 -0800 Subject: [PATCH 071/137] Disable shader compile status and info log due to crash --- src/gl/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 8cdeca88..e5b6964e 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -577,15 +577,21 @@ impl Shader { } pub fn get_shader_compile_status(&self) -> bool { + true + /* TODO unsafe { glow_context().get_shader_compile_status(self.0) } + */ } pub fn get_info_log(&self) -> String { + /* TODO unsafe { glow_context().get_shader_info_log(self.0) } + */ + "".to_string() } } From 55bcc72c8120237d375c3a2d0a8db07adc35e31e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:23:21 -0800 Subject: [PATCH 072/137] Revert "Disable all buffer-related functions" This reverts commit 8d7d75679ab6cde3486d3ab42116f0ea7b5b9f6a. --- src/gl/mod.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index e5b6964e..1dc2ef41 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -267,7 +267,6 @@ pub fn test_image_3d() { println!("\tt = {}", t); println!("bind texture"); CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); - /* println!("teximage3d\n"); CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, // target @@ -282,7 +281,6 @@ pub fn test_image_3d() { None, // pixels //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); - */ println!("delete_texture"); CONTEXT.as_ref().unwrap().delete_texture(t); } @@ -314,7 +312,7 @@ impl Texture { level, format, ty, - None /* TODO Some(pixels) */); + Some(pixels)); } } @@ -335,7 +333,7 @@ impl Texture { 0, format, ty, - None /* TODO pix */ + pix ); } } @@ -359,7 +357,7 @@ impl Texture { height as i32, format, ty, - None /* TODO Some(pix) */ + Some(pix) ); } } @@ -382,7 +380,7 @@ impl Texture { 0, format, ty, - None /* TODO pix */ + pix ); } } @@ -437,7 +435,7 @@ impl Texture { 0, format, ty, - None /* Some(pix) */); + Some(pix)); } } @@ -464,7 +462,7 @@ impl Texture { depth as i32, format, ty, - None /* TODO Some(pix) */); + Some(pix)); } } @@ -773,21 +771,17 @@ impl Buffer { } pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { - /* TODO unsafe { glow_context().buffer_data_u8_slice(target, data, usage); } - */ } pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) { - /* TODO unsafe { glow_context().buffer_sub_data_u8_slice(target, 0, data); } - */ } /// Maps the memory in the buffer on the gpu to memory which the program @@ -948,11 +942,9 @@ pub fn unbind_framebuffer_draw() { } pub fn draw_buffers(bufs: &[Attachment]) { - /* TODO unsafe { glow_context().draw_buffers(bufs); } - */ } pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { From 09fc990cedbe4ea4dbab2ccee197374668f42b05 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:29:04 -0800 Subject: [PATCH 073/137] Disable broken tex_image_3d call in test_image_3d --- src/gl/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 1dc2ef41..b1885153 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -267,6 +267,7 @@ pub fn test_image_3d() { println!("\tt = {}", t); println!("bind texture"); CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); + /* println!("teximage3d\n"); CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, // target @@ -281,6 +282,7 @@ pub fn test_image_3d() { None, // pixels //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); + */ println!("delete_texture"); CONTEXT.as_ref().unwrap().delete_texture(t); } From d48bdcc8ef7d7a816090f9eb113e90600968aa85 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:42:57 -0800 Subject: [PATCH 074/137] Disable every glow context function to track down a crash --- src/gl/mod.rs | 145 +++++++++++++++++++++++++++++++------------------- 1 file changed, 89 insertions(+), 56 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index b1885153..a8af06d3 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -53,20 +53,20 @@ pub const POINTS: DrawType = gl::POINTS; pub fn draw_arrays(ty: DrawType, offset: usize, count: usize) { unsafe { - glow_context().draw_arrays(ty, offset as i32, count as i32); + //glow_context().draw_arrays(ty, offset as i32, count as i32); } } pub fn draw_elements(ty: DrawType, count: i32, dty: Type, offset: usize) { unsafe { - glow_context().draw_elements(ty, count, dty, offset as i32); + //glow_context().draw_elements(ty, count, dty, offset as i32); } } // Sets the size of the viewport of this context. pub fn viewport(x: i32, y: i32, w: i32, h: i32) { unsafe { - glow_context().viewport(x, y, w, h); + //glow_context().viewport(x, y, w, h); } } @@ -74,7 +74,7 @@ pub fn viewport(x: i32, y: i32, w: i32, h: i32) { /// when Clear is called with the color flag. pub fn clear_color(r: f32, g: f32, b: f32, a: f32) { unsafe { - glow_context().clear_color(r, g, b, a); + //glow_context().clear_color(r, g, b, a); } } @@ -108,11 +108,15 @@ impl BitOr for ClearFlags { /// Clears the buffers specified by the passed flags. pub fn clear(flags: ClearFlags) { - unsafe { glow_context().clear(flags.internal()) } + unsafe { + //glow_context().clear(flags.internal()) + } } pub fn depth_mask(f: bool) { - unsafe { glow_context().depth_mask(f); } + unsafe { + //glow_context().depth_mask(f); + } } /// `Func` is a function to be preformed on two values. @@ -127,7 +131,7 @@ pub const EQUAL: Func = gl::EQUAL; pub fn depth_func(f: Func) { unsafe { - glow_context().depth_func(f); + //glow_context().depth_func(f); } } @@ -143,14 +147,14 @@ pub const MULTISAMPLE: Flag = gl::MULTISAMPLE; /// Enables the passed flag. pub fn enable(f: Flag) { unsafe { - glow_context().enable(f); + //glow_context().enable(f); } } /// Disables the passed flag. pub fn disable(f: Flag) { unsafe { - glow_context().disable(f); + //glow_context().disable(f); } } @@ -158,7 +162,7 @@ pub fn disable(f: Flag) { /// currently active one. pub fn active_texture(id: u32) { unsafe { - glow_context().active_texture(gl::TEXTURE0 + id); + //glow_context().active_texture(gl::TEXTURE0 + id); } } @@ -172,13 +176,13 @@ pub const ZERO_FACTOR: Factor = gl::ZERO; /// Sets the factors to be used when blending. pub fn blend_func(s_factor: Factor, d_factor: Factor) { unsafe { - glow_context().blend_func(s_factor, d_factor); + //glow_context().blend_func(s_factor, d_factor); } } pub fn blend_func_separate(s_factor_rgb: Factor, d_factor_rgb: Factor, s_factor_a: Factor, d_factor_a: Factor) { unsafe { - glow_context().blend_func_separate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); + //glow_context().blend_func_separate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); } } @@ -190,7 +194,7 @@ pub const FRONT: Face = gl::FRONT; /// Sets the face to be culled by the gpu. pub fn cull_face(face: Face) { unsafe { - glow_context().cull_face(face); + //glow_context().cull_face(face); } } @@ -203,7 +207,9 @@ pub const COUNTER_CLOCK_WISE: FaceDirection = gl::CCW; /// Sets the direction of vertices used to specify the /// front face (e.g. for culling). pub fn front_face(dir: FaceDirection) { - unsafe { glow_context().front_face(dir) } + unsafe { + //glow_context().front_face(dir) + } } /// `Type` is a type of data used by various operations. @@ -293,13 +299,13 @@ pub fn test_image_3d() { impl Texture { // Allocates a new texture. pub fn new() -> Texture { - Texture(unsafe { glow_context().create_texture().expect("create texture failed") }) + Texture(0) //unsafe { glow_context().create_texture().expect("create texture failed") }) } /// Binds the texture to the passed target. pub fn bind(&self, target: TextureTarget) { unsafe { - glow_context().bind_texture(target, Some(self.0)); + //glow_context().bind_texture(target, Some(self.0)); } } @@ -310,11 +316,13 @@ impl Texture { ty: Type, pixels: &mut [u8]) { unsafe { + /* glow_context().get_tex_image_u8_slice(target, level, format, ty, Some(pixels)); + */ } } @@ -327,6 +335,7 @@ impl Texture { ty: Type, pix: Option<&[u8]>) { unsafe { + /* glow_context().tex_image_2d(target, level, format as i32, @@ -337,6 +346,7 @@ impl Texture { ty, pix ); + */ } } @@ -351,6 +361,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { + /* glow_context().tex_sub_image_2d_u8_slice(target, level, x as i32, @@ -361,6 +372,7 @@ impl Texture { ty, Some(pix) ); + */ } } @@ -374,6 +386,7 @@ impl Texture { ty: Type, pix: Option<&[u8]>) { unsafe { + /* glow_context().tex_image_2d(target, level, internal_format as i32, @@ -384,6 +397,7 @@ impl Texture { ty, pix ); + */ } } @@ -395,6 +409,7 @@ impl Texture { format: TextureFormat, fixed: bool) { unsafe { + /* let result: i32 = glow_context().get_parameter_i32(gl::MAX_SAMPLES); let use_samples = if samples > result { @@ -403,7 +418,7 @@ impl Texture { } else { samples }; - +*/ // TODO: switch to glRenderbufferStorageMultisample? // from glTexImage2DMultisample which isn't in WebGL /* @@ -428,6 +443,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { + /* glow_context().tex_image_3d(target, level, format as i32, @@ -438,6 +454,7 @@ impl Texture { format, ty, Some(pix)); + */ } } @@ -454,6 +471,7 @@ impl Texture { ty: Type, pix: &[u8]) { unsafe { + /* glow_context().tex_sub_image_3d_u8_slice(target, level, x as i32, @@ -465,6 +483,7 @@ impl Texture { format, ty, Some(pix)); + */ } } @@ -483,7 +502,7 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { - glow_context().delete_texture(self.0); + //glow_context().delete_texture(self.0); } } } @@ -503,54 +522,58 @@ pub struct Program(u32); impl Program { pub fn new() -> Program { - Program(unsafe { glow_context().create_program().expect("program creation failed") }) + Program(0) //unsafe { glow_context().create_program().expect("program creation failed") }) } pub fn attach_shader(&self, shader: Shader) { unsafe { - glow_context().attach_shader(self.0, shader.0); + //glow_context().attach_shader(self.0, shader.0); } } pub fn link(&self) { unsafe { - glow_context().link_program(self.0); + //glow_context().link_program(self.0); } } pub fn use_program(&self) { unsafe { - glow_context().use_program(Some(self.0)); + //glow_context().use_program(Some(self.0)); } } pub fn uniform_location(&self, name: &str) -> Option { + /* let u = unsafe { glow_context().get_uniform_location(self.0, name) }; if let Some(u) = u { Some(Uniform(u)) } else { + */ None - } + //} } pub fn attribute_location(&self, name: &str) -> Option { + /* let a = unsafe { glow_context().get_attrib_location(self.0, name) }; if let Some(a) = a { Some(Attribute(a as i32)) } else { + */ None - } + //} } } impl Drop for Program { fn drop(&mut self) { unsafe { - glow_context().delete_program(self.0); + //glow_context().delete_program(self.0); } } } @@ -559,7 +582,7 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { - Shader(unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) + Shader(0) //unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) } pub fn set_source(&self, src: &str) { @@ -572,7 +595,7 @@ impl Shader { pub fn compile(&self) { unsafe { - glow_context().compile_shader(self.0); + //glow_context().compile_shader(self.0); } } @@ -601,37 +624,37 @@ pub struct Uniform(u32); impl Uniform { pub fn set_int(&self, val: i32) { unsafe { - glow_context().uniform_1_i32(Some(&self.0), val); + //glow_context().uniform_1_i32(Some(&self.0), val); } } pub fn set_int3(&self, x: i32, y: i32, z: i32) { unsafe { - glow_context().uniform_3_i32(Some(&self.0), x, y, z); + //glow_context().uniform_3_i32(Some(&self.0), x, y, z); } } pub fn set_float(&self, val: f32) { unsafe { - glow_context().uniform_1_f32(Some(&self.0), val); + //glow_context().uniform_1_f32(Some(&self.0), val); } } pub fn set_float2(&self, x: f32, y: f32) { unsafe { - glow_context().uniform_2_f32(Some(&self.0), x, y); + //glow_context().uniform_2_f32(Some(&self.0), x, y); } } pub fn set_float3(&self, x: f32, y: f32, z: f32) { unsafe { - glow_context().uniform_3_f32(Some(&self.0), x, y, z); + //glow_context().uniform_3_f32(Some(&self.0), x, y, z); } } pub fn set_float4(&self, x: f32, y: f32, z: f32, w: f32) { unsafe { - glow_context().uniform_4_f32(Some(&self.0), x, y, z, w); + //glow_context().uniform_4_f32(Some(&self.0), x, y, z, w); } } @@ -664,34 +687,38 @@ pub struct Attribute(i32); impl Attribute { pub fn enable(&self) { unsafe { - glow_context().enable_vertex_attrib_array(self.0 as u32); + //glow_context().enable_vertex_attrib_array(self.0 as u32); } } pub fn disable(&self) { unsafe { - glow_context().disable_vertex_attrib_array(self.0 as u32); + //glow_context().disable_vertex_attrib_array(self.0 as u32); } } pub fn vertex_pointer(&self, size: i32, ty: Type, normalized: bool, stride: i32, offset: i32) { unsafe { + /* glow_context().vertex_attrib_pointer_f32(self.0 as u32, size, ty, normalized, stride, offset); + */ } } pub fn vertex_pointer_int(&self, size: i32, ty: Type, stride: i32, offset: i32) { unsafe { + /* glow_context().vertex_attrib_pointer_i32(self.0 as u32, size, ty, stride, offset); + */ } } } @@ -704,7 +731,7 @@ pub struct VertexArray(u32); impl VertexArray { /// Allocates a new `VertexArray`. pub fn new() -> VertexArray { - VertexArray(unsafe { glow_context().create_vertex_array().expect("create vertex array failed") }) + VertexArray(0) //unsafe { glow_context().create_vertex_array().expect("create vertex array failed") }) } /// Marks the `VertexArray` as the currently active one, this @@ -712,7 +739,7 @@ impl VertexArray { /// this `VertexArray`. pub fn bind(&self) { unsafe { - glow_context().bind_vertex_array(Some(self.0)); + //glow_context().bind_vertex_array(Some(self.0)); } } } @@ -720,7 +747,7 @@ impl VertexArray { impl Drop for VertexArray { fn drop(&mut self) { unsafe { - glow_context().delete_vertex_array(self.0); + //glow_context().delete_vertex_array(self.0); } self.0 = 0; } @@ -760,7 +787,7 @@ pub struct Buffer(u32); impl Buffer { /// Allocates a new Buffer. pub fn new() -> Buffer { - Buffer(unsafe { glow_context().create_buffer().expect("create buffer failed") }) + Buffer(0) //unsafe { glow_context().create_buffer().expect("create buffer failed") }) } /// Makes the buffer the currently active one for the given target. @@ -768,21 +795,23 @@ impl Buffer { /// (Data, Map etc). pub fn bind(&self, target: BufferTarget) { unsafe { - glow_context().bind_buffer(target, Some(self.0)); + //glow_context().bind_buffer(target, Some(self.0)); } } pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { unsafe { + /* glow_context().buffer_data_u8_slice(target, data, usage); + */ } } pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) { unsafe { - glow_context().buffer_sub_data_u8_slice(target, 0, data); + //glow_context().buffer_sub_data_u8_slice(target, 0, data); } } @@ -796,7 +825,7 @@ impl Buffer { pub fn map(&self, target: BufferTarget, access: Access, length: usize) -> MappedBuffer { unsafe { MappedBuffer { - inner: Vec::from_raw_parts(glow_context().map_buffer_range(target, 0, length as i32, access) as *mut u8, 0, length), + inner: vec![], //Vec::from_raw_parts(glow_context().map_buffer_range(target, 0, length as i32, access) as *mut u8, 0, length), target, } } @@ -806,7 +835,7 @@ impl Buffer { impl Drop for Buffer { fn drop(&mut self) { unsafe { - glow_context().delete_buffer(self.0); + //glow_context().delete_buffer(self.0); } } } @@ -833,7 +862,7 @@ impl DerefMut for MappedBuffer { impl Drop for MappedBuffer { fn drop(&mut self) { unsafe { - glow_context().unmap_buffer(self.target); + //glow_context().unmap_buffer(self.target); } mem::forget(mem::replace(&mut self.inner, Vec::new())); } @@ -876,6 +905,7 @@ pub fn check_framebuffer_status() { pub fn check_gl_error() { unsafe { + /* loop { let err = glow_context().get_error(); if err == gl::NO_ERROR { @@ -884,35 +914,36 @@ pub fn check_gl_error() { error!("glGetError = {}", err); } + */ } } impl Framebuffer { pub fn new() -> Framebuffer { - Framebuffer(unsafe { glow_context().create_framebuffer().expect("create framebuffer failed") }) + Framebuffer(0) //unsafe { glow_context().create_framebuffer().expect("create framebuffer failed") }) } pub fn bind(&self) { unsafe { - glow_context().bind_framebuffer(gl::FRAMEBUFFER, Some(self.0)); + //glow_context().bind_framebuffer(gl::FRAMEBUFFER, Some(self.0)); } } pub fn bind_read(&self) { unsafe { - glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, Some(self.0)); + //glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, Some(self.0)); } } pub fn bind_draw(&self) { unsafe { - glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, Some(self.0)); + //glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, Some(self.0)); } } pub fn texture_2d(&self, attachment: Attachment, target: TextureTarget, tex: &Texture, level: i32) { unsafe { - glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, Some(tex.0), level); + //glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, Some(tex.0), level); } } } @@ -920,38 +951,38 @@ impl Framebuffer { impl Drop for Framebuffer { fn drop(&mut self) { unsafe { - glow_context().delete_framebuffer(self.0); + //glow_context().delete_framebuffer(self.0); } } } pub fn unbind_framebuffer() { unsafe { - glow_context().bind_framebuffer(gl::FRAMEBUFFER, None); + //glow_context().bind_framebuffer(gl::FRAMEBUFFER, None); } } pub fn unbind_framebuffer_read() { unsafe { - glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, None); + //glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, None); } } pub fn unbind_framebuffer_draw() { unsafe { - glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, None); + //glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, None); } } pub fn draw_buffers(bufs: &[Attachment]) { unsafe { - glow_context().draw_buffers(bufs); + //glow_context().draw_buffers(bufs); } } pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { unsafe { - glow_context().bind_frag_data_location(p.0, cn, name) + //glow_context().bind_frag_data_location(p.0, cn, name) } } @@ -959,6 +990,7 @@ pub fn blit_framebuffer( sx0: i32, sy0: i32, sx1: i32, sy1: i32, dx0: i32, dy0: i32, dx1: i32, dy1: i32, mask: ClearFlags, filter: TextureValue) { + /* unsafe { glow_context().blit_framebuffer( sx0, sy0, sx1, sy1, @@ -966,6 +998,7 @@ pub fn blit_framebuffer( mask.internal(), filter as u32 ); } + */ } pub type TargetBuffer = u32; @@ -974,6 +1007,6 @@ pub const COLOR: TargetBuffer = gl::COLOR; pub fn clear_buffer(buffer: TargetBuffer, draw_buffer: u32, values: &mut [f32]) { unsafe { // TODO: why does glow have &mut on clear buffer values, why would it change the color? - glow_context().clear_buffer_f32_slice(buffer, draw_buffer, values); + //glow_context().clear_buffer_f32_slice(buffer, draw_buffer, values); } } From 6c8e2d702ecc86e412970a6adbea3f53c821f583 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:46:42 -0800 Subject: [PATCH 075/137] Re-enable glow shader functions, crashes illegal hardware instruction --- src/gl/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a8af06d3..603fe031 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -557,16 +557,14 @@ impl Program { } pub fn attribute_location(&self, name: &str) -> Option { - /* let a = unsafe { glow_context().get_attrib_location(self.0, name) }; if let Some(a) = a { Some(Attribute(a as i32)) } else { - */ None - //} + } } } @@ -582,7 +580,7 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { - Shader(0) //unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) + Shader(unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) } pub fn set_source(&self, src: &str) { From 4a3258f63be3aec156eb105901b143dd98c9f89d Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:50:50 -0800 Subject: [PATCH 076/137] Revert "Re-enable glow shader functions, crashes illegal hardware instruction" This reverts commit 6c8e2d702ecc86e412970a6adbea3f53c821f583. --- src/gl/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 603fe031..a8af06d3 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -557,14 +557,16 @@ impl Program { } pub fn attribute_location(&self, name: &str) -> Option { + /* let a = unsafe { glow_context().get_attrib_location(self.0, name) }; if let Some(a) = a { Some(Attribute(a as i32)) } else { + */ None - } + //} } } @@ -580,7 +582,7 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { - Shader(unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) + Shader(0) //unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) } pub fn set_source(&self, src: &str) { From 1fd8ae16055db4bb45308d6bfaa73e03ac1d847e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:54:41 -0800 Subject: [PATCH 077/137] Shaders return Some instead of None, comment out test_image_3d --- src/gl/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a8af06d3..7634517c 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -265,6 +265,7 @@ pub const CLAMP_TO_EDGE: TextureValue = gl::CLAMP_TO_EDGE as TextureValue; pub struct Texture(u32); pub fn test_image_3d() { + /* const ATLAS_SIZE: usize = 1024; println!("inner tex_image_3d"); unsafe { @@ -273,7 +274,6 @@ pub fn test_image_3d() { println!("\tt = {}", t); println!("bind texture"); CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); - /* println!("teximage3d\n"); CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, // target @@ -288,11 +288,11 @@ pub fn test_image_3d() { None, // pixels //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); - */ println!("delete_texture"); CONTEXT.as_ref().unwrap().delete_texture(t); } println!("returning\n"); + */ } @@ -551,9 +551,10 @@ impl Program { if let Some(u) = u { Some(Uniform(u)) } else { - */ None - //} + } + */ + Some(Uniform(0)) } pub fn attribute_location(&self, name: &str) -> Option { @@ -564,9 +565,10 @@ impl Program { if let Some(a) = a { Some(Attribute(a as i32)) } else { - */ None - //} + } + */ + Some(Attribute(0)) } } From b0c489ed0dc47194754aa61ed7fb562a8ba2cc9c Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 15:57:41 -0800 Subject: [PATCH 078/137] Re-enable part of test_image_3d, reproduces GenTextures crash --- src/gl/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 7634517c..89460060 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -265,7 +265,6 @@ pub const CLAMP_TO_EDGE: TextureValue = gl::CLAMP_TO_EDGE as TextureValue; pub struct Texture(u32); pub fn test_image_3d() { - /* const ATLAS_SIZE: usize = 1024; println!("inner tex_image_3d"); unsafe { @@ -275,6 +274,7 @@ pub fn test_image_3d() { println!("bind texture"); CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); println!("teximage3d\n"); + /* CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, // target 0, // level @@ -288,11 +288,11 @@ pub fn test_image_3d() { None, // pixels //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); + */ println!("delete_texture"); CONTEXT.as_ref().unwrap().delete_texture(t); } println!("returning\n"); - */ } From 18956ad34d98b8b513ead89a39202693358c338c Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 17:06:49 -0800 Subject: [PATCH 079/137] Log from_loader_function callback calls --- src/gl/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 89460060..7bce93e5 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -25,6 +25,7 @@ static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; pub fn init(vid: & glutin::WindowedContext) { unsafe { CONTEXT = &mut (gl::Context::from_loader_function(|s| { + println!("Loaded {} = {:?}", s, vid.get_proc_address(s)); vid.get_proc_address(s) as *const _ })) as *mut glow::Context; } From 996b598a76f72b76868432bb521aa1b39748735f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 17:25:59 -0800 Subject: [PATCH 080/137] Move test image to main(), it does NOT crash here --- src/main.rs | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4764180b..910a2536 100644 --- a/src/main.rs +++ b/src/main.rs @@ -250,14 +250,50 @@ fn main2() { window.make_current().expect("Could not set current context.") }; - gl::init(&window); - - for i in 0..10 { - println!("\nmain {}", i); - gl::test_image_3d(); - println!("ok {}", i); + unsafe { + use glow as gl; + use glow::HasContext; + let CONTEXT = &mut (gl::Context::from_loader_function(|s| { + println!("Loaded {} = {:?}", s, window.get_proc_address(s)); + window.get_proc_address(s) as *const _ + })) as *mut glow::Context; + + for i in 0..10 { + println!("\nmain {}", i); + + println!("creating texture"); + let t = CONTEXT.as_ref().unwrap().create_texture().unwrap(); + println!("\tt = {}", t); + println!("bind texture"); + CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); + println!("teximage3d\n"); + /* + CONTEXT.as_ref().unwrap().tex_image_3d( + gl::TEXTURE_2D_ARRAY, // target + 0, // level + gl::RGBA as i32, // internal_format + ATLAS_SIZE as i32, + ATLAS_SIZE as i32, + 1, // depth + 0, // border + gl::RGBA, // format + gl::UNSIGNED_BYTE, // ty + None, // pixels + //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels + ); + */ + println!("delete_texture"); + CONTEXT.as_ref().unwrap().delete_texture(t); + + println!("ok {}", i); + } } + println!("done"); + return; + + gl::init(&window); + let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); gl::test_image_3d(); println!("ok"); let mut ui_container = ui::Container::new(); From 39e94f87cdaa992faa60bcebe1c9aa79bf41faca Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 17:27:28 -0800 Subject: [PATCH 081/137] Add tex_image_3d in main, does NOT crash here either --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 910a2536..cacc0baf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -267,7 +267,7 @@ fn main2() { println!("bind texture"); CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); println!("teximage3d\n"); - /* + let ATLAS_SIZE = 1024; CONTEXT.as_ref().unwrap().tex_image_3d( gl::TEXTURE_2D_ARRAY, // target 0, // level @@ -281,7 +281,6 @@ fn main2() { None, // pixels //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); - */ println!("delete_texture"); CONTEXT.as_ref().unwrap().delete_texture(t); From 687e8e240add187348cc21bde3b9506abc6cf645 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 17:36:52 -0800 Subject: [PATCH 082/137] Move to gl_init in main and static mut unsafe, still no crash --- src/main.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index cacc0baf..699f7836 100644 --- a/src/main.rs +++ b/src/main.rs @@ -203,6 +203,19 @@ cfg_if! { } } +use glow::HasContext; +static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; + +fn gl_init(window: & glutin::WindowedContext) { + use glow as gl; + unsafe { + CONTEXT = &mut (gl::Context::from_loader_function(|s| { + println!("Loaded {} = {:?}", s, window.get_proc_address(s)); + window.get_proc_address(s) as *const _ + })) as *mut glow::Context; + } +} + fn main2() { let opt = Opt::from_args(); @@ -251,12 +264,8 @@ fn main2() { }; unsafe { + gl_init(&window); use glow as gl; - use glow::HasContext; - let CONTEXT = &mut (gl::Context::from_loader_function(|s| { - println!("Loaded {} = {:?}", s, window.get_proc_address(s)); - window.get_proc_address(s) as *const _ - })) as *mut glow::Context; for i in 0..10 { println!("\nmain {}", i); From 86a491c1a48a01a91e3db5b949c6c367d737793f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 17:39:07 -0800 Subject: [PATCH 083/137] Revert test in main(), back to crashing --- src/main.rs | 56 ++++++----------------------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/src/main.rs b/src/main.rs index 699f7836..4764180b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -203,19 +203,6 @@ cfg_if! { } } -use glow::HasContext; -static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; - -fn gl_init(window: & glutin::WindowedContext) { - use glow as gl; - unsafe { - CONTEXT = &mut (gl::Context::from_loader_function(|s| { - println!("Loaded {} = {:?}", s, window.get_proc_address(s)); - window.get_proc_address(s) as *const _ - })) as *mut glow::Context; - } -} - fn main2() { let opt = Opt::from_args(); @@ -263,45 +250,14 @@ fn main2() { window.make_current().expect("Could not set current context.") }; - unsafe { - gl_init(&window); - use glow as gl; - - for i in 0..10 { - println!("\nmain {}", i); - - println!("creating texture"); - let t = CONTEXT.as_ref().unwrap().create_texture().unwrap(); - println!("\tt = {}", t); - println!("bind texture"); - CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); - println!("teximage3d\n"); - let ATLAS_SIZE = 1024; - CONTEXT.as_ref().unwrap().tex_image_3d( - gl::TEXTURE_2D_ARRAY, // target - 0, // level - gl::RGBA as i32, // internal_format - ATLAS_SIZE as i32, - ATLAS_SIZE as i32, - 1, // depth - 0, // border - gl::RGBA, // format - gl::UNSIGNED_BYTE, // ty - None, // pixels - //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels - ); - println!("delete_texture"); - CONTEXT.as_ref().unwrap().delete_texture(t); - - println!("ok {}", i); - } - } - - println!("done"); - return; - gl::init(&window); + for i in 0..10 { + println!("\nmain {}", i); + gl::test_image_3d(); + println!("ok {}", i); + } + let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); gl::test_image_3d(); println!("ok"); let mut ui_container = ui::Container::new(); From 4a62b9c119d760a53ee28bc03a32a6cb9bc1ec54 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 17:40:59 -0800 Subject: [PATCH 084/137] Return early, no crash --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 4764180b..4db2eff2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -257,6 +257,8 @@ fn main2() { gl::test_image_3d(); println!("ok {}", i); } + println!("done"); + return; let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); gl::test_image_3d(); println!("ok"); From 023829344e44b69d5515f62b4cd97f128235f0b1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 17:51:20 -0800 Subject: [PATCH 085/137] Revert "Return early, no crash" This reverts commit 4a62b9c119d760a53ee28bc03a32a6cb9bc1ec54. --- src/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4db2eff2..4764180b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -257,8 +257,6 @@ fn main2() { gl::test_image_3d(); println!("ok {}", i); } - println!("done"); - return; let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); gl::test_image_3d(); println!("ok"); From aece114d274b678bb36c608b7ec2cbff3fd514eb Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 17:53:02 -0800 Subject: [PATCH 086/137] Remove loop from main, crashes in main 4 creating texture --- src/main.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4764180b..ca0c7f14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,12 +252,6 @@ fn main2() { gl::init(&window); - for i in 0..10 { - println!("\nmain {}", i); - gl::test_image_3d(); - println!("ok {}", i); - } - let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); gl::test_image_3d(); println!("ok"); let mut ui_container = ui::Container::new(); From 19f6034438930f52b0c4df572948774fa94516b8 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:00:56 -0800 Subject: [PATCH 087/137] Pull render gl calls into main, no crash --- src/main.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ca0c7f14..85d738e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,8 +252,57 @@ fn main2() { gl::init(&window); - let renderer = render::Renderer::new(resource_manager.clone()); + { + println!("\nabout to call 1st tex_image_3d"); + gl::test_image_3d(); + //let version = { res.read().unwrap().version() }; + let tex = gl::Texture::new(); + tex.bind(gl::TEXTURE_2D_ARRAY); + println!("about to call 2nd tex_image_3d"); + gl::test_image_3d(); + /* + tex.image_3d(gl::TEXTURE_2D_ARRAY, + 0, + ATLAS_SIZE as u32, + ATLAS_SIZE as u32, + 1, + gl::RGBA, + gl::UNSIGNED_BYTE, + &[0; ATLAS_SIZE * ATLAS_SIZE * 4]); + */ + println!("returned 2"); + tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); + tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); + tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE); + tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE); + + let mut greg = render::glsl::Registry::new(); + render::shaders::add_shaders(&mut greg); + + gl::enable(gl::DEPTH_TEST); + gl::enable(gl::CULL_FACE_FLAG); + gl::cull_face(gl::BACK); + gl::front_face(gl::CLOCK_WISE); + + /* + // Shaders + let chunk_shader = render::ChunkShader::new(&greg); + let chunk_shader_alpha = render::ChunkShaderAlpha::new(&greg); + let trans_shader = render::TransShader::new(&greg); + */ + + // UI + // Line Drawer + // Clouds + + gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); + gl::depth_func(gl::LESS_OR_EQUAL); + } println!("main 4"); gl::test_image_3d(); println!("ok"); + + return; + let renderer = render::Renderer::new(resource_manager.clone()); + let mut ui_container = ui::Container::new(); let mut last_frame = Instant::now(); From eae25dd37c0e53312172100a8f5709bb32374571 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:02:34 -0800 Subject: [PATCH 088/137] Create shaders in main, no crash --- src/main.rs | 2 -- src/render/shaders.rs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 85d738e0..ea084c21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -284,12 +284,10 @@ fn main2() { gl::cull_face(gl::BACK); gl::front_face(gl::CLOCK_WISE); - /* // Shaders let chunk_shader = render::ChunkShader::new(&greg); let chunk_shader_alpha = render::ChunkShaderAlpha::new(&greg); let trans_shader = render::TransShader::new(&greg); - */ // UI // Line Drawer diff --git a/src/render/shaders.rs b/src/render/shaders.rs index e52ba558..100b01e3 100644 --- a/src/render/shaders.rs +++ b/src/render/shaders.rs @@ -74,7 +74,7 @@ macro_rules! init_shader { } ) => ( #[allow(dead_code)] - struct $name { + pub struct $name { // TODO: remove pub program: gl::Program, $( $field: gl::Attribute, From e6f9df616fc01b382fec27f3fa198a956ef13b1a Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:06:04 -0800 Subject: [PATCH 089/137] Clone resource manager and get version, still no crash --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ea084c21..c97ba199 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,9 +253,13 @@ fn main2() { gl::init(&window); { + let res = resource_manager.clone(); + println!("\nabout to call 1st tex_image_3d"); gl::test_image_3d(); - //let version = { res.read().unwrap().version() }; + let version = { + res.read().unwrap().version() + }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); println!("about to call 2nd tex_image_3d"); From 95b68470ee6999e091229e9334440ce2630a140e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:08:03 -0800 Subject: [PATCH 090/137] Revert to non-main crashing, glGenSamplers bus error 0x0000000101b85000 --- src/main.rs | 51 +-------------------------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/src/main.rs b/src/main.rs index c97ba199..602b7b57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,58 +252,9 @@ fn main2() { gl::init(&window); - { - let res = resource_manager.clone(); - - println!("\nabout to call 1st tex_image_3d"); - gl::test_image_3d(); - let version = { - res.read().unwrap().version() - }; - let tex = gl::Texture::new(); - tex.bind(gl::TEXTURE_2D_ARRAY); - println!("about to call 2nd tex_image_3d"); - gl::test_image_3d(); - /* - tex.image_3d(gl::TEXTURE_2D_ARRAY, - 0, - ATLAS_SIZE as u32, - ATLAS_SIZE as u32, - 1, - gl::RGBA, - gl::UNSIGNED_BYTE, - &[0; ATLAS_SIZE * ATLAS_SIZE * 4]); - */ - println!("returned 2"); - tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); - tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); - tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE); - tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE); - - let mut greg = render::glsl::Registry::new(); - render::shaders::add_shaders(&mut greg); - - gl::enable(gl::DEPTH_TEST); - gl::enable(gl::CULL_FACE_FLAG); - gl::cull_face(gl::BACK); - gl::front_face(gl::CLOCK_WISE); - - // Shaders - let chunk_shader = render::ChunkShader::new(&greg); - let chunk_shader_alpha = render::ChunkShaderAlpha::new(&greg); - let trans_shader = render::TransShader::new(&greg); - - // UI - // Line Drawer - // Clouds - - gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); - gl::depth_func(gl::LESS_OR_EQUAL); - } + let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); gl::test_image_3d(); println!("ok"); - return; - let renderer = render::Renderer::new(resource_manager.clone()); let mut ui_container = ui::Container::new(); From ce9e1e349907fd3450b4d68febb7756639f7ee7d Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:13:42 -0800 Subject: [PATCH 091/137] Remove unnecessary test_image_3d call, GenTextures FnPtr is now overwritten to 0x1f --- src/render/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 63c70979..3886a4e4 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -156,8 +156,6 @@ init_shader! { impl Renderer { pub fn new(res: Arc>) -> Renderer { - println!("\nabout to call 1st tex_image_3d"); - gl::test_image_3d(); let version = { res.read().unwrap().version() }; From f9e5771c6c0bb09da32ebdc34982a0f37acf8d9e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:15:39 -0800 Subject: [PATCH 092/137] Remove 2nd tex_image_3d call, now GenTextures is 0x3e0 --- src/render/mod.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 3886a4e4..e469ee23 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -161,18 +161,6 @@ impl Renderer { }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); - println!("about to call 2nd tex_image_3d"); - gl::test_image_3d(); - /* - tex.image_3d(gl::TEXTURE_2D_ARRAY, - 0, - ATLAS_SIZE as u32, - ATLAS_SIZE as u32, - 1, - gl::RGBA, - gl::UNSIGNED_BYTE, - &[0; ATLAS_SIZE * ATLAS_SIZE * 4]); - */ println!("returned 2"); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); From df71b6d072ad58625613773086bb4a9f80128c54 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:22:26 -0800 Subject: [PATCH 093/137] Use gl/mod.rs wrappers, glGenTextures crash still 0x3e0 --- src/gl/mod.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 7bce93e5..18e0ca44 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -270,10 +270,10 @@ pub fn test_image_3d() { println!("inner tex_image_3d"); unsafe { println!("creating texture"); - let t = CONTEXT.as_ref().unwrap().create_texture().unwrap(); - println!("\tt = {}", t); + let tex = Texture::new(); + println!("\ttex = {:?}", tex.0); println!("bind texture"); - CONTEXT.as_ref().unwrap().bind_texture(gl::TEXTURE_2D_ARRAY, Some(t)); + tex.bind(gl::TEXTURE_2D_ARRAY); println!("teximage3d\n"); /* CONTEXT.as_ref().unwrap().tex_image_3d( @@ -290,8 +290,7 @@ pub fn test_image_3d() { //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels ); */ - println!("delete_texture"); - CONTEXT.as_ref().unwrap().delete_texture(t); + // std::mem::drop(tex) -> delete_texture } println!("returning\n"); } @@ -300,13 +299,15 @@ pub fn test_image_3d() { impl Texture { // Allocates a new texture. pub fn new() -> Texture { - Texture(0) //unsafe { glow_context().create_texture().expect("create texture failed") }) + println!("create_texture"); + Texture(unsafe { glow_context().create_texture().expect("create texture failed") }) } /// Binds the texture to the passed target. pub fn bind(&self, target: TextureTarget) { + println!("bind_texture"); unsafe { - //glow_context().bind_texture(target, Some(self.0)); + glow_context().bind_texture(target, Some(self.0)); } } @@ -503,7 +504,8 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { - //glow_context().delete_texture(self.0); + println!("delete_texture"); + glow_context().delete_texture(self.0); } } } From 3b9425983b49db4ead40178eb948eb864c157b7b Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:23:52 -0800 Subject: [PATCH 094/137] Remove unnecessary bind call, crash GenTextures 0x101d33840 --- src/gl/mod.rs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 18e0ca44..ad1c5821 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -271,26 +271,6 @@ pub fn test_image_3d() { unsafe { println!("creating texture"); let tex = Texture::new(); - println!("\ttex = {:?}", tex.0); - println!("bind texture"); - tex.bind(gl::TEXTURE_2D_ARRAY); - println!("teximage3d\n"); - /* - CONTEXT.as_ref().unwrap().tex_image_3d( - gl::TEXTURE_2D_ARRAY, // target - 0, // level - gl::RGBA as i32, // internal_format - ATLAS_SIZE as i32, - ATLAS_SIZE as i32, - 1, // depth - 0, // border - gl::RGBA, // format - gl::UNSIGNED_BYTE, // ty - None, // pixels - //Some(&[0; ATLAS_SIZE * ATLAS_SIZE * 4]) // pixels - ); - */ - // std::mem::drop(tex) -> delete_texture } println!("returning\n"); } From 0001302db64df9dfd13d53a1d251d1d1a3c49eb6 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:25:40 -0800 Subject: [PATCH 095/137] Remove test_image_3d, to main, crash glGenTextures 0x101e3c4e0 --- src/gl/mod.rs | 11 ----------- src/main.rs | 7 ++++++- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index ad1c5821..263c5995 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -265,17 +265,6 @@ pub const CLAMP_TO_EDGE: TextureValue = gl::CLAMP_TO_EDGE as TextureValue; /// `Texture` is a buffer of data used by fragment shaders. pub struct Texture(u32); -pub fn test_image_3d() { - const ATLAS_SIZE: usize = 1024; - println!("inner tex_image_3d"); - unsafe { - println!("creating texture"); - let tex = Texture::new(); - } - println!("returning\n"); -} - - impl Texture { // Allocates a new texture. pub fn new() -> Texture { diff --git a/src/main.rs b/src/main.rs index 602b7b57..b98d35d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,7 +253,12 @@ fn main2() { gl::init(&window); let renderer = render::Renderer::new(resource_manager.clone()); - println!("main 4"); gl::test_image_3d(); println!("ok"); + println!("main 4"); + unsafe { + println!("creating texture"); + let tex = gl::Texture::new(); + } + println!("ok"); return; let mut ui_container = ui::Container::new(); From a1340511e01ca841821c5f6baa19aefec504b213 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:30:54 -0800 Subject: [PATCH 096/137] Remove setting parameters, same GenSamplers address=0x1030472e0 crash --- src/render/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index e469ee23..547786e5 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -162,10 +162,12 @@ impl Renderer { let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); println!("returned 2"); + /* tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE); + */ let (textures, skin_req, skin_reply) = TextureManager::new(res.clone()); let textures = Arc::new(RwLock::new(textures)); From 3d7486a1cf3c9d5998bb5e4c1884f45024a1ed9a Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:31:49 -0800 Subject: [PATCH 097/137] Remove gl enable face calls, glGenSamplers crash address=0x3e0 --- src/render/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index 547786e5..c399d043 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -176,10 +176,12 @@ impl Renderer { shaders::add_shaders(&mut greg); let ui = ui::UIState::new(&greg, textures.clone(), res.clone()); + /* gl::enable(gl::DEPTH_TEST); gl::enable(gl::CULL_FACE_FLAG); gl::cull_face(gl::BACK); gl::front_face(gl::CLOCK_WISE); + */ // Shaders let chunk_shader = ChunkShader::new(&greg); From 9c17e063a910e5ede6afbe56834bc60e16387fc9 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:35:02 -0800 Subject: [PATCH 098/137] Move creating texture into Renderer new, glGenSampler 0x3e0: --- src/main.rs | 4 ---- src/render/mod.rs | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index b98d35d6..8ffa6dfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -254,10 +254,6 @@ fn main2() { let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); - unsafe { - println!("creating texture"); - let tex = gl::Texture::new(); - } println!("ok"); return; diff --git a/src/render/mod.rs b/src/render/mod.rs index c399d043..2a233445 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -195,6 +195,11 @@ impl Renderer { gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); gl::depth_func(gl::LESS_OR_EQUAL); + unsafe { + println!("creating texture"); + let tex = gl::Texture::new(); + } + Renderer { resource_version: version, model: model::Manager::new(&greg), From af9bbcf674fa80a4c933d21c47833fb6ab074c34 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:35:55 -0800 Subject: [PATCH 099/137] Exit after creating texture before returning renderer construction, no crash --- src/render/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index 2a233445..a7c4ac34 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -199,6 +199,7 @@ impl Renderer { println!("creating texture"); let tex = gl::Texture::new(); } + std::process::exit(0); Renderer { resource_version: version, From e4969ba45c82b969e84b2b71d4d97ec2f5c73c82 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:37:11 -0800 Subject: [PATCH 100/137] Exit in main, glGenTextures EXC_BAD_ACCESS (code=1, address=0xf8) --- src/main.rs | 2 +- src/render/mod.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8ffa6dfc..524d1d07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -255,7 +255,7 @@ fn main2() { let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); println!("ok"); - return; + std::process::exit(0); let mut ui_container = ui::Container::new(); diff --git a/src/render/mod.rs b/src/render/mod.rs index a7c4ac34..2a233445 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -199,7 +199,6 @@ impl Renderer { println!("creating texture"); let tex = gl::Texture::new(); } - std::process::exit(0); Renderer { resource_version: version, From f5f4cf460576f7749efde6d14fffaed2e5ca2a63 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:42:08 -0800 Subject: [PATCH 101/137] Remove reading version, GenTextures address=0x10 --- src/render/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 2a233445..8df22139 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -156,9 +156,7 @@ init_shader! { impl Renderer { pub fn new(res: Arc>) -> Renderer { - let version = { - res.read().unwrap().version() - }; + let version = 0; //{ res.read().unwrap().version() }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); println!("returned 2"); From 59c50cefedd4bc6e9be6eac17e6e65014e99d3ee Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 12 Jan 2020 18:48:47 -0800 Subject: [PATCH 102/137] Remove blend depth func, glGenTextures crash 0x10 --- src/render/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index 8df22139..27438ad3 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -190,8 +190,10 @@ impl Renderer { // Line Drawer // Clouds + /* gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); gl::depth_func(gl::LESS_OR_EQUAL); + */ unsafe { println!("creating texture"); From a62c52d083f178d9308a6da962097f395e7334b4 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sat, 18 Jan 2020 16:13:27 -0800 Subject: [PATCH 103/137] Exit process immediately after 2nd create texture -- no crash --- src/render/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index 27438ad3..387d3a3a 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -199,6 +199,7 @@ impl Renderer { println!("creating texture"); let tex = gl::Texture::new(); } + std::process::exit(0); Renderer { resource_version: version, From 1b6fdd05e73ad7657aefaee8c75e55dddca9e7a9 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sat, 18 Jan 2020 17:32:31 -0800 Subject: [PATCH 104/137] Try reading a line from stdin after 2nd texture creation instead of exiting; crashes reading with glGenTexture = 0xf8 (instead of 0x10) --- src/render/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 387d3a3a..dc2afbd3 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -199,7 +199,8 @@ impl Renderer { println!("creating texture"); let tex = gl::Texture::new(); } - std::process::exit(0); + let mut s = String::new(); + std::io::stdin().read_line(&mut s); Renderer { resource_version: version, From ece0ca67184ed63e9700a690f3e558f7812ac832 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sat, 18 Jan 2020 17:40:07 -0800 Subject: [PATCH 105/137] Try sleeping the thread before exiting; no crash --- src/render/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index dc2afbd3..84bf7780 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -199,8 +199,8 @@ impl Renderer { println!("creating texture"); let tex = gl::Texture::new(); } - let mut s = String::new(); - std::io::stdin().read_line(&mut s); + std::thread::sleep(std::time::Duration::from_millis(1000 * 10)); + std::process::exit(0); Renderer { resource_version: version, From 6f33aa16c17952582e7c4bcd887a7d122afe4aa1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sat, 18 Jan 2020 17:44:57 -0800 Subject: [PATCH 106/137] Log when in process_skins thread --- src/render/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 84bf7780..fba4f947 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -199,8 +199,6 @@ impl Renderer { println!("creating texture"); let tex = gl::Texture::new(); } - std::thread::sleep(std::time::Duration::from_millis(1000 * 10)); - std::process::exit(0); Renderer { resource_version: version, @@ -850,6 +848,7 @@ impl TextureManager { #[cfg(not(target_arch = "wasm32"))] fn process_skins(recv: mpsc::Receiver, reply: mpsc::Sender<(String, Option)>) { + println!("in process_skins thread"); let client = reqwest::blocking::Client::new(); loop { let hash = match recv.recv() { From 0672d3d08bd009e8a20325429e2053e6d84fec22 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sat, 18 Jan 2020 17:46:50 -0800 Subject: [PATCH 107/137] Return early from process_skins, same 0x10 crash --- src/render/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index fba4f947..00af4f22 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -849,6 +849,7 @@ impl TextureManager { #[cfg(not(target_arch = "wasm32"))] fn process_skins(recv: mpsc::Receiver, reply: mpsc::Sender<(String, Option)>) { println!("in process_skins thread"); + return; let client = reqwest::blocking::Client::new(); loop { let hash = match recv.recv() { From 07144f459eede1df2b3e75b0c42232b6bebcaba8 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sat, 18 Jan 2020 17:49:57 -0800 Subject: [PATCH 108/137] Disable the skin thread, now crashes from szone_malloc_should_clear --- src/render/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 00af4f22..011e35d2 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -793,14 +793,14 @@ pub struct TextureManager { skins: HashMap>, - _skin_thread: thread::JoinHandle<()>, + //_skin_thread: thread::JoinHandle<()>, } impl TextureManager { fn new(res: Arc>) -> (TextureManager, mpsc::Sender, mpsc::Receiver<(String, Option)>) { let (tx, rx) = mpsc::channel(); let (stx, srx) = mpsc::channel(); - let skin_thread = thread::spawn(|| Self::process_skins(srx, tx)); + //let skin_thread = thread::spawn(|| Self::process_skins(srx, tx)); let mut tm = TextureManager { textures: HashMap::with_hasher(BuildHasherDefault::default()), version: { @@ -816,7 +816,7 @@ impl TextureManager { free_dynamics: Vec::new(), skins: HashMap::with_hasher(BuildHasherDefault::default()), - _skin_thread: skin_thread, + //_skin_thread: skin_thread, }; tm.add_defaults(); (tm, stx, rx) @@ -849,7 +849,6 @@ impl TextureManager { #[cfg(not(target_arch = "wasm32"))] fn process_skins(recv: mpsc::Receiver, reply: mpsc::Sender<(String, Option)>) { println!("in process_skins thread"); - return; let client = reqwest::blocking::Client::new(); loop { let hash = match recv.recv() { From 84b76e6bfbc16ecec4884c09c7522cad2dea6430 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 21 Jun 2020 13:05:19 -0700 Subject: [PATCH 109/137] cargo fmt --- blocks/src/lib.rs | 600 ++++++---- blocks/src/material.rs | 1 - protocol/src/format.rs | 23 +- protocol/src/item.rs | 5 +- protocol/src/lib.rs | 5 +- protocol/src/macros.rs | 2 - protocol/src/nbt/mod.rs | 6 +- protocol/src/protocol/forge.rs | 47 +- protocol/src/protocol/mod.rs | 230 ++-- protocol/src/protocol/mojang.rs | 95 +- protocol/src/protocol/packet.rs | 158 +-- protocol/src/protocol/versions.rs | 36 +- protocol/src/protocol/versions/v15w39c.rs | 2 - protocol/src/protocol/versions/v18w50a.rs | 2 - protocol/src/protocol/versions/v19w02a.rs | 2 - protocol/src/protocol/versions/v1_10_2.rs | 2 - protocol/src/protocol/versions/v1_11_2.rs | 2 - protocol/src/protocol/versions/v1_12_2.rs | 2 - protocol/src/protocol/versions/v1_13_2.rs | 2 - protocol/src/protocol/versions/v1_14.rs | 2 - protocol/src/protocol/versions/v1_14_1.rs | 2 - protocol/src/protocol/versions/v1_14_2.rs | 2 - protocol/src/protocol/versions/v1_14_3.rs | 2 - protocol/src/protocol/versions/v1_14_4.rs | 2 - protocol/src/protocol/versions/v1_15_1.rs | 2 - protocol/src/protocol/versions/v1_7_10.rs | 2 - protocol/src/protocol/versions/v1_8_9.rs | 2 - protocol/src/protocol/versions/v1_9.rs | 2 - protocol/src/protocol/versions/v1_9_2.rs | 2 - protocol/src/types/bit/map.rs | 2 +- protocol/src/types/bit/mod.rs | 4 +- protocol/src/types/bit/set.rs | 4 +- protocol/src/types/hash.rs | 2 - protocol/src/types/metadata.rs | 97 +- protocol/src/types/mod.rs | 2 +- protocol/src/types/nibble.rs | 7 +- resources/build.rs | 16 +- resources/src/lib.rs | 1 - shared/src/axis.rs | 3 +- shared/src/direction.rs | 11 +- shared/src/lib.rs | 1 - shared/src/position.rs | 9 +- src/chunk_builder.rs | 189 +++- src/console/mod.rs | 93 +- src/ecs/mod.rs | 246 +++-- src/entity/block_entity/mod.rs | 9 +- src/entity/block_entity/sign.rs | 149 ++- src/entity/mod.rs | 29 +- src/entity/player.rs | 421 ++++--- src/entity/systems.rs | 73 +- src/gl/mod.rs | 229 ++-- src/main.rs | 365 +++--- src/model/liquid.rs | 73 +- src/model/mod.rs | 556 ++++++---- src/render/atlas.rs | 20 +- src/render/clouds.rs | 53 +- src/render/glsl.rs | 7 +- src/render/mod.rs | 563 +++++++--- src/render/model.rs | 181 ++- src/render/shaders.rs | 15 +- src/render/ui.rs | 269 +++-- src/resources.rs | 149 ++- src/screen/connecting.rs | 13 +- src/screen/edit_server.rs | 25 +- src/screen/login.rs | 38 +- src/screen/mod.rs | 35 +- src/screen/server_list.rs | 113 +- src/screen/settings_menu.rs | 87 +- src/server/mod.rs | 1230 +++++++++++++++------ src/server/plugin_messages.rs | 2 - src/server/sun.rs | 123 ++- src/server/target.rs | 109 +- src/settings.rs | 64 +- src/ui/logo.rs | 30 +- src/ui/mod.rs | 403 +++++-- src/world/biome.rs | 21 +- src/world/mod.rs | 568 ++++++---- src/world/storage.rs | 10 +- 78 files changed, 5177 insertions(+), 2784 deletions(-) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index 48c8850a..b5bcda84 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -1,11 +1,10 @@ - -#![recursion_limit="600"] +#![recursion_limit = "600"] extern crate steven_shared as shared; use crate::shared::{Axis, Direction, Position}; -use collision::Aabb3; use cgmath::Point3; +use collision::Aabb3; use lazy_static::lazy_static; use std::collections::HashMap; @@ -500,7 +499,7 @@ macro_rules! define_blocks { #[derive(Clone, Copy)] pub enum TintType { Default, - Color{r: u8, g: u8, b: u8}, + Color { r: u8, g: u8, b: u8 }, Grass, Foliage, } @@ -5625,59 +5624,65 @@ define_blocks! { fn can_burn(world: &W, pos: Position) -> bool { match world.get_block(pos) { - Block::Planks{..} | - Block::DoubleWoodenSlab{..} | - Block::WoodenSlab{..} | - Block::FenceGate{..} | - Block::SpruceFenceGate{..} | - Block::BirchFenceGate{..} | - Block::JungleFenceGate{..} | - Block::DarkOakFenceGate{..} | - Block::AcaciaFenceGate{..} | - Block::Fence{..} | - Block::SpruceFence{..} | - Block::BirchFence{..} | - Block::JungleFence{..} | - Block::DarkOakFence{..} | - Block::AcaciaFence{..} | - Block::OakStairs{..} | - Block::BirchStairs{..} | - Block::SpruceStairs{..} | - Block::JungleStairs{..} | - Block::AcaciaStairs{..} | - Block::DarkOakStairs{..} | - Block::Log{..} | - Block::Log2{..} | - Block::Leaves{..} | - Block::Leaves2{..} | - Block::BookShelf{..} | - Block::TNT{..} | - Block::TallGrass{..} | - Block::DoublePlant{..} | - Block::YellowFlower{..} | - Block::RedFlower{..} | - Block::DeadBush{..} | - Block::Wool{..} | - Block::Vine{..} | - Block::CoalBlock{..} | - Block::HayBlock{..} | - Block::Carpet{..} => true, + Block::Planks { .. } + | Block::DoubleWoodenSlab { .. } + | Block::WoodenSlab { .. } + | Block::FenceGate { .. } + | Block::SpruceFenceGate { .. } + | Block::BirchFenceGate { .. } + | Block::JungleFenceGate { .. } + | Block::DarkOakFenceGate { .. } + | Block::AcaciaFenceGate { .. } + | Block::Fence { .. } + | Block::SpruceFence { .. } + | Block::BirchFence { .. } + | Block::JungleFence { .. } + | Block::DarkOakFence { .. } + | Block::AcaciaFence { .. } + | Block::OakStairs { .. } + | Block::BirchStairs { .. } + | Block::SpruceStairs { .. } + | Block::JungleStairs { .. } + | Block::AcaciaStairs { .. } + | Block::DarkOakStairs { .. } + | Block::Log { .. } + | Block::Log2 { .. } + | Block::Leaves { .. } + | Block::Leaves2 { .. } + | Block::BookShelf { .. } + | Block::TNT { .. } + | Block::TallGrass { .. } + | Block::DoublePlant { .. } + | Block::YellowFlower { .. } + | Block::RedFlower { .. } + | Block::DeadBush { .. } + | Block::Wool { .. } + | Block::Vine { .. } + | Block::CoalBlock { .. } + | Block::HayBlock { .. } + | Block::Carpet { .. } => true, _ => false, } } fn is_snowy(world: &W, pos: Position) -> bool { match world.get_block(pos.shift(Direction::Up)) { - Block::Snow{..} | Block::SnowLayer{..} => true, + Block::Snow { .. } | Block::SnowLayer { .. } => true, _ => false, } } -fn can_connect_sides bool, W: WorldAccess>(world: &W, pos: Position, f: &F) -> (bool, bool, bool, bool) { - (can_connect(world, pos.shift(Direction::North), f), - can_connect(world, pos.shift(Direction::South), f), - can_connect(world, pos.shift(Direction::West), f), - can_connect(world, pos.shift(Direction::East), f)) +fn can_connect_sides bool, W: WorldAccess>( + world: &W, + pos: Position, + f: &F, +) -> (bool, bool, bool, bool) { + ( + can_connect(world, pos.shift(Direction::North), f), + can_connect(world, pos.shift(Direction::South), f), + can_connect(world, pos.shift(Direction::West), f), + can_connect(world, pos.shift(Direction::East), f), + ) } fn can_connect bool, W: WorldAccess>(world: &W, pos: Position, f: &F) -> bool { @@ -5687,28 +5692,28 @@ fn can_connect bool, W: WorldAccess>(world: &W, pos: Position, f fn can_connect_fence(block: Block) -> bool { match block { - Block::Fence{..} | - Block::SpruceFence{..} | - Block::BirchFence{..} | - Block::JungleFence{..} | - Block::DarkOakFence{..} | - Block::AcaciaFence{..} | - Block::FenceGate{..} | - Block::SpruceFenceGate{..} | - Block::BirchFenceGate{..} | - Block::JungleFenceGate{..} | - Block::DarkOakFenceGate{..} | - Block::AcaciaFenceGate{..} => true, + Block::Fence { .. } + | Block::SpruceFence { .. } + | Block::BirchFence { .. } + | Block::JungleFence { .. } + | Block::DarkOakFence { .. } + | Block::AcaciaFence { .. } + | Block::FenceGate { .. } + | Block::SpruceFenceGate { .. } + | Block::BirchFenceGate { .. } + | Block::JungleFenceGate { .. } + | Block::DarkOakFenceGate { .. } + | Block::AcaciaFenceGate { .. } => true, _ => false, } } fn can_connect_glasspane(block: Block) -> bool { match block { - Block::Glass{..} | - Block::StainedGlass{..} | - Block::GlassPane{..} | - Block::StainedGlassPane{..} => true, + Block::Glass { .. } + | Block::StainedGlass { .. } + | Block::GlassPane { .. } + | Block::StainedGlassPane { .. } => true, _ => false, } } @@ -5721,7 +5726,11 @@ fn can_connect_redstone(world: &W, pos: Position, dir: Direction let side_up = world.get_block(shift_pos.shift(Direction::Up)); let up = world.get_block(pos.shift(Direction::Up)); - if match side_up { Block::RedstoneWire{..} => true, _ => false,} && !up.get_material().should_cull_against { + if match side_up { + Block::RedstoneWire { .. } => true, + _ => false, + } && !up.get_material().should_cull_against + { return RedstoneSide::Up; } @@ -5729,71 +5738,90 @@ fn can_connect_redstone(world: &W, pos: Position, dir: Direction } let side_down = world.get_block(shift_pos.shift(Direction::Down)); - if match block { Block::RedstoneWire{..} => true, _ => false,} || match side_down { Block::RedstoneWire{..} => true, _ => false,} { + if match block { + Block::RedstoneWire { .. } => true, + _ => false, + } || match side_down { + Block::RedstoneWire { .. } => true, + _ => false, + } { return RedstoneSide::Side; } RedstoneSide::None } fn fence_gate_data(facing: Direction, in_wall: bool, open: bool, powered: bool) -> Option { - if in_wall || powered { return None; } + if in_wall || powered { + return None; + } Some(facing.horizontal_index() | (if open { 0x4 } else { 0x0 })) } fn fence_gate_offset(facing: Direction, in_wall: bool, open: bool, powered: bool) -> Option { - Some(if powered { 0 } else { 1<<0 } + - if open { 0 } else { 1<<1 } + - if in_wall { 0 } else { 1<<2 } + - facing.horizontal_offset() * (1<<3)) + Some( + if powered { 0 } else { 1 << 0 } + + if open { 0 } else { 1 << 1 } + + if in_wall { 0 } else { 1 << 2 } + + facing.horizontal_offset() * (1 << 3), + ) } fn fence_gate_collision(facing: Direction, in_wall: bool, open: bool) -> Vec> { - if open { return vec![]; } + if open { + return vec![]; + } let (min_x, min_y, min_z, max_x, max_y, max_z) = if in_wall { match facing.axis() { - Axis::Z => (0.0, 0.0, 3.0/8.0, 1.0, 13.0/16.0, 5.0/8.0), - Axis::X => (3.0/8.0, 0.0, 0.0, 5.0/8.0, 13.0/16.0, 1.0), + Axis::Z => (0.0, 0.0, 3.0 / 8.0, 1.0, 13.0 / 16.0, 5.0 / 8.0), + Axis::X => (3.0 / 8.0, 0.0, 0.0, 5.0 / 8.0, 13.0 / 16.0, 1.0), _ => unreachable!(), } } else { match facing.axis() { - Axis::Z => (0.0, 0.0, 3.0/8.0, 1.0, 1.0, 5.0/8.0), - Axis::X => (3.0/8.0, 0.0, 0.0, 5.0/8.0, 1.0, 1.0), + Axis::Z => (0.0, 0.0, 3.0 / 8.0, 1.0, 1.0, 5.0 / 8.0), + Axis::X => (3.0 / 8.0, 0.0, 0.0, 5.0 / 8.0, 1.0, 1.0), _ => unreachable!(), } }; vec![Aabb3::new( Point3::new(min_x, min_y, min_z), - Point3::new(max_x, max_y, max_z) + Point3::new(max_x, max_y, max_z), )] } fn fence_gate_update_state(world: &W, pos: Position, facing: Direction) -> bool { - if let Block::CobblestoneWall{..} = world.get_block(pos.shift(facing.clockwise())) { + if let Block::CobblestoneWall { .. } = world.get_block(pos.shift(facing.clockwise())) { return true; } - if let Block::CobblestoneWall{..} = world.get_block(pos.shift(facing.counter_clockwise())) { + if let Block::CobblestoneWall { .. } = world.get_block(pos.shift(facing.counter_clockwise())) { return true; } false } -fn door_data(facing: Direction, half: DoorHalf, hinge: Side, open: bool, powered: bool) -> Option { +fn door_data( + facing: Direction, + half: DoorHalf, + hinge: Side, + open: bool, + powered: bool, +) -> Option { match half { DoorHalf::Upper => { if facing == Direction::North && open { - Some(0x8 - | (if hinge == Side::Right { 0x1 } else { 0x0 }) - | (if powered { 0x2 } else { 0x0 })) + Some( + 0x8 | (if hinge == Side::Right { 0x1 } else { 0x0 }) + | (if powered { 0x2 } else { 0x0 }), + ) } else { None } - }, + } DoorHalf::Lower => { if hinge == Side::Left && !powered { Some(facing.clockwise().horizontal_index() | (if open { 0x4 } else { 0x0 })) @@ -5804,26 +5832,83 @@ fn door_data(facing: Direction, half: DoorHalf, hinge: Side, open: bool, powered } } -fn door_offset(facing: Direction, half: DoorHalf, hinge: Side, open: bool, powered: bool) -> Option { - Some(if powered { 0 } else { 1<<0 } + - if open { 0 } else { 1<<1 } + - if hinge == Side::Left { 0 } else { 1<<2 } + - if half == DoorHalf::Upper { 0 } else { 1<<3 } + - facing.horizontal_offset() * (1<<4)) +fn door_offset( + facing: Direction, + half: DoorHalf, + hinge: Side, + open: bool, + powered: bool, +) -> Option { + Some( + if powered { 0 } else { 1 << 0 } + + if open { 0 } else { 1 << 1 } + + if hinge == Side::Left { 0 } else { 1 << 2 } + + if half == DoorHalf::Upper { 0 } else { 1 << 3 } + + facing.horizontal_offset() * (1 << 4), + ) } - -fn update_door_state(world: &W, pos: Position, ohalf: DoorHalf, ofacing: Direction, ohinge: Side, oopen: bool, opowered: bool) -> (Direction, Side, bool, bool) { +fn update_door_state( + world: &W, + pos: Position, + ohalf: DoorHalf, + ofacing: Direction, + ohinge: Side, + oopen: bool, + opowered: bool, +) -> (Direction, Side, bool, bool) { let oy = if ohalf == DoorHalf::Upper { -1 } else { 1 }; match world.get_block(pos + (0, oy, 0)) { - Block::WoodenDoor{half, facing, hinge, open, powered} | - Block::SpruceDoor{half, facing, hinge, open, powered} | - Block::BirchDoor{half, facing, hinge, open, powered} | - Block::JungleDoor{half, facing, hinge, open, powered} | - Block::AcaciaDoor{half, facing, hinge, open, powered} | - Block::DarkOakDoor{half, facing, hinge, open, powered} | - Block::IronDoor{half, facing, hinge, open, powered} => { + Block::WoodenDoor { + half, + facing, + hinge, + open, + powered, + } + | Block::SpruceDoor { + half, + facing, + hinge, + open, + powered, + } + | Block::BirchDoor { + half, + facing, + hinge, + open, + powered, + } + | Block::JungleDoor { + half, + facing, + hinge, + open, + powered, + } + | Block::AcaciaDoor { + half, + facing, + hinge, + open, + powered, + } + | Block::DarkOakDoor { + half, + facing, + hinge, + open, + powered, + } + | Block::IronDoor { + half, + facing, + hinge, + open, + powered, + } => { if half != ohalf { if ohalf == DoorHalf::Upper { return (facing, ohinge, open, opowered); @@ -5831,8 +5916,8 @@ fn update_door_state(world: &W, pos: Position, ohalf: DoorHalf, return (ofacing, hinge, oopen, powered); } } - }, - _ => {}, + } + _ => {} } (ofacing, ohinge, oopen, opowered) @@ -5842,7 +5927,7 @@ fn door_collision(facing: Direction, hinge: Side, open: bool) -> Vec> use std::f64::consts::PI; let mut bounds = Aabb3::new( Point3::new(0.0, 0.0, 0.0), - Point3::new(1.0, 1.0, 3.0 / 16.0) + Point3::new(1.0, 1.0, 3.0 / 16.0), ); let mut angle = match facing { Direction::South => 0.0, @@ -5851,43 +5936,48 @@ fn door_collision(facing: Direction, hinge: Side, open: bool) -> Vec> Direction::East => PI * 1.5, _ => 0.0, }; - angle += if open { - PI * 0.5 - } else { - 0.0 - } * match hinge { Side::Left => 1.0, Side::Right => -1.0 }; + angle += if open { PI * 0.5 } else { 0.0 } + * match hinge { + Side::Left => 1.0, + Side::Right => -1.0, + }; let c = angle.cos(); let s = angle.sin(); let x = bounds.min.x - 0.5; let z = bounds.min.z - 0.5; - bounds.min.x = 0.5 + (x*c - z*s); - bounds.min.z = 0.5 + (z*c + x*s); + bounds.min.x = 0.5 + (x * c - z * s); + bounds.min.z = 0.5 + (z * c + x * s); let x = bounds.max.x - 0.5; let z = bounds.max.z - 0.5; - bounds.max.x = 0.5 + (x*c - z*s); - bounds.max.z = 0.5 + (z*c + x*s); + bounds.max.x = 0.5 + (x * c - z * s); + bounds.max.z = 0.5 + (z * c + x * s); vec![bounds] } fn update_repeater_state(world: &W, pos: Position, facing: Direction) -> bool { - let f = |dir| { - match world.get_block(pos.shift(dir)) { - Block::RepeaterPowered{..} => true, - _ => false, - } + let f = |dir| match world.get_block(pos.shift(dir)) { + Block::RepeaterPowered { .. } => true, + _ => false, }; f(facing.clockwise()) || f(facing.counter_clockwise()) } -fn update_double_plant_state(world: &W, pos: Position, ohalf: BlockHalf, ovariant: DoublePlantVariant) -> (BlockHalf, DoublePlantVariant) { - if ohalf != BlockHalf::Upper { return (ohalf, ovariant); } +fn update_double_plant_state( + world: &W, + pos: Position, + ohalf: BlockHalf, + ovariant: DoublePlantVariant, +) -> (BlockHalf, DoublePlantVariant) { + if ohalf != BlockHalf::Upper { + return (ohalf, ovariant); + } match world.get_block(pos.shift(Direction::Down)) { - Block::DoublePlant{variant, ..} => (ohalf, variant), + Block::DoublePlant { variant, .. } => (ohalf, variant), _ => (ohalf, ovariant), } } @@ -5909,65 +5999,65 @@ fn piston_collision(extended: bool, facing: Direction) -> Vec> { vec![Aabb3::new( Point3::new(min_x, min_y, min_z), - Point3::new(max_x, max_y, max_z) + Point3::new(max_x, max_y, max_z), )] } fn trapdoor_collision(facing: Direction, half: BlockHalf, open: bool) -> Vec> { let (min_x, min_y, min_z, max_x, max_y, max_z) = if open { match facing { - Direction::North => (0.0, 0.0, 3.0/16.0, 1.0, 1.0, 1.0), - Direction::South => (0.0, 0.0, 0.0, 1.0, 1.0, 3.0/16.0), - Direction::West => (3.0/16.0, 0.0, 0.0, 1.0, 1.0, 1.0), - Direction::East => (0.0, 0.0, 0.0, 3.0/16.0, 1.0, 1.0), + Direction::North => (0.0, 0.0, 3.0 / 16.0, 1.0, 1.0, 1.0), + Direction::South => (0.0, 0.0, 0.0, 1.0, 1.0, 3.0 / 16.0), + Direction::West => (3.0 / 16.0, 0.0, 0.0, 1.0, 1.0, 1.0), + Direction::East => (0.0, 0.0, 0.0, 3.0 / 16.0, 1.0, 1.0), _ => unreachable!(), } } else { match half { - BlockHalf::Bottom => (0.0, 0.0, 0.0, 1.0, 3.0/16.0, 1.0), - BlockHalf::Top => (0.0, 3.0/16.0, 0.0, 1.0, 1.0, 1.0), + BlockHalf::Bottom => (0.0, 0.0, 0.0, 1.0, 3.0 / 16.0, 1.0), + BlockHalf::Top => (0.0, 3.0 / 16.0, 0.0, 1.0, 1.0, 1.0), _ => unreachable!(), } }; vec![Aabb3::new( Point3::new(min_x, min_y, min_z), - Point3::new(max_x, max_y, max_z)) - ] + Point3::new(max_x, max_y, max_z), + )] } fn fence_collision(north: bool, south: bool, west: bool, east: bool) -> Vec> { let mut collision = vec![Aabb3::new( - Point3::new(3.0/8.0, 0.0, 3.0/8.0), - Point3::new(5.0/8.0, 1.5, 5.0/8.0)) - ]; + Point3::new(3.0 / 8.0, 0.0, 3.0 / 8.0), + Point3::new(5.0 / 8.0, 1.5, 5.0 / 8.0), + )]; if north { collision.push(Aabb3::new( - Point3::new(3.0/8.0, 0.0, 0.0), - Point3::new(5.0/8.0, 1.5, 3.0/8.0)) - ); + Point3::new(3.0 / 8.0, 0.0, 0.0), + Point3::new(5.0 / 8.0, 1.5, 3.0 / 8.0), + )); } if south { collision.push(Aabb3::new( - Point3::new(3.0/8.0, 0.0, 5.0/8.0), - Point3::new(5.0/8.0, 1.5, 1.0)) - ); + Point3::new(3.0 / 8.0, 0.0, 5.0 / 8.0), + Point3::new(5.0 / 8.0, 1.5, 1.0), + )); } if west { collision.push(Aabb3::new( - Point3::new(0.0, 0.0, 3.0/8.0), - Point3::new(3.0/8.0, 1.5, 5.0/8.0)) - ); + Point3::new(0.0, 0.0, 3.0 / 8.0), + Point3::new(3.0 / 8.0, 1.5, 5.0 / 8.0), + )); } if east { collision.push(Aabb3::new( - Point3::new(5.0/8.0, 0.0, 3.0/8.0), - Point3::new(1.0, 1.5, 5.0/8.0)) - ); + Point3::new(5.0 / 8.0, 0.0, 3.0 / 8.0), + Point3::new(1.0, 1.5, 5.0 / 8.0), + )); } collision @@ -5975,36 +6065,36 @@ fn fence_collision(north: bool, south: bool, west: bool, east: bool) -> Vec Vec> { let mut collision = vec![Aabb3::new( - Point3::new(7.0/16.0, 0.0, 7.0/16.0), - Point3::new(9.0/16.0, 1.0, 9.0/16.0)) - ]; + Point3::new(7.0 / 16.0, 0.0, 7.0 / 16.0), + Point3::new(9.0 / 16.0, 1.0, 9.0 / 16.0), + )]; if north { collision.push(Aabb3::new( - Point3::new(7.0/16.0, 0.0, 0.0), - Point3::new(9.0/16.0, 1.0, 9.0/16.0)) - ); + Point3::new(7.0 / 16.0, 0.0, 0.0), + Point3::new(9.0 / 16.0, 1.0, 9.0 / 16.0), + )); } if south { collision.push(Aabb3::new( - Point3::new(7.0/16.0, 0.0, 7.0/16.0), - Point3::new(9.0/16.0, 1.0, 1.0)) - ); + Point3::new(7.0 / 16.0, 0.0, 7.0 / 16.0), + Point3::new(9.0 / 16.0, 1.0, 1.0), + )); } if west { collision.push(Aabb3::new( - Point3::new(0.0, 0.0, 7.0/16.0), - Point3::new(9.0/16.0, 1.0, 9.0/16.0)) - ); + Point3::new(0.0, 0.0, 7.0 / 16.0), + Point3::new(9.0 / 16.0, 1.0, 9.0 / 16.0), + )); } if east { collision.push(Aabb3::new( - Point3::new(7.0/16.0, 0.0, 7.0/16.0), - Point3::new(1.0, 1.0, 9.0/16.0)) - ); + Point3::new(7.0 / 16.0, 0.0, 7.0 / 16.0), + Point3::new(1.0, 1.0, 9.0 / 16.0), + )); } collision @@ -6012,20 +6102,20 @@ fn pane_collision(north: bool, south: bool, east: bool, west: bool) -> Vec(world: &W, pos: Position) -> Option<(Direction, BlockHalf)> { match world.get_block(pos) { - Block::OakStairs{facing, half, ..} | - Block::StoneStairs{facing, half, ..} | - Block::BrickStairs{facing, half, ..} | - Block::StoneBrickStairs{facing, half, ..} | - Block::NetherBrickStairs{facing, half, ..} | - Block::SandstoneStairs{facing, half, ..} | - Block::SpruceStairs{facing, half, ..} | - Block::BirchStairs{facing, half, ..} | - Block::JungleStairs{facing, half, ..} | - Block::QuartzStairs{facing, half, ..} | - Block::AcaciaStairs{facing, half, ..} | - Block::DarkOakStairs{facing, half, ..} | - Block::RedSandstoneStairs{facing, half, ..} | - Block::PurpurStairs{facing, half, ..} => Some((facing, half)), + Block::OakStairs { facing, half, .. } + | Block::StoneStairs { facing, half, .. } + | Block::BrickStairs { facing, half, .. } + | Block::StoneBrickStairs { facing, half, .. } + | Block::NetherBrickStairs { facing, half, .. } + | Block::SandstoneStairs { facing, half, .. } + | Block::SpruceStairs { facing, half, .. } + | Block::BirchStairs { facing, half, .. } + | Block::JungleStairs { facing, half, .. } + | Block::QuartzStairs { facing, half, .. } + | Block::AcaciaStairs { facing, half, .. } + | Block::DarkOakStairs { facing, half, .. } + | Block::RedSandstoneStairs { facing, half, .. } + | Block::PurpurStairs { facing, half, .. } => Some((facing, half)), _ => None, } } @@ -6054,18 +6144,34 @@ fn update_stair_shape(world: &W, pos: Position, facing: Directio StairShape::Straight } -fn stair_data(facing: Direction, half: BlockHalf, shape: StairShape, waterlogged: bool) -> Option { - if shape != StairShape::Straight { return None; } - if waterlogged { return None; } +fn stair_data( + facing: Direction, + half: BlockHalf, + shape: StairShape, + waterlogged: bool, +) -> Option { + if shape != StairShape::Straight { + return None; + } + if waterlogged { + return None; + } Some((5 - facing.index()) | (if half == BlockHalf::Top { 0x4 } else { 0x0 })) } -fn stair_offset(facing: Direction, half: BlockHalf, shape: StairShape, waterlogged: bool) -> Option { - Some(if waterlogged { 0 } else { 1 } + - shape.offset() * 2 + - if half == BlockHalf::Top { 0 } else { 2 * 5 } + - facing.horizontal_offset() * 2 * 5 * 2) +fn stair_offset( + facing: Direction, + half: BlockHalf, + shape: StairShape, + waterlogged: bool, +) -> Option { + Some( + if waterlogged { 0 } else { 1 } + + shape.offset() * 2 + + if half == BlockHalf::Top { 0 } else { 2 * 5 } + + facing.horizontal_offset() * 2 * 5 * 2, + ) } #[allow(clippy::many_single_char_names)] @@ -6113,24 +6219,24 @@ fn stair_collision(facing: Direction, shape: StairShape, half: BlockHalf) -> Vec for bound in &mut bounds { let x = bound.min.x - 0.5; let z = bound.min.z - 0.5; - bound.min.x = 0.5 + (x*c - z*s); - bound.min.z = 0.5 + (z*c + x*s); + bound.min.x = 0.5 + (x * c - z * s); + bound.min.z = 0.5 + (z * c + x * s); let x = bound.max.x - 0.5; let z = bound.max.z - 0.5; - bound.max.x = 0.5 + (x*c - z*s); - bound.max.z = 0.5 + (z*c + x*s); + bound.max.x = 0.5 + (x * c - z * s); + bound.max.z = 0.5 + (z * c + x * s); if half == BlockHalf::Top { let c = PI.cos(); let s = PI.sin(); let z = bound.min.z - 0.5; let y = bound.min.y - 0.5; - bound.min.z = 0.5 + (z*c - y*s); - bound.min.y = 0.5 + (y*c + z*s); + bound.min.z = 0.5 + (z * c - y * s); + bound.min.y = 0.5 + (y * c + z * s); let z = bound.max.z - 0.5; let y = bound.max.y - 0.5; - bound.max.z = 0.5 + (z*c - y*s); - bound.max.y = 0.5 + (y*c + z*s); + bound.max.z = 0.5 + (z * c - y * s); + bound.max.y = 0.5 + (y * c + z * s); bound.min.x = 1.0 - bound.min.x; bound.max.x = 1.0 - bound.max.x; @@ -6150,7 +6256,7 @@ fn slab_collision(half: BlockHalf) -> Vec> { vec![Aabb3::new( Point3::new(min_x, min_y, min_z), - Point3::new(max_x, max_y, max_z) + Point3::new(max_x, max_y, max_z), )] } @@ -6218,7 +6324,7 @@ impl DirtVariant { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum BedPart { Head, - Foot + Foot, } impl BedPart { @@ -6301,7 +6407,6 @@ impl NoteBlockInstrument { } } - #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum RedSandstoneVariant { Normal, @@ -6382,67 +6487,91 @@ impl PrismarineVariant { } } -fn mushroom_block_data(is_stem: bool, west: bool, up: bool, south: bool, north: bool, east: bool, down: bool) -> Option { - Some(match - (is_stem, west, up, south, north, east, down) { +fn mushroom_block_data( + is_stem: bool, + west: bool, + up: bool, + south: bool, + north: bool, + east: bool, + down: bool, +) -> Option { + Some(match (is_stem, west, up, south, north, east, down) { (false, false, false, false, false, false, false) => 0, - (false, true, false, false, true, false, false) => 1, - (false, false, false, false, true, false, false) => 2, - (false, false, false, false, true, true, false) => 3, - (false, true, false, false, false, false, false) => 4, - (false, false, true, false, false, false, false) => 5, - (false, false, false, false, false, true, false) => 6, - (false, true, false, true, false, false, false) => 7, - (false, false, false, true, false, false, false) => 8, - (false, false, false, true, false, true, false) => 9, - (false, true, false, true, true, true, false) => 10, - (false, true, true, true, true, true, true) => 14, - (true, false, false, false, false, false, false) => 15, + (false, true, false, false, true, false, false) => 1, + (false, false, false, false, true, false, false) => 2, + (false, false, false, false, true, true, false) => 3, + (false, true, false, false, false, false, false) => 4, + (false, false, true, false, false, false, false) => 5, + (false, false, false, false, false, true, false) => 6, + (false, true, false, true, false, false, false) => 7, + (false, false, false, true, false, false, false) => 8, + (false, false, false, true, false, true, false) => 9, + (false, true, false, true, true, true, false) => 10, + (false, true, true, true, true, true, true) => 14, + (true, false, false, false, false, false, false) => 15, _ => return None, }) } -fn mushroom_block_offset(is_stem: bool, west: bool, up: bool, south: bool, north: bool, east: bool, down: bool) -> Option { +fn mushroom_block_offset( + is_stem: bool, + west: bool, + up: bool, + south: bool, + north: bool, + east: bool, + down: bool, +) -> Option { if is_stem { None } else { - Some(if west { 0 } else { 1<<0 } + - if up { 0 } else { 1<<1 } + - if south { 0 } else { 1<<2 } + - if north { 0 } else { 1<<3 } + - if east { 0 } else { 1<<4 } + - if down { 0 } else { 1<<5 }) + Some( + if west { 0 } else { 1 << 0 } + + if up { 0 } else { 1 << 1 } + + if south { 0 } else { 1 << 2 } + + if north { 0 } else { 1 << 3 } + + if east { 0 } else { 1 << 4 } + + if down { 0 } else { 1 << 5 }, + ) } } - -fn mushroom_block_variant(is_stem: bool, west: bool, up: bool, south: bool, north: bool, east: bool, down: bool) -> String { +fn mushroom_block_variant( + is_stem: bool, + west: bool, + up: bool, + south: bool, + north: bool, + east: bool, + down: bool, +) -> String { (if is_stem { "all_stem" } else { - match - (west, up, south, north, east, down) { + match (west, up, south, north, east, down) { (false, false, false, false, false, false) => "all_inside", - (true, false, false, true, false, false) => "north_west", - (false, false, false, true, false, false) => "north", - (false, false, false, true, true, false) => "north_east", - (true, false, false, false, false, false) => "west", - (false, true, false, false, false, false) => "center", - (false, false, false, false, true, false) => "east", - (true, false, true, false, false, false) => "south_west", - (false, false, true, false, false, false) => "south", - (false, false, true, false, true, false) => "south_east", - (true, false, true, true, true, false) => "stem", - (true, true, true, true, true, true) => "all_outside", + (true, false, false, true, false, false) => "north_west", + (false, false, false, true, false, false) => "north", + (false, false, false, true, true, false) => "north_east", + (true, false, false, false, false, false) => "west", + (false, true, false, false, false, false) => "center", + (false, false, false, false, true, false) => "east", + (true, false, true, false, false, false) => "south_west", + (false, false, true, false, false, false) => "south", + (false, false, true, false, true, false) => "south_east", + (true, false, true, true, true, false) => "stem", + (true, true, true, true, true, true) => "all_outside", _ => "all_stem", } - }).to_string() + }) + .to_string() } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum DoorHalf { Upper, - Lower + Lower, } impl DoorHalf { @@ -6771,9 +6900,9 @@ impl StoneSlabVariant { fn data(self) -> usize { match self { - StoneSlabVariant::Stone | - StoneSlabVariant::RedSandstone | - StoneSlabVariant::Purpur => 0, + StoneSlabVariant::Stone | StoneSlabVariant::RedSandstone | StoneSlabVariant::Purpur => { + 0 + } StoneSlabVariant::Sandstone => 1, StoneSlabVariant::PetrifiedWood => 2, StoneSlabVariant::Cobblestone => 3, @@ -7037,7 +7166,8 @@ impl AttachedFace { (AttachedFace::Floor, Direction::East) => "up_x", (AttachedFace::Ceiling, Direction::South) => "down_z", _ => "north", // TODO: support 1.13.2+ new directions - }.to_owned() + } + .to_owned() } } @@ -7094,7 +7224,6 @@ impl StructureBlockMode { } } - #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum TreeVariant { Oak, @@ -7125,7 +7254,7 @@ impl TreeVariant { TreeVariant::StrippedJungle => "stripped_jungle_log", TreeVariant::StrippedAcacia => "stripped_acacia_log", TreeVariant::StrippedDarkOak => "stripped_dark_oak_log", - TreeVariant::StrippedOak => "stripped_oak_log" + TreeVariant::StrippedOak => "stripped_oak_log", } } @@ -7388,4 +7517,3 @@ impl CoralVariant { } } } - diff --git a/blocks/src/material.rs b/blocks/src/material.rs index a809bab2..b91e6ee4 100644 --- a/blocks/src/material.rs +++ b/blocks/src/material.rs @@ -1,4 +1,3 @@ - pub struct Material { pub renderable: bool, pub should_cull_against: bool, diff --git a/protocol/src/format.rs b/protocol/src/format.rs index 29776bd7..aed20803 100644 --- a/protocol/src/format.rs +++ b/protocol/src/format.rs @@ -22,7 +22,6 @@ pub enum Component { } impl Component { - pub fn from_string(str: &str) -> Self { let mut component; match serde_json::from_str::(str) { @@ -31,7 +30,7 @@ impl Component { Err(_) => { component = Component::Text(TextComponent::new(str)); convert_legacy(&mut component); - }, + } } component } @@ -47,7 +46,9 @@ impl Component { Component::Text(TextComponent::from_value(v, modifier)) } else if v.get("translate").is_some() { // TODO: translations - Component::Text(TextComponent::new(v.get("translate").unwrap().as_str().unwrap())) + Component::Text(TextComponent::new( + v.get("translate").unwrap().as_str().unwrap(), + )) } else { modifier.color = Some(Color::RGB(255, 0, 0)); Component::Text(TextComponent { @@ -100,9 +101,10 @@ impl Modifier { underlined: v.get("underlined").map_or(Option::None, |v| v.as_bool()), strikethrough: v.get("strikethrough").map_or(Option::None, |v| v.as_bool()), obfuscated: v.get("obfuscated").map_or(Option::None, |v| v.as_bool()), - color: v.get("color") - .map_or(Option::None, |v| v.as_str()) - .map(|v| Color::from_string(&v.to_owned())), + color: v + .get("color") + .map_or(Option::None, |v| v.as_str()) + .map(|v| Color::from_string(&v.to_owned())), extra: Option::None, }; if let Some(extra) = v.get("extra") { @@ -132,7 +134,9 @@ impl TextComponent { pub fn new(val: &str) -> TextComponent { TextComponent { text: val.to_owned(), - modifier: Modifier { ..Default::default() }, + modifier: Modifier { + ..Default::default() + }, } } @@ -319,8 +323,9 @@ pub fn convert_legacy(c: &mut Component) { current.text = txt.text[last..i].to_owned(); last = next.0 + 1; - let mut modifier = if (color_char >= 'a' && color_char <= 'f') || - (color_char >= '0' && color_char <= '9') { + let mut modifier = if (color_char >= 'a' && color_char <= 'f') + || (color_char >= '0' && color_char <= '9') + { Default::default() } else { current.modifier.clone() diff --git a/protocol/src/item.rs b/protocol/src/item.rs index 8aa6ab42..7d797edd 100644 --- a/protocol/src/item.rs +++ b/protocol/src/item.rs @@ -14,8 +14,8 @@ use crate::nbt; use crate::protocol::{self, Serializable}; +use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use std::io; -use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt}; #[derive(Debug)] pub struct Stack { @@ -25,7 +25,6 @@ pub struct Stack { tag: Option, } - impl Default for Stack { fn default() -> Stack { Stack { @@ -44,7 +43,7 @@ impl Serializable for Option { if protocol_version >= 404 { let present = buf.read_u8()? != 0; if !present { - return Ok(None) + return Ok(None); } } diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index fe136ebf..d29b9d1c 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -1,10 +1,9 @@ - -#![recursion_limit="300"] +#![recursion_limit = "300"] #[macro_use] pub mod macros; -pub mod item; pub mod format; +pub mod item; pub mod nbt; pub mod protocol; pub mod types; diff --git a/protocol/src/macros.rs b/protocol/src/macros.rs index bf2b7a2c..3c9b47bb 100644 --- a/protocol/src/macros.rs +++ b/protocol/src/macros.rs @@ -1,5 +1,3 @@ - - #[doc(hidden)] #[macro_export] macro_rules! create_ids { diff --git a/protocol/src/nbt/mod.rs b/protocol/src/nbt/mod.rs index 37c3eca0..72fce8be 100644 --- a/protocol/src/nbt/mod.rs +++ b/protocol/src/nbt/mod.rs @@ -16,9 +16,9 @@ use std::collections::HashMap; use std::io; use std::io::Read; -use super::protocol::Serializable; use super::protocol; -use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt}; +use super::protocol::Serializable; +use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; #[derive(Debug, Clone)] pub enum Tag { @@ -41,7 +41,6 @@ pub enum Tag { pub struct NamedTag(pub String, pub Tag); impl Tag { - pub fn new_compound() -> Tag { Tag::Compound(HashMap::new()) } @@ -163,7 +162,6 @@ impl Tag { } } - fn internal_id(&self) -> u8 { match *self { Tag::End => 0, diff --git a/protocol/src/protocol/forge.rs b/protocol/src/protocol/forge.rs index c3096e1a..f9526e47 100644 --- a/protocol/src/protocol/forge.rs +++ b/protocol/src/protocol/forge.rs @@ -1,10 +1,9 @@ - -/// Implements https://wiki.vg/Minecraft_Forge_Handshake -use std::io; use byteorder::WriteBytesExt; use log::debug; +/// Implements https://wiki.vg/Minecraft_Forge_Handshake +use std::io; -use super::{Serializable, Error, LenPrefixed, VarInt}; +use super::{Error, LenPrefixed, Serializable, VarInt}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Phase { @@ -45,7 +44,6 @@ impl Serializable for Phase { } } - #[derive(Clone, Debug, Default)] pub struct ForgeMod { pub modid: String, @@ -133,19 +131,20 @@ impl Serializable for FmlHs { None }; - debug!("FML|HS ServerHello: fml_protocol_version={}, override_dimension={:?}", fml_protocol_version, override_dimension); + debug!( + "FML|HS ServerHello: fml_protocol_version={}, override_dimension={:?}", + fml_protocol_version, override_dimension + ); Ok(FmlHs::ServerHello { fml_protocol_version, override_dimension, }) - }, + } 1 => panic!("Received unexpected FML|HS ClientHello from server"), - 2 => { - Ok(FmlHs::ModList { - mods: Serializable::read_from(buf)?, - }) - }, + 2 => Ok(FmlHs::ModList { + mods: Serializable::read_from(buf)?, + }), 3 => { let protocol_version = super::current_protocol_version(); @@ -161,34 +160,34 @@ impl Serializable for FmlHs { Ok(FmlHs::ModIdData { mappings: Serializable::read_from(buf)?, block_substitutions: Serializable::read_from(buf)?, - item_substitutions: Serializable::read_from(buf)?, + item_substitutions: Serializable::read_from(buf)?, }) } - }, - 255 => { - Ok(FmlHs::HandshakeAck { - phase: Serializable::read_from(buf)?, - }) - }, + } + 255 => Ok(FmlHs::HandshakeAck { + phase: Serializable::read_from(buf)?, + }), _ => panic!("Unhandled FML|HS packet: discriminator={}", discriminator), } } fn write_to(&self, buf: &mut W) -> Result<(), Error> { match self { - FmlHs::ClientHello { fml_protocol_version } => { + FmlHs::ClientHello { + fml_protocol_version, + } => { buf.write_u8(1)?; fml_protocol_version.write_to(buf) - }, + } FmlHs::ModList { mods } => { buf.write_u8(2)?; mods.write_to(buf) - }, + } FmlHs::HandshakeAck { phase } => { buf.write_u8(255)?; phase.write_to(buf) - }, - _ => unimplemented!() + } + _ => unimplemented!(), } } } diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 13be61a5..6b1184c4 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -16,34 +16,36 @@ #![allow(non_camel_case_types)] use aes::Aes128; -use cfb8::Cfb8; use cfb8::stream_cipher::{NewStreamCipher, StreamCipher}; -use serde_json; -use std_or_web::fs; +use cfb8::Cfb8; +use hex; #[cfg(not(target_arch = "wasm32"))] use reqwest; -use hex; +use serde_json; +use std_or_web::fs; -pub mod mojang; pub mod forge; +pub mod mojang; -use crate::nbt; use crate::format; -use std::fmt; -use std::default; -use std::net::TcpStream; -use std::io; -use std::io::{Write, Read}; -use std::convert; -use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; -use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt}; +use crate::nbt; +use crate::shared::Position; +use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use flate2::read::{ZlibDecoder, ZlibEncoder}; use flate2::Compression; -use std::time::{Instant, Duration}; -use crate::shared::Position; use log::debug; +use std::convert; +use std::default; +use std::fmt; +use std::io; +use std::io::{Read, Write}; +use std::net::TcpStream; +use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; +use std::time::{Duration, Instant}; -pub const SUPPORTED_PROTOCOLS: [i32; 18] = [575, 498, 490, 485, 480, 477, 452, 451, 404, 340, 316, 315, 210, 109, 107, 74, 47, 5]; +pub const SUPPORTED_PROTOCOLS: [i32; 18] = [ + 575, 498, 490, 485, 480, 477, 452, 451, 404, 340, 316, 315, 210, 109, 107, 74, 47, 5, +]; static CURRENT_PROTOCOL_VERSION: AtomicI32 = AtomicI32::new(SUPPORTED_PROTOCOLS[0]); static NETWORK_DEBUG: AtomicBool = AtomicBool::new(false); @@ -233,7 +235,7 @@ impl Serializable for Vec { } } -impl Serializable for Option{ +impl Serializable for Option { fn read_from(buf: &mut R) -> Result, Error> { let ty = buf.read_u8()?; if ty == 0 { @@ -257,7 +259,10 @@ impl Serializable for Option{ } } -impl Serializable for Option where T : Serializable { +impl Serializable for Option +where + T: Serializable, +{ fn read_from(buf: &mut R) -> Result, Error> { Result::Ok(Some(T::read_from(buf)?)) } @@ -318,11 +323,7 @@ impl Serializable for bool { Result::Ok(buf.read_u8()? != 0) } fn write_to(&self, buf: &mut W) -> Result<(), Error> { - buf.write_u8(if *self { - 1 - } else { - 0 - })?; + buf.write_u8(if *self { 1 } else { 0 })?; Result::Ok(()) } } @@ -433,9 +434,9 @@ impl UUID { parts.extend_from_slice(&hex::decode(&s[24..36]).unwrap()); let mut high = 0u64; let mut low = 0u64; - for i in 0 .. 8 { - high |= (parts[i] as u64) << (56 - i*8); - low |= (parts[i + 8] as u64) << (56 - i*8); + for i in 0..8 { + high |= (parts[i] as u64) << (56 - i * 8); + low |= (parts[i + 8] as u64) << (56 - i * 8); } UUID(high, low) } @@ -449,8 +450,10 @@ impl Default for UUID { impl Serializable for UUID { fn read_from(buf: &mut R) -> Result { - Result::Ok(UUID(buf.read_u64::()?, - buf.read_u64::()?)) + Result::Ok(UUID( + buf.read_u64::()?, + buf.read_u64::()?, + )) } fn write_to(&self, buf: &mut W) -> Result<(), Error> { buf.write_u64::(self.0)?; @@ -496,8 +499,7 @@ impl Serializable for Biomes3D { } } - -pub trait Lengthable : Serializable + Copy + Default { +pub trait Lengthable: Serializable + Copy + Default { fn into_len(self) -> usize; fn from_len(_: usize) -> Self; } @@ -507,7 +509,7 @@ pub struct LenPrefixed { pub data: Vec, } -impl LenPrefixed { +impl LenPrefixed { pub fn new(data: Vec) -> LenPrefixed { LenPrefixed { len: Default::default(), @@ -516,7 +518,7 @@ impl LenPrefixed { } } -impl Serializable for LenPrefixed { +impl Serializable for LenPrefixed { fn read_from(buf: &mut R) -> Result, Error> { let len_data: L = Serializable::read_from(buf)?; let len: usize = len_data.into_len(); @@ -541,8 +543,7 @@ impl Serializable for LenPrefixed { } } - -impl Default for LenPrefixed { +impl Default for LenPrefixed { fn default() -> Self { LenPrefixed { len: default::Default::default(), @@ -551,7 +552,7 @@ impl Default for LenPrefixed { } } -impl fmt::Debug for LenPrefixed { +impl fmt::Debug for LenPrefixed { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.data.fmt(f) } @@ -563,7 +564,7 @@ pub struct LenPrefixedBytes { pub data: Vec, } -impl LenPrefixedBytes { +impl LenPrefixedBytes { pub fn new(data: Vec) -> LenPrefixedBytes { LenPrefixedBytes { len: Default::default(), @@ -572,7 +573,7 @@ impl LenPrefixedBytes { } } -impl Serializable for LenPrefixedBytes { +impl Serializable for LenPrefixedBytes { fn read_from(buf: &mut R) -> Result, Error> { let len_data: L = Serializable::read_from(buf)?; let len: usize = len_data.into_len(); @@ -592,8 +593,7 @@ impl Serializable for LenPrefixedBytes { } } - -impl Default for LenPrefixedBytes { +impl Default for LenPrefixedBytes { fn default() -> Self { LenPrefixedBytes { len: default::Default::default(), @@ -602,7 +602,7 @@ impl Default for LenPrefixedBytes { } } -impl fmt::Debug for LenPrefixedBytes { +impl fmt::Debug for LenPrefixedBytes { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.data.fmt(f) } @@ -610,7 +610,11 @@ impl fmt::Debug for LenPrefixedBytes { impl Lengthable for bool { fn into_len(self) -> usize { - if self { 1 } else { 0 } + if self { + 1 + } else { + 0 + } } fn from_len(u: usize) -> bool { @@ -618,7 +622,6 @@ impl Lengthable for bool { } } - impl Lengthable for u8 { fn into_len(self) -> usize { self as usize @@ -685,7 +688,12 @@ impl convert::From> for f64 { } } -impl fmt::Debug for FixedPoint5 where T: fmt::Display, f64: convert::From, T: NumCast + Copy { +impl fmt::Debug for FixedPoint5 +where + T: fmt::Display, + f64: convert::From, + T: NumCast + Copy, +{ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let x: f64 = (*self).into(); write!(f, "FixedPoint5(#{} = {}f)", self.0, x) @@ -726,7 +734,12 @@ impl convert::From> for f64 { } } -impl fmt::Debug for FixedPoint12 where T: fmt::Display, f64: convert::From, T: NumCast + Copy { +impl fmt::Debug for FixedPoint12 +where + T: fmt::Display, + f64: convert::From, + T: NumCast + Copy, +{ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let x: f64 = (*self).into(); write!(f, "FixedPoint12(#{} = {}f)", self.0, x) @@ -751,7 +764,7 @@ impl Lengthable for VarInt { impl Serializable for VarInt { /// Decodes a `VarInt` from the Reader fn read_from(buf: &mut R) -> Result { - const PART : u32 = 0x7F; + const PART: u32 = 0x7F; let mut size = 0; let mut val = 0u32; loop { @@ -762,7 +775,7 @@ impl Serializable for VarInt { return Result::Err(Error::Err("VarInt too big".to_owned())); } if (b & 0x80) == 0 { - break + break; } } @@ -771,7 +784,7 @@ impl Serializable for VarInt { /// Encodes a `VarInt` into the Writer fn write_to(&self, buf: &mut W) -> Result<(), Error> { - const PART : u32 = 0x7F; + const PART: u32 = 0x7F; let mut val = self.0 as u32; loop { if (val & !PART) == 0 { @@ -826,7 +839,11 @@ impl Serializable for VarShort { } fn write_to(&self, buf: &mut W) -> Result<(), Error> { - assert!(self.0 >= 0 && self.0 <= 0x7fffff, "VarShort invalid value: {}", self.0); + assert!( + self.0 >= 0 && self.0 <= 0x7fffff, + "VarShort invalid value: {}", + self.0 + ); let mut low = self.0 & 0x7fff; let high = (self.0 & 0x7f8000) >> 15; if high != 0 { @@ -873,7 +890,7 @@ impl Lengthable for VarLong { impl Serializable for VarLong { /// Decodes a `VarLong` from the Reader fn read_from(buf: &mut R) -> Result { - const PART : u64 = 0x7F; + const PART: u64 = 0x7F; let mut size = 0; let mut val = 0u64; loop { @@ -884,7 +901,7 @@ impl Serializable for VarLong { return Result::Err(Error::Err("VarLong too big".to_owned())); } if (b & 0x80) == 0 { - break + break; } } @@ -893,7 +910,7 @@ impl Serializable for VarLong { /// Encodes a `VarLong` into the Writer fn write_to(&self, buf: &mut W) -> Result<(), Error> { - const PART : u64 = 0x7F; + const PART: u64 = 0x7F; let mut val = self.0 as u64; loop { if (val & !PART) == 0 { @@ -924,7 +941,7 @@ impl Serializable for Position { Ok(Position::new( ((pos as i64) >> 38) as i32, (((pos as i64) >> 26) & 0xFFF) as i32, - ((pos as i64) << 38 >> 38) as i32 + ((pos as i64) << 38 >> 38) as i32, )) } fn write_to(&self, buf: &mut W) -> Result<(), Error> { @@ -936,7 +953,6 @@ impl Serializable for Position { } } - /// Direction is used to define whether packets are going to the /// server or the client. #[derive(Clone, Copy, Debug)] @@ -1058,9 +1074,13 @@ impl Conn { let mut write = ZlibEncoder::new(io::Cursor::new(buf), Compression::default()); write.read_to_end(&mut new)?; if is_network_debug() { - debug!("Compressed for sending {} bytes to {} since > threshold {}, new={:?}", - uncompressed_size, new.len(), self.compression_threshold, - new); + debug!( + "Compressed for sending {} bytes to {} since > threshold {}, new={:?}", + uncompressed_size, + new.len(), + self.compression_threshold, + new + ); } buf = new; } @@ -1090,8 +1110,13 @@ impl Conn { reader.read_to_end(&mut new)?; } if is_network_debug() { - debug!("Decompressed threshold={} len={} uncompressed_size={} to {} bytes", - self.compression_threshold, len, uncompressed_size, new.len()); + debug!( + "Decompressed threshold={} len={} uncompressed_size={} to {} bytes", + self.compression_threshold, + len, + uncompressed_size, + new.len() + ); } buf = io::Cursor::new(new); } @@ -1104,7 +1129,10 @@ impl Conn { }; if is_network_debug() { - debug!("about to parse id={:x}, dir={:?} state={:?}", id, dir, self.state); + debug!( + "about to parse id={:x}, dir={:?} state={:?}", + id, dir, self.state + ); fs::File::create("last-packet")?.write_all(buf.get_ref())?; } @@ -1119,10 +1147,12 @@ impl Conn { let pos = buf.position() as usize; let ibuf = buf.into_inner(); if ibuf.len() != pos { - return Result::Err(Error::Err(format!("Failed to read all of packet 0x{:X}, \ + return Result::Err(Error::Err(format!( + "Failed to read all of packet 0x{:X}, \ had {} bytes left", - id, - ibuf.len() - pos))) + id, + ibuf.len() - pos + ))); } Result::Ok(val) } @@ -1140,10 +1170,10 @@ impl Conn { } pub fn do_status(mut self) -> Result<(Status, Duration), Error> { - use serde_json::Value; - use self::packet::status::serverbound::*; use self::packet::handshake::serverbound::Handshake; + use self::packet::status::serverbound::*; use self::packet::Packet; + use serde_json::Value; let host = self.host.clone(); let port = self.port; self.write_packet(Handshake { @@ -1191,43 +1221,61 @@ impl Conn { if let Value::Array(items) = modlist { for item in items { if let Value::Object(obj) = item { - let modid = obj.get("modid").unwrap().as_str().unwrap().to_string(); - let version = obj.get("version").unwrap().as_str().unwrap().to_string(); + let modid = + obj.get("modid").unwrap().as_str().unwrap().to_string(); + let version = + obj.get("version").unwrap().as_str().unwrap().to_string(); - forge_mods.push(crate::protocol::forge::ForgeMod { modid, version }); + forge_mods + .push(crate::protocol::forge::ForgeMod { modid, version }); } } } } } else { - panic!("Unrecognized modinfo type in server ping response: {} in {}", modinfo_type, modinfo); + panic!( + "Unrecognized modinfo type in server ping response: {} in {}", + modinfo_type, modinfo + ); } } } - Ok((Status { - version: StatusVersion { - name: version.get("name").and_then(Value::as_str).ok_or(invalid_status())? - .to_owned(), - protocol: version.get("protocol") - .and_then(Value::as_i64) - .ok_or(invalid_status())? as i32, + Ok(( + Status { + version: StatusVersion { + name: version + .get("name") + .and_then(Value::as_str) + .ok_or(invalid_status())? + .to_owned(), + protocol: version + .get("protocol") + .and_then(Value::as_i64) + .ok_or(invalid_status())? as i32, + }, + players: StatusPlayers { + max: players + .get("max") + .and_then(Value::as_i64) + .ok_or(invalid_status())? as i32, + online: players + .get("online") + .and_then(Value::as_i64) + .ok_or(invalid_status())? as i32, + sample: Vec::new(), /* TODO */ + }, + description: format::Component::from_value( + val.get("description").ok_or(invalid_status())?, + ), + favicon: val + .get("favicon") + .and_then(Value::as_str) + .map(|v| v.to_owned()), + forge_mods, }, - players: StatusPlayers { - max: players.get("max") - .and_then(Value::as_i64) - .ok_or(invalid_status())? as i32, - online: players.get("online") - .and_then(Value::as_i64) - .ok_or(invalid_status())? as i32, - sample: Vec::new(), /* TODO */ - }, - description: format::Component::from_value(val.get("description") - .ok_or(invalid_status())?), - favicon: val.get("favicon").and_then(Value::as_str).map(|v| v.to_owned()), - forge_mods, - }, - ping)) + ping, + )) } } diff --git a/protocol/src/protocol/mojang.rs b/protocol/src/protocol/mojang.rs index 165fa38d..b781ff48 100644 --- a/protocol/src/protocol/mojang.rs +++ b/protocol/src/protocol/mojang.rs @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use sha1::{self, Digest}; -use serde_json::json; #[cfg(not(target_arch = "wasm32"))] use reqwest; +use serde_json::json; +use sha1::{self, Digest}; #[derive(Clone, Debug)] pub struct Profile { @@ -33,17 +33,18 @@ const VALIDATE_URL: &str = "https://authserver.mojang.com/validate"; impl Profile { pub fn login(username: &str, password: &str, token: &str) -> Result { let req_msg = json!({ - "username": username, - "password": password, - "clientToken": token, - "agent": { - "name": "Minecraft", - "version": 1 - }}); + "username": username, + "password": password, + "clientToken": token, + "agent": { + "name": "Minecraft", + "version": 1 + }}); let req = serde_json::to_string(&req_msg)?; let client = reqwest::blocking::Client::new(); - let res = client.post(LOGIN_URL) + let res = client + .post(LOGIN_URL) .header(reqwest::header::CONTENT_TYPE, "application/json") .body(req) .send()?; @@ -53,33 +54,47 @@ impl Profile { return Err(super::Error::Err(format!( "{}: {}", error, - ret.get("errorMessage").and_then(|v| v.as_str()).unwrap()) - )); + ret.get("errorMessage").and_then(|v| v.as_str()).unwrap() + ))); } Ok(Profile { - username: ret.pointer("/selectedProfile/name").and_then(|v| v.as_str()).unwrap().to_owned(), - id: ret.pointer("/selectedProfile/id").and_then(|v| v.as_str()).unwrap().to_owned(), - access_token: ret.get("accessToken").and_then(|v| v.as_str()).unwrap().to_owned(), + username: ret + .pointer("/selectedProfile/name") + .and_then(|v| v.as_str()) + .unwrap() + .to_owned(), + id: ret + .pointer("/selectedProfile/id") + .and_then(|v| v.as_str()) + .unwrap() + .to_owned(), + access_token: ret + .get("accessToken") + .and_then(|v| v.as_str()) + .unwrap() + .to_owned(), }) } pub fn refresh(self, token: &str) -> Result { let req_msg = json!({ - "accessToken": self.access_token.clone(), - "clientToken": token - }); + "accessToken": self.access_token.clone(), + "clientToken": token + }); let req = serde_json::to_string(&req_msg)?; let client = reqwest::blocking::Client::new(); - let res = client.post(VALIDATE_URL) + let res = client + .post(VALIDATE_URL) .header(reqwest::header::CONTENT_TYPE, "application/json") .body(req) .send()?; if res.status() != reqwest::StatusCode::NO_CONTENT { let req = serde_json::to_string(&req_msg)?; // TODO: fix parsing twice to avoid move - // Refresh needed - let res = client.post(REFRESH_URL) + // Refresh needed + let res = client + .post(REFRESH_URL) .header(reqwest::header::CONTENT_TYPE, "application/json") .body(req) .send()?; @@ -89,19 +104,36 @@ impl Profile { return Err(super::Error::Err(format!( "{}: {}", error, - ret.get("errorMessage").and_then(|v| v.as_str()).unwrap()) - )); + ret.get("errorMessage").and_then(|v| v.as_str()).unwrap() + ))); } return Ok(Profile { - username: ret.pointer("/selectedProfile/name").and_then(|v| v.as_str()).unwrap().to_owned(), - id: ret.pointer("/selectedProfile/id").and_then(|v| v.as_str()).unwrap().to_owned(), - access_token: ret.get("accessToken").and_then(|v| v.as_str()).unwrap().to_owned(), + username: ret + .pointer("/selectedProfile/name") + .and_then(|v| v.as_str()) + .unwrap() + .to_owned(), + id: ret + .pointer("/selectedProfile/id") + .and_then(|v| v.as_str()) + .unwrap() + .to_owned(), + access_token: ret + .get("accessToken") + .and_then(|v| v.as_str()) + .unwrap() + .to_owned(), }); } Ok(self) } - pub fn join_server(&self, server_id: &str, shared_key: &[u8], public_key: &[u8]) -> Result<(), super::Error> { + pub fn join_server( + &self, + server_id: &str, + shared_key: &[u8], + public_key: &[u8], + ) -> Result<(), super::Error> { let mut hasher = sha1::Sha1::new(); hasher.input(server_id.as_bytes()); hasher.input(shared_key); @@ -114,7 +146,11 @@ impl Profile { if negative { twos_compliment(&mut hash); } - let hash_str = hash.iter().map(|b| format!("{:02x}", b)).collect::>().join(""); + let hash_str = hash + .iter() + .map(|b| format!("{:02x}", b)) + .collect::>() + .join(""); let hash_val = hash_str.trim_start_matches('0'); let hash_str = if negative { "-".to_owned() + &hash_val[..] @@ -130,7 +166,8 @@ impl Profile { let join = serde_json::to_string(&join_msg).unwrap(); let client = reqwest::blocking::Client::new(); - let res = client.post(JOIN_URL) + let res = client + .post(JOIN_URL) .header(reqwest::header::CONTENT_TYPE, "application/json") .body(join) .send()?; diff --git a/protocol/src/protocol/packet.rs b/protocol/src/protocol/packet.rs index a1acce97..edf490a7 100644 --- a/protocol/src/protocol/packet.rs +++ b/protocol/src/protocol/packet.rs @@ -2193,7 +2193,8 @@ impl Serializable for Advancement { }; let criteria: LenPrefixed = Serializable::read_from(buf)?; - let requirements: LenPrefixed> = Serializable::read_from(buf)?; + let requirements: LenPrefixed> = + Serializable::read_from(buf)?; Ok(Advancement { id, parent_id, @@ -2210,7 +2211,6 @@ impl Serializable for Advancement { self.criteria.write_to(buf)?; self.requirements.write_to(buf) } - } #[derive(Debug, Default)] @@ -2264,7 +2264,6 @@ impl Serializable for AdvancementDisplay { self.x_coord.write_to(buf)?; self.y_coord.write_to(buf) } - } #[derive(Debug, Default)] @@ -2315,8 +2314,6 @@ impl Serializable for CriterionProgress { } } - - #[derive(Debug, Default)] pub struct EntityProperty { pub key: String, @@ -2363,7 +2360,6 @@ impl Serializable for EntityProperty_i16 { } } - #[derive(Debug, Default)] pub struct PropertyModifier { pub uuid: UUID, @@ -2434,33 +2430,25 @@ impl Serializable for PlayerInfoData { }; m.players.push(p); } - 1 => { - m.players.push(PlayerDetail::UpdateGamemode { - uuid, - gamemode: Serializable::read_from(buf)?, - }) - } - 2 => { - m.players.push(PlayerDetail::UpdateLatency { - uuid, - ping: Serializable::read_from(buf)?, - }) - } - 3 => { - m.players.push(PlayerDetail::UpdateDisplayName { - uuid, - display: { - if bool::read_from(buf)? { - Some(Serializable::read_from(buf)?) - } else { - None - } - }, - }) - } - 4 => { - m.players.push(PlayerDetail::Remove { uuid: uuid }) - } + 1 => m.players.push(PlayerDetail::UpdateGamemode { + uuid, + gamemode: Serializable::read_from(buf)?, + }), + 2 => m.players.push(PlayerDetail::UpdateLatency { + uuid, + ping: Serializable::read_from(buf)?, + }), + 3 => m.players.push(PlayerDetail::UpdateDisplayName { + uuid, + display: { + if bool::read_from(buf)? { + Some(Serializable::read_from(buf)?) + } else { + None + } + }, + }), + 4 => m.players.push(PlayerDetail::Remove { uuid: uuid }), _ => panic!(), } } @@ -2619,8 +2607,7 @@ impl Serializable for Recipe { } }; - let data = - match ty.as_ref() { + let data = match ty.as_ref() { "minecraft:crafting_shapeless" => RecipeData::Shapeless { group: Serializable::read_from(buf)?, ingredients: Serializable::read_from(buf)?, @@ -2634,12 +2621,18 @@ impl Serializable for Recipe { let capacity = width.0 as usize * height.0 as usize; let mut ingredients = Vec::with_capacity(capacity); - for _ in 0 .. capacity { + for _ in 0..capacity { ingredients.push(Serializable::read_from(buf)?); } let result: Option = Serializable::read_from(buf)?; - RecipeData::Shaped { width, height, group, ingredients, result } + RecipeData::Shaped { + width, + height, + group, + ingredients, + result, + } } "minecraft:crafting_special_armordye" => RecipeData::ArmorDye, "minecraft:crafting_special_bookcloning" => RecipeData::BookCloning, @@ -2688,7 +2681,7 @@ impl Serializable for Recipe { ingredient: Serializable::read_from(buf)?, result: Serializable::read_from(buf)?, }, - _ => panic!("unrecognized recipe type: {}", ty) + _ => panic!("unrecognized recipe type: {}", ty), }; Ok(Recipe { id, ty, data }) @@ -2748,7 +2741,11 @@ impl Serializable for Trade { xp: Serializable::read_from(buf)?, special_price: Serializable::read_from(buf)?, price_multiplier: Serializable::read_from(buf)?, - demand: if protocol_version >= 498 { Some(Serializable::read_from(buf)?) } else { None }, + demand: if protocol_version >= 498 { + Some(Serializable::read_from(buf)?) + } else { + None + }, }) } @@ -2757,7 +2754,6 @@ impl Serializable for Trade { } } - #[derive(Debug, Default)] pub struct CommandNode { pub flags: u8, @@ -2843,7 +2839,6 @@ pub enum CommandProperty { Dimension, } - impl Serializable for CommandNode { fn read_from(buf: &mut R) -> Result { let flags: u8 = Serializable::read_from(buf)?; @@ -2865,11 +2860,12 @@ impl Serializable for CommandNode { None }; - let name: Option = if node_type == CommandNodeType::Argument || node_type == CommandNodeType::Literal { - Serializable::read_from(buf)? - } else { - None - }; + let name: Option = + if node_type == CommandNodeType::Argument || node_type == CommandNodeType::Literal { + Serializable::read_from(buf)? + } else { + None + }; let parser: Option = if node_type == CommandNodeType::Argument { Serializable::read_from(buf)? } else { @@ -2881,27 +2877,51 @@ impl Serializable for CommandNode { "brigadier:bool" => CommandProperty::Bool, "brigadier:double" => { let flags = Serializable::read_from(buf)?; - let min = if flags & 0x01 != 0 { Some(Serializable::read_from(buf)?) } else { None }; - let max = if flags & 0x02 != 0 { Some(Serializable::read_from(buf)?) } else { None }; + let min = if flags & 0x01 != 0 { + Some(Serializable::read_from(buf)?) + } else { + None + }; + let max = if flags & 0x02 != 0 { + Some(Serializable::read_from(buf)?) + } else { + None + }; CommandProperty::Double { flags, min, max } - }, + } "brigadier:float" => { let flags = Serializable::read_from(buf)?; - let min = if flags & 0x01 != 0 { Some(Serializable::read_from(buf)?) } else { None }; - let max = if flags & 0x02 != 0 { Some(Serializable::read_from(buf)?) } else { None }; + let min = if flags & 0x01 != 0 { + Some(Serializable::read_from(buf)?) + } else { + None + }; + let max = if flags & 0x02 != 0 { + Some(Serializable::read_from(buf)?) + } else { + None + }; CommandProperty::Float { flags, min, max } - }, + } "brigadier:integer" => { let flags = Serializable::read_from(buf)?; - let min = if flags & 0x01 != 0 { Some(Serializable::read_from(buf)?) } else { None }; - let max = if flags & 0x02 != 0 { Some(Serializable::read_from(buf)?) } else { None }; + let min = if flags & 0x01 != 0 { + Some(Serializable::read_from(buf)?) + } else { + None + }; + let max = if flags & 0x02 != 0 { + Some(Serializable::read_from(buf)?) + } else { + None + }; CommandProperty::Integer { flags, min, max } + } + "brigadier:string" => CommandProperty::String { + token_type: Serializable::read_from(buf)?, }, - "brigadier:string" => { - CommandProperty::String { token_type: Serializable::read_from(buf)? } - }, - "minecraft:entity" => { - CommandProperty::Entity { flags: Serializable::read_from(buf)? } + "minecraft:entity" => CommandProperty::Entity { + flags: Serializable::read_from(buf)?, }, "minecraft:game_profile" => CommandProperty::GameProfile, "minecraft:block_pos" => CommandProperty::BlockPos, @@ -2926,8 +2946,8 @@ impl Serializable for CommandNode { "minecraft:particle" => CommandProperty::Particle, "minecraft:rotation" => CommandProperty::Rotation, "minecraft:scoreboard_slot" => CommandProperty::ScoreboardSlot, - "minecraft:score_holder" => { - CommandProperty::ScoreHolder { flags: Serializable::read_from(buf)? } + "minecraft:score_holder" => CommandProperty::ScoreHolder { + flags: Serializable::read_from(buf)?, }, "minecraft:swizzle" => CommandProperty::Swizzle, "minecraft:team" => CommandProperty::Team, @@ -2936,8 +2956,8 @@ impl Serializable for CommandNode { "minecraft:mob_effect" => CommandProperty::MobEffect, "minecraft:function" => CommandProperty::Function, "minecraft:entity_anchor" => CommandProperty::EntityAnchor, - "minecraft:range" => { - CommandProperty::Range { decimals: Serializable::read_from(buf)? } + "minecraft:range" => CommandProperty::Range { + decimals: Serializable::read_from(buf)?, }, "minecraft:int_range" => CommandProperty::IntRange, "minecraft:float_range" => CommandProperty::FloatRange, @@ -2956,12 +2976,18 @@ impl Serializable for CommandNode { None }; - Ok(CommandNode { flags, children, redirect_node, name, parser, properties, suggestions_type }) + Ok(CommandNode { + flags, + children, + redirect_node, + name, + parser, + properties, + suggestions_type, + }) } fn write_to(&self, _: &mut W) -> Result<(), Error> { unimplemented!() } } - - diff --git a/protocol/src/protocol/versions.rs b/protocol/src/protocol/versions.rs index 461bca19..0cad075c 100644 --- a/protocol/src/protocol/versions.rs +++ b/protocol/src/protocol/versions.rs @@ -1,22 +1,22 @@ use super::*; -mod v1_15_1; -mod v1_14_4; -mod v1_14_3; -mod v1_14_2; -mod v1_14_1; -mod v1_14; -mod v19w02a; +mod v15w39c; mod v18w50a; -mod v1_13_2; -mod v1_12_2; -mod v1_11_2; +mod v19w02a; mod v1_10_2; -mod v1_9_2; -mod v1_9; -mod v15w39c; -mod v1_8_9; +mod v1_11_2; +mod v1_12_2; +mod v1_13_2; +mod v1_14; +mod v1_14_1; +mod v1_14_2; +mod v1_14_3; +mod v1_14_4; +mod v1_15_1; mod v1_7_10; +mod v1_8_9; +mod v1_9; +mod v1_9_2; // https://wiki.vg/Protocol_History // https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite @@ -52,7 +52,13 @@ pub fn protocol_name_to_protocol_version(s: String) -> i32 { } } -pub fn translate_internal_packet_id_for_version(version: i32, state: State, dir: Direction, id: i32, to_internal: bool) -> i32 { +pub fn translate_internal_packet_id_for_version( + version: i32, + state: State, + dir: Direction, + id: i32, + to_internal: bool, +) -> i32 { match version { 575 => v1_15_1::translate_internal_packet_id(state, dir, id, to_internal), 498 => v1_14_4::translate_internal_packet_id(state, dir, id, to_internal), diff --git a/protocol/src/protocol/versions/v15w39c.rs b/protocol/src/protocol/versions/v15w39c.rs index 98015718..f12dbdab 100644 --- a/protocol/src/protocol/versions/v15w39c.rs +++ b/protocol/src/protocol/versions/v15w39c.rs @@ -137,5 +137,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v18w50a.rs b/protocol/src/protocol/versions/v18w50a.rs index 0a9d6a92..b153340a 100644 --- a/protocol/src/protocol/versions/v18w50a.rs +++ b/protocol/src/protocol/versions/v18w50a.rs @@ -168,5 +168,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v19w02a.rs b/protocol/src/protocol/versions/v19w02a.rs index 9a2af5c5..d24b82f1 100644 --- a/protocol/src/protocol/versions/v19w02a.rs +++ b/protocol/src/protocol/versions/v19w02a.rs @@ -170,5 +170,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_10_2.rs b/protocol/src/protocol/versions/v1_10_2.rs index 02ddc6c4..066006fb 100644 --- a/protocol/src/protocol/versions/v1_10_2.rs +++ b/protocol/src/protocol/versions/v1_10_2.rs @@ -141,5 +141,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_11_2.rs b/protocol/src/protocol/versions/v1_11_2.rs index aa82c975..cf95ffe8 100644 --- a/protocol/src/protocol/versions/v1_11_2.rs +++ b/protocol/src/protocol/versions/v1_11_2.rs @@ -141,5 +141,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_12_2.rs b/protocol/src/protocol/versions/v1_12_2.rs index 1e3b9096..679b6976 100644 --- a/protocol/src/protocol/versions/v1_12_2.rs +++ b/protocol/src/protocol/versions/v1_12_2.rs @@ -148,5 +148,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_13_2.rs b/protocol/src/protocol/versions/v1_13_2.rs index 04871b1a..09f5aca9 100644 --- a/protocol/src/protocol/versions/v1_13_2.rs +++ b/protocol/src/protocol/versions/v1_13_2.rs @@ -165,5 +165,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_14.rs b/protocol/src/protocol/versions/v1_14.rs index b5c9a9ae..bd215105 100644 --- a/protocol/src/protocol/versions/v1_14.rs +++ b/protocol/src/protocol/versions/v1_14.rs @@ -175,5 +175,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_14_1.rs b/protocol/src/protocol/versions/v1_14_1.rs index b5c9a9ae..bd215105 100644 --- a/protocol/src/protocol/versions/v1_14_1.rs +++ b/protocol/src/protocol/versions/v1_14_1.rs @@ -175,5 +175,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_14_2.rs b/protocol/src/protocol/versions/v1_14_2.rs index b5c9a9ae..bd215105 100644 --- a/protocol/src/protocol/versions/v1_14_2.rs +++ b/protocol/src/protocol/versions/v1_14_2.rs @@ -175,5 +175,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_14_3.rs b/protocol/src/protocol/versions/v1_14_3.rs index a5eebf2b..5b05fdec 100644 --- a/protocol/src/protocol/versions/v1_14_3.rs +++ b/protocol/src/protocol/versions/v1_14_3.rs @@ -175,5 +175,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_14_4.rs b/protocol/src/protocol/versions/v1_14_4.rs index 60be91a7..820c60fa 100644 --- a/protocol/src/protocol/versions/v1_14_4.rs +++ b/protocol/src/protocol/versions/v1_14_4.rs @@ -176,5 +176,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_15_1.rs b/protocol/src/protocol/versions/v1_15_1.rs index 6c3386c8..e5ae7dd2 100644 --- a/protocol/src/protocol/versions/v1_15_1.rs +++ b/protocol/src/protocol/versions/v1_15_1.rs @@ -176,5 +176,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_7_10.rs b/protocol/src/protocol/versions/v1_7_10.rs index c930e422..8da21372 100644 --- a/protocol/src/protocol/versions/v1_7_10.rs +++ b/protocol/src/protocol/versions/v1_7_10.rs @@ -124,5 +124,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_8_9.rs b/protocol/src/protocol/versions/v1_8_9.rs index c645c455..8130a10c 100644 --- a/protocol/src/protocol/versions/v1_8_9.rs +++ b/protocol/src/protocol/versions/v1_8_9.rs @@ -135,5 +135,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_9.rs b/protocol/src/protocol/versions/v1_9.rs index 7b714e84..dc817dce 100644 --- a/protocol/src/protocol/versions/v1_9.rs +++ b/protocol/src/protocol/versions/v1_9.rs @@ -142,5 +142,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/protocol/versions/v1_9_2.rs b/protocol/src/protocol/versions/v1_9_2.rs index ecd1e28b..9ee61b31 100644 --- a/protocol/src/protocol/versions/v1_9_2.rs +++ b/protocol/src/protocol/versions/v1_9_2.rs @@ -142,5 +142,3 @@ protocol_packet_ids!( } } ); - - diff --git a/protocol/src/types/bit/map.rs b/protocol/src/types/bit/map.rs index 2f869794..66cfc980 100644 --- a/protocol/src/types/bit/map.rs +++ b/protocol/src/types/bit/map.rs @@ -61,7 +61,7 @@ impl Map { } pub fn from_raw(bits: Vec, size: usize) -> Map { Map { - length: (bits.len()*64 + (size-1)) / size, + length: (bits.len() * 64 + (size - 1)) / size, bit_size: size, bits, } diff --git a/protocol/src/types/bit/mod.rs b/protocol/src/types/bit/mod.rs index 6754eabe..812da5d4 100644 --- a/protocol/src/types/bit/mod.rs +++ b/protocol/src/types/bit/mod.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod set; pub mod map; +pub mod set; -pub use self::set::Set; pub use self::map::Map; +pub use self::set::Set; diff --git a/protocol/src/types/bit/set.rs b/protocol/src/types/bit/set.rs index 894d936b..14cf4fc9 100644 --- a/protocol/src/types/bit/set.rs +++ b/protocol/src/types/bit/set.rs @@ -34,7 +34,9 @@ fn test_set() { impl Set { pub fn new(size: usize) -> Set { - Set { data: vec![0; (size + 63) / 64] } + Set { + data: vec![0; (size + 63) / 64], + } } pub fn resize(&mut self, new_size: usize) { diff --git a/protocol/src/types/hash.rs b/protocol/src/types/hash.rs index cf16af97..a06519b3 100644 --- a/protocol/src/types/hash.rs +++ b/protocol/src/types/hash.rs @@ -1,5 +1,3 @@ - - use std::hash::Hasher; pub struct FNVHash(u64); diff --git a/protocol/src/types/metadata.rs b/protocol/src/types/metadata.rs index 17c18eb9..2297d5f6 100644 --- a/protocol/src/types/metadata.rs +++ b/protocol/src/types/metadata.rs @@ -12,24 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; -use std::marker::PhantomData; -use std::io; -use std::fmt; -use crate::protocol; -use crate::protocol::Serializable; -use crate::protocol::LenPrefixed; use crate::format; use crate::item; -use crate::shared::Position; use crate::nbt; +use crate::protocol; +use crate::protocol::LenPrefixed; +use crate::protocol::Serializable; +use crate::shared::Position; +use std::collections::HashMap; +use std::fmt; +use std::io; +use std::marker::PhantomData; pub struct MetadataKey { index: i32, ty: PhantomData, } -impl MetadataKey { +impl MetadataKey { #[allow(dead_code)] fn new(index: i32) -> MetadataKey { MetadataKey { @@ -45,7 +45,9 @@ pub struct Metadata { impl Metadata { pub fn new() -> Metadata { - Metadata { map: HashMap::new() } + Metadata { + map: HashMap::new(), + } } pub fn get(&self, key: &MetadataKey) -> Option<&T> { @@ -77,14 +79,22 @@ impl Metadata { 3 => m.put_raw(index, f32::read_from(buf)?), 4 => m.put_raw(index, String::read_from(buf)?), 5 => m.put_raw(index, Option::::read_from(buf)?), - 6 => m.put_raw(index, - [i32::read_from(buf)?, - i32::read_from(buf)?, - i32::read_from(buf)?]), - 7 => m.put_raw(index, - [f32::read_from(buf)?, - f32::read_from(buf)?, - f32::read_from(buf)?]), + 6 => m.put_raw( + index, + [ + i32::read_from(buf)?, + i32::read_from(buf)?, + i32::read_from(buf)?, + ], + ), + 7 => m.put_raw( + index, + [ + f32::read_from(buf)?, + f32::read_from(buf)?, + f32::read_from(buf)?, + ], + ), _ => return Err(protocol::Error::Err("unknown metadata type".to_owned())), } } @@ -100,8 +110,7 @@ impl Metadata { let ty_index: u8 = *k as u8; const TYPE_SHIFT: usize = 5; - match *v - { + match *v { Value::Byte(ref val) => { u8::write_to(&(ty_index | (0 << TYPE_SHIFT)), buf)?; val.write_to(buf)?; @@ -165,10 +174,14 @@ impl Metadata { 4 => m.put_raw(index, format::Component::read_from(buf)?), 5 => m.put_raw(index, Option::::read_from(buf)?), 6 => m.put_raw(index, bool::read_from(buf)?), - 7 => m.put_raw(index, - [f32::read_from(buf)?, - f32::read_from(buf)?, - f32::read_from(buf)?]), + 7 => m.put_raw( + index, + [ + f32::read_from(buf)?, + f32::read_from(buf)?, + f32::read_from(buf)?, + ], + ), 8 => m.put_raw(index, Position::read_from(buf)?), 9 => { if bool::read_from(buf)? { @@ -287,13 +300,20 @@ impl Metadata { 2 => m.put_raw(index, f32::read_from(buf)?), 3 => m.put_raw(index, String::read_from(buf)?), 4 => m.put_raw(index, format::Component::read_from(buf)?), - 5 => m.put_raw(index, LenPrefixed::::read_from(buf)?), + 5 => m.put_raw( + index, + LenPrefixed::::read_from(buf)?, + ), 6 => m.put_raw(index, Option::::read_from(buf)?), 7 => m.put_raw(index, bool::read_from(buf)?), - 8 => m.put_raw(index, - [f32::read_from(buf)?, - f32::read_from(buf)?, - f32::read_from(buf)?]), + 8 => m.put_raw( + index, + [ + f32::read_from(buf)?, + f32::read_from(buf)?, + f32::read_from(buf)?, + ], + ), 9 => m.put_raw(index, Position::read_from(buf)?), 10 => { if bool::read_from(buf)? { @@ -328,7 +348,7 @@ impl Metadata { } else { m.put_raw::>(index, None); } - }, + } 18 => m.put_raw(index, PoseData::read_from(buf)?), _ => return Err(protocol::Error::Err("unknown metadata type".to_owned())), } @@ -427,8 +447,6 @@ impl Metadata { u8::write_to(&0xFF, buf)?; Ok(()) } - - } impl Serializable for Metadata { @@ -571,7 +589,7 @@ impl Serializable for ParticleData { 1 => ParticleData::AngryVillager, 2 => ParticleData::Barrier, 3 => ParticleData::Block { - block_state: Serializable::read_from(buf)? + block_state: Serializable::read_from(buf)?, }, 4 => ParticleData::Bubble, 5 => ParticleData::Cloud, @@ -649,7 +667,11 @@ impl Serializable for VillagerData { let villager_type = protocol::VarInt::read_from(buf)?; let profession = protocol::VarInt::read_from(buf)?; let level = protocol::VarInt::read_from(buf)?; - Ok(VillagerData { villager_type, profession, level }) + Ok(VillagerData { + villager_type, + profession, + level, + }) } fn write_to(&self, _buf: &mut W) -> Result<(), protocol::Error> { @@ -688,8 +710,6 @@ impl Serializable for PoseData { } } - - pub trait MetaValue { fn unwrap(_: &Value) -> &Self; fn wrap(self) -> Value; @@ -779,7 +799,6 @@ impl MetaValue for LenPrefixed { } } - impl MetaValue for Option { fn unwrap(value: &Value) -> &Self { match *value { @@ -936,14 +955,12 @@ impl MetaValue for PoseData { } } - #[cfg(test)] mod test { use super::*; use std::marker::PhantomData; - const TEST: MetadataKey = - MetadataKey { + const TEST: MetadataKey = MetadataKey { index: 0, ty: PhantomData, }; diff --git a/protocol/src/types/mod.rs b/protocol/src/types/mod.rs index 5232c8cb..dcde2676 100644 --- a/protocol/src/types/mod.rs +++ b/protocol/src/types/mod.rs @@ -16,8 +16,8 @@ mod metadata; pub use self::metadata::*; pub mod bit; -pub mod nibble; pub mod hash; +pub mod nibble; #[derive(Clone, Copy, Debug)] pub enum Gamemode { diff --git a/protocol/src/types/nibble.rs b/protocol/src/types/nibble.rs index 91ecdc8a..c1d6e79c 100644 --- a/protocol/src/types/nibble.rs +++ b/protocol/src/types/nibble.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - pub struct Array { pub data: Vec, } @@ -25,8 +24,8 @@ impl Array { } pub fn get(&self, idx: usize) -> u8 { - let val = self.data[idx>>1]; - if idx&1 == 0 { + let val = self.data[idx >> 1]; + if idx & 1 == 0 { val & 0xF } else { val >> 4 @@ -36,7 +35,7 @@ impl Array { pub fn set(&mut self, idx: usize, val: u8) { let i = idx >> 1; let old = self.data[i]; - if idx&1 == 0 { + if idx & 1 == 0 { self.data[i] = (old & 0xF0) | (val & 0xF); } else { self.data[i] = (old & 0x0F) | ((val & 0xF) << 4); diff --git a/resources/build.rs b/resources/build.rs index 600741d2..12220ab9 100644 --- a/resources/build.rs +++ b/resources/build.rs @@ -1,8 +1,8 @@ use std::env; use std::fs; -use std::path::{Path, PathBuf}; use std::io::BufWriter; use std::io::Write; +use std::path::{Path, PathBuf}; fn main() { let out_dir = env::var("OUT_DIR").unwrap(); @@ -13,7 +13,11 @@ fn main() { build_map(&mut out, &base); let mut file = BufWriter::new(fs::File::create(&dest.join("resources.rs")).unwrap()); - write!(file, "pub fn get_file(name: &str) -> Option<&'static [u8]> {{\n").unwrap(); + write!( + file, + "pub fn get_file(name: &str) -> Option<&'static [u8]> {{\n" + ) + .unwrap(); write!(file, " match name {{\n").unwrap(); for path in &out { let mut absolute_path = std::env::current_dir().unwrap(); @@ -22,10 +26,14 @@ fn main() { let absolute = absolute_path.to_str().unwrap().replace("\\", "/"); let relative = path.to_str().unwrap().replace("\\", "/"); - write!(file, " {:?} => Some(include_bytes!(\"{}\")),\n", relative, absolute).unwrap(); + write!( + file, + " {:?} => Some(include_bytes!(\"{}\")),\n", + relative, absolute + ) + .unwrap(); } write!(file, " _ => None\n }}\n}}\n").unwrap(); - } fn build_map(out: &mut Vec, path: &Path) { diff --git a/resources/src/lib.rs b/resources/src/lib.rs index 6b4e3991..9b885ffd 100644 --- a/resources/src/lib.rs +++ b/resources/src/lib.rs @@ -1,2 +1 @@ - include!(concat!(env!("OUT_DIR"), "/resources.rs")); diff --git a/shared/src/axis.rs b/shared/src/axis.rs index e0cfa6d6..d255f636 100644 --- a/shared/src/axis.rs +++ b/shared/src/axis.rs @@ -1,10 +1,9 @@ - #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Axis { Y, Z, X, - None + None, } impl Axis { diff --git a/shared/src/direction.rs b/shared/src/direction.rs index 273dc982..d2c69380 100644 --- a/shared/src/direction.rs +++ b/shared/src/direction.rs @@ -1,4 +1,3 @@ - use crate::axis::Axis; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -15,9 +14,12 @@ pub enum Direction { impl Direction { pub fn all() -> Vec { vec![ - Direction::Down, Direction::Up, - Direction::North, Direction::South, - Direction::West, Direction::East, + Direction::Down, + Direction::Up, + Direction::North, + Direction::South, + Direction::West, + Direction::East, ] } @@ -117,7 +119,6 @@ impl Direction { } } - pub fn horizontal_index(&self) -> usize { match *self { Direction::North => 2, diff --git a/shared/src/lib.rs b/shared/src/lib.rs index a1b09fe2..041be19e 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -1,4 +1,3 @@ - pub mod axis; pub use self::axis::Axis; diff --git a/shared/src/position.rs b/shared/src/position.rs index c2ad4f19..b6dbe495 100644 --- a/shared/src/position.rs +++ b/shared/src/position.rs @@ -1,6 +1,5 @@ - -use std::fmt; use crate::direction::Direction; +use std::fmt; use std::ops; #[derive(Clone, Copy, PartialEq, Eq, Hash)] @@ -12,11 +11,7 @@ pub struct Position { impl Position { pub fn new(x: i32, y: i32, z: i32) -> Position { - Position { - x, - y, - z, - } + Position { x, y, z } } pub fn shift(self, dir: Direction) -> Position { diff --git a/src/chunk_builder.rs b/src/chunk_builder.rs index b0157c87..20b5b553 100644 --- a/src/chunk_builder.rs +++ b/src/chunk_builder.rs @@ -1,16 +1,15 @@ - -use std::thread; -use std::sync::mpsc; -use std::sync::{Arc, RwLock}; -use crate::world; -use crate::world::block; +use crate::model; use crate::render; use crate::resources; -use crate::model; -use crate::types::bit::Set; use crate::shared::Direction; -use rand::{self, SeedableRng, Rng}; +use crate::types::bit::Set; +use crate::world; +use crate::world::block; +use rand::{self, Rng, SeedableRng}; use rand_pcg; +use std::sync::mpsc; +use std::sync::{Arc, RwLock}; +use std::thread; const NUM_WORKERS: usize = 8; @@ -24,18 +23,27 @@ pub struct ChunkBuilder { } impl ChunkBuilder { - pub fn new(resources: Arc>, textures: Arc>) -> ChunkBuilder { - let models = Arc::new(RwLock::new(model::Factory::new(resources.clone(), textures))); + pub fn new( + resources: Arc>, + textures: Arc>, + ) -> ChunkBuilder { + let models = Arc::new(RwLock::new(model::Factory::new( + resources.clone(), + textures, + ))); let mut threads = vec![]; let mut free = vec![]; let (built_send, built_recv) = mpsc::channel(); - for i in 0 .. NUM_WORKERS { + for i in 0..NUM_WORKERS { let built_send = built_send.clone(); let (work_send, work_recv) = mpsc::channel(); let models = models.clone(); let id = i; - threads.push((work_send, thread::spawn(move || build_func(id, models, work_recv, built_send)))); + threads.push(( + work_send, + thread::spawn(move || build_func(id, models, work_recv, built_send)), + )); free.push((i, vec![], vec![])); } ChunkBuilder { @@ -47,7 +55,12 @@ impl ChunkBuilder { } } - pub fn tick(&mut self, world: &mut world::World, renderer: &mut render::Renderer, version: usize) { + pub fn tick( + &mut self, + world: &mut world::World, + renderer: &mut render::Renderer, + version: usize, + ) { { if version != self.resource_version { self.resource_version = version; @@ -58,35 +71,50 @@ impl ChunkBuilder { while let Ok((id, mut val)) = self.built_recv.try_recv() { world.reset_building_flag(val.position); - if let Some(sec) = world.get_section_mut(val.position.0, val.position.1, val.position.2) { + if let Some(sec) = world.get_section_mut(val.position.0, val.position.1, val.position.2) + { sec.cull_info = val.cull_info; - renderer.update_chunk_solid(&mut sec.render_buffer, &val.solid_buffer, val.solid_count); - renderer.update_chunk_trans(&mut sec.render_buffer, &val.trans_buffer, val.trans_count); + renderer.update_chunk_solid( + &mut sec.render_buffer, + &val.solid_buffer, + val.solid_count, + ); + renderer.update_chunk_trans( + &mut sec.render_buffer, + &val.trans_buffer, + val.trans_count, + ); } val.solid_buffer.clear(); val.trans_buffer.clear(); - self.free_builders.push((id, val.solid_buffer, val.trans_buffer)); + self.free_builders + .push((id, val.solid_buffer, val.trans_buffer)); } if self.free_builders.is_empty() { return; } - let dirty_sections = world.get_render_list().iter() - .map(|v| v.0) - .filter(|v| world.is_section_dirty(*v)) - .collect::>(); - for (x,y, z) in dirty_sections { + let dirty_sections = world + .get_render_list() + .iter() + .map(|v| v.0) + .filter(|v| world.is_section_dirty(*v)) + .collect::>(); + for (x, y, z) in dirty_sections { let t_id = self.free_builders.pop().unwrap(); world.set_building_flag((x, y, z)); let (cx, cy, cz) = (x << 4, y << 4, z << 4); let mut snapshot = world.capture_snapshot(cx - 2, cy - 2, cz - 2, 20, 20, 20); snapshot.make_relative(-2, -2, -2); - self.threads[t_id.0].0.send(BuildReq { - snapshot, - position: (x, y, z), - solid_buffer: t_id.1, - trans_buffer: t_id.2, - }).unwrap(); + self.threads[t_id.0] + .0 + .send(BuildReq { + snapshot, + position: (x, y, z), + solid_buffer: t_id.1, + trans_buffer: t_id.2, + }) + .unwrap(); if self.free_builders.is_empty() { return; } @@ -110,7 +138,12 @@ struct BuildReply { cull_info: CullInfo, } -fn build_func(id: usize, models: Arc>, work_recv: mpsc::Receiver, built_send: mpsc::Sender<(usize, BuildReply)>) { +fn build_func( + id: usize, + models: Arc>, + work_recv: mpsc::Receiver, + built_send: mpsc::Sender<(usize, BuildReply)>, +) { loop { let BuildReq { snapshot, @@ -127,17 +160,14 @@ fn build_func(id: usize, models: Arc>, work_recv: mpsc::R (((position.0 as u32) >> 8) & 0xff) as u8, (((position.0 as u32) >> 16) & 0xff) as u8, ((position.0 as u32) >> 24) as u8, - ((position.1 as u32) & 0xff) as u8, (((position.1 as u32) >> 8) & 0xff) as u8, (((position.1 as u32) >> 16) & 0xff) as u8, ((position.1 as u32) >> 24) as u8, - ((position.2 as u32) & 0xff) as u8, (((position.2 as u32) >> 8) & 0xff) as u8, (((position.2 as u32) >> 16) & 0xff) as u8, ((position.2 as u32) >> 24) as u8, - (((position.0 as u32 ^ position.2 as u32) | 1) & 0xff) as u8, ((((position.0 as u32 ^ position.2 as u32) | 1) >> 8) & 0xff) as u8, ((((position.0 as u32 ^ position.2 as u32) | 1) >> 16) & 0xff) as u8, @@ -147,9 +177,9 @@ fn build_func(id: usize, models: Arc>, work_recv: mpsc::R let mut solid_count = 0; let mut trans_count = 0; - for y in 0 .. 16 { - for x in 0 .. 16 { - for z in 0 .. 16 { + for y in 0..16 { + for x in 0..16 { + for z in 0..16 { let block = snapshot.get_block(x, y, z); let mat = block.get_material(); if !mat.renderable { @@ -161,26 +191,56 @@ fn build_func(id: usize, models: Arc>, work_recv: mpsc::R } match block { - block::Block::Water{..} | block::Block::FlowingWater{..} => { + block::Block::Water { .. } | block::Block::FlowingWater { .. } => { let tex = models.read().unwrap().textures.clone(); - trans_count += model::liquid::render_liquid(tex, false, &snapshot, x, y, z, &mut trans_buffer); + trans_count += model::liquid::render_liquid( + tex, + false, + &snapshot, + x, + y, + z, + &mut trans_buffer, + ); continue; - }, - block::Block::Lava{..} | block::Block::FlowingLava{..} => { + } + block::Block::Lava { .. } | block::Block::FlowingLava { .. } => { let tex = models.read().unwrap().textures.clone(); - solid_count += model::liquid::render_liquid(tex, true, &snapshot, x, y, z, &mut solid_buffer); + solid_count += model::liquid::render_liquid( + tex, + true, + &snapshot, + x, + y, + z, + &mut solid_buffer, + ); continue; - }, - _ => {}, + } + _ => {} } if mat.transparent { trans_count += model::Factory::get_state_model( - &models, block, &mut rng, &snapshot, x, y, z, &mut trans_buffer + &models, + block, + &mut rng, + &snapshot, + x, + y, + z, + &mut trans_buffer, ); } else { solid_count += model::Factory::get_state_model( - &models, block, &mut rng, &snapshot, x, y, z, &mut solid_buffer + &models, + block, + &mut rng, + &snapshot, + x, + y, + z, + &mut solid_buffer, ); } } @@ -189,14 +249,19 @@ fn build_func(id: usize, models: Arc>, work_recv: mpsc::R let cull_info = build_cull_info(&snapshot); - built_send.send((id, BuildReply { - position, - solid_buffer, - solid_count, - trans_buffer, - trans_count, - cull_info, - })).unwrap(); + built_send + .send(( + id, + BuildReply { + position, + solid_buffer, + solid_count, + trans_buffer, + trans_count, + cull_info, + }, + )) + .unwrap(); } } @@ -204,9 +269,9 @@ fn build_cull_info(snapshot: &world::Snapshot) -> CullInfo { let mut visited = Set::new(16 * 16 * 16); let mut info = CullInfo::new(); - for y in 0 .. 16 { - for z in 0 .. 16 { - for x in 0 .. 16 { + for y in 0..16 { + for z in 0..16 { + for x in 0..16 { if visited.get(x | (z << 4) | (y << 8)) { continue; } @@ -246,7 +311,11 @@ fn flood_fill(snapshot: &world::Snapshot, visited: &mut Set, x: i32, y: i32, z: } visited.set(idx, true); - if snapshot.get_block(x, y, z).get_material().should_cull_against { + if snapshot + .get_block(x, y, z) + .get_material() + .should_cull_against + { continue; } @@ -268,7 +337,7 @@ fn flood_fill(snapshot: &world::Snapshot, visited: &mut Set, x: i32, y: i32, z: for d in Direction::all() { let (ox, oy, oz) = d.get_offset(); - next_position.push_back((x+ox, y+oy, z+oz)); + next_position.push_back((x + ox, y + oy, z + oz)); } } touched @@ -278,7 +347,9 @@ fn flood_fill(snapshot: &world::Snapshot, visited: &mut Set, x: i32, y: i32, z: pub struct CullInfo(u64); impl CullInfo { - pub fn new() -> CullInfo { Default::default() } + pub fn new() -> CullInfo { + Default::default() + } pub fn all_vis() -> CullInfo { CullInfo(0xFFFFFFFFFFFFFFFF) diff --git a/src/console/mod.rs b/src/console/mod.rs index 1fcc3eb2..0f21b6f5 100644 --- a/src/console/mod.rs +++ b/src/console/mod.rs @@ -12,18 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::marker::PhantomData; -use std::collections::HashMap; +use log; use std::any::Any; -use std::cell::{RefCell, Ref}; +use std::cell::{Ref, RefCell}; +use std::collections::HashMap; +use std::io::{BufRead, BufReader, BufWriter, Write}; +use std::marker::PhantomData; use std::sync::{Arc, Mutex}; use std_or_web::fs; -use std::io::{BufWriter, Write, BufRead, BufReader}; -use log; -use crate::ui; +use crate::format::{Color, Component, TextComponent}; use crate::render; -use crate::format::{Component, TextComponent, Color}; +use crate::ui; #[cfg(target_arch = "wasm32")] use web_sys; @@ -126,21 +126,26 @@ pub struct Vars { } impl Vars { - pub fn new() -> Vars { Default::default() } + pub fn new() -> Vars { + Default::default() + } pub fn register(&mut self, var: CVar) - where CVar: Var + where + CVar: Var, { if self.vars.contains_key(var.name) { panic!("Key registered twice {}", var.name); } self.names.insert(var.name.to_owned(), var.name); - self.var_values.insert(var.name, RefCell::new(Box::new((var.default)()))); + self.var_values + .insert(var.name, RefCell::new(Box::new((var.default)()))); self.vars.insert(var.name, Box::new(var)); } pub fn get(&self, var: CVar) -> Ref - where CVar: Var + where + CVar: Var, { // Should never fail let var = self.var_values.get(var.name).unwrap().borrow(); @@ -148,7 +153,8 @@ impl Vars { } pub fn set(&self, var: CVar, val: T) - where CVar: Var + where + CVar: Var, { *self.var_values.get(var.name).unwrap().borrow_mut() = Box::new(val); self.save_config(); @@ -162,7 +168,10 @@ impl Vars { if line.starts_with('#') || line.is_empty() { continue; } - let parts = line.splitn(2, ' ').map(|v| v.to_owned()).collect::>(); + let parts = line + .splitn(2, ' ') + .map(|v| v.to_owned()) + .collect::>(); let (name, arg) = (&parts[0], &parts[1]); if let Some(var_name) = self.names.get(name) { let var = self.vars.get(var_name).unwrap(); @@ -184,11 +193,13 @@ impl Vars { for line in var.description().lines() { write!(file, "# {}\n", line).unwrap(); } - write!(file, - "{} {}\n\n", - name, - var.serialize(&self.var_values.get(name).unwrap().borrow())) - .unwrap(); + write!( + file, + "{} {}\n\n", + name, + var.serialize(&self.var_values.get(name).unwrap().borrow()) + ) + .unwrap(); } } } @@ -227,11 +238,13 @@ impl Console { self.active = !self.active; } - pub fn tick(&mut self, - ui_container: &mut ui::Container, - renderer: &render::Renderer, - delta: f64, - width: f64) { + pub fn tick( + &mut self, + ui_container: &mut ui::Container, + renderer: &render::Renderer, + delta: f64, + width: f64, + ) { if !self.active && self.position <= -220.0 { self.elements = None; return; @@ -281,12 +294,14 @@ impl Console { break; } let (_, height) = ui::Formatted::compute_size(renderer, line, w - 10.0); - elements.lines.push(ui::FormattedBuilder::new() - .text(line.clone()) - .position(5.0, 5.0 + offset) - .max_width(w - 10.0) - .alignment(ui::VAttach::Bottom, ui::HAttach::Left) - .create(&mut *background)); + elements.lines.push( + ui::FormattedBuilder::new() + .text(line.clone()) + .position(5.0, 5.0 + offset) + .max_width(w - 10.0) + .alignment(ui::VAttach::Bottom, ui::HAttach::Left) + .create(&mut *background), + ); offset += height; } } @@ -304,11 +319,16 @@ impl Console { file = &file[pos + 4..]; } - println_level(record.level(), format!("[{}:{}][{}] {}", - file, - record.line().unwrap_or(0), - record.level(), - record.args())); + println_level( + record.level(), + format!( + "[{}:{}][{}] {}", + file, + record.line().unwrap_or(0), + record.level(), + record.args() + ), + ); self.history.remove(0); let mut msg = TextComponent::new(""); msg.modifier.extra = Some(vec![ @@ -338,7 +358,7 @@ impl Console { Component::Text(msg) }, Component::Text(TextComponent::new("] ")), - Component::Text(TextComponent::new(&format!("{}", record.args()))) + Component::Text(TextComponent::new(&format!("{}", record.args()))), ]); self.history.push(Component::Text(msg)); self.dirty = true; @@ -366,8 +386,7 @@ impl log::Log for ConsoleProxy { } } - fn flush(&self) { - } + fn flush(&self) {} } unsafe impl Send for ConsoleProxy {} diff --git a/src/ecs/mod.rs b/src/ecs/mod.rs index 2fa3fd50..719bf8d4 100644 --- a/src/ecs/mod.rs +++ b/src/ecs/mod.rs @@ -13,17 +13,17 @@ // limitations under the License. use crate::types::bit::Set as BSet; -use std::collections::{HashMap, HashSet}; -use std::hash::BuildHasherDefault; use crate::types::hash::FNVHash; use std::any::{Any, TypeId}; use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::hash::BuildHasherDefault; use std::marker::PhantomData; use std::mem; use std::ptr; -use crate::world; use crate::render; +use crate::world; /// Used to reference an entity. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -38,7 +38,7 @@ pub struct Key { id: usize, _t: PhantomData, } -impl Clone for Key { +impl Clone for Key { fn clone(&self) -> Self { Key { id: self.id, @@ -46,7 +46,7 @@ impl Clone for Key { } } } -impl Copy for Key {} +impl Copy for Key {} /// Used to search for entities with the requested components. pub struct Filter { @@ -56,9 +56,7 @@ pub struct Filter { impl Filter { /// Creates an empty filter which matches everything pub fn new() -> Filter { - Filter { - bits: BSet::new(0), - } + Filter { bits: BSet::new(0) } } /// Adds the component to the filter. @@ -74,12 +72,29 @@ impl Filter { /// A system processes entities pub trait System { fn filter(&self) -> &Filter; - fn update(&mut self, m: &mut Manager, world: &mut world::World, renderer: &mut render::Renderer); - - fn entity_added(&mut self, _m: &mut Manager, _e: Entity, _world: &mut world::World, _renderer: &mut render::Renderer) { - } - - fn entity_removed(&mut self, _m: &mut Manager, _e: Entity, _world: &mut world::World, _renderer: &mut render::Renderer) { + fn update( + &mut self, + m: &mut Manager, + world: &mut world::World, + renderer: &mut render::Renderer, + ); + + fn entity_added( + &mut self, + _m: &mut Manager, + _e: Entity, + _world: &mut world::World, + _renderer: &mut render::Renderer, + ) { + } + + fn entity_removed( + &mut self, + _m: &mut Manager, + _e: Entity, + _world: &mut world::World, + _renderer: &mut render::Renderer, + ) { } } @@ -110,11 +125,14 @@ impl Manager { pub fn new() -> Manager { Manager { num_components: 0, - entities: vec![(Some(EntityState { - last_components: BSet::new(0), - components: BSet::new(0), - removed: false, - }), 0)], // Has the world entity pre-defined + entities: vec![( + Some(EntityState { + last_components: BSet::new(0), + components: BSet::new(0), + removed: false, + }), + 0, + )], // Has the world entity pre-defined free_entities: vec![], components: vec![], @@ -166,7 +184,11 @@ impl Manager { self.process_entity_changes(world, renderer); } - fn process_entity_changes(&mut self, world: &mut world::World, renderer: &mut render::Renderer) { + fn process_entity_changes( + &mut self, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { let changes = self.changed_entity_components.clone(); self.changed_entity_components = HashSet::with_hasher(BuildHasherDefault::default()); for entity in changes { @@ -177,11 +199,35 @@ impl Manager { state.components.or(&state.last_components); (cur, orig) }; - self.trigger_add_for_systems(entity, &state.last_components, &state.components, world, renderer); - self.trigger_add_for_render_systems(entity, &state.last_components, &state.components, world, renderer); - self.trigger_remove_for_systems(entity, &state.last_components, &state.components, world, renderer); - self.trigger_remove_for_render_systems(entity, &state.last_components, &state.components, world, renderer); - for i in 0 .. self.components.len() { + self.trigger_add_for_systems( + entity, + &state.last_components, + &state.components, + world, + renderer, + ); + self.trigger_add_for_render_systems( + entity, + &state.last_components, + &state.components, + world, + renderer, + ); + self.trigger_remove_for_systems( + entity, + &state.last_components, + &state.components, + world, + renderer, + ); + self.trigger_remove_for_render_systems( + entity, + &state.last_components, + &state.components, + world, + renderer, + ); + for i in 0..self.components.len() { if !state.components.get(i) && state.last_components.get(i) { let components = self.components.get_mut(i).and_then(|v| v.as_mut()).unwrap(); components.remove(entity.id); @@ -230,7 +276,7 @@ impl Manager { return Entity { id, generation: entity.1, - } + }; } let id = self.entities.len(); self.entities.push(( @@ -239,12 +285,9 @@ impl Manager { components: BSet::new(self.num_components), removed: false, }), - 0 + 0, )); - Entity { - id, - generation: 0, - } + Entity { id, generation: 0 } } /// Deallocates an entity and frees its components @@ -257,12 +300,16 @@ impl Manager { } /// Deallocates all entities/components excluding the world entity - pub fn remove_all_entities(&mut self, world: &mut world::World, renderer: &mut render::Renderer) { + pub fn remove_all_entities( + &mut self, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { for (id, e) in self.entities[1..].iter_mut().enumerate() { if let Some(set) = e.0.as_mut() { set.components = BSet::new(self.components.len()); set.removed = true; - self.changed_entity_components.insert(Entity{ + self.changed_entity_components.insert(Entity { id: id + 1, generation: e.1, }); @@ -312,7 +359,13 @@ impl Manager { } let mut e = self.entities.get_mut(entity.id); let set = match e { - Some(ref mut val) => if val.1 == entity.generation { &mut val.0 } else { panic!("Missing entity") }, + Some(ref mut val) => { + if val.1 == entity.generation { + &mut val.0 + } else { + panic!("Missing entity") + } + } None => panic!("Missing entity"), }; let set = match set.as_mut() { @@ -327,24 +380,44 @@ impl Manager { } set.components.set(key.id, true); self.changed_entity_components.insert(entity); - let components = self.components.get_mut(key.id).and_then(|v| v.as_mut()).unwrap(); + let components = self + .components + .get_mut(key.id) + .and_then(|v| v.as_mut()) + .unwrap(); components.add(entity.id, val); } - fn trigger_add_for_systems(&mut self, e: Entity, old_set: &BSet, new_set: &BSet, world: &mut world::World, renderer: &mut render::Renderer) { + fn trigger_add_for_systems( + &mut self, + e: Entity, + old_set: &BSet, + new_set: &BSet, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { let mut systems = self.systems.take().unwrap(); for sys in &mut systems { - if new_set.includes_set(&sys.filter().bits) && !old_set.includes_set(&sys.filter().bits) { + if new_set.includes_set(&sys.filter().bits) && !old_set.includes_set(&sys.filter().bits) + { sys.entity_added(self, e, world, renderer); } } self.systems = Some(systems); } - fn trigger_add_for_render_systems(&mut self, e: Entity, old_set: &BSet, new_set: &BSet, world: &mut world::World, renderer: &mut render::Renderer) { + fn trigger_add_for_render_systems( + &mut self, + e: Entity, + old_set: &BSet, + new_set: &BSet, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { let mut systems = self.render_systems.take().unwrap(); for sys in &mut systems { - if new_set.includes_set(&sys.filter().bits) && !old_set.includes_set(&sys.filter().bits) { + if new_set.includes_set(&sys.filter().bits) && !old_set.includes_set(&sys.filter().bits) + { sys.entity_added(self, e, world, renderer); } } @@ -371,7 +444,13 @@ impl Manager { } let mut e = self.entities.get_mut(entity.id); let set = match e { - Some(ref mut val) => if val.1 == entity.generation { &mut val.0 } else { panic!("Missing entity") }, + Some(ref mut val) => { + if val.1 == entity.generation { + &mut val.0 + } else { + panic!("Missing entity") + } + } None => panic!("Missing entity"), }; let set = match set.as_mut() { @@ -382,7 +461,7 @@ impl Manager { panic!("Double change within a single tick"); } if !set.components.get(key.id) { - return false + return false; } set.components.set(key.id, false); self.changed_entity_components.insert(entity); @@ -390,20 +469,36 @@ impl Manager { true } - fn trigger_remove_for_systems(&mut self, e: Entity, old_set: &BSet, new_set: &BSet, world: &mut world::World, renderer: &mut render::Renderer) { + fn trigger_remove_for_systems( + &mut self, + e: Entity, + old_set: &BSet, + new_set: &BSet, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { let mut systems = self.systems.take().unwrap(); for sys in &mut systems { - if !new_set.includes_set(&sys.filter().bits) && old_set.includes_set(&sys.filter().bits) { + if !new_set.includes_set(&sys.filter().bits) && old_set.includes_set(&sys.filter().bits) + { sys.entity_removed(self, e, world, renderer); } } self.systems = Some(systems); } - fn trigger_remove_for_render_systems(&mut self, e: Entity, old_set: &BSet, new_set: &BSet, world: &mut world::World, renderer: &mut render::Renderer) { + fn trigger_remove_for_render_systems( + &mut self, + e: Entity, + old_set: &BSet, + new_set: &BSet, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { let mut systems = self.render_systems.take().unwrap(); for sys in &mut systems { - if !new_set.includes_set(&sys.filter().bits) && old_set.includes_set(&sys.filter().bits) { + if !new_set.includes_set(&sys.filter().bits) && old_set.includes_set(&sys.filter().bits) + { sys.entity_removed(self, e, world, renderer); } } @@ -424,7 +519,13 @@ impl Manager { None => return None, }; let set = match self.entities.get(entity.id).as_ref() { - Some(val) => if val.1 == entity.generation { &val.0 } else { return None }, + Some(val) => { + if val.1 == entity.generation { + &val.0 + } else { + return None; + } + } None => return None, }; if !set.as_ref().map_or(false, |v| v.components.get(key.id)) { @@ -442,13 +543,23 @@ impl Manager { } /// Returns the given component that the key points to if it exists. - pub fn get_component_mut<'a, 'b: 'a, T>(&'a mut self, entity: Entity, key: Key) -> Option<&'b mut T> { + pub fn get_component_mut<'a, 'b: 'a, T>( + &'a mut self, + entity: Entity, + key: Key, + ) -> Option<&'b mut T> { let components = match self.components.get_mut(key.id).and_then(|v| v.as_mut()) { Some(val) => val, None => return None, }; let set = match self.entities.get(entity.id).as_ref() { - Some(val) => if val.1 == entity.generation { &val.0 } else { return None }, + Some(val) => { + if val.1 == entity.generation { + &val.0 + } else { + return None; + } + } None => return None, }; if !set.as_ref().map_or(false, |v| v.components.get(key.id)) { @@ -460,7 +571,10 @@ impl Manager { /// Same as `get_component_mut` but doesn't require a key. Using a key /// is better for frequent lookups. - pub fn get_component_mut_direct<'a, 'b: 'a, T: Any>(&'a mut self, entity: Entity) -> Option<&'b mut T> { + pub fn get_component_mut_direct<'a, 'b: 'a, T: Any>( + &'a mut self, + entity: Entity, + ) -> Option<&'b mut T> { let key = self.get_key(); self.get_component_mut(entity, key) } @@ -479,12 +593,10 @@ impl ComponentMem { ComponentMem { data: vec![], component_size: mem::size_of::(), - drop_func: Box::new(|data| { - unsafe { - let mut val: T = mem::MaybeUninit::uninit().assume_init(); - ptr::copy(data as *mut T, &mut val, 1); - mem::drop(val); - } + drop_func: Box::new(|data| unsafe { + let mut val: T = mem::MaybeUninit::uninit().assume_init(); + ptr::copy(data as *mut T, &mut val, 1); + mem::drop(val); }), } } @@ -496,7 +608,11 @@ impl ComponentMem { let idx = index / COMPONENTS_PER_BLOCK; let rem = index % COMPONENTS_PER_BLOCK; if self.data[idx].is_none() { - self.data[idx] = Some((vec![0; self.component_size * COMPONENTS_PER_BLOCK], BSet::new(COMPONENTS_PER_BLOCK), 0)); + self.data[idx] = Some(( + vec![0; self.component_size * COMPONENTS_PER_BLOCK], + BSet::new(COMPONENTS_PER_BLOCK), + 0, + )); } let data = self.data[idx].as_mut().unwrap(); let start = rem * self.component_size; @@ -518,7 +634,9 @@ impl ComponentMem { // We don't have access to the actual type in this method so // we use the drop_func which stores the type in its closure // to handle the dropping for us. - unsafe { (self.drop_func)(data.0.as_mut_ptr().offset(start as isize)); } + unsafe { + (self.drop_func)(data.0.as_mut_ptr().offset(start as isize)); + } data.2 -= 1; data.2 }; @@ -532,9 +650,7 @@ impl ComponentMem { let rem = index % COMPONENTS_PER_BLOCK; let data = self.data[idx].as_ref().unwrap(); let start = rem * self.component_size; - unsafe { - &*(data.0.as_ptr().offset(start as isize) as *const T) - } + unsafe { &*(data.0.as_ptr().offset(start as isize) as *const T) } } fn get_mut(&mut self, index: usize) -> &mut T { @@ -542,9 +658,7 @@ impl ComponentMem { let rem = index % COMPONENTS_PER_BLOCK; let data = self.data[idx].as_mut().unwrap(); let start = rem * self.component_size; - unsafe { - &mut *(data.0.as_mut_ptr().offset(start as isize) as *mut T) - } + unsafe { &mut *(data.0.as_mut_ptr().offset(start as isize) as *mut T) } } } @@ -552,10 +666,12 @@ impl Drop for ComponentMem { fn drop(&mut self) { for data in &mut self.data { if let Some(data) = data.as_mut() { - for i in 0 .. COMPONENTS_PER_BLOCK { + for i in 0..COMPONENTS_PER_BLOCK { if data.1.get(i) { let start = i * self.component_size; - unsafe { (self.drop_func)(data.0.as_mut_ptr().offset(start as isize)); } + unsafe { + (self.drop_func)(data.0.as_mut_ptr().offset(start as isize)); + } } } } diff --git a/src/entity/block_entity/mod.rs b/src/entity/block_entity/mod.rs index 9a1b55b8..82305aed 100644 --- a/src/entity/block_entity/mod.rs +++ b/src/entity/block_entity/mod.rs @@ -1,22 +1,21 @@ - pub mod sign; -use crate::world::block::Block; -use crate::shared::Position; use crate::ecs; +use crate::shared::Position; +use crate::world::block::Block; pub fn add_systems(m: &mut ecs::Manager) { sign::add_systems(m); } pub enum BlockEntityType { - Sign + Sign, } impl BlockEntityType { pub fn get_block_entity(bl: Block) -> Option { match bl { - Block::StandingSign{..} | Block::WallSign{..} => Some(BlockEntityType::Sign), + Block::StandingSign { .. } | Block::WallSign { .. } => Some(BlockEntityType::Sign), _ => None, } } diff --git a/src/entity/block_entity/sign.rs b/src/entity/block_entity/sign.rs index 8171fbf6..eaf650ad 100644 --- a/src/entity/block_entity/sign.rs +++ b/src/entity/block_entity/sign.rs @@ -1,11 +1,10 @@ - use crate::ecs; use crate::format::{self, Component}; +use crate::render; +use crate::render::model::{self, FormatState}; use crate::shared::{Direction, Position}; use crate::world; use crate::world::block::Block; -use crate::render; -use crate::render::model::{self, FormatState}; pub fn add_systems(m: &mut ecs::Manager) { let sys = SignRenderer::new(m); @@ -13,21 +12,24 @@ pub fn add_systems(m: &mut ecs::Manager) { } pub fn init_entity(m: &mut ecs::Manager, e: ecs::Entity) { - m.add_component_direct(e, SignInfo { - model: None, - lines: [ - Component::Text(format::TextComponent::new("")), - Component::Text(format::TextComponent::new("")), - Component::Text(format::TextComponent::new("")), - Component::Text(format::TextComponent::new("")), - ], - offset_x: 0.0, - offset_y: 0.0, - offset_z: 0.0, - has_stand: false, - rotation: 0.0, - dirty: false, - }); + m.add_component_direct( + e, + SignInfo { + model: None, + lines: [ + Component::Text(format::TextComponent::new("")), + Component::Text(format::TextComponent::new("")), + Component::Text(format::TextComponent::new("")), + Component::Text(format::TextComponent::new("")), + ], + offset_x: 0.0, + offset_y: 0.0, + offset_z: 0.0, + has_stand: false, + rotation: 0.0, + dirty: false, + }, + ); } pub struct SignInfo { @@ -54,9 +56,7 @@ impl SignRenderer { let sign_info = m.get_key(); let position = m.get_key(); SignRenderer { - filter: ecs::Filter::new() - .with(position) - .with(sign_info), + filter: ecs::Filter::new().with(position).with(sign_info), position, sign_info, } @@ -64,12 +64,16 @@ impl SignRenderer { } impl ecs::System for SignRenderer { - fn filter(&self) -> &ecs::Filter { &self.filter } - fn update(&mut self, m: &mut ecs::Manager, world: &mut world::World, renderer: &mut render::Renderer) { + fn update( + &mut self, + m: &mut ecs::Manager, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { for e in m.find(&self.filter) { let position = *m.get_component(e, self.position).unwrap(); let info = m.get_component_mut(e, self.sign_info).unwrap(); @@ -85,24 +89,30 @@ impl ecs::System for SignRenderer { } } - fn entity_added(&mut self, m: &mut ecs::Manager, e: ecs::Entity, world: &mut world::World, renderer: &mut render::Renderer) { + fn entity_added( + &mut self, + m: &mut ecs::Manager, + e: ecs::Entity, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { + use cgmath::{Decomposed, Matrix4, Quaternion, Rad, Rotation3, Vector3}; use std::f64::consts::PI; - use cgmath::{Vector3, Matrix4, Decomposed, Rotation3, Rad, Quaternion}; let position = *m.get_component(e, self.position).unwrap(); let info = m.get_component_mut(e, self.sign_info).unwrap(); info.dirty = false; match world.get_block(position) { - Block::WallSign{facing, ..} => { + Block::WallSign { facing, .. } => { info.offset_z = 7.5 / 16.0; match facing { - Direction::North => {}, + Direction::North => {} Direction::South => info.rotation = PI, Direction::West => info.rotation = PI / 2.0, Direction::East => info.rotation = -PI / 2.0, _ => unreachable!(), } - }, - Block::StandingSign{rotation, ..} => { + } + Block::StandingSign { rotation, .. } => { info.offset_y = 5.0 / 16.0; info.has_stand = true; info.rotation = -(rotation.data() as f64 / 16.0) * PI * 2.0 + PI; @@ -112,30 +122,48 @@ impl ecs::System for SignRenderer { let tex = render::Renderer::get_texture(renderer.get_textures_ref(), "entity/sign"); macro_rules! rel { - ($x:expr, $y:expr, $w:expr, $h:expr) => ( + ($x:expr, $y:expr, $w:expr, $h:expr) => { Some(tex.relative(($x) / 64.0, ($y) / 32.0, ($w) / 64.0, ($h) / 32.0)) - ); + }; } let mut verts = vec![]; // Backboard - model::append_box(&mut verts, -0.5, -4.0/16.0, -0.5/16.0, 1.0, 8.0/16.0, 1.0/16.0, [ - rel!(26.0, 0.0, 24.0, 2.0), // Down - rel!(2.0, 0.0, 24.0, 2.0), // Up - rel!(2.0, 2.0, 24.0, 12.0), // North - rel!(26.0, 2.0, 24.0, 12.0), // South - rel!(0.0, 2.0, 2.0, 12.0), // West - rel!(50.0, 2.0, 2.0, 12.0), // East - ]); + model::append_box( + &mut verts, + -0.5, + -4.0 / 16.0, + -0.5 / 16.0, + 1.0, + 8.0 / 16.0, + 1.0 / 16.0, + [ + rel!(26.0, 0.0, 24.0, 2.0), // Down + rel!(2.0, 0.0, 24.0, 2.0), // Up + rel!(2.0, 2.0, 24.0, 12.0), // North + rel!(26.0, 2.0, 24.0, 12.0), // South + rel!(0.0, 2.0, 2.0, 12.0), // West + rel!(50.0, 2.0, 2.0, 12.0), // East + ], + ); if info.has_stand { - model::append_box(&mut verts, -0.5/16.0, -0.25-9.0/16.0, -0.5/16.0, 1.0/16.0, 9.0/16.0, 1.0/16.0, [ - rel!(4.0, 14.0, 2.0, 2.0), // Down - rel!(2.0, 14.0, 2.0, 2.0), // Up - rel!(2.0, 16.0, 2.0, 12.0), // North - rel!(6.0, 16.0, 2.0, 12.0), // South - rel!(0.0, 16.0, 2.0, 12.0), // West - rel!(4.0, 16.0, 2.0, 12.0), // East - ]); + model::append_box( + &mut verts, + -0.5 / 16.0, + -0.25 - 9.0 / 16.0, + -0.5 / 16.0, + 1.0 / 16.0, + 9.0 / 16.0, + 1.0 / 16.0, + [ + rel!(4.0, 14.0, 2.0, 2.0), // Down + rel!(2.0, 14.0, 2.0, 2.0), // Up + rel!(2.0, 16.0, 2.0, 12.0), // North + rel!(6.0, 16.0, 2.0, 12.0), // South + rel!(0.0, 16.0, 2.0, 12.0), // West + rel!(4.0, 16.0, 2.0, 12.0), // East + ], + ); } for (i, line) in info.lines.iter().enumerate() { @@ -154,15 +182,12 @@ impl ecs::System for SignRenderer { // Center align text for vert in &mut state.text { vert.x += width * 0.5; - vert.y -= (Y_SCALE + 0.4/16.0) * (i as f32); + vert.y -= (Y_SCALE + 0.4 / 16.0) * (i as f32); } verts.extend_from_slice(&state.text); } - let model = renderer.model.create_model( - model::DEFAULT, - vec![verts] - ); + let model = renderer.model.create_model(model::DEFAULT, vec![verts]); { let mdl = renderer.model.get_model(model).unwrap(); @@ -173,14 +198,28 @@ impl ecs::System for SignRenderer { mdl.matrix[0] = Matrix4::from(Decomposed { scale: 1.0, rot: Quaternion::from_angle_y(Rad(info.rotation as f32)), - disp: Vector3::new(position.x as f32 + 0.5, -position.y as f32 - 0.5, position.z as f32 + 0.5), - }) * Matrix4::from_translation(Vector3::new(info.offset_x as f32, -info.offset_y as f32, info.offset_z as f32)); + disp: Vector3::new( + position.x as f32 + 0.5, + -position.y as f32 - 0.5, + position.z as f32 + 0.5, + ), + }) * Matrix4::from_translation(Vector3::new( + info.offset_x as f32, + -info.offset_y as f32, + info.offset_z as f32, + )); } info.model = Some(model); } - fn entity_removed(&mut self, m: &mut ecs::Manager, e: ecs::Entity, _: &mut world::World, renderer: &mut render::Renderer) { + fn entity_removed( + &mut self, + m: &mut ecs::Manager, + e: ecs::Entity, + _: &mut world::World, + renderer: &mut render::Renderer, + ) { let info = m.get_component_mut(e, self.sign_info).unwrap(); if let Some(model) = info.model { renderer.model.remove_model(model); diff --git a/src/entity/mod.rs b/src/entity/mod.rs index 8b5f4323..d5c80bfc 100644 --- a/src/entity/mod.rs +++ b/src/entity/mod.rs @@ -1,6 +1,5 @@ - -pub mod player; pub mod block_entity; +pub mod player; use crate::ecs; use cgmath::Vector3; @@ -96,10 +95,7 @@ pub struct Rotation { impl Rotation { pub fn new(yaw: f64, pitch: f64) -> Rotation { - Rotation { - yaw, - pitch, - } + Rotation { yaw, pitch } } pub fn zero() -> Rotation { @@ -114,10 +110,7 @@ pub struct TargetRotation { impl TargetRotation { pub fn new(yaw: f64, pitch: f64) -> TargetRotation { - TargetRotation { - yaw, - pitch, - } + TargetRotation { yaw, pitch } } pub fn zero() -> TargetRotation { @@ -131,7 +124,9 @@ pub struct Gravity { } impl Gravity { - pub fn new() -> Gravity { Default::default() } + pub fn new() -> Gravity { + Default::default() + } } pub struct Bounds { @@ -140,9 +135,7 @@ pub struct Bounds { impl Bounds { pub fn new(bounds: Aabb3) -> Bounds { - Bounds { - bounds, - } + Bounds { bounds } } } @@ -152,7 +145,9 @@ pub struct GameInfo { } impl GameInfo { - pub fn new() -> GameInfo { Default::default() } + pub fn new() -> GameInfo { + Default::default() + } } #[derive(Default)] @@ -162,5 +157,7 @@ pub struct Light { } impl Light { - pub fn new() -> Light { Default::default() } + pub fn new() -> Light { + Default::default() + } } diff --git a/src/entity/player.rs b/src/entity/player.rs index 4e424700..997115fd 100644 --- a/src/entity/player.rs +++ b/src/entity/player.rs @@ -1,29 +1,20 @@ - -use crate::ecs; use super::{ - Position, - TargetPosition, - Velocity, - Rotation, - TargetRotation, - Gravity, - Bounds, - GameInfo, - Light + Bounds, GameInfo, Gravity, Light, Position, Rotation, TargetPosition, TargetRotation, Velocity, }; -use crate::world; +use crate::ecs; +use crate::format; use crate::render; use crate::render::model::{self, FormatState}; +use crate::settings::Stevenkey; +use crate::shared::Position as BPosition; +use crate::types::hash::FNVHash; use crate::types::Gamemode; +use crate::world; +use cgmath::{self, Decomposed, Matrix4, Point3, Quaternion, Rad, Rotation3, Vector3}; use collision::{Aabb, Aabb3}; -use cgmath::{self, Point3, Vector3, Matrix4, Decomposed, Rotation3, Rad, Quaternion}; use std::collections::HashMap; use std::hash::BuildHasherDefault; use std::time::Instant; -use crate::types::hash::FNVHash; -use crate::settings::Stevenkey; -use crate::shared::Position as BPosition; -use crate::format; pub fn add_systems(m: &mut ecs::Manager) { let sys = MovementHandler::new(m); @@ -43,10 +34,13 @@ pub fn create_local(m: &mut ecs::Manager) -> ecs::Entity { m.add_component_direct(entity, Gamemode::Survival); m.add_component_direct(entity, Gravity::new()); m.add_component_direct(entity, PlayerMovement::new()); - m.add_component_direct(entity, Bounds::new(Aabb3::new( - Point3::new(-0.3, 0.0, -0.3), - Point3::new(0.3, 1.8, 0.3) - ))); + m.add_component_direct( + entity, + Bounds::new(Aabb3::new( + Point3::new(-0.3, 0.0, -0.3), + Point3::new(0.3, 1.8, 0.3), + )), + ); m.add_component_direct(entity, PlayerModel::new("", false, false, true)); m.add_component_direct(entity, Light::new()); entity @@ -59,16 +53,18 @@ pub fn create_remote(m: &mut ecs::Manager, name: &str) -> ecs::Entity { m.add_component_direct(entity, Rotation::new(0.0, 0.0)); m.add_component_direct(entity, TargetRotation::new(0.0, 0.0)); m.add_component_direct(entity, Velocity::new(0.0, 0.0, 0.0)); - m.add_component_direct(entity, Bounds::new(Aabb3::new( - Point3::new(-0.3, 0.0, -0.3), - Point3::new(0.3, 1.8, 0.3) - ))); + m.add_component_direct( + entity, + Bounds::new(Aabb3::new( + Point3::new(-0.3, 0.0, -0.3), + Point3::new(0.3, 1.8, 0.3), + )), + ); m.add_component_direct(entity, PlayerModel::new(name, true, true, false)); m.add_component_direct(entity, Light::new()); entity } - pub struct PlayerModel { model: Option, skin_url: Option, @@ -155,16 +151,23 @@ enum PlayerModelPart { // TODO: Setup culling impl ecs::System for PlayerRenderer { - fn filter(&self) -> &ecs::Filter { &self.filter } - fn update(&mut self, m: &mut ecs::Manager, world: &mut world::World, renderer: &mut render::Renderer) { + fn update( + &mut self, + m: &mut ecs::Manager, + world: &mut world::World, + renderer: &mut render::Renderer, + ) { use std::f32::consts::PI; use std::f64::consts::PI as PI64; let world_entity = m.get_world(); - let delta = m.get_component_mut(world_entity, self.game_info).unwrap().delta; + let delta = m + .get_component_mut(world_entity, self.game_info) + .unwrap() + .delta; for e in m.find(&self.filter) { let player_model = m.get_component_mut(e, self.player_model).unwrap(); let position = m.get_component_mut(e, self.position).unwrap(); @@ -183,8 +186,8 @@ impl ecs::System for PlayerRenderer { mdl.sky_light = light.sky_light; let offset = if player_model.first_person { - let ox = (rotation.yaw - PI64/2.0).cos() * 0.25; - let oz = -(rotation.yaw - PI64/2.0).sin() * 0.25; + let ox = (rotation.yaw - PI64 / 2.0).cos() * 0.25; + let oz = -(rotation.yaw - PI64 / 2.0).sin() * 0.25; Vector3::new( position.position.x as f32 - ox as f32, -position.position.y as f32, @@ -205,24 +208,28 @@ impl ecs::System for PlayerRenderer { // TODO This sucks if player_model.has_name_tag { - let ang = (position.position.x - renderer.camera.pos.x).atan2(position.position.z - renderer.camera.pos.z) as f32; + let ang = (position.position.x - renderer.camera.pos.x) + .atan2(position.position.z - renderer.camera.pos.z) + as f32; mdl.matrix[PlayerModelPart::NameTag as usize] = Matrix4::from(Decomposed { scale: 1.0, rot: Quaternion::from_angle_y(Rad(ang)), - disp: offset + Vector3::new(0.0, (-24.0/16.0) - 0.6, 0.0), + disp: offset + Vector3::new(0.0, (-24.0 / 16.0) - 0.6, 0.0), }); } - mdl.matrix[PlayerModelPart::Head as usize] = offset_matrix * Matrix4::from(Decomposed { - scale: 1.0, - rot: Quaternion::from_angle_x(Rad(-rotation.pitch as f32)), - disp: Vector3::new(0.0, -12.0/16.0 - 12.0/16.0, 0.0), - }); - mdl.matrix[PlayerModelPart::Body as usize] = offset_matrix * Matrix4::from(Decomposed { - scale: 1.0, - rot: Quaternion::from_angle_x(Rad(0.0)), - disp: Vector3::new(0.0, -12.0/16.0 - 6.0/16.0, 0.0), - }); + mdl.matrix[PlayerModelPart::Head as usize] = offset_matrix + * Matrix4::from(Decomposed { + scale: 1.0, + rot: Quaternion::from_angle_x(Rad(-rotation.pitch as f32)), + disp: Vector3::new(0.0, -12.0 / 16.0 - 12.0 / 16.0, 0.0), + }); + mdl.matrix[PlayerModelPart::Body as usize] = offset_matrix + * Matrix4::from(Decomposed { + scale: 1.0, + rot: Quaternion::from_angle_x(Rad(0.0)), + disp: Vector3::new(0.0, -12.0 / 16.0 - 6.0 / 16.0, 0.0), + }); let mut time = player_model.time; let mut dir = player_model.dir; @@ -232,16 +239,18 @@ impl ecs::System for PlayerRenderer { } let ang = ((time / 15.0) - 1.0) * (PI64 / 4.0); - mdl.matrix[PlayerModelPart::LegRight as usize] = offset_matrix * Matrix4::from(Decomposed { - scale: 1.0, - rot: Quaternion::from_angle_x(Rad(ang as f32)), - disp: Vector3::new(2.0/16.0, -12.0/16.0, 0.0), - }); - mdl.matrix[PlayerModelPart::LegLeft as usize] = offset_matrix * Matrix4::from(Decomposed { - scale: 1.0, - rot: Quaternion::from_angle_x(Rad(-ang as f32)), - disp: Vector3::new(-2.0/16.0, -12.0/16.0, 0.0), - }); + mdl.matrix[PlayerModelPart::LegRight as usize] = offset_matrix + * Matrix4::from(Decomposed { + scale: 1.0, + rot: Quaternion::from_angle_x(Rad(ang as f32)), + disp: Vector3::new(2.0 / 16.0, -12.0 / 16.0, 0.0), + }); + mdl.matrix[PlayerModelPart::LegLeft as usize] = offset_matrix + * Matrix4::from(Decomposed { + scale: 1.0, + rot: Quaternion::from_angle_x(Rad(-ang as f32)), + disp: Vector3::new(-2.0 / 16.0, -12.0 / 16.0, 0.0), + }); let mut i_time = player_model.idle_time; i_time += delta * 0.02; @@ -256,17 +265,31 @@ impl ecs::System for PlayerRenderer { player_model.arm_time -= delta; } - mdl.matrix[PlayerModelPart::ArmRight as usize] = offset_matrix * Matrix4::from_translation( - Vector3::new(6.0/16.0, -12.0/16.0-12.0/16.0, 0.0) - ) * Matrix4::from(Quaternion::from_angle_x(Rad(-(ang * 0.75) as f32))) - * Matrix4::from(Quaternion::from_angle_z(Rad((i_time.cos() * 0.06 - 0.06) as f32))) - * Matrix4::from(Quaternion::from_angle_x(Rad((i_time.sin() * 0.06 - ((7.5 - (player_model.arm_time-7.5).abs()) / 7.5)) as f32))); - - mdl.matrix[PlayerModelPart::ArmLeft as usize] = offset_matrix * Matrix4::from_translation( - Vector3::new(-6.0/16.0, -12.0/16.0-12.0/16.0, 0.0) - ) * Matrix4::from(Quaternion::from_angle_x(Rad((ang * 0.75) as f32))) - * Matrix4::from(Quaternion::from_angle_z(Rad(-(i_time.cos() * 0.06 - 0.06) as f32))) - * Matrix4::from(Quaternion::from_angle_x(Rad(-(i_time.sin() * 0.06) as f32))); + mdl.matrix[PlayerModelPart::ArmRight as usize] = offset_matrix + * Matrix4::from_translation(Vector3::new( + 6.0 / 16.0, + -12.0 / 16.0 - 12.0 / 16.0, + 0.0, + )) + * Matrix4::from(Quaternion::from_angle_x(Rad(-(ang * 0.75) as f32))) + * Matrix4::from(Quaternion::from_angle_z(Rad( + (i_time.cos() * 0.06 - 0.06) as f32 + ))) + * Matrix4::from(Quaternion::from_angle_x(Rad((i_time.sin() * 0.06 + - ((7.5 - (player_model.arm_time - 7.5).abs()) / 7.5)) + as f32))); + + mdl.matrix[PlayerModelPart::ArmLeft as usize] = offset_matrix + * Matrix4::from_translation(Vector3::new( + -6.0 / 16.0, + -12.0 / 16.0 - 12.0 / 16.0, + 0.0, + )) + * Matrix4::from(Quaternion::from_angle_x(Rad((ang * 0.75) as f32))) + * Matrix4::from(Quaternion::from_angle_z(Rad( + -(i_time.cos() * 0.06 - 0.06) as f32 + ))) + * Matrix4::from(Quaternion::from_angle_x(Rad(-(i_time.sin() * 0.06) as f32))); let mut update = true; if position.moved { @@ -297,7 +320,13 @@ impl ecs::System for PlayerRenderer { } } - fn entity_added(&mut self, m: &mut ecs::Manager, e: ecs::Entity, _: &mut world::World, renderer: &mut render::Renderer) { + fn entity_added( + &mut self, + m: &mut ecs::Manager, + e: ecs::Entity, + _: &mut world::World, + renderer: &mut render::Renderer, + ) { let player_model = m.get_component_mut(e, self.player_model).unwrap(); player_model.dirty = false; @@ -309,76 +338,133 @@ impl ecs::System for PlayerRenderer { }; macro_rules! srel { - ($x:expr, $y:expr, $w:expr, $h:expr) => ( + ($x:expr, $y:expr, $w:expr, $h:expr) => { Some(skin.relative(($x) / 64.0, ($y) / 64.0, ($w) / 64.0, ($h) / 64.0)) - ); + }; } let mut head_verts = vec![]; if player_model.has_head { - model::append_box(&mut head_verts, -4.0/16.0, 0.0, -4.0/16.0, 8.0/16.0, 8.0/16.0, 8.0/16.0, [ - srel!(16.0, 0.0, 8.0, 8.0), // Down - srel!(8.0, 0.0, 8.0, 8.0), // Up - srel!(8.0, 8.0, 8.0, 8.0), // North - srel!(24.0, 8.0, 8.0, 8.0), // South - srel!(16.0, 8.0, 8.0, 8.0), // West - srel!(0.0, 8.0, 8.0, 8.0), // East - ]); - model::append_box(&mut head_verts, -4.2/16.0, -0.2/16.0, -4.2/16.0, 8.4/16.0, 8.4/16.0, 8.4/16.0, [ - srel!((16.0 + 32.0), 0.0, 8.0, 8.0), // Down - srel!((8.0 + 32.0), 0.0, 8.0, 8.0), // Up - srel!((8.0 + 32.0), 8.0, 8.0, 8.0), // North - srel!((24.0 + 32.0), 8.0, 8.0, 8.0), // South - srel!((16.0 + 32.0), 8.0, 8.0, 8.0), // West - srel!((0.0 + 32.0), 8.0, 8.0, 8.0), // East - ]); + model::append_box( + &mut head_verts, + -4.0 / 16.0, + 0.0, + -4.0 / 16.0, + 8.0 / 16.0, + 8.0 / 16.0, + 8.0 / 16.0, + [ + srel!(16.0, 0.0, 8.0, 8.0), // Down + srel!(8.0, 0.0, 8.0, 8.0), // Up + srel!(8.0, 8.0, 8.0, 8.0), // North + srel!(24.0, 8.0, 8.0, 8.0), // South + srel!(16.0, 8.0, 8.0, 8.0), // West + srel!(0.0, 8.0, 8.0, 8.0), // East + ], + ); + model::append_box( + &mut head_verts, + -4.2 / 16.0, + -0.2 / 16.0, + -4.2 / 16.0, + 8.4 / 16.0, + 8.4 / 16.0, + 8.4 / 16.0, + [ + srel!((16.0 + 32.0), 0.0, 8.0, 8.0), // Down + srel!((8.0 + 32.0), 0.0, 8.0, 8.0), // Up + srel!((8.0 + 32.0), 8.0, 8.0, 8.0), // North + srel!((24.0 + 32.0), 8.0, 8.0, 8.0), // South + srel!((16.0 + 32.0), 8.0, 8.0, 8.0), // West + srel!((0.0 + 32.0), 8.0, 8.0, 8.0), // East + ], + ); } // TODO: Cape let mut body_verts = vec![]; - model::append_box(&mut body_verts, -4.0/16.0, -6.0/16.0, -2.0/16.0, 8.0/16.0, 12.0/16.0, 4.0/16.0, [ - srel!(28.0, 16.0, 8.0, 4.0), // Down - srel!(20.0, 16.0, 8.0, 4.0), // Up - srel!(20.0, 20.0, 8.0, 12.0), // North - srel!(32.0, 20.0, 8.0, 12.0), // South - srel!(16.0, 20.0, 4.0, 12.0), // West - srel!(28.0, 20.0, 4.0, 12.0), // East - ]); - model::append_box(&mut body_verts, -4.2/16.0, -6.2/16.0, -2.2/16.0, 8.4/16.0, 12.4/16.0, 4.4/16.0, [ - srel!(28.0, 16.0 + 16.0, 8.0, 4.0), // Down - srel!(20.0, 16.0 + 16.0, 8.0, 4.0), // Up - srel!(20.0, 20.0 + 16.0, 8.0, 12.0), // North - srel!(32.0, 20.0 + 16.0, 8.0, 12.0), // South - srel!(16.0, 20.0 + 16.0, 4.0, 12.0), // West - srel!(28.0, 20.0 + 16.0, 4.0, 12.0), // East - ]); + model::append_box( + &mut body_verts, + -4.0 / 16.0, + -6.0 / 16.0, + -2.0 / 16.0, + 8.0 / 16.0, + 12.0 / 16.0, + 4.0 / 16.0, + [ + srel!(28.0, 16.0, 8.0, 4.0), // Down + srel!(20.0, 16.0, 8.0, 4.0), // Up + srel!(20.0, 20.0, 8.0, 12.0), // North + srel!(32.0, 20.0, 8.0, 12.0), // South + srel!(16.0, 20.0, 4.0, 12.0), // West + srel!(28.0, 20.0, 4.0, 12.0), // East + ], + ); + model::append_box( + &mut body_verts, + -4.2 / 16.0, + -6.2 / 16.0, + -2.2 / 16.0, + 8.4 / 16.0, + 12.4 / 16.0, + 4.4 / 16.0, + [ + srel!(28.0, 16.0 + 16.0, 8.0, 4.0), // Down + srel!(20.0, 16.0 + 16.0, 8.0, 4.0), // Up + srel!(20.0, 20.0 + 16.0, 8.0, 12.0), // North + srel!(32.0, 20.0 + 16.0, 8.0, 12.0), // South + srel!(16.0, 20.0 + 16.0, 4.0, 12.0), // West + srel!(28.0, 20.0 + 16.0, 4.0, 12.0), // East + ], + ); let mut part_verts = vec![vec![]; 4]; for (i, offsets) in [ - [16.0, 48.0, 0.0, 48.0], // Left left - [0.0, 16.0, 0.0, 32.0], // Right Leg + [16.0, 48.0, 0.0, 48.0], // Left left + [0.0, 16.0, 0.0, 32.0], // Right Leg [32.0, 48.0, 48.0, 48.0], // Left arm [40.0, 16.0, 40.0, 32.0], // Right arm - ].iter().enumerate() { + ] + .iter() + .enumerate() + { let (ox, oy) = (offsets[0], offsets[1]); - model::append_box(&mut part_verts[i], -2.0/16.0, -12.0/16.0, -2.0/16.0, 4.0/16.0, 12.0/16.0, 4.0/16.0, [ - srel!(ox + 8.0, oy + 0.0, 4.0, 4.0), // Down - srel!(ox + 4.0, oy + 0.0, 4.0, 4.0), // Up - srel!(ox + 4.0, oy + 4.0, 4.0, 12.0), // North - srel!(ox + 12.0, oy + 4.0, 4.0, 12.0), // South - srel!(ox + 8.0, oy + 4.0, 4.0, 12.0), // West - srel!(ox + 0.0, oy + 4.0, 4.0, 12.0), // East - ]); + model::append_box( + &mut part_verts[i], + -2.0 / 16.0, + -12.0 / 16.0, + -2.0 / 16.0, + 4.0 / 16.0, + 12.0 / 16.0, + 4.0 / 16.0, + [ + srel!(ox + 8.0, oy + 0.0, 4.0, 4.0), // Down + srel!(ox + 4.0, oy + 0.0, 4.0, 4.0), // Up + srel!(ox + 4.0, oy + 4.0, 4.0, 12.0), // North + srel!(ox + 12.0, oy + 4.0, 4.0, 12.0), // South + srel!(ox + 8.0, oy + 4.0, 4.0, 12.0), // West + srel!(ox + 0.0, oy + 4.0, 4.0, 12.0), // East + ], + ); let (ox, oy) = (offsets[2], offsets[3]); - model::append_box(&mut part_verts[i], -2.2/16.0, -12.2/16.0, -2.2/16.0, 4.4/16.0, 12.4/16.0, 4.4/16.0, [ - srel!(ox + 8.0, oy + 0.0, 4.0, 4.0), // Down - srel!(ox + 4.0, oy + 0.0, 4.0, 4.0), // Up - srel!(ox + 4.0, oy + 4.0, 4.0, 12.0), // North - srel!(ox + 12.0, oy + 4.0, 4.0, 12.0), // South - srel!(ox + 8.0, oy + 4.0, 4.0, 12.0), // West - srel!(ox + 0.0, oy + 4.0, 4.0, 12.0), // East - ]); + model::append_box( + &mut part_verts[i], + -2.2 / 16.0, + -12.2 / 16.0, + -2.2 / 16.0, + 4.4 / 16.0, + 12.4 / 16.0, + 4.4 / 16.0, + [ + srel!(ox + 8.0, oy + 0.0, 4.0, 4.0), // Down + srel!(ox + 4.0, oy + 0.0, 4.0, 4.0), // Up + srel!(ox + 4.0, oy + 4.0, 4.0, 12.0), // North + srel!(ox + 12.0, oy + 4.0, 4.0, 12.0), // South + srel!(ox + 8.0, oy + 4.0, 4.0, 12.0), // West + srel!(ox + 0.0, oy + 4.0, 4.0, 12.0), // East + ], + ); } let mut name_verts = vec![]; @@ -423,17 +509,27 @@ impl ecs::System for PlayerRenderer { part_verts[1].clone(), part_verts[2].clone(), part_verts[3].clone(), - name_verts - ] + name_verts, + ], )); } - fn entity_removed(&mut self, m: &mut ecs::Manager, e: ecs::Entity, _: &mut world::World, renderer: &mut render::Renderer) { + fn entity_removed( + &mut self, + m: &mut ecs::Manager, + e: ecs::Entity, + _: &mut world::World, + renderer: &mut render::Renderer, + ) { let player_model = m.get_component_mut(e, self.player_model).unwrap(); if let Some(model) = player_model.model.take() { renderer.model.remove_model(model); if let Some(url) = player_model.skin_url.as_ref() { - renderer.get_textures_ref().read().unwrap().release_skin(url); + renderer + .get_textures_ref() + .read() + .unwrap() + .release_skin(url); } } } @@ -450,12 +546,14 @@ pub struct PlayerMovement { } impl PlayerMovement { - pub fn new() -> PlayerMovement { Default::default() } + pub fn new() -> PlayerMovement { + Default::default() + } fn calculate_movement(&self, player_yaw: f64) -> (f64, f64) { use std::f64::consts::PI; let mut forward = 0.0f64; - let mut yaw = player_yaw - (PI/2.0); + let mut yaw = player_yaw - (PI / 2.0); if self.is_key_pressed(Stevenkey::Forward) || self.is_key_pressed(Stevenkey::Backward) { forward = 1.0; if self.is_key_pressed(Stevenkey::Backward) { @@ -466,7 +564,9 @@ impl PlayerMovement { (PI / 2.0) / (forward.abs() + 1.0) } else if self.is_key_pressed(Stevenkey::Right) { -(PI / 2.0) / (forward.abs() + 1.0) - } else { 0.0 }; + } else { + 0.0 + }; if self.is_key_pressed(Stevenkey::Left) || self.is_key_pressed(Stevenkey::Right) { forward = 1.0; } @@ -521,7 +621,6 @@ impl MovementHandler { } impl ecs::System for MovementHandler { - fn filter(&self) -> &ecs::Filter { &self.filter } @@ -542,8 +641,11 @@ impl ecs::System for MovementHandler { if movement.when_last_jump_pressed.is_none() { movement.when_last_jump_pressed = Some(Instant::now()); if !movement.when_last_jump_released.is_none() { - let dt = movement.when_last_jump_pressed.unwrap() - movement.when_last_jump_released.unwrap(); - if dt.as_secs() == 0 && dt.subsec_millis() <= crate::settings::DOUBLE_JUMP_MS { + let dt = movement.when_last_jump_pressed.unwrap() + - movement.when_last_jump_released.unwrap(); + if dt.as_secs() == 0 + && dt.subsec_millis() <= crate::settings::DOUBLE_JUMP_MS + { movement.want_to_fly = !movement.want_to_fly; //info!("double jump! dt={:?} toggle want_to_fly = {}", dt, movement.want_to_fly); @@ -567,11 +669,16 @@ impl ecs::System for MovementHandler { let mut last_position = position.position; - if world.is_chunk_loaded((position.position.x as i32) >> 4, (position.position.z as i32) >> 4) { + if world.is_chunk_loaded( + (position.position.x as i32) >> 4, + (position.position.z as i32) >> 4, + ) { let (forward, yaw) = movement.calculate_movement(rotation.yaw); let mut speed = if movement.is_key_pressed(Stevenkey::Sprint) { 0.2806 - } else { 0.21585 }; + } else { + 0.21585 + }; if movement.flying { speed *= 2.5; @@ -582,7 +689,8 @@ impl ecs::System for MovementHandler { position.position.y -= speed; } } else if gravity.as_ref().map_or(false, |v| v.on_ground) { - if movement.is_key_pressed(Stevenkey::Jump) && velocity.velocity.y.abs() < 0.001 { + if movement.is_key_pressed(Stevenkey::Jump) && velocity.velocity.y.abs() < 0.001 + { velocity.velocity.y = 0.42; } } else { @@ -604,12 +712,14 @@ impl ecs::System for MovementHandler { // We handle each axis separately to allow for a sliding // effect when pushing up against walls. - let (bounds, xhit) = check_collisions(world, position, &last_position, player_bounds); + let (bounds, xhit) = + check_collisions(world, position, &last_position, player_bounds); position.position.x = bounds.min.x + 0.3; last_position.x = position.position.x; position.position.z = target.z; - let (bounds, zhit) = check_collisions(world, position, &last_position, player_bounds); + let (bounds, zhit) = + check_collisions(world, position, &last_position, player_bounds); position.position.z = bounds.min.z + 0.3; last_position.z = position.position.z; @@ -624,8 +734,12 @@ impl ecs::System for MovementHandler { let mut oz = position.position.z; position.position.x = target.x; position.position.z = target.z; - for offset in 1 .. 9 { - let mini = player_bounds.add_v(cgmath::Vector3::new(0.0, offset as f64 / 16.0, 0.0)); + for offset in 1..9 { + let mini = player_bounds.add_v(cgmath::Vector3::new( + 0.0, + offset as f64 / 16.0, + 0.0, + )); let (_, hit) = check_collisions(world, position, &last_position, mini); if !hit { target.y += offset as f64 / 16.0; @@ -639,7 +753,8 @@ impl ecs::System for MovementHandler { } position.position.y = target.y; - let (bounds, yhit) = check_collisions(world, position, &last_position, player_bounds); + let (bounds, yhit) = + check_collisions(world, position, &last_position, player_bounds); position.position.y = bounds.min.y; last_position.y = position.position.y; if yhit { @@ -647,10 +762,8 @@ impl ecs::System for MovementHandler { } if let Some(gravity) = gravity { - let ground = Aabb3::new( - Point3::new(-0.3, -0.005, -0.3), - Point3::new(0.3, 0.0, 0.3) - ); + let ground = + Aabb3::new(Point3::new(-0.3, -0.005, -0.3), Point3::new(0.3, 0.0, 0.3)); let prev = gravity.on_ground; let (_, hit) = check_collisions(world, position, &last_position, ground); gravity.on_ground = hit; @@ -664,8 +777,12 @@ impl ecs::System for MovementHandler { } } - -fn check_collisions(world: &world::World, position: &mut TargetPosition, last_position: &Vector3, bounds: Aabb3) -> (Aabb3, bool) { +fn check_collisions( + world: &world::World, + position: &mut TargetPosition, + last_position: &Vector3, + bounds: Aabb3, +) -> (Aabb3, bool) { let mut bounds = bounds.add_v(position.position); let dir = position.position - last_position; @@ -678,9 +795,9 @@ fn check_collisions(world: &world::World, position: &mut TargetPosition, last_po let max_z = (bounds.max.z + 1.0) as i32; let mut hit = false; - for y in min_y .. max_y { - for z in min_z .. max_z { - for x in min_x .. max_x { + for y in min_y..max_y { + for z in min_z..max_z { + for x in min_x..max_x { let block = world.get_block(BPosition::new(x, y, z)); if block.get_material().collidable { for bb in block.get_collision_boxes() { @@ -705,14 +822,12 @@ trait Collidable { impl Collidable> for Aabb3 { fn collides(&self, t: &Aabb3) -> bool { - !( - t.min.x >= self.max.x || - t.max.x <= self.min.x || - t.min.y >= self.max.y || - t.max.y <= self.min.y || - t.min.z >= self.max.z || - t.max.z <= self.min.z - ) + !(t.min.x >= self.max.x + || t.max.x <= self.min.x + || t.min.y >= self.max.y + || t.max.y <= self.min.y + || t.min.z >= self.max.z + || t.max.z <= self.min.z) } fn move_out_of(mut self, other: Self, dir: cgmath::Vector3) -> Self { diff --git a/src/entity/systems.rs b/src/entity/systems.rs index 06b9fe10..dbb56ec3 100644 --- a/src/entity/systems.rs +++ b/src/entity/systems.rs @@ -1,9 +1,8 @@ - use super::*; use crate::ecs; -use crate::world; use crate::render; use crate::shared::Position as BPos; +use crate::world; use cgmath::InnerSpace; pub struct ApplyVelocity { @@ -18,9 +17,7 @@ impl ApplyVelocity { let position = m.get_key(); let velocity = m.get_key(); ApplyVelocity { - filter: ecs::Filter::new() - .with(position) - .with(velocity), + filter: ecs::Filter::new().with(position).with(velocity), position, velocity, movement: m.get_key(), @@ -29,7 +26,6 @@ impl ApplyVelocity { } impl ecs::System for ApplyVelocity { - fn filter(&self) -> &ecs::Filter { &self.filter } @@ -58,9 +54,7 @@ impl ApplyGravity { let gravity = m.get_key::(); let velocity = m.get_key(); ApplyGravity { - filter: ecs::Filter::new() - .with(gravity) - .with(velocity), + filter: ecs::Filter::new().with(gravity).with(velocity), velocity, movement: m.get_key(), } @@ -68,7 +62,6 @@ impl ApplyGravity { } impl ecs::System for ApplyGravity { - fn filter(&self) -> &ecs::Filter { &self.filter } @@ -98,15 +91,13 @@ impl UpdateLastPosition { pub fn new(m: &mut ecs::Manager) -> UpdateLastPosition { let position = m.get_key(); UpdateLastPosition { - filter: ecs::Filter::new() - .with(position), + filter: ecs::Filter::new().with(position), position, } } } impl ecs::System for UpdateLastPosition { - fn filter(&self) -> &ecs::Filter { &self.filter } @@ -133,9 +124,7 @@ impl LerpPosition { let position = m.get_key(); let target_position = m.get_key(); LerpPosition { - filter: ecs::Filter::new() - .with(position) - .with(target_position), + filter: ecs::Filter::new().with(position).with(target_position), position, target_position, game_info: m.get_key(), @@ -144,20 +133,24 @@ impl LerpPosition { } impl ecs::System for LerpPosition { - fn filter(&self) -> &ecs::Filter { &self.filter } fn update(&mut self, m: &mut ecs::Manager, _: &mut world::World, _: &mut render::Renderer) { let world_entity = m.get_world(); - let delta = m.get_component_mut(world_entity, self.game_info).unwrap().delta.min(5.0); + let delta = m + .get_component_mut(world_entity, self.game_info) + .unwrap() + .delta + .min(5.0); for e in m.find(&self.filter) { let pos = m.get_component_mut(e, self.position).unwrap(); let target_pos = m.get_component(e, self.target_position).unwrap(); - pos.position = pos.position + (target_pos.position - pos.position) * delta * target_pos.lerp_amount; - let len = (pos.position - target_pos.position).magnitude2() ; + pos.position = pos.position + + (target_pos.position - pos.position) * delta * target_pos.lerp_amount; + let len = (pos.position - target_pos.position).magnitude2(); if len < 0.001 || len > 100.0 * 100.0 { pos.position = target_pos.position; } @@ -177,9 +170,7 @@ impl LerpRotation { let rotation = m.get_key(); let target_rotation = m.get_key(); LerpRotation { - filter: ecs::Filter::new() - .with(rotation) - .with(target_rotation), + filter: ecs::Filter::new().with(rotation).with(target_rotation), rotation, target_rotation, game_info: m.get_key(), @@ -188,7 +179,6 @@ impl LerpRotation { } impl ecs::System for LerpRotation { - fn filter(&self) -> &ecs::Filter { &self.filter } @@ -196,12 +186,16 @@ impl ecs::System for LerpRotation { fn update(&mut self, m: &mut ecs::Manager, _: &mut world::World, _: &mut render::Renderer) { use std::f64::consts::PI; let world_entity = m.get_world(); - let delta = m.get_component_mut(world_entity, self.game_info).unwrap().delta.min(5.0); + let delta = m + .get_component_mut(world_entity, self.game_info) + .unwrap() + .delta + .min(5.0); for e in m.find(&self.filter) { let rot = m.get_component_mut(e, self.rotation).unwrap(); let target_rot = m.get_component_mut(e, self.target_rotation).unwrap(); - target_rot.yaw = (PI*2.0 + target_rot.yaw) % (PI*2.0); - target_rot.pitch = (PI*2.0 + target_rot.pitch) % (PI*2.0); + target_rot.yaw = (PI * 2.0 + target_rot.yaw) % (PI * 2.0); + target_rot.pitch = (PI * 2.0 + target_rot.pitch) % (PI * 2.0); let mut delta_yaw = target_rot.yaw - rot.yaw; let mut delta_pitch = target_rot.pitch - rot.pitch; @@ -215,8 +209,8 @@ impl ecs::System for LerpRotation { rot.yaw += delta_yaw * 0.2 * delta; rot.pitch += delta_pitch * 0.2 * delta; - rot.yaw = (PI*2.0 + rot.yaw) % (PI*2.0); - rot.pitch = (PI*2.0 + rot.pitch) % (PI*2.0); + rot.yaw = (PI * 2.0 + rot.yaw) % (PI * 2.0); + rot.pitch = (PI * 2.0 + rot.pitch) % (PI * 2.0); } } } @@ -225,7 +219,7 @@ pub struct LightEntity { filter: ecs::Filter, position: ecs::Key, bounds: ecs::Key, - light: ecs::Key + light: ecs::Key, } impl LightEntity { @@ -234,10 +228,7 @@ impl LightEntity { let bounds = m.get_key(); let light = m.get_key(); LightEntity { - filter: ecs::Filter::new() - .with(position) - .with(bounds) - .with(light), + filter: ecs::Filter::new().with(position).with(bounds).with(light), position, bounds, light, @@ -246,7 +237,6 @@ impl LightEntity { } impl ecs::System for LightEntity { - fn filter(&self) -> &ecs::Filter { &self.filter } @@ -269,14 +259,13 @@ impl ecs::System for LightEntity { let length = (bounds.bounds.max - bounds.bounds.min).magnitude() as f32; - for y in min_y .. max_y { - for z in min_z .. max_z { - for x in min_x .. max_x { - let dist = length - ( - ((x as f32 + 0.5) - pos.position.x as f32).powi(2) + for y in min_y..max_y { + for z in min_z..max_z { + for x in min_x..max_x { + let dist = length + - (((x as f32 + 0.5) - pos.position.x as f32).powi(2) + ((y as f32 + 0.5) - pos.position.y as f32).powi(2) - + ((z as f32 + 0.5) - pos.position.z as f32).powi(2) - ) + + ((z as f32 + 0.5) - pos.position.z as f32).powi(2)) .sqrt() .min(length); let dist = dist / length; diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 263c5995..3714f3b6 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::ops::BitOr; -use std::mem; -use std::ops::{Deref, DerefMut}; -use log::{error, info}; use glow as gl; use glow::HasContext; +use log::{error, info}; +use std::mem; +use std::ops::BitOr; +use std::ops::{Deref, DerefMut}; static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; /// Inits the gl library. This should be called once a context is ready. -pub fn init(vid: & glutin::WindowedContext) { +pub fn init(vid: &glutin::WindowedContext) { unsafe { CONTEXT = &mut (gl::Context::from_loader_function(|s| { println!("Loaded {} = {:?}", s, vid.get_proc_address(s)); @@ -109,7 +109,7 @@ impl BitOr for ClearFlags { /// Clears the buffers specified by the passed flags. pub fn clear(flags: ClearFlags) { - unsafe { + unsafe { //glow_context().clear(flags.internal()) } } @@ -181,7 +181,12 @@ pub fn blend_func(s_factor: Factor, d_factor: Factor) { } } -pub fn blend_func_separate(s_factor_rgb: Factor, d_factor_rgb: Factor, s_factor_a: Factor, d_factor_a: Factor) { +pub fn blend_func_separate( + s_factor_rgb: Factor, + d_factor_rgb: Factor, + s_factor_a: Factor, + d_factor_a: Factor, +) { unsafe { //glow_context().blend_func_separate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); } @@ -208,7 +213,7 @@ pub const COUNTER_CLOCK_WISE: FaceDirection = gl::CCW; /// Sets the direction of vertices used to specify the /// front face (e.g. for culling). pub fn front_face(dir: FaceDirection) { - unsafe { + unsafe { //glow_context().front_face(dir) } } @@ -269,7 +274,11 @@ impl Texture { // Allocates a new texture. pub fn new() -> Texture { println!("create_texture"); - Texture(unsafe { glow_context().create_texture().expect("create texture failed") }) + Texture(unsafe { + glow_context() + .create_texture() + .expect("create texture failed") + }) } /// Binds the texture to the passed target. @@ -280,12 +289,14 @@ impl Texture { } } - pub fn get_pixels(&self, - target: TextureTarget, - level: i32, - format: TextureFormat, - ty: Type, - pixels: &mut [u8]) { + pub fn get_pixels( + &self, + target: TextureTarget, + level: i32, + format: TextureFormat, + ty: Type, + pixels: &mut [u8], + ) { unsafe { /* glow_context().get_tex_image_u8_slice(target, @@ -297,14 +308,16 @@ impl Texture { } } - pub fn image_2d(&self, - target: TextureTarget, - level: i32, - width: u32, - height: u32, - format: TextureFormat, - ty: Type, - pix: Option<&[u8]>) { + pub fn image_2d( + &self, + target: TextureTarget, + level: i32, + width: u32, + height: u32, + format: TextureFormat, + ty: Type, + pix: Option<&[u8]>, + ) { unsafe { /* glow_context().tex_image_2d(target, @@ -321,16 +334,18 @@ impl Texture { } } - pub fn sub_image_2d(&self, - target: TextureTarget, - level: i32, - x: u32, - y: u32, - width: u32, - height: u32, - format: TextureFormat, - ty: Type, - pix: &[u8]) { + pub fn sub_image_2d( + &self, + target: TextureTarget, + level: i32, + x: u32, + y: u32, + width: u32, + height: u32, + format: TextureFormat, + ty: Type, + pix: &[u8], + ) { unsafe { /* glow_context().tex_sub_image_2d_u8_slice(target, @@ -347,15 +362,17 @@ impl Texture { } } - pub fn image_2d_ex(&self, - target: TextureTarget, - level: i32, - width: u32, - height: u32, - internal_format: TextureFormat, - format: TextureFormat, - ty: Type, - pix: Option<&[u8]>) { + pub fn image_2d_ex( + &self, + target: TextureTarget, + level: i32, + width: u32, + height: u32, + internal_format: TextureFormat, + format: TextureFormat, + ty: Type, + pix: Option<&[u8]>, + ) { unsafe { /* glow_context().tex_image_2d(target, @@ -372,24 +389,26 @@ impl Texture { } } - pub fn image_2d_sample(&self, - target: TextureTarget, - samples: i32, - width: u32, - height: u32, - format: TextureFormat, - fixed: bool) { + pub fn image_2d_sample( + &self, + target: TextureTarget, + samples: i32, + width: u32, + height: u32, + format: TextureFormat, + fixed: bool, + ) { unsafe { /* - let result: i32 = glow_context().get_parameter_i32(gl::MAX_SAMPLES); - let use_samples = - if samples > result { - info!("glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", samples, result); - result - } else { - samples - }; -*/ + let result: i32 = glow_context().get_parameter_i32(gl::MAX_SAMPLES); + let use_samples = + if samples > result { + info!("glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", samples, result); + result + } else { + samples + }; + */ // TODO: switch to glRenderbufferStorageMultisample? // from glTexImage2DMultisample which isn't in WebGL /* @@ -404,15 +423,17 @@ impl Texture { } } - pub fn image_3d(&self, - target: TextureTarget, - level: i32, - width: u32, - height: u32, - depth: u32, - format: TextureFormat, - ty: Type, - pix: &[u8]) { + pub fn image_3d( + &self, + target: TextureTarget, + level: i32, + width: u32, + height: u32, + depth: u32, + format: TextureFormat, + ty: Type, + pix: &[u8], + ) { unsafe { /* glow_context().tex_image_3d(target, @@ -429,18 +450,20 @@ impl Texture { } } - pub fn sub_image_3d(&self, - target: TextureTarget, - level: i32, - x: u32, - y: u32, - z: u32, - width: u32, - height: u32, - depth: u32, - format: TextureFormat, - ty: Type, - pix: &[u8]) { + pub fn sub_image_3d( + &self, + target: TextureTarget, + level: i32, + x: u32, + y: u32, + z: u32, + width: u32, + height: u32, + depth: u32, + format: TextureFormat, + ty: Type, + pix: &[u8], + ) { unsafe { /* glow_context().tex_sub_image_3d_u8_slice(target, @@ -458,10 +481,12 @@ impl Texture { } } - pub fn set_parameter(&self, - target: TextureTarget, - param: TextureParameter, - value: TextureValue) { + pub fn set_parameter( + &self, + target: TextureTarget, + param: TextureParameter, + value: TextureValue, + ) { /* TODO unsafe { glow_context().tex_parameter_i32(target, param, value); @@ -575,7 +600,7 @@ impl Shader { pub fn get_shader_compile_status(&self) -> bool { true - /* TODO + /* TODO unsafe { glow_context().get_shader_compile_status(self.0) } @@ -855,11 +880,12 @@ pub struct Framebuffer(u32); pub fn check_framebuffer_status() { unsafe { let status = glow_context().check_framebuffer_status(gl::FRAMEBUFFER); - let s = - match status { + let s = match status { gl::FRAMEBUFFER_UNDEFINED => "GL_FRAMEBUFFER_UNDEFINED", gl::FRAMEBUFFER_INCOMPLETE_ATTACHMENT => "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT", - gl::FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT => "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT", + gl::FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT => { + "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT" + } gl::FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER => "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER", gl::FRAMEBUFFER_INCOMPLETE_READ_BUFFER => "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER", gl::FRAMEBUFFER_UNSUPPORTED => "GL_FRAMEBUFFER_UNSUPPORTED", @@ -868,11 +894,14 @@ pub fn check_framebuffer_status() { gl::FRAMEBUFFER_COMPLETE => "GL_FRAMEBUFFER_COMPLETE", //gl::FRAMEBUFFER_INCOMPLETE_DIMENSIONS => "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS", - _ => "unknown" + _ => "unknown", }; if status != gl::FRAMEBUFFER_COMPLETE { - panic!("glBindFramebuffer failed, glCheckFrameBufferStatus(GL_FRAMEBUFFER) = {} {}", status, s); + panic!( + "glBindFramebuffer failed, glCheckFrameBufferStatus(GL_FRAMEBUFFER) = {} {}", + status, s + ); } } } @@ -915,7 +944,13 @@ impl Framebuffer { } } - pub fn texture_2d(&self, attachment: Attachment, target: TextureTarget, tex: &Texture, level: i32) { + pub fn texture_2d( + &self, + attachment: Attachment, + target: TextureTarget, + tex: &Texture, + level: i32, + ) { unsafe { //glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, Some(tex.0), level); } @@ -961,9 +996,17 @@ pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { } pub fn blit_framebuffer( - sx0: i32, sy0: i32, sx1: i32, sy1: i32, - dx0: i32, dy0: i32, dx1: i32, dy1: i32, - mask: ClearFlags, filter: TextureValue) { + sx0: i32, + sy0: i32, + sx1: i32, + sy1: i32, + dx0: i32, + dy0: i32, + dx1: i32, + dy1: i32, + mask: ClearFlags, + filter: TextureValue, +) { /* unsafe { glow_context().blit_framebuffer( diff --git a/src/main.rs b/src/main.rs index f4ab367f..73f9a335 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![recursion_limit="300"] +#![recursion_limit = "300"] -use std::time::{Instant, Duration}; -use log::{info, warn, error}; +use log::{error, info, warn}; +use std::time::{Duration, Instant}; extern crate steven_shared as shared; use structopt::StructOpt; @@ -23,32 +23,32 @@ use structopt::StructOpt; extern crate steven_protocol; pub mod ecs; -use steven_protocol::protocol as protocol; -use steven_protocol::format as format; -use steven_protocol::nbt as nbt; +use steven_protocol::format; +use steven_protocol::nbt; +use steven_protocol::protocol; pub mod gl; -use steven_protocol::types as types; -pub mod resources; +use steven_protocol::types; +pub mod auth; +pub mod chunk_builder; +pub mod console; +pub mod entity; +pub mod model; pub mod render; -pub mod ui; +pub mod resources; pub mod screen; -pub mod settings; -pub mod console; pub mod server; +pub mod settings; +pub mod ui; pub mod world; -pub mod chunk_builder; -pub mod auth; -pub mod model; -pub mod entity; +use crate::protocol::mojang; use cfg_if::cfg_if; -use std::sync::{Arc, RwLock, Mutex}; -use std::rc::Rc; +use glutin; use std::marker::PhantomData; -use std::thread; +use std::rc::Rc; use std::sync::mpsc; -use crate::protocol::mojang; -use glutin; +use std::sync::{Arc, Mutex, RwLock}; +use std::thread; const CL_BRAND: console::CVar = console::CVar { ty: PhantomData, @@ -87,16 +87,24 @@ pub struct Game { impl Game { pub fn connect_to(&mut self, address: &str) { - let (protocol_version, forge_mods) = match protocol::Conn::new(&address, self.default_protocol_version) - .and_then(|conn| conn.do_status()) { + let (protocol_version, forge_mods) = + 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); + info!( + "Detected server protocol version {}", + res.0.version.protocol + ); (res.0.version.protocol, res.0.forge_mods) - }, + } Err(err) => { - warn!("Error pinging server {} to get protocol version: {:?}, defaulting to {}", address, err, self.default_protocol_version); + warn!( + "Error pinging server {} to get protocol version: {:?}, defaulting to {}", + address, err, self.default_protocol_version + ); (self.default_protocol_version, vec![]) - }, + } }; let (tx, rx) = mpsc::channel(); @@ -109,7 +117,14 @@ impl Game { access_token: self.vars.get(auth::AUTH_TOKEN).clone(), }; thread::spawn(move || { - tx.send(server::Server::connect(resources, profile, &address, protocol_version, forge_mods)).unwrap(); + tx.send(server::Server::connect( + resources, + profile, + &address, + protocol_version, + forge_mods, + )) + .unwrap(); }); } @@ -122,9 +137,8 @@ impl Game { } if let Some(disconnect_reason) = self.server.disconnect_reason.take() { - self.screen_sys.replace_screen(Box::new(screen::ServerList::new( - Some(disconnect_reason) - ))); + self.screen_sys + .replace_screen(Box::new(screen::ServerList::new(Some(disconnect_reason)))); } if !self.server.is_connected() { self.focused = false; @@ -140,7 +154,7 @@ impl Game { self.focused = true; self.server.remove(&mut self.renderer); self.server = val; - }, + } Err(err) => { let msg = match err { protocol::Error::Disconnect(val) => val, @@ -148,11 +162,10 @@ impl Game { let mut msg = format::TextComponent::new(&format!("{}", err)); msg.modifier.color = Some(format::Color::Red); format::Component::Text(msg) - }, + } }; - self.screen_sys.replace_screen(Box::new(screen::ServerList::new( - Some(msg) - ))); + self.screen_sys + .replace_screen(Box::new(screen::ServerList::new(Some(msg)))); } } } @@ -245,7 +258,9 @@ fn main2() { .expect("Could not create glutin window."); let mut window = unsafe { - window.make_current().expect("Could not set current context.") + window + .make_current() + .expect("Could not set current context.") }; gl::init(&window); @@ -276,7 +291,8 @@ fn main2() { let textures = renderer.get_textures(); let dpi_factor = window.window().current_monitor().hidpi_factor(); let default_protocol_version = protocol::versions::protocol_name_to_protocol_version( - opt.default_protocol_version.unwrap_or("".to_string())); + opt.default_protocol_version.unwrap_or("".to_string()), + ); let mut game = Game { server: server::Server::dummy_server(resource_manager.clone()), focused: false, @@ -315,7 +331,11 @@ fn main2() { last_frame = now; let delta = (diff.subsec_nanos() as f64) / frame_time; let (width, height) = window.window().inner_size().into(); - let (physical_width, physical_height) = window.window().inner_size().to_physical(game.dpi_factor).into(); + let (physical_width, physical_height) = window + .window() + .inner_size() + .to_physical(game.dpi_factor) + .into(); let version = { let try_res = game.resource_manager.try_write(); @@ -345,16 +365,24 @@ fn main2() { 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.chunk_builder + .tick(&mut game.server.world, &mut game.renderer, version); - game.screen_sys.tick(delta, &mut game.renderer, &mut ui_container); + game.screen_sys + .tick(delta, &mut game.renderer, &mut ui_container); game.console .lock() .unwrap() .tick(&mut ui_container, &game.renderer, delta, width as f64); ui_container.tick(&mut game.renderer, delta, width as f64, height as f64); - game.renderer.tick(&mut game.server.world, delta, width, height, physical_width, physical_height); - + game.renderer.tick( + &mut game.server.world, + delta, + width, + height, + physical_width, + physical_height, + ); if fps_cap > 0 && !vsync { let frame_time = now.elapsed(); @@ -373,31 +401,37 @@ fn main2() { }); } -fn handle_window_event(window: &mut glutin::WindowedContext, - game: &mut Game, - ui_container: &mut ui::Container, - event: glutin::event::Event) { +fn handle_window_event( + window: &mut glutin::WindowedContext, + game: &mut Game, + ui_container: &mut ui::Container, + event: glutin::event::Event, +) { use glutin::event::*; match event { - Event::DeviceEvent{event, ..} => match event { + Event::DeviceEvent { event, .. } => match event { DeviceEvent::ModifiersChanged(modifiers_state) => { game.is_ctrl_pressed = modifiers_state.ctrl(); game.is_logo_pressed = modifiers_state.logo(); - }, - - 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) - }; + } + + 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; @@ -408,44 +442,51 @@ fn handle_window_event(window: &mut glutin::WindowedContext (PI/2.0)*3.0 - 0.01 { - rotation.pitch = (PI/2.0)*3.0 - 0.01; + if rotation.pitch > (PI / 2.0) * 3.0 - 0.01 { + rotation.pitch = (PI / 2.0) * 3.0 - 0.01; } } } else { window.window().set_cursor_grab(false).unwrap(); window.window().set_cursor_visible(true); } - }, + } - _ => () + _ => (), }, - Event::WindowEvent{event, ..} => match event { - WindowEvent::CloseRequested => game.should_close = true, - WindowEvent::Resized(logical_size) => { - game.dpi_factor = window.window().hidpi_factor(); - window.resize(logical_size.to_physical(game.dpi_factor)); - }, + Event::WindowEvent { event, .. } => { + match event { + WindowEvent::CloseRequested => game.should_close = true, + WindowEvent::Resized(logical_size) => { + game.dpi_factor = window.window().hidpi_factor(); + window.resize(logical_size.to_physical(game.dpi_factor)); + } - WindowEvent::ReceivedCharacter(codepoint) => { - if !game.focused { - ui_container.key_type(game, codepoint); + WindowEvent::ReceivedCharacter(codepoint) => { + if !game.focused { + ui_container.key_type(game, codepoint); + } } - }, - WindowEvent::MouseInput{state, button, ..} => { - match (state, button) { + WindowEvent::MouseInput { state, button, .. } => match (state, button) { (ElementState::Released, MouseButton::Left) => { let (width, height) = window.window().inner_size().into(); - if game.server.is_connected() && !game.focused && !game.screen_sys.is_current_closable() { + if game.server.is_connected() + && !game.focused + && !game.screen_sys.is_current_closable() + { game.focused = true; window.window().set_cursor_grab(true).unwrap(); window.window().set_cursor_visible(false); @@ -454,93 +495,109 @@ fn handle_window_event(window: &mut glutin::WindowedContext { if game.focused { game.server.on_right_click(&mut game.renderer); } - }, - (_, _) => () - } - }, - WindowEvent::CursorMoved{position, ..} => { - let (x, y) = position.into(); - game.last_mouse_x = x; - game.last_mouse_y = y; - - if !game.focused { - let (width, height) = window.window().inner_size().into(); - ui_container.hover_at(game, x, y, width, height); - } - }, - 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); - }, + } + (_, _) => (), + }, + WindowEvent::CursorMoved { position, .. } => { + let (x, y) = position.into(); + game.last_mouse_x = x; + game.last_mouse_y = y; + + if !game.focused { + let (width, height) = window.window().inner_size().into(); + ui_container.hover_at(game, x, y, width, height); + } } - }, - WindowEvent::KeyboardInput{input, ..} => { - match (input.state, input.virtual_keycode) { - (ElementState::Released, Some(VirtualKeyCode::Escape)) => { - if game.focused { - window.window().set_cursor_grab(false).unwrap(); - window.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.window().set_cursor_grab(true).unwrap(); - window.window().set_cursor_visible(false); - game.focused = true; - game.screen_sys.pop_screen(); + 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); } } - (ElementState::Pressed, Some(VirtualKeyCode::Grave)) => { - game.console.lock().unwrap().toggle(); - }, - (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 - window.window().set_fullscreen(Some(glutin::window::Fullscreen::Borderless(window.window().current_monitor()))); - } else { - window.window().set_fullscreen(None); + } + WindowEvent::KeyboardInput { input, .. } => { + match (input.state, input.virtual_keycode) { + (ElementState::Released, Some(VirtualKeyCode::Escape)) => { + if game.focused { + window.window().set_cursor_grab(false).unwrap(); + window.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.window().set_cursor_grab(true).unwrap(); + window.window().set_cursor_visible(false); + game.focused = true; + game.screen_sys.pop_screen(); + } } + (ElementState::Pressed, Some(VirtualKeyCode::Grave)) => { + game.console.lock().unwrap().toggle(); + } + (ElementState::Pressed, Some(VirtualKeyCode::F11)) => { + if !game.is_fullscreen { + // 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 + window.window().set_fullscreen(Some( + glutin::window::Fullscreen::Borderless( + window.window().current_monitor(), + ), + )); + } else { + window.window().set_fullscreen(None); + } - game.is_fullscreen = !game.is_fullscreen; - }, - (ElementState::Pressed, Some(key)) => { - if game.focused { - if let Some(steven_key) = settings::Stevenkey::get_by_keycode(key, &game.vars) { - game.server.key_press(true, steven_key); + 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); } - } else { - let ctrl_pressed = game.is_ctrl_pressed || game.is_logo_pressed; - ui_container.key_press(game, key, true, ctrl_pressed); } - }, - (ElementState::Released, Some(key)) => { - if game.focused { - if let Some(steven_key) = settings::Stevenkey::get_by_keycode(key, &game.vars) { - game.server.key_press(false, steven_key); + (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); } - } else { - let ctrl_pressed = game.is_ctrl_pressed; - ui_container.key_press(game, key, false, ctrl_pressed); } - }, - (_, None) => () + (_, None) => (), + } } - }, - _ => () - }, + _ => (), + } + } _ => (), } diff --git a/src/model/liquid.rs b/src/model/liquid.rs index 9b70e34a..c7019319 100644 --- a/src/model/liquid.rs +++ b/src/model/liquid.rs @@ -1,12 +1,19 @@ - -use std::io::Write; -use std::sync::{Arc, RwLock}; -use crate::world::{self, block}; -use crate::shared::Direction; use crate::model::BlockVertex; use crate::render; +use crate::shared::Direction; +use crate::world::{self, block}; +use std::io::Write; +use std::sync::{Arc, RwLock}; -pub fn render_liquid(textures: Arc>,lava: bool, snapshot: &world::Snapshot, x: i32, y: i32, z: i32, buf: &mut W) -> usize { +pub fn render_liquid( + textures: Arc>, + lava: bool, + snapshot: &world::Snapshot, + x: i32, + y: i32, + z: i32, + buf: &mut W, +) -> usize { let get_liquid = if lava { get_lava_level } else { @@ -20,17 +27,25 @@ pub fn render_liquid(textures: Arc>,lav } else { ( average_liquid_level(get_liquid, snapshot, x, y, z), - average_liquid_level(get_liquid, snapshot, x+1, y, z), - average_liquid_level(get_liquid, snapshot, x, y, z+1), - average_liquid_level(get_liquid, snapshot, x+1, y, z+1) + average_liquid_level(get_liquid, snapshot, x + 1, y, z), + average_liquid_level(get_liquid, snapshot, x, y, z + 1), + average_liquid_level(get_liquid, snapshot, x + 1, y, z + 1), ) }; let tex = match snapshot.get_block(x, y, z) { - block::Block::Water{..} => render::Renderer::get_texture(&textures, "minecraft:blocks/water_still"), - block::Block::FlowingWater{..} => render::Renderer::get_texture(&textures, "minecraft:blocks/water_flow"), - block::Block::Lava{..} => render::Renderer::get_texture(&textures, "minecraft:blocks/lava_still"), - block::Block::FlowingLava{..} => render::Renderer::get_texture(&textures, "minecraft:blocks/lava_flow"), + block::Block::Water { .. } => { + render::Renderer::get_texture(&textures, "minecraft:blocks/water_still") + } + block::Block::FlowingWater { .. } => { + render::Renderer::get_texture(&textures, "minecraft:blocks/water_flow") + } + block::Block::Lava { .. } => { + render::Renderer::get_texture(&textures, "minecraft:blocks/lava_still") + } + block::Block::FlowingLava { .. } => { + render::Renderer::get_texture(&textures, "minecraft:blocks/lava_flow") + } _ => unreachable!(), }; let ux1 = 0i16; @@ -41,8 +56,11 @@ pub fn render_liquid(textures: Arc>,lav for dir in Direction::all() { let (ox, oy, oz) = dir.get_offset(); let special = dir == Direction::Up && (tl < 8 || tr < 8 || bl < 8 || br < 8); - let block = snapshot.get_block(x+ox, y+oy, z+oz); - if special || (!block.get_material().should_cull_against && get_liquid(snapshot, x+ox, y+oy, z+oz).is_none()) { + let block = snapshot.get_block(x + ox, y + oy, z + oz); + if special + || (!block.get_material().should_cull_against + && get_liquid(snapshot, x + ox, y + oy, z + oz).is_none()) + { let verts = BlockVertex::face_by_direction(dir); for vert in verts { let mut vert = vert.clone(); @@ -64,7 +82,7 @@ pub fn render_liquid(textures: Arc>,lav (0, _) => ((16.0 / 8.0) * (bl as f32)) as i32, (_, _) => ((16.0 / 8.0) * (br as f32)) as i32, }; - vert.y = (height as f32)/16.0 + (y as f32); + vert.y = (height as f32) / 16.0 + (y as f32); } vert.x += x as f32; @@ -72,13 +90,15 @@ pub fn render_liquid(textures: Arc>,lav let (bl, sl) = super::calculate_light( snapshot, - x, y, z, + x, + y, + z, vert.x as f64, vert.y as f64, vert.z as f64, dir, !lava, - false + false, ); vert.block_light = bl; vert.sky_light = sl; @@ -106,15 +126,18 @@ pub fn render_liquid(textures: Arc>,lav fn average_liquid_level( get: fn(&world::Snapshot, i32, i32, i32) -> Option, - snapshot: &world::Snapshot, x: i32, y: i32, z: i32 + snapshot: &world::Snapshot, + x: i32, + y: i32, + z: i32, ) -> i32 { let mut level = 0; - for xx in -1 .. 1 { - for zz in -1 .. 1 { - if get(snapshot, x+xx, y+1, z+zz).is_some() { + for xx in -1..1 { + for zz in -1..1 { + if get(snapshot, x + xx, y + 1, z + zz).is_some() { return 8; } - if let Some(l) = get(snapshot, x+xx, y, z+zz) { + if let Some(l) = get(snapshot, x + xx, y, z + zz) { let nl = 7 - (l & 0x7); if nl > level { level = nl; @@ -127,14 +150,14 @@ fn average_liquid_level( fn get_water_level(snapshot: &world::Snapshot, x: i32, y: i32, z: i32) -> Option { match snapshot.get_block(x, y, z) { - block::Block::Water{level} | block::Block::FlowingWater{level} => Some(level as i32), + block::Block::Water { level } | block::Block::FlowingWater { level } => Some(level as i32), _ => None, } } fn get_lava_level(snapshot: &world::Snapshot, x: i32, y: i32, z: i32) -> Option { match snapshot.get_block(x, y, z) { - block::Block::Lava{level} | block::Block::FlowingLava{level} => Some(level as i32), + block::Block::Lava { level } | block::Block::FlowingLava { level } => Some(level as i32), _ => None, } } diff --git a/src/model/mod.rs b/src/model/mod.rs index 67f96e51..00d74591 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1,25 +1,24 @@ - pub mod liquid; -use std::sync::{Arc, RwLock}; -use std::collections::HashMap; -use std::cell::RefCell; -use std::io::Write; -use byteorder::{WriteBytesExt, NativeEndian}; -use crate::resources; use crate::render; +use crate::resources; +use crate::shared::Direction; use crate::world; use crate::world::block::{Block, TintType}; -use crate::shared::Direction; +use byteorder::{NativeEndian, WriteBytesExt}; use serde_json; +use std::cell::RefCell; +use std::collections::HashMap; +use std::io::Write; +use std::sync::{Arc, RwLock}; -use std::hash::BuildHasherDefault; use crate::types::hash::FNVHash; -use log::{error}; +use log::error; +use std::hash::BuildHasherDefault; -use rand::Rng; -use rand::seq::SliceRandom; use image::GenericImageView; +use rand::seq::SliceRandom; +use rand::Rng; pub struct Factory { resources: Arc>, @@ -35,7 +34,7 @@ pub struct Factory { struct Key(String, String); macro_rules! try_log { - ($e:expr) => ( + ($e:expr) => { match $e { Ok(val) => val, Err(err) => { @@ -43,8 +42,8 @@ macro_rules! try_log { return false; } } - ); - (opt $e:expr) => ( + }; + (opt $e:expr) => { match $e { Ok(val) => val, Err(err) => { @@ -52,7 +51,7 @@ macro_rules! try_log { return None; } } - ); + }; } thread_local!( @@ -60,7 +59,10 @@ thread_local!( ); impl Factory { - pub fn new(resources: Arc>, textures: Arc>) -> Factory { + pub fn new( + resources: Arc>, + textures: Arc>, + ) -> Factory { Factory { grass_colors: Factory::load_biome_colors(resources.clone(), "grass"), foliage_colors: Factory::load_biome_colors(resources.clone(), "foliage"), @@ -72,7 +74,11 @@ impl Factory { } fn load_biome_colors(res: Arc>, name: &str) -> image::DynamicImage { - let mut val = match res.read().unwrap().open("minecraft", &format!("textures/colormap/{}.png", name)) { + let mut val = match res + .read() + .unwrap() + .open("minecraft", &format!("textures/colormap/{}.png", name)) + { Some(val) => val, None => return image::DynamicImage::new_rgb8(256, 256), }; @@ -87,7 +93,17 @@ impl Factory { self.foliage_colors = Factory::load_biome_colors(self.resources.clone(), "foliage"); } - fn get_model(&self, key: Key, block: Block, rng: &mut R, snapshot: &world::Snapshot, x: i32, y: i32, z: i32, buf: &mut W) -> Result { + fn get_model( + &self, + key: Key, + block: Block, + rng: &mut R, + snapshot: &world::Snapshot, + x: i32, + y: i32, + z: i32, + buf: &mut W, + ) -> Result { use std::collections::hash_map::Entry; if let Some(model) = self.models.get(&key) { if model.multipart.is_empty() { @@ -103,7 +119,7 @@ impl Factory { match entry { Entry::Occupied(e) => { return Ok(e.get().render(self, snapshot, x, y, z, buf)); - }, + } Entry::Vacant(e) => { let mut res: Option = None; for rule in &model.multipart { @@ -119,7 +135,7 @@ impl Factory { if let Some(mdl) = res { return Ok(e.insert(mdl).render(self, snapshot, x, y, z, buf)); } - }, + } }; Err(true) }); @@ -143,7 +159,7 @@ impl Factory { if !ok { return false; } - }, + } Rule::Match(ref key, ref val) => { if !block.match_multipart(key, val) { return false; @@ -154,8 +170,16 @@ impl Factory { true } - pub fn get_state_model(models: &Arc>, block: Block, rng: &mut R, - snapshot: &world::Snapshot, x: i32, y: i32, z: i32, buf: &mut W) -> usize { + pub fn get_state_model( + models: &Arc>, + block: Block, + rng: &mut R, + snapshot: &world::Snapshot, + x: i32, + y: i32, + z: i32, + buf: &mut W, + ) -> usize { let (plugin, name) = block.get_model(); let key = Key(plugin.to_owned(), name.to_owned()); let mut missing_variant; @@ -177,23 +201,32 @@ impl Factory { Err(val) => missing_variant = val, }; } - let ret = Factory::get_state_model(models, Block::Missing{}, rng, snapshot, x, y, z, buf); + let ret = Factory::get_state_model(models, Block::Missing {}, rng, snapshot, x, y, z, buf); if !missing_variant { // Still no model, replace with placeholder let mut m = models.write().unwrap(); - let model = m.models.get(&Key("steven".to_owned(), "missing_block".to_owned())).unwrap().clone(); + let model = m + .models + .get(&Key("steven".to_owned(), "missing_block".to_owned())) + .unwrap() + .clone(); m.models.insert(key, model); } ret } fn load_model(&mut self, plugin: &str, name: &str) -> bool { - let file = match self.resources.read().unwrap().open(plugin, &format!("blockstates/{}.json", name)) { + let file = match self + .resources + .read() + .unwrap() + .open(plugin, &format!("blockstates/{}.json", name)) + { Some(val) => val, None => { error!("Error missing block state for {}:{}", plugin, name); return false; - }, + } }; let mdl: serde_json::Value = try_log!(serde_json::from_reader(file)); @@ -218,14 +251,12 @@ impl Factory { if let Some(when) = rule.get("when").and_then(|v| v.as_object()) { Self::parse_rules(when, &mut rules); } - model.multipart.push(MultipartRule { - apply, - rules, - }) + model.multipart.push(MultipartRule { apply, rules }) } } - self.models.insert(Key(plugin.to_owned(), name.to_owned()), model); + self.models + .insert(Key(plugin.to_owned(), name.to_owned()), model); true } @@ -252,9 +283,7 @@ impl Factory { } fn parse_model_list(&self, plugin: &str, v: &serde_json::Value) -> Variants { - let mut variants = Variants { - models: vec![] - }; + let mut variants = Variants { models: vec![] }; if let Some(list) = v.as_array() { for val in list { if let Some(mdl) = self.parse_block_state_variant(plugin, val) { @@ -273,24 +302,35 @@ impl Factory { None => { error!("Couldn't find model name"); return None; - }, + } }; - let file = match self.resources.read().unwrap().open(plugin, &format!("models/block/{}.json", model_name)) { + let file = match self + .resources + .read() + .unwrap() + .open(plugin, &format!("models/block/{}.json", model_name)) + { Some(val) => val, None => { - error!("Couldn't find model {}", format!("models/block/{}.json", model_name)); + error!( + "Couldn't find model {}", + format!("models/block/{}.json", model_name) + ); return None; - }, + } }; let block_model: serde_json::Value = try_log!(opt serde_json::from_reader(file)); let mut model = match self.parse_model(plugin, &block_model) { Some(val) => val, None => { - error!("Failed to parse model {}", format!("models/block/{}.json", model_name)); + error!( + "Failed to parse model {}", + format!("models/block/{}.json", model_name) + ); return None; - }, + } }; model.y = v.get("y").and_then(|v| v.as_f64()).unwrap_or(0.0); @@ -303,20 +343,28 @@ impl Factory { fn parse_model(&self, plugin: &str, v: &serde_json::Value) -> Option { let parent = v.get("parent").and_then(|v| v.as_str()).unwrap_or(""); let mut model = if !parent.is_empty() && !parent.starts_with("builtin/") { - let file = match self.resources.read().unwrap().open(plugin, &format!("models/{}.json", parent)) { + let file = match self + .resources + .read() + .unwrap() + .open(plugin, &format!("models/{}.json", parent)) + { Some(val) => val, None => { error!("Couldn't find model {}", format!("models/{}.json", parent)); return None; - }, + } }; let block_model: serde_json::Value = try_log!(opt serde_json::from_reader(file)); match self.parse_model(plugin, &block_model) { Some(val) => val, None => { - error!("Failed to parse model {}", format!("models/{}.json", parent)); - return None - }, + error!( + "Failed to parse model {}", + format!("models/{}.json", parent) + ); + return None; + } } } else { RawModel { @@ -343,7 +391,9 @@ impl Factory { if let Some(textures) = v.get("textures").and_then(|v| v.as_object()) { for (k, v) in textures { - model.texture_vars.insert(k.clone(), v.as_str().unwrap_or("").to_owned()); + model + .texture_vars + .insert(k.clone(), v.as_str().unwrap_or("").to_owned()); } } @@ -367,16 +417,28 @@ impl Factory { fn parse_block_element(&self, v: &serde_json::Value) -> ModelElement { let mut element = ModelElement { - from: v.get("from").and_then(|v| v.as_array()).map(|v| [ - v[0].as_f64().unwrap(), - v[1].as_f64().unwrap(), - v[2].as_f64().unwrap() - ]).unwrap(), - to: v.get("to").and_then(|v| v.as_array()).map(|v| [ - v[0].as_f64().unwrap(), - v[1].as_f64().unwrap(), - v[2].as_f64().unwrap() - ]).unwrap(), + from: v + .get("from") + .and_then(|v| v.as_array()) + .map(|v| { + [ + v[0].as_f64().unwrap(), + v[1].as_f64().unwrap(), + v[2].as_f64().unwrap(), + ] + }) + .unwrap(), + to: v + .get("to") + .and_then(|v| v.as_array()) + .map(|v| { + [ + v[0].as_f64().unwrap(), + v[1].as_f64().unwrap(), + v[2].as_f64().unwrap(), + ] + }) + .unwrap(), shade: v.get("shade").and_then(|v| v.as_bool()).unwrap_or(false), faces: [None, None, None, None, None, None], rotation: None, @@ -390,50 +452,58 @@ impl Factory { let mut uv = [0.0, 0.0, 16.0, 16.0]; match dir { Direction::North | Direction::South => { - uv[0] = element.from[0]; - uv[2] = element.to[0]; - uv[1] = 16.0 - element.to[1]; - uv[3] = 16.0 - element.from[1]; - }, + uv[0] = element.from[0]; + uv[2] = element.to[0]; + uv[1] = 16.0 - element.to[1]; + uv[3] = 16.0 - element.from[1]; + } Direction::West | Direction::East => { - uv[0] = element.from[2]; - uv[2] = element.to[2]; - uv[1] = 16.0 - element.to[1]; - uv[3] = 16.0 - element.from[1]; - }, + uv[0] = element.from[2]; + uv[2] = element.to[2]; + uv[1] = 16.0 - element.to[1]; + uv[3] = 16.0 - element.from[1]; + } Direction::Down | Direction::Up => { - uv[0] = element.from[0]; - uv[2] = element.to[0]; - uv[1] = 16.0 - element.to[2]; - uv[3] = 16.0 - element.from[2]; - }, + uv[0] = element.from[0]; + uv[2] = element.to[0]; + uv[1] = 16.0 - element.to[2]; + uv[3] = 16.0 - element.from[2]; + } _ => unreachable!(), } uv }, - |v| [ - v[0].as_f64().unwrap(), - v[1].as_f64().unwrap(), - v[2].as_f64().unwrap(), - v[3].as_f64().unwrap() - ] + |v| { + [ + v[0].as_f64().unwrap(), + v[1].as_f64().unwrap(), + v[2].as_f64().unwrap(), + v[3].as_f64().unwrap(), + ] + }, ), - texture: face.get("texture") + texture: face + .get("texture") .and_then(|v| v.as_str()) - .map(|v| if v.starts_with('#') { - v.to_owned() - } else { - "#".to_owned() + v - }).unwrap(), + .map(|v| { + if v.starts_with('#') { + v.to_owned() + } else { + "#".to_owned() + v + } + }) + .unwrap(), cull_face: Direction::from_string( - face.get("cullface") - .and_then(|v| v.as_str()) - .unwrap_or("invalid") - ), - rotation: face.get("rotation") + face.get("cullface") + .and_then(|v| v.as_str()) + .unwrap_or("invalid"), + ), + rotation: face + .get("rotation") .and_then(|v| v.as_i64()) .map_or(0, |v| v as i32), - tint_index: face.get("tintindex") + tint_index: face + .get("tintindex") .and_then(|v| v.as_i64()) .map_or(-1, |v| v as i32), }); @@ -443,14 +513,29 @@ impl Factory { if let Some(rotation) = v.get("rotation") { element.rotation = Some(BlockRotation { - origin: rotation.get("origin").and_then(|v| v.as_array()).map_or([8.0, 8.0, 8.0], |v| [ - v[0].as_f64().unwrap(), - v[1].as_f64().unwrap(), - v[2].as_f64().unwrap() - ]), - axis: rotation.get("axis").and_then(|v| v.as_str()).unwrap_or("").to_owned(), - angle: rotation.get("angle").and_then(|v| v.as_f64()).unwrap_or(0.0), - rescale: rotation.get("rescale").and_then(|v| v.as_bool()).unwrap_or(false), + origin: rotation.get("origin").and_then(|v| v.as_array()).map_or( + [8.0, 8.0, 8.0], + |v| { + [ + v[0].as_f64().unwrap(), + v[1].as_f64().unwrap(), + v[2].as_f64().unwrap(), + ] + }, + ), + axis: rotation + .get("axis") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_owned(), + angle: rotation + .get("angle") + .and_then(|v| v.as_f64()) + .unwrap_or(0.0), + rescale: rotation + .get("rescale") + .and_then(|v| v.as_bool()) + .unwrap_or(false), }); } @@ -480,29 +565,33 @@ impl Factory { }; if raw.x > 0.0 { let o = (raw.x as i32) / 90; - processed_face.cull_face = rotate_direction(processed_face.cull_face, o, FACE_ROTATION_X, &[ - Direction::East, - Direction::West, - Direction::Invalid, - ]); - processed_face.facing = rotate_direction(processed_face.facing, o, FACE_ROTATION_X, &[ - Direction::East, - Direction::West, - Direction::Invalid, - ]); + processed_face.cull_face = rotate_direction( + processed_face.cull_face, + o, + FACE_ROTATION_X, + &[Direction::East, Direction::West, Direction::Invalid], + ); + processed_face.facing = rotate_direction( + processed_face.facing, + o, + FACE_ROTATION_X, + &[Direction::East, Direction::West, Direction::Invalid], + ); } if raw.y > 0.0 { let o = (raw.y as i32) / 90; - processed_face.cull_face = rotate_direction(processed_face.cull_face, o, FACE_ROTATION, &[ - Direction::Up, - Direction::Down, - Direction::Invalid, - ]); - processed_face.facing = rotate_direction(processed_face.facing, o, FACE_ROTATION, &[ - Direction::Up, - Direction::Down, - Direction::Invalid, - ]); + processed_face.cull_face = rotate_direction( + processed_face.cull_face, + o, + FACE_ROTATION, + &[Direction::Up, Direction::Down, Direction::Invalid], + ); + processed_face.facing = rotate_direction( + processed_face.facing, + o, + FACE_ROTATION, + &[Direction::Up, Direction::Down, Direction::Invalid], + ); } let mut verts = BlockVertex::face_by_direction(all_dirs[i]).to_vec(); @@ -523,24 +612,24 @@ impl Factory { let oy2 = uy2; match face.rotation { 270 => { - uy1 = tw*16 - ox2; - uy2 = tw*16 - ox1; + uy1 = tw * 16 - ox2; + uy2 = tw * 16 - ox1; ux1 = oy1; ux2 = oy2; - }, + } 180 => { - uy1 = th*16 - oy2; - uy2 = th*16 - oy1; - ux1 = tw*16 - ox2; - ux2 = tw*16 - ox1; - }, + uy1 = th * 16 - oy2; + uy2 = th * 16 - oy1; + ux1 = tw * 16 - ox2; + ux2 = tw * 16 - ox1; + } 90 => { uy1 = ox1; uy2 = ox2; - ux1 = th*16 - oy2; - ux2 = th*16 - oy1; - }, - _ => {}, + ux1 = th * 16 - oy2; + ux2 = th * 16 - oy1; + } + _ => {} } } @@ -583,40 +672,40 @@ impl Factory { let s = angle.sin(); let x = v.x; let z = v.z; - v.x = x*c - z*s; - v.z = z*c + x*s; + v.x = x * c - z * s; + v.z = z * c + x * s; if r.rescale { v.x *= ci; v.z *= ci; } - }, + } "x" => { let c = angle.cos(); let s = angle.sin(); let z = v.z; let y = v.y; - v.z = z*c - y*s; - v.y = y*c + z*s; + v.z = z * c - y * s; + v.y = y * c + z * s; if r.rescale { v.z *= ci; v.y *= ci; } - }, + } "z" => { let c = angle.cos(); let s = angle.sin(); let x = v.x; let y = v.y; - v.x = x*c - y*s; - v.y = y*c + x*s; + v.x = x * c - y * s; + v.y = y * c + x * s; if r.rescale { v.x *= ci; v.y *= ci; } - }, + } _ => {} } v.x += (r.origin[0] / 16.0) as f32; @@ -630,8 +719,8 @@ impl Factory { let s = rot_x.sin(); let z = v.z - 0.5; let y = v.y - 0.5; - v.z = 0.5 + (z*c - y*s); - v.y = 0.5 + (y*c + z*s); + v.z = 0.5 + (z * c - y * s); + v.y = 0.5 + (y * c + z * s); } if raw.y > 0.0 { @@ -640,8 +729,8 @@ impl Factory { let s = rot_y.sin(); let x = v.x - 0.5; let z = v.z - 0.5; - v.x = 0.5 + (x*c - z*s); - v.z = 0.5 + (z*c + x*s); + v.x = 0.5 + (x * c - z * s); + v.z = 0.5 + (z * c + x * s); } if v.toffsetx == 0 { @@ -657,35 +746,42 @@ impl Factory { } if face.rotation > 0 { - let rot_y = (-face.rotation as f64 * (::std::f64::consts::PI / 180.0)) as f32; + let rot_y = + (-face.rotation as f64 * (::std::f64::consts::PI / 180.0)) as f32; let c = rot_y.cos() as i16; let s = rot_y.sin() as i16; - let x = v.toffsetx - 8*tw; - let y = v.toffsety - 8*th; - v.toffsetx = 8*tw + (x*c - y*s); - v.toffsety = 8*th + (y*c + x*s); + let x = v.toffsetx - 8 * tw; + let y = v.toffsety - 8 * th; + v.toffsetx = 8 * tw + (x * c - y * s); + v.toffsety = 8 * th + (y * c + x * s); } - if raw.uvlock && raw.y > 0.0 - && (processed_face.facing == Direction::Up || processed_face.facing == Direction::Down) { + if raw.uvlock + && raw.y > 0.0 + && (processed_face.facing == Direction::Up + || processed_face.facing == Direction::Down) + { let rot_y = (raw.y * (::std::f64::consts::PI / 180.0)) as f32; let c = rot_y.cos() as i16; let s = rot_y.sin() as i16; - let x = v.toffsetx - 8*tw; - let y = v.toffsety - 8*th; - v.toffsetx = 8*tw + (x*c - y*s); - v.toffsety = 8*th + (y*c + x*s); + let x = v.toffsetx - 8 * tw; + let y = v.toffsety - 8 * th; + v.toffsetx = 8 * tw + (x * c - y * s); + v.toffsety = 8 * th + (y * c + x * s); } - if raw.uvlock && raw.x > 0.0 - && (processed_face.facing != Direction::Up && processed_face.facing != Direction::Down) { + if raw.uvlock + && raw.x > 0.0 + && (processed_face.facing != Direction::Up + && processed_face.facing != Direction::Down) + { let rot_x = (raw.x * (::std::f64::consts::PI / 180.0)) as f32; let c = rot_x.cos() as i16; let s = rot_x.sin() as i16; - let x = v.toffsetx - 8*tw; - let y = v.toffsety - 8*th; - v.toffsetx = 8*tw + (x*c - y*s); - v.toffsety = 8*th + (y*c + x*s); + let x = v.toffsetx - 8 * tw; + let y = v.toffsety - 8 * th; + v.toffsetx = 8 * tw + (x * c - y * s); + v.toffsety = 8 * th + (y * c + x * s); } } @@ -713,15 +809,18 @@ const FACE_ROTATION_X: &[Direction] = &[ Direction::Up, ]; -fn rotate_direction(val: Direction, offset: i32, rots: &[Direction], invalid: &[Direction]) -> Direction { +fn rotate_direction( + val: Direction, + offset: i32, + rots: &[Direction], + invalid: &[Direction], +) -> Direction { for d in invalid { if *d == val { return val; } } - let pos = rots.iter() - .position(|v| *v == val) - .unwrap_or(0) as i32; + let pos = rots.iter().position(|v| *v == val).unwrap_or(0) as i32; rots[(rots.len() as i32 + pos + offset) as usize % rots.len()] } @@ -767,7 +866,7 @@ enum BuiltinType { Generated, Entity, Compass, - Clock + Clock, } #[derive(Debug)] @@ -789,7 +888,11 @@ struct RawModel { impl RawModel { fn lookup_texture(&self, name: &str) -> String { if !name.is_empty() && name.starts_with('#') { - let tex = self.texture_vars.get(&name[1..]).cloned().unwrap_or("".to_owned()); + let tex = self + .texture_vars + .get(&name[1..]) + .cloned() + .unwrap_or("".to_owned()); return self.lookup_texture(&tex); } name.to_owned() @@ -852,7 +955,15 @@ impl Model { self.faces.extend_from_slice(&other.faces); } - fn render(&self, factory: &Factory, snapshot: &world::Snapshot, x: i32, y: i32, z: i32, buf: &mut W) -> usize { + fn render( + &self, + factory: &Factory, + snapshot: &world::Snapshot, + x: i32, + y: i32, + z: i32, + buf: &mut W, + ) -> usize { let this = snapshot.get_block(x, y, z); let this_mat = this.get_material(); let mut indices = 0; @@ -879,9 +990,19 @@ impl Model { let (mut cr, mut cg, mut cb) = if face.tint_index == 0 { match tint { TintType::Default => (255, 255, 255), - TintType::Color{r, g, b} => (r, g, b), - TintType::Grass => calculate_biome(snapshot, vert.x as i32, vert.z as i32, &factory.grass_colors), - TintType::Foliage => calculate_biome(snapshot, vert.x as i32, vert.z as i32, &factory.foliage_colors), + TintType::Color { r, g, b } => (r, g, b), + TintType::Grass => calculate_biome( + snapshot, + vert.x as i32, + vert.z as i32, + &factory.grass_colors, + ), + TintType::Foliage => calculate_biome( + snapshot, + vert.x as i32, + vert.z as i32, + &factory.foliage_colors, + ), } } else { (255, 255, 255) @@ -898,13 +1019,15 @@ impl Model { let (bl, sl) = calculate_light( snapshot, - x, y, z, + x, + y, + z, vert.x as f64, vert.y as f64, vert.z as f64, face.facing, self.ambient_occlusion, - this_mat.force_shade + this_mat.force_shade, ); vert.block_light = bl; vert.sky_light = sl; @@ -915,15 +1038,20 @@ impl Model { } } -fn calculate_biome(snapshot: &world::Snapshot, x: i32, z: i32, img: &image::DynamicImage) -> (u8, u8, u8) { - use std::cmp::{min, max}; +fn calculate_biome( + snapshot: &world::Snapshot, + x: i32, + z: i32, + img: &image::DynamicImage, +) -> (u8, u8, u8) { + use std::cmp::{max, min}; let mut count = 0; let mut r = 0; let mut g = 0; let mut b = 0; - for xx in -1 .. 2 { - for zz in -1 .. 2 { - let bi = snapshot.get_biome(x+xx, z+zz); + for xx in -1..2 { + for zz in -1..2 { + let bi = snapshot.get_biome(x + xx, z + zz); let color_index = bi.get_color_index(); let ix = color_index & 0xFF; let iy = color_index >> 8; @@ -939,13 +1067,23 @@ fn calculate_biome(snapshot: &world::Snapshot, x: i32, z: i32, img: &image::Dyna count += 1; } } - ((r/count) as u8, (g/count) as u8, (b/count) as u8) + ((r / count) as u8, (g / count) as u8, (b / count) as u8) } -fn calculate_light(snapshot: &world::Snapshot, orig_x: i32, orig_y: i32, orig_z: i32, - x: f64, y: f64, z: f64, face: Direction, smooth: bool, force: bool) -> (u16, u16) { - use std::cmp::max; +fn calculate_light( + snapshot: &world::Snapshot, + orig_x: i32, + orig_y: i32, + orig_z: i32, + x: f64, + y: f64, + z: f64, + face: Direction, + smooth: bool, + force: bool, +) -> (u16, u16) { use crate::world::block; + use std::cmp::max; let (ox, oy, oz) = face.get_offset(); let s_block_light = snapshot.get_block_light(orig_x + ox, orig_y + oy, orig_z + oz); @@ -973,8 +1111,13 @@ fn calculate_light(snapshot: &world::Snapshot, orig_x: i32, orig_y: i32, orig_z: let lz = (z + oz + dz).round() as i32; let mut bl = snapshot.get_block_light(lx, ly, lz); let mut sl = snapshot.get_sky_light(lx, ly, lz); - if (force && match snapshot.get_block(lx, ly, lz) { block::Air{} => false, _ => true }) - || (sl == 0 && bl == 0){ + if (force + && match snapshot.get_block(lx, ly, lz) { + block::Air {} => false, + _ => true, + }) + || (sl == 0 && bl == 0) + { bl = s_block_light; sl = s_sky_light; } @@ -985,43 +1128,50 @@ fn calculate_light(snapshot: &world::Snapshot, orig_x: i32, orig_y: i32, orig_z: } } - ((((block_light * 4000) / count) as u16), (((sky_light * 4000) / count) as u16)) + ( + (((block_light * 4000) / count) as u16), + (((sky_light * 4000) / count) as u16), + ) } - - pub const PRECOMPUTED_VERTS: [&[BlockVertex; 4]; 6] = [ - &[ // Up + &[ + // Up BlockVertex::base(0.0, 1.0, 0.0, 0, 0), BlockVertex::base(1.0, 1.0, 0.0, 1, 0), BlockVertex::base(0.0, 1.0, 1.0, 0, 1), BlockVertex::base(1.0, 1.0, 1.0, 1, 1), ], - &[ // Down + &[ + // Down BlockVertex::base(0.0, 0.0, 0.0, 0, 1), BlockVertex::base(0.0, 0.0, 1.0, 0, 0), BlockVertex::base(1.0, 0.0, 0.0, 1, 1), BlockVertex::base(1.0, 0.0, 1.0, 1, 0), ], - &[ // North + &[ + // North BlockVertex::base(0.0, 0.0, 0.0, 1, 1), BlockVertex::base(1.0, 0.0, 0.0, 0, 1), BlockVertex::base(0.0, 1.0, 0.0, 1, 0), BlockVertex::base(1.0, 1.0, 0.0, 0, 0), ], - &[ // South + &[ + // South BlockVertex::base(0.0, 0.0, 1.0, 0, 1), BlockVertex::base(0.0, 1.0, 1.0, 0, 0), BlockVertex::base(1.0, 0.0, 1.0, 1, 1), BlockVertex::base(1.0, 1.0, 1.0, 1, 0), ], - &[ // West + &[ + // West BlockVertex::base(0.0, 0.0, 0.0, 0, 1), BlockVertex::base(0.0, 1.0, 0.0, 0, 0), BlockVertex::base(0.0, 0.0, 1.0, 1, 1), BlockVertex::base(0.0, 1.0, 1.0, 1, 0), ], - &[ // East + &[ + // East BlockVertex::base(1.0, 0.0, 0.0, 1, 1), BlockVertex::base(1.0, 0.0, 1.0, 0, 1), BlockVertex::base(1.0, 1.0, 0.0, 1, 0), @@ -1051,11 +1201,21 @@ pub struct BlockVertex { impl BlockVertex { const fn base(x: f32, y: f32, z: f32, tx: i16, ty: i16) -> BlockVertex { BlockVertex { - x, y, z, - tx: 0, ty: 0, tw: 0, th: 0, - toffsetx: tx, toffsety: ty, tatlas: 0, - r: 0, g: 0, b: 0, - block_light: 0, sky_light: 0, + x, + y, + z, + tx: 0, + ty: 0, + tw: 0, + th: 0, + toffsetx: tx, + toffsety: ty, + tatlas: 0, + r: 0, + g: 0, + b: 0, + block_light: 0, + sky_light: 0, } } pub fn write(&self, w: &mut W) { diff --git a/src/render/atlas.rs b/src/render/atlas.rs index abc47f72..8ad527ec 100644 --- a/src/render/atlas.rs +++ b/src/render/atlas.rs @@ -26,7 +26,9 @@ pub struct Rect { impl Atlas { pub fn new(width: usize, height: usize) -> Atlas { - let mut a = Atlas { free_space: Vec::new() }; + let mut a = Atlas { + free_space: Vec::new(), + }; a.free_space.push(Rect { x: 0, y: 0, @@ -78,13 +80,15 @@ impl Atlas { } else { if t.height > height { // Split by height - self.free_space.insert(0, - Rect { - x: t.x, - y: t.y + height, - width, - height: t.height - height, - }); + self.free_space.insert( + 0, + Rect { + x: t.x, + y: t.y + height, + width, + height: t.height - height, + }, + ); target_index += 1; } t.x += width; diff --git a/src/render/clouds.rs b/src/render/clouds.rs index 4a8b1375..a2fd8293 100644 --- a/src/render/clouds.rs +++ b/src/render/clouds.rs @@ -1,10 +1,9 @@ - use std::sync::{Arc, RwLock}; -use cgmath::{Point3, Matrix4}; -use byteorder::{WriteBytesExt, NativeEndian}; -use crate::gl; use super::glsl; +use crate::gl; +use byteorder::{NativeEndian, WriteBytesExt}; +use cgmath::{Matrix4, Point3}; use log::error; pub struct Clouds { @@ -115,8 +114,8 @@ impl Clouds { let mut data = vec![]; let mut num_points = 0; - for x in -160 .. 160 { - for z in -160 .. 160 { + for x in -160..160 { + for z in -160..160 { let _ = data.write_f32::(x as f32); let _ = data.write_f32::(128.0); let _ = data.write_f32::(z as f32); @@ -126,11 +125,19 @@ impl Clouds { buffer.set_data(gl::ARRAY_BUFFER, &data, gl::STATIC_DRAW); - let heightmap_data = vec![0; 512*512]; + let heightmap_data = vec![0; 512 * 512]; let texture = gl::Texture::new(); texture.bind(gl::TEXTURE_2D); - texture.image_2d(gl::TEXTURE_2D, 0, 512, 512, gl::RED, gl::UNSIGNED_BYTE, Some(&heightmap_data)); + texture.image_2d( + gl::TEXTURE_2D, + 0, + 512, + 512, + gl::RED, + gl::UNSIGNED_BYTE, + Some(&heightmap_data), + ); texture.set_parameter(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST); texture.set_parameter(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST); @@ -163,7 +170,15 @@ impl Clouds { } } - pub fn draw(&mut self, camera_pos: &Point3, perspective_matrix: &Matrix4, camera_matrix: &Matrix4, light_level: f32, sky_offset: f32, delta: f64) { + pub fn draw( + &mut self, + camera_pos: &Point3, + perspective_matrix: &Matrix4, + camera_matrix: &Matrix4, + light_level: f32, + sky_offset: f32, + delta: f64, + ) { self.offset += delta; let tex = super::Renderer::get_texture(&self.textures, "steven:environment/clouds"); @@ -173,12 +188,16 @@ impl Clouds { self.u_camera_matrix.set_matrix4(camera_matrix); self.u_sky_offset.set_float(sky_offset); self.u_light_level.set_float(light_level); - self.u_offset.set_float3(camera_pos.x.floor() as f32, 0.0, camera_pos.z.floor() as f32); + self.u_offset.set_float3( + camera_pos.x.floor() as f32, + 0.0, + camera_pos.z.floor() as f32, + ); self.u_texture_info.set_float4( tex.get_x() as f32, tex.get_y() as f32, tex.get_width() as f32, - tex.get_height() as f32 + tex.get_height() as f32, ); self.u_atlas.set_float(tex.atlas as f32); self.u_cloud_offset.set_float((self.offset / 60.0) as f32); @@ -187,7 +206,17 @@ impl Clouds { gl::active_texture(1); self.texture.bind(gl::TEXTURE_2D); if self.dirty { - self.texture.sub_image_2d(gl::TEXTURE_2D, 0, 0, 0, 512, 512, gl::RED, gl::UNSIGNED_BYTE, &self.heightmap_data); + self.texture.sub_image_2d( + gl::TEXTURE_2D, + 0, + 0, + 0, + 512, + 512, + gl::RED, + gl::UNSIGNED_BYTE, + &self.heightmap_data, + ); self.dirty = false; } self.u_cloud_map.set_int(1); diff --git a/src/render/glsl.rs b/src/render/glsl.rs index 28cfcf71..65aa8ff2 100644 --- a/src/render/glsl.rs +++ b/src/render/glsl.rs @@ -20,13 +20,16 @@ pub struct Registry { } impl Registry { - pub fn new() -> Registry { Default::default() } + pub fn new() -> Registry { + Default::default() + } pub fn register(&mut self, name: &str, source: &str) { if self.shaders.contains_key(name) { panic!("shader {} is already defined", name); } - self.shaders.insert(name.to_owned(), source.trim().to_owned()); + self.shaders + .insert(name.to_owned(), source.trim().to_owned()); } pub fn get(&self, name: &str) -> String { diff --git a/src/render/mod.rs b/src/render/mod.rs index 011e35d2..5aa82542 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -16,29 +16,29 @@ mod atlas; pub mod glsl; #[macro_use] pub mod shaders; -pub mod ui; -pub mod model; pub mod clouds; +pub mod model; +pub mod ui; -use std::collections::HashMap; -use std::sync::{Arc, RwLock}; -use std::io::Write; -use crate::resources; use crate::gl; -use image; -use image::{GenericImage, GenericImageView}; -use byteorder::{WriteBytesExt, NativeEndian}; -use serde_json; -use cgmath::prelude::*; +use crate::resources; use crate::world; +use byteorder::{NativeEndian, WriteBytesExt}; +use cgmath::prelude::*; use collision; +use image; +use image::{GenericImage, GenericImageView}; use log::{error, trace}; +use serde_json; +use std::collections::HashMap; +use std::io::Write; +use std::sync::{Arc, RwLock}; -use std::hash::BuildHasherDefault; use crate::types::hash::FNVHash; +use std::hash::BuildHasherDefault; use std::sync::atomic::{AtomicIsize, Ordering}; -use std::thread; use std::sync::mpsc; +use std::thread; #[cfg(not(target_arch = "wasm32"))] use reqwest; @@ -100,7 +100,9 @@ pub struct ChunkBuffer { } impl ChunkBuffer { - pub fn new() -> ChunkBuffer { Default::default() } + pub fn new() -> ChunkBuffer { + Default::default() + } } struct ChunkRenderInfo { @@ -250,9 +252,13 @@ impl Renderer { if rm.version() != self.resource_version { self.resource_version = rm.version(); trace!("Updating textures to {}", self.resource_version); - self.textures.write().unwrap().update_textures(self.resource_version); + self.textures + .write() + .unwrap() + .update_textures(self.resource_version); - self.model.rebuild_models(self.resource_version, &self.textures); + self.model + .rebuild_models(self.resource_version, &self.textures); } } @@ -261,34 +267,47 @@ impl Renderer { self.height = height; gl::viewport(0, 0, width as i32, height as i32); - self.perspective_matrix = cgmath::Matrix4::from( - cgmath::PerspectiveFov { - fovy: cgmath::Rad::from(cgmath::Deg(90f32)), - aspect: (width as f32 / height as f32), - near: 0.1f32, - far: 500.0f32, - } - ); + self.perspective_matrix = cgmath::Matrix4::from(cgmath::PerspectiveFov { + fovy: cgmath::Rad::from(cgmath::Deg(90f32)), + aspect: (width as f32 / height as f32), + near: 0.1f32, + far: 500.0f32, + }); self.init_trans(width, height); } self.view_vector = cgmath::Vector3::new( - ((self.camera.yaw - PI64/2.0).cos() * -self.camera.pitch.cos()) as f32, + ((self.camera.yaw - PI64 / 2.0).cos() * -self.camera.pitch.cos()) as f32, (-self.camera.pitch.sin()) as f32, - (-(self.camera.yaw - PI64/2.0).sin() * -self.camera.pitch.cos()) as f32 + (-(self.camera.yaw - PI64 / 2.0).sin() * -self.camera.pitch.cos()) as f32, + ); + let camera = cgmath::Point3::new( + -self.camera.pos.x as f32, + -self.camera.pos.y as f32, + self.camera.pos.z as f32, ); - let camera = cgmath::Point3::new(-self.camera.pos.x as f32, -self.camera.pos.y as f32, self.camera.pos.z as f32); let camera_matrix = cgmath::Matrix4::look_at( camera, - camera + cgmath::Point3::new(-self.view_vector.x, -self.view_vector.y, self.view_vector.z).to_vec(), - cgmath::Vector3::new(0.0, -1.0, 0.0) + camera + + cgmath::Point3::new(-self.view_vector.x, -self.view_vector.y, self.view_vector.z) + .to_vec(), + cgmath::Vector3::new(0.0, -1.0, 0.0), ); self.camera_matrix = camera_matrix * cgmath::Matrix4::from_nonuniform_scale(-1.0, 1.0, 1.0); - self.frustum = collision::Frustum::from_matrix4(self.perspective_matrix * self.camera_matrix).unwrap(); + self.frustum = + collision::Frustum::from_matrix4(self.perspective_matrix * self.camera_matrix).unwrap(); } - pub fn tick(&mut self, world: &mut world::World, delta: f64, width: u32, height: u32, physical_width: u32, physical_height: u32) { + pub fn tick( + &mut self, + world: &mut world::World, + delta: f64, + width: u32, + height: u32, + physical_width: u32, + physical_height: u32, + ) { self.update_textures(delta); let trans = self.trans.as_mut().unwrap(); @@ -301,18 +320,22 @@ impl Renderer { let time_offset = self.sky_offset * 0.9; gl::clear_color( - (122.0 / 255.0) * time_offset, - (165.0 / 255.0) * time_offset, - (247.0 / 255.0) * time_offset, - 1.0 + (122.0 / 255.0) * time_offset, + (165.0 / 255.0) * time_offset, + (247.0 / 255.0) * time_offset, + 1.0, ); gl::clear(gl::ClearFlags::Color | gl::ClearFlags::Depth); // Chunk rendering self.chunk_shader.program.use_program(); - self.chunk_shader.perspective_matrix.set_matrix4(&self.perspective_matrix); - self.chunk_shader.camera_matrix.set_matrix4(&self.camera_matrix); + self.chunk_shader + .perspective_matrix + .set_matrix4(&self.perspective_matrix); + self.chunk_shader + .camera_matrix + .set_matrix4(&self.camera_matrix); self.chunk_shader.texture.set_int(0); self.chunk_shader.light_level.set_float(self.light_level); self.chunk_shader.sky_offset.set_float(self.sky_offset); @@ -320,36 +343,71 @@ impl Renderer { for (pos, info) in world.get_render_list() { if let Some(solid) = info.solid.as_ref() { if solid.count > 0 { - self.chunk_shader.offset.set_int3(pos.0, pos.1 * 4096, pos.2); + self.chunk_shader + .offset + .set_int3(pos.0, pos.1 * 4096, pos.2); solid.array.bind(); - gl::draw_elements(gl::TRIANGLES, solid.count as i32, self.element_buffer_type, 0); + gl::draw_elements( + gl::TRIANGLES, + solid.count as i32, + self.element_buffer_type, + 0, + ); } } } // Line rendering // Model rendering - self.model.draw(&self.frustum, &self.perspective_matrix, &self.camera_matrix, self.light_level, self.sky_offset); + self.model.draw( + &self.frustum, + &self.perspective_matrix, + &self.camera_matrix, + self.light_level, + self.sky_offset, + ); if world.copy_cloud_heightmap(&mut self.clouds.heightmap_data) { self.clouds.dirty = true; } - self.clouds.draw(&self.camera.pos, &self.perspective_matrix, &self.camera_matrix, self.light_level, self.sky_offset, delta); + self.clouds.draw( + &self.camera.pos, + &self.perspective_matrix, + &self.camera_matrix, + self.light_level, + self.sky_offset, + delta, + ); // Trans chunk rendering self.chunk_shader_alpha.program.use_program(); - self.chunk_shader_alpha.perspective_matrix.set_matrix4(&self.perspective_matrix); - self.chunk_shader_alpha.camera_matrix.set_matrix4(&self.camera_matrix); + self.chunk_shader_alpha + .perspective_matrix + .set_matrix4(&self.perspective_matrix); + self.chunk_shader_alpha + .camera_matrix + .set_matrix4(&self.camera_matrix); self.chunk_shader_alpha.texture.set_int(0); - self.chunk_shader_alpha.light_level.set_float(self.light_level); - self.chunk_shader_alpha.sky_offset.set_float(self.sky_offset); + self.chunk_shader_alpha + .light_level + .set_float(self.light_level); + self.chunk_shader_alpha + .sky_offset + .set_float(self.sky_offset); // Copy the depth buffer trans.main.bind_read(); trans.trans.bind_draw(); gl::blit_framebuffer( - 0, 0, physical_width as i32, physical_height as i32, - 0, 0, physical_width as i32, physical_height as i32, - gl::ClearFlags::Depth, gl::NEAREST + 0, + 0, + physical_width as i32, + physical_height as i32, + 0, + 0, + physical_width as i32, + physical_height as i32, + gl::ClearFlags::Depth, + gl::NEAREST, ); gl::enable(gl::BLEND); @@ -359,14 +417,26 @@ impl Renderer { gl::clear(gl::ClearFlags::Color); gl::clear_buffer(gl::COLOR, 0, &mut [0.0, 0.0, 0.0, 1.0]); gl::clear_buffer(gl::COLOR, 1, &mut [0.0, 0.0, 0.0, 0.0]); - gl::blend_func_separate(gl::ONE_FACTOR, gl::ONE_FACTOR, gl::ZERO_FACTOR, gl::ONE_MINUS_SRC_ALPHA); + gl::blend_func_separate( + gl::ONE_FACTOR, + gl::ONE_FACTOR, + gl::ZERO_FACTOR, + gl::ONE_MINUS_SRC_ALPHA, + ); for (pos, info) in world.get_render_list().iter().rev() { if let Some(trans) = info.trans.as_ref() { if trans.count > 0 { - self.chunk_shader_alpha.offset.set_int3(pos.0, pos.1 * 4096, pos.2); + self.chunk_shader_alpha + .offset + .set_int3(pos.0, pos.1 * 4096, pos.2); trans.array.bind(); - gl::draw_elements(gl::TRIANGLES, trans.count as i32, self.element_buffer_type, 0); + gl::draw_elements( + gl::TRIANGLES, + trans.count as i32, + self.element_buffer_type, + 0, + ); } } } @@ -395,7 +465,8 @@ impl Renderer { let (data, ty) = self::generate_element_buffer(size); self.element_buffer_type = ty; self.element_buffer.bind(gl::ELEMENT_ARRAY_BUFFER); - self.element_buffer.set_data(gl::ELEMENT_ARRAY_BUFFER, &data, gl::DYNAMIC_DRAW); + self.element_buffer + .set_data(gl::ELEMENT_ARRAY_BUFFER, &data, gl::DYNAMIC_DRAW); self.element_buffer_size = size; } } @@ -431,16 +502,27 @@ impl Renderer { info.buffer.bind(gl::ARRAY_BUFFER); if new || info.buffer_size < data.len() { info.buffer_size = data.len(); - info.buffer.set_data(gl::ARRAY_BUFFER, data, gl::DYNAMIC_DRAW); + info.buffer + .set_data(gl::ARRAY_BUFFER, data, gl::DYNAMIC_DRAW); } else { info.buffer.re_set_data(gl::ARRAY_BUFFER, data); } - self.chunk_shader.position.vertex_pointer(3, gl::FLOAT, false, 40, 0); - self.chunk_shader.texture_info.vertex_pointer(4, gl::UNSIGNED_SHORT, false, 40, 12); - self.chunk_shader.texture_offset.vertex_pointer(3, gl::SHORT, false, 40, 20); - self.chunk_shader.color.vertex_pointer(3, gl::UNSIGNED_BYTE, true, 40, 28); - self.chunk_shader.lighting.vertex_pointer(2, gl::UNSIGNED_SHORT, false, 40, 32); + self.chunk_shader + .position + .vertex_pointer(3, gl::FLOAT, false, 40, 0); + self.chunk_shader + .texture_info + .vertex_pointer(4, gl::UNSIGNED_SHORT, false, 40, 12); + self.chunk_shader + .texture_offset + .vertex_pointer(3, gl::SHORT, false, 40, 20); + self.chunk_shader + .color + .vertex_pointer(3, gl::UNSIGNED_BYTE, true, 40, 28); + self.chunk_shader + .lighting + .vertex_pointer(2, gl::UNSIGNED_SHORT, false, 40, 32); info.count = count; } @@ -476,16 +558,27 @@ impl Renderer { info.buffer.bind(gl::ARRAY_BUFFER); if new || info.buffer_size < data.len() { info.buffer_size = data.len(); - info.buffer.set_data(gl::ARRAY_BUFFER, data, gl::DYNAMIC_DRAW); + info.buffer + .set_data(gl::ARRAY_BUFFER, data, gl::DYNAMIC_DRAW); } else { info.buffer.re_set_data(gl::ARRAY_BUFFER, data); } - self.chunk_shader_alpha.position.vertex_pointer(3, gl::FLOAT, false, 40, 0); - self.chunk_shader_alpha.texture_info.vertex_pointer(4, gl::UNSIGNED_SHORT, false, 40, 12); - self.chunk_shader_alpha.texture_offset.vertex_pointer(3, gl::SHORT, false, 40, 20); - self.chunk_shader_alpha.color.vertex_pointer(3, gl::UNSIGNED_BYTE, true, 40, 28); - self.chunk_shader_alpha.lighting.vertex_pointer(2, gl::UNSIGNED_SHORT, false, 40, 32); + self.chunk_shader_alpha + .position + .vertex_pointer(3, gl::FLOAT, false, 40, 0); + self.chunk_shader_alpha + .texture_info + .vertex_pointer(4, gl::UNSIGNED_SHORT, false, 40, 12); + self.chunk_shader_alpha + .texture_offset + .vertex_pointer(3, gl::SHORT, false, 40, 20); + self.chunk_shader_alpha + .color + .vertex_pointer(3, gl::UNSIGNED_BYTE, true, 40, 28); + self.chunk_shader_alpha + .lighting + .vertex_pointer(2, gl::UNSIGNED_SHORT, false, 40, 32); info.count = count; } @@ -500,19 +593,23 @@ impl Renderer { unsafe { data.set_len(len); } - self.gl_texture.get_pixels(gl::TEXTURE_2D_ARRAY, - 0, - gl::RGBA, - gl::UNSIGNED_BYTE, - &mut data[..]); - self.gl_texture.image_3d(gl::TEXTURE_2D_ARRAY, - 0, - ATLAS_SIZE as u32, - ATLAS_SIZE as u32, - tex.atlases.len() as u32, - gl::RGBA, - gl::UNSIGNED_BYTE, - &data[..]); + self.gl_texture.get_pixels( + gl::TEXTURE_2D_ARRAY, + 0, + gl::RGBA, + gl::UNSIGNED_BYTE, + &mut data[..], + ); + self.gl_texture.image_3d( + gl::TEXTURE_2D_ARRAY, + 0, + ATLAS_SIZE as u32, + ATLAS_SIZE as u32, + tex.atlases.len() as u32, + gl::RGBA, + gl::UNSIGNED_BYTE, + &data[..], + ); self.texture_layers = tex.atlases.len(); } tex.pending_uploads.len() @@ -524,17 +621,19 @@ impl Renderer { let atlas = upload.0; let rect = upload.1; let img = &upload.2; - self.gl_texture.sub_image_3d(gl::TEXTURE_2D_ARRAY, - 0, - rect.x as u32, - rect.y as u32, - atlas as u32, - rect.width as u32, - rect.height as u32, - 1, - gl::RGBA, - gl::UNSIGNED_BYTE, - &img[..]); + self.gl_texture.sub_image_3d( + gl::TEXTURE_2D_ARRAY, + 0, + rect.x as u32, + rect.y as u32, + atlas as u32, + rect.width as u32, + rect.height as u32, + 1, + gl::RGBA, + gl::UNSIGNED_BYTE, + &img[..], + ); } tex.pending_uploads.clear(); } @@ -566,30 +665,36 @@ impl Renderer { if ani.remaining_time <= 0.0 { ani.current_frame = (ani.current_frame + 1) % ani.frames.len(); ani.remaining_time += ani.frames[ani.current_frame].time as f64; - let offset = ani.texture.width * ani.texture.width * - ani.frames[ani.current_frame].index * 4; + let offset = + ani.texture.width * ani.texture.width * ani.frames[ani.current_frame].index * 4; let offset2 = offset + ani.texture.width * ani.texture.width * 4; - self.gl_texture.sub_image_3d(gl::TEXTURE_2D_ARRAY, - 0, - ani.texture.get_x() as u32, - ani.texture.get_y() as u32, - ani.texture.atlas as u32, - ani.texture.get_width() as u32, - ani.texture.get_height() as u32, - 1, - gl::RGBA, - gl::UNSIGNED_BYTE, - &ani.data[offset..offset2]); + self.gl_texture.sub_image_3d( + gl::TEXTURE_2D_ARRAY, + 0, + ani.texture.get_x() as u32, + ani.texture.get_y() as u32, + ani.texture.atlas as u32, + ani.texture.get_width() as u32, + ani.texture.get_height() as u32, + 1, + gl::RGBA, + gl::UNSIGNED_BYTE, + &ani.data[offset..offset2], + ); } else { ani.remaining_time -= delta / 3.0; } } - } fn init_trans(&mut self, width: u32, height: u32) { self.trans = None; - self.trans = Some(TransInfo::new(width, height, &self.chunk_shader_alpha, &self.trans_shader)); + self.trans = Some(TransInfo::new( + width, + height, + &self.chunk_shader_alpha, + &self.trans_shader, + )); } pub fn get_textures(&self) -> Arc> { @@ -615,9 +720,7 @@ impl Renderer { } pub fn get_texture(textures: &RwLock, name: &str) -> Texture { - let tex = { - textures.read().unwrap().get_texture(name) - }; + let tex = { textures.read().unwrap().get_texture(name) }; match tex { Some(val) => val, None => { @@ -635,9 +738,7 @@ impl Renderer { } pub fn get_skin(&self, textures: &RwLock, url: &str) -> Texture { - let tex = { - textures.read().unwrap().get_skin(url) - }; + let tex = { textures.read().unwrap().get_skin(url) }; match tex { Some(val) => val, None => { @@ -685,27 +786,59 @@ init_shader! { } impl TransInfo { - pub fn new(width: u32, height: u32, chunk_shader: &ChunkShaderAlpha, shader: &TransShader) -> TransInfo { + pub fn new( + width: u32, + height: u32, + chunk_shader: &ChunkShaderAlpha, + shader: &TransShader, + ) -> TransInfo { let trans = gl::Framebuffer::new(); trans.bind(); let accum = gl::Texture::new(); accum.bind(gl::TEXTURE_2D); - accum.image_2d_ex(gl::TEXTURE_2D, 0, width, height, gl::RGBA16F, gl::RGBA, gl::FLOAT, None); + accum.image_2d_ex( + gl::TEXTURE_2D, + 0, + width, + height, + gl::RGBA16F, + gl::RGBA, + gl::FLOAT, + None, + ); accum.set_parameter(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR); accum.set_parameter(gl::TEXTURE_2D, gl::TEXTURE_MAX_LEVEL, gl::LINEAR); trans.texture_2d(gl::COLOR_ATTACHMENT_0, gl::TEXTURE_2D, &accum, 0); let revealage = gl::Texture::new(); revealage.bind(gl::TEXTURE_2D); - revealage.image_2d_ex(gl::TEXTURE_2D, 0, width, height, gl::R16F, gl::RED, gl::FLOAT, None); + revealage.image_2d_ex( + gl::TEXTURE_2D, + 0, + width, + height, + gl::R16F, + gl::RED, + gl::FLOAT, + None, + ); revealage.set_parameter(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR); revealage.set_parameter(gl::TEXTURE_2D, gl::TEXTURE_MAX_LEVEL, gl::LINEAR); trans.texture_2d(gl::COLOR_ATTACHMENT_1, gl::TEXTURE_2D, &revealage, 0); let trans_depth = gl::Texture::new(); trans_depth.bind(gl::TEXTURE_2D); - trans_depth.image_2d_ex(gl::TEXTURE_2D, 0, width, height, gl::DEPTH_COMPONENT24, gl::DEPTH_COMPONENT, gl::UNSIGNED_BYTE, None); + trans_depth.image_2d_ex( + gl::TEXTURE_2D, + 0, + width, + height, + gl::DEPTH_COMPONENT24, + gl::DEPTH_COMPONENT, + gl::UNSIGNED_BYTE, + None, + ); trans_depth.set_parameter(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR); trans_depth.set_parameter(gl::TEXTURE_2D, gl::TEXTURE_MAX_LEVEL, gl::LINEAR); trans.texture_2d(gl::DEPTH_ATTACHMENT, gl::TEXTURE_2D, &trans_depth, 0); @@ -721,13 +854,37 @@ impl TransInfo { let fb_color = gl::Texture::new(); fb_color.bind(gl::TEXTURE_2D_MULTISAMPLE); - fb_color.image_2d_sample(gl::TEXTURE_2D_MULTISAMPLE, NUM_SAMPLES, width, height, gl::RGBA8, false); - main.texture_2d(gl::COLOR_ATTACHMENT_0, gl::TEXTURE_2D_MULTISAMPLE, &fb_color, 0); + fb_color.image_2d_sample( + gl::TEXTURE_2D_MULTISAMPLE, + NUM_SAMPLES, + width, + height, + gl::RGBA8, + false, + ); + main.texture_2d( + gl::COLOR_ATTACHMENT_0, + gl::TEXTURE_2D_MULTISAMPLE, + &fb_color, + 0, + ); let fb_depth = gl::Texture::new(); fb_depth.bind(gl::TEXTURE_2D_MULTISAMPLE); - fb_depth.image_2d_sample(gl::TEXTURE_2D_MULTISAMPLE, NUM_SAMPLES, width, height, gl::DEPTH_COMPONENT24, false); - main.texture_2d(gl::DEPTH_ATTACHMENT, gl::TEXTURE_2D_MULTISAMPLE, &fb_depth, 0); + fb_depth.image_2d_sample( + gl::TEXTURE_2D_MULTISAMPLE, + NUM_SAMPLES, + width, + height, + gl::DEPTH_COMPONENT24, + false, + ); + main.texture_2d( + gl::DEPTH_ATTACHMENT, + gl::TEXTURE_2D_MULTISAMPLE, + &fb_depth, + 0, + ); gl::check_framebuffer_status(); gl::unbind_framebuffer(); @@ -739,7 +896,11 @@ impl TransInfo { buffer.bind(gl::ARRAY_BUFFER); let mut data = vec![]; - for f in [-1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0].iter() { + for f in [ + -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, + ] + .iter() + { data.write_f32::(*f).unwrap(); } buffer.set_data(gl::ARRAY_BUFFER, &data, gl::STATIC_DRAW); @@ -792,12 +953,17 @@ pub struct TextureManager { free_dynamics: Vec, skins: HashMap>, - //_skin_thread: thread::JoinHandle<()>, } impl TextureManager { - fn new(res: Arc>) -> (TextureManager, mpsc::Sender, mpsc::Receiver<(String, Option)>) { + fn new( + res: Arc>, + ) -> ( + TextureManager, + mpsc::Sender, + mpsc::Receiver<(String, Option)>, + ) { let (tx, rx) = mpsc::channel(); let (stx, srx) = mpsc::channel(); //let skin_thread = thread::spawn(|| Self::process_skins(srx, tx)); @@ -815,7 +981,6 @@ impl TextureManager { dynamic_textures: HashMap::with_hasher(BuildHasherDefault::default()), free_dynamics: Vec::new(), skins: HashMap::with_hasher(BuildHasherDefault::default()), - //_skin_thread: skin_thread, }; tm.add_defaults(); @@ -823,31 +988,30 @@ impl TextureManager { } fn add_defaults(&mut self) { - self.put_texture("steven", - "missing_texture", - 2, - 2, - vec![ - 0, 0, 0, 255, - 255, 0, 255, 255, - 255, 0, 255, 255, - 0, 0, 0, 255, - ]); - self.put_texture("steven", - "solid", - 1, - 1, - vec![ - 255, 255, 255, 255, - ]); + self.put_texture( + "steven", + "missing_texture", + 2, + 2, + vec![ + 0, 0, 0, 255, 255, 0, 255, 255, 255, 0, 255, 255, 0, 0, 0, 255, + ], + ); + self.put_texture("steven", "solid", 1, 1, vec![255, 255, 255, 255]); } #[cfg(target_arch = "wasm32")] - fn process_skins(recv: mpsc::Receiver, reply: mpsc::Sender<(String, Option)>) { + fn process_skins( + recv: mpsc::Receiver, + reply: mpsc::Sender<(String, Option)>, + ) { } #[cfg(not(target_arch = "wasm32"))] - fn process_skins(recv: mpsc::Receiver, reply: mpsc::Sender<(String, Option)>) { + fn process_skins( + recv: mpsc::Receiver, + reply: mpsc::Sender<(String, Option)>, + ) { println!("in process_skins thread"); let client = reqwest::blocking::Client::new(); loop { @@ -858,21 +1022,24 @@ impl TextureManager { match Self::obtain_skin(&client, &hash) { Ok(img) => { let _ = reply.send((hash, Some(img))); - }, + } Err(err) => { error!("Failed to get skin {:?}: {}", hash, err); let _ = reply.send((hash, None)); - }, + } } } } #[cfg(not(target_arch = "wasm32"))] - fn obtain_skin(client: &::reqwest::blocking::Client, hash: &str) -> Result { + fn obtain_skin( + client: &::reqwest::blocking::Client, + hash: &str, + ) -> Result { use std::io::Read; - use std_or_web::fs; - use std::path::Path; use std::io::{Error, ErrorKind}; + use std::path::Path; + use std_or_web::fs; let path = format!("skin-cache/{}/{}.png", &hash[..2], hash); let cache_path = Path::new(&path); fs::create_dir_all(cache_path.parent().unwrap())?; @@ -892,7 +1059,7 @@ impl TextureManager { }; let mut buf = vec![]; match res.read_to_end(&mut buf) { - Ok(_) => {}, + Ok(_) => {} Err(err) => { // TODO: different error for failure to read? return Err(Error::new(ErrorKind::InvalidData, err)); @@ -914,9 +1081,9 @@ impl TextureManager { // Needs changing to the new format let mut new = image::DynamicImage::new_rgba8(64, 64); new.copy_from(&img, 0, 0); - for xx in 0 .. 4 { - for yy in 0 .. 16 { - for section in 0 .. 4 { + for xx in 0..4 { + for yy in 0..16 { + for section in 0..4 { let os = match section { 0 => 2, 1 => 1, @@ -924,8 +1091,16 @@ impl TextureManager { 3 => 3, _ => unreachable!(), }; - new.put_pixel(16 + (3 - xx) + section * 4, 48 + yy, img.get_pixel(xx + os * 4, 16 + yy)); - new.put_pixel(32 + (3 - xx) + section * 4, 48 + yy, img.get_pixel(xx + 40 + os * 4, 16 + yy)); + new.put_pixel( + 16 + (3 - xx) + section * 4, + 48 + yy, + img.get_pixel(xx + os * 4, 16 + yy), + ); + new.put_pixel( + 32 + (3 - xx) + section * 4, + 48 + yy, + img.get_pixel(xx + 40 + os * 4, 16 + yy), + ); } } } @@ -942,8 +1117,8 @@ impl TextureManager { (40, 16, 16, 16), ]; for bl in blacklist.iter() { - for x in bl.0 .. (bl.0 + bl.2) { - for y in bl.1 .. (bl.1 + bl.3) { + for x in bl.0..(bl.0 + bl.2) { + for y in bl.1..(bl.1 + bl.3) { let mut col = img.get_pixel(x, y); col.0[3] = 255; img.put_pixel(x, y, col); @@ -977,7 +1152,8 @@ impl TextureManager { let (width, height) = img.dimensions(); (width, height, img.to_rgba().into_vec()) }; - let new_tex = self.put_texture("steven-dynamic", n, width as u32, height as u32, data); + let new_tex = + self.put_texture("steven-dynamic", n, width as u32, height as u32, data); self.dynamic_textures.get_mut(n).unwrap().0 = new_tex; } else if !self.textures.contains_key(name) { self.load_texture(name); @@ -1005,7 +1181,11 @@ impl TextureManager { let res = self.resources.clone(); // TODO: This shouldn't be hardcoded to steve but instead // have a way to select alex as a default. - let img = if let Some(mut val) = res.read().unwrap().open("minecraft", "textures/entity/steve.png") { + let img = if let Some(mut val) = res + .read() + .unwrap() + .open("minecraft", "textures/entity/steve.png") + { let mut data = Vec::new(); val.read_to_end(&mut data).unwrap(); image::load_from_memory(&data).unwrap() @@ -1018,7 +1198,9 @@ impl TextureManager { } fn update_skin(&mut self, hash: String, img: image::DynamicImage) { - if !self.skins.contains_key(&hash) { return; } + if !self.skins.contains_key(&hash) { + return; + } let name = format!("steven-dynamic:skin-{}", hash); let tex = self.get_texture(&name).unwrap(); let rect = atlas::Rect { @@ -1028,8 +1210,12 @@ impl TextureManager { height: tex.height, }; - self.pending_uploads.push((tex.atlas, rect, img.to_rgba().into_vec())); - self.dynamic_textures.get_mut(&format!("skin-{}", hash)).unwrap().1 = img; + self.pending_uploads + .push((tex.atlas, rect, img.to_rgba().into_vec())); + self.dynamic_textures + .get_mut(&format!("skin-{}", hash)) + .unwrap() + .1 = img; } fn get_texture(&self, name: &str) -> Option { @@ -1070,23 +1256,27 @@ impl TextureManager { self.insert_texture_dummy(plugin, name); } - fn load_animation(&mut self, - plugin: &str, - name: &str, - img: &image::DynamicImage, - data: Vec) - -> Option { + fn load_animation( + &mut self, + plugin: &str, + name: &str, + img: &image::DynamicImage, + data: Vec, + ) -> Option { let path = format!("textures/{}.png.mcmeta", name); let res = self.resources.clone(); if let Some(val) = res.read().unwrap().open(plugin, &path) { let meta: serde_json::Value = serde_json::from_reader(val).unwrap(); let animation = meta.get("animation").unwrap(); - let frame_time = animation.get("frametime").and_then(|v| v.as_i64()).unwrap_or(1); - let interpolate = animation.get("interpolate") - .and_then(|v| v.as_bool()) - .unwrap_or(false); - let frames = if let Some(frames) = animation.get("frames") - .and_then(|v| v.as_array()) { + let frame_time = animation + .get("frametime") + .and_then(|v| v.as_i64()) + .unwrap_or(1); + let interpolate = animation + .get("interpolate") + .and_then(|v| v.as_bool()) + .unwrap_or(false); + let frames = if let Some(frames) = animation.get("frames").and_then(|v| v.as_array()) { let mut out = Vec::with_capacity(frames.len()); for frame in frames { if let Some(index) = frame.as_i64() { @@ -1095,7 +1285,7 @@ impl TextureManager { time: frame_time, }) } else { - out.push(AnimationFrame{ + out.push(AnimationFrame { index: frame.get("index").unwrap().as_i64().unwrap() as usize, time: frame_time * frame.get("frameTime").unwrap().as_i64().unwrap(), }) @@ -1127,13 +1317,14 @@ impl TextureManager { None } - fn put_texture(&mut self, - plugin: &str, - name: &str, - width: u32, - height: u32, - data: Vec) - -> Texture { + fn put_texture( + &mut self, + plugin: &str, + name: &str, + width: u32, + height: u32, + data: Vec, + ) -> Texture { let (atlas, rect) = self.find_free(width as usize, height as usize); self.pending_uploads.push((atlas, rect, data)); @@ -1224,19 +1415,27 @@ impl TextureManager { height, }; self.pending_uploads.push((tex.atlas, rect, data)); - let mut t = tex.relative(0.0, 0.0, (width as f32) / (tex.width as f32), (height as f32) / (tex.height as f32)); + let mut t = tex.relative( + 0.0, + 0.0, + (width as f32) / (tex.width as f32), + (height as f32) / (tex.height as f32), + ); let old_name = mem::replace(&mut tex.name, format!("steven-dynamic:{}", name)); - self.dynamic_textures.insert(name.to_owned(), (tex.clone(), img)); + self.dynamic_textures + .insert(name.to_owned(), (tex.clone(), img)); // We need to rename the texture itself so that get_texture calls // work with the new name let mut old = self.textures.remove(&old_name).unwrap(); old.name = format!("steven-dynamic:{}", name); t.name = old.name.clone(); - self.textures.insert(format!("steven-dynamic:{}", name), old); + self.textures + .insert(format!("steven-dynamic:{}", name), old); t } else { let tex = self.put_texture("steven-dynamic", name, width as u32, height as u32, data); - self.dynamic_textures.insert(name.to_owned(), (tex.clone(), img)); + self.dynamic_textures + .insert(name.to_owned(), (tex.clone(), img)); tex } } diff --git a/src/render/model.rs b/src/render/model.rs index 8298da18..c4d2a309 100644 --- a/src/render/model.rs +++ b/src/render/model.rs @@ -1,17 +1,16 @@ - use super::glsl; use super::shaders; +use crate::format::{self, Component}; use crate::gl; -use cgmath::{Point3, Matrix4, SquareMatrix}; +use crate::model::BlockVertex; +use crate::shared::Direction; +use crate::types::hash::FNVHash; +use byteorder::{NativeEndian, WriteBytesExt}; +use cgmath::{Matrix4, Point3, SquareMatrix}; use collision::{self, Frustum, Sphere}; use std::collections::HashMap; use std::hash::BuildHasherDefault; use std::sync::{Arc, RwLock}; -use crate::types::hash::FNVHash; -use crate::shared::Direction; -use byteorder::{WriteBytesExt, NativeEndian}; -use crate::model::BlockVertex; -use crate::format::{self, Component}; pub struct Manager { collections: Vec, @@ -42,17 +41,25 @@ impl Manager { m.add_collection( &greg.get("model_vertex"), &greg.get("model_frag"), - gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA + gl::SRC_ALPHA, + gl::ONE_MINUS_SRC_ALPHA, ); m.add_collection( &greg.get("sun_vertex"), &greg.get("sun_frag"), - gl::SRC_ALPHA, gl::ONE_FACTOR + gl::SRC_ALPHA, + gl::ONE_FACTOR, ); m } - pub fn add_collection(&mut self, vert: &str, frag: &str, blend_s: gl::Factor, blend_d: gl::Factor) -> CollectionKey { + pub fn add_collection( + &mut self, + vert: &str, + frag: &str, + blend_s: gl::Factor, + blend_d: gl::Factor, + ) -> CollectionKey { let collection = Collection { shader: ModelShader::new_manual(vert, frag), models: HashMap::with_hasher(BuildHasherDefault::default()), @@ -84,11 +91,26 @@ impl Manager { collection.shader.texture_offset.map(|v| v.enable()); collection.shader.color.map(|v| v.enable()); collection.shader.id.map(|v| v.enable()); - collection.shader.position.map(|v| v.vertex_pointer(3, gl::FLOAT, false, 36, 0)); - collection.shader.texture_info.map(|v| v.vertex_pointer(4, gl::UNSIGNED_SHORT, false, 36, 12)); - collection.shader.texture_offset.map(|v| v.vertex_pointer_int(3, gl::SHORT, 36, 20)); - collection.shader.color.map(|v| v.vertex_pointer(4, gl::UNSIGNED_BYTE, true, 36, 28)); - collection.shader.id.map(|v| v.vertex_pointer_int(1, gl::UNSIGNED_BYTE, 36, 32)); + collection + .shader + .position + .map(|v| v.vertex_pointer(3, gl::FLOAT, false, 36, 0)); + collection + .shader + .texture_info + .map(|v| v.vertex_pointer(4, gl::UNSIGNED_SHORT, false, 36, 12)); + collection + .shader + .texture_offset + .map(|v| v.vertex_pointer_int(3, gl::SHORT, 36, 20)); + collection + .shader + .color + .map(|v| v.vertex_pointer(4, gl::UNSIGNED_BYTE, true, 36, 28)); + collection + .shader + .id + .map(|v| v.vertex_pointer_int(1, gl::UNSIGNED_BYTE, 36, 32)); let mut model = Model { // For culling only @@ -125,7 +147,8 @@ impl Manager { if self.max_index < model.count as usize { let (data, ty) = super::generate_element_buffer(model.count as usize); self.index_buffer.bind(gl::ELEMENT_ARRAY_BUFFER); - self.index_buffer.set_data(gl::ELEMENT_ARRAY_BUFFER, &data, gl::DYNAMIC_DRAW); + self.index_buffer + .set_data(gl::ELEMENT_ARRAY_BUFFER, &data, gl::DYNAMIC_DRAW); self.max_index = model.count as usize; self.index_type = ty; } @@ -156,8 +179,12 @@ impl Manager { let _ = buffer.write_u16::(vert.texture.get_y() as u16); let _ = buffer.write_u16::(vert.texture.get_width() as u16); let _ = buffer.write_u16::(vert.texture.get_height() as u16); - let _ = buffer.write_i16::(((vert.texture.get_width() as f64) * 16.0 * vert.texture_x) as i16); - let _ = buffer.write_i16::(((vert.texture.get_height() as f64) * 16.0 * vert.texture_y) as i16); + let _ = buffer.write_i16::( + ((vert.texture.get_width() as f64) * 16.0 * vert.texture_x) as i16, + ); + let _ = buffer.write_i16::( + ((vert.texture.get_height() as f64) * 16.0 * vert.texture_y) as i16, + ); let _ = buffer.write_i16::(vert.texture.atlas as i16); let _ = buffer.write_i16::(0); let _ = buffer.write_u8(vert.r); @@ -174,12 +201,18 @@ impl Manager { if buffer.len() < model.buffer_size { model.buffer.re_set_data(gl::ARRAY_BUFFER, &buffer); } else { - model.buffer.set_data(gl::ARRAY_BUFFER, &buffer, gl::DYNAMIC_DRAW); + model + .buffer + .set_data(gl::ARRAY_BUFFER, &buffer, gl::DYNAMIC_DRAW); model.buffer_size = buffer.len(); } } - pub fn rebuild_models(&mut self, version: usize, textures: &Arc>) { + pub fn rebuild_models( + &mut self, + version: usize, + textures: &Arc>, + ) { for collection in &mut self.collections { for (_, model) in &mut collection.models { for vert in &mut model.verts { @@ -200,28 +233,57 @@ impl Manager { } } - pub fn draw(&mut self, frustum: &Frustum, perspective_matrix: &Matrix4, camera_matrix: &Matrix4, light_level: f32, sky_offset: f32) { + pub fn draw( + &mut self, + frustum: &Frustum, + perspective_matrix: &Matrix4, + camera_matrix: &Matrix4, + light_level: f32, + sky_offset: f32, + ) { gl::enable(gl::BLEND); for collection in &self.collections { collection.shader.program.use_program(); - collection.shader.perspective_matrix.map(|v| v.set_matrix4(perspective_matrix)); - collection.shader.camera_matrix.map(|v| v.set_matrix4(camera_matrix)); + collection + .shader + .perspective_matrix + .map(|v| v.set_matrix4(perspective_matrix)); + collection + .shader + .camera_matrix + .map(|v| v.set_matrix4(camera_matrix)); collection.shader.texture.map(|v| v.set_int(0)); - collection.shader.sky_offset.map(|v| v.set_float(sky_offset)); - collection.shader.light_level.map(|v| v.set_float(light_level)); + collection + .shader + .sky_offset + .map(|v| v.set_float(sky_offset)); + collection + .shader + .light_level + .map(|v| v.set_float(light_level)); gl::blend_func(collection.blend_s, collection.blend_d); for model in collection.models.values() { - if model.radius > 0.0 && frustum.contains(&Sphere { - center: Point3::new(model.x, -model.y, model.z), - radius: model.radius - }) == collision::Relation::Out { + if model.radius > 0.0 + && frustum.contains(&Sphere { + center: Point3::new(model.x, -model.y, model.z), + radius: model.radius, + }) == collision::Relation::Out + { continue; } model.array.bind(); - collection.shader.lighting.map(|v| v.set_float2(model.block_light, model.sky_light)); - collection.shader.model_matrix.map(|v| v.set_matrix4_multi(&model.matrix)); - collection.shader.color_mul.map(|v| v.set_float_mutli_raw(model.colors.as_ptr() as *const _, model.colors.len())); + collection + .shader + .lighting + .map(|v| v.set_float2(model.block_light, model.sky_light)); + collection + .shader + .model_matrix + .map(|v| v.set_matrix4_multi(&model.matrix)); + collection.shader.color_mul.map(|v| { + v.set_float_mutli_raw(model.colors.as_ptr() as *const _, model.colors.len()) + }); gl::draw_elements(gl::TRIANGLES, model.count, self.index_type, 0); } } @@ -301,23 +363,44 @@ init_shader! { // Helper methods pub fn append_box( verts: &mut Vec, - x: f32, y: f32, z: f32, - w: f32, h: f32, d: f32, textures: [Option; 6] + x: f32, + y: f32, + z: f32, + w: f32, + h: f32, + d: f32, + textures: [Option; 6], ) { - append_box_texture_scale(verts, x, y, z, w, h, d, textures, [ - [1.0, 1.0], - [1.0, 1.0], - [1.0, 1.0], - [1.0, 1.0], - [1.0, 1.0], - [1.0, 1.0] - ]); + append_box_texture_scale( + verts, + x, + y, + z, + w, + h, + d, + textures, + [ + [1.0, 1.0], + [1.0, 1.0], + [1.0, 1.0], + [1.0, 1.0], + [1.0, 1.0], + [1.0, 1.0], + ], + ); } pub fn append_box_texture_scale( verts: &mut Vec, - x: f32, y: f32, z: f32, - w: f32, h: f32, d: f32, - textures: [Option; 6], texture_scale: [[f64; 2]; 6]) { + x: f32, + y: f32, + z: f32, + w: f32, + h: f32, + d: f32, + textures: [Option; 6], + texture_scale: [[f64; 2]; 6], +) { for dir in Direction::all() { let tex = textures[dir.index()].clone(); if tex.is_none() { @@ -326,7 +409,11 @@ pub fn append_box_texture_scale( let tex = tex.unwrap(); for vert in BlockVertex::face_by_direction(dir) { let (rr, gg, bb) = if dir == Direction::West || dir == Direction::East { - ((255.0 * 0.8) as u8, (255.0 * 0.8) as u8, (255.0 * 0.8) as u8) + ( + (255.0 * 0.8) as u8, + (255.0 * 0.8) as u8, + (255.0 * 0.8) as u8, + ) } else { (255, 255, 255) }; @@ -356,7 +443,7 @@ pub struct FormatState<'a> { pub x_scale: f32, } -impl <'a> FormatState<'a> { +impl<'a> FormatState<'a> { pub fn build(&mut self, c: &Component, color: format::Color) { match *c { format::Component::Text(ref txt) => { diff --git a/src/render/shaders.rs b/src/render/shaders.rs index 100b01e3..c67a148a 100644 --- a/src/render/shaders.rs +++ b/src/render/shaders.rs @@ -12,12 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::render::glsl; use crate::gl; +use crate::render::glsl; use log::error; pub fn add_shaders(reg: &mut glsl::Registry) { - reg.register("lookup_texture", include_str!("shaders/lookup_texture.glsl")); + reg.register( + "lookup_texture", + include_str!("shaders/lookup_texture.glsl"), + ); reg.register("get_light", include_str!("shaders/get_light.glsl")); reg.register("ui_vertex", include_str!("shaders/ui_vertex.glsl")); @@ -41,12 +44,12 @@ pub fn add_shaders(reg: &mut glsl::Registry) { } macro_rules! get_shader { - ($reg:ident, $name:expr) => ( + ($reg:ident, $name:expr) => { $reg.get($name) - ); - ($reg:ident, $name:expr, $def:expr) => ( + }; + ($reg:ident, $name:expr, $def:expr) => { $reg.get_define($name, $def) - ) + }; } #[macro_export] diff --git a/src/render/ui.rs b/src/render/ui.rs index ea1a92db..bea74d47 100644 --- a/src/render/ui.rs +++ b/src/render/ui.rs @@ -12,16 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::sync::{Arc, RwLock}; -use std::collections::HashMap; -use crate::resources; use crate::gl; use crate::render; use crate::render::glsl; use crate::render::shaders; -use byteorder::{WriteBytesExt, NativeEndian}; +use crate::resources; +use byteorder::{NativeEndian, WriteBytesExt}; use image; use image::GenericImageView; +use std::collections::HashMap; +use std::sync::{Arc, RwLock}; const UI_WIDTH: f64 = 854.0; const UI_HEIGHT: f64 = 480.0; @@ -69,10 +69,11 @@ init_shader! { } impl UIState { - pub fn new(glsl: &glsl::Registry, - textures: Arc>, - res: Arc>) - -> UIState { + pub fn new( + glsl: &glsl::Registry, + textures: Arc>, + res: Arc>, + ) -> UIState { let shader = UIShader::new(glsl); let array = gl::VertexArray::new(); @@ -84,9 +85,15 @@ impl UIState { shader.texture_offset.enable(); shader.color.enable(); shader.position.vertex_pointer_int(3, gl::SHORT, 28, 0); - shader.texture_info.vertex_pointer(4, gl::UNSIGNED_SHORT, false, 28, 8); - shader.texture_offset.vertex_pointer_int(3, gl::SHORT, 28, 16); - shader.color.vertex_pointer(4, gl::UNSIGNED_BYTE, true, 28, 24); + shader + .texture_info + .vertex_pointer(4, gl::UNSIGNED_SHORT, false, 28, 8); + shader + .texture_offset + .vertex_pointer_int(3, gl::SHORT, 28, 16); + shader + .color + .vertex_pointer(4, gl::UNSIGNED_BYTE, true, 28, 24); let index_buffer = gl::Buffer::new(); index_buffer.bind(gl::ELEMENT_ARRAY_BUFFER); @@ -155,17 +162,21 @@ impl UIState { let (data, ty) = render::generate_element_buffer(self.count); self.index_type = ty; self.index_buffer.bind(gl::ELEMENT_ARRAY_BUFFER); - self.index_buffer.set_data(gl::ELEMENT_ARRAY_BUFFER, &data, gl::DYNAMIC_DRAW); + self.index_buffer + .set_data(gl::ELEMENT_ARRAY_BUFFER, &data, gl::DYNAMIC_DRAW); self.max_index = self.count; } - self.shader.screensize.set_float2(width as f32, height as f32); + self.shader + .screensize + .set_float2(width as f32, height as f32); self.buffer.bind(gl::ARRAY_BUFFER); self.index_buffer.bind(gl::ELEMENT_ARRAY_BUFFER); if self.data.len() > self.prev_size { self.prev_size = self.data.len(); - self.buffer.set_data(gl::ARRAY_BUFFER, &self.data, gl::STREAM_DRAW); + self.buffer + .set_data(gl::ARRAY_BUFFER, &self.data, gl::STREAM_DRAW); } else { self.buffer.re_set_data(gl::ARRAY_BUFFER, &self.data); } @@ -209,15 +220,19 @@ impl UIState { if page == 0 { let sw = (self.page_width / 16.0) as u32; let sh = (self.page_height / 16.0) as u32; - return p.relative((cx * sw + info.0 as u32) as f32 / (self.page_width as f32), - (cy * sh) as f32 / (self.page_height as f32), - (info.1 - info.0) as f32 / (self.page_width as f32), - (sh as f32) / (self.page_height as f32)) + return p.relative( + (cx * sw + info.0 as u32) as f32 / (self.page_width as f32), + (cy * sh) as f32 / (self.page_height as f32), + (info.1 - info.0) as f32 / (self.page_width as f32), + (sh as f32) / (self.page_height as f32), + ); } - p.relative((cx * 16 + info.0 as u32) as f32 / 256.0, - (cy * 16) as f32 / 256.0, - (info.1 - info.0) as f32 / 256.0, - 16.0 / 256.0) + p.relative( + (cx * 16 + info.0 as u32) as f32 / 256.0, + (cy * 16) as f32 / 256.0, + (info.1 - info.0) as f32 / 256.0, + 16.0 / 256.0, + ) } pub fn size_of_string(&self, val: &str) -> f64 { @@ -296,44 +311,47 @@ impl UIState { self.new_text_scaled(val, x, y, 1.0, 1.0, r, g, b) } - pub fn new_text_scaled(&mut self, - val: &str, - x: f64, - y: f64, - sx: f64, - sy: f64, - r: u8, - g: u8, - b: u8) - -> UIText { + pub fn new_text_scaled( + &mut self, + val: &str, + x: f64, + y: f64, + sx: f64, + sy: f64, + r: u8, + g: u8, + b: u8, + ) -> UIText { self.create_text(val, x, y, sx, sy, 0.0, r, g, b) } - pub fn new_text_rotated(&mut self, - val: &str, - x: f64, - y: f64, - sx: f64, - sy: f64, - rotation: f64, - r: u8, - g: u8, - b: u8) - -> UIText { + pub fn new_text_rotated( + &mut self, + val: &str, + x: f64, + y: f64, + sx: f64, + sy: f64, + rotation: f64, + r: u8, + g: u8, + b: u8, + ) -> UIText { self.create_text(val, x, y, sx, sy, rotation, r, g, b) } - fn create_text(&mut self, - val: &str, - x: f64, - y: f64, - sx: f64, - sy: f64, - rotation: f64, - r: u8, - g: u8, - b: u8) - -> UIText { + fn create_text( + &mut self, + val: &str, + x: f64, + y: f64, + sx: f64, + sy: f64, + rotation: f64, + r: u8, + g: u8, + b: u8, + ) -> UIText { let mut elements = Vec::new(); let mut offset = 0.0; for ch in val.chars() { @@ -361,30 +379,34 @@ impl UIState { dy = (16.0 * 0.5) + (tmpy * c + tmpx * s); } - let mut shadow = UIElement::new(&texture, - x + dsx * sx, - y + dsy * sy, - w * sx, - 16.0 * sy, - 0.0, - 0.0, - 1.0, - 1.0); + let mut shadow = UIElement::new( + &texture, + x + dsx * sx, + y + dsy * sy, + w * sx, + 16.0 * sy, + 0.0, + 0.0, + 1.0, + 1.0, + ); shadow.r = ((r as f64) * 0.25) as u8; shadow.g = ((g as f64) * 0.25) as u8; shadow.b = ((b as f64) * 0.25) as u8; shadow.rotation = rotation; elements.push(shadow); - let mut text = UIElement::new(&texture, - x + dx * sx, - y + dy * sy, - w * sx, - 16.0 * sy, - 0.0, - 0.0, - 1.0, - 1.0); + let mut text = UIElement::new( + &texture, + x + dx * sx, + y + dy * sy, + w * sx, + 16.0 * sy, + 0.0, + 0.0, + 1.0, + 1.0, + ); text.r = r; text.g = g; text.b = b; @@ -437,16 +459,17 @@ pub struct UIElement { } impl UIElement { - pub fn new(tex: &render::Texture, - x: f64, - y: f64, - width: f64, - height: f64, - tx: f64, - ty: f64, - tw: f64, - th: f64) - -> UIElement { + pub fn new( + tex: &render::Texture, + x: f64, + y: f64, + width: f64, + height: f64, + tx: f64, + ty: f64, + tw: f64, + th: f64, + ) -> UIElement { let twidth = tex.get_width(); let theight = tex.get_height(); UIElement { @@ -474,46 +497,56 @@ impl UIElement { pub fn bytes(&self, width: f64, height: f64) -> Vec { let mut buf = Vec::with_capacity(28 * 4); - self.append_vertex(&mut buf, - self.x, - self.y, - self.t_offsetx, - self.t_offsety, - width, - height); - self.append_vertex(&mut buf, - self.x + self.w, - self.y, - self.t_offsetx + self.t_sizew, - self.t_offsety, - width, - height); - self.append_vertex(&mut buf, - self.x, - self.y + self.h, - self.t_offsetx, - self.t_offsety + self.t_sizeh, - width, - height); - self.append_vertex(&mut buf, - self.x + self.w, - self.y + self.h, - self.t_offsetx + self.t_sizew, - self.t_offsety + self.t_sizeh, - width, - height); + self.append_vertex( + &mut buf, + self.x, + self.y, + self.t_offsetx, + self.t_offsety, + width, + height, + ); + self.append_vertex( + &mut buf, + self.x + self.w, + self.y, + self.t_offsetx + self.t_sizew, + self.t_offsety, + width, + height, + ); + self.append_vertex( + &mut buf, + self.x, + self.y + self.h, + self.t_offsetx, + self.t_offsety + self.t_sizeh, + width, + height, + ); + self.append_vertex( + &mut buf, + self.x + self.w, + self.y + self.h, + self.t_offsetx + self.t_sizew, + self.t_offsety + self.t_sizeh, + width, + height, + ); buf } #[allow(unused_must_use)] - pub fn append_vertex(&self, - buf: &mut Vec, - x: f64, - y: f64, - tx: i16, - ty: i16, - width: f64, - height: f64) { + pub fn append_vertex( + &self, + buf: &mut Vec, + x: f64, + y: f64, + tx: i16, + ty: i16, + width: f64, + height: f64, + ) { let mut dx = x as f64; let mut dy = y as f64; if self.rotation != 0.0 { diff --git a/src/resources.rs b/src/resources.rs index 9ebad809..50589faa 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -14,15 +14,15 @@ extern crate steven_resources as internal; -use std::thread; -use std::path; +use serde_json; +use std::collections::HashMap; +use std::hash::BuildHasherDefault; use std::io; -use std_or_web::fs; +use std::path; use std::sync::mpsc; use std::sync::{Arc, Mutex}; -use std::collections::HashMap; -use std::hash::BuildHasherDefault; -use serde_json; +use std::thread; +use std_or_web::fs; #[cfg(not(target_arch = "wasm32"))] use reqwest; @@ -32,7 +32,8 @@ use crate::types::hash::FNVHash; use crate::ui; const RESOURCES_VERSION: &str = "1.12.2"; -const VANILLA_CLIENT_URL: &str = "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"; +const VANILLA_CLIENT_URL: &str = + "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"; const ASSET_VERSION: &str = "1.12"; const ASSET_INDEX_URL: &str = "https://launchermeta.mojang.com/mc/assets/1.12/67e29e024e664064c1f04c728604f83c24cbc218/1.12.json"; @@ -85,9 +86,7 @@ impl Manager { version: 0, vanilla_chan: None, vanilla_assets_chan: None, - vanilla_progress: Arc::new(Mutex::new(Progress { - tasks: vec![], - })), + vanilla_progress: Arc::new(Mutex::new(Progress { tasks: vec![] })), }; m.add_pack(Box::new(InternalPack)); #[cfg(not(target_arch = "wasm32"))] @@ -95,7 +94,13 @@ impl Manager { m.download_vanilla(); m.download_assets(); } - (m, ManagerUI { progress_ui: vec!{}, num_tasks: 0 }) + ( + m, + ManagerUI { + progress_ui: vec![], + num_tasks: 0, + }, + ) } /// Returns the 'version' of the manager. The version is @@ -156,9 +161,12 @@ impl Manager { progress.tasks.retain(|v| v.progress < v.total); // Find out what we have to work with for task in &progress.tasks { - if !mui.progress_ui.iter() + if !mui + .progress_ui + .iter() .filter(|v| v.task_file == task.task_file) - .any(|v| v.task_name == task.task_name) { + .any(|v| v.task_name == task.task_name) + { mui.num_tasks += 1; // Add a ui element for it let background = ui::ImageBuilder::new() @@ -217,16 +225,22 @@ impl Manager { } let mut found = false; let mut prog = 1.0; - for task in progress.tasks.iter() + for task in progress + .tasks + .iter() .filter(|v| v.task_file == ui.task_file) - .filter(|v| v.task_name == ui.task_name) { + .filter(|v| v.task_name == ui.task_name) + { found = true; prog = task.progress as f64 / task.total as f64; } let background = ui.background.borrow(); let bar = ui.progress_bar.borrow(); // Let the progress bar finish - if !found && (background.y - ui.position).abs() < 0.7 * delta && (bar.width - 350.0).abs() < 1.0 * delta { + if !found + && (background.y - ui.position).abs() < 0.7 * delta + && (bar.width - 350.0).abs() < 1.0 * delta + { ui.closing = true; ui.position = -UI_HEIGHT; } @@ -258,7 +272,8 @@ impl Manager { } // Clean up dead elements - mui.progress_ui.retain(|v| v.position >= -UI_HEIGHT || !v.closing); + mui.progress_ui + .retain(|v| v.position >= -UI_HEIGHT || !v.closing); } fn add_pack(&mut self, pck: Box) { @@ -269,7 +284,12 @@ impl Manager { fn load_vanilla(&mut self) { let loc = format!("./resources-{}", RESOURCES_VERSION); let location = path::Path::new(&loc); - self.packs.insert(1, Box::new(DirPack { root: location.to_path_buf() })); + self.packs.insert( + 1, + Box::new(DirPack { + root: location.to_path_buf(), + }), + ); self.version += 1; } @@ -284,23 +304,34 @@ impl Manager { let location = path::Path::new(&loc).to_owned(); let progress_info = self.vanilla_progress.clone(); let (send, recv) = mpsc::channel(); - if fs::metadata(&location).is_ok(){ + if fs::metadata(&location).is_ok() { self.load_assets(); } else { self.vanilla_assets_chan = Some(recv); } thread::spawn(move || { let client = reqwest::blocking::Client::new(); - if fs::metadata(&location).is_err(){ + if fs::metadata(&location).is_err() { fs::create_dir_all(location.parent().unwrap()).unwrap(); - let res = client.get(ASSET_INDEX_URL) - .send() - .unwrap(); - - let length = res.headers().get(reqwest::header::CONTENT_LENGTH).unwrap().to_str().unwrap().parse::().unwrap(); - Self::add_task(&progress_info, "Downloading Asset Index", &*location.to_string_lossy(), length); + let res = client.get(ASSET_INDEX_URL).send().unwrap(); + + let length = res + .headers() + .get(reqwest::header::CONTENT_LENGTH) + .unwrap() + .to_str() + .unwrap() + .parse::() + .unwrap(); + Self::add_task( + &progress_info, + "Downloading Asset Index", + &*location.to_string_lossy(), + length, + ); { - let mut file = fs::File::create(format!("index-{}.tmp", ASSET_VERSION)).unwrap(); + let mut file = + fs::File::create(format!("index-{}.tmp", ASSET_VERSION)).unwrap(); let mut progress = ProgressRead { read: res, progress: &progress_info, @@ -316,16 +347,25 @@ impl Manager { let index: serde_json::Value = serde_json::from_reader(&file).unwrap(); let root_location = path::Path::new("./objects/"); let objects = index.get("objects").and_then(|v| v.as_object()).unwrap(); - Self::add_task(&progress_info, "Downloading Assets", "./objects", objects.len() as u64); + Self::add_task( + &progress_info, + "Downloading Assets", + "./objects", + objects.len() as u64, + ); for (k, v) in objects { let hash = v.get("hash").and_then(|v| v.as_str()).unwrap(); let hash_path = format!("{}/{}", &hash[..2], hash); let location = root_location.join(&hash_path); - if fs::metadata(&location).is_err(){ + if fs::metadata(&location).is_err() { fs::create_dir_all(location.parent().unwrap()).unwrap(); - let res = client.get(&format!("http://resources.download.minecraft.net/{}", hash_path)) - .send() - .unwrap(); + let res = client + .get(&format!( + "http://resources.download.minecraft.net/{}", + hash_path + )) + .send() + .unwrap(); let length = v.get("size").and_then(|v| v.as_u64()).unwrap(); Self::add_task(&progress_info, "Downloading Asset", k, length); let mut tmp_file = location.to_owned(); @@ -361,14 +401,24 @@ impl Manager { let progress_info = self.vanilla_progress.clone(); thread::spawn(move || { let client = reqwest::blocking::Client::new(); - let res = client.get(VANILLA_CLIENT_URL) - .send() - .unwrap(); + let res = client.get(VANILLA_CLIENT_URL).send().unwrap(); let mut file = fs::File::create(format!("{}.tmp", RESOURCES_VERSION)).unwrap(); - let length = res.headers().get(reqwest::header::CONTENT_LENGTH).unwrap().to_str().unwrap().parse::().unwrap(); + let length = res + .headers() + .get(reqwest::header::CONTENT_LENGTH) + .unwrap() + .to_str() + .unwrap() + .parse::() + .unwrap(); let task_file = format!("./resources-{}", RESOURCES_VERSION); - Self::add_task(&progress_info, "Downloading Core Assets", &task_file, length); + Self::add_task( + &progress_info, + "Downloading Core Assets", + &task_file, + length, + ); { let mut progress = ProgressRead { read: res, @@ -384,7 +434,12 @@ impl Manager { let mut zip = zip::ZipArchive::new(file).unwrap(); let task_file = format!("./resources-{}", RESOURCES_VERSION); - Self::add_task(&progress_info, "Unpacking Core Assets", &task_file, zip.len() as u64); + Self::add_task( + &progress_info, + "Unpacking Core Assets", + &task_file, + zip.len() as u64, + ); let loc = format!("./resources-{}", RESOURCES_VERSION); let location = path::Path::new(&loc); @@ -420,9 +475,12 @@ impl Manager { fn add_task_progress(progress: &Arc>, name: &str, file: &str, prog: u64) { let mut progress = progress.lock().unwrap(); - for task in progress.tasks.iter_mut() + for task in progress + .tasks + .iter_mut() .filter(|v| v.task_file == file) - .filter(|v| v.task_name == name) { + .filter(|v| v.task_name == name) + { task.progress += prog as u64; } } @@ -465,11 +523,12 @@ impl ObjectPack { let objects = index.get("objects").and_then(|v| v.as_object()).unwrap(); let mut hash_objs = HashMap::with_hasher(BuildHasherDefault::default()); for (k, v) in objects { - hash_objs.insert(k.clone(), v.get("hash").and_then(|v| v.as_str()).unwrap().to_owned()); - } - ObjectPack { - objects: hash_objs, + hash_objs.insert( + k.clone(), + v.get("hash").and_then(|v| v.as_str()).unwrap().to_owned(), + ); } + ObjectPack { objects: hash_objs } } } @@ -500,7 +559,7 @@ struct ProgressRead<'a, T> { task_file: String, } -impl <'a, T: io::Read> io::Read for ProgressRead<'a, T> { +impl<'a, T: io::Read> io::Read for ProgressRead<'a, T> { fn read(&mut self, buf: &mut [u8]) -> io::Result { let size = self.read.read(buf)?; Manager::add_task_progress(self.progress, &self.task_name, &self.task_file, size as u64); diff --git a/src/screen/connecting.rs b/src/screen/connecting.rs index fc10386d..9f37ef09 100644 --- a/src/screen/connecting.rs +++ b/src/screen/connecting.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::ui; use crate::render; +use crate::ui; pub struct Connecting { elements: Option, @@ -27,7 +27,6 @@ struct UIElements { _disclaimer: ui::TextRef, } - impl Connecting { pub fn new(target: &str) -> Connecting { Connecting { @@ -74,10 +73,12 @@ impl super::Screen for Connecting { self.elements = None } - fn tick(&mut self, - _delta: f64, - renderer: &mut render::Renderer, - _ui_container: &mut ui::Container) -> Option>{ + fn tick( + &mut self, + _delta: f64, + renderer: &mut render::Renderer, + _ui_container: &mut ui::Container, + ) -> Option> { let elements = self.elements.as_mut().unwrap(); elements.logo.tick(renderer); diff --git a/src/screen/edit_server.rs b/src/screen/edit_server.rs index dacd3ec0..e721737d 100644 --- a/src/screen/edit_server.rs +++ b/src/screen/edit_server.rs @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std_or_web::fs; use std::collections::BTreeMap; +use std_or_web::fs; -use crate::ui; use crate::render; +use crate::ui; use serde_json::{self, Value}; @@ -60,7 +60,8 @@ impl EditServerEntry { }; { - let servers = servers_info.as_object_mut() + let servers = servers_info + .as_object_mut() .unwrap() .get_mut("servers") .unwrap() @@ -76,7 +77,6 @@ impl EditServerEntry { let mut out = fs::File::create("servers.json").unwrap(); serde_json::to_writer_pretty(&mut out, &servers_info).unwrap(); } - } impl super::Screen for EditServerEntry { @@ -131,7 +131,8 @@ impl super::Screen for EditServerEntry { &server_name.borrow().input, &server_address.borrow().input, ); - game.screen_sys.replace_screen(Box::new(super::ServerList::new(None))); + game.screen_sys + .replace_screen(Box::new(super::ServerList::new(None))); true }); } @@ -150,7 +151,8 @@ impl super::Screen for EditServerEntry { .attach(&mut *cancel); cancel.add_text(txt); cancel.add_click_func(|_, game| { - game.screen_sys.replace_screen(Box::new(super::ServerList::new(None))); + game.screen_sys + .replace_screen(Box::new(super::ServerList::new(None))); true }); } @@ -169,11 +171,12 @@ impl super::Screen for EditServerEntry { self.elements = None } - fn tick(&mut self, - _delta: f64, - renderer: &mut render::Renderer, - _ui_container: &mut ui::Container) -> Option> { - + fn tick( + &mut self, + _delta: f64, + renderer: &mut render::Renderer, + _ui_container: &mut ui::Container, + ) -> Option> { let elements = self.elements.as_mut().unwrap(); elements.logo.tick(renderer); None diff --git a/src/screen/login.rs b/src/screen/login.rs index b5cacc4e..784554bf 100644 --- a/src/screen/login.rs +++ b/src/screen/login.rs @@ -19,12 +19,12 @@ use std::thread; use rand::{self, Rng}; -use crate::ui; -use crate::render; +use crate::auth; use crate::console; use crate::protocol; use crate::protocol::mojang; -use crate::auth; +use crate::render; +use crate::ui; pub struct Login { elements: Option, @@ -47,10 +47,12 @@ struct UIElements { profile: mojang::Profile, } - impl Login { pub fn new(vars: Rc) -> Login { - Login { elements: None, vars: vars } + Login { + elements: None, + vars: vars, + } } } @@ -82,7 +84,6 @@ impl super::Screen for Login { }); } - // Login Error let login_error = ui::TextBuilder::new() .text("") @@ -157,10 +158,12 @@ impl super::Screen for Login { self.elements = None } - fn tick(&mut self, - _delta: f64, - renderer: &mut render::Renderer, - _ui_container: &mut ui::Container) -> Option> { + fn tick( + &mut self, + _delta: f64, + renderer: &mut render::Renderer, + _ui_container: &mut ui::Container, + ) -> Option> { let elements = self.elements.as_mut().unwrap(); if elements.try_login.get() && elements.login_res.is_none() { @@ -171,10 +174,10 @@ impl super::Screen for Login { elements.login_btn_text.borrow_mut().text = "Logging in...".into(); let mut client_token = self.vars.get(auth::AUTH_CLIENT_TOKEN).clone(); if client_token.is_empty() { - client_token = std::iter::repeat(()).map(|()| rand::thread_rng() - .sample(&rand::distributions::Alphanumeric)) - .take(20) - .collect(); + client_token = std::iter::repeat(()) + .map(|()| rand::thread_rng().sample(&rand::distributions::Alphanumeric)) + .take(20) + .collect(); self.vars.set(auth::AUTH_CLIENT_TOKEN, client_token); } let client_token = self.vars.get(auth::AUTH_CLIENT_TOKEN).clone(); @@ -186,7 +189,8 @@ impl super::Screen for Login { if refresh { tx.send(profile.refresh(&client_token)).unwrap(); } else { - tx.send(mojang::Profile::login(&username, &password, &client_token)).unwrap(); + tx.send(mojang::Profile::login(&username, &password, &client_token)) + .unwrap(); } }); } @@ -203,10 +207,10 @@ impl super::Screen for Login { self.vars.set(auth::AUTH_TOKEN, val.access_token.clone()); elements.profile = val; return Some(Box::new(super::ServerList::new(None))); - }, + } Err(err) => { elements.login_error.borrow_mut().text = format!("{}", err); - }, + } } } } diff --git a/src/screen/mod.rs b/src/screen/mod.rs index b10dab16..057e2a7b 100644 --- a/src/screen/mod.rs +++ b/src/screen/mod.rs @@ -21,31 +21,30 @@ pub mod connecting; pub mod edit_server; pub mod settings_menu; -pub use self::settings_menu::{SettingsMenu, VideoSettingsMenu, AudioSettingsMenu}; +pub use self::settings_menu::{AudioSettingsMenu, SettingsMenu, VideoSettingsMenu}; use crate::render; use crate::ui; pub trait Screen { // Called once - fn init(&mut self, _renderer: &mut render::Renderer, _ui_container: &mut ui::Container) { - } - fn deinit(&mut self, _renderer: &mut render::Renderer, _ui_container: &mut ui::Container) { - } + fn init(&mut self, _renderer: &mut render::Renderer, _ui_container: &mut ui::Container) {} + fn deinit(&mut self, _renderer: &mut render::Renderer, _ui_container: &mut ui::Container) {} // May be called multiple times fn on_active(&mut self, renderer: &mut render::Renderer, ui_container: &mut ui::Container); fn on_deactive(&mut self, renderer: &mut render::Renderer, ui_container: &mut ui::Container); // Called every frame the screen is active - fn tick(&mut self, - delta: f64, - renderer: &mut render::Renderer, - ui_container: &mut ui::Container) -> Option>; + fn tick( + &mut self, + delta: f64, + renderer: &mut render::Renderer, + ui_container: &mut ui::Container, + ) -> Option>; // Events - fn on_scroll(&mut self, _x: f64, _y: f64) { - } + fn on_scroll(&mut self, _x: f64, _y: f64) {} fn is_closable(&self) -> bool { false @@ -65,7 +64,9 @@ pub struct ScreenSystem { } impl ScreenSystem { - pub fn new() -> ScreenSystem { Default::default() } + pub fn new() -> ScreenSystem { + Default::default() + } pub fn add_screen(&mut self, screen: Box) { self.screens.push(ScreenInfo { @@ -94,10 +95,12 @@ impl ScreenSystem { } } - pub fn tick(&mut self, - delta: f64, - renderer: &mut render::Renderer, - ui_container: &mut ui::Container) { + pub fn tick( + &mut self, + delta: f64, + renderer: &mut render::Renderer, + ui_container: &mut ui::Container, + ) { for screen in &mut self.remove_queue { if screen.active { screen.screen.on_deactive(renderer, ui_container); diff --git a/src/screen/server_list.rs b/src/screen/server_list.rs index 10e4829f..dbbbc9a2 100644 --- a/src/screen/server_list.rs +++ b/src/screen/server_list.rs @@ -12,24 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std_or_web::fs; -use std::thread; -use std::sync::mpsc; -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; +use std::sync::mpsc; +use std::thread; +use std_or_web::fs; -use crate::ui; -use crate::render; use crate::format; use crate::format::{Component, TextComponent}; use crate::protocol; +use crate::render; +use crate::ui; -use serde_json; -use std::time::{Duration}; -use image; use base64; +use image; use rand; use rand::Rng; +use serde_json; +use std::time::Duration; pub struct ServerList { elements: Option, @@ -98,9 +98,11 @@ impl ServerList { } } - fn reload_server_list(&mut self, - renderer: &mut render::Renderer, - ui_container: &mut ui::Container) { + fn reload_server_list( + &mut self, + renderer: &mut render::Renderer, + ui_container: &mut ui::Container, + ) { let elements = self.elements.as_mut().unwrap(); *self.needs_reload.borrow_mut() = false; { @@ -141,15 +143,12 @@ impl ServerList { let mut backr = back.borrow_mut(); let address = address.clone(); backr.add_hover_func(move |this, over, _| { - this.colour.3 = if over { - 200 - } else { - 100 - }; + this.colour.3 = if over { 200 } else { 100 }; false }); backr.add_click_func(move |_, game| { - game.screen_sys.replace_screen(Box::new(super::connecting::Connecting::new(&address))); + game.screen_sys + .replace_screen(Box::new(super::connecting::Connecting::new(&address))); game.connect_to(&address); true }); @@ -168,7 +167,6 @@ impl ServerList { .size(90.0, 90.0) .attach(&mut *back.borrow_mut()); - // Ping indicator let ping = ui::ImageBuilder::new() .texture("gui/icons") @@ -232,9 +230,13 @@ impl ServerList { let sname = name.clone(); let saddr = address.clone(); btn.add_click_func(move |_, game| { - game.screen_sys.replace_screen(Box::new(super::edit_server::EditServerEntry::new( - Some((index, sname.clone(), saddr.clone())) - ))); + game.screen_sys.replace_screen(Box::new( + super::edit_server::EditServerEntry::new(Some(( + index, + sname.clone(), + saddr.clone(), + ))), + )); true }) } @@ -260,7 +262,9 @@ impl ServerList { // Don't block the main thread whilst pinging the server thread::spawn(move || { - match protocol::Conn::new(&address, protocol::SUPPORTED_PROTOCOLS[0]).and_then(|conn| conn.do_status()) { + match protocol::Conn::new(&address, protocol::SUPPORTED_PROTOCOLS[0]) + .and_then(|conn| conn.do_status()) + { Ok(res) => { let mut desc = res.0.description; format::convert_legacy(&mut desc); @@ -345,9 +349,8 @@ impl super::Screen for ServerList { .attach(&mut *add); add.add_text(txt); add.add_click_func(move |_, game| { - game.screen_sys.replace_screen(Box::new(super::edit_server::EditServerEntry::new( - None - ))); + game.screen_sys + .replace_screen(Box::new(super::edit_server::EditServerEntry::new(None))); true }) } @@ -367,7 +370,8 @@ impl super::Screen for ServerList { .alignment(ui::VAttach::Middle, ui::HAttach::Center) .attach(&mut *options); options.add_click_func(|_, game| { - game.screen_sys.add_screen(Box::new(super::SettingsMenu::new(game.vars.clone(), false))); + game.screen_sys + .add_screen(Box::new(super::SettingsMenu::new(game.vars.clone(), false))); true }); } @@ -386,7 +390,10 @@ impl super::Screen for ServerList { let background = ui::ImageBuilder::new() .texture("steven:solid") .position(0.0, 3.0) - .size(width.max(renderer.ui.size_of_string("Disconnected")) + 4.0, height + 4.0 + 16.0) + .size( + width.max(renderer.ui.size_of_string("Disconnected")) + 4.0, + height + 4.0 + 16.0, + ) .colour((0, 0, 0, 100)) .alignment(ui::VAttach::Top, ui::HAttach::Center) .draw_index(10) @@ -435,10 +442,12 @@ impl super::Screen for ServerList { self.elements = None } - fn tick(&mut self, - delta: f64, - renderer: &mut render::Renderer, - ui_container: &mut ui::Container) -> Option> { + fn tick( + &mut self, + delta: f64, + renderer: &mut render::Renderer, + ui_container: &mut ui::Container, + ) -> Option> { if *self.needs_reload.borrow() { self.reload_server_list(renderer, ui_container); } @@ -468,20 +477,23 @@ impl super::Screen for ServerList { s.motd.borrow_mut().set_text(res.motd); // Selects the icon for the given ping range // TODO: switch to as_millis() experimental duration_as_u128 #50202 once available? - let ping_ms = (res.ping.subsec_nanos() as f64)/1000000.0 + (res.ping.as_secs() as f64)*1000.0; + let ping_ms = (res.ping.subsec_nanos() as f64) / 1000000.0 + + (res.ping.as_secs() as f64) * 1000.0; let y = match ping_ms.round() as u64 { - _x @ 0 ..= 75 => 16.0 / 256.0, - _x @ 76 ..= 150 => 24.0 / 256.0, - _x @ 151 ..= 225 => 32.0 / 256.0, - _x @ 226 ..= 350 => 40.0 / 256.0, - _x @ 351 ..= 999 => 48.0 / 256.0, + _x @ 0..=75 => 16.0 / 256.0, + _x @ 76..=150 => 24.0 / 256.0, + _x @ 151..=225 => 32.0 / 256.0, + _x @ 226..=350 => 40.0 / 256.0, + _x @ 351..=999 => 48.0 / 256.0, _ => 56.0 / 256.0, }; s.ping.borrow_mut().texture_coords.1 = y; if res.exists { { let mut players = s.players.borrow_mut(); - let txt = if protocol::SUPPORTED_PROTOCOLS.contains(&res.protocol_version) { + let txt = if protocol::SUPPORTED_PROTOCOLS + .contains(&res.protocol_version) + { players.colour.1 = 255; players.colour.2 = 255; format!("{}/{}", res.online, res.max) @@ -492,8 +504,13 @@ impl super::Screen for ServerList { }; players.text = txt; } - let sm = format!("{} mods + {}", res.forge_mods.len(), res.protocol_name); - let st = if res.forge_mods.len() > 0 { &sm } else { &res.protocol_name }; + let sm = + format!("{} mods + {}", res.forge_mods.len(), res.protocol_name); + let st = if res.forge_mods.len() > 0 { + &sm + } else { + &res.protocol_name + }; let mut txt = TextComponent::new(&st); txt.modifier.color = Some(format::Color::Yellow); let mut msg = Component::Text(txt); @@ -501,15 +518,15 @@ impl super::Screen for ServerList { s.version.borrow_mut().set_text(msg); } if let Some(favicon) = res.favicon { - let name: String = std::iter::repeat(()).map(|()| rand::thread_rng() - .sample(&rand::distributions::Alphanumeric)) - .take(30) - .collect(); + let name: String = std::iter::repeat(()) + .map(|()| { + rand::thread_rng().sample(&rand::distributions::Alphanumeric) + }) + .take(30) + .collect(); let tex = renderer.get_textures_ref(); s.icon_texture = Some(name.clone()); - let icon_tex = tex.write() - .unwrap() - .put_dynamic(&name, favicon); + let icon_tex = tex.write().unwrap().put_dynamic(&name, favicon); s.icon.borrow_mut().texture = icon_tex.name; } } diff --git a/src/screen/settings_menu.rs b/src/screen/settings_menu.rs index 34de1fd0..f44cc405 100644 --- a/src/screen/settings_menu.rs +++ b/src/screen/settings_menu.rs @@ -1,7 +1,7 @@ use crate::console; use crate::render; -use crate::ui; use crate::settings; +use crate::ui; use std::rc::Rc; @@ -13,7 +13,7 @@ pub struct UIElements { pub struct SettingsMenu { _vars: Rc, elements: Option, - show_disconnect_button: bool + show_disconnect_button: bool, } impl SettingsMenu { @@ -21,7 +21,7 @@ impl SettingsMenu { SettingsMenu { _vars: vars, elements: None, - show_disconnect_button: show_disconnect_button + show_disconnect_button: show_disconnect_button, } } } @@ -51,7 +51,8 @@ impl super::Screen for SettingsMenu { .attach(&mut *audio_settings); audio_settings.add_text(txt); audio_settings.add_click_func(|_, game| { - game.screen_sys.add_screen(Box::new(AudioSettingsMenu::new(game.vars.clone()))); + game.screen_sys + .add_screen(Box::new(AudioSettingsMenu::new(game.vars.clone()))); true }); } @@ -70,7 +71,8 @@ impl super::Screen for SettingsMenu { .attach(&mut *video_settings); video_settings.add_text(txt); video_settings.add_click_func(|_, game| { - game.screen_sys.add_screen(Box::new(VideoSettingsMenu::new(game.vars.clone()))); + game.screen_sys + .add_screen(Box::new(VideoSettingsMenu::new(game.vars.clone()))); true }); } @@ -142,7 +144,8 @@ impl super::Screen for SettingsMenu { disconnect_button.add_text(txt); disconnect_button.add_click_func(|_, game| { game.server.disconnect(None); - game.screen_sys.replace_screen(Box::new(super::ServerList::new(None))); + game.screen_sys + .replace_screen(Box::new(super::ServerList::new(None))); true }); } @@ -153,14 +156,18 @@ impl super::Screen for SettingsMenu { background, _buttons: buttons, }); - } fn on_deactive(&mut self, _renderer: &mut render::Renderer, _ui_container: &mut ui::Container) { self.elements = None; } // Called every frame the screen is active - fn tick(&mut self, _delta: f64, renderer: &mut render::Renderer, ui_container: &mut ui::Container) -> Option> { + fn tick( + &mut self, + _delta: f64, + renderer: &mut render::Renderer, + ui_container: &mut ui::Container, + ) -> Option> { let elements = self.elements.as_mut().unwrap(); { let mode = ui_container.mode; @@ -178,9 +185,7 @@ impl super::Screen for SettingsMenu { } // Events - fn on_scroll(&mut self, _x: f64, _y: f64) { - - } + fn on_scroll(&mut self, _x: f64, _y: f64) {} fn is_closable(&self) -> bool { true @@ -227,11 +232,14 @@ impl super::Screen for VideoSettingsMenu { { let mut fov_setting = fov_setting.borrow_mut(); let txt = ui::TextBuilder::new() - .text(format!("FOV: {}", match r_fov { - 90 => "Normal".into(), - 110 => "Quake pro".into(), - val => val.to_string(), - })) + .text(format!( + "FOV: {}", + match r_fov { + 90 => "Normal".into(), + 110 => "Quake pro".into(), + val => val.to_string(), + } + )) .alignment(ui::VAttach::Middle, ui::HAttach::Center) .attach(&mut *fov_setting); fov_setting.add_text(txt); @@ -246,14 +254,18 @@ impl super::Screen for VideoSettingsMenu { { let mut vsync_setting = vsync_setting.borrow_mut(); let txt = ui::TextBuilder::new() - .text(format!("VSync: {}", if r_vsync { "Enabled" } else { "Disabled" })) + .text(format!( + "VSync: {}", + if r_vsync { "Enabled" } else { "Disabled" } + )) .alignment(ui::VAttach::Middle, ui::HAttach::Center) .attach(&mut *vsync_setting); let txt_vsync = txt.clone(); vsync_setting.add_text(txt); vsync_setting.add_click_func(move |_, game| { let r_vsync = !*game.vars.get(settings::R_VSYNC); - txt_vsync.borrow_mut().text = format!("VSync: {}", if r_vsync { "Enabled" } else { "Disabled" }); + txt_vsync.borrow_mut().text = + format!("VSync: {}", if r_vsync { "Enabled" } else { "Disabled" }); game.vars.set(settings::R_VSYNC, r_vsync); true }); @@ -269,10 +281,13 @@ impl super::Screen for VideoSettingsMenu { { let mut fps_setting = fps_setting.borrow_mut(); let txt = ui::TextBuilder::new() - .text(format!("FPS cap: {}", match r_max_fps { - 0 => "Unlimited".into(), - val => val.to_string(), - })) + .text(format!( + "FPS cap: {}", + match r_max_fps { + 0 => "Unlimited".into(), + val => val.to_string(), + } + )) .alignment(ui::VAttach::Middle, ui::HAttach::Center) .attach(&mut *fps_setting); fps_setting.add_text(txt); @@ -302,14 +317,18 @@ impl super::Screen for VideoSettingsMenu { background, _buttons: buttons, }); - } fn on_deactive(&mut self, _renderer: &mut render::Renderer, _ui_container: &mut ui::Container) { self.elements = None; } // Called every frame the screen is active - fn tick(&mut self, _delta: f64, renderer: &mut render::Renderer, ui_container: &mut ui::Container) -> Option> { + fn tick( + &mut self, + _delta: f64, + renderer: &mut render::Renderer, + ui_container: &mut ui::Container, + ) -> Option> { let elements = self.elements.as_mut().unwrap(); { let mode = ui_container.mode; @@ -327,9 +346,7 @@ impl super::Screen for VideoSettingsMenu { } // Events - fn on_scroll(&mut self, _x: f64, _y: f64) { - - } + fn on_scroll(&mut self, _x: f64, _y: f64) {} fn is_closable(&self) -> bool { true @@ -338,14 +355,14 @@ impl super::Screen for VideoSettingsMenu { pub struct AudioSettingsMenu { _vars: Rc, - elements: Option + elements: Option, } impl AudioSettingsMenu { pub fn new(vars: Rc) -> AudioSettingsMenu { AudioSettingsMenu { _vars: vars, - elements: None + elements: None, } } } @@ -387,14 +404,18 @@ impl super::Screen for AudioSettingsMenu { background, _buttons: buttons, }); - } fn on_deactive(&mut self, _renderer: &mut render::Renderer, _ui_container: &mut ui::Container) { self.elements = None; } // Called every frame the screen is active - fn tick(&mut self, _delta: f64, renderer: &mut render::Renderer, ui_container: &mut ui::Container) -> Option> { + fn tick( + &mut self, + _delta: f64, + renderer: &mut render::Renderer, + ui_container: &mut ui::Container, + ) -> Option> { let elements = self.elements.as_mut().unwrap(); { let mode = ui_container.mode; @@ -412,9 +433,7 @@ impl super::Screen for AudioSettingsMenu { } // Events - fn on_scroll(&mut self, _x: f64, _y: f64) { - - } + fn on_scroll(&mut self, _x: f64, _y: f64) {} fn is_closable(&self) -> bool { true diff --git a/src/server/mod.rs b/src/server/mod.rs index f5ec7230..a7563db2 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -12,32 +12,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::protocol::{self, mojang, packet, forge}; -use crate::world; -use crate::world::block; -use rand::{self, Rng}; -use std::sync::{Arc, RwLock}; -use std::sync::mpsc; -use std::thread; -use std::collections::HashMap; -use std::hash::BuildHasherDefault; -use crate::types::hash::FNVHash; -use crate::resources; -use crate::render; -use crate::settings::Stevenkey; use crate::ecs; use crate::entity; -use cgmath::prelude::*; -use crate::types::Gamemode; -use crate::shared::{Axis, Position}; use crate::format; -use rsa_public_encrypt_pkcs1; -use log::{error, debug, warn}; +use crate::protocol::{self, forge, mojang, packet}; +use crate::render; +use crate::resources; +use crate::settings::Stevenkey; +use crate::shared::{Axis, Position}; +use crate::types::hash::FNVHash; +use crate::types::Gamemode; +use crate::world; +use crate::world::block; use base64; +use cgmath::prelude::*; +use log::{debug, error, warn}; +use rand::{self, Rng}; +use rsa_public_encrypt_pkcs1; use serde_json; +use std::collections::HashMap; +use std::hash::BuildHasherDefault; +use std::sync::mpsc; +use std::sync::{Arc, RwLock}; +use std::thread; -mod sun; pub mod plugin_messages; +mod sun; pub mod target; pub struct Server { @@ -70,7 +70,6 @@ pub struct Server { pub rotation: ecs::Key, target_rotation: ecs::Key, // - pub player: Option, entity_map: HashMap>, players: HashMap>, @@ -106,19 +105,24 @@ macro_rules! handle_packet { } impl Server { - - pub fn connect(resources: Arc>, profile: mojang::Profile, address: &str, protocol_version: i32, forge_mods: Vec) -> Result { + pub fn connect( + resources: Arc>, + profile: mojang::Profile, + address: &str, + protocol_version: i32, + forge_mods: Vec, + ) -> Result { let mut conn = protocol::Conn::new(address, protocol_version)?; let tag = if forge_mods.len() != 0 { "\0FML\0" } else { "" }; let host = conn.host.clone() + tag; let port = conn.port; conn.write_packet(protocol::packet::handshake::serverbound::Handshake { - protocol_version: protocol::VarInt(protocol_version), - host, - port, - next: protocol::VarInt(2), - })?; + protocol_version: protocol::VarInt(protocol_version), + host, + port, + next: protocol::VarInt(2), + })?; conn.state = protocol::State::Login; conn.write_packet(protocol::packet::login::serverbound::LoginStart { username: profile.username.clone(), @@ -130,19 +134,19 @@ impl Server { match conn.read_packet()? { protocol::packet::Packet::SetInitialCompression(val) => { conn.set_compresssion(val.threshold.0); - }, + } protocol::packet::Packet::EncryptionRequest(val) => { server_id = Rc::new(val.server_id); public_key = Rc::new(val.public_key.data); verify_token = Rc::new(val.verify_token.data); break; - }, + } protocol::packet::Packet::EncryptionRequest_i16(val) => { server_id = Rc::new(val.server_id); public_key = Rc::new(val.public_key.data); verify_token = Rc::new(val.verify_token.data); break; - }, + } protocol::packet::Packet::LoginSuccess(val) => { warn!("Server is running in offline mode"); debug!("Login: {} {}", val.username, val.uuid); @@ -151,9 +155,18 @@ impl Server { read.state = protocol::State::Play; write.state = protocol::State::Play; let rx = Self::spawn_reader(read); - return Ok(Server::new(protocol_version, forge_mods, protocol::UUID::from_str(&val.uuid), resources, Some(write), Some(rx))); + return Ok(Server::new( + protocol_version, + forge_mods, + protocol::UUID::from_str(&val.uuid), + resources, + Some(write), + Some(rx), + )); + } + protocol::packet::Packet::LoginDisconnect(val) => { + return Err(protocol::Error::Disconnect(val.reason)) } - protocol::packet::Packet::LoginDisconnect(val) => return Err(protocol::Error::Disconnect(val.reason)), val => return Err(protocol::Error::Err(format!("Wrong packet: {:?}", val))), }; } @@ -176,10 +189,12 @@ impl Server { verify_token: protocol::LenPrefixedBytes::new(token_e), })?; } else { - conn.write_packet(protocol::packet::login::serverbound::EncryptionResponse_i16 { - shared_secret: protocol::LenPrefixedBytes::new(shared_e), - verify_token: protocol::LenPrefixedBytes::new(token_e), - })?; + conn.write_packet( + protocol::packet::login::serverbound::EncryptionResponse_i16 { + shared_secret: protocol::LenPrefixedBytes::new(shared_e), + verify_token: protocol::LenPrefixedBytes::new(token_e), + }, + )?; } let mut read = conn.clone(); @@ -190,72 +205,134 @@ impl Server { let uuid; loop { - match read.read_packet()? { - protocol::packet::Packet::SetInitialCompression(val) => { - read.set_compresssion(val.threshold.0); - write.set_compresssion(val.threshold.0); - } - protocol::packet::Packet::LoginSuccess(val) => { - debug!("Login: {} {}", val.username, val.uuid); - uuid = val.uuid; - read.state = protocol::State::Play; - write.state = protocol::State::Play; - break; - } - protocol::packet::Packet::LoginDisconnect(val) => return Err(protocol::Error::Disconnect(val.reason)), - val => return Err(protocol::Error::Err(format!("Wrong packet: {:?}", val))), - } + match read.read_packet()? { + protocol::packet::Packet::SetInitialCompression(val) => { + read.set_compresssion(val.threshold.0); + write.set_compresssion(val.threshold.0); + } + protocol::packet::Packet::LoginSuccess(val) => { + debug!("Login: {} {}", val.username, val.uuid); + uuid = val.uuid; + read.state = protocol::State::Play; + write.state = protocol::State::Play; + break; + } + protocol::packet::Packet::LoginDisconnect(val) => { + return Err(protocol::Error::Disconnect(val.reason)) + } + val => return Err(protocol::Error::Err(format!("Wrong packet: {:?}", val))), + } } let rx = Self::spawn_reader(read); - Ok(Server::new(protocol_version, forge_mods, protocol::UUID::from_str(&uuid), resources, Some(write), Some(rx))) + Ok(Server::new( + protocol_version, + forge_mods, + protocol::UUID::from_str(&uuid), + resources, + Some(write), + Some(rx), + )) } - fn spawn_reader(mut read: protocol::Conn) -> mpsc::Receiver> { + fn spawn_reader( + mut read: protocol::Conn, + ) -> mpsc::Receiver> { let (tx, rx) = mpsc::channel(); - thread::spawn(move || { - loop { - let pck = read.read_packet(); - let was_error = pck.is_err(); - if let Err(_) = tx.send(pck) { - return; - } - if was_error { - return; - } + thread::spawn(move || loop { + let pck = read.read_packet(); + let was_error = pck.is_err(); + if let Err(_) = tx.send(pck) { + return; + } + if was_error { + return; } }); rx } pub fn dummy_server(resources: Arc>) -> Server { - let mut server = Server::new(protocol::SUPPORTED_PROTOCOLS[0], vec![], protocol::UUID::default(), resources, None, None); + let mut server = Server::new( + protocol::SUPPORTED_PROTOCOLS[0], + vec![], + protocol::UUID::default(), + resources, + None, + None, + ); let mut rng = rand::thread_rng(); - for x in -7*16 .. 7*16 { - for z in -7*16 .. 7*16 { + for x in -7 * 16..7 * 16 { + for z in -7 * 16..7 * 16 { let h = 5 + (6.0 * (x as f64 / 16.0).cos() * (z as f64 / 16.0).sin()) as i32; - for y in 0 .. h { - server.world.set_block(Position::new(x, y, z), block::Dirt{ snowy: false, variant: block::DirtVariant::Normal }); + for y in 0..h { + server.world.set_block( + Position::new(x, y, z), + block::Dirt { + snowy: false, + variant: block::DirtVariant::Normal, + }, + ); } - server.world.set_block(Position::new(x, h, z), block::Grass{ snowy: false }); - - if x*x + z*z > 16*16 && rng.gen_bool(1.0 / 80.0) { - for i in 0 .. 5 { - server.world.set_block(Position::new(x, h + 1 + i, z), block::Log{ axis: Axis::Y, variant: block::TreeVariant::Oak }); + server + .world + .set_block(Position::new(x, h, z), block::Grass { snowy: false }); + + if x * x + z * z > 16 * 16 && rng.gen_bool(1.0 / 80.0) { + for i in 0..5 { + server.world.set_block( + Position::new(x, h + 1 + i, z), + block::Log { + axis: Axis::Y, + variant: block::TreeVariant::Oak, + }, + ); } - for xx in -2 .. 3 { - for zz in -2 .. 3 { + for xx in -2..3 { + for zz in -2..3 { if xx == 0 && z == 0 { continue; } - server.world.set_block(Position::new(x + xx, h + 3, z + zz), block::Leaves{ variant: block::TreeVariant::Oak, check_decay: false, decayable: false, distance: 1 }); - server.world.set_block(Position::new(x + xx, h + 4, z + zz), block::Leaves{ variant: block::TreeVariant::Oak, check_decay: false, decayable: false, distance: 1 }); + server.world.set_block( + Position::new(x + xx, h + 3, z + zz), + block::Leaves { + variant: block::TreeVariant::Oak, + check_decay: false, + decayable: false, + distance: 1, + }, + ); + server.world.set_block( + Position::new(x + xx, h + 4, z + zz), + block::Leaves { + variant: block::TreeVariant::Oak, + check_decay: false, + decayable: false, + distance: 1, + }, + ); if xx.abs() <= 1 && zz.abs() <= 1 { - server.world.set_block(Position::new(x + xx, h + 5, z + zz), block::Leaves{ variant: block::TreeVariant::Oak, check_decay: false, decayable: false, distance: 1 }); + server.world.set_block( + Position::new(x + xx, h + 5, z + zz), + block::Leaves { + variant: block::TreeVariant::Oak, + check_decay: false, + decayable: false, + distance: 1, + }, + ); } if xx * xx + zz * zz <= 1 { - server.world.set_block(Position::new(x + xx, h + 6, z + zz), block::Leaves{ variant: block::TreeVariant::Oak, check_decay: false, decayable: false, distance: 1 }); + server.world.set_block( + Position::new(x + xx, h + 6, z + zz), + block::Leaves { + variant: block::TreeVariant::Oak, + check_decay: false, + decayable: false, + distance: 1, + }, + ); } } } @@ -270,7 +347,8 @@ impl Server { forge_mods: Vec, uuid: protocol::UUID, resources: Arc>, - conn: Option, read_queue: Option>> + conn: Option, + read_queue: Option>>, ) -> Server { let mut entities = ecs::Manager::new(); entity::add_systems(&mut entities); @@ -309,7 +387,6 @@ impl Server { rotation: entities.get_key(), target_rotation: entities.get_key(), // - entities, player: None, entity_map: HashMap::with_hasher(BuildHasherDefault::default()), @@ -351,7 +428,8 @@ impl Server { if let Some(player) = self.player { let position = self.entities.get_component(player, self.position).unwrap(); let rotation = self.entities.get_component(player, self.rotation).unwrap(); - renderer.camera.pos = cgmath::Point3::from_vec(position.position + cgmath::Vector3::new(0.0, 1.62, 0.0)); + renderer.camera.pos = + cgmath::Point3::from_vec(position.position + cgmath::Vector3::new(0.0, 1.62, 0.0)); renderer.camera.yaw = rotation.yaw; renderer.camera.pitch = rotation.pitch; } @@ -372,7 +450,13 @@ impl Server { self.world.tick(&mut self.entities); if self.player.is_some() { - if let Some((pos, bl, _, _)) = target::trace_ray(&self.world, 4.0, renderer.camera.pos.to_vec(), renderer.view_vector.cast().unwrap(), target::test_block) { + if let Some((pos, bl, _, _)) = target::trace_ray( + &self.world, + 4.0, + renderer.camera.pos.to_vec(), + renderer.view_vector.cast().unwrap(), + target::test_block, + ) { self.target_info.update(renderer, pos, bl); } else { self.target_info.clear(renderer); @@ -385,14 +469,16 @@ impl Server { fn entity_tick(&mut self, renderer: &mut render::Renderer, delta: f64) { let world_entity = self.entities.get_world(); // Update the game's state for entities to read - self.entities.get_component_mut(world_entity, self.game_info) - .unwrap().delta = delta; + self.entities + .get_component_mut(world_entity, self.game_info) + .unwrap() + .delta = delta; // Packets modify entities so need to handled here if let Some(rx) = self.read_queue.take() { while let Ok(pck) = rx.try_recv() { match pck { - Ok(pck) => handle_packet!{ + Ok(pck) => handle_packet! { self pck { PluginMessageClientbound_i16 => on_plugin_message_clientbound_i16, PluginMessageClientbound => on_plugin_message_clientbound_1, @@ -464,7 +550,8 @@ impl Server { } } - if self.is_connected() || self.just_disconnected { // Allow an extra tick when disconnected to clean up + if self.is_connected() || self.just_disconnected { + // Allow an extra tick when disconnected to clean up self.just_disconnected = false; self.entity_tick_timer += delta; while self.entity_tick_timer >= 3.0 { @@ -528,9 +615,18 @@ impl Server { pub fn minecraft_tick(&mut self) { use std::f32::consts::PI; if let Some(player) = self.player { - let movement = self.entities.get_component_mut(player, self.player_movement).unwrap(); - let on_ground = self.entities.get_component(player, self.gravity).map_or(false, |v| v.on_ground); - let position = self.entities.get_component(player, self.target_position).unwrap(); + let movement = self + .entities + .get_component_mut(player, self.player_movement) + .unwrap(); + let on_ground = self + .entities + .get_component(player, self.gravity) + .map_or(false, |v| v.on_ground); + let position = self + .entities + .get_component(player, self.target_position) + .unwrap(); let rotation = self.entities.get_component(player, self.rotation).unwrap(); // Force the server to know when touched the ground @@ -572,7 +668,10 @@ impl Server { pub fn key_press(&mut self, down: bool, key: Stevenkey) { if let Some(player) = self.player { - if let Some(movement) = self.entities.get_component_mut(player, self.player_movement) { + if let Some(movement) = self + .entities + .get_component_mut(player, self.player_movement) + { movement.pressed_keys.insert(key, down); } } @@ -581,7 +680,13 @@ impl Server { pub fn on_right_click(&mut self, renderer: &mut render::Renderer) { use crate::shared::Direction; if self.player.is_some() { - if let Some((pos, _, face, at)) = target::trace_ray(&self.world, 4.0, renderer.camera.pos.to_vec(), renderer.view_vector.cast().unwrap(), target::test_block) { + if let Some((pos, _, face, at)) = target::trace_ray( + &self.world, + 4.0, + renderer.camera.pos.to_vec(), + renderer.view_vector.cast().unwrap(), + target::test_block, + ) { if self.protocol_version >= 315 { self.write_packet(packet::play::serverbound::PlayerBlockPlacement_f32 { location: pos, @@ -634,24 +739,26 @@ impl Server { cursor_z: (at.z * 16.0) as u8, }); } else { - self.write_packet(packet::play::serverbound::PlayerBlockPlacement_u8_Item_u8y { - x: pos.x, - y: pos.y as u8, - z: pos.x, - face: match face { - Direction::Down => 0, - Direction::Up => 1, - Direction::North => 2, - Direction::South => 3, - Direction::West => 4, - Direction::East => 5, - _ => unreachable!(), + self.write_packet( + packet::play::serverbound::PlayerBlockPlacement_u8_Item_u8y { + x: pos.x, + y: pos.y as u8, + z: pos.x, + face: match face { + Direction::Down => 0, + Direction::Up => 1, + Direction::North => 2, + Direction::South => 3, + Direction::West => 4, + Direction::East => 5, + _ => unreachable!(), + }, + hand: None, + cursor_x: (at.x * 16.0) as u8, + cursor_y: (at.y * 16.0) as u8, + cursor_z: (at.z * 16.0) as u8, }, - hand: None, - cursor_x: (at.x * 16.0) as u8, - cursor_y: (at.y * 16.0) as u8, - cursor_z: (at.z * 16.0) as u8, - }); + ); } } } @@ -661,72 +768,121 @@ impl Server { let _ = self.conn.as_mut().unwrap().write_packet(p); // TODO handle errors } - fn on_keep_alive_i64(&mut self, keep_alive: packet::play::clientbound::KeepAliveClientbound_i64) { + fn on_keep_alive_i64( + &mut self, + keep_alive: packet::play::clientbound::KeepAliveClientbound_i64, + ) { self.write_packet(packet::play::serverbound::KeepAliveServerbound_i64 { id: keep_alive.id, }); } - fn on_keep_alive_varint(&mut self, keep_alive: packet::play::clientbound::KeepAliveClientbound_VarInt) { + fn on_keep_alive_varint( + &mut self, + keep_alive: packet::play::clientbound::KeepAliveClientbound_VarInt, + ) { self.write_packet(packet::play::serverbound::KeepAliveServerbound_VarInt { id: keep_alive.id, }); } - fn on_keep_alive_i32(&mut self, keep_alive: packet::play::clientbound::KeepAliveClientbound_i32) { + fn on_keep_alive_i32( + &mut self, + keep_alive: packet::play::clientbound::KeepAliveClientbound_i32, + ) { self.write_packet(packet::play::serverbound::KeepAliveServerbound_i32 { id: keep_alive.id, }); } - fn on_plugin_message_clientbound_i16(&mut self, msg: packet::play::clientbound::PluginMessageClientbound_i16) { + fn on_plugin_message_clientbound_i16( + &mut self, + msg: packet::play::clientbound::PluginMessageClientbound_i16, + ) { self.on_plugin_message_clientbound(&msg.channel, msg.data.data.as_slice()) } - fn on_plugin_message_clientbound_1(&mut self, msg: packet::play::clientbound::PluginMessageClientbound) { + fn on_plugin_message_clientbound_1( + &mut self, + msg: packet::play::clientbound::PluginMessageClientbound, + ) { self.on_plugin_message_clientbound(&msg.channel, &msg.data) } fn on_plugin_message_clientbound(&mut self, channel: &str, data: &[u8]) { if protocol::is_network_debug() { - debug!("Received plugin message: channel={}, data={:?}", channel, data); + debug!( + "Received plugin message: channel={}, data={:?}", + channel, data + ); } match channel { - // TODO: "REGISTER" => + // TODO: "REGISTER" => // TODO: "UNREGISTER" => "FML|HS" => { - let msg = crate::protocol::Serializable::read_from(&mut std::io::Cursor::new(data)).unwrap(); + let msg = crate::protocol::Serializable::read_from(&mut std::io::Cursor::new(data)) + .unwrap(); //debug!("FML|HS msg={:?}", msg); use forge::FmlHs::*; use forge::Phase::*; match msg { - ServerHello { fml_protocol_version, override_dimension } => { - debug!("Received FML|HS ServerHello {} {:?}", fml_protocol_version, override_dimension); - - self.write_plugin_message("REGISTER", "FML|HS\0FML\0FML|MP\0FML\0FORGE".as_bytes()); - self.write_fmlhs_plugin_message(&ClientHello { fml_protocol_version }); + ServerHello { + fml_protocol_version, + override_dimension, + } => { + debug!( + "Received FML|HS ServerHello {} {:?}", + fml_protocol_version, override_dimension + ); + + self.write_plugin_message( + "REGISTER", + "FML|HS\0FML\0FML|MP\0FML\0FORGE".as_bytes(), + ); + self.write_fmlhs_plugin_message(&ClientHello { + fml_protocol_version, + }); // Send stashed mods list received from ping packet, client matching server - let mods = crate::protocol::LenPrefixed::::new(self.forge_mods.clone()); + let mods = crate::protocol::LenPrefixed::< + crate::protocol::VarInt, + forge::ForgeMod, + >::new(self.forge_mods.clone()); self.write_fmlhs_plugin_message(&ModList { mods }); - }, + } ModList { mods } => { debug!("Received FML|HS ModList: {:?}", mods); - self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerData }); - }, - ModIdData { mappings, block_substitutions: _, item_substitutions: _ } => { + self.write_fmlhs_plugin_message(&HandshakeAck { + phase: WaitingServerData, + }); + } + ModIdData { + mappings, + block_substitutions: _, + item_substitutions: _, + } => { debug!("Received FML|HS ModIdData"); for m in mappings.data { let (namespace, name) = m.name.split_at(1); if namespace == protocol::forge::BLOCK_NAMESPACE { - self.world.modded_block_ids.insert(m.id.0 as usize, name.to_string()); + self.world + .modded_block_ids + .insert(m.id.0 as usize, name.to_string()); } } - self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerComplete }); - }, - RegistryData { has_more, name, ids, substitutions: _, dummies: _ } => { + self.write_fmlhs_plugin_message(&HandshakeAck { + phase: WaitingServerComplete, + }); + } + RegistryData { + has_more, + name, + ids, + substitutions: _, + dummies: _, + } => { debug!("Received FML|HS RegistryData for {}", name); if name == "minecraft:blocks" { for m in ids.data { @@ -734,24 +890,26 @@ impl Server { } } if !has_more { - self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerComplete }); + self.write_fmlhs_plugin_message(&HandshakeAck { + phase: WaitingServerComplete, + }); } - }, - HandshakeAck { phase } => { - match phase { - WaitingCAck => { - self.write_fmlhs_plugin_message(&HandshakeAck { phase: PendingComplete }); - }, - Complete => { - debug!("FML|HS handshake complete!"); - }, - _ => unimplemented!(), + } + HandshakeAck { phase } => match phase { + WaitingCAck => { + self.write_fmlhs_plugin_message(&HandshakeAck { + phase: PendingComplete, + }); } + Complete => { + debug!("FML|HS handshake complete!"); + } + _ => unimplemented!(), }, _ => (), } } - _ => () + _ => (), } } @@ -766,7 +924,10 @@ impl Server { fn write_plugin_message(&mut self, channel: &str, data: &[u8]) { if protocol::is_network_debug() { - debug!("Sending plugin message: channel={}, data={:?}", channel, data); + debug!( + "Sending plugin message: channel={}, data={:?}", + channel, data + ); } if self.protocol_version >= 47 { self.write_packet(packet::play::serverbound::PluginMessageServerbound { @@ -781,11 +942,17 @@ impl Server { } } - fn on_game_join_hashedseed_respawn(&mut self, join: packet::play::clientbound::JoinGame_HashedSeed_Respawn) { + fn on_game_join_hashedseed_respawn( + &mut self, + join: packet::play::clientbound::JoinGame_HashedSeed_Respawn, + ) { self.on_game_join(join.gamemode, join.entity_id) } - fn on_game_join_i32_viewdistance(&mut self, join: packet::play::clientbound::JoinGame_i32_ViewDistance) { + fn on_game_join_i32_viewdistance( + &mut self, + join: packet::play::clientbound::JoinGame_i32_ViewDistance, + ) { self.on_game_join(join.gamemode, join.entity_id) } @@ -801,25 +968,33 @@ impl Server { self.on_game_join(join.gamemode, join.entity_id) } - fn on_game_join(&mut self, gamemode: u8, entity_id: i32) { let gamemode = Gamemode::from_int((gamemode & 0x7) as i32); let player = entity::player::create_local(&mut self.entities); if let Some(info) = self.players.get(&self.uuid) { - let model = self.entities.get_component_mut_direct::(player).unwrap(); + let model = self + .entities + .get_component_mut_direct::(player) + .unwrap(); model.set_skin(info.skin_url.clone()); } - *self.entities.get_component_mut(player, self.gamemode).unwrap() = gamemode; + *self + .entities + .get_component_mut(player, self.gamemode) + .unwrap() = gamemode; // TODO: Temp - self.entities.get_component_mut(player, self.player_movement).unwrap().flying = gamemode.can_fly(); + self.entities + .get_component_mut(player, self.player_movement) + .unwrap() + .flying = gamemode.can_fly(); self.entity_map.insert(entity_id, player); self.player = Some(player); // Let the server know who we are let brand = plugin_messages::Brand { - brand: "Steven".into(), - }; + brand: "Steven".into(), + }; // TODO: refactor with write_plugin_message if self.protocol_version >= 47 { self.write_packet(brand.as_message()); @@ -841,9 +1016,15 @@ impl Server { let gamemode = Gamemode::from_int((gamemode_u8 & 0x7) as i32); if let Some(player) = self.player { - *self.entities.get_component_mut(player, self.gamemode).unwrap() = gamemode; + *self + .entities + .get_component_mut(player, self.gamemode) + .unwrap() = gamemode; // TODO: Temp - self.entities.get_component_mut(player, self.player_movement).unwrap().flying = gamemode.can_fly(); + self.entities + .get_component_mut(player, self.player_movement) + .unwrap() + .flying = gamemode.can_fly(); } } @@ -866,9 +1047,15 @@ impl Server { if game_state.reason == 3 { if let Some(player) = self.player { let gamemode = Gamemode::from_int(game_state.value as i32); - *self.entities.get_component_mut(player, self.gamemode).unwrap() = gamemode; + *self + .entities + .get_component_mut(player, self.gamemode) + .unwrap() = gamemode; // TODO: Temp - self.entities.get_component_mut(player, self.player_movement).unwrap().flying = gamemode.can_fly(); + self.entities + .get_component_mut(player, self.player_movement) + .unwrap() + .flying = gamemode.can_fly(); } } } @@ -881,7 +1068,10 @@ impl Server { } } - fn on_entity_destroy_u8(&mut self, entity_destroy: packet::play::clientbound::EntityDestroy_u8) { + fn on_entity_destroy_u8( + &mut self, + entity_destroy: packet::play::clientbound::EntityDestroy_u8, + ) { for id in entity_destroy.entity_ids.data { if let Some(entity) = self.entity_map.remove(&id) { self.entities.remove_entity(entity); @@ -889,25 +1079,72 @@ impl Server { } } - fn on_entity_teleport_f64(&mut self, entity_telport: packet::play::clientbound::EntityTeleport_f64) { - self.on_entity_teleport(entity_telport.entity_id.0, entity_telport.x, entity_telport.y, entity_telport.z, entity_telport.yaw as f64, entity_telport.pitch as f64, entity_telport.on_ground) - } - - fn on_entity_teleport_i32(&mut self, entity_telport: packet::play::clientbound::EntityTeleport_i32) { - self.on_entity_teleport(entity_telport.entity_id.0, f64::from(entity_telport.x), f64::from(entity_telport.y), f64::from(entity_telport.z), entity_telport.yaw as f64, entity_telport.pitch as f64, entity_telport.on_ground) - } - - fn on_entity_teleport_i32_i32_noground(&mut self, entity_telport: packet::play::clientbound::EntityTeleport_i32_i32_NoGround) { + fn on_entity_teleport_f64( + &mut self, + entity_telport: packet::play::clientbound::EntityTeleport_f64, + ) { + self.on_entity_teleport( + entity_telport.entity_id.0, + entity_telport.x, + entity_telport.y, + entity_telport.z, + entity_telport.yaw as f64, + entity_telport.pitch as f64, + entity_telport.on_ground, + ) + } + + fn on_entity_teleport_i32( + &mut self, + entity_telport: packet::play::clientbound::EntityTeleport_i32, + ) { + self.on_entity_teleport( + entity_telport.entity_id.0, + f64::from(entity_telport.x), + f64::from(entity_telport.y), + f64::from(entity_telport.z), + entity_telport.yaw as f64, + entity_telport.pitch as f64, + entity_telport.on_ground, + ) + } + + fn on_entity_teleport_i32_i32_noground( + &mut self, + entity_telport: packet::play::clientbound::EntityTeleport_i32_i32_NoGround, + ) { let on_ground = true; // TODO: how is this supposed to be set? (for 1.7) - self.on_entity_teleport(entity_telport.entity_id, f64::from(entity_telport.x), f64::from(entity_telport.y), f64::from(entity_telport.z), entity_telport.yaw as f64, entity_telport.pitch as f64, on_ground) - } - - - fn on_entity_teleport(&mut self, entity_id: i32, x: f64, y: f64, z: f64, yaw: f64, pitch: f64, _on_ground: bool) { + self.on_entity_teleport( + entity_telport.entity_id, + f64::from(entity_telport.x), + f64::from(entity_telport.y), + f64::from(entity_telport.z), + entity_telport.yaw as f64, + entity_telport.pitch as f64, + on_ground, + ) + } + + fn on_entity_teleport( + &mut self, + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: f64, + pitch: f64, + _on_ground: bool, + ) { use std::f64::consts::PI; if let Some(entity) = self.entity_map.get(&entity_id) { - let target_position = self.entities.get_component_mut(*entity, self.target_position).unwrap(); - let target_rotation = self.entities.get_component_mut(*entity, self.target_rotation).unwrap(); + let target_position = self + .entities + .get_component_mut(*entity, self.target_position) + .unwrap(); + let target_rotation = self + .entities + .get_component_mut(*entity, self.target_rotation) + .unwrap(); target_position.position.x = x; target_position.position.y = y; target_position.position.z = z; @@ -917,21 +1154,41 @@ impl Server { } fn on_entity_move_i16(&mut self, m: packet::play::clientbound::EntityMove_i16) { - self.on_entity_move(m.entity_id.0, f64::from(m.delta_x), f64::from(m.delta_y), f64::from(m.delta_z)) + self.on_entity_move( + m.entity_id.0, + f64::from(m.delta_x), + f64::from(m.delta_y), + f64::from(m.delta_z), + ) } fn on_entity_move_i8(&mut self, m: packet::play::clientbound::EntityMove_i8) { - self.on_entity_move(m.entity_id.0, f64::from(m.delta_x), f64::from(m.delta_y), f64::from(m.delta_z)) + self.on_entity_move( + m.entity_id.0, + f64::from(m.delta_x), + f64::from(m.delta_y), + f64::from(m.delta_z), + ) + } + + fn on_entity_move_i8_i32_noground( + &mut self, + m: packet::play::clientbound::EntityMove_i8_i32_NoGround, + ) { + self.on_entity_move( + m.entity_id, + f64::from(m.delta_x), + f64::from(m.delta_y), + f64::from(m.delta_z), + ) } - fn on_entity_move_i8_i32_noground(&mut self, m: packet::play::clientbound::EntityMove_i8_i32_NoGround) { - self.on_entity_move(m.entity_id, f64::from(m.delta_x), f64::from(m.delta_y), f64::from(m.delta_z)) - } - - fn on_entity_move(&mut self, entity_id: i32, delta_x: f64, delta_y: f64, delta_z: f64) { if let Some(entity) = self.entity_map.get(&entity_id) { - let position = self.entities.get_component_mut(*entity, self.target_position).unwrap(); + let position = self + .entities + .get_component_mut(*entity, self.target_position) + .unwrap(); position.position.x += delta_x; position.position.y += delta_y; position.position.z += delta_z; @@ -941,7 +1198,10 @@ impl Server { fn on_entity_look(&mut self, entity_id: i32, yaw: f64, pitch: f64) { use std::f64::consts::PI; if let Some(entity) = self.entity_map.get(&entity_id) { - let rotation = self.entities.get_component_mut(*entity, self.target_rotation).unwrap(); + let rotation = self + .entities + .get_component_mut(*entity, self.target_rotation) + .unwrap(); rotation.yaw = -(yaw / 256.0) * PI * 2.0; rotation.pitch = -(pitch / 256.0) * PI * 2.0; } @@ -951,33 +1211,74 @@ impl Server { self.on_entity_look(look.entity_id.0, look.yaw as f64, look.pitch as f64) } - fn on_entity_look_i32_noground(&mut self, look: packet::play::clientbound::EntityLook_i32_NoGround) { + fn on_entity_look_i32_noground( + &mut self, + look: packet::play::clientbound::EntityLook_i32_NoGround, + ) { self.on_entity_look(look.entity_id, look.yaw as f64, look.pitch as f64) } - fn on_entity_look_and_move_i16(&mut self, lookmove: packet::play::clientbound::EntityLookAndMove_i16) { - self.on_entity_look_and_move(lookmove.entity_id.0, - f64::from(lookmove.delta_x), f64::from(lookmove.delta_y), f64::from(lookmove.delta_z), - lookmove.yaw as f64, lookmove.pitch as f64) - } - - fn on_entity_look_and_move_i8(&mut self, lookmove: packet::play::clientbound::EntityLookAndMove_i8) { - self.on_entity_look_and_move(lookmove.entity_id.0, - f64::from(lookmove.delta_x), f64::from(lookmove.delta_y), f64::from(lookmove.delta_z), - lookmove.yaw as f64, lookmove.pitch as f64) - } - - fn on_entity_look_and_move_i8_i32_noground(&mut self, lookmove: packet::play::clientbound::EntityLookAndMove_i8_i32_NoGround) { - self.on_entity_look_and_move(lookmove.entity_id, - f64::from(lookmove.delta_x), f64::from(lookmove.delta_y), f64::from(lookmove.delta_z), - lookmove.yaw as f64, lookmove.pitch as f64) - } - - fn on_entity_look_and_move(&mut self, entity_id: i32, delta_x: f64, delta_y: f64, delta_z: f64, yaw: f64, pitch: f64) { + fn on_entity_look_and_move_i16( + &mut self, + lookmove: packet::play::clientbound::EntityLookAndMove_i16, + ) { + self.on_entity_look_and_move( + lookmove.entity_id.0, + f64::from(lookmove.delta_x), + f64::from(lookmove.delta_y), + f64::from(lookmove.delta_z), + lookmove.yaw as f64, + lookmove.pitch as f64, + ) + } + + fn on_entity_look_and_move_i8( + &mut self, + lookmove: packet::play::clientbound::EntityLookAndMove_i8, + ) { + self.on_entity_look_and_move( + lookmove.entity_id.0, + f64::from(lookmove.delta_x), + f64::from(lookmove.delta_y), + f64::from(lookmove.delta_z), + lookmove.yaw as f64, + lookmove.pitch as f64, + ) + } + + fn on_entity_look_and_move_i8_i32_noground( + &mut self, + lookmove: packet::play::clientbound::EntityLookAndMove_i8_i32_NoGround, + ) { + self.on_entity_look_and_move( + lookmove.entity_id, + f64::from(lookmove.delta_x), + f64::from(lookmove.delta_y), + f64::from(lookmove.delta_z), + lookmove.yaw as f64, + lookmove.pitch as f64, + ) + } + + fn on_entity_look_and_move( + &mut self, + entity_id: i32, + delta_x: f64, + delta_y: f64, + delta_z: f64, + yaw: f64, + pitch: f64, + ) { use std::f64::consts::PI; if let Some(entity) = self.entity_map.get(&entity_id) { - let position = self.entities.get_component_mut(*entity, self.target_position).unwrap(); - let rotation = self.entities.get_component_mut(*entity, self.target_rotation).unwrap(); + let position = self + .entities + .get_component_mut(*entity, self.target_position) + .unwrap(); + let rotation = self + .entities + .get_component_mut(*entity, self.target_rotation) + .unwrap(); position.position.x += delta_x; position.position.y += delta_y; position.position.z += delta_z; @@ -987,31 +1288,93 @@ impl Server { } fn on_player_spawn_f64(&mut self, spawn: packet::play::clientbound::SpawnPlayer_f64) { - self.on_player_spawn(spawn.entity_id.0, spawn.uuid, spawn.x, spawn.y, spawn.z, spawn.yaw as f64, spawn.pitch as f64) + self.on_player_spawn( + spawn.entity_id.0, + spawn.uuid, + spawn.x, + spawn.y, + spawn.z, + spawn.yaw as f64, + spawn.pitch as f64, + ) } fn on_player_spawn_i32(&mut self, spawn: packet::play::clientbound::SpawnPlayer_i32) { - self.on_player_spawn(spawn.entity_id.0, spawn.uuid, f64::from(spawn.x), f64::from(spawn.y), f64::from(spawn.z), spawn.yaw as f64, spawn.pitch as f64) - } - - fn on_player_spawn_i32_helditem(&mut self, spawn: packet::play::clientbound::SpawnPlayer_i32_HeldItem) { - self.on_player_spawn(spawn.entity_id.0, spawn.uuid, f64::from(spawn.x), f64::from(spawn.y), f64::from(spawn.z), spawn.yaw as f64, spawn.pitch as f64) - } - - fn on_player_spawn_i32_helditem_string(&mut self, spawn: packet::play::clientbound::SpawnPlayer_i32_HeldItem_String) { - self.on_player_spawn(spawn.entity_id.0, protocol::UUID::from_str(&spawn.uuid), f64::from(spawn.x), f64::from(spawn.y), f64::from(spawn.z), spawn.yaw as f64, spawn.pitch as f64) - } - - fn on_player_spawn(&mut self, entity_id: i32, uuid: protocol::UUID, x: f64, y: f64, z: f64, pitch: f64, yaw: f64) { + self.on_player_spawn( + spawn.entity_id.0, + spawn.uuid, + f64::from(spawn.x), + f64::from(spawn.y), + f64::from(spawn.z), + spawn.yaw as f64, + spawn.pitch as f64, + ) + } + + fn on_player_spawn_i32_helditem( + &mut self, + spawn: packet::play::clientbound::SpawnPlayer_i32_HeldItem, + ) { + self.on_player_spawn( + spawn.entity_id.0, + spawn.uuid, + f64::from(spawn.x), + f64::from(spawn.y), + f64::from(spawn.z), + spawn.yaw as f64, + spawn.pitch as f64, + ) + } + + fn on_player_spawn_i32_helditem_string( + &mut self, + spawn: packet::play::clientbound::SpawnPlayer_i32_HeldItem_String, + ) { + self.on_player_spawn( + spawn.entity_id.0, + protocol::UUID::from_str(&spawn.uuid), + f64::from(spawn.x), + f64::from(spawn.y), + f64::from(spawn.z), + spawn.yaw as f64, + spawn.pitch as f64, + ) + } + + fn on_player_spawn( + &mut self, + entity_id: i32, + uuid: protocol::UUID, + x: f64, + y: f64, + z: f64, + pitch: f64, + yaw: f64, + ) { use std::f64::consts::PI; if let Some(entity) = self.entity_map.remove(&entity_id) { self.entities.remove_entity(entity); } - let entity = entity::player::create_remote(&mut self.entities, self.players.get(&uuid).map_or("MISSING", |v| &v.name)); - let position = self.entities.get_component_mut(entity, self.position).unwrap(); - let target_position = self.entities.get_component_mut(entity, self.target_position).unwrap(); - let rotation = self.entities.get_component_mut(entity, self.rotation).unwrap(); - let target_rotation = self.entities.get_component_mut(entity, self.target_rotation).unwrap(); + let entity = entity::player::create_remote( + &mut self.entities, + self.players.get(&uuid).map_or("MISSING", |v| &v.name), + ); + let position = self + .entities + .get_component_mut(entity, self.position) + .unwrap(); + let target_position = self + .entities + .get_component_mut(entity, self.target_position) + .unwrap(); + let rotation = self + .entities + .get_component_mut(entity, self.rotation) + .unwrap(); + let target_rotation = self + .entities + .get_component_mut(entity, self.target_rotation) + .unwrap(); position.position.x = x; position.position.y = y; position.position.z = z; @@ -1023,43 +1386,106 @@ impl Server { target_rotation.yaw = rotation.yaw; target_rotation.pitch = rotation.pitch; if let Some(info) = self.players.get(&uuid) { - let model = self.entities.get_component_mut_direct::(entity).unwrap(); + let model = self + .entities + .get_component_mut_direct::(entity) + .unwrap(); model.set_skin(info.skin_url.clone()); } self.entity_map.insert(entity_id, entity); } - fn on_teleport_player_withconfirm(&mut self, teleport: packet::play::clientbound::TeleportPlayer_WithConfirm) { - self.on_teleport_player(teleport.x, teleport.y, teleport.z, teleport.yaw as f64, teleport.pitch as f64, teleport.flags, Some(teleport.teleport_id)) - } - - fn on_teleport_player_noconfirm(&mut self, teleport: packet::play::clientbound::TeleportPlayer_NoConfirm) { - self.on_teleport_player(teleport.x, teleport.y, teleport.z, teleport.yaw as f64, teleport.pitch as f64, teleport.flags, None) - } - - fn on_teleport_player_onground(&mut self, teleport: packet::play::clientbound::TeleportPlayer_OnGround) { + fn on_teleport_player_withconfirm( + &mut self, + teleport: packet::play::clientbound::TeleportPlayer_WithConfirm, + ) { + self.on_teleport_player( + teleport.x, + teleport.y, + teleport.z, + teleport.yaw as f64, + teleport.pitch as f64, + teleport.flags, + Some(teleport.teleport_id), + ) + } + + fn on_teleport_player_noconfirm( + &mut self, + teleport: packet::play::clientbound::TeleportPlayer_NoConfirm, + ) { + self.on_teleport_player( + teleport.x, + teleport.y, + teleport.z, + teleport.yaw as f64, + teleport.pitch as f64, + teleport.flags, + None, + ) + } + + fn on_teleport_player_onground( + &mut self, + teleport: packet::play::clientbound::TeleportPlayer_OnGround, + ) { let flags: u8 = 0; // always absolute - self.on_teleport_player(teleport.x, teleport.eyes_y - 1.62, teleport.z, teleport.yaw as f64, teleport.pitch as f64, flags, None) - } - - fn on_teleport_player(&mut self, x: f64, y: f64, z: f64, yaw: f64, pitch: f64, flags: u8, teleport_id: Option) { + self.on_teleport_player( + teleport.x, + teleport.eyes_y - 1.62, + teleport.z, + teleport.yaw as f64, + teleport.pitch as f64, + flags, + None, + ) + } + + fn on_teleport_player( + &mut self, + x: f64, + y: f64, + z: f64, + yaw: f64, + pitch: f64, + flags: u8, + teleport_id: Option, + ) { use std::f64::consts::PI; if let Some(player) = self.player { - let position = self.entities.get_component_mut(player, self.target_position).unwrap(); - let rotation = self.entities.get_component_mut(player, self.rotation).unwrap(); - let velocity = self.entities.get_component_mut(player, self.velocity).unwrap(); - - position.position.x = calculate_relative_teleport(TeleportFlag::RelX, flags, position.position.x, x); - position.position.y = calculate_relative_teleport(TeleportFlag::RelY, flags, position.position.y, y); - position.position.z = calculate_relative_teleport(TeleportFlag::RelZ, flags, position.position.z, z); - rotation.yaw = calculate_relative_teleport(TeleportFlag::RelYaw, flags, rotation.yaw, -yaw as f64 * (PI / 180.0)); + let position = self + .entities + .get_component_mut(player, self.target_position) + .unwrap(); + let rotation = self + .entities + .get_component_mut(player, self.rotation) + .unwrap(); + let velocity = self + .entities + .get_component_mut(player, self.velocity) + .unwrap(); + + position.position.x = + calculate_relative_teleport(TeleportFlag::RelX, flags, position.position.x, x); + position.position.y = + calculate_relative_teleport(TeleportFlag::RelY, flags, position.position.y, y); + position.position.z = + calculate_relative_teleport(TeleportFlag::RelZ, flags, position.position.z, z); + rotation.yaw = calculate_relative_teleport( + TeleportFlag::RelYaw, + flags, + rotation.yaw, + -yaw as f64 * (PI / 180.0), + ); rotation.pitch = -((calculate_relative_teleport( TeleportFlag::RelPitch, flags, (-rotation.pitch) * (180.0 / PI) + 180.0, - pitch - ) - 180.0) * (PI / 180.0)); + pitch, + ) - 180.0) + * (PI / 180.0)); if (flags & (TeleportFlag::RelX as u8)) == 0 { velocity.velocity.x = 0.0; @@ -1072,21 +1498,23 @@ impl Server { } if let Some(teleport_id) = teleport_id { - self.write_packet(packet::play::serverbound::TeleportConfirm { - teleport_id, - }); + self.write_packet(packet::play::serverbound::TeleportConfirm { teleport_id }); } } } - fn on_block_entity_update(&mut self, block_update: packet::play::clientbound::UpdateBlockEntity) { + fn on_block_entity_update( + &mut self, + block_update: packet::play::clientbound::UpdateBlockEntity, + ) { match block_update.nbt { None => { // NBT is null, so we need to remove the block entity - self.world.add_block_entity_action(world::BlockEntityAction::Remove( - block_update.location, - )); - }, + self.world + .add_block_entity_action(world::BlockEntityAction::Remove( + block_update.location, + )); + } Some(nbt) => { match block_update.action { // TODO: support more block update actions @@ -1098,32 +1526,46 @@ impl Server { //6 => // Banner //7 => // Structure //8 => // Gateway - 9 => { // Sign - let line1 = format::Component::from_string(nbt.1.get("Text1").unwrap().as_str().unwrap()); - let line2 = format::Component::from_string(nbt.1.get("Text2").unwrap().as_str().unwrap()); - let line3 = format::Component::from_string(nbt.1.get("Text3").unwrap().as_str().unwrap()); - let line4 = format::Component::from_string(nbt.1.get("Text4").unwrap().as_str().unwrap()); - self.world.add_block_entity_action(world::BlockEntityAction::UpdateSignText( - block_update.location, - line1, - line2, - line3, - line4, - )); - }, + 9 => { + // Sign + let line1 = format::Component::from_string( + nbt.1.get("Text1").unwrap().as_str().unwrap(), + ); + let line2 = format::Component::from_string( + nbt.1.get("Text2").unwrap().as_str().unwrap(), + ); + let line3 = format::Component::from_string( + nbt.1.get("Text3").unwrap().as_str().unwrap(), + ); + let line4 = format::Component::from_string( + nbt.1.get("Text4").unwrap().as_str().unwrap(), + ); + self.world.add_block_entity_action( + world::BlockEntityAction::UpdateSignText( + block_update.location, + line1, + line2, + line3, + line4, + ), + ); + } //10 => // Unused //11 => // Jigsaw //12 => // Campfire //14 => // Beehive _ => { debug!("Unsupported block entity action: {}", block_update.action); - }, + } } } } } - fn on_block_entity_update_data(&mut self, _block_update: packet::play::clientbound::UpdateBlockEntity_Data) { + fn on_block_entity_update_data( + &mut self, + _block_update: packet::play::clientbound::UpdateBlockEntity_Data, + ) { // TODO: handle UpdateBlockEntity_Data for 1.7, decompress gzipped_nbt } @@ -1132,13 +1574,14 @@ impl Server { format::convert_legacy(&mut update_sign.line2); format::convert_legacy(&mut update_sign.line3); format::convert_legacy(&mut update_sign.line4); - self.world.add_block_entity_action(world::BlockEntityAction::UpdateSignText( - update_sign.location, - update_sign.line1, - update_sign.line2, - update_sign.line3, - update_sign.line4, - )); + self.world + .add_block_entity_action(world::BlockEntityAction::UpdateSignText( + update_sign.location, + update_sign.line1, + update_sign.line2, + update_sign.line3, + update_sign.line4, + )); } fn on_sign_update_u16(&mut self, mut update_sign: packet::play::clientbound::UpdateSign_u16) { @@ -1146,17 +1589,20 @@ impl Server { format::convert_legacy(&mut update_sign.line2); format::convert_legacy(&mut update_sign.line3); format::convert_legacy(&mut update_sign.line4); - self.world.add_block_entity_action(world::BlockEntityAction::UpdateSignText( - Position::new(update_sign.x, update_sign.y as i32, update_sign.z), - update_sign.line1, - update_sign.line2, - update_sign.line3, - update_sign.line4, - )); - } - - - fn on_player_info_string(&mut self, _player_info: packet::play::clientbound::PlayerInfo_String) { + self.world + .add_block_entity_action(world::BlockEntityAction::UpdateSignText( + Position::new(update_sign.x, update_sign.y as i32, update_sign.z), + update_sign.line1, + update_sign.line2, + update_sign.line3, + update_sign.line4, + )); + } + + fn on_player_info_string( + &mut self, + _player_info: packet::play::clientbound::PlayerInfo_String, + ) { // TODO: support PlayerInfo_String for 1.7 } @@ -1164,7 +1610,14 @@ impl Server { use crate::protocol::packet::PlayerDetail::*; for detail in player_info.inner.players { match detail { - Add { name, uuid, properties, display, gamemode, ping} => { + Add { + name, + uuid, + properties, + display, + gamemode, + ping, + } => { let info = self.players.entry(uuid.clone()).or_insert(PlayerInfo { name: name.clone(), uuid, @@ -1195,16 +1648,20 @@ impl Server { Err(err) => { error!("Failed to decode skin blob, {:?}", err); continue; - }, + } }; - let skin_blob: serde_json::Value = match serde_json::from_slice(&skin_blob) { + let skin_blob: serde_json::Value = match serde_json::from_slice(&skin_blob) + { Ok(val) => val, Err(err) => { error!("Failed to parse skin blob, {:?}", err); continue; - }, + } }; - if let Some(skin_url) = skin_blob.pointer("/textures/SKIN/url").and_then(|v| v.as_str()) { + if let Some(skin_url) = skin_blob + .pointer("/textures/SKIN/url") + .and_then(|v| v.as_str()) + { info.skin_url = Some(skin_url.to_owned()); } } @@ -1215,28 +1672,33 @@ impl Server { // This isn't an issue for other players because this packet // must come before the spawn player packet. if info.uuid == self.uuid { - let model = self.entities.get_component_mut_direct::(self.player.unwrap()).unwrap(); + let model = self + .entities + .get_component_mut_direct::( + self.player.unwrap(), + ) + .unwrap(); model.set_skin(info.skin_url.clone()); } - }, + } UpdateGamemode { uuid, gamemode } => { if let Some(info) = self.players.get_mut(&uuid) { info.gamemode = Gamemode::from_int(gamemode.0); } - }, + } UpdateLatency { uuid, ping } => { if let Some(info) = self.players.get_mut(&uuid) { info.ping = ping.0; } - }, + } UpdateDisplayName { uuid, display } => { if let Some(info) = self.players.get_mut(&uuid) { info.display_name = display; } - }, + } Remove { uuid } => { self.players.remove(&uuid); - }, + } } } } @@ -1264,93 +1726,151 @@ impl Server { } } - fn on_chunk_data_biomes3d(&mut self, chunk_data: packet::play::clientbound::ChunkData_Biomes3D) { - self.world.load_chunk115( - chunk_data.chunk_x, - chunk_data.chunk_z, - chunk_data.new, - chunk_data.bitmask.0 as u16, - chunk_data.data.data - ).unwrap(); + fn on_chunk_data_biomes3d( + &mut self, + chunk_data: packet::play::clientbound::ChunkData_Biomes3D, + ) { + self.world + .load_chunk115( + chunk_data.chunk_x, + chunk_data.chunk_z, + chunk_data.new, + chunk_data.bitmask.0 as u16, + chunk_data.data.data, + ) + .unwrap(); self.load_block_entities(chunk_data.block_entities.data); } - fn on_chunk_data(&mut self, chunk_data: packet::play::clientbound::ChunkData) { - self.world.load_chunk19( - chunk_data.chunk_x, - chunk_data.chunk_z, - chunk_data.new, - chunk_data.bitmask.0 as u16, - chunk_data.data.data - ).unwrap(); + self.world + .load_chunk19( + chunk_data.chunk_x, + chunk_data.chunk_z, + chunk_data.new, + chunk_data.bitmask.0 as u16, + chunk_data.data.data, + ) + .unwrap(); self.load_block_entities(chunk_data.block_entities.data); } - fn on_chunk_data_heightmap(&mut self, chunk_data: packet::play::clientbound::ChunkData_HeightMap) { - self.world.load_chunk19( - chunk_data.chunk_x, - chunk_data.chunk_z, - chunk_data.new, - chunk_data.bitmask.0 as u16, - chunk_data.data.data - ).unwrap(); + fn on_chunk_data_heightmap( + &mut self, + chunk_data: packet::play::clientbound::ChunkData_HeightMap, + ) { + self.world + .load_chunk19( + chunk_data.chunk_x, + chunk_data.chunk_z, + chunk_data.new, + chunk_data.bitmask.0 as u16, + chunk_data.data.data, + ) + .unwrap(); self.load_block_entities(chunk_data.block_entities.data); } - fn on_chunk_data_no_entities(&mut self, chunk_data: packet::play::clientbound::ChunkData_NoEntities) { - self.world.load_chunk19( - chunk_data.chunk_x, - chunk_data.chunk_z, - chunk_data.new, - chunk_data.bitmask.0 as u16, - chunk_data.data.data - ).unwrap(); - } - - fn on_chunk_data_no_entities_u16(&mut self, chunk_data: packet::play::clientbound::ChunkData_NoEntities_u16) { + fn on_chunk_data_no_entities( + &mut self, + chunk_data: packet::play::clientbound::ChunkData_NoEntities, + ) { + self.world + .load_chunk19( + chunk_data.chunk_x, + chunk_data.chunk_z, + chunk_data.new, + chunk_data.bitmask.0 as u16, + chunk_data.data.data, + ) + .unwrap(); + } + + fn on_chunk_data_no_entities_u16( + &mut self, + chunk_data: packet::play::clientbound::ChunkData_NoEntities_u16, + ) { let chunk_meta = vec![crate::protocol::packet::ChunkMeta { x: chunk_data.chunk_x, z: chunk_data.chunk_z, bitmask: chunk_data.bitmask, }]; let skylight = false; - self.world.load_chunks18(chunk_data.new, skylight, &chunk_meta, chunk_data.data.data).unwrap(); + self.world + .load_chunks18(chunk_data.new, skylight, &chunk_meta, chunk_data.data.data) + .unwrap(); } fn on_chunk_data_17(&mut self, chunk_data: packet::play::clientbound::ChunkData_17) { - self.world.load_chunk17(chunk_data.chunk_x, chunk_data.chunk_z, chunk_data.new, chunk_data.bitmask, chunk_data.add_bitmask, chunk_data.compressed_data.data).unwrap(); + self.world + .load_chunk17( + chunk_data.chunk_x, + chunk_data.chunk_z, + chunk_data.new, + chunk_data.bitmask, + chunk_data.add_bitmask, + chunk_data.compressed_data.data, + ) + .unwrap(); } fn on_chunk_data_bulk(&mut self, bulk: packet::play::clientbound::ChunkDataBulk) { let new = true; - self.world.load_chunks18(new, bulk.skylight, &bulk.chunk_meta.data, bulk.chunk_data.to_vec()).unwrap(); + self.world + .load_chunks18( + new, + bulk.skylight, + &bulk.chunk_meta.data, + bulk.chunk_data.to_vec(), + ) + .unwrap(); } fn on_chunk_data_bulk_17(&mut self, bulk: packet::play::clientbound::ChunkDataBulk_17) { - self.world.load_chunks17(bulk.chunk_column_count, bulk.data_length, bulk.skylight, &bulk.chunk_data_and_meta).unwrap(); + self.world + .load_chunks17( + bulk.chunk_column_count, + bulk.data_length, + bulk.skylight, + &bulk.chunk_data_and_meta, + ) + .unwrap(); } fn on_chunk_unload(&mut self, chunk_unload: packet::play::clientbound::ChunkUnload) { - self.world.unload_chunk(chunk_unload.x, chunk_unload.z, &mut self.entities); + self.world + .unload_chunk(chunk_unload.x, chunk_unload.z, &mut self.entities); } fn on_block_change(&mut self, location: Position, id: i32) { - self.world.set_block(location, block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.world.modded_block_ids)) - } - - fn on_block_change_varint(&mut self, block_change: packet::play::clientbound::BlockChange_VarInt) { + self.world.set_block( + location, + block::Block::by_vanilla_id( + id as usize, + self.protocol_version, + &self.world.modded_block_ids, + ), + ) + } + + fn on_block_change_varint( + &mut self, + block_change: packet::play::clientbound::BlockChange_VarInt, + ) { self.on_block_change(block_change.location, block_change.block_id.0) } fn on_block_change_u8(&mut self, block_change: packet::play::clientbound::BlockChange_u8) { self.on_block_change( crate::shared::Position::new(block_change.x, block_change.y as i32, block_change.z), - (block_change.block_id.0 << 4) | (block_change.block_metadata as i32) + (block_change.block_id.0 << 4) | (block_change.block_metadata as i32), ); } - fn on_multi_block_change_varint(&mut self, block_change: packet::play::clientbound::MultiBlockChange_VarInt) { + fn on_multi_block_change_varint( + &mut self, + block_change: packet::play::clientbound::MultiBlockChange_VarInt, + ) { let ox = block_change.chunk_x << 4; let oz = block_change.chunk_z << 4; for record in block_change.records.data { @@ -1358,20 +1878,27 @@ impl Server { Position::new( ox + (record.xz >> 4) as i32, record.y as i32, - oz + (record.xz & 0xF) as i32 + oz + (record.xz & 0xF) as i32, + ), + block::Block::by_vanilla_id( + record.block_id.0 as usize, + self.protocol_version, + &self.world.modded_block_ids, ), - block::Block::by_vanilla_id(record.block_id.0 as usize, self.protocol_version, &self.world.modded_block_ids) ); } } - fn on_multi_block_change_u16(&mut self, block_change: packet::play::clientbound::MultiBlockChange_u16) { + fn on_multi_block_change_u16( + &mut self, + block_change: packet::play::clientbound::MultiBlockChange_u16, + ) { let ox = block_change.chunk_x << 4; let oz = block_change.chunk_z << 4; let mut data = std::io::Cursor::new(block_change.data); - for _ in 0 .. block_change.record_count { + for _ in 0..block_change.record_count { use byteorder::{BigEndian, ReadBytesExt}; let record = data.read_u32::().unwrap(); @@ -1383,11 +1910,14 @@ impl Server { self.world.set_block( Position::new(x, y, z), - block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.world.modded_block_ids) + block::Block::by_vanilla_id( + id as usize, + self.protocol_version, + &self.world.modded_block_ids, + ), ); } } - } #[derive(Debug, Clone, Copy)] diff --git a/src/server/plugin_messages.rs b/src/server/plugin_messages.rs index 42f75f6a..0ba269ed 100644 --- a/src/server/plugin_messages.rs +++ b/src/server/plugin_messages.rs @@ -1,4 +1,3 @@ - use crate::protocol::packet::play::serverbound::PluginMessageServerbound; use crate::protocol::packet::play::serverbound::PluginMessageServerbound_i16; use crate::protocol::{Serializable, VarShort}; @@ -34,5 +33,4 @@ impl Brand { data: crate::protocol::LenPrefixedBytes::::new(data), } } - } diff --git a/src/server/sun.rs b/src/server/sun.rs index 55961164..9855c889 100644 --- a/src/server/sun.rs +++ b/src/server/sun.rs @@ -1,7 +1,6 @@ - use crate::render; use crate::render::model; -use cgmath::{Vector3, Matrix4, Decomposed, Rotation3, Rad, Quaternion}; +use cgmath::{Decomposed, Matrix4, Quaternion, Rad, Rotation3, Vector3}; pub struct SunModel { sun: model::ModelKey, @@ -12,7 +11,6 @@ pub struct SunModel { const SIZE: f32 = 50.0; impl SunModel { - pub fn new(renderer: &mut render::Renderer) -> SunModel { SunModel { sun: SunModel::generate_sun(renderer), @@ -71,26 +69,123 @@ impl SunModel { renderer.model.create_model( model::SUN, vec![vec![ - model::Vertex{x: 0.0, y: -SIZE, z: -SIZE, texture_x: 0.0, texture_y: 1.0, texture: tex.clone(), r: 255, g: 255, b: 255, a: 0, id: 0}, - model::Vertex{x: 0.0, y: SIZE, z: -SIZE, texture_x: 0.0, texture_y: 0.0, texture: tex.clone(), r: 255, g: 255, b: 255, a: 0, id: 0}, - model::Vertex{x: 0.0, y: -SIZE, z: SIZE, texture_x: 1.0, texture_y: 1.0, texture: tex.clone(), r: 255, g: 255, b: 255, a: 0, id: 0}, - model::Vertex{x: 0.0, y: SIZE, z: SIZE, texture_x: 1.0, texture_y: 0.0, texture: tex.clone(), r: 255, g: 255, b: 255, a: 0, id: 0} - ]] + model::Vertex { + x: 0.0, + y: -SIZE, + z: -SIZE, + texture_x: 0.0, + texture_y: 1.0, + texture: tex.clone(), + r: 255, + g: 255, + b: 255, + a: 0, + id: 0, + }, + model::Vertex { + x: 0.0, + y: SIZE, + z: -SIZE, + texture_x: 0.0, + texture_y: 0.0, + texture: tex.clone(), + r: 255, + g: 255, + b: 255, + a: 0, + id: 0, + }, + model::Vertex { + x: 0.0, + y: -SIZE, + z: SIZE, + texture_x: 1.0, + texture_y: 1.0, + texture: tex.clone(), + r: 255, + g: 255, + b: 255, + a: 0, + id: 0, + }, + model::Vertex { + x: 0.0, + y: SIZE, + z: SIZE, + texture_x: 1.0, + texture_y: 0.0, + texture: tex.clone(), + r: 255, + g: 255, + b: 255, + a: 0, + id: 0, + }, + ]], ) } pub fn generate_moon(renderer: &mut render::Renderer, phase: i32) -> model::ModelKey { - let tex = render::Renderer::get_texture(renderer.get_textures_ref(), "environment/moon_phases"); + let tex = + render::Renderer::get_texture(renderer.get_textures_ref(), "environment/moon_phases"); let mpx = (phase % 4) as f64 * (1.0 / 4.0); let mpy = (phase / 4) as f64 * (1.0 / 2.0); renderer.model.create_model( model::SUN, vec![vec![ - model::Vertex{x: 0.0, y: -SIZE, z: -SIZE, texture_x: mpx, texture_y: mpy + (1.0 / 2.0), texture: tex.clone(), r: 255, g: 255, b: 255, a: 0, id: 0}, - model::Vertex{x: 0.0, y: SIZE, z: -SIZE, texture_x: mpx, texture_y: mpy, texture: tex.clone(), r: 255, g: 255, b: 255, a: 0, id: 0}, - model::Vertex{x: 0.0, y: -SIZE, z: SIZE, texture_x: mpx + (1.0 / 4.0), texture_y: mpy + (1.0 / 2.0), texture: tex.clone(), r: 255, g: 255, b: 255, a: 0, id: 0}, - model::Vertex{x: 0.0, y: SIZE, z: SIZE, texture_x: mpx + (1.0 / 4.0), texture_y: mpy, texture: tex.clone(), r: 255, g: 255, b: 255, a: 0, id: 0} - ]] + model::Vertex { + x: 0.0, + y: -SIZE, + z: -SIZE, + texture_x: mpx, + texture_y: mpy + (1.0 / 2.0), + texture: tex.clone(), + r: 255, + g: 255, + b: 255, + a: 0, + id: 0, + }, + model::Vertex { + x: 0.0, + y: SIZE, + z: -SIZE, + texture_x: mpx, + texture_y: mpy, + texture: tex.clone(), + r: 255, + g: 255, + b: 255, + a: 0, + id: 0, + }, + model::Vertex { + x: 0.0, + y: -SIZE, + z: SIZE, + texture_x: mpx + (1.0 / 4.0), + texture_y: mpy + (1.0 / 2.0), + texture: tex.clone(), + r: 255, + g: 255, + b: 255, + a: 0, + id: 0, + }, + model::Vertex { + x: 0.0, + y: SIZE, + z: SIZE, + texture_x: mpx + (1.0 / 4.0), + texture_y: mpy, + texture: tex.clone(), + r: 255, + g: 255, + b: 255, + a: 0, + id: 0, + }, + ]], ) } } diff --git a/src/server/target.rs b/src/server/target.rs index 63c8e1a6..ebb103ba 100644 --- a/src/server/target.rs +++ b/src/server/target.rs @@ -1,10 +1,9 @@ - +use crate::render; +use crate::render::model; +use crate::shared::{Direction, Position}; use crate::world; use crate::world::block; -use crate::shared::{Position, Direction}; use cgmath; -use crate::render; -use crate::render::model; use collision::{self, Aabb}; pub struct Info { @@ -17,13 +16,13 @@ impl Info { pub fn new() -> Info { Info { model: None, - last_block: block::Air{}, + last_block: block::Air {}, last_pos: Position::new(0, 0, 0), } } pub fn clear(&mut self, renderer: &mut render::Renderer) { - self.last_block = block::Air{}; + self.last_block = block::Air {}; if let Some(model) = self.model.take() { renderer.model.remove_model(model); } @@ -44,16 +43,27 @@ impl Info { let tex = render::Renderer::get_texture(renderer.get_textures_ref(), "steven:solid"); for bound in bl.get_collision_boxes() { - let bound = bound.add_v(cgmath::Vector3::new(pos.x as f64, pos.y as f64, pos.z as f64)); + let bound = bound.add_v(cgmath::Vector3::new( + pos.x as f64, + pos.y as f64, + pos.z as f64, + )); for point in [ (bound.min.x, bound.min.z), (bound.min.x, bound.max.z), (bound.max.x, bound.min.z), (bound.max.x, bound.max.z), - ].iter() { - model::append_box(&mut parts, - (point.0-LINE_SIZE) as f32, (bound.min.y-LINE_SIZE) as f32, (point.1-LINE_SIZE) as f32, - (LINE_SIZE*2.0) as f32, ((bound.max.y-bound.min.y)+LINE_SIZE*2.0) as f32, (LINE_SIZE*2.0) as f32, + ] + .iter() + { + model::append_box( + &mut parts, + (point.0 - LINE_SIZE) as f32, + (bound.min.y - LINE_SIZE) as f32, + (point.1 - LINE_SIZE) as f32, + (LINE_SIZE * 2.0) as f32, + ((bound.max.y - bound.min.y) + LINE_SIZE * 2.0) as f32, + (LINE_SIZE * 2.0) as f32, [ Some(tex.clone()), Some(tex.clone()), @@ -61,7 +71,8 @@ impl Info { Some(tex.clone()), Some(tex.clone()), Some(tex.clone()), - ]); + ], + ); } for point in [ @@ -69,10 +80,17 @@ impl Info { (bound.min.x, bound.max.z, bound.max.x, bound.max.z), (bound.min.x, bound.min.z, bound.min.x, bound.max.z), (bound.max.x, bound.min.z, bound.max.x, bound.max.z), - ].iter() { - model::append_box(&mut parts, - (point.0-LINE_SIZE) as f32, (bound.min.y-LINE_SIZE) as f32, (point.1-LINE_SIZE) as f32, - ((point.2-point.0)+(LINE_SIZE*2.0)) as f32, (LINE_SIZE*2.0) as f32, ((point.3-point.1)+(LINE_SIZE*2.0)) as f32, + ] + .iter() + { + model::append_box( + &mut parts, + (point.0 - LINE_SIZE) as f32, + (bound.min.y - LINE_SIZE) as f32, + (point.1 - LINE_SIZE) as f32, + ((point.2 - point.0) + (LINE_SIZE * 2.0)) as f32, + (LINE_SIZE * 2.0) as f32, + ((point.3 - point.1) + (LINE_SIZE * 2.0)) as f32, [ Some(tex.clone()), Some(tex.clone()), @@ -80,10 +98,16 @@ impl Info { Some(tex.clone()), Some(tex.clone()), Some(tex.clone()), - ]); - model::append_box(&mut parts, - (point.0-LINE_SIZE) as f32, (bound.max.y-LINE_SIZE) as f32, (point.1-LINE_SIZE) as f32, - ((point.2-point.0)+(LINE_SIZE*2.0)) as f32, (LINE_SIZE*2.0) as f32, ((point.3-point.1)+(LINE_SIZE*2.0)) as f32, + ], + ); + model::append_box( + &mut parts, + (point.0 - LINE_SIZE) as f32, + (bound.max.y - LINE_SIZE) as f32, + (point.1 - LINE_SIZE) as f32, + ((point.2 - point.0) + (LINE_SIZE * 2.0)) as f32, + (LINE_SIZE * 2.0) as f32, + ((point.3 - point.1) + (LINE_SIZE * 2.0)) as f32, [ Some(tex.clone()), Some(tex.clone()), @@ -91,7 +115,8 @@ impl Info { Some(tex.clone()), Some(tex.clone()), Some(tex.clone()), - ]); + ], + ); } } @@ -105,7 +130,15 @@ impl Info { } } -pub fn test_block(world: &world::World, pos: Position, s: cgmath::Vector3, d: cgmath::Vector3) -> (bool, Option<(Position, block::Block, Direction, cgmath::Vector3)>) { +pub fn test_block( + world: &world::World, + pos: Position, + s: cgmath::Vector3, + d: cgmath::Vector3, +) -> ( + bool, + Option<(Position, block::Block, Direction, cgmath::Vector3)>, +) { let block = world.get_block(pos); let posf = cgmath::Vector3::new(pos.x as f64, pos.y as f64, pos.z as f64); for bound in block.get_collision_boxes() { @@ -137,7 +170,11 @@ fn find_face(bound: collision::Aabb3, hit: cgmath::Vector3) -> Directi } } -fn intersects_line(bound: collision::Aabb3, origin: cgmath::Vector3, dir: cgmath::Vector3) -> Option> { +fn intersects_line( + bound: collision::Aabb3, + origin: cgmath::Vector3, + dir: cgmath::Vector3, +) -> Option> { const RIGHT: usize = 0; const LEFT: usize = 1; const MIDDLE: usize = 2; @@ -145,7 +182,7 @@ fn intersects_line(bound: collision::Aabb3, origin: cgmath::Vector3, d let mut candidate_plane = [0.0, 0.0, 0.0]; let mut max_t = [0.0, 0.0, 0.0]; let mut inside = true; - for i in 0 .. 3 { + for i in 0..3 { if origin[i] < bound.min[i] { quadrant[i] = LEFT; candidate_plane[i] = bound.min[i]; @@ -162,13 +199,13 @@ fn intersects_line(bound: collision::Aabb3, origin: cgmath::Vector3, d return Some(origin); } - for i in 0 .. 3 { + for i in 0..3 { if quadrant[i] != MIDDLE && dir[i] != 0.0 { max_t[i] = (candidate_plane[i] - origin[i]) / dir[i]; } } let mut which_plane = 0; - for i in 1 .. 3 { + for i in 1..3 { if max_t[which_plane] < max_t[i] { which_plane = i; } @@ -178,7 +215,7 @@ fn intersects_line(bound: collision::Aabb3, origin: cgmath::Vector3, d } let mut coord = cgmath::Vector3::new(0.0, 0.0, 0.0); - for i in 0 .. 3 { + for i in 0..3 { if which_plane != i { coord[i] = origin[i] + max_t[which_plane] * dir[i]; if coord[i] < bound.min[i] || coord[i] > bound.max[i] { @@ -191,8 +228,16 @@ fn intersects_line(bound: collision::Aabb3, origin: cgmath::Vector3, d Some(coord) } -pub fn trace_ray(world: &world::World, max: f64, s: cgmath::Vector3, d: cgmath::Vector3, collide_func: F) -> Option - where F: Fn(&world::World, Position, cgmath::Vector3, cgmath::Vector3,) -> (bool, Option) { +pub fn trace_ray( + world: &world::World, + max: f64, + s: cgmath::Vector3, + d: cgmath::Vector3, + collide_func: F, +) -> Option +where + F: Fn(&world::World, Position, cgmath::Vector3, cgmath::Vector3) -> (bool, Option), +{ struct Gen { count: i32, base: f64, @@ -208,11 +253,7 @@ pub fn trace_ray(world: &world::World, max: f64, s: cgmath::Vector3, } else { 0.0 }; - Gen { - count: 0, - base, - d, - } + Gen { count: 0, base, d } } fn next(&mut self) -> f64 { diff --git a/src/settings.rs b/src/settings.rs index 20bee79d..fc260583 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,6 +1,6 @@ use crate::console; -use std::marker::PhantomData; use glutin::event::VirtualKeyCode; +use std::marker::PhantomData; // Might just rename this to settings.rs pub const R_MAX_FPS: console::CVar = console::CVar { @@ -40,24 +40,37 @@ pub const CL_MASTER_VOLUME: console::CVar = console::CVar { }; macro_rules! create_keybind { - ($keycode:ident, $name:expr, $description:expr) => (console::CVar { - ty: PhantomData, - name: $name, - description: $description, - mutable: true, - serializable: true, - default: &|| VirtualKeyCode::$keycode as i64 - }) + ($keycode:ident, $name:expr, $description:expr) => { + console::CVar { + ty: PhantomData, + name: $name, + description: $description, + mutable: true, + serializable: true, + default: &|| VirtualKeyCode::$keycode as i64, + } + }; } -pub const CL_KEYBIND_FORWARD: console::CVar = create_keybind!(W, "cl_keybind_forward", "Keybinding for moving forward"); -pub const CL_KEYBIND_BACKWARD: console::CVar = create_keybind!(S, "cl_keybind_backward", "Keybinding for moving backward"); -pub const CL_KEYBIND_LEFT: console::CVar = create_keybind!(A, "cl_keybind_left", "Keybinding for moving the left"); -pub const CL_KEYBIND_RIGHT: console::CVar = create_keybind!(D, "cl_keybind_right", "Keybinding for moving to the right"); -pub const CL_KEYBIND_OPEN_INV: console::CVar = create_keybind!(E, "cl_keybind_open_inv", "Keybinding for opening the inventory"); -pub const CL_KEYBIND_SNEAK: console::CVar = create_keybind!(LShift, "cl_keybind_sneak", "Keybinding for sneaking"); -pub const CL_KEYBIND_SPRINT: console::CVar = create_keybind!(LControl, "cl_keybind_sprint", "Keybinding for sprinting"); -pub const CL_KEYBIND_JUMP: console::CVar = create_keybind!(Space, "cl_keybind_jump", "Keybinding for jumping"); +pub const CL_KEYBIND_FORWARD: console::CVar = + create_keybind!(W, "cl_keybind_forward", "Keybinding for moving forward"); +pub const CL_KEYBIND_BACKWARD: console::CVar = + create_keybind!(S, "cl_keybind_backward", "Keybinding for moving backward"); +pub const CL_KEYBIND_LEFT: console::CVar = + create_keybind!(A, "cl_keybind_left", "Keybinding for moving the left"); +pub const CL_KEYBIND_RIGHT: console::CVar = + create_keybind!(D, "cl_keybind_right", "Keybinding for moving to the right"); +pub const CL_KEYBIND_OPEN_INV: console::CVar = create_keybind!( + E, + "cl_keybind_open_inv", + "Keybinding for opening the inventory" +); +pub const CL_KEYBIND_SNEAK: console::CVar = + create_keybind!(LShift, "cl_keybind_sneak", "Keybinding for sneaking"); +pub const CL_KEYBIND_SPRINT: console::CVar = + create_keybind!(LControl, "cl_keybind_sprint", "Keybinding for sprinting"); +pub const CL_KEYBIND_JUMP: console::CVar = + create_keybind!(Space, "cl_keybind_jump", "Keybinding for jumping"); pub const DOUBLE_JUMP_MS: u32 = 100; @@ -90,15 +103,22 @@ pub enum Stevenkey { impl Stevenkey { pub fn values() -> Vec { - vec!(Stevenkey::Forward, Stevenkey::Backward, Stevenkey::Left, - Stevenkey::Right, Stevenkey::OpenInv, Stevenkey::Sneak, - Stevenkey::Sprint, Stevenkey::Jump) + vec![ + Stevenkey::Forward, + Stevenkey::Backward, + Stevenkey::Left, + Stevenkey::Right, + Stevenkey::OpenInv, + Stevenkey::Sneak, + Stevenkey::Sprint, + Stevenkey::Jump, + ] } pub fn get_by_keycode(keycode: VirtualKeyCode, vars: &console::Vars) -> Option { for steven_key in Stevenkey::values() { if keycode as i64 == *vars.get(steven_key.get_cvar()) { - return Some(steven_key) + return Some(steven_key); } } None @@ -113,7 +133,7 @@ impl Stevenkey { Stevenkey::OpenInv => CL_KEYBIND_OPEN_INV, Stevenkey::Sneak => CL_KEYBIND_SNEAK, Stevenkey::Sprint => CL_KEYBIND_SPRINT, - Stevenkey::Jump => CL_KEYBIND_JUMP + Stevenkey::Jump => CL_KEYBIND_JUMP, } } } diff --git a/src/ui/logo.rs b/src/ui/logo.rs index 976faaea..20f9c84f 100644 --- a/src/ui/logo.rs +++ b/src/ui/logo.rs @@ -1,12 +1,11 @@ - -use std::sync::{Arc, RwLock}; -use std::f64::consts; -use crate::ui; use crate::render; use crate::resources; -use std::time::{SystemTime, UNIX_EPOCH}; +use crate::ui; use rand::{self, seq::SliceRandom}; use rand_pcg; +use std::f64::consts; +use std::sync::{Arc, RwLock}; +use std::time::{SystemTime, UNIX_EPOCH}; pub struct Logo { _shadow: ui::BatchRef, @@ -20,9 +19,10 @@ pub struct Logo { } impl Logo { - pub fn new(resources: Arc>, - ui_container: &mut ui::Container) - -> Logo { + pub fn new( + resources: Arc>, + ui_container: &mut ui::Container, + ) -> Logo { let logo_str = { let res = resources.read().unwrap(); let mut logo = res.open("steven", "logo/logo.txt").unwrap(); @@ -66,14 +66,15 @@ impl Logo { .colour((0, 0, 0, 100)) .attach(&mut *shadow_batch.borrow_mut()); - ui::ImageBuilder::new() .texture("minecraft:blocks/planks_oak") .position(x as f64, y as f64) .size(4.0, 8.0) .texture_coords(( - (x % 16) as f64 / 16.0, (y % 16) as f64 / 16.0, - 4.0 / 16.0, 8.0 / 16.0 + (x % 16) as f64 / 16.0, + (y % 16) as f64 / 16.0, + 4.0 / 16.0, + 8.0 / 16.0, )) .colour((r, g, b, 255)) .attach(&mut *layer0.borrow_mut()); @@ -101,7 +102,8 @@ impl Logo { text_strings.push(line.to_owned().replace("\r", "")); } } - let mut r: rand_pcg::Pcg32 = rand::SeedableRng::from_seed([45, 0, 0, 0, 64, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0]); + let mut r: rand_pcg::Pcg32 = + rand::SeedableRng::from_seed([45, 0, 0, 0, 64, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0]); text_strings.shuffle(&mut r); } @@ -147,7 +149,7 @@ impl Logo { if self.text_base_scale > 1.0 { self.text_base_scale = 1.0; } - text.x =(-width / 2.0) * self.text_base_scale; + text.x = (-width / 2.0) * self.text_base_scale; self.text_orig_x = text.x; } @@ -160,6 +162,6 @@ impl Logo { text.scale_x = (0.7 + (offset / 3.0)) * self.text_base_scale; text.scale_y = (0.7 + (offset / 3.0)) * self.text_base_scale; let scale = text.scale_x; - text.x =self.text_orig_x * scale * self.text_base_scale; + text.x = self.text_orig_x * scale * self.text_base_scale; } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 2e81c707..86dedb31 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -14,18 +14,17 @@ pub mod logo; -use std::rc::{Rc, Weak}; -use std::cell::{RefCell, RefMut}; -use crate::render; use crate::format; -use glutin::event::VirtualKeyCode; +use crate::render; #[cfg(not(target_arch = "wasm32"))] -use clipboard::{ClipboardProvider, ClipboardContext}; +use clipboard::{ClipboardContext, ClipboardProvider}; +use glutin::event::VirtualKeyCode; +use std::cell::{RefCell, RefMut}; +use std::rc::{Rc, Weak}; const SCALED_WIDTH: f64 = 854.0; const SCALED_HEIGHT: f64 = 480.0; - #[derive(Clone, Copy, PartialEq)] pub enum Mode { Scaled, @@ -56,8 +55,10 @@ struct Region { impl Region { fn intersects(&self, o: &Region) -> bool { - !(self.x + self.w < o.x || self.x > o.x + o.w || self.y + self.h < o.y || - self.y > o.y + o.h) + !(self.x + self.w < o.x + || self.x > o.x + o.w + || self.y + self.h < o.y + || self.y > o.y + o.h) } } @@ -304,8 +305,13 @@ impl Container { Mode::Unscaled(scale) => (scale, scale), }; - if self.last_sw != sw || self.last_sh != sh || self.last_width != width || - self.last_height != height || self.version != renderer.ui.version || self.last_mode != self.mode { + if self.last_sw != sw + || self.last_sh != sh + || self.last_width != width + || self.last_height != height + || self.version != renderer.ui.version + || self.last_mode != self.mode + { self.last_sw = sw; self.last_sh = sh; self.last_width = width; @@ -324,9 +330,12 @@ impl Container { // If we don't have an element focused, focus one if !self.focusable_elements.is_empty() - && !self.focusable_elements.iter() - .flat_map(|v| v.upgrade()) - .any(|v| v.is_focused()) { + && !self + .focusable_elements + .iter() + .flat_map(|v| v.upgrade()) + .any(|v| v.is_focused()) + { self.cycle_focus() } @@ -380,13 +389,14 @@ impl Container { if self.focusable_elements.is_empty() { return; } - let focusables = self.focusable_elements.iter() + let focusables = self + .focusable_elements + .iter() .flat_map(|v| v.upgrade()) .collect::>(); // Find the last focused element if there is one - let last_focus = focusables.iter() - .position(|v| v.is_focused()); + let last_focus = focusables.iter().position(|v| v.is_focused()); let next_focus = last_focus.map_or(0, |v| v + 1) % focusables.len(); // Clear the last focus @@ -397,15 +407,20 @@ impl Container { focusables[next_focus].set_focused(true); } - pub fn key_press(&mut self, game: &mut crate::Game, key: VirtualKeyCode, down: bool, ctrl_pressed: bool) { + pub fn key_press( + &mut self, + game: &mut crate::Game, + key: VirtualKeyCode, + down: bool, + ctrl_pressed: bool, + ) { if key == VirtualKeyCode::Tab { if !down { self.cycle_focus(); } return; } - for el in self.focusable_elements.iter() - .flat_map(|v| v.upgrade()) { + for el in self.focusable_elements.iter().flat_map(|v| v.upgrade()) { if el.is_focused() { el.key_press(game, key, down, ctrl_pressed); } @@ -416,8 +431,7 @@ impl Container { if c < ' ' { return; } - for el in self.focusable_elements.iter() - .flat_map(|v| v.upgrade()) { + for el in self.focusable_elements.iter().flat_map(|v| v.upgrade()) { if el.is_focused() { el.key_type(game, c); } @@ -463,11 +477,27 @@ impl ElementHolder for Container { } trait UIElement { - fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, sw: f64, sh: f64, width: f64, height: f64, delta: f64) -> &mut [u8]; + fn draw( + &mut self, + renderer: &mut render::Renderer, + r: &Region, + sw: f64, + sh: f64, + width: f64, + height: f64, + delta: f64, + ) -> &mut [u8]; fn get_size(&self) -> (f64, f64); fn is_dirty(&self) -> bool; fn post_init(_: Rc>) {} - fn key_press(&mut self, _game: &mut crate::Game, _key: VirtualKeyCode, _down: bool, _ctrl_pressed: bool) {} + fn key_press( + &mut self, + _game: &mut crate::Game, + _key: VirtualKeyCode, + _down: bool, + _ctrl_pressed: bool, + ) { + } fn key_type(&mut self, _game: &mut crate::Game, _c: char) {} fn tick(&mut self, renderer: &mut render::Renderer); } @@ -804,14 +834,29 @@ impl ImageBuilder { } impl UIElement for Image { - fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, sw: f64, sh: f64, width: f64, height: f64, delta: f64) -> &mut [u8] { + fn draw( + &mut self, + renderer: &mut render::Renderer, + r: &Region, + sw: f64, + sh: f64, + width: f64, + height: f64, + delta: f64, + ) -> &mut [u8] { if self.check_rebuild() { self.data.clear(); let texture = render::Renderer::get_texture(renderer.get_textures_ref(), &self.texture); let mut element = render::ui::UIElement::new( &texture, - r.x, r.y, r.w, r.h, - self.texture_coords.0, self.texture_coords.1, self.texture_coords.2, self.texture_coords.3, + r.x, + r.y, + r.w, + r.h, + self.texture_coords.0, + self.texture_coords.1, + self.texture_coords.2, + self.texture_coords.3, ); element.r = self.colour.0; element.g = self.colour.1; @@ -862,7 +907,16 @@ impl BatchBuilder { } impl UIElement for Batch { - fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, sw: f64, sh: f64, width: f64, height: f64, delta: f64) -> &mut [u8] { + fn draw( + &mut self, + renderer: &mut render::Renderer, + r: &Region, + sw: f64, + sh: f64, + width: f64, + height: f64, + delta: f64, + ) -> &mut [u8] { if self.check_rebuild() { self.data.clear(); self.super_draw(renderer, r, sw, sh, width, height, delta); @@ -916,15 +970,29 @@ element! { } impl UIElement for Text { - fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, sw: f64, sh: f64, width: f64, height: f64, delta: f64) -> &mut [u8] { + fn draw( + &mut self, + renderer: &mut render::Renderer, + r: &Region, + sw: f64, + sh: f64, + width: f64, + height: f64, + delta: f64, + ) -> &mut [u8] { if self.check_rebuild() { self.data.clear(); let mut text = if self.rotation == 0.0 { renderer.ui.new_text_scaled( &self.text, - r.x, r.y, sw * self.scale_x, sh * self.scale_y, - self.colour.0, self.colour.1, self.colour.2, + r.x, + r.y, + sw * self.scale_x, + sh * self.scale_y, + self.colour.0, + self.colour.1, + self.colour.2, ) } else { let c = self.rotation.cos(); @@ -934,11 +1002,15 @@ impl UIElement for Text { let w = (tmpx * c - tmpy * s).abs(); let h = (tmpy * c + tmpx * s).abs(); renderer.ui.new_text_rotated( - &self.text, - r.x + w - (r.w / 2.0), r.y + h - (r.h / 2.0), - sw * self.scale_x, sh * self.scale_y, - self.rotation, - self.colour.0, self.colour.1, self.colour.2, + &self.text, + r.x + w - (r.w / 2.0), + r.y + h - (r.h / 2.0), + sw * self.scale_x, + sh * self.scale_y, + self.rotation, + self.colour.0, + self.colour.1, + self.colour.2, ) }; for e in &mut text.elements { @@ -964,7 +1036,10 @@ impl UIElement for Text { } fn get_size(&self) -> (f64, f64) { - ((self.width + 2.0) * self.scale_x, self.height * self.scale_y) + ( + (self.width + 2.0) * self.scale_x, + self.height * self.scale_y, + ) } fn is_dirty(&self) -> bool { @@ -976,8 +1051,6 @@ impl UIElement for Text { } } - - element! { ref FormattedRef pub struct Formatted { @@ -1011,7 +1084,16 @@ element! { } impl UIElement for Formatted { - fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, sw: f64, sh: f64, width: f64, height: f64, delta: f64) -> &mut [u8] { + fn draw( + &mut self, + renderer: &mut render::Renderer, + r: &Region, + sw: f64, + sh: f64, + width: f64, + height: f64, + delta: f64, + ) -> &mut [u8] { if self.check_rebuild() { self.data.clear(); @@ -1058,7 +1140,10 @@ impl UIElement for Formatted { } fn get_size(&self) -> (f64, f64) { - ((self.width + 2.0) * self.scale_x, self.height * self.scale_y) + ( + (self.width + 2.0) * self.scale_x, + self.height * self.scale_y, + ) } fn is_dirty(&self) -> bool { @@ -1075,7 +1160,11 @@ impl Formatted { self.dirty = true; } - pub fn compute_size(renderer: &render::Renderer, text: &format::Component, max_width: f64) -> (f64, f64) { + pub fn compute_size( + renderer: &render::Renderer, + text: &format::Component, + max_width: f64, + ) -> (f64, f64) { let mut state = FormatState { lines: 0, width: 0.0, @@ -1098,14 +1187,13 @@ struct FormatState<'a> { renderer: &'a render::Renderer, } - -impl <'a> ElementHolder for FormatState<'a> { +impl<'a> ElementHolder for FormatState<'a> { fn add(&mut self, el: Element, _: bool) { self.text.push(el); } } -impl <'a> FormatState<'a> { +impl<'a> FormatState<'a> { fn build(&mut self, c: &format::Component, color: format::Color) { match *c { format::Component::Text(ref txt) => { @@ -1197,46 +1285,156 @@ impl ButtonBuilder { } impl UIElement for Button { - fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, sw: f64, sh: f64, width: f64, height: f64, delta: f64) -> &mut [u8] { + fn draw( + &mut self, + renderer: &mut render::Renderer, + r: &Region, + sw: f64, + sh: f64, + width: f64, + height: f64, + delta: f64, + ) -> &mut [u8] { if self.check_rebuild() { self.data.clear(); let offset = match (self.disabled, self.hovered) { - (true, _) => 46.0, - (false, true) => 86.0, - (false, false) => 66.0, + (true, _) => 46.0, + (false, true) => 86.0, + (false, false) => 66.0, }; let texture = render::Renderer::get_texture(renderer.get_textures_ref(), "gui/widgets") - .relative(0.0, offset / 256.0, 200.0 / 256.0, 20.0 / 256.0); - - self.data.extend(render::ui::UIElement::new(&texture, r.x, r.y, 4.0 * sw, 4.0 * sh, 0.0, 0.0, 2.0/200.0, 2.0/20.0).bytes(width, height)); - self.data.extend(render::ui::UIElement::new(&texture, r.x + r.w - 4.0 * sw, r.y, 4.0 * sw, 4.0 * sh, 198.0/200.0, 0.0, 2.0/200.0, 2.0/20.0).bytes(width, height)); - self.data.extend(render::ui::UIElement::new(&texture, r.x, r.y + r.h - 6.0 * sh, 4.0 * sw, 6.0 * sh, 0.0, 17.0/20.0, 2.0/200.0, 3.0/20.0).bytes(width, height)); - self.data.extend(render::ui::UIElement::new(&texture, r.x + r.w - 4.0 * sw, r.y + r.h - 6.0 * sh, 4.0 * sw, 6.0 * sh, 198.0/200.0, 17.0/20.0, 2.0/200.0, 3.0/20.0).bytes(width, height)); - - let w = ((r.w / sw)/2.0) - 4.0; - self.data.extend(render::ui::UIElement::new( - &texture.relative(2.0/200.0, 0.0, 196.0/200.0, 2.0/20.0), - r.x+4.0*sw, r.y, r.w - 8.0 * sw, 4.0 * sh, 0.0, 0.0, w/196.0, 1.0).bytes(width, height) + .relative(0.0, offset / 256.0, 200.0 / 256.0, 20.0 / 256.0); + + self.data.extend( + render::ui::UIElement::new( + &texture, + r.x, + r.y, + 4.0 * sw, + 4.0 * sh, + 0.0, + 0.0, + 2.0 / 200.0, + 2.0 / 20.0, + ) + .bytes(width, height), ); - self.data.extend(render::ui::UIElement::new( - &texture.relative(2.0/200.0, 17.0/20.0, 196.0/200.0, 3.0/20.0), - r.x+4.0*sw, r.y+r.h-6.0*sh, r.w - 8.0 * sw, 6.0 * sh, 0.0, 0.0, w/196.0, 1.0).bytes(width, height) + self.data.extend( + render::ui::UIElement::new( + &texture, + r.x + r.w - 4.0 * sw, + r.y, + 4.0 * sw, + 4.0 * sh, + 198.0 / 200.0, + 0.0, + 2.0 / 200.0, + 2.0 / 20.0, + ) + .bytes(width, height), + ); + self.data.extend( + render::ui::UIElement::new( + &texture, + r.x, + r.y + r.h - 6.0 * sh, + 4.0 * sw, + 6.0 * sh, + 0.0, + 17.0 / 20.0, + 2.0 / 200.0, + 3.0 / 20.0, + ) + .bytes(width, height), + ); + self.data.extend( + render::ui::UIElement::new( + &texture, + r.x + r.w - 4.0 * sw, + r.y + r.h - 6.0 * sh, + 4.0 * sw, + 6.0 * sh, + 198.0 / 200.0, + 17.0 / 20.0, + 2.0 / 200.0, + 3.0 / 20.0, + ) + .bytes(width, height), ); - let h = ((r.h / sh)/2.0) - 5.0; - self.data.extend(render::ui::UIElement::new( - &texture.relative(0.0/200.0, 2.0/20.0, 2.0/200.0, 15.0/20.0), - r.x, r.y + 4.0*sh, 4.0 * sw, r.h - 10.0*sh, 0.0, 0.0, 1.0, h/16.0).bytes(width, height) + let w = ((r.w / sw) / 2.0) - 4.0; + self.data.extend( + render::ui::UIElement::new( + &texture.relative(2.0 / 200.0, 0.0, 196.0 / 200.0, 2.0 / 20.0), + r.x + 4.0 * sw, + r.y, + r.w - 8.0 * sw, + 4.0 * sh, + 0.0, + 0.0, + w / 196.0, + 1.0, + ) + .bytes(width, height), ); - self.data.extend(render::ui::UIElement::new( - &texture.relative(198.0/200.0, 2.0/20.0, 2.0/200.0, 15.0/20.0), - r.x+r.w - 4.0 * sw, r.y + 4.0*sh, 4.0 * sw, r.h - 10.0*sh, 0.0, 0.0, 1.0, h/16.0).bytes(width, height) + self.data.extend( + render::ui::UIElement::new( + &texture.relative(2.0 / 200.0, 17.0 / 20.0, 196.0 / 200.0, 3.0 / 20.0), + r.x + 4.0 * sw, + r.y + r.h - 6.0 * sh, + r.w - 8.0 * sw, + 6.0 * sh, + 0.0, + 0.0, + w / 196.0, + 1.0, + ) + .bytes(width, height), ); + let h = ((r.h / sh) / 2.0) - 5.0; + self.data.extend( + render::ui::UIElement::new( + &texture.relative(0.0 / 200.0, 2.0 / 20.0, 2.0 / 200.0, 15.0 / 20.0), + r.x, + r.y + 4.0 * sh, + 4.0 * sw, + r.h - 10.0 * sh, + 0.0, + 0.0, + 1.0, + h / 16.0, + ) + .bytes(width, height), + ); + self.data.extend( + render::ui::UIElement::new( + &texture.relative(198.0 / 200.0, 2.0 / 20.0, 2.0 / 200.0, 15.0 / 20.0), + r.x + r.w - 4.0 * sw, + r.y + 4.0 * sh, + 4.0 * sw, + r.h - 10.0 * sh, + 0.0, + 0.0, + 1.0, + h / 16.0, + ) + .bytes(width, height), + ); - self.data.extend(render::ui::UIElement::new( - &texture.relative(2.0/200.0, 2.0/20.0, 196.0/200.0, 15.0/20.0), - r.x+4.0*sw, r.y+4.0*sh, r.w - 8.0 * sw, r.h - 10.0 * sh, 0.0, 0.0, w/196.0, h/16.0).bytes(width, height) + self.data.extend( + render::ui::UIElement::new( + &texture.relative(2.0 / 200.0, 2.0 / 20.0, 196.0 / 200.0, 15.0 / 20.0), + r.x + 4.0 * sw, + r.y + 4.0 * sh, + r.w - 8.0 * sw, + r.h - 10.0 * sh, + 0.0, + 0.0, + w / 196.0, + h / 16.0, + ) + .bytes(width, height), ); self.super_draw(renderer, r, sw, sh, width, height, delta); self.last_disabled = self.disabled; @@ -1254,11 +1452,9 @@ impl UIElement for Button { } fn is_dirty(&self) -> bool { - self.last_disabled != self.disabled - || self.last_hovered != self.hovered + self.last_disabled != self.disabled || self.last_hovered != self.hovered } - fn post_init(s: Rc>) { s.borrow_mut().add_hover_func(move |this, hover, _| { this.hovered = hover; @@ -1311,9 +1507,17 @@ impl TextBoxBuilder { } impl UIElement for TextBox { - fn key_press(&mut self, game: &mut crate::Game, key: VirtualKeyCode, down: bool, ctrl_pressed: bool) { + fn key_press( + &mut self, + game: &mut crate::Game, + key: VirtualKeyCode, + down: bool, + ctrl_pressed: bool, + ) { match (key, down) { - (VirtualKeyCode::Back, _) => {self.input.pop();}, + (VirtualKeyCode::Back, _) => { + self.input.pop(); + } (VirtualKeyCode::Return, false) => { use std::mem; let len = self.submit_funcs.len(); @@ -1322,7 +1526,7 @@ impl UIElement for TextBox { (func)(self, game); } self.submit_funcs.append(&mut temp); - }, + } // TODO: wasm clipboard pasting, Clipboard API: https://www.w3.org/TR/clipboard-apis/ #[cfg(not(target_arch = "wasm32"))] (VirtualKeyCode::V, true) => { @@ -1330,11 +1534,11 @@ impl UIElement for TextBox { let mut clipboard: ClipboardContext = ClipboardProvider::new().unwrap(); match clipboard.get_contents() { Ok(text) => self.input.push_str(&text), - Err(_) => () + Err(_) => (), } } - }, - _ => {}, + } + _ => {} } } @@ -1342,7 +1546,16 @@ impl UIElement for TextBox { self.input.push(c); } - fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, sw: f64, sh: f64, width: f64, height: f64, delta: f64) -> &mut [u8] { + fn draw( + &mut self, + renderer: &mut render::Renderer, + r: &Region, + sw: f64, + sh: f64, + width: f64, + height: f64, + delta: f64, + ) -> &mut [u8] { if self.check_rebuild() { self.data.clear(); self.cursor_tick += delta; @@ -1381,17 +1594,21 @@ impl UIElement for TextBox { fn post_init(s: Rc>) { let mut textbox = s.borrow_mut(); - textbox.button = Some(ButtonBuilder::new() - .position(0.0, 0.0) - .size(textbox.width, textbox.height) - .disabled(true) - .attach(&mut *textbox)); - textbox.text = Some(TextBuilder::new() - .text("") - .position(5.0, 0.0) - .draw_index(1) - .alignment(VAttach::Middle, HAttach::Left) - .attach(&mut *textbox)); + textbox.button = Some( + ButtonBuilder::new() + .position(0.0, 0.0) + .size(textbox.width, textbox.height) + .disabled(true) + .attach(&mut *textbox), + ); + textbox.text = Some( + TextBuilder::new() + .text("") + .position(5.0, 0.0) + .draw_index(1) + .alignment(VAttach::Middle, HAttach::Left) + .attach(&mut *textbox), + ); } } diff --git a/src/world/biome.rs b/src/world/biome.rs index 9e1c3dfe..ea3e9991 100644 --- a/src/world/biome.rs +++ b/src/world/biome.rs @@ -1,4 +1,3 @@ - use image::Rgba; use lazy_static::lazy_static; @@ -14,7 +13,7 @@ impl Biome { Biome { id, temperature: t, - moisture: m*t, + moisture: m * t, } } @@ -23,21 +22,19 @@ impl Biome { } pub fn get_color_index(self) -> usize { - let t = (self.temperature as f64 / 100f64) .min(1.0).max(0.0); + let t = (self.temperature as f64 / 100f64).min(1.0).max(0.0); let m = (self.moisture as f64 / 100f64).min(1.0).max(0.0); - (((1.0 - t) * 255.0) as usize) | ((((1.0 - (m*t)) * 255.0) as usize) << 8) + (((1.0 - t) * 255.0) as usize) | ((((1.0 - (m * t)) * 255.0) as usize) << 8) } pub fn process_color(self, col: Rgba) -> Rgba { if self.id == ROOFED_FOREST.id || self.id == ROOFED_FOREST_MOUNTAINS.id { - Rgba ( - [ - ((col.0[0] as u32 + 0x28) / 2) as u8, - ((col.0[1] as u32 + 0x34) / 2) as u8, - ((col.0[2] as u32 + 0x0A) / 2) as u8, - 255 - ] - ) + Rgba([ + ((col.0[0] as u32 + 0x28) / 2) as u8, + ((col.0[1] as u32 + 0x34) / 2) as u8, + ((col.0[2] as u32 + 0x0A) / 2) as u8, + 255, + ]) } else { col } diff --git a/src/world/mod.rs b/src/world/mod.rs index df0a2a67..cdb4d23e 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -14,21 +14,21 @@ pub use steven_blocks as block; -use std::collections::HashMap; -use std::collections::VecDeque; -use std::hash::BuildHasherDefault; -use crate::types::{bit, nibble}; -use crate::shared::{Position, Direction}; -use crate::types::hash::FNVHash; -use crate::protocol; -use crate::render; -use collision; -use cgmath::prelude::*; use crate::chunk_builder; use crate::ecs; use crate::entity::block_entity; use crate::format; +use crate::protocol; +use crate::render; +use crate::shared::{Direction, Position}; +use crate::types::hash::FNVHash; +use crate::types::{bit, nibble}; +use cgmath::prelude::*; +use collision; use flate2::read::ZlibDecoder; +use std::collections::HashMap; +use std::collections::VecDeque; +use std::hash::BuildHasherDefault; use std::io::Read; pub mod biome; @@ -52,13 +52,19 @@ pub struct World { pub enum BlockEntityAction { Create(Position), Remove(Position), - UpdateSignText(Position, format::Component, format::Component, format::Component, format::Component), + UpdateSignText( + Position, + format::Component, + format::Component, + format::Component, + format::Component, + ), } #[derive(Clone, Copy, PartialEq, Eq)] enum LightType { Block, - Sky + Sky, } impl LightType { @@ -104,10 +110,12 @@ impl World { let chunk = self.chunks.entry(cpos).or_insert_with(|| Chunk::new(cpos)); if chunk.set_block(pos.x & 0xF, pos.y, pos.z & 0xF, b) { if chunk.block_entities.contains_key(&pos) { - self.block_entity_actions.push_back(BlockEntityAction::Remove(pos)); + self.block_entity_actions + .push_back(BlockEntityAction::Remove(pos)); } if block_entity::BlockEntityType::get_block_entity(b).is_some() { - self.block_entity_actions.push_back(BlockEntityAction::Create(pos)); + self.block_entity_actions + .push_back(BlockEntityAction::Create(pos)); } true } else { @@ -116,9 +124,9 @@ impl World { } pub fn update_block(&mut self, pos: Position) { - for yy in -1 .. 2 { - for zz in -1 .. 2 { - for xx in -1 .. 2 { + for yy in -1..2 { + for zz in -1..2 { + for xx in -1..2 { let bp = pos + (xx, yy, zz); let current = self.get_block(bp); let new = current.update_state(self, bp); @@ -134,9 +142,9 @@ impl World { } fn update_range(&mut self, x1: i32, y1: i32, z1: i32, x2: i32, y2: i32, z2: i32) { - for by in y1 .. y2 { - for bz in z1 .. z2 { - for bx in x1 .. x2 { + for by in y1..y2 { + for bz in z1..z2 { + for bx in x1..x2 { let bp = Position::new(bx, by, bz); let current = self.get_block(bp); let new = current.update_state(self, bp); @@ -156,7 +164,7 @@ impl World { pub fn get_block(&self, pos: Position) -> block::Block { match self.chunks.get(&CPos(pos.x >> 4, pos.z >> 4)) { Some(chunk) => chunk.get_block(pos.x & 0xF, pos.y, pos.z & 0xF), - None => block::Missing{}, + None => block::Missing {}, } } @@ -187,10 +195,7 @@ impl World { } fn update_light(&mut self, pos: Position, ty: LightType) { - self.light_updates.push_back(LightUpdate { - ty, - pos, - }); + self.light_updates.push_back(LightUpdate { ty, pos }); } pub fn add_block_entity_action(&mut self, action: BlockEntityAction) { @@ -198,14 +203,15 @@ impl World { } pub fn tick(&mut self, m: &mut ecs::Manager) { - use std::time::{Instant}; + use std::time::Instant; let start = Instant::now(); let mut updates_performed = 0; while !self.light_updates.is_empty() { updates_performed += 1; self.do_light_update(); if updates_performed & 0xFFF == 0 { - if start.elapsed().subsec_nanos() >= 5000000 { // 5 ms for light updates + if start.elapsed().subsec_nanos() >= 5000000 { + // 5 ms for light updates break; } } @@ -221,7 +227,7 @@ impl World { m.remove_entity(entity); } } - }, + } BlockEntityAction::Create(pos) => { if let Some(chunk) = self.chunks.get_mut(&CPos(pos.x >> 4, pos.z >> 4)) { // Remove existing entity @@ -229,22 +235,19 @@ impl World { m.remove_entity(entity); } let block = chunk.get_block(pos.x & 0xF, pos.y, pos.z & 0xF); - if let Some(entity_type) = block_entity::BlockEntityType::get_block_entity(block) { + if let Some(entity_type) = + block_entity::BlockEntityType::get_block_entity(block) + { let entity = entity_type.create_entity(m, pos); chunk.block_entities.insert(pos, entity); } } - }, + } BlockEntityAction::UpdateSignText(pos, line1, line2, line3, line4) => { if let Some(chunk) = self.chunks.get(&CPos(pos.x >> 4, pos.z >> 4)) { if let Some(entity) = chunk.block_entities.get(&pos) { if let Some(sign) = m.get_component_mut(*entity, sign_info) { - sign.lines = [ - line1, - line2, - line3, - line4, - ]; + sign.lines = [line1, line2, line3, line4]; sign.dirty = true; } } @@ -257,7 +260,10 @@ impl World { fn do_light_update(&mut self) { use std::cmp; if let Some(update) = self.light_updates.pop_front() { - if update.pos.y < 0 || update.pos.y > 255 || !self.is_chunk_loaded(update.pos.x >> 4, update.pos.z >> 4) { + if update.pos.y < 0 + || update.pos.y > 255 + || !self.is_chunk_loaded(update.pos.x >> 4, update.pos.z >> 4) + { return; } @@ -280,7 +286,8 @@ impl World { // Sky light doesn't decrease when going down at full brightness if update.ty == LightType::Sky && block.absorbed_light == 0 - && update.ty.get_light(self, update.pos.shift(Direction::Up)) == 15 { + && update.ty.get_light(self, update.pos.shift(Direction::Up)) == 15 + { best = 15; } @@ -291,9 +298,9 @@ impl World { // Use our new light value update.ty.set_light(self, update.pos, best); // Flag surrounding chunks as dirty - for yy in -1 .. 2 { - for zz in -1 .. 2 { - for xx in -1 .. 2 { + for yy in -1..2 { + for zz in -1..2 { + for xx in -1..2 { let bp = update.pos + (xx, yy, zz); self.set_dirty(bp.x >> 4, bp.y >> 4, bp.z >> 4); } @@ -313,12 +320,11 @@ impl World { if c.heightmap_dirty { dirty = true; c.heightmap_dirty = false; - for xx in 0 .. 16 { - for zz in 0 .. 16 { - data[ - (((c.position.0 << 4) as usize + xx) & 0x1FF) + - ((((c.position.1 << 4) as usize + zz) & 0x1FF) << 9) - ] = c.heightmap[(zz << 4) | xx]; + for xx in 0..16 { + for zz in 0..16 { + data[(((c.position.0 << 4) as usize + xx) & 0x1FF) + + ((((c.position.1 << 4) as usize + zz) & 0x1FF) << 9)] = + c.heightmap[(zz << 4) | xx]; } } } @@ -339,25 +345,37 @@ impl World { let start = ( ((renderer.camera.pos.x as i32) >> 4), ((renderer.camera.pos.y as i32) >> 4), - ((renderer.camera.pos.z as i32) >> 4) + ((renderer.camera.pos.z as i32) >> 4), ); let mut process_queue = VecDeque::with_capacity(self.chunks.len() * 16); process_queue.push_front((Direction::Invalid, start)); while let Some((from, pos)) = process_queue.pop_front() { - let (exists, cull) = if let Some((sec, rendered_on)) = self.get_render_section_mut(pos.0, pos.1, pos.2) { + let (exists, cull) = if let Some((sec, rendered_on)) = + self.get_render_section_mut(pos.0, pos.1, pos.2) + { if *rendered_on == renderer.frame_id { continue; } *rendered_on = renderer.frame_id; - let min = cgmath::Point3::new(pos.0 as f32 * 16.0, -pos.1 as f32 * 16.0, pos.2 as f32 * 16.0); - let bounds = collision::Aabb3::new(min, min + cgmath::Vector3::new(16.0, -16.0, 16.0)); - if renderer.frustum.contains(&bounds) == collision::Relation::Out && from != Direction::Invalid { + let min = cgmath::Point3::new( + pos.0 as f32 * 16.0, + -pos.1 as f32 * 16.0, + pos.2 as f32 * 16.0, + ); + let bounds = + collision::Aabb3::new(min, min + cgmath::Vector3::new(16.0, -16.0, 16.0)); + if renderer.frustum.contains(&bounds) == collision::Relation::Out + && from != Direction::Invalid + { continue; } - (sec.is_some(), sec.map_or(chunk_builder::CullInfo::all_vis(), |v| v.cull_info)) + ( + sec.is_some(), + sec.map_or(chunk_builder::CullInfo::all_vis(), |v| v.cull_info), + ) } else { continue; }; @@ -369,11 +387,14 @@ impl World { for dir in Direction::all() { let (ox, oy, oz) = dir.get_offset(); let opos = (pos.0 + ox, pos.1 + oy, pos.2 + oz); - if let Some((_, rendered_on)) = self.get_render_section_mut(opos.0, opos.1, opos.2) { + if let Some((_, rendered_on)) = self.get_render_section_mut(opos.0, opos.1, opos.2) + { if *rendered_on == renderer.frame_id { continue; } - if from == Direction::Invalid || (valid_dirs[dir.index()] && cull.is_visible(from, dir)) { + if from == Direction::Invalid + || (valid_dirs[dir.index()] && cull.is_visible(from, dir)) + { process_queue.push_back((dir.opposite(), opos)); } } @@ -382,11 +403,14 @@ impl World { } pub fn get_render_list(&self) -> Vec<((i32, i32, i32), &render::ChunkBuffer)> { - self.render_list.iter().map(|v| { - let chunk = self.chunks.get(&CPos(v.0, v.2)).unwrap(); - let sec = chunk.sections[v.1 as usize].as_ref().unwrap(); - (*v, &sec.render_buffer) - }).collect() + self.render_list + .iter() + .map(|v| { + let chunk = self.chunks.get(&CPos(v.0, v.2)).unwrap(); + let sec = chunk.sections[v.1 as usize].as_ref().unwrap(); + (*v, &sec.render_buffer) + }) + .collect() } pub fn get_section_mut(&mut self, x: i32, y: i32, z: i32) -> Option<&mut Section> { @@ -398,7 +422,12 @@ impl World { None } - fn get_render_section_mut(&mut self, x: i32, y: i32, z: i32) -> Option<(Option<&mut Section>, &mut u32)> { + fn get_render_section_mut( + &mut self, + x: i32, + y: i32, + z: i32, + ) -> Option<(Option<&mut Section>, &mut u32)> { if y < 0 || y > 15 { return None; } @@ -471,17 +500,21 @@ impl World { } pub fn capture_snapshot(&self, x: i32, y: i32, z: i32, w: i32, h: i32, d: i32) -> Snapshot { - use std::cmp::{min, max}; + use std::cmp::{max, min}; let mut snapshot = Snapshot { - blocks: storage::BlockStorage::new_default((w * h * d) as usize, block::Missing{}), + blocks: storage::BlockStorage::new_default((w * h * d) as usize, block::Missing {}), block_light: nibble::Array::new((w * h * d) as usize), sky_light: nibble::Array::new((w * h * d) as usize), biomes: vec![0; (w * d) as usize], - x, y, z, - w, _h: h, d, + x, + y, + z, + w, + _h: h, + d, }; - for i in 0 .. (w * h * d) as usize { + for i in 0..(w * h * d) as usize { snapshot.sky_light.set(i, 0xF); } @@ -492,48 +525,58 @@ impl World { let cy2 = (y + h + 15) >> 4; let cz2 = (z + d + 15) >> 4; - for cx in cx1 .. cx2 { - for cz in cz1 .. cz2 { + for cx in cx1..cx2 { + for cz in cz1..cz2 { let chunk = match self.chunks.get(&CPos(cx, cz)) { Some(val) => val, None => continue, }; - let x1 = min(16, max(0, x - (cx<<4))); - let x2 = min(16, max(0, x + w - (cx<<4))); - let z1 = min(16, max(0, z - (cz<<4))); - let z2 = min(16, max(0, z + d - (cz<<4))); + let x1 = min(16, max(0, x - (cx << 4))); + let x2 = min(16, max(0, x + w - (cx << 4))); + let z1 = min(16, max(0, z - (cz << 4))); + let z2 = min(16, max(0, z + d - (cz << 4))); - for cy in cy1 .. cy2 { + for cy in cy1..cy2 { if cy < 0 || cy > 15 { continue; } let section = &chunk.sections[cy as usize]; - let y1 = min(16, max(0, y - (cy<<4))); - let y2 = min(16, max(0, y + h - (cy<<4))); + let y1 = min(16, max(0, y - (cy << 4))); + let y2 = min(16, max(0, y + h - (cy << 4))); - for yy in y1 .. y2 { - for zz in z1 .. z2 { - for xx in x1 .. x2 { + for yy in y1..y2 { + for zz in z1..z2 { + for xx in x1..x2 { let ox = xx + (cx << 4); let oy = yy + (cy << 4); let oz = zz + (cz << 4); match section.as_ref() { Some(sec) => { snapshot.set_block(ox, oy, oz, sec.get_block(xx, yy, zz)); - snapshot.set_block_light(ox, oy, oz, sec.get_block_light(xx, yy, zz)); - snapshot.set_sky_light(ox, oy, oz, sec.get_sky_light(xx, yy, zz)); - }, + snapshot.set_block_light( + ox, + oy, + oz, + sec.get_block_light(xx, yy, zz), + ); + snapshot.set_sky_light( + ox, + oy, + oz, + sec.get_sky_light(xx, yy, zz), + ); + } None => { - snapshot.set_block(ox, oy, oz, block::Air{}); - }, + snapshot.set_block(ox, oy, oz, block::Air {}); + } } } } } } - for zz in z1 .. z2 { - for xx in x1 .. x2 { + for zz in z1..z2 { + for xx in x1..x2 { let ox = xx + (cx << 4); let oz = zz + (cz << 4); snapshot.set_biome(ox, oz, chunk.get_biome(xx, zz)); @@ -553,38 +596,62 @@ impl World { } } - pub fn load_chunks18(&mut self, new: bool, skylight: bool, chunk_metas: &[crate::protocol::packet::ChunkMeta], data: Vec) -> Result<(), protocol::Error> { - let mut data = std::io::Cursor::new(data); + pub fn load_chunks18( + &mut self, + new: bool, + skylight: bool, + chunk_metas: &[crate::protocol::packet::ChunkMeta], + data: Vec, + ) -> Result<(), protocol::Error> { + let mut data = std::io::Cursor::new(data); - for chunk_meta in chunk_metas { - let x = chunk_meta.x; - let z = chunk_meta.z; - let mask = chunk_meta.bitmask; + for chunk_meta in chunk_metas { + let x = chunk_meta.x; + let z = chunk_meta.z; + let mask = chunk_meta.bitmask; - self.load_chunk18(x, z, new, skylight, mask, &mut data)?; - } - Ok(()) + self.load_chunk18(x, z, new, skylight, mask, &mut data)?; + } + Ok(()) } fn dirty_chunks_by_bitmask(&mut self, x: i32, z: i32, mask: u16) { - for i in 0 .. 16 { + for i in 0..16 { if mask & (1 << i) == 0 { continue; } for pos in [ - (-1, 0, 0), (1, 0, 0), - (0, -1, 0), (0, 1, 0), - (0, 0, -1), (0, 0, 1)].iter() { + (-1, 0, 0), + (1, 0, 0), + (0, -1, 0), + (0, 1, 0), + (0, 0, -1), + (0, 0, 1), + ] + .iter() + { self.flag_section_dirty(x + pos.0, i as i32 + pos.1, z + pos.2); } self.update_range( - (x<<4) - 1, (i<<4) - 1, (z<<4) - 1, - (x<<4) + 17, (i<<4) + 17, (z<<4) + 17 + (x << 4) - 1, + (i << 4) - 1, + (z << 4) - 1, + (x << 4) + 17, + (i << 4) + 17, + (z << 4) + 17, ); } } - pub fn load_chunk18(&mut self, x: i32, z: i32, new: bool, _skylight: bool, mask: u16, data: &mut std::io::Cursor>) -> Result<(), protocol::Error> { + pub fn load_chunk18( + &mut self, + x: i32, + z: i32, + new: bool, + _skylight: bool, + mask: u16, + data: &mut std::io::Cursor>, + ) -> Result<(), protocol::Error> { use byteorder::ReadBytesExt; let cpos = CPos(x, z); @@ -599,11 +666,9 @@ impl World { self.chunks.get_mut(&cpos).unwrap() }; - for i in 0 .. 16 { + for i in 0..16 { if chunk.sections[i].is_none() { - let mut fill_sky = chunk.sections.iter() - .skip(i) - .all(|v| v.is_none()); + let mut fill_sky = chunk.sections.iter().skip(i).all(|v| v.is_none()); fill_sky &= (mask & !((1 << i) | ((1 << i) - 1))) == 0; if !fill_sky || mask & (1 << i) != 0 { chunk.sections[i] = Some(Section::new(i as u8, fill_sky)); @@ -615,9 +680,16 @@ impl World { let section = chunk.sections[i as usize].as_mut().unwrap(); section.dirty = true; - for bi in 0 .. 4096 { + for bi in 0..4096 { let id = data.read_u16::()?; - section.blocks.set(bi, block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.modded_block_ids)); + section.blocks.set( + bi, + block::Block::by_vanilla_id( + id as usize, + self.protocol_version, + &self.modded_block_ids, + ), + ); // Spawn block entities let b = section.blocks.get(bi); @@ -625,17 +697,23 @@ impl World { let pos = Position::new( (bi & 0xF) as i32, (bi >> 8) as i32, - ((bi >> 4) & 0xF) as i32 - ) + (chunk.position.0 << 4, (i << 4) as i32, chunk.position.1 << 4); + ((bi >> 4) & 0xF) as i32, + ) + ( + chunk.position.0 << 4, + (i << 4) as i32, + chunk.position.1 << 4, + ); if chunk.block_entities.contains_key(&pos) { - self.block_entity_actions.push_back(BlockEntityAction::Remove(pos)) + self.block_entity_actions + .push_back(BlockEntityAction::Remove(pos)) } - self.block_entity_actions.push_back(BlockEntityAction::Create(pos)) + self.block_entity_actions + .push_back(BlockEntityAction::Create(pos)) } } } - for i in 0 .. 16 { + for i in 0..16 { if mask & (1 << i) == 0 { continue; } @@ -644,7 +722,7 @@ impl World { data.read_exact(&mut section.block_light.data)?; } - for i in 0 .. 16 { + for i in 0..16 { if mask & (1 << i) == 0 { continue; } @@ -664,7 +742,13 @@ impl World { Ok(()) } - pub fn load_chunks17(&mut self, chunk_column_count: u16, data_length: i32, skylight: bool, data: &[u8]) -> Result<(), protocol::Error> { + pub fn load_chunks17( + &mut self, + chunk_column_count: u16, + data_length: i32, + skylight: bool, + data: &[u8], + ) -> Result<(), protocol::Error> { let compressed_chunk_data = &data[0..data_length as usize]; let metadata = &data[data_length as usize..]; @@ -692,16 +776,41 @@ impl World { Ok(()) } - pub fn load_chunk17(&mut self, x: i32, z: i32, new: bool, mask: u16, mask_add: u16, compressed_data: Vec) -> Result<(), protocol::Error> { - let mut zlib = ZlibDecoder::new(std::io::Cursor::new(compressed_data.to_vec())); - let mut data = Vec::new(); - zlib.read_to_end(&mut data)?; - - let skylight = true; - self.load_uncompressed_chunk17(x, z, new, skylight, mask, mask_add, &mut std::io::Cursor::new(data)) - } - - fn load_uncompressed_chunk17(&mut self, x: i32, z: i32, new: bool, skylight: bool, mask: u16, mask_add: u16, data: &mut std::io::Cursor>) -> Result<(), protocol::Error> { + pub fn load_chunk17( + &mut self, + x: i32, + z: i32, + new: bool, + mask: u16, + mask_add: u16, + compressed_data: Vec, + ) -> Result<(), protocol::Error> { + let mut zlib = ZlibDecoder::new(std::io::Cursor::new(compressed_data.to_vec())); + let mut data = Vec::new(); + zlib.read_to_end(&mut data)?; + + let skylight = true; + self.load_uncompressed_chunk17( + x, + z, + new, + skylight, + mask, + mask_add, + &mut std::io::Cursor::new(data), + ) + } + + fn load_uncompressed_chunk17( + &mut self, + x: i32, + z: i32, + new: bool, + skylight: bool, + mask: u16, + mask_add: u16, + data: &mut std::io::Cursor>, + ) -> Result<(), protocol::Error> { let cpos = CPos(x, z); { let chunk = if new { @@ -716,11 +825,9 @@ impl World { // Block type array - whole byte per block let mut block_types = [[0u8; 4096]; 16]; - for i in 0 .. 16 { + for i in 0..16 { if chunk.sections[i].is_none() { - let mut fill_sky = chunk.sections.iter() - .skip(i) - .all(|v| v.is_none()); + let mut fill_sky = chunk.sections.iter().skip(i).all(|v| v.is_none()); fill_sky &= (mask & !((1 << i) | ((1 << i) - 1))) == 0; if !fill_sky || mask & (1 << i) != 0 { chunk.sections[i] = Some(Section::new(i as u8, fill_sky)); @@ -738,13 +845,25 @@ impl World { // Block metadata array - half byte per block let mut block_meta: [nibble::Array; 16] = [ // TODO: cleanup this initialization - nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), - nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), - nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), - nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), ]; - for i in 0 .. 16 { + for i in 0..16 { if mask & (1 << i) == 0 { continue; } @@ -753,7 +872,7 @@ impl World { } // Block light array - half byte per block - for i in 0 .. 16 { + for i in 0..16 { if mask & (1 << i) == 0 { continue; } @@ -764,7 +883,7 @@ impl World { // Sky light array - half byte per block - only if 'skylight' is true if skylight { - for i in 0 .. 16 { + for i in 0..16 { if mask & (1 << i) == 0 { continue; } @@ -777,13 +896,25 @@ impl World { // Add array - half byte per block - uses secondary bitmask let mut block_add: [nibble::Array; 16] = [ // TODO: cleanup this initialization - nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), - nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), - nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), - nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), + nibble::Array::new(16 * 16 * 16), ]; - for i in 0 .. 16 { + for i in 0..16 { if mask_add & (1 << i) == 0 { continue; } @@ -791,16 +922,25 @@ impl World { } // Now that we have the block types, metadata, and add, combine to initialize the blocks - for i in 0 .. 16 { + for i in 0..16 { if mask & (1 << i) == 0 { continue; } let section = chunk.sections[i as usize].as_mut().unwrap(); - for bi in 0 .. 4096 { - let id = ((block_add[i].get(bi) as u16) << 12) | ((block_types[i][bi] as u16) << 4) | (block_meta[i].get(bi) as u16); - section.blocks.set(bi, block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.modded_block_ids)); + for bi in 0..4096 { + let id = ((block_add[i].get(bi) as u16) << 12) + | ((block_types[i][bi] as u16) << 4) + | (block_meta[i].get(bi) as u16); + section.blocks.set( + bi, + block::Block::by_vanilla_id( + id as usize, + self.protocol_version, + &self.modded_block_ids, + ), + ); // Spawn block entities let b = section.blocks.get(bi); @@ -808,12 +948,18 @@ impl World { let pos = Position::new( (bi & 0xF) as i32, (bi >> 8) as i32, - ((bi >> 4) & 0xF) as i32 - ) + (chunk.position.0 << 4, (i << 4) as i32, chunk.position.1 << 4); + ((bi >> 4) & 0xF) as i32, + ) + ( + chunk.position.0 << 4, + (i << 4) as i32, + chunk.position.1 << 4, + ); if chunk.block_entities.contains_key(&pos) { - self.block_entity_actions.push_back(BlockEntityAction::Remove(pos)) + self.block_entity_actions + .push_back(BlockEntityAction::Remove(pos)) } - self.block_entity_actions.push_back(BlockEntityAction::Create(pos)) + self.block_entity_actions + .push_back(BlockEntityAction::Create(pos)) } } } @@ -829,18 +975,40 @@ impl World { Ok(()) } - pub fn load_chunk19(&mut self, x: i32, z: i32, new: bool, mask: u16, data: Vec) -> Result<(), protocol::Error> { + pub fn load_chunk19( + &mut self, + x: i32, + z: i32, + new: bool, + mask: u16, + data: Vec, + ) -> Result<(), protocol::Error> { self.load_chunk19_or_115(true, x, z, new, mask, data) } - pub fn load_chunk115(&mut self, x: i32, z: i32, new: bool, mask: u16, data: Vec) -> Result<(), protocol::Error> { + pub fn load_chunk115( + &mut self, + x: i32, + z: i32, + new: bool, + mask: u16, + data: Vec, + ) -> Result<(), protocol::Error> { self.load_chunk19_or_115(false, x, z, new, mask, data) } - fn load_chunk19_or_115(&mut self, read_biomes: bool, x: i32, z: i32, new: bool, mask: u16, data: Vec) -> Result<(), protocol::Error> { - use std::io::Cursor; + fn load_chunk19_or_115( + &mut self, + read_biomes: bool, + x: i32, + z: i32, + new: bool, + mask: u16, + data: Vec, + ) -> Result<(), protocol::Error> { + use crate::protocol::{LenPrefixed, Serializable, VarInt}; use byteorder::ReadBytesExt; - use crate::protocol::{VarInt, Serializable, LenPrefixed}; + use std::io::Cursor; let mut data = Cursor::new(data); @@ -856,11 +1024,9 @@ impl World { self.chunks.get_mut(&cpos).unwrap() }; - for i in 0 .. 16 { + for i in 0..16 { if chunk.sections[i].is_none() { - let mut fill_sky = chunk.sections.iter() - .skip(i) - .all(|v| v.is_none()); + let mut fill_sky = chunk.sections.iter().skip(i).all(|v| v.is_none()); fill_sky &= (mask & !((1 << i) | ((1 << i) - 1))) == 0; if !fill_sky || mask & (1 << i) != 0 { chunk.sections[i] = Some(Section::new(i as u8, fill_sky)); @@ -871,21 +1037,26 @@ impl World { } let section = chunk.sections[i as usize].as_mut().unwrap(); section.dirty = true; - + if self.protocol_version >= 451 { let _block_count = data.read_u16::()?; // TODO: use block_count } let mut bit_size = data.read_u8()?; - let mut mappings: HashMap> = HashMap::with_hasher(BuildHasherDefault::default()); + let mut mappings: HashMap> = + HashMap::with_hasher(BuildHasherDefault::default()); if bit_size == 0 { bit_size = 13; } else { let count = VarInt::read_from(&mut data)?.0; - for i in 0 .. count { + for i in 0..count { let id = VarInt::read_from(&mut data)?.0; - let bl = block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.modded_block_ids); + let bl = block::Block::by_vanilla_id( + id as usize, + self.protocol_version, + &self.modded_block_ids, + ); mappings.insert(i as usize, bl); } } @@ -893,21 +1064,37 @@ impl World { let bits = LenPrefixed::::read_from(&mut data)?.data; let m = bit::Map::from_raw(bits, bit_size as usize); - for bi in 0 .. 4096 { + for bi in 0..4096 { let id = m.get(bi); - section.blocks.set(bi, mappings.get(&id).cloned().unwrap_or(block::Block::by_vanilla_id(id, self.protocol_version, &self.modded_block_ids))); + section.blocks.set( + bi, + mappings + .get(&id) + .cloned() + .unwrap_or(block::Block::by_vanilla_id( + id, + self.protocol_version, + &self.modded_block_ids, + )), + ); // Spawn block entities let b = section.blocks.get(bi); if block_entity::BlockEntityType::get_block_entity(b).is_some() { let pos = Position::new( (bi & 0xF) as i32, (bi >> 8) as i32, - ((bi >> 4) & 0xF) as i32 - ) + (chunk.position.0 << 4, (i << 4) as i32, chunk.position.1 << 4); + ((bi >> 4) & 0xF) as i32, + ) + ( + chunk.position.0 << 4, + (i << 4) as i32, + chunk.position.1 << 4, + ); if chunk.block_entities.contains_key(&pos) { - self.block_entity_actions.push_back(BlockEntityAction::Remove(pos)) + self.block_entity_actions + .push_back(BlockEntityAction::Remove(pos)) } - self.block_entity_actions.push_back(BlockEntityAction::Create(pos)) + self.block_entity_actions + .push_back(BlockEntityAction::Create(pos)) } } @@ -964,7 +1151,6 @@ pub struct Snapshot { } impl Snapshot { - pub fn make_relative(&mut self, x: i32, y: i32, z: i32) { self.x = x; self.y = y; @@ -1033,10 +1219,8 @@ impl Chunk { Chunk { position: pos, sections: [ - None,None,None,None, - None,None,None,None, - None,None,None,None, - None,None,None,None, + None, None, None, None, None, None, None, None, None, None, None, None, None, None, + None, None, ], sections_rendered_on: [0; 16], biomes: [0; 16 * 16], @@ -1047,13 +1231,13 @@ impl Chunk { } fn calculate_heightmap(&mut self) { - for x in 0 .. 16 { - for z in 0 .. 16 { - let idx = ((z<<4)|x) as usize; - for yy in 0 .. 256 { + for x in 0..16 { + for z in 0..16 { + let idx = ((z << 4) | x) as usize; + for yy in 0..256 { let sy = 255 - yy; - if let block::Air{..} = self.get_block(x, sy, z) { - continue + if let block::Air { .. } = self.get_block(x, sy, z) { + continue; } self.heightmap[idx] = sy as u8; break; @@ -1073,9 +1257,7 @@ impl Chunk { if let block::Air {} = b { return false; } - let fill_sky = self.sections.iter() - .skip(s_idx) - .all(|v| v.is_none()); + let fill_sky = self.sections.iter().skip(s_idx).all(|v| v.is_none()); self.sections[s_idx] = Some(Section::new(s_idx as u8, fill_sky)); } { @@ -1084,16 +1266,16 @@ impl Chunk { return false; } } - let idx = ((z<<4)|x) as usize; + let idx = ((z << 4) | x) as usize; if self.heightmap[idx] < y as u8 { self.heightmap[idx] = y as u8; self.heightmap_dirty = true; } else if self.heightmap[idx] == y as u8 { // Find a new lowest - for yy in 0 .. y { + for yy in 0..y { let sy = y - yy - 1; - if let block::Air{..} = self.get_block(x, sy, z) { - continue + if let block::Air { .. } = self.get_block(x, sy, z) { + continue; } self.heightmap[idx] = sy as u8; break; @@ -1106,11 +1288,11 @@ impl Chunk { fn get_block(&self, x: i32, y: i32, z: i32) -> block::Block { let s_idx = y >> 4; if s_idx < 0 || s_idx > 15 { - return block::Missing{}; + return block::Missing {}; } match self.sections[s_idx as usize].as_ref() { Some(sec) => sec.get_block(x, y & 0xF, z), - None => block::Air{}, + None => block::Air {}, } } @@ -1135,9 +1317,7 @@ impl Chunk { if light == 0 { return; } - let fill_sky = self.sections.iter() - .skip(s_idx) - .all(|v| v.is_none()); + let fill_sky = self.sections.iter().skip(s_idx).all(|v| v.is_none()); self.sections[s_idx] = Some(Section::new(s_idx as u8, fill_sky)); } if let Some(sec) = self.sections[s_idx].as_mut() { @@ -1166,9 +1346,7 @@ impl Chunk { if light == 15 { return; } - let fill_sky = self.sections.iter() - .skip(s_idx) - .all(|v| v.is_none()); + let fill_sky = self.sections.iter().skip(s_idx).all(|v| v.is_none()); self.sections[s_idx] = Some(Section::new(s_idx as u8, fill_sky)); } if let Some(sec) = self.sections[s_idx as usize].as_mut() { @@ -1177,7 +1355,7 @@ impl Chunk { } fn get_biome(&self, x: i32, z: i32) -> biome::Biome { - biome::Biome::by_id(self.biomes[((z<<4)|x) as usize] as usize) + biome::Biome::by_id(self.biomes[((z << 4) | x) as usize] as usize) } } @@ -1212,7 +1390,7 @@ impl Section { building: false, }; if fill_sky { - for i in 0 .. 16*16*16 { + for i in 0..16 * 16 * 16 { section.sky_light.set(i, 0xF); } } diff --git a/src/world/storage.rs b/src/world/storage.rs index e9cc244e..312edff7 100644 --- a/src/world/storage.rs +++ b/src/world/storage.rs @@ -1,4 +1,3 @@ - use crate::types::bit; use crate::types::hash::FNVHash; use crate::world::block; @@ -14,15 +13,13 @@ pub struct BlockStorage { impl BlockStorage { pub fn new(size: usize) -> BlockStorage { - Self::new_default(size, block::Air{}) + Self::new_default(size, block::Air {}) } pub fn new_default(size: usize, def: block::Block) -> BlockStorage { let mut storage = BlockStorage { blocks: bit::Map::new(size, 4), - block_map: vec![ - (def, size as u32) - ], + block_map: vec![(def, size as u32)], rev_block_map: HashMap::with_hasher(BuildHasherDefault::default()), }; storage.rev_block_map.insert(def, 0); @@ -45,7 +42,8 @@ impl BlockStorage { let idx = *self.rev_block_map.get(&old).unwrap(); let info = &mut self.block_map[idx]; info.1 -= 1; - if info.1 == 0 { // None left of this type + if info.1 == 0 { + // None left of this type self.rev_block_map.remove(&old); } } From ed1b41025bfc9e1f4f8fc23ac508b9202705d324 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 21 Jun 2020 13:15:38 -0700 Subject: [PATCH 110/137] Revert to master --- src/render/clouds.rs | 6 +++--- src/render/shaders.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/render/clouds.rs b/src/render/clouds.rs index a2fd8293..c3d102fa 100644 --- a/src/render/clouds.rs +++ b/src/render/clouds.rs @@ -46,7 +46,7 @@ impl Clouds { v.set_source(&vertex); v.compile(); - if !v.get_shader_compile_status() { + if v.get_parameter(gl::COMPILE_STATUS) == 0 { error!("Src: {}", vertex); panic!("Shader error: {}", v.get_info_log()); } else { @@ -61,7 +61,7 @@ impl Clouds { g.set_source(&geo); g.compile(); - if !g.get_shader_compile_status() { + if g.get_parameter(gl::COMPILE_STATUS) == 0 { error!("Src: {}", geo); panic!("Shader error: {}", g.get_info_log()); } else { @@ -76,7 +76,7 @@ impl Clouds { f.set_source(&fragment); f.compile(); - if !f.get_shader_compile_status() { + if f.get_parameter(gl::COMPILE_STATUS) == 0 { error!("Src: {}", fragment); panic!("Shader error: {}", f.get_info_log()); } else { diff --git a/src/render/shaders.rs b/src/render/shaders.rs index c67a148a..bdd2f7c5 100644 --- a/src/render/shaders.rs +++ b/src/render/shaders.rs @@ -77,7 +77,7 @@ macro_rules! init_shader { } ) => ( #[allow(dead_code)] - pub struct $name { // TODO: remove pub + struct $name { program: gl::Program, $( $field: gl::Attribute, @@ -131,7 +131,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program { v.set_source(vertex); v.compile(); - if !v.get_shader_compile_status() { + if v.get_parameter(gl::COMPILE_STATUS) == 0 { error!("Src: {}", vertex); panic!("Shader error: {}", v.get_info_log()); } else { @@ -146,7 +146,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program { f.set_source(fragment); f.compile(); - if !f.get_shader_compile_status() { + if f.get_parameter(gl::COMPILE_STATUS) == 0 { error!("Src: {}", fragment); panic!("Shader error: {}", f.get_info_log()); } else { From 5097ebf8c73e5a522044095696919e7d0fe39f99 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 21 Jun 2020 13:16:14 -0700 Subject: [PATCH 111/137] Merge master after cargo fmt --- Cargo.lock | 33 ++- Cargo.toml | 7 +- src/gl/mod.rs | 479 +++++++++++++++++++++--------------------- src/main.rs | 5 + src/render/clouds.rs | 6 +- src/render/mod.rs | 40 ++-- src/render/shaders.rs | 6 +- 7 files changed, 284 insertions(+), 292 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0353584b..7b4a0cc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -661,13 +661,15 @@ dependencies = [ ] [[package]] -name = "gl_generator" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +name = "glow" +version = "0.4.0" +source = "git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94#666a7529d0f48a05b32deb919668cd172b0adc94" dependencies = [ - "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "xml-rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", + "gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", + "slotmap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1905,6 +1907,11 @@ name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "slotmap" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "smallvec" version = "0.6.13" @@ -2021,15 +2028,6 @@ dependencies = [ "steven_shared 0.0.1", ] -[[package]] -name = "steven_gl" -version = "0.0.1" -dependencies = [ - "gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", - "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "steven_protocol" version = "0.0.1" @@ -2068,6 +2066,7 @@ dependencies = [ "clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "collision 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "glow 0.4.0 (git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94)", "glutin 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2082,7 +2081,6 @@ dependencies = [ "std_or_web 0.0.1", "stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "steven_blocks 0.0.1", - "steven_gl 0.0.1", "steven_protocol 0.0.1", "steven_resources 0.1.0", "steven_shared 0.0.1", @@ -2685,7 +2683,7 @@ dependencies = [ "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" "checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" "checksum gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a" -"checksum gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" +"checksum glow 0.4.0 (git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94)" = "" "checksum glutin 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c40ccddfa5fb8aaad6a152bfa6b17f157d6635928a832211534f87c9877e1" "checksum glutin_egl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "772edef3b28b8ad41e4ea202748e65eefe8e5ffd1f4535f1219793dbb20b3d4c" "checksum glutin_emscripten_sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80de4146df76e8a6c32b03007bc764ff3249dcaeb4f675d68a06caf1bac363f1" @@ -2822,6 +2820,7 @@ dependencies = [ "checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" "checksum simple_asn1 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "57f6bbbcefb91c0dac9b27c91ba13bd2aa29a815fe980f5b1e07d523fbf7b350" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +"checksum slotmap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "759fd553261805f128e2900bf69ab3d034260bc338caf7f0ee54dbf035c85acd" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" "checksum smithay-client-toolkit 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "421c8dc7acf5cb205b88160f8b4cc2c5cfabe210e43b2f80f009f4c1ef910f1d" diff --git a/Cargo.toml b/Cargo.toml index b650cf96..b33a5e02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,13 +15,14 @@ path = "src/main.rs" # Steven runs horrendously slow with no optimizations, and often freezes. # However, building with full -O3 optimizations takes too long for a debug build. # Use an -O1 optimization level strikes a good compromise between build and program performance. -opt-level = 1 +#opt-level = 1 [dependencies] cfg-if = "0.1.9" wasm-bindgen = "0.2.44" sha-1 = "0.8.2" glutin = "0.22.0" +glow = { git = "https://github.com/grovesNL/glow", rev = "666a7529d0f48a05b32deb919668cd172b0adc94" } byteorder = "1.3.4" serde = "1.0.104" serde_json = "1.0.55" @@ -47,10 +48,6 @@ reqwest = { version = "0.10.6", features = [ "blocking" ]} stdweb = "0.4.20" winit = { version = "0.20.0", features = [ "stdweb" ]} -[dependencies.steven_gl] -path = "./gl" -version = "0" - [dependencies.steven_resources] path = "./resources" version = "0" diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 52e6b8a2..3714f3b6 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -12,18 +12,30 @@ // See the License for the specific language governing permissions and // limitations under the License. -extern crate steven_gl as gl; - +use glow as gl; +use glow::HasContext; use log::{error, info}; -use std::ffi; use std::mem; use std::ops::BitOr; use std::ops::{Deref, DerefMut}; -use std::ptr; + +static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; /// Inits the gl library. This should be called once a context is ready. pub fn init(vid: &glutin::WindowedContext) { - gl::load_with(|s| vid.get_proc_address(s) as *const _); + unsafe { + CONTEXT = &mut (gl::Context::from_loader_function(|s| { + println!("Loaded {} = {:?}", s, vid.get_proc_address(s)); + vid.get_proc_address(s) as *const _ + })) as *mut glow::Context; + } +} + +fn glow_context() -> &'static glow::Context { + unsafe { + println!("glow_context = {:?}", CONTEXT); + CONTEXT.as_ref().unwrap() + } } /// Dsed to specify how the vertices will be handled @@ -42,32 +54,20 @@ pub const POINTS: DrawType = gl::POINTS; pub fn draw_arrays(ty: DrawType, offset: usize, count: usize) { unsafe { - gl::DrawArrays(ty, offset as i32, count as i32); + //glow_context().draw_arrays(ty, offset as i32, count as i32); } } pub fn draw_elements(ty: DrawType, count: i32, dty: Type, offset: usize) { unsafe { - gl::DrawElements(ty, count, dty, offset as *const gl::types::GLvoid); + //glow_context().draw_elements(ty, count, dty, offset as i32); } } -pub fn multi_draw_elements(ty: DrawType, count: &[i32], dty: Type, offsets: &[usize]) { - unsafe { - gl::MultiDrawElements( - ty, - count.as_ptr(), - dty, - offsets.as_ptr() as *const _, - count.len() as i32, - ); - } -} - -/// Sets the size of the viewport of this context. +// Sets the size of the viewport of this context. pub fn viewport(x: i32, y: i32, w: i32, h: i32) { unsafe { - gl::Viewport(x, y, w, h); + //glow_context().viewport(x, y, w, h); } } @@ -75,7 +75,7 @@ pub fn viewport(x: i32, y: i32, w: i32, h: i32) { /// when Clear is called with the color flag. pub fn clear_color(r: f32, g: f32, b: f32, a: f32) { unsafe { - gl::ClearColor(r, g, b, a); + //glow_context().clear_color(r, g, b, a); } } @@ -109,12 +109,14 @@ impl BitOr for ClearFlags { /// Clears the buffers specified by the passed flags. pub fn clear(flags: ClearFlags) { - unsafe { gl::Clear(flags.internal()) } + unsafe { + //glow_context().clear(flags.internal()) + } } pub fn depth_mask(f: bool) { unsafe { - gl::DepthMask(f as u8); + //glow_context().depth_mask(f); } } @@ -130,7 +132,7 @@ pub const EQUAL: Func = gl::EQUAL; pub fn depth_func(f: Func) { unsafe { - gl::DepthFunc(f); + //glow_context().depth_func(f); } } @@ -146,14 +148,14 @@ pub const MULTISAMPLE: Flag = gl::MULTISAMPLE; /// Enables the passed flag. pub fn enable(f: Flag) { unsafe { - gl::Enable(f); + //glow_context().enable(f); } } /// Disables the passed flag. pub fn disable(f: Flag) { unsafe { - gl::Disable(f); + //glow_context().disable(f); } } @@ -161,7 +163,7 @@ pub fn disable(f: Flag) { /// currently active one. pub fn active_texture(id: u32) { unsafe { - gl::ActiveTexture(gl::TEXTURE0 + id); + //glow_context().active_texture(gl::TEXTURE0 + id); } } @@ -175,7 +177,7 @@ pub const ZERO_FACTOR: Factor = gl::ZERO; /// Sets the factors to be used when blending. pub fn blend_func(s_factor: Factor, d_factor: Factor) { unsafe { - gl::BlendFunc(s_factor, d_factor); + //glow_context().blend_func(s_factor, d_factor); } } @@ -186,7 +188,7 @@ pub fn blend_func_separate( d_factor_a: Factor, ) { unsafe { - gl::BlendFuncSeparate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); + //glow_context().blend_func_separate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); } } @@ -198,7 +200,7 @@ pub const FRONT: Face = gl::FRONT; /// Sets the face to be culled by the gpu. pub fn cull_face(face: Face) { unsafe { - gl::CullFace(face); + //glow_context().cull_face(face); } } @@ -211,7 +213,9 @@ pub const COUNTER_CLOCK_WISE: FaceDirection = gl::CCW; /// Sets the direction of vertices used to specify the /// front face (e.g. for culling). pub fn front_face(dir: FaceDirection) { - unsafe { gl::FrontFace(dir) } + unsafe { + //glow_context().front_face(dir) + } } /// `Type` is a type of data used by various operations. @@ -269,17 +273,19 @@ pub struct Texture(u32); impl Texture { // Allocates a new texture. pub fn new() -> Texture { - let mut t = Texture(0); - unsafe { - gl::GenTextures(1, &mut t.0); - } - t + println!("create_texture"); + Texture(unsafe { + glow_context() + .create_texture() + .expect("create texture failed") + }) } /// Binds the texture to the passed target. pub fn bind(&self, target: TextureTarget) { + println!("bind_texture"); unsafe { - gl::BindTexture(target, self.0); + glow_context().bind_texture(target, Some(self.0)); } } @@ -292,13 +298,13 @@ impl Texture { pixels: &mut [u8], ) { unsafe { - gl::GetTexImage( - target, - level, - format, - ty, - pixels.as_mut_ptr() as *mut gl::types::GLvoid, - ); + /* + glow_context().get_tex_image_u8_slice(target, + level, + format, + ty, + Some(pixels)); + */ } } @@ -313,21 +319,18 @@ impl Texture { pix: Option<&[u8]>, ) { unsafe { - let ptr = match pix { - Some(val) => val.as_ptr() as *const gl::types::GLvoid, - None => ptr::null(), - }; - gl::TexImage2D( - target, - level, - format as i32, - width as i32, - height as i32, - 0, - format, - ty, - ptr, + /* + glow_context().tex_image_2d(target, + level, + format as i32, + width as i32, + height as i32, + 0, + format, + ty, + pix ); + */ } } @@ -344,17 +347,18 @@ impl Texture { pix: &[u8], ) { unsafe { - gl::TexSubImage2D( - target, - level, - x as i32, - y as i32, - width as i32, - height as i32, - format, - ty, - pix.as_ptr() as *const _, + /* + glow_context().tex_sub_image_2d_u8_slice(target, + level, + x as i32, + y as i32, + width as i32, + height as i32, + format, + ty, + Some(pix) ); + */ } } @@ -370,21 +374,18 @@ impl Texture { pix: Option<&[u8]>, ) { unsafe { - let ptr = match pix { - Some(val) => val.as_ptr() as *const gl::types::GLvoid, - None => ptr::null(), - }; - gl::TexImage2D( - target, - level, - internal_format as i32, - width as i32, - height as i32, - 0, - format, - ty, - ptr, + /* + glow_context().tex_image_2d(target, + level, + internal_format as i32, + width as i32, + height as i32, + 0, + format, + ty, + pix ); + */ } } @@ -398,26 +399,27 @@ impl Texture { fixed: bool, ) { unsafe { - let result: &mut [i32] = &mut [0; 1]; - gl::GetIntegerv(gl::MAX_SAMPLES, &mut result[0]); - let use_samples = if samples > result[0] { - info!( - "glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", - samples, result[0] - ); - result[0] - } else { - samples - }; - - gl::TexImage2DMultisample( - target, - use_samples, - format, - width as i32, - height as i32, - fixed as u8, + /* + let result: i32 = glow_context().get_parameter_i32(gl::MAX_SAMPLES); + let use_samples = + if samples > result { + info!("glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", samples, result); + result + } else { + samples + }; + */ + // TODO: switch to glRenderbufferStorageMultisample? + // from glTexImage2DMultisample which isn't in WebGL + /* + glow_context().tex_image_2d_multisample(target, + use_samples, + format, + width as i32, + height as i32, + fixed as u8 ); + */ } } @@ -433,18 +435,18 @@ impl Texture { pix: &[u8], ) { unsafe { - gl::TexImage3D( - target, - level, - format as i32, - width as i32, - height as i32, - depth as i32, - 0, - format, - ty, - pix.as_ptr() as *const gl::types::GLvoid, - ); + /* + glow_context().tex_image_3d(target, + level, + format as i32, + width as i32, + height as i32, + depth as i32, + 0, + format, + ty, + Some(pix)); + */ } } @@ -463,19 +465,19 @@ impl Texture { pix: &[u8], ) { unsafe { - gl::TexSubImage3D( - target, - level, - x as i32, - y as i32, - z as i32, - width as i32, - height as i32, - depth as i32, - format, - ty, - pix.as_ptr() as *const gl::types::GLvoid, - ); + /* + glow_context().tex_sub_image_3d_u8_slice(target, + level, + x as i32, + y as i32, + z as i32, + width as i32, + height as i32, + depth as i32, + format, + ty, + Some(pix)); + */ } } @@ -485,16 +487,19 @@ impl Texture { param: TextureParameter, value: TextureValue, ) { + /* TODO unsafe { - gl::TexParameteri(target, param, value); + glow_context().tex_parameter_i32(target, param, value); } + */ } } impl Drop for Texture { fn drop(&mut self) { unsafe { - gl::DeleteTextures(1, &self.0); + println!("delete_texture"); + glow_context().delete_texture(self.0); } } } @@ -514,54 +519,60 @@ pub struct Program(u32); impl Program { pub fn new() -> Program { - Program(unsafe { gl::CreateProgram() }) + Program(0) //unsafe { glow_context().create_program().expect("program creation failed") }) } pub fn attach_shader(&self, shader: Shader) { unsafe { - gl::AttachShader(self.0, shader.0); + //glow_context().attach_shader(self.0, shader.0); } } pub fn link(&self) { unsafe { - gl::LinkProgram(self.0); + //glow_context().link_program(self.0); } } pub fn use_program(&self) { unsafe { - gl::UseProgram(self.0); + //glow_context().use_program(Some(self.0)); } } pub fn uniform_location(&self, name: &str) -> Option { - let u = - unsafe { gl::GetUniformLocation(self.0, ffi::CString::new(name).unwrap().as_ptr()) }; - if u != -1 { + /* + let u = unsafe { + glow_context().get_uniform_location(self.0, name) + }; + if let Some(u) = u { Some(Uniform(u)) } else { None } + */ + Some(Uniform(0)) } pub fn attribute_location(&self, name: &str) -> Option { + /* let a = unsafe { - let name_c = ffi::CString::new(name).unwrap(); - gl::GetAttribLocation(self.0, name_c.as_ptr()) + glow_context().get_attrib_location(self.0, name) }; - if a != -1 { - Some(Attribute(a)) + if let Some(a) = a { + Some(Attribute(a as i32)) } else { None } + */ + Some(Attribute(0)) } } impl Drop for Program { fn drop(&mut self) { unsafe { - gl::DeleteProgram(self.0); + //glow_context().delete_program(self.0); } } } @@ -570,99 +581,101 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { - Shader(unsafe { gl::CreateShader(ty) }) + Shader(0) //unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) } pub fn set_source(&self, src: &str) { + /* TODO unsafe { - let src_c = ffi::CString::new(src).unwrap(); - gl::ShaderSource(self.0, 1, &src_c.as_ptr(), ptr::null()); + glow_context().shader_source(self.0, src); } + */ } pub fn compile(&self) { unsafe { - gl::CompileShader(self.0); + //glow_context().compile_shader(self.0); } } - pub fn get_parameter(&self, param: ShaderParameter) -> i32 { - let mut ret: i32 = 0; + pub fn get_shader_compile_status(&self) -> bool { + true + /* TODO unsafe { - gl::GetShaderiv(self.0, param, &mut ret); + glow_context().get_shader_compile_status(self.0) } - ret + */ } pub fn get_info_log(&self) -> String { - let len = self.get_parameter(INFO_LOG_LENGTH); - - let mut data = Vec::::with_capacity(len as usize); + /* TODO unsafe { - data.set_len(len as usize); - gl::GetShaderInfoLog(self.0, len, ptr::null_mut(), data.as_mut_ptr() as *mut i8); + glow_context().get_shader_info_log(self.0) } - String::from_utf8(data).unwrap() + */ + "".to_string() } } #[derive(Clone, Copy)] -pub struct Uniform(i32); +pub struct Uniform(u32); impl Uniform { pub fn set_int(&self, val: i32) { unsafe { - gl::Uniform1i(self.0, val); + //glow_context().uniform_1_i32(Some(&self.0), val); } } pub fn set_int3(&self, x: i32, y: i32, z: i32) { unsafe { - gl::Uniform3i(self.0, x, y, z); + //glow_context().uniform_3_i32(Some(&self.0), x, y, z); } } pub fn set_float(&self, val: f32) { unsafe { - gl::Uniform1f(self.0, val); + //glow_context().uniform_1_f32(Some(&self.0), val); } } pub fn set_float2(&self, x: f32, y: f32) { unsafe { - gl::Uniform2f(self.0, x, y); + //glow_context().uniform_2_f32(Some(&self.0), x, y); } } pub fn set_float3(&self, x: f32, y: f32, z: f32) { unsafe { - gl::Uniform3f(self.0, x, y, z); + //glow_context().uniform_3_f32(Some(&self.0), x, y, z); } } pub fn set_float4(&self, x: f32, y: f32, z: f32, w: f32) { unsafe { - gl::Uniform4f(self.0, x, y, z, w); + //glow_context().uniform_4_f32(Some(&self.0), x, y, z, w); } } pub fn set_float_mutli_raw(&self, data: *const f32, len: usize) { unsafe { - gl::Uniform4fv(self.0, len as i32, data); + // TODO: takes a slice, not a raw pointer + //TODO glow_context().uniform_4_f32_slice(Some(&self.0), len as i32, data); } } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - gl::UniformMatrix4fv(self.0, 1, false as u8, m.as_ptr()); + // TODO + //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), 1, false as u8, m.as_ptr()); } } pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { unsafe { - gl::UniformMatrix4fv(self.0, m.len() as i32, false as u8, m.as_ptr() as *const _); - // TODO: Most likely isn't safe + // TODO + //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe } } } @@ -673,38 +686,38 @@ pub struct Attribute(i32); impl Attribute { pub fn enable(&self) { unsafe { - gl::EnableVertexAttribArray(self.0 as u32); + //glow_context().enable_vertex_attrib_array(self.0 as u32); } } pub fn disable(&self) { unsafe { - gl::DisableVertexAttribArray(self.0 as u32); + //glow_context().disable_vertex_attrib_array(self.0 as u32); } } pub fn vertex_pointer(&self, size: i32, ty: Type, normalized: bool, stride: i32, offset: i32) { unsafe { - gl::VertexAttribPointer( - self.0 as u32, - size, - ty, - normalized as u8, - stride, - offset as *const gl::types::GLvoid, - ); + /* + glow_context().vertex_attrib_pointer_f32(self.0 as u32, + size, + ty, + normalized, + stride, + offset); + */ } } pub fn vertex_pointer_int(&self, size: i32, ty: Type, stride: i32, offset: i32) { unsafe { - gl::VertexAttribIPointer( - self.0 as u32, - size, - ty, - stride, - offset as *const gl::types::GLvoid, - ); + /* + glow_context().vertex_attrib_pointer_i32(self.0 as u32, + size, + ty, + stride, + offset); + */ } } } @@ -717,11 +730,7 @@ pub struct VertexArray(u32); impl VertexArray { /// Allocates a new `VertexArray`. pub fn new() -> VertexArray { - let mut va = VertexArray(0); - unsafe { - gl::GenVertexArrays(1, &mut va.0); - } - va + VertexArray(0) //unsafe { glow_context().create_vertex_array().expect("create vertex array failed") }) } /// Marks the `VertexArray` as the currently active one, this @@ -729,7 +738,7 @@ impl VertexArray { /// this `VertexArray`. pub fn bind(&self) { unsafe { - gl::BindVertexArray(self.0); + //glow_context().bind_vertex_array(Some(self.0)); } } } @@ -737,7 +746,7 @@ impl VertexArray { impl Drop for VertexArray { fn drop(&mut self) { unsafe { - gl::DeleteVertexArrays(1, &self.0); + //glow_context().delete_vertex_array(self.0); } self.0 = 0; } @@ -777,11 +786,7 @@ pub struct Buffer(u32); impl Buffer { /// Allocates a new Buffer. pub fn new() -> Buffer { - let mut b = Buffer(0); - unsafe { - gl::GenBuffers(1, &mut b.0); - } - b + Buffer(0) //unsafe { glow_context().create_buffer().expect("create buffer failed") }) } /// Makes the buffer the currently active one for the given target. @@ -789,24 +794,23 @@ impl Buffer { /// (Data, Map etc). pub fn bind(&self, target: BufferTarget) { unsafe { - gl::BindBuffer(target, self.0); + //glow_context().bind_buffer(target, Some(self.0)); } } pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { unsafe { - gl::BufferData( - target, - data.len() as isize, - data.as_ptr() as *const gl::types::GLvoid, - usage, - ); + /* + glow_context().buffer_data_u8_slice(target, + data, + usage); + */ } } pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) { unsafe { - gl::BufferSubData(target, 0, data.len() as isize, data.as_ptr() as *const _); + //glow_context().buffer_sub_data_u8_slice(target, 0, data); } } @@ -820,7 +824,7 @@ impl Buffer { pub fn map(&self, target: BufferTarget, access: Access, length: usize) -> MappedBuffer { unsafe { MappedBuffer { - inner: Vec::from_raw_parts(gl::MapBuffer(target, access) as *mut u8, 0, length), + inner: vec![], //Vec::from_raw_parts(glow_context().map_buffer_range(target, 0, length as i32, access) as *mut u8, 0, length), target, } } @@ -830,7 +834,7 @@ impl Buffer { impl Drop for Buffer { fn drop(&mut self) { unsafe { - gl::DeleteBuffers(1, &self.0); + //glow_context().delete_buffer(self.0); } } } @@ -857,7 +861,7 @@ impl DerefMut for MappedBuffer { impl Drop for MappedBuffer { fn drop(&mut self) { unsafe { - gl::UnmapBuffer(self.target); + //glow_context().unmap_buffer(self.target); } mem::forget(mem::replace(&mut self.inner, Vec::new())); } @@ -875,7 +879,7 @@ pub struct Framebuffer(u32); pub fn check_framebuffer_status() { unsafe { - let status = gl::CheckFramebufferStatus(gl::FRAMEBUFFER); + let status = glow_context().check_framebuffer_status(gl::FRAMEBUFFER); let s = match status { gl::FRAMEBUFFER_UNDEFINED => "GL_FRAMEBUFFER_UNDEFINED", gl::FRAMEBUFFER_INCOMPLETE_ATTACHMENT => "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT", @@ -904,41 +908,39 @@ pub fn check_framebuffer_status() { pub fn check_gl_error() { unsafe { + /* loop { - let err = gl::GetError(); + let err = glow_context().get_error(); if err == gl::NO_ERROR { - break; + break } error!("glGetError = {}", err); } + */ } } impl Framebuffer { pub fn new() -> Framebuffer { - let mut fb = Framebuffer(0); - unsafe { - gl::GenFramebuffers(1, &mut fb.0); - } - fb + Framebuffer(0) //unsafe { glow_context().create_framebuffer().expect("create framebuffer failed") }) } pub fn bind(&self) { unsafe { - gl::BindFramebuffer(gl::FRAMEBUFFER, self.0); + //glow_context().bind_framebuffer(gl::FRAMEBUFFER, Some(self.0)); } } pub fn bind_read(&self) { unsafe { - gl::BindFramebuffer(gl::READ_FRAMEBUFFER, self.0); + //glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, Some(self.0)); } } pub fn bind_draw(&self) { unsafe { - gl::BindFramebuffer(gl::DRAW_FRAMEBUFFER, self.0); + //glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, Some(self.0)); } } @@ -950,7 +952,7 @@ impl Framebuffer { level: i32, ) { unsafe { - gl::FramebufferTexture2D(gl::FRAMEBUFFER, attachment, target, tex.0, level); + //glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, Some(tex.0), level); } } } @@ -958,39 +960,38 @@ impl Framebuffer { impl Drop for Framebuffer { fn drop(&mut self) { unsafe { - gl::DeleteFramebuffers(1, &self.0); + //glow_context().delete_framebuffer(self.0); } } } pub fn unbind_framebuffer() { unsafe { - gl::BindFramebuffer(gl::FRAMEBUFFER, 0); + //glow_context().bind_framebuffer(gl::FRAMEBUFFER, None); } } pub fn unbind_framebuffer_read() { unsafe { - gl::BindFramebuffer(gl::READ_FRAMEBUFFER, 0); + //glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, None); } } pub fn unbind_framebuffer_draw() { unsafe { - gl::BindFramebuffer(gl::DRAW_FRAMEBUFFER, 0); + //glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, None); } } pub fn draw_buffers(bufs: &[Attachment]) { unsafe { - gl::DrawBuffers(bufs.len() as i32, bufs.as_ptr()); + //glow_context().draw_buffers(bufs); } } pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { unsafe { - let name_c = ffi::CString::new(name).unwrap(); - gl::BindFragDataLocation(p.0, cn, name_c.as_ptr()); + //glow_context().bind_frag_data_location(p.0, cn, name) } } @@ -1006,33 +1007,23 @@ pub fn blit_framebuffer( mask: ClearFlags, filter: TextureValue, ) { + /* unsafe { - gl::BlitFramebuffer( - sx0, - sy0, - sx1, - sy1, - dx0, - dy0, - dx1, - dy1, - mask.internal(), - filter as u32, + glow_context().blit_framebuffer( + sx0, sy0, sx1, sy1, + dx0, dy0, dx1, dy1, + mask.internal(), filter as u32 ); } -} - -pub fn read_buffer(a: Attachment) { - unsafe { - gl::ReadBuffer(a); - } + */ } pub type TargetBuffer = u32; pub const COLOR: TargetBuffer = gl::COLOR; -pub fn clear_buffer(buffer: TargetBuffer, draw_buffer: i32, values: &[f32]) { +pub fn clear_buffer(buffer: TargetBuffer, draw_buffer: u32, values: &mut [f32]) { unsafe { - gl::ClearBufferfv(buffer, draw_buffer, values.as_ptr()); + // TODO: why does glow have &mut on clear buffer values, why would it change the color? + //glow_context().clear_buffer_f32_slice(buffer, draw_buffer, values); } } diff --git a/src/main.rs b/src/main.rs index 12d47817..f55a301a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,6 +251,7 @@ fn main2() { .with_title("Stevenarella") .with_inner_size(glutin::dpi::LogicalSize::new(854.0, 480.0)); let window = glutin::ContextBuilder::new() + /* .with_stencil_buffer(0) .with_depth_buffer(24) .with_gl(glutin::GlRequest::GlThenGles { @@ -258,6 +259,7 @@ fn main2() { opengles_version: (2, 0), }) .with_gl_profile(glutin::GlProfile::Core) + */ .with_vsync(vsync) .build_windowed(window_builder, &events_loop) .expect("Could not create glutin window."); @@ -271,6 +273,9 @@ fn main2() { gl::init(&window); let renderer = render::Renderer::new(resource_manager.clone()); + println!("main 4"); + println!("ok"); + std::process::exit(0); let mut ui_container = ui::Container::new(); let mut last_frame = Instant::now(); diff --git a/src/render/clouds.rs b/src/render/clouds.rs index c3d102fa..a2fd8293 100644 --- a/src/render/clouds.rs +++ b/src/render/clouds.rs @@ -46,7 +46,7 @@ impl Clouds { v.set_source(&vertex); v.compile(); - if v.get_parameter(gl::COMPILE_STATUS) == 0 { + if !v.get_shader_compile_status() { error!("Src: {}", vertex); panic!("Shader error: {}", v.get_info_log()); } else { @@ -61,7 +61,7 @@ impl Clouds { g.set_source(&geo); g.compile(); - if g.get_parameter(gl::COMPILE_STATUS) == 0 { + if !g.get_shader_compile_status() { error!("Src: {}", geo); panic!("Shader error: {}", g.get_info_log()); } else { @@ -76,7 +76,7 @@ impl Clouds { f.set_source(&fragment); f.compile(); - if f.get_parameter(gl::COMPILE_STATUS) == 0 { + if !f.get_shader_compile_status() { error!("Src: {}", fragment); panic!("Shader error: {}", f.get_info_log()); } else { diff --git a/src/render/mod.rs b/src/render/mod.rs index d70f6674..62514b54 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -158,23 +158,16 @@ init_shader! { impl Renderer { pub fn new(res: Arc>) -> Renderer { - let version = { res.read().unwrap().version() }; + let version = 0; //{ res.read().unwrap().version() }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); - tex.image_3d( - gl::TEXTURE_2D_ARRAY, - 0, - ATLAS_SIZE as u32, - ATLAS_SIZE as u32, - 1, - gl::RGBA, - gl::UNSIGNED_BYTE, - &[0; ATLAS_SIZE * ATLAS_SIZE * 4], - ); + println!("returned 2"); + /* tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE); + */ let (textures, skin_req, skin_reply) = TextureManager::new(res.clone()); let textures = Arc::new(RwLock::new(textures)); @@ -183,10 +176,12 @@ impl Renderer { shaders::add_shaders(&mut greg); let ui = ui::UIState::new(&greg, textures.clone(), res.clone()); + /* gl::enable(gl::DEPTH_TEST); gl::enable(gl::CULL_FACE_FLAG); gl::cull_face(gl::BACK); gl::front_face(gl::CLOCK_WISE); + */ // Shaders let chunk_shader = ChunkShader::new(&greg); @@ -197,8 +192,15 @@ impl Renderer { // Line Drawer // Clouds + /* gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); gl::depth_func(gl::LESS_OR_EQUAL); + */ + + unsafe { + println!("creating texture"); + let tex = gl::Texture::new(); + } Renderer { resource_version: version, @@ -416,8 +418,8 @@ impl Renderer { trans.trans.bind(); gl::clear_color(0.0, 0.0, 0.0, 1.0); gl::clear(gl::ClearFlags::Color); - gl::clear_buffer(gl::COLOR, 0, &[0.0, 0.0, 0.0, 1.0]); - gl::clear_buffer(gl::COLOR, 1, &[0.0, 0.0, 0.0, 0.0]); + gl::clear_buffer(gl::COLOR, 0, &mut [0.0, 0.0, 0.0, 1.0]); + gl::clear_buffer(gl::COLOR, 1, &mut [0.0, 0.0, 0.0, 0.0]); gl::blend_func_separate( gl::ONE_FACTOR, gl::ONE_FACTOR, @@ -954,8 +956,7 @@ pub struct TextureManager { free_dynamics: Vec, skins: HashMap>, - - _skin_thread: thread::JoinHandle<()>, + //_skin_thread: thread::JoinHandle<()>, } impl TextureManager { @@ -968,7 +969,7 @@ impl TextureManager { ) { let (tx, rx) = mpsc::channel(); let (stx, srx) = mpsc::channel(); - let skin_thread = thread::spawn(|| Self::process_skins(srx, tx)); + //let skin_thread = thread::spawn(|| Self::process_skins(srx, tx)); let mut tm = TextureManager { textures: HashMap::with_hasher(BuildHasherDefault::default()), version: { @@ -983,8 +984,7 @@ impl TextureManager { dynamic_textures: HashMap::with_hasher(BuildHasherDefault::default()), free_dynamics: Vec::new(), skins: HashMap::with_hasher(BuildHasherDefault::default()), - - _skin_thread: skin_thread, + //_skin_thread: skin_thread, }; tm.add_defaults(); (tm, stx, rx) @@ -1015,6 +1015,7 @@ impl TextureManager { recv: mpsc::Receiver, reply: mpsc::Sender<(String, Option)>, ) { + println!("in process_skins thread"); let client = reqwest::blocking::Client::new(); loop { let hash = match recv.recv() { @@ -1082,8 +1083,7 @@ impl TextureManager { if height == 32 { // Needs changing to the new format let mut new = image::DynamicImage::new_rgba8(64, 64); - new.copy_from(&img, 0, 0) - .expect("Invalid png image in skin"); + new.copy_from(&img, 0, 0); for xx in 0..4 { for yy in 0..16 { for section in 0..4 { diff --git a/src/render/shaders.rs b/src/render/shaders.rs index bdd2f7c5..c67a148a 100644 --- a/src/render/shaders.rs +++ b/src/render/shaders.rs @@ -77,7 +77,7 @@ macro_rules! init_shader { } ) => ( #[allow(dead_code)] - struct $name { + pub struct $name { // TODO: remove pub program: gl::Program, $( $field: gl::Attribute, @@ -131,7 +131,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program { v.set_source(vertex); v.compile(); - if v.get_parameter(gl::COMPILE_STATUS) == 0 { + if !v.get_shader_compile_status() { error!("Src: {}", vertex); panic!("Shader error: {}", v.get_info_log()); } else { @@ -146,7 +146,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program { f.set_source(fragment); f.compile(); - if f.get_parameter(gl::COMPILE_STATUS) == 0 { + if !f.get_shader_compile_status() { error!("Src: {}", fragment); panic!("Shader error: {}", f.get_info_log()); } else { From 3695c16cf02cddaf043bb6d0bcfab4c72c845d18 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 20 Dec 2020 12:03:29 -0800 Subject: [PATCH 112/137] Revert Cargo.lock changes --- Cargo.lock | 2761 ++++++++++++++++++++++++++++------------------------ 1 file changed, 1500 insertions(+), 1261 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 987c8378..d7e56d2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,2054 +1,2420 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "ab_glyph_rasterizer" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9fe5e32de01730eb1f6b7f5b51c17e03e2325bf40a74f754f04f130043affff" + [[package]] name = "adler" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" [[package]] name = "adler32" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "aes" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7001367fde4c768a19d1029f0a8be5abd9308e1119846d5bd9ad26297b8faf5" dependencies = [ - "aes-soft 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "aesni 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "block-cipher 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "aes-soft", + "aesni", + "block-cipher", ] [[package]] name = "aes-soft" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4925647ee64e5056cf231608957ce7c81e12d6d6e316b9ce1404778cc1d35fa7" dependencies = [ - "block-cipher 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "block-cipher", + "byteorder", + "opaque-debug 0.2.3", ] [[package]] name = "aesni" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050d39b0b7688b3a3254394c3e30a9d66c41dcf9b05b0e2dbdc623f6505d264" dependencies = [ - "block-cipher 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "block-cipher", + "opaque-debug 0.2.3", ] [[package]] name = "andrew" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c4afb09dd642feec8408e33f92f3ffc4052946f6b20f32fb99c1f58cd4fa7cf" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rusttype 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "xml-rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "rusttype", + "walkdir", + "xdg", + "xml-rs", ] [[package]] name = "android_glue" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" [[package]] name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9", ] [[package]] name = "approx" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" dependencies = [ - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits", ] [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", + "winapi 0.3.9", ] [[package]] name = "autocfg" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" [[package]] name = "autocfg" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "base-x" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" [[package]] name = "base64" -version = "0.12.3" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bit-set" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" dependencies = [ - "bit-vec 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bit-vec", ] [[package]] name = "bit-vec" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "block" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "block-buffer" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array", ] [[package]] name = "block-cipher" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa136449e765dc7faa244561ccae839c394048667929af599b5d931ebe7b7f10" dependencies = [ - "generic-array 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array", ] [[package]] name = "bumpalo" version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" [[package]] name = "bytemuck" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41aa2ec95ca3b5c54cf73c91acf06d24f4495d5f1b1c12506ae3483d646177ac" [[package]] name = "byteorder" version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "bytes" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "loom 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" [[package]] name = "calloop" -version = "0.4.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b036167e76041694579972c28cf4877b4f92da222560ddb49008937b6a6727c" dependencies = [ - "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log", + "nix", ] [[package]] name = "cc" -version = "1.0.54" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" [[package]] name = "cfb8" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba2baac45bade12cdd992418b4b4ea40f6198c03b2de1a9eb7b059f118f445d6" dependencies = [ - "block-cipher 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "stream-cipher 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "block-cipher", + "stream-cipher", ] [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cgl" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "cgmath" version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "283944cdecc44bf0b8dd010ec9af888d3b4f142844fdbe026c20ef68148d6fe7" dependencies = [ - "approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "approx", + "num-traits", + "rand 0.6.5", + "serde", ] [[package]] name = "chrono" -version = "0.4.11" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ - "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "num-integer", + "num-traits", + "time", + "winapi 0.3.9", ] [[package]] name = "clap" -version = "2.33.1" +version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ansi_term", + "atty", + "bitflags", + "strsim 0.8.0", + "textwrap", + "unicode-width", + "vec_map", ] [[package]] name = "clipboard" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a904646c0340239dcf7c51677b33928bf24fdf424b79a57909c0109075b2e7" dependencies = [ - "clipboard-win 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "x11-clipboard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "clipboard-win", + "objc", + "objc-foundation", + "objc_id", + "x11-clipboard", ] [[package]] name = "clipboard-win" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a093d6fed558e5fe24c3dfc85a68bb68f1c824f440d3ba5aca189e2998786b" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9", ] [[package]] name = "cloudabi" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "cocoa" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54201c07dcf3a5ca33fececb8042aed767ee4bfd5a0235a8ceabcda956044b2" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "block", + "cocoa-foundation", + "core-foundation 0.9.1", + "core-graphics 0.22.2", + "foreign-types", + "libc", + "objc", ] [[package]] name = "cocoa" -version = "0.19.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63902e9223530efb4e26ccd0cf55ec30d592d3b42e21a28defc42a9586e832" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "block", + "cocoa-foundation", + "core-foundation 0.9.1", + "core-graphics 0.22.2", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "cocoa-foundation" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" +dependencies = [ + "bitflags", + "block", + "core-foundation 0.9.1", + "core-graphics-types", + "foreign-types", + "libc", + "objc", ] [[package]] name = "collision" version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6107f6be76c2269a9c8d89e707a66122bd3086f987fa508133a5f774e8ac4ced" dependencies = [ - "approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "bit-set 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "approx", + "bit-set", + "cgmath", + "num", + "rand 0.6.5", + "smallvec 0.6.13", ] [[package]] name = "color_quant" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "const_fn" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" [[package]] name = "core-foundation" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" dependencies = [ - "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.7.0", + "libc", ] [[package]] name = "core-foundation" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" dependencies = [ - "core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.8.2", + "libc", ] [[package]] name = "core-foundation-sys" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "core-foundation-sys" -version = "0.7.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "core-graphics" -version = "0.17.3" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "core-foundation 0.7.0", + "foreign-types", + "libc", ] [[package]] name = "core-graphics" -version = "0.19.0" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "269f35f69b542b80e736a20a89a05215c0ce80c2c03c514abb2e318b78379d86" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "core-foundation 0.9.1", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" +dependencies = [ + "bitflags", + "core-foundation 0.9.1", + "foreign-types", + "libc", ] [[package]] name = "core-video-sys" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ecad23610ad9757664d644e369246edde1803fcb43ed72876565098a5d3828" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10", + "core-foundation-sys 0.7.0", + "core-graphics 0.19.2", + "libc", + "objc", ] [[package]] name = "cpuid-bool" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" [[package]] name = "crc32fast" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.7.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" dependencies = [ - "crossbeam-epoch 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.8.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "const_fn", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", ] [[package]] -name = "crossbeam-queue" -version = "0.2.3" +name = "crossbeam-utils" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "cfg-if 1.0.0", + "lazy_static", ] [[package]] -name = "crossbeam-utils" -version = "0.7.2" +name = "darling" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.9.3", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core", + "quote", + "syn", ] [[package]] name = "deflate" -version = "0.8.4" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" +dependencies = [ + "adler32", + "byteorder", +] + +[[package]] +name = "derivative" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" dependencies = [ - "adler32 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "digest" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array", ] [[package]] name = "discard" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" [[package]] name = "dispatch" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" [[package]] name = "dlib" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b11f15d1e3268f140f68d390637d5e76d849782d971ae7063e0da69fe9709a76" dependencies = [ - "libloading 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libloading", ] [[package]] name = "downcast-rs" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "dtoa" -version = "0.4.6" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "either" -version = "1.5.3" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "encoding_rs" -version = "0.8.23" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801bbab217d7f79c0062f4f7205b5d4427c6d1a7bd7aafdd1475f7c59d62b283" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", ] [[package]] name = "flate2" -version = "1.0.16" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7411863d55df97a419aa64cb4d2f167103ea9d767e2c54a1868b7ac3f6b47129" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz_oxide 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "crc32fast", + "libc", + "miniz_oxide 0.4.3", ] [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foreign-types" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "foreign-types-shared", ] [[package]] name = "foreign-types-shared" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +dependencies = [ + "matches", + "percent-encoding", +] [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "fuchsia-zircon-sys", ] [[package]] name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures-channel" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" dependencies = [ - "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core", ] [[package]] name = "futures-channel-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5e5f4df964fa9c1c2f8bddeb5c3611631cacd93baf810fc8bb2fb4b495c263a" dependencies = [ - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview", ] [[package]] name = "futures-core" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748" [[package]] name = "futures-core-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35b6263fb1ef523c3056565fa67b1d16f0a8604ff12b11b08c25f28a734c60a" [[package]] name = "futures-executor-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75236e88bd9fe88e5e8bfcd175b665d0528fe03ca4c5207fabc028c8f9d93e98" dependencies = [ - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview", + "futures-util-preview", + "num_cpus", ] [[package]] name = "futures-io" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" [[package]] name = "futures-sink" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d" [[package]] name = "futures-task" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" dependencies = [ - "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell", ] [[package]] name = "futures-util" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" dependencies = [ - "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-io 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-project 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project 1.0.2", + "pin-utils", + "slab", ] [[package]] name = "futures-util-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce968633c17e5f97936bd2797b6e38fb56cf16a7422319f7ec2e30d3c470e8d" dependencies = [ - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "generator" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview", + "pin-utils", + "slab", ] [[package]] name = "generic-array" -version = "0.14.2" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ - "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum", + "version_check", ] [[package]] name = "getrandom" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", ] [[package]] name = "gif" -version = "0.10.3" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02efba560f227847cb41463a7395c514d127d4f74fff12ef0137fff1b84b96c4" dependencies = [ - "color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "color_quant", + "weezl", ] [[package]] name = "gl_generator" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" dependencies = [ - "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "xml-rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "glow" -version = "0.4.0" -source = "git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94#666a7529d0f48a05b32deb919668cd172b0adc94" -dependencies = [ - "gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", - "slotmap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", + "khronos_api", + "log", + "xml-rs", ] [[package]] name = "glutin" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cgl 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cocoa 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_egl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_emscripten_sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_gles2_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_glx_sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_wgl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winit 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ae1cbb9176b9151c4ce03f012e3cd1c6c18c4be79edeaeb3d99f5d8085c5fa3" +dependencies = [ + "android_glue", + "cgl", + "cocoa 0.23.0", + "core-foundation 0.9.1", + "glutin_egl_sys", + "glutin_emscripten_sys", + "glutin_gles2_sys", + "glutin_glx_sys", + "glutin_wgl_sys", + "lazy_static", + "libloading", + "log", + "objc", + "osmesa-sys", + "parking_lot", + "wayland-client", + "wayland-egl", + "winapi 0.3.9", + "winit", ] [[package]] name = "glutin_egl_sys" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2abb6aa55523480c4adc5a56bbaa249992e2dddb2fc63dc96e04a3355364c211" dependencies = [ - "gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "gl_generator", + "winapi 0.3.9", ] [[package]] name = "glutin_emscripten_sys" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80de4146df76e8a6c32b03007bc764ff3249dcaeb4f675d68a06caf1bac363f1" [[package]] name = "glutin_gles2_sys" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094e708b730a7c8a1954f4f8a31880af00eb8a1c5b5bf85d28a0a3c6d69103" dependencies = [ - "gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "gl_generator", + "objc", ] [[package]] name = "glutin_glx_sys" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e393c8fc02b807459410429150e9c4faffdb312d59b8c038566173c81991351" dependencies = [ - "gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "x11-dl 2.18.5 (registry+https://github.com/rust-lang/crates.io-index)", + "gl_generator", + "x11-dl", ] [[package]] name = "glutin_wgl_sys" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3da5951a1569dbab865c6f2a863efafff193a93caf05538d193e9e3816d21696" dependencies = [ - "gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gl_generator", ] [[package]] name = "h2" -version = "0.2.5" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" dependencies = [ - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "indexmap 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", + "tracing-futures", ] +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + [[package]] name = "heck" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" dependencies = [ - "unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-segmentation", ] [[package]] name = "hermit-abi" -version = "0.1.14" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "hex" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" [[package]] name = "hex" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" [[package]] name = "http" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84129d298a6d57d246960ff8eb831ca4af3f96d29e2e28848dae275408658e26" dependencies = [ - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes", + "fnv", + "itoa", ] [[package]] name = "http-body" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" dependencies = [ - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes", + "http", ] [[package]] name = "httparse" version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" + +[[package]] +name = "httpdate" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] name = "hyper" -version = "0.13.6" +version = "0.13.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf" dependencies = [ - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-channel 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "h2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-project 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", - "socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", - "tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project 1.0.2", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", ] [[package]] name = "hyper-tls" -version = "0.4.1" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" dependencies = [ - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.13.6 (registry+https://github.com/rust-lang/crates.io-index)", - "native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-tls 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-tls", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "matches", + "unicode-bidi", + "unicode-normalization", ] [[package]] name = "image" -version = "0.23.6" +version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce04077ead78e39ae8610ad26216aed811996b043d47beed5090db674f9e9b5" dependencies = [ - "bytemuck 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", - "jpeg-decoder 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "num-rational 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", - "png 0.16.5 (registry+https://github.com/rust-lang/crates.io-index)", - "scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tiff 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytemuck", + "byteorder", + "color_quant", + "gif", + "jpeg-decoder", + "num-iter", + "num-rational 0.3.2", + "num-traits", + "png", + "scoped_threadpool", + "tiff", ] [[package]] name = "indexmap" -version = "1.4.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "hashbrown", ] [[package]] name = "instant" -version = "0.1.4" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "stdweb", ] [[package]] name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] +[[package]] +name = "ipnet" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" + [[package]] name = "itoa" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "jpeg-decoder" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc797adac5f083b8ff0ca6f6294a999393d76e197c36488e2ef732c4715f6fa3" dependencies = [ - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder", + "rayon", ] [[package]] name = "js-sys" -version = "0.3.40" +version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" dependencies = [ - "wasm-bindgen 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen", ] [[package]] name = "kernel32-sys" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8", + "winapi-build", ] [[package]] name = "khronos_api" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.71" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "libloading" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libloading" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "line_drawing" -version = "0.7.0" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9367bdfa836b7e3cf895867f7a570283444da90562980ec2263d6e1569b16bc" dependencies = [ - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "winapi 0.3.9", ] [[package]] name = "localstoragefs" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6cbee6bbe7e6ea61ad375952239a9678624f216a0f442ae04a90260e76cdf" dependencies = [ - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2", + "stdweb", ] [[package]] name = "lock_api" -version = "0.3.4" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" dependencies = [ - "scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard", ] [[package]] name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "loom" -version = "0.3.4" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "generator 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", - "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10", ] -[[package]] -name = "lzw" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "malloc_buf" version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "maybe-uninit" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.3.3" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] -name = "memmap" -version = "0.7.0" +name = "memmap2" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b70ca2a6103ac8b665dc150b142ef0e4e89df640c9e6cf295d189c3caebe5a" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "memoffset" -version = "0.5.4" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", ] [[package]] name = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mime_guess" version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" dependencies = [ - "mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "mime", + "unicase", ] [[package]] name = "miniz_oxide" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" dependencies = [ - "adler32 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "adler32", ] [[package]] name = "miniz_oxide" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" dependencies = [ - "adler 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "adler", + "autocfg 1.0.1", ] [[package]] name = "mio" -version = "0.6.22" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow", + "net2", + "slab", + "winapi 0.2.8", ] [[package]] name = "mio-extras" version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazycell", + "log", + "mio", + "slab", ] [[package]] name = "miow" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", ] [[package]] name = "native-tls" -version = "0.2.4" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fcc7939b5edc4e4f86b1b4a04bb1498afaaf871b1a6691838ed06fcb48d3a3f" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "ndk" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb167c1febed0a496639034d0c76b3b74263636045db5489eee52143c246e73" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.58 (registry+https://github.com/rust-lang/crates.io-index)", - "schannel 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jni-sys", + "ndk-sys", + "num_enum", + "thiserror", ] +[[package]] +name = "ndk-glue" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdf399b8b7a39c6fb153c4ec32c72fd5fe789df24a647f229c239aa7adb15241" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk", + "ndk-macro", + "ndk-sys", +] + +[[package]] +name = "ndk-macro" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d" +dependencies = [ + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ndk-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c44922cb3dbb1c70b5e5f443d63b64363a898564d739ba5198e3a9138442868d" + [[package]] name = "net2" -version = "0.2.34" +version = "0.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", ] [[package]] name = "nix" -version = "0.14.1" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055" +dependencies = [ + "bitflags", + "cc", + "cfg-if 0.1.10", + "libc", +] + +[[package]] +name = "nom" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88034cfd6b4a0d54dd14f4a507eceee36c0b70e5a02236c4e4df571102be17f0" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", + "version_check", ] [[package]] name = "num" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" dependencies = [ - "num-bigint 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-complex 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "num-rational 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational 0.2.4", + "num-traits", ] [[package]] name = "num-bigint" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "num-integer", + "num-traits", + "serde", ] [[package]] name = "num-complex" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "num-traits", + "serde", ] [[package]] name = "num-integer" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "num-traits", ] [[package]] name = "num-iter" -version = "0.1.41" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "num-integer", + "num-traits", ] [[package]] name = "num-rational" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-bigint 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "num-bigint", + "num-integer", + "num-traits", + "serde", ] [[package]] name = "num-rational" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "num-integer", + "num-traits", ] [[package]] name = "num-traits" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", ] [[package]] name = "num_cpus" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ - "hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", +] + +[[package]] +name = "num_enum" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca565a7df06f3d4b485494f25ba05da1435950f4dc263440eda7a6fa9b8e36e4" +dependencies = [ + "derivative", + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffa5a33ddddfee04c0283a7653987d634e880347e96b5b2ed64de07efb59db9d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "objc" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" dependencies = [ - "malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "malloc_buf", ] [[package]] name = "objc-foundation" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" dependencies = [ - "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "block", + "objc", + "objc_id", ] [[package]] name = "objc_id" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" dependencies = [ - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "objc", ] [[package]] name = "once_cell" -version = "1.4.0" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" [[package]] name = "opaque-debug" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "opaque-debug" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.29" +version = "0.10.31" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d008f51b1acffa0d3450a68606e6a51c123012edaacb0f4e1426bd978869187" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.58 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", ] [[package]] name = "openssl-probe" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" -version = "0.9.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ordered-float" -version = "1.0.2" +version = "0.9.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de52d8eabd217311538a39bba130d7dea1f1e118010fee7a033d966845e7d5fe" dependencies = [ - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "cc", + "libc", + "pkg-config", + "vcpkg", ] [[package]] name = "osmesa-sys" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" dependencies = [ - "shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "shared_library", ] [[package]] -name = "parking_lot" -version = "0.9.0" +name = "owned_ttf_parser" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f923fb806c46266c02ab4a5b239735c144bdeda724a50ed058e5226f594cde3" dependencies = [ - "lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ttf-parser", ] [[package]] name = "parking_lot" -version = "0.10.2" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" dependencies = [ - "lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "instant", + "lock_api", + "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.6.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c6d9b8427445284a09c55be860a15855ab580a417ccad9da88f5a06787ced0" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec 1.5.1", + "winapi 0.3.9", ] [[package]] -name = "parking_lot_core" -version = "0.7.2" +name = "percent-encoding" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project-internal 0.4.27", ] [[package]] -name = "percent-encoding" -version = "2.1.0" +name = "pin-project" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7" +dependencies = [ + "pin-project-internal 1.0.2", +] [[package]] -name = "pin-project" -version = "0.4.22" +name = "pin-project-internal" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" dependencies = [ - "pin-project-internal 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "pin-project-internal" -version = "0.4.22" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f" dependencies = [ - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "pin-project-lite" -version = "0.1.7" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" + +[[package]] +name = "pin-project-lite" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" [[package]] name = "pin-utils" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "png" -version = "0.16.5" +version = "0.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "deflate 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz_oxide 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "crc32fast", + "deflate", + "miniz_oxide 0.3.7", ] [[package]] name = "podio" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b18befed8bc2b61abc79a457295e7e838417326da1586050b919414073977f19" [[package]] name = "ppv-lite86" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] -name = "proc-macro-error" -version = "1.0.2" +name = "proc-macro-crate" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "toml", ] [[package]] -name = "proc-macro-error-attr" -version = "1.0.2" +name = "proc-macro-error" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", ] [[package]] -name = "proc-macro2" -version = "0.4.30" +name = "proc-macro-error-attr" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "version_check", ] [[package]] name = "proc-macro2" -version = "1.0.18" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quote" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid", ] [[package]] name = "quote" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "rand" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" dependencies = [ - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "winapi 0.3.9", ] [[package]] name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" dependencies = [ - "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg 0.1.2", + "rand_xorshift", + "winapi 0.3.9", ] [[package]] name = "rand" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", ] [[package]] name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" dependencies = [ - "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7", + "rand_core 0.3.1", ] [[package]] name = "rand_chacha" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ - "ppv-lite86 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ppv-lite86", + "rand_core 0.5.1", ] [[package]] name = "rand_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" dependencies = [ - "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2", ] [[package]] name = "rand_core" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" [[package]] name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom", ] [[package]] name = "rand_hc" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1", ] [[package]] name = "rand_isaac" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] [[package]] name = "rand_jitter" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "rand_core 0.4.2", + "winapi 0.3.9", ] [[package]] name = "rand_os" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" dependencies = [ - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi 0.3.9", ] [[package]] name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" dependencies = [ - "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7", + "rand_core 0.4.2", ] [[package]] name = "rand_pcg" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" dependencies = [ - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1", ] [[package]] name = "rand_xorshift" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] [[package]] name = "raw-window-handle" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "rayon" -version = "1.3.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-deque 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon-core 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1", + "crossbeam-deque", + "either", + "rayon-core", ] [[package]] name = "rayon-core" -version = "1.7.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ - "crossbeam-deque 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-queue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", ] [[package]] name = "rdrand" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9", ] [[package]] name = "reqwest" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding_rs 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.13.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper-tls 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-tls 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-futures 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", - "winreg 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +version = "0.10.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "mime_guess", + "native-tls", + "percent-encoding", + "pin-project-lite 0.2.0", + "serde", + "serde_urlencoded", + "tokio", + "tokio-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", ] [[package]] name = "rsa_public_encrypt_pkcs1" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c82a2353440d2314c25680aefd2e34e7e47e3dd60fddccb2228a6e3b977845ee" dependencies = [ - "num 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "simple_asn1 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num", + "rand 0.5.6", + "simple_asn1", ] [[package]] name = "rustc_version" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver", ] [[package]] name = "rusttype" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rusttype 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rusttype" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc7c727aded0be18c5b80c1640eae0ac8e396abf6fa8477d96cb37d18ee5ec59" dependencies = [ - "approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "stb_truetype 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ab_glyph_rasterizer", + "owned_ttf_parser", ] [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "same-file" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ - "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util", ] [[package]] name = "schannel" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", + "winapi 0.3.9", ] [[package]] name = "scoped-tls" -version = "0.1.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" [[package]] name = "scoped_threadpool" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "0.4.4" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "core-foundation 0.9.1", + "core-foundation-sys 0.8.2", + "libc", + "security-framework-sys", ] [[package]] name = "security-framework-sys" -version = "0.4.3" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" dependencies = [ - "core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.8.2", + "libc", ] [[package]] name = "semver" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver-parser", ] [[package]] name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.114" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" dependencies = [ - "serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.114" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" dependencies = [ - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "serde_json" -version = "1.0.56" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779" dependencies = [ - "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa", + "ryu", + "serde", ] [[package]] name = "serde_urlencoded" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" dependencies = [ - "dtoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "form_urlencoded", + "itoa", + "ryu", + "serde", ] [[package]] name = "sha-1" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce3cdf1b5e620a498ee6f2a171885ac7e22f0e12089ec4b3d22b84921792507c" dependencies = [ - "block-buffer 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cpuid-bool 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "opaque-debug 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "block-buffer", + "cfg-if 1.0.0", + "cpuid-bool", + "digest", + "opaque-debug 0.3.0", ] [[package]] name = "sha1" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" [[package]] name = "shared_library" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", + "libc", ] [[package]] name = "simple_asn1" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57f6bbbcefb91c0dac9b27c91ba13bd2aa29a815fe980f5b1e07d523fbf7b350" dependencies = [ - "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono", + "num", ] [[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "slotmap" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" dependencies = [ - "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "maybe-uninit", ] [[package]] name = "smallvec" -version = "1.4.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" [[package]] name = "smithay-client-toolkit" -version = "0.6.6" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d1d080d3dc98d68251d073b231dfaa200fdc2ddebc435b313ad937d0ae9dfd" dependencies = [ - "andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dlib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-protocols 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", + "andrew", + "bitflags", + "byteorder", + "calloop", + "dlib", + "lazy_static", + "log", + "memmap2", + "nix", + "wayland-client", + "wayland-cursor", + "wayland-protocols", ] [[package]] name = "socket2" -version = "0.3.12" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97e0e9fd577458a4f61fb91fcb559ea2afecc54c934119421f9f5d3d5b1a1057" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stb_truetype" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "libc", + "winapi 0.3.9", ] [[package]] name = "std_or_web" version = "0.0.1" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "localstoragefs 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "localstoragefs", ] [[package]] name = "stdweb" version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" dependencies = [ - "discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-executor-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-derive 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-macros 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-runtime 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", + "discard", + "futures-channel-preview", + "futures-core-preview", + "futures-executor-preview", + "futures-util-preview", + "rustc_version", + "serde", + "serde_json", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", ] [[package]] name = "stdweb-derive" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", ] [[package]] name = "stdweb-internal-macros" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ - "base-x 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", ] [[package]] name = "stdweb-internal-runtime" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" [[package]] name = "steven_blocks" version = "0.0.1" dependencies = [ - "cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "collision 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "steven_shared 0.0.1", + "cgmath", + "collision", + "lazy_static", + "steven_shared", +] + +[[package]] +name = "steven_gl" +version = "0.0.1" +dependencies = [ + "gl_generator", + "khronos_api", + "libc", ] [[package]] name = "steven_protocol" version = "0.0.1" dependencies = [ - "aes 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfb8 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", - "sha-1 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "std_or_web 0.0.1", - "steven_shared 0.0.1", + "aes", + "byteorder", + "cfb8", + "flate2", + "hex 0.4.2", + "log", + "num-traits", + "reqwest", + "serde", + "serde_json", + "sha-1", + "std_or_web", + "steven_shared", ] [[package]] @@ -2063,833 +2429,706 @@ version = "0.0.1" name = "stevenarella" version = "0.0.1" dependencies = [ - "base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "collision 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", - "glow 0.4.0 (git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94)", - "glutin 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "image 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rsa_public_encrypt_pkcs1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", - "std_or_web 0.0.1", - "stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "steven_blocks 0.0.1", - "steven_protocol 0.0.1", - "steven_resources 0.1.0", - "steven_shared 0.0.1", - "structopt 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", - "winit 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", - "zip 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "base64", + "byteorder", + "cfg-if 1.0.0", + "cgmath", + "clipboard", + "collision", + "flate2", + "glutin", + "image", + "lazy_static", + "log", + "rand 0.7.3", + "rand_pcg 0.2.1", + "reqwest", + "rsa_public_encrypt_pkcs1", + "serde", + "serde_json", + "std_or_web", + "stdweb", + "steven_blocks", + "steven_gl", + "steven_protocol", + "steven_resources", + "steven_shared", + "structopt", + "wasm-bindgen", + "winit", + "zip", ] [[package]] name = "stream-cipher" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f8ed9974042b8c3672ff3030a69fcc03b74c47c3d1ecb7755e8a3626011e88" dependencies = [ - "generic-array 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array", ] [[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "structopt" -version = "0.3.15" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" dependencies = [ - "clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt-derive 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "clap", + "lazy_static", + "structopt-derive", ] [[package]] name = "structopt-derive" -version = "0.4.8" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" dependencies = [ - "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "syn" -version = "1.0.33" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" dependencies = [ - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-xid", ] [[package]] -name = "syn-mid" -version = "0.5.0" +name = "tempfile" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10", + "libc", + "rand 0.7.3", + "redox_syscall", + "remove_dir_all", + "winapi 0.3.9", ] [[package]] -name = "tempfile" -version = "3.1.0" +name = "textwrap" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "remove_dir_all 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] [[package]] -name = "textwrap" -version = "0.11.0" +name = "thiserror" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e" dependencies = [ - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] name = "tiff" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" dependencies = [ - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz_oxide 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "jpeg-decoder", + "miniz_oxide 0.4.3", + "weezl", ] [[package]] name = "time" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi 0.3.9", ] [[package]] name = "tinyvec" -version = "0.3.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "0.2.21" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099837d3464c16a808060bb3f02263b412f6fafcb5d01c533d309985fbeebe48" dependencies = [ - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes", + "fnv", + "futures-core", + "iovec", + "lazy_static", + "memchr", + "mio", + "num_cpus", + "pin-project-lite 0.1.11", + "slab", ] [[package]] name = "tokio-tls" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" dependencies = [ - "native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls", + "tokio", ] [[package]] name = "tokio-util" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite 0.1.11", + "tokio", +] + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "serde", ] [[package]] name = "tower-service" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" + +[[package]] +name = "tracing" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" +dependencies = [ + "cfg-if 1.0.0", + "log", + "pin-project-lite 0.2.0", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-futures" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" +dependencies = [ + "pin-project 0.4.27", + "tracing", +] [[package]] name = "try-lock" -version = "0.2.2" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "ttf-parser" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5d7cd7ab3e47dda6e56542f4bbf3824c15234958c6e1bd6aaa347e93499fdc" [[package]] name = "typenum" version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "unicase" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" dependencies = [ - "version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check", ] [[package]] name = "unicode-bidi" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "matches", ] [[package]] name = "unicode-normalization" -version = "0.1.13" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" dependencies = [ - "tinyvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-width" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-xid" -version = "0.1.0" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "url" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" dependencies = [ - "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "form_urlencoded", + "idna", + "matches", + "percent-encoding", ] [[package]] name = "vcpkg" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" [[package]] name = "vec_map" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "walkdir" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" dependencies = [ - "same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "same-file", + "winapi 0.3.9", + "winapi-util", ] [[package]] name = "want" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log", + "try-lock", ] [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" -version = "0.2.64" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "serde", + "serde_json", + "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.64" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" dependencies = [ - "bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.13" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.64" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" dependencies = [ - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro-support 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.64" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" dependencies = [ - "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.64" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" [[package]] name = "wayland-client" -version = "0.23.6" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222b227f47871e47d657c1c5e5360b4af9a877aa9c892716787be1c192c78c42" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "calloop 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "downcast-rs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-commons 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-scanner 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "downcast-rs", + "libc", + "nix", + "scoped-tls", + "wayland-commons", + "wayland-scanner", + "wayland-sys", ] [[package]] name = "wayland-commons" -version = "0.23.6" +version = "0.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "230b3ffeda101f877ff8ecb8573f5d26e7beb345b197807c4df34ec06879a3e6" +dependencies = [ + "nix", + "once_cell", + "smallvec 1.5.1", + "wayland-sys", +] + +[[package]] +name = "wayland-cursor" +version = "0.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aad1b4301cdccfb5f64056a4736e8155a5f4734bac41fdbca80b1fdbe1ab3e1" +dependencies = [ + "nix", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-egl" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308f3ec651a099d1aa4e60625c81f67b4264d72d1b524bc7fb1a7675f7c050b4" dependencies = [ - "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client", + "wayland-sys", ] [[package]] name = "wayland-protocols" -version = "0.23.6" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc16a9db803cae58b45f9a84a6cf364434cc49a95c8b1ef98ffeb467d228bdc9" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-commons 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-scanner 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "wayland-client", + "wayland-commons", + "wayland-scanner", ] [[package]] name = "wayland-scanner" -version = "0.23.6" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee5bd43a1d746efc486515fec561e47205f328b74802b959f10f5500f7e56cc" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "xml-rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "xml-rs", ] [[package]] name = "wayland-sys" -version = "0.23.6" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0814adbecc7ea97869971e1d1c1b657e31863dda6fd768f119ad3dc408a01e58" dependencies = [ - "dlib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dlib", + "lazy_static", + "pkg-config", ] [[package]] name = "web-sys" -version = "0.3.40" +version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" dependencies = [ - "js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys", + "wasm-bindgen", ] +[[package]] +name = "weezl" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2bb9fc8309084dd7cd651336673844c1d47f8ef6d2091ec160b27f5c4aa277" + [[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winit" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cocoa 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-video-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "dispatch 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "instant 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smithay-client-toolkit 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "x11-dl 2.18.5 (registry+https://github.com/rust-lang/crates.io-index)", +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da4eda6fce0eb84bd0a33e3c8794eb902e1033d0a1d5a31bc4f19b1b4bbff597" +dependencies = [ + "bitflags", + "cocoa 0.24.0", + "core-foundation 0.9.1", + "core-graphics 0.22.2", + "core-video-sys", + "dispatch", + "instant", + "lazy_static", + "libc", + "log", + "mio", + "mio-extras", + "ndk", + "ndk-glue", + "ndk-sys", + "objc", + "parking_lot", + "percent-encoding", + "raw-window-handle", + "smithay-client-toolkit", + "stdweb", + "wayland-client", + "winapi 0.3.9", + "x11-dl", ] [[package]] name = "winreg" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9", ] [[package]] name = "ws2_32-sys" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8", + "winapi-build", ] [[package]] name = "x11-clipboard" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89bd49c06c9eb5d98e6ba6536cf64ac9f7ee3a009b2f53996d405b3944f6bcea" dependencies = [ - "xcb 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "xcb", ] [[package]] name = "x11-dl" version = "2.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf981e3a5b3301209754218f962052d4d9ee97e478f4d26d4a6eced34c1fef8" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", + "libc", + "maybe-uninit", + "pkg-config", ] [[package]] name = "xcb" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e917a3f24142e9ff8be2414e36c649d47d6cc2ba81f16201cdef96e533e02de" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "log", +] + +[[package]] +name = "xcursor" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9a231574ae78801646617cefd13bfe94be907c0e4fa979cfd8b770aa3c5d08" +dependencies = [ + "nom", ] [[package]] name = "xdg" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" [[package]] name = "xml-rs" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" [[package]] name = "zip" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58287c28d78507f5f91f2a4cf1e8310e2c76fd4c6932f93ac60fd1ceb402db7d" dependencies = [ - "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", - "podio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[metadata] -"checksum adler 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc9a9dd069569f212bc4330af9f17c4afb5e8ce185e83dbb14f1349dda18b10" -"checksum adler32 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d" -"checksum aes 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f7001367fde4c768a19d1029f0a8be5abd9308e1119846d5bd9ad26297b8faf5" -"checksum aes-soft 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4925647ee64e5056cf231608957ce7c81e12d6d6e316b9ce1404778cc1d35fa7" -"checksum aesni 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d050d39b0b7688b3a3254394c3e30a9d66c41dcf9b05b0e2dbdc623f6505d264" -"checksum andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9b7f09f89872c2b6b29e319377b1fbe91c6f5947df19a25596e121cf19a7b35e" -"checksum android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" -"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" -"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" -"checksum base-x 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1b20b618342cf9891c292c4f5ac2cde7287cc5c87e87e9c769d617793607dec1" -"checksum base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" -"checksum bit-set 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" -"checksum bit-vec 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" -"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -"checksum block-buffer 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -"checksum block-cipher 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fa136449e765dc7faa244561ccae839c394048667929af599b5d931ebe7b7f10" -"checksum bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" -"checksum bytemuck 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37fa13df2292ecb479ec23aa06f4507928bef07839be9ef15281411076629431" -"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" -"checksum bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "118cf036fbb97d0816e3c34b2d7a1e8cfc60f68fcf63d550ddbe9bd5f59c213b" -"checksum calloop 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7aa2097be53a00de9e8fc349fea6d76221f398f5c4fa550d420669906962d160" -"checksum cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)" = "7bbb73db36c1246e9034e307d0fba23f9a2e251faa47ade70c1bd252220c8311" -"checksum cfb8 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba2baac45bade12cdd992418b4b4ea40f6198c03b2de1a9eb7b059f118f445d6" -"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum cgl 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff" -"checksum cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "283944cdecc44bf0b8dd010ec9af888d3b4f142844fdbe026c20ef68148d6fe7" -"checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" -"checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" -"checksum clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "25a904646c0340239dcf7c51677b33928bf24fdf424b79a57909c0109075b2e7" -"checksum clipboard-win 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3a093d6fed558e5fe24c3dfc85a68bb68f1c824f440d3ba5aca189e2998786b" -"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum cocoa 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f29f7768b2d1be17b96158e3285951d366b40211320fb30826a76cb7a0da6400" -"checksum collision 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6107f6be76c2269a9c8d89e707a66122bd3086f987fa508133a5f774e8ac4ced" -"checksum color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" -"checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" -"checksum core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" -"checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" -"checksum core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" -"checksum core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "56790968ab1c8a1202a102e6de05fc6e1ec87da99e4e93e9a7d13efbfc1e95a9" -"checksum core-graphics 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "59e78b2e0aaf43f08e7ae0d6bc96895ef72ff0921c7d4ff4762201b2dba376dd" -"checksum core-video-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "34ecad23610ad9757664d644e369246edde1803fcb43ed72876565098a5d3828" -"checksum cpuid-bool 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d375c433320f6c5057ae04a04376eef4d04ce2801448cf8863a78da99107be4" -"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" -"checksum crossbeam-deque 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" -"checksum crossbeam-epoch 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" -"checksum crossbeam-queue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" -"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -"checksum deflate 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e7e5d2a2273fed52a7f947ee55b092c4057025d7a3e04e5ecdbd25d6c3fb1bd7" -"checksum digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -"checksum discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" -"checksum dispatch 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e93ca78226c51902d7aa8c12c988338aadd9e85ed9c6be8aaac39192ff3605" -"checksum dlib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b11f15d1e3268f140f68d390637d5e76d849782d971ae7063e0da69fe9709a76" -"checksum downcast-rs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52ba6eb47c2131e784a38b726eb54c1e1484904f013e576a25354d0124161af6" -"checksum dtoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" -"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" -"checksum encoding_rs 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171" -"checksum flate2 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)" = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e" -"checksum fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" -"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures-channel 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" -"checksum futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d5e5f4df964fa9c1c2f8bddeb5c3611631cacd93baf810fc8bb2fb4b495c263a" -"checksum futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" -"checksum futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "b35b6263fb1ef523c3056565fa67b1d16f0a8604ff12b11b08c25f28a734c60a" -"checksum futures-executor-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "75236e88bd9fe88e5e8bfcd175b665d0528fe03ca4c5207fabc028c8f9d93e98" -"checksum futures-io 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" -"checksum futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" -"checksum futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" -"checksum futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" -"checksum futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "5ce968633c17e5f97936bd2797b6e38fb56cf16a7422319f7ec2e30d3c470e8d" -"checksum generator 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "add72f17bb81521258fcc8a7a3245b1e184e916bfbe34f0ea89558f440df5c68" -"checksum generic-array 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ac746a5f3bbfdadd6106868134545e684693d54d9d44f6e9588a7d54af0bf980" -"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" -"checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" -"checksum gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a" -"checksum glow 0.4.0 (git+https://github.com/grovesNL/glow?rev=666a7529d0f48a05b32deb919668cd172b0adc94)" = "" -"checksum glutin 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c40ccddfa5fb8aaad6a152bfa6b17f157d6635928a832211534f87c9877e1" -"checksum glutin_egl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "772edef3b28b8ad41e4ea202748e65eefe8e5ffd1f4535f1219793dbb20b3d4c" -"checksum glutin_emscripten_sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80de4146df76e8a6c32b03007bc764ff3249dcaeb4f675d68a06caf1bac363f1" -"checksum glutin_gles2_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07e853d96bebcb8e53e445225c3009758c6f5960d44f2543245f6f07b567dae0" -"checksum glutin_glx_sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "08c243de74d6cf5ea100c788826d2fb9319de315485dd4b310811a663b3809c3" -"checksum glutin_wgl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a93dba7ee3a0feeac0f437141ff25e71ce2066bcf1a706acab1559ffff94eb6a" -"checksum h2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "79b7246d7e4b979c03fa093da39cfb3617a96bbeee6310af63991668d7e843ff" -"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" -"checksum hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" -"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" -"checksum hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" -"checksum http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" -"checksum http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" -"checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" -"checksum hyper 0.13.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e7655b9594024ad0ee439f3b5a7299369dc2a3f459b47c696f9ff676f9aa1f" -"checksum hyper-tls 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" -"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" -"checksum image 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b0553fec6407d63fe2975b794dfb099f3f790bdc958823851af37b26404ab4" -"checksum indexmap 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" -"checksum instant 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7777a24a1ce5de49fcdde84ec46efa487c3af49d5b6e6e0a50367cc5c1096182" -"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -"checksum itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" -"checksum jpeg-decoder 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "5b47b4c4e017b01abdc5bcc126d2d1002e5a75bbe3ce73f9f4f311a916363704" -"checksum js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "ce10c23ad2ea25ceca0093bd3192229da4c5b3c0f2de499c1ecac0d98d452177" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" -"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" -"checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" -"checksum libloading 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2cadb8e769f070c45df05c78c7520eb4cd17061d4ab262e43cfc68b4d00ac71c" -"checksum line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" -"checksum localstoragefs 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba6cbee6bbe7e6ea61ad375952239a9678624f216a0f442ae04a90260e76cdf" -"checksum lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" -"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -"checksum loom 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecc775857611e1df29abba5c41355cdf540e7e9d4acfdf0f355eefee82330b7" -"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" -"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" -"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" -"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" -"checksum memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8" -"checksum mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -"checksum mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -"checksum miniz_oxide 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" -"checksum miniz_oxide 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" -"checksum mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" -"checksum mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" -"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" -"checksum net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" -"checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" -"checksum num 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" -"checksum num-bigint 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" -"checksum num-complex 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" -"checksum num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" -"checksum num-iter 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" -"checksum num-rational 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" -"checksum num-rational 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b4d7360f362cfb50dde8143501e6940b22f644be75a4cc90b2d81968908138" -"checksum num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" -"checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -"checksum objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" -"checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -"checksum objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" -"checksum once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" -"checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" -"checksum opaque-debug 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -"checksum openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)" = "cee6d85f4cb4c4f59a6a85d5b68a233d280c82e29e822913b9c8b129fbf20bdd" -"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" -"checksum openssl-sys 0.9.58 (registry+https://github.com/rust-lang/crates.io-index)" = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" -"checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" -"checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" -"checksum parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" -"checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" -"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" -"checksum parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" -"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -"checksum pin-project 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)" = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17" -"checksum pin-project-internal 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" -"checksum pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" -"checksum pin-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" -"checksum png 0.16.5 (registry+https://github.com/rust-lang/crates.io-index)" = "34ccdd66f6fe4b2433b07e4728e9a013e43233120427046e93ceb709c3a439bf" -"checksum podio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b18befed8bc2b61abc79a457295e7e838417326da1586050b919414073977f19" -"checksum ppv-lite86 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" -"checksum proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" -"checksum proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" -"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" -"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" -"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" -"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -"checksum rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" -"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -"checksum rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" -"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -"checksum raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211" -"checksum rayon 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080" -"checksum rayon-core 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280" -"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" -"checksum remove_dir_all 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -"checksum reqwest 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3b82c9238b305f26f53443e3a4bc8528d64b8d0bee408ec949eb7bf5635ec680" -"checksum rsa_public_encrypt_pkcs1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c82a2353440d2314c25680aefd2e34e7e47e3dd60fddccb2228a6e3b977845ee" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum rusttype 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "310942406a39981bed7e12b09182a221a29e0990f3e7e0c971f131922ed135d5" -"checksum rusttype 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9f61411055101f7b60ecf1041d87fb74205fb20b0c7a723f07ef39174cf6b4c0" -"checksum ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -"checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -"checksum schannel 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -"checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" -"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" -"checksum scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -"checksum security-framework 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" -"checksum security-framework-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" -"checksum serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" -"checksum serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)" = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" -"checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" -"checksum sha-1 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770" -"checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" -"checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" -"checksum simple_asn1 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "57f6bbbcefb91c0dac9b27c91ba13bd2aa29a815fe980f5b1e07d523fbf7b350" -"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum slotmap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "759fd553261805f128e2900bf69ab3d034260bc338caf7f0ee54dbf035c85acd" -"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" -"checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" -"checksum smithay-client-toolkit 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "421c8dc7acf5cb205b88160f8b4cc2c5cfabe210e43b2f80f009f4c1ef910f1d" -"checksum socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" -"checksum stb_truetype 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f77b6b07e862c66a9f3e62a07588fee67cd90a9135a2b942409f195507b4fb51" -"checksum stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -"checksum stdweb-derive 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -"checksum stdweb-internal-macros 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -"checksum stdweb-internal-runtime 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" -"checksum stream-cipher 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09f8ed9974042b8c3672ff3030a69fcc03b74c47c3d1ecb7755e8a3626011e88" -"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum structopt 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "de2f5e239ee807089b62adce73e48c625e0ed80df02c7ab3f068f5db5281065c" -"checksum structopt-derive 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "510413f9de616762a4fbeab62509bf15c729603b72d7cd71280fbca431b1c118" -"checksum syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd" -"checksum syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" -"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -"checksum tiff 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f3b8a87c4da944c3f27e5943289171ac71a6150a79ff6bacfff06d159dfff2f" -"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -"checksum tinyvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" -"checksum tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d099fa27b9702bed751524694adbe393e18b36b204da91eb1cbbbbb4a5ee2d58" -"checksum tokio-tls 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" -"checksum tokio-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" -"checksum tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" -"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" -"checksum typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" -"checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" -"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" -"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" -"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" -"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" -"checksum vcpkg 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" -"checksum vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -"checksum version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" -"checksum want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -"checksum wasm-bindgen 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)" = "6a634620115e4a229108b71bde263bb4220c483b3f07f5ba514ee8d15064c4c2" -"checksum wasm-bindgen-backend 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)" = "3e53963b583d18a5aa3aaae4b4c1cb535218246131ba22a71f05b518098571df" -"checksum wasm-bindgen-futures 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "64487204d863f109eb77e8462189d111f27cb5712cc9fdb3461297a76963a2f6" -"checksum wasm-bindgen-macro 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)" = "3fcfd5ef6eec85623b4c6e844293d4516470d8f19cd72d0d12246017eb9060b8" -"checksum wasm-bindgen-macro-support 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)" = "9adff9ee0e94b926ca81b57f57f86d5545cdcb1d259e21ec9bdd95b901754c75" -"checksum wasm-bindgen-shared 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)" = "7f7b90ea6c632dd06fd765d44542e234d5e63d9bb917ecd64d79778a13bd79ae" -"checksum wayland-client 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "af1080ebe0efabcf12aef2132152f616038f2d7dcbbccf7b2d8c5270fe14bcda" -"checksum wayland-commons 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "bb66b0d1a27c39bbce712b6372131c6e25149f03ffb0cd017cf8f7de8d66dbdb" -"checksum wayland-protocols 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc286643656742777d55dc8e70d144fa4699e426ca8e9d4ef454f4bf15ffcf9" -"checksum wayland-scanner 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93b02247366f395b9258054f964fe293ddd019c3237afba9be2ccbe9e1651c3d" -"checksum wayland-sys 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d94e89a86e6d6d7c7c9b19ebf48a03afaac4af6bc22ae570e9a24124b75358f4" -"checksum web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "7b72fe77fd39e4bd3eaa4412fd299a0be6b3dfe9d2597e2f1c20beb968f41d17" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum winit 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba128780050481f453bec2a115b916dbc6ae79c303dee9bad8b9080bdccd4f5" -"checksum winreg 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" -"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -"checksum x11-clipboard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "89bd49c06c9eb5d98e6ba6536cf64ac9f7ee3a009b2f53996d405b3944f6bcea" -"checksum x11-dl 2.18.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2bf981e3a5b3301209754218f962052d4d9ee97e478f4d26d4a6eced34c1fef8" -"checksum xcb 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5e917a3f24142e9ff8be2414e36c649d47d6cc2ba81f16201cdef96e533e02de" -"checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" -"checksum xml-rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" -"checksum zip 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58287c28d78507f5f91f2a4cf1e8310e2c76fd4c6932f93ac60fd1ceb402db7d" + "crc32fast", + "flate2", + "podio", +] From 641d66579718303d1fc3e606c9041090b5e90cc1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 20 Dec 2020 19:02:12 -0800 Subject: [PATCH 113/137] Update to glow 0.6.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3f3acb48..e4316d50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ path = "src/main.rs" cfg-if = "1.0.0" wasm-bindgen = "0.2.69" glutin = "0.26.0" -glow = { git = "https://github.com/grovesNL/glow", rev = "666a7529d0f48a05b32deb919668cd172b0adc94" } +glow = "0.6.1" byteorder = "1.3.4" serde = "1.0.118" serde_json = "1.0.60" From 8b9fbf007aabcdf08b79aea9e98b315d681ae668 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 20 Dec 2020 19:36:01 -0800 Subject: [PATCH 114/137] Unbox the context to a raw pointer; fixes glow_context() segafault --- src/gl/mod.rs | 6 ++++-- src/main.rs | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index c03da7c7..d4d2a20a 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -24,10 +24,12 @@ static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; /// Inits the gl library. This should be called once a context is ready. pub fn init(vid: &glutin::WindowedContext) { unsafe { - CONTEXT = &mut (gl::Context::from_loader_function(|s| { + let mut context = Box::new(gl::Context::from_loader_function(|s| { println!("Loaded {} = {:?}", s, vid.get_proc_address(s)); vid.get_proc_address(s) as *const _ - })) as *mut glow::Context; + })); + println!("context = {:?}", context); + CONTEXT = Box::into_raw(context); } } diff --git a/src/main.rs b/src/main.rs index 0c120233..8d45dcba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -282,7 +282,6 @@ fn main2() { let renderer = render::Renderer::new(resource_manager.clone()); println!("main 4"); println!("ok"); - std::process::exit(0); let mut ui_container = ui::Container::new(); let mut last_frame = Instant::now(); From be63bbc06585889f856daa51a94a79b159830eb0 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 21 Dec 2020 17:54:01 -0800 Subject: [PATCH 115/137] Revert unnecessary changes to src/render/mod.rs --- src/render/mod.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 16b807b7..163e33e9 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -154,16 +154,23 @@ init_shader! { impl Renderer { pub fn new(res: Arc>) -> Renderer { - let version = 0; //{ res.read().unwrap().version() }; + let version = { res.read().unwrap().version() }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); - println!("returned 2"); - /* + tex.image_3d( + gl::TEXTURE_2D_ARRAY, + 0, + ATLAS_SIZE as u32, + ATLAS_SIZE as u32, + 1, + gl::RGBA, + gl::UNSIGNED_BYTE, + &[0; ATLAS_SIZE * ATLAS_SIZE * 4], + ); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE); - */ let (textures, skin_req, skin_reply) = TextureManager::new(res.clone()); let textures = Arc::new(RwLock::new(textures)); @@ -172,12 +179,10 @@ impl Renderer { shaders::add_shaders(&mut greg); let ui = ui::UIState::new(&greg, textures.clone(), res.clone()); - /* gl::enable(gl::DEPTH_TEST); gl::enable(gl::CULL_FACE_FLAG); gl::cull_face(gl::BACK); gl::front_face(gl::CLOCK_WISE); - */ // Shaders let chunk_shader = ChunkShader::new(&greg); @@ -188,15 +193,8 @@ impl Renderer { // Line Drawer // Clouds - /* gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); gl::depth_func(gl::LESS_OR_EQUAL); - */ - - unsafe { - println!("creating texture"); - let tex = gl::Texture::new(); - } Renderer { resource_version: version, @@ -952,7 +950,8 @@ pub struct TextureManager { free_dynamics: Vec, skins: HashMap>, - //_skin_thread: thread::JoinHandle<()>, + + _skin_thread: thread::JoinHandle<()>, } impl TextureManager { @@ -967,7 +966,7 @@ impl TextureManager { ) { let (tx, rx) = mpsc::channel(); let (stx, srx) = mpsc::channel(); - //let skin_thread = thread::spawn(|| Self::process_skins(srx, tx)); + let skin_thread = thread::spawn(|| Self::process_skins(srx, tx)); let mut tm = TextureManager { textures: HashMap::with_hasher(BuildHasherDefault::default()), version: { @@ -983,7 +982,8 @@ impl TextureManager { dynamic_textures: HashMap::with_hasher(BuildHasherDefault::default()), free_dynamics: Vec::new(), skins: HashMap::with_hasher(BuildHasherDefault::default()), - //_skin_thread: skin_thread, + + _skin_thread: skin_thread, }; tm.add_defaults(); (tm, stx, rx) @@ -1014,7 +1014,6 @@ impl TextureManager { recv: mpsc::Receiver, reply: mpsc::Sender<(String, Option)>, ) { - println!("in process_skins thread"); let client = reqwest::blocking::Client::new(); loop { let hash = match recv.recv() { @@ -1082,7 +1081,8 @@ impl TextureManager { if height == 32 { // Needs changing to the new format let mut new = image::DynamicImage::new_rgba8(64, 64); - new.copy_from(&img, 0, 0); + new.copy_from(&img, 0, 0) + .expect("Invalid png image in skin"); for xx in 0..4 { for yy in 0..16 { for section in 0..4 { From 84ec3e98e414e29d159828ea99a35780d297eb52 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 21 Dec 2020 17:54:48 -0800 Subject: [PATCH 116/137] gl: comment out all glow_context() usages --- src/gl/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index d4d2a20a..e008bade 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -278,9 +278,11 @@ impl Texture { pub fn new() -> Texture { println!("create_texture"); Texture(unsafe { - glow_context() + 0 + /*glow_context() .create_texture() .expect("create texture failed") + */ }) } @@ -288,7 +290,7 @@ impl Texture { pub fn bind(&self, target: TextureTarget) { println!("bind_texture"); unsafe { - glow_context().bind_texture(target, Some(self.0)); + //glow_context().bind_texture(target, Some(self.0)); } } @@ -886,6 +888,8 @@ pub struct Framebuffer(u32); pub fn check_framebuffer_status() { unsafe { + return; + println!("check_framebuffer_status()"); let status = glow_context().check_framebuffer_status(gl::FRAMEBUFFER); let s = match status { gl::FRAMEBUFFER_UNDEFINED => "GL_FRAMEBUFFER_UNDEFINED", From f0acbe9589248d3245a13ddfc8d8fc48e7637b68 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 21 Dec 2020 17:54:55 -0800 Subject: [PATCH 117/137] Revert "gl: comment out all glow_context() usages" This reverts commit 84ec3e98e414e29d159828ea99a35780d297eb52. --- src/gl/mod.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index e008bade..d4d2a20a 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -278,11 +278,9 @@ impl Texture { pub fn new() -> Texture { println!("create_texture"); Texture(unsafe { - 0 - /*glow_context() + glow_context() .create_texture() .expect("create texture failed") - */ }) } @@ -290,7 +288,7 @@ impl Texture { pub fn bind(&self, target: TextureTarget) { println!("bind_texture"); unsafe { - //glow_context().bind_texture(target, Some(self.0)); + glow_context().bind_texture(target, Some(self.0)); } } @@ -888,8 +886,6 @@ pub struct Framebuffer(u32); pub fn check_framebuffer_status() { unsafe { - return; - println!("check_framebuffer_status()"); let status = glow_context().check_framebuffer_status(gl::FRAMEBUFFER); let s = match status { gl::FRAMEBUFFER_UNDEFINED => "GL_FRAMEBUFFER_UNDEFINED", From c8dd631cbc48754f41a12fc7d7b2380fb0ef045a Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 21 Dec 2020 17:56:13 -0800 Subject: [PATCH 118/137] Disable add_screen() for now to avoid stack overflow crash --- src/screen/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/screen/mod.rs b/src/screen/mod.rs index bbbb635d..12a70ed2 100644 --- a/src/screen/mod.rs +++ b/src/screen/mod.rs @@ -70,6 +70,7 @@ impl ScreenSystem { } pub fn add_screen(&mut self, screen: Box) { + return; // TODO: fix crash self.screens.push(ScreenInfo { screen, init: false, From 0311911e0f2260b5c2b03930d61fa2026542dfea Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 21 Dec 2020 19:07:36 -0800 Subject: [PATCH 119/137] Add debugging to help find the __rust_probestack crash in reload_server_list --- src/screen/mod.rs | 1 - src/screen/server_list.rs | 1 + src/ui/mod.rs | 13 +++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/screen/mod.rs b/src/screen/mod.rs index 12a70ed2..bbbb635d 100644 --- a/src/screen/mod.rs +++ b/src/screen/mod.rs @@ -70,7 +70,6 @@ impl ScreenSystem { } pub fn add_screen(&mut self, screen: Box) { - return; // TODO: fix crash self.screens.push(ScreenInfo { screen, init: false, diff --git a/src/screen/server_list.rs b/src/screen/server_list.rs index 073dd4f2..1c1bf143 100644 --- a/src/screen/server_list.rs +++ b/src/screen/server_list.rs @@ -99,6 +99,7 @@ impl ServerList { renderer: &mut render::Renderer, ui_container: &mut ui::Container, ) { + println!("reload_server_list"); let elements = self.elements.as_mut().unwrap(); *self.needs_reload.borrow_mut() = false; { diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4b43a35f..e32e4255 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -349,9 +349,20 @@ impl Container { e.tick(renderer); } for e in &self.elements { + let (w, h) = e.get_size(); + let (ox, oy) = e.get_position(); + println!("draw w={}, h={}, ox={}, oy={}", w,h,ox,oy); + if oy as i32==0{ println!("skip 0"); continue;} + + println!("compute_draw_region {}x{}", sw, sh); + if oy as i32==100{ + println!("oy=100"); // crashes 3rd time hits here, drawing an Image UIElement - b src/ui/mod.rs:359 + } let r = Self::compute_draw_region(e, sw, sh, &SCREEN); if r.intersects(&SCREEN) { + println!("\tintersects - drawing {}x{} {}x{} {}",sw,sh,width,height,delta); let data = e.draw(renderer, &r, sw, sh, width, height, delta); + println!("\tdata={:?}", data); renderer.ui.add_bytes(&data); } } @@ -851,6 +862,8 @@ impl UIElement for Image { height: f64, delta: f64, ) -> &mut [u8] { + println!("UIImage Image draw()"); + return &mut self.data; if self.check_rebuild() { self.data.clear(); let texture = render::Renderer::get_texture(renderer.get_textures_ref(), &self.texture); From 2d72135b50ea6d3da5238884e6337794dd327e2e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 08:50:40 -0800 Subject: [PATCH 120/137] Log backtraces from glow_context() --- Cargo.toml | 2 ++ src/gl/mod.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e4316d50..399891d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,8 @@ path = "src/main.rs" #opt-level = 1 [dependencies] +backtrace = "*" +trace = "*" cfg-if = "1.0.0" wasm-bindgen = "0.2.69" glutin = "0.26.0" diff --git a/src/gl/mod.rs b/src/gl/mod.rs index d4d2a20a..759a13ec 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -18,6 +18,7 @@ use log::{error, info}; use std::mem; use std::ops::BitOr; use std::ops::{Deref, DerefMut}; +use backtrace::Backtrace; static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; @@ -36,6 +37,8 @@ pub fn init(vid: &glutin::WindowedContext) { fn glow_context() -> &'static glow::Context { unsafe { println!("glow_context = {:?}", CONTEXT); + let bt = Backtrace::new(); + println!("\tbt = {:?}", bt); CONTEXT.as_ref().unwrap() } } @@ -286,7 +289,7 @@ impl Texture { /// Binds the texture to the passed target. pub fn bind(&self, target: TextureTarget) { - println!("bind_texture"); + println!("bind_texture {} target {:?}", self.0, target); unsafe { glow_context().bind_texture(target, Some(self.0)); } From 7ed785386af2f71fb5f038a4446765d1c73a8bf6 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 09:08:30 -0800 Subject: [PATCH 121/137] Enable most glow methods --- src/gl/mod.rs | 137 ++++++++++++++++++++++---------------------------- src/ui/mod.rs | 1 - 2 files changed, 60 insertions(+), 78 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 759a13ec..c13304ae 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -59,20 +59,20 @@ pub const POINTS: DrawType = gl::POINTS; pub fn draw_arrays(ty: DrawType, offset: usize, count: usize) { unsafe { - //glow_context().draw_arrays(ty, offset as i32, count as i32); + glow_context().draw_arrays(ty, offset as i32, count as i32); } } pub fn draw_elements(ty: DrawType, count: i32, dty: Type, offset: usize) { unsafe { - //glow_context().draw_elements(ty, count, dty, offset as i32); + glow_context().draw_elements(ty, count, dty, offset as i32); } } // Sets the size of the viewport of this context. pub fn viewport(x: i32, y: i32, w: i32, h: i32) { unsafe { - //glow_context().viewport(x, y, w, h); + glow_context().viewport(x, y, w, h); } } @@ -80,7 +80,7 @@ pub fn viewport(x: i32, y: i32, w: i32, h: i32) { /// when Clear is called with the color flag. pub fn clear_color(r: f32, g: f32, b: f32, a: f32) { unsafe { - //glow_context().clear_color(r, g, b, a); + glow_context().clear_color(r, g, b, a); } } @@ -115,13 +115,13 @@ impl BitOr for ClearFlags { /// Clears the buffers specified by the passed flags. pub fn clear(flags: ClearFlags) { unsafe { - //glow_context().clear(flags.internal()) + glow_context().clear(flags.internal()) } } pub fn depth_mask(f: bool) { unsafe { - //glow_context().depth_mask(f); + glow_context().depth_mask(f); } } @@ -137,7 +137,7 @@ pub const EQUAL: Func = gl::EQUAL; pub fn depth_func(f: Func) { unsafe { - //glow_context().depth_func(f); + glow_context().depth_func(f); } } @@ -153,14 +153,14 @@ pub const MULTISAMPLE: Flag = gl::MULTISAMPLE; /// Enables the passed flag. pub fn enable(f: Flag) { unsafe { - //glow_context().enable(f); + glow_context().enable(f); } } /// Disables the passed flag. pub fn disable(f: Flag) { unsafe { - //glow_context().disable(f); + glow_context().disable(f); } } @@ -168,7 +168,7 @@ pub fn disable(f: Flag) { /// currently active one. pub fn active_texture(id: u32) { unsafe { - //glow_context().active_texture(gl::TEXTURE0 + id); + glow_context().active_texture(gl::TEXTURE0 + id); } } @@ -182,7 +182,7 @@ pub const ZERO_FACTOR: Factor = gl::ZERO; /// Sets the factors to be used when blending. pub fn blend_func(s_factor: Factor, d_factor: Factor) { unsafe { - //glow_context().blend_func(s_factor, d_factor); + glow_context().blend_func(s_factor, d_factor); } } @@ -193,7 +193,7 @@ pub fn blend_func_separate( d_factor_a: Factor, ) { unsafe { - //glow_context().blend_func_separate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); + glow_context().blend_func_separate(s_factor_rgb, d_factor_rgb, s_factor_a, d_factor_a); } } @@ -205,7 +205,7 @@ pub const FRONT: Face = gl::FRONT; /// Sets the face to be culled by the gpu. pub fn cull_face(face: Face) { unsafe { - //glow_context().cull_face(face); + glow_context().cull_face(face); } } @@ -219,7 +219,7 @@ pub const COUNTER_CLOCK_WISE: FaceDirection = gl::CCW; /// front face (e.g. for culling). pub fn front_face(dir: FaceDirection) { unsafe { - //glow_context().front_face(dir) + glow_context().front_face(dir) } } @@ -526,29 +526,31 @@ pub struct Program(u32); impl Program { pub fn new() -> Program { - Program(0) //unsafe { glow_context().create_program().expect("program creation failed") }) + Program(unsafe { + glow_context().create_program().expect("program creation failed") + }) } pub fn attach_shader(&self, shader: Shader) { unsafe { - //glow_context().attach_shader(self.0, shader.0); + glow_context().attach_shader(self.0, shader.0); } } pub fn link(&self) { unsafe { - //glow_context().link_program(self.0); + glow_context().link_program(self.0); } } pub fn use_program(&self) { unsafe { - //glow_context().use_program(Some(self.0)); + glow_context().use_program(Some(self.0)); } } pub fn uniform_location(&self, name: &str) -> Option { - /* + /* TODO: ffi? let c_name = ffi::CString::new(name).unwrap(); let u = unsafe { glow_context().get_uniform_location(self.0, c_name.as_ptr()) @@ -556,14 +558,12 @@ impl Program { if let Some(u) = u { Some(Uniform(u)) } else { - None - } */ - Some(Uniform(0)) + None + //} } pub fn attribute_location(&self, name: &str) -> Option { - /* let a = unsafe { glow_context().get_attrib_location(self.0, name) }; @@ -572,15 +572,13 @@ impl Program { } else { None } - */ - Some(Attribute(0)) } } impl Drop for Program { fn drop(&mut self) { unsafe { - //glow_context().delete_program(self.0); + glow_context().delete_program(self.0); } } } @@ -589,39 +587,33 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { - Shader(0) //unsafe { glow_context().create_shader(ty).expect("failed to create shader") }) + Shader(unsafe { + glow_context().create_shader(ty).expect("failed to create shader") + }) } pub fn set_source(&self, src: &str) { - /* TODO unsafe { glow_context().shader_source(self.0, src); } - */ } pub fn compile(&self) { unsafe { - //glow_context().compile_shader(self.0); + glow_context().compile_shader(self.0); } } pub fn get_shader_compile_status(&self) -> bool { - true - /* TODO unsafe { glow_context().get_shader_compile_status(self.0) } - */ } pub fn get_info_log(&self) -> String { - /* TODO unsafe { glow_context().get_shader_info_log(self.0) } - */ - "".to_string() } } @@ -631,37 +623,37 @@ pub struct Uniform(u32); impl Uniform { pub fn set_int(&self, val: i32) { unsafe { - //glow_context().uniform_1_i32(Some(&self.0), val); + glow_context().uniform_1_i32(Some(&self.0), val); } } pub fn set_int3(&self, x: i32, y: i32, z: i32) { unsafe { - //glow_context().uniform_3_i32(Some(&self.0), x, y, z); + glow_context().uniform_3_i32(Some(&self.0), x, y, z); } } pub fn set_float(&self, val: f32) { unsafe { - //glow_context().uniform_1_f32(Some(&self.0), val); + glow_context().uniform_1_f32(Some(&self.0), val); } } pub fn set_float2(&self, x: f32, y: f32) { unsafe { - //glow_context().uniform_2_f32(Some(&self.0), x, y); + glow_context().uniform_2_f32(Some(&self.0), x, y); } } pub fn set_float3(&self, x: f32, y: f32, z: f32) { unsafe { - //glow_context().uniform_3_f32(Some(&self.0), x, y, z); + glow_context().uniform_3_f32(Some(&self.0), x, y, z); } } pub fn set_float4(&self, x: f32, y: f32, z: f32, w: f32) { unsafe { - //glow_context().uniform_4_f32(Some(&self.0), x, y, z, w); + glow_context().uniform_4_f32(Some(&self.0), x, y, z, w); } } @@ -674,14 +666,12 @@ impl Uniform { pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - // TODO //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), 1, false as u8, m.as_ptr()); } } pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { unsafe { - // TODO //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe } } @@ -693,38 +683,34 @@ pub struct Attribute(i32); impl Attribute { pub fn enable(&self) { unsafe { - //glow_context().enable_vertex_attrib_array(self.0 as u32); + glow_context().enable_vertex_attrib_array(self.0 as u32); } } pub fn disable(&self) { unsafe { - //glow_context().disable_vertex_attrib_array(self.0 as u32); + glow_context().disable_vertex_attrib_array(self.0 as u32); } } pub fn vertex_pointer(&self, size: i32, ty: Type, normalized: bool, stride: i32, offset: i32) { unsafe { - /* glow_context().vertex_attrib_pointer_f32(self.0 as u32, size, ty, normalized, stride, offset); - */ } } pub fn vertex_pointer_int(&self, size: i32, ty: Type, stride: i32, offset: i32) { unsafe { - /* glow_context().vertex_attrib_pointer_i32(self.0 as u32, size, ty, stride, offset); - */ } } } @@ -738,7 +724,8 @@ pub struct VertexArray(u32); impl VertexArray { /// Allocates a new `VertexArray`. pub fn new() -> VertexArray { - VertexArray(0) //unsafe { glow_context().create_vertex_array().expect("create vertex array failed") }) + VertexArray(unsafe { + glow_context().create_vertex_array().expect("create vertex array failed") }) } /// Marks the `VertexArray` as the currently active one, this @@ -746,7 +733,7 @@ impl VertexArray { /// this `VertexArray`. pub fn bind(&self) { unsafe { - //glow_context().bind_vertex_array(Some(self.0)); + glow_context().bind_vertex_array(Some(self.0)); } } } @@ -754,7 +741,7 @@ impl VertexArray { impl Drop for VertexArray { fn drop(&mut self) { unsafe { - //glow_context().delete_vertex_array(self.0); + glow_context().delete_vertex_array(self.0); } self.0 = 0; } @@ -795,7 +782,8 @@ pub struct Buffer(u32); impl Buffer { /// Allocates a new Buffer. pub fn new() -> Buffer { - Buffer(0) //unsafe { glow_context().create_buffer().expect("create buffer failed") }) + Buffer(unsafe { + glow_context().create_buffer().expect("create buffer failed") }) } /// Makes the buffer the currently active one for the given target. @@ -803,23 +791,21 @@ impl Buffer { /// (Data, Map etc). pub fn bind(&self, target: BufferTarget) { unsafe { - //glow_context().bind_buffer(target, Some(self.0)); + glow_context().bind_buffer(target, Some(self.0)); } } pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { unsafe { - /* glow_context().buffer_data_u8_slice(target, data, usage); - */ } } pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) { unsafe { - //glow_context().buffer_sub_data_u8_slice(target, 0, data); + glow_context().buffer_sub_data_u8_slice(target, 0, data); } } @@ -833,7 +819,7 @@ impl Buffer { pub fn map(&self, target: BufferTarget, access: Access, length: usize) -> MappedBuffer { unsafe { MappedBuffer { - inner: vec![], //Vec::from_raw_parts(glow_context().map_buffer_range(target, 0, length as i32, access) as *mut u8, 0, length), + inner: Vec::from_raw_parts(glow_context().map_buffer_range(target, 0, length as i32, access) as *mut u8, 0, length), target, } } @@ -843,7 +829,7 @@ impl Buffer { impl Drop for Buffer { fn drop(&mut self) { unsafe { - //glow_context().delete_buffer(self.0); + glow_context().delete_buffer(self.0); } } } @@ -870,7 +856,7 @@ impl DerefMut for MappedBuffer { impl Drop for MappedBuffer { fn drop(&mut self) { unsafe { - //glow_context().unmap_buffer(self.target); + glow_context().unmap_buffer(self.target); } mem::forget(mem::replace(&mut self.inner, Vec::new())); } @@ -918,7 +904,6 @@ pub fn check_framebuffer_status() { pub fn check_gl_error() { unsafe { - /* loop { let err = glow_context().get_error(); if err == gl::NO_ERROR { @@ -927,30 +912,30 @@ pub fn check_gl_error() { error!("glGetError = {}", err); } - */ } } impl Framebuffer { pub fn new() -> Framebuffer { - Framebuffer(0) //unsafe { glow_context().create_framebuffer().expect("create framebuffer failed") }) + Framebuffer(unsafe { + glow_context().create_framebuffer().expect("create framebuffer failed") }) } pub fn bind(&self) { unsafe { - //glow_context().bind_framebuffer(gl::FRAMEBUFFER, Some(self.0)); + glow_context().bind_framebuffer(gl::FRAMEBUFFER, Some(self.0)); } } pub fn bind_read(&self) { unsafe { - //glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, Some(self.0)); + glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, Some(self.0)); } } pub fn bind_draw(&self) { unsafe { - //glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, Some(self.0)); + glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, Some(self.0)); } } @@ -962,7 +947,7 @@ impl Framebuffer { level: i32, ) { unsafe { - //glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, Some(tex.0), level); + glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, Some(tex.0), level); } } } @@ -970,38 +955,38 @@ impl Framebuffer { impl Drop for Framebuffer { fn drop(&mut self) { unsafe { - //glow_context().delete_framebuffer(self.0); + glow_context().delete_framebuffer(self.0); } } } pub fn unbind_framebuffer() { unsafe { - //glow_context().bind_framebuffer(gl::FRAMEBUFFER, None); + glow_context().bind_framebuffer(gl::FRAMEBUFFER, None); } } pub fn unbind_framebuffer_read() { unsafe { - //glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, None); + glow_context().bind_framebuffer(gl::READ_FRAMEBUFFER, None); } } pub fn unbind_framebuffer_draw() { unsafe { - //glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, None); + glow_context().bind_framebuffer(gl::DRAW_FRAMEBUFFER, None); } } pub fn draw_buffers(bufs: &[Attachment]) { unsafe { - //glow_context().draw_buffers(bufs); + glow_context().draw_buffers(bufs); } } pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { unsafe { - //glow_context().bind_frag_data_location(p.0, cn, name) + glow_context().bind_frag_data_location(p.0, cn, name) } } @@ -1017,7 +1002,6 @@ pub fn blit_framebuffer( mask: ClearFlags, filter: TextureValue, ) { - /* unsafe { glow_context().blit_framebuffer( sx0, sy0, sx1, sy1, @@ -1025,7 +1009,6 @@ pub fn blit_framebuffer( mask.internal(), filter as u32 ); } - */ } pub type TargetBuffer = u32; @@ -1034,6 +1017,6 @@ pub const COLOR: TargetBuffer = gl::COLOR; pub fn clear_buffer(buffer: TargetBuffer, draw_buffer: u32, values: &mut [f32]) { unsafe { // TODO: why does glow have &mut on clear buffer values, why would it change the color? - //glow_context().clear_buffer_f32_slice(buffer, draw_buffer, values); + glow_context().clear_buffer_f32_slice(buffer, draw_buffer, values); } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index e32e4255..beddd913 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -352,7 +352,6 @@ impl Container { let (w, h) = e.get_size(); let (ox, oy) = e.get_position(); println!("draw w={}, h={}, ox={}, oy={}", w,h,ox,oy); - if oy as i32==0{ println!("skip 0"); continue;} println!("compute_draw_region {}x{}", sw, sh); if oy as i32==100{ From 3e04828f31765237ffd6c0e41600abf028ce94fa Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 09:16:15 -0800 Subject: [PATCH 122/137] Implement uniform_location, fixing unwrap None failed --- src/gl/mod.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index c13304ae..3b6ce177 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -38,7 +38,7 @@ fn glow_context() -> &'static glow::Context { unsafe { println!("glow_context = {:?}", CONTEXT); let bt = Backtrace::new(); - println!("\tbt = {:?}", bt); + //println!("\tbt = {:?}", bt); CONTEXT.as_ref().unwrap() } } @@ -493,11 +493,9 @@ impl Texture { param: TextureParameter, value: TextureValue, ) { - /* TODO unsafe { glow_context().tex_parameter_i32(target, param, value); } - */ } } @@ -550,17 +548,14 @@ impl Program { } pub fn uniform_location(&self, name: &str) -> Option { - /* TODO: ffi? - let c_name = ffi::CString::new(name).unwrap(); let u = unsafe { - glow_context().get_uniform_location(self.0, c_name.as_ptr()) + glow_context().get_uniform_location(self.0, name) }; if let Some(u) = u { Some(Uniform(u)) } else { - */ None - //} + } } pub fn attribute_location(&self, name: &str) -> Option { From bb560de8e0442dea2b8fb8fa566bbe25c500a0af Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 19:06:24 -0800 Subject: [PATCH 123/137] Use tex_image_2d_multisample added in glow fork https://github.com/iceiix/glow/pull/1 until #442 renderbuffer --- Cargo.toml | 2 +- src/gl/mod.rs | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 399891d8..d6ab1b9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ trace = "*" cfg-if = "1.0.0" wasm-bindgen = "0.2.69" glutin = "0.26.0" -glow = "0.6.1" +glow = { git = "https://github.com/iceiix/glow", branch = "ms" } byteorder = "1.3.4" serde = "1.0.118" serde_json = "1.0.60" diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 3b6ce177..b626faf4 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -405,7 +405,6 @@ impl Texture { fixed: bool, ) { unsafe { - /* let result: i32 = glow_context().get_parameter_i32(gl::MAX_SAMPLES); let use_samples = if samples > result { @@ -414,18 +413,14 @@ impl Texture { } else { samples }; - */ - // TODO: switch to glRenderbufferStorageMultisample? - // from glTexImage2DMultisample which isn't in WebGL - /* + // TODO: switch to glRenderbufferStorageMultisample https://github.com/iceiix/stevenarella/pull/442 glow_context().tex_image_2d_multisample(target, use_samples, format, width as i32, height as i32, - fixed as u8 + fixed ); - */ } } From 8417df54415e44edd76275a7dedf3c053ea4d681 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 19:11:53 -0800 Subject: [PATCH 124/137] Enable more tex_image calls --- src/gl/mod.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index b626faf4..5360eed1 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -325,7 +325,6 @@ impl Texture { pix: Option<&[u8]>, ) { unsafe { - /* glow_context().tex_image_2d(target, level, format as i32, @@ -336,7 +335,6 @@ impl Texture { ty, pix ); - */ } } @@ -380,7 +378,6 @@ impl Texture { pix: Option<&[u8]>, ) { unsafe { - /* glow_context().tex_image_2d(target, level, internal_format as i32, @@ -391,7 +388,6 @@ impl Texture { ty, pix ); - */ } } @@ -436,7 +432,6 @@ impl Texture { pix: &[u8], ) { unsafe { - /* glow_context().tex_image_3d(target, level, format as i32, @@ -447,7 +442,6 @@ impl Texture { format, ty, Some(pix)); - */ } } From 68c74a5f1f8f706ff20c192b1bac9550979c89fd Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 19:38:55 -0800 Subject: [PATCH 125/137] Add tex_sub_image_3d, using PixelUnpackData::Slice --- src/gl/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 5360eed1..11b49e3a 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -13,7 +13,7 @@ // limitations under the License. use glow as gl; -use glow::HasContext; +use glow::{HasContext, PixelUnpackData}; use log::{error, info}; use std::mem; use std::ops::BitOr; @@ -460,8 +460,7 @@ impl Texture { pix: &[u8], ) { unsafe { - /* - glow_context().tex_sub_image_3d_u8_slice(target, + glow_context().tex_sub_image_3d(target, level, x as i32, y as i32, @@ -471,8 +470,7 @@ impl Texture { depth as i32, format, ty, - Some(pix)); - */ + PixelUnpackData::Slice(pix)); } } @@ -650,7 +648,8 @@ impl Uniform { pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), 1, false as u8, m.as_ptr()); + // TODO: cgmath::Matrix to &[f32] + //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), false, m.as_ptr()); } } From 6706762301505c21280c7a71d3abf9bb1a3d45f6 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 19:52:35 -0800 Subject: [PATCH 126/137] set_matrix4: transmute the Matrix4 since it is repr(C) --- src/gl/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 11b49e3a..568e4d31 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -648,8 +648,8 @@ impl Uniform { pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { use cgmath::Matrix; unsafe { - // TODO: cgmath::Matrix to &[f32] - //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), false, m.as_ptr()); + let slice: &[f32; 4*4] = std::mem::transmute(m); + glow_context().uniform_matrix_4_f32_slice(Some(&self.0), false, slice); } } From b15c9264c40f42d214be5d598cdc02841cd032b1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 19:59:38 -0800 Subject: [PATCH 127/137] get_pixels -> get_tex_image -> glGetTexImage, with PixelPackData::Slice --- src/gl/mod.rs | 12 ++++-------- src/ui/mod.rs | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 568e4d31..b54c94fd 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -13,7 +13,7 @@ // limitations under the License. use glow as gl; -use glow::{HasContext, PixelUnpackData}; +use glow::{HasContext, PixelPackData, PixelUnpackData}; use log::{error, info}; use std::mem; use std::ops::BitOr; @@ -37,8 +37,7 @@ pub fn init(vid: &glutin::WindowedContext) { fn glow_context() -> &'static glow::Context { unsafe { println!("glow_context = {:?}", CONTEXT); - let bt = Backtrace::new(); - //println!("\tbt = {:?}", bt); + //let bt = Backtrace::new(); println!("\tbt = {:?}", bt); CONTEXT.as_ref().unwrap() } } @@ -304,13 +303,11 @@ impl Texture { pixels: &mut [u8], ) { unsafe { - /* - glow_context().get_tex_image_u8_slice(target, + glow_context().get_tex_image(target, level, format, ty, - Some(pixels)); - */ + PixelPackData::Slice(pixels)); } } @@ -646,7 +643,6 @@ impl Uniform { } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { - use cgmath::Matrix; unsafe { let slice: &[f32; 4*4] = std::mem::transmute(m); glow_context().uniform_matrix_4_f32_slice(Some(&self.0), false, slice); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index beddd913..4ad53da5 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -862,7 +862,6 @@ impl UIElement for Image { delta: f64, ) -> &mut [u8] { println!("UIImage Image draw()"); - return &mut self.data; if self.check_rebuild() { self.data.clear(); let texture = render::Renderer::get_texture(renderer.get_textures_ref(), &self.texture); From c58a4bcc878f84409449aecc5c07746ff03fbd0e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 20:04:26 -0800 Subject: [PATCH 128/137] Wrap sub_image_2d (glTexSubImage2D) and fix warnings --- src/gl/mod.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index b54c94fd..0eec45c9 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -18,14 +18,13 @@ use log::{error, info}; use std::mem; use std::ops::BitOr; use std::ops::{Deref, DerefMut}; -use backtrace::Backtrace; static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; /// Inits the gl library. This should be called once a context is ready. pub fn init(vid: &glutin::WindowedContext) { unsafe { - let mut context = Box::new(gl::Context::from_loader_function(|s| { + let context = Box::new(gl::Context::from_loader_function(|s| { println!("Loaded {} = {:?}", s, vid.get_proc_address(s)); vid.get_proc_address(s) as *const _ })); @@ -37,7 +36,7 @@ pub fn init(vid: &glutin::WindowedContext) { fn glow_context() -> &'static glow::Context { unsafe { println!("glow_context = {:?}", CONTEXT); - //let bt = Backtrace::new(); println!("\tbt = {:?}", bt); + //use backtrace::Backtrace; let bt = Backtrace::new(); println!("\tbt = {:?}", bt); CONTEXT.as_ref().unwrap() } } @@ -348,8 +347,7 @@ impl Texture { pix: &[u8], ) { unsafe { - /* - glow_context().tex_sub_image_2d_u8_slice(target, + glow_context().tex_sub_image_2d(target, level, x as i32, y as i32, @@ -357,9 +355,8 @@ impl Texture { height as i32, format, ty, - Some(pix) + PixelUnpackData::Slice(pix) ); - */ } } @@ -637,7 +634,7 @@ impl Uniform { } #[allow(clippy::missing_safety_doc)] - pub unsafe fn set_float_multi_raw(&self, data: *const f32, len: usize) { + pub unsafe fn set_float_multi_raw(&self, _data: *const f32, _len: usize) { // TODO: takes a slice, not a raw pointer //TODO glow_context().uniform_4_f32_slice(Some(&self.0), len as i32, data); } @@ -649,10 +646,11 @@ impl Uniform { } } - pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { + pub fn set_matrix4_multi(&self, _m: &[::cgmath::Matrix4]) { + /* TODO: transmute all slices unsafe { //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe - } + }*/ } } From cd256a51bb5c95061645736e6a494f342b6f3a5a Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 20:25:26 -0800 Subject: [PATCH 129/137] cargo fmt --- src/gl/mod.rs | 246 +++++++++++++++++++++++++++----------------------- src/ui/mod.rs | 9 +- 2 files changed, 138 insertions(+), 117 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 0eec45c9..a7699427 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -112,9 +112,7 @@ impl BitOr for ClearFlags { /// Clears the buffers specified by the passed flags. pub fn clear(flags: ClearFlags) { - unsafe { - glow_context().clear(flags.internal()) - } + unsafe { glow_context().clear(flags.internal()) } } pub fn depth_mask(f: bool) { @@ -216,9 +214,7 @@ pub const COUNTER_CLOCK_WISE: FaceDirection = gl::CCW; /// Sets the direction of vertices used to specify the /// front face (e.g. for culling). pub fn front_face(dir: FaceDirection) { - unsafe { - glow_context().front_face(dir) - } + unsafe { glow_context().front_face(dir) } } /// `Type` is a type of data used by various operations. @@ -302,11 +298,7 @@ impl Texture { pixels: &mut [u8], ) { unsafe { - glow_context().get_tex_image(target, - level, - format, - ty, - PixelPackData::Slice(pixels)); + glow_context().get_tex_image(target, level, format, ty, PixelPackData::Slice(pixels)); } } @@ -321,15 +313,16 @@ impl Texture { pix: Option<&[u8]>, ) { unsafe { - glow_context().tex_image_2d(target, - level, - format as i32, - width as i32, - height as i32, - 0, - format, - ty, - pix + glow_context().tex_image_2d( + target, + level, + format as i32, + width as i32, + height as i32, + 0, + format, + ty, + pix, ); } } @@ -347,15 +340,16 @@ impl Texture { pix: &[u8], ) { unsafe { - glow_context().tex_sub_image_2d(target, - level, - x as i32, - y as i32, - width as i32, - height as i32, - format, - ty, - PixelUnpackData::Slice(pix) + glow_context().tex_sub_image_2d( + target, + level, + x as i32, + y as i32, + width as i32, + height as i32, + format, + ty, + PixelUnpackData::Slice(pix), ); } } @@ -372,15 +366,16 @@ impl Texture { pix: Option<&[u8]>, ) { unsafe { - glow_context().tex_image_2d(target, - level, - internal_format as i32, - width as i32, - height as i32, - 0, - format, - ty, - pix + glow_context().tex_image_2d( + target, + level, + internal_format as i32, + width as i32, + height as i32, + 0, + format, + ty, + pix, ); } } @@ -395,21 +390,24 @@ impl Texture { fixed: bool, ) { unsafe { - let result: i32 = glow_context().get_parameter_i32(gl::MAX_SAMPLES); - let use_samples = - if samples > result { - info!("glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", samples, result); - result - } else { - samples - }; + let result: i32 = glow_context().get_parameter_i32(gl::MAX_SAMPLES); + let use_samples = if samples > result { + info!( + "glTexImage2DMultisample: requested {} samples but GL_MAX_SAMPLES is {}", + samples, result + ); + result + } else { + samples + }; // TODO: switch to glRenderbufferStorageMultisample https://github.com/iceiix/stevenarella/pull/442 - glow_context().tex_image_2d_multisample(target, - use_samples, - format, - width as i32, - height as i32, - fixed + glow_context().tex_image_2d_multisample( + target, + use_samples, + format, + width as i32, + height as i32, + fixed, ); } } @@ -426,16 +424,18 @@ impl Texture { pix: &[u8], ) { unsafe { - glow_context().tex_image_3d(target, - level, - format as i32, - width as i32, - height as i32, - depth as i32, - 0, - format, - ty, - Some(pix)); + glow_context().tex_image_3d( + target, + level, + format as i32, + width as i32, + height as i32, + depth as i32, + 0, + format, + ty, + Some(pix), + ); } } @@ -454,17 +454,19 @@ impl Texture { pix: &[u8], ) { unsafe { - glow_context().tex_sub_image_3d(target, - level, - x as i32, - y as i32, - z as i32, - width as i32, - height as i32, - depth as i32, - format, - ty, - PixelUnpackData::Slice(pix)); + glow_context().tex_sub_image_3d( + target, + level, + x as i32, + y as i32, + z as i32, + width as i32, + height as i32, + depth as i32, + format, + ty, + PixelUnpackData::Slice(pix), + ); } } @@ -506,7 +508,9 @@ pub struct Program(u32); impl Program { pub fn new() -> Program { Program(unsafe { - glow_context().create_program().expect("program creation failed") + glow_context() + .create_program() + .expect("program creation failed") }) } @@ -529,9 +533,7 @@ impl Program { } pub fn uniform_location(&self, name: &str) -> Option { - let u = unsafe { - glow_context().get_uniform_location(self.0, name) - }; + let u = unsafe { glow_context().get_uniform_location(self.0, name) }; if let Some(u) = u { Some(Uniform(u)) } else { @@ -540,9 +542,7 @@ impl Program { } pub fn attribute_location(&self, name: &str) -> Option { - let a = unsafe { - glow_context().get_attrib_location(self.0, name) - }; + let a = unsafe { glow_context().get_attrib_location(self.0, name) }; if let Some(a) = a { Some(Attribute(a as i32)) } else { @@ -564,7 +564,9 @@ pub struct Shader(u32); impl Shader { pub fn new(ty: ShaderType) -> Shader { Shader(unsafe { - glow_context().create_shader(ty).expect("failed to create shader") + glow_context() + .create_shader(ty) + .expect("failed to create shader") }) } @@ -581,15 +583,11 @@ impl Shader { } pub fn get_shader_compile_status(&self) -> bool { - unsafe { - glow_context().get_shader_compile_status(self.0) - } + unsafe { glow_context().get_shader_compile_status(self.0) } } pub fn get_info_log(&self) -> String { - unsafe { - glow_context().get_shader_info_log(self.0) - } + unsafe { glow_context().get_shader_info_log(self.0) } } } @@ -641,7 +639,7 @@ impl Uniform { pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { unsafe { - let slice: &[f32; 4*4] = std::mem::transmute(m); + let slice: &[f32; 4 * 4] = std::mem::transmute(m); glow_context().uniform_matrix_4_f32_slice(Some(&self.0), false, slice); } } @@ -672,22 +670,20 @@ impl Attribute { pub fn vertex_pointer(&self, size: i32, ty: Type, normalized: bool, stride: i32, offset: i32) { unsafe { - glow_context().vertex_attrib_pointer_f32(self.0 as u32, - size, - ty, - normalized, - stride, - offset); + glow_context().vertex_attrib_pointer_f32( + self.0 as u32, + size, + ty, + normalized, + stride, + offset, + ); } } pub fn vertex_pointer_int(&self, size: i32, ty: Type, stride: i32, offset: i32) { unsafe { - glow_context().vertex_attrib_pointer_i32(self.0 as u32, - size, - ty, - stride, - offset); + glow_context().vertex_attrib_pointer_i32(self.0 as u32, size, ty, stride, offset); } } } @@ -702,7 +698,10 @@ impl VertexArray { /// Allocates a new `VertexArray`. pub fn new() -> VertexArray { VertexArray(unsafe { - glow_context().create_vertex_array().expect("create vertex array failed") }) + glow_context() + .create_vertex_array() + .expect("create vertex array failed") + }) } /// Marks the `VertexArray` as the currently active one, this @@ -760,7 +759,10 @@ impl Buffer { /// Allocates a new Buffer. pub fn new() -> Buffer { Buffer(unsafe { - glow_context().create_buffer().expect("create buffer failed") }) + glow_context() + .create_buffer() + .expect("create buffer failed") + }) } /// Makes the buffer the currently active one for the given target. @@ -774,9 +776,7 @@ impl Buffer { pub fn set_data(&self, target: BufferTarget, data: &[u8], usage: BufferUsage) { unsafe { - glow_context().buffer_data_u8_slice(target, - data, - usage); + glow_context().buffer_data_u8_slice(target, data, usage); } } @@ -796,7 +796,11 @@ impl Buffer { pub fn map(&self, target: BufferTarget, access: Access, length: usize) -> MappedBuffer { unsafe { MappedBuffer { - inner: Vec::from_raw_parts(glow_context().map_buffer_range(target, 0, length as i32, access) as *mut u8, 0, length), + inner: Vec::from_raw_parts( + glow_context().map_buffer_range(target, 0, length as i32, access) as *mut u8, + 0, + length, + ), target, } } @@ -884,7 +888,7 @@ pub fn check_gl_error() { loop { let err = glow_context().get_error(); if err == gl::NO_ERROR { - break + break; } error!("glGetError = {}", err); @@ -895,7 +899,10 @@ pub fn check_gl_error() { impl Framebuffer { pub fn new() -> Framebuffer { Framebuffer(unsafe { - glow_context().create_framebuffer().expect("create framebuffer failed") }) + glow_context() + .create_framebuffer() + .expect("create framebuffer failed") + }) } pub fn bind(&self) { @@ -924,7 +931,13 @@ impl Framebuffer { level: i32, ) { unsafe { - glow_context().framebuffer_texture_2d(gl::FRAMEBUFFER, attachment, target, Some(tex.0), level); + glow_context().framebuffer_texture_2d( + gl::FRAMEBUFFER, + attachment, + target, + Some(tex.0), + level, + ); } } } @@ -962,9 +975,7 @@ pub fn draw_buffers(bufs: &[Attachment]) { } pub fn bind_frag_data_location(p: &Program, cn: u32, name: &str) { - unsafe { - glow_context().bind_frag_data_location(p.0, cn, name) - } + unsafe { glow_context().bind_frag_data_location(p.0, cn, name) } } pub fn blit_framebuffer( @@ -981,9 +992,16 @@ pub fn blit_framebuffer( ) { unsafe { glow_context().blit_framebuffer( - sx0, sy0, sx1, sy1, - dx0, dy0, dx1, dy1, - mask.internal(), filter as u32 + sx0, + sy0, + sx1, + sy1, + dx0, + dy0, + dx1, + dy1, + mask.internal(), + filter as u32, ); } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4ad53da5..dd2b0658 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -351,15 +351,18 @@ impl Container { for e in &self.elements { let (w, h) = e.get_size(); let (ox, oy) = e.get_position(); - println!("draw w={}, h={}, ox={}, oy={}", w,h,ox,oy); + println!("draw w={}, h={}, ox={}, oy={}", w, h, ox, oy); println!("compute_draw_region {}x{}", sw, sh); - if oy as i32==100{ + if oy as i32 == 100 { println!("oy=100"); // crashes 3rd time hits here, drawing an Image UIElement - b src/ui/mod.rs:359 } let r = Self::compute_draw_region(e, sw, sh, &SCREEN); if r.intersects(&SCREEN) { - println!("\tintersects - drawing {}x{} {}x{} {}",sw,sh,width,height,delta); + println!( + "\tintersects - drawing {}x{} {}x{} {}", + sw, sh, width, height, delta + ); let data = e.draw(renderer, &r, sw, sh, width, height, delta); println!("\tdata={:?}", data); renderer.ui.add_bytes(&data); From cf80d924cef5c4c9a3bb2ea4d8695c316df07d64 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 24 Dec 2020 21:08:31 -0800 Subject: [PATCH 130/137] Fix clippy::transmute-ptr-to-ptr --- src/gl/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a7699427..ce9efdd2 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -639,8 +639,11 @@ impl Uniform { pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { unsafe { - let slice: &[f32; 4 * 4] = std::mem::transmute(m); - glow_context().uniform_matrix_4_f32_slice(Some(&self.0), false, slice); + glow_context().uniform_matrix_4_f32_slice( + Some(&self.0), + false, + &*(m as *const cgmath::Matrix4 as *const [f32; 16]), + ); } } From f1b1e5367cff64f3c5bf933b4d252db9019464de Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 25 Dec 2020 08:47:01 -0800 Subject: [PATCH 131/137] Reenable optimizations, fixes/worksaround #443 rust_probestack crash --- Cargo.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d6ab1b9c..bbaea3ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,11 +15,9 @@ path = "src/main.rs" # Steven runs horrendously slow with no optimizations, and often freezes. # However, building with full -O3 optimizations takes too long for a debug build. # Use an -O1 optimization level strikes a good compromise between build and program performance. -#opt-level = 1 +opt-level = 1 [dependencies] -backtrace = "*" -trace = "*" cfg-if = "1.0.0" wasm-bindgen = "0.2.69" glutin = "0.26.0" From a0f34a041e80c9d0c687a594fa8f5c31f6b7e6af Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 25 Dec 2020 08:48:07 -0800 Subject: [PATCH 132/137] Cleanup debugging --- src/gl/mod.rs | 7 ------- src/render/shaders.rs | 2 +- src/screen/server_list.rs | 1 - src/ui/mod.rs | 14 -------------- 4 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index ce9efdd2..fc9b2c9d 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -25,18 +25,14 @@ static mut CONTEXT: *mut glow::Context = 0 as *mut glow::Context; pub fn init(vid: &glutin::WindowedContext) { unsafe { let context = Box::new(gl::Context::from_loader_function(|s| { - println!("Loaded {} = {:?}", s, vid.get_proc_address(s)); vid.get_proc_address(s) as *const _ })); - println!("context = {:?}", context); CONTEXT = Box::into_raw(context); } } fn glow_context() -> &'static glow::Context { unsafe { - println!("glow_context = {:?}", CONTEXT); - //use backtrace::Backtrace; let bt = Backtrace::new(); println!("\tbt = {:?}", bt); CONTEXT.as_ref().unwrap() } } @@ -273,7 +269,6 @@ pub struct Texture(u32); impl Texture { // Allocates a new texture. pub fn new() -> Texture { - println!("create_texture"); Texture(unsafe { glow_context() .create_texture() @@ -283,7 +278,6 @@ impl Texture { /// Binds the texture to the passed target. pub fn bind(&self, target: TextureTarget) { - println!("bind_texture {} target {:?}", self.0, target); unsafe { glow_context().bind_texture(target, Some(self.0)); } @@ -485,7 +479,6 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { unsafe { - println!("delete_texture"); glow_context().delete_texture(self.0); } } diff --git a/src/render/shaders.rs b/src/render/shaders.rs index c67a148a..050ac954 100644 --- a/src/render/shaders.rs +++ b/src/render/shaders.rs @@ -77,7 +77,7 @@ macro_rules! init_shader { } ) => ( #[allow(dead_code)] - pub struct $name { // TODO: remove pub + struct $name { program: gl::Program, $( $field: gl::Attribute, diff --git a/src/screen/server_list.rs b/src/screen/server_list.rs index 1c1bf143..073dd4f2 100644 --- a/src/screen/server_list.rs +++ b/src/screen/server_list.rs @@ -99,7 +99,6 @@ impl ServerList { renderer: &mut render::Renderer, ui_container: &mut ui::Container, ) { - println!("reload_server_list"); let elements = self.elements.as_mut().unwrap(); *self.needs_reload.borrow_mut() = false; { diff --git a/src/ui/mod.rs b/src/ui/mod.rs index dd2b0658..4b43a35f 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -349,22 +349,9 @@ impl Container { e.tick(renderer); } for e in &self.elements { - let (w, h) = e.get_size(); - let (ox, oy) = e.get_position(); - println!("draw w={}, h={}, ox={}, oy={}", w, h, ox, oy); - - println!("compute_draw_region {}x{}", sw, sh); - if oy as i32 == 100 { - println!("oy=100"); // crashes 3rd time hits here, drawing an Image UIElement - b src/ui/mod.rs:359 - } let r = Self::compute_draw_region(e, sw, sh, &SCREEN); if r.intersects(&SCREEN) { - println!( - "\tintersects - drawing {}x{} {}x{} {}", - sw, sh, width, height, delta - ); let data = e.draw(renderer, &r, sw, sh, width, height, delta); - println!("\tdata={:?}", data); renderer.ui.add_bytes(&data); } } @@ -864,7 +851,6 @@ impl UIElement for Image { height: f64, delta: f64, ) -> &mut [u8] { - println!("UIImage Image draw()"); if self.check_rebuild() { self.data.clear(); let texture = render::Renderer::get_texture(renderer.get_textures_ref(), &self.texture); From 6271464a79c0fb6a9e4b6f0ce18c87158e260628 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 25 Dec 2020 08:53:10 -0800 Subject: [PATCH 133/137] Pin glow to specific commit of https://github.com/iceiix/glow/pull/1 --- Cargo.lock | 28 ++++++++++++++++++---------- Cargo.toml | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7e56d2a..f8026246 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -827,6 +827,17 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "glow" +version = "0.6.1" +source = "git+https://github.com/iceiix/glow?rev=45c808678735e03737d5e1b9d6ed0e21070edcd9#45c808678735e03737d5e1b9d6ed0e21070edcd9" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "glutin" version = "0.26.0" @@ -2270,6 +2281,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "slotmap" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c46a3482db8f247956e464d783693ece164ca056e6e67563ee5505bdb86452cd" + [[package]] name = "smallvec" version = "0.6.13" @@ -2389,15 +2406,6 @@ dependencies = [ "steven_shared", ] -[[package]] -name = "steven_gl" -version = "0.0.1" -dependencies = [ - "gl_generator", - "khronos_api", - "libc", -] - [[package]] name = "steven_protocol" version = "0.0.1" @@ -2436,6 +2444,7 @@ dependencies = [ "clipboard", "collision", "flate2", + "glow", "glutin", "image", "lazy_static", @@ -2449,7 +2458,6 @@ dependencies = [ "std_or_web", "stdweb", "steven_blocks", - "steven_gl", "steven_protocol", "steven_resources", "steven_shared", diff --git a/Cargo.toml b/Cargo.toml index bbaea3ed..7ef5c523 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ opt-level = 1 cfg-if = "1.0.0" wasm-bindgen = "0.2.69" glutin = "0.26.0" -glow = { git = "https://github.com/iceiix/glow", branch = "ms" } +glow = { git = "https://github.com/iceiix/glow", rev = "45c808678735e03737d5e1b9d6ed0e21070edcd9" } byteorder = "1.3.4" serde = "1.0.118" serde_json = "1.0.60" From c90814b3540a7ad089a7332730bcdbfb05b6a747 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 25 Dec 2020 08:58:41 -0800 Subject: [PATCH 134/137] Revert unnecessary change to main.rs --- src/main.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8d45dcba..1cad3423 100644 --- a/src/main.rs +++ b/src/main.rs @@ -258,7 +258,6 @@ fn main2() { .with_title("Stevenarella") .with_inner_size(glutin::dpi::LogicalSize::new(854.0, 480.0)); let window = glutin::ContextBuilder::new() - /* .with_stencil_buffer(0) .with_depth_buffer(24) .with_gl(glutin::GlRequest::GlThenGles { @@ -266,7 +265,6 @@ fn main2() { opengles_version: (2, 0), }) .with_gl_profile(glutin::GlProfile::Core) - */ .with_vsync(vsync) .build_windowed(window_builder, &events_loop) .expect("Could not create glutin window."); @@ -280,8 +278,6 @@ fn main2() { gl::init(&window); let renderer = render::Renderer::new(resource_manager.clone()); - println!("main 4"); - println!("ok"); let mut ui_container = ui::Container::new(); let mut last_frame = Instant::now(); From 45ed6397e90568d50dd7c2245fe7557bb58779cc Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 25 Dec 2020 09:15:34 -0800 Subject: [PATCH 135/137] Remove gl module --- gl/build.rs | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 gl/build.rs diff --git a/gl/build.rs b/gl/build.rs deleted file mode 100644 index 2ede0324..00000000 --- a/gl/build.rs +++ /dev/null @@ -1,15 +0,0 @@ -use gl_generator::{Api, Fallbacks, GlobalGenerator, Profile, Registry}; -use std::env; -use std::fs::File; -use std::io::BufWriter; -use std::path::Path; - -fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); - let dest = Path::new(&out_dir); - - let mut file = BufWriter::new(File::create(&dest.join("bindings.rs")).unwrap()); - Registry::new(Api::Gl, (3, 2), Profile::Core, Fallbacks::All, []) - .write_bindings(GlobalGenerator, &mut file) - .unwrap(); -} From efd0372bb24681880a4edc5881e4148d6949c507 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 25 Dec 2020 09:16:02 -0800 Subject: [PATCH 136/137] cargo fmt --- src/gl/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index fc9b2c9d..4f6ce849 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -32,9 +32,7 @@ pub fn init(vid: &glutin::WindowedContext) { } fn glow_context() -> &'static glow::Context { - unsafe { - CONTEXT.as_ref().unwrap() - } + unsafe { CONTEXT.as_ref().unwrap() } } /// Dsed to specify how the vertices will be handled From 471f20f0c557897e5d329ebf98b3c6ef8444e641 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Fri, 25 Dec 2020 09:29:18 -0800 Subject: [PATCH 137/137] Implement set_float_multi_raw and set_matrix4_multi, using from_raw_parts --- src/gl/mod.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 4f6ce849..05bac147 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -623,9 +623,8 @@ impl Uniform { } #[allow(clippy::missing_safety_doc)] - pub unsafe fn set_float_multi_raw(&self, _data: *const f32, _len: usize) { - // TODO: takes a slice, not a raw pointer - //TODO glow_context().uniform_4_f32_slice(Some(&self.0), len as i32, data); + pub unsafe fn set_float_multi_raw(&self, data: *const f32, len: usize) { + glow_context().uniform_4_f32_slice(Some(&self.0), std::slice::from_raw_parts(data, len)); } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { @@ -633,16 +632,19 @@ impl Uniform { glow_context().uniform_matrix_4_f32_slice( Some(&self.0), false, - &*(m as *const cgmath::Matrix4 as *const [f32; 16]), + &*(m as *const cgmath::Matrix4 as *const [f32; 4 * 4]), ); } } - pub fn set_matrix4_multi(&self, _m: &[::cgmath::Matrix4]) { - /* TODO: transmute all slices + pub fn set_matrix4_multi(&self, m: &[::cgmath::Matrix4]) { unsafe { - //TODO glow_context().uniform_matrix_4_f32_slice(Some(&self.0), m.len() as i32, false as u8, m.as_ptr() as *const _); // TODO: Most likely isn't safe - }*/ + glow_context().uniform_matrix_4_f32_slice( + Some(&self.0), + false, + std::slice::from_raw_parts(m.as_ptr() as *const _, m.len() * 4 * 4), + ); // TODO: Most likely isn't safe + } } }