Improve calculation performance, write helpful README

This commit is contained in:
Till Affeldt 2020-04-25 15:49:53 +02:00
parent 1057342ac6
commit bff54bfb74
8 changed files with 133 additions and 48 deletions

View File

@ -1,5 +1,8 @@
# Climate API # Climate API
A powerful engine for weather presets and visual effects A powerful engine for weather presets and visual effects.
Requires a weather pack like [Regional Weather](https://github.com/t-affeldt/regional_weather).
![](https://raw.githubusercontent.com/t-affeldt/climate_api/master/screenshot.png)
Use the regional climate to set up different effects for different regions. Use the regional climate to set up different effects for different regions.
Control where your effects are activated based on temperature, humidity, wind, Control where your effects are activated based on temperature, humidity, wind,
@ -8,12 +11,98 @@ Climate API provides temperature and humidity values on a block-per-block basis
that follow the seasons, day / night cycle and random changes. that follow the seasons, day / night cycle and random changes.
Make it rain, change the sky or poison the player - it's up to you. Make it rain, change the sky or poison the player - it's up to you.
## Assets ## Troubleshooting
Generally speaking, most mods should be compatible.
If you notice __odd movement speeds__ or jump heights of players, you should check for mods that also modify player physics. Use a compatibility mod like [player_monoids](https://github.com/minetest-mods/player_monoids) or [playerphysics](https://forum.minetest.net/viewtopic.php?t=22172) to get rid of this problem. This requires the conflicting mod to also support the chosen compatibility layer.
Mods that __modify the sky__ (including skybox, moon, sun, stars and clouds) are sadly not fully compatible because they conflict with Climate API's sky system. You should deactivate the sky features in either mod. You can do this here using the ``Override the skybox`` setting. If you're a mod maker then you can also optionally depend on climate_api and use ``climate_api.skybox.add_layer(playername, layer_name, options)`` to register your skybox change in a compatible way. Note that you need __at least Minetest v5.2.0__ for skybox changes to have any effect.
Conflicting skybox changes include the ``weather`` mod included in vanilla __Minetest Game__. You will want to disable that mod in order to use the more advanced cloud system introduced by Climate API. Head to ``Settings → All Settings → Games → Minetest Game`` and set ``Enable weather`` to ``Disabled``. This setting will only exist if you are using Minetest Game v5.2.0 or higher.
The following mods have been created specifically with Climate API in mind:
- [Regional Weather](https://github.com/t-affeldt/regional_weather): My own weather pack for climate based weather effects
- [Moon Phases](https://github.com/t-affeldt/minetest_moon_phase): Complements weather effects with dynamic sky changes and a full moon cycle
- [Sailing Kit](https://github.com/t-affeldt/sailing_kit) (Fork): Uses Climate API's new wind system to sail across the sea.
The following mods complement Climate API particularly well:
- [Lightning](https://github.com/minetest-mods/lightning): Adds to heavy rain by enabling additional lightning effects
- [Ambience](https://notabug.org/TenPlus1/ambience): Plays some nice ambient sound effects based on where you are.
## Chat Commands
- ``/weather``: Display information on current weather effects. This command will show you current temperature and humidity, active weather presets and currently playing effects
- ``/weather_settings``: Display current mod configuration in the chat
- ``/weather_influences``: Display all different factors and how they affect you in this moment.
- ``/weather_status``: Display a list of all installed weather presets and whether they have been forced on, turned off, or are running normally (auto).
- ``/grant <playername> weather``: Enable a specified player to modify the current weather.
- ``/set_heat <value>``: Override the base heat value used to calculate local climate. Positive numbers will increase temperature by X degrees Fahrenheit, whereas negative values will lower it.
- ``/set_humidity <value>``: Override the base humidity value used to calculate local climate. Positive numbers will increase humidity by X percent, whereas negative values will lower it.
- ``/set_wind <x> <z>``: Override wind speed and direction. Higher absolute values result in stronger wind. The sign indicates direction.
- ``/set_weather <weather> <on|off|auto>``: Set a weather preset to always be applied (on), disable it completely (off), or reset it to be applied automatically (auto). Turning presets on manually might result in partially missing effects (like no sound if you enable sandstorms but no storms). Use ``/weather_status`` for a full list of installed weather presets. The prefix is important.
## Configuration Options
You can find all mod configuration options in your Minetest launcher.
Go to ``Settings → All Settings → Mods → climate_api`` to change them.
Individual weather packs may provide additional configuration options in their respective mod configuration section.
### Performance
- ``Update speed of weather effects`` (default 1.0):
This value regulates how often weather presets are recalculated.
Higher values will result in smoother transitions between effects as well as faster response times to traveling players.
Lower values will significantly increase overall performance at the cost of rougher looking effects.
- ``Multiplicator for used particles`` (default 1.0):
This value regulated how many particles will be spawned.
A value of 1 will use the recommended amount of particles.
Lower values can possible increase performance.
- ``Dynamically modify nodes`` (default true):
If set to true, weather packs are allowed to register node update handlers.
These can be used to dynamically place snow layers, melt ice, or hydrate soil.
### Visuals
- ``Show particle effects`` (default true):
If set to true, weather effects (like rain) are allowed to render particles.
Deactivating this feature will prevent some presets from being visible.
For performance considerations it is recommended to decrease the amount of particles instead.
- ``Override the skybox`` (default true):
If set to true, weather effects are allowed to modify a player's sky.
This includes skybox, sun, moon, and clouds (also used for fog effects).
Running this mod on Minetest 5.1.2 or earlier versions will automatically disable this feature.
- ``Display HUD overlays`` (default true):
If set to true, weather effects are allowed to render an image on top of the gameplay.
This is usually an optional effect used to increase immersion (like a frozen-over camera in a snow storm).
### Environment
- ``Global base temperature`` (default 0):
This value will be added to all biome's base temperatures before applying random modifiers.
Every unit here will increase the global base heat by one degree Fahrenheit.
Negative values will cool down global base heat respectively.
- ``Global base humidity`` (default 0):
This value will be added to all biome's base humidity before applying random modifiers.
Every unit here will increase the global base humidity by one percent.
Negative values will dry up global base humidity respectively.
- ``Time rate of weather changes`` (default 1.0):
This value regulates how quickly environment factors like heat, humidity and wind are changing.
A value of 2 will double the speed at which weather presets change.
A value of 0.5 will half the speed respectively.
### Preferences
- ``Show degrees in Fahrenheit instead of Celsius`` (default true):
If set to true, temperature information in /weather command will be displayed in Fahrenheit.
- ``Play ambient sound loops`` (default true):
If set to true, weather effects are allowed to play sound loops.
You can also adjust sound levels instead of deactivating this feature completely.
Setting this value to false will be slightly more performant than setting the volume to zero.
- ``Volume of sound effects`` (default 1.0):
This value regulates overall sound volume.
A value of 2 will double the volume whereas a value of 0.5 will reduce the volume by half.
## License
- Source Code: *GNU LGPL v3* by me
- Sun and moon textures: *CC BY-SA (3.0)* by Cap - Sun and moon textures: *CC BY-SA (3.0)* by Cap
## Assets in screenshots ## Assets in screenshots
- Screenshots and editing by me: *CC BY-SA (3.0)* - Screenshots and editing by me: *CC BY-SA (3.0)*
- Logos and artwork: *CC BY-SA (3.0)* by Cap - Logos and artwork: *CC BY-SA (3.0)* by Cap
- Lato Font (for the Logo): *OFL* by Łukasz Dziedzic from http://www.latofonts.com/lato-free-fonts/ - Lato Font (for the Logo): *OFL* by Łukasz Dziedzic from http://www.latofonts.com/lato-free-fonts/
- Liberation Fonts (for the text): *OFL*, see https://github.com/liberationfonts/liberation-fonts - Source Sans Pro (for the subtitles): *OFL*, see https://fonts.google.com/specimen/Source+Sans+Pro
- Used texture pack: Polygonia (128px edition) *CC BY-SA (4.0)* by Lokrates. See https://forum.minetest.net/viewtopic.php?f=4&t=19043 - Used texture pack: Polygonia (128px edition) *CC BY-SA (4.0)* by Lokrates. See https://forum.minetest.net/viewtopic.php?f=4&t=19043

View File

@ -1,13 +1,9 @@
# TODO # TODO
## Required for Beta
- Write helpful README
## Planned for first release ## Planned for first release
- Improve value structures of particle effects - Improve value structures of particle effects
- Find good values for weather conditions - Find good values for weather conditions
- Write documentation on how to add weathers and effects - Write documentation on how to add weathers and effects
- Ability to register global influences that are the same for any position
## Nice to have ## Nice to have
- Assign meta data (like "downfall", "wind", etc.) to weather presets - Assign meta data (like "downfall", "wind", etc.) to weather presets

View File

@ -40,6 +40,8 @@ climate_mod.settings = {
climate_mod.weathers = {} climate_mod.weathers = {}
climate_mod.effects = {} climate_mod.effects = {}
climate_mod.cycles = {} climate_mod.cycles = {}
climate_mod.global_environment = {}
climate_mod.global_influences = {}
climate_mod.influences = {} climate_mod.influences = {}
climate_mod.current_weather = {} climate_mod.current_weather = {}
climate_mod.current_effects = {} climate_mod.current_effects = {}

View File

@ -33,6 +33,10 @@ function api.set_effect_cycle(name, cycle)
climate_mod.cycles[name].timespan = cycle climate_mod.cycles[name].timespan = cycle
end end
function api.register_global_influence(name, func)
climate_mod.global_influences[name] = func
end
function api.register_influence(name, func) function api.register_influence(name, func)
climate_mod.influences[name] = func climate_mod.influences[name] = func
end end

View File

@ -20,12 +20,12 @@ climate_api.register_influence("biome", function(pos)
return biome return biome
end) end)
climate_api.register_influence("windspeed", function(_) climate_api.register_global_influence("windspeed", function()
local wind = climate_api.environment.get_wind() local wind = climate_api.environment.get_wind()
return vector.length(wind) return vector.length(wind)
end) end)
climate_api.register_influence("wind_yaw", function(_) climate_api.register_global_influence("wind_yaw", function()
local wind = climate_api.environment.get_wind() local wind = climate_api.environment.get_wind()
if vector.length(wind) == 0 then return 0 end if vector.length(wind) == 0 then return 0 end
return minetest.dir_to_yaw(wind) return minetest.dir_to_yaw(wind)
@ -45,10 +45,6 @@ climate_api.register_influence("daylight", function(pos)
return minetest.env:get_node_light(pos, 0.5) return minetest.env:get_node_light(pos, 0.5)
end) end)
climate_api.register_influence("time", function(_) climate_api.register_global_influence("time", function()
return minetest.get_timeofday() return minetest.get_timeofday()
end) end)
climate_api.register_influence("day_count", function(_)
return minetest.get_day_count()
end)

View File

@ -14,6 +14,7 @@ minetest.register_globalstep(function(dtime)
world_timer = 0 world_timer = 0
climate_mod.state:set_float("noise_timer", noise_timer) climate_mod.state:set_float("noise_timer", noise_timer)
climate_mod.world.update_status(noise_timer) climate_mod.world.update_status(noise_timer)
climate_mod.global_environment = climate_mod.trigger.get_global_environment()
end end
local previous_effects = table.copy(climate_mod.current_effects) local previous_effects = table.copy(climate_mod.current_effects)

View File

@ -1,20 +1,15 @@
local trigger = {} local trigger = {}
function trigger.get_position_environment(pos) function trigger.get_global_environment()
local wind_x = climate_mod.state:get_float("wind_x")
local wind_z = climate_mod.state:get_float("wind_z")
--[[local env = {}
env.pos = pos
env.height = pos.y
env.wind = vector.new(wind_x, 0, wind_z)
env.windspeed = vector.length(env.wind)
env.heat = climate_api.environment.get_heat(pos)
env.humidity = climate_api.environment.get_humidity(pos)
env.time = minetest.get_timeofday()
env.date = minetest.get_day_count()
env.light = minetest.get_node_light(vector.add(pos, vector.new({x=0,y=1,z=0})), 0.5)]]
local env = {} local env = {}
for influence, func in pairs(climate_mod.global_influences) do
env[influence] = func()
end
return env
end
function trigger.get_position_environment(pos)
local env = table.copy(climate_mod.global_environment)
for influence, func in pairs(climate_mod.influences) do for influence, func in pairs(climate_mod.influences) do
env[influence] = func(pos) env[influence] = func(pos)
end end

View File

@ -1,5 +1,21 @@
[Features] [Performance]
# This value regulates how often weather presets are recalculated.
# Higher values will result in smoother transitions between effects as well as faster response times to traveling players.
# Lower values will significantly increase overall performance at the cost of rougher looking effects.
climate_api_tick_speed (Update speed of weather effects) float 1 0.1 10
# This value regulated how many particles will be spawned.
# A value of 1 will use the recommended amount of particles.
# Lower values can possible increase performance.
climate_api_particle_count (Multiplicator for used particles) float 1 0.1 2
# If set to true, weather packs are allowed to register node update handlers.
# These can be used to dynamically place snow layers, melt ice, or hydrate soil.
climate_api_block_updates (Dynamically modify nodes) bool true
[Visuals]
# If set to true, weather effects (like rain) are allowed to render particles. # If set to true, weather effects (like rain) are allowed to render particles.
# Deactivating this feature will prevent some presets from being visible. # Deactivating this feature will prevent some presets from being visible.
# For performance considerations it is recommended to decrease the amount of particles instead. # For performance considerations it is recommended to decrease the amount of particles instead.
@ -10,19 +26,10 @@ climate_api_particles (Show particle effects) bool true
# Running this mod on Minetest 5.1.2 or earlier versions will automatically disable this feature. # Running this mod on Minetest 5.1.2 or earlier versions will automatically disable this feature.
climate_api_skybox (Override the skybox) bool true climate_api_skybox (Override the skybox) bool true
# If set to true, weather effects are allowed to play sound loops.
# You can also adjust sound levels instead of deactivating this feature completely.
# Setting this value to false will be slightly more performant than setting the volume to zero.
climate_api_sound (Play ambient sound loops) bool true
# If set to true, weather effects are allowed to render an image on top of the gameplay. # If set to true, weather effects are allowed to render an image on top of the gameplay.
# This is usually an optional effect used to increase immersion (like a frozen-over camera in a snow storm). # This is usually an optional effect used to increase immersion (like a frozen-over camera in a snow storm).
climate_api_hud_overlay (Display HUD overlays) bool true climate_api_hud_overlay (Display HUD overlays) bool true
# If set to true, weather packs are allowed to register node update handlers.
# These can be used to dynamically place snow layers, melt ice, or hydrate soil.
climate_api_block_updates (Dynamically modify nodes) bool true
[Environment] [Environment]
@ -41,22 +48,17 @@ climate_api_humidity_base (Global base humidity) float 0
# A value of 0.5 will half the speed respectively. # A value of 0.5 will half the speed respectively.
climate_api_time_spread (Time rate of weather changes) float 1 0.1 10 climate_api_time_spread (Time rate of weather changes) float 1 0.1 10
# This value regulates how often weather presets are recalculated.
# Higher values will result in smoother transitions between effects as well as faster response times to traveling players.
# Lower values will significantly increase overall performance at the cost of rougher looking effects.
climate_api_tick_speed (Update speed of weather effects) float 1 0.1 10
[Preferences] [Preferences]
# This value regulated how many particles will be spawned.
# A value of 1 will use the recommended amount of particles.
# Lower values can possible increase performance.
climate_api_particle_count (Multiplicator for used particles) float 1 0.1 2
# If set to true, temperature information in /weather command will be displayed in Fahrenheit. # If set to true, temperature information in /weather command will be displayed in Fahrenheit.
climate_api_fahrenheit (Show degrees in Fahrenheit instead of Celsius) bool false climate_api_fahrenheit (Show degrees in Fahrenheit instead of Celsius) bool false
# If set to true, weather effects are allowed to play sound loops.
# You can also adjust sound levels instead of deactivating this feature completely.
# Setting this value to false will be slightly more performant than setting the volume to zero.
climate_api_sound (Play ambient sound loops) bool true
# This value regulates overall sound volume. # This value regulates overall sound volume.
# A value of 2 will double the volume whereas a value of 0.5 will reduce the volume by half. # A value of 2 will double the volume whereas a value of 0.5 will reduce the volume by half.
climate_api_volume (Volume of sound effects) float 1 0 10 climate_api_volume (Volume of sound effects) float 1 0 10