Apply limits to the ZDRayInfo lm_sampledist value

This commit is contained in:
nashmuhandes 2024-10-02 01:37:30 +08:00
commit 5ac0b1b84c
3 changed files with 8 additions and 7 deletions

View file

@ -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

View file

@ -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
{

View file

@ -810,14 +810,12 @@ public:
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: