Compare commits

..

No commits in common. "9532161ed742a6e02cfe575bf46367553abd5d06" and "3b752dfbf89a144044258121a7cb9008c0a79f0f" have entirely different histories.

10 changed files with 26 additions and 128 deletions

View file

@ -1,6 +1,5 @@
[workspace] [workspace]
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging"] members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging"]
default-members = ["kubi"]
resolver = "2" resolver = "2"
[profile.release-with-debug] [profile.release-with-debug]
@ -16,7 +15,7 @@ opt-level = 1
[profile.dev.package.uflow] [profile.dev.package.uflow]
opt-level = 3 opt-level = 3
[profile.dev.package.wgpu] [profile.dev.package.glium]
opt-level = 3 opt-level = 3
[profile.dev.package.bracket-noise] [profile.dev.package.bracket-noise]

View file

@ -9,7 +9,7 @@ pub fn init() {
use env_logger::{fmt::Color, Builder, Env}; use env_logger::{fmt::Color, Builder, Env};
let env = Env::default() let env = Env::default()
.filter_or("RUST_LOG", "trace,gilrs=warn,rusty_xinput=warn,wgpu=warn,wgpu_core=warn,wgpu_hal=error"); .filter_or("RUST_LOG", "trace,gilrs=warn,rusty_xinput=warn");
Builder::from_env(env) Builder::from_env(env)
.format(|buf, record| { .format(|buf, record| {
let mut level_style = buf.style(); let mut level_style = buf.style();

View file

@ -1,19 +1 @@
//TODO migrate, this is just some filler code to make the game compile //TODO migrate
struct VertexOutput {
@builtin(position) position: vec4<f32>,
};
@vertex
fn vs_main(
@builtin(vertex_index) in_vertex_index: u32,
) -> VertexOutput {
var out: VertexOutput;
out.position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
return out;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(0.3, 0.2, 0.1, 1.0);
}

View file

@ -37,14 +37,14 @@ impl AssetPaths for BlockTexture {
#[derive(Unique)] #[derive(Unique)]
#[repr(transparent)] #[repr(transparent)]
pub struct BlockTexturesAsset(pub wgpu::Texture); pub struct BlockTexturesPrefab(pub wgpu::Texture);
pub fn load_prefabs( pub fn load_prefabs(
storages: AllStoragesView, storages: AllStoragesView,
renderer: NonSendSync<UniqueView<Renderer>> renderer: NonSendSync<UniqueView<Renderer>>
) { ) {
log::info!("Loading textures..."); log::info!("Loading textures...");
storages.add_unique_non_send_sync(BlockTexturesAsset( storages.add_unique_non_send_sync(BlockTexturesPrefab(
load_asset_texture_array::<BlockTexture>("blocks".into(), &renderer) load_asset_texture_array::<BlockTexture>("blocks".into(), &renderer)
)); ));
} }

View file

@ -47,7 +47,7 @@ pub fn load_asset_texture_array<
//Ensure same size (skip if poisoned) //Ensure same size (skip if poisoned)
if !img_dim.is_poisoned() { if !img_dim.is_poisoned() {
let mut img_dim = img_dim.lock().unwrap(); let img_dim = img_dim.lock().unwrap();
if let Some(current_size) = img_dim.replace(dim_nonzero) { if let Some(current_size) = img_dim.replace(dim_nonzero) {
assert!(dim_nonzero == current_size, "image dimensions do not match"); assert!(dim_nonzero == current_size, "image dimensions do not match");
} }

View file

@ -81,13 +81,10 @@ pub fn process_glutin_events(world: &mut World, event: &Event<'_, ()>) {
pub fn initial_resize_event( pub fn initial_resize_event(
mut storages: AllStoragesViewMut, mut storages: AllStoragesViewMut,
) { ) {
let size = { let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
UVec2::new(renderer.size.width, renderer.size.height)
};
storages.add_entity(( storages.add_entity((
EventComponent, EventComponent,
WindowResizedEvent(size) WindowResizedEvent(UVec2::new(renderer.size.width, renderer.size.height))
)); ));
} }

View file

@ -213,10 +213,6 @@ pub fn kubi_main() {
#[allow(clippy::collapsible_match, clippy::single_match)] #[allow(clippy::collapsible_match, clippy::single_match)]
match event { match event {
Event::WindowEvent { event, .. } => match event { Event::WindowEvent { event, .. } => match event {
WindowEvent::Resized(new_size) => {
//this can be in a system but I don't care
world.borrow::<NonSendSync<UniqueViewMut<Renderer>>>().unwrap().resize(new_size);
}
WindowEvent::CloseRequested => { WindowEvent::CloseRequested => {
log::info!("exit requested"); log::info!("exit requested");
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;
@ -238,19 +234,16 @@ pub fn kubi_main() {
//Start rendering (maybe use custom views for this?) //Start rendering (maybe use custom views for this?)
let target = { let target = {
let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap(); let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
renderer.begin() renderer.render()
}; };
world.add_unique(target); world.add_unique_non_send_sync(RenderTarget(target));
//Run render workflow //Run render workflow
world.run_workload(render).unwrap(); world.run_workload(render).unwrap();
//Finish rendering //Finish rendering
{ let target = world.remove_unique::<RenderTarget>().unwrap();
let target = world.remove_unique::<RenderTarget>().unwrap(); target.0.finish().unwrap();
let renderer = world.borrow::<UniqueView<Renderer>>().unwrap();
renderer.end(target);
}
//After frame end //After frame end
world.run_workload(after_frame_end).unwrap(); world.run_workload(after_frame_end).unwrap();

View file

@ -18,11 +18,8 @@ pub mod selection_box;
pub mod entities; pub mod entities;
#[derive(Unique)] #[derive(Unique)]
pub struct RenderTarget { #[repr(transparent)]
pub output: wgpu::SurfaceTexture, pub struct RenderTarget(pub ());
pub view: wgpu::TextureView,
pub encoder: wgpu::CommandEncoder,
}
#[derive(Unique)] #[derive(Unique)]
#[repr(transparent)] #[repr(transparent)]
@ -144,9 +141,7 @@ impl Renderer {
}; };
surface.configure(&device, &config); surface.configure(&device, &config);
Self { Self { window, instance, surface, adapter, device, queue, size, config }
window, instance, surface, adapter, device, queue, size, config,
}
} }
/// do not call from async functions /// do not call from async functions
@ -155,51 +150,14 @@ impl Renderer {
} }
/// Start a new frame /// Start a new frame
pub fn begin(&self) -> RenderTarget { pub fn render() -> RenderTarget {
//Surface texture todo!()
let output = self.surface.get_current_texture().unwrap();
//View
let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default());
//Encoder
let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("RenderEncoder"),
});
//Begin render pass
{
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("RenderPass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.1,
g: 0.2,
b: 0.3,
a: 1.0,
}),
store: true,
},
})],
depth_stencil_attachment: None,
});
}
RenderTarget { output, view, encoder }
}
pub fn end(&self, target: RenderTarget) {
self.queue.submit([target.encoder.finish()]);
target.output.present();
} }
/// Resize the surface /// Resize the surface
/// ## Panics: /// ## Panics:
/// - ...if any dimension is equal to zero /// - ...if any dimension is equal to zero
pub fn resize(&mut self, new_size: PhysicalSize<u32>) { pub fn resize(&self, new_size: PhysicalSize<u32>) {
//XXX: just check instead? //XXX: just check instead?
assert!(new_size.width > 0, "width cannot be zero"); assert!(new_size.width > 0, "width cannot be zero");
assert!(new_size.height > 0, "height cannot be zero"); assert!(new_size.height > 0, "height cannot be zero");

View file

@ -1,18 +1,17 @@
use glam::{Vec3, Mat4, Quat, ivec3}; use glam::{Vec3, Mat4, Quat, ivec3};
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track, Unique}; use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track};
use wgpu::util::DeviceExt;
use crate::{ use crate::{
camera::Camera, camera::Camera,
player::MainPlayer, player::MainPlayer,
transform::Transform, transform::Transform,
assets::BlockTexturesAsset, assets::BlockTexturesPrefab,
world::{ world::{
ChunkStorage, ChunkStorage,
ChunkMeshStorage, ChunkMeshStorage,
chunk::CHUNK_SIZE, chunk::CHUNK_SIZE,
}, settings::GameSettings, }, settings::GameSettings,
}; };
use super::{RenderTarget, shaders::Shaders, Renderer}; use super::{RenderTarget, primitives::cube::CubePrimitive};
#[repr(C, packed)] #[repr(C, packed)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] #[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
@ -23,37 +22,7 @@ pub struct ChunkVertex {
pub tex_index: u8, pub tex_index: u8,
} }
#[repr(C, packed)] pub fn draw_world() {}
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct WorldUniform {
position_offset: [f32; 3],
view: [[f32; 4]; 4],
perspective: [[f32; 4]; 4],
}
pub fn draw_world(
renderer: UniqueView<Renderer>,
mut target: UniqueViewMut<RenderTarget>,
chunks: UniqueView<ChunkStorage>,
meshes: UniqueView<ChunkMeshStorage>,
shaders: UniqueView<Shaders>,
texture: UniqueView<BlockTexturesAsset>,
camera: View<Camera>,
settings: UniqueView<GameSettings>
) {
let camera = camera.iter().next().expect("No cameras in the scene");
for (&position, chunk) in &chunks.chunks {
if let Some(key) = chunk.mesh_index {
let mesh = meshes.get(key).expect("Mesh index pointing to nothing");
let world_position = position.as_vec3() * CHUNK_SIZE as f32;
//TODO culling
//Draw chunk mesh
}
}
}
#[cfg(fuck)] #[cfg(fuck)]
pub fn draw_world( pub fn draw_world(
@ -61,7 +30,7 @@ pub fn draw_world(
chunks: UniqueView<ChunkStorage>, chunks: UniqueView<ChunkStorage>,
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>, meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
program: NonSendSync<UniqueView<ChunkShaderPrefab>>, program: NonSendSync<UniqueView<ChunkShaderPrefab>>,
texture: NonSendSync<UniqueView<BlockTexturesAsset>>, texture: NonSendSync<UniqueView<BlockTexturesPrefab>>,
camera: View<Camera>, camera: View<Camera>,
settings: UniqueView<GameSettings> settings: UniqueView<GameSettings>
) { ) {

View file

@ -102,7 +102,7 @@ impl ChunkMeshStorage {
pub fn init_game_world( pub fn init_game_world(
storages: AllStoragesView, storages: AllStoragesView,
) { ) {
storages.add_unique(ChunkMeshStorage::new()); storages.add_unique_non_send_sync(ChunkMeshStorage::new());
storages.add_unique(ChunkStorage::new()); storages.add_unique(ChunkStorage::new());
storages.add_unique(ChunkTaskManager::new()); storages.add_unique(ChunkTaskManager::new());
storages.add_unique(BlockUpdateQueue::new()); storages.add_unique(BlockUpdateQueue::new());