From 147d373a5d42beff8b51925737dbda382a798183 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Mon, 5 Jan 2026 00:51:42 +0000 Subject: [PATCH] Enhance logging across various services - Added detailed logging to the ScriptEngineService to trace initialization status. - Improved logging in SdlAudioService to track audio operations including initialization, shutdown, and playback functions. - Enhanced SdlInputService with logging for key and mouse events, as well as state retrieval. - Updated SdlWindowService to log window creation, destruction, and event polling. - Added logging to ShaderScriptService for shader path loading and Lua state retrieval. - Implemented logging in SwapchainService for swapchain operations, including creation, cleanup, and querying support details. - Enhanced VulkanDeviceService with logging for device creation, shutdown, and memory type queries. - Improved VulkanGuiService with logging for GUI initialization, frame preparation, and rendering operations. --- src/app/service_based_app.cpp | 3 +- .../impl/application_loop_service.cpp | 12 ++- src/services/impl/audio_command_service.cpp | 11 +++ src/services/impl/buffer_service.cpp | 28 +++++-- src/services/impl/buffer_service.hpp | 20 ++++- src/services/impl/bullet_physics_service.cpp | 65 +++++++++++++--- src/services/impl/bullet_physics_service.hpp | 5 +- src/services/impl/command_line_service.cpp | 22 +++++- src/services/impl/crash_recovery_service.cpp | 31 +++++++- src/services/impl/graphics_service.cpp | 56 +++++++++----- src/services/impl/gui_renderer_service.cpp | 29 +++++-- src/services/impl/gui_script_service.cpp | 31 +++++++- src/services/impl/json_config_service.cpp | 27 ++++++- src/services/impl/json_config_service.hpp | 42 ++++++++-- .../impl/json_config_writer_service.cpp | 9 ++- src/services/impl/lifecycle_service.cpp | 2 +- src/services/impl/mesh_service.cpp | 21 ++++- src/services/impl/mesh_service.hpp | 5 +- src/services/impl/physics_bridge_service.cpp | 13 +++- src/services/impl/pipeline_service.cpp | 44 ++++++++--- src/services/impl/pipeline_service.hpp | 10 ++- src/services/impl/platform_service.cpp | 7 ++ src/services/impl/render_command_service.cpp | 36 ++++++--- src/services/impl/render_command_service.hpp | 10 ++- .../impl/render_coordinator_service.cpp | 8 +- src/services/impl/scene_script_service.cpp | 11 ++- src/services/impl/scene_service.cpp | 20 +++-- src/services/impl/script_engine_service.cpp | 55 ++++++++++---- src/services/impl/script_engine_service.hpp | 7 +- src/services/impl/sdl_audio_service.cpp | 52 +++++++++++-- src/services/impl/sdl_input_service.cpp | 76 +++++++++++++++++++ src/services/impl/sdl_input_service.hpp | 7 +- src/services/impl/sdl_window_service.cpp | 28 ++++++- src/services/impl/sdl_window_service.hpp | 10 ++- src/services/impl/shader_script_service.cpp | 11 +++ src/services/impl/swapchain_service.cpp | 55 +++++++++++--- src/services/impl/swapchain_service.hpp | 35 +++++++-- src/services/impl/vulkan_device_service.cpp | 35 +++++++-- src/services/impl/vulkan_device_service.hpp | 30 ++++++-- src/services/impl/vulkan_gui_service.cpp | 29 +++++-- 40 files changed, 842 insertions(+), 166 deletions(-) diff --git a/src/app/service_based_app.cpp b/src/app/service_based_app.cpp index 679448a..31818b3 100644 --- a/src/app/service_based_app.cpp +++ b/src/app/service_based_app.cpp @@ -229,7 +229,8 @@ void ServiceBasedApp::RegisterServices() { // Script bridge services registry_.RegisterService( - registry_.GetService()); + registry_.GetService(), + registry_.GetService()); registry_.RegisterService( registry_.GetService()); registry_.RegisterService( diff --git a/src/services/impl/application_loop_service.cpp b/src/services/impl/application_loop_service.cpp index 933a961..95759ec 100644 --- a/src/services/impl/application_loop_service.cpp +++ b/src/services/impl/application_loop_service.cpp @@ -19,7 +19,14 @@ ApplicationLoopService::ApplicationLoopService(std::shared_ptr logger, sceneService_(std::move(sceneService)), audioService_(std::move(audioService)) { if (logger_) { - logger_->Trace("ApplicationLoopService", "ApplicationLoopService", "", "Created"); + logger_->Trace("ApplicationLoopService", "ApplicationLoopService", + "windowService=" + std::string(windowService_ ? "set" : "null") + + ", eventBus=" + std::string(eventBus_ ? "set" : "null") + + ", inputService=" + std::string(inputService_ ? "set" : "null") + + ", physicsService=" + std::string(physicsService_ ? "set" : "null") + + ", sceneService=" + std::string(sceneService_ ? "set" : "null") + + ", audioService=" + std::string(audioService_ ? "set" : "null"), + "Created"); } } @@ -59,6 +66,9 @@ void ApplicationLoopService::Run() { } void ApplicationLoopService::HandleEvents() { + if (logger_) { + logger_->Trace("ApplicationLoopService", "HandleEvents"); + } if (windowService_) { windowService_->PollEvents(); } diff --git a/src/services/impl/audio_command_service.cpp b/src/services/impl/audio_command_service.cpp index b47e309..9a2b330 100644 --- a/src/services/impl/audio_command_service.cpp +++ b/src/services/impl/audio_command_service.cpp @@ -11,12 +11,23 @@ AudioCommandService::AudioCommandService(std::shared_ptr configS : configService_(std::move(configService)), audioService_(std::move(audioService)), logger_(std::move(logger)) { + if (logger_) { + logger_->Trace("AudioCommandService", "AudioCommandService", + "configService=" + std::string(configService_ ? "set" : "null") + + ", audioService=" + std::string(audioService_ ? "set" : "null")); + } } bool AudioCommandService::QueueAudioCommand(AudioCommandType type, const std::string& path, bool loop, std::string& error) { + if (logger_) { + logger_->Trace("AudioCommandService", "QueueAudioCommand", + "type=" + std::to_string(static_cast(type)) + + ", path=" + path + + ", loop=" + std::string(loop ? "true" : "false")); + } if (!audioService_) { error = "Audio service not available"; return false; diff --git a/src/services/impl/buffer_service.cpp b/src/services/impl/buffer_service.cpp index 0bb1d68..5163974 100644 --- a/src/services/impl/buffer_service.cpp +++ b/src/services/impl/buffer_service.cpp @@ -6,16 +6,25 @@ namespace sdl3cpp::services::impl { BufferService::BufferService(std::shared_ptr deviceService, std::shared_ptr logger) - : deviceService_(std::move(deviceService)), logger_(logger) {} + : deviceService_(std::move(deviceService)), logger_(logger) { + if (logger_) { + logger_->Trace("BufferService", "BufferService", + "deviceService=" + std::string(deviceService_ ? "set" : "null")); + } +} BufferService::~BufferService() { + if (logger_) { + logger_->Trace("BufferService", "~BufferService"); + } if (vertexBuffer_ != VK_NULL_HANDLE || indexBuffer_ != VK_NULL_HANDLE) { Shutdown(); } } void BufferService::UploadVertexData(const std::vector& vertices) { - logger_->TraceFunction(__func__); + logger_->Trace("BufferService", "UploadVertexData", + "vertices.size=" + std::to_string(vertices.size())); if (vertices.empty()) { throw std::runtime_error("Cannot upload vertex data: empty vertex array"); @@ -48,7 +57,8 @@ void BufferService::UploadVertexData(const std::vector& vertices) } void BufferService::UploadIndexData(const std::vector& indices) { - logger_->TraceFunction(__func__); + logger_->Trace("BufferService", "UploadIndexData", + "indices.size=" + std::to_string(indices.size())); if (indices.empty()) { throw std::runtime_error("Cannot upload index data: empty index array"); @@ -81,18 +91,24 @@ void BufferService::UploadIndexData(const std::vector& indices) { } void BufferService::Cleanup() { + logger_->Trace("BufferService", "Cleanup"); CleanupBuffers(); } void BufferService::Shutdown() noexcept { - logger_->TraceFunction(__func__); + logger_->Trace("BufferService", "Shutdown"); CleanupBuffers(); } void BufferService::CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory) { - logger_->TraceFunction(__func__); + logger_->Trace("BufferService", "CreateBuffer", + "size=" + std::to_string(size) + + ", usage=" + std::to_string(static_cast(usage)) + + ", properties=" + std::to_string(static_cast(properties)) + + ", bufferIsNull=" + std::string(buffer == VK_NULL_HANDLE ? "true" : "false") + + ", bufferMemoryIsNull=" + std::string(bufferMemory == VK_NULL_HANDLE ? "true" : "false")); auto device = deviceService_->GetDevice(); auto physicalDevice = deviceService_->GetPhysicalDevice(); @@ -188,7 +204,7 @@ void BufferService::CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, } void BufferService::CleanupBuffers() { - logger_->TraceFunction(__func__); + logger_->Trace("BufferService", "CleanupBuffers"); auto device = deviceService_->GetDevice(); diff --git a/src/services/impl/buffer_service.hpp b/src/services/impl/buffer_service.hpp index fc8ad86..f487f11 100644 --- a/src/services/impl/buffer_service.hpp +++ b/src/services/impl/buffer_service.hpp @@ -25,10 +25,22 @@ public: void UploadIndexData(const std::vector& indices) override; void Cleanup() override; - VkBuffer GetVertexBuffer() const override { return vertexBuffer_; } - VkBuffer GetIndexBuffer() const override { return indexBuffer_; } - size_t GetVertexCount() const override { return vertexCount_; } - size_t GetIndexCount() const override { return indexCount_; } + VkBuffer GetVertexBuffer() const override { + logger_->Trace("BufferService", "GetVertexBuffer"); + return vertexBuffer_; + } + VkBuffer GetIndexBuffer() const override { + logger_->Trace("BufferService", "GetIndexBuffer"); + return indexBuffer_; + } + size_t GetVertexCount() const override { + logger_->Trace("BufferService", "GetVertexCount"); + return vertexCount_; + } + size_t GetIndexCount() const override { + logger_->Trace("BufferService", "GetIndexCount"); + return indexCount_; + } // Public buffer creation utility void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, diff --git a/src/services/impl/bullet_physics_service.cpp b/src/services/impl/bullet_physics_service.cpp index e5e237a..1fe651e 100644 --- a/src/services/impl/bullet_physics_service.cpp +++ b/src/services/impl/bullet_physics_service.cpp @@ -6,16 +6,25 @@ namespace sdl3cpp::services::impl { BulletPhysicsService::BulletPhysicsService(std::shared_ptr logger) : logger_(std::move(logger)) { + if (logger_) { + logger_->Trace("BulletPhysicsService", "BulletPhysicsService"); + } } BulletPhysicsService::~BulletPhysicsService() { + if (logger_) { + logger_->Trace("BulletPhysicsService", "~BulletPhysicsService"); + } if (initialized_) { Shutdown(); } } void BulletPhysicsService::Initialize(const btVector3& gravity) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "Initialize", + "gravity.x=" + std::to_string(gravity.getX()) + + ", gravity.y=" + std::to_string(gravity.getY()) + + ", gravity.z=" + std::to_string(gravity.getZ())); if (initialized_) { return; @@ -28,7 +37,7 @@ void BulletPhysicsService::Initialize(const btVector3& gravity) { } void BulletPhysicsService::Shutdown() noexcept { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "Shutdown"); if (!initialized_) { return; @@ -44,7 +53,15 @@ bool BulletPhysicsService::AddBoxRigidBody(const std::string& name, const btVector3& halfExtents, float mass, const btTransform& transform) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "AddBoxRigidBody", + "name=" + name + + ", halfExtents.x=" + std::to_string(halfExtents.getX()) + + ", halfExtents.y=" + std::to_string(halfExtents.getY()) + + ", halfExtents.z=" + std::to_string(halfExtents.getZ()) + + ", mass=" + std::to_string(mass) + + ", origin.x=" + std::to_string(transform.getOrigin().getX()) + + ", origin.y=" + std::to_string(transform.getOrigin().getY()) + + ", origin.z=" + std::to_string(transform.getOrigin().getZ())); if (!physicsBridge_) { throw std::runtime_error("Physics service not initialized"); @@ -62,7 +79,13 @@ bool BulletPhysicsService::AddSphereRigidBody(const std::string& name, float radius, float mass, const btTransform& transform) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "AddSphereRigidBody", + "name=" + name + + ", radius=" + std::to_string(radius) + + ", mass=" + std::to_string(mass) + + ", origin.x=" + std::to_string(transform.getOrigin().getX()) + + ", origin.y=" + std::to_string(transform.getOrigin().getY()) + + ", origin.z=" + std::to_string(transform.getOrigin().getZ())); // PhysicsBridgeService doesn't support sphere rigid bodies in current implementation logger_->Warn("AddSphereRigidBody not supported by PhysicsBridgeService"); @@ -70,7 +93,7 @@ bool BulletPhysicsService::AddSphereRigidBody(const std::string& name, } bool BulletPhysicsService::RemoveRigidBody(const std::string& name) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "RemoveRigidBody", "name=" + name); // PhysicsBridgeService doesn't support removing bodies in current implementation logger_->Warn("RemoveRigidBody not supported by PhysicsBridgeService"); @@ -78,7 +101,9 @@ bool BulletPhysicsService::RemoveRigidBody(const std::string& name) { } void BulletPhysicsService::StepSimulation(float deltaTime, int maxSubSteps) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "StepSimulation", + "deltaTime=" + std::to_string(deltaTime) + + ", maxSubSteps=" + std::to_string(maxSubSteps)); if (!physicsBridge_) { throw std::runtime_error("Physics service not initialized"); @@ -88,6 +113,7 @@ void BulletPhysicsService::StepSimulation(float deltaTime, int maxSubSteps) { } bool BulletPhysicsService::GetTransform(const std::string& name, btTransform& outTransform) const { + logger_->Trace("BulletPhysicsService", "GetTransform", "name=" + name); if (!physicsBridge_) { return false; } @@ -103,7 +129,11 @@ bool BulletPhysicsService::GetTransform(const std::string& name, btTransform& ou } bool BulletPhysicsService::SetTransform(const std::string& name, const btTransform& transform) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "SetTransform", + "name=" + name + + ", origin.x=" + std::to_string(transform.getOrigin().getX()) + + ", origin.y=" + std::to_string(transform.getOrigin().getY()) + + ", origin.z=" + std::to_string(transform.getOrigin().getZ())); // PhysicsBridgeService doesn't support setting transforms in current implementation logger_->Warn("SetTransform not supported by PhysicsBridgeService"); @@ -111,7 +141,11 @@ bool BulletPhysicsService::SetTransform(const std::string& name, const btTransfo } bool BulletPhysicsService::ApplyForce(const std::string& name, const btVector3& force) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "ApplyForce", + "name=" + name + + ", force.x=" + std::to_string(force.getX()) + + ", force.y=" + std::to_string(force.getY()) + + ", force.z=" + std::to_string(force.getZ())); // PhysicsBridgeService doesn't support applying forces in current implementation logger_->Warn("ApplyForce not supported by PhysicsBridgeService"); @@ -119,7 +153,11 @@ bool BulletPhysicsService::ApplyForce(const std::string& name, const btVector3& } bool BulletPhysicsService::ApplyImpulse(const std::string& name, const btVector3& impulse) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "ApplyImpulse", + "name=" + name + + ", impulse.x=" + std::to_string(impulse.getX()) + + ", impulse.y=" + std::to_string(impulse.getY()) + + ", impulse.z=" + std::to_string(impulse.getZ())); // PhysicsBridgeService doesn't support applying impulses in current implementation logger_->Warn("ApplyImpulse not supported by PhysicsBridgeService"); @@ -127,7 +165,11 @@ bool BulletPhysicsService::ApplyImpulse(const std::string& name, const btVector3 } bool BulletPhysicsService::SetLinearVelocity(const std::string& name, const btVector3& velocity) { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "SetLinearVelocity", + "name=" + name + + ", velocity.x=" + std::to_string(velocity.getX()) + + ", velocity.y=" + std::to_string(velocity.getY()) + + ", velocity.z=" + std::to_string(velocity.getZ())); // PhysicsBridgeService doesn't support setting velocity in current implementation logger_->Warn("SetLinearVelocity not supported by PhysicsBridgeService"); @@ -135,13 +177,14 @@ bool BulletPhysicsService::SetLinearVelocity(const std::string& name, const btVe } size_t BulletPhysicsService::GetBodyCount() const { + logger_->Trace("BulletPhysicsService", "GetBodyCount"); // PhysicsBridgeService doesn't expose GetBodyCount in current implementation // Returning 0 as stub - could track bodies in wrapper if needed return 0; } void BulletPhysicsService::Clear() { - logger_->TraceFunction(__func__); + logger_->Trace("BulletPhysicsService", "Clear"); if (!physicsBridge_) { return; diff --git a/src/services/impl/bullet_physics_service.hpp b/src/services/impl/bullet_physics_service.hpp index a7e8b35..d666f64 100644 --- a/src/services/impl/bullet_physics_service.hpp +++ b/src/services/impl/bullet_physics_service.hpp @@ -22,7 +22,10 @@ public: ~BulletPhysicsService() override; // IInitializable interface - void Initialize() override { Initialize(btVector3(0, -9.8f, 0)); } + void Initialize() override { + logger_->Trace("BulletPhysicsService", "Initialize"); + Initialize(btVector3(0, -9.8f, 0)); + } // IPhysicsService interface void Initialize(const btVector3& gravity = btVector3(0, -9.8f, 0)) override; diff --git a/src/services/impl/command_line_service.cpp b/src/services/impl/command_line_service.cpp index a65539b..072d60e 100644 --- a/src/services/impl/command_line_service.cpp +++ b/src/services/impl/command_line_service.cpp @@ -17,10 +17,16 @@ CommandLineService::CommandLineService(std::shared_ptr logger, if (!logger_) { throw std::runtime_error("CommandLineService requires a logger"); } - logger_->Trace("CommandLineService", "CommandLineService", "", "Created"); + logger_->Trace("CommandLineService", "CommandLineService", + "platformService=" + std::string(platformService_ ? "set" : "null"), + "Created"); } CommandLineOptions CommandLineService::Parse(int argc, char** argv) { + std::string argv0; + if (argc > 0 && argv && argv[0]) { + argv0 = argv[0]; + } bool traceRequested = false; for (int i = 1; i < argc; ++i) { if (argv[i] && std::string(argv[i]) == "--trace") { @@ -32,7 +38,11 @@ CommandLineOptions CommandLineService::Parse(int argc, char** argv) { logger_->SetLevel(LogLevel::TRACE); } - logger_->Trace("CommandLineService", "Parse", "argc=" + std::to_string(argc), "Entering"); + logger_->Trace("CommandLineService", "Parse", + "argc=" + std::to_string(argc) + + ", argvIsNull=" + std::string(argv ? "false" : "true") + + ", argv0=" + argv0, + "Entering"); std::string jsonInputText; std::string seedOutputText; @@ -98,6 +108,7 @@ CommandLineOptions CommandLineService::Parse(int argc, char** argv) { } std::optional CommandLineService::GetDefaultConfigPath() const { + logger_->Trace("CommandLineService", "GetDefaultConfigPath"); if (!platformService_) { logger_->Warn("CommandLineService::GetDefaultConfigPath: Platform service not available"); return std::nullopt; @@ -109,13 +120,16 @@ std::optional CommandLineService::GetDefaultConfigPath() } RuntimeConfig CommandLineService::LoadConfigFromJson(const std::filesystem::path& configPath, bool dumpConfig) { - logger_->Trace("CommandLineService", "LoadConfigFromJson", "configPath=" + configPath.string()); + logger_->Trace("CommandLineService", "LoadConfigFromJson", + "configPath=" + configPath.string() + + ", dumpConfig=" + std::string(dumpConfig ? "true" : "false")); JsonConfigService configService(logger_, configPath, dumpConfig); return configService.GetConfig(); } RuntimeConfig CommandLineService::LoadDefaultConfig(const char* argv0) { - logger_->Trace("CommandLineService", "LoadDefaultConfig"); + logger_->Trace("CommandLineService", "LoadDefaultConfig", + "argv0=" + std::string(argv0 ? argv0 : "")); JsonConfigService configService(logger_, argv0); return configService.GetConfig(); } diff --git a/src/services/impl/crash_recovery_service.cpp b/src/services/impl/crash_recovery_service.cpp index 73caf50..827dd58 100644 --- a/src/services/impl/crash_recovery_service.cpp +++ b/src/services/impl/crash_recovery_service.cpp @@ -23,7 +23,9 @@ CrashRecoveryService::CrashRecoveryService(std::shared_ptr logger) , fileFormatErrors_(0) , memoryWarnings_(0) , lastHealthCheck_(std::chrono::steady_clock::now()) { - logger_->Trace("CrashRecoveryService", "CrashRecoveryService", "", "Created"); + logger_->Trace("CrashRecoveryService", "CrashRecoveryService", + "logger=" + std::string(logger_ ? "set" : "null"), + "Created"); } CrashRecoveryService::~CrashRecoveryService() { @@ -75,6 +77,7 @@ bool CrashRecoveryService::ExecuteWithTimeout(std::function func, int ti } bool CrashRecoveryService::IsCrashDetected() const { + logger_->Trace("CrashRecoveryService", "IsCrashDetected"); return crashDetected_.load(); } @@ -102,17 +105,23 @@ bool CrashRecoveryService::AttemptRecovery() { } std::string CrashRecoveryService::GetCrashReport() const { + logger_->Trace("CrashRecoveryService", "GetCrashReport"); std::lock_guard lock(crashMutex_); return crashReport_; } void CrashRecoveryService::SignalHandler(int signal) { if (instance_) { + if (instance_->logger_) { + instance_->logger_->Trace("CrashRecoveryService", "SignalHandler", + "signal=" + std::to_string(signal)); + } instance_->HandleCrash(signal); } } void CrashRecoveryService::SetupSignalHandlers() { + logger_->Trace("CrashRecoveryService", "SetupSignalHandlers"); if (signalHandlersInstalled_) { return; } @@ -143,6 +152,7 @@ void CrashRecoveryService::SetupSignalHandlers() { } void CrashRecoveryService::RemoveSignalHandlers() { + logger_->Trace("CrashRecoveryService", "RemoveSignalHandlers"); if (!signalHandlersInstalled_) { return; } @@ -160,6 +170,8 @@ void CrashRecoveryService::RemoveSignalHandlers() { } void CrashRecoveryService::HandleCrash(int signal) { + logger_->Trace("CrashRecoveryService", "HandleCrash", + "signal=" + std::to_string(signal)); std::lock_guard lock(crashMutex_); crashDetected_ = true; @@ -193,6 +205,7 @@ void CrashRecoveryService::HandleCrash(int signal) { } bool CrashRecoveryService::PerformRecovery() { + logger_->Trace("CrashRecoveryService", "PerformRecovery"); // Basic recovery logic - in a real implementation this would be more sophisticated logger_->Info("CrashRecoveryService::PerformRecovery: Performing basic recovery"); @@ -208,6 +221,9 @@ bool CrashRecoveryService::PerformRecovery() { } bool CrashRecoveryService::CheckGpuHealth(double lastFrameTime, double expectedFrameTime) { + logger_->Trace("CrashRecoveryService", "CheckGpuHealth", + "lastFrameTime=" + std::to_string(lastFrameTime) + + ", expectedFrameTime=" + std::to_string(expectedFrameTime)); UpdateHealthMetrics(); // Check for GPU hangs - if we haven't had a successful frame in too long @@ -234,6 +250,9 @@ bool CrashRecoveryService::CheckGpuHealth(double lastFrameTime, double expectedF } bool CrashRecoveryService::ValidateLuaExecution(bool scriptResult, const std::string& scriptName) { + logger_->Trace("CrashRecoveryService", "ValidateLuaExecution", + "scriptResult=" + std::string(scriptResult ? "true" : "false") + + ", scriptName=" + scriptName); if (!scriptResult) { luaExecutionFailures_++; std::lock_guard lock(crashMutex_); @@ -255,6 +274,9 @@ bool CrashRecoveryService::ValidateLuaExecution(bool scriptResult, const std::st } bool CrashRecoveryService::ValidateFileFormat(const std::string& filePath, const std::string& expectedFormat) { + logger_->Trace("CrashRecoveryService", "ValidateFileFormat", + "filePath=" + filePath + + ", expectedFormat=" + expectedFormat); // Basic file format validation std::filesystem::path path(filePath); @@ -307,6 +329,7 @@ bool CrashRecoveryService::ValidateFileFormat(const std::string& filePath, const } bool CrashRecoveryService::CheckMemoryHealth() { + logger_->Trace("CrashRecoveryService", "CheckMemoryHealth"); UpdateHealthMetrics(); size_t currentMemory = GetCurrentMemoryUsage(); @@ -334,6 +357,7 @@ bool CrashRecoveryService::CheckMemoryHealth() { } std::string CrashRecoveryService::GetSystemHealthStatus() const { + logger_->Trace("CrashRecoveryService", "GetSystemHealthStatus"); std::stringstream ss; ss << "=== SYSTEM HEALTH STATUS ===\n"; @@ -358,10 +382,12 @@ std::string CrashRecoveryService::GetSystemHealthStatus() const { } void CrashRecoveryService::UpdateHealthMetrics() { + logger_->Trace("CrashRecoveryService", "UpdateHealthMetrics"); lastHealthCheck_ = std::chrono::steady_clock::now(); } size_t CrashRecoveryService::GetCurrentMemoryUsage() const { + logger_->Trace("CrashRecoveryService", "GetCurrentMemoryUsage"); // This is a simplified memory usage check // In a real implementation, you'd use platform-specific APIs // For Linux, you might read /proc/self/status or use getrusage @@ -376,6 +402,7 @@ size_t CrashRecoveryService::GetCurrentMemoryUsage() const { } bool CrashRecoveryService::IsGpuResponsive() const { + logger_->Trace("CrashRecoveryService", "IsGpuResponsive"); // This is a placeholder for GPU responsiveness checking // In a real implementation, you'd try a simple GPU operation // and check if it completes within a reasonable time @@ -383,4 +410,4 @@ bool CrashRecoveryService::IsGpuResponsive() const { return consecutiveFrameTimeouts_ < 3; } -} // namespace sdl3cpp::services::impl \ No newline at end of file +} // namespace sdl3cpp::services::impl diff --git a/src/services/impl/graphics_service.cpp b/src/services/impl/graphics_service.cpp index 23b2293..8356f46 100644 --- a/src/services/impl/graphics_service.cpp +++ b/src/services/impl/graphics_service.cpp @@ -18,7 +18,13 @@ GraphicsService::GraphicsService(std::shared_ptr logger, bufferService_(bufferService), renderCommandService_(renderCommandService), windowService_(windowService) { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "GraphicsService", + "deviceService=" + std::string(deviceService_ ? "set" : "null") + + ", swapchainService=" + std::string(swapchainService_ ? "set" : "null") + + ", pipelineService=" + std::string(pipelineService_ ? "set" : "null") + + ", bufferService=" + std::string(bufferService_ ? "set" : "null") + + ", renderCommandService=" + std::string(renderCommandService_ ? "set" : "null") + + ", windowService=" + std::string(windowService_ ? "set" : "null")); if (!deviceService_ || !swapchainService_ || !pipelineService_ || !bufferService_ || !renderCommandService_ || !windowService_) { throw std::invalid_argument("All graphics services must be provided"); @@ -26,14 +32,14 @@ GraphicsService::GraphicsService(std::shared_ptr logger, } GraphicsService::~GraphicsService() { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "~GraphicsService"); if (initialized_) { Shutdown(); } } void GraphicsService::Initialize() { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "Initialize"); if (initialized_) { throw std::runtime_error("Graphics service already initialized"); @@ -44,14 +50,17 @@ void GraphicsService::Initialize() { } void GraphicsService::Shutdown() noexcept { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "Shutdown"); // Services are shutdown individually by the registry initialized_ = false; } void GraphicsService::InitializeDevice(SDL_Window* window, const GraphicsConfig& config) { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "InitializeDevice", + "windowIsNull=" + std::string(window ? "false" : "true") + + ", deviceExtensions.size=" + std::to_string(config.deviceExtensions.size()) + + ", enableValidationLayers=" + std::string(config.enableValidationLayers ? "true" : "false")); if (!initialized_) { throw std::runtime_error("Graphics service not initialized"); @@ -64,7 +73,7 @@ void GraphicsService::InitializeDevice(SDL_Window* window, const GraphicsConfig& } void GraphicsService::InitializeSwapchain() { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "InitializeSwapchain"); if (!initialized_) { throw std::runtime_error("Graphics service not initialized"); @@ -76,7 +85,7 @@ void GraphicsService::InitializeSwapchain() { } void GraphicsService::RecreateSwapchain() { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "RecreateSwapchain"); if (!initialized_) { throw std::runtime_error("Graphics service not initialized"); @@ -88,7 +97,8 @@ void GraphicsService::RecreateSwapchain() { } void GraphicsService::LoadShaders(const std::unordered_map& shaders) { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "LoadShaders", + "shaders.size=" + std::to_string(shaders.size())); if (!initialized_) { throw std::runtime_error("Graphics service not initialized"); @@ -102,7 +112,8 @@ void GraphicsService::LoadShaders(const std::unordered_map& vertices) { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "UploadVertexData", + "vertices.size=" + std::to_string(vertices.size())); if (!initialized_) { throw std::runtime_error("Graphics service not initialized"); @@ -112,7 +123,8 @@ void GraphicsService::UploadVertexData(const std::vector& vertices } void GraphicsService::UploadIndexData(const std::vector& indices) { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "UploadIndexData", + "indices.size=" + std::to_string(indices.size())); if (!initialized_) { throw std::runtime_error("Graphics service not initialized"); @@ -122,7 +134,7 @@ void GraphicsService::UploadIndexData(const std::vector& indices) { } bool GraphicsService::BeginFrame() { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "BeginFrame"); if (!initialized_) { return false; @@ -133,7 +145,9 @@ bool GraphicsService::BeginFrame() { void GraphicsService::RenderScene(const std::vector& commands, const std::array& viewProj) { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "RenderScene", + "commands.size=" + std::to_string(commands.size()) + + ", viewProj.size=" + std::to_string(viewProj.size())); if (!initialized_) { return; @@ -143,7 +157,7 @@ void GraphicsService::RenderScene(const std::vector& commands, } bool GraphicsService::EndFrame() { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "EndFrame"); if (!initialized_) { return false; @@ -153,7 +167,7 @@ bool GraphicsService::EndFrame() { } void GraphicsService::WaitIdle() { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "WaitIdle"); if (!initialized_) { return; @@ -163,7 +177,7 @@ void GraphicsService::WaitIdle() { } VkDevice GraphicsService::GetDevice() const { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "GetDevice"); if (!initialized_) { return VK_NULL_HANDLE; @@ -173,7 +187,7 @@ VkDevice GraphicsService::GetDevice() const { } VkPhysicalDevice GraphicsService::GetPhysicalDevice() const { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "GetPhysicalDevice"); if (!initialized_) { return VK_NULL_HANDLE; @@ -183,7 +197,7 @@ VkPhysicalDevice GraphicsService::GetPhysicalDevice() const { } VkExtent2D GraphicsService::GetSwapchainExtent() const { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "GetSwapchainExtent"); if (!initialized_) { return {0, 0}; @@ -193,7 +207,7 @@ VkExtent2D GraphicsService::GetSwapchainExtent() const { } VkFormat GraphicsService::GetSwapchainFormat() const { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "GetSwapchainFormat"); if (!initialized_) { return VK_FORMAT_UNDEFINED; @@ -203,7 +217,7 @@ VkFormat GraphicsService::GetSwapchainFormat() const { } VkCommandBuffer GraphicsService::GetCurrentCommandBuffer() const { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "GetCurrentCommandBuffer"); if (!initialized_) { return VK_NULL_HANDLE; @@ -213,7 +227,7 @@ VkCommandBuffer GraphicsService::GetCurrentCommandBuffer() const { } VkQueue GraphicsService::GetGraphicsQueue() const { - logger_->TraceFunction(__func__); + logger_->Trace("GraphicsService", "GetGraphicsQueue"); if (!initialized_) { return VK_NULL_HANDLE; @@ -222,4 +236,4 @@ VkQueue GraphicsService::GetGraphicsQueue() const { return deviceService_->GetGraphicsQueue(); } -} // namespace sdl3cpp::services::impl \ No newline at end of file +} // namespace sdl3cpp::services::impl diff --git a/src/services/impl/gui_renderer_service.cpp b/src/services/impl/gui_renderer_service.cpp index ec9589f..a57751c 100644 --- a/src/services/impl/gui_renderer_service.cpp +++ b/src/services/impl/gui_renderer_service.cpp @@ -9,6 +9,10 @@ GuiRendererService::GuiRendererService(std::shared_ptr logger, std::shared_ptr bufferService) : logger_(std::move(logger)), bufferService_(std::move(bufferService)) { + if (logger_) { + logger_->Trace("GuiRendererService", "GuiRendererService", + "bufferService=" + std::string(bufferService_ ? "set" : "null")); + } } void GuiRendererService::Initialize(VkDevice device, @@ -16,7 +20,11 @@ void GuiRendererService::Initialize(VkDevice device, VkFormat format, const std::filesystem::path& resourcePath) { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("GuiRendererService", "Initialize", + "deviceIsNull=" + std::string(device == VK_NULL_HANDLE ? "true" : "false") + + ", physicalDeviceIsNull=" + std::string(physicalDevice == VK_NULL_HANDLE ? "true" : "false") + + ", format=" + std::to_string(static_cast(format)) + + ", resourcePath=" + resourcePath.string()); } renderer_ = std::make_unique( device, physicalDevice, format, resourcePath, bufferService_); @@ -26,7 +34,10 @@ void GuiRendererService::PrepareFrame(const std::vector& commands, uint32_t width, uint32_t height) { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("GuiRendererService", "PrepareFrame", + "commands.size=" + std::to_string(commands.size()) + + ", width=" + std::to_string(width) + + ", height=" + std::to_string(height)); } if (!renderer_) { throw std::runtime_error("GuiRenderer service not initialized"); @@ -36,7 +47,9 @@ void GuiRendererService::PrepareFrame(const std::vector& commands, void GuiRendererService::RenderToSwapchain(VkCommandBuffer commandBuffer, VkImage image) { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("GuiRendererService", "RenderToSwapchain", + "commandBufferIsNull=" + std::string(commandBuffer == VK_NULL_HANDLE ? "true" : "false") + + ", imageIsNull=" + std::string(image == VK_NULL_HANDLE ? "true" : "false")); } if (!renderer_) { throw std::runtime_error("GuiRenderer service not initialized"); @@ -46,7 +59,10 @@ void GuiRendererService::RenderToSwapchain(VkCommandBuffer commandBuffer, VkImag void GuiRendererService::Resize(uint32_t width, uint32_t height, VkFormat format) { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("GuiRendererService", "Resize", + "width=" + std::to_string(width) + + ", height=" + std::to_string(height) + + ", format=" + std::to_string(static_cast(format))); } if (!renderer_) { return; @@ -56,12 +72,15 @@ void GuiRendererService::Resize(uint32_t width, uint32_t height, VkFormat format void GuiRendererService::Shutdown() noexcept { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("GuiRendererService", "Shutdown"); } renderer_.reset(); } bool GuiRendererService::IsReady() const { + if (logger_) { + logger_->Trace("GuiRendererService", "IsReady"); + } return renderer_ && renderer_->IsReady(); } diff --git a/src/services/impl/gui_script_service.cpp b/src/services/impl/gui_script_service.cpp index 1f821b3..a995458 100644 --- a/src/services/impl/gui_script_service.cpp +++ b/src/services/impl/gui_script_service.cpp @@ -17,6 +17,10 @@ GuiScriptService::GuiScriptService(std::shared_ptr engineS std::shared_ptr logger) : engineService_(std::move(engineService)), logger_(std::move(logger)) { + if (logger_) { + logger_->Trace("GuiScriptService", "GuiScriptService", + "engineService=" + std::string(engineService_ ? "set" : "null")); + } } void GuiScriptService::Initialize() { @@ -183,7 +187,13 @@ std::vector GuiScriptService::LoadGuiCommands() { void GuiScriptService::UpdateGuiInput(const GuiInputSnapshot& input) { if (logger_) { - logger_->Trace("GuiScriptService", "UpdateGuiInput"); + logger_->Trace("GuiScriptService", "UpdateGuiInput", + "mouseX=" + std::to_string(input.mouseX) + + ", mouseY=" + std::to_string(input.mouseY) + + ", mouseDown=" + std::string(input.mouseDown ? "true" : "false") + + ", wheel=" + std::to_string(input.wheel) + + ", textInput.size=" + std::to_string(input.textInput.size()) + + ", keyStates.size=" + std::to_string(input.keyStates.size())); } if (guiInputRef_ < 0) { return; @@ -228,10 +238,17 @@ void GuiScriptService::UpdateGuiInput(const GuiInputSnapshot& input) { } bool GuiScriptService::HasGuiCommands() const { + if (logger_) { + logger_->Trace("GuiScriptService", "HasGuiCommands"); + } return guiCommandsFnRef_ >= 0; } GuiCommand::RectData GuiScriptService::ReadRect(lua_State* L, int index) const { + if (logger_) { + logger_->Trace("GuiScriptService", "ReadRect", + "index=" + std::to_string(index)); + } GuiCommand::RectData rect{}; if (!lua_istable(L, index)) { return rect; @@ -254,6 +271,10 @@ GuiCommand::RectData GuiScriptService::ReadRect(lua_State* L, int index) const { } GuiColor GuiScriptService::ReadColor(lua_State* L, int index, const GuiColor& defaultColor) const { + if (logger_) { + logger_->Trace("GuiScriptService", "ReadColor", + "index=" + std::to_string(index)); + } GuiColor color = defaultColor; if (!lua_istable(L, index)) { return color; @@ -276,6 +297,11 @@ GuiColor GuiScriptService::ReadColor(lua_State* L, int index, const GuiColor& de } bool GuiScriptService::ReadStringField(lua_State* L, int index, const char* name, std::string& outString) const { + if (logger_) { + logger_->Trace("GuiScriptService", "ReadStringField", + "index=" + std::to_string(index) + + ", name=" + std::string(name ? name : "")); + } int absIndex = lua_absindex(L, index); lua_getfield(L, absIndex, name); if (lua_isstring(L, -1)) { @@ -288,6 +314,9 @@ bool GuiScriptService::ReadStringField(lua_State* L, int index, const char* name } lua_State* GuiScriptService::GetLuaState() const { + if (logger_) { + logger_->Trace("GuiScriptService", "GetLuaState"); + } if (!engineService_) { throw std::runtime_error("GUI script service is missing script engine service"); } diff --git a/src/services/impl/json_config_service.cpp b/src/services/impl/json_config_service.cpp index 678b313..c2f9ce4 100644 --- a/src/services/impl/json_config_service.cpp +++ b/src/services/impl/json_config_service.cpp @@ -19,25 +19,49 @@ static const std::vector kDeviceExtensions = { JsonConfigService::JsonConfigService(std::shared_ptr logger, const char* argv0) : logger_(std::move(logger)), config_(RuntimeConfig{}) { + if (logger_) { + logger_->Trace("JsonConfigService", "JsonConfigService", + "argv0=" + std::string(argv0 ? argv0 : "")); + } config_.scriptPath = FindScriptPath(argv0); logger_->Info("JsonConfigService initialized with default configuration"); } JsonConfigService::JsonConfigService(std::shared_ptr logger, const std::filesystem::path& configPath, bool dumpConfig) : logger_(std::move(logger)), config_(LoadFromJson(logger_, configPath, dumpConfig)) { + if (logger_) { + logger_->Trace("JsonConfigService", "JsonConfigService", + "configPath=" + configPath.string() + + ", dumpConfig=" + std::string(dumpConfig ? "true" : "false")); + } logger_->Info("JsonConfigService initialized from config file: " + configPath.string()); } JsonConfigService::JsonConfigService(std::shared_ptr logger, const RuntimeConfig& config) : logger_(std::move(logger)), config_(config) { + if (logger_) { + logger_->Trace("JsonConfigService", "JsonConfigService", + "config.width=" + std::to_string(config.width) + + ", config.height=" + std::to_string(config.height) + + ", config.scriptPath=" + config.scriptPath.string() + + ", config.luaDebug=" + std::string(config.luaDebug ? "true" : "false") + + ", config.windowTitle=" + config.windowTitle); + } logger_->Info("JsonConfigService initialized with explicit configuration"); } std::vector JsonConfigService::GetDeviceExtensions() const { + if (logger_) { + logger_->Trace("JsonConfigService", "GetDeviceExtensions"); + } return kDeviceExtensions; } std::filesystem::path JsonConfigService::FindScriptPath(const char* argv0) { + if (logger_) { + logger_->Trace("JsonConfigService", "FindScriptPath", + "argv0=" + std::string(argv0 ? argv0 : "")); + } std::filesystem::path executable; if (argv0 && *argv0 != '\0') { executable = std::filesystem::path(argv0); @@ -56,7 +80,8 @@ std::filesystem::path JsonConfigService::FindScriptPath(const char* argv0) { } RuntimeConfig JsonConfigService::LoadFromJson(std::shared_ptr logger, const std::filesystem::path& configPath, bool dumpConfig) { - std::string args = configPath.string() + " dumpConfig=" + (dumpConfig ? "true" : "false"); + std::string args = "configPath=" + configPath.string() + + ", dumpConfig=" + (dumpConfig ? "true" : "false"); logger->Trace("JsonConfigService", "LoadFromJson", args); std::ifstream configStream(configPath); diff --git a/src/services/impl/json_config_service.hpp b/src/services/impl/json_config_service.hpp index 7cb2123..b43ff4f 100644 --- a/src/services/impl/json_config_service.hpp +++ b/src/services/impl/json_config_service.hpp @@ -45,11 +45,36 @@ public: JsonConfigService(std::shared_ptr logger, const RuntimeConfig& config); // IConfigService interface implementation - uint32_t GetWindowWidth() const override { return config_.width; } - uint32_t GetWindowHeight() const override { return config_.height; } - std::filesystem::path GetScriptPath() const override { return config_.scriptPath; } - bool IsLuaDebugEnabled() const override { return config_.luaDebug; } - std::string GetWindowTitle() const override { return config_.windowTitle; } + uint32_t GetWindowWidth() const override { + if (logger_) { + logger_->Trace("JsonConfigService", "GetWindowWidth"); + } + return config_.width; + } + uint32_t GetWindowHeight() const override { + if (logger_) { + logger_->Trace("JsonConfigService", "GetWindowHeight"); + } + return config_.height; + } + std::filesystem::path GetScriptPath() const override { + if (logger_) { + logger_->Trace("JsonConfigService", "GetScriptPath"); + } + return config_.scriptPath; + } + bool IsLuaDebugEnabled() const override { + if (logger_) { + logger_->Trace("JsonConfigService", "IsLuaDebugEnabled"); + } + return config_.luaDebug; + } + std::string GetWindowTitle() const override { + if (logger_) { + logger_->Trace("JsonConfigService", "GetWindowTitle"); + } + return config_.windowTitle; + } std::vector GetDeviceExtensions() const override; /** @@ -57,7 +82,12 @@ public: * * @return Reference to the config structure */ - const RuntimeConfig& GetConfig() const { return config_; } + const RuntimeConfig& GetConfig() const { + if (logger_) { + logger_->Trace("JsonConfigService", "GetConfig"); + } + return config_; + } private: std::shared_ptr logger_; diff --git a/src/services/impl/json_config_writer_service.cpp b/src/services/impl/json_config_writer_service.cpp index b214ea8..bb2e8d9 100644 --- a/src/services/impl/json_config_writer_service.cpp +++ b/src/services/impl/json_config_writer_service.cpp @@ -22,7 +22,14 @@ JsonConfigWriterService::JsonConfigWriterService(std::shared_ptr logger void JsonConfigWriterService::WriteConfig(const RuntimeConfig& config, const std::filesystem::path& configPath) { if (logger_) { - logger_->Trace("JsonConfigWriterService", "WriteConfig", "configPath=" + configPath.string(), "Entering"); + logger_->Trace("JsonConfigWriterService", "WriteConfig", + "config.width=" + std::to_string(config.width) + + ", config.height=" + std::to_string(config.height) + + ", config.scriptPath=" + config.scriptPath.string() + + ", config.luaDebug=" + std::string(config.luaDebug ? "true" : "false") + + ", config.windowTitle=" + config.windowTitle + + ", configPath=" + configPath.string(), + "Entering"); } rapidjson::Document document; diff --git a/src/services/impl/lifecycle_service.cpp b/src/services/impl/lifecycle_service.cpp index c93d9f8..ea38d4b 100644 --- a/src/services/impl/lifecycle_service.cpp +++ b/src/services/impl/lifecycle_service.cpp @@ -5,7 +5,7 @@ namespace sdl3cpp::services::impl { LifecycleService::LifecycleService(di::ServiceRegistry& registry, std::shared_ptr logger) : registry_(registry), logger_(std::move(logger)) { if (logger_) { - logger_->Trace("LifecycleService", "LifecycleService"); + logger_->Trace("LifecycleService", "LifecycleService", "registry=provided"); } } diff --git a/src/services/impl/mesh_service.cpp b/src/services/impl/mesh_service.cpp index 9a4e525..31ea023 100644 --- a/src/services/impl/mesh_service.cpp +++ b/src/services/impl/mesh_service.cpp @@ -11,13 +11,23 @@ namespace sdl3cpp::services::impl { -MeshService::MeshService(std::shared_ptr configService) - : configService_(std::move(configService)) { +MeshService::MeshService(std::shared_ptr configService, + std::shared_ptr logger) + : configService_(std::move(configService)), + logger_(std::move(logger)) { + if (logger_) { + logger_->Trace("MeshService", "MeshService", + "configService=" + std::string(configService_ ? "set" : "null")); + } } bool MeshService::LoadFromFile(const std::string& requestedPath, MeshPayload& outPayload, std::string& outError) { + if (logger_) { + logger_->Trace("MeshService", "LoadFromFile", + "requestedPath=" + requestedPath); + } if (!configService_) { outError = "Config service not available"; return false; @@ -110,6 +120,13 @@ bool MeshService::LoadFromFile(const std::string& requestedPath, } void MeshService::PushMeshToLua(lua_State* L, const MeshPayload& payload) { + if (logger_) { + logger_->Trace("MeshService", "PushMeshToLua", + "positions.size=" + std::to_string(payload.positions.size()) + + ", colors.size=" + std::to_string(payload.colors.size()) + + ", indices.size=" + std::to_string(payload.indices.size()) + + ", luaStateIsNull=" + std::string(L ? "false" : "true")); + } lua_newtable(L); lua_newtable(L); diff --git a/src/services/impl/mesh_service.hpp b/src/services/impl/mesh_service.hpp index b7a1aa6..54a4655 100644 --- a/src/services/impl/mesh_service.hpp +++ b/src/services/impl/mesh_service.hpp @@ -2,6 +2,7 @@ #include "../interfaces/i_mesh_service.hpp" #include "../interfaces/i_config_service.hpp" +#include "../interfaces/i_logger.hpp" #include namespace sdl3cpp::services::impl { @@ -11,7 +12,8 @@ namespace sdl3cpp::services::impl { */ class MeshService : public IMeshService { public: - explicit MeshService(std::shared_ptr configService); + MeshService(std::shared_ptr configService, + std::shared_ptr logger); bool LoadFromFile(const std::string& requestedPath, MeshPayload& outPayload, @@ -20,6 +22,7 @@ public: private: std::shared_ptr configService_; + std::shared_ptr logger_; }; } // namespace sdl3cpp::services::impl diff --git a/src/services/impl/physics_bridge_service.cpp b/src/services/impl/physics_bridge_service.cpp index fe83a6d..f1f234f 100644 --- a/src/services/impl/physics_bridge_service.cpp +++ b/src/services/impl/physics_bridge_service.cpp @@ -24,6 +24,9 @@ PhysicsBridgeService::PhysicsBridgeService(std::shared_ptr logger) } PhysicsBridgeService::~PhysicsBridgeService() { + if (logger_) { + logger_->Trace("PhysicsBridgeService", "~PhysicsBridgeService"); + } if (world_) { for (auto& [name, entry] : bodies_) { if (entry.body) { @@ -39,7 +42,15 @@ bool PhysicsBridgeService::AddBoxRigidBody(const std::string& name, const btTransform& transform, std::string& error) { if (logger_) { - logger_->Trace("PhysicsBridgeService", "AddBoxRigidBody", "name=" + name); + logger_->Trace("PhysicsBridgeService", "AddBoxRigidBody", + "name=" + name + + ", halfExtents.x=" + std::to_string(halfExtents.getX()) + + ", halfExtents.y=" + std::to_string(halfExtents.getY()) + + ", halfExtents.z=" + std::to_string(halfExtents.getZ()) + + ", mass=" + std::to_string(mass) + + ", origin.x=" + std::to_string(transform.getOrigin().getX()) + + ", origin.y=" + std::to_string(transform.getOrigin().getY()) + + ", origin.z=" + std::to_string(transform.getOrigin().getZ())); } if (name.empty()) { error = "Rigid body name must not be empty"; diff --git a/src/services/impl/pipeline_service.cpp b/src/services/impl/pipeline_service.cpp index 2beb4b8..d68c786 100644 --- a/src/services/impl/pipeline_service.cpp +++ b/src/services/impl/pipeline_service.cpp @@ -8,22 +8,36 @@ namespace sdl3cpp::services::impl { PipelineService::PipelineService(std::shared_ptr deviceService, std::shared_ptr logger) - : deviceService_(std::move(deviceService)), logger_(logger) {} + : deviceService_(std::move(deviceService)), logger_(logger) { + if (logger_) { + logger_->Trace("PipelineService", "PipelineService", + "deviceService=" + std::string(deviceService_ ? "set" : "null")); + } +} PipelineService::~PipelineService() { + if (logger_) { + logger_->Trace("PipelineService", "~PipelineService"); + } if (pipelineLayout_ != VK_NULL_HANDLE || !pipelines_.empty()) { Shutdown(); } } void PipelineService::RegisterShader(const std::string& key, const ShaderPaths& paths) { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "RegisterShader", + "key=" + key + + ", vertex=" + paths.vertex + + ", fragment=" + paths.fragment); shaderPathMap_[key] = paths; logger_->Debug("Registered shader: " + key); } void PipelineService::CompileAll(VkRenderPass renderPass, VkExtent2D extent) { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "CompileAll", + "renderPassIsNull=" + std::string(renderPass == VK_NULL_HANDLE ? "true" : "false") + + ", extent.width=" + std::to_string(extent.width) + + ", extent.height=" + std::to_string(extent.height)); if (shaderPathMap_.empty()) { throw std::runtime_error("No shader paths were registered before pipeline creation"); @@ -36,7 +50,10 @@ void PipelineService::CompileAll(VkRenderPass renderPass, VkExtent2D extent) { } void PipelineService::RecreatePipelines(VkRenderPass renderPass, VkExtent2D extent) { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "RecreatePipelines", + "renderPassIsNull=" + std::string(renderPass == VK_NULL_HANDLE ? "true" : "false") + + ", extent.width=" + std::to_string(extent.width) + + ", extent.height=" + std::to_string(extent.height)); CleanupPipelines(); CreatePipelineLayout(); @@ -46,6 +63,7 @@ void PipelineService::RecreatePipelines(VkRenderPass renderPass, VkExtent2D exte } void PipelineService::Cleanup() { + logger_->Trace("PipelineService", "Cleanup"); CleanupPipelines(); auto device = deviceService_->GetDevice(); @@ -57,11 +75,12 @@ void PipelineService::Cleanup() { } void PipelineService::Shutdown() noexcept { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "Shutdown"); Cleanup(); } VkPipeline PipelineService::GetPipeline(const std::string& key) const { + logger_->Trace("PipelineService", "GetPipeline", "key=" + key); auto it = pipelines_.find(key); if (it == pipelines_.end()) { throw std::out_of_range("Pipeline not found: " + key); @@ -70,11 +89,12 @@ VkPipeline PipelineService::GetPipeline(const std::string& key) const { } bool PipelineService::HasShader(const std::string& key) const { + logger_->Trace("PipelineService", "HasShader", "key=" + key); return shaderPathMap_.find(key) != shaderPathMap_.end(); } void PipelineService::CreatePipelineLayout() { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "CreatePipelineLayout"); auto device = deviceService_->GetDevice(); @@ -99,7 +119,10 @@ void PipelineService::CreatePipelineLayout() { } void PipelineService::CreatePipelinesInternal(VkRenderPass renderPass, VkExtent2D extent) { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "CreatePipelinesInternal", + "renderPassIsNull=" + std::string(renderPass == VK_NULL_HANDLE ? "true" : "false") + + ", extent.width=" + std::to_string(extent.width) + + ", extent.height=" + std::to_string(extent.height)); auto device = deviceService_->GetDevice(); @@ -253,7 +276,7 @@ void PipelineService::CreatePipelinesInternal(VkRenderPass renderPass, VkExtent2 } void PipelineService::CleanupPipelines() { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "CleanupPipelines"); auto device = deviceService_->GetDevice(); @@ -264,7 +287,8 @@ void PipelineService::CleanupPipelines() { } VkShaderModule PipelineService::CreateShaderModule(const std::vector& code) { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "CreateShaderModule", + "code.size=" + std::to_string(code.size())); auto device = deviceService_->GetDevice(); @@ -281,7 +305,7 @@ VkShaderModule PipelineService::CreateShaderModule(const std::vector& code } std::vector PipelineService::ReadShaderFile(const std::string& path) { - logger_->TraceFunction(__func__); + logger_->Trace("PipelineService", "ReadShaderFile", "path=" + path); if (!std::filesystem::exists(path)) { throw std::runtime_error("Shader file not found: " + path + diff --git a/src/services/impl/pipeline_service.hpp b/src/services/impl/pipeline_service.hpp index 06775aa..854520f 100644 --- a/src/services/impl/pipeline_service.hpp +++ b/src/services/impl/pipeline_service.hpp @@ -29,9 +29,15 @@ public: void Cleanup() override; VkPipeline GetPipeline(const std::string& key) const override; - VkPipelineLayout GetPipelineLayout() const override { return pipelineLayout_; } + VkPipelineLayout GetPipelineLayout() const override { + logger_->Trace("PipelineService", "GetPipelineLayout"); + return pipelineLayout_; + } bool HasShader(const std::string& key) const override; - size_t GetShaderCount() const override { return shaderPathMap_.size(); } + size_t GetShaderCount() const override { + logger_->Trace("PipelineService", "GetShaderCount"); + return shaderPathMap_.size(); + } // IShutdownable interface void Shutdown() noexcept override; diff --git a/src/services/impl/platform_service.cpp b/src/services/impl/platform_service.cpp index 6fd188e..2e49f71 100644 --- a/src/services/impl/platform_service.cpp +++ b/src/services/impl/platform_service.cpp @@ -11,6 +11,9 @@ namespace sdl3cpp::services::impl { PlatformService::PlatformService(std::shared_ptr logger) : logger_(std::move(logger)) { + if (logger_) { + logger_->Trace("PlatformService", "PlatformService"); + } } std::optional PlatformService::GetUserConfigDirectory() const { @@ -34,6 +37,10 @@ std::optional PlatformService::GetUserConfigDirectory() c #ifdef _WIN32 std::string PlatformService::FormatWin32Error(unsigned long errorCode) const { + if (logger_) { + logger_->Trace("PlatformService", "FormatWin32Error", + "errorCode=" + std::to_string(errorCode)); + } if (errorCode == ERROR_SUCCESS) { return "ERROR_SUCCESS"; } diff --git a/src/services/impl/render_command_service.cpp b/src/services/impl/render_command_service.cpp index f73471c..aca5e68 100644 --- a/src/services/impl/render_command_service.cpp +++ b/src/services/impl/render_command_service.cpp @@ -1,6 +1,7 @@ #include "render_command_service.hpp" #include "../../core/vertex.hpp" #include +#include namespace sdl3cpp::services::impl { @@ -9,25 +10,37 @@ RenderCommandService::RenderCommandService(std::shared_ptr std::shared_ptr logger) : deviceService_(std::move(deviceService)), swapchainService_(std::move(swapchainService)), - logger_(logger) {} + logger_(logger) { + if (logger_) { + logger_->Trace("RenderCommandService", "RenderCommandService", + "deviceService=" + std::string(deviceService_ ? "set" : "null") + + ", swapchainService=" + std::string(swapchainService_ ? "set" : "null")); + } +} RenderCommandService::~RenderCommandService() { + if (logger_) { + logger_->Trace("RenderCommandService", "~RenderCommandService"); + } if (commandPool_ != VK_NULL_HANDLE || imageAvailableSemaphore_ != VK_NULL_HANDLE) { Shutdown(); } } void RenderCommandService::Cleanup() { + logger_->Trace("RenderCommandService", "Cleanup"); CleanupCommandResources(); CleanupSyncObjects(); } void RenderCommandService::Shutdown() noexcept { + logger_->Trace("RenderCommandService", "Shutdown"); Cleanup(); } bool RenderCommandService::BeginFrame(uint32_t& imageIndex) { - logger_->TraceFunction(__func__); + logger_->Trace("RenderCommandService", "BeginFrame", + "imageIndex=" + std::to_string(imageIndex)); // Lazy initialization if (commandPool_ == VK_NULL_HANDLE) { @@ -71,7 +84,10 @@ bool RenderCommandService::BeginFrame(uint32_t& imageIndex) { void RenderCommandService::RecordCommands(uint32_t imageIndex, const std::vector& commands, const std::array& viewProj) { - logger_->TraceFunction(__func__); + logger_->Trace("RenderCommandService", "RecordCommands", + "imageIndex=" + std::to_string(imageIndex) + + ", commands.size=" + std::to_string(commands.size()) + + ", viewProj.size=" + std::to_string(viewProj.size())); VkCommandBuffer commandBuffer = commandBuffers_[imageIndex]; @@ -109,7 +125,8 @@ void RenderCommandService::RecordCommands(uint32_t imageIndex, } bool RenderCommandService::EndFrame(uint32_t imageIndex) { - logger_->TraceFunction(__func__); + logger_->Trace("RenderCommandService", "EndFrame", + "imageIndex=" + std::to_string(imageIndex)); auto device = deviceService_->GetDevice(); auto graphicsQueue = deviceService_->GetGraphicsQueue(); @@ -149,6 +166,7 @@ bool RenderCommandService::EndFrame(uint32_t imageIndex) { } VkCommandBuffer RenderCommandService::GetCurrentCommandBuffer() const { + logger_->Trace("RenderCommandService", "GetCurrentCommandBuffer"); if (commandBuffers_.empty()) { return VK_NULL_HANDLE; } @@ -156,7 +174,7 @@ VkCommandBuffer RenderCommandService::GetCurrentCommandBuffer() const { } void RenderCommandService::CreateCommandPool() { - logger_->TraceFunction(__func__); + logger_->Trace("RenderCommandService", "CreateCommandPool"); auto device = deviceService_->GetDevice(); auto queueFamilies = deviceService_->GetQueueFamilies(); @@ -172,7 +190,7 @@ void RenderCommandService::CreateCommandPool() { } void RenderCommandService::CreateCommandBuffers() { - logger_->TraceFunction(__func__); + logger_->Trace("RenderCommandService", "CreateCommandBuffers"); auto device = deviceService_->GetDevice(); auto framebuffers = swapchainService_->GetSwapchainFramebuffers(); @@ -193,7 +211,7 @@ void RenderCommandService::CreateCommandBuffers() { } void RenderCommandService::CreateSyncObjects() { - logger_->TraceFunction(__func__); + logger_->Trace("RenderCommandService", "CreateSyncObjects"); auto device = deviceService_->GetDevice(); @@ -214,7 +232,7 @@ void RenderCommandService::CreateSyncObjects() { } void RenderCommandService::CleanupCommandResources() { - logger_->TraceFunction(__func__); + logger_->Trace("RenderCommandService", "CleanupCommandResources"); auto device = deviceService_->GetDevice(); @@ -232,7 +250,7 @@ void RenderCommandService::CleanupCommandResources() { } void RenderCommandService::CleanupSyncObjects() { - logger_->TraceFunction(__func__); + logger_->Trace("RenderCommandService", "CleanupSyncObjects"); auto device = deviceService_->GetDevice(); diff --git a/src/services/impl/render_command_service.hpp b/src/services/impl/render_command_service.hpp index ce5666a..c682ff5 100644 --- a/src/services/impl/render_command_service.hpp +++ b/src/services/impl/render_command_service.hpp @@ -34,8 +34,14 @@ public: bool EndFrame(uint32_t imageIndex) override; VkCommandBuffer GetCurrentCommandBuffer() const override; - uint32_t GetCurrentFrameIndex() const override { return currentFrame_; } - uint32_t GetMaxFramesInFlight() const override { return maxFramesInFlight_; } + uint32_t GetCurrentFrameIndex() const override { + logger_->Trace("RenderCommandService", "GetCurrentFrameIndex"); + return currentFrame_; + } + uint32_t GetMaxFramesInFlight() const override { + logger_->Trace("RenderCommandService", "GetMaxFramesInFlight"); + return maxFramesInFlight_; + } // IShutdownable interface void Shutdown() noexcept override; diff --git a/src/services/impl/render_coordinator_service.cpp b/src/services/impl/render_coordinator_service.cpp index aefb058..1dad955 100644 --- a/src/services/impl/render_coordinator_service.cpp +++ b/src/services/impl/render_coordinator_service.cpp @@ -15,7 +15,13 @@ RenderCoordinatorService::RenderCoordinatorService(std::shared_ptr logg guiService_(std::move(guiService)), sceneService_(std::move(sceneService)) { if (logger_) { - logger_->Trace("RenderCoordinatorService", "RenderCoordinatorService", "", "Created"); + logger_->Trace("RenderCoordinatorService", "RenderCoordinatorService", + "graphicsService=" + std::string(graphicsService_ ? "set" : "null") + + ", sceneScriptService=" + std::string(sceneScriptService_ ? "set" : "null") + + ", guiScriptService=" + std::string(guiScriptService_ ? "set" : "null") + + ", guiService=" + std::string(guiService_ ? "set" : "null") + + ", sceneService=" + std::string(sceneService_ ? "set" : "null"), + "Created"); } } diff --git a/src/services/impl/scene_script_service.cpp b/src/services/impl/scene_script_service.cpp index 1a78cf8..3a9e94f 100644 --- a/src/services/impl/scene_script_service.cpp +++ b/src/services/impl/scene_script_service.cpp @@ -97,6 +97,10 @@ SceneScriptService::SceneScriptService(std::shared_ptr eng std::shared_ptr logger) : engineService_(std::move(engineService)), logger_(std::move(logger)) { + if (logger_) { + logger_->Trace("SceneScriptService", "SceneScriptService", + "engineService=" + std::string(engineService_ ? "set" : "null")); + } } std::vector SceneScriptService::LoadSceneObjects() { @@ -190,7 +194,9 @@ std::vector SceneScriptService::LoadSceneObjects() { std::array SceneScriptService::ComputeModelMatrix(int functionRef, float time) { if (logger_) { - logger_->Trace("SceneScriptService", "ComputeModelMatrix", "time=" + std::to_string(time)); + logger_->Trace("SceneScriptService", "ComputeModelMatrix", + "functionRef=" + std::to_string(functionRef) + + ", time=" + std::to_string(time)); } lua_State* L = GetLuaState(); @@ -262,6 +268,9 @@ std::array SceneScriptService::GetViewProjectionMatrix(float aspect) } lua_State* SceneScriptService::GetLuaState() const { + if (logger_) { + logger_->Trace("SceneScriptService", "GetLuaState"); + } if (!engineService_) { throw std::runtime_error("Scene script service is missing script engine service"); } diff --git a/src/services/impl/scene_service.cpp b/src/services/impl/scene_service.cpp index 394edff..2f53f81 100644 --- a/src/services/impl/scene_service.cpp +++ b/src/services/impl/scene_service.cpp @@ -5,7 +5,8 @@ namespace sdl3cpp::services::impl { SceneService::SceneService(std::shared_ptr scriptService, std::shared_ptr logger) : scriptService_(scriptService), logger_(logger) { - logger_->TraceFunction(__func__); + logger_->Trace("SceneService", "SceneService", + "scriptService=" + std::string(scriptService_ ? "set" : "null")); if (!scriptService_) { throw std::invalid_argument("Scene script service cannot be null"); @@ -13,21 +14,23 @@ SceneService::SceneService(std::shared_ptr scriptService, s } SceneService::~SceneService() { - logger_->TraceFunction(__func__); + logger_->Trace("SceneService", "~SceneService"); if (initialized_) { Shutdown(); } } void SceneService::LoadScene(const std::vector& objects) { - logger_->TraceFunction(__func__); + logger_->Trace("SceneService", "LoadScene", + "objects.size=" + std::to_string(objects.size())); sceneObjects_ = objects; initialized_ = true; } void SceneService::UpdateScene(float deltaTime) { - logger_->TraceFunction(__func__); + logger_->Trace("SceneService", "UpdateScene", + "deltaTime=" + std::to_string(deltaTime)); // Scene updates would go here (animations, physics, etc.) // For now, this is a placeholder @@ -35,7 +38,8 @@ void SceneService::UpdateScene(float deltaTime) { } std::vector SceneService::GetRenderCommands(float time) const { - logger_->TraceFunction(__func__); + logger_->Trace("SceneService", "GetRenderCommands", + "time=" + std::to_string(time)); if (!initialized_) { return {}; @@ -58,20 +62,20 @@ std::vector SceneService::GetRenderCommands(float time) const { } void SceneService::Clear() { - logger_->TraceFunction(__func__); + logger_->Trace("SceneService", "Clear"); sceneObjects_.clear(); initialized_ = false; } size_t SceneService::GetObjectCount() const { - logger_->TraceFunction(__func__); + logger_->Trace("SceneService", "GetObjectCount"); return sceneObjects_.size(); } void SceneService::Shutdown() noexcept { - logger_->TraceFunction(__func__); + logger_->Trace("SceneService", "Shutdown"); Clear(); } diff --git a/src/services/impl/script_engine_service.cpp b/src/services/impl/script_engine_service.cpp index d722d5e..3439a75 100644 --- a/src/services/impl/script_engine_service.cpp +++ b/src/services/impl/script_engine_service.cpp @@ -25,9 +25,20 @@ ScriptEngineService::ScriptEngineService(const std::filesystem::path& scriptPath physicsBridgeService_(std::move(physicsBridgeService)), scriptPath_(scriptPath), debugEnabled_(debugEnabled) { + if (logger_) { + logger_->Trace("ScriptEngineService", "ScriptEngineService", + "scriptPath=" + scriptPath_.string() + + ", debugEnabled=" + std::string(debugEnabled_ ? "true" : "false") + + ", meshService=" + std::string(meshService_ ? "set" : "null") + + ", audioCommandService=" + std::string(audioCommandService_ ? "set" : "null") + + ", physicsBridgeService=" + std::string(physicsBridgeService_ ? "set" : "null")); + } } ScriptEngineService::~ScriptEngineService() { + if (logger_) { + logger_->Trace("ScriptEngineService", "~ScriptEngineService"); + } if (initialized_) { Shutdown(); } @@ -37,7 +48,9 @@ void ScriptEngineService::Initialize() { if (initialized_) { return; } - logger_->TraceFunction(__func__); + logger_->Trace("ScriptEngineService", "Initialize", + "scriptPath=" + scriptPath_.string() + + ", debugEnabled=" + std::string(debugEnabled_ ? "true" : "false")); bindingContext_ = std::make_shared(); bindingContext_->meshService = meshService_; @@ -93,7 +106,7 @@ void ScriptEngineService::Shutdown() noexcept { if (!initialized_) { return; } - logger_->TraceFunction(__func__); + logger_->Trace("ScriptEngineService", "Shutdown"); if (luaState_) { lua_close(luaState_); @@ -106,6 +119,9 @@ void ScriptEngineService::Shutdown() noexcept { } lua_State* ScriptEngineService::GetLuaState() const { + if (logger_) { + logger_->Trace("ScriptEngineService", "GetLuaState"); + } if (!luaState_) { throw std::runtime_error("Script engine service not initialized"); } @@ -113,6 +129,9 @@ lua_State* ScriptEngineService::GetLuaState() const { } std::filesystem::path ScriptEngineService::GetScriptDirectory() const { + if (logger_) { + logger_->Trace("ScriptEngineService", "GetScriptDirectory"); + } if (!luaState_) { throw std::runtime_error("Script engine service not initialized"); } @@ -153,8 +172,8 @@ int ScriptEngineService::LoadMeshFromFile(lua_State* L) { const char* path = luaL_checkstring(L, 1); if (logger) { - logger->Trace("LuaBindings", "LoadMeshFromFile"); - logger->TraceVariable("path", std::string(path)); + logger->Trace("ScriptEngineService", "LoadMeshFromFile", + "path=" + std::string(path)); } MeshPayload payload; @@ -181,8 +200,8 @@ int ScriptEngineService::PhysicsCreateBox(lua_State* L) { const char* name = luaL_checkstring(L, 1); if (logger) { - logger->Trace("LuaBindings", "PhysicsCreateBox"); - logger->TraceVariable("name", std::string(name)); + logger->Trace("ScriptEngineService", "PhysicsCreateBox", + "name=" + std::string(name)); } if (!lua_istable(L, 2) || !lua_istable(L, 4) || !lua_istable(L, 5)) { @@ -223,7 +242,7 @@ int ScriptEngineService::PhysicsStepSimulation(lua_State* L) { return 1; } if (logger) { - logger->Trace("LuaBindings", "PhysicsStepSimulation"); + logger->Trace("ScriptEngineService", "PhysicsStepSimulation"); } float deltaTime = static_cast(luaL_checknumber(L, 1)); int steps = context->physicsBridgeService->StepSimulation(deltaTime); @@ -241,8 +260,8 @@ int ScriptEngineService::PhysicsGetTransform(lua_State* L) { } const char* name = luaL_checkstring(L, 1); if (logger) { - logger->Trace("LuaBindings", "PhysicsGetTransform"); - logger->TraceVariable("name", std::string(name)); + logger->Trace("ScriptEngineService", "PhysicsGetTransform", + "name=" + std::string(name)); } btTransform transform; @@ -293,9 +312,9 @@ int ScriptEngineService::AudioPlayBackground(lua_State* L) { loop = lua_toboolean(L, 2); } if (logger) { - logger->Trace("LuaBindings", "AudioPlayBackground"); - logger->TraceVariable("path", std::string(path)); - logger->TraceVariable("loop", loop); + logger->Trace("ScriptEngineService", "AudioPlayBackground", + "path=" + std::string(path) + + ", loop=" + std::string(loop ? "true" : "false")); } std::string error; @@ -324,9 +343,9 @@ int ScriptEngineService::AudioPlaySound(lua_State* L) { loop = lua_toboolean(L, 2); } if (logger) { - logger->Trace("LuaBindings", "AudioPlaySound"); - logger->TraceVariable("path", std::string(path)); - logger->TraceVariable("loop", loop); + logger->Trace("ScriptEngineService", "AudioPlaySound", + "path=" + std::string(path) + + ", loop=" + std::string(loop ? "true" : "false")); } std::string error; @@ -342,6 +361,12 @@ int ScriptEngineService::AudioPlaySound(lua_State* L) { } int ScriptEngineService::GlmMatrixFromTransform(lua_State* L) { + auto* context = static_cast(lua_touserdata(L, lua_upvalueindex(1))); + auto logger = context ? context->logger : nullptr; + if (logger) { + logger->Trace("ScriptEngineService", "GlmMatrixFromTransform", + "luaStateIsNull=" + std::string(L ? "false" : "true")); + } return lua::LuaGlmMatrixFromTransform(L); } diff --git a/src/services/impl/script_engine_service.hpp b/src/services/impl/script_engine_service.hpp index e23e6ac..1427ab0 100644 --- a/src/services/impl/script_engine_service.hpp +++ b/src/services/impl/script_engine_service.hpp @@ -35,7 +35,12 @@ public: // IScriptEngineService interface lua_State* GetLuaState() const override; std::filesystem::path GetScriptDirectory() const override; - bool IsInitialized() const override { return initialized_; } + bool IsInitialized() const override { + if (logger_) { + logger_->Trace("ScriptEngineService", "IsInitialized"); + } + return initialized_; + } private: struct LuaBindingContext { diff --git a/src/services/impl/sdl_audio_service.cpp b/src/services/impl/sdl_audio_service.cpp index b4f6ce8..5bafdb0 100644 --- a/src/services/impl/sdl_audio_service.cpp +++ b/src/services/impl/sdl_audio_service.cpp @@ -12,9 +12,16 @@ constexpr int kMixFrames = 1024; } // namespace SdlAudioService::SdlAudioService(std::shared_ptr logger) - : logger_(logger) {} + : logger_(logger) { + if (logger_) { + logger_->Trace("SdlAudioService", "SdlAudioService"); + } +} SdlAudioService::~SdlAudioService() { + if (logger_) { + logger_->Trace("SdlAudioService", "~SdlAudioService"); + } if (initialized_) { Shutdown(); } @@ -22,7 +29,7 @@ SdlAudioService::~SdlAudioService() { void SdlAudioService::Initialize() { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("SdlAudioService", "Initialize"); } if (initialized_) { @@ -68,7 +75,7 @@ void SdlAudioService::Initialize() { void SdlAudioService::Shutdown() noexcept { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("SdlAudioService", "Shutdown"); } if (!initialized_) { @@ -104,7 +111,9 @@ void SdlAudioService::Shutdown() noexcept { void SdlAudioService::PlayBackground(const std::filesystem::path& path, bool loop) { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("SdlAudioService", "PlayBackground", + "path=" + path.string() + + ", loop=" + std::string(loop ? "true" : "false")); } if (!initialized_) { @@ -136,7 +145,9 @@ void SdlAudioService::PlayBackground(const std::filesystem::path& path, bool loo void SdlAudioService::PlayEffect(const std::filesystem::path& path, bool loop) { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("SdlAudioService", "PlayEffect", + "path=" + path.string() + + ", loop=" + std::string(loop ? "true" : "false")); } if (!initialized_) { @@ -159,7 +170,7 @@ void SdlAudioService::PlayEffect(const std::filesystem::path& path, bool loop) { void SdlAudioService::StopBackground() { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("SdlAudioService", "StopBackground"); } if (!initialized_) { @@ -179,7 +190,7 @@ void SdlAudioService::StopBackground() { void SdlAudioService::StopAll() { if (logger_) { - logger_->TraceFunction(__func__); + logger_->Trace("SdlAudioService", "StopAll"); } if (!initialized_) { @@ -202,6 +213,10 @@ void SdlAudioService::StopAll() { } void SdlAudioService::SetVolume(float volume) { + if (logger_) { + logger_->Trace("SdlAudioService", "SetVolume", + "volume=" + std::to_string(volume)); + } std::lock_guard lock(audioMutex_); volume_ = std::clamp(volume, 0.0f, 1.0f); if (logger_) { @@ -210,16 +225,25 @@ void SdlAudioService::SetVolume(float volume) { } float SdlAudioService::GetVolume() const { + if (logger_) { + logger_->Trace("SdlAudioService", "GetVolume"); + } std::lock_guard lock(const_cast(audioMutex_)); return volume_; } bool SdlAudioService::IsBackgroundPlaying() const { + if (logger_) { + logger_->Trace("SdlAudioService", "IsBackgroundPlaying"); + } std::lock_guard lock(const_cast(audioMutex_)); return backgroundAudio_ && backgroundAudio_->isOpen && !backgroundAudio_->finished; } void SdlAudioService::Update() { + if (logger_) { + logger_->Trace("SdlAudioService", "Update"); + } if (!initialized_ || !audioStream_) { return; } @@ -312,6 +336,11 @@ void SdlAudioService::Update() { } bool SdlAudioService::LoadAudioFile(const std::filesystem::path& path, AudioData& audioData) { + if (logger_) { + logger_->Trace("SdlAudioService", "LoadAudioFile", + "path=" + path.string() + + ", audioData.isOpen=" + std::string(audioData.isOpen ? "true" : "false")); + } std::string pathText = path.string(); FILE* file = fopen(pathText.c_str(), "rb"); if (!file) { @@ -356,6 +385,10 @@ bool SdlAudioService::LoadAudioFile(const std::filesystem::path& path, AudioData } void SdlAudioService::CleanupAudioData(AudioData& audioData) { + if (logger_) { + logger_->Trace("SdlAudioService", "CleanupAudioData", + "audioData.isOpen=" + std::string(audioData.isOpen ? "true" : "false")); + } if (audioData.convertStream) { SDL_DestroyAudioStream(audioData.convertStream); audioData.convertStream = nullptr; @@ -368,6 +401,11 @@ void SdlAudioService::CleanupAudioData(AudioData& audioData) { } int SdlAudioService::ReadStreamSamples(AudioData& audioData, std::vector& output, int frames) { + if (logger_) { + logger_->Trace("SdlAudioService", "ReadStreamSamples", + "frames=" + std::to_string(frames) + + ", audioData.isOpen=" + std::string(audioData.isOpen ? "true" : "false")); + } if (!audioData.isOpen || !audioData.convertStream) { return 0; } diff --git a/src/services/impl/sdl_input_service.cpp b/src/services/impl/sdl_input_service.cpp index 0ae2133..a85b810 100644 --- a/src/services/impl/sdl_input_service.cpp +++ b/src/services/impl/sdl_input_service.cpp @@ -43,9 +43,18 @@ SdlInputService::SdlInputService(std::shared_ptr eventBus, st eventBus_->Subscribe(events::EventType::TextInput, [this](const events::Event& e) { OnTextInput(e); }); + + if (logger_) { + logger_->Trace("SdlInputService", "SdlInputService", + "eventBus=" + std::string(eventBus_ ? "set" : "null")); + } } void SdlInputService::ProcessEvent(const SDL_Event& event) { + if (logger_) { + logger_->Trace("SdlInputService", "ProcessEvent", + "eventType=" + std::to_string(static_cast(event.type))); + } // This method allows direct event processing if needed // (though typically events flow through the event bus) switch (event.type) { @@ -114,6 +123,9 @@ void SdlInputService::ProcessEvent(const SDL_Event& event) { } void SdlInputService::ResetFrameState() { + if (logger_) { + logger_->Trace("SdlInputService", "ResetFrameState"); + } // Reset per-frame state state_.mouseWheelDeltaX = 0.0f; state_.mouseWheelDeltaY = 0.0f; @@ -125,59 +137,123 @@ void SdlInputService::ResetFrameState() { } bool SdlInputService::IsKeyPressed(SDL_Keycode key) const { + if (logger_) { + logger_->Trace("SdlInputService", "IsKeyPressed", + "key=" + std::to_string(static_cast(key))); + } return state_.keysPressed.count(key) > 0; } bool SdlInputService::IsMouseButtonPressed(uint8_t button) const { + if (logger_) { + logger_->Trace("SdlInputService", "IsMouseButtonPressed", + "button=" + std::to_string(static_cast(button))); + } return state_.mouseButtonsPressed.count(button) > 0; } std::pair SdlInputService::GetMousePosition() const { + if (logger_) { + logger_->Trace("SdlInputService", "GetMousePosition"); + } return {state_.mouseX, state_.mouseY}; } void SdlInputService::OnKeyPressed(const events::Event& event) { const auto& keyEvent = event.GetData(); + if (logger_) { + logger_->Trace("SdlInputService", "OnKeyPressed", + "key=" + std::to_string(static_cast(keyEvent.key)) + + ", scancode=" + std::to_string(static_cast(keyEvent.scancode)) + + ", modifiers=" + std::to_string(static_cast(keyEvent.modifiers)) + + ", repeat=" + std::string(keyEvent.repeat ? "true" : "false")); + } state_.keysPressed.insert(keyEvent.key); } void SdlInputService::OnKeyReleased(const events::Event& event) { const auto& keyEvent = event.GetData(); + if (logger_) { + logger_->Trace("SdlInputService", "OnKeyReleased", + "key=" + std::to_string(static_cast(keyEvent.key)) + + ", scancode=" + std::to_string(static_cast(keyEvent.scancode)) + + ", modifiers=" + std::to_string(static_cast(keyEvent.modifiers)) + + ", repeat=" + std::string(keyEvent.repeat ? "true" : "false")); + } state_.keysPressed.erase(keyEvent.key); } void SdlInputService::OnMouseMoved(const events::Event& event) { const auto& mouseEvent = event.GetData(); + if (logger_) { + logger_->Trace("SdlInputService", "OnMouseMoved", + "x=" + std::to_string(mouseEvent.x) + + ", y=" + std::to_string(mouseEvent.y) + + ", deltaX=" + std::to_string(mouseEvent.deltaX) + + ", deltaY=" + std::to_string(mouseEvent.deltaY)); + } state_.mouseX = mouseEvent.x; state_.mouseY = mouseEvent.y; } void SdlInputService::OnMouseButtonPressed(const events::Event& event) { const auto& buttonEvent = event.GetData(); + if (logger_) { + logger_->Trace("SdlInputService", "OnMouseButtonPressed", + "button=" + std::to_string(static_cast(buttonEvent.button)) + + ", clicks=" + std::to_string(static_cast(buttonEvent.clicks)) + + ", x=" + std::to_string(buttonEvent.x) + + ", y=" + std::to_string(buttonEvent.y)); + } state_.mouseButtonsPressed.insert(buttonEvent.button); } void SdlInputService::OnMouseButtonReleased(const events::Event& event) { const auto& buttonEvent = event.GetData(); + if (logger_) { + logger_->Trace("SdlInputService", "OnMouseButtonReleased", + "button=" + std::to_string(static_cast(buttonEvent.button)) + + ", clicks=" + std::to_string(static_cast(buttonEvent.clicks)) + + ", x=" + std::to_string(buttonEvent.x) + + ", y=" + std::to_string(buttonEvent.y)); + } state_.mouseButtonsPressed.erase(buttonEvent.button); } void SdlInputService::OnMouseWheel(const events::Event& event) { const auto& wheelEvent = event.GetData(); + if (logger_) { + logger_->Trace("SdlInputService", "OnMouseWheel", + "deltaX=" + std::to_string(wheelEvent.deltaX) + + ", deltaY=" + std::to_string(wheelEvent.deltaY) + + ", flipped=" + std::string(wheelEvent.flipped ? "true" : "false")); + } state_.mouseWheelDeltaX += wheelEvent.deltaX; state_.mouseWheelDeltaY += wheelEvent.deltaY; } void SdlInputService::OnTextInput(const events::Event& event) { const auto& textEvent = event.GetData(); + if (logger_) { + logger_->Trace("SdlInputService", "OnTextInput", + "text=" + textEvent.text); + } state_.textInput += textEvent.text; } void SdlInputService::SetGuiScriptService(IGuiScriptService* guiScriptService) { + if (logger_) { + logger_->Trace("SdlInputService", "SetGuiScriptService", + "guiScriptServiceIsNull=" + std::string(guiScriptService ? "false" : "true")); + } guiScriptService_ = guiScriptService; } void SdlInputService::UpdateGuiInput() { + if (logger_) { + logger_->Trace("SdlInputService", "UpdateGuiInput", + "guiScriptServiceIsNull=" + std::string(guiScriptService_ ? "false" : "true")); + } if (guiScriptService_) { guiScriptService_->UpdateGuiInput(guiInputSnapshot_); } diff --git a/src/services/impl/sdl_input_service.hpp b/src/services/impl/sdl_input_service.hpp index b094a6a..d3c8dd2 100644 --- a/src/services/impl/sdl_input_service.hpp +++ b/src/services/impl/sdl_input_service.hpp @@ -28,7 +28,12 @@ public: // IInputService interface void ProcessEvent(const SDL_Event& event) override; void ResetFrameState() override; - const InputState& GetState() const override { return state_; } + const InputState& GetState() const override { + if (logger_) { + logger_->Trace("SdlInputService", "GetState"); + } + return state_; + } bool IsKeyPressed(SDL_Keycode key) const override; bool IsMouseButtonPressed(uint8_t button) const override; std::pair GetMousePosition() const override; diff --git a/src/services/impl/sdl_window_service.cpp b/src/services/impl/sdl_window_service.cpp index f6a3ecc..79515e5 100644 --- a/src/services/impl/sdl_window_service.cpp +++ b/src/services/impl/sdl_window_service.cpp @@ -52,16 +52,24 @@ SdlWindowService::SdlWindowService(std::shared_ptr logger, : logger_(std::move(logger)), platformService_(std::move(platformService)), eventBus_(std::move(eventBus)) { + if (logger_) { + logger_->Trace("SdlWindowService", "SdlWindowService", + "platformService=" + std::string(platformService_ ? "set" : "null") + + ", eventBus=" + std::string(eventBus_ ? "set" : "null")); + } } SdlWindowService::~SdlWindowService() { + if (logger_) { + logger_->Trace("SdlWindowService", "~SdlWindowService"); + } if (window_) { DestroyWindow(); } } void SdlWindowService::Initialize() { - logger_->TraceFunction(__func__); + logger_->Trace("SdlWindowService", "Initialize"); if (initialized_) { throw std::runtime_error("SdlWindowService already initialized"); @@ -79,6 +87,7 @@ void SdlWindowService::Initialize() { } void SdlWindowService::Shutdown() noexcept { + logger_->Trace("SdlWindowService", "Shutdown"); if (!initialized_) { return; } @@ -93,7 +102,11 @@ void SdlWindowService::Shutdown() noexcept { } void SdlWindowService::CreateWindow(const WindowConfig& config) { - logger_->TraceFunction(__func__); + logger_->Trace("SdlWindowService", "CreateWindow", + "config.width=" + std::to_string(config.width) + + ", config.height=" + std::to_string(config.height) + + ", config.title=" + config.title + + ", config.resizable=" + std::string(config.resizable ? "true" : "false")); if (!initialized_) { throw std::runtime_error("SdlWindowService not initialized"); @@ -149,6 +162,8 @@ void SdlWindowService::CreateWindow(const WindowConfig& config) { } void SdlWindowService::DestroyWindow() { + logger_->Trace("SdlWindowService", "DestroyWindow", + "windowIsNull=" + std::string(window_ ? "false" : "true")); if (window_) { SDL_StopTextInput(window_); SDL_DestroyWindow(window_); @@ -157,6 +172,8 @@ void SdlWindowService::DestroyWindow() { } std::pair SdlWindowService::GetSize() const { + logger_->Trace("SdlWindowService", "GetSize", + "windowIsNull=" + std::string(window_ ? "false" : "true")); if (!window_) { return {0, 0}; } @@ -167,6 +184,8 @@ std::pair SdlWindowService::GetSize() const { } bool SdlWindowService::IsMinimized() const { + logger_->Trace("SdlWindowService", "IsMinimized", + "windowIsNull=" + std::string(window_ ? "false" : "true")); if (!window_) { return false; } @@ -176,6 +195,7 @@ bool SdlWindowService::IsMinimized() const { } void SdlWindowService::PollEvents() { + logger_->Trace("SdlWindowService", "PollEvents"); SDL_Event event; while (SDL_PollEvent(&event)) { // Convert SDL event to application event and publish @@ -189,12 +209,15 @@ void SdlWindowService::PollEvents() { } void SdlWindowService::SetTitle(const std::string& title) { + logger_->Trace("SdlWindowService", "SetTitle", "title=" + title); if (window_) { SDL_SetWindowTitle(window_, title.c_str()); } } void SdlWindowService::PublishEvent(const SDL_Event& sdlEvent) { + logger_->Trace("SdlWindowService", "PublishEvent", + "eventType=" + std::to_string(static_cast(sdlEvent.type))); double timestamp = GetCurrentTime(); switch (sdlEvent.type) { @@ -351,6 +374,7 @@ void SdlWindowService::PublishEvent(const SDL_Event& sdlEvent) { } double SdlWindowService::GetCurrentTime() const { + logger_->Trace("SdlWindowService", "GetCurrentTime"); using namespace std::chrono; auto now = steady_clock::now(); auto dur = now.time_since_epoch(); diff --git a/src/services/impl/sdl_window_service.hpp b/src/services/impl/sdl_window_service.hpp index a7e93dd..3a0c5cb 100644 --- a/src/services/impl/sdl_window_service.hpp +++ b/src/services/impl/sdl_window_service.hpp @@ -41,9 +41,15 @@ public: // IWindowService interface void CreateWindow(const WindowConfig& config) override; void DestroyWindow() override; - SDL_Window* GetNativeHandle() const override { return window_; } + SDL_Window* GetNativeHandle() const override { + logger_->Trace("SdlWindowService", "GetNativeHandle"); + return window_; + } std::pair GetSize() const override; - bool ShouldClose() const override { return shouldClose_; } + bool ShouldClose() const override { + logger_->Trace("SdlWindowService", "ShouldClose"); + return shouldClose_; + } void PollEvents() override; void SetTitle(const std::string& title) override; bool IsMinimized() const override; diff --git a/src/services/impl/shader_script_service.cpp b/src/services/impl/shader_script_service.cpp index d78126d..16b8cee 100644 --- a/src/services/impl/shader_script_service.cpp +++ b/src/services/impl/shader_script_service.cpp @@ -16,6 +16,10 @@ ShaderScriptService::ShaderScriptService(std::shared_ptr e std::shared_ptr logger) : engineService_(std::move(engineService)), logger_(std::move(logger)) { + if (logger_) { + logger_->Trace("ShaderScriptService", "ShaderScriptService", + "engineService=" + std::string(engineService_ ? "set" : "null")); + } } std::unordered_map ShaderScriptService::LoadShaderPathsMap() { @@ -69,6 +73,10 @@ std::unordered_map ShaderScriptService::LoadShaderPath } ShaderPaths ShaderScriptService::ReadShaderPathsTable(lua_State* L, int index) const { + if (logger_) { + logger_->Trace("ShaderScriptService", "ReadShaderPathsTable", + "index=" + std::to_string(index)); + } ShaderPaths paths; int absIndex = lua_absindex(L, index); @@ -98,6 +106,9 @@ ShaderPaths ShaderScriptService::ReadShaderPathsTable(lua_State* L, int index) c } lua_State* ShaderScriptService::GetLuaState() const { + if (logger_) { + logger_->Trace("ShaderScriptService", "GetLuaState"); + } if (!engineService_) { throw std::runtime_error("Shader script service is missing script engine service"); } diff --git a/src/services/impl/swapchain_service.cpp b/src/services/impl/swapchain_service.cpp index 0934f80..1aac85b 100644 --- a/src/services/impl/swapchain_service.cpp +++ b/src/services/impl/swapchain_service.cpp @@ -1,6 +1,7 @@ #include "swapchain_service.hpp" #include #include +#include namespace sdl3cpp::services::impl { @@ -8,24 +9,34 @@ SwapchainService::SwapchainService(std::shared_ptr deviceS std::shared_ptr eventBus, std::shared_ptr logger) : deviceService_(std::move(deviceService)), eventBus_(std::move(eventBus)), logger_(logger) { + if (logger_) { + logger_->Trace("SwapchainService", "SwapchainService", + "deviceService=" + std::string(deviceService_ ? "set" : "null") + + ", eventBus=" + std::string(eventBus_ ? "set" : "null")); + } // Subscribe to window resize events eventBus_->Subscribe(events::EventType::WindowResized, [this](const events::Event& event) { OnWindowResized(event); }); } SwapchainService::~SwapchainService() { + if (logger_) { + logger_->Trace("SwapchainService", "~SwapchainService"); + } if (swapchain_ != VK_NULL_HANDLE) { Shutdown(); } } void SwapchainService::Initialize() { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "Initialize"); // Initialization happens in CreateSwapchain() } void SwapchainService::CreateSwapchain(uint32_t width, uint32_t height) { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "CreateSwapchain", + "width=" + std::to_string(width) + + ", height=" + std::to_string(height)); currentWidth_ = width; currentHeight_ = height; @@ -112,7 +123,9 @@ void SwapchainService::CreateSwapchain(uint32_t width, uint32_t height) { } void SwapchainService::RecreateSwapchain(uint32_t width, uint32_t height) { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "RecreateSwapchain", + "width=" + std::to_string(width) + + ", height=" + std::to_string(height)); logger_->Info("Recreating swapchain: " + std::to_string(width) + "x" + std::to_string(height)); @@ -122,6 +135,9 @@ void SwapchainService::RecreateSwapchain(uint32_t width, uint32_t height) { } VkResult SwapchainService::AcquireNextImage(VkSemaphore semaphore, uint32_t& imageIndex) { + logger_->Trace("SwapchainService", "AcquireNextImage", + "semaphoreIsNull=" + std::string(semaphore == VK_NULL_HANDLE ? "true" : "false") + + ", imageIndex=" + std::to_string(imageIndex)); auto device = deviceService_->GetDevice(); return vkAcquireNextImageKHR(device, swapchain_, UINT64_MAX, semaphore, VK_NULL_HANDLE, &imageIndex); @@ -129,6 +145,9 @@ VkResult SwapchainService::AcquireNextImage(VkSemaphore semaphore, uint32_t& ima VkResult SwapchainService::Present(const std::vector& waitSemaphores, uint32_t imageIndex) { + logger_->Trace("SwapchainService", "Present", + "waitSemaphores.size=" + std::to_string(waitSemaphores.size()) + + ", imageIndex=" + std::to_string(imageIndex)); auto presentQueue = deviceService_->GetPresentQueue(); VkPresentInfoKHR presentInfo{}; @@ -143,7 +162,7 @@ VkResult SwapchainService::Present(const std::vector& waitSemaphore } void SwapchainService::CreateImageViews() { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "CreateImageViews"); auto device = deviceService_->GetDevice(); @@ -169,7 +188,7 @@ void SwapchainService::CreateImageViews() { } void SwapchainService::CreateRenderPass() { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "CreateRenderPass"); auto device = deviceService_->GetDevice(); @@ -215,7 +234,7 @@ void SwapchainService::CreateRenderPass() { } void SwapchainService::CreateFramebuffers() { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "CreateFramebuffers"); auto device = deviceService_->GetDevice(); @@ -239,7 +258,7 @@ void SwapchainService::CreateFramebuffers() { } void SwapchainService::CleanupSwapchainInternal() { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "CleanupSwapchainInternal"); auto device = deviceService_->GetDevice(); @@ -265,16 +284,20 @@ void SwapchainService::CleanupSwapchainInternal() { } void SwapchainService::CleanupSwapchain() { + logger_->Trace("SwapchainService", "CleanupSwapchain"); CleanupSwapchainInternal(); } void SwapchainService::Shutdown() noexcept { + logger_->Trace("SwapchainService", "Shutdown"); CleanupSwapchainInternal(); } SwapchainService::SwapchainSupportDetails SwapchainService::QuerySwapchainSupport( VkPhysicalDevice device, VkSurfaceKHR surface) { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "QuerySwapchainSupport", + "deviceIsNull=" + std::string(device == VK_NULL_HANDLE ? "true" : "false") + + ", surfaceIsNull=" + std::string(surface == VK_NULL_HANDLE ? "true" : "false")); SwapchainSupportDetails details; vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities); @@ -299,7 +322,8 @@ SwapchainService::SwapchainSupportDetails SwapchainService::QuerySwapchainSuppor VkSurfaceFormatKHR SwapchainService::ChooseSurfaceFormat( const std::vector& availableFormats) { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "ChooseSurfaceFormat", + "availableFormats.size=" + std::to_string(availableFormats.size())); for (const auto& availableFormat : availableFormats) { if (availableFormat.format == VK_FORMAT_B8G8R8A8_SRGB && @@ -312,7 +336,8 @@ VkSurfaceFormatKHR SwapchainService::ChooseSurfaceFormat( VkPresentModeKHR SwapchainService::ChoosePresentMode( const std::vector& availablePresentModes) { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "ChoosePresentMode", + "availablePresentModes.size=" + std::to_string(availablePresentModes.size())); for (const auto& availablePresentMode : availablePresentModes) { if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) { @@ -324,6 +349,13 @@ VkPresentModeKHR SwapchainService::ChoosePresentMode( VkExtent2D SwapchainService::ChooseExtent(const VkSurfaceCapabilitiesKHR& capabilities, uint32_t width, uint32_t height) { + logger_->Trace("SwapchainService", "ChooseExtent", + "width=" + std::to_string(width) + + ", height=" + std::to_string(height) + + ", minWidth=" + std::to_string(capabilities.minImageExtent.width) + + ", minHeight=" + std::to_string(capabilities.minImageExtent.height) + + ", maxWidth=" + std::to_string(capabilities.maxImageExtent.width) + + ", maxHeight=" + std::to_string(capabilities.maxImageExtent.height)); return VkExtent2D{ std::clamp(width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width), std::clamp(height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height) @@ -331,7 +363,8 @@ VkExtent2D SwapchainService::ChooseExtent(const VkSurfaceCapabilitiesKHR& capabi } void SwapchainService::OnWindowResized(const events::Event& event) { - logger_->TraceFunction(__func__); + logger_->Trace("SwapchainService", "OnWindowResized", + "eventType=" + std::to_string(static_cast(event.type))); logger_->Info("Window resized event received, swapchain recreation needed"); } diff --git a/src/services/impl/swapchain_service.hpp b/src/services/impl/swapchain_service.hpp index a5c3960..f274cfc 100644 --- a/src/services/impl/swapchain_service.hpp +++ b/src/services/impl/swapchain_service.hpp @@ -34,13 +34,34 @@ public: VkResult Present(const std::vector& waitSemaphores, uint32_t imageIndex) override; - VkSwapchainKHR GetSwapchain() const override { return swapchain_; } - const std::vector& GetSwapchainImages() const override { return images_; } - const std::vector& GetSwapchainImageViews() const override { return imageViews_; } - const std::vector& GetSwapchainFramebuffers() const override { return framebuffers_; } - VkFormat GetSwapchainImageFormat() const override { return imageFormat_; } - VkExtent2D GetSwapchainExtent() const override { return extent_; } - VkRenderPass GetRenderPass() const override { return renderPass_; } + VkSwapchainKHR GetSwapchain() const override { + logger_->Trace("SwapchainService", "GetSwapchain"); + return swapchain_; + } + const std::vector& GetSwapchainImages() const override { + logger_->Trace("SwapchainService", "GetSwapchainImages"); + return images_; + } + const std::vector& GetSwapchainImageViews() const override { + logger_->Trace("SwapchainService", "GetSwapchainImageViews"); + return imageViews_; + } + const std::vector& GetSwapchainFramebuffers() const override { + logger_->Trace("SwapchainService", "GetSwapchainFramebuffers"); + return framebuffers_; + } + VkFormat GetSwapchainImageFormat() const override { + logger_->Trace("SwapchainService", "GetSwapchainImageFormat"); + return imageFormat_; + } + VkExtent2D GetSwapchainExtent() const override { + logger_->Trace("SwapchainService", "GetSwapchainExtent"); + return extent_; + } + VkRenderPass GetRenderPass() const override { + logger_->Trace("SwapchainService", "GetRenderPass"); + return renderPass_; + } // IInitializable interface void Initialize() override; diff --git a/src/services/impl/vulkan_device_service.cpp b/src/services/impl/vulkan_device_service.cpp index e8972d2..a4b21a9 100644 --- a/src/services/impl/vulkan_device_service.cpp +++ b/src/services/impl/vulkan_device_service.cpp @@ -8,9 +8,16 @@ namespace sdl3cpp::services::impl { VulkanDeviceService::VulkanDeviceService(std::shared_ptr logger) - : logger_(logger) {} + : logger_(logger) { + if (logger_) { + logger_->Trace("VulkanDeviceService", "VulkanDeviceService"); + } +} VulkanDeviceService::~VulkanDeviceService() { + if (logger_) { + logger_->Trace("VulkanDeviceService", "~VulkanDeviceService"); + } if (device_ != VK_NULL_HANDLE) { Shutdown(); } @@ -18,7 +25,9 @@ VulkanDeviceService::~VulkanDeviceService() { void VulkanDeviceService::Initialize(const std::vector& deviceExtensions, bool enableValidationLayers) { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanDeviceService", "Initialize", + "deviceExtensions.size=" + std::to_string(deviceExtensions.size()) + + ", enableValidationLayers=" + std::string(enableValidationLayers ? "true" : "false")); deviceExtensions_ = deviceExtensions; validationLayersEnabled_ = enableValidationLayers; @@ -37,7 +46,8 @@ void VulkanDeviceService::Initialize(const std::vector& deviceExten } void VulkanDeviceService::CreateSurface(SDL_Window* window) { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanDeviceService", "CreateSurface", + "windowIsNull=" + std::string(window ? "false" : "true")); if (!window) { throw std::invalid_argument("Window cannot be null"); @@ -49,7 +59,8 @@ void VulkanDeviceService::CreateSurface(SDL_Window* window) { } void VulkanDeviceService::CreateInstance(const std::vector& requiredExtensions) { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanDeviceService", "CreateInstance", + "requiredExtensions.size=" + std::to_string(requiredExtensions.size())); // Check Vulkan availability uint32_t apiVersion = 0; @@ -112,7 +123,7 @@ void VulkanDeviceService::CreateInstance(const std::vector& require } void VulkanDeviceService::PickPhysicalDevice() { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanDeviceService", "PickPhysicalDevice"); uint32_t deviceCount = 0; VkResult enumResult = vkEnumeratePhysicalDevices(instance_, &deviceCount, nullptr); @@ -146,6 +157,8 @@ void VulkanDeviceService::PickPhysicalDevice() { } bool VulkanDeviceService::IsDeviceSuitable(VkPhysicalDevice device) const { + logger_->Trace("VulkanDeviceService", "IsDeviceSuitable", + "deviceIsNull=" + std::string(device == VK_NULL_HANDLE ? "true" : "false")); QueueFamilyIndices indices = FindQueueFamilies(device); bool extensionsSupported = CheckDeviceExtensionSupport(device); @@ -168,6 +181,8 @@ bool VulkanDeviceService::IsDeviceSuitable(VkPhysicalDevice device) const { } QueueFamilyIndices VulkanDeviceService::FindQueueFamilies(VkPhysicalDevice device) const { + logger_->Trace("VulkanDeviceService", "FindQueueFamilies", + "deviceIsNull=" + std::string(device == VK_NULL_HANDLE ? "true" : "false")); QueueFamilyIndices indices; uint32_t queueFamilyCount = 0; @@ -196,6 +211,8 @@ QueueFamilyIndices VulkanDeviceService::FindQueueFamilies(VkPhysicalDevice devic } bool VulkanDeviceService::CheckDeviceExtensionSupport(VkPhysicalDevice device) const { + logger_->Trace("VulkanDeviceService", "CheckDeviceExtensionSupport", + "deviceIsNull=" + std::string(device == VK_NULL_HANDLE ? "true" : "false")); uint32_t extensionCount; vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr); @@ -212,7 +229,7 @@ bool VulkanDeviceService::CheckDeviceExtensionSupport(VkPhysicalDevice device) c } void VulkanDeviceService::CreateLogicalDevice() { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanDeviceService", "CreateLogicalDevice"); QueueFamilyIndices indices = FindQueueFamilies(physicalDevice_); @@ -249,6 +266,7 @@ void VulkanDeviceService::CreateLogicalDevice() { } void VulkanDeviceService::Shutdown() noexcept { + logger_->Trace("VulkanDeviceService", "Shutdown"); if (device_ != VK_NULL_HANDLE) { vkDestroyDevice(device_, nullptr); device_ = VK_NULL_HANDLE; @@ -266,17 +284,22 @@ void VulkanDeviceService::Shutdown() noexcept { } void VulkanDeviceService::WaitIdle() { + logger_->Trace("VulkanDeviceService", "WaitIdle"); if (device_ != VK_NULL_HANDLE) { vkDeviceWaitIdle(device_); } } QueueFamilyIndices VulkanDeviceService::GetQueueFamilies() const { + logger_->Trace("VulkanDeviceService", "GetQueueFamilies"); return FindQueueFamilies(physicalDevice_); } uint32_t VulkanDeviceService::FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties) const { + logger_->Trace("VulkanDeviceService", "FindMemoryType", + "typeFilter=" + std::to_string(typeFilter) + + ", properties=" + std::to_string(static_cast(properties))); VkPhysicalDeviceMemoryProperties memProperties; vkGetPhysicalDeviceMemoryProperties(physicalDevice_, &memProperties); diff --git a/src/services/impl/vulkan_device_service.hpp b/src/services/impl/vulkan_device_service.hpp index 5a358d0..f927a0d 100644 --- a/src/services/impl/vulkan_device_service.hpp +++ b/src/services/impl/vulkan_device_service.hpp @@ -29,12 +29,30 @@ public: void Shutdown() noexcept override; void WaitIdle() override; - VkInstance GetInstance() const override { return instance_; } - VkSurfaceKHR GetSurface() const override { return surface_; } - VkPhysicalDevice GetPhysicalDevice() const override { return physicalDevice_; } - VkDevice GetDevice() const override { return device_; } - VkQueue GetGraphicsQueue() const override { return graphicsQueue_; } - VkQueue GetPresentQueue() const override { return presentQueue_; } + VkInstance GetInstance() const override { + logger_->Trace("VulkanDeviceService", "GetInstance"); + return instance_; + } + VkSurfaceKHR GetSurface() const override { + logger_->Trace("VulkanDeviceService", "GetSurface"); + return surface_; + } + VkPhysicalDevice GetPhysicalDevice() const override { + logger_->Trace("VulkanDeviceService", "GetPhysicalDevice"); + return physicalDevice_; + } + VkDevice GetDevice() const override { + logger_->Trace("VulkanDeviceService", "GetDevice"); + return device_; + } + VkQueue GetGraphicsQueue() const override { + logger_->Trace("VulkanDeviceService", "GetGraphicsQueue"); + return graphicsQueue_; + } + VkQueue GetPresentQueue() const override { + logger_->Trace("VulkanDeviceService", "GetPresentQueue"); + return presentQueue_; + } QueueFamilyIndices GetQueueFamilies() const override; uint32_t FindMemoryType(uint32_t typeFilter, diff --git a/src/services/impl/vulkan_gui_service.cpp b/src/services/impl/vulkan_gui_service.cpp index fa5fc7c..334e0fb 100644 --- a/src/services/impl/vulkan_gui_service.cpp +++ b/src/services/impl/vulkan_gui_service.cpp @@ -8,9 +8,16 @@ VulkanGuiService::VulkanGuiService(std::shared_ptr logger, std::shared_ptr rendererService) : logger_(std::move(logger)), rendererService_(std::move(rendererService)) { + if (logger_) { + logger_->Trace("VulkanGuiService", "VulkanGuiService", + "rendererService=" + std::string(rendererService_ ? "set" : "null")); + } } VulkanGuiService::~VulkanGuiService() { + if (logger_) { + logger_->Trace("VulkanGuiService", "~VulkanGuiService"); + } if (initialized_) { Shutdown(); } @@ -20,7 +27,11 @@ void VulkanGuiService::Initialize(VkDevice device, VkPhysicalDevice physicalDevice, VkFormat format, const std::filesystem::path& resourcePath) { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanGuiService", "Initialize", + "deviceIsNull=" + std::string(device == VK_NULL_HANDLE ? "true" : "false") + + ", physicalDeviceIsNull=" + std::string(physicalDevice == VK_NULL_HANDLE ? "true" : "false") + + ", format=" + std::to_string(static_cast(format)) + + ", resourcePath=" + resourcePath.string()); if (initialized_) { return; @@ -38,7 +49,10 @@ void VulkanGuiService::Initialize(VkDevice device, void VulkanGuiService::PrepareFrame(const std::vector& commands, uint32_t width, uint32_t height) { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanGuiService", "PrepareFrame", + "commands.size=" + std::to_string(commands.size()) + + ", width=" + std::to_string(width) + + ", height=" + std::to_string(height)); if (!rendererService_) { throw std::runtime_error("GUI renderer service not available"); @@ -47,7 +61,9 @@ void VulkanGuiService::PrepareFrame(const std::vector& commands, } void VulkanGuiService::RenderToSwapchain(VkCommandBuffer commandBuffer, VkImage image) { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanGuiService", "RenderToSwapchain", + "commandBufferIsNull=" + std::string(commandBuffer == VK_NULL_HANDLE ? "true" : "false") + + ", imageIsNull=" + std::string(image == VK_NULL_HANDLE ? "true" : "false")); if (!rendererService_) { throw std::runtime_error("GUI renderer service not available"); @@ -57,7 +73,10 @@ void VulkanGuiService::RenderToSwapchain(VkCommandBuffer commandBuffer, VkImage } void VulkanGuiService::Resize(uint32_t width, uint32_t height, VkFormat format) { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanGuiService", "Resize", + "width=" + std::to_string(width) + + ", height=" + std::to_string(height) + + ", format=" + std::to_string(static_cast(format))); if (rendererService_) { rendererService_->Resize(width, height, format); @@ -65,7 +84,7 @@ void VulkanGuiService::Resize(uint32_t width, uint32_t height, VkFormat format) } void VulkanGuiService::Shutdown() noexcept { - logger_->TraceFunction(__func__); + logger_->Trace("VulkanGuiService", "Shutdown"); if (!initialized_) { return;