Tweak closing android device
This commit is contained in:
parent
f13f69851f
commit
f672088a04
@ -35,7 +35,6 @@ namespace irr
|
||||
bool CIrrDeviceAndroid::IsPaused = true;
|
||||
bool CIrrDeviceAndroid::IsFocused = false;
|
||||
bool CIrrDeviceAndroid::IsStarted = false;
|
||||
bool CIrrDeviceAndroid::IsClosing = false;
|
||||
|
||||
//! constructor
|
||||
CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
|
||||
@ -49,13 +48,22 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
|
||||
#endif
|
||||
|
||||
Android = (android_app *)(param.PrivateData);
|
||||
|
||||
IsClosing = Android->destroyRequested;
|
||||
assert(Android != NULL);
|
||||
|
||||
Android->userData = this;
|
||||
Android->onAppCmd = handleAndroidCommand;
|
||||
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();
|
||||
SensorEventQueue = ASensorManager_createEventQueue(SensorManager,
|
||||
Android->looper, LOOPER_ID_USER, NULL, NULL);
|
||||
@ -64,14 +72,9 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
|
||||
AWINDOW_FLAG_KEEP_SCREEN_ON |
|
||||
AWINDOW_FLAG_FULLSCREEN, 0);
|
||||
|
||||
createKeyMap();
|
||||
|
||||
// Create cursor control
|
||||
CursorControl = new CCursorControl();
|
||||
|
||||
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;
|
||||
android_poll_source* source = 0;
|
||||
@ -101,6 +104,8 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
|
||||
CIrrDeviceAndroid::~CIrrDeviceAndroid()
|
||||
{
|
||||
Android->userData = NULL;
|
||||
Android->onAppCmd = NULL;
|
||||
Android->onInputEvent = NULL;
|
||||
}
|
||||
|
||||
void CIrrDeviceAndroid::createVideoModeList()
|
||||
@ -160,11 +165,11 @@ bool CIrrDeviceAndroid::run()
|
||||
{
|
||||
os::Timer::tick();
|
||||
|
||||
while (!IsClosing)
|
||||
while (!Close)
|
||||
{
|
||||
s32 Events = 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,
|
||||
(void**)&Source);
|
||||
|
||||
@ -210,7 +215,7 @@ bool CIrrDeviceAndroid::run()
|
||||
}
|
||||
}
|
||||
|
||||
return !IsClosing;
|
||||
return !Close;
|
||||
}
|
||||
|
||||
void CIrrDeviceAndroid::yield()
|
||||
@ -263,6 +268,7 @@ bool CIrrDeviceAndroid::isWindowMinimized() const
|
||||
|
||||
void CIrrDeviceAndroid::closeDevice()
|
||||
{
|
||||
Close = true;
|
||||
}
|
||||
|
||||
void CIrrDeviceAndroid::setResizable(bool resize)
|
||||
@ -289,6 +295,7 @@ E_DEVICE_TYPE CIrrDeviceAndroid::getType() const
|
||||
void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
|
||||
{
|
||||
CIrrDeviceAndroid* device = (CIrrDeviceAndroid *)app->userData;
|
||||
assert(device != NULL);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@ -298,8 +305,6 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
|
||||
case APP_CMD_INIT_WINDOW:
|
||||
os::Printer::log("Android command APP_CMD_INIT_WINDOW", ELL_DEBUG);
|
||||
|
||||
if (device != NULL)
|
||||
{
|
||||
device->getExposedVideoData().OGLESAndroid.Window = app->window;
|
||||
|
||||
// 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);
|
||||
driver->getEGLContext()->reloadEGLSurface(app->window);
|
||||
}
|
||||
}
|
||||
|
||||
IsStarted = true;
|
||||
break;
|
||||
@ -328,7 +332,7 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
|
||||
break;
|
||||
case APP_CMD_DESTROY:
|
||||
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
|
||||
// when the app is destroyed
|
||||
IsPaused = true;
|
||||
@ -362,25 +366,20 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd)
|
||||
break;
|
||||
}
|
||||
|
||||
if (device != NULL)
|
||||
{
|
||||
SEvent event;
|
||||
event.EventType = EET_SYSTEM_EVENT;
|
||||
event.SystemEvent.EventType = ESET_ANDROID_CMD;
|
||||
event.SystemEvent.AndroidCmd.Cmd = cmd;
|
||||
device->postEventFromUser(event);
|
||||
}
|
||||
}
|
||||
|
||||
s32 CIrrDeviceAndroid::handleInput(android_app* app, AInputEvent* androidEvent)
|
||||
{
|
||||
CIrrDeviceAndroid* device = (CIrrDeviceAndroid*)app->userData;
|
||||
assert(device != NULL);
|
||||
|
||||
s32 status = 0;
|
||||
|
||||
if (device == NULL)
|
||||
return status;
|
||||
|
||||
|
||||
switch (AInputEvent_getType(androidEvent))
|
||||
{
|
||||
case AINPUT_EVENT_TYPE_MOTION:
|
||||
|
@ -103,7 +103,6 @@ namespace irr
|
||||
static bool IsPaused;
|
||||
static bool IsFocused;
|
||||
static bool IsStarted;
|
||||
static bool IsClosing;
|
||||
|
||||
bool IsMousePressed;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user