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]
|
||||
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging"]
|
||||
default-members = ["kubi"]
|
||||
resolver = "2"
|
||||
|
||||
[profile.release-with-debug]
|
||||
|
@ -15,7 +16,7 @@ opt-level = 1
|
|||
[profile.dev.package.uflow]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.glium]
|
||||
[profile.dev.package.wgpu]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.bracket-noise]
|
||||
|
|
|
@ -9,7 +9,7 @@ pub fn init() {
|
|||
use env_logger::{fmt::Color, Builder, Env};
|
||||
|
||||
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)
|
||||
.format(|buf, record| {
|
||||
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)]
|
||||
#[repr(transparent)]
|
||||
pub struct BlockTexturesPrefab(pub wgpu::Texture);
|
||||
pub struct BlockTexturesAsset(pub wgpu::Texture);
|
||||
|
||||
pub fn load_prefabs(
|
||||
storages: AllStoragesView,
|
||||
renderer: NonSendSync<UniqueView<Renderer>>
|
||||
) {
|
||||
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)
|
||||
));
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn load_asset_texture_array<
|
|||
|
||||
//Ensure same size (skip if 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) {
|
||||
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(
|
||||
mut storages: AllStoragesViewMut,
|
||||
) {
|
||||
let size = {
|
||||
let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
|
||||
UVec2::new(renderer.size.width, renderer.size.height)
|
||||
};
|
||||
storages.add_entity((
|
||||
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)]
|
||||
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 => {
|
||||
log::info!("exit requested");
|
||||
*control_flow = ControlFlow::Exit;
|
||||
|
@ -234,16 +238,19 @@ pub fn kubi_main() {
|
|||
//Start rendering (maybe use custom views for this?)
|
||||
let target = {
|
||||
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
|
||||
world.run_workload(render).unwrap();
|
||||
|
||||
//Finish rendering
|
||||
{
|
||||
let target = world.remove_unique::<RenderTarget>().unwrap();
|
||||
target.0.finish().unwrap();
|
||||
let renderer = world.borrow::<UniqueView<Renderer>>().unwrap();
|
||||
renderer.end(target);
|
||||
}
|
||||
|
||||
//After frame end
|
||||
world.run_workload(after_frame_end).unwrap();
|
||||
|
|
|
@ -18,8 +18,11 @@ pub mod selection_box;
|
|||
pub mod entities;
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
pub struct RenderTarget(pub ());
|
||||
pub struct RenderTarget {
|
||||
pub output: wgpu::SurfaceTexture,
|
||||
pub view: wgpu::TextureView,
|
||||
pub encoder: wgpu::CommandEncoder,
|
||||
}
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
|
@ -141,7 +144,9 @@ impl Renderer {
|
|||
};
|
||||
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
|
||||
|
@ -150,14 +155,51 @@ impl Renderer {
|
|||
}
|
||||
|
||||
/// Start a new frame
|
||||
pub fn render() -> RenderTarget {
|
||||
todo!()
|
||||
pub fn begin(&self) -> RenderTarget {
|
||||
//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
|
||||
/// ## Panics:
|
||||
/// - ...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?
|
||||
assert!(new_size.width > 0, "width cannot be zero");
|
||||
assert!(new_size.height > 0, "height cannot be zero");
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
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::{
|
||||
camera::Camera,
|
||||
player::MainPlayer,
|
||||
transform::Transform,
|
||||
assets::BlockTexturesPrefab,
|
||||
assets::BlockTexturesAsset,
|
||||
world::{
|
||||
ChunkStorage,
|
||||
ChunkMeshStorage,
|
||||
chunk::CHUNK_SIZE,
|
||||
}, settings::GameSettings,
|
||||
};
|
||||
use super::{RenderTarget, primitives::cube::CubePrimitive};
|
||||
use super::{RenderTarget, shaders::Shaders, Renderer};
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
|
@ -22,7 +23,37 @@ pub struct ChunkVertex {
|
|||
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)]
|
||||
pub fn draw_world(
|
||||
|
@ -30,7 +61,7 @@ pub fn draw_world(
|
|||
chunks: UniqueView<ChunkStorage>,
|
||||
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
|
||||
program: NonSendSync<UniqueView<ChunkShaderPrefab>>,
|
||||
texture: NonSendSync<UniqueView<BlockTexturesPrefab>>,
|
||||
texture: NonSendSync<UniqueView<BlockTexturesAsset>>,
|
||||
camera: View<Camera>,
|
||||
settings: UniqueView<GameSettings>
|
||||
) {
|
||||
|
|
|
@ -102,7 +102,7 @@ impl ChunkMeshStorage {
|
|||
pub fn init_game_world(
|
||||
storages: AllStoragesView,
|
||||
) {
|
||||
storages.add_unique_non_send_sync(ChunkMeshStorage::new());
|
||||
storages.add_unique(ChunkMeshStorage::new());
|
||||
storages.add_unique(ChunkStorage::new());
|
||||
storages.add_unique(ChunkTaskManager::new());
|
||||
storages.add_unique(BlockUpdateQueue::new());
|
||||
|
|
Loading…
Reference in a new issue