The International Simutrans Forum

 

Author Topic: [Android] Autodpi - display with correct ratio and appropriate zoom level  (Read 442 times)

0 Members and 1 Guest are viewing this topic.

Offline krosk

  • *
  • Posts: 38
  • Languages: EN,FR,ZH
Hello,

Patch applicable to r10061.

Simutrans was launched by default with argument -screensize 800x600, which is not appropriate.

Now, it does 3 things. Without -screensize argument:
- the resolution width is rounded to above the device max screen resolution, causing a crash. => The patch fixes the crash by disabling the rounding for Android
- the resolution defaults to the native resolution, which respects the device screen ratio so it is better looking for a default. => The patch removes the default -screensize argument, but you can set yourself a resolution of your choice if you want
- the native resolution is however quite high on a smartphone screen, so buttons and text are very small. => I backport the -autodpi argument to SDL1.2, which goal is to scale up the game played in a window so that it appears normal on very high dpi screens (retina screens for example). To reach the same experience on Android where there is no window and no support for scaling in SDL1.2; the patch is dividing screen resolution by a factor, while maintaining fullscreen, so it appears zoomed. The actual DPI of your device screen is unavailable, so the patch assumes an average DPI from the smartphone on the market. This auto-scaling can be disabled by removing -autodpi from starting arguments.

See https://imgur.com/a/9NTf7ue for the difference.
Above is with -screensize 800x600 (the previous default)
Middle is with -autodpi (the new default)
Below is without argument (so it displays at native resolution; unplayable with fingers, but manageable with a mouse)


Until we have SDL 2 support for Android, this is the closest I can think of getting automatically a correct display ratio.

I will comment as well that for mobile screen, we could use a 1080p high resolution (to display a lot of information) but only if we have super-sized buttons. On-screen buttons should be about 0.5cm to 1cm wide; On a 1080p 6inch 400dpi smartphone screen, that means a button should be more than 128 pixel, instead of the current 32 pixels. Maybe themes larger that the current "large size" is the future for mobile?

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [Android] Autodpi - display with correct ratio and appropriate zoom level
« Reply #1 on: September 02, 2021, 05:58:49 AM »
The rounding was needed for SDL to prevent crashing on other machines since 1366 for instance are not dividable by 16 and thus cause problems on blitting. (Actually, I am surprised the resizing works on Android ... )

The buttons can be much larger, but I think especially the default font needs to be larger. Since download size does not matter so much, I would suggest to distribute a different default font for Android (via freetype a TTF font). Assuming there is a roboto-font present, thenn adding
Code: [Select]
fontname=/system/fonts/Roboto-Medium.ttf
fontsize=20
or if this not work locally as res/font/filename.ttf apparently.

EDIT: I submitted this and some further patch to make a predefined font more useful. Also there is some language detection using std::locale, which may work even with SDL1.2 (maybe).
« Last Edit: September 02, 2021, 01:01:40 PM by prissi »

Offline krosk

  • *
  • Posts: 38
  • Languages: EN,FR,ZH
Re: [Android] Autodpi - display with correct ratio and appropriate zoom level
« Reply #2 on: September 11, 2021, 01:49:37 PM »
Another patch applicable to r10084.

* I experimented with ttf fonts on Android; I have not found information on a standard, accessible folder that contains standard fonts. For the time being, I propose to embed Roboto and Roboto-Condensed fonts as downloaded assets for android at build time, and they are found in the font list.
* The list of assets downloaded at build time on Android is growing (soundfont, fonts, ssl certificate, starter paks...) but it is a hardcoded list found on a fork of libsdl-android repository I maintain. It made sense to move this list of assets back to simutrans repo (in the form of a shell script in the folder android/add_assets.sh), so simutrans maintainers and community can customize the list of assets as they see fit..

Important note for the dev team: please add the file at https://curl.se/ca/cacert.pem in the folder <simutrans repo root>/android/, alongside <repo root>/android/add_assets.sh. I would have included it in the patch but the forum attachment limitation forbids me to (file too big). This is required for https calls to pass (for the in-game pakset download). I could have made the shell script download the file, but according to curl site they don't want us to download it often and it is more appropriate to store a copy of it ourselves.

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [Android] Autodpi - display with correct ratio and appropriate zoom level
« Reply #3 on: September 11, 2021, 02:55:03 PM »
Thank you, added in r10089

Offline krosk

  • *
  • Posts: 38
  • Languages: EN,FR,ZH
Re: [Android] Autodpi - display with correct ratio and appropriate zoom level
« Reply #4 on: September 11, 2021, 10:30:48 PM »
@prissi

Following the merge to r10089, I found out the nightly apk released on github did not start correctly. The root cause was on github actions, the below temporary failure to download the soundfont, creating a soundfont file of size zero and then the build would silently pass. Simutrans would crash upon trying to load the zero-sized soundfont.

Code: [Select]
--2021-09-11 16:45:15--  https://sourceforge.net/p/mscore/code/HEAD/tree/trunk/mscore/share/sound/TimGM6mb.sf2?format=raw
Resolving sourceforge.net (sourceforge.net)... 204.68.111.105
Connecting to sourceforge.net (sourceforge.net)|204.68.111.105|:443... connected.
HTTP request sent, awaiting response... 502 Bad Gateway
2021-09-11 16:45:16 ERROR 502: Bad Gateway.


The attached patch adds:
- retrying upon such temporary errors (default wget behavior is retrying up to 20 times)
- failing if file failed to download instead of silently pass

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [Android] Autodpi - display with correct ratio and appropriate zoom level
« Reply #5 on: September 12, 2021, 12:54:23 AM »
Thanks, in in r10093. I think I should add you to the svn ...