mirror of
https://files.creativekara.fr/git/poschangelib.git
synced 2024-12-04 21:13:50 +01:00
Teleportation. Version 0.3
This commit is contained in:
parent
9c52feed90
commit
8bc2e7c64d
@ -1,6 +1,6 @@
|
||||
Minetest mod library: poschangelib
|
||||
==================================
|
||||
version 0.2
|
||||
version 0.3
|
||||
|
||||
See LICENSE for license information
|
||||
|
||||
@ -166,6 +166,9 @@ interpolated
|
||||
Is true when the position was assumed and not observed. Most of the time because the
|
||||
player moved too fast to check all nodes in real time.
|
||||
|
||||
teleported
|
||||
Is true when the player was moving to fast. The interpolation is then not computed.
|
||||
|
||||
player_pos
|
||||
Is set for walk listeners, it contains the player's position. Not set when
|
||||
interpolated.
|
||||
|
22
init.lua
22
init.lua
@ -12,6 +12,9 @@ poschangelib = {}
|
||||
function poschangelib.setting_check_interval()
|
||||
return tonumber(minetest.setting_get('poschangelib.check_interval')) or 0.3
|
||||
end
|
||||
function poschangelib.setting_teleport_range()
|
||||
return tonumber(minetest.setting_get('poschangelib.teleport_range')) or 10
|
||||
end
|
||||
|
||||
--- Table of already called listeners in main loop to prevent triggering them
|
||||
-- more than once per loop (player) if they are registered for more than one event
|
||||
@ -169,10 +172,15 @@ function poschangelib.get_path(start_pos, end_pos, path)
|
||||
if path == nil then path = {} end
|
||||
table.insert(path, start_pos)
|
||||
local distance = vector.subtract(end_pos, start_pos)
|
||||
-- Check for teleportation
|
||||
local teleport_range = poschangelib.setting_teleport_range()
|
||||
local dX = math.abs(distance.x)
|
||||
local dY = math.abs(distance.y)
|
||||
local dZ = math.abs(distance.z)
|
||||
if (dX + dY + dZ <= 1) then -- Next step will reach end_pos
|
||||
if (dX + dY + dZ <= 1) or
|
||||
(teleport_range > 0 and dX + dY + dZ > teleport_range) then
|
||||
-- Next step will reach end_pos
|
||||
-- or teleported
|
||||
table.insert(path, end_pos)
|
||||
return path
|
||||
end
|
||||
@ -298,12 +306,22 @@ local function loop(dtime)
|
||||
-- Wait loop
|
||||
if timer + dtime < poschangelib.setting_check_interval() then return end
|
||||
timer = 0
|
||||
local teleport_range = poschangelib.setting_teleport_range()
|
||||
-- Player checks
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local poss = get_updated_positions(player)
|
||||
if poss then
|
||||
if table.getn(poss) == 1 then
|
||||
local pos_count = table.getn(poss)
|
||||
if pos_count == 1 then
|
||||
trigger_player_position_listeners(player, nil, poss[0])
|
||||
elseif pos_count == 2 then
|
||||
local teleported = false
|
||||
local trigger_meta = {}
|
||||
if teleport_range > 0 and vector.distance(poss[1], poss[2]) >= teleport_range then
|
||||
trigger_meta.teleported = true
|
||||
end
|
||||
trigger_player_position_listeners(player, poss[1], poss[2], trigger_meta)
|
||||
check_on_walk_triggers(player, poss[1], poss[2], trigger_meta)
|
||||
else
|
||||
local poss_end_couple = table.getn(poss) - 1
|
||||
for i = 1, poss_end_couple do
|
||||
|
@ -1,3 +1,8 @@
|
||||
# Interval in seconds between position checking
|
||||
# The lesser it is, the more accurate it is but also the more resources demanding.
|
||||
poschangelib.check_interval (Check interval) float 0.3 0.05
|
||||
|
||||
# Distance between two checks that is considered to be a teleportation and won't
|
||||
# compute interpolated positions between last known position and current position.
|
||||
# Set to 0 to disable checking.
|
||||
poschangelib.teleport_range (Teleport range) int 10 0
|
||||
|
Loading…
Reference in New Issue
Block a user