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:
Kelsi 2026-03-30 15:07:55 -07:00
parent 548828f2ee
commit 7b4fdaa277
3 changed files with 22 additions and 11 deletions

View file

@ -122,8 +122,11 @@ public:
};
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 {
if (nodeId == 0 || nodeId > 384) return false;
if (nodeId == 0 || nodeId > kMaxTaxiNodeId) return false;
uint32_t idx = nodeId - 1;
return (knownTaxiMask_[idx / 32] & (1u << (idx % 32))) != 0;
}

View file

@ -23,9 +23,10 @@ size_t readMemAvailableBytesFromProc() {
std::string 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;
std::istringstream iss(line.substr(13));
std::istringstream iss(line.substr(kFieldPrefixLen));
size_t kb = 0;
iss >> kb;
if (kb > 0) return kb * 1024ull;
@ -42,13 +43,18 @@ MemoryMonitor& MemoryMonitor::getInstance() {
}
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
ULONGLONG totalKB = 0;
if (GetPhysicallyInstalledSystemMemory(&totalKB)) {
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 {
totalRAM_ = 16ull * 1024 * 1024 * 1024;
totalRAM_ = kFallbackRAM;
LOG_WARNING("Could not detect system RAM, assuming 16GB");
}
#elif defined(__APPLE__)
@ -56,19 +62,18 @@ void MemoryMonitor::initialize() {
size_t len = sizeof(physmem);
if (sysctlbyname("hw.memsize", &physmem, &len, nullptr, 0) == 0) {
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 {
totalRAM_ = 16ull * 1024 * 1024 * 1024;
totalRAM_ = kFallbackRAM;
LOG_WARNING("Could not detect system RAM, assuming 16GB");
}
#else
struct sysinfo info;
if (sysinfo(&info) == 0) {
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 {
// Fallback: assume 16GB
totalRAM_ = 16ull * 1024 * 1024 * 1024;
totalRAM_ = kFallbackRAM;
LOG_WARNING("Could not detect system RAM, assuming 16GB");
}
#endif

View file

@ -48,7 +48,10 @@ glm::vec3 Camera::getUp() const {
}
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][1] -= jitterOffset.y;
jitterOffset = glm::vec2(jx, jy);