News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

[Android] Autodpi - display with correct ratio and appropriate zoom level

Started by krosk, September 01, 2021, 02:59:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

krosk

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?

prissi

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 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).

krosk

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.

prissi


krosk

@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.

--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

prissi