java_godot_wrapper.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**************************************************************************/
  2. /* java_godot_wrapper.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. // note, swapped java and godot around in the file name so all the java
  31. // wrappers are together
  32. #ifndef JAVA_GODOT_WRAPPER_H
  33. #define JAVA_GODOT_WRAPPER_H
  34. #include <android/log.h>
  35. #include <jni.h>
  36. #include "core/list.h"
  37. #include "java_godot_view_wrapper.h"
  38. #include "string_android.h"
  39. // Class that makes functions in java/src/org/godotengine/godot/Godot.java callable from C++
  40. class GodotJavaWrapper {
  41. private:
  42. jobject godot_instance;
  43. jobject activity;
  44. jclass godot_class;
  45. jclass activity_class;
  46. GodotJavaViewWrapper *godot_view = nullptr;
  47. jmethodID _on_video_init = nullptr;
  48. jmethodID _create_offscreen_gl = nullptr;
  49. jmethodID _destroy_offscreen_gl = nullptr;
  50. jmethodID _set_offscreen_gl_current = nullptr;
  51. jmethodID _restart = nullptr;
  52. jmethodID _finish = nullptr;
  53. jmethodID _set_keep_screen_on = nullptr;
  54. jmethodID _alert = nullptr;
  55. jmethodID _get_GLES_version_code = nullptr;
  56. jmethodID _get_clipboard = nullptr;
  57. jmethodID _set_clipboard = nullptr;
  58. jmethodID _has_clipboard = nullptr;
  59. jmethodID _request_permission = nullptr;
  60. jmethodID _request_permissions = nullptr;
  61. jmethodID _get_granted_permissions = nullptr;
  62. jmethodID _init_input_devices = nullptr;
  63. jmethodID _get_surface = nullptr;
  64. jmethodID _is_activity_resumed = nullptr;
  65. jmethodID _vibrate = nullptr;
  66. jmethodID _get_input_fallback_mapping = nullptr;
  67. jmethodID _on_godot_setup_completed = nullptr;
  68. jmethodID _on_godot_main_loop_started = nullptr;
  69. jmethodID _get_class_loader = nullptr;
  70. jmethodID _create_new_godot_instance = nullptr;
  71. jmethodID _get_render_view = nullptr;
  72. jmethodID _begin_benchmark_measure = nullptr;
  73. jmethodID _end_benchmark_measure = nullptr;
  74. jmethodID _dump_benchmark = nullptr;
  75. public:
  76. GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_godot_instance);
  77. ~GodotJavaWrapper();
  78. jobject get_activity();
  79. jobject get_member_object(const char *p_name, const char *p_class, JNIEnv *p_env = NULL);
  80. jobject get_class_loader();
  81. GodotJavaViewWrapper *get_godot_view();
  82. bool create_offscreen_gl(JNIEnv *p_env);
  83. void destroy_offscreen_gl(JNIEnv *p_env);
  84. void set_offscreen_gl_current(JNIEnv *p_env, bool p_current);
  85. void on_video_init(JNIEnv *p_env = NULL);
  86. void on_godot_setup_completed(JNIEnv *p_env = NULL);
  87. void on_godot_main_loop_started(JNIEnv *p_env = NULL);
  88. void restart(JNIEnv *p_env = NULL);
  89. bool force_quit(JNIEnv *p_env = NULL, int p_instance_id = 0);
  90. void set_keep_screen_on(bool p_enabled);
  91. void alert(const String &p_message, const String &p_title);
  92. int get_gles_version_code();
  93. bool has_get_clipboard();
  94. String get_clipboard();
  95. bool has_set_clipboard();
  96. void set_clipboard(const String &p_text);
  97. bool has_has_clipboard();
  98. bool has_clipboard();
  99. bool request_permission(const String &p_name);
  100. bool request_permissions();
  101. Vector<String> get_granted_permissions() const;
  102. void init_input_devices();
  103. jobject get_surface();
  104. bool is_activity_resumed();
  105. void vibrate(int p_duration_ms);
  106. String get_input_fallback_mapping();
  107. int create_new_godot_instance(List<String> args);
  108. void begin_benchmark_measure(const String &p_label);
  109. void end_benchmark_measure(const String &p_label);
  110. void dump_benchmark(const String &benchmark_file);
  111. };
  112. #endif // JAVA_GODOT_WRAPPER_H