restructure stuff and fix some warnings

This commit is contained in:
griffi-gh 2024-05-06 16:53:40 +02:00
parent db8243cb90
commit 66afd3057e
8 changed files with 56 additions and 85 deletions

View file

@ -1,4 +1,3 @@
use fastnoise_lite::FastNoiseLite;
use glam::ivec3; use glam::ivec3;
use crate::{block::Block, chunk::CHUNK_SIZE, worldgen::SeedThingy}; use crate::{block::Block, chunk::CHUNK_SIZE, worldgen::SeedThingy};
use super::{ use super::{

View file

@ -1,5 +1,5 @@
use kubi_shared::networking::client::ClientId; use kubi_shared::networking::client::ClientId;
use shipyard::{AllStoragesView, Unique, UniqueViewMut}; use shipyard::{AllStoragesView, Unique};
pub enum ChatMessage { pub enum ChatMessage {
PlayerMessage { PlayerMessage {

View file

@ -1,7 +1,7 @@
//TODO client-side physics //TODO client-side physics
//TODO move this to shared //TODO move this to shared
use glam::{vec3, IVec3, Mat4, Vec3, Vec3Swizzles}; use glam::{vec3, Mat4, Vec3, Vec3Swizzles};
use shipyard::{track, AllStoragesView, Component, IntoIter, Unique, UniqueView, View, ViewMut}; use shipyard::{track, AllStoragesView, Component, IntoIter, Unique, UniqueView, ViewMut};
use kubi_shared::{block::{Block, CollisionType}, transform::Transform}; use kubi_shared::{block::{Block, CollisionType}, transform::Transform};
use crate::{delta_time::DeltaTime, world::ChunkStorage}; use crate::{delta_time::DeltaTime, world::ChunkStorage};

View file

@ -86,18 +86,18 @@ pub fn process_winit_events(world: &mut World, event: &Event<()>) {
} }
} }
pub fn initial_resize_event( // pub fn initial_resize_event(
mut storages: AllStoragesViewMut, // mut storages: AllStoragesViewMut,
) { // ) {
let (w, h) = { // let (w, h) = {
let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap(); // let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
(renderer.size().width, renderer.size().height) // (renderer.size().width, renderer.size().height)
}; // };
storages.add_entity(( // storages.add_entity((
EventComponent, // EventComponent,
WindowResizedEvent(UVec2::new(w, h)) // WindowResizedEvent(UVec2::new(w, h))
)); // ));
} // }
pub fn clear_events( pub fn clear_events(
mut all_storages: AllStoragesViewMut, mut all_storages: AllStoragesViewMut,

View file

@ -13,7 +13,7 @@
use shipyard::{ use shipyard::{
World, Workload, IntoWorkload, World, Workload, IntoWorkload,
UniqueView, UniqueViewMut, UniqueView, UniqueViewMut,
NonSendSync, WorkloadModificator, WorkloadModificator,
SystemModificator SystemModificator
}; };
use winit::{ use winit::{
@ -58,29 +58,19 @@ pub(crate) mod chat;
use world::{ use world::{
init_game_world, init_game_world,
loading::update_loaded_world_around_player, loading::update_loaded_world_around_player,
raycast::update_raycasts, raycast::update_raycasts,
queue::apply_queued_blocks, queue::apply_queued_blocks,
tasks::ChunkTaskManager, tasks::ChunkTaskManager,
}; };
use player::{spawn_player, MainPlayer}; use player::{spawn_player, MainPlayer};
use prefabs::load_prefabs; use prefabs::load_prefabs;
use settings::{load_settings, GameSettings}; use settings::{load_settings, GameSettings};
use camera::compute_cameras; use camera::compute_cameras;
use events::{ use events::{clear_events, process_winit_events, player_actions::generate_move_events};
clear_events,
process_winit_events,
initial_resize_event,
player_actions::generate_move_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::{ use rendering::{BackgroundColor, Renderer, init_rendering, render_master, update_rendering_early, update_rendering_late};
init_render_states,
render_master,
resize_renderer,
BackgroundColor, Renderer,
};
use block_placement::update_block_placement; use block_placement::update_block_placement;
use delta_time::{DeltaTime, init_delta_time}; use delta_time::{DeltaTime, init_delta_time};
use cursor_lock::{debug_toggle_lock, insert_lock_state, lock_cursor_now, update_cursor_lock_state}; use cursor_lock::{debug_toggle_lock, insert_lock_state, lock_cursor_now, update_cursor_lock_state};
@ -110,10 +100,9 @@ fn pre_startup() -> Workload {
fn startup() -> Workload { fn startup() -> Workload {
( (
init_fixed_timestamp_storage, init_fixed_timestamp_storage,
initial_resize_event,
kubi_ui_init, kubi_ui_init,
load_prefabs, load_prefabs,
init_render_states, init_rendering,
insert_lock_state, insert_lock_state,
init_state, init_state,
initialize_from_args, initialize_from_args,
@ -129,8 +118,8 @@ fn startup() -> Workload {
fn update() -> Workload { fn update() -> Workload {
( (
update_rendering_early,
debug_toggle_lock, debug_toggle_lock,
resize_renderer,
update_cursor_lock_state, update_cursor_lock_state,
process_inputs, process_inputs,
kubi_ui_begin, kubi_ui_begin,
@ -169,6 +158,7 @@ fn update() -> Workload {
update_state, update_state,
exit_on_esc, exit_on_esc,
disconnect_on_exit.run_if(is_multiplayer), disconnect_on_exit.run_if(is_multiplayer),
update_rendering_late,
).into_sequential_workload() ).into_sequential_workload()
} }
@ -187,7 +177,7 @@ fn update() -> Workload {
// ).into_sequential_workload() // ).into_sequential_workload()
// } // }
fn after_frame_end() -> Workload { fn after_render() -> Workload {
( (
clear_events, clear_events,
).into_sequential_workload() ).into_sequential_workload()
@ -236,7 +226,7 @@ pub fn kubi_main(
world.add_workload(startup); world.add_workload(startup);
world.add_workload(update); world.add_workload(update);
//world.add_workload(render); //world.add_workload(render);
world.add_workload(after_frame_end); world.add_workload(after_render);
//Save _visualizer.json //Save _visualizer.json
#[cfg(feature = "generate_visualizer_data")] #[cfg(feature = "generate_visualizer_data")]
@ -333,7 +323,7 @@ pub fn kubi_main(
// target.0.finish().unwrap(); // target.0.finish().unwrap();
//After frame end //After frame end
world.run_workload(after_frame_end).unwrap(); world.run_workload(after_render).unwrap();
//Process control flow changes //Process control flow changes
if world.borrow::<UniqueView<RequestExit>>().unwrap().0 { if world.borrow::<UniqueView<RequestExit>>().unwrap().0 {

View file

@ -1,53 +1,17 @@
use shipyard::{AllStoragesView, AllStoragesViewMut, IntoIter, IntoWorkload, Unique, UniqueView, UniqueViewMut, View, Workload}; use shipyard::{AllStoragesViewMut, IntoIter, IntoWorkload, SystemModificator, Unique, UniqueView, UniqueViewMut, View, Workload, WorkloadModificator};
use winit::dpi::PhysicalSize; use winit::dpi::PhysicalSize;
use glam::{mat4, vec4, Mat4, UVec2, Vec3}; use glam::Vec3;
use crate::{events::WindowResizedEvent, state::is_ingame}; use crate::{events::WindowResizedEvent, state::is_ingame};
mod renderer; mod renderer;
pub use renderer::Renderer; pub use renderer::Renderer;
use self::camera::update_camera_unform_buffer; use self::{camera::CameraUniformBuffer, world::WorldRenderState};
pub mod world; pub mod world;
pub mod camera; pub mod camera;
pub mod depth; pub mod depth;
//pub mod primitives;
//pub mod selection_box;
//pub mod entities;
//pub mod sumberge;
// pub const WGPU_COORDINATE_SYSTEM: Mat4 = mat4(
// vec4(1.0, 0.0, 0.0, 0.0),
// vec4(0.0, 1.0, 0.0, 0.0),
// vec4(0.0, 0.0, 0.5, 0.5),
// vec4(0.0, 0.0, 0.0, 1.0),
// );
// #[repr(C)]
// #[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
// struct TrasnformUniformData {
// pub transform: [[f32; 4]; 4],
// }
// impl TrasnformUniformData {
// pub const LAYOUT: &wgpu::Layou
// }
// impl From<Mat4> for TrasnformUniformData {
// fn from(mat: Mat4) -> Self {
// Self {
// transform: mat.to_cols_array_2d(),
// }
// }
// }
// impl From<Transform> for TrasnformUniformData {
// fn from(value: Transform) -> Self {
// value.0.into()
// }
// }
pub struct BufferPair { pub struct BufferPair {
pub index: wgpu::Buffer, pub index: wgpu::Buffer,
pub index_len: u32, pub index_len: u32,
@ -64,10 +28,24 @@ pub struct RenderCtx<'a> {
pub surface_view: &'a wgpu::TextureView, pub surface_view: &'a wgpu::TextureView,
} }
pub fn init_render_states() -> Workload { pub fn init_rendering() -> Workload {
( (
depth::init_depth_texture,
camera::init_camera_uniform_buffer, camera::init_camera_uniform_buffer,
world::init_world_render_state, world::init_world_render_state, //TODO run only once ingame
).into_sequential_workload()
}
pub fn update_rendering_early() -> Workload {
(
resize_renderer,
depth::resize_depth_texture,
).into_sequential_workload()
}
pub fn update_rendering_late() -> Workload {
(
camera::update_camera_uniform_buffer,
).into_workload() ).into_workload()
} }
@ -109,7 +87,6 @@ pub fn render_master(storages: AllStoragesViewMut) {
}; };
if storages.run(is_ingame) { if storages.run(is_ingame) {
//TODO init world render state on demand
storages.run_with_data(world::draw_world, &mut data); storages.run_with_data(world::draw_world, &mut data);
} }

View file

@ -72,7 +72,7 @@ pub fn init_camera_uniform_buffer(storages: AllStoragesView) {
storages.add_unique(CameraUniformBuffer::init_default(&renderer)); storages.add_unique(CameraUniformBuffer::init_default(&renderer));
} }
pub fn update_camera_unform_buffer( pub fn update_camera_uniform_buffer(
renderer: UniqueView<Renderer>, renderer: UniqueView<Renderer>,
camera_uniform_buffer: UniqueView<CameraUniformBuffer>, camera_uniform_buffer: UniqueView<CameraUniformBuffer>,
camera: View<Camera>, camera: View<Camera>,

View file

@ -1,7 +1,9 @@
use glam::{uvec2, UVec2}; use glam::{uvec2, UVec2};
use shipyard::{AllStoragesView, Unique, UniqueView, UniqueViewMut};
use super::Renderer; use super::Renderer;
#[derive(Unique)]
pub struct DepthTexture { pub struct DepthTexture {
pub depth_texture: wgpu::Texture, pub depth_texture: wgpu::Texture,
pub depth_view: wgpu::TextureView, pub depth_view: wgpu::TextureView,
@ -55,13 +57,16 @@ impl DepthTexture {
} }
} }
pub fn init_depth_texture(renderer: &Renderer) -> DepthTexture { pub fn init_depth_texture(
DepthTexture::init(renderer) storages: AllStoragesView,
) {
let renderer = storages.borrow::<UniqueView<Renderer>>().unwrap();
storages.add_unique(DepthTexture::init(&renderer));
} }
pub fn resize_depth_texture( pub fn resize_depth_texture(
renderer: &Renderer, mut depth_texture: UniqueViewMut<DepthTexture>,
depth_texture: &mut DepthTexture, renderer: UniqueView<Renderer>,
) { ) {
depth_texture.resize(renderer); depth_texture.resize(&renderer);
} }