add gfx.weather.get_current, get_current_data, get_fall_intencity
This commit is contained in:
parent
4d5b450145
commit
a152237f26
@ -273,7 +273,7 @@ console.add_command(
|
||||
return "weather preset not found"
|
||||
end
|
||||
local preset = json.parse(file.read(filename))
|
||||
gfx.weather.change(preset, args[2])
|
||||
gfx.weather.change(preset, args[2], args[1])
|
||||
return "weather set to "..filename.." preset ("..tostring(args[2]).." s)"
|
||||
end
|
||||
)
|
||||
|
||||
@ -37,6 +37,8 @@ struct EngineSettings;
|
||||
struct Weather {
|
||||
WeatherPreset a {};
|
||||
WeatherPreset b {};
|
||||
std::string nameA;
|
||||
std::string nameB;
|
||||
float t = 1.0f;
|
||||
float speed = 0.0f;
|
||||
|
||||
@ -47,11 +49,13 @@ struct Weather {
|
||||
a.intensity = 1.0f - t;
|
||||
}
|
||||
|
||||
void change(WeatherPreset preset, float time) {
|
||||
void change(WeatherPreset preset, float time, std::string name="") {
|
||||
std::swap(a, b);
|
||||
std::swap(nameA, nameB);
|
||||
b = std::move(preset);
|
||||
t = 0.0f;
|
||||
speed = 1.0f / glm::max(time, 1.e-5f);
|
||||
nameB = std::move(name);
|
||||
update(0.0f);
|
||||
}
|
||||
|
||||
|
||||
@ -6,11 +6,44 @@ 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);
|
||||
std::string name;
|
||||
if (lua::isstring(L, 3)) {
|
||||
name = lua::tostring(L, 3);
|
||||
}
|
||||
renderer->weather.change(std::move(weather), time, std::move(name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_current(lua::State* L) {
|
||||
if (renderer->weather.t > 0.5f) {
|
||||
return lua::pushstring(L, renderer->weather.nameB);
|
||||
} else {
|
||||
return lua::pushstring(L, renderer->weather.nameA);
|
||||
}
|
||||
}
|
||||
|
||||
static int l_get_fall_intencity(lua::State* L) {
|
||||
const auto& a = renderer->weather.a;
|
||||
const auto& b = renderer->weather.b;
|
||||
float t = renderer->weather.t;
|
||||
return lua::pushnumber(L,
|
||||
(a.fall.texture.empty() ? 0.0f : (1.0f - t)) +
|
||||
(b.fall.texture.empty() ? 0.0f : t)
|
||||
);
|
||||
}
|
||||
|
||||
static int l_get_current_data(lua::State* L) {
|
||||
if (renderer->weather.t > 0.5f) {
|
||||
return lua::pushvalue(L, renderer->weather.b.serialize());
|
||||
} else {
|
||||
return lua::pushvalue(L, renderer->weather.a.serialize());
|
||||
}
|
||||
}
|
||||
|
||||
const luaL_Reg weatherlib[] = {
|
||||
{"change", wrap_hud<l_change>},
|
||||
{"get_current", wrap_hud<l_get_current>},
|
||||
{"get_current_data", wrap_hud<l_get_current_data>},
|
||||
{"get_fall_intencity", wrap_hud<l_get_fall_intencity>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user