mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
wip stuff
This commit is contained in:
parent
098c168639
commit
81f169a89a
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -265,6 +265,20 @@ name = "bytemuck"
|
||||||
version = "1.13.1"
|
version = "1.13.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
|
checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
|
||||||
|
dependencies = [
|
||||||
|
"bytemuck_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytemuck_derive"
|
||||||
|
version = "1.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.23",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
|
@ -898,6 +912,7 @@ version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-activity",
|
"android-activity",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"bytemuck",
|
||||||
"flume",
|
"flume",
|
||||||
"gilrs",
|
"gilrs",
|
||||||
"glam",
|
"glam",
|
||||||
|
|
|
@ -30,6 +30,7 @@ serde_json = { version = "1.0", optional = true } #only used for `generate_visua
|
||||||
lz4_flex = { version = "0.11", default-features = false, features = ["std"] }
|
lz4_flex = { version = "0.11", default-features = false, features = ["std"] }
|
||||||
tinyset = "0.4"
|
tinyset = "0.4"
|
||||||
pollster = "0.3"
|
pollster = "0.3"
|
||||||
|
bytemuck = { version = "1.12", features = ["derive"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
android-activity = { version = "0.4", features = ["native-activity"] }
|
android-activity = { version = "0.4", features = ["native-activity"] }
|
||||||
|
|
|
@ -244,7 +244,7 @@ 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.display.draw()
|
renderer.render()
|
||||||
};
|
};
|
||||||
world.add_unique_non_send_sync(RenderTarget(target));
|
world.add_unique_non_send_sync(RenderTarget(target));
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
GuiComponent,
|
GuiComponent,
|
||||||
progressbar::ProgressbarComponent
|
progressbar::ProgressbarComponent
|
||||||
},
|
},
|
||||||
rendering::{WindowSize, if_resized},
|
rendering::{Renderer, if_resized},
|
||||||
input::RawKbmInputState,
|
input::RawKbmInputState,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ struct ProgressbarId(EntityId);
|
||||||
fn spawn_loading_screen(
|
fn spawn_loading_screen(
|
||||||
mut storages: AllStoragesViewMut,
|
mut storages: AllStoragesViewMut,
|
||||||
) {
|
) {
|
||||||
let size = *storages.borrow::<UniqueView<WindowSize>>().unwrap();
|
let size = storages.borrow::<UniqueView<Renderer>>().unwrap().size;
|
||||||
let entity = storages.add_entity((
|
let entity = storages.add_entity((
|
||||||
GuiComponent,
|
GuiComponent,
|
||||||
Transform2d(Mat3::from_scale_angle_translation(
|
Transform2d(Mat3::from_scale_angle_translation(
|
||||||
vec2(size.0.x as f32, 16.),
|
vec2(size.width as f32, 16.),
|
||||||
0.,
|
0.,
|
||||||
vec2(0., 0.)
|
vec2(0., 0.)
|
||||||
)),
|
)),
|
||||||
|
@ -35,12 +35,12 @@ fn spawn_loading_screen(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resize_progress_bar(
|
fn resize_progress_bar(
|
||||||
size: UniqueView<WindowSize>,
|
renderer: UniqueView<Renderer>,
|
||||||
bar: UniqueView<ProgressbarId>,
|
bar: UniqueView<ProgressbarId>,
|
||||||
mut transforms: ViewMut<Transform2d, track::All>
|
mut transforms: ViewMut<Transform2d, track::All>
|
||||||
) {
|
) {
|
||||||
let mut trans = (&mut transforms).get(bar.0).unwrap();
|
let mut trans = (&mut transforms).get(bar.0).unwrap();
|
||||||
trans.0.x_axis.x = size.0.x as f32;
|
trans.0.x_axis.x = renderer.size.width as f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_progress_bar_progress (
|
fn update_progress_bar_progress (
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView};
|
use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView};
|
||||||
|
use wgpu::SurfaceConfiguration;
|
||||||
use winit::{
|
use winit::{
|
||||||
event_loop::EventLoop,
|
event_loop::EventLoop,
|
||||||
window::{Window, WindowBuilder, Fullscreen},
|
window::{Window, WindowBuilder, Fullscreen},
|
||||||
|
@ -33,11 +34,14 @@ pub struct Renderer {
|
||||||
pub device: wgpu::Device,
|
pub device: wgpu::Device,
|
||||||
pub queue: wgpu::Queue,
|
pub queue: wgpu::Queue,
|
||||||
pub size: PhysicalSize<u32>,
|
pub size: PhysicalSize<u32>,
|
||||||
|
pub config: wgpu::SurfaceConfiguration,
|
||||||
}
|
}
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
pub async fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self {
|
pub async fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self {
|
||||||
log::info!("initializing display");
|
log::info!("initializing display");
|
||||||
|
|
||||||
|
// ========== Create a winit window ==========
|
||||||
|
|
||||||
//Build window
|
//Build window
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_title("kubi")
|
.with_title("kubi")
|
||||||
|
@ -63,20 +67,30 @@ impl Renderer {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
//Create wgpu stuff
|
let size = window.inner_size();
|
||||||
|
|
||||||
|
// ========== Create wgpu stuff ==========
|
||||||
|
|
||||||
|
// instance
|
||||||
|
|
||||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
backends: wgpu::Backends::all(),
|
backends: wgpu::Backends::all(),
|
||||||
dx12_shader_compiler: if cfg!(all(windows, feature = "dx12-dxc")) {
|
dx12_shader_compiler: if cfg!(all(windows, feature = "dx12-dxc")) {
|
||||||
|
// Better, but requires shipping ms dxil dlls
|
||||||
wgpu::Dx12Compiler::Dxc { dxil_path: None, dxc_path: None }
|
wgpu::Dx12Compiler::Dxc { dxil_path: None, dxc_path: None }
|
||||||
} else {
|
} else {
|
||||||
wgpu::Dx12Compiler::Fxc
|
wgpu::Dx12Compiler::Fxc
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// surface
|
||||||
|
|
||||||
let surface = unsafe {
|
let surface = unsafe {
|
||||||
instance.create_surface(&window)
|
instance.create_surface(&window)
|
||||||
}.expect("Failed to create a Surface");
|
}.expect("Failed to create a Surface");
|
||||||
|
|
||||||
|
// adapter
|
||||||
|
|
||||||
let adapter = instance.request_adapter(
|
let adapter = instance.request_adapter(
|
||||||
&wgpu::RequestAdapterOptions {
|
&wgpu::RequestAdapterOptions {
|
||||||
power_preference: wgpu::PowerPreference::HighPerformance,
|
power_preference: wgpu::PowerPreference::HighPerformance,
|
||||||
|
@ -84,6 +98,9 @@ impl Renderer {
|
||||||
force_fallback_adapter: false,
|
force_fallback_adapter: false,
|
||||||
},
|
},
|
||||||
).await.expect("Failed to create wgpu adapter");
|
).await.expect("Failed to create wgpu adapter");
|
||||||
|
log::info!("Adapter: {:?}", adapter.get_info());
|
||||||
|
|
||||||
|
// device/queue
|
||||||
|
|
||||||
let (device, queue) = adapter.request_device(
|
let (device, queue) = adapter.request_device(
|
||||||
&wgpu::DeviceDescriptor {
|
&wgpu::DeviceDescriptor {
|
||||||
|
@ -100,9 +117,31 @@ impl Renderer {
|
||||||
None,
|
None,
|
||||||
).await.unwrap();
|
).await.unwrap();
|
||||||
|
|
||||||
log::info!("Adapter: {:?}", adapter.get_info());
|
// surf. format
|
||||||
|
|
||||||
Self { window, instance, surface, adapter, device, queue, size: PhysicalSize::default() }
|
let surface_capabilities = surface.get_capabilities(&adapter);
|
||||||
|
let surface_format = surface_capabilities.formats.iter()
|
||||||
|
.copied()
|
||||||
|
.find(|f| f.is_srgb())
|
||||||
|
.unwrap_or(surface_capabilities.formats[0]);
|
||||||
|
|
||||||
|
// config
|
||||||
|
|
||||||
|
let config = wgpu::SurfaceConfiguration {
|
||||||
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
|
format: surface_format,
|
||||||
|
width: size.width,
|
||||||
|
height: size.height,
|
||||||
|
present_mode: match settings.vsync {
|
||||||
|
true => wgpu::PresentMode::AutoVsync,
|
||||||
|
false => wgpu::PresentMode::AutoNoVsync,
|
||||||
|
},
|
||||||
|
alpha_mode: surface_capabilities.alpha_modes[0],
|
||||||
|
view_formats: vec![],
|
||||||
|
};
|
||||||
|
surface.configure(&device, &config);
|
||||||
|
|
||||||
|
Self { window, instance, surface, adapter, device, queue, size, config };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// do not call from async functions
|
/// do not call from async functions
|
||||||
|
@ -112,7 +151,20 @@ impl Renderer {
|
||||||
|
|
||||||
/// Start a new frame
|
/// Start a new frame
|
||||||
pub fn render() -> RenderTarget {
|
pub fn render() -> RenderTarget {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resize the surface
|
||||||
|
/// ## Panics:
|
||||||
|
/// - ...if any dimension is equal to zero
|
||||||
|
pub fn resize(&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");
|
||||||
|
self.size = new_size;
|
||||||
|
self.config.width = new_size.width;
|
||||||
|
self.config.height = new_size.height;
|
||||||
|
self.surface.configure(&self.device, &self.config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ pub fn render_entities(
|
||||||
entities: View<Entity>,
|
entities: View<Entity>,
|
||||||
transform: View<Transform>,
|
transform: View<Transform>,
|
||||||
) {
|
) {
|
||||||
|
#[cfg(fuck)] {
|
||||||
let (camera_id, camera) = camera.iter().with_id().next().expect("No cameras in the scene");
|
let (camera_id, camera) = camera.iter().with_id().next().expect("No cameras in the scene");
|
||||||
|
|
||||||
let draw_parameters = DrawParameters {
|
let draw_parameters = DrawParameters {
|
||||||
|
@ -55,3 +56,4 @@ pub fn render_entities(
|
||||||
// ).unwrap();
|
// ).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
use shipyard::{AllStoragesView, NonSendSync, UniqueView, Unique};
|
use shipyard::{AllStoragesView, NonSendSync, UniqueView, Unique};
|
||||||
use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType};
|
|
||||||
use crate::rendering::Renderer;
|
use crate::rendering::Renderer;
|
||||||
use super::PositionOnlyVertex;
|
use super::PositionOnlyVertex;
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
pub struct CubePrimitive(pub VertexBuffer<PositionOnlyVertex>, pub IndexBuffer<u16>);
|
pub struct CubePrimitive {
|
||||||
|
pub vert: wgpu::Buffer,
|
||||||
|
pub idx: wgpu::Buffer
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
pub struct CenteredCubePrimitive(pub VertexBuffer<PositionOnlyVertex>, pub IndexBuffer<u16>);
|
pub struct CenteredCubePrimitive {
|
||||||
|
pub vert: wgpu::Buffer,
|
||||||
|
pub idx: wgpu::Buffer
|
||||||
|
}
|
||||||
|
|
||||||
const CENTERED_CUBE_VERTICES: &[PositionOnlyVertex] = &[
|
const CENTERED_CUBE_VERTICES: &[PositionOnlyVertex] = &[
|
||||||
// front
|
// front
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
use super::{RenderTarget, primitives::cube::CubePrimitive};
|
use super::{RenderTarget, primitives::cube::CubePrimitive};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
pub struct ChunkVertex {
|
pub struct ChunkVertex {
|
||||||
pub position: [f32; 3],
|
pub position: [f32; 3],
|
||||||
pub normal: [f32; 3],
|
pub normal: [f32; 3],
|
||||||
|
@ -35,6 +35,7 @@ pub fn draw_world(
|
||||||
camera: View<Camera>,
|
camera: View<Camera>,
|
||||||
settings: UniqueView<GameSettings>
|
settings: UniqueView<GameSettings>
|
||||||
) {
|
) {
|
||||||
|
#[cfg(fuck)] {
|
||||||
let camera = camera.iter().next().expect("No cameras in the scene");
|
let camera = camera.iter().next().expect("No cameras in the scene");
|
||||||
let draw_parameters = DrawParameters {
|
let draw_parameters = DrawParameters {
|
||||||
depth: Depth {
|
depth: Depth {
|
||||||
|
@ -92,6 +93,7 @@ pub fn draw_world(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn draw_current_chunk_border(
|
pub fn draw_current_chunk_border(
|
||||||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||||
|
@ -102,6 +104,7 @@ pub fn draw_current_chunk_border(
|
||||||
camera: View<Camera>,
|
camera: View<Camera>,
|
||||||
settings: UniqueView<GameSettings>,
|
settings: UniqueView<GameSettings>,
|
||||||
) {
|
) {
|
||||||
|
#[cfg(fuck)] {
|
||||||
if cfg!(target_os = "android") {
|
if cfg!(target_os = "android") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -164,3 +167,4 @@ pub fn draw_current_chunk_border(
|
||||||
}
|
}
|
||||||
).unwrap();
|
).unwrap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue