Compare commits

..

8 commits

15 changed files with 1106 additions and 1117 deletions

633
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -33,3 +33,8 @@ opt-level = 3
[profile.dev.package.rayon] [profile.dev.package.rayon]
opt-level = 3 opt-level = 3
#this is cursed as fuck
#enabling debug assertions here causes the game to abort
[profile.dev.package.android-activity]
debug-assertions = false

View file

@ -8,10 +8,10 @@ publish = false
kubi-shared = { path = "../kubi-shared" } kubi-shared = { path = "../kubi-shared" }
kubi-logging = { path = "../kubi-logging" } kubi-logging = { path = "../kubi-logging" }
log = "0.4" log = "0.4"
shipyard = { git = "https://github.com/leudz/shipyard", rev = "8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49", default-features = false, features = ["std", "proc", "thread_local"] } shipyard = { git = "https://github.com/leudz/shipyard", rev = "9099b990e", default-features = false, features = ["std", "proc", "thread_local"] }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
toml = "0.8" toml = "0.8"
glam = { version = "0.24", features = ["debug-glam-assert", "fast-math"] } glam = { version = "0.25", features = ["debug-glam-assert", "fast-math"] }
hashbrown = "0.14" hashbrown = "0.14"
nohash-hasher = "0.2" nohash-hasher = "0.2"
anyhow = "1.0" anyhow = "1.0"

View file

@ -5,9 +5,9 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
glam = { version = "0.24", features = ["debug-glam-assert", "fast-math", "serde"] } glam = { version = "0.25", features = ["debug-glam-assert", "fast-math", "serde"] }
shipyard = { git = "https://github.com/leudz/shipyard", rev = "8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49", default-features = false, features = ["std"] } shipyard = { git = "https://github.com/leudz/shipyard", rev = "9099b990e", default-features = false, features = ["std"] }
strum = { version = "0.25", features = ["derive"] } strum = { version = "0.26", features = ["derive"] }
num_enum = "0.7" num_enum = "0.7"
postcard = { version = "1.0", features = ["alloc"] } postcard = { version = "1.0", features = ["alloc"] }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }

View file

@ -10,7 +10,7 @@ publish = false
kubi-ui = { path = "../kubi-ui" } kubi-ui = { path = "../kubi-ui" }
kubi-ui-glium = { path = "../kubi-ui-glium" } kubi-ui-glium = { path = "../kubi-ui-glium" }
kubi-logging = { path = "../kubi-logging" } kubi-logging = { path = "../kubi-logging" }
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" } glium = { git = "https://github.com/glium/glium", rev = "a352c667" }
winit = "0.29" winit = "0.29"
glam = "0.24" glam = "0.25"
log = "0.4" log = "0.4"

View file

@ -7,6 +7,6 @@ publish = false
[dependencies] [dependencies]
kubi-ui = { path = "../kubi-ui", default-features = false } kubi-ui = { path = "../kubi-ui", default-features = false }
#kubi-ui = { path = "../kubi-ui" } #kubi-ui = { path = "../kubi-ui" }
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" } glium = { git = "https://github.com/glium/glium", rev = "a352c667" }
glam = "0.24" glam = "0.25"
log = "0.4" log = "0.4"

View file

@ -50,8 +50,8 @@ impl BufferPair {
pub fn new<F: Facade>(facade: &F) -> Self { pub fn new<F: Facade>(facade: &F) -> Self {
log::debug!("init ui buffers..."); log::debug!("init ui buffers...");
Self { Self {
vertex_buffer: VertexBuffer::empty_persistent(facade, 1024).unwrap(), vertex_buffer: VertexBuffer::empty_dynamic(facade, 1024).unwrap(),
index_buffer: IndexBuffer::empty_persistent(facade, PrimitiveType::TrianglesList, 1024).unwrap(), index_buffer: IndexBuffer::empty_dynamic(facade, PrimitiveType::TrianglesList, 1024).unwrap(),
vertex_count: 0, vertex_count: 0,
index_count: 0, index_count: 0,
} }
@ -68,13 +68,13 @@ impl BufferPair {
let new_idx_size = (need_idx + 1).next_power_of_two(); let new_idx_size = (need_idx + 1).next_power_of_two();
log::debug!("resizing buffers: vtx {} -> {}, idx {} -> {}", current_vtx_size, new_vtx_size, current_idx_size, new_idx_size); log::debug!("resizing buffers: vtx {} -> {}, idx {} -> {}", current_vtx_size, new_vtx_size, current_idx_size, new_idx_size);
if current_vtx_size != new_vtx_size { if current_vtx_size != new_vtx_size {
self.vertex_buffer = VertexBuffer::empty_persistent( self.vertex_buffer = VertexBuffer::empty_dynamic(
self.vertex_buffer.get_context(), self.vertex_buffer.get_context(),
new_vtx_size new_vtx_size
).unwrap(); ).unwrap();
} }
if current_idx_size != new_idx_size { if current_idx_size != new_idx_size {
self.index_buffer = IndexBuffer::empty_persistent( self.index_buffer = IndexBuffer::empty_dynamic(
self.index_buffer.get_context(), self.index_buffer.get_context(),
PrimitiveType::TrianglesList, PrimitiveType::TrianglesList,
new_idx_size new_idx_size

View file

@ -7,7 +7,7 @@ publish = false
[dependencies] [dependencies]
hashbrown = "0.14" hashbrown = "0.14"
nohash-hasher = "0.2" nohash-hasher = "0.2"
glam = "0.24" glam = "0.25"
fontdue = "0.8" fontdue = "0.8"
rect_packer = "0.2" rect_packer = "0.2"
log = "0.4" log = "0.4"

View file

@ -14,18 +14,18 @@ kubi-logging = { path = "../kubi-logging" }
kubi-ui = { path = "../kubi-ui" } kubi-ui = { path = "../kubi-ui" }
kubi-ui-glium = { path = "../kubi-ui-glium" } kubi-ui-glium = { path = "../kubi-ui-glium" }
log = "0.4" log = "0.4"
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" } glium = { git = "https://github.com/glium/glium", rev = "a352c667" }
glutin = "0.31" glutin = "0.31"
winit = { version = "0.29", features = ["android-native-activity"] } winit = { version = "0.29", features = ["android-native-activity"] }
glutin-winit = "0.4" glutin-winit = "0.4"
raw-window-handle = "0.5" raw-window-handle = "=0.5.*"
glam = { version = "0.24", features = ["debug-glam-assert", "fast-math"] } glam = { version = "0.25", features = ["debug-glam-assert", "fast-math"] }
image = { version = "0.24", default_features = false, features = ["png"] } image = { version = "0.24", default_features = false, features = ["png"] }
strum = { version = "0.25", features = ["derive"] } strum = { version = "0.26", features = ["derive"] }
hashbrown = "0.14" hashbrown = "0.14"
nohash-hasher = "0.2" nohash-hasher = "0.2"
rayon = "1.7" rayon = "1.7"
shipyard = { git = "https://github.com/leudz/shipyard", rev = "8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49", default-features = false, features = ["std", "proc", "thread_local"] } shipyard = { git = "https://github.com/leudz/shipyard", rev = "9099b990e", default-features = false, features = ["std", "proc", "thread_local"] }
anyhow = "1.0" anyhow = "1.0"
flume = "0.11" flume = "0.11"
gilrs = { version = "0.10", default_features = false, features = ["xinput"] } gilrs = { version = "0.10", default_features = false, features = ["xinput"] }
@ -37,7 +37,7 @@ tinyset = "0.4"
serde_json = { version = "1.0", optional = true } #only used for `generate_visualizer_data` serde_json = { version = "1.0", optional = true } #only used for `generate_visualizer_data`
[target.'cfg(target_os = "android")'.dependencies] [target.'cfg(target_os = "android")'.dependencies]
android-activity = "0.5" android-activity = "^0.5.2"
ndk = "0.8" ndk = "0.8"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
@ -59,15 +59,14 @@ assets = "../assets"
apk_name = "kubi" apk_name = "kubi"
theme = "@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen" theme = "@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen"
label = "Kubi" label = "Kubi"
orientation = "sensorLandscape"
[package.metadata.android.sdk] [package.metadata.android.sdk]
min_sdk_version = 16 min_sdk_version = 16
target_sdk_version = 30 target_sdk_version = 30
[[package.metadata.android.uses_feature]] [[package.metadata.android.uses_feature]]
required = true
glEsVersion = 0x00030000 glEsVersion = 0x00030000
required = true
[[package.metadata.android.uses_feature]] [[package.metadata.android.uses_feature]]
name = "android.hardware.touchscreen.multitouch" name = "android.hardware.touchscreen.multitouch"
@ -78,6 +77,13 @@ name = "android.hardware.touchscreen.multitouch.distinct"
required = true required = true
[package.metadata.android.application.activity] [package.metadata.android.application.activity]
label = "Kubi"
launch_mode = "singleTop"
orientation = "sensorLandscape"
config_changes = "orientation|keyboardHidden|screenLayout|screenSize" config_changes = "orientation|keyboardHidden|screenLayout|screenSize"
exported = true exported = true
resizeable_activity = true resizeable_activity = true
# [package.metadata.android.signing.release]
# path = "$HOME/.android/debug.keystore"
# keystore_password = "android"

View file

@ -0,0 +1,52 @@
//TODO client-side physics
//TODO move this to shared
use glam::{Mat4, Vec3};
use kubi_shared::transform::Transform;
use shipyard::{track, AllStoragesView, Component, IntoIter, Unique, UniqueView, View, ViewMut};
use crate::delta_time::DeltaTime;
#[derive(Unique)]
pub struct GlobalClPhysicsConfig {
pub gravity: Vec3,
}
#[derive(Component)]
pub struct ClPhysicsActor {
pub forces: Vec3,
pub velocity: Vec3,
pub terminal_velocity: f32,
//TODO: this should be configurable per block
pub friction_agains_ground: f32,
}
impl Default for ClPhysicsActor {
fn default() -> Self {
Self {
forces: Vec3::ZERO,
velocity: Vec3::ZERO,
terminal_velocity: 40.,
friction_agains_ground: 0.5,
}
}
}
pub fn init_client_physics(
storages: AllStoragesView,
) {
storages.add_unique(GlobalClPhysicsConfig {
gravity: Vec3::new(0., -9.8, 0.),
});
}
pub fn update_client_physics_late(
controllers: View<ClPhysicsActor>,
mut transforms: ViewMut<Transform, track::All>,
dt: UniqueView<DeltaTime>,
phy_conf: UniqueView<GlobalClPhysicsConfig>,
) {
// for (_, mut transform) in (&controllers, &mut transforms).iter() {
// let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
// translation.y -= dt.0.as_secs_f32() * 100.;
// transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
// }
}

View file

@ -1,6 +1,6 @@
use glam::UVec2; use glam::UVec2;
use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView}; use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView};
use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch, RawKeyEvent, TouchPhase}; use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch};
use crate::rendering::Renderer; use crate::rendering::Renderer;
pub mod player_actions; pub mod player_actions;
@ -24,7 +24,7 @@ pub struct TouchEvent(pub Touch);
#[derive(Component, Clone, Copy, Debug, Default)] #[derive(Component, Clone, Copy, Debug, Default)]
pub struct WindowResizedEvent(pub UVec2); pub struct WindowResizedEvent(pub UVec2);
pub fn process_glutin_events(world: &mut World, event: &Event<()>) { pub fn process_winit_events(world: &mut World, event: &Event<()>) {
#[allow(clippy::collapsible_match, clippy::single_match)] #[allow(clippy::collapsible_match, clippy::single_match)]
match event { match event {
Event::WindowEvent { window_id: _, event } => match event { Event::WindowEvent { window_id: _, event } => match event {

View file

@ -45,8 +45,9 @@ fn update_movement(
let movement = inputs.movement * 30. * dt.0.as_secs_f32(); let movement = inputs.movement * 30. * dt.0.as_secs_f32();
for (_, mut transform) in (&controllers, &mut transforms).iter() { for (_, mut transform) in (&controllers, &mut transforms).iter() {
let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation(); let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
translation += (rotation * Vec3::NEG_Z).normalize() * movement.y; let rotation_norm = rotation.normalize();
translation += (rotation * Vec3::X).normalize() * movement.x; translation += (rotation_norm * Vec3::NEG_Z).normalize() * movement.y;
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation); translation += (rotation_norm * Vec3::X).normalize() * movement.x;
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation_norm, translation);
} }
} }

View file

@ -37,6 +37,7 @@ pub(crate) mod loading_screen;
pub(crate) mod connecting_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;
use world::{ use world::{
init_game_world, init_game_world,
@ -51,7 +52,7 @@ use settings::{load_settings, GameSettings};
use camera::compute_cameras; use camera::compute_cameras;
use events::{ use events::{
clear_events, clear_events,
process_glutin_events, process_winit_events,
initial_resize_event, initial_resize_event,
player_actions::generate_move_events, player_actions::generate_move_events,
}; };
@ -81,6 +82,7 @@ use loading_screen::update_loading_screen;
use connecting_screen::switch_to_loading_if_connected; use connecting_screen::switch_to_loading_if_connected;
use fixed_timestamp::init_fixed_timestamp_storage; use fixed_timestamp::init_fixed_timestamp_storage;
use filesystem::AssetManager; use filesystem::AssetManager;
use client_physics::{init_client_physics, update_client_physics_late};
/// stuff required to init the renderer and other basic systems /// stuff required to init the renderer and other basic systems
fn pre_startup() -> Workload { fn pre_startup() -> Workload {
@ -104,6 +106,7 @@ fn startup() -> Workload {
init_input, init_input,
insert_control_flow_unique, insert_control_flow_unique,
init_delta_time, init_delta_time,
init_client_physics,
).into_sequential_workload() ).into_sequential_workload()
} }
@ -131,6 +134,7 @@ fn update() -> Workload {
).into_sequential_workload().run_if(is_ingame_or_loading), ).into_sequential_workload().run_if(is_ingame_or_loading),
( (
update_controllers, update_controllers,
update_client_physics_late,
generate_move_events, generate_move_events,
update_raycasts, update_raycasts,
update_block_placement, update_block_placement,
@ -179,9 +183,13 @@ pub fn android_main(app: android_activity::AndroidApp) {
} }
#[no_mangle] #[no_mangle]
pub fn kubi_main(#[cfg(target_os = "android")] app: android_activity::AndroidApp) { pub fn kubi_main(
#[cfg(target_os = "android")]
app: android_activity::AndroidApp
) {
//Attach console on release builds on windows //Attach console on release builds on windows
#[cfg(all(windows, not(debug_assertions)))] attach_console(); #[cfg(all(windows, not(debug_assertions)))]
attach_console();
//Print version //Print version
println!("{:─^54}", format!("[ ▄▀ Kubi client v. {} ]", env!("CARGO_PKG_VERSION"))); println!("{:─^54}", format!("[ ▄▀ Kubi client v. {} ]", env!("CARGO_PKG_VERSION")));
@ -253,7 +261,7 @@ pub fn kubi_main(#[cfg(target_os = "android")] app: android_activity::AndroidApp
window_target.set_control_flow(ControlFlow::Poll); window_target.set_control_flow(ControlFlow::Poll);
process_glutin_events(&mut world, &event); process_winit_events(&mut world, &event);
#[allow(clippy::collapsible_match, clippy::single_match)] #[allow(clippy::collapsible_match, clippy::single_match)]
match event { match event {

View file

@ -10,10 +10,11 @@ use kubi_shared::{
} }
}; };
use crate::{ use crate::{
transform::Transform,
camera::Camera, camera::Camera,
client_physics::ClPhysicsActor,
fly_controller::FlyController, fly_controller::FlyController,
world::raycast::LookingAtBlock, transform::Transform,
world::raycast::LookingAtBlock
}; };
#[derive(Component)] #[derive(Component)]
@ -23,7 +24,7 @@ pub fn spawn_player (
mut storages: AllStoragesViewMut, mut storages: AllStoragesViewMut,
) { ) {
log::info!("spawning player"); log::info!("spawning player");
storages.add_entity(( storages.add_entity(((
Player, Player,
MainPlayer, MainPlayer,
Entity, Entity,
@ -33,8 +34,10 @@ pub fn spawn_player (
FlyController, FlyController,
LookingAtBlock::default(), LookingAtBlock::default(),
PlayerHolding(Some(Block::Cobblestone)), PlayerHolding(Some(Block::Cobblestone)),
Username("LocalPlayer".into()) Username("LocalPlayer".into()),
)); ),(
ClPhysicsActor::default(),
)));
} }
pub fn spawn_local_player_multiplayer ( pub fn spawn_local_player_multiplayer (
@ -42,8 +45,7 @@ pub fn spawn_local_player_multiplayer (
init: ClientInitData init: ClientInitData
) { ) {
log::info!("spawning local multiplayer player"); log::info!("spawning local multiplayer player");
let entity_id = storages.add_entity(( let entity_id = storages.add_entity(((
(
Player, Player,
Client(init.client_id), Client(init.client_id),
MainPlayer, MainPlayer,
@ -55,9 +57,9 @@ pub fn spawn_local_player_multiplayer (
LookingAtBlock::default(), LookingAtBlock::default(),
PlayerHolding::default(), PlayerHolding::default(),
),( ),(
Username(init.username) Username(init.username),
) ClPhysicsActor::default(),
)); )));
//Add ourself to the client id map //Add ourself to the client id map
let mut client_id_map = storages.borrow::<UniqueViewMut<ClientIdMap>>().unwrap(); let mut client_id_map = storages.borrow::<UniqueViewMut<ClientIdMap>>().unwrap();