Tweak world cycle, add documentation

This commit is contained in:
Till Affeldt 2020-04-26 18:11:38 +02:00
parent bff54bfb74
commit 9e0ed0c256
10 changed files with 114 additions and 15 deletions

View File

@ -1,3 +1,12 @@
--[[
# HUD Overlay Effect
Use this effect to display a fullscreen image as part of a player's HUD.
Expects a table as the parameter containing the following values:
- ``file <string>``: The name (including file ending) if the image to be displayed
- ``z_index <number>`` (optional): The z_index to forward to player.hud_add. Defaults to 1
- ``color_correction <bool>`` (optional): Whether the image should automatically darken based on current light. Defaults to false.
]]
if not climate_mod.settings.hud_overlay then return end
local EFFECT_NAME = "climate_api:hud_overlay"

View File

@ -1,3 +1,21 @@
--[[
# Particle Effect
Use this effect to render downfall using particles.
Expects a table as the parameter containing the following values:
- amount <number>: The quantity of spawned particles per cycle
- EITHER texture <string>: The image file name
- OR textures <table>: A list of possible texture variants
- falling_speed <number>: The downwards speed
- min_pos <number>: Bottom-left corner of spawn position (automatically adjusted by wind)
- max_pos <number>: Top-right corner of spawn position (automatically adjusted by wind)
- acceleration <vector> (optional): Particle acceleration in any direction
- exptime <number>: Time of life of particles
- time <number> (optional): The time of life of particle spawners (defaults to 0.5)
- EITHER size <number>: Size of the particles
- OR min_size <number> and max_size <number>: Minimum and maximum size
- vertical <bool> (optional): Whether particles should rotate in 2D space only (default depends on falling vector)
]]
if not climate_mod.settings.particles then return end
local EFFECT_NAME = "climate_api:particles"
@ -10,7 +28,7 @@ local function get_particle_texture(particles)
end
local function spawn_particles(player, particles)
local ppos = player:getpos()
local ppos = player:get_pos()
local wind = climate_api.environment.get_wind()
local amount = particles.amount * climate_mod.settings.particle_count

View File

@ -1,3 +1,15 @@
--[[
# Skybox Effect
Use this effect to modify a player's sky, clouds, sun, moon, or stars
Expects a table as the parameter containing the following values:
- ``sky_data <table>`` (optional): Sky paramaters to be applied using player.set_sky
- ``cloud_data <table>`` (optional): Cloud paramaters to be applied using player.set_clouds
- ``sun_data <table>`` (optional): Sun paramaters to be applied using player.set_sun
- ``moon_data <table>`` (optional): Sky paramaters to be applied using player.set_moon
- ``star_data <table>`` (optional): Sky paramaters to be applied using player.set_stars
- ``priority <number>`` (optional): A skybox with higher priority will override lower rated ones (defaults to 1)
]]
if not climate_mod.settings.skybox then return end
local EFFECT_NAME = "climate_api:skybox"

View File

@ -1,3 +1,12 @@
--[[
# Sound Loop Effect
Use this effect to loop an ambient sound effect
Expects a table as the parameter containing the following values:
- ``name <string>``: Name of the played sound effect (without .ogg file ending)
- ``gain <number>`` (optional): Volume of the sound (defaults to 1.0)
- ``pitch <number>`` (optional): Pitch of the sound (defaults to 1.0)
]]
if not climate_mod.settings.sound then return end
local EFFECT_NAME = "climate_api:sound"

View File

@ -1,17 +1,22 @@
-- warn about outdated Minetest versions
assert(minetest.add_particlespawner, "[Climate API] This mod requires a more current version of Minetest")
-- initialize global API interfaces
climate_api = {}
climate_mod = {}
-- set mod path for file imports
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
-- retrieve boolean value from mod config
local function get_setting_bool(name, default)
local value = minetest.settings:get_bool("climate_api_" .. name)
if type(value) == "nil" then value = default end
return minetest.is_yes(value)
end
-- retrive numeric value from mod config
local function get_setting_number(name, default)
local value = minetest.settings:get("climate_api_" .. name)
if type(value) == "nil" then value = default end
@ -36,7 +41,7 @@ climate_mod.settings = {
volume = get_setting_number("volume", 1)
}
-- initiate empty registers
-- initialize empty registers
climate_mod.weathers = {}
climate_mod.effects = {}
climate_mod.cycles = {}
@ -48,19 +53,24 @@ climate_mod.current_effects = {}
climate_mod.forced_weather = {}
climate_mod.forced_wind = nil
-- import core API
-- handle persistent mod storage
climate_mod.state = dofile(modpath .. "/lib/datastorage.lua")
-- import core API
climate_api = dofile(modpath .. "/lib/api.lua")
climate_api.utility = dofile(modpath .. "/lib/api_utility.lua")
climate_api.skybox = dofile(modpath .. "/lib/skybox_merger.lua")
dofile(modpath .. "/lib/influences.lua")
climate_api.environment = dofile(modpath .. "/lib/environment.lua")
--climate_api = dofile(modpath .. "/lib/influences.lua")
climate_mod.world = dofile(modpath .. "/lib/world.lua")
climate_mod.trigger = dofile(modpath .. "/lib/trigger.lua")
-- start event loop and register chat commands
dofile(modpath.."/lib/main.lua")
dofile(modpath.."/lib/commands.lua")
-- register environment influences
dofile(modpath .. "/lib/influences.lua")
-- import predefined environment effects
dofile(modpath .. "/ca_effects/hud_overlay.lua")
dofile(modpath .. "/ca_effects/particles.lua")

View File

@ -1,12 +1,17 @@
-- initialize API interface
local api = {}
api.SHORT_CYCLE = 0.03 -- for particles and fast animations
-- define various standard effect cycle lengths
api.SHORT_CYCLE = 0 -- for particles and fast animations (use GSCYCLE)
api.DEFAULT_CYCLE = 0.1 -- for most effect types
api.MEDIUM_CYCLE = 2.0 -- for ressource intensive tasks
api.LONG_CYCLE = 5.0 -- for write operations and skybox changes
-- register new weather presets (like rain)
-- @param name <string> Unique preset name, ideally prefixed
-- @param conditions <table> A collection of required influences
-- @param effects <table> A <table> containing all applied effects as keys and parameters as values
function api.register_weather(name, conditions, effects)
-- TODO: check and sanitize
climate_mod.weathers[name] = {
conditions = conditions,
effects = effects,
@ -14,6 +19,10 @@ function api.register_weather(name, conditions, effects)
}
end
-- register new weather effects (like particles)
-- @param name <string> Unique effect name, ideally prefixed
-- @param handler <function> A function to be called when the effect is active
-- @param htype <string: start|tick|stop> Determines when the function is called
function api.register_effect(name, handler, htype)
-- check for valid handler types
if htype ~= "start" and htype ~= "tick" and htype ~= "stop" then
@ -29,18 +38,32 @@ function api.register_effect(name, handler, htype)
table.insert(climate_mod.effects[name][htype], handler)
end
-- set cycle length of given effect
-- @param name <string> Name of the affected effect
-- @param cycle <number> Duration between function calls
function api.set_effect_cycle(name, cycle)
climate_mod.cycles[name].timespan = cycle
end
-- register new environment influence that is independent of position
-- @param name <string> Unique influence name
-- @param func <function> Returns current influence value for entire world
function api.register_global_influence(name, func)
climate_mod.global_influences[name] = func
end
-- register new environment influence based on position
-- @param name <string> Unique influence name
-- @param func <function> Returns current influence value for given position
function api.register_influence(name, func)
climate_mod.influences[name] = func
end
-- register new Active Block Modifier dependent on weather status
-- Uses same config as Minetest.register_abm() but also adds
-- conditions similiar to weather presets and provides local environment
-- to action event handler as third parameter.
-- @param config <table> ABM configuration with additional information
function api.register_abm(config)
if not climate_mod.settings.block_updates then return end
@ -48,16 +71,21 @@ function api.register_abm(config)
local action = config.action
local pos_override = config.pos_override
-- override action handler to inject weather status
local override = function(pos, node)
local env = climate_mod.trigger.get_position_environment(pos)
if type(pos_override) == "function" then
pos = pos_override(pos)
node = minetest.get_node(pos)
end
-- get environment influences for current position
local env = climate_mod.trigger.get_position_environment(pos)
if conditions == nil then
return action(pos, node, env)
end
-- check if all conditions are met
for condition, goal in pairs(conditions) do
local is_applicable = climate_mod.trigger.test_condition(condition, env, goal)
if not is_applicable then return end
@ -65,9 +93,11 @@ function api.register_abm(config)
return action(pos, node, env)
end
-- register overridden abm setup
config.conditions = nil
config.action = override
minetest.register_abm(config)
end
-- return supplied API endpoint
return api

View File

@ -1,3 +1,5 @@
-- parse heat values into readable format
-- also convert to Celsius if configured
local function parse_heat(heat)
local indicator = "°F"
if not climate_mod.settings.fahrenheit then
@ -8,11 +10,14 @@ local function parse_heat(heat)
return heat .. indicator
end
-- register weather privilege in order to modify the weather status
minetest.register_privilege("weather", {
description = "Make changes to the current weather",
give_to_singleplayer = false
})
-- display general information on current weather
minetest.register_chatcommand("weather", {
description ="Display weather information",
func = function(playername)
@ -49,6 +54,7 @@ minetest.register_chatcommand("weather", {
end
})
-- set base heat to increase or decrease global climate temperatures
minetest.register_chatcommand("set_heat", {
params = "<heat>",
description = "Override the weather algorithm's base heat",
@ -63,6 +69,7 @@ minetest.register_chatcommand("set_heat", {
end
})
-- set base heat to increase or decrease global climate humidity
minetest.register_chatcommand("set_humidity", {
params = "<humidity>",
description = "Override the weather algorithm's base humidity",
@ -77,6 +84,7 @@ minetest.register_chatcommand("set_humidity", {
end
})
-- override wind direction and speed with given values
minetest.register_chatcommand("set_wind", {
params = "<wind>",
description = "Override the weather algorithm's windspeed",
@ -103,6 +111,7 @@ minetest.register_chatcommand("set_wind", {
end
})
-- display current mod config
minetest.register_chatcommand("weather_settings", {
description = "Print the active Climate API configuration",
func = function(playername)
@ -113,6 +122,7 @@ minetest.register_chatcommand("weather_settings", {
end
})
-- force a weather preset or disable it
minetest.register_chatcommand("set_weather", {
params ="<weather> <status>",
description ="Turn the specified weather preset on or off for all players or reset it to automatic",
@ -141,6 +151,7 @@ minetest.register_chatcommand("set_weather", {
end
})
-- list all weather presets and whether they have been forced or disabled
minetest.register_chatcommand("weather_status", {
description = "Prints which weather presets are enforced or disabled",
func = function(playername)
@ -157,6 +168,7 @@ minetest.register_chatcommand("weather_status", {
end
})
-- show all environment influences and their values for the executing player
minetest.register_chatcommand("weather_influences", {
description = "Prints which weather influences cause your current weather",
func = function(playername)

View File

@ -7,7 +7,7 @@ if not state:contains("noise_timer") then
humidity_base = 50,
wind_x = 0.5,
wind_z = 0.5,
noise_timer = math.random(0, 300000)
noise_timer = 0
})
end

View File

@ -1,5 +1,5 @@
local GSCYCLE = 0.03 * climate_mod.settings.tick_speed
local WORLD_CYCLE = 2 * climate_mod.settings.tick_speed
local GSCYCLE = 0.03 * climate_mod.settings.tick_speed -- only process event loop after this time amount
local WORLD_CYCLE = 15.00 * climate_mod.settings.tick_speed -- only update global environment influences after this time amount
local gs_timer = 0
local world_timer = 0

View File

@ -122,7 +122,6 @@ function trigger.call_handlers(name, effect, prev_effect)
has_ticks = true
ticks.current[player] = sources
ticks.prev[player] = prev_effect[player]
--prev_effect[player] = nil -- remove any found entries
else
has_starts = true
starts[player] = sources