Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/mono/mono_gd/gd_mono.h
10278 views
1
/**************************************************************************/
2
/* gd_mono.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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
} // namespace gdmono
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 // DEBUG_ENABLED
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 // TOOLS_ENABLED
110
#endif // DEBUG_ENABLED
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 // DEBUG_ENABLED
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
} // namespace MonoBind
182
183