mirror of
https://github.com/minetest/minetest.git
synced 2024-12-24 23:22:24 +01:00
Optimized minetest.get_connected_players()
Instead of collecting all objects within a huge radius (which could be a big value), just register each player that connects and give back the current hold list.
This commit is contained in:
parent
2134316c80
commit
2170c9958a
@ -40,15 +40,22 @@ function minetest.check_player_privs(name, privs)
|
|||||||
return true, ""
|
return true, ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local player_list = {}
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
player_list[player:get_player_name()] = player
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
player_list[player:get_player_name()] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
function minetest.get_connected_players()
|
function minetest.get_connected_players()
|
||||||
-- This could be optimized a bit, but leave that for later
|
local temp_table = {}
|
||||||
local list = {}
|
for index, value in pairs(player_list) do
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius({x=0,y=0,z=0}, 1000000)) do
|
table.insert(temp_table, value)
|
||||||
if obj:is_player() then
|
|
||||||
table.insert(list, obj)
|
|
||||||
end
|
end
|
||||||
end
|
return temp_table
|
||||||
return list
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.hash_node_position(pos)
|
function minetest.hash_node_position(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user