mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
Compare commits
3 commits
3b752dfbf8
...
9532161ed7
Author | SHA1 | Date | |
---|---|---|---|
griffi-gh | 9532161ed7 | ||
griffi-gh | 37ced81e7b | ||
griffi-gh | 34b9398e80 |
|
@ -1,5 +1,6 @@
|
||||||
[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]
|
||||||
|
@ -15,7 +16,7 @@ opt-level = 1
|
||||||
[profile.dev.package.uflow]
|
[profile.dev.package.uflow]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
||||||
[profile.dev.package.glium]
|
[profile.dev.package.wgpu]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
||||||
[profile.dev.package.bracket-noise]
|
[profile.dev.package.bracket-noise]
|
||||||
|
|
|
@ -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");
|
.filter_or("RUST_LOG", "trace,gilrs=warn,rusty_xinput=warn,wgpu=warn,wgpu_core=warn,wgpu_hal=error");
|
||||||
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();
|
||||||
|
|
|
@ -1 +1,19 @@
|
||||||
//TODO migrate
|
//TODO migrate, this is just some filler code to make the game compile
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -37,14 +37,14 @@ impl AssetPaths for BlockTexture {
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct BlockTexturesPrefab(pub wgpu::Texture);
|
pub struct BlockTexturesAsset(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(BlockTexturesPrefab(
|
storages.add_unique_non_send_sync(BlockTexturesAsset(
|
||||||
load_asset_texture_array::<BlockTexture>("blocks".into(), &renderer)
|
load_asset_texture_array::<BlockTexture>("blocks".into(), &renderer)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 img_dim = img_dim.lock().unwrap();
|
let mut 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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,10 +81,13 @@ 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 renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
|
let size = {
|
||||||
|
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(UVec2::new(renderer.size.width, renderer.size.height))
|
WindowResizedEvent(size)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,10 @@ 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;
|
||||||
|
@ -234,16 +238,19 @@ 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.render()
|
renderer.begin()
|
||||||
};
|
};
|
||||||
world.add_unique_non_send_sync(RenderTarget(target));
|
world.add_unique(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();
|
{
|
||||||
target.0.finish().unwrap();
|
let target = world.remove_unique::<RenderTarget>().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();
|
||||||
|
|
|
@ -18,8 +18,11 @@ pub mod selection_box;
|
||||||
pub mod entities;
|
pub mod entities;
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
#[repr(transparent)]
|
pub struct RenderTarget {
|
||||||
pub struct RenderTarget(pub ());
|
pub output: wgpu::SurfaceTexture,
|
||||||
|
pub view: wgpu::TextureView,
|
||||||
|
pub encoder: wgpu::CommandEncoder,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
@ -116,7 +119,7 @@ impl Renderer {
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
).await.unwrap();
|
).await.unwrap();
|
||||||
|
|
||||||
// surf. format
|
// surf. format
|
||||||
|
|
||||||
let surface_capabilities = surface.get_capabilities(&adapter);
|
let surface_capabilities = surface.get_capabilities(&adapter);
|
||||||
|
@ -141,7 +144,9 @@ impl Renderer {
|
||||||
};
|
};
|
||||||
surface.configure(&device, &config);
|
surface.configure(&device, &config);
|
||||||
|
|
||||||
Self { window, instance, surface, adapter, device, queue, size, config }
|
Self {
|
||||||
|
window, instance, surface, adapter, device, queue, size, config,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// do not call from async functions
|
/// do not call from async functions
|
||||||
|
@ -150,14 +155,51 @@ impl Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start a new frame
|
/// Start a new frame
|
||||||
pub fn render() -> RenderTarget {
|
pub fn begin(&self) -> RenderTarget {
|
||||||
todo!()
|
//Surface texture
|
||||||
|
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(&self, new_size: PhysicalSize<u32>) {
|
pub fn resize(&mut 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");
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
use glam::{Vec3, Mat4, Quat, ivec3};
|
use glam::{Vec3, Mat4, Quat, ivec3};
|
||||||
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track};
|
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track, Unique};
|
||||||
|
use wgpu::util::DeviceExt;
|
||||||
use crate::{
|
use crate::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
player::MainPlayer,
|
player::MainPlayer,
|
||||||
transform::Transform,
|
transform::Transform,
|
||||||
assets::BlockTexturesPrefab,
|
assets::BlockTexturesAsset,
|
||||||
world::{
|
world::{
|
||||||
ChunkStorage,
|
ChunkStorage,
|
||||||
ChunkMeshStorage,
|
ChunkMeshStorage,
|
||||||
chunk::CHUNK_SIZE,
|
chunk::CHUNK_SIZE,
|
||||||
}, settings::GameSettings,
|
}, settings::GameSettings,
|
||||||
};
|
};
|
||||||
use super::{RenderTarget, primitives::cube::CubePrimitive};
|
use super::{RenderTarget, shaders::Shaders, Renderer};
|
||||||
|
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
|
@ -22,15 +23,45 @@ pub struct ChunkVertex {
|
||||||
pub tex_index: u8,
|
pub tex_index: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_world() {}
|
#[repr(C, packed)]
|
||||||
|
#[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(
|
||||||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||||
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<BlockTexturesPrefab>>,
|
texture: NonSendSync<UniqueView<BlockTexturesAsset>>,
|
||||||
camera: View<Camera>,
|
camera: View<Camera>,
|
||||||
settings: UniqueView<GameSettings>
|
settings: UniqueView<GameSettings>
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -102,7 +102,7 @@ impl ChunkMeshStorage {
|
||||||
pub fn init_game_world(
|
pub fn init_game_world(
|
||||||
storages: AllStoragesView,
|
storages: AllStoragesView,
|
||||||
) {
|
) {
|
||||||
storages.add_unique_non_send_sync(ChunkMeshStorage::new());
|
storages.add_unique(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());
|
||||||
|
|
Loading…
Reference in a new issue