Merge branch 'zesterer/small-fixes' into 'master'

Small fixes

Closes #174, #114, #148, and #176

See merge request veloren/veloren!266
This commit is contained in:
Joshua Barretto 2019-06-29 16:11:35 +00:00
commit e8fbab7ba8
8 changed files with 87 additions and 131 deletions

View File

@ -1,5 +1,7 @@
use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
const MAX_ALIAS_LEN: usize = 32;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Player {
pub alias: String,
@ -13,6 +15,12 @@ impl Player {
view_distance,
}
}
pub fn is_valid(&self) -> bool {
self.alias.chars().all(|c| c.is_alphanumeric() || c == '_')
&& self.alias.len() <= MAX_ALIAS_LEN
// TODO: Check view distance here based on server config too
}
}
impl Component for Player {

View File

@ -14,7 +14,7 @@ const HUMANOID_ACCEL: f32 = 70.0;
const HUMANOID_SPEED: f32 = 120.0;
const HUMANOID_AIR_ACCEL: f32 = 10.0;
const HUMANOID_AIR_SPEED: f32 = 100.0;
const HUMANOID_JUMP_ACCEL: f32 = 16.0;
const HUMANOID_JUMP_ACCEL: f32 = 17.0;
const ROLL_ACCEL: f32 = 120.0;
const ROLL_SPEED: f32 = 550.0;
const GLIDE_ACCEL: f32 = 15.0;
@ -130,7 +130,7 @@ impl<'a> System<'a> for Sys {
}
// Set direction based on velocity
if vel.0.magnitude_squared() != 0.0 {
if vel.0.magnitude_squared() > 0.1 {
ori.0 = vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0);
}
@ -146,7 +146,7 @@ impl<'a> System<'a> for Sys {
// Basic collision with terrain
let player_rad = 0.3f32; // half-width of the player's AABB
let player_height = 1.55f32;
let player_height = 1.5f32;
// Probe distances
let hdist = player_rad.ceil() as i32;
@ -253,8 +253,12 @@ impl<'a> System<'a> for Sys {
// When the resolution direction is non-vertical, we must be colliding with a wall
// If the space above is free...
if resolve_dir.z == 0.0
&& !collision_with(pos.0 + Vec3::unit_z() * 1.1, near_iter.clone())
if !collision_with(pos.0 + Vec3::unit_z() * 1.1, near_iter.clone())
&& resolve_dir.z == 0.0
&& terrain
.get((pos.0 - Vec3::unit_z()).map(|e| e.floor() as i32)) // Make sure we're close to the ground
.map(|vox| !vox.is_empty())
.unwrap_or(false)
{
// ...block-hop!
pos.0.z = (pos.0.z + 1.0).ceil();

View File

@ -1,4 +1,4 @@
#![feature(drain_filter)]
#![feature(drain_filter, bind_by_move_pattern_guards)]
pub mod client;
pub mod cmd;
@ -454,19 +454,26 @@ impl Server {
ClientState::Dead => client.error_state(RequestStateError::Impossible),
ClientState::Pending => {}
},
ClientMsg::Register { player } => match client.client_state {
ClientState::Connected => {
Self::initialize_player(state, entity, client, player);
if let Some(player) =
state.ecs().read_storage::<comp::Player>().get(entity)
{
new_chat_msgs
.push((None, format!("{} logged in", &player.alias)));
// Valid player
ClientMsg::Register { player } if player.is_valid() => {
match client.client_state {
ClientState::Connected => {
Self::initialize_player(state, entity, client, player);
if let Some(player) =
state.ecs().read_storage::<comp::Player>().get(entity)
{
new_chat_msgs
.push((None, format!("{} logged in", &player.alias)));
}
}
// Use RequestState instead (No need to send `player` again).
_ => client.error_state(RequestStateError::Impossible),
}
// Use RequestState instead (No need to send `player` again).
_ => client.error_state(RequestStateError::Impossible),
},
}
// Invalid player
ClientMsg::Register { player } => {
client.error_state(RequestStateError::Impossible)
}
ClientMsg::SetViewDistance(view_distance) => match client.client_state {
ClientState::Character { .. } => {
state

View File

@ -32,7 +32,7 @@ void main() {
vec4(f_norm, 0.0)
).xyz;
float light = get_sun_diffuse(world_norm, time_of_day.x);
vec3 light = get_sun_diffuse(world_norm, time_of_day.x);
vec3 surf_color = model_col.rgb * f_col * 2.0 * light;
float fog_level = fog(f_pos.xy, focus_pos.xy);

View File

@ -1,30 +1,19 @@
const float PI = 3.141592;
float mod289(float x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
vec4 perm(vec4 x){return mod289(((x * 34.0) + 1.0) * x);}
const vec3 SKY_DAY_TOP = vec3(0.2, 0.3, 0.9);
const vec3 SKY_DAY_MID = vec3(0.15, 0.2, 0.8);
const vec3 SKY_DAY_BOT = vec3(0.02, 0.1, 0.3);
const vec3 DAY_LIGHT = vec3(0.5, 0.5, 0.8);
float noise(vec3 p){
vec3 a = floor(p);
vec3 d = p - a;
d = d * d * (3.0 - 2.0 * d);
const vec3 SKY_DUSK_TOP = vec3(0.1, 0.15, 0.3);
const vec3 SKY_DUSK_MID = vec3(0.9, 0.3, 0.2);
const vec3 SKY_DUSK_BOT = vec3(0.01, 0.05, 0.15);
const vec3 DUSK_LIGHT = vec3(0.9, 0.2, 0.1);
vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0);
vec4 k1 = perm(b.xyxy);
vec4 k2 = perm(k1.xyxy + b.zzww);
vec4 c = k2 + a.zzzz;
vec4 k3 = perm(c);
vec4 k4 = perm(c + 1.0);
vec4 o1 = fract(k3 * (1.0 / 41.0));
vec4 o2 = fract(k4 * (1.0 / 41.0));
vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
return o4.y * d.y + o4.x * (1.0 - d.y);
}
const vec3 SKY_NIGHT_TOP = vec3(0.002, 0.002, 0.005);
const vec3 SKY_NIGHT_MID = vec3(0.002, 0.01, 0.03);
const vec3 SKY_NIGHT_BOT = vec3(0.002, 0.002, 0.005);
const vec3 NIGHT_LIGHT = vec3(0.002, 0.01, 0.03);
vec3 get_sun_dir(float time_of_day) {
const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0);
@ -39,16 +28,28 @@ float get_sun_brightness(vec3 sun_dir) {
return max(-sun_dir.z + 0.6, 0.0) * 0.8;
}
const float PERSISTENT_AMBIANCE = 0.015;
const float PERSISTENT_AMBIANCE = 0.008;
float get_sun_diffuse(vec3 norm, float time_of_day) {
vec3 get_sun_diffuse(vec3 norm, float time_of_day) {
const float SUN_AMBIANCE = 0.2;
vec3 sun_dir = get_sun_dir(time_of_day);
float sun_light = get_sun_brightness(sun_dir);
return (SUN_AMBIANCE + max(dot(-norm, sun_dir), 0.0)) * sun_light + PERSISTENT_AMBIANCE;
vec3 sun_color = normalize(mix(
mix(
DUSK_LIGHT,
NIGHT_LIGHT,
clamp(sun_dir.z, 0, 1)
),
DAY_LIGHT,
clamp(-sun_dir.z, 0, 1)
)) / 2.0 + 0.5;
vec3 diffuse_light = (SUN_AMBIANCE + max(dot(-norm, sun_dir), 0.0)) * sun_light * sun_color + PERSISTENT_AMBIANCE;
return diffuse_light;
}
vec3 rand_offs(vec3 pos) {
@ -82,18 +83,6 @@ vec3 get_sky_color(vec3 dir, float time_of_day) {
// Sky color
const vec3 SKY_DAY_TOP = vec3(0.2, 0.3, 0.9);
const vec3 SKY_DAY_MID = vec3(0.1, 0.15, 0.7);
const vec3 SKY_DAY_BOT = vec3(0.025, 0.15, 0.35);
const vec3 SKY_DUSK_TOP = vec3(0.1, 0.15, 0.3);
const vec3 SKY_DUSK_MID = vec3(0.9, 0.3, 0.2);
const vec3 SKY_DUSK_BOT = vec3(0.01, 0.05, 0.15);
const vec3 SKY_NIGHT_TOP = vec3(0.002, 0.002, 0.005);
const vec3 SKY_NIGHT_MID = vec3(0.002, 0.01, 0.03);
const vec3 SKY_NIGHT_BOT = vec3(0.002, 0.002, 0.005);
vec3 sun_dir = get_sun_dir(time_of_day);
vec3 sky_top = mix(
@ -122,7 +111,7 @@ vec3 get_sky_color(vec3 dir, float time_of_day) {
SKY_NIGHT_BOT,
clamp(sun_dir.z, 0, 1)
),
SKY_DAY_MID,
SKY_DAY_BOT,
clamp(-sun_dir.z, 0, 1)
);
@ -146,64 +135,6 @@ vec3 get_sky_color(vec3 dir, float time_of_day) {
vec3 sun_light = (sun_halo + sun_surf) * clamp(dir.z * 10.0, 0, 1);
return sky_color + sun_light;
/*
bool objects = true;
vec2 pos2d = dir.xy / dir.z;
const vec3 SKY_TOP = vec3(0.2, 0.3, 0.9);
const vec3 SKY_MIDDLE = vec3(0.1, 0.15, 0.7);
const vec3 SKY_BOTTOM = vec3(0.025, 0.15, 0.35);
const vec3 SUN_HALO_COLOR = vec3(1.0, 0.4, 0.3) * 0.5;
const vec3 SUN_SURF_COLOR = vec3(1.0, 0.9, 0.35) * 200.0;
vec3 sun_dir = get_sun_dir(time_of_day);
float sky_brightness = get_sun_brightness(sun_dir);
vec3 sun_halo = pow(max(dot(dir, -sun_dir) + 0.1, 0.0), 8.0) * SUN_HALO_COLOR;
vec3 sun_surf = pow(max(dot(dir, -sun_dir) - 0.0045, 0.0), 1000.0) * SUN_SURF_COLOR;
vec3 sun_light = sun_halo + sun_surf;
float brightess = (sky_brightness + PERSISTENT_AMBIANCE);
vec3 sky_top = SKY_TOP * brightess;
vec3 sky_middle = SKY_MIDDLE * brightess;
if (objects) {
// Clouds
// vec3 p = vec3(pos2d + time_of_day * 0.0002, time_of_day * 0.00003);
// sky_top = mix(sky_top, vec3(1) * brightess, pow(noise(p) * 0.8 + noise(p * 3.0) * 0.2, 2.5) * 3.0);
}
if (objects) {
sky_top += sun_light;
sky_middle += sun_light;
}
vec3 sky_color = mix(
mix(
sky_middle,
sky_top,
clamp(dir.z * 1.0, 0, 1)
),
SKY_BOTTOM * brightess,
clamp(-dir.z * 3.0, 0, 1)
);
return sky_color;
*/
}
float fog(vec2 f_pos, vec2 focus_pos) {

View File

@ -28,7 +28,7 @@ void main() {
f_norm = vec3(0.0, 0.0, 1.0) * norm_dir;
}
float light = get_sun_diffuse(f_norm, time_of_day.x) * f_light;
vec3 light = get_sun_diffuse(f_norm, time_of_day.x) * f_light;
vec3 surf_color = f_col * light;
float fog_level = fog(f_pos.xy, focus_pos.xy);

View File

@ -311,11 +311,6 @@ impl Hud {
Err(_) => env!("CARGO_PKG_VERSION").to_owned(),
};
// Don't show anything if the UI is toggled off.
if !self.show.ui {
return events;
}
// Nametags and healthbars
if self.show.ingame {
let ecs = client.state().ecs();
@ -819,7 +814,10 @@ impl Hud {
}
pub fn render(&self, renderer: &mut Renderer, globals: &Consts<Globals>) {
self.ui.render(renderer, Some(globals));
// Don't show anything if the UI is toggled off.
if self.show.ui {
self.ui.render(renderer, Some(globals));
}
}
}

View File

@ -100,15 +100,23 @@ impl PlayState for MainMenuState {
if let Err(err) = global_state.settings.save_to_file() {
warn!("Failed to save settings: {:?}", err);
}
// Don't try to connect if there is already a connection in progress.
client_init = client_init.or(Some(ClientInit::new(
(server_address, DEFAULT_PORT, false),
comp::Player::new(
username.clone(),
Some(global_state.settings.graphics.view_distance),
),
false,
)));
let player = comp::Player::new(
username.clone(),
Some(global_state.settings.graphics.view_distance),
);
if player.is_valid() {
// Don't try to connect if there is already a connection in progress.
client_init = client_init.or(Some(ClientInit::new(
(server_address, DEFAULT_PORT, false),
player,
false,
)));
} else {
self.main_menu_ui
.login_error("Invalid username".to_string());
}
}
MainMenuEvent::StartSingleplayer => {
return PlayStateResult::Push(Box::new(StartSingleplayerState::new()));