2 Commits

Author SHA1 Message Date
710a1d717b Enable shadow registration, improve indoor check 2023-02-22 05:21:52 +01:00
59bf43aa28 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 <>
2023-02-22 03:10:33 +01:00
8 changed files with 31 additions and 36 deletions

View File

@ -43,7 +43,7 @@ local function check_hit(player, ray)
)
origin = vector.add(origin, windpos)
end
local ray = minetest.raycast(origin, ppos)
ray = minetest.raycast(origin, ppos)
local obj = ray:next()
-- found nothing
if obj == nil then return false end

View File

@ -165,7 +165,7 @@ local function parse_config(player, particles)
-- correct spawn coordinates to adjust for player movement
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.maxpos = vector.add(config.maxpos, velocity)
end
@ -212,4 +212,4 @@ local function handle_effect(player_data)
end
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
climate_api.set_effect_cycle(EFFECT_NAME, CYCLE_LENGTH)
climate_api.set_effect_cycle(EFFECT_NAME, CYCLE_LENGTH)

View File

@ -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 = {}
function utility.rangelim(value, min, max)

View File

@ -55,13 +55,15 @@ end)
climate_api.register_influence("daylight", function(pos)
pos = vector.add(pos, {x = 0, y = 1, z = 0})
return minetest.get_node_light(pos, 0.5) or 0
return minetest.get_natural_light(pos, 0.5) or 0
end)
climate_api.register_influence("indoors", function(pos)
pos = vector.add(pos, {x = 0, y = 1, z = 0})
local daylight = minetest.get_node_light(pos, 0.5) or 0
if daylight < 15 then return true end
local daylight = minetest.get_natural_light(pos, 0.5) or 0
-- max light is 15 but allow adjacent nodes to still be outdoors
-- to reduce effect switching on and off when walking underneath single nodes
if daylight < 14 then return true end
for i = 1, climate_mod.settings.ceiling_checks do
local lpos = vector.add(pos, {x = 0, y = i, z = 0})

View File

@ -1,15 +1,6 @@
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 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 world_timer = 0
minetest.register_globalstep(function(dtime)
@ -29,7 +20,7 @@ minetest.register_globalstep(function(dtime)
-- skip weather changes for offline players
for effect, data in pairs(previous_effects) 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
end
end
@ -47,4 +38,4 @@ minetest.register_globalstep(function(dtime)
climate_mod.cycles[name].timer = climate_mod.cycles[name].timer + dtime
end
end
end)
end)

View File

@ -42,6 +42,10 @@ local default_sky = {
count = 1000,
star_color = "#ebebff69",
scale = 1
},
light_data = {
shadow_intensity = 0.33,
saturation = 1
}
}
@ -70,6 +74,12 @@ local function set_skybox(playername, sky)
player:set_moon(sky.moon_data)
player:set_sun(sky.sun_data)
player:set_stars(sky.star_data)
if player.set_lighting then
player:set_lighting({
shadows = { intensity = sky.light_data.shadow_intensity },
saturation = sky.light_data.saturation
})
end
end
function skybox.update(playername)

View File

@ -19,7 +19,6 @@ soundloop.play = function(player, sound, fade)
if sounds[player] == nil then sounds[player] = {} end
if sounds[player][sound.name] == nil then
step = sound.gain / fade
start_gain = 0
elseif sounds[player][sound.name] ~= sound.gain then
minetest.sound_stop(sounds[player][sound.name].handle)
start_gain = sounds[player][sound.name].gain
@ -54,4 +53,4 @@ soundloop.stop = function(player, sound, fade)
minetest.after(fade, minetest.sound_stop, handle)
end
return soundloop
return soundloop

View File

@ -68,7 +68,7 @@ local function is_weather_active(player, weather, env)
end
local function get_weather_effects(player, weather_config, env)
local config = {}
local config
local effects = {}
if type(weather_config.effects) == "function" then
config = weather_config.effects(env)
@ -85,22 +85,19 @@ end
function trigger.get_active_effects()
local environments = {}
local effects = {}
climate_mod.current_weather = {}
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()
-- skip weather presets for dead players
if hp ~= nil and hp > 0 then
environments[playername] = trigger.get_player_environment(player)
environments[pname] = trigger.get_player_environment(player)
end
end
local effects = {}
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
local env = environments[pname]
if env ~= nil then
for wname, wconfig in pairs(climate_mod.weathers) do
if is_weather_active(player, wname, env) then
if climate_mod.current_weather[pname] == nil then
climate_mod.current_weather[pname] = {}
@ -172,4 +169,4 @@ function trigger.call_handlers(name, effect, prev_effect)
end
end
return trigger
return trigger