use crate::utils; use approx::assert_relative_eq; use common::{comp::Controller, resources::Time, shared_server_config::ServerConstants}; use specs::WorldExt; use std::error::Error; use utils::{DT, DT_F64, EPSILON}; use vek::{approx, Vec2, Vec3}; use veloren_common_systems::add_local_systems; #[test] fn simple_run() { let mut state = utils::setup(); utils::create_player(&mut state); state.tick( DT, |dispatcher_builder| { add_local_systems(dispatcher_builder); }, false, None, &ServerConstants { day_cycle_coefficient: 24.0, }, |_, _| {}, ); } #[test] fn dont_fall_outside_world() -> Result<(), Box> { let mut state = utils::setup(); let p1 = utils::create_player(&mut state); { let mut storage = state.ecs_mut().write_storage::(); storage .insert(p1, common::comp::Pos(Vec3::new(1000.0, 1000.0, 265.0))) .unwrap(); } let (pos, vel, _) = utils::get_transform(&state, p1)?; assert_relative_eq!(pos.0.x, 1000.0); assert_relative_eq!(pos.0.y, 1000.0); assert_relative_eq!(pos.0.z, 265.0); assert_eq!(vel.0, Vec3::zero()); utils::tick(&mut state, DT); let (pos, vel, _) = utils::get_transform(&state, p1)?; assert_relative_eq!(pos.0.x, 1000.0); assert_relative_eq!(pos.0.y, 1000.0); assert_relative_eq!(pos.0.z, 265.0); assert_eq!(vel.0, Vec3::zero()); Ok(()) } #[test] fn fall_simple() -> Result<(), Box> { let mut state = utils::setup(); let p1 = utils::create_player(&mut state); let (pos, vel, _) = utils::get_transform(&state, p1)?; assert_relative_eq!(pos.0.x, 16.0); assert_relative_eq!(pos.0.y, 16.0); assert_relative_eq!(pos.0.z, 265.0); assert_eq!(vel.0, Vec3::zero()); utils::tick(&mut state, DT); let (pos, vel, _) = utils::get_transform(&state, p1)?; assert_relative_eq!(pos.0.x, 16.0); assert_relative_eq!(pos.0.y, 16.0); assert_relative_eq!(pos.0.z, 264.9975, epsilon = EPSILON); assert_relative_eq!(vel.0.z, -0.25, epsilon = EPSILON); utils::tick(&mut state, DT); let (pos, vel, _) = utils::get_transform(&state, p1)?; assert_relative_eq!(pos.0.z, 264.9925, epsilon = EPSILON); assert_relative_eq!(vel.0.z, -0.49969065, epsilon = EPSILON); utils::tick(&mut state, DT); let (pos, vel, _) = utils::get_transform(&state, p1)?; assert_relative_eq!(pos.0.z, 264.985, epsilon = EPSILON); assert_relative_eq!(vel.0.z, -0.7493813, epsilon = EPSILON); utils::tick(&mut state, DT * 7); let (pos, vel, _) = utils::get_transform(&state, p1)?; assert_relative_eq!(state.ecs_mut().read_resource::