1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-15 20:46:35 +00:00

Expose getCurrentSunLightDirection in interiors and use perfect forwarding

This commit is contained in:
Evil Eye 2025-08-17 08:25:05 +02:00
parent ead19d099a
commit aa9978d720
2 changed files with 15 additions and 13 deletions

View file

@ -42,25 +42,25 @@ namespace
}
template <class Cell>
bool hasWeather(const Cell& cell)
bool hasWeather(const Cell& cell, bool requireExterior)
{
if (!cell.mStore->isQuasiExterior() && !cell.mStore->isExterior())
if (requireExterior && !cell.mStore->isQuasiExterior() && !cell.mStore->isExterior())
return false;
return MWBase::Environment::get().getWorldScene()->isCellActive(*cell.mStore);
}
template <class Getter>
auto overloadForActiveCell(const Getter&& getter)
auto overloadForActiveCell(Getter&& getter, bool requireExterior = true)
{
using Result = std::invoke_result_t<Getter>;
return sol::overload(
[=](const MWLua::GCell& cell) -> Result {
if (!hasWeather(cell))
if (!hasWeather(cell, requireExterior))
return Result{};
return getter();
},
[=](const MWLua::LCell& cell) -> Result {
if (!hasWeather(cell))
if (!hasWeather(cell, requireExterior))
return Result{};
return getter();
});
@ -210,14 +210,16 @@ namespace MWLua
api["getNext"] = overloadForActiveCell(
[]() -> const MWWorld::Weather* { return MWBase::Environment::get().getWorld()->getNextWeather(); });
api["getTransition"] = overloadWeatherGetter(&MWBase::World::getWeatherTransition);
api["getCurrentSunLightDirection"] = overloadForActiveCell([]() -> std::optional<osg::Vec4f> {
api["getCurrentSunLightDirection"] = overloadForActiveCell(
[]() -> std::optional<osg::Vec4f> {
osg::Vec4f sunPos = MWBase::Environment::get().getWorld()->getSunLightPosition();
// normalize to get the direction towards the sun
sunPos.normalize();
// and invert it to get the direction of the sun light
return -sunPos;
});
},
false);
api["getCurrentSunVisibility"] = overloadWeatherGetter(&MWBase::World::getSunVisibility);
api["getCurrentSunPercentage"] = overloadWeatherGetter(&MWBase::World::getSunPercentage);
api["getCurrentWindSpeed"] = overloadWeatherGetter(&MWBase::World::getWindSpeed);

View file

@ -1275,7 +1275,7 @@
-- Get the current direction of the light of the sun.
-- @function [parent=#Weather] getCurrentSunLightDirection
-- @param #Cell The cell to get the sun direction for
-- @return openmw.util#Vector4 or nil if the cell is inactive or has no weather
-- @return openmw.util#Vector4 or nil if the cell is inactive
---
-- Get the current sun visibility taking weather transition into account.