gdextension.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**************************************************************************/
  2. /* gdextension.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 GDEXTENSION_H
  31. #define GDEXTENSION_H
  32. #include <functional>
  33. #include "core/extension/gdextension_interface.h"
  34. #include "core/io/config_file.h"
  35. #include "core/io/resource_loader.h"
  36. #include "core/object/ref_counted.h"
  37. class GDExtension : public Resource {
  38. GDCLASS(GDExtension, Resource)
  39. void *library = nullptr; // pointer if valid,
  40. String library_path;
  41. struct Extension {
  42. ObjectGDExtension gdextension;
  43. };
  44. HashMap<StringName, Extension> extension_classes;
  45. static void _register_extension_class(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo *p_extension_funcs);
  46. static void _register_extension_class_method(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassMethodInfo *p_method_info);
  47. static void _register_extension_class_integer_constant(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_enum_name, GDExtensionConstStringNamePtr p_constant_name, GDExtensionInt p_constant_value, GDExtensionBool p_is_bitfield);
  48. static void _register_extension_class_property(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionPropertyInfo *p_info, GDExtensionConstStringNamePtr p_setter, GDExtensionConstStringNamePtr p_getter);
  49. static void _register_extension_class_property_group(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_group_name, GDExtensionConstStringNamePtr p_prefix);
  50. static void _register_extension_class_property_subgroup(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_subgroup_name, GDExtensionConstStringNamePtr p_prefix);
  51. static void _register_extension_class_signal(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_signal_name, const GDExtensionPropertyInfo *p_argument_info, GDExtensionInt p_argument_count);
  52. static void _unregister_extension_class(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name);
  53. static void _get_library_path(GDExtensionClassLibraryPtr p_library, GDExtensionStringPtr r_path);
  54. GDExtensionInitialization initialization;
  55. int32_t level_initialized = -1;
  56. protected:
  57. static void _bind_methods();
  58. public:
  59. static String get_extension_list_config_file();
  60. static String find_extension_library(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature, PackedStringArray *r_tags = nullptr);
  61. Error open_library(const String &p_path, const String &p_entry_symbol);
  62. void close_library();
  63. enum InitializationLevel {
  64. INITIALIZATION_LEVEL_CORE = GDEXTENSION_INITIALIZATION_CORE,
  65. INITIALIZATION_LEVEL_SERVERS = GDEXTENSION_INITIALIZATION_SERVERS,
  66. INITIALIZATION_LEVEL_SCENE = GDEXTENSION_INITIALIZATION_SCENE,
  67. INITIALIZATION_LEVEL_EDITOR = GDEXTENSION_INITIALIZATION_EDITOR
  68. };
  69. bool is_library_open() const;
  70. InitializationLevel get_minimum_library_initialization_level() const;
  71. void initialize_library(InitializationLevel p_level);
  72. void deinitialize_library(InitializationLevel p_level);
  73. static void initialize_gdextensions();
  74. GDExtension();
  75. ~GDExtension();
  76. };
  77. VARIANT_ENUM_CAST(GDExtension::InitializationLevel)
  78. class GDExtensionResourceLoader : public ResourceFormatLoader {
  79. public:
  80. virtual Ref<Resource> load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE);
  81. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  82. virtual bool handles_type(const String &p_type) const;
  83. virtual String get_resource_type(const String &p_path) const;
  84. };
  85. #endif // GDEXTENSION_H