mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 07:40:14 +00:00
refactor: consolidate duplicate environment variable utility functions
Move envSizeMBOrDefault and envSizeOrDefault from 4 separate rendering modules (character_renderer, m2_renderer, terrain_renderer, wmo_renderer) into shared vk_utils.hpp header as inline functions. Use the most robust version which includes overflow checking for MB-to-bytes conversion. This eliminates 7 identical local function definitions and improves consistency across all rendering modules.
This commit is contained in:
parent
cda703b0f4
commit
b3d8651db9
5 changed files with 22 additions and 65 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include <vulkan/vulkan.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace wowee {
|
||||
namespace rendering {
|
||||
|
|
@ -56,5 +58,25 @@ inline bool vkCheck(VkResult result, [[maybe_unused]] const char* msg) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Environment variable utility functions
|
||||
inline size_t envSizeMBOrDefault(const char* name, size_t defMb) {
|
||||
const char* v = std::getenv(name);
|
||||
if (!v || !*v) return defMb;
|
||||
char* end = nullptr;
|
||||
unsigned long long mb = std::strtoull(v, &end, 10);
|
||||
if (end == v || mb == 0) return defMb;
|
||||
if (mb > (std::numeric_limits<size_t>::max() / (1024ull * 1024ull))) return defMb;
|
||||
return static_cast<size_t>(mb);
|
||||
}
|
||||
|
||||
inline size_t envSizeOrDefault(const char* name, size_t defValue) {
|
||||
const char* v = std::getenv(name);
|
||||
if (!v || !*v) return defValue;
|
||||
char* end = nullptr;
|
||||
unsigned long long n = std::strtoull(v, &end, 10);
|
||||
if (end == v || n == 0) return defValue;
|
||||
return static_cast<size_t>(n);
|
||||
}
|
||||
|
||||
} // namespace rendering
|
||||
} // namespace wowee
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue