Add Platform::CreateMainWindow

This commit is contained in:
Attila Uygun 2023-08-09 23:02:12 +02:00 committed by Attila Uygun
parent 8503c549d7
commit 6e952e511e
4 changed files with 22 additions and 13 deletions

View File

@ -108,6 +108,8 @@ void Engine::Initialize() {
thread_pool_.Initialize();
platform_->CreateMainWindow();
CreateRendererInternal(RendererType::kVulkan);
CreateProjectionMatrix();
@ -485,6 +487,7 @@ bool Engine::IsMobile() const {
}
void Engine::OnWindowCreated() {
if (renderer_)
renderer_->Initialize(platform_);
}
@ -493,8 +496,8 @@ void Engine::OnWindowDestroyed() {
}
void Engine::OnWindowResized(int width, int height) {
if (width != renderer_->GetScreenWidth() ||
height != renderer_->GetScreenHeight()) {
if (renderer_ && (width != renderer_->GetScreenWidth() ||
height != renderer_->GetScreenHeight())) {
renderer_->OnWindowResized(width, height);
CreateProjectionMatrix();
}

View File

@ -31,6 +31,8 @@ class Platform {
#endif
~Platform();
void CreateMainWindow();
void Update();
void Exit();

View File

@ -292,20 +292,18 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
DLOG(0) << "APP_CMD_INIT_WINDOW";
if (app->window != NULL) {
platform->SetFrameRate(60);
if (platform->observer_)
platform->observer_->OnWindowCreated();
}
break;
case APP_CMD_TERM_WINDOW:
DLOG(0) << "APP_CMD_TERM_WINDOW";
if (platform->observer_)
platform->observer_->OnWindowDestroyed();
break;
case APP_CMD_CONFIG_CHANGED:
DLOG(0) << "APP_CMD_CONFIG_CHANGED";
if (platform->app_->window != NULL && platform->observer_)
if (platform->app_->window != NULL)
platform->observer_->OnWindowResized(
ANativeWindow_getWidth(app->window),
ANativeWindow_getHeight(app->window));
@ -319,7 +317,6 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
DLOG(0) << "APP_CMD_GAINED_FOCUS";
// platform->timer_.Reset();
platform->has_focus_ = true;
if (platform->observer_)
platform->observer_->GainedFocus(g_showing_interstitial_ad);
g_showing_interstitial_ad = false;
break;
@ -327,7 +324,6 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
case APP_CMD_LOST_FOCUS:
DLOG(0) << "APP_CMD_LOST_FOCUS";
platform->has_focus_ = false;
if (platform->observer_)
platform->observer_->LostFocus();
break;
@ -370,8 +366,12 @@ Platform::Platform(android_app* app) {
reinterpret_cast<PFN_ANativeWindow_setFrameRateWithChangeStrategy>(
dlsym(mLibAndroid, "ANativeWindow_setFrameRateWithChangeStrategy"));
}
}
void Platform::CreateMainWindow() {
DCHECK(!app_->window);
Update();
DCHECK(app_->window);
}
Platform::~Platform() {

View File

@ -39,7 +39,9 @@ Platform::Platform() {
LOG(0) << "Root path: " << root_path_.c_str();
LOG(0) << "Data path: " << data_path_.c_str();
LOG(0) << "Shared data path: " << shared_data_path_.c_str();
}
void Platform::CreateMainWindow() {
bool res = CreateWindow(800, 1205);
CHECK(res) << "Failed to create window.";
@ -103,8 +105,10 @@ void Platform::Update() {
}
case ClientMessage: {
// WM_DELETE_WINDOW is the only registered type for now.
observer_->OnWindowDestroyed();
DestroyWindow();
should_exit_ = true;
break;
return;
}
case ConfigureNotify: {
XConfigureEvent xce = e.xconfigure;