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
|
|
@ -46,25 +46,6 @@ namespace wowee {
|
|||
namespace rendering {
|
||||
|
||||
namespace {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
size_t approxTextureBytesWithMips(int w, int h) {
|
||||
if (w <= 0 || h <= 0) return 0;
|
||||
size_t base = static_cast<size_t>(w) * static_cast<size_t>(h) * 4ull;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue