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