summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaul Santos <raulsntos@gmail.com>2023-02-02 00:54:16 +0100
committerRaul Santos <raulsntos@gmail.com>2023-05-29 19:04:02 +0200
commita1f454fee353fadbdb6f7032b6458f92be46560c (patch)
treeb5dd332d65aeee6745845cbffb7feabc1c59ed35
parent2eec9a67d564b11326f44c5ef8b6b6f9aec251b9 (diff)
downloadredot-engine-a1f454fee353fadbdb6f7032b6458f92be46560c.tar.gz
C#: Add global class support
Co-authored-by: willnationsdev <willnationsdev@gmail.com>
-rw-r--r--modules/mono/csharp_script.cpp74
-rw-r--r--modules/mono/csharp_script.h7
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs3
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotClasses.cs1
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs19
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/GlobalClassAttribute.cs12
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/IconAttribute.cs25
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ManagedCallbacks.cs2
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs29
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs4
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj2
-rw-r--r--modules/mono/glue/runtime_interop.cpp24
-rw-r--r--modules/mono/mono_gd/gd_mono.cpp10
-rw-r--r--modules/mono/mono_gd/gd_mono.h12
-rw-r--r--modules/mono/mono_gd/gd_mono_cache.h2
15 files changed, 201 insertions, 25 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index a12cac5a99..20b36fc377 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -42,6 +42,7 @@
#ifdef TOOLS_ENABLED
#include "core/os/keyboard.h"
+#include "editor/editor_file_system.h"
#include "editor/editor_internal_calls.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
@@ -535,6 +536,48 @@ String CSharpLanguage::_get_indentation() const {
return "\t";
}
+bool CSharpLanguage::handles_global_class_type(const String &p_type) const {
+ return p_type == get_type();
+}
+
+String CSharpLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
+ Ref<CSharpScript> scr = ResourceLoader::load(p_path, get_type());
+ if (!scr.is_valid() || !scr->valid || !scr->global_class) {
+ // Invalid script or the script is not a global class.
+ return String();
+ }
+
+ String name = scr->class_name;
+ if (unlikely(name.is_empty())) {
+ return String();
+ }
+
+ if (r_icon_path) {
+ if (scr->icon_path.is_empty() || scr->icon_path.is_absolute_path()) {
+ *r_icon_path = scr->icon_path.simplify_path();
+ } else if (scr->icon_path.is_relative_path()) {
+ *r_icon_path = p_path.get_base_dir().path_join(scr->icon_path).simplify_path();
+ }
+ }
+ if (r_base_type) {
+ bool found_global_base_script = false;
+ const CSharpScript *top = scr->base_script.ptr();
+ while (top != nullptr) {
+ if (top->global_class) {
+ *r_base_type = top->class_name;
+ found_global_base_script = true;
+ break;
+ }
+
+ top = top->base_script.ptr();
+ }
+ if (!found_global_base_script) {
+ *r_base_type = scr->get_instance_base_type();
+ }
+ }
+ return name;
+}
+
String CSharpLanguage::debug_get_error() const {
return _debug_error;
}
@@ -2203,11 +2246,21 @@ void CSharpScript::reload_registered_script(Ref<CSharpScript> p_script) {
update_script_class_info(p_script);
p_script->_update_exports();
+
+#if TOOLS_ENABLED
+ // If the EditorFileSystem singleton is available, update the file;
+ // otherwise, the file will be updated when the singleton becomes available.
+ EditorFileSystem *efs = EditorFileSystem::get_singleton();
+ if (efs) {
+ efs->update_file(p_script->get_path());
+ }
+#endif
}
// Extract information about the script using the mono class.
void CSharpScript::update_script_class_info(Ref<CSharpScript> p_script) {
bool tool = false;
+ bool global_class = false;
// TODO: Use GDExtension godot_dictionary
Array methods_array;
@@ -2217,11 +2270,17 @@ void CSharpScript::update_script_class_info(Ref<CSharpScript> p_script) {
Dictionary signals_dict;
signals_dict.~Dictionary();
+ String class_name;
+ String icon_path;
Ref<CSharpScript> base_script;
GDMonoCache::managed_callbacks.ScriptManagerBridge_UpdateScriptClassInfo(
- p_script.ptr(), &tool, &methods_array, &rpc_functions_dict, &signals_dict, &base_script);
+ p_script.ptr(), &class_name, &tool, &global_class, &icon_path,
+ &methods_array, &rpc_functions_dict, &signals_dict, &base_script);
+ p_script->class_name = class_name;
p_script->tool = tool;
+ p_script->global_class = global_class;
+ p_script->icon_path = icon_path;
p_script->rpc_config.clear();
p_script->rpc_config = rpc_functions_dict;
@@ -2519,6 +2578,15 @@ Error CSharpScript::reload(bool p_keep_state) {
update_script_class_info(this);
_update_exports();
+
+#if TOOLS_ENABLED
+ // If the EditorFileSystem singleton is available, update the file;
+ // otherwise, the file will be updated when the singleton becomes available.
+ EditorFileSystem *efs = EditorFileSystem::get_singleton();
+ if (efs) {
+ efs->update_file(script_path);
+ }
+#endif
}
return OK;
@@ -2605,11 +2673,11 @@ bool CSharpScript::inherits_script(const Ref<Script> &p_script) const {
}
Ref<Script> CSharpScript::get_base_script() const {
- return base_script;
+ return base_script.is_valid() && !base_script->get_path().is_empty() ? base_script : nullptr;
}
StringName CSharpScript::get_global_name() const {
- return StringName();
+ return global_class ? StringName(class_name) : StringName();
}
void CSharpScript::get_script_property_list(List<PropertyInfo> *r_list) const {
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index 02c354f74e..13c7c4b412 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -62,6 +62,7 @@ class CSharpScript : public Script {
friend class CSharpLanguage;
bool tool = false;
+ bool global_class = false;
bool valid = false;
bool reload_invalidated = false;
@@ -86,6 +87,8 @@ class CSharpScript : public Script {
#endif
String source;
+ String class_name;
+ String icon_path;
SelfList<CSharpScript> script_list = this;
@@ -442,6 +445,10 @@ public:
/* TODO? */ void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override {}
/* TODO */ void add_global_constant(const StringName &p_variable, const Variant &p_value) override {}
+ /* SCRIPT GLOBAL CLASS FUNCTIONS */
+ virtual bool handles_global_class_type(const String &p_type) const override;
+ virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const override;
+
/* DEBUGGER FUNCTIONS */
String debug_get_error() const override;
int debug_get_stack_level_count() const override;
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs
index 7f627f0dc4..38af1cbade 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs
@@ -241,6 +241,9 @@ namespace Godot.SourceGenerators
public static bool IsGodotClassNameAttribute(this INamedTypeSymbol symbol)
=> symbol.ToString() == GodotClasses.GodotClassNameAttr;
+ public static bool IsGodotGlobalClassAttribute(this INamedTypeSymbol symbol)
+ => symbol.ToString() == GodotClasses.GlobalClassAttr;
+
public static bool IsSystemFlagsAttribute(this INamedTypeSymbol symbol)
=> symbol.ToString() == GodotClasses.SystemFlagsAttr;
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotClasses.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotClasses.cs
index b60148b34f..e80837dbe0 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotClasses.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotClasses.cs
@@ -11,6 +11,7 @@ namespace Godot.SourceGenerators
public const string SignalAttr = "Godot.SignalAttribute";
public const string MustBeVariantAttr = "Godot.MustBeVariantAttribute";
public const string GodotClassNameAttr = "Godot.GodotClassNameAttribute";
+ public const string GlobalClassAttr = "Godot.GlobalClassAttribute";
public const string SystemFlagsAttr = "System.FlagsAttribute";
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
index ef8e6f8fff..e856ad5c13 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
@@ -547,25 +547,32 @@ namespace Godot.SourceGenerators
{
if (memberNamedType.InheritsFrom("GodotSharp", "Godot.Resource"))
{
- string nativeTypeName = memberNamedType.GetGodotScriptNativeClassName()!;
-
hint = PropertyHint.ResourceType;
- hintString = nativeTypeName;
+ hintString = GetTypeName(memberNamedType);
return true;
}
if (memberNamedType.InheritsFrom("GodotSharp", "Godot.Node"))
{
- string nativeTypeName = memberNamedType.GetGodotScriptNativeClassName()!;
-
hint = PropertyHint.NodeType;
- hintString = nativeTypeName;
+ hintString = GetTypeName(memberNamedType);
return true;
}
}
+ static string GetTypeName(INamedTypeSymbol memberSymbol)
+ {
+ if (memberSymbol.GetAttributes()
+ .Any(a => a.AttributeClass?.IsGodotGlobalClassAttribute() ?? false))
+ {
+ return memberSymbol.Name;
+ }
+
+ return memberSymbol.GetGodotScriptNativeClassName()!;
+ }
+
static bool GetStringArrayEnumHint(VariantType elementVariantType,
AttributeData exportAttr, out string? hintString)
{
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/GlobalClassAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/GlobalClassAttribute.cs
new file mode 100644
index 0000000000..8f3297839d
--- /dev/null
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/GlobalClassAttribute.cs
@@ -0,0 +1,12 @@
+using System;
+
+#nullable enable
+
+namespace Godot
+{
+ /// <summary>
+ /// Exposes the target class as a global script class to Godot Engine.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class)]
+ public sealed class GlobalClassAttribute : Attribute { }
+}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/IconAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/IconAttribute.cs
new file mode 100644
index 0000000000..7b5c73c082
--- /dev/null
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/IconAttribute.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace Godot
+{
+ /// <summary>
+ /// Specifies a custom icon for representing this class in the Godot Editor.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class)]
+ public sealed class IconAttribute : Attribute
+ {
+ /// <summary>
+ /// File path to a custom icon for representing this class in the Godot Editor.
+ /// </summary>
+ public string Path { get; }
+
+ /// <summary>
+ /// Specify the custom icon that represents the class.
+ /// </summary>
+ /// <param name="path">File path to the custom icon.</param>
+ public IconAttribute(string path)
+ {
+ Path = path;
+ }
+ }
+}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ManagedCallbacks.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ManagedCallbacks.cs
index 03744fc4e3..0571515e61 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ManagedCallbacks.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ManagedCallbacks.cs
@@ -25,7 +25,7 @@ namespace Godot.Bridge
public delegate* unmanaged<godot_string*, godot_ref*, void> ScriptManagerBridge_GetOrCreateScriptBridgeForPath;
public delegate* unmanaged<IntPtr, void> ScriptManagerBridge_RemoveScriptBridge;
public delegate* unmanaged<IntPtr, godot_bool> ScriptManagerBridge_TryReloadRegisteredScriptWithClass;
- public delegate* unmanaged<IntPtr, godot_bool*, godot_array*, godot_dictionary*, godot_dictionary*, godot_ref*, void> ScriptManagerBridge_UpdateScriptClassInfo;
+ public delegate* unmanaged<IntPtr, godot_string*, godot_bool*, godot_bool*, godot_string*, godot_array*, godot_dictionary*, godot_dictionary*, godot_ref*, void> ScriptManagerBridge_UpdateScriptClassInfo;
public delegate* unmanaged<IntPtr, IntPtr*, godot_bool, godot_bool> ScriptManagerBridge_SwapGCHandleForType;
public delegate* unmanaged<IntPtr, delegate* unmanaged<IntPtr, godot_string*, void*, int, void>, void> ScriptManagerBridge_GetPropertyInfoList;
public delegate* unmanaged<IntPtr, delegate* unmanaged<IntPtr, void*, int, void>, void> ScriptManagerBridge_GetPropertyDefaultValues;
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
index ec2728140e..98c9ed3f0e 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
@@ -298,6 +298,13 @@ namespace Godot.Bridge
_pathTypeBiMap.Add(scriptPathAttr.Path, type);
+ // This method may be called before initialization.
+ if (NativeFuncs.godotsharp_dotnet_module_is_initialized().ToBool() && Engine.IsEditorHint())
+ {
+ using godot_string scriptPath = Marshaling.ConvertStringToNative(scriptPathAttr.Path);
+ NativeFuncs.godotsharp_internal_editor_file_system_update_file(scriptPath);
+ }
+
if (AlcReloadCfg.IsAlcReloadingEnabled)
{
AddTypeForAlcReloading(type);
@@ -584,7 +591,8 @@ namespace Godot.Bridge
}
[UnmanagedCallersOnly]
- internal static unsafe void UpdateScriptClassInfo(IntPtr scriptPtr, godot_bool* outTool,
+ internal static unsafe void UpdateScriptClassInfo(IntPtr scriptPtr, godot_string* outClassName,
+ godot_bool* outTool, godot_bool* outGlobal, godot_string* outIconPath,
godot_array* outMethodsDest, godot_dictionary* outRpcFunctionsDest,
godot_dictionary* outEventSignalsDest, godot_ref* outBaseScript)
{
@@ -593,6 +601,8 @@ namespace Godot.Bridge
// Performance is not critical here as this will be replaced with source generators.
var scriptType = _scriptTypeBiMap.GetScriptType(scriptPtr);
+ *outClassName = Marshaling.ConvertStringToNative(scriptType.Name);
+
*outTool = scriptType.GetCustomAttributes(inherit: false)
.OfType<ToolAttribute>()
.Any().ToGodotBool();
@@ -607,6 +617,18 @@ namespace Godot.Bridge
if (!(*outTool).ToBool() && scriptType.Assembly.GetName().Name == "GodotTools")
*outTool = godot_bool.True;
+ var globalAttr = scriptType.GetCustomAttributes(inherit: false)
+ .OfType<GlobalClassAttribute>()
+ .FirstOrDefault();
+
+ *outGlobal = (globalAttr != null).ToGodotBool();
+
+ var iconAttr = scriptType.GetCustomAttributes(inherit: false)
+ .OfType<IconAttribute>()
+ .FirstOrDefault();
+
+ *outIconPath = Marshaling.ConvertStringToNative(iconAttr?.Path);
+
// Methods
// Performance is not critical here as this will be replaced with source generators.
@@ -693,7 +715,7 @@ namespace Godot.Bridge
}
*outRpcFunctionsDest = NativeFuncs.godotsharp_dictionary_new_copy(
- (godot_dictionary)(rpcFunctions).NativeValue);
+ (godot_dictionary)rpcFunctions.NativeValue);
// Event signals
@@ -755,7 +777,10 @@ namespace Godot.Bridge
catch (Exception e)
{
ExceptionUtils.LogException(e);
+ *outClassName = default;
*outTool = godot_bool.False;
+ *outGlobal = godot_bool.False;
+ *outIconPath = default;
*outMethodsDest = NativeFuncs.godotsharp_array_new();
*outRpcFunctionsDest = NativeFuncs.godotsharp_dictionary_new();
*outEventSignalsDest = NativeFuncs.godotsharp_dictionary_new();
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs
index fc2ceed479..3ec3d1e530 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs
@@ -37,6 +37,8 @@ namespace Godot.NativeInterop
// Custom functions
+ internal static partial godot_bool godotsharp_dotnet_module_is_initialized();
+
public static partial IntPtr godotsharp_method_bind_get_method(in godot_string_name p_classname,
in godot_string_name p_methodname);
@@ -52,6 +54,8 @@ namespace Godot.NativeInterop
internal static partial void godotsharp_stack_info_vector_destroy(
ref DebuggingUtils.godot_stack_info_vector p_stack_info_vector);
+ internal static partial void godotsharp_internal_editor_file_system_update_file(in godot_string p_script_path);
+
internal static partial void godotsharp_internal_script_debugger_send_error(in godot_string p_func,
in godot_string p_file, int p_line, in godot_string p_err, in godot_string p_descr,
godot_bool p_warning, in DebuggingUtils.godot_stack_info_vector p_stack_info_vector);
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj b/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj
index 7f045e0fab..56bc74c9dc 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj
+++ b/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj
@@ -60,7 +60,9 @@
<Compile Include="Core\Attributes\ExportCategoryAttribute.cs" />
<Compile Include="Core\Attributes\ExportGroupAttribute.cs" />
<Compile Include="Core\Attributes\ExportSubgroupAttribute.cs" />
+ <Compile Include="Core\Attributes\GlobalClassAttribute.cs" />
<Compile Include="Core\Attributes\GodotClassNameAttribute.cs" />
+ <Compile Include="Core\Attributes\IconAttribute.cs" />
<Compile Include="Core\Attributes\MustBeVariantAttribute.cs" />
<Compile Include="Core\Attributes\RpcAttribute.cs" />
<Compile Include="Core\Attributes\ScriptPathAttribute.cs" />
diff --git a/modules/mono/glue/runtime_interop.cpp b/modules/mono/glue/runtime_interop.cpp
index 306ac333eb..56fc467b77 100644
--- a/modules/mono/glue/runtime_interop.cpp
+++ b/modules/mono/glue/runtime_interop.cpp
@@ -40,6 +40,10 @@
#include "core/os/os.h"
#include "core/string/string_name.h"
+#ifdef TOOLS_ENABLED
+#include "editor/editor_file_system.h"
+#endif
+
#include "../interop_types.h"
#include "modules/mono/csharp_script.h"
@@ -57,6 +61,10 @@ static_assert(sizeof(SafeRefCount) == sizeof(uint32_t));
typedef Object *(*godotsharp_class_creation_func)();
+bool godotsharp_dotnet_module_is_initialized() {
+ return GDMono::get_singleton()->is_initialized();
+}
+
MethodBind *godotsharp_method_bind_get_method(const StringName *p_classname, const StringName *p_methodname) {
return ClassDB::get_method(*p_classname, *p_methodname);
}
@@ -304,6 +312,20 @@ void godotsharp_internal_new_csharp_script(Ref<CSharpScript> *r_dest) {
memnew_placement(r_dest, Ref<CSharpScript>(memnew(CSharpScript)));
}
+void godotsharp_internal_editor_file_system_update_file(const String *p_script_path) {
+#if TOOLS_ENABLED
+ // If the EditorFileSystem singleton is available, update the file;
+ // otherwise, the file will be updated when the singleton becomes available.
+ EditorFileSystem *efs = EditorFileSystem::get_singleton();
+ if (efs) {
+ efs->update_file(*p_script_path);
+ }
+#else
+ // EditorFileSystem is only available when running in the Godot editor.
+ DEV_ASSERT(false);
+#endif
+}
+
bool godotsharp_internal_script_load(const String *p_path, Ref<CSharpScript> *r_dest) {
Ref<Resource> res = ResourceLoader::load(*p_path);
if (res.is_valid()) {
@@ -1391,11 +1413,13 @@ void godotsharp_object_to_string(Object *p_ptr, godot_string *r_str) {
// The order in this array must match the declaration order of
// the methods in 'GodotSharp/Core/NativeInterop/NativeFuncs.cs'.
static const void *unmanaged_callbacks[]{
+ (void *)godotsharp_dotnet_module_is_initialized,
(void *)godotsharp_method_bind_get_method,
(void *)godotsharp_get_class_constructor,
(void *)godotsharp_engine_get_singleton,
(void *)godotsharp_stack_info_vector_resize,
(void *)godotsharp_stack_info_vector_destroy,
+ (void *)godotsharp_internal_editor_file_system_update_file,
(void *)godotsharp_internal_script_debugger_send_error,
(void *)godotsharp_internal_script_debugger_is_active,
(void *)godotsharp_internal_object_get_associated_gchandle,
diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp
index 8bcfc5a5eb..97bf49271a 100644
--- a/modules/mono/mono_gd/gd_mono.cpp
+++ b/modules/mono/mono_gd/gd_mono.cpp
@@ -443,6 +443,8 @@ void GDMono::initialize() {
print_verbose(".NET: GodotPlugins initialized");
_on_core_api_assembly_loaded();
+
+ initialized = true;
}
#ifdef TOOLS_ENABLED
@@ -527,14 +529,6 @@ Error GDMono::reload_project_assemblies() {
GDMono::GDMono() {
singleton = this;
-
- runtime_initialized = false;
- finalizing_scripts_domain = false;
-
- api_core_hash = 0;
-#ifdef TOOLS_ENABLED
- api_editor_hash = 0;
-#endif
}
GDMono::~GDMono() {
diff --git a/modules/mono/mono_gd/gd_mono.h b/modules/mono/mono_gd/gd_mono.h
index 080b2c4669..04c375059d 100644
--- a/modules/mono/mono_gd/gd_mono.h
+++ b/modules/mono/mono_gd/gd_mono.h
@@ -59,8 +59,9 @@ struct PluginCallbacks {
} // namespace gdmono
class GDMono {
- bool runtime_initialized;
- bool finalizing_scripts_domain;
+ bool initialized = false;
+ bool runtime_initialized = false;
+ bool finalizing_scripts_domain = false;
void *hostfxr_dll_handle = nullptr;
bool is_native_aot = false;
@@ -72,9 +73,9 @@ class GDMono {
bool _load_project_assembly();
#endif
- uint64_t api_core_hash;
+ uint64_t api_core_hash = 0;
#ifdef TOOLS_ENABLED
- uint64_t api_editor_hash;
+ uint64_t api_editor_hash = 0;
#endif
void _init_godot_api_hashes();
@@ -119,6 +120,9 @@ public:
return singleton;
}
+ _FORCE_INLINE_ bool is_initialized() const {
+ return initialized;
+ }
_FORCE_INLINE_ bool is_runtime_initialized() const {
return runtime_initialized;
}
diff --git a/modules/mono/mono_gd/gd_mono_cache.h b/modules/mono/mono_gd/gd_mono_cache.h
index b180d8133a..e4cddce1d2 100644
--- a/modules/mono/mono_gd/gd_mono_cache.h
+++ b/modules/mono/mono_gd/gd_mono_cache.h
@@ -90,7 +90,7 @@ struct ManagedCallbacks {
using FuncScriptManagerBridge_GetOrCreateScriptBridgeForPath = void(GD_CLR_STDCALL *)(const String *, Ref<CSharpScript> *);
using FuncScriptManagerBridge_RemoveScriptBridge = void(GD_CLR_STDCALL *)(const CSharpScript *);
using FuncScriptManagerBridge_TryReloadRegisteredScriptWithClass = bool(GD_CLR_STDCALL *)(const CSharpScript *);
- using FuncScriptManagerBridge_UpdateScriptClassInfo = void(GD_CLR_STDCALL *)(const CSharpScript *, bool *, Array *, Dictionary *, Dictionary *, Ref<CSharpScript> *);
+ using FuncScriptManagerBridge_UpdateScriptClassInfo = void(GD_CLR_STDCALL *)(const CSharpScript *, String *, bool *, bool *, String *, Array *, Dictionary *, Dictionary *, Ref<CSharpScript> *);
using FuncScriptManagerBridge_SwapGCHandleForType = bool(GD_CLR_STDCALL *)(GCHandleIntPtr, GCHandleIntPtr *, bool);
using FuncScriptManagerBridge_GetPropertyInfoList = void(GD_CLR_STDCALL *)(CSharpScript *, Callback_ScriptManagerBridge_GetPropertyInfoList_Add);
using FuncScriptManagerBridge_GetPropertyDefaultValues = void(GD_CLR_STDCALL *)(CSharpScript *, Callback_ScriptManagerBridge_GetPropertyDefaultValues_Add);