make it possible to create set app for GraphicsAppManager in deferred mode
This commit is contained in:
@@ -19,6 +19,8 @@ using namespace OpenVulkano;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
GraphicsAppManager manager;
|
||||
|
||||
std::vector<std::string> examples;
|
||||
for (const auto& e : EXAMPLE_APPS)
|
||||
{
|
||||
@@ -36,8 +38,7 @@ int main(int argc, char** argv)
|
||||
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");
|
||||
|
||||
std::unique_ptr<IGraphicsApp> app( EXAMPLE_APPS[selectedExample].second() );
|
||||
|
||||
GraphicsAppManager manager(app.get());
|
||||
manager.SetApp(app.get());
|
||||
manager.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -24,65 +24,64 @@ namespace OpenVulkano
|
||||
{
|
||||
using clock = std::chrono::steady_clock;
|
||||
|
||||
GraphicsAppManager::GraphicsAppManager(RenderAPI::RenderApi renderApi) { Init(nullptr, nullptr, renderApi); }
|
||||
|
||||
GraphicsAppManager::GraphicsAppManager(OpenVulkano::IGraphicsApp* app, RenderAPI::RenderApi renderApi)
|
||||
: app(app), renderApi(renderApi)
|
||||
{
|
||||
Utils::SetThreadName("Main");
|
||||
#ifdef HAS_TRACY
|
||||
ZoneScoped;
|
||||
#endif
|
||||
|
||||
|
||||
Logger::SetupLogger();
|
||||
if (!app)
|
||||
{
|
||||
constexpr auto msg = "The app must not be null!";
|
||||
Logger::MANAGER->error(msg);
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
platform = std::unique_ptr<IPlatform>(PlatformProducer::CreatePlatform(renderApi));
|
||||
window = platform->MakeWindow();
|
||||
renderer = std::unique_ptr<IRenderer>(PlatformProducer::CreateRenderManager(renderApi));
|
||||
app->SetGraphicsAppManager(this);
|
||||
window->SetWindowHandler(this);
|
||||
inputManager = Input::InputManager::GetInstance();
|
||||
engineConfig = EngineConfiguration::GetEngineConfiguration();
|
||||
engineConfig->OnFpsCapChanged += EventHandler(this, &GraphicsAppManager::UpdateCappedFpsInfo);
|
||||
// set initial values
|
||||
if (engineConfig->GetFpsCap() > 0)
|
||||
{
|
||||
UpdateCappedFpsInfo(engineConfig->GetFpsCap());
|
||||
}
|
||||
Init(app, nullptr, renderApi);
|
||||
}
|
||||
|
||||
GraphicsAppManager::GraphicsAppManager(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi)
|
||||
: app(app), renderApi(renderApi)
|
||||
{
|
||||
Init(app, window, renderApi);
|
||||
}
|
||||
|
||||
void GraphicsAppManager::SetApp(IGraphicsApp* app)
|
||||
{
|
||||
this->app = app;
|
||||
app->SetGraphicsAppManager(this);
|
||||
}
|
||||
|
||||
void GraphicsAppManager::Init(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi)
|
||||
{
|
||||
Utils::SetThreadName("Main");
|
||||
#ifdef HAS_TRACY
|
||||
ZoneScoped;
|
||||
#endif
|
||||
|
||||
Logger::SetupLogger();
|
||||
if (!app)
|
||||
{
|
||||
constexpr auto msg = "The app must not be null!";
|
||||
Logger::MANAGER->error(msg);
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
//platform = std::unique_ptr<IPlatform>(PlatformProducer::CreatePlatform(renderApi));
|
||||
this->window = window;
|
||||
Logger::MANAGER->info("Initializing graphics app manager ...");
|
||||
this->renderApi = renderApi;
|
||||
platform = std::unique_ptr<IPlatform>(PlatformProducer::CreatePlatform(renderApi));
|
||||
renderer = std::unique_ptr<IRenderer>(PlatformProducer::CreateRenderManager(renderApi));
|
||||
app->SetGraphicsAppManager(this);
|
||||
window->SetWindowHandler(this);
|
||||
inputManager = OpenVulkano::Input::InputManager::GetInstance();
|
||||
engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
||||
inputManager = Input::InputManager::GetInstance();
|
||||
engineConfig = EngineConfiguration::GetEngineConfiguration();
|
||||
engineConfig->OnFpsCapChanged += EventHandler(this, &GraphicsAppManager::UpdateCappedFpsInfo);
|
||||
if (window)
|
||||
{
|
||||
this->window = window;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->window = platform->MakeWindow();
|
||||
}
|
||||
if (app)
|
||||
{
|
||||
app->SetGraphicsAppManager(this);
|
||||
}
|
||||
this->window->SetWindowHandler(this);
|
||||
|
||||
// set initial values
|
||||
if (engineConfig->GetFpsCap() > 0)
|
||||
{
|
||||
UpdateCappedFpsInfo(engineConfig->GetFpsCap());
|
||||
}
|
||||
if (platform)
|
||||
{
|
||||
platform->Init();
|
||||
}
|
||||
Logger::MANAGER->info("Initialized...");
|
||||
}
|
||||
|
||||
void GraphicsAppManager::UpdateCappedFpsInfo(int32_t newFpsCap)
|
||||
@@ -144,6 +143,12 @@ namespace OpenVulkano
|
||||
|
||||
void GraphicsAppManager::StartUp()
|
||||
{
|
||||
if (!app)
|
||||
{
|
||||
constexpr auto msg = "The app must not be null!";
|
||||
Logger::MANAGER->error(msg);
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
#ifdef HAS_TRACY
|
||||
ZoneScoped;
|
||||
#endif
|
||||
@@ -151,7 +156,9 @@ namespace OpenVulkano
|
||||
{
|
||||
Logger::MANAGER->info("Initializing ...");
|
||||
app->Init();
|
||||
if (platform) platform->Init();
|
||||
|
||||
//if (platform) platform->Init();
|
||||
|
||||
window->Init(renderApi);
|
||||
//TODO restore window settings if there are any set
|
||||
renderer->Init(static_cast<IGraphicsAppManager*>(this), window);
|
||||
|
||||
@@ -48,10 +48,17 @@ namespace OpenVulkano
|
||||
void OnCappedFPS(const auto& frameStartTime);
|
||||
void UpdateCappedFpsInfo(int32_t newFpsCap);
|
||||
public:
|
||||
|
||||
GraphicsAppManager(RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
||||
|
||||
explicit GraphicsAppManager(IGraphicsApp* app, RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
||||
|
||||
explicit GraphicsAppManager(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi = RenderAPI::Vulkan);
|
||||
|
||||
void SetApp(IGraphicsApp* app);
|
||||
|
||||
void Init(IGraphicsApp* app, IWindow* window, RenderAPI::RenderApi renderApi);
|
||||
|
||||
~GraphicsAppManager() noexcept override;
|
||||
|
||||
public: // Getter
|
||||
|
||||
Reference in New Issue
Block a user