godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Change Android Display server DPI #10811

Open reverseslayer opened 1 month ago

reverseslayer commented 1 month ago

Describe the project you are working on

A multiplayer game where 2 phones will be side by side and I need to reference exact display DPI on android and IOS

Describe the problem or limitation you are having in your project

The current implementation of public int getScreenDPI() in the file platform/android/java/lib/src/org/godotengine/godot/GodotIO.java only allows for relative DPI

Describe the feature / enhancement and how it helps to overcome the problem or limitation

This would allow the game I am trying to make without having to rebuild from source every update of Godot Engine

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The version of DPI that i'm using just gets an average of the width DPI and height DPI that android gives you

public int getScreenDPI() { float xDPI = activity.getResources().getDisplayMetrics().xdpi; float yDPI = activity.getResources().getDisplayMetrics().ydpi; return Math.round( (xDPI+yDPI)/2 ); }

and the documentation in doc/classes/DisplayServer.xml can have the part where android DPI's are relative can be removed.

If this enhancement will not be used often, can it be worked around with a few lines of script?

The current implementation is not work around-able due to android.permission.DUMP being blocked by default unless for system applications. So unable to get true DPI from the system.

Is there a reason why this should be core and not an add-on in the asset library?

Its a fix of an already existing feature

reverseslayer commented 1 month ago

I have compiled the modifications into the export templates linked here and it results in accurate DPI returned from android. Ill link it here for anyone who wants to use it. Just copy the 3 android files from the zip to the current version of godot you are using at this reference. PLEASE DO NOT USE THIS IN PRODUCTION.

https://drive.google.com/file/d/10_H6EUC4wv1mSDK83DDHJXon-qeqPgeG/view?usp=sharing

C:\Users\user\AppData\Roaming\Godot\export_templates