Fix edge case where relativePosition of light is valid at 0,0,0

This commit is contained in:
RaveYard 2022-10-30 22:25:45 +01:00
parent ea5b1a3cac
commit 91c0871b0b
3 changed files with 6 additions and 5 deletions

View file

@ -8,7 +8,7 @@ include( CheckCXXCompilerFlag )
project( ZDRay )
SET( CMAKE_CXX_STANDARD 14 )
SET( CMAKE_CXX_STANDARD 17 )
IF( NOT CMAKE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE Debug CACHE STRING

View file

@ -7,6 +7,7 @@
#include "math/mathlib.h"
#include <memory>
#include <cmath>
#include <optional>
#undef MIN
#undef MAX
#undef min
@ -346,15 +347,15 @@ struct ThingLight
MapSubsectorEx *ssect;
// Portal related functionality
vec3 relativePosition = vec3(0);
std::optional<vec3> relativePosition;
int sectorGroup = 0;
// Portal aware position
vec3 LightRelativeOrigin() const
{
if (relativePosition != vec3(0))
if (relativePosition)
{
return relativePosition;
return *relativePosition;
}
return LightOrigin();
}

View file

@ -205,7 +205,7 @@ void LevelMesh::PropagateLight(FLevel& doomMap, ThingLight *light)
{
auto fakeLight = std::make_unique<ThingLight>(*light);
fakeLight->relativePosition = portal->TransformPosition(light->LightRelativeOrigin());
fakeLight->relativePosition.emplace(portal->TransformPosition(light->LightRelativeOrigin()));
fakeLight->sectorGroup = portal->targetSectorGroup;
PropagateLight(doomMap, fakeLight.get());