Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of querying ProjectSettings fully each time, these macros first check a static local version against ProjectSettings. If the version has changed, a static local variable is updated and returned. If the version is up to date, the cached static local variable is returned.
The idea of this PR is to decrease the cost of the rather heavyweight calls to
GLOBAL_GET
in the codebase.I'd already added a couple of other methods previously (the
project_settings_changed
signal etc) in #53296 , and that still represents the recommended way to check project settings in bulk. But this PR adds a slightly more efficient variation of the standardGLOBAL_GET
, which can be fine in some circumstances and requires less boiler plate.Notes
SNAME
macro in Godot 4, so could do with checking by someone who properly understands this voodoo and actually knows what they are doing.ProjectSettings::get()
call is thread safe, which is outside the scope of this PR), despite there being no atomics etc. The only changes to_version
are made in_set()
which is a_THREAD_SAFE_METHOD
. Reading only needs to detect a difference, even if the local version (in the macro) is mangled for 1 frame, the worst that can happen seems to a read of the project setting on 2 adjacent frames. So it doesn't seem worth making_version
atomic, or having locks on_version
.