mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-26 05:38:20 -06:00
wip cl physics
This commit is contained in:
parent
d49c858cd8
commit
5f2f27396b
52
kubi/src/client_physics.rs
Normal file
52
kubi/src/client_physics.rs
Normal 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);
|
||||
// }
|
||||
}
|
|
@ -37,6 +37,7 @@ pub(crate) mod loading_screen;
|
|||
pub(crate) mod connecting_screen;
|
||||
pub(crate) mod fixed_timestamp;
|
||||
pub(crate) mod filesystem;
|
||||
pub(crate) mod client_physics;
|
||||
|
||||
use world::{
|
||||
init_game_world,
|
||||
|
@ -81,6 +82,7 @@ use loading_screen::update_loading_screen;
|
|||
use connecting_screen::switch_to_loading_if_connected;
|
||||
use fixed_timestamp::init_fixed_timestamp_storage;
|
||||
use filesystem::AssetManager;
|
||||
use client_physics::{init_client_physics, update_client_physics_late};
|
||||
|
||||
/// stuff required to init the renderer and other basic systems
|
||||
fn pre_startup() -> Workload {
|
||||
|
@ -104,6 +106,7 @@ fn startup() -> Workload {
|
|||
init_input,
|
||||
insert_control_flow_unique,
|
||||
init_delta_time,
|
||||
init_client_physics,
|
||||
).into_sequential_workload()
|
||||
}
|
||||
|
||||
|
@ -131,6 +134,7 @@ fn update() -> Workload {
|
|||
).into_sequential_workload().run_if(is_ingame_or_loading),
|
||||
(
|
||||
update_controllers,
|
||||
update_client_physics_late,
|
||||
generate_move_events,
|
||||
update_raycasts,
|
||||
update_block_placement,
|
||||
|
|
|
@ -10,10 +10,11 @@ use kubi_shared::{
|
|||
}
|
||||
};
|
||||
use crate::{
|
||||
transform::Transform,
|
||||
camera::Camera,
|
||||
client_physics::ClPhysicsActor,
|
||||
fly_controller::FlyController,
|
||||
world::raycast::LookingAtBlock,
|
||||
transform::Transform,
|
||||
world::raycast::LookingAtBlock
|
||||
};
|
||||
|
||||
#[derive(Component)]
|
||||
|
@ -23,7 +24,7 @@ pub fn spawn_player (
|
|||
mut storages: AllStoragesViewMut,
|
||||
) {
|
||||
log::info!("spawning player");
|
||||
storages.add_entity((
|
||||
storages.add_entity(((
|
||||
Player,
|
||||
MainPlayer,
|
||||
Entity,
|
||||
|
@ -33,8 +34,10 @@ pub fn spawn_player (
|
|||
FlyController,
|
||||
LookingAtBlock::default(),
|
||||
PlayerHolding(Some(Block::Cobblestone)),
|
||||
Username("LocalPlayer".into())
|
||||
));
|
||||
Username("LocalPlayer".into()),
|
||||
),(
|
||||
ClPhysicsActor::default(),
|
||||
)));
|
||||
}
|
||||
|
||||
pub fn spawn_local_player_multiplayer (
|
||||
|
@ -42,8 +45,7 @@ pub fn spawn_local_player_multiplayer (
|
|||
init: ClientInitData
|
||||
) {
|
||||
log::info!("spawning local multiplayer player");
|
||||
let entity_id = storages.add_entity((
|
||||
(
|
||||
let entity_id = storages.add_entity(((
|
||||
Player,
|
||||
Client(init.client_id),
|
||||
MainPlayer,
|
||||
|
@ -55,9 +57,9 @@ pub fn spawn_local_player_multiplayer (
|
|||
LookingAtBlock::default(),
|
||||
PlayerHolding::default(),
|
||||
),(
|
||||
Username(init.username)
|
||||
)
|
||||
));
|
||||
Username(init.username),
|
||||
ClPhysicsActor::default(),
|
||||
)));
|
||||
|
||||
//Add ourself to the client id map
|
||||
let mut client_id_map = storages.borrow::<UniqueViewMut<ClientIdMap>>().unwrap();
|
||||
|
|
Loading…
Reference in a new issue