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:
parent
ead19d099a
commit
aa9978d720
2 changed files with 15 additions and 13 deletions
|
@ -42,25 +42,25 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Cell>
|
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 false;
|
||||||
return MWBase::Environment::get().getWorldScene()->isCellActive(*cell.mStore);
|
return MWBase::Environment::get().getWorldScene()->isCellActive(*cell.mStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Getter>
|
template <class Getter>
|
||||||
auto overloadForActiveCell(const Getter&& getter)
|
auto overloadForActiveCell(Getter&& getter, bool requireExterior = true)
|
||||||
{
|
{
|
||||||
using Result = std::invoke_result_t<Getter>;
|
using Result = std::invoke_result_t<Getter>;
|
||||||
return sol::overload(
|
return sol::overload(
|
||||||
[=](const MWLua::GCell& cell) -> Result {
|
[=](const MWLua::GCell& cell) -> Result {
|
||||||
if (!hasWeather(cell))
|
if (!hasWeather(cell, requireExterior))
|
||||||
return Result{};
|
return Result{};
|
||||||
return getter();
|
return getter();
|
||||||
},
|
},
|
||||||
[=](const MWLua::LCell& cell) -> Result {
|
[=](const MWLua::LCell& cell) -> Result {
|
||||||
if (!hasWeather(cell))
|
if (!hasWeather(cell, requireExterior))
|
||||||
return Result{};
|
return Result{};
|
||||||
return getter();
|
return getter();
|
||||||
});
|
});
|
||||||
|
@ -210,14 +210,16 @@ namespace MWLua
|
||||||
api["getNext"] = overloadForActiveCell(
|
api["getNext"] = overloadForActiveCell(
|
||||||
[]() -> const MWWorld::Weather* { return MWBase::Environment::get().getWorld()->getNextWeather(); });
|
[]() -> const MWWorld::Weather* { return MWBase::Environment::get().getWorld()->getNextWeather(); });
|
||||||
api["getTransition"] = overloadWeatherGetter(&MWBase::World::getWeatherTransition);
|
api["getTransition"] = overloadWeatherGetter(&MWBase::World::getWeatherTransition);
|
||||||
api["getCurrentSunLightDirection"] = overloadForActiveCell([]() -> std::optional<osg::Vec4f> {
|
api["getCurrentSunLightDirection"] = overloadForActiveCell(
|
||||||
osg::Vec4f sunPos = MWBase::Environment::get().getWorld()->getSunLightPosition();
|
[]() -> std::optional<osg::Vec4f> {
|
||||||
// normalize to get the direction towards the sun
|
osg::Vec4f sunPos = MWBase::Environment::get().getWorld()->getSunLightPosition();
|
||||||
sunPos.normalize();
|
// normalize to get the direction towards the sun
|
||||||
|
sunPos.normalize();
|
||||||
|
|
||||||
// and invert it to get the direction of the sun light
|
// and invert it to get the direction of the sun light
|
||||||
return -sunPos;
|
return -sunPos;
|
||||||
});
|
},
|
||||||
|
false);
|
||||||
api["getCurrentSunVisibility"] = overloadWeatherGetter(&MWBase::World::getSunVisibility);
|
api["getCurrentSunVisibility"] = overloadWeatherGetter(&MWBase::World::getSunVisibility);
|
||||||
api["getCurrentSunPercentage"] = overloadWeatherGetter(&MWBase::World::getSunPercentage);
|
api["getCurrentSunPercentage"] = overloadWeatherGetter(&MWBase::World::getSunPercentage);
|
||||||
api["getCurrentWindSpeed"] = overloadWeatherGetter(&MWBase::World::getWindSpeed);
|
api["getCurrentWindSpeed"] = overloadWeatherGetter(&MWBase::World::getWindSpeed);
|
||||||
|
|
|
@ -1275,7 +1275,7 @@
|
||||||
-- Get the current direction of the light of the sun.
|
-- Get the current direction of the light of the sun.
|
||||||
-- @function [parent=#Weather] getCurrentSunLightDirection
|
-- @function [parent=#Weather] getCurrentSunLightDirection
|
||||||
-- @param #Cell The cell to get the sun direction for
|
-- @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.
|
-- Get the current sun visibility taking weather transition into account.
|
||||||
|
|
Loading…
Reference in a new issue