mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 13:44:58 +00:00
feat: Add IRenderCoordinatorService to ApplicationLoopService and update ProcessFrame method
This commit is contained in:
@@ -339,6 +339,7 @@ void ServiceBasedApp::RegisterServices() {
|
||||
registry_.GetService<services::IInputService>(),
|
||||
registry_.GetService<services::IPhysicsService>(),
|
||||
registry_.GetService<services::ISceneService>(),
|
||||
registry_.GetService<services::IRenderCoordinatorService>(),
|
||||
registry_.GetService<services::IAudioService>());
|
||||
|
||||
logger_->Trace("ServiceBasedApp", "RegisterServices", "", "Exiting");
|
||||
|
||||
@@ -10,6 +10,7 @@ ApplicationLoopService::ApplicationLoopService(std::shared_ptr<ILogger> logger,
|
||||
std::shared_ptr<IInputService> inputService,
|
||||
std::shared_ptr<IPhysicsService> physicsService,
|
||||
std::shared_ptr<ISceneService> sceneService,
|
||||
std::shared_ptr<IRenderCoordinatorService> renderCoordinatorService,
|
||||
std::shared_ptr<IAudioService> audioService)
|
||||
: logger_(std::move(logger)),
|
||||
windowService_(std::move(windowService)),
|
||||
@@ -17,6 +18,7 @@ ApplicationLoopService::ApplicationLoopService(std::shared_ptr<ILogger> 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<ILogger> 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<float>(currentTime - lastTime).count();
|
||||
float elapsedTime = std::chrono::duration<float>(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();
|
||||
}
|
||||
|
||||
@@ -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<IInputService> inputService,
|
||||
std::shared_ptr<IPhysicsService> physicsService,
|
||||
std::shared_ptr<ISceneService> sceneService,
|
||||
std::shared_ptr<IRenderCoordinatorService> renderCoordinatorService,
|
||||
std::shared_ptr<IAudioService> 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<ILogger> logger_;
|
||||
std::shared_ptr<IWindowService> windowService_;
|
||||
@@ -35,6 +37,7 @@ private:
|
||||
std::shared_ptr<IInputService> inputService_;
|
||||
std::shared_ptr<IPhysicsService> physicsService_;
|
||||
std::shared_ptr<ISceneService> sceneService_;
|
||||
std::shared_ptr<IRenderCoordinatorService> renderCoordinatorService_;
|
||||
std::shared_ptr<IAudioService> audioService_;
|
||||
bool running_ = false;
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user