Tweak closing android device

This commit is contained in:
Deve 2017-07-04 22:43:11 +02:00
parent f13f69851f
commit f672088a04
2 changed files with 36 additions and 38 deletions

View File

@ -35,7 +35,6 @@ namespace irr
bool CIrrDeviceAndroid::IsPaused = true; bool CIrrDeviceAndroid::IsPaused = true;
bool CIrrDeviceAndroid::IsFocused = false; bool CIrrDeviceAndroid::IsFocused = false;
bool CIrrDeviceAndroid::IsStarted = false; bool CIrrDeviceAndroid::IsStarted = false;
bool CIrrDeviceAndroid::IsClosing = false;
//! constructor //! constructor
CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param) CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
@ -49,13 +48,22 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
#endif #endif
Android = (android_app *)(param.PrivateData); Android = (android_app *)(param.PrivateData);
assert(Android != NULL);
IsClosing = Android->destroyRequested;
Android->userData = this; Android->userData = this;
Android->onAppCmd = handleAndroidCommand; Android->onAppCmd = handleAndroidCommand;
Android->onInputEvent = handleInput; Android->onInputEvent = handleInput;
createKeyMap();
CursorControl = new CCursorControl();
Close = Android->destroyRequested;
// It typically shouldn't happen, but just in case...
if (Close)
return;
SensorManager = ASensorManager_getInstance(); SensorManager = ASensorManager_getInstance();
SensorEventQueue = ASensorManager_createEventQueue(SensorManager, SensorEventQueue = ASensorManager_createEventQueue(SensorManager,
Android->looper, LOOPER_ID_USER, NULL, NULL); Android->looper, LOOPER_ID_USER, NULL, NULL);
@ -64,14 +72,9 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
AWINDOW_FLAG_KEEP_SCREEN_ON | AWINDOW_FLAG_KEEP_SCREEN_ON |
AWINDOW_FLAG_FULLSCREEN, 0); AWINDOW_FLAG_FULLSCREEN, 0);
createKeyMap();
// Create cursor control
CursorControl = new CCursorControl();
os::Printer::log("Waiting for Android activity window to be created.", ELL_DEBUG); os::Printer::log("Waiting for Android activity window to be created.", ELL_DEBUG);
while ((!IsStarted || !IsFocused || IsPaused) && !IsClosing) while (!IsStarted || !IsFocused || IsPaused)
{ {
s32 events = 0; s32 events = 0;
android_poll_source* source = 0; android_poll_source* source = 0;
@ -101,6 +104,8 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
CIrrDeviceAndroid::~CIrrDeviceAndroid() CIrrDeviceAndroid::~CIrrDeviceAndroid()
{ {
Android->userData = NULL; Android->userData = NULL;
Android->onAppCmd = NULL;
Android->onInputEvent = NULL;
} }
void CIrrDeviceAndroid::createVideoModeList() void CIrrDeviceAndroid::createVideoModeList()
@ -160,11 +165,11 @@ bool CIrrDeviceAndroid::run()
{ {
os::Timer::tick(); os::Timer::tick();
while (!IsClosing) while (!Close)
{ {
s32 Events = 0; s32 Events = 0;
android_poll_source* Source = 0; android_poll_source* Source = 0;
bool should_run = (IsStarted && IsFocused && !IsPaused) || IsClosing; bool should_run = (IsStarted && IsFocused && !IsPaused);
s32 id = ALooper_pollAll(should_run ? 0 : -1, NULL, &Events, s32 id = ALooper_pollAll(should_run ? 0 : -1, NULL, &Events,
(void**)&Source); (void**)&Source);
@ -210,7 +215,7 @@ bool CIrrDeviceAndroid::run()
} }
} }
return !IsClosing; return !Close;
} }
void CIrrDeviceAndroid::yield() void CIrrDeviceAndroid::yield()
@ -263,6 +268,7 @@ bool CIrrDeviceAndroid::isWindowMinimized() const
void CIrrDeviceAndroid::closeDevice() void CIrrDeviceAndroid::closeDevice()
{ {
Close = true;
} }
void CIrrDeviceAndroid::setResizable(bool resize) void CIrrDeviceAndroid::setResizable(bool resize)
@ -289,6 +295,7 @@ E_DEVICE_TYPE CIrrDeviceAndroid::getType() const
void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd) void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
{ {
CIrrDeviceAndroid* device = (CIrrDeviceAndroid *)app->userData; CIrrDeviceAndroid* device = (CIrrDeviceAndroid *)app->userData;
assert(device != NULL);
switch (cmd) switch (cmd)
{ {
@ -298,8 +305,6 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
case APP_CMD_INIT_WINDOW: case APP_CMD_INIT_WINDOW:
os::Printer::log("Android command APP_CMD_INIT_WINDOW", ELL_DEBUG); os::Printer::log("Android command APP_CMD_INIT_WINDOW", ELL_DEBUG);
if (device != NULL)
{
device->getExposedVideoData().OGLESAndroid.Window = app->window; device->getExposedVideoData().OGLESAndroid.Window = app->window;
// If the Android app is resumed, we need to re-create EGL surface // If the Android app is resumed, we need to re-create EGL surface
@ -310,7 +315,6 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
video::COGLES2Driver* driver = (video::COGLES2Driver*)(device->VideoDriver); video::COGLES2Driver* driver = (video::COGLES2Driver*)(device->VideoDriver);
driver->getEGLContext()->reloadEGLSurface(app->window); driver->getEGLContext()->reloadEGLSurface(app->window);
} }
}
IsStarted = true; IsStarted = true;
break; break;
@ -328,7 +332,7 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
break; break;
case APP_CMD_DESTROY: case APP_CMD_DESTROY:
os::Printer::log("Android command APP_CMD_DESTROY", ELL_DEBUG); os::Printer::log("Android command APP_CMD_DESTROY", ELL_DEBUG);
IsClosing = true; device->Close = true;
// Make sure that state variables are set to the default state // Make sure that state variables are set to the default state
// when the app is destroyed // when the app is destroyed
IsPaused = true; IsPaused = true;
@ -362,25 +366,20 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
break; break;
} }
if (device != NULL)
{
SEvent event; SEvent event;
event.EventType = EET_SYSTEM_EVENT; event.EventType = EET_SYSTEM_EVENT;
event.SystemEvent.EventType = ESET_ANDROID_CMD; event.SystemEvent.EventType = ESET_ANDROID_CMD;
event.SystemEvent.AndroidCmd.Cmd = cmd; event.SystemEvent.AndroidCmd.Cmd = cmd;
device->postEventFromUser(event); device->postEventFromUser(event);
}
} }
s32 CIrrDeviceAndroid::handleInput(android_app* app, AInputEvent* androidEvent) s32 CIrrDeviceAndroid::handleInput(android_app* app, AInputEvent* androidEvent)
{ {
CIrrDeviceAndroid* device = (CIrrDeviceAndroid*)app->userData; CIrrDeviceAndroid* device = (CIrrDeviceAndroid*)app->userData;
assert(device != NULL);
s32 status = 0; s32 status = 0;
if (device == NULL)
return status;
switch (AInputEvent_getType(androidEvent)) switch (AInputEvent_getType(androidEvent))
{ {
case AINPUT_EVENT_TYPE_MOTION: case AINPUT_EVENT_TYPE_MOTION:

View File

@ -103,7 +103,6 @@ namespace irr
static bool IsPaused; static bool IsPaused;
static bool IsFocused; static bool IsFocused;
static bool IsStarted; static bool IsStarted;
static bool IsClosing;
bool IsMousePressed; bool IsMousePressed;