diff options
261 files changed, 2237 insertions, 154 deletions
diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index c0bb756d2e..6d227d6615 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -63,6 +63,11 @@ Copyright: 2011, Ole Kniemeyer, MAXON, www.maxon.net 2007-2014, Juan Linietsky, Ariel Manzur License: Expat and Zlib +Files: ./modules/godot_physics_2d/godot_joints_2d.cpp +Comment: Chipmunk2D Joint Constraints +Copyright: 2007, Scott Lembcke +License: Expat + Files: ./modules/godot_physics_3d/gjk_epa.cpp ./modules/godot_physics_3d/joints/godot_generic_6dof_joint_3d.cpp ./modules/godot_physics_3d/joints/godot_generic_6dof_joint_3d.h @@ -126,11 +131,6 @@ Copyright: 2001, Robert Penner 2007-2014, Juan Linietsky, Ariel Manzur License: Expat -Files: ./servers/physics_2d/godot_joints_2d.cpp -Comment: Chipmunk2D Joint Constraints -Copyright: 2007, Scott Lembcke -License: Expat - Files: ./servers/rendering/renderer_rd/shaders/ss_effects_downsample.glsl ./servers/rendering/renderer_rd/shaders/ssao_blur.glsl ./servers/rendering/renderer_rd/shaders/ssao_importance_map.glsl diff --git a/SConstruct b/SConstruct index 0245531b45..5566770148 100644 --- a/SConstruct +++ b/SConstruct @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * EnsureSConsVersion(3, 1, 2) EnsurePythonVersion(3, 6) diff --git a/core/SCsub b/core/SCsub index c8267ae960..8bda230b87 100644 --- a/core/SCsub +++ b/core/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/config/SCsub b/core/config/SCsub index bf70285490..1417a258c1 100644 --- a/core/config/SCsub +++ b/core/config/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/crypto/SCsub b/core/crypto/SCsub index 8cff3cf679..3cea6bfb47 100644 --- a/core/crypto/SCsub +++ b/core/crypto/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/debugger/SCsub b/core/debugger/SCsub index 19a6549225..ab81175894 100644 --- a/core/debugger/SCsub +++ b/core/debugger/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/error/SCsub b/core/error/SCsub index dfd6248a94..08089d31b0 100644 --- a/core/error/SCsub +++ b/core/error/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/extension/SCsub b/core/extension/SCsub index 6ab2d2b0a6..8688ca5b6e 100644 --- a/core/extension/SCsub +++ b/core/extension/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/input/SCsub b/core/input/SCsub index d8e6f33156..521f7702e4 100644 --- a/core/input/SCsub +++ b/core/input/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/io/SCsub b/core/io/SCsub index 19a6549225..ab81175894 100644 --- a/core/io/SCsub +++ b/core/io/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/math/SCsub b/core/math/SCsub index c8fdac207e..6ea3ab6b12 100644 --- a/core/math/SCsub +++ b/core/math/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/object/SCsub b/core/object/SCsub index 7c00bb719e..3d0d2c14dd 100644 --- a/core/object/SCsub +++ b/core/object/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp index 4d67cd930e..03537dbeb1 100644 --- a/core/object/undo_redo.cpp +++ b/core/object/undo_redo.cpp @@ -48,7 +48,7 @@ void UndoRedo::Operation::delete_reference() { } } -void UndoRedo::_discard_redo() { +void UndoRedo::discard_redo() { if (current_action == actions.size() - 1) { return; } @@ -89,7 +89,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode, bool p_back uint64_t ticks = OS::get_singleton()->get_ticks_msec(); if (action_level == 0) { - _discard_redo(); + discard_redo(); // Check if the merge operation is valid if (p_mode != MERGE_DISABLE && actions.size() && actions[actions.size() - 1].name == p_name && actions[actions.size() - 1].backward_undo_ops == p_backward_undo_ops && actions[actions.size() - 1].last_tick + 800 > ticks) { @@ -288,7 +288,7 @@ void UndoRedo::end_force_keep_in_merge_ends() { } void UndoRedo::_pop_history_tail() { - _discard_redo(); + discard_redo(); if (!actions.size()) { return; @@ -455,7 +455,7 @@ String UndoRedo::get_action_name(int p_id) { void UndoRedo::clear_history(bool p_increase_version) { ERR_FAIL_COND(action_level > 0); - _discard_redo(); + discard_redo(); while (actions.size()) { _pop_history_tail(); diff --git a/core/object/undo_redo.h b/core/object/undo_redo.h index 19d178635c..ded962670c 100644 --- a/core/object/undo_redo.h +++ b/core/object/undo_redo.h @@ -129,6 +129,7 @@ public: int get_current_action(); String get_action_name(int p_id); void clear_history(bool p_increase_version = true); + void discard_redo(); bool has_undo() const; bool has_redo() const; diff --git a/core/os/SCsub b/core/os/SCsub index 19a6549225..ab81175894 100644 --- a/core/os/SCsub +++ b/core/os/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/string/SCsub b/core/string/SCsub index 3217166f18..b06e32eb88 100644 --- a/core/string/SCsub +++ b/core/string/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/templates/SCsub b/core/templates/SCsub index 8c4c843a33..7f806d5609 100644 --- a/core/templates/SCsub +++ b/core/templates/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/core/variant/SCsub b/core/variant/SCsub index 7f4c8b7788..8264503a22 100644 --- a/core/variant/SCsub +++ b/core/variant/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/doc/classes/CameraFeed.xml b/doc/classes/CameraFeed.xml index 974f6d4a33..8033c0880b 100644 --- a/doc/classes/CameraFeed.xml +++ b/doc/classes/CameraFeed.xml @@ -34,6 +34,17 @@ Returns the position of camera on the device. </description> </method> + <method name="set_format"> + <return type="bool" /> + <param index="0" name="index" type="int" /> + <param index="1" name="parameters" type="Dictionary" /> + <description> + Sets the feed format parameters for the given index in the [member formats] array. Returns [code]true[/code] on success. By default YUYV encoded stream is transformed to FEED_RGB. YUYV encoded stream output format can be changed with [param parameters].output value: + [code]separate[/code] will result in FEED_YCBCR_SEP + [code]grayscale[/code] will result in desaturated FEED_RGB + [code]copy[/code] will result in FEED_YCBCR + </description> + </method> </methods> <members> <member name="feed_is_active" type="bool" setter="set_active" getter="is_active" default="false"> @@ -42,7 +53,22 @@ <member name="feed_transform" type="Transform2D" setter="set_transform" getter="get_transform" default="Transform2D(1, 0, 0, -1, 0, 1)"> The transform applied to the camera's image. </member> + <member name="formats" type="Array" setter="" getter="get_formats" default="[]"> + Formats supported by the feed. Each entry is a [Dictionary] describing format parameters. + </member> </members> + <signals> + <signal name="format_changed"> + <description> + Emitted when the format has changed. + </description> + </signal> + <signal name="frame_changed"> + <description> + Emitted when a new frame is available. + </description> + </signal> + </signals> <constants> <constant name="FEED_NOIMAGE" value="0" enum="FeedDataType"> No image set for the feed. diff --git a/doc/classes/CameraServer.xml b/doc/classes/CameraServer.xml index 020b5d887b..b09010147e 100644 --- a/doc/classes/CameraServer.xml +++ b/doc/classes/CameraServer.xml @@ -6,7 +6,7 @@ <description> The [CameraServer] keeps track of different cameras accessible in Godot. These are external cameras such as webcams or the cameras on your phone. It is notably used to provide AR modules with a video feed from the camera. - [b]Note:[/b] This class is currently only implemented on macOS and iOS. To get a [CameraFeed] on iOS, the camera plugin from [url=https://github.com/godotengine/godot-ios-plugins]godot-ios-plugins[/url] is required. On other platforms, no [CameraFeed]s will be available. + [b]Note:[/b] This class is currently only implemented on Linux, macOS, and iOS, on other platforms no [CameraFeed]s will be available. To get a [CameraFeed] on iOS, the camera plugin from [url=https://github.com/godotengine/godot-ios-plugins]godot-ios-plugins[/url] is required. </description> <tutorials> </tutorials> diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml index 423059a0c7..bc17c8b008 100644 --- a/doc/classes/CanvasItem.xml +++ b/doc/classes/CanvasItem.xml @@ -648,7 +648,7 @@ </signal> <signal name="hidden"> <description> - Emitted when the [CanvasItem] becomes hidden, either because its own [member visible] property was set to [code]false[/code] or the [member visible] property of one of its [CanvasItem] ancestors was set to [code]false[/code]. + Emitted when the [CanvasItem] is hidden, i.e. it's no longer visible in the tree (see [method is_visible_in_tree]). </description> </signal> <signal name="item_rect_changed"> @@ -658,7 +658,7 @@ </signal> <signal name="visibility_changed"> <description> - Emitted when the [CanvasItem]'s visibility changes, either because its own [member visible] property changed or because the visility of one of its [CanvasItem] ancestors changed (equivalent to a change in [method is_visible_in_tree]). + Emitted when the [CanvasItem]'s visibility changes, either because its own [member visible] property changed or because its visibility in the tree changed (see [method is_visible_in_tree]). </description> </signal> </signals> diff --git a/doc/classes/Environment.xml b/doc/classes/Environment.xml index 8c26509812..de3295fbe0 100644 --- a/doc/classes/Environment.xml +++ b/doc/classes/Environment.xml @@ -414,7 +414,7 @@ Linear tonemapper operator. Reads the linear data and passes it on unmodified. This can cause bright lighting to look blown out, with noticeable clipping in the output colors. </constant> <constant name="TONE_MAPPER_REINHARDT" value="1" enum="ToneMapper"> - Reinhardt tonemapper operator. Performs a variation on rendered pixels' colors by this formula: [code]color = color / (1 + color)[/code]. This avoids clipping bright highlights, but the resulting image can look a bit dull. + Reinhard tonemapper operator. Performs a variation on rendered pixels' colors by this formula: [code]color = color * (1 + color / (white * white)) / (1 + color)[/code]. This avoids clipping bright highlights, but the resulting image can look a bit dull. When [member tonemap_white] is left at the default value of [code]1.0[/code] this is identical to [constant TONE_MAPPER_LINEAR] while also being slightly less performant. </constant> <constant name="TONE_MAPPER_FILMIC" value="2" enum="ToneMapper"> Filmic tonemapper operator. This avoids clipping bright highlights, with a resulting image that usually looks more vivid than [constant TONE_MAPPER_REINHARDT]. diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 0e5097b7b2..7b6d8d0cd3 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2215,6 +2215,7 @@ <member name="physics/2d/physics_engine" type="String" setter="" getter="" default=""DEFAULT""> Sets which physics engine to use for 2D physics. "DEFAULT" and "GodotPhysics2D" are the same, as there is currently no alternative 2D physics server implemented. + "Dummy" is a 2D physics server that does nothing and returns only dummy values, effectively disabling all 2D physics functionality. </member> <member name="physics/2d/run_on_separate_thread" type="bool" setter="" getter="" default="false"> If [code]true[/code], the 2D physics server runs on a separate thread, making better use of multi-core CPUs. If [code]false[/code], the 2D physics server runs on the main thread. Running the physics server on a separate thread can increase performance, but restricts API access to only physics process. diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 144f78349f..4b2ce6f45e 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -5219,7 +5219,7 @@ Output color as they came in. This can cause bright lighting to look blown out, with noticeable clipping in the output colors. </constant> <constant name="ENV_TONE_MAPPER_REINHARD" value="1" enum="EnvironmentToneMapper"> - Use the Reinhard tonemapper. Performs a variation on rendered pixels' colors by this formula: [code]color = color / (1 + color)[/code]. This avoids clipping bright highlights, but the resulting image can look a bit dull. + Use the Reinhard tonemapper. Performs a variation on rendered pixels' colors by this formula: [code]color = color * (1 + color / (white * white)) / (1 + color)[/code]. This avoids clipping bright highlights, but the resulting image can look a bit dull. When [member Environment.tonemap_white] is left at the default value of [code]1.0[/code] this is identical to [constant ENV_TONE_MAPPER_LINEAR] while also being slightly less performant. </constant> <constant name="ENV_TONE_MAPPER_FILMIC" value="2" enum="EnvironmentToneMapper"> Use the filmic tonemapper. This avoids clipping bright highlights, with a resulting image that usually looks more vivid than [constant ENV_TONE_MAPPER_REINHARD]. diff --git a/doc/classes/Signal.xml b/doc/classes/Signal.xml index 65168d6980..c970ccb094 100644 --- a/doc/classes/Signal.xml +++ b/doc/classes/Signal.xml @@ -48,7 +48,7 @@ <param index="0" name="object" type="Object" /> <param index="1" name="signal" type="StringName" /> <description> - Creates a new [Signal] named [param signal] in the specified [param object]. + Creates a [Signal] object referencing a signal named [param signal] in the specified [param object]. </description> </constructor> </constructors> diff --git a/drivers/SCsub b/drivers/SCsub index 44d29fb7c1..219c4451ee 100644 --- a/drivers/SCsub +++ b/drivers/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/alsa/SCsub b/drivers/alsa/SCsub index f17acb0f91..6242d0e359 100644 --- a/drivers/alsa/SCsub +++ b/drivers/alsa/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/alsamidi/SCsub b/drivers/alsamidi/SCsub index 4e1b5f2a36..69d667c57b 100644 --- a/drivers/alsamidi/SCsub +++ b/drivers/alsamidi/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/backtrace/SCsub b/drivers/backtrace/SCsub index f61fb21581..cc2cf0a6d8 100644 --- a/drivers/backtrace/SCsub +++ b/drivers/backtrace/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/coreaudio/SCsub b/drivers/coreaudio/SCsub index 4e1b5f2a36..69d667c57b 100644 --- a/drivers/coreaudio/SCsub +++ b/drivers/coreaudio/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/coremidi/SCsub b/drivers/coremidi/SCsub index 4e1b5f2a36..69d667c57b 100644 --- a/drivers/coremidi/SCsub +++ b/drivers/coremidi/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/d3d12/SCsub b/drivers/d3d12/SCsub index 482a549189..b6ceed23ac 100644 --- a/drivers/d3d12/SCsub +++ b/drivers/d3d12/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * import os from pathlib import Path diff --git a/drivers/egl/SCsub b/drivers/egl/SCsub index 1fd15b4bae..3a9b484b83 100644 --- a/drivers/egl/SCsub +++ b/drivers/egl/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/gl_context/SCsub b/drivers/gl_context/SCsub index ce6ea747b1..a2ba425990 100644 --- a/drivers/gl_context/SCsub +++ b/drivers/gl_context/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/gles3/SCsub b/drivers/gles3/SCsub index 506312df80..4f4b33de03 100644 --- a/drivers/gles3/SCsub +++ b/drivers/gles3/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/gles3/effects/SCsub b/drivers/gles3/effects/SCsub index 91e1140b75..9ad6234fbe 100644 --- a/drivers/gles3/effects/SCsub +++ b/drivers/gles3/effects/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/gles3/environment/SCsub b/drivers/gles3/environment/SCsub index 91e1140b75..9ad6234fbe 100644 --- a/drivers/gles3/environment/SCsub +++ b/drivers/gles3/environment/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index df7aba265b..3c959f0143 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -2184,7 +2184,9 @@ void RasterizerCanvasGLES3::canvas_begin(RID p_to_render_target, bool p_to_backb glBindFramebuffer(GL_FRAMEBUFFER, render_target->fbo); glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 4); glBindTexture(GL_TEXTURE_2D, render_target->backbuffer); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, p_backbuffer_has_mipmaps ? render_target->mipmap_count - 1 : 0); + if (render_target->backbuffer != 0) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, p_backbuffer_has_mipmaps ? render_target->mipmap_count - 1 : 0); + } } if (render_target->is_transparent || p_to_backbuffer) { diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index 19ef3d416c..e79f1db08d 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -349,9 +349,6 @@ RasterizerGLES3::RasterizerGLES3() { } } - // Disable OpenGL linear to sRGB conversion, because Godot will always do this conversion itself. - glDisable(GL_FRAMEBUFFER_SRGB); - // OpenGL needs to be initialized before initializing the Rasterizers config = memnew(GLES3::Config); utilities = memnew(GLES3::Utilities); @@ -368,6 +365,11 @@ RasterizerGLES3::RasterizerGLES3() { fog = memnew(GLES3::Fog); canvas = memnew(RasterizerCanvasGLES3()); scene = memnew(RasterizerSceneGLES3()); + + // Disable OpenGL linear to sRGB conversion, because Godot will always do this conversion itself. + if (config->srgb_framebuffer_supported) { + glDisable(GL_FRAMEBUFFER_SRGB); + } } RasterizerGLES3::~RasterizerGLES3() { diff --git a/drivers/gles3/shaders/SCsub b/drivers/gles3/shaders/SCsub index e70912cb4d..df2c515035 100644 --- a/drivers/gles3/shaders/SCsub +++ b/drivers/gles3/shaders/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/gles3/shaders/effects/SCsub b/drivers/gles3/shaders/effects/SCsub index 38b185ed88..387c317b90 100644 --- a/drivers/gles3/shaders/effects/SCsub +++ b/drivers/gles3/shaders/effects/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/gles3/shaders/tonemap_inc.glsl b/drivers/gles3/shaders/tonemap_inc.glsl index fb915aeb38..6738bdf748 100644 --- a/drivers/gles3/shaders/tonemap_inc.glsl +++ b/drivers/gles3/shaders/tonemap_inc.glsl @@ -76,8 +76,12 @@ vec3 tonemap_aces(vec3 color, float p_white) { return color_tonemapped / p_white_tonemapped; } +// Based on Reinhard's extended formula, see equation 4 in https://doi.org/cjbgrt vec3 tonemap_reinhard(vec3 color, float p_white) { - return (p_white * color + color) / (color * p_white + p_white); + float white_squared = p_white * p_white; + vec3 white_squared_color = white_squared * color; + // Equivalent to color * (1 + color / white_squared) / (1 + color) + return (white_squared_color + color * color) / (white_squared_color + white_squared); } #define TONEMAPPER_LINEAR 0 @@ -85,7 +89,7 @@ vec3 tonemap_reinhard(vec3 color, float p_white) { #define TONEMAPPER_FILMIC 2 #define TONEMAPPER_ACES 3 -vec3 apply_tonemapping(vec3 color, float p_white) { // inputs are LINEAR, always outputs clamped [0;1] color +vec3 apply_tonemapping(vec3 color, float p_white) { // inputs are LINEAR // Ensure color values passed to tonemappers are positive. // They can be negative in the case of negative lights, which leads to undesired behavior. if (tonemapper == TONEMAPPER_LINEAR) { diff --git a/drivers/gles3/storage/SCsub b/drivers/gles3/storage/SCsub index 91e1140b75..9ad6234fbe 100644 --- a/drivers/gles3/storage/SCsub +++ b/drivers/gles3/storage/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/gles3/storage/config.cpp b/drivers/gles3/storage/config.cpp index 4947d5d4ce..0100719151 100644 --- a/drivers/gles3/storage/config.cpp +++ b/drivers/gles3/storage/config.cpp @@ -88,6 +88,7 @@ Config::Config() { etc2_supported = false; s3tc_supported = true; rgtc_supported = true; //RGTC - core since OpenGL version 3.0 + srgb_framebuffer_supported = true; } else { float_texture_supported = extensions.has("GL_EXT_color_buffer_float"); etc2_supported = true; @@ -100,6 +101,7 @@ Config::Config() { s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc"); #endif rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc"); + srgb_framebuffer_supported = extensions.has("GL_EXT_sRGB_write_control"); } glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units); diff --git a/drivers/gles3/storage/config.h b/drivers/gles3/storage/config.h index 1de00094f0..d60f295d66 100644 --- a/drivers/gles3/storage/config.h +++ b/drivers/gles3/storage/config.h @@ -80,6 +80,7 @@ public: bool astc_supported = false; bool astc_hdr_supported = false; bool astc_layered_supported = false; + bool srgb_framebuffer_supported = false; bool force_vertex_shading = false; diff --git a/drivers/metal/SCsub b/drivers/metal/SCsub index 30129b7806..f597580763 100644 --- a/drivers/metal/SCsub +++ b/drivers/metal/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/png/SCsub b/drivers/png/SCsub index e38f3c4760..fce37257b1 100644 --- a/drivers/png/SCsub +++ b/drivers/png/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/pulseaudio/SCsub b/drivers/pulseaudio/SCsub index f48489d787..6a76ff6d85 100644 --- a/drivers/pulseaudio/SCsub +++ b/drivers/pulseaudio/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/unix/SCsub b/drivers/unix/SCsub index 146563a3b6..bca4acfd74 100644 --- a/drivers/unix/SCsub +++ b/drivers/unix/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/vulkan/SCsub b/drivers/vulkan/SCsub index 1efef5ad77..6ea7cc9a3b 100644 --- a/drivers/vulkan/SCsub +++ b/drivers/vulkan/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/wasapi/SCsub b/drivers/wasapi/SCsub index 4e1b5f2a36..69d667c57b 100644 --- a/drivers/wasapi/SCsub +++ b/drivers/wasapi/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/windows/SCsub b/drivers/windows/SCsub index 91e1140b75..9ad6234fbe 100644 --- a/drivers/windows/SCsub +++ b/drivers/windows/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/winmidi/SCsub b/drivers/winmidi/SCsub index 4e1b5f2a36..69d667c57b 100644 --- a/drivers/winmidi/SCsub +++ b/drivers/winmidi/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/drivers/xaudio2/SCsub b/drivers/xaudio2/SCsub index 6778ad281e..cd210466a2 100644 --- a/drivers/xaudio2/SCsub +++ b/drivers/xaudio2/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/SCsub b/editor/SCsub index 029048969a..9fcaf61245 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/debugger/SCsub b/editor/debugger/SCsub index 99f1c888f0..e26d09d88b 100644 --- a/editor/debugger/SCsub +++ b/editor/debugger/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/debugger/debug_adapter/SCsub b/editor/debugger/debug_adapter/SCsub index 359d04e5df..b3cff5b9dc 100644 --- a/editor/debugger/debug_adapter/SCsub +++ b/editor/debugger/debug_adapter/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 184176391a..f248d03140 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1202,7 +1202,7 @@ void EditorNode::_reload_modified_scenes() { editor_data.set_edited_scene(i); _remove_edited_scene(false); - Error err = load_scene(filename, false, false, true, false, true); + Error err = load_scene(filename, false, false, false, true); if (err != OK) { ERR_PRINT(vformat("Failed to load scene: %s", filename)); } @@ -3931,7 +3931,7 @@ int EditorNode::new_scene() { return idx; } -Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, bool p_set_inherited, bool p_clear_errors, bool p_force_open_imported, bool p_silent_change_tab) { +Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, bool p_set_inherited, bool p_force_open_imported, bool p_silent_change_tab) { if (!is_inside_tree()) { defer_load_scene = p_scene; return OK; @@ -3954,10 +3954,6 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b } } - if (p_clear_errors && !load_errors_queued_to_display) { - load_errors->clear(); - } - String lpath = ProjectSettings::get_singleton()->localize_path(p_scene); if (!lpath.begins_with("res://")) { @@ -4935,6 +4931,12 @@ void EditorNode::_progress_dialog_visibility_changed() { } } +void EditorNode::_load_error_dialog_visibility_changed() { + if (!load_error_dialog->is_visible()) { + load_errors->clear(); + } +} + String EditorNode::_get_system_info() const { String distribution_name = OS::get_singleton()->get_distribution_name(); if (distribution_name.is_empty()) { @@ -5915,7 +5917,7 @@ void EditorNode::reload_scene(const String &p_path) { // Reload scene. _remove_scene(scene_idx, false); - load_scene(p_path, true, false, true, true); + load_scene(p_path, true, false, true); // Adjust index so tab is back a the previous position. editor_data.move_edited_scene_to_index(scene_idx); @@ -6441,7 +6443,7 @@ void EditorNode::_inherit_imported(const String &p_action) { } void EditorNode::_open_imported() { - load_scene(open_import_request, true, false, true, true); + load_scene(open_import_request, true, false, true); } void EditorNode::dim_editor(bool p_dimming) { @@ -7848,6 +7850,7 @@ EditorNode::EditorNode() { load_error_dialog->set_unparent_when_invisible(true); load_error_dialog->add_child(load_errors); load_error_dialog->set_title(TTR("Load Errors")); + load_error_dialog->connect(SceneStringName(visibility_changed), callable_mp(this, &EditorNode::_load_error_dialog_visibility_changed)); execute_outputs = memnew(RichTextLabel); execute_outputs->set_selection_enabled(true); diff --git a/editor/editor_node.h b/editor/editor_node.h index 109cacdf0e..7ef38b4edb 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -660,6 +660,7 @@ private: void _remove_all_not_owned_children(Node *p_node, Node *p_owner); void _progress_dialog_visibility_changed(); + void _load_error_dialog_visibility_changed(); protected: friend class FileSystemDock; @@ -778,7 +779,7 @@ public: void fix_dependencies(const String &p_for_file); int new_scene(); - Error load_scene(const String &p_scene, bool p_ignore_broken_deps = false, bool p_set_inherited = false, bool p_clear_errors = true, bool p_force_open_imported = false, bool p_silent_change_tab = false); + Error load_scene(const String &p_scene, bool p_ignore_broken_deps = false, bool p_set_inherited = false, bool p_force_open_imported = false, bool p_silent_change_tab = false); Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false); HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node, bool p_node_references_only); diff --git a/editor/editor_undo_redo_manager.cpp b/editor/editor_undo_redo_manager.cpp index 2e96ae82fc..57e55e7bac 100644 --- a/editor/editor_undo_redo_manager.cpp +++ b/editor/editor_undo_redo_manager.cpp @@ -264,6 +264,22 @@ void EditorUndoRedoManager::commit_action(bool p_execute) { history.undo_stack.push_back(pending_action); } + if (history.id != GLOBAL_HISTORY) { + // Clear global redo, to avoid unexpected actions when redoing. + History &global = get_or_create_history(GLOBAL_HISTORY); + global.redo_stack.clear(); + global.undo_redo->discard_redo(); + } else { + // On global actions, clear redo of all scenes instead. + for (KeyValue<int, History> &E : history_map) { + if (E.key == GLOBAL_HISTORY) { + continue; + } + E.value.redo_stack.clear(); + E.value.undo_redo->discard_redo(); + } + } + pending_action = Action(); is_committing = false; emit_signal(SNAME("history_changed")); diff --git a/editor/export/SCsub b/editor/export/SCsub index 359d04e5df..b3cff5b9dc 100644 --- a/editor/export/SCsub +++ b/editor/export/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/gui/SCsub b/editor/gui/SCsub index 359d04e5df..b3cff5b9dc 100644 --- a/editor/gui/SCsub +++ b/editor/gui/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/icons/SCsub b/editor/icons/SCsub index 0d9ac43c46..a66ef56699 100644 --- a/editor/icons/SCsub +++ b/editor/icons/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/import/SCsub b/editor/import/SCsub index a8c06cc406..3d3b7780ba 100644 --- a/editor/import/SCsub +++ b/editor/import/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp index 3c07e85758..921467ccbc 100644 --- a/editor/localization_editor.cpp +++ b/editor/localization_editor.cpp @@ -74,15 +74,20 @@ void LocalizationEditor::add_translation(const String &p_translation) { void LocalizationEditor::_translation_add(const PackedStringArray &p_paths) { PackedStringArray translations = GLOBAL_GET("internationalization/locale/translations"); - for (int i = 0; i < p_paths.size(); i++) { - if (!translations.has(p_paths[i])) { + int count = 0; + for (const String &path : p_paths) { + if (!translations.has(path)) { // Don't add duplicate translation paths. - translations.push_back(p_paths[i]); + translations.push_back(path); + count += 1; } } + if (count == 0) { + return; + } EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - undo_redo->create_action(vformat(TTR("Add %d Translations"), p_paths.size())); + undo_redo->create_action(vformat(TTRN("Add %d Translation", "Add %d Translations", count), count)); undo_redo->add_do_property(ProjectSettings::get_singleton(), "internationalization/locale/translations", translations); undo_redo->add_undo_property(ProjectSettings::get_singleton(), "internationalization/locale/translations", GLOBAL_GET("internationalization/locale/translations")); undo_redo->add_do_method(this, "update_translations"); @@ -136,15 +141,20 @@ void LocalizationEditor::_translation_res_add(const PackedStringArray &p_paths) prev = remaps; } - for (int i = 0; i < p_paths.size(); i++) { - if (!remaps.has(p_paths[i])) { + int count = 0; + for (const String &path : p_paths) { + if (!remaps.has(path)) { // Don't overwrite with an empty remap array if an array already exists for the given path. - remaps[p_paths[i]] = PackedStringArray(); + remaps[path] = PackedStringArray(); + count += 1; } } + if (count == 0) { + return; + } EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - undo_redo->create_action(vformat(TTR("Translation Resource Remap: Add %d Path(s)"), p_paths.size())); + undo_redo->create_action(vformat(TTRN("Translation Resource Remap: Add %d Path", "Translation Resource Remap: Add %d Paths", count), count)); undo_redo->add_do_property(ProjectSettings::get_singleton(), "internationalization/locale/translation_remaps", remaps); undo_redo->add_undo_property(ProjectSettings::get_singleton(), "internationalization/locale/translation_remaps", prev); undo_redo->add_do_method(this, "update_translations"); @@ -176,7 +186,7 @@ void LocalizationEditor::_translation_res_option_add(const PackedStringArray &p_ remaps[key] = r; EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - undo_redo->create_action(vformat(TTR("Translation Resource Remap: Add %d Remap(s)"), p_paths.size())); + undo_redo->create_action(vformat(TTRN("Translation Resource Remap: Add %d Remap", "Translation Resource Remap: Add %d Remaps", p_paths.size()), p_paths.size())); undo_redo->add_do_property(ProjectSettings::get_singleton(), "internationalization/locale/translation_remaps", remaps); undo_redo->add_undo_property(ProjectSettings::get_singleton(), "internationalization/locale/translation_remaps", GLOBAL_GET("internationalization/locale/translation_remaps")); undo_redo->add_do_method(this, "update_translations"); @@ -326,14 +336,19 @@ void LocalizationEditor::_translation_res_option_delete(Object *p_item, int p_co void LocalizationEditor::_pot_add(const PackedStringArray &p_paths) { PackedStringArray pot_translations = GLOBAL_GET("internationalization/locale/translations_pot_files"); - for (int i = 0; i < p_paths.size(); i++) { - if (!pot_translations.has(p_paths[i])) { - pot_translations.push_back(p_paths[i]); + int count = 0; + for (const String &path : p_paths) { + if (!pot_translations.has(path)) { + pot_translations.push_back(path); + count += 1; } } + if (count == 0) { + return; + } EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - undo_redo->create_action(vformat(TTR("Add %d file(s) for POT generation"), p_paths.size())); + undo_redo->create_action(vformat(TTRN("Add %d file for POT generation", "Add %d files for POT generation", count), count)); undo_redo->add_do_property(ProjectSettings::get_singleton(), "internationalization/locale/translations_pot_files", pot_translations); undo_redo->add_undo_property(ProjectSettings::get_singleton(), "internationalization/locale/translations_pot_files", GLOBAL_GET("internationalization/locale/translations_pot_files")); undo_redo->add_do_method(this, "update_translations"); diff --git a/editor/plugins/SCsub b/editor/plugins/SCsub index 4b6abf18f9..2d3066c7c9 100644 --- a/editor/plugins/SCsub +++ b/editor/plugins/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/plugins/gizmos/SCsub b/editor/plugins/gizmos/SCsub index 359d04e5df..b3cff5b9dc 100644 --- a/editor/plugins/gizmos/SCsub +++ b/editor/plugins/gizmos/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/plugins/tiles/SCsub b/editor/plugins/tiles/SCsub index 359d04e5df..b3cff5b9dc 100644 --- a/editor/plugins/tiles/SCsub +++ b/editor/plugins/tiles/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/project_manager/SCsub b/editor/project_manager/SCsub index 359d04e5df..b3cff5b9dc 100644 --- a/editor/project_manager/SCsub +++ b/editor/project_manager/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/editor/themes/SCsub b/editor/themes/SCsub index e8f96e4299..5a9949dfa7 100644 --- a/editor/themes/SCsub +++ b/editor/themes/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/main/SCsub b/main/SCsub index f3807167a2..71bee465f5 100644 --- a/main/SCsub +++ b/main/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/main/main.cpp b/main/main.cpp index 439cd385c0..75797e31de 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -80,6 +80,7 @@ #include "servers/navigation_server_2d.h" #include "servers/navigation_server_2d_dummy.h" #include "servers/physics_server_2d.h" +#include "servers/physics_server_2d_dummy.h" #ifndef _3D_DISABLED #include "servers/physics_server_3d.h" @@ -340,7 +341,15 @@ void initialize_physics() { // Physics server not found, Use the default physics physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server(); } - ERR_FAIL_NULL(physics_server_2d); + + // Fall back to dummy if no default server has been registered. + if (!physics_server_2d) { + WARN_PRINT(vformat("Falling back to dummy PhysicsServer2D; 2D physics functionality will be disabled. If this is intended, set the %s project setting to Dummy.", PhysicsServer2DManager::setting_property_name)); + physics_server_2d = memnew(PhysicsServer2DDummy); + } + + // Should be impossible, but make sure it's not null. + ERR_FAIL_NULL_MSG(physics_server_2d, "Failed to initialize PhysicsServer2D."); physics_server_2d->init(); } diff --git a/misc/utility/scons_hints.py b/misc/utility/scons_hints.py new file mode 100644 index 0000000000..fe380e399d --- /dev/null +++ b/misc/utility/scons_hints.py @@ -0,0 +1,98 @@ +""" +Adds type hints to SCons scripts. Implemented via +`from misc.utility.scons_hints import *`. + +This is NOT a 1-1 representation of what the defines will represent in an +SCons build, as proxies are almost always utilized instead. Rather, this is +a means of tracing back what those proxies are calling to in the first place. +""" + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + # ruff: noqa: F401 + from SCons.Action import Action + from SCons.Builder import Builder + from SCons.Defaults import Chmod, Copy, CScan, DefaultEnvironment, Delete, DirScanner, Mkdir, Move, Touch + from SCons.Environment import Base + from SCons.Platform import Platform + from SCons.Platform.virtualenv import Virtualenv + from SCons.Scanner import FindPathDirs, ScannerBase + from SCons.Script import ARGLIST, ARGUMENTS, BUILD_TARGETS, COMMAND_LINE_TARGETS, DEFAULT_TARGETS + from SCons.Script.Main import ( + AddOption, + BuildTask, + CleanTask, + DebugOptions, + GetBuildFailures, + GetOption, + PrintHelp, + Progress, + QuestionTask, + SetOption, + ValidateOptions, + ) + from SCons.Script.SConscript import Configure, Return, SConsEnvironment, call_stack + from SCons.Script.SConscript import SConsEnvironment as Environment + from SCons.Subst import SetAllowableExceptions as AllowSubstExceptions + from SCons.Tool import CScanner, DScanner, ProgramScanner, SourceFileScanner, Tool + from SCons.Util import AddMethod, WhereIs + from SCons.Variables import BoolVariable, EnumVariable, ListVariable, PackageVariable, PathVariable, Variables + + # Global functions + GetSConsVersion = SConsEnvironment.GetSConsVersion + EnsurePythonVersion = SConsEnvironment.EnsurePythonVersion + EnsureSConsVersion = SConsEnvironment.EnsureSConsVersion + Exit = SConsEnvironment.Exit + GetLaunchDir = SConsEnvironment.GetLaunchDir + SConscriptChdir = SConsEnvironment.SConscriptChdir + + # SConsEnvironment functions + Default = SConsEnvironment(DefaultEnvironment()).Default + Export = SConsEnvironment(DefaultEnvironment()).Export + Help = SConsEnvironment(DefaultEnvironment()).Help + Import = SConsEnvironment(DefaultEnvironment()).Import + SConscript = SConsEnvironment(DefaultEnvironment()).SConscript + + # Environment functions + AddPostAction = DefaultEnvironment().AddPostAction + AddPreAction = DefaultEnvironment().AddPreAction + Alias = DefaultEnvironment().Alias + AlwaysBuild = DefaultEnvironment().AlwaysBuild + CacheDir = DefaultEnvironment().CacheDir + Clean = DefaultEnvironment().Clean + Command = DefaultEnvironment().Command + Decider = DefaultEnvironment().Decider + Depends = DefaultEnvironment().Depends + Dir = DefaultEnvironment().Dir + Entry = DefaultEnvironment().Entry + Execute = DefaultEnvironment().Execute + File = DefaultEnvironment().File + FindFile = DefaultEnvironment().FindFile + FindInstalledFiles = DefaultEnvironment().FindInstalledFiles + FindSourceFiles = DefaultEnvironment().FindSourceFiles + Flatten = DefaultEnvironment().Flatten + GetBuildPath = DefaultEnvironment().GetBuildPath + Glob = DefaultEnvironment().Glob + Ignore = DefaultEnvironment().Ignore + Install = DefaultEnvironment().Install + InstallAs = DefaultEnvironment().InstallAs + InstallVersionedLib = DefaultEnvironment().InstallVersionedLib + Literal = DefaultEnvironment().Literal + Local = DefaultEnvironment().Local + NoCache = DefaultEnvironment().NoCache + NoClean = DefaultEnvironment().NoClean + ParseDepends = DefaultEnvironment().ParseDepends + Precious = DefaultEnvironment().Precious + PyPackageDir = DefaultEnvironment().PyPackageDir + Repository = DefaultEnvironment().Repository + Requires = DefaultEnvironment().Requires + SConsignFile = DefaultEnvironment().SConsignFile + SideEffect = DefaultEnvironment().SideEffect + Split = DefaultEnvironment().Split + Tag = DefaultEnvironment().Tag + Value = DefaultEnvironment().Value + VariantDir = DefaultEnvironment().VariantDir + + env: SConsEnvironment + env_modules: SConsEnvironment diff --git a/modules/SCsub b/modules/SCsub index e16cc17b67..fea2f2eeb8 100644 --- a/modules/SCsub +++ b/modules/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * import os diff --git a/modules/astcenc/SCsub b/modules/astcenc/SCsub index 691c74b4a7..23e9fa87fc 100644 --- a/modules/astcenc/SCsub +++ b/modules/astcenc/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/basis_universal/SCsub b/modules/basis_universal/SCsub index 80bfd7e858..0142317e1e 100644 --- a/modules/basis_universal/SCsub +++ b/modules/basis_universal/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/betsy/SCsub b/modules/betsy/SCsub index ed5dcbf58b..2735116cc3 100644 --- a/modules/betsy/SCsub +++ b/modules/betsy/SCsub @@ -1,4 +1,6 @@ -# !/ usr / bin / env python +#!/usr/bin/env python +from misc.utility.scons_hints import * + Import("env") Import("env_modules") diff --git a/modules/bmp/SCsub b/modules/bmp/SCsub index 9d317887c3..cc3684b94b 100644 --- a/modules/bmp/SCsub +++ b/modules/bmp/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/camera/SCsub b/modules/camera/SCsub index 9a6147d433..aed5efd0d2 100644 --- a/modules/camera/SCsub +++ b/modules/camera/SCsub @@ -1,14 +1,21 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") env_camera = env_modules.Clone() -if env["platform"] == "windows": +if env["platform"] in ["windows", "macos", "linuxbsd"]: env_camera.add_source_files(env.modules_sources, "register_types.cpp") + +if env["platform"] == "windows": env_camera.add_source_files(env.modules_sources, "camera_win.cpp") elif env["platform"] == "macos": - env_camera.add_source_files(env.modules_sources, "register_types.cpp") env_camera.add_source_files(env.modules_sources, "camera_macos.mm") + +elif env["platform"] == "linuxbsd": + env_camera.add_source_files(env.modules_sources, "camera_linux.cpp") + env_camera.add_source_files(env.modules_sources, "camera_feed_linux.cpp") + env_camera.add_source_files(env.modules_sources, "buffer_decoder.cpp") diff --git a/modules/camera/buffer_decoder.cpp b/modules/camera/buffer_decoder.cpp new file mode 100644 index 0000000000..024a68f080 --- /dev/null +++ b/modules/camera/buffer_decoder.cpp @@ -0,0 +1,212 @@ +/**************************************************************************/ +/* buffer_decoder.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "buffer_decoder.h" + +#include "servers/camera/camera_feed.h" + +#include <linux/videodev2.h> + +BufferDecoder::BufferDecoder(CameraFeed *p_camera_feed) { + camera_feed = p_camera_feed; + width = camera_feed->get_format().width; + height = camera_feed->get_format().height; + image.instantiate(); +} + +AbstractYuyvBufferDecoder::AbstractYuyvBufferDecoder(CameraFeed *p_camera_feed) : + BufferDecoder(p_camera_feed) { + switch (camera_feed->get_format().pixel_format) { + case V4L2_PIX_FMT_YYUV: + component_indexes = new int[4]{ 0, 1, 2, 3 }; + break; + case V4L2_PIX_FMT_YVYU: + component_indexes = new int[4]{ 0, 2, 3, 1 }; + break; + case V4L2_PIX_FMT_UYVY: + component_indexes = new int[4]{ 1, 3, 0, 2 }; + break; + case V4L2_PIX_FMT_VYUY: + component_indexes = new int[4]{ 1, 3, 2, 0 }; + break; + default: + component_indexes = new int[4]{ 0, 2, 1, 3 }; + } +} + +AbstractYuyvBufferDecoder::~AbstractYuyvBufferDecoder() { + delete[] component_indexes; +} + +SeparateYuyvBufferDecoder::SeparateYuyvBufferDecoder(CameraFeed *p_camera_feed) : + AbstractYuyvBufferDecoder(p_camera_feed) { + y_image_data.resize(width * height); + cbcr_image_data.resize(width * height); + y_image.instantiate(); + cbcr_image.instantiate(); +} + +void SeparateYuyvBufferDecoder::decode(StreamingBuffer p_buffer) { + uint8_t *y_dst = (uint8_t *)y_image_data.ptrw(); + uint8_t *uv_dst = (uint8_t *)cbcr_image_data.ptrw(); + uint8_t *src = (uint8_t *)p_buffer.start; + uint8_t *y0_src = src + component_indexes[0]; + uint8_t *y1_src = src + component_indexes[1]; + uint8_t *u_src = src + component_indexes[2]; + uint8_t *v_src = src + component_indexes[3]; + + for (int i = 0; i < width * height; i += 2) { + *y_dst++ = *y0_src; + *y_dst++ = *y1_src; + *uv_dst++ = *u_src; + *uv_dst++ = *v_src; + + y0_src += 4; + y1_src += 4; + u_src += 4; + v_src += 4; + } + + if (y_image.is_valid()) { + y_image->set_data(width, height, false, Image::FORMAT_L8, y_image_data); + } else { + y_image.instantiate(width, height, false, Image::FORMAT_RGB8, y_image_data); + } + if (cbcr_image.is_valid()) { + cbcr_image->set_data(width, height, false, Image::FORMAT_L8, cbcr_image_data); + } else { + cbcr_image.instantiate(width, height, false, Image::FORMAT_RGB8, cbcr_image_data); + } + + camera_feed->set_YCbCr_imgs(y_image, cbcr_image); +} + +YuyvToGrayscaleBufferDecoder::YuyvToGrayscaleBufferDecoder(CameraFeed *p_camera_feed) : + AbstractYuyvBufferDecoder(p_camera_feed) { + image_data.resize(width * height); +} + +void YuyvToGrayscaleBufferDecoder::decode(StreamingBuffer p_buffer) { + uint8_t *dst = (uint8_t *)image_data.ptrw(); + uint8_t *src = (uint8_t *)p_buffer.start; + uint8_t *y0_src = src + component_indexes[0]; + uint8_t *y1_src = src + component_indexes[1]; + + for (int i = 0; i < width * height; i += 2) { + *dst++ = *y0_src; + *dst++ = *y1_src; + + y0_src += 4; + y1_src += 4; + } + + if (image.is_valid()) { + image->set_data(width, height, false, Image::FORMAT_L8, image_data); + } else { + image.instantiate(width, height, false, Image::FORMAT_RGB8, image_data); + } + + camera_feed->set_RGB_img(image); +} + +YuyvToRgbBufferDecoder::YuyvToRgbBufferDecoder(CameraFeed *p_camera_feed) : + AbstractYuyvBufferDecoder(p_camera_feed) { + image_data.resize(width * height * 3); +} + +void YuyvToRgbBufferDecoder::decode(StreamingBuffer p_buffer) { + uint8_t *src = (uint8_t *)p_buffer.start; + uint8_t *y0_src = src + component_indexes[0]; + uint8_t *y1_src = src + component_indexes[1]; + uint8_t *u_src = src + component_indexes[2]; + uint8_t *v_src = src + component_indexes[3]; + uint8_t *dst = (uint8_t *)image_data.ptrw(); + + for (int i = 0; i < width * height; i += 2) { + int u = *u_src; + int v = *v_src; + int u1 = (((u - 128) << 7) + (u - 128)) >> 6; + int rg = (((u - 128) << 1) + (u - 128) + ((v - 128) << 2) + ((v - 128) << 1)) >> 3; + int v1 = (((v - 128) << 1) + (v - 128)) >> 1; + + *dst++ = CLAMP(*y0_src + v1, 0, 255); + *dst++ = CLAMP(*y0_src - rg, 0, 255); + *dst++ = CLAMP(*y0_src + u1, 0, 255); + + *dst++ = CLAMP(*y1_src + v1, 0, 255); + *dst++ = CLAMP(*y1_src - rg, 0, 255); + *dst++ = CLAMP(*y1_src + u1, 0, 255); + + y0_src += 4; + y1_src += 4; + u_src += 4; + v_src += 4; + } + + if (image.is_valid()) { + image->set_data(width, height, false, Image::FORMAT_RGB8, image_data); + } else { + image.instantiate(width, height, false, Image::FORMAT_RGB8, image_data); + } + + camera_feed->set_RGB_img(image); +} + +CopyBufferDecoder::CopyBufferDecoder(CameraFeed *p_camera_feed, bool p_rgba) : + BufferDecoder(p_camera_feed) { + rgba = p_rgba; + image_data.resize(width * height * (rgba ? 4 : 2)); +} + +void CopyBufferDecoder::decode(StreamingBuffer p_buffer) { + uint8_t *dst = (uint8_t *)image_data.ptrw(); + memcpy(dst, p_buffer.start, p_buffer.length); + + if (image.is_valid()) { + image->set_data(width, height, false, rgba ? Image::FORMAT_RGBA8 : Image::FORMAT_LA8, image_data); + } else { + image.instantiate(width, height, false, rgba ? Image::FORMAT_RGBA8 : Image::FORMAT_LA8, image_data); + } + + camera_feed->set_RGB_img(image); +} + +JpegBufferDecoder::JpegBufferDecoder(CameraFeed *p_camera_feed) : + BufferDecoder(p_camera_feed) { +} + +void JpegBufferDecoder::decode(StreamingBuffer p_buffer) { + image_data.resize(p_buffer.length); + uint8_t *dst = (uint8_t *)image_data.ptrw(); + memcpy(dst, p_buffer.start, p_buffer.length); + if (image->load_jpg_from_buffer(image_data) == OK) { + camera_feed->set_RGB_img(image); + } +} diff --git a/modules/camera/buffer_decoder.h b/modules/camera/buffer_decoder.h new file mode 100644 index 0000000000..97cc66b6da --- /dev/null +++ b/modules/camera/buffer_decoder.h @@ -0,0 +1,116 @@ +/**************************************************************************/ +/* buffer_decoder.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef BUFFER_DECODER_H +#define BUFFER_DECODER_H + +#include "core/io/image.h" +#include "core/templates/vector.h" + +class CameraFeed; + +struct StreamingBuffer { + void *start = nullptr; + size_t length = 0; +}; + +class BufferDecoder { +protected: + CameraFeed *camera_feed = nullptr; + Ref<Image> image; + int width = 0; + int height = 0; + +public: + virtual void decode(StreamingBuffer p_buffer) = 0; + + BufferDecoder(CameraFeed *p_camera_feed); + virtual ~BufferDecoder() {} +}; + +class AbstractYuyvBufferDecoder : public BufferDecoder { +protected: + int *component_indexes = nullptr; + +public: + AbstractYuyvBufferDecoder(CameraFeed *p_camera_feed); + ~AbstractYuyvBufferDecoder(); +}; + +class SeparateYuyvBufferDecoder : public AbstractYuyvBufferDecoder { +private: + Vector<uint8_t> y_image_data; + Vector<uint8_t> cbcr_image_data; + Ref<Image> y_image; + Ref<Image> cbcr_image; + +public: + SeparateYuyvBufferDecoder(CameraFeed *p_camera_feed); + virtual void decode(StreamingBuffer p_buffer) override; +}; + +class YuyvToGrayscaleBufferDecoder : public AbstractYuyvBufferDecoder { +private: + Vector<uint8_t> image_data; + +public: + YuyvToGrayscaleBufferDecoder(CameraFeed *p_camera_feed); + virtual void decode(StreamingBuffer p_buffer) override; +}; + +class YuyvToRgbBufferDecoder : public AbstractYuyvBufferDecoder { +private: + Vector<uint8_t> image_data; + +public: + YuyvToRgbBufferDecoder(CameraFeed *p_camera_feed); + virtual void decode(StreamingBuffer p_buffer) override; +}; + +class CopyBufferDecoder : public BufferDecoder { +private: + Vector<uint8_t> image_data; + bool rgba = false; + +public: + CopyBufferDecoder(CameraFeed *p_camera_feed, bool p_rgba); + virtual void decode(StreamingBuffer p_buffer) override; +}; + +class JpegBufferDecoder : public BufferDecoder { +private: + Vector<uint8_t> image_data; + +public: + JpegBufferDecoder(CameraFeed *p_camera_feed); + virtual void decode(StreamingBuffer p_buffer) override; +}; + +#endif // BUFFER_DECODER_H diff --git a/modules/camera/camera_feed_linux.cpp b/modules/camera/camera_feed_linux.cpp new file mode 100644 index 0000000000..9ed8eb0d0a --- /dev/null +++ b/modules/camera/camera_feed_linux.cpp @@ -0,0 +1,363 @@ +/**************************************************************************/ +/* camera_feed_linux.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "camera_feed_linux.h" + +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <unistd.h> + +void CameraFeedLinux::update_buffer_thread_func(void *p_func) { + if (p_func) { + CameraFeedLinux *camera_feed_linux = (CameraFeedLinux *)p_func; + camera_feed_linux->_update_buffer(); + } +} + +void CameraFeedLinux::_update_buffer() { + while (!exit_flag.is_set()) { + _read_frame(); + usleep(10000); + } +} + +void CameraFeedLinux::_query_device(const String &p_device_name) { + file_descriptor = open(p_device_name.ascii(), O_RDWR | O_NONBLOCK, 0); + ERR_FAIL_COND_MSG(file_descriptor == -1, vformat("Cannot open file descriptor for %s. Error: %d.", p_device_name, errno)); + + struct v4l2_capability capability; + if (ioctl(file_descriptor, VIDIOC_QUERYCAP, &capability) == -1) { + ERR_FAIL_MSG(vformat("Cannot query device. Error: %d.", errno)); + } + name = String((char *)capability.card); + + for (int index = 0;; index++) { + struct v4l2_fmtdesc fmtdesc; + memset(&fmtdesc, 0, sizeof(fmtdesc)); + fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + fmtdesc.index = index; + + if (ioctl(file_descriptor, VIDIOC_ENUM_FMT, &fmtdesc) == -1) { + break; + } + + for (int res_index = 0;; res_index++) { + struct v4l2_frmsizeenum frmsizeenum; + memset(&frmsizeenum, 0, sizeof(frmsizeenum)); + frmsizeenum.pixel_format = fmtdesc.pixelformat; + frmsizeenum.index = res_index; + + if (ioctl(file_descriptor, VIDIOC_ENUM_FRAMESIZES, &frmsizeenum) == -1) { + break; + } + + for (int framerate_index = 0;; framerate_index++) { + struct v4l2_frmivalenum frmivalenum; + memset(&frmivalenum, 0, sizeof(frmivalenum)); + frmivalenum.pixel_format = fmtdesc.pixelformat; + frmivalenum.width = frmsizeenum.discrete.width; + frmivalenum.height = frmsizeenum.discrete.height; + frmivalenum.index = framerate_index; + + if (ioctl(file_descriptor, VIDIOC_ENUM_FRAMEINTERVALS, &frmivalenum) == -1) { + if (framerate_index == 0) { + _add_format(fmtdesc, frmsizeenum.discrete, -1, 1); + } + break; + } + + _add_format(fmtdesc, frmsizeenum.discrete, frmivalenum.discrete.numerator, frmivalenum.discrete.denominator); + } + } + } + + close(file_descriptor); +} + +void CameraFeedLinux::_add_format(v4l2_fmtdesc p_description, v4l2_frmsize_discrete p_size, int p_frame_numerator, int p_frame_denominator) { + FeedFormat feed_format; + feed_format.width = p_size.width; + feed_format.height = p_size.height; + feed_format.format = String((char *)p_description.description); + feed_format.frame_numerator = p_frame_numerator; + feed_format.frame_denominator = p_frame_denominator; + feed_format.pixel_format = p_description.pixelformat; + print_verbose(vformat("%s %dx%d@%d/%dfps", (char *)p_description.description, p_size.width, p_size.height, p_frame_denominator, p_frame_numerator)); + formats.push_back(feed_format); +} + +bool CameraFeedLinux::_request_buffers() { + struct v4l2_requestbuffers requestbuffers; + + memset(&requestbuffers, 0, sizeof(requestbuffers)); + requestbuffers.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + requestbuffers.memory = V4L2_MEMORY_MMAP; + requestbuffers.count = 4; + + if (ioctl(file_descriptor, VIDIOC_REQBUFS, &requestbuffers) == -1) { + ERR_FAIL_V_MSG(false, vformat("ioctl(VIDIOC_REQBUFS) error: %d.", errno)); + } + + ERR_FAIL_COND_V_MSG(requestbuffers.count < 2, false, "Not enough buffers granted."); + + buffer_count = requestbuffers.count; + buffers = new StreamingBuffer[buffer_count]; + + for (unsigned int i = 0; i < buffer_count; i++) { + struct v4l2_buffer buffer; + + memset(&buffer, 0, sizeof(buffer)); + buffer.type = requestbuffers.type; + buffer.memory = V4L2_MEMORY_MMAP; + buffer.index = i; + + if (ioctl(file_descriptor, VIDIOC_QUERYBUF, &buffer) == -1) { + delete[] buffers; + ERR_FAIL_V_MSG(false, vformat("ioctl(VIDIOC_QUERYBUF) error: %d.", errno)); + } + + buffers[i].length = buffer.length; + buffers[i].start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED, file_descriptor, buffer.m.offset); + + if (buffers[i].start == MAP_FAILED) { + for (unsigned int b = 0; b < i; b++) { + _unmap_buffers(i); + } + delete[] buffers; + ERR_FAIL_V_MSG(false, "Mapping buffers failed."); + } + } + + return true; +} + +bool CameraFeedLinux::_start_capturing() { + for (unsigned int i = 0; i < buffer_count; i++) { + struct v4l2_buffer buffer; + + memset(&buffer, 0, sizeof(buffer)); + buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buffer.memory = V4L2_MEMORY_MMAP; + buffer.index = i; + + if (ioctl(file_descriptor, VIDIOC_QBUF, &buffer) == -1) { + ERR_FAIL_V_MSG(false, vformat("ioctl(VIDIOC_QBUF) error: %d.", errno)); + } + } + + enum v4l2_buf_type type; + type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + if (ioctl(file_descriptor, VIDIOC_STREAMON, &type) == -1) { + ERR_FAIL_V_MSG(false, vformat("ioctl(VIDIOC_STREAMON) error: %d.", errno)); + } + + return true; +} + +void CameraFeedLinux::_read_frame() { + struct v4l2_buffer buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buffer.memory = V4L2_MEMORY_MMAP; + + if (ioctl(file_descriptor, VIDIOC_DQBUF, &buffer) == -1) { + if (errno != EAGAIN) { + print_error(vformat("ioctl(VIDIOC_DQBUF) error: %d.", errno)); + exit_flag.set(); + } + return; + } + + buffer_decoder->decode(buffers[buffer.index]); + + if (ioctl(file_descriptor, VIDIOC_QBUF, &buffer) == -1) { + print_error(vformat("ioctl(VIDIOC_QBUF) error: %d.", errno)); + } + + emit_signal(SNAME("frame_changed")); +} + +void CameraFeedLinux::_stop_capturing() { + enum v4l2_buf_type type; + type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + if (ioctl(file_descriptor, VIDIOC_STREAMOFF, &type) == -1) { + print_error(vformat("ioctl(VIDIOC_STREAMOFF) error: %d.", errno)); + } +} + +void CameraFeedLinux::_unmap_buffers(unsigned int p_count) { + for (unsigned int i = 0; i < p_count; i++) { + munmap(buffers[i].start, buffers[i].length); + } +} + +void CameraFeedLinux::_start_thread() { + exit_flag.clear(); + thread = memnew(Thread); + thread->start(CameraFeedLinux::update_buffer_thread_func, this); +} + +String CameraFeedLinux::get_device_name() const { + return device_name; +} + +bool CameraFeedLinux::activate_feed() { + file_descriptor = open(device_name.ascii(), O_RDWR | O_NONBLOCK, 0); + if (_request_buffers() && _start_capturing()) { + buffer_decoder = _create_buffer_decoder(); + _start_thread(); + return true; + } + ERR_FAIL_V_MSG(false, "Could not activate feed."); +} + +BufferDecoder *CameraFeedLinux::_create_buffer_decoder() { + switch (formats[selected_format].pixel_format) { + case V4L2_PIX_FMT_MJPEG: + case V4L2_PIX_FMT_JPEG: + return memnew(JpegBufferDecoder(this)); + case V4L2_PIX_FMT_YUYV: + case V4L2_PIX_FMT_YYUV: + case V4L2_PIX_FMT_YVYU: + case V4L2_PIX_FMT_UYVY: + case V4L2_PIX_FMT_VYUY: { + String output = parameters["output"]; + if (output == "separate") { + return memnew(SeparateYuyvBufferDecoder(this)); + } + if (output == "grayscale") { + return memnew(YuyvToGrayscaleBufferDecoder(this)); + } + if (output == "copy") { + return memnew(CopyBufferDecoder(this, false)); + } + return memnew(YuyvToRgbBufferDecoder(this)); + } + default: + return memnew(CopyBufferDecoder(this, true)); + } +} + +void CameraFeedLinux::deactivate_feed() { + exit_flag.set(); + thread->wait_to_finish(); + memdelete(thread); + _stop_capturing(); + _unmap_buffers(buffer_count); + delete[] buffers; + memdelete(buffer_decoder); + for (int i = 0; i < CameraServer::FEED_IMAGES; i++) { + RID placeholder = RenderingServer::get_singleton()->texture_2d_placeholder_create(); + RenderingServer::get_singleton()->texture_replace(texture[i], placeholder); + } + base_width = 0; + base_height = 0; + close(file_descriptor); + + emit_signal(SNAME("format_changed")); +} + +Array CameraFeedLinux::get_formats() const { + Array result; + for (const FeedFormat &format : formats) { + Dictionary dictionary; + dictionary["width"] = format.width; + dictionary["height"] = format.height; + dictionary["format"] = format.format; + dictionary["frame_numerator"] = format.frame_numerator; + dictionary["frame_denominator"] = format.frame_denominator; + result.push_back(dictionary); + } + return result; +} + +CameraFeed::FeedFormat CameraFeedLinux::get_format() const { + return formats[selected_format]; +} + +bool CameraFeedLinux::set_format(int p_index, const Dictionary &p_parameters) { + ERR_FAIL_COND_V_MSG(active, false, "Feed is active."); + ERR_FAIL_INDEX_V_MSG(p_index, formats.size(), false, "Invalid format index."); + + parameters = p_parameters.duplicate(); + selected_format = p_index; + + FeedFormat feed_format = formats[p_index]; + + file_descriptor = open(device_name.ascii(), O_RDWR | O_NONBLOCK, 0); + + struct v4l2_format format; + memset(&format, 0, sizeof(format)); + format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + format.fmt.pix.width = feed_format.width; + format.fmt.pix.height = feed_format.height; + format.fmt.pix.pixelformat = feed_format.pixel_format; + + if (ioctl(file_descriptor, VIDIOC_S_FMT, &format) == -1) { + close(file_descriptor); + ERR_FAIL_V_MSG(false, vformat("Cannot set format, error: %d.", errno)); + } + + if (feed_format.frame_numerator > 0) { + struct v4l2_streamparm param; + memset(¶m, 0, sizeof(param)); + + param.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + param.parm.capture.capability = V4L2_CAP_TIMEPERFRAME; + param.parm.capture.timeperframe.numerator = feed_format.frame_numerator; + param.parm.capture.timeperframe.denominator = feed_format.frame_denominator; + + if (ioctl(file_descriptor, VIDIOC_S_PARM, ¶m) == -1) { + close(file_descriptor); + ERR_FAIL_V_MSG(false, vformat("Cannot set framerate, error: %d.", errno)); + } + } + close(file_descriptor); + + emit_signal(SNAME("format_changed")); + + return true; +} + +CameraFeedLinux::CameraFeedLinux(const String &p_device_name) : + CameraFeed() { + device_name = p_device_name; + _query_device(device_name); + set_format(0, Dictionary()); +} + +CameraFeedLinux::~CameraFeedLinux() { + if (is_active()) { + deactivate_feed(); + } +} diff --git a/modules/camera/camera_feed_linux.h b/modules/camera/camera_feed_linux.h new file mode 100644 index 0000000000..bf29201c99 --- /dev/null +++ b/modules/camera/camera_feed_linux.h @@ -0,0 +1,78 @@ +/**************************************************************************/ +/* camera_feed_linux.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef CAMERA_FEED_LINUX_H +#define CAMERA_FEED_LINUX_H + +#include "buffer_decoder.h" + +#include "core/os/thread.h" +#include "servers/camera/camera_feed.h" + +#include <linux/videodev2.h> + +struct StreamingBuffer; + +class CameraFeedLinux : public CameraFeed { +private: + SafeFlag exit_flag; + Thread *thread = nullptr; + String device_name; + int file_descriptor = -1; + StreamingBuffer *buffers = nullptr; + unsigned int buffer_count = 0; + BufferDecoder *buffer_decoder = nullptr; + + static void update_buffer_thread_func(void *p_func); + + void _update_buffer(); + void _query_device(const String &p_device_name); + void _add_format(v4l2_fmtdesc description, v4l2_frmsize_discrete size, int frame_numerator, int frame_denominator); + bool _request_buffers(); + bool _start_capturing(); + void _read_frame(); + void _stop_capturing(); + void _unmap_buffers(unsigned int p_count); + BufferDecoder *_create_buffer_decoder(); + void _start_thread(); + +public: + String get_device_name() const; + bool activate_feed(); + void deactivate_feed(); + bool set_format(int p_index, const Dictionary &p_parameters); + Array get_formats() const; + FeedFormat get_format() const; + + CameraFeedLinux(const String &p_device_name); + virtual ~CameraFeedLinux(); +}; + +#endif // CAMERA_FEED_LINUX_H diff --git a/modules/camera/camera_linux.cpp b/modules/camera/camera_linux.cpp new file mode 100644 index 0000000000..0cfb6b7b9e --- /dev/null +++ b/modules/camera/camera_linux.cpp @@ -0,0 +1,169 @@ +/**************************************************************************/ +/* camera_linux.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "camera_linux.h" + +#include "camera_feed_linux.h" + +#include <dirent.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <unistd.h> + +void CameraLinux::camera_thread_func(void *p_camera_linux) { + if (p_camera_linux) { + CameraLinux *camera_linux = (CameraLinux *)p_camera_linux; + camera_linux->_update_devices(); + } +} + +void CameraLinux::_update_devices() { + while (!exit_flag.is_set()) { + { + MutexLock lock(camera_mutex); + + for (int i = feeds.size() - 1; i >= 0; i--) { + Ref<CameraFeedLinux> feed = (Ref<CameraFeedLinux>)feeds[i]; + String device_name = feed->get_device_name(); + if (!_is_active(device_name)) { + remove_feed(feed); + } + } + + DIR *devices = opendir("/dev"); + + if (devices) { + struct dirent *device; + + while ((device = readdir(devices)) != nullptr) { + if (strncmp(device->d_name, "video", 5) != 0) { + continue; + } + String device_name = String("/dev/") + String(device->d_name); + if (!_has_device(device_name)) { + _add_device(device_name); + } + } + } + + closedir(devices); + } + + usleep(1000000); + } +} + +bool CameraLinux::_has_device(const String &p_device_name) { + for (int i = 0; i < feeds.size(); i++) { + Ref<CameraFeedLinux> feed = (Ref<CameraFeedLinux>)feeds[i]; + if (feed->get_device_name() == p_device_name) { + return true; + } + } + return false; +} + +void CameraLinux::_add_device(const String &p_device_name) { + int file_descriptor = _open_device(p_device_name); + + if (file_descriptor != -1) { + if (_is_video_capture_device(file_descriptor)) { + Ref<CameraFeedLinux> feed = memnew(CameraFeedLinux(p_device_name)); + add_feed(feed); + } + } + + close(file_descriptor); +} + +int CameraLinux::_open_device(const String &p_device_name) { + struct stat s; + + if (stat(p_device_name.ascii(), &s) == -1) { + return -1; + } + + if (!S_ISCHR(s.st_mode)) { + return -1; + } + + return open(p_device_name.ascii(), O_RDWR | O_NONBLOCK, 0); +} + +// TODO any cheaper/cleaner way to check if file descriptor is invalid? +bool CameraLinux::_is_active(const String &p_device_name) { + struct v4l2_capability capability; + bool result = false; + int file_descriptor = _open_device(p_device_name); + if (file_descriptor != -1 && ioctl(file_descriptor, VIDIOC_QUERYCAP, &capability) != -1) { + result = true; + } + close(file_descriptor); + return result; +} + +bool CameraLinux::_is_video_capture_device(int p_file_descriptor) { + struct v4l2_capability capability; + + if (ioctl(p_file_descriptor, VIDIOC_QUERYCAP, &capability) == -1) { + print_verbose("Cannot query device"); + return false; + } + + if (!(capability.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { + print_verbose(vformat("%s is no video capture device\n", String((char *)capability.card))); + return false; + } + + if (!(capability.capabilities & V4L2_CAP_STREAMING)) { + print_verbose(vformat("%s does not support streaming", String((char *)capability.card))); + return false; + } + + return _can_query_format(p_file_descriptor, V4L2_BUF_TYPE_VIDEO_CAPTURE); +} + +bool CameraLinux::_can_query_format(int p_file_descriptor, int p_type) { + struct v4l2_format format; + memset(&format, 0, sizeof(format)); + format.type = p_type; + + return ioctl(p_file_descriptor, VIDIOC_G_FMT, &format) != -1; +} + +CameraLinux::CameraLinux() { + camera_thread.start(CameraLinux::camera_thread_func, this); +}; + +CameraLinux::~CameraLinux() { + exit_flag.set(); + camera_thread.wait_to_finish(); +} diff --git a/modules/camera/camera_linux.h b/modules/camera/camera_linux.h new file mode 100644 index 0000000000..66f6aa0ffb --- /dev/null +++ b/modules/camera/camera_linux.h @@ -0,0 +1,60 @@ +/**************************************************************************/ +/* camera_linux.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef CAMERA_LINUX_H +#define CAMERA_LINUX_H + +#include "core/os/mutex.h" +#include "core/os/thread.h" +#include "servers/camera_server.h" + +class CameraLinux : public CameraServer { +private: + SafeFlag exit_flag; + Thread camera_thread; + Mutex camera_mutex; + + static void camera_thread_func(void *p_camera_linux); + + void _update_devices(); + bool _has_device(const String &p_device_name); + void _add_device(const String &p_device_name); + void _remove_device(const String &p_device_name); + int _open_device(const String &p_device_name); + bool _is_active(const String &p_device_name); + bool _is_video_capture_device(int p_file_descriptor); + bool _can_query_format(int p_file_descriptor, int p_type); + +public: + CameraLinux(); + ~CameraLinux(); +}; + +#endif // CAMERA_LINUX_H diff --git a/modules/camera/config.py b/modules/camera/config.py index d2b2542dd9..7b368d2193 100644 --- a/modules/camera/config.py +++ b/modules/camera/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return platform == "macos" or platform == "windows" + return platform == "macos" or platform == "windows" or platform == "linuxbsd" def configure(env): diff --git a/modules/camera/register_types.cpp b/modules/camera/register_types.cpp index feee6769f8..666ea8ba65 100644 --- a/modules/camera/register_types.cpp +++ b/modules/camera/register_types.cpp @@ -30,6 +30,9 @@ #include "register_types.h" +#if defined(LINUXBSD_ENABLED) +#include "camera_linux.h" +#endif #if defined(WINDOWS_ENABLED) #include "camera_win.h" #endif @@ -42,6 +45,9 @@ void initialize_camera_module(ModuleInitializationLevel p_level) { return; } +#if defined(LINUXBSD_ENABLED) + CameraServer::make_default<CameraLinux>(); +#endif #if defined(WINDOWS_ENABLED) CameraServer::make_default<CameraWindows>(); #endif diff --git a/modules/csg/SCsub b/modules/csg/SCsub index 1cf9974fc1..f71618ab22 100644 --- a/modules/csg/SCsub +++ b/modules/csg/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/cvtt/SCsub b/modules/cvtt/SCsub index 1d5a7ff6a3..44e56ab6a7 100644 --- a/modules/cvtt/SCsub +++ b/modules/cvtt/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/dds/SCsub b/modules/dds/SCsub index 06980bd670..d1c67c31ea 100644 --- a/modules/dds/SCsub +++ b/modules/dds/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/enet/SCsub b/modules/enet/SCsub index 580e5a3eb0..0c31638e46 100644 --- a/modules/enet/SCsub +++ b/modules/enet/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/etcpak/SCsub b/modules/etcpak/SCsub index 2d3b69be75..a872e1cd03 100644 --- a/modules/etcpak/SCsub +++ b/modules/etcpak/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/fbx/SCsub b/modules/fbx/SCsub index 6a791094c6..6f9fbba0b4 100644 --- a/modules/fbx/SCsub +++ b/modules/fbx/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/freetype/SCsub b/modules/freetype/SCsub index 2813eaecd5..5edce96680 100644 --- a/modules/freetype/SCsub +++ b/modules/freetype/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/gdscript/SCsub b/modules/gdscript/SCsub index 61accd4fc9..8f50bf9588 100644 --- a/modules/gdscript/SCsub +++ b/modules/gdscript/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/gdscript/editor/script_templates/SCsub b/modules/gdscript/editor/script_templates/SCsub index 5db7e3fc3b..28a27db3fa 100644 --- a/modules/gdscript/editor/script_templates/SCsub +++ b/modules/gdscript/editor/script_templates/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/modules/glslang/SCsub b/modules/glslang/SCsub index 3068377e60..b6e3da2316 100644 --- a/modules/glslang/SCsub +++ b/modules/glslang/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/gltf/SCsub b/modules/gltf/SCsub index 9d263cccac..1075116863 100644 --- a/modules/gltf/SCsub +++ b/modules/gltf/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/gltf/extensions/SCsub b/modules/gltf/extensions/SCsub index fdf14300f1..e403cd6fdc 100644 --- a/modules/gltf/extensions/SCsub +++ b/modules/gltf/extensions/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/godot_physics_2d/SCsub b/modules/godot_physics_2d/SCsub new file mode 100644 index 0000000000..39eb469978 --- /dev/null +++ b/modules/godot_physics_2d/SCsub @@ -0,0 +1,6 @@ +#!/usr/bin/env python +from misc.utility.scons_hints import * + +Import("env") + +env.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/godot_physics_2d/config.py b/modules/godot_physics_2d/config.py new file mode 100644 index 0000000000..d22f9454ed --- /dev/null +++ b/modules/godot_physics_2d/config.py @@ -0,0 +1,6 @@ +def can_build(env, platform): + return True + + +def configure(env): + pass diff --git a/servers/physics_2d/godot_area_2d.cpp b/modules/godot_physics_2d/godot_area_2d.cpp index d6c786706c..d6c786706c 100644 --- a/servers/physics_2d/godot_area_2d.cpp +++ b/modules/godot_physics_2d/godot_area_2d.cpp diff --git a/servers/physics_2d/godot_area_2d.h b/modules/godot_physics_2d/godot_area_2d.h index e6c3b45d6c..e6c3b45d6c 100644 --- a/servers/physics_2d/godot_area_2d.h +++ b/modules/godot_physics_2d/godot_area_2d.h diff --git a/servers/physics_2d/godot_area_pair_2d.cpp b/modules/godot_physics_2d/godot_area_pair_2d.cpp index ca12e30c29..ca12e30c29 100644 --- a/servers/physics_2d/godot_area_pair_2d.cpp +++ b/modules/godot_physics_2d/godot_area_pair_2d.cpp diff --git a/servers/physics_2d/godot_area_pair_2d.h b/modules/godot_physics_2d/godot_area_pair_2d.h index eb091288a9..eb091288a9 100644 --- a/servers/physics_2d/godot_area_pair_2d.h +++ b/modules/godot_physics_2d/godot_area_pair_2d.h diff --git a/servers/physics_2d/godot_body_2d.cpp b/modules/godot_physics_2d/godot_body_2d.cpp index c401e6eee7..c401e6eee7 100644 --- a/servers/physics_2d/godot_body_2d.cpp +++ b/modules/godot_physics_2d/godot_body_2d.cpp diff --git a/servers/physics_2d/godot_body_2d.h b/modules/godot_physics_2d/godot_body_2d.h index 529305dbb2..529305dbb2 100644 --- a/servers/physics_2d/godot_body_2d.h +++ b/modules/godot_physics_2d/godot_body_2d.h diff --git a/servers/physics_2d/godot_body_direct_state_2d.cpp b/modules/godot_physics_2d/godot_body_direct_state_2d.cpp index b34c70831d..b34c70831d 100644 --- a/servers/physics_2d/godot_body_direct_state_2d.cpp +++ b/modules/godot_physics_2d/godot_body_direct_state_2d.cpp diff --git a/servers/physics_2d/godot_body_direct_state_2d.h b/modules/godot_physics_2d/godot_body_direct_state_2d.h index 90b7c1d369..90b7c1d369 100644 --- a/servers/physics_2d/godot_body_direct_state_2d.h +++ b/modules/godot_physics_2d/godot_body_direct_state_2d.h diff --git a/servers/physics_2d/godot_body_pair_2d.cpp b/modules/godot_physics_2d/godot_body_pair_2d.cpp index 6c2d28dc92..6c2d28dc92 100644 --- a/servers/physics_2d/godot_body_pair_2d.cpp +++ b/modules/godot_physics_2d/godot_body_pair_2d.cpp diff --git a/servers/physics_2d/godot_body_pair_2d.h b/modules/godot_physics_2d/godot_body_pair_2d.h index 4e9bfa6022..4e9bfa6022 100644 --- a/servers/physics_2d/godot_body_pair_2d.h +++ b/modules/godot_physics_2d/godot_body_pair_2d.h diff --git a/servers/physics_2d/godot_broad_phase_2d.cpp b/modules/godot_physics_2d/godot_broad_phase_2d.cpp index eb6bc21d60..eb6bc21d60 100644 --- a/servers/physics_2d/godot_broad_phase_2d.cpp +++ b/modules/godot_physics_2d/godot_broad_phase_2d.cpp diff --git a/servers/physics_2d/godot_broad_phase_2d.h b/modules/godot_physics_2d/godot_broad_phase_2d.h index f3c07a69bb..f3c07a69bb 100644 --- a/servers/physics_2d/godot_broad_phase_2d.h +++ b/modules/godot_physics_2d/godot_broad_phase_2d.h diff --git a/servers/physics_2d/godot_broad_phase_2d_bvh.cpp b/modules/godot_physics_2d/godot_broad_phase_2d_bvh.cpp index 59623a2667..59623a2667 100644 --- a/servers/physics_2d/godot_broad_phase_2d_bvh.cpp +++ b/modules/godot_physics_2d/godot_broad_phase_2d_bvh.cpp diff --git a/servers/physics_2d/godot_broad_phase_2d_bvh.h b/modules/godot_physics_2d/godot_broad_phase_2d_bvh.h index 6c1fae5cb2..6c1fae5cb2 100644 --- a/servers/physics_2d/godot_broad_phase_2d_bvh.h +++ b/modules/godot_physics_2d/godot_broad_phase_2d_bvh.h diff --git a/servers/physics_2d/godot_collision_object_2d.cpp b/modules/godot_physics_2d/godot_collision_object_2d.cpp index 9851cac140..9851cac140 100644 --- a/servers/physics_2d/godot_collision_object_2d.cpp +++ b/modules/godot_physics_2d/godot_collision_object_2d.cpp diff --git a/servers/physics_2d/godot_collision_object_2d.h b/modules/godot_physics_2d/godot_collision_object_2d.h index 129fa27ff3..129fa27ff3 100644 --- a/servers/physics_2d/godot_collision_object_2d.h +++ b/modules/godot_physics_2d/godot_collision_object_2d.h diff --git a/servers/physics_2d/godot_collision_solver_2d.cpp b/modules/godot_physics_2d/godot_collision_solver_2d.cpp index a1acbe9cf0..a1acbe9cf0 100644 --- a/servers/physics_2d/godot_collision_solver_2d.cpp +++ b/modules/godot_physics_2d/godot_collision_solver_2d.cpp diff --git a/servers/physics_2d/godot_collision_solver_2d.h b/modules/godot_physics_2d/godot_collision_solver_2d.h index 1c09714f76..1c09714f76 100644 --- a/servers/physics_2d/godot_collision_solver_2d.h +++ b/modules/godot_physics_2d/godot_collision_solver_2d.h diff --git a/servers/physics_2d/godot_collision_solver_2d_sat.cpp b/modules/godot_physics_2d/godot_collision_solver_2d_sat.cpp index daa9982b2e..daa9982b2e 100644 --- a/servers/physics_2d/godot_collision_solver_2d_sat.cpp +++ b/modules/godot_physics_2d/godot_collision_solver_2d_sat.cpp diff --git a/servers/physics_2d/godot_collision_solver_2d_sat.h b/modules/godot_physics_2d/godot_collision_solver_2d_sat.h index c9183f7ecb..c9183f7ecb 100644 --- a/servers/physics_2d/godot_collision_solver_2d_sat.h +++ b/modules/godot_physics_2d/godot_collision_solver_2d_sat.h diff --git a/servers/physics_2d/godot_constraint_2d.h b/modules/godot_physics_2d/godot_constraint_2d.h index f4136f6643..f4136f6643 100644 --- a/servers/physics_2d/godot_constraint_2d.h +++ b/modules/godot_physics_2d/godot_constraint_2d.h diff --git a/servers/physics_2d/godot_joints_2d.cpp b/modules/godot_physics_2d/godot_joints_2d.cpp index 5c76eb9dad..5c76eb9dad 100644 --- a/servers/physics_2d/godot_joints_2d.cpp +++ b/modules/godot_physics_2d/godot_joints_2d.cpp diff --git a/servers/physics_2d/godot_joints_2d.h b/modules/godot_physics_2d/godot_joints_2d.h index c6a1fdb692..c6a1fdb692 100644 --- a/servers/physics_2d/godot_joints_2d.h +++ b/modules/godot_physics_2d/godot_joints_2d.h diff --git a/servers/physics_2d/godot_physics_server_2d.cpp b/modules/godot_physics_2d/godot_physics_server_2d.cpp index 8df17992ea..8df17992ea 100644 --- a/servers/physics_2d/godot_physics_server_2d.cpp +++ b/modules/godot_physics_2d/godot_physics_server_2d.cpp diff --git a/servers/physics_2d/godot_physics_server_2d.h b/modules/godot_physics_2d/godot_physics_server_2d.h index 991cf67c95..991cf67c95 100644 --- a/servers/physics_2d/godot_physics_server_2d.h +++ b/modules/godot_physics_2d/godot_physics_server_2d.h diff --git a/servers/physics_2d/godot_shape_2d.cpp b/modules/godot_physics_2d/godot_shape_2d.cpp index d77b1a77e3..d77b1a77e3 100644 --- a/servers/physics_2d/godot_shape_2d.cpp +++ b/modules/godot_physics_2d/godot_shape_2d.cpp diff --git a/servers/physics_2d/godot_shape_2d.h b/modules/godot_physics_2d/godot_shape_2d.h index 28c69574a0..28c69574a0 100644 --- a/servers/physics_2d/godot_shape_2d.h +++ b/modules/godot_physics_2d/godot_shape_2d.h diff --git a/servers/physics_2d/godot_space_2d.cpp b/modules/godot_physics_2d/godot_space_2d.cpp index 2966818beb..2966818beb 100644 --- a/servers/physics_2d/godot_space_2d.cpp +++ b/modules/godot_physics_2d/godot_space_2d.cpp diff --git a/servers/physics_2d/godot_space_2d.h b/modules/godot_physics_2d/godot_space_2d.h index ded3b08d5b..ded3b08d5b 100644 --- a/servers/physics_2d/godot_space_2d.h +++ b/modules/godot_physics_2d/godot_space_2d.h diff --git a/servers/physics_2d/godot_step_2d.cpp b/modules/godot_physics_2d/godot_step_2d.cpp index bbaec8be2b..bbaec8be2b 100644 --- a/servers/physics_2d/godot_step_2d.cpp +++ b/modules/godot_physics_2d/godot_step_2d.cpp diff --git a/servers/physics_2d/godot_step_2d.h b/modules/godot_physics_2d/godot_step_2d.h index c08c6379de..c08c6379de 100644 --- a/servers/physics_2d/godot_step_2d.h +++ b/modules/godot_physics_2d/godot_step_2d.h diff --git a/modules/godot_physics_2d/register_types.cpp b/modules/godot_physics_2d/register_types.cpp new file mode 100644 index 0000000000..57422b1814 --- /dev/null +++ b/modules/godot_physics_2d/register_types.cpp @@ -0,0 +1,61 @@ +/**************************************************************************/ +/* register_types.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "register_types.h" + +#include "godot_physics_server_2d.h" +#include "servers/physics_server_2d.h" +#include "servers/physics_server_2d_wrap_mt.h" + +static PhysicsServer2D *_createGodotPhysics2DCallback() { +#ifdef THREADS_ENABLED + bool using_threads = GLOBAL_GET("physics/2d/run_on_separate_thread"); +#else + bool using_threads = false; +#endif + + PhysicsServer2D *physics_server_2d = memnew(GodotPhysicsServer2D(using_threads)); + + return memnew(PhysicsServer2DWrapMT(physics_server_2d, using_threads)); +} + +void initialize_godot_physics_2d_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) { + return; + } + PhysicsServer2DManager::get_singleton()->register_server("GodotPhysics2D", callable_mp_static(_createGodotPhysics2DCallback)); + PhysicsServer2DManager::get_singleton()->set_default_server("GodotPhysics2D"); +} + +void uninitialize_godot_physics_2d_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) { + return; + } +} diff --git a/modules/godot_physics_2d/register_types.h b/modules/godot_physics_2d/register_types.h new file mode 100644 index 0000000000..1d2d1301b9 --- /dev/null +++ b/modules/godot_physics_2d/register_types.h @@ -0,0 +1,39 @@ +/**************************************************************************/ +/* register_types.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef GODOT_PHYSICS_2D_REGISTER_TYPES_H +#define GODOT_PHYSICS_2D_REGISTER_TYPES_H + +#include "modules/register_module_types.h" + +void initialize_godot_physics_2d_module(ModuleInitializationLevel p_level); +void uninitialize_godot_physics_2d_module(ModuleInitializationLevel p_level); + +#endif // GODOT_PHYSICS_2D_REGISTER_TYPES_H diff --git a/modules/godot_physics_3d/SCsub b/modules/godot_physics_3d/SCsub index 41a59cd24e..1502eb39ee 100644 --- a/modules/godot_physics_3d/SCsub +++ b/modules/godot_physics_3d/SCsub @@ -1,6 +1,7 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * -Import('env') +Import("env") env.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/godot_physics_3d/joints/SCsub b/modules/godot_physics_3d/joints/SCsub index 5d93da5ecf..39eb469978 100644 --- a/modules/godot_physics_3d/joints/SCsub +++ b/modules/godot_physics_3d/joints/SCsub @@ -1,5 +1,6 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * -Import('env') +Import("env") env.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/gridmap/SCsub b/modules/gridmap/SCsub index 282d772592..d4baa9000e 100644 --- a/modules/gridmap/SCsub +++ b/modules/gridmap/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/hdr/SCsub b/modules/hdr/SCsub index 10629bda3c..739b2caecf 100644 --- a/modules/hdr/SCsub +++ b/modules/hdr/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/interactive_music/SCsub b/modules/interactive_music/SCsub index 2950a30854..f2546747a0 100644 --- a/modules/interactive_music/SCsub +++ b/modules/interactive_music/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/jpg/SCsub b/modules/jpg/SCsub index b840542c1b..2d948d3355 100644 --- a/modules/jpg/SCsub +++ b/modules/jpg/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/jsonrpc/SCsub b/modules/jsonrpc/SCsub index 8ee4f8bfea..923567b138 100644 --- a/modules/jsonrpc/SCsub +++ b/modules/jsonrpc/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/ktx/SCsub b/modules/ktx/SCsub index c4cb732498..f4c394d734 100644 --- a/modules/ktx/SCsub +++ b/modules/ktx/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/lightmapper_rd/SCsub b/modules/lightmapper_rd/SCsub index fe9737b36f..157381ae98 100644 --- a/modules/lightmapper_rd/SCsub +++ b/modules/lightmapper_rd/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/mbedtls/SCsub b/modules/mbedtls/SCsub index 90ce98c751..e217ca5ca4 100644 --- a/modules/mbedtls/SCsub +++ b/modules/mbedtls/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/meshoptimizer/SCsub b/modules/meshoptimizer/SCsub index 3f86bb4f00..b335b5db3a 100644 --- a/modules/meshoptimizer/SCsub +++ b/modules/meshoptimizer/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/minimp3/SCsub b/modules/minimp3/SCsub index 09e84f71e9..e9491bb72f 100644 --- a/modules/minimp3/SCsub +++ b/modules/minimp3/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/mobile_vr/SCsub b/modules/mobile_vr/SCsub index e6c43228b4..b237f31209 100644 --- a/modules/mobile_vr/SCsub +++ b/modules/mobile_vr/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/mono/SCsub b/modules/mono/SCsub index d267df938a..f74f0fb9c1 100644 --- a/modules/mono/SCsub +++ b/modules/mono/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * import build_scripts.mono_configure as mono_configure diff --git a/modules/mono/editor/script_templates/SCsub b/modules/mono/editor/script_templates/SCsub index 01c293c25d..f465374758 100644 --- a/modules/mono/editor/script_templates/SCsub +++ b/modules/mono/editor/script_templates/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs index 1b3062c5db..91d49854c7 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs @@ -660,15 +660,7 @@ namespace Godot.Bridge { Type native = GodotObject.InternalGetClassNativeBase(scriptType); - string typeName = scriptType.Name; - if (scriptType.IsGenericType) - { - var sb = new StringBuilder(); - AppendTypeName(sb, scriptType); - typeName = sb.ToString(); - } - - godot_string className = Marshaling.ConvertStringToNative(typeName); + godot_string className = Marshaling.ConvertStringToNative(ReflectionUtils.ConstructTypeName(scriptType)); bool isTool = scriptType.IsDefined(typeof(ToolAttribute), inherit: false); @@ -701,24 +693,6 @@ namespace Godot.Bridge outTypeInfo->IsGenericTypeDefinition = scriptType.IsGenericTypeDefinition.ToGodotBool(); outTypeInfo->IsConstructedGenericType = scriptType.IsConstructedGenericType.ToGodotBool(); - static void AppendTypeName(StringBuilder sb, Type type) - { - sb.Append(type.Name); - if (type.IsGenericType) - { - sb.Append('<'); - for (int i = 0; i < type.GenericTypeArguments.Length; i++) - { - Type typeArg = type.GenericTypeArguments[i]; - AppendTypeName(sb, typeArg); - if (i != type.GenericTypeArguments.Length - 1) - { - sb.Append(", "); - } - } - sb.Append('>'); - } - } } [UnmanagedCallersOnly] @@ -1032,7 +1006,7 @@ namespace Godot.Bridge interopProperties[i] = interopProperty; } - using godot_string currentClassName = Marshaling.ConvertStringToNative(type.Name); + using godot_string currentClassName = Marshaling.ConvertStringToNative(ReflectionUtils.ConstructTypeName(type)); addPropInfoFunc(scriptPtr, ¤tClassName, interopProperties, length); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/ReflectionUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/ReflectionUtils.cs index ee605f8d8f..27989b5c81 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/ReflectionUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/ReflectionUtils.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Text; #nullable enable @@ -7,10 +10,186 @@ namespace Godot; internal class ReflectionUtils { + private static readonly HashSet<Type>? _tupleTypeSet; + private static readonly Dictionary<Type, string>? _builtinTypeNameDictionary; + private static readonly bool _isEditorHintCached; + + static ReflectionUtils() + { + _isEditorHintCached = Engine.IsEditorHint(); + if (!_isEditorHintCached) + { + return; + } + + _tupleTypeSet = new HashSet<Type> + { + // ValueTuple with only one element should be treated as normal generic type. + //typeof(ValueTuple<>), + typeof(ValueTuple<,>), + typeof(ValueTuple<,,>), + typeof(ValueTuple<,,,>), + typeof(ValueTuple<,,,,>), + typeof(ValueTuple<,,,,,>), + typeof(ValueTuple<,,,,,,>), + typeof(ValueTuple<,,,,,,,>), + }; + + _builtinTypeNameDictionary ??= new Dictionary<Type, string> + { + { typeof(sbyte), "sbyte" }, + { typeof(byte), "byte" }, + { typeof(short), "short" }, + { typeof(ushort), "ushort" }, + { typeof(int), "int" }, + { typeof(uint), "uint" }, + { typeof(long), "long" }, + { typeof(ulong), "ulong" }, + { typeof(nint), "nint" }, + { typeof(nuint), "nuint" }, + { typeof(float), "float" }, + { typeof(double), "double" }, + { typeof(decimal), "decimal" }, + { typeof(bool), "bool" }, + { typeof(char), "char" }, + { typeof(string), "string" }, + { typeof(object), "object" }, + }; + } + public static Type? FindTypeInLoadedAssemblies(string assemblyName, string typeFullName) { return AppDomain.CurrentDomain.GetAssemblies() .FirstOrDefault(a => a.GetName().Name == assemblyName)? .GetType(typeFullName); } + + public static string ConstructTypeName(Type type) + { + if (!_isEditorHintCached) + { + return type.Name; + } + + if (type is { IsArray: false, IsGenericType: false }) + { + return GetSimpleTypeName(type); + } + + var typeNameBuilder = new StringBuilder(); + AppendType(typeNameBuilder, type); + return typeNameBuilder.ToString(); + + static void AppendType(StringBuilder sb, Type type) + { + if (type.IsArray) + { + AppendArray(sb, type); + } + else if (type.IsGenericType) + { + AppendGeneric(sb, type); + } + else + { + sb.Append(GetSimpleTypeName(type)); + } + } + + static void AppendArray(StringBuilder sb, Type type) + { + // Append inner most non-array element. + var elementType = type.GetElementType()!; + while (elementType.IsArray) + { + elementType = elementType.GetElementType()!; + } + + AppendType(sb, elementType); + // Append brackets. + AppendArrayBrackets(sb, type); + + static void AppendArrayBrackets(StringBuilder sb, Type type) + { + while (type != null && type.IsArray) + { + int rank = type.GetArrayRank(); + sb.Append('['); + sb.Append(',', rank - 1); + sb.Append(']'); + type = type.GetElementType(); + } + } + } + + static void AppendGeneric(StringBuilder sb, Type type) + { + var genericArgs = type.GenericTypeArguments; + var genericDefinition = type.GetGenericTypeDefinition(); + + // Nullable<T> + if (genericDefinition == typeof(Nullable<>)) + { + AppendType(sb, genericArgs[0]); + sb.Append('?'); + return; + } + + // ValueTuple + Debug.Assert(_tupleTypeSet != null); + if (_tupleTypeSet.Contains(genericDefinition)) + { + sb.Append('('); + while (true) + { + // We assume that ValueTuple has 1~8 elements. + // And the 8th element (TRest) is always another ValueTuple. + + // This is a hard coded tuple element length check. + if (genericArgs.Length != 8) + { + AppendParamTypes(sb, genericArgs); + break; + } + else + { + AppendParamTypes(sb, genericArgs.AsSpan(0, 7)); + sb.Append(", "); + + // TRest should be a ValueTuple! + var nextTuple = genericArgs[7]; + + genericArgs = nextTuple.GenericTypeArguments; + } + } + sb.Append(')'); + return; + } + + // Normal generic + var typeName = type.Name.AsSpan(); + sb.Append(typeName[..typeName.LastIndexOf('`')]); + sb.Append('<'); + AppendParamTypes(sb, genericArgs); + sb.Append('>'); + + static void AppendParamTypes(StringBuilder sb, ReadOnlySpan<Type> genericArgs) + { + int n = genericArgs.Length - 1; + for (int i = 0; i < n; i += 1) + { + AppendType(sb, genericArgs[i]); + sb.Append(", "); + } + + AppendType(sb, genericArgs[n]); + } + } + + static string GetSimpleTypeName(Type type) + { + Debug.Assert(_builtinTypeNameDictionary != null); + return _builtinTypeNameDictionary.TryGetValue(type, out string? name) ? name : type.Name; + } + } } diff --git a/modules/msdfgen/SCsub b/modules/msdfgen/SCsub index f4316a74e7..844b0980ac 100644 --- a/modules/msdfgen/SCsub +++ b/modules/msdfgen/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/multiplayer/SCsub b/modules/multiplayer/SCsub index e89038c3e0..97f91c5674 100644 --- a/modules/multiplayer/SCsub +++ b/modules/multiplayer/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/multiplayer/editor/editor_network_profiler.cpp b/modules/multiplayer/editor/editor_network_profiler.cpp index 3a51712c70..f5f20d6931 100644 --- a/modules/multiplayer/editor/editor_network_profiler.cpp +++ b/modules/multiplayer/editor/editor_network_profiler.cpp @@ -193,6 +193,9 @@ void EditorNetworkProfiler::_update_button_text() { } void EditorNetworkProfiler::started() { + _clear_pressed(); + activate->set_disabled(false); + if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_network_profiler", false)) { set_profiling(true); refresh_timer->start(); @@ -200,6 +203,7 @@ void EditorNetworkProfiler::started() { } void EditorNetworkProfiler::stopped() { + activate->set_disabled(true); set_profiling(false); refresh_timer->stop(); } @@ -218,6 +222,7 @@ void EditorNetworkProfiler::_clear_pressed() { set_bandwidth(0, 0); refresh_rpc_data(); refresh_replication_data(); + clear_button->set_disabled(true); } void EditorNetworkProfiler::_autostart_toggled(bool p_toggled_on) { @@ -235,6 +240,9 @@ void EditorNetworkProfiler::_replication_button_clicked(TreeItem *p_item, int p_ } void EditorNetworkProfiler::add_rpc_frame_data(const RPCNodeInfo &p_frame) { + if (clear_button->is_disabled()) { + clear_button->set_disabled(false); + } dirty = true; if (!rpc_data.has(p_frame.node)) { rpc_data.insert(p_frame.node, p_frame); @@ -251,6 +259,9 @@ void EditorNetworkProfiler::add_rpc_frame_data(const RPCNodeInfo &p_frame) { } void EditorNetworkProfiler::add_sync_frame_data(const SyncInfo &p_frame) { + if (clear_button->is_disabled()) { + clear_button->set_disabled(false); + } dirty = true; if (!sync_data.has(p_frame.synchronizer)) { sync_data[p_frame.synchronizer] = p_frame; @@ -292,11 +303,13 @@ EditorNetworkProfiler::EditorNetworkProfiler() { activate = memnew(Button); activate->set_toggle_mode(true); activate->set_text(TTR("Start")); + activate->set_disabled(true); activate->connect(SceneStringName(pressed), callable_mp(this, &EditorNetworkProfiler::_activate_pressed)); hb->add_child(activate); clear_button = memnew(Button); clear_button->set_text(TTR("Clear")); + clear_button->set_disabled(true); clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorNetworkProfiler::_clear_pressed)); hb->add_child(clear_button); diff --git a/modules/navigation/SCsub b/modules/navigation/SCsub index 02d3b7487e..ab578252c1 100644 --- a/modules/navigation/SCsub +++ b/modules/navigation/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/noise/SCsub b/modules/noise/SCsub index f309fd2dd4..dcf51b03e3 100644 --- a/modules/noise/SCsub +++ b/modules/noise/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/ogg/SCsub b/modules/ogg/SCsub index f15525648f..fabd4f936a 100644 --- a/modules/ogg/SCsub +++ b/modules/ogg/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/openxr/SCsub b/modules/openxr/SCsub index 77922045eb..dd6a921440 100644 --- a/modules/openxr/SCsub +++ b/modules/openxr/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/openxr/action_map/SCsub b/modules/openxr/action_map/SCsub index 7a493011ec..d659be1d99 100644 --- a/modules/openxr/action_map/SCsub +++ b/modules/openxr/action_map/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_openxr") diff --git a/modules/openxr/editor/SCsub b/modules/openxr/editor/SCsub index ccf67a80d0..39eb469978 100644 --- a/modules/openxr/editor/SCsub +++ b/modules/openxr/editor/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/modules/openxr/editor/openxr_select_action_dialog.cpp b/modules/openxr/editor/openxr_select_action_dialog.cpp index a4ccc98408..89dea09be4 100644 --- a/modules/openxr/editor/openxr_select_action_dialog.cpp +++ b/modules/openxr/editor/openxr_select_action_dialog.cpp @@ -66,7 +66,7 @@ void OpenXRSelectActionDialog::_on_select_action(const String p_action) { void OpenXRSelectActionDialog::open() { ERR_FAIL_COND(action_map.is_null()); - // out with the old... + // Out with the old. while (main_vb->get_child_count() > 0) { memdelete(main_vb->get_child(0)); } @@ -74,6 +74,7 @@ void OpenXRSelectActionDialog::open() { selected_action = ""; action_buttons.clear(); + // In with the new. Array action_sets = action_map->get_action_sets(); for (int i = 0; i < action_sets.size(); i++) { Ref<OpenXRActionSet> action_set = action_sets[i]; diff --git a/modules/openxr/editor/openxr_select_interaction_profile_dialog.cpp b/modules/openxr/editor/openxr_select_interaction_profile_dialog.cpp index 53b8cbd401..ee8940f30b 100644 --- a/modules/openxr/editor/openxr_select_interaction_profile_dialog.cpp +++ b/modules/openxr/editor/openxr_select_interaction_profile_dialog.cpp @@ -66,15 +66,15 @@ void OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile(const void OpenXRSelectInteractionProfileDialog::open(PackedStringArray p_do_not_include) { int available_count = 0; - // out with the old... - while (main_vb->get_child_count() > 0) { - memdelete(main_vb->get_child(0)); + // Out with the old. + while (main_vb->get_child_count() > 1) { + memdelete(main_vb->get_child(1)); } selected_interaction_profile = ""; ip_buttons.clear(); - // in with the new + // In with the new. PackedStringArray interaction_profiles = OpenXRInteractionProfileMetadata::get_singleton()->get_interaction_profile_paths(); for (int i = 0; i < interaction_profiles.size(); i++) { const String &path = interaction_profiles[i]; @@ -82,6 +82,7 @@ void OpenXRSelectInteractionProfileDialog::open(PackedStringArray p_do_not_inclu Button *ip_button = memnew(Button); ip_button->set_flat(true); ip_button->set_text(OpenXRInteractionProfileMetadata::get_singleton()->get_profile(path)->display_name); + ip_button->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT); ip_button->connect(SceneStringName(pressed), callable_mp(this, &OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile).bind(path)); main_vb->add_child(ip_button); @@ -90,23 +91,16 @@ void OpenXRSelectInteractionProfileDialog::open(PackedStringArray p_do_not_inclu } } - if (available_count == 0) { - // give warning that we have all profiles selected - - } else { - // TODO maybe if we only have one, auto select it? - - popup_centered(); - } + all_selected->set_visible(available_count == 0); + get_cancel_button()->set_visible(available_count > 0); + popup_centered(); } void OpenXRSelectInteractionProfileDialog::ok_pressed() { - if (selected_interaction_profile == "") { - return; + if (selected_interaction_profile != "") { + emit_signal("interaction_profile_selected", selected_interaction_profile); } - emit_signal("interaction_profile_selected", selected_interaction_profile); - hide(); } @@ -118,6 +112,10 @@ OpenXRSelectInteractionProfileDialog::OpenXRSelectInteractionProfileDialog() { add_child(scroll); main_vb = memnew(VBoxContainer); - // main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); scroll->add_child(main_vb); + + all_selected = memnew(Label); + all_selected->set_text(TTR("All interaction profiles have been added to the action map.")); + main_vb->add_child(all_selected); } diff --git a/modules/openxr/editor/openxr_select_interaction_profile_dialog.h b/modules/openxr/editor/openxr_select_interaction_profile_dialog.h index 1d1615321c..d85e4cd4d6 100644 --- a/modules/openxr/editor/openxr_select_interaction_profile_dialog.h +++ b/modules/openxr/editor/openxr_select_interaction_profile_dialog.h @@ -51,6 +51,7 @@ private: VBoxContainer *main_vb = nullptr; ScrollContainer *scroll = nullptr; + Label *all_selected = nullptr; protected: static void _bind_methods(); diff --git a/modules/openxr/extensions/SCsub b/modules/openxr/extensions/SCsub index 1bd9cfaa22..95b75ccd65 100644 --- a/modules/openxr/extensions/SCsub +++ b/modules/openxr/extensions/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_openxr") diff --git a/modules/openxr/scene/SCsub b/modules/openxr/scene/SCsub index 7a493011ec..d659be1d99 100644 --- a/modules/openxr/scene/SCsub +++ b/modules/openxr/scene/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_openxr") diff --git a/modules/raycast/SCsub b/modules/raycast/SCsub index f3a8e30763..bbf5ff7983 100644 --- a/modules/raycast/SCsub +++ b/modules/raycast/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/regex/SCsub b/modules/regex/SCsub index f5e2dd5dfc..5d70604e76 100644 --- a/modules/regex/SCsub +++ b/modules/regex/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/squish/SCsub b/modules/squish/SCsub index c9e29911d8..d8e7fbc142 100644 --- a/modules/squish/SCsub +++ b/modules/squish/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/svg/SCsub b/modules/svg/SCsub index a32be0e41a..af8f6c14f4 100644 --- a/modules/svg/SCsub +++ b/modules/svg/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/text_server_adv/SCsub b/modules/text_server_adv/SCsub index 4112b81622..304a09515c 100644 --- a/modules/text_server_adv/SCsub +++ b/modules/text_server_adv/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/text_server_adv/gdextension_build/SConstruct b/modules/text_server_adv/gdextension_build/SConstruct index effed1e772..8f4f2cba40 100644 --- a/modules/text_server_adv/gdextension_build/SConstruct +++ b/modules/text_server_adv/gdextension_build/SConstruct @@ -1,4 +1,6 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * + import atexit import sys import time diff --git a/modules/text_server_fb/SCsub b/modules/text_server_fb/SCsub index fc0a8727c6..b56df192c2 100644 --- a/modules/text_server_fb/SCsub +++ b/modules/text_server_fb/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/text_server_fb/gdextension_build/SConstruct b/modules/text_server_fb/gdextension_build/SConstruct index a3c2052040..dc849d5814 100644 --- a/modules/text_server_fb/gdextension_build/SConstruct +++ b/modules/text_server_fb/gdextension_build/SConstruct @@ -1,4 +1,6 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * + import atexit import sys import time diff --git a/modules/tga/SCsub b/modules/tga/SCsub index ccd7d2ee37..c7f58e87f7 100644 --- a/modules/tga/SCsub +++ b/modules/tga/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/theora/SCsub b/modules/theora/SCsub index ca666050dd..be557c1c24 100644 --- a/modules/theora/SCsub +++ b/modules/theora/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/tinyexr/SCsub b/modules/tinyexr/SCsub index bf9242cc16..434e99bf84 100644 --- a/modules/tinyexr/SCsub +++ b/modules/tinyexr/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/upnp/SCsub b/modules/upnp/SCsub index 98c03e9ee9..6657d75cae 100644 --- a/modules/upnp/SCsub +++ b/modules/upnp/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/vhacd/SCsub b/modules/vhacd/SCsub index 1ff4122114..926cc5b16f 100644 --- a/modules/vhacd/SCsub +++ b/modules/vhacd/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/vorbis/SCsub b/modules/vorbis/SCsub index 322314487f..f063d97fee 100644 --- a/modules/vorbis/SCsub +++ b/modules/vorbis/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/webp/SCsub b/modules/webp/SCsub index dde4450c23..a939e2f90e 100644 --- a/modules/webp/SCsub +++ b/modules/webp/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/webrtc/SCsub b/modules/webrtc/SCsub index e315633f55..0c5f2c9dda 100644 --- a/modules/webrtc/SCsub +++ b/modules/webrtc/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/websocket/SCsub b/modules/websocket/SCsub index 8b469fe5be..acaa0d3ceb 100644 --- a/modules/websocket/SCsub +++ b/modules/websocket/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/webxr/SCsub b/modules/webxr/SCsub index 81caa4a279..9fe4e03ea6 100644 --- a/modules/webxr/SCsub +++ b/modules/webxr/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/xatlas_unwrap/SCsub b/modules/xatlas_unwrap/SCsub index aa6bdaea33..ae82a53bd9 100644 --- a/modules/xatlas_unwrap/SCsub +++ b/modules/xatlas_unwrap/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/modules/zip/SCsub b/modules/zip/SCsub index b7710123fd..0bab3ff5f9 100644 --- a/modules/zip/SCsub +++ b/modules/zip/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") Import("env_modules") diff --git a/platform/SCsub b/platform/SCsub index cdaa6074ba..7c9d07f6ef 100644 --- a/platform/SCsub +++ b/platform/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * from glob import glob from pathlib import Path diff --git a/platform/android/SCsub b/platform/android/SCsub index 8c88b419b3..3bc8959351 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * import subprocess import sys diff --git a/platform/ios/SCsub b/platform/ios/SCsub index cff7dcc1fd..959a657aac 100644 --- a/platform/ios/SCsub +++ b/platform/ios/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/platform/linuxbsd/SCsub b/platform/linuxbsd/SCsub index 0802b528f4..4def765e9c 100644 --- a/platform/linuxbsd/SCsub +++ b/platform/linuxbsd/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/platform/linuxbsd/wayland/SCsub b/platform/linuxbsd/wayland/SCsub index 89b586845c..1a8e243728 100644 --- a/platform/linuxbsd/wayland/SCsub +++ b/platform/linuxbsd/wayland/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/platform/linuxbsd/x11/SCsub b/platform/linuxbsd/x11/SCsub index 75fe584ad5..b76b98447f 100644 --- a/platform/linuxbsd/x11/SCsub +++ b/platform/linuxbsd/x11/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 7949f80f24..97ea1147ec 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -2998,11 +2998,7 @@ bool DisplayServerX11::window_is_focused(WindowID p_window) const { const WindowData &wd = windows[p_window]; - Window focused_window; - int focus_ret_state; - XGetInputFocus(x11_display, &focused_window, &focus_ret_state); - - return wd.x11_window == focused_window; + return wd.focused; } bool DisplayServerX11::window_can_draw(WindowID p_window) const { @@ -3050,7 +3046,7 @@ void DisplayServerX11::window_set_ime_active(const bool p_active, WindowID p_win XWindowAttributes xwa; XSync(x11_display, False); XGetWindowAttributes(x11_display, wd.x11_xim_window, &xwa); - if (xwa.map_state == IsViewable) { + if (xwa.map_state == IsViewable && _window_focus_check()) { _set_input_focus(wd.x11_xim_window, RevertToParent); } XSetICFocus(wd.xic); @@ -4319,7 +4315,7 @@ bool DisplayServerX11::_window_focus_check() { bool has_focus = false; for (const KeyValue<int, DisplayServerX11::WindowData> &wid : windows) { - if (wid.value.x11_window == focused_window) { + if (wid.value.x11_window == focused_window || (wid.value.xic && wid.value.ime_active && wid.value.x11_xim_window == focused_window)) { has_focus = true; break; } diff --git a/platform/macos/SCsub b/platform/macos/SCsub index a10262c524..3924e79fb6 100644 --- a/platform/macos/SCsub +++ b/platform/macos/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/platform/web/SCsub b/platform/web/SCsub index e81f2ec516..b30bf20f26 100644 --- a/platform/web/SCsub +++ b/platform/web/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * from methods import print_error diff --git a/platform/windows/SCsub b/platform/windows/SCsub index f8ed8b73f5..1d17e7b325 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/pyproject.toml b/pyproject.toml index 1cf789b460..a4bfd27816 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,19 @@ extend-select = [ [tool.ruff.lint.per-file-ignores] "{SConstruct,SCsub}" = [ "E402", # Module level import not at top of file - "F821", # Undefined name + "F403", # Undefined local with import star + "F405", # Undefined local with import star usage +] + +[tool.ruff.lint.isort] +sections = { metadata = ["misc.utility.scons_hints"] } +section-order = [ + "future", + "metadata", + "standard-library", + "third-party", + "first-party", + "local-folder", ] [tool.codespell] @@ -70,6 +82,7 @@ ignore-words-list = """\ numer, ot, outin, + parm, requestor, te, textin, diff --git a/scene/2d/SCsub b/scene/2d/SCsub index 94e1ab6c96..6f6bf9818c 100644 --- a/scene/2d/SCsub +++ b/scene/2d/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/2d/parallax_2d.cpp b/scene/2d/parallax_2d.cpp index fdb2d2cdd0..c6176390dc 100644 --- a/scene/2d/parallax_2d.cpp +++ b/scene/2d/parallax_2d.cpp @@ -83,7 +83,11 @@ void Parallax2D::_validate_property(PropertyInfo &p_property) const { void Parallax2D::_camera_moved(const Transform2D &p_transform, const Point2 &p_screen_offset, const Point2 &p_adj_screen_pos) { if (!ignore_camera_scroll) { if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { - set_screen_offset((p_adj_screen_pos + Vector2(0.5, 0.5)).floor()); + Size2 vps = get_viewport_rect().size; + Vector2 offset; + offset.x = ((int)vps.width % 2) ? 0.0 : 0.5; + offset.y = ((int)vps.height % 2) ? 0.0 : 0.5; + set_screen_offset((p_adj_screen_pos + offset).floor()); } else { set_screen_offset(p_adj_screen_pos); } diff --git a/scene/2d/physics/SCsub b/scene/2d/physics/SCsub index e7fd3fe643..5f9747514a 100644 --- a/scene/2d/physics/SCsub +++ b/scene/2d/physics/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/2d/physics/joints/SCsub b/scene/2d/physics/joints/SCsub index fc61250247..374dc2119d 100644 --- a/scene/2d/physics/joints/SCsub +++ b/scene/2d/physics/joints/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/2d/physics/shape_cast_2d.cpp b/scene/2d/physics/shape_cast_2d.cpp index b92978bcad..dd9d589165 100644 --- a/scene/2d/physics/shape_cast_2d.cpp +++ b/scene/2d/physics/shape_cast_2d.cpp @@ -34,7 +34,7 @@ #include "scene/2d/physics/collision_object_2d.h" #include "scene/2d/physics/physics_body_2d.h" #include "scene/resources/2d/circle_shape_2d.h" -#include "servers/physics_2d/godot_physics_server_2d.h" +#include "servers/physics_server_2d.h" void ShapeCast2D::set_target_position(const Vector2 &p_point) { target_position = p_point; diff --git a/scene/3d/SCsub b/scene/3d/SCsub index 94e1ab6c96..6f6bf9818c 100644 --- a/scene/3d/SCsub +++ b/scene/3d/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/3d/physics/SCsub b/scene/3d/physics/SCsub index e7fd3fe643..5f9747514a 100644 --- a/scene/3d/physics/SCsub +++ b/scene/3d/physics/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/3d/physics/joints/SCsub b/scene/3d/physics/joints/SCsub index fc61250247..374dc2119d 100644 --- a/scene/3d/physics/joints/SCsub +++ b/scene/3d/physics/joints/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/SCsub b/scene/SCsub index b4b2d6dd0a..1eb4ffa53d 100644 --- a/scene/SCsub +++ b/scene/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/animation/SCsub b/scene/animation/SCsub index d0aa0bc8aa..dd2b22c2e3 100644 --- a/scene/animation/SCsub +++ b/scene/animation/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/audio/SCsub b/scene/audio/SCsub index fc61250247..374dc2119d 100644 --- a/scene/audio/SCsub +++ b/scene/audio/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/debugger/SCsub b/scene/debugger/SCsub index fc61250247..374dc2119d 100644 --- a/scene/debugger/SCsub +++ b/scene/debugger/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/gui/SCsub b/scene/gui/SCsub index fc61250247..374dc2119d 100644 --- a/scene/gui/SCsub +++ b/scene/gui/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index c92dcbc153..002a738b83 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -33,8 +33,6 @@ #include "core/input/input.h" #include "core/io/image.h" #include "core/math/color.h" -#include "core/os/keyboard.h" -#include "core/os/os.h" #include "scene/gui/color_mode.h" #include "scene/gui/margin_container.h" #include "scene/resources/image_texture.h" @@ -42,7 +40,6 @@ #include "scene/resources/style_box_texture.h" #include "scene/theme/theme_db.h" #include "servers/display_server.h" -#include "thirdparty/misc/ok_color.h" #include "thirdparty/misc/ok_color_shader.h" List<Color> ColorPicker::preset_cache; @@ -1567,7 +1564,7 @@ void ColorPicker::_pick_button_pressed_legacy() { picker_preview_label = memnew(Label); picker_preview->set_anchors_preset(Control::PRESET_CENTER_TOP); - picker_preview_label->set_text("Color Picking active"); + picker_preview_label->set_text(ETR("Color Picking active")); picker_preview->add_child(picker_preview_label); picker_preview_style_box = (Ref<StyleBoxFlat>)memnew(StyleBoxFlat); @@ -1905,7 +1902,7 @@ ColorPicker::ColorPicker() { mode_popup->add_radio_check_item(modes[i]->get_name(), i); } mode_popup->add_separator(); - mode_popup->add_check_item("Colorized Sliders", MODE_MAX); + mode_popup->add_check_item(ETR("Colorized Sliders"), MODE_MAX); mode_popup->set_item_checked(current_mode, true); mode_popup->set_item_checked(MODE_MAX + 1, true); mode_popup->connect(SceneStringName(id_pressed), callable_mp(this, &ColorPicker::_set_mode_popup_value)); @@ -1933,7 +1930,7 @@ ColorPicker::ColorPicker() { hex_hbc->set_alignment(ALIGNMENT_BEGIN); vbr->add_child(hex_hbc); - hex_hbc->add_child(memnew(Label("Hex"))); + hex_hbc->add_child(memnew(Label(ETR("Hex")))); text_type = memnew(Button); hex_hbc->add_child(text_type); @@ -1997,8 +1994,7 @@ ColorPicker::ColorPicker() { preset_group.instantiate(); - btn_preset = memnew(Button); - btn_preset->set_text("Swatches"); + btn_preset = memnew(Button(ETR("Swatches"))); btn_preset->set_flat(true); btn_preset->set_toggle_mode(true); btn_preset->set_focus_mode(FOCUS_NONE); @@ -2014,8 +2010,7 @@ ColorPicker::ColorPicker() { recent_preset_group.instantiate(); - btn_recent_preset = memnew(Button); - btn_recent_preset->set_text("Recent Colors"); + btn_recent_preset = memnew(Button(ETR("Recent Colors"))); btn_recent_preset->set_flat(true); btn_recent_preset->set_toggle_mode(true); btn_recent_preset->set_focus_mode(FOCUS_NONE); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 43782409a8..6e5b555cdf 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -103,7 +103,7 @@ void LineEdit::_close_ime_window() { void LineEdit::_update_ime_window_position() { DisplayServer::WindowID wid = get_window() ? get_window()->get_window_id() : DisplayServer::INVALID_WINDOW_ID; - if (wid == DisplayServer::INVALID_WINDOW_ID || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME) || !DisplayServer::get_singleton()->window_is_focused(wid)) { + if (wid == DisplayServer::INVALID_WINDOW_ID || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) { return; } DisplayServer::get_singleton()->window_set_ime_active(true, wid); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 0e8d76d294..6b5ff23436 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2958,7 +2958,7 @@ void TextEdit::_close_ime_window() { void TextEdit::_update_ime_window_position() { DisplayServer::WindowID wid = get_window() ? get_window()->get_window_id() : DisplayServer::INVALID_WINDOW_ID; - if (wid == DisplayServer::INVALID_WINDOW_ID || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME) || !DisplayServer::get_singleton()->window_is_focused(wid)) { + if (wid == DisplayServer::INVALID_WINDOW_ID || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) { return; } DisplayServer::get_singleton()->window_set_ime_active(true, wid); diff --git a/scene/main/SCsub b/scene/main/SCsub index fc61250247..374dc2119d 100644 --- a/scene/main/SCsub +++ b/scene/main/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/resources/2d/SCsub b/scene/resources/2d/SCsub index fdf20e0bde..408aa3cf7e 100644 --- a/scene/resources/2d/SCsub +++ b/scene/resources/2d/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/resources/3d/SCsub b/scene/resources/3d/SCsub index fdf20e0bde..408aa3cf7e 100644 --- a/scene/resources/3d/SCsub +++ b/scene/resources/3d/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/resources/SCsub b/scene/resources/SCsub index 2b6aa88d2c..46f6251b91 100644 --- a/scene/resources/SCsub +++ b/scene/resources/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index a2ed6af23c..9abc6a02d2 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -321,8 +321,12 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { Vector<real_t> times = d["times"]; Vector<real_t> values = d["points"]; #ifdef TOOLS_ENABLED - ERR_FAIL_COND_V(!d.has("handle_modes"), false); - Vector<int> handle_modes = d["handle_modes"]; + Vector<int> handle_modes; + if (d.has("handle_modes")) { + handle_modes = d["handle_modes"]; + } else { + handle_modes.resize_zeroed(times.size()); + } #endif // TOOLS_ENABLED ERR_FAIL_COND_V(times.size() * 5 != values.size(), false); @@ -4804,9 +4808,9 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol continue; // This track is exhausted (all keys were added already), don't consider. } } - - uint32_t key_frame = double(track_get_key_time(uncomp_track, time_tracks[i].key_index)) / frame_len; - + double key_time = track_get_key_time(uncomp_track, time_tracks[i].key_index); + double result = key_time / frame_len; + uint32_t key_frame = Math::fast_ftoi(result); if (time_tracks[i].needs_start_frame && key_frame > base_page_frame) { start_frame = true; best_frame = base_page_frame; diff --git a/scene/resources/camera_texture.cpp b/scene/resources/camera_texture.cpp index b575a099ed..b219f89e59 100644 --- a/scene/resources/camera_texture.cpp +++ b/scene/resources/camera_texture.cpp @@ -47,6 +47,11 @@ void CameraTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "camera_is_active"), "set_camera_active", "get_camera_active"); } +void CameraTexture::_on_format_changed() { + // FIXME: `emit_changed` is more appropriate, but causes errors for some reason. + callable_mp((Resource *)this, &Resource::emit_changed).call_deferred(); +} + int CameraTexture::get_width() const { Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id); if (feed.is_valid()) { @@ -82,13 +87,26 @@ RID CameraTexture::get_rid() const { } Ref<Image> CameraTexture::get_image() const { - // not (yet) supported - return Ref<Image>(); + return RenderingServer::get_singleton()->texture_2d_get(get_rid()); } void CameraTexture::set_camera_feed_id(int p_new_id) { + Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id); + if (feed.is_valid()) { + if (feed->is_connected("format_changed", callable_mp(this, &CameraTexture::_on_format_changed))) { + feed->disconnect("format_changed", callable_mp(this, &CameraTexture::_on_format_changed)); + } + } + camera_feed_id = p_new_id; + + feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id); + if (feed.is_valid()) { + feed->connect("format_changed", callable_mp(this, &CameraTexture::_on_format_changed)); + } + notify_property_list_changed(); + callable_mp((Resource *)this, &Resource::emit_changed).call_deferred(); } int CameraTexture::get_camera_feed_id() const { @@ -98,6 +116,7 @@ int CameraTexture::get_camera_feed_id() const { void CameraTexture::set_which_feed(CameraServer::FeedImage p_which) { which_feed = p_which; notify_property_list_changed(); + callable_mp((Resource *)this, &Resource::emit_changed).call_deferred(); } CameraServer::FeedImage CameraTexture::get_which_feed() const { @@ -109,6 +128,7 @@ void CameraTexture::set_camera_active(bool p_active) { if (feed.is_valid()) { feed->set_active(p_active); notify_property_list_changed(); + callable_mp((Resource *)this, &Resource::emit_changed).call_deferred(); } } diff --git a/scene/resources/camera_texture.h b/scene/resources/camera_texture.h index 521121f9ea..dd216a72d6 100644 --- a/scene/resources/camera_texture.h +++ b/scene/resources/camera_texture.h @@ -43,6 +43,7 @@ private: protected: static void _bind_methods(); + void _on_format_changed(); public: virtual int get_width() const override; diff --git a/scene/theme/SCsub b/scene/theme/SCsub index 2372d1820a..fb0914c0ee 100644 --- a/scene/theme/SCsub +++ b/scene/theme/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scene/theme/icons/SCsub b/scene/theme/icons/SCsub index 1f3b7f6d17..19aca74e57 100644 --- a/scene/theme/icons/SCsub +++ b/scene/theme/icons/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/scu_builders.py b/scu_builders.py index 7fc0c15b2d..3c04d66668 100644 --- a/scu_builders.py +++ b/scu_builders.py @@ -322,6 +322,7 @@ def generate_scu_files(max_includes_per_scu): process_folder(["modules/openxr"], ["register_types"]) process_folder(["modules/openxr/action_map"]) process_folder(["modules/openxr/editor"]) + process_folder(["modules/godot_physics_2d"]) process_folder(["modules/godot_physics_3d"]) process_folder(["modules/godot_physics_3d/joints"]) @@ -350,7 +351,6 @@ def generate_scu_files(max_includes_per_scu): process_folder(["servers/rendering/renderer_rd/effects"]) process_folder(["servers/rendering/renderer_rd/environment"]) process_folder(["servers/rendering/renderer_rd/storage_rd"]) - process_folder(["servers/physics_2d"]) process_folder(["servers/audio"]) process_folder(["servers/audio/effects"]) diff --git a/servers/SCsub b/servers/SCsub index 472cb096ab..7abe53b9e1 100644 --- a/servers/SCsub +++ b/servers/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") @@ -25,8 +26,6 @@ SConscript("navigation/SCsub") SConscript("rendering/SCsub") SConscript("text/SCsub") -SConscript("physics_2d/SCsub") - if not env["disable_3d"]: env.add_source_files(env.servers_sources, "physics_server_3d.cpp") env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp") diff --git a/servers/audio/SCsub b/servers/audio/SCsub index 5021e578c3..7d293c628d 100644 --- a/servers/audio/SCsub +++ b/servers/audio/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/audio/effects/SCsub b/servers/audio/effects/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/audio/effects/SCsub +++ b/servers/audio/effects/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/camera/SCsub b/servers/camera/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/camera/SCsub +++ b/servers/camera/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/camera/camera_feed.cpp b/servers/camera/camera_feed.cpp index 0661ffd576..8f6a40481d 100644 --- a/servers/camera/camera_feed.cpp +++ b/servers/camera/camera_feed.cpp @@ -56,9 +56,16 @@ void CameraFeed::_bind_methods() { ClassDB::bind_method(D_METHOD("get_datatype"), &CameraFeed::get_datatype); + ClassDB::bind_method(D_METHOD("get_formats"), &CameraFeed::get_formats); + ClassDB::bind_method(D_METHOD("set_format", "index", "parameters"), &CameraFeed::set_format); + + ADD_SIGNAL(MethodInfo("frame_changed")); + ADD_SIGNAL(MethodInfo("format_changed")); + ADD_GROUP("Feed", "feed_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "feed_is_active"), "set_active", "is_active"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "feed_transform"), "set_transform", "get_transform"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "formats"), "", "get_formats"); BIND_ENUM_CONSTANT(FEED_NOIMAGE); BIND_ENUM_CONSTANT(FEED_RGB); @@ -84,13 +91,11 @@ void CameraFeed::set_active(bool p_is_active) { } else if (p_is_active) { // attempt to activate this feed if (activate_feed()) { - print_line("Activate " + name); active = true; } } else { // just deactivate it deactivate_feed(); - print_line("Deactivate " + name); active = false; } } @@ -183,6 +188,8 @@ void CameraFeed::set_RGB_img(const Ref<Image> &p_rgb_img) { RID new_texture = RenderingServer::get_singleton()->texture_2d_create(p_rgb_img); RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_RGBA_IMAGE], new_texture); + + emit_signal(SNAME("format_changed")); } else { RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_RGBA_IMAGE], p_rgb_img); } @@ -204,6 +211,8 @@ void CameraFeed::set_YCbCr_img(const Ref<Image> &p_ycbcr_img) { RID new_texture = RenderingServer::get_singleton()->texture_2d_create(p_ycbcr_img); RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_RGBA_IMAGE], new_texture); + + emit_signal(SNAME("format_changed")); } else { RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_RGBA_IMAGE], p_ycbcr_img); } @@ -235,6 +244,8 @@ void CameraFeed::set_YCbCr_imgs(const Ref<Image> &p_y_img, const Ref<Image> &p_c RID new_texture = RenderingServer::get_singleton()->texture_2d_create(p_cbcr_img); RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_CBCR_IMAGE], new_texture); } + + emit_signal(SNAME("format_changed")); } else { RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_Y_IMAGE], p_y_img); RenderingServer::get_singleton()->texture_2d_update(texture[CameraServer::FEED_CBCR_IMAGE], p_cbcr_img); @@ -252,3 +263,16 @@ bool CameraFeed::activate_feed() { void CameraFeed::deactivate_feed() { // nothing to do here } + +bool CameraFeed::set_format(int p_index, const Dictionary &p_parameters) { + return false; +} + +Array CameraFeed::get_formats() const { + return Array(); +} + +CameraFeed::FeedFormat CameraFeed::get_format() const { + FeedFormat feed_format = {}; + return feed_format; +} diff --git a/servers/camera/camera_feed.h b/servers/camera/camera_feed.h index b85a44cfae..5d1f54be07 100644 --- a/servers/camera/camera_feed.h +++ b/servers/camera/camera_feed.h @@ -60,14 +60,26 @@ public: private: int id; // unique id for this, for internal use in case feeds are removed - int base_width; - int base_height; protected: + struct FeedFormat { + int width = 0; + int height = 0; + String format; + int frame_numerator = 0; + int frame_denominator = 0; + uint32_t pixel_format = 0; + }; + String name; // name of our camera feed FeedDataType datatype; // type of texture data stored FeedPosition position; // position of camera on the device Transform2D transform; // display transform + int base_width = 0; + int base_height = 0; + Vector<FeedFormat> formats; + Dictionary parameters; + int selected_format = -1; bool active; // only when active do we actually update the camera texture each frame RID texture[CameraServer::FEED_IMAGES]; // texture images needed for this @@ -102,6 +114,10 @@ public: void set_YCbCr_img(const Ref<Image> &p_ycbcr_img); void set_YCbCr_imgs(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img); + virtual bool set_format(int p_index, const Dictionary &p_parameters); + virtual Array get_formats() const; + virtual FeedFormat get_format() const; + virtual bool activate_feed(); virtual void deactivate_feed(); }; diff --git a/servers/debugger/SCsub b/servers/debugger/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/debugger/SCsub +++ b/servers/debugger/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/display/SCsub b/servers/display/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/display/SCsub +++ b/servers/display/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/extensions/SCsub b/servers/extensions/SCsub index 95c7f5d319..e7bb57e9f3 100644 --- a/servers/extensions/SCsub +++ b/servers/extensions/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/movie_writer/SCsub b/servers/movie_writer/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/movie_writer/SCsub +++ b/servers/movie_writer/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/navigation/SCsub b/servers/navigation/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/navigation/SCsub +++ b/servers/navigation/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/physics_2d/SCsub b/servers/physics_2d/SCsub deleted file mode 100644 index 86681f9c74..0000000000 --- a/servers/physics_2d/SCsub +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python - -Import("env") - -env.add_source_files(env.servers_sources, "*.cpp") diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index da25621ba5..f4f9a2e8b7 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -972,7 +972,9 @@ String PhysicsServer2DManager::get_server_name(int p_id) { } PhysicsServer2D *PhysicsServer2DManager::new_default_server() { - ERR_FAIL_COND_V(default_server_id == -1, nullptr); + if (default_server_id == -1) { + return nullptr; + } Variant ret; Callable::CallError ce; physics_2d_servers[default_server_id].create_callback.callp(nullptr, 0, ret, ce); diff --git a/servers/physics_server_2d_dummy.h b/servers/physics_server_2d_dummy.h new file mode 100644 index 0000000000..1f211d7ce0 --- /dev/null +++ b/servers/physics_server_2d_dummy.h @@ -0,0 +1,350 @@ +/**************************************************************************/ +/* physics_server_2d_dummy.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef PHYSICS_SERVER_2D_DUMMY_H +#define PHYSICS_SERVER_2D_DUMMY_H + +#include "physics_server_2d.h" + +class PhysicsDirectBodyState2DDummy : public PhysicsDirectBodyState2D { + GDCLASS(PhysicsDirectBodyState2DDummy, PhysicsDirectBodyState2D); + + PhysicsDirectSpaceState2D *space_state_dummy = nullptr; + +public: + virtual Vector2 get_total_gravity() const override { return Vector2(); } + virtual real_t get_total_linear_damp() const override { return 0; } + virtual real_t get_total_angular_damp() const override { return 0; } + + virtual Vector2 get_center_of_mass() const override { return Vector2(); } + virtual Vector2 get_center_of_mass_local() const override { return Vector2(); } + virtual real_t get_inverse_mass() const override { return 0; } + virtual real_t get_inverse_inertia() const override { return 0; } + + virtual void set_linear_velocity(const Vector2 &p_velocity) override {} + virtual Vector2 get_linear_velocity() const override { return Vector2(); } + + virtual void set_angular_velocity(real_t p_velocity) override {} + virtual real_t get_angular_velocity() const override { return 0; } + + virtual void set_transform(const Transform2D &p_transform) override {} + virtual Transform2D get_transform() const override { return Transform2D(); } + + virtual Vector2 get_velocity_at_local_position(const Vector2 &p_position) const override { return Vector2(); } + + virtual void apply_central_impulse(const Vector2 &p_impulse) override {} + virtual void apply_torque_impulse(real_t p_torque) override {} + virtual void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) override {} + + virtual void apply_central_force(const Vector2 &p_force) override {} + virtual void apply_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {} + virtual void apply_torque(real_t p_torque) override {} + + virtual void add_constant_central_force(const Vector2 &p_force) override {} + virtual void add_constant_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {} + virtual void add_constant_torque(real_t p_torque) override {} + + virtual void set_constant_force(const Vector2 &p_force) override {} + virtual Vector2 get_constant_force() const override { return Vector2(); } + + virtual void set_constant_torque(real_t p_torque) override {} + virtual real_t get_constant_torque() const override { return 0; } + + virtual void set_sleep_state(bool p_enable) override {} + virtual bool is_sleeping() const override { return false; } + + virtual int get_contact_count() const override { return 0; } + + virtual Vector2 get_contact_local_position(int p_contact_idx) const override { return Vector2(); } + virtual Vector2 get_contact_local_normal(int p_contact_idx) const override { return Vector2(); } + virtual int get_contact_local_shape(int p_contact_idx) const override { return 0; } + virtual Vector2 get_contact_local_velocity_at_position(int p_contact_idx) const override { return Vector2(); } + + virtual RID get_contact_collider(int p_contact_idx) const override { return RID(); } + virtual Vector2 get_contact_collider_position(int p_contact_idx) const override { return Vector2(); } + virtual ObjectID get_contact_collider_id(int p_contact_idx) const override { return ObjectID(); } + virtual Object *get_contact_collider_object(int p_contact_idx) const override { return nullptr; } + virtual int get_contact_collider_shape(int p_contact_idx) const override { return 0; } + virtual Vector2 get_contact_collider_velocity_at_position(int p_contact_idx) const override { return Vector2(); } + virtual Vector2 get_contact_impulse(int p_contact_idx) const override { return Vector2(); } + + virtual real_t get_step() const override { return 0; } + virtual void integrate_forces() override {} + + virtual PhysicsDirectSpaceState2D *get_space_state() override { return space_state_dummy; } + + PhysicsDirectBodyState2DDummy(PhysicsDirectSpaceState2D *p_space_state_dummy) { + space_state_dummy = p_space_state_dummy; + } +}; + +class PhysicsDirectSpaceState2DDummy : public PhysicsDirectSpaceState2D { + GDCLASS(PhysicsDirectSpaceState2DDummy, PhysicsDirectSpaceState2D); + +public: + virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) override { return false; } + + virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { return 0; } + + virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { return 0; } + virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe) override { return false; } + virtual bool collide_shape(const ShapeParameters &p_parameters, Vector2 *r_results, int p_result_max, int &r_result_count) override { return false; } + virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) override { return false; } +}; + +class PhysicsServer2DDummy : public PhysicsServer2D { + GDCLASS(PhysicsServer2DDummy, PhysicsServer2D); + + PhysicsDirectSpaceState2DDummy *space_state_dummy = nullptr; + PhysicsDirectBodyState2DDummy *body_state_dummy = nullptr; + +public: + virtual RID world_boundary_shape_create() override { return RID(); } + virtual RID separation_ray_shape_create() override { return RID(); } + virtual RID segment_shape_create() override { return RID(); } + virtual RID circle_shape_create() override { return RID(); } + virtual RID rectangle_shape_create() override { return RID(); } + virtual RID capsule_shape_create() override { return RID(); } + virtual RID convex_polygon_shape_create() override { return RID(); } + virtual RID concave_polygon_shape_create() override { return RID(); } + + virtual void shape_set_data(RID p_shape, const Variant &p_data) override {} + virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) override {} + + virtual ShapeType shape_get_type(RID p_shape) const override { return ShapeType::SHAPE_CIRCLE; } + virtual Variant shape_get_data(RID p_shape) const override { return Variant(); } + virtual real_t shape_get_custom_solver_bias(RID p_shape) const override { return 0; } + + virtual bool shape_collide(RID p_shape_A, const Transform2D &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Transform2D &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) override { return false; } + + /* SPACE API */ + + virtual RID space_create() override { return RID(); } + virtual void space_set_active(RID p_space, bool p_active) override {} + virtual bool space_is_active(RID p_space) const override { return false; } + + virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) override {} + virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const override { return 0; } + + virtual PhysicsDirectSpaceState2D *space_get_direct_state(RID p_space) override { return space_state_dummy; } + + virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) override {} + virtual Vector<Vector2> space_get_contacts(RID p_space) const override { return Vector<Vector2>(); } + virtual int space_get_contact_count(RID p_space) const override { return 0; } + + /* AREA API */ + + virtual RID area_create() override { return RID(); } + + virtual void area_set_space(RID p_area, RID p_space) override {} + virtual RID area_get_space(RID p_area) const override { return RID(); } + + virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) override {} + virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) override {} + virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) override {} + + virtual int area_get_shape_count(RID p_area) const override { return 0; } + virtual RID area_get_shape(RID p_area, int p_shape_idx) const override { return RID(); } + virtual Transform2D area_get_shape_transform(RID p_area, int p_shape_idx) const override { return Transform2D(); } + + virtual void area_remove_shape(RID p_area, int p_shape_idx) override {} + virtual void area_clear_shapes(RID p_area) override {} + + virtual void area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) override {} + + virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) override {} + virtual ObjectID area_get_object_instance_id(RID p_area) const override { return ObjectID(); } + + virtual void area_attach_canvas_instance_id(RID p_area, ObjectID p_id) override {} + virtual ObjectID area_get_canvas_instance_id(RID p_area) const override { return ObjectID(); } + + virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) override {} + virtual void area_set_transform(RID p_area, const Transform2D &p_transform) override {} + + virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const override { return Variant(); } + virtual Transform2D area_get_transform(RID p_area) const override { return Transform2D(); } + + virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) override {} + virtual uint32_t area_get_collision_layer(RID p_area) const override { return 0; } + + virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override {} + virtual uint32_t area_get_collision_mask(RID p_area) const override { return 0; } + + virtual void area_set_monitorable(RID p_area, bool p_monitorable) override {} + virtual void area_set_pickable(RID p_area, bool p_pickable) override {} + + virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) override {} + virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) override {} + + /* BODY API */ + + virtual RID body_create() override { return RID(); } + + virtual void body_set_space(RID p_body, RID p_space) override {} + virtual RID body_get_space(RID p_body) const override { return RID(); } + + virtual void body_set_mode(RID p_body, BodyMode p_mode) override {} + virtual BodyMode body_get_mode(RID p_body) const override { return BodyMode::BODY_MODE_STATIC; } + + virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) override {} + virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) override {} + virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) override {} + + virtual int body_get_shape_count(RID p_body) const override { return 0; } + virtual RID body_get_shape(RID p_body, int p_shape_idx) const override { return RID(); } + virtual Transform2D body_get_shape_transform(RID p_body, int p_shape_idx) const override { return Transform2D(); } + + virtual void body_set_shape_disabled(RID p_body, int p_shape, bool p_disabled) override {} + virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled, real_t p_margin = 0) override {} + + virtual void body_remove_shape(RID p_body, int p_shape_idx) override {} + virtual void body_clear_shapes(RID p_body) override {} + + virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) override {} + virtual ObjectID body_get_object_instance_id(RID p_body) const override { return ObjectID(); } + + virtual void body_attach_canvas_instance_id(RID p_body, ObjectID p_id) override {} + virtual ObjectID body_get_canvas_instance_id(RID p_body) const override { return ObjectID(); } + + virtual void body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) override {} + virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const override { return CCDMode::CCD_MODE_DISABLED; } + + virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) override {} + virtual uint32_t body_get_collision_layer(RID p_body) const override { return 0; } + + virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) override {} + virtual uint32_t body_get_collision_mask(RID p_body) const override { return 0; } + + virtual void body_set_collision_priority(RID p_body, real_t p_priority) override {} + virtual real_t body_get_collision_priority(RID p_body) const override { return 0; } + + virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) override {} + virtual Variant body_get_param(RID p_body, BodyParameter p_param) const override { return Variant(); } + + virtual void body_reset_mass_properties(RID p_body) override {} + + virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override {} + virtual Variant body_get_state(RID p_body, BodyState p_state) const override { return Variant(); } + + virtual void body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) override {} + virtual void body_apply_torque_impulse(RID p_body, real_t p_torque) override {} + virtual void body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) override {} + + virtual void body_apply_central_force(RID p_body, const Vector2 &p_force) override {} + virtual void body_apply_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {} + virtual void body_apply_torque(RID p_body, real_t p_torque) override {} + + virtual void body_add_constant_central_force(RID p_body, const Vector2 &p_force) override {} + virtual void body_add_constant_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {} + virtual void body_add_constant_torque(RID p_body, real_t p_torque) override {} + + virtual void body_set_constant_force(RID p_body, const Vector2 &p_force) override {} + virtual Vector2 body_get_constant_force(RID p_body) const override { return Vector2(); } + + virtual void body_set_constant_torque(RID p_body, real_t p_torque) override {} + virtual real_t body_get_constant_torque(RID p_body) const override { return 0; } + + virtual void body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) override {} + + virtual void body_add_collision_exception(RID p_body, RID p_body_b) override {} + virtual void body_remove_collision_exception(RID p_body, RID p_body_b) override {} + virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override {} + + virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) override {} + virtual int body_get_max_contacts_reported(RID p_body) const override { return 0; } + + virtual void body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) override {} + virtual real_t body_get_contacts_reported_depth_threshold(RID p_body) const override { return 0; } + + virtual void body_set_omit_force_integration(RID p_body, bool p_omit) override {} + virtual bool body_is_omitting_force_integration(RID p_body) const override { return false; } + + virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) override {} + virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) override {} + + virtual bool body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) override { return false; } + + virtual void body_set_pickable(RID p_body, bool p_pickable) override {} + + virtual PhysicsDirectBodyState2D *body_get_direct_state(RID p_body) override { return body_state_dummy; } + + virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override { return false; } + + /* JOINT API */ + + virtual RID joint_create() override { return RID(); } + + virtual void joint_clear(RID p_joint) override {} + + virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value) override {} + virtual real_t joint_get_param(RID p_joint, JointParam p_param) const override { return 0; } + + virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) override {} + virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const override { return false; } + + virtual void joint_make_pin(RID p_joint, const Vector2 &p_anchor, RID p_body_a, RID p_body_b = RID()) override {} + virtual void joint_make_groove(RID p_joint, const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, RID p_body_a, RID p_body_b) override {} + virtual void joint_make_damped_spring(RID p_joint, const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, RID p_body_a, RID p_body_b = RID()) override {} + + virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) override {} + virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const override { return 0; } + + virtual void pin_joint_set_flag(RID p_joint, PinJointFlag p_flag, bool p_enabled) override {} + virtual bool pin_joint_get_flag(RID p_joint, PinJointFlag p_flag) const override { return false; } + + virtual void damped_spring_joint_set_param(RID p_joint, DampedSpringParam p_param, real_t p_value) override {} + virtual real_t damped_spring_joint_get_param(RID p_joint, DampedSpringParam p_param) const override { return 0; } + + virtual JointType joint_get_type(RID p_joint) const override { return JointType::JOINT_TYPE_PIN; } + + /* MISC */ + + virtual void free(RID p_rid) override {} + + virtual void set_active(bool p_active) override {} + virtual void init() override { + space_state_dummy = memnew(PhysicsDirectSpaceState2DDummy); + body_state_dummy = memnew(PhysicsDirectBodyState2DDummy(space_state_dummy)); + } + virtual void step(real_t p_step) override {} + virtual void sync() override {} + virtual void flush_queries() override {} + virtual void end_sync() override {} + virtual void finish() override { + memdelete(body_state_dummy); + memdelete(space_state_dummy); + } + + virtual bool is_flushing_queries() const override { return false; } + + virtual int get_process_info(ProcessInfo p_info) override { return 0; } +}; + +#endif // PHYSICS_SERVER_2D_DUMMY_H diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index b23c77aa0a..18ee863083 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -81,8 +81,8 @@ // 2D physics and navigation. #include "navigation_server_2d.h" -#include "physics_2d/godot_physics_server_2d.h" #include "physics_server_2d.h" +#include "physics_server_2d_dummy.h" #include "physics_server_2d_wrap_mt.h" #include "servers/extensions/physics_server_2d_extension.h" @@ -111,16 +111,8 @@ static PhysicsServer3D *_create_dummy_physics_server_3d() { } #endif // _3D_DISABLED -static PhysicsServer2D *_createGodotPhysics2DCallback() { -#ifdef THREADS_ENABLED - bool using_threads = GLOBAL_GET("physics/2d/run_on_separate_thread"); -#else - bool using_threads = false; -#endif - - PhysicsServer2D *physics_server_2d = memnew(GodotPhysicsServer2D(using_threads)); - - return memnew(PhysicsServer2DWrapMT(physics_server_2d, using_threads)); +static PhysicsServer2D *_create_dummy_physics_server_2d() { + return memnew(PhysicsServer2DDummy); } static bool has_server_feature_callback(const String &p_feature) { @@ -281,8 +273,7 @@ void register_server_types() { GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer2DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT"); - PhysicsServer2DManager::get_singleton()->register_server("GodotPhysics2D", callable_mp_static(_createGodotPhysics2DCallback)); - PhysicsServer2DManager::get_singleton()->set_default_server("GodotPhysics2D"); + PhysicsServer2DManager::get_singleton()->register_server("Dummy", callable_mp_static(_create_dummy_physics_server_2d)); GDREGISTER_ABSTRACT_CLASS(NavigationServer2D); GDREGISTER_CLASS(NavigationPathQueryParameters2D); diff --git a/servers/rendering/SCsub b/servers/rendering/SCsub index cf26ca029d..9971761818 100644 --- a/servers/rendering/SCsub +++ b/servers/rendering/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/dummy/SCsub b/servers/rendering/dummy/SCsub index aa688af6cd..3e1f338227 100644 --- a/servers/rendering/dummy/SCsub +++ b/servers/rendering/dummy/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/dummy/storage/SCsub b/servers/rendering/dummy/storage/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/rendering/dummy/storage/SCsub +++ b/servers/rendering/dummy/storage/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/SCsub b/servers/rendering/renderer_rd/SCsub index a27439e931..c6d9e3ef36 100644 --- a/servers/rendering/renderer_rd/SCsub +++ b/servers/rendering/renderer_rd/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/effects/SCsub b/servers/rendering/renderer_rd/effects/SCsub index 8e13715447..9f330c9f0f 100644 --- a/servers/rendering/renderer_rd/effects/SCsub +++ b/servers/rendering/renderer_rd/effects/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/environment/SCsub b/servers/rendering/renderer_rd/environment/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/rendering/renderer_rd/environment/SCsub +++ b/servers/rendering/renderer_rd/environment/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/forward_clustered/SCsub b/servers/rendering/renderer_rd/forward_clustered/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/rendering/renderer_rd/forward_clustered/SCsub +++ b/servers/rendering/renderer_rd/forward_clustered/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/forward_mobile/SCsub b/servers/rendering/renderer_rd/forward_mobile/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/rendering/renderer_rd/forward_mobile/SCsub +++ b/servers/rendering/renderer_rd/forward_mobile/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/shaders/SCsub b/servers/rendering/renderer_rd/shaders/SCsub index 5405985741..e102b839b5 100644 --- a/servers/rendering/renderer_rd/shaders/SCsub +++ b/servers/rendering/renderer_rd/shaders/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/shaders/effects/SCsub b/servers/rendering/renderer_rd/shaders/effects/SCsub index 810f781340..e5517e52eb 100644 --- a/servers/rendering/renderer_rd/shaders/effects/SCsub +++ b/servers/rendering/renderer_rd/shaders/effects/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/shaders/effects/fsr2/SCsub b/servers/rendering/renderer_rd/shaders/effects/fsr2/SCsub index 5b8bbc343b..53f3ee3977 100644 --- a/servers/rendering/renderer_rd/shaders/effects/fsr2/SCsub +++ b/servers/rendering/renderer_rd/shaders/effects/fsr2/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl b/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl index 841f02f673..fa3b45a962 100644 --- a/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl +++ b/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl @@ -256,8 +256,12 @@ vec3 tonemap_aces(vec3 color, float white) { return color_tonemapped / white_tonemapped; } +// Based on Reinhard's extended formula, see equation 4 in https://doi.org/cjbgrt vec3 tonemap_reinhard(vec3 color, float white) { - return (white * color + color) / (color * white + white); + float white_squared = white * white; + vec3 white_squared_color = white_squared * color; + // Equivalent to color * (1 + color / white_squared) / (1 + color) + return (white_squared_color + color * color) / (white_squared_color + white_squared); } vec3 linear_to_srgb(vec3 color) { @@ -272,7 +276,7 @@ vec3 linear_to_srgb(vec3 color) { #define TONEMAPPER_FILMIC 2 #define TONEMAPPER_ACES 3 -vec3 apply_tonemapping(vec3 color, float white) { // inputs are LINEAR, always outputs clamped [0;1] color +vec3 apply_tonemapping(vec3 color, float white) { // inputs are LINEAR // Ensure color values passed to tonemappers are positive. // They can be negative in the case of negative lights, which leads to undesired behavior. if (params.tonemapper == TONEMAPPER_LINEAR) { diff --git a/servers/rendering/renderer_rd/shaders/environment/SCsub b/servers/rendering/renderer_rd/shaders/environment/SCsub index f06a2d86e2..2c3e7d39ef 100644 --- a/servers/rendering/renderer_rd/shaders/environment/SCsub +++ b/servers/rendering/renderer_rd/shaders/environment/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/shaders/forward_clustered/SCsub b/servers/rendering/renderer_rd/shaders/forward_clustered/SCsub index f06a2d86e2..2c3e7d39ef 100644 --- a/servers/rendering/renderer_rd/shaders/forward_clustered/SCsub +++ b/servers/rendering/renderer_rd/shaders/forward_clustered/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/shaders/forward_mobile/SCsub b/servers/rendering/renderer_rd/shaders/forward_mobile/SCsub index f06a2d86e2..2c3e7d39ef 100644 --- a/servers/rendering/renderer_rd/shaders/forward_mobile/SCsub +++ b/servers/rendering/renderer_rd/shaders/forward_mobile/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/spirv-reflect/SCsub b/servers/rendering/renderer_rd/spirv-reflect/SCsub index 4c27e5bef7..8d3d8560a5 100644 --- a/servers/rendering/renderer_rd/spirv-reflect/SCsub +++ b/servers/rendering/renderer_rd/spirv-reflect/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_rd/storage_rd/SCsub b/servers/rendering/renderer_rd/storage_rd/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/rendering/renderer_rd/storage_rd/SCsub +++ b/servers/rendering/renderer_rd/storage_rd/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 781d29ffaa..4d6435f48a 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -41,14 +41,31 @@ static Transform2D _canvas_get_transform(RendererViewport::Viewport *p_viewport, RendererCanvasCull::Canvas *p_canvas, RendererViewport::Viewport::CanvasData *p_canvas_data, const Vector2 &p_vp_size) { Transform2D xf = p_viewport->global_transform; + Vector2 pixel_snap_offset; + if (p_viewport->snap_2d_transforms_to_pixel) { + // We use `floor(p + 0.5)` to snap canvas items, but `ceil(p - 0.5)` + // to snap viewport transform because the viewport transform is inverse + // to the camera transform. Also, if the viewport size is not divisible + // by 2, the center point is offset by 0.5 px and we need to add 0.5 + // before rounding to cancel it out. + pixel_snap_offset.x = (p_viewport->size.width % 2) ? 0.0 : -0.5; + pixel_snap_offset.y = (p_viewport->size.height % 2) ? 0.0 : -0.5; + } + float scale = 1.0; if (p_viewport->canvas_map.has(p_canvas->parent)) { Transform2D c_xform = p_viewport->canvas_map[p_canvas->parent].transform; + if (p_viewport->snap_2d_transforms_to_pixel) { + c_xform.columns[2] = (c_xform.columns[2] * p_canvas->parent_scale + pixel_snap_offset).ceil() / p_canvas->parent_scale; + } xf = xf * c_xform; scale = p_canvas->parent_scale; } Transform2D c_xform = p_canvas_data->transform; + if (p_viewport->snap_2d_transforms_to_pixel) { + c_xform.columns[2] = (c_xform.columns[2] + pixel_snap_offset).ceil(); + } xf = xf * c_xform; if (scale != 1.0 && !RSG::canvas->disable_scale) { diff --git a/servers/rendering/storage/SCsub b/servers/rendering/storage/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/rendering/storage/SCsub +++ b/servers/rendering/storage/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/text/SCsub b/servers/text/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/text/SCsub +++ b/servers/text/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/servers/xr/SCsub b/servers/xr/SCsub index 86681f9c74..98f918b245 100644 --- a/servers/xr/SCsub +++ b/servers/xr/SCsub @@ -1,4 +1,5 @@ #!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/tests/SCsub b/tests/SCsub index d96a1142e4..169c7c1efa 100644 --- a/tests/SCsub +++ b/tests/SCsub @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python +from misc.utility.scons_hints import * Import("env") diff --git a/tests/scene/test_viewport.h b/tests/scene/test_viewport.h index 9d02c41719..dde37944ec 100644 --- a/tests/scene/test_viewport.h +++ b/tests/scene/test_viewport.h @@ -38,6 +38,7 @@ #include "scene/main/canvas_layer.h" #include "scene/main/window.h" #include "scene/resources/2d/rectangle_shape_2d.h" +#include "servers/physics_server_2d_dummy.h" #include "tests/test_macros.h" @@ -1550,6 +1551,12 @@ int TestArea2D::counter = 0; TEST_CASE("[SceneTree][Viewport] Physics Picking 2D") { // FIXME: MOUSE_MODE_CAPTURED if-conditions are not testable, because DisplayServerMock doesn't support it. + // NOTE: This test requires a real physics server. + PhysicsServer2DDummy *physics_server_2d_dummy = Object::cast_to<PhysicsServer2DDummy>(PhysicsServer2D::get_singleton()); + if (physics_server_2d_dummy) { + return; + } + struct PickingCollider { TestArea2D *a; CollisionShape2D *c; diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 3c184ccc5d..12ff3ad4bc 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -174,6 +174,7 @@ #include "servers/navigation_server_3d.h" #endif // _3D_DISABLED #include "servers/physics_server_2d.h" +#include "servers/physics_server_2d_dummy.h" #ifndef _3D_DISABLED #include "servers/physics_server_3d.h" #include "servers/physics_server_3d_dummy.h" @@ -298,6 +299,9 @@ struct GodotTestCaseListener : public doctest::IReporter { #endif // _3D_DISABLED physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server(); + if (!physics_server_2d) { + physics_server_2d = memnew(PhysicsServer2DDummy); + } physics_server_2d->init(); #ifndef _3D_DISABLED |