mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
restructure stuff
This commit is contained in:
parent
a63cc4bd17
commit
00edf0d272
|
@ -1,15 +1,12 @@
|
||||||
use std::{io::{BufReader, prelude::*}, path::Path};
|
use hui::UiInstance;
|
||||||
use hui::{text::FontHandle, UiInstance};
|
|
||||||
use hui_glium::GliumUiRenderer;
|
use hui_glium::GliumUiRenderer;
|
||||||
use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut};
|
use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut};
|
||||||
use crate::{filesystem::AssetManager, rendering::{RenderTarget, Renderer, WindowSize}};
|
use crate::rendering::{RenderTarget, Renderer, WindowSize};
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
pub struct UiState {
|
pub struct UiState {
|
||||||
pub hui: UiInstance,
|
pub hui: UiInstance,
|
||||||
pub renderer: GliumUiRenderer,
|
pub renderer: GliumUiRenderer
|
||||||
//HACK: This is a temporary solution, i don't think fonts should be stored here
|
|
||||||
pub fonts: Vec<FontHandle>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kubi_ui_init(
|
pub fn kubi_ui_init(
|
||||||
|
@ -19,22 +16,9 @@ pub fn kubi_ui_init(
|
||||||
storages.add_unique_non_send_sync(UiState {
|
storages.add_unique_non_send_sync(UiState {
|
||||||
hui: UiInstance::new(),
|
hui: UiInstance::new(),
|
||||||
renderer: GliumUiRenderer::new(&renderer.display),
|
renderer: GliumUiRenderer::new(&renderer.display),
|
||||||
fonts: vec![],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Use prefab system for this
|
|
||||||
pub fn kubi_ui_load_assets(
|
|
||||||
asset_manager: UniqueView<AssetManager>,
|
|
||||||
mut ui: NonSendSync<UniqueViewMut<UiState>>
|
|
||||||
) {
|
|
||||||
let asset_handle = asset_manager.open_asset(Path::new("fonts/Crisp.ttf")).unwrap();
|
|
||||||
let mut font_data = vec![];
|
|
||||||
BufReader::new(asset_handle).read_to_end(&mut font_data).unwrap();
|
|
||||||
let font_handle = ui.hui.add_font_from_bytes(&font_data);
|
|
||||||
ui.fonts.push(font_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn kubi_ui_begin(
|
pub fn kubi_ui_begin(
|
||||||
mut ui: NonSendSync<UniqueViewMut<UiState>>
|
mut ui: NonSendSync<UniqueViewMut<UiState>>
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -13,7 +13,13 @@ use winit::{
|
||||||
use glam::vec3;
|
use glam::vec3;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
pub use kubi_shared::transform;
|
pub(crate) use kubi_shared::transform;
|
||||||
|
|
||||||
|
mod ui {
|
||||||
|
pub(crate) mod loading_screen;
|
||||||
|
pub(crate) mod connecting_screen;
|
||||||
|
}
|
||||||
|
pub(crate) use ui::{loading_screen, connecting_screen};
|
||||||
|
|
||||||
pub(crate) mod rendering;
|
pub(crate) mod rendering;
|
||||||
pub(crate) mod world;
|
pub(crate) mod world;
|
||||||
|
@ -33,8 +39,6 @@ pub(crate) mod hui_integration;
|
||||||
pub(crate) mod networking;
|
pub(crate) mod networking;
|
||||||
pub(crate) mod init;
|
pub(crate) mod init;
|
||||||
pub(crate) mod color;
|
pub(crate) mod color;
|
||||||
pub(crate) mod loading_screen;
|
|
||||||
pub(crate) mod connecting_screen;
|
|
||||||
pub(crate) mod fixed_timestamp;
|
pub(crate) mod fixed_timestamp;
|
||||||
pub(crate) mod filesystem;
|
pub(crate) mod filesystem;
|
||||||
pub(crate) mod client_physics;
|
pub(crate) mod client_physics;
|
||||||
|
@ -77,7 +81,7 @@ use control_flow::{exit_on_esc, insert_control_flow_unique, RequestExit};
|
||||||
use state::{is_ingame, is_ingame_or_loading, is_loading, init_state, update_state, is_connecting};
|
use state::{is_ingame, is_ingame_or_loading, is_loading, init_state, update_state, is_connecting};
|
||||||
use networking::{update_networking, update_networking_late, is_multiplayer, disconnect_on_exit, is_singleplayer};
|
use networking::{update_networking, update_networking_late, is_multiplayer, disconnect_on_exit, is_singleplayer};
|
||||||
use init::initialize_from_args;
|
use init::initialize_from_args;
|
||||||
use hui_integration::{kubi_ui_begin, kubi_ui_draw, kubi_ui_end, kubi_ui_init, kubi_ui_load_assets};
|
use hui_integration::{kubi_ui_begin, kubi_ui_draw, kubi_ui_end, kubi_ui_init};
|
||||||
use loading_screen::update_loading_screen;
|
use loading_screen::update_loading_screen;
|
||||||
use connecting_screen::update_connecting_screen;
|
use connecting_screen::update_connecting_screen;
|
||||||
use fixed_timestamp::init_fixed_timestamp_storage;
|
use fixed_timestamp::init_fixed_timestamp_storage;
|
||||||
|
@ -97,7 +101,6 @@ fn startup() -> Workload {
|
||||||
initial_resize_event,
|
initial_resize_event,
|
||||||
init_window_size,
|
init_window_size,
|
||||||
kubi_ui_init,
|
kubi_ui_init,
|
||||||
kubi_ui_load_assets,
|
|
||||||
load_prefabs,
|
load_prefabs,
|
||||||
init_primitives,
|
init_primitives,
|
||||||
insert_lock_state,
|
insert_lock_state,
|
||||||
|
|
|
@ -1,87 +1,103 @@
|
||||||
use shipyard::{NonSendSync, UniqueView, Unique, AllStoragesView};
|
use std::{io::{BufReader, Read}, path::Path};
|
||||||
use glium::{texture::{SrgbTexture2dArray, MipmapsOption}, Program};
|
use hui::text::FontHandle;
|
||||||
use kubi_shared::block::BlockTexture;
|
use shipyard::{AllStoragesView, NonSendSync, Unique, UniqueView, UniqueViewMut};
|
||||||
use crate::{rendering::Renderer, filesystem::AssetManager};
|
use glium::{texture::{SrgbTexture2dArray, MipmapsOption}, Program};
|
||||||
|
use kubi_shared::block::BlockTexture;
|
||||||
mod texture;
|
use crate::{filesystem::AssetManager, hui_integration::UiState, rendering::Renderer};
|
||||||
mod shaders;
|
|
||||||
|
mod texture;
|
||||||
use texture::load_texture2darray_prefab;
|
mod shaders;
|
||||||
use shaders::include_shader_prefab;
|
|
||||||
|
use texture::load_texture2darray_prefab;
|
||||||
pub trait AssetPaths {
|
use shaders::include_shader_prefab;
|
||||||
fn file_name(self) -> &'static str;
|
|
||||||
}
|
pub trait AssetPaths {
|
||||||
|
fn file_name(self) -> &'static str;
|
||||||
impl AssetPaths for BlockTexture {
|
}
|
||||||
fn file_name(self) -> &'static str {
|
|
||||||
match self {
|
impl AssetPaths for BlockTexture {
|
||||||
Self::Stone => "stone.png",
|
fn file_name(self) -> &'static str {
|
||||||
Self::Dirt => "dirt.png",
|
match self {
|
||||||
Self::GrassTop => "grass_top.png",
|
Self::Stone => "stone.png",
|
||||||
Self::GrassSide => "grass_side.png",
|
Self::Dirt => "dirt.png",
|
||||||
Self::Sand => "sand.png",
|
Self::GrassTop => "grass_top.png",
|
||||||
Self::Bedrock => "bedrock.png",
|
Self::GrassSide => "grass_side.png",
|
||||||
Self::Wood => "wood.png",
|
Self::Sand => "sand.png",
|
||||||
Self::WoodTop => "wood_top.png",
|
Self::Bedrock => "bedrock.png",
|
||||||
Self::Leaf => "leaf.png",
|
Self::Wood => "wood.png",
|
||||||
Self::Torch => "torch.png",
|
Self::WoodTop => "wood_top.png",
|
||||||
Self::TallGrass => "tall_grass.png",
|
Self::Leaf => "leaf.png",
|
||||||
Self::Snow => "snow.png",
|
Self::Torch => "torch.png",
|
||||||
Self::GrassSideSnow => "grass_side_snow.png",
|
Self::TallGrass => "tall_grass.png",
|
||||||
Self::Cobblestone => "cobblestone.png",
|
Self::Snow => "snow.png",
|
||||||
Self::Planks => "planks.png",
|
Self::GrassSideSnow => "grass_side_snow.png",
|
||||||
Self::WaterSolid => "solid_water.png",
|
Self::Cobblestone => "cobblestone.png",
|
||||||
}
|
Self::Planks => "planks.png",
|
||||||
}
|
Self::WaterSolid => "solid_water.png",
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#[derive(Unique)]
|
}
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct BlockTexturesPrefab(pub SrgbTexture2dArray);
|
#[derive(Unique)]
|
||||||
|
#[repr(transparent)]
|
||||||
#[derive(Unique)]
|
pub struct BlockTexturesPrefab(pub SrgbTexture2dArray);
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct ChunkShaderPrefab(pub Program);
|
#[derive(Unique)]
|
||||||
|
#[repr(transparent)]
|
||||||
#[derive(Unique)]
|
pub struct ChunkShaderPrefab(pub Program);
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct ColoredShaderPrefab(pub Program);
|
#[derive(Unique)]
|
||||||
|
#[repr(transparent)]
|
||||||
pub fn load_prefabs(
|
pub struct ColoredShaderPrefab(pub Program);
|
||||||
storages: AllStoragesView,
|
|
||||||
renderer: NonSendSync<UniqueView<Renderer>>,
|
#[derive(Unique)]
|
||||||
assman: UniqueView<AssetManager>
|
#[repr(transparent)]
|
||||||
) {
|
pub struct UiFontPrefab(pub FontHandle);
|
||||||
log::info!("Loading textures...");
|
|
||||||
storages.add_unique_non_send_sync(BlockTexturesPrefab(
|
pub fn load_prefabs(
|
||||||
load_texture2darray_prefab::<BlockTexture, _>(
|
storages: AllStoragesView,
|
||||||
&assman,
|
renderer: NonSendSync<UniqueView<Renderer>>,
|
||||||
"blocks".into(),
|
mut ui: NonSendSync<UniqueViewMut<UiState>>,
|
||||||
&renderer.display,
|
assman: UniqueView<AssetManager>
|
||||||
MipmapsOption::AutoGeneratedMipmaps
|
) {
|
||||||
)
|
log::info!("Loading textures...");
|
||||||
));
|
storages.add_unique_non_send_sync(BlockTexturesPrefab(
|
||||||
|
load_texture2darray_prefab::<BlockTexture, _>(
|
||||||
log::info!("Compiling shaders...");
|
&assman,
|
||||||
storages.add_unique_non_send_sync(ChunkShaderPrefab(
|
"blocks".into(),
|
||||||
include_shader_prefab!(
|
&renderer.display,
|
||||||
"world",
|
MipmapsOption::AutoGeneratedMipmaps
|
||||||
"../shaders/world.vert",
|
)
|
||||||
"../shaders/world.frag",
|
));
|
||||||
&renderer.display
|
|
||||||
)
|
log::info!("Loading the UI stuff...");
|
||||||
));
|
{
|
||||||
storages.add_unique_non_send_sync(ColoredShaderPrefab(
|
let asset_handle = assman.open_asset(Path::new("fonts/Crisp.ttf")).unwrap();
|
||||||
include_shader_prefab!(
|
let mut font_data = vec![];
|
||||||
"colored",
|
BufReader::new(asset_handle).read_to_end(&mut font_data).unwrap();
|
||||||
"../shaders/colored.vert",
|
let font_handle = ui.hui.add_font_from_bytes(&font_data);
|
||||||
"../shaders/colored.frag",
|
storages.add_unique(UiFontPrefab(font_handle));
|
||||||
&renderer.display
|
}
|
||||||
)
|
|
||||||
));
|
log::info!("Compiling shaders...");
|
||||||
|
storages.add_unique_non_send_sync(ChunkShaderPrefab(
|
||||||
log::info!("releasing shader compiler");
|
include_shader_prefab!(
|
||||||
|
"world",
|
||||||
renderer.display.release_shader_compiler();
|
"../shaders/world.vert",
|
||||||
}
|
"../shaders/world.frag",
|
||||||
|
&renderer.display
|
||||||
|
)
|
||||||
|
));
|
||||||
|
storages.add_unique_non_send_sync(ColoredShaderPrefab(
|
||||||
|
include_shader_prefab!(
|
||||||
|
"colored",
|
||||||
|
"../shaders/colored.vert",
|
||||||
|
"../shaders/colored.frag",
|
||||||
|
&renderer.display
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
log::info!("releasing shader compiler");
|
||||||
|
|
||||||
|
renderer.display.release_shader_compiler();
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ use crate::{
|
||||||
hui_integration::UiState,
|
hui_integration::UiState,
|
||||||
loading_screen::loading_screen_base,
|
loading_screen::loading_screen_base,
|
||||||
networking::ServerAddress,
|
networking::ServerAddress,
|
||||||
|
prefabs::UiFontPrefab,
|
||||||
rendering::WindowSize,
|
rendering::WindowSize,
|
||||||
state::{GameState, NextState}
|
state::{GameState, NextState}
|
||||||
};
|
};
|
||||||
|
@ -12,9 +13,9 @@ use crate::{
|
||||||
fn render_connecting_ui(
|
fn render_connecting_ui(
|
||||||
addr: UniqueView<ServerAddress>,
|
addr: UniqueView<ServerAddress>,
|
||||||
mut ui: NonSendSync<UniqueViewMut<UiState>>,
|
mut ui: NonSendSync<UniqueViewMut<UiState>>,
|
||||||
|
font: UniqueView<UiFontPrefab>,
|
||||||
size: UniqueView<WindowSize>,
|
size: UniqueView<WindowSize>,
|
||||||
) {
|
) {
|
||||||
let font_handle = ui.fonts[0];
|
|
||||||
ui.hui.add(
|
ui.hui.add(
|
||||||
loading_screen_base(vec![
|
loading_screen_base(vec![
|
||||||
Box::new(Text {
|
Box::new(Text {
|
||||||
|
@ -22,7 +23,7 @@ fn render_connecting_ui(
|
||||||
"Connecting to {}...",
|
"Connecting to {}...",
|
||||||
addr.0,
|
addr.0,
|
||||||
).into(),
|
).into(),
|
||||||
font: font_handle,
|
font: font.0,
|
||||||
text_size: 16,
|
text_size: 16,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
|
@ -6,12 +6,7 @@ use hui::{
|
||||||
use shipyard::{UniqueView, UniqueViewMut, Workload, NonSendSync, IntoWorkload};
|
use shipyard::{UniqueView, UniqueViewMut, Workload, NonSendSync, IntoWorkload};
|
||||||
use winit::keyboard::KeyCode;
|
use winit::keyboard::KeyCode;
|
||||||
use crate::{
|
use crate::{
|
||||||
hui_integration::UiState,
|
hui_integration::UiState, input::RawKbmInputState, networking::ServerAddress, prefabs::UiFontPrefab, rendering::WindowSize, state::{GameState, NextState}, world::ChunkStorage
|
||||||
input::RawKbmInputState,
|
|
||||||
networking::ServerAddress,
|
|
||||||
rendering::WindowSize,
|
|
||||||
state::{GameState, NextState},
|
|
||||||
world::ChunkStorage
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn loading_screen_base(elements: Vec<Box<dyn UiElement>>, bg_alpha: f32) -> Container {
|
pub fn loading_screen_base(elements: Vec<Box<dyn UiElement>>, bg_alpha: f32) -> Container {
|
||||||
|
@ -37,6 +32,7 @@ fn render_loading_ui(
|
||||||
addr: Option<UniqueView<ServerAddress>>,
|
addr: Option<UniqueView<ServerAddress>>,
|
||||||
world: UniqueView<ChunkStorage>,
|
world: UniqueView<ChunkStorage>,
|
||||||
mut ui: NonSendSync<UniqueViewMut<UiState>>,
|
mut ui: NonSendSync<UniqueViewMut<UiState>>,
|
||||||
|
font: UniqueView<UiFontPrefab>,
|
||||||
size: UniqueView<WindowSize>
|
size: UniqueView<WindowSize>
|
||||||
) {
|
) {
|
||||||
let loaded = world.chunks.iter().fold(0, |acc, (&_, chunk)| {
|
let loaded = world.chunks.iter().fold(0, |acc, (&_, chunk)| {
|
||||||
|
@ -46,14 +42,13 @@ fn render_loading_ui(
|
||||||
let value = loaded as f32 / total as f32;
|
let value = loaded as f32 / total as f32;
|
||||||
let percentage = value * 100.;
|
let percentage = value * 100.;
|
||||||
|
|
||||||
let font_handle = ui.fonts[0];
|
|
||||||
ui.hui.add(loading_screen_base(vec![
|
ui.hui.add(loading_screen_base(vec![
|
||||||
Box::new(Text {
|
Box::new(Text {
|
||||||
text: match addr {
|
text: match addr {
|
||||||
Some(addr) => format!("Connected to {}\nDownloading world data...", addr.0).into(),
|
Some(addr) => format!("Connected to {}\nDownloading world data...", addr.0).into(),
|
||||||
_ => "Loading...".into(),
|
_ => "Loading...".into(),
|
||||||
},
|
},
|
||||||
font: font_handle,
|
font: font.0,
|
||||||
text_size: 16,
|
text_size: 16,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
@ -70,7 +65,7 @@ fn render_loading_ui(
|
||||||
elements: vec![
|
elements: vec![
|
||||||
Box::new(Text {
|
Box::new(Text {
|
||||||
text: format!("{loaded}/{total} ({percentage:.1}%)").into(),
|
text: format!("{loaded}/{total} ({percentage:.1}%)").into(),
|
||||||
font: font_handle,
|
font: font.0,
|
||||||
text_size: 16,
|
text_size: 16,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
Loading…
Reference in a new issue