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"
|
return "weather preset not found"
|
||||||
end
|
end
|
||||||
local preset = json.parse(file.read(filename))
|
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)"
|
return "weather set to "..filename.." preset ("..tostring(args[2]).." s)"
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|||||||
@ -37,6 +37,8 @@ struct EngineSettings;
|
|||||||
struct Weather {
|
struct Weather {
|
||||||
WeatherPreset a {};
|
WeatherPreset a {};
|
||||||
WeatherPreset b {};
|
WeatherPreset b {};
|
||||||
|
std::string nameA;
|
||||||
|
std::string nameB;
|
||||||
float t = 1.0f;
|
float t = 1.0f;
|
||||||
float speed = 0.0f;
|
float speed = 0.0f;
|
||||||
|
|
||||||
@ -47,11 +49,13 @@ struct Weather {
|
|||||||
a.intensity = 1.0f - t;
|
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(a, b);
|
||||||
|
std::swap(nameA, nameB);
|
||||||
b = std::move(preset);
|
b = std::move(preset);
|
||||||
t = 0.0f;
|
t = 0.0f;
|
||||||
speed = 1.0f / glm::max(time, 1.e-5f);
|
speed = 1.0f / glm::max(time, 1.e-5f);
|
||||||
|
nameB = std::move(name);
|
||||||
update(0.0f);
|
update(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,11 +6,44 @@ static int l_change(lua::State* L) {
|
|||||||
WeatherPreset weather {};
|
WeatherPreset weather {};
|
||||||
weather.deserialize(lua::tovalue(L, 1));
|
weather.deserialize(lua::tovalue(L, 1));
|
||||||
float time = lua::tonumber(L, 2);
|
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;
|
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[] = {
|
const luaL_Reg weatherlib[] = {
|
||||||
{"change", wrap_hud<l_change>},
|
{"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}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user