mirror of
https://github.com/t-affeldt/climate_api.git
synced 2024-12-22 17:00:36 +01:00
Optimize code and modernize API calls
* Remove is_connected() and use minetest counterpart * Less calls to minetest.get_connected_players() * Deprecated: get_player_velocity * Luacheck: unused assignements * Luacheck: unused variable * Luacheck: already declared variable --------- Co-authored-by: mazes 80 <>
This commit is contained in:
parent
a56116e8ab
commit
59bf43aa28
@ -43,7 +43,7 @@ local function check_hit(player, ray)
|
|||||||
)
|
)
|
||||||
origin = vector.add(origin, windpos)
|
origin = vector.add(origin, windpos)
|
||||||
end
|
end
|
||||||
local ray = minetest.raycast(origin, ppos)
|
ray = minetest.raycast(origin, ppos)
|
||||||
local obj = ray:next()
|
local obj = ray:next()
|
||||||
-- found nothing
|
-- found nothing
|
||||||
if obj == nil then return false end
|
if obj == nil then return false end
|
||||||
|
@ -165,7 +165,7 @@ local function parse_config(player, particles)
|
|||||||
|
|
||||||
-- correct spawn coordinates to adjust for player movement
|
-- correct spawn coordinates to adjust for player movement
|
||||||
if config.adjust_for_velocity then
|
if config.adjust_for_velocity then
|
||||||
local velocity = player:get_player_velocity()
|
local velocity = player:get_velocity()
|
||||||
config.minpos = vector.add(config.minpos, velocity)
|
config.minpos = vector.add(config.minpos, velocity)
|
||||||
config.maxpos = vector.add(config.maxpos, velocity)
|
config.maxpos = vector.add(config.maxpos, velocity)
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
local mod_player_monoids = minetest.get_modpath("player_monoids") ~= nil
|
|
||||||
local mod_playerphysics = minetest.get_modpath("playerphysics") ~= nil
|
|
||||||
local mod_pova = minetest.get_modpath("pova") ~= nil
|
|
||||||
|
|
||||||
local utility = {}
|
local utility = {}
|
||||||
|
|
||||||
function utility.rangelim(value, min, max)
|
function utility.rangelim(value, min, max)
|
||||||
|
11
lib/main.lua
11
lib/main.lua
@ -1,15 +1,6 @@
|
|||||||
local GSCYCLE = 0.03 * climate_mod.settings.tick_speed -- only process event loop after this amount of time
|
local GSCYCLE = 0.03 * climate_mod.settings.tick_speed -- only process event loop after this amount of time
|
||||||
local WORLD_CYCLE = 30.00 * climate_mod.settings.tick_speed -- only update global environment influences after this amount of time
|
local WORLD_CYCLE = 30.00 * climate_mod.settings.tick_speed -- only update global environment influences after this amount of time
|
||||||
|
|
||||||
local function is_connected(playername)
|
|
||||||
local connected = minetest.get_connected_players()
|
|
||||||
for _, player in ipairs(connected) do
|
|
||||||
local name = player:get_player_name()
|
|
||||||
if playername == name then return true end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local gs_timer = 0
|
local gs_timer = 0
|
||||||
local world_timer = 0
|
local world_timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
@ -29,7 +20,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
-- skip weather changes for offline players
|
-- skip weather changes for offline players
|
||||||
for effect, data in pairs(previous_effects) do
|
for effect, data in pairs(previous_effects) do
|
||||||
for playername, _ in pairs(data) do
|
for playername, _ in pairs(data) do
|
||||||
if not is_connected(playername) then
|
if not minetest.get_player_by_name(playername) then
|
||||||
previous_effects[effect][playername] = nil
|
previous_effects[effect][playername] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,6 @@ soundloop.play = function(player, sound, fade)
|
|||||||
if sounds[player] == nil then sounds[player] = {} end
|
if sounds[player] == nil then sounds[player] = {} end
|
||||||
if sounds[player][sound.name] == nil then
|
if sounds[player][sound.name] == nil then
|
||||||
step = sound.gain / fade
|
step = sound.gain / fade
|
||||||
start_gain = 0
|
|
||||||
elseif sounds[player][sound.name] ~= sound.gain then
|
elseif sounds[player][sound.name] ~= sound.gain then
|
||||||
minetest.sound_stop(sounds[player][sound.name].handle)
|
minetest.sound_stop(sounds[player][sound.name].handle)
|
||||||
start_gain = sounds[player][sound.name].gain
|
start_gain = sounds[player][sound.name].gain
|
||||||
|
@ -68,7 +68,7 @@ local function is_weather_active(player, weather, env)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_weather_effects(player, weather_config, env)
|
local function get_weather_effects(player, weather_config, env)
|
||||||
local config = {}
|
local config
|
||||||
local effects = {}
|
local effects = {}
|
||||||
if type(weather_config.effects) == "function" then
|
if type(weather_config.effects) == "function" then
|
||||||
config = weather_config.effects(env)
|
config = weather_config.effects(env)
|
||||||
@ -85,22 +85,19 @@ end
|
|||||||
|
|
||||||
function trigger.get_active_effects()
|
function trigger.get_active_effects()
|
||||||
local environments = {}
|
local environments = {}
|
||||||
|
local effects = {}
|
||||||
|
climate_mod.current_weather = {}
|
||||||
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
local playername = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
-- skip weather presets for dead players
|
-- skip weather presets for dead players
|
||||||
if hp ~= nil and hp > 0 then
|
if hp ~= nil and hp > 0 then
|
||||||
environments[playername] = trigger.get_player_environment(player)
|
environments[pname] = trigger.get_player_environment(player)
|
||||||
end
|
end
|
||||||
end
|
local env = environments[pname]
|
||||||
|
if env ~= nil then
|
||||||
local effects = {}
|
for wname, wconfig in pairs(climate_mod.weathers) do
|
||||||
climate_mod.current_weather = {}
|
|
||||||
for wname, wconfig in pairs(climate_mod.weathers) do
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
|
||||||
local pname = player:get_player_name()
|
|
||||||
local env = environments[pname]
|
|
||||||
if env ~= nil then
|
|
||||||
if is_weather_active(player, wname, env) then
|
if is_weather_active(player, wname, env) then
|
||||||
if climate_mod.current_weather[pname] == nil then
|
if climate_mod.current_weather[pname] == nil then
|
||||||
climate_mod.current_weather[pname] = {}
|
climate_mod.current_weather[pname] = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user