mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-05-21 06:43:17 -04:00
Heavily optimize data usage with player_api
This commit is contained in:
parent
6d2a897e1b
commit
5bbda73fc2
2 changed files with 47 additions and 25 deletions
|
@ -108,36 +108,55 @@ end
|
||||||
-- Check each player and apply animations
|
-- Check each player and apply animations
|
||||||
minetest.register_globalstep(function()
|
minetest.register_globalstep(function()
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
local name = player:get_player_name()
|
-- Check if the player's control state has changed
|
||||||
local model_name = player_model[name]
|
local meta = player:get_meta()
|
||||||
local model = model_name and models[model_name]
|
local controls = player:get_player_control()
|
||||||
if model and not player_attached[name] then
|
local control_table = meta:get_string("player_api_old_controls")
|
||||||
local controls = player:get_player_control()
|
local player_input_changed = false
|
||||||
local animation_speed_mod = model.animation_speed or 30
|
if control_table ~= "" then
|
||||||
|
control_table = minetest.deserialize(control_table)
|
||||||
-- Determine if the player is sneaking, and reduce animation speed if so
|
for index,boolean in pairs(control_table) do
|
||||||
if controls.sneak then
|
if controls[index] ~= boolean then
|
||||||
animation_speed_mod = animation_speed_mod / 2
|
player_input_changed = true
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
player_input_changed = true
|
||||||
|
end
|
||||||
|
|
||||||
-- Apply animations based on what the player is doing
|
if player_input_changed then
|
||||||
if player:get_hp() == 0 then
|
-- Serialize old control state to be used in next server step
|
||||||
player_set_animation(player, "lay")
|
meta:set_string("player_api_old_controls",minetest.serialize(controls))
|
||||||
-- Determine if the player is walking
|
local name = player:get_player_name()
|
||||||
elseif controls.up or controls.down or controls.left or controls.right then
|
local model_name = player_model[name]
|
||||||
if player_sneak[name] ~= controls.sneak then
|
local model = model_name and models[model_name]
|
||||||
player_anim[name] = nil
|
if model and not player_attached[name] then
|
||||||
player_sneak[name] = controls.sneak
|
local controls = player:get_player_control()
|
||||||
|
local animation_speed_mod = model.animation_speed or 30
|
||||||
|
-- Determine if the player is sneaking, and reduce animation speed if so
|
||||||
|
if controls.sneak then
|
||||||
|
animation_speed_mod = animation_speed_mod / 2
|
||||||
end
|
end
|
||||||
if controls.LMB or controls.RMB then
|
-- Apply animations based on what the player is doing
|
||||||
player_set_animation(player, "walk_mine", animation_speed_mod)
|
if player:get_hp() == 0 then
|
||||||
|
player_set_animation(player, "lay")
|
||||||
|
-- Determine if the player is walking
|
||||||
|
elseif controls.up or controls.down or controls.left or controls.right then
|
||||||
|
if player_sneak[name] ~= controls.sneak then
|
||||||
|
player_anim[name] = nil
|
||||||
|
player_sneak[name] = controls.sneak
|
||||||
|
end
|
||||||
|
if controls.LMB or controls.RMB then
|
||||||
|
player_set_animation(player, "walk_mine", animation_speed_mod)
|
||||||
|
else
|
||||||
|
player_set_animation(player, "walk", animation_speed_mod)
|
||||||
|
end
|
||||||
|
elseif controls.LMB or controls.RMB then
|
||||||
|
player_set_animation(player, "mine", animation_speed_mod)
|
||||||
else
|
else
|
||||||
player_set_animation(player, "walk", animation_speed_mod)
|
player_set_animation(player, "stand", animation_speed_mod)
|
||||||
end
|
end
|
||||||
elseif controls.LMB or controls.RMB then
|
|
||||||
player_set_animation(player, "mine", animation_speed_mod)
|
|
||||||
else
|
|
||||||
player_set_animation(player, "stand", animation_speed_mod)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,4 +31,7 @@ minetest.register_on_joinplayer(function(player)
|
||||||
{x = 200, y = 219},
|
{x = 200, y = 219},
|
||||||
30
|
30
|
||||||
)
|
)
|
||||||
|
-- Remove old player controls when they join
|
||||||
|
local meta = player:get_meta()
|
||||||
|
meta:set_string("player_api_old_controls", "")
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Reference in a new issue