Add Platform::CreateMainWindow

This commit is contained in:
Attila Uygun 2023-08-09 23:02:12 +02:00
parent eb50e547b8
commit 92dbf5cd97
4 changed files with 18 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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