From 5ac0b1b84cf8a674f75a65ecc79ad99b2620bb93 Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Wed, 2 Oct 2024 01:37:30 +0800 Subject: [PATCH] Apply limits to the ZDRayInfo `lm_sampledist` value --- src/common/rendering/hwrenderer/data/hw_lightmaptile.h | 3 +++ src/maploader/maploader.cpp | 2 +- src/maploader/udmf.cpp | 10 ++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_lightmaptile.h b/src/common/rendering/hwrenderer/data/hw_lightmaptile.h index 7f803f5a8a..627b13c512 100644 --- a/src/common/rendering/hwrenderer/data/hw_lightmaptile.h +++ b/src/common/rendering/hwrenderer/data/hw_lightmaptile.h @@ -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 diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index eb4e19c0dc..3ea84000c6 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -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 { diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index f71f60fa62..c813cc4a4f 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -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: