Skip to content

Commit a7178c7

Browse files
committed
Address all outstanding comments from PR#119
Refactor code structure: move Initialize methods to private, improve Vulkan object initialization, enhance material caching, and clean up resource handling - Move AudioSystem and ModelLoader Initialize methods to private (called by constructors) - Replace manual static member initialization with inline static initialization (C++17) - Simplify Vulkan struct initialization by removing redundant `.sType` fields - Use `vk::StructureChain` for device feature configuration - Replace C-style arrays with `std::array` for queue family indices - Optimize swapchain image view creation by reusing template - Enhance fence wait error handling with result checking - Improve material caching by using existing iterators to avoid redundant lookups - Refactor ModelLoader: extract helper methods for materials, cameras, animations, and meshes - Add assertions for null camera checks in uniform buffer updates - Change GetMaterial return type to `const Material*` for immutability - Fix documentation comments and AsciiDoc formatting issues - Optimize descriptor set binding by removing unnecessary vector allocation - Refine swapchain recreation to only trigger on `eSuboptimalKHR`, not `eErrorOutOfDateKHR` - Improve semaphore management with clearer comments on indexing strategy
1 parent e3749dc commit a7178c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+10635
-11463
lines changed

attachments/simple_engine/audio_system.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <chrono>
2222
#include <cmath>
2323
#include <cstring>
24+
#include <numbers>
2425
#include <fstream>
2526
#include <iomanip>
2627
#include <iostream>
@@ -795,7 +796,7 @@ void AudioSystem::GenerateSineWavePing(float* buffer, uint32_t sampleCount, uint
795796
envelope = static_cast<float>(relPos) / static_cast<float>(std::max(1u, releaseSamples));
796797
}
797798

798-
float sineWave = sinf(2.0f * static_cast<float>(M_PI) * frequency * t);
799+
float sineWave = sinf(2.0f * std::numbers::pi_v<float> * frequency * t);
799800
buffer[i] = amplitude * envelope * sineWave;
800801
} else {
801802
// Silence phase
@@ -1160,8 +1161,7 @@ bool AudioSystem::IsHRTFEnabled() const {
11601161
return hrtfEnabled;
11611162
}
11621163

1163-
void AudioSystem::SetHRTFCPUOnly(const bool cpuOnly) {
1164-
(void) cpuOnly;
1164+
void AudioSystem::SetHRTFCPUOnly([[maybe_unused]] const bool cpuOnly) {
11651165
// Enforce GPU-only HRTF processing: ignore CPU-only requests
11661166
hrtfCPUOnly = false;
11671167
}
@@ -1218,8 +1218,8 @@ bool AudioSystem::LoadHRTFData(const std::string& filename) {
12181218
uint32_t azimuthIndex = pos % 36;
12191219
uint32_t elevationIndex = pos / 36;
12201220

1221-
float azimuth = (static_cast<float>(azimuthIndex) * 10.0f - 180.0f) * static_cast<float>(M_PI) / 180.0f;
1222-
float elevation = (static_cast<float>(elevationIndex) * 15.0f - 90.0f) * static_cast<float>(M_PI) / 180.0f;
1221+
float azimuth = (static_cast<float>(azimuthIndex) * 10.0f - 180.0f) * std::numbers::pi_v<float> / 180.0f;
1222+
float elevation = (static_cast<float>(elevationIndex) * 15.0f - 90.0f) * std::numbers::pi_v<float> / 180.0f;
12231223

12241224
// Convert to Cartesian coordinates
12251225
float x = std::cos(elevation) * std::sin(azimuth);
@@ -1258,7 +1258,7 @@ bool AudioSystem::LoadHRTFData(const std::string& filename) {
12581258
// Direct path impulse
12591259
if (i >= sampleDelay && i < sampleDelay + 10) {
12601260
float t = static_cast<float>(i - sampleDelay) / sampleRate;
1261-
value = shadowFactor * std::exp(-t * 1000.0f) * std::cos(2.0f * static_cast<float>(M_PI) * 1000.0f * t);
1261+
value = shadowFactor * std::exp(-t * 1000.0f) * std::cos(2.0f * std::numbers::pi_v<float> * 1000.0f * t);
12621262
}
12631263

12641264
// Apply distance attenuation
@@ -1349,8 +1349,8 @@ bool AudioSystem::ProcessHRTF(const float* inputBuffer, float* outputBuffer, uin
13491349
float elevation = std::asin(std::max(-1.0f, std::min(1.0f, direction[1])));
13501350

13511351
// Convert to indices
1352-
int azimuthIndex = static_cast<int>((azimuth + M_PI) / (2.0f * M_PI) * 36.0f) % 36;
1353-
int elevationIndex = static_cast<int>((elevation + M_PI / 2.0f) / M_PI * 13.0f);
1352+
int azimuthIndex = static_cast<int>((azimuth + std::numbers::pi_v<float>) / (2.0f * std::numbers::pi_v<float>) * 36.0f) % 36;
1353+
int elevationIndex = static_cast<int>((elevation + std::numbers::pi_v<float> / 2.0f) / std::numbers::pi_v<float> * 13.0f);
13541354
elevationIndex = std::max(0, std::min(12, elevationIndex));
13551355

13561356
// Get HRTF index

0 commit comments

Comments
 (0)