Merge pull request 'PLAYER/mcl_sprint: Send FOV packets only when necessary' (#106) from reduce-fov-packet-spam into master

Reviewed-on: Mineclonia/Mineclonia#106
Reviewed-by: cora <cora@noreply.git.minetest.land>
This commit is contained in:
cora 2021-07-06 20:35:12 +00:00
commit 9f086a9242
1 changed files with 8 additions and 4 deletions

View File

@ -45,15 +45,19 @@ local function setSprinting(playerName, sprinting) --Sets the state of a player
local player = minetest.get_player_by_name(playerName)
if players[playerName] then
players[playerName].sprinting = sprinting
local fov_old = players[playerName].fov
local fov_new
if sprinting == true then
players[playerName].fov = math.min(players[playerName].fov + 0.05, 1.2)
player:set_fov(players[playerName].fov, true, 0.15)
fov_new = math.min(players[playerName].fov + 0.05, 1.2)
playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED)
elseif sprinting == false then
players[playerName].fov = math.max(players[playerName].fov - 0.05, 1.0)
player:set_fov(players[playerName].fov, true, 0.15)
fov_new = math.max(players[playerName].fov - 0.05, 1.0)
playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint")
end
if fov_new ~= fov_old then
players[playerName].fov = fov_new
player:set_fov(fov_new, true, 0.15)
end
return true
end
return false