mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-03 20:03:50 +00:00
refactor: name memory/taxi constants, add camera jitter why-comment
- memory_monitor: extract kOneGB and kFallbackRAM constants from 6 duplicated 1024*1024*1024 expressions; name kFieldPrefixLen for /proc/meminfo "MemAvailable:" offset (was bare 13) - camera: add why-comment on projection matrix jitter — column 2 holds NDC x/y offset for TAA/FSR2 sub-pixel sampling - movement_handler: name kMaxTaxiNodeId (384) with why-comment — WotLK TaxiNodes.dbc has 384 entries, bitmask is 12 × uint32
This commit is contained in:
parent
548828f2ee
commit
7b4fdaa277
3 changed files with 22 additions and 11 deletions
|
|
@ -122,8 +122,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::unordered_map<uint32_t, TaxiNode>& getTaxiNodes() const { return taxiNodes_; }
|
const std::unordered_map<uint32_t, TaxiNode>& getTaxiNodes() const { return taxiNodes_; }
|
||||||
|
// WotLK 3.3.5a TaxiNodes.dbc has 384 entries; the known-taxi bitmask
|
||||||
|
// is 12 × uint32 = 384 bits. Node IDs outside this range are invalid.
|
||||||
|
static constexpr uint32_t kMaxTaxiNodeId = 384;
|
||||||
bool isKnownTaxiNode(uint32_t nodeId) const {
|
bool isKnownTaxiNode(uint32_t nodeId) const {
|
||||||
if (nodeId == 0 || nodeId > 384) return false;
|
if (nodeId == 0 || nodeId > kMaxTaxiNodeId) return false;
|
||||||
uint32_t idx = nodeId - 1;
|
uint32_t idx = nodeId - 1;
|
||||||
return (knownTaxiMask_[idx / 32] & (1u << (idx % 32))) != 0;
|
return (knownTaxiMask_[idx / 32] & (1u << (idx % 32))) != 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,10 @@ size_t readMemAvailableBytesFromProc() {
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(meminfo, line)) {
|
while (std::getline(meminfo, line)) {
|
||||||
// Format: "MemAvailable: 123456789 kB"
|
// /proc/meminfo format: "MemAvailable: 123456789 kB"
|
||||||
|
static constexpr size_t kFieldPrefixLen = 13; // strlen("MemAvailable:")
|
||||||
if (line.rfind("MemAvailable:", 0) != 0) continue;
|
if (line.rfind("MemAvailable:", 0) != 0) continue;
|
||||||
std::istringstream iss(line.substr(13));
|
std::istringstream iss(line.substr(kFieldPrefixLen));
|
||||||
size_t kb = 0;
|
size_t kb = 0;
|
||||||
iss >> kb;
|
iss >> kb;
|
||||||
if (kb > 0) return kb * 1024ull;
|
if (kb > 0) return kb * 1024ull;
|
||||||
|
|
@ -42,13 +43,18 @@ MemoryMonitor& MemoryMonitor::getInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryMonitor::initialize() {
|
void MemoryMonitor::initialize() {
|
||||||
|
constexpr size_t kOneGB = 1024ull * 1024 * 1024;
|
||||||
|
// Fallback if OS API unavailable — 16 GB is a safe conservative estimate
|
||||||
|
// that prevents over-aggressive asset caching on unknown hardware.
|
||||||
|
constexpr size_t kFallbackRAM = 16 * kOneGB;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ULONGLONG totalKB = 0;
|
ULONGLONG totalKB = 0;
|
||||||
if (GetPhysicallyInstalledSystemMemory(&totalKB)) {
|
if (GetPhysicallyInstalledSystemMemory(&totalKB)) {
|
||||||
totalRAM_ = static_cast<size_t>(totalKB) * 1024ull;
|
totalRAM_ = static_cast<size_t>(totalKB) * 1024ull;
|
||||||
LOG_INFO("System RAM detected: ", totalRAM_ / (1024 * 1024 * 1024), " GB");
|
LOG_INFO("System RAM detected: ", totalRAM_ / kOneGB, " GB");
|
||||||
} else {
|
} else {
|
||||||
totalRAM_ = 16ull * 1024 * 1024 * 1024;
|
totalRAM_ = kFallbackRAM;
|
||||||
LOG_WARNING("Could not detect system RAM, assuming 16GB");
|
LOG_WARNING("Could not detect system RAM, assuming 16GB");
|
||||||
}
|
}
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
|
|
@ -56,19 +62,18 @@ void MemoryMonitor::initialize() {
|
||||||
size_t len = sizeof(physmem);
|
size_t len = sizeof(physmem);
|
||||||
if (sysctlbyname("hw.memsize", &physmem, &len, nullptr, 0) == 0) {
|
if (sysctlbyname("hw.memsize", &physmem, &len, nullptr, 0) == 0) {
|
||||||
totalRAM_ = static_cast<size_t>(physmem);
|
totalRAM_ = static_cast<size_t>(physmem);
|
||||||
LOG_INFO("System RAM detected: ", totalRAM_ / (1024 * 1024 * 1024), " GB");
|
LOG_INFO("System RAM detected: ", totalRAM_ / kOneGB, " GB");
|
||||||
} else {
|
} else {
|
||||||
totalRAM_ = 16ull * 1024 * 1024 * 1024;
|
totalRAM_ = kFallbackRAM;
|
||||||
LOG_WARNING("Could not detect system RAM, assuming 16GB");
|
LOG_WARNING("Could not detect system RAM, assuming 16GB");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
if (sysinfo(&info) == 0) {
|
if (sysinfo(&info) == 0) {
|
||||||
totalRAM_ = static_cast<size_t>(info.totalram) * info.mem_unit;
|
totalRAM_ = static_cast<size_t>(info.totalram) * info.mem_unit;
|
||||||
LOG_INFO("System RAM detected: ", totalRAM_ / (1024 * 1024 * 1024), " GB");
|
LOG_INFO("System RAM detected: ", totalRAM_ / kOneGB, " GB");
|
||||||
} else {
|
} else {
|
||||||
// Fallback: assume 16GB
|
totalRAM_ = kFallbackRAM;
|
||||||
totalRAM_ = 16ull * 1024 * 1024 * 1024;
|
|
||||||
LOG_WARNING("Could not detect system RAM, assuming 16GB");
|
LOG_WARNING("Could not detect system RAM, assuming 16GB");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,10 @@ glm::vec3 Camera::getUp() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::setJitter(float jx, float jy) {
|
void Camera::setJitter(float jx, float jy) {
|
||||||
// Remove old jitter, apply new
|
// Sub-pixel jitter for temporal anti-aliasing (TAA / FSR2).
|
||||||
|
// Column 2 of the projection matrix holds the NDC x/y offset — modifying
|
||||||
|
// [2][0] and [2][1] shifts the entire rendered image by a sub-pixel amount
|
||||||
|
// each frame, giving the upscaler different sample positions to reconstruct.
|
||||||
projectionMatrix[2][0] -= jitterOffset.x;
|
projectionMatrix[2][0] -= jitterOffset.x;
|
||||||
projectionMatrix[2][1] -= jitterOffset.y;
|
projectionMatrix[2][1] -= jitterOffset.y;
|
||||||
jitterOffset = glm::vec2(jx, jy);
|
jitterOffset = glm::vec2(jx, jy);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue