gd_mono_cache.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**************************************************************************/
  2. /* gd_mono_cache.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. #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; // object
  40. GDMonoClass *class_bool; // bool
  41. GDMonoClass *class_int8_t; // sbyte
  42. GDMonoClass *class_int16_t; // short
  43. GDMonoClass *class_int32_t; // int
  44. GDMonoClass *class_int64_t; // long
  45. GDMonoClass *class_uint8_t; // byte
  46. GDMonoClass *class_uint16_t; // ushort
  47. GDMonoClass *class_uint32_t; // uint
  48. GDMonoClass *class_uint64_t; // ulong
  49. GDMonoClass *class_float; // float
  50. GDMonoClass *class_double; // double
  51. GDMonoClass *class_String; // string
  52. GDMonoClass *class_IntPtr; // System.IntPtr
  53. GDMonoClass *class_System_Collections_IEnumerable;
  54. GDMonoClass *class_System_Collections_ICollection;
  55. GDMonoClass *class_System_Collections_IDictionary;
  56. #ifdef DEBUG_ENABLED
  57. GDMonoClass *class_System_Diagnostics_StackTrace;
  58. GDMonoMethodThunkR<MonoArray *, MonoObject *> methodthunk_System_Diagnostics_StackTrace_GetFrames;
  59. GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_bool;
  60. GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_Exception_bool;
  61. #endif
  62. GDMonoClass *class_KeyNotFoundException;
  63. MonoClass *rawclass_Dictionary;
  64. // -----------------------------------------------
  65. GDMonoClass *class_Vector2;
  66. GDMonoClass *class_Rect2;
  67. GDMonoClass *class_Transform2D;
  68. GDMonoClass *class_Vector3;
  69. GDMonoClass *class_Basis;
  70. GDMonoClass *class_Quat;
  71. GDMonoClass *class_Transform;
  72. GDMonoClass *class_AABB;
  73. GDMonoClass *class_Color;
  74. GDMonoClass *class_Plane;
  75. GDMonoClass *class_NodePath;
  76. GDMonoClass *class_RID;
  77. GDMonoClass *class_GodotObject;
  78. GDMonoClass *class_GodotResource;
  79. GDMonoClass *class_Node;
  80. GDMonoClass *class_Control;
  81. GDMonoClass *class_Spatial;
  82. GDMonoClass *class_WeakRef;
  83. GDMonoClass *class_Array;
  84. GDMonoClass *class_Dictionary;
  85. GDMonoClass *class_MarshalUtils;
  86. GDMonoClass *class_ISerializationListener;
  87. #ifdef DEBUG_ENABLED
  88. GDMonoClass *class_DebuggingUtils;
  89. GDMonoMethodThunk<MonoObject *, MonoString **, int *, MonoString **> methodthunk_DebuggingUtils_GetStackFrameInfo;
  90. #endif
  91. GDMonoClass *class_ExportAttribute;
  92. GDMonoField *field_ExportAttribute_hint;
  93. GDMonoField *field_ExportAttribute_hintString;
  94. GDMonoClass *class_SignalAttribute;
  95. GDMonoClass *class_ToolAttribute;
  96. GDMonoClass *class_RemoteAttribute;
  97. GDMonoClass *class_SyncAttribute;
  98. GDMonoClass *class_RemoteSyncAttribute;
  99. GDMonoClass *class_MasterSyncAttribute;
  100. GDMonoClass *class_PuppetSyncAttribute;
  101. GDMonoClass *class_MasterAttribute;
  102. GDMonoClass *class_PuppetAttribute;
  103. GDMonoClass *class_SlaveAttribute;
  104. GDMonoClass *class_GodotMethodAttribute;
  105. GDMonoField *field_GodotMethodAttribute_methodName;
  106. GDMonoField *field_GodotObject_ptr;
  107. GDMonoField *field_NodePath_ptr;
  108. GDMonoField *field_Image_ptr;
  109. GDMonoField *field_RID_ptr;
  110. GDMonoMethodThunk<MonoObject *> methodthunk_GodotObject_Dispose;
  111. GDMonoMethodThunkR<Array *, MonoObject *> methodthunk_Array_GetPtr;
  112. GDMonoMethodThunkR<Dictionary *, MonoObject *> methodthunk_Dictionary_GetPtr;
  113. GDMonoMethodThunk<MonoObject *, MonoArray *> methodthunk_SignalAwaiter_SignalCallback;
  114. GDMonoMethodThunk<MonoObject *> methodthunk_SignalAwaiter_FailureCallback;
  115. GDMonoMethodThunk<MonoObject *> methodthunk_GodotTaskScheduler_Activate;
  116. // Start of MarshalUtils methods
  117. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericArray;
  118. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericDictionary;
  119. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsSystemGenericList;
  120. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsSystemGenericDictionary;
  121. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericIEnumerable;
  122. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericICollection;
  123. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericIDictionary;
  124. GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeHasFlagsAttribute;
  125. GDMonoMethodThunk<MonoReflectionType *, MonoReflectionType **> methodthunk_MarshalUtils_GetGenericTypeDefinition;
  126. GDMonoMethodThunk<MonoReflectionType *, MonoReflectionType **> methodthunk_MarshalUtils_ArrayGetElementType;
  127. GDMonoMethodThunk<MonoReflectionType *, MonoReflectionType **, MonoReflectionType **> methodthunk_MarshalUtils_DictionaryGetKeyValueTypes;
  128. GDMonoMethodThunkR<MonoReflectionType *, MonoReflectionType *> methodthunk_MarshalUtils_MakeGenericArrayType;
  129. GDMonoMethodThunkR<MonoReflectionType *, MonoReflectionType *, MonoReflectionType *> methodthunk_MarshalUtils_MakeGenericDictionaryType;
  130. // End of MarshalUtils methods
  131. Ref<MonoGCHandle> task_scheduler_handle;
  132. bool corlib_cache_updated;
  133. bool godot_api_cache_updated;
  134. void clear_corlib_cache();
  135. void clear_godot_api_cache();
  136. CachedData() {
  137. clear_corlib_cache();
  138. clear_godot_api_cache();
  139. }
  140. };
  141. extern CachedData cached_data;
  142. void update_corlib_cache();
  143. void update_godot_api_cache();
  144. inline void clear_corlib_cache() {
  145. cached_data.clear_corlib_cache();
  146. }
  147. inline void clear_godot_api_cache() {
  148. cached_data.clear_godot_api_cache();
  149. }
  150. } // namespace GDMonoCache
  151. #define CACHED_CLASS(m_class) (GDMonoCache::cached_data.class_##m_class)
  152. #define CACHED_CLASS_RAW(m_class) (GDMonoCache::cached_data.class_##m_class->get_mono_ptr())
  153. #define CACHED_RAW_MONO_CLASS(m_class) (GDMonoCache::cached_data.rawclass_##m_class)
  154. #define CACHED_FIELD(m_class, m_field) (GDMonoCache::cached_data.field_##m_class##_##m_field)
  155. #define CACHED_METHOD(m_class, m_method) (GDMonoCache::cached_data.method_##m_class##_##m_method)
  156. #define CACHED_METHOD_THUNK(m_class, m_method) (GDMonoCache::cached_data.methodthunk_##m_class##_##m_method)
  157. #define CACHED_PROPERTY(m_class, m_property) (GDMonoCache::cached_data.property_##m_class##_##m_property)
  158. #ifdef REAL_T_IS_DOUBLE
  159. #define REAL_T_MONOCLASS CACHED_CLASS_RAW(double)
  160. #else
  161. #define REAL_T_MONOCLASS CACHED_CLASS_RAW(float)
  162. #endif
  163. #endif // GD_MONO_CACHE_H