Try to merge Mineclonia/Send FOV packets only when necessary

This commit is contained in:
Nils Dagsson Moskopp 2021-07-04 03:25:05 +02:00 committed by kay27
parent a7c3154a22
commit b43d0af4a5
1 changed files with 25 additions and 29 deletions

View File

@ -67,36 +67,32 @@ end
local function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting)
local player = minetest.get_player_by_name(playerName)
local controls = player:get_player_control()
if players[playerName] then
players[playerName].sprinting = sprinting
if sprinting == true
or controls.RMB
and string.find(player:get_wielded_item():get_name(), "mcl_bows:bow")
and player:get_wielded_item():get_name() ~= "mcl_bows:bow" then
if sprinting == true then
players[playerName].fov = math.min(players[playerName].fov + 0.05, 1.2)
players[playerName].fade_time = .15
else
players[playerName].fov = .7
players[playerName].fade_time = .3
if not players[playerName] then
return false
end
player:set_fov(players[playerName].fov, true, players[playerName].fade_time)
local player_data = players[playerName]
local fov, fov_new, fade_time = player_data.fov
local wielded_item_name = player:get_wielded_item():get_name()
player_data.sprinting = sprinting
if sprinting == true or controls.RMB and string.find(wielded_item_name, "mcl_bows:bow") and wielded_item_name ~= "mcl_bows:bow" then
if sprinting == true then
fov_new, fade_time = math.min(fov + 0.05, 1.2), .15
playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED)
else
fov_new, fade_time = .7, .3
end
elseif sprinting == false
and player:get_wielded_item():get_name() ~= "mcl_bows:bow_0"
and player:get_wielded_item():get_name() ~= "mcl_bows:bow_1"
and player:get_wielded_item():get_name() ~= "mcl_bows:bow_2" then
players[playerName].fov = math.max(players[playerName].fov - 0.05, 1.0)
player:set_fov(players[playerName].fov, true, 0.15)
elseif sprinting == false and wielded_item_name ~= "mcl_bows:bow_0" and wielded_item_name ~= "mcl_bows:bow_1" and wielded_item_name ~= "mcl_bows:bow_2" then
fov_new = math.max(fov - 0.05, 1.0)
fade_time = 0.15
if sprinting == false then
playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint")
end
end
return true
if fov_new and fov_new ~= fov then
player:set_fov(fov_new, true, fade_time)
player_data.fov = fov_new
end
return false
return true
end
-- Given the param2 and paramtype2 of a node, returns the tile that is facing upwards