Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dynamic values in the Device context #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

limbonaut
Copy link
Collaborator

The current default is to set context values during initialization, which works for most cases. The only context that is currently updated is "godot_performance".

This PR introduces a code path that updates values in the standard Device context just before the event is sent.
Values that are dynamically updated in the Device context with this PR: orientation, free_memory, usable_memory, free_storage.

@limbonaut limbonaut added the enhancement New feature or request label Nov 19, 2024
@limbonaut limbonaut linked an issue Nov 19, 2024 that may be closed by this pull request
@@ -73,6 +73,7 @@ Dictionary make_device_context(const Ref<RuntimeConfig> &p_runtime_config) {
device_context["model"] = model;
}

// Note: Godot Engine doesn't support changing screen resolution.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, ever? How do Godot games support different screens?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Godot doesn't change the physical resolution of your desktop environment, it changes resolution scale instead. I.e., projects 720p on 1080p resolution, for example, like consoles do. Most modern games do the same, some also support changing the real resolution. But this way it makes Alt-Tab faster, and fewer issues with it. Upscaling is cheap these days.

device_context["free_memory"] = double(meminfo["free"]);
device_context["usable_memory"] = double(meminfo["available"]);

auto dir = DirAccess::open("user://");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need permissions for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's guaranteed to be writable, judging by the docs: https://docs.godotengine.org/en/stable/tutorials/io/data_paths.html#accessing-persistent-user-data-user

Also, some interesting bits:

On mobile platforms, this path is unique to the project and is not accessible by other applications for security reasons.

On HTML5 exports, user:// will refer to a virtual filesystem stored on the device via IndexedDB. (Interaction with the main filesystem can still be performed through the JavaScriptBridge singleton.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve context handling
2 participants