WIP Android improve multi-window support

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
81
The games can't respond to Window resizes if they don't have focus (but are still visible) right now. It would be nice to be able to respond to it properly.

For now I did some edits to the AndroidGame class inside androidgame.java.

I moved these two lines from onWindowFocusChanged to onResume.
Code:
_view.onResume();
_game.ResumeGame();

and moved these two lines from onWindowFocusChanged to onStop.
Code:
_game.SuspendGame();
_view.onPause();

This should be added to the application tag in the manifest.
Code:
android:resizeableActivity="true"

With those edits: If the game is visible but not focused, it will still run. It will not stop unless the window is not visible to the user.

It may also be nice for games to be able to detect when they lose focus (but are still visible) so they can show pause menus.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,165
And this is a fundamental change which I think would break existing code. We have a flag that turns off the suspension of APPS that don't have the focus.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
912
With those edits: If the game is visible but not focused, it will still run. It will not stop unless the window is not visible to the user.

It may also be nice for games to be able to detect when they lose focus (but are still visible) so they can show pause menus.
This sounds interesting, does it behave different than #MOJO_AUTO_SUSPEND_ENABLED = False
I'm trying to wrap my head around this, what's the difference?
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
912
Come to think about it, this would be nice addition as I never actually succeeded at getting OnSuspend to work like Intended on Android. Having a possibility to save things before an app goes to sleep and to restore things when wakening up would be very helpful!
 

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
81
#MOJO_AUTO_SUSPEND_ENABLED didn't work for me on Android. My edits still suspend the game, but only when it's not visible. That way when the window is resized in split window mode the game can resize itself (even if it doesn't have focus). It would be on phones, tablets, and laptops. Ya, those edits will need to be tested and improved, but supporting multi-window mode will be nice (eventually it'll have to be supported).
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,165
Ya, those edits will need to be tested and improved, but supporting multi-window mode will be nice (eventually it'll have to be supported).
To bad, non of us have devices that can display multiple windows on Android. We only have phones. So it couldn't be supported by us.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,165
Ahhh that shitty feature which always pisses me off when I accidently and somehow activate this on an app. Would never ever want this for my game. But hell ya, your mileage may vary.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,165
Ok, I looked into the code. My findings so far:

#MOJO_AUTO_SUSPEND_ENABLED only works on GLFW and HTML5

That way when the window is resized in split window mode the game can resize itself (even if it doesn't have focus)
Use OnResize to determine the new DeviceWidth and DeviceHeight, works fine for me.

The rest I will look into more tomorrow evening.
 
Top Bottom