remove WindowSize

This commit is contained in:
griffi-gh 2024-05-06 16:24:44 +02:00
parent 9a01ecd6f2
commit 6f25cb728f
11 changed files with 52 additions and 47 deletions

View file

@ -1,6 +1,6 @@
use glam::{Vec3, Mat4}; use glam::{Vec3, Mat4};
use shipyard::{ViewMut, View, IntoIter, Workload, IntoWorkload, track, UniqueView, SystemModificator}; 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; use super::Camera;
//maybe parallelize these two? //maybe parallelize these two?
@ -18,12 +18,13 @@ fn update_view_matrix(
fn update_perspective_matrix( fn update_perspective_matrix(
mut vm_camera: ViewMut<Camera>, mut vm_camera: ViewMut<Camera>,
size: UniqueView<WindowSize>, ren: UniqueView<Renderer>,
) { ) {
let sz = ren.size_vec2();
for mut camera in (&mut vm_camera).iter() { for mut camera in (&mut vm_camera).iter() {
camera.perspective_matrix = Mat4::perspective_rh( camera.perspective_matrix = Mat4::perspective_rh(
camera.fov, camera.fov,
size.0.x as f32 / size.0.y as f32, sz.x / sz.y,
camera.z_near, camera.z_near,
camera.z_far, camera.z_far,
) )

View file

@ -1,7 +1,7 @@
use hui::UiInstance; use hui::UiInstance;
//use hui_glium::GliumUiRenderer; //use hui_glium::GliumUiRenderer;
use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut}; use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut};
use crate::rendering::{Renderer, WindowSize}; use crate::rendering::Renderer;
#[derive(Unique)] #[derive(Unique)]
pub struct UiState { pub struct UiState {

View file

@ -10,7 +10,7 @@ use nohash_hasher::BuildNoHashHasher;
use shipyard::{AllStoragesView, Unique, View, IntoIter, UniqueViewMut, Workload, IntoWorkload, UniqueView, NonSendSync}; use shipyard::{AllStoragesView, Unique, View, IntoIter, UniqueViewMut, Workload, IntoWorkload, UniqueView, NonSendSync};
use crate::{ use crate::{
events::{InputDeviceEvent, TouchEvent}, events::{InputDeviceEvent, TouchEvent},
rendering::WindowSize rendering::Renderer,
}; };
#[derive(Unique, Clone, Copy, Default, Debug)] #[derive(Unique, Clone, Copy, Default, Debug)]
@ -211,10 +211,10 @@ fn update_input_state_gamepad (
fn update_input_state_touch ( fn update_input_state_touch (
touch_state: UniqueView<RawTouchState>, touch_state: UniqueView<RawTouchState>,
win_size: UniqueView<WindowSize>, renderer: UniqueView<Renderer>,
mut inputs: UniqueViewMut<Inputs>, mut inputs: UniqueViewMut<Inputs>,
) { ) {
let w = win_size.0.as_dvec2(); let w = renderer.size_uvec2().as_dvec2();
//Movement //Movement
if let Some(finger) = touch_state.query_area( if let Some(finger) = touch_state.query_area(

View file

@ -75,15 +75,10 @@ use events::{
}; };
use input::{init_input, process_inputs}; use input::{init_input, process_inputs};
use player_controller::{debug_switch_ctl_type, update_player_controllers}; 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::{ use rendering::{
init_render_states, init_render_states,
init_window_size,
render_master, render_master,
resize_renderer, resize_renderer,
update_window_size,
BackgroundColor, Renderer, BackgroundColor, Renderer,
}; };
use block_placement::update_block_placement; use block_placement::update_block_placement;
@ -116,7 +111,6 @@ fn startup() -> Workload {
( (
init_fixed_timestamp_storage, init_fixed_timestamp_storage,
initial_resize_event, initial_resize_event,
init_window_size,
kubi_ui_init, kubi_ui_init,
load_prefabs, load_prefabs,
init_render_states, init_render_states,
@ -136,7 +130,6 @@ fn startup() -> Workload {
fn update() -> Workload { fn update() -> Workload {
( (
debug_toggle_lock, debug_toggle_lock,
update_window_size,
resize_renderer, resize_renderer,
update_cursor_lock_state, update_cursor_lock_state,
process_inputs, process_inputs,

View file

@ -129,25 +129,25 @@ pub fn resize_renderer(
//Deprecated WindowSize thingy //Deprecated WindowSize thingy
#[derive(Unique, Clone, Copy)] // #[derive(Unique, Clone, Copy)]
#[repr(transparent)] // #[repr(transparent)]
#[deprecated = "use Renderer.size instead"] // #[deprecated = "use Renderer.size instead"]
#[allow(deprecated)] // #[allow(deprecated)]
pub struct WindowSize(pub UVec2); // pub struct WindowSize(pub UVec2);
pub fn init_window_size(storages: AllStoragesView) { // pub fn init_window_size(storages: AllStoragesView) {
let size = storages.borrow::<View<WindowResizedEvent>>().unwrap().iter().next().unwrap().0; // let size = storages.borrow::<View<WindowResizedEvent>>().unwrap().iter().next().unwrap().0;
storages.add_unique(WindowSize(size)) // storages.add_unique(WindowSize(size))
} // }
pub fn update_window_size( // pub fn update_window_size(
mut win_size: UniqueViewMut<WindowSize>, // mut win_size: UniqueViewMut<WindowSize>,
resize: View<WindowResizedEvent>, // resize: View<WindowResizedEvent>,
) { // ) {
if let Some(resize) = resize.iter().next() { // if let Some(resize) = resize.iter().next() {
win_size.0 = resize.0; // win_size.0 = resize.0;
} // }
} // }
// pub fn if_resized ( // pub fn if_resized (
// resize: View<WindowResizedEvent>, // resize: View<WindowResizedEvent>,

View file

@ -143,6 +143,14 @@ impl Renderer {
self.size 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 { pub fn window(&self) -> &Window {
&self.window &self.window
} }

View file

@ -1,10 +1,10 @@
use hui::{color, element::{container::Container, text::Text, UiElementExt}, layout::Alignment, size}; use hui::{color, element::{container::Container, text::Text, UiElementExt}, layout::Alignment, size};
use shipyard::{NonSendSync, UniqueView, UniqueViewMut}; 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( pub fn render_chat(
mut hui: NonSendSync<UniqueViewMut<UiState>>, mut hui: NonSendSync<UniqueViewMut<UiState>>,
size: UniqueView<WindowSize>, ren: UniqueView<Renderer>,
chat: UniqueView<ChatHistory>, chat: UniqueView<ChatHistory>,
) { ) {
let messages = chat.get_messages(); let messages = chat.get_messages();
@ -39,5 +39,5 @@ pub fn render_chat(
.add_child(ui); .add_child(ui);
} }
}) })
.add_root(&mut hui.hui, size.0.as_vec2()); .add_root(&mut hui.hui, ren.size_vec2());
} }

View file

@ -5,7 +5,7 @@ use crate::{
hui_integration::UiState, hui_integration::UiState,
loading_screen::loading_screen_base, loading_screen::loading_screen_base,
networking::{ConnectionRejectionReason, ServerAddress}, networking::{ConnectionRejectionReason, ServerAddress},
rendering::WindowSize, rendering::Renderer,
state::{GameState, NextState} state::{GameState, NextState}
}; };
@ -14,7 +14,7 @@ fn render_connecting_ui(
rejection: Option<UniqueView<ConnectionRejectionReason>>, rejection: Option<UniqueView<ConnectionRejectionReason>>,
join_state: UniqueView<ClientJoinState>, join_state: UniqueView<ClientJoinState>,
mut ui: NonSendSync<UniqueViewMut<UiState>>, mut ui: NonSendSync<UniqueViewMut<UiState>>,
size: UniqueView<WindowSize>, ren: UniqueView<Renderer>,
) { ) {
let text = match (rejection, *join_state) { let text = match (rejection, *join_state) {
(Some(err), _) => { (Some(err), _) => {
@ -32,7 +32,7 @@ fn render_connecting_ui(
Text::new(text) Text::new(text)
.with_text_size(16) .with_text_size(16)
.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_loading_if_connected( fn switch_to_loading_if_connected(

View file

@ -6,7 +6,7 @@ use hui::{
size size
}; };
use shipyard::{AllStoragesViewMut, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View}; 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_SIZE: usize = 9;
const CROSSHAIR: &[u8] = &[ const CROSSHAIR: &[u8] = &[
@ -45,7 +45,7 @@ pub fn init_crosshair_image(storages: AllStoragesViewMut) {
pub fn draw_crosshair( pub fn draw_crosshair(
mut ui: NonSendSync<UniqueViewMut<UiState>>, mut ui: NonSendSync<UniqueViewMut<UiState>>,
crosshair: UniqueView<CrosshairImage>, crosshair: UniqueView<CrosshairImage>,
size: UniqueView<WindowSize>, ren: UniqueView<Renderer>,
player: View<MainPlayer>, player: View<MainPlayer>,
raycast: View<LookingAtBlock>, raycast: View<LookingAtBlock>,
settings: UniqueView<GameSettings>, settings: UniqueView<GameSettings>,
@ -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() Container::default()
.with_size(size!(100%)) .with_size(size!(100%))
.with_align(Alignment::Center) .with_align(Alignment::Center)
@ -66,5 +69,5 @@ pub fn draw_crosshair(
.with_size(size!((CROSSHAIR_SIZE * 2))) .with_size(size!((CROSSHAIR_SIZE * 2)))
.add_child(ui); .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);
} }

View file

@ -15,7 +15,7 @@ use crate::{
hui_integration::UiState, hui_integration::UiState,
input::RawKbmInputState, input::RawKbmInputState,
networking::ServerAddress, networking::ServerAddress,
rendering::WindowSize, rendering::Renderer,
state::{GameState, NextState}, state::{GameState, NextState},
world::ChunkStorage, world::ChunkStorage,
}; };
@ -43,7 +43,7 @@ fn render_loading_ui(
addr: Option<UniqueView<ServerAddress>>, addr: Option<UniqueView<ServerAddress>>,
world: UniqueView<ChunkStorage>, world: UniqueView<ChunkStorage>,
mut ui: NonSendSync<UniqueViewMut<UiState>>, mut ui: NonSendSync<UniqueViewMut<UiState>>,
size: UniqueView<WindowSize> ren: UniqueView<Renderer>,
) { ) {
let loaded = world.chunks.iter().fold(0, |acc, (&_, chunk)| { let loaded = world.chunks.iter().fold(0, |acc, (&_, chunk)| {
acc + chunk.desired_state.matches_current(chunk.current_state) as usize 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_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( fn switch_to_ingame_if_loaded(

View file

@ -6,7 +6,7 @@ use hui::{
}; };
use shipyard::{NonSendSync, UniqueView, UniqueViewMut}; use shipyard::{NonSendSync, UniqueView, UniqueViewMut};
use winit::keyboard::KeyCode; 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)] #[derive(Signal)]
enum SettingsSignal { enum SettingsSignal {
@ -18,7 +18,7 @@ enum SettingsSignal {
pub fn render_settings_ui( pub fn render_settings_ui(
mut ui: NonSendSync<UniqueViewMut<UiState>>, mut ui: NonSendSync<UniqueViewMut<UiState>>,
size: UniqueView<WindowSize>, ren: UniqueView<Renderer>,
mut settings: UniqueViewMut<GameSettings>, mut settings: UniqueViewMut<GameSettings>,
kbd: UniqueView<RawKbmInputState>, kbd: UniqueView<RawKbmInputState>,
) { ) {
@ -99,7 +99,7 @@ pub fn render_settings_ui(
}) })
.add_child(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 { ui.hui.process_signals(|signal: SettingsSignal| match signal {
SettingsSignal::SetRenderDistance(value) => settings.render_distance = value, SettingsSignal::SetRenderDistance(value) => settings.render_distance = value,