Skip to content

Commit

Permalink
Add alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed May 4, 2024
1 parent aff2e47 commit dbeee93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ void CSharpLanguage::pre_unsafe_unreference(Object *p_obj) {
#endif
}

bool CSharpLanguage::is_runtime_initialized() const {
return gdmono && gdmono->is_runtime_initialized();
}

void CSharpLanguage::frame() {
if (gdmono && gdmono->is_runtime_initialized() && GDMonoCache::godot_api_cache_updated) {
GDMonoCache::managed_callbacks.ScriptManagerBridge_FrameCallback();
Expand Down Expand Up @@ -2168,6 +2172,7 @@ void CSharpScript::_get_property_list(List<PropertyInfo> *p_properties) const {

void CSharpScript::_bind_methods() {
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &CSharpScript::_new, MethodInfo("new"));
ClassDB::bind_static_method("CSharpScript", D_METHOD("is_runtime_initialized"), &CSharpScript::_is_runtime_initialized);
}

void CSharpScript::reload_registered_script(Ref<CSharpScript> p_script) {
Expand Down Expand Up @@ -2293,6 +2298,10 @@ void CSharpScript::update_script_class_info(Ref<CSharpScript> p_script) {
p_script->base_script = base_script;
}

bool CSharpScript::_is_runtime_initialized() {
return CSharpLanguage::get_singleton() && CSharpLanguage::get_singleton()->is_runtime_initialized();
}

bool CSharpScript::can_instantiate() const {
#ifdef TOOLS_ENABLED
bool extra_cond = type_info.is_tool || ScriptServer::is_scripting_enabled();
Expand Down
4 changes: 4 additions & 0 deletions modules/mono/csharp_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ class CSharpScript : public Script {
// Do not use unless you know what you are doing
static void update_script_class_info(Ref<CSharpScript> p_script);

static bool _is_runtime_initialized();

protected:
static void _bind_methods();

Expand Down Expand Up @@ -579,6 +581,8 @@ class CSharpLanguage : public ScriptLanguage {
void post_unsafe_reference(Object *p_obj);
void pre_unsafe_unreference(Object *p_obj);

bool is_runtime_initialized() const;

CSharpLanguage();
~CSharpLanguage();
};
Expand Down
6 changes: 6 additions & 0 deletions modules/mono/doc_classes/CSharpScript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<link title="C# documentation index">$DOCS_URL/tutorials/scripting/c_sharp/index.html</link>
</tutorials>
<methods>
<method name="is_runtime_initialized" qualifiers="static">
<return type="bool" />
<description>
Returns [code]true[/code] if the .NET runtime is initialized, [code]false[/code] otherwise.
</description>
</method>
<method name="new" qualifiers="vararg">
<return type="Variant" />
<description>
Expand Down

0 comments on commit dbeee93

Please sign in to comment.