add gfx.weather library & add weather.set command
This commit is contained in:
parent
02d8d8d6bf
commit
4d5b450145
1
res/presets/weather/clear.json
Normal file
1
res/presets/weather/clear.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"fog_opacity": 0.99,
|
||||
"fog_opacity": 0.98,
|
||||
"fog_dencity": 3.6,
|
||||
"fog_curve": 0.25,
|
||||
"clouds": 0.8
|
||||
|
||||
@ -264,6 +264,20 @@ console.add_command(
|
||||
end
|
||||
)
|
||||
|
||||
console.add_command(
|
||||
"weather.set name:str time:num=1",
|
||||
"Change weather",
|
||||
function (args, kwargs)
|
||||
local filename = file.find("presets/weather/"..args[1]..".json")
|
||||
if not filename then
|
||||
return "weather preset not found"
|
||||
end
|
||||
local preset = json.parse(file.read(filename))
|
||||
gfx.weather.change(preset, args[2])
|
||||
return "weather set to "..filename.." preset ("..tostring(args[2]).." s)"
|
||||
end
|
||||
)
|
||||
|
||||
console.cheats = {
|
||||
"blocks.fill",
|
||||
"tp",
|
||||
@ -271,5 +285,6 @@ console.cheats = {
|
||||
"time.set",
|
||||
"time.daycycle",
|
||||
"entity.despawn",
|
||||
"player.respawn"
|
||||
"player.respawn",
|
||||
"weather.set",
|
||||
}
|
||||
|
||||
@ -154,22 +154,6 @@ void WorldRenderer::renderLevel(
|
||||
) {
|
||||
weather.update(delta);
|
||||
|
||||
if (timer > 1.0f && weather.b.fall.texture.empty() && timer < 2.0f) {
|
||||
weather.b.deserialize(io::read_json("res:presets/weather/snow.json"));
|
||||
weather.t = 0.0f;
|
||||
weather.speed = 0.5f;
|
||||
weather.update(delta);
|
||||
}
|
||||
|
||||
if (timer > 15.0f && weather.a.fall.texture.empty()) {
|
||||
std::swap(weather.a, weather.b);
|
||||
weather.b = {};
|
||||
weather.b.deserialize(io::read_json("res:presets/weather/fog.json"));
|
||||
weather.t = 0.0f;
|
||||
weather.speed = 0.1f;
|
||||
weather.update(delta);
|
||||
}
|
||||
|
||||
texts->render(ctx, camera, settings, hudVisible, false);
|
||||
|
||||
bool culling = engine.getSettings().graphics.frustumCulling.get();
|
||||
|
||||
@ -47,6 +47,14 @@ struct Weather {
|
||||
a.intensity = 1.0f - t;
|
||||
}
|
||||
|
||||
void change(WeatherPreset preset, float time) {
|
||||
std::swap(a, b);
|
||||
b = std::move(preset);
|
||||
t = 0.0f;
|
||||
speed = 1.0f / glm::max(time, 1.e-5f);
|
||||
update(0.0f);
|
||||
}
|
||||
|
||||
float fogOpacity() const {
|
||||
return b.fogOpacity * t + a.fogOpacity * (1.0f - t);
|
||||
}
|
||||
|
||||
@ -46,6 +46,7 @@ extern const luaL_Reg utf8lib[];
|
||||
extern const luaL_Reg vec2lib[]; // vecn.cpp
|
||||
extern const luaL_Reg vec3lib[]; // vecn.cpp
|
||||
extern const luaL_Reg vec4lib[]; // vecn.cpp
|
||||
extern const luaL_Reg weatherlib[]; // gfx.weather
|
||||
extern const luaL_Reg worldlib[];
|
||||
|
||||
// Components
|
||||
|
||||
16
src/logic/scripting/lua/libs/libweather.cpp
Normal file
16
src/logic/scripting/lua/libs/libweather.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "libhud.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_change(lua::State* L) {
|
||||
WeatherPreset weather {};
|
||||
weather.deserialize(lua::tovalue(L, 1));
|
||||
float time = lua::tonumber(L, 2);
|
||||
renderer->weather.change(std::move(weather), time);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg weatherlib[] = {
|
||||
{"change", wrap_hud<l_change>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
@ -36,6 +36,7 @@ void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
|
||||
lua::openlib(L, "gfx", "blockwraps", blockwrapslib);
|
||||
lua::openlib(L, "gfx", "particles", particleslib);
|
||||
lua::openlib(L, "gfx", "text3d", text3dlib);
|
||||
lua::openlib(L, "gfx", "weather", weatherlib);
|
||||
|
||||
load_script("hud_classes.lua");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user