Skip to content

Commit

Permalink
Apply limits to the ZDRayInfo lm_sampledist value
Browse files Browse the repository at this point in the history
  • Loading branch information
nashmuhandes committed Oct 1, 2024
1 parent a0f56b3 commit 5ac0b1b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/common/rendering/hwrenderer/data/hw_lightmaptile.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "vectors.h"
#include "bounds.h"

#define LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MIN (int)4
#define LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MAX (int)64

struct LevelMeshSurface;

struct LightmapTileBinding
Expand Down
2 changes: 1 addition & 1 deletion src/maploader/maploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2967,7 +2967,7 @@ void MapLoader::InitLevelMesh(MapData* map)
if (map->Size(ML_LIGHTMAP))
{
// Arbitrary ZDRay limit. This will break lightmap lump loading if not enforced.
Level->LightmapSampleDistance = Level->LightmapSampleDistance < 8 ? 8 : Level->LightmapSampleDistance;
Level->LightmapSampleDistance = std::clamp((int)Level->LightmapSampleDistance, LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MIN, LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MAX);

if (!Level->lightmaps) // We are unfortunately missing ZDRayInfo
{
Expand Down
10 changes: 4 additions & 6 deletions src/maploader/udmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,14 +810,12 @@ class UDMFParser : public UDMFParserBase
break;
case NAME_lm_sampledist:
CHECK_N(Zd | Zdt)
if (CheckInt(key) >= 0 && CheckInt(key) <= 0xFFFF)
if (CheckInt(key) < LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MIN || CheckInt(key) > LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MAX)
{
Level->LightmapSampleDistance = CheckInt(key);
}
else
{
DPrintf(DMSG_WARNING, "Can't set the global lm_sampledist to %s\n", key.GetChars());
DPrintf(DMSG_WARNING, "Current lm_sampledist value, %x, on the ZDRayInfo thing is out of range (min: %i, max: %i)\n",
CheckInt(key), LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MIN, LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MAX);
}
Level->LightmapSampleDistance = CheckInt(key);
break;

default:
Expand Down

0 comments on commit 5ac0b1b

Please sign in to comment.