| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "../godotsharp_defs.h" |
| 34 |
|
| 35 |
#include "core/io/config_file.h" |
| 36 |
|
| 37 |
#ifndef GD_CLR_STDCALL |
| 38 |
#ifdef WIN32 |
| 39 |
#define GD_CLR_STDCALL __stdcall |
| 40 |
#else |
| 41 |
#define GD_CLR_STDCALL |
| 42 |
#endif |
| 43 |
#endif |
| 44 |
|
| 45 |
namespace gdmono { |
| 46 |
|
| 47 |
#ifdef TOOLS_ENABLED |
| 48 |
struct PluginCallbacks { |
| 49 |
using FuncLoadProjectAssemblyCallback = bool(GD_CLR_STDCALL *)(const char16_t *, String *); |
| 50 |
using FuncLoadToolsAssemblyCallback = Object *(GD_CLR_STDCALL *)(const char16_t *, const void **, int32_t); |
| 51 |
using FuncUnloadProjectPluginCallback = bool(GD_CLR_STDCALL *)(); |
| 52 |
FuncLoadProjectAssemblyCallback LoadProjectAssemblyCallback = nullptr; |
| 53 |
FuncLoadToolsAssemblyCallback LoadToolsAssemblyCallback = nullptr; |
| 54 |
FuncUnloadProjectPluginCallback UnloadProjectPluginCallback = nullptr; |
| 55 |
}; |
| 56 |
#endif |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
class GDMono { |
| 61 |
bool initialized = false; |
| 62 |
bool runtime_initialized = false; |
| 63 |
bool finalizing_scripts_domain = false; |
| 64 |
|
| 65 |
void *hostfxr_dll_handle = nullptr; |
| 66 |
void *coreclr_dll_handle = nullptr; |
| 67 |
|
| 68 |
String project_assembly_path; |
| 69 |
uint64_t project_assembly_modified_time = 0; |
| 70 |
#ifdef GD_MONO_HOT_RELOAD |
| 71 |
int project_load_failure_count = 0; |
| 72 |
#endif |
| 73 |
|
| 74 |
#ifdef TOOLS_ENABLED |
| 75 |
bool _load_project_assembly(); |
| 76 |
void _try_load_project_assembly(); |
| 77 |
#endif |
| 78 |
|
| 79 |
#ifdef DEBUG_ENABLED |
| 80 |
uint64_t api_core_hash = 0; |
| 81 |
#endif |
| 82 |
#ifdef TOOLS_ENABLED |
| 83 |
uint64_t api_editor_hash = 0; |
| 84 |
#endif |
| 85 |
void _init_godot_api_hashes(); |
| 86 |
|
| 87 |
#ifdef TOOLS_ENABLED |
| 88 |
gdmono::PluginCallbacks plugin_callbacks; |
| 89 |
#endif |
| 90 |
|
| 91 |
protected: |
| 92 |
static GDMono *singleton; |
| 93 |
|
| 94 |
public: |
| 95 |
#ifdef DEBUG_ENABLED |
| 96 |
uint64_t get_api_core_hash() { |
| 97 |
if (api_core_hash == 0) { |
| 98 |
api_core_hash = ClassDB::get_api_hash(ClassDB::API_CORE); |
| 99 |
} |
| 100 |
return api_core_hash; |
| 101 |
} |
| 102 |
#ifdef TOOLS_ENABLED |
| 103 |
uint64_t get_api_editor_hash() { |
| 104 |
if (api_editor_hash == 0) { |
| 105 |
api_editor_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); |
| 106 |
} |
| 107 |
return api_editor_hash; |
| 108 |
} |
| 109 |
#endif |
| 110 |
#endif |
| 111 |
|
| 112 |
_FORCE_INLINE_ static String get_expected_api_build_config() { |
| 113 |
#ifdef TOOLS_ENABLED |
| 114 |
return "Debug"; |
| 115 |
#else |
| 116 |
#ifdef DEBUG_ENABLED |
| 117 |
return "Debug"; |
| 118 |
#else |
| 119 |
return "Release"; |
| 120 |
#endif |
| 121 |
#endif |
| 122 |
} |
| 123 |
|
| 124 |
static GDMono *get_singleton() { |
| 125 |
return singleton; |
| 126 |
} |
| 127 |
|
| 128 |
_FORCE_INLINE_ bool is_initialized() const { |
| 129 |
return initialized; |
| 130 |
} |
| 131 |
_FORCE_INLINE_ bool is_runtime_initialized() const { |
| 132 |
return runtime_initialized; |
| 133 |
} |
| 134 |
_FORCE_INLINE_ bool is_finalizing_scripts_domain() { |
| 135 |
return finalizing_scripts_domain; |
| 136 |
} |
| 137 |
|
| 138 |
_FORCE_INLINE_ const String &get_project_assembly_path() const { |
| 139 |
return project_assembly_path; |
| 140 |
} |
| 141 |
_FORCE_INLINE_ uint64_t get_project_assembly_modified_time() const { |
| 142 |
return project_assembly_modified_time; |
| 143 |
} |
| 144 |
|
| 145 |
#ifdef TOOLS_ENABLED |
| 146 |
const gdmono::PluginCallbacks &get_plugin_callbacks() { |
| 147 |
return plugin_callbacks; |
| 148 |
} |
| 149 |
#endif |
| 150 |
|
| 151 |
#ifdef GD_MONO_HOT_RELOAD |
| 152 |
void reload_failure(); |
| 153 |
Error reload_project_assemblies(); |
| 154 |
#endif |
| 155 |
|
| 156 |
bool should_initialize(); |
| 157 |
|
| 158 |
void initialize(); |
| 159 |
|
| 160 |
GDMono(); |
| 161 |
~GDMono(); |
| 162 |
}; |
| 163 |
|
| 164 |
namespace MonoBind { |
| 165 |
|
| 166 |
class GodotSharp : public Object { |
| 167 |
GDCLASS(GodotSharp, Object); |
| 168 |
|
| 169 |
protected: |
| 170 |
static GodotSharp *singleton; |
| 171 |
|
| 172 |
public: |
| 173 |
static GodotSharp *get_singleton() { return singleton; } |
| 174 |
|
| 175 |
void reload_assemblies(bool p_soft_reload); |
| 176 |
|
| 177 |
GodotSharp(); |
| 178 |
~GodotSharp(); |
| 179 |
}; |
| 180 |
|
| 181 |
} |