From 1acf08390a4e69d97b29482b2475767f702668c7 Mon Sep 17 00:00:00 2001 From: Imbris Date: Tue, 31 Dec 2019 16:37:55 -0500 Subject: [PATCH] Fix issue where controller events aren't processed while mounted. Fix non humanoids being able to climb and glide. --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- common/src/sys/controller.rs | 62 +++++++++++++++++++++--------------- common/src/sys/mod.rs | 4 +-- common/src/sys/mount.rs | 18 +++++++++-- common/src/sys/movement.rs | 3 +- 6 files changed, 57 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50b2594f95..9874892a9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed the bow fire rate - Healthbars now flash on critical health - Fixed ghosts when going back to character screen +- Fixed not being able to unmount +- Fixed non-humanoids being able to climb and glide ### Removed diff --git a/Cargo.toml b/Cargo.toml index 1c26a0fa62..122302dbfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ opt-level = 2 inherits= 'dev' debug = true -# this profil is used for veloren releases, compile time doesn't matter +# this profile is used for veloren releases, compile time doesn't matter # we need stacktraces, light debug information, as much checks as possible # I would like to put it in a seperate `official_release` target, but that doesnt share caches with `cargo test` and `cargo bench` [profile.release] diff --git a/common/src/sys/controller.rs b/common/src/sys/controller.rs index 999ebbba4a..ddc8ad08f8 100644 --- a/common/src/sys/controller.rs +++ b/common/src/sys/controller.rs @@ -327,6 +327,24 @@ impl<'a> System<'a> for Sys { // Or do nothing continue; } + + // Process controller events + for event in controller.events.drain(..) { + match event { + ControlEvent::Mount(mountee_uid) => { + if let Some(mountee_entity) = + uid_allocator.retrieve_entity_internal(mountee_uid.id()) + { + server_emitter.emit(ServerEvent::Mount(entity, mountee_entity)); + } + } + ControlEvent::Unmount => server_emitter.emit(ServerEvent::Unmount(entity)), + ControlEvent::InventoryManip(manip) => { + server_emitter.emit(ServerEvent::InventoryManip(entity, manip)) + } //ControlEvent::Respawn => server_emitter.emit(ServerEvent::Unmount(entity)), + } + } + // If mounted, character state is controlled by mount if mount.is_some() { character.movement = Sit; @@ -394,16 +412,17 @@ impl<'a> System<'a> for Sys { // Any Action + Falling (action_state, Fall) => { character.movement = get_state_from_move_dir(&inputs.move_dir); - if inputs.glide.is_pressed() { + if inputs.glide.is_pressed() && can_glide(body) { character.movement = Glide; continue; } // Try to climb if let (true, Some(_wall_dir)) = ( - inputs.climb.is_pressed() | inputs.climb_down.is_pressed() - && body.is_humanoid(), + (inputs.climb.is_pressed() | inputs.climb_down.is_pressed()) + && can_climb(body), physics.on_wall, ) { + println!("here 1"); character.movement = Climb; continue; } @@ -530,10 +549,11 @@ impl<'a> System<'a> for Sys { // Try to climb if let (true, Some(_wall_dir)) = ( - inputs.climb.is_pressed() | inputs.climb_down.is_pressed() - && body.is_humanoid(), + (inputs.climb.is_pressed() | inputs.climb_down.is_pressed()) + && can_climb(body), physics.on_wall, ) { + println!("here 2"); character.movement = Climb; continue; } @@ -578,9 +598,7 @@ impl<'a> System<'a> for Sys { // While not on ground ... else { // Try to glide - if physics.on_wall == None - && inputs.glide.is_pressed() - && body.is_humanoid() + if physics.on_wall == None && inputs.glide.is_pressed() && can_glide(&body) { character.movement = Glide; continue; @@ -652,7 +670,8 @@ impl<'a> System<'a> for Sys { if !inputs.glide.is_pressed() { character.movement = Fall; - } else if let Some(_wall_dir) = physics.on_wall { + } else if let (Some(_wall_dir), true) = (physics.on_wall, can_climb(body)) { + println!("here 3"); character.movement = Climb; } @@ -681,23 +700,14 @@ impl<'a> System<'a> for Sys { // character.movement = Fall; // } }; - - // Process other controller events - for event in controller.events.drain(..) { - match event { - ControlEvent::Mount(mountee_uid) => { - if let Some(mountee_entity) = - uid_allocator.retrieve_entity_internal(mountee_uid.id()) - { - server_emitter.emit(ServerEvent::Mount(entity, mountee_entity)); - } - } - ControlEvent::Unmount => server_emitter.emit(ServerEvent::Unmount(entity)), - ControlEvent::InventoryManip(manip) => { - server_emitter.emit(ServerEvent::InventoryManip(entity, manip)) - } //ControlEvent::Respawn => server_emitter.emit(ServerEvent::Unmount(entity)), - } - } } } } + +fn can_glide(body: &Body) -> bool { + body.is_humanoid() +} + +fn can_climb(body: &Body) -> bool { + body.is_humanoid() +} diff --git a/common/src/sys/mod.rs b/common/src/sys/mod.rs index 8006c20abc..6f2c402318 100644 --- a/common/src/sys/mod.rs +++ b/common/src/sys/mod.rs @@ -24,8 +24,8 @@ const CLEANUP_SYS: &str = "cleanup_sys"; pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch_builder.add(agent::Sys, AGENT_SYS, &[]); - dispatch_builder.add(controller::Sys, CONTROLLER_SYS, &[AGENT_SYS]); - dispatch_builder.add(mount::Sys, MOUNT_SYS, &[CONTROLLER_SYS]); + dispatch_builder.add(mount::Sys, MOUNT_SYS, &[AGENT_SYS]); + dispatch_builder.add(controller::Sys, CONTROLLER_SYS, &[AGENT_SYS, MOUNT_SYS]); dispatch_builder.add(movement::Sys, MOVEMENT_SYS, &[]); dispatch_builder.add(combat::Sys, COMBAT_SYS, &[CONTROLLER_SYS]); dispatch_builder.add(stats::Sys, STATS_SYS, &[COMBAT_SYS]); diff --git a/common/src/sys/mount.rs b/common/src/sys/mount.rs index 741ee9212d..acb0e65b5e 100644 --- a/common/src/sys/mount.rs +++ b/common/src/sys/mount.rs @@ -40,9 +40,15 @@ impl<'a> System<'a> for Sys { match mount_states.get_unchecked() { MountState::Unmounted => {} MountState::MountedBy(mounter_uid) => { - if let Some((controller, mounter)) = uid_allocator + // Note: currently controller events are not passed through since none of them + // are currently relevant to controlling the mounted entity + if let Some((inputs, mounter)) = uid_allocator .retrieve_entity_internal(mounter_uid.id()) - .and_then(|mounter| controllers.get(mounter).cloned().map(|x| (x, mounter))) + .and_then(|mounter| { + controllers + .get(mounter) + .map(|c| (c.inputs.clone(), mounter)) + }) { // TODO: consider joining on these? (remember we can use .maybe()) let pos = positions.get(entity).copied(); @@ -53,7 +59,13 @@ impl<'a> System<'a> for Sys { let _ = orientations.insert(mounter, ori); let _ = velocities.insert(mounter, vel); } - let _ = controllers.insert(entity, controller); + let _ = controllers.insert( + entity, + Controller { + inputs, + ..Default::default() + }, + ); } else { *(mount_states.get_mut_unchecked()) = MountState::Unmounted; } diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index 4c85dfc8cc..805de636a4 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -209,8 +209,7 @@ impl<'a> System<'a> for Sys { // Climb if let (true, Some(_wall_dir)) = ( - (inputs.climb.is_pressed() | inputs.climb_down.is_pressed()) - && vel.0.z <= CLIMB_SPEED, + character.movement == Climb && vel.0.z <= CLIMB_SPEED, physics.on_wall, ) { if inputs.climb_down.is_pressed() && !inputs.climb.is_pressed() {