mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Add GLOBAL_GET cached macros.
GLOBAL_GET is an expensive operation which should not be used each frame / tick. This PR adds macros which do a cheaper revision check, and only call the expensive GLOBAL_GET when project settings have changed. Co-authored-by: Lukas Tenbrink <lukas.tenbrink@gmail.com>
This commit is contained in:
@@ -953,7 +953,7 @@ void Window::set_visible(bool p_visible) {
|
||||
embedder = embedder_vp;
|
||||
if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
|
||||
if (is_in_edited_scene_root()) {
|
||||
Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
|
||||
Size2 screen_size = Size2(GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_width"), GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_height"));
|
||||
position = (screen_size - size) / 2;
|
||||
} else {
|
||||
position = (embedder->get_visible_rect().size - size) / 2;
|
||||
@@ -1483,7 +1483,7 @@ void Window::_notification(int p_what) {
|
||||
if (embedder) {
|
||||
if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
|
||||
if (is_in_edited_scene_root()) {
|
||||
Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
|
||||
Size2 screen_size = Size2(GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_width"), GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_height"));
|
||||
position = (screen_size - size) / 2;
|
||||
} else {
|
||||
position = (embedder->get_visible_rect().size - size) / 2;
|
||||
@@ -2853,13 +2853,13 @@ bool Window::is_layout_rtl() const {
|
||||
ERR_READ_THREAD_GUARD_V(false);
|
||||
if (layout_dir == LAYOUT_DIRECTION_INHERITED) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (is_part_of_edited_scene() && GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
|
||||
if (is_part_of_edited_scene() && GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) {
|
||||
return true;
|
||||
}
|
||||
if (is_inside_tree()) {
|
||||
Node *edited_scene_root = get_tree()->get_edited_scene_root();
|
||||
if (edited_scene_root == this) {
|
||||
int proj_root_layout_direction = GLOBAL_GET(SNAME("internationalization/rendering/root_node_layout_direction"));
|
||||
int proj_root_layout_direction = GLOBAL_GET_CACHED(int, "internationalization/rendering/root_node_layout_direction");
|
||||
if (proj_root_layout_direction == 1) {
|
||||
return false;
|
||||
} else if (proj_root_layout_direction == 2) {
|
||||
@@ -2874,7 +2874,7 @@ bool Window::is_layout_rtl() const {
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
|
||||
if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -2904,14 +2904,14 @@ bool Window::is_layout_rtl() const {
|
||||
return TS->is_locale_right_to_left(locale);
|
||||
}
|
||||
} else if (layout_dir == LAYOUT_DIRECTION_APPLICATION_LOCALE) {
|
||||
if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
|
||||
if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) {
|
||||
return true;
|
||||
} else {
|
||||
String locale = TranslationServer::get_singleton()->get_tool_locale();
|
||||
return TS->is_locale_right_to_left(locale);
|
||||
}
|
||||
} else if (layout_dir == LAYOUT_DIRECTION_SYSTEM_LOCALE) {
|
||||
if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
|
||||
if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) {
|
||||
return true;
|
||||
} else {
|
||||
String locale = OS::get_singleton()->get_locale();
|
||||
|
||||
Reference in New Issue
Block a user