godot.hpp 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*************************************************************************/
  2. /* godot.hpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 GODOT_HPP
  31. #define GODOT_HPP
  32. #include <godot/gdnative_interface.h>
  33. namespace godot {
  34. namespace internal {
  35. extern "C" const GDNativeInterface *interface;
  36. extern "C" GDNativeExtensionClassLibraryPtr library;
  37. extern "C" void *token;
  38. } // namespace internal
  39. class GDExtensionBinding {
  40. public:
  41. using Callback = void (*)();
  42. static Callback init_callbacks[GDNATIVE_MAX_INITIALIZATION_LEVEL];
  43. static Callback terminate_callbacks[GDNATIVE_MAX_INITIALIZATION_LEVEL];
  44. static GDNativeBool init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization);
  45. public:
  46. static void initialize_level(void *userdata, GDNativeInitializationLevel p_level);
  47. static void deinitialize_level(void *userdata, GDNativeInitializationLevel p_level);
  48. static void *create_instance_callback(void *p_token, void *p_instance);
  49. static void free_instance_callback(void *p_token, void *p_instance, void *p_binding);
  50. class InitObject {
  51. const GDNativeInterface *interface;
  52. const GDNativeExtensionClassLibraryPtr library;
  53. GDNativeInitialization *initialization;
  54. public:
  55. InitObject(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) :
  56. interface(p_interface),
  57. library(p_library),
  58. initialization(r_initialization){};
  59. void register_core_initializer(Callback p_core_init) const;
  60. void register_server_initializer(Callback p_server_init) const;
  61. void register_scene_initializer(Callback p_scene_init) const;
  62. void register_editor_initializer(Callback p_editor_init) const;
  63. void register_driver_initializer(Callback p_driver_init) const;
  64. void register_core_terminator(Callback p_core_terminate) const;
  65. void register_server_terminator(Callback p_server_terminate) const;
  66. void register_scene_terminator(Callback p_scene_terminate) const;
  67. void register_editor_terminator(Callback p_editor_terminate) const;
  68. void register_driver_terminator(Callback p_driver_terminate) const;
  69. GDNativeBool init() const;
  70. };
  71. };
  72. } // namespace godot
  73. #endif // ! GODOT_HPP