From 21113ad4105dd3fb181b3d0638b907af94a352ab Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 1 Oct 2021 14:21:24 +0000 Subject: Split liquid_viscosity to liquid_viscosity and move_resistance (#10810) --- src/client/clientenvironment.cpp | 37 +++++++++++++++++++++++-------------- src/client/localplayer.cpp | 24 ++++++++++++++---------- src/client/localplayer.h | 4 ++-- 3 files changed, 39 insertions(+), 26 deletions(-) (limited to 'src/client') diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 7e3867537..448af36c6 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -194,32 +194,41 @@ void ClientEnvironment::step(float dtime) lplayer->applyControl(dtime_part, this); // Apply physics - if (!free_move && !is_climbing) { + if (!free_move) { // Gravity v3f speed = lplayer->getSpeed(); - if (!lplayer->in_liquid) + if (!is_climbing && !lplayer->in_liquid) speed.Y -= lplayer->movement_gravity * lplayer->physics_override_gravity * dtime_part * 2.0f; // Liquid floating / sinking - if (lplayer->in_liquid && !lplayer->swimming_vertical && + if (!is_climbing && lplayer->in_liquid && + !lplayer->swimming_vertical && !lplayer->swimming_pitch) speed.Y -= lplayer->movement_liquid_sink * dtime_part * 2.0f; - // Liquid resistance - if (lplayer->in_liquid_stable || lplayer->in_liquid) { - // How much the node's viscosity blocks movement, ranges - // between 0 and 1. Should match the scale at which viscosity + // Movement resistance + if (lplayer->move_resistance > 0) { + // How much the node's move_resistance blocks movement, ranges + // between 0 and 1. Should match the scale at which liquid_viscosity // increase affects other liquid attributes. - static const f32 viscosity_factor = 0.3f; - - v3f d_wanted = -speed / lplayer->movement_liquid_fluidity; + static const f32 resistance_factor = 0.3f; + + v3f d_wanted; + bool in_liquid_stable = lplayer->in_liquid_stable || lplayer->in_liquid; + if (in_liquid_stable) { + d_wanted = -speed / lplayer->movement_liquid_fluidity; + } else { + d_wanted = -speed / BS; + } f32 dl = d_wanted.getLength(); - if (dl > lplayer->movement_liquid_fluidity_smooth) - dl = lplayer->movement_liquid_fluidity_smooth; + if (in_liquid_stable) { + if (dl > lplayer->movement_liquid_fluidity_smooth) + dl = lplayer->movement_liquid_fluidity_smooth; + } - dl *= (lplayer->liquid_viscosity * viscosity_factor) + - (1 - viscosity_factor); + dl *= (lplayer->move_resistance * resistance_factor) + + (1 - resistance_factor); v3f d = d_wanted.normalize() * (dl * dtime_part * 100.0f); speed += d; } diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 2d4f7305a..3f78d201d 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -227,8 +227,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid = nodemgr->get(node.getContent()).isLiquid(); - liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; + const ContentFeatures &cf = nodemgr->get(node.getContent()); + in_liquid = cf.liquid_move_physics; + move_resistance = cf.move_resistance; } else { in_liquid = false; } @@ -238,8 +239,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid = nodemgr->get(node.getContent()).isLiquid(); - liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; + const ContentFeatures &cf = nodemgr->get(node.getContent()); + in_liquid = cf.liquid_move_physics; + move_resistance = cf.move_resistance; } else { in_liquid = false; } @@ -252,7 +254,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid_stable = nodemgr->get(node.getContent()).isLiquid(); + in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics; } else { in_liquid_stable = false; } @@ -800,8 +802,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid = nodemgr->get(node.getContent()).isLiquid(); - liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; + const ContentFeatures &cf = nodemgr->get(node.getContent()); + in_liquid = cf.liquid_move_physics; + move_resistance = cf.move_resistance; } else { in_liquid = false; } @@ -810,8 +813,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid = nodemgr->get(node.getContent()).isLiquid(); - liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; + const ContentFeatures &cf = nodemgr->get(node.getContent()); + in_liquid = cf.liquid_move_physics; + move_resistance = cf.move_resistance; } else { in_liquid = false; } @@ -823,7 +827,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) - in_liquid_stable = nodemgr->get(node.getContent()).isLiquid(); + in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics; else in_liquid_stable = false; diff --git a/src/client/localplayer.h b/src/client/localplayer.h index 345aec9d9..13b35ae4e 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -55,8 +55,8 @@ public: bool in_liquid = false; // This is more stable and defines the maximum speed of the player bool in_liquid_stable = false; - // Gets the viscosity of water to calculate friction - u8 liquid_viscosity = 0; + // Slows down the player when moving through + u8 move_resistance = 0; bool is_climbing = false; bool swimming_vertical = false; bool swimming_pitch = false; -- cgit v1.2.3