gd_mono_cache.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*************************************************************************/
  2. /* gd_mono_cache.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef GD_MONO_CACHE_H
  31. #define GD_MONO_CACHE_H
  32. #include "gd_mono_header.h"
  33. #include "gd_mono_method_thunk.h"
  34. namespace GDMonoCache {
  35. struct CachedData {
  36. // -----------------------------------------------
  37. // corlib classes
  38. // Let's use the no-namespace format for these too
  39. GDMonoClass *class_MonoObject = nullptr; // object
  40. GDMonoClass *class_bool = nullptr; // bool
  41. GDMonoClass *class_int8_t = nullptr; // sbyte
  42. GDMonoClass *class_int16_t = nullptr; // short
  43. GDMonoClass *class_int32_t = nullptr; // int
  44. GDMonoClass *class_int64_t = nullptr; // long
  45. GDMonoClass *class_uint8_t = nullptr; // byte
  46. GDMonoClass *class_uint16_t = nullptr; // ushort
  47. GDMonoClass *class_uint32_t = nullptr; // uint
  48. GDMonoClass *class_uint64_t = nullptr; // ulong
  49. GDMonoClass *class_float = nullptr; // float
  50. GDMonoClass *class_double = nullptr; // double
  51. GDMonoClass *class_String = nullptr; // string
  52. GDMonoClass *class_IntPtr = nullptr; // System.IntPtr
  53. GDMonoClass *class_System_Collections_IEnumerable = nullptr;
  54. GDMonoClass *class_System_Collections_ICollection = nullptr;
  55. GDMonoClass *class_System_Collections_IDictionary = nullptr;
  56. #ifdef DEBUG_ENABLED
  57. GDMonoClass *class_System_Diagnostics_StackTrace = nullptr;
  58. GDMonoMethodThunkR<MonoArray *, MonoObject *> methodthunk_System_Diagnostics_StackTrace_GetFrames;
  59. GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_bool = nullptr;
  60. GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_Exception_bool = nullptr;
  61. #endif
  62. GDMonoClass *class_KeyNotFoundException = nullptr;
  63. MonoClass *rawclass_Dictionary = nullptr;
  64. // -----------------------------------------------
  65. GDMonoClass *class_Vector2 = nullptr;
  66. GDMonoClass *class_Vector2i = nullptr;
  67. GDMonoClass *class_Rect2 = nullptr;
  68. GDMonoClass *class_Rect2i = nullptr;
  69. GDMonoClass *class_Transform2D = nullptr;
  70. GDMonoClass *class_Vector3 = nullptr;
  71. GDMonoClass *class_Vector3i = nullptr;
  72. GDMonoClass *class_Vector4 = nullptr;
  73. GDMonoClass *class_Vector4i = nullptr;
  74. GDMonoClass *class_Basis = nullptr;
  75. GDMonoClass *class_Quaternion = nullptr;
  76. GDMonoClass *class_Transform3D = nullptr;
  77. GDMonoClass *class_Projection = nullptr;
  78. GDMonoClass *class_AABB = nullptr;
  79. GDMonoClass *class_Color = nullptr;
  80. GDMonoClass *class_Plane = nullptr;
  81. GDMonoClass *class_StringName = nullptr;
  82. GDMonoClass *class_NodePath = nullptr;
  83. GDMonoClass *class_RID = nullptr;
  84. GDMonoClass *class_GodotObject = nullptr;
  85. GDMonoClass *class_GodotResource = nullptr;
  86. GDMonoClass *class_Node = nullptr;
  87. GDMonoClass *class_Control = nullptr;
  88. GDMonoClass *class_Node3D = nullptr;
  89. GDMonoClass *class_WeakRef = nullptr;
  90. GDMonoClass *class_Callable = nullptr;
  91. GDMonoClass *class_SignalInfo = nullptr;
  92. GDMonoClass *class_Array = nullptr;
  93. GDMonoClass *class_Dictionary = nullptr;
  94. GDMonoClass *class_MarshalUtils = nullptr;
  95. GDMonoClass *class_ISerializationListener = nullptr;
  96. #ifdef DEBUG_ENABLED
  97. GDMonoClass *class_DebuggingUtils = nullptr;
  98. GDMonoMethodThunk<MonoObject *, MonoString **, int *, MonoString **> methodthunk_DebuggingUtils_GetStackFrameInfo;
  99. #endif
  100. GDMonoClass *class_ExportAttribute = nullptr;
  101. GDMonoField *field_ExportAttribute_hint = nullptr;
  102. GDMonoField *field_ExportAttribute_hintString = nullptr;
  103. GDMonoClass *class_SignalAttribute = nullptr;
  104. GDMonoClass *class_ToolAttribute = nullptr;
  105. GDMonoClass *class_RPCAttribute = nullptr;
  106. GDMonoProperty *property_RPCAttribute_Mode = nullptr;
  107. GDMonoProperty *property_RPCAttribute_CallLocal = nullptr;
  108. GDMonoProperty *property_RPCAttribute_TransferMode = nullptr;
  109. GDMonoProperty *property_RPCAttribute_TransferChannel = nullptr;
  110. GDMonoClass *class_GodotMethodAttribute = nullptr;
  111. GDMonoField *field_GodotMethodAttribute_methodName = nullptr;
  112. GDMonoClass *class_ScriptPathAttribute = nullptr;
  113. GDMonoField *field_ScriptPathAttribute_path = nullptr;
  114. GDMonoClass *class_AssemblyHasScriptsAttribute = nullptr;
  115. GDMonoField *field_AssemblyHasScriptsAttribute_requiresLookup = nullptr;
  116. GDMonoField *field_AssemblyHasScriptsAttribute_scriptTypes = nullptr;
  117. GDMonoField *field_GodotObject_ptr = nullptr;
  118. GDMonoField *field_StringName_ptr = nullptr;
  119. GDMonoField *field_NodePath_ptr = nullptr;
  120. GDMonoField *field_Image_ptr = nullptr;
  121. GDMonoField *field_RID_ptr = nullptr;
  122. GDMonoMethodThunk<MonoObject *> methodthunk_GodotObject_Dispose;
  123. GDMonoMethodThunkR<Array *, MonoObject *> methodthunk_Array_GetPtr;
  124. GDMonoMethodThunkR<Dictionary *, MonoObject *> methodthunk_Dictionary_GetPtr;
  125. GDMonoMethodThunk<MonoObject *, MonoArray *> methodthunk_SignalAwaiter_SignalCallback;
  126. GDMonoMethodThunk<MonoObject *> methodthunk_GodotTaskScheduler_Activate;
  127. GDMonoMethodThunkR<MonoBoolean, MonoObject *, MonoObject *> methodthunk_Delegate_Equals;
  128. GDMonoMethodThunkR<MonoBoolean, MonoDelegate *, MonoObject *> methodthunk_DelegateUtils_TrySerializeDelegate;
  129. GDMonoMethodThunkR<MonoBoolean, MonoObject *, MonoDelegate **> methodthunk_DelegateUtils_TryDeserializeDelegate;
  130. // Start of MarshalUtils methods
  131. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericArray;
  132. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericDictionary;
  133. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsSystemGenericList;
  134. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsSystemGenericDictionary;
  135. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericIEnumerable;
  136. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericICollection;
  137. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericIDictionary;
  138. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeHasFlagsAttribute;
  139. GDMonoMethodThunk<MonoReflectionType *, MonoReflectionType **> methodthunk_MarshalUtils_GetGenericTypeDefinition;
  140. GDMonoMethodThunk<MonoReflectionType *, MonoReflectionType **> methodthunk_MarshalUtils_ArrayGetElementType;
  141. GDMonoMethodThunk<MonoReflectionType *, MonoReflectionType **, MonoReflectionType **> methodthunk_MarshalUtils_DictionaryGetKeyValueTypes;
  142. GDMonoMethodThunkR<MonoReflectionType *, MonoReflectionType *> methodthunk_MarshalUtils_MakeGenericArrayType;
  143. GDMonoMethodThunkR<MonoReflectionType *, MonoReflectionType *, MonoReflectionType *> methodthunk_MarshalUtils_MakeGenericDictionaryType;
  144. // End of MarshalUtils methods
  145. Ref<MonoGCHandleRef> task_scheduler_handle;
  146. bool corlib_cache_updated;
  147. bool godot_api_cache_updated;
  148. void clear_corlib_cache();
  149. void clear_godot_api_cache();
  150. CachedData() {
  151. clear_corlib_cache();
  152. clear_godot_api_cache();
  153. }
  154. };
  155. extern CachedData cached_data;
  156. void update_corlib_cache();
  157. void update_godot_api_cache();
  158. inline void clear_corlib_cache() {
  159. cached_data.clear_corlib_cache();
  160. }
  161. inline void clear_godot_api_cache() {
  162. cached_data.clear_godot_api_cache();
  163. }
  164. } // namespace GDMonoCache
  165. #define CACHED_CLASS(m_class) (GDMonoCache::cached_data.class_##m_class)
  166. #define CACHED_CLASS_RAW(m_class) (GDMonoCache::cached_data.class_##m_class->get_mono_ptr())
  167. #define CACHED_RAW_MONO_CLASS(m_class) (GDMonoCache::cached_data.rawclass_##m_class)
  168. #define CACHED_FIELD(m_class, m_field) (GDMonoCache::cached_data.field_##m_class##_##m_field)
  169. #define CACHED_METHOD(m_class, m_method) (GDMonoCache::cached_data.method_##m_class##_##m_method)
  170. #define CACHED_METHOD_THUNK(m_class, m_method) (GDMonoCache::cached_data.methodthunk_##m_class##_##m_method)
  171. #define CACHED_PROPERTY(m_class, m_property) (GDMonoCache::cached_data.property_##m_class##_##m_property)
  172. #endif // GD_MONO_CACHE_H