diff --git a/res/scripts/components/mob.lua b/res/scripts/components/mob.lua index 2266487d2..92c2a3723 100644 --- a/res/scripts/components/mob.lua +++ b/res/scripts/components/mob.lua @@ -20,7 +20,7 @@ end def_prop("jump_force", 0.0) def_prop("air_damping", 10.0) def_prop("ground_damping", 10.0) -def_prop("movement_speed", 3.0) +def_prop("movement_speed", 27.0) def_prop("run_speed_mul", 1.5) def_prop("crouch_speed_mul", 0.35) def_prop("flight_speed_mul", 2.0) @@ -62,9 +62,8 @@ local function move_horizontal(speed, dir, vel) vec2.normalize(dir, dir) local delta = time.delta() - local damping = body:get_linear_damping() - vel[1] = vel[1] + dir[1] * speed * delta * damping - vel[3] = vel[3] + dir[2] * speed * delta * damping + vel[1] = vel[1] + dir[1] * speed * delta + vel[3] = vel[3] + dir[2] * speed * delta end body:set_vel(vel) end diff --git a/res/scripts/components/player.lua b/res/scripts/components/player.lua index 840bce743..49a03377f 100644 --- a/res/scripts/components/player.lua +++ b/res/scripts/components/player.lua @@ -49,9 +49,9 @@ local function process_player_inputs(pid, rot, delta) if mob.is_flight() then if isjump then - mob.move_vertical(speed * 3) + mob.move_vertical(speed / 4.0) elseif iscrouch then - mob.move_vertical(-speed * 3) + mob.move_vertical(-speed / 4.0) end elseif body:is_grounded() and isjump then mob.jump() diff --git a/src/physics/PhysicsSolver.cpp b/src/physics/PhysicsSolver.cpp index 6cf5ac62e..117136ea0 100644 --- a/src/physics/PhysicsSolver.cpp +++ b/src/physics/PhysicsSolver.cpp @@ -180,7 +180,6 @@ bool PhysicsSolver::calcCollisionNegY( if (vel.y >= 0.0f) { return false; } - hitbox.groundVelocity = {}; for (int ix = 0; ix <= glm::ceil((half.x - E) * 2); ix++) { glm::vec3 coord; coord.x = (pos.x - half.x + E) + ix; @@ -202,6 +201,7 @@ bool PhysicsSolver::calcCollisionNegY( vel.y = -hitbox.elasticity * vel.y; pos.y = newy; } + hitbox.groundVelocity = {}; return true; } } @@ -398,6 +398,10 @@ void PhysicsSolver::step( for (auto hitbox : hitboxes) { float linearDamping = hitbox->linearDamping; + if (hitbox->grounded) { + linearDamping = 10.0f; // TODO: add friction to material + } + glm::vec3& vel = hitbox->velocity; auto diff = hitbox->groundVelocity - vel; vel.x += diff.x * delta * linearDamping; @@ -407,7 +411,7 @@ void PhysicsSolver::step( vel.y /= 1.0f + delta * linearDamping * hitbox->verticalDamping; } if (!hitbox->grounded) { - hitbox->groundVelocity = {}; + hitbox->groundVelocity *= 1.0f - delta; } updateSensors(*hitbox); diff --git a/src/util/stringutil.cpp b/src/util/stringutil.cpp index e1a99f9e0..0329305c3 100644 --- a/src/util/stringutil.cpp +++ b/src/util/stringutil.cpp @@ -7,6 +7,8 @@ #include #include +static std::locale locale("en_US.UTF-8"); + std::string util::escape(std::string_view s, bool escapeUnicode) { std::stringstream ss; ss << '"'; @@ -507,39 +509,34 @@ double util::parse_double(const std::string& str, size_t offset, size_t len) { std::wstring util::lower_case(const std::wstring& str) { std::wstring result = str; - static const std::locale loc(""); for (uint i = 0; i < result.length(); i++) { - result[i] = static_cast(std::tolower(str[i], loc)); + result[i] = static_cast(std::tolower(str[i], locale)); } return result; } std::wstring util::upper_case(const std::wstring& str) { std::wstring result = str; - static const std::locale loc(""); for (uint i = 0; i < result.length(); i++) { - result[i] = static_cast(std::toupper(str[i], loc)); + result[i] = static_cast(std::toupper(str[i], locale)); } return result; } std::wstring util::capitalized(const std::wstring& str) { if (str.empty()) return str; - static const std::locale loc(""); - return std::wstring({static_cast(std::toupper(str[0], loc))}) + + return std::wstring({static_cast(std::toupper(str[0], locale))}) + str.substr(1); } std::string util::capitalized(const std::string& str) { if (str.empty()) return str; - static const std::locale loc(""); - return std::string({static_cast(std::toupper(str[0], loc))}) + + return std::string({static_cast(std::toupper(str[0], locale))}) + str.substr(1); } std::wstring util::pascal_case(const std::wstring& str) { if (str.empty()) return str; - static const std::locale loc(""); std::wstring result = str; bool upper = true; for (uint i = 0; i < result.length(); i++) { @@ -547,7 +544,7 @@ std::wstring util::pascal_case(const std::wstring& str) { if (c <= ' ') { upper = true; } else if (upper) { - result[i] = static_cast(std::toupper(str[i], loc)); + result[i] = static_cast(std::toupper(str[i], locale)); upper = false; } } diff --git a/test/util/stringutil.cpp b/test/util/stringutil.cpp index 22df2b356..a057d4e69 100644 --- a/test/util/stringutil.cpp +++ b/test/util/stringutil.cpp @@ -101,3 +101,9 @@ TEST(stringutil, escape_cases) { } EXPECT_EQ(utf8str, restored); } + +TEST(stringutil, cases) { + EXPECT_EQ(util::upper_case(L"тест"), std::wstring(L"ТЕСТ")); + EXPECT_EQ(util::lower_case(L"ТЕСТ"), std::wstring(L"тест")); + EXPECT_EQ(util::pascal_case(L"тестовая строка"), std::wstring(L"Тестовая Строка")); +}