restructure stuff and fix some warnings

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
//TODO client-side physics
//TODO move this to shared
use glam::{vec3, IVec3, Mat4, Vec3, Vec3Swizzles};
use shipyard::{track, AllStoragesView, Component, IntoIter, Unique, UniqueView, View, ViewMut};
use glam::{vec3, Mat4, Vec3, Vec3Swizzles};
use shipyard::{track, AllStoragesView, Component, IntoIter, Unique, UniqueView, ViewMut};
use kubi_shared::{block::{Block, CollisionType}, transform::Transform};
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(
mut storages: AllStoragesViewMut,
) {
let (w, h) = {
let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
(renderer.size().width, renderer.size().height)
};
storages.add_entity((
EventComponent,
WindowResizedEvent(UVec2::new(w, h))
));
}
// pub fn initial_resize_event(
// mut storages: AllStoragesViewMut,
// ) {
// let (w, h) = {
// let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
// (renderer.size().width, renderer.size().height)
// };
// storages.add_entity((
// EventComponent,
// WindowResizedEvent(UVec2::new(w, h))
// ));
// }
pub fn clear_events(
mut all_storages: AllStoragesViewMut,

View file

@ -13,7 +13,7 @@
use shipyard::{
World, Workload, IntoWorkload,
UniqueView, UniqueViewMut,
NonSendSync, WorkloadModificator,
WorkloadModificator,
SystemModificator
};
use winit::{
@ -58,29 +58,19 @@ pub(crate) mod chat;
use world::{
init_game_world,
loading::update_loaded_world_around_player,
loading::update_loaded_world_around_player,
raycast::update_raycasts,
queue::apply_queued_blocks,
queue::apply_queued_blocks,
tasks::ChunkTaskManager,
};
use player::{spawn_player, MainPlayer};
use prefabs::load_prefabs;
use settings::{load_settings, GameSettings};
use camera::compute_cameras;
use events::{
clear_events,
process_winit_events,
initial_resize_event,
player_actions::generate_move_events,
};
use events::{clear_events, process_winit_events, player_actions::generate_move_events};
use input::{init_input, process_inputs};
use player_controller::{debug_switch_ctl_type, update_player_controllers};
use rendering::{
init_render_states,
render_master,
resize_renderer,
BackgroundColor, Renderer,
};
use rendering::{BackgroundColor, Renderer, init_rendering, render_master, update_rendering_early, update_rendering_late};
use block_placement::update_block_placement;
use delta_time::{DeltaTime, init_delta_time};
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 {
(
init_fixed_timestamp_storage,
initial_resize_event,
kubi_ui_init,
load_prefabs,
init_render_states,
init_rendering,
insert_lock_state,
init_state,
initialize_from_args,
@ -129,8 +118,8 @@ fn startup() -> Workload {
fn update() -> Workload {
(
update_rendering_early,
debug_toggle_lock,
resize_renderer,
update_cursor_lock_state,
process_inputs,
kubi_ui_begin,
@ -169,6 +158,7 @@ fn update() -> Workload {
update_state,
exit_on_esc,
disconnect_on_exit.run_if(is_multiplayer),
update_rendering_late,
).into_sequential_workload()
}
@ -187,7 +177,7 @@ fn update() -> Workload {
// ).into_sequential_workload()
// }
fn after_frame_end() -> Workload {
fn after_render() -> Workload {
(
clear_events,
).into_sequential_workload()
@ -236,7 +226,7 @@ pub fn kubi_main(
world.add_workload(startup);
world.add_workload(update);
//world.add_workload(render);
world.add_workload(after_frame_end);
world.add_workload(after_render);
//Save _visualizer.json
#[cfg(feature = "generate_visualizer_data")]
@ -333,7 +323,7 @@ pub fn kubi_main(
// target.0.finish().unwrap();
//After frame end
world.run_workload(after_frame_end).unwrap();
world.run_workload(after_render).unwrap();
//Process control flow changes
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 glam::{mat4, vec4, Mat4, UVec2, Vec3};
use glam::Vec3;
use crate::{events::WindowResizedEvent, state::is_ingame};
mod renderer;
pub use renderer::Renderer;
use self::camera::update_camera_unform_buffer;
use self::{camera::CameraUniformBuffer, world::WorldRenderState};
pub mod world;
pub mod camera;
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 index: wgpu::Buffer,
pub index_len: u32,
@ -64,10 +28,24 @@ pub struct RenderCtx<'a> {
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,
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()
}
@ -109,7 +87,6 @@ pub fn render_master(storages: AllStoragesViewMut) {
};
if storages.run(is_ingame) {
//TODO init world render state on demand
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));
}
pub fn update_camera_unform_buffer(
pub fn update_camera_uniform_buffer(
renderer: UniqueView<Renderer>,
camera_uniform_buffer: UniqueView<CameraUniformBuffer>,
camera: View<Camera>,

View file

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