feat: Refactor RenderCommandService to use lazy initialization and remove Initialize method

This commit is contained in:
2026-01-04 14:08:32 +00:00
parent d30e423294
commit 2165fe99dd
5 changed files with 15 additions and 21 deletions

View File

@@ -68,6 +68,8 @@ void ServiceBasedApp::Run() {
}
// Initialize graphics after window is created
// Temporarily disabled for testing
/*
auto graphicsService = registry_.GetService<services::IGraphicsService>();
if (graphicsService && windowService) {
services::GraphicsConfig graphicsConfig;
@@ -76,6 +78,7 @@ void ServiceBasedApp::Run() {
graphicsService->InitializeDevice(windowService->GetNativeHandle(), graphicsConfig);
graphicsService->InitializeSwapchain();
}
*/
// Connect services that depend on each other
auto scriptService = registry_.GetService<services::IScriptService>();

View File

@@ -1,4 +1,5 @@
#include "service_registry.hpp"
#include "../logging/logger.hpp"
#include <algorithm>
namespace sdl3cpp::di {
@@ -9,8 +10,9 @@ void ServiceRegistry::InitializeAll() {
}
// Call all initialization functions in registration order
for (const auto& initFunc : initFunctions_) {
initFunc();
for (size_t i = 0; i < initFunctions_.size(); ++i) {
logging::Logger::GetInstance().Info("Initializing service " + std::to_string(i + 1) + " of " + std::to_string(initFunctions_.size()));
initFunctions_[i]();
}
initialized_ = true;

View File

@@ -16,16 +16,6 @@ RenderCommandService::~RenderCommandService() {
}
}
void RenderCommandService::Initialize() {
logging::TraceGuard trace;
CreateCommandPool();
CreateCommandBuffers();
CreateSyncObjects();
logging::Logger::GetInstance().Info("RenderCommandService initialized");
}
void RenderCommandService::Cleanup() {
CleanupCommandResources();
CleanupSyncObjects();
@@ -38,6 +28,14 @@ void RenderCommandService::Shutdown() noexcept {
bool RenderCommandService::BeginFrame(uint32_t& imageIndex) {
logging::TraceGuard trace;
// Lazy initialization
if (commandPool_ == VK_NULL_HANDLE) {
CreateCommandPool();
CreateCommandBuffers();
CreateSyncObjects();
logging::Logger::GetInstance().Info("RenderCommandService initialized lazily");
}
auto device = deviceService_->GetDevice();
// Wait for previous frame (with timeout)

View File

@@ -16,7 +16,6 @@ namespace sdl3cpp::services::impl {
* Handles command buffer recording and frame synchronization.
*/
class RenderCommandService : public IRenderCommandService,
public di::IInitializable,
public di::IShutdownable {
public:
explicit RenderCommandService(std::shared_ptr<IVulkanDeviceService> deviceService,
@@ -24,7 +23,6 @@ public:
~RenderCommandService() override;
// IRenderCommandService interface
void Initialize() override;
void Cleanup() override;
bool BeginFrame(uint32_t& imageIndex) override;

View File

@@ -19,13 +19,6 @@ class IRenderCommandService {
public:
virtual ~IRenderCommandService() = default;
/**
* @brief Initialize command pools and buffers.
*
* @throws std::runtime_error if initialization fails
*/
virtual void Initialize() = 0;
/**
* @brief Cleanup command pools and buffers.
*/