mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30: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 <vulkan/vulkan.h>
|
||||||
#include <vk_mem_alloc.h>
|
#include <vk_mem_alloc.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <limits>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace wowee {
|
namespace wowee {
|
||||||
namespace rendering {
|
namespace rendering {
|
||||||
|
|
@ -56,5 +58,25 @@ inline bool vkCheck(VkResult result, [[maybe_unused]] const char* msg) {
|
||||||
return true;
|
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 rendering
|
||||||
} // namespace wowee
|
} // namespace wowee
|
||||||
|
|
|
||||||
|
|
@ -46,25 +46,6 @@ namespace wowee {
|
||||||
namespace rendering {
|
namespace rendering {
|
||||||
|
|
||||||
namespace {
|
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) {
|
size_t approxTextureBytesWithMips(int w, int h) {
|
||||||
if (w <= 0 || h <= 0) return 0;
|
if (w <= 0 || h <= 0) return 0;
|
||||||
size_t base = static_cast<size_t>(w) * static_cast<size_t>(h) * 4ull;
|
size_t base = static_cast<size_t>(w) * static_cast<size_t>(h) * 4ull;
|
||||||
|
|
|
||||||
|
|
@ -40,24 +40,6 @@ bool envFlagEnabled(const char* key, bool defaultValue) {
|
||||||
return !(v == "0" || v == "false" || v == "off" || v == "no");
|
return !(v == "0" || v == "false" || v == "off" || v == "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t envSizeMBOrDefault(const char* name, size_t defMb) {
|
|
||||||
const char* raw = std::getenv(name);
|
|
||||||
if (!raw || !*raw) return defMb;
|
|
||||||
char* end = nullptr;
|
|
||||||
unsigned long long mb = std::strtoull(raw, &end, 10);
|
|
||||||
if (end == raw || mb == 0) return defMb;
|
|
||||||
return static_cast<size_t>(mb);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t envSizeOrDefault(const char* name, size_t defValue) {
|
|
||||||
const char* raw = std::getenv(name);
|
|
||||||
if (!raw || !*raw) return defValue;
|
|
||||||
char* end = nullptr;
|
|
||||||
unsigned long long v = std::strtoull(raw, &end, 10);
|
|
||||||
if (end == raw || v == 0) return defValue;
|
|
||||||
return static_cast<size_t>(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr uint32_t kParticleFlagRandomized = 0x40;
|
static constexpr uint32_t kParticleFlagRandomized = 0x40;
|
||||||
static constexpr uint32_t kParticleFlagTiled = 0x80;
|
static constexpr uint32_t kParticleFlagTiled = 0x80;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,6 @@
|
||||||
namespace wowee {
|
namespace wowee {
|
||||||
namespace rendering {
|
namespace rendering {
|
||||||
|
|
||||||
namespace {
|
|
||||||
size_t envSizeMBOrDefault(const char* name, size_t defMb) {
|
|
||||||
const char* raw = std::getenv(name);
|
|
||||||
if (!raw || !*raw) return defMb;
|
|
||||||
char* end = nullptr;
|
|
||||||
unsigned long long mb = std::strtoull(raw, &end, 10);
|
|
||||||
if (end == raw || mb == 0) return defMb;
|
|
||||||
return static_cast<size_t>(mb);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
// Matches set 1 binding 7 in terrain.frag.glsl
|
// Matches set 1 binding 7 in terrain.frag.glsl
|
||||||
struct TerrainParamsUBO {
|
struct TerrainParamsUBO {
|
||||||
int32_t layerCount;
|
int32_t layerCount;
|
||||||
|
|
|
||||||
|
|
@ -29,23 +29,6 @@ namespace wowee {
|
||||||
namespace rendering {
|
namespace rendering {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
size_t envSizeMBOrDefault(const char* name, size_t defMb) {
|
|
||||||
const char* raw = std::getenv(name);
|
|
||||||
if (!raw || !*raw) return defMb;
|
|
||||||
char* end = nullptr;
|
|
||||||
unsigned long long mb = std::strtoull(raw, &end, 10);
|
|
||||||
if (end == raw || mb == 0) return defMb;
|
|
||||||
return static_cast<size_t>(mb);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t envSizeOrDefault(const char* name, size_t defValue) {
|
|
||||||
const char* raw = std::getenv(name);
|
|
||||||
if (!raw || !*raw) return defValue;
|
|
||||||
char* end = nullptr;
|
|
||||||
unsigned long long v = std::strtoull(raw, &end, 10);
|
|
||||||
if (end == raw || v == 0) return defValue;
|
|
||||||
return static_cast<size_t>(v);
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// Thread-local scratch buffers for collision queries (allows concurrent getFloorHeight/checkWallCollision calls)
|
// Thread-local scratch buffers for collision queries (allows concurrent getFloorHeight/checkWallCollision calls)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue