From 6f25cb728fe1164ae98b6a438965833e0699fd09 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 6 May 2024 16:24:44 +0200 Subject: [PATCH] remove `WindowSize` --- kubi/src/camera/matrices.rs | 9 +++++---- kubi/src/hui_integration.rs | 2 +- kubi/src/input.rs | 6 +++--- kubi/src/lib.rs | 7 ------- kubi/src/rendering.rs | 34 ++++++++++++++++---------------- kubi/src/rendering/renderer.rs | 8 ++++++++ kubi/src/ui/chat_ui.rs | 6 +++--- kubi/src/ui/connecting_screen.rs | 6 +++--- kubi/src/ui/crosshair_ui.rs | 9 ++++++--- kubi/src/ui/loading_screen.rs | 6 +++--- kubi/src/ui/settings_ui.rs | 6 +++--- 11 files changed, 52 insertions(+), 47 deletions(-) diff --git a/kubi/src/camera/matrices.rs b/kubi/src/camera/matrices.rs index 2309724..6230447 100644 --- a/kubi/src/camera/matrices.rs +++ b/kubi/src/camera/matrices.rs @@ -1,6 +1,6 @@ use glam::{Vec3, Mat4}; use shipyard::{ViewMut, View, IntoIter, Workload, IntoWorkload, track, UniqueView, SystemModificator}; -use crate::{transform::Transform, rendering::WindowSize, events::WindowResizedEvent}; +use crate::{transform::Transform, rendering::Renderer, events::WindowResizedEvent}; use super::Camera; //maybe parallelize these two? @@ -18,14 +18,15 @@ fn update_view_matrix( fn update_perspective_matrix( mut vm_camera: ViewMut, - size: UniqueView, + ren: UniqueView, ) { + let sz = ren.size_vec2(); for mut camera in (&mut vm_camera).iter() { camera.perspective_matrix = Mat4::perspective_rh( camera.fov, - size.0.x as f32 / size.0.y as f32, + sz.x / sz.y, camera.z_near, - camera.z_far, + camera.z_far, ) } } diff --git a/kubi/src/hui_integration.rs b/kubi/src/hui_integration.rs index 15b862c..95fcfae 100644 --- a/kubi/src/hui_integration.rs +++ b/kubi/src/hui_integration.rs @@ -1,7 +1,7 @@ use hui::UiInstance; //use hui_glium::GliumUiRenderer; use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut}; -use crate::rendering::{Renderer, WindowSize}; +use crate::rendering::Renderer; #[derive(Unique)] pub struct UiState { diff --git a/kubi/src/input.rs b/kubi/src/input.rs index c24081e..1cfcf57 100644 --- a/kubi/src/input.rs +++ b/kubi/src/input.rs @@ -10,7 +10,7 @@ use nohash_hasher::BuildNoHashHasher; use shipyard::{AllStoragesView, Unique, View, IntoIter, UniqueViewMut, Workload, IntoWorkload, UniqueView, NonSendSync}; use crate::{ events::{InputDeviceEvent, TouchEvent}, - rendering::WindowSize + rendering::Renderer, }; #[derive(Unique, Clone, Copy, Default, Debug)] @@ -211,10 +211,10 @@ fn update_input_state_gamepad ( fn update_input_state_touch ( touch_state: UniqueView, - win_size: UniqueView, + renderer: UniqueView, mut inputs: UniqueViewMut, ) { - let w = win_size.0.as_dvec2(); + let w = renderer.size_uvec2().as_dvec2(); //Movement if let Some(finger) = touch_state.query_area( diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index ba75b14..2bb336d 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -75,15 +75,10 @@ use events::{ }; use input::{init_input, process_inputs}; use player_controller::{debug_switch_ctl_type, update_player_controllers}; -// use rendering::{ -// clear_background, entities::render_entities, init_window_size, primitives::init_primitives, resize_renderer, selection_box::render_selection_box, sumberge::render_submerged_view, update_window_size, world::{draw_current_chunk_border, draw_world, draw_world_trans, init_trans_chunk_queue}, BackgroundColor, RenderTarget, Renderer -// }; use rendering::{ init_render_states, - init_window_size, render_master, resize_renderer, - update_window_size, BackgroundColor, Renderer, }; use block_placement::update_block_placement; @@ -116,7 +111,6 @@ fn startup() -> Workload { ( init_fixed_timestamp_storage, initial_resize_event, - init_window_size, kubi_ui_init, load_prefabs, init_render_states, @@ -136,7 +130,6 @@ fn startup() -> Workload { fn update() -> Workload { ( debug_toggle_lock, - update_window_size, resize_renderer, update_cursor_lock_state, process_inputs, diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index 215e597..e34f7b0 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -129,25 +129,25 @@ pub fn resize_renderer( //Deprecated WindowSize thingy -#[derive(Unique, Clone, Copy)] -#[repr(transparent)] -#[deprecated = "use Renderer.size instead"] -#[allow(deprecated)] -pub struct WindowSize(pub UVec2); +// #[derive(Unique, Clone, Copy)] +// #[repr(transparent)] +// #[deprecated = "use Renderer.size instead"] +// #[allow(deprecated)] +// pub struct WindowSize(pub UVec2); -pub fn init_window_size(storages: AllStoragesView) { - let size = storages.borrow::>().unwrap().iter().next().unwrap().0; - storages.add_unique(WindowSize(size)) -} +// pub fn init_window_size(storages: AllStoragesView) { +// let size = storages.borrow::>().unwrap().iter().next().unwrap().0; +// storages.add_unique(WindowSize(size)) +// } -pub fn update_window_size( - mut win_size: UniqueViewMut, - resize: View, -) { - if let Some(resize) = resize.iter().next() { - win_size.0 = resize.0; - } -} +// pub fn update_window_size( +// mut win_size: UniqueViewMut, +// resize: View, +// ) { +// if let Some(resize) = resize.iter().next() { +// win_size.0 = resize.0; +// } +// } // pub fn if_resized ( // resize: View, diff --git a/kubi/src/rendering/renderer.rs b/kubi/src/rendering/renderer.rs index 4cecbf9..8b4bf91 100644 --- a/kubi/src/rendering/renderer.rs +++ b/kubi/src/rendering/renderer.rs @@ -143,6 +143,14 @@ impl Renderer { self.size } + pub fn size_uvec2(&self) -> glam::UVec2 { + glam::UVec2::new(self.size.width, self.size.height) + } + + pub fn size_vec2(&self) -> glam::Vec2 { + glam::Vec2::new(self.size.width as f32, self.size.height as f32) + } + pub fn window(&self) -> &Window { &self.window } diff --git a/kubi/src/ui/chat_ui.rs b/kubi/src/ui/chat_ui.rs index d419ed6..0c34131 100644 --- a/kubi/src/ui/chat_ui.rs +++ b/kubi/src/ui/chat_ui.rs @@ -1,10 +1,10 @@ use hui::{color, element::{container::Container, text::Text, UiElementExt}, layout::Alignment, size}; use shipyard::{NonSendSync, UniqueView, UniqueViewMut}; -use crate::{chat::{ChatHistory, ChatMessage}, hui_integration::UiState, rendering::WindowSize}; +use crate::{chat::{ChatHistory, ChatMessage}, hui_integration::UiState, rendering::Renderer}; pub fn render_chat( mut hui: NonSendSync>, - size: UniqueView, + ren: UniqueView, chat: UniqueView, ) { let messages = chat.get_messages(); @@ -39,5 +39,5 @@ pub fn render_chat( .add_child(ui); } }) - .add_root(&mut hui.hui, size.0.as_vec2()); + .add_root(&mut hui.hui, ren.size_vec2()); } diff --git a/kubi/src/ui/connecting_screen.rs b/kubi/src/ui/connecting_screen.rs index 0ceab5f..d01ad5d 100644 --- a/kubi/src/ui/connecting_screen.rs +++ b/kubi/src/ui/connecting_screen.rs @@ -5,7 +5,7 @@ use crate::{ hui_integration::UiState, loading_screen::loading_screen_base, networking::{ConnectionRejectionReason, ServerAddress}, - rendering::WindowSize, + rendering::Renderer, state::{GameState, NextState} }; @@ -14,7 +14,7 @@ fn render_connecting_ui( rejection: Option>, join_state: UniqueView, mut ui: NonSendSync>, - size: UniqueView, + ren: UniqueView, ) { let text = match (rejection, *join_state) { (Some(err), _) => { @@ -32,7 +32,7 @@ fn render_connecting_ui( Text::new(text) .with_text_size(16) .add_child(ui); - }).add_root(&mut ui.hui, size.0.as_vec2()) + }).add_root(&mut ui.hui, ren.size_vec2()) } fn switch_to_loading_if_connected( diff --git a/kubi/src/ui/crosshair_ui.rs b/kubi/src/ui/crosshair_ui.rs index 353429e..39df924 100644 --- a/kubi/src/ui/crosshair_ui.rs +++ b/kubi/src/ui/crosshair_ui.rs @@ -6,7 +6,7 @@ use hui::{ size }; use shipyard::{AllStoragesViewMut, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View}; -use crate::{hui_integration::UiState, player::MainPlayer, rendering::WindowSize, settings::GameSettings, world::raycast::LookingAtBlock}; +use crate::{hui_integration::UiState, player::MainPlayer, rendering::Renderer, settings::GameSettings, world::raycast::LookingAtBlock}; const CROSSHAIR_SIZE: usize = 9; const CROSSHAIR: &[u8] = &[ @@ -45,7 +45,7 @@ pub fn init_crosshair_image(storages: AllStoragesViewMut) { pub fn draw_crosshair( mut ui: NonSendSync>, crosshair: UniqueView, - size: UniqueView, + ren: UniqueView, player: View, raycast: View, settings: UniqueView, @@ -57,6 +57,9 @@ pub fn draw_crosshair( } } + let size = ren.size_uvec2(); + let size_rounded = uvec2(size.x & !1, size.y & !1).as_vec2(); + Container::default() .with_size(size!(100%)) .with_align(Alignment::Center) @@ -66,5 +69,5 @@ pub fn draw_crosshair( .with_size(size!((CROSSHAIR_SIZE * 2))) .add_child(ui); }) - .add_root(&mut ui.hui, uvec2(size.0.x & !1, size.0.y & !1).as_vec2()); + .add_root(&mut ui.hui, size_rounded); } diff --git a/kubi/src/ui/loading_screen.rs b/kubi/src/ui/loading_screen.rs index be71392..df03aec 100644 --- a/kubi/src/ui/loading_screen.rs +++ b/kubi/src/ui/loading_screen.rs @@ -15,7 +15,7 @@ use crate::{ hui_integration::UiState, input::RawKbmInputState, networking::ServerAddress, - rendering::WindowSize, + rendering::Renderer, state::{GameState, NextState}, world::ChunkStorage, }; @@ -43,7 +43,7 @@ fn render_loading_ui( addr: Option>, world: UniqueView, mut ui: NonSendSync>, - size: UniqueView + ren: UniqueView, ) { let loaded = world.chunks.iter().fold(0, |acc, (&_, chunk)| { acc + chunk.desired_state.matches_current(chunk.current_state) as usize @@ -83,7 +83,7 @@ fn render_loading_ui( .add_child(ui) }) .add_child(ui); - }).add_root(&mut ui.hui, size.0.as_vec2()); + }).add_root(&mut ui.hui, ren.size_vec2()); } fn switch_to_ingame_if_loaded( diff --git a/kubi/src/ui/settings_ui.rs b/kubi/src/ui/settings_ui.rs index b863da8..6211c6d 100644 --- a/kubi/src/ui/settings_ui.rs +++ b/kubi/src/ui/settings_ui.rs @@ -6,7 +6,7 @@ use hui::{ }; use shipyard::{NonSendSync, UniqueView, UniqueViewMut}; use winit::keyboard::KeyCode; -use crate::{hui_integration::UiState, input::RawKbmInputState, rendering::WindowSize, settings::GameSettings}; +use crate::{hui_integration::UiState, input::RawKbmInputState, rendering::Renderer, settings::GameSettings}; #[derive(Signal)] enum SettingsSignal { @@ -18,7 +18,7 @@ enum SettingsSignal { pub fn render_settings_ui( mut ui: NonSendSync>, - size: UniqueView, + ren: UniqueView, mut settings: UniqueViewMut, kbd: UniqueView, ) { @@ -99,7 +99,7 @@ pub fn render_settings_ui( }) .add_child(ui); }) - .add_root(&mut ui.hui, size.0.as_vec2()); + .add_root(&mut ui.hui, ren.size_vec2()); ui.hui.process_signals(|signal: SettingsSignal| match signal { SettingsSignal::SetRenderDistance(value) => settings.render_distance = value,