gd_mono_cache.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**************************************************************************/
  2. /* gd_mono_cache.cpp */
  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. #include "gd_mono_cache.h"
  31. #include "core/error/error_macros.h"
  32. namespace GDMonoCache {
  33. ManagedCallbacks managed_callbacks;
  34. bool godot_api_cache_updated = false;
  35. void update_godot_api_cache(const ManagedCallbacks &p_managed_callbacks) {
  36. int checked_count = 0;
  37. #define CHECK_CALLBACK_NOT_NULL_IMPL(m_var, m_class, m_method) \
  38. { \
  39. ERR_FAIL_NULL_MSG(m_var, \
  40. "Mono Cache: Managed callback for '" #m_class "_" #m_method "' is null."); \
  41. checked_count += 1; \
  42. }
  43. #define CHECK_CALLBACK_NOT_NULL(m_class, m_method) CHECK_CALLBACK_NOT_NULL_IMPL(p_managed_callbacks.m_class##_##m_method, m_class, m_method)
  44. CHECK_CALLBACK_NOT_NULL(SignalAwaiter, SignalCallback);
  45. CHECK_CALLBACK_NOT_NULL(DelegateUtils, InvokeWithVariantArgs);
  46. CHECK_CALLBACK_NOT_NULL(DelegateUtils, DelegateEquals);
  47. CHECK_CALLBACK_NOT_NULL(DelegateUtils, DelegateHash);
  48. CHECK_CALLBACK_NOT_NULL(DelegateUtils, GetArgumentCount);
  49. CHECK_CALLBACK_NOT_NULL(DelegateUtils, TrySerializeDelegateWithGCHandle);
  50. CHECK_CALLBACK_NOT_NULL(DelegateUtils, TryDeserializeDelegateWithGCHandle);
  51. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, FrameCallback);
  52. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, CreateManagedForGodotObjectBinding);
  53. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, CreateManagedForGodotObjectScriptInstance);
  54. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetScriptNativeName);
  55. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetGlobalClassName);
  56. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, SetGodotObjectPtr);
  57. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, RaiseEventSignal);
  58. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, ScriptIsOrInherits);
  59. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, AddScriptBridge);
  60. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetOrCreateScriptBridgeForPath);
  61. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, RemoveScriptBridge);
  62. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, TryReloadRegisteredScriptWithClass);
  63. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, UpdateScriptClassInfo);
  64. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, SwapGCHandleForType);
  65. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetPropertyInfoList);
  66. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetPropertyDefaultValues);
  67. CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, CallStatic);
  68. CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, Call);
  69. CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, Set);
  70. CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, Get);
  71. CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, CallDispose);
  72. CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, CallToString);
  73. CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, HasMethodUnknownParams);
  74. CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, SerializeState);
  75. CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, DeserializeState);
  76. CHECK_CALLBACK_NOT_NULL(GCHandleBridge, FreeGCHandle);
  77. CHECK_CALLBACK_NOT_NULL(GCHandleBridge, GCHandleIsTargetCollectible);
  78. CHECK_CALLBACK_NOT_NULL(DebuggingUtils, GetCurrentStackInfo);
  79. CHECK_CALLBACK_NOT_NULL(DisposablesTracker, OnGodotShuttingDown);
  80. CHECK_CALLBACK_NOT_NULL(GD, OnCoreApiAssemblyLoaded);
  81. managed_callbacks = p_managed_callbacks;
  82. // It's easy to forget to add new callbacks here, so this should help
  83. if (checked_count * sizeof(void *) != sizeof(ManagedCallbacks)) {
  84. int missing_count = (sizeof(ManagedCallbacks) / sizeof(void *)) - checked_count;
  85. WARN_PRINT("The presence of " + itos(missing_count) + " callback(s) was not validated");
  86. }
  87. godot_api_cache_updated = true;
  88. }
  89. } // namespace GDMonoCache