diff --git a/src/app/service_based_app.cpp b/src/app/service_based_app.cpp index 049f49d..9ebe458 100644 --- a/src/app/service_based_app.cpp +++ b/src/app/service_based_app.cpp @@ -339,6 +339,7 @@ void ServiceBasedApp::RegisterServices() { registry_.GetService(), registry_.GetService(), registry_.GetService(), + registry_.GetService(), registry_.GetService()); logger_->Trace("ServiceBasedApp", "RegisterServices", "", "Exiting"); diff --git a/src/services/impl/application_loop_service.cpp b/src/services/impl/application_loop_service.cpp index 95759ec..b3d1ed0 100644 --- a/src/services/impl/application_loop_service.cpp +++ b/src/services/impl/application_loop_service.cpp @@ -10,6 +10,7 @@ ApplicationLoopService::ApplicationLoopService(std::shared_ptr logger, std::shared_ptr inputService, std::shared_ptr physicsService, std::shared_ptr sceneService, + std::shared_ptr renderCoordinatorService, std::shared_ptr audioService) : logger_(std::move(logger)), windowService_(std::move(windowService)), @@ -17,6 +18,7 @@ ApplicationLoopService::ApplicationLoopService(std::shared_ptr logger, inputService_(std::move(inputService)), physicsService_(std::move(physicsService)), sceneService_(std::move(sceneService)), + renderCoordinatorService_(std::move(renderCoordinatorService)), audioService_(std::move(audioService)) { if (logger_) { logger_->Trace("ApplicationLoopService", "ApplicationLoopService", @@ -25,6 +27,7 @@ ApplicationLoopService::ApplicationLoopService(std::shared_ptr logger, ", inputService=" + std::string(inputService_ ? "set" : "null") + ", physicsService=" + std::string(physicsService_ ? "set" : "null") + ", sceneService=" + std::string(sceneService_ ? "set" : "null") + + ", renderCoordinatorService=" + std::string(renderCoordinatorService_ ? "set" : "null") + ", audioService=" + std::string(audioService_ ? "set" : "null"), "Created"); } @@ -39,24 +42,16 @@ void ApplicationLoopService::Run() { running_ = true; auto lastTime = std::chrono::high_resolution_clock::now(); auto startTime = lastTime; - const auto timeout = std::chrono::seconds(5); while (running_) { auto currentTime = std::chrono::high_resolution_clock::now(); - if (currentTime - startTime > timeout) { - if (logger_) { - logger_->Info("ApplicationLoopService::Run: Timeout reached, exiting"); - } - running_ = false; - break; - } - float deltaTime = std::chrono::duration(currentTime - lastTime).count(); + float elapsedTime = std::chrono::duration(currentTime - startTime).count(); lastTime = currentTime; HandleEvents(); - ProcessFrame(deltaTime); + ProcessFrame(deltaTime, elapsedTime); } if (logger_) { @@ -82,9 +77,13 @@ void ApplicationLoopService::HandleEvents() { } } -void ApplicationLoopService::ProcessFrame(float deltaTime) { +void ApplicationLoopService::ProcessFrame(float deltaTime, float elapsedTime) { if (logger_) { - logger_->Trace("ApplicationLoopService", "ProcessFrame", "deltaTime=" + std::to_string(deltaTime), "Entering"); + logger_->Trace("ApplicationLoopService", "ProcessFrame", + "deltaTime=" + std::to_string(deltaTime) + + ", elapsedTime=" + std::to_string(elapsedTime) + + ", renderCoordinatorAvailable=" + std::string(renderCoordinatorService_ ? "true" : "false"), + "Entering"); } if (inputService_) { @@ -99,6 +98,10 @@ void ApplicationLoopService::ProcessFrame(float deltaTime) { sceneService_->UpdateScene(deltaTime); } + if (renderCoordinatorService_) { + renderCoordinatorService_->RenderFrame(elapsedTime); + } + if (audioService_) { audioService_->Update(); } diff --git a/src/services/impl/application_loop_service.hpp b/src/services/impl/application_loop_service.hpp index ff6fb21..bc7927b 100644 --- a/src/services/impl/application_loop_service.hpp +++ b/src/services/impl/application_loop_service.hpp @@ -5,6 +5,7 @@ #include "../interfaces/i_input_service.hpp" #include "../interfaces/i_logger.hpp" #include "../interfaces/i_physics_service.hpp" +#include "../interfaces/i_render_coordinator_service.hpp" #include "../interfaces/i_scene_service.hpp" #include "../interfaces/i_window_service.hpp" #include "../../events/i_event_bus.hpp" @@ -20,6 +21,7 @@ public: std::shared_ptr inputService, std::shared_ptr physicsService, std::shared_ptr sceneService, + std::shared_ptr renderCoordinatorService, std::shared_ptr audioService); ~ApplicationLoopService() override = default; @@ -27,7 +29,7 @@ public: private: void HandleEvents(); - void ProcessFrame(float deltaTime); + void ProcessFrame(float deltaTime, float elapsedTime); std::shared_ptr logger_; std::shared_ptr windowService_; @@ -35,6 +37,7 @@ private: std::shared_ptr inputService_; std::shared_ptr physicsService_; std::shared_ptr sceneService_; + std::shared_ptr renderCoordinatorService_; std::shared_ptr audioService_; bool running_ = false; }; diff --git a/src/services/impl/sdl_window_service.cpp b/src/services/impl/sdl_window_service.cpp index e68f260..5b5e3fe 100644 --- a/src/services/impl/sdl_window_service.cpp +++ b/src/services/impl/sdl_window_service.cpp @@ -220,7 +220,8 @@ void SdlWindowService::PollEvents() { PublishEvent(event); // Check for quit event - if (event.type == SDL_EVENT_QUIT) { + if (event.type == SDL_EVENT_QUIT || event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) { + logger_->Trace("SdlWindowService", "PollEvents", "closeRequested=true"); shouldClose_ = true; } } @@ -240,6 +241,7 @@ void SdlWindowService::PublishEvent(const SDL_Event& sdlEvent) { switch (sdlEvent.type) { case SDL_EVENT_QUIT: + case SDL_EVENT_WINDOW_CLOSE_REQUESTED: eventBus_->Publish(events::Event{ events::EventType::WindowClosed, timestamp,