From 535f7d6112bdef6bdbcfba53bb0c618796d112e6 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sun, 5 May 2024 00:16:55 +0200 Subject: [PATCH] :3 --- kubi/src/lib.rs | 7 ++--- kubi/src/rendering.rs | 8 ++++-- kubi/src/rendering/world.rs | 53 ++++++++++++++++--------------------- kubi/src/world.rs | 1 + 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index b40872d..e708b19 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -79,8 +79,9 @@ use player_controller::{debug_switch_ctl_type, update_player_controllers}; // 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::{ - render_master, init_window_size, resize_renderer, update_window_size, - BackgroundColor, Renderer + init_window_size, render_master, resize_renderer, update_window_size, + world::{init_trans_chunk_queue, TransChunkQueue}, + BackgroundColor, Renderer, }; use block_placement::update_block_placement; use delta_time::{DeltaTime, init_delta_time}; @@ -126,7 +127,6 @@ fn startup() -> Workload { init_client_physics, init_chat_manager, init_crosshair_image, - //init_trans_chunk_queue, ).into_sequential_workload() } @@ -139,6 +139,7 @@ fn update() -> Workload { process_inputs, kubi_ui_begin, ( + init_trans_chunk_queue.run_if_missing_unique::(), init_game_world.run_if_missing_unique::(), ( spawn_player.run_if_storage_empty::(), diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index fdafbed..16c3f1a 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -8,7 +8,7 @@ use winit::{ dpi::PhysicalSize }; use glam::{Vec3, UVec2}; -use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}}; +use crate::{events::WindowResizedEvent, settings::{FullscreenMode, GameSettings}, state::is_ingame}; pub mod primitives; pub mod world; @@ -188,7 +188,7 @@ pub fn render_master(storages: AllStoragesViewMut) { let surface_texture = renderer.surface().get_current_texture().unwrap(); let surface_view = surface_texture.texture.create_view(&wgpu::TextureViewDescriptor::default()); - { + if storages.run(is_ingame) { let bg_color = storages.borrow::>().unwrap(); let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("main0_pass"), @@ -209,6 +209,10 @@ pub fn render_master(storages: AllStoragesViewMut) { ..Default::default() }); + let data = (&mut render_pass, &*renderer); + + storages.run_with_data(world::draw_world, data); + // render_pass.set_pipeline(&renderer.pipeline); // render_pass.set_bind_group(0, &renderer.bind_group, &[]); // render_pass.set_vertex_buffer(0, renderer.vertex_buffer.slice(..)); diff --git a/kubi/src/rendering/world.rs b/kubi/src/rendering/world.rs index 9c66c34..c83dde9 100644 --- a/kubi/src/rendering/world.rs +++ b/kubi/src/rendering/world.rs @@ -1,29 +1,9 @@ -// use glam::{ivec3, IVec3, Mat4, Quat, Vec3}; -// use shipyard::{track, AllStoragesView, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View}; -// use glium::{ -// draw_parameters::{ -// BackfaceCullingMode, Depth, DepthTest, PolygonMode -// }, implement_vertex, uniform, uniforms::{ -// MagnifySamplerFilter, MinifySamplerFilter, Sampler, SamplerBehavior, SamplerWrapFunction -// }, Blend, DrawParameters, Smooth, Surface -// }; -// use crate::{ -// camera::Camera, -// player::MainPlayer, -// transform::Transform, -// prefabs::{ -// ChunkShaderPrefab, -// BlockTexturesPrefab, -// ColoredShaderPrefab, -// }, -// world::{ -// ChunkStorage, -// ChunkMeshStorage, -// chunk::CHUNK_SIZE, -// }, settings::GameSettings, -// }; -// use super::{RenderTarget, primitives::cube::CubePrimitive}; use bytemuck::{Pod, Zeroable}; +use glam::IVec3; +use shipyard::{AllStoragesView, NonSendSync, Unique, UniqueView, UniqueViewMut, View}; +use kubi_shared::transform::Transform; +use crate::{camera::Camera, settings::GameSettings, world::{ChunkMeshStorage, ChunkStorage}}; +use super::Renderer; #[derive(Clone, Copy, Pod, Zeroable)] #[repr(C, packed)] @@ -47,12 +27,25 @@ impl ChunkVertex { }; } -// #[derive(Unique)] -// pub struct TransChunkQueue(pub Vec); +#[derive(Unique)] +pub struct TransChunkQueue(pub Vec); + +pub fn init_trans_chunk_queue(storages: AllStoragesView) { + storages.add_unique(TransChunkQueue(Vec::with_capacity(512))); +} + +pub fn draw_world( + (render_pass, renderer): (&mut wgpu::RenderPass, &Renderer), + chunks: UniqueView, + meshes: NonSendSync>, + transform: View, + camera: View, + settings: UniqueView, + mut trans_queue: UniqueViewMut, +) { + //TODO +} -// pub fn init_trans_chunk_queue(storages: AllStoragesView) { -// storages.add_unique(TransChunkQueue(Vec::with_capacity(512))); -// } // fn draw_params(settings: &GameSettings) -> DrawParameters { // DrawParameters { diff --git a/kubi/src/world.rs b/kubi/src/world.rs index 50664d2..1626d17 100644 --- a/kubi/src/world.rs +++ b/kubi/src/world.rs @@ -102,6 +102,7 @@ impl ChunkMeshStorage { pub fn init_game_world( storages: AllStoragesView, ) { + log::info!("init_game_world called"); storages.add_unique_non_send_sync(ChunkMeshStorage::new()); storages.add_unique(ChunkStorage::new()); storages.add_unique(ChunkTaskManager::new());