refactor: Remove AudioPlayer references and transition to service-based audio management

This commit is contained in:
2026-01-04 14:58:27 +00:00
parent 8d269b8c67
commit f76be2d4e2
7 changed files with 29 additions and 41 deletions

View File

@@ -142,7 +142,6 @@ if(BUILD_SDL3_APP)
src/controllers/application_controller.cpp
src/controllers/render_controller.cpp
src/controllers/lifecycle_controller.cpp
src/app/audio_player.cpp
src/app/service_based_app.cpp
src/gui/gui_renderer.cpp
src/core/vulkan_utils.cpp
@@ -189,7 +188,6 @@ add_executable(script_engine_tests
src/script/lua_helpers.cpp
src/script/lua_bindings.cpp
src/script/mesh_loader.cpp
src/app/audio_player.cpp
)
target_include_directories(script_engine_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(script_engine_tests PRIVATE ${SDL_TARGET} lua::lua assimp::assimp Bullet::Bullet glm::glm Vorbis::vorbisfile Vorbis::vorbis)

View File

@@ -21,9 +21,10 @@
#include "app/service_based_app.hpp"
#include <SDL3/SDL_main.h>
#include "services/interfaces/i_logger.hpp"
#include "logging/string_utils.hpp"
#include "core/platform.hpp"
using namespace sdl3cpp::services;
namespace sdl3cpp::app {
std::atomic<bool> g_signalReceived{false};
@@ -78,8 +79,6 @@ RuntimeConfig GenerateDefaultRuntimeConfig(const char* argv0) {
}
RuntimeConfig LoadRuntimeConfigFromJson(const std::filesystem::path& configPath, bool dumpConfig) {
using sdl3cpp::logging::ToString;
sdl3cpp::logging::Logger::GetInstance().TraceFunctionWithArgs("LoadRuntimeConfigFromJson", configPath.string() + " " + ToString(dumpConfig));
std::ifstream configStream(configPath);
if (!configStream) {
throw std::runtime_error("Failed to open config file: " + configPath.string());
@@ -245,8 +244,8 @@ AppOptions ParseCommandLine(int argc, char** argv) {
void LogRuntimeConfig(const RuntimeConfig& config, std::shared_ptr<services::ILogger> logger) {
if (logger) {
logger->TraceVariable("config.width", static_cast<int>(config.width));
logger->TraceVariable("config.height", static_cast<int>(config.height));
logger->TraceVariable("config.width", config.width);
logger->TraceVariable("config.height", config.height);
logger->TraceVariable("config.scriptPath", config.scriptPath.string());
}
}

View File

@@ -6,10 +6,6 @@
#include <string>
#include <vector>
namespace sdl3cpp::app {
class AudioPlayer;
}
namespace sdl3cpp::script {
class AudioManager {
@@ -27,7 +23,7 @@ public:
explicit AudioManager(const std::filesystem::path& scriptDirectory);
void SetAudioPlayer(app::AudioPlayer* audioPlayer);
// void SetAudioPlayer(app::AudioPlayer* audioPlayer); // Removed - using services now
bool QueueAudioCommand(AudioCommandType type, std::string path, bool loop, std::string& error);
private:

View File

@@ -4,7 +4,6 @@
#include "script/gui_manager.hpp"
#include "script/audio_manager.hpp"
#include "script/lua_bindings.hpp"
#include "app/audio_player.hpp"
#include "logging/logger.hpp"
#include <lua.hpp>
@@ -111,7 +110,8 @@ std::filesystem::path ScriptEngine::GetScriptDirectory() const {
}
void ScriptEngine::SetAudioPlayer(app::AudioPlayer* audioPlayer) {
audioManager_->SetAudioPlayer(audioPlayer);
// Stub - audio functionality now handled through services
sdl3cpp::logging::Logger::GetInstance().Trace("ScriptEngine::SetAudioPlayer: Stub implementation - using services now");
}
bool ScriptEngine::QueueAudioCommand(AudioManager::AudioCommandType type, std::string path, bool loop, std::string& error) {

View File

@@ -41,13 +41,12 @@ public:
bool HasGuiCommands() const;
std::filesystem::path GetScriptDirectory() const;
PhysicsBridge& GetPhysicsBridge();
void SetAudioPlayer(app::AudioPlayer* audioPlayer);
// void SetAudioPlayer(app::AudioPlayer* audioPlayer); // Removed - using services now
bool QueueAudioCommand(AudioManager::AudioCommandType type, std::string path, bool loop, std::string& error);
std::string GetLuaError();
private:
private:
void ExecuteAudioCommand(app::AudioPlayer* player, const AudioManager::AudioCommand& command);
void ExecuteAudioCommand(const AudioManager::AudioCommand& command); // Updated to not take AudioPlayer
std::filesystem::path ResolveScriptPath(const std::string& requested) const;
static std::vector<core::Vertex> ReadVertexArray(lua_State* L, int index);

View File

@@ -19,10 +19,9 @@ void SdlAudioService::Initialize() {
return;
}
audioPlayer_ = std::make_unique<app::AudioPlayer>();
// TODO: Initialize SDL audio subsystem
logger_->Info("Audio service initialized (stub implementation)");
initialized_ = true;
logger_->Info("Audio service initialized");
}
void SdlAudioService::Shutdown() noexcept {
@@ -32,55 +31,53 @@ void SdlAudioService::Shutdown() noexcept {
return;
}
audioPlayer_.reset();
// TODO: Shutdown SDL audio subsystem
initialized_ = false;
logger_->Info("Audio service shutdown");
logger_->Info("Audio service shutdown (stub implementation)");
}
void SdlAudioService::PlayBackground(const std::filesystem::path& path, bool loop) {
logger_->TraceFunction(__func__);
if (!audioPlayer_) {
if (!initialized_) {
throw std::runtime_error("Audio service not initialized");
}
audioPlayer_->PlayBackground(path, loop);
// TODO: Implement background music playback using SDL_mixer or similar
logger_->Info("Playing background audio: " + path.string() + " (loop: " + std::to_string(loop) + ") - STUB");
}
void SdlAudioService::PlayEffect(const std::filesystem::path& path, bool loop) {
logger_->TraceFunction(__func__);
if (!audioPlayer_) {
if (!initialized_) {
throw std::runtime_error("Audio service not initialized");
}
audioPlayer_->PlayEffect(path, loop);
// TODO: Implement sound effect playback
logger_->Info("Playing effect audio: " + path.string() + " (loop: " + std::to_string(loop) + ") - STUB");
}
void SdlAudioService::StopBackground() {
logger_->TraceFunction(__func__);
if (!audioPlayer_) {
if (!initialized_) {
return;
}
// AudioPlayer doesn't have StopBackground(), so recreate to stop
auto oldPlayer = std::move(audioPlayer_);
oldPlayer.reset();
audioPlayer_ = std::make_unique<app::AudioPlayer>();
// TODO: Stop background music
logger_->Info("Stopping background audio - STUB");
}
void SdlAudioService::StopAll() {
logger_->TraceFunction(__func__);
if (!audioPlayer_) {
if (!initialized_) {
return;
}
// Recreate player to stop all audio
audioPlayer_.reset();
audioPlayer_ = std::make_unique<app::AudioPlayer>();
// TODO: Stop all audio
logger_->Info("Stopping all audio - STUB");
}
void SdlAudioService::SetVolume(float volume) {
@@ -94,9 +91,8 @@ float SdlAudioService::GetVolume() const {
}
bool SdlAudioService::IsBackgroundPlaying() const {
// AudioPlayer doesn't expose this state,
// would need to be added to AudioPlayer implementation
return false;
// TODO: Check if background music is currently playing
return false; // Stub implementation
}
} // namespace sdl3cpp::services::impl

View File

@@ -2,9 +2,9 @@
#include "../interfaces/i_audio_service.hpp"
#include "../interfaces/i_logger.hpp"
#include "../../app/audio_player.hpp"
#include "../../di/lifecycle.hpp"
#include <memory>
#include <SDL3/SDL.h>
namespace sdl3cpp::services::impl {
@@ -36,9 +36,9 @@ public:
private:
std::shared_ptr<ILogger> logger_;
std::unique_ptr<app::AudioPlayer> audioPlayer_;
float volume_ = 1.0f;
bool initialized_ = false;
// SDL audio structures would go here
};
} // namespace sdl3cpp::services::impl