jsb_module_register.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /****************************************************************************
  2. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos.com
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated engine source code (the "Software"), a limited,
  6. worldwide, royalty-free, non-assignable, revocable and non-exclusive license
  7. to use Cocos Creator solely to develop games on your target platforms. You shall
  8. not use Cocos Creator software for developing other software or tools that's
  9. used for developing games. You are not granted to publish, distribute,
  10. sublicense, and/or sell copies of Cocos Creator.
  11. The software or tools in this License Agreement are licensed, not sold.
  12. Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #include "cocos2d.h"
  22. #include "cocos/scripting/js-bindings/manual/jsb_module_register.hpp"
  23. #include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
  24. #include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp"
  25. #include "cocos/scripting/js-bindings/manual/jsb_global.h"
  26. #include "cocos/scripting/js-bindings/manual/jsb_node.hpp"
  27. #include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
  28. #include "cocos/scripting/js-bindings/manual/jsb_opengl_manual.hpp"
  29. #include "cocos/scripting/js-bindings/manual/jsb_platform.h"
  30. #include "cocos/scripting/js-bindings/manual/jsb_cocos2dx_manual.hpp"
  31. #include "cocos/scripting/js-bindings/manual/jsb_xmlhttprequest.hpp"
  32. #include "cocos/scripting/js-bindings/manual/jsb_cocos2dx_network_manual.h"
  33. #include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_network_auto.hpp"
  34. #include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.hpp"
  35. #if USE_GFX_RENDERER
  36. #include "cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp"
  37. #include "cocos/scripting/js-bindings/auto/jsb_renderer_auto.hpp"
  38. #include "cocos/scripting/js-bindings/manual/jsb_gfx_manual.hpp"
  39. #include "cocos/scripting/js-bindings/manual/jsb_renderer_manual.hpp"
  40. #endif
  41. #if USE_SOCKET
  42. #include "cocos/scripting/js-bindings/manual/jsb_websocket.hpp"
  43. #include "cocos/scripting/js-bindings/manual/jsb_socketio.hpp"
  44. #if USE_WEBSOCKET_SERVER
  45. #include "cocos/scripting/js-bindings/manual/jsb_websocket_server.hpp"
  46. #endif
  47. #endif // USE_SOCKET
  48. #if USE_AUDIO
  49. #include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_audioengine_auto.hpp"
  50. #endif
  51. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
  52. #include "cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.h"
  53. #endif
  54. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  55. #include "cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.h"
  56. #endif
  57. #if USE_GFX_RENDERER && USE_MIDDLEWARE
  58. #include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.hpp"
  59. #if USE_SPINE
  60. #include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_spine_auto.hpp"
  61. #include "cocos/scripting/js-bindings/manual/jsb_spine_manual.hpp"
  62. #endif
  63. #if USE_DRAGONBONES
  64. #include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_dragonbones_auto.hpp"
  65. #include "cocos/scripting/js-bindings/manual/jsb_dragonbones_manual.hpp"
  66. #endif
  67. #if USE_PARTICLE
  68. #include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_particle_auto.hpp"
  69. #endif
  70. #endif // USE_MIDDLEWARE
  71. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  72. #if USE_VIDEO
  73. #include "cocos/scripting/js-bindings/auto/jsb_video_auto.hpp"
  74. #endif
  75. #if USE_WEB_VIEW
  76. #include "cocos/scripting/js-bindings/auto/jsb_webview_auto.hpp"
  77. #endif
  78. #endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  79. using namespace cocos2d;
  80. bool jsb_register_all_modules()
  81. {
  82. se::ScriptEngine* se = se::ScriptEngine::getInstance();
  83. se->addBeforeInitHook([](){
  84. JSBClassType::init();
  85. });
  86. se->addBeforeCleanupHook([se](){
  87. se->garbageCollect();
  88. PoolManager::getInstance()->getCurrentPool()->clear();
  89. se->garbageCollect();
  90. PoolManager::getInstance()->getCurrentPool()->clear();
  91. });
  92. se->addRegisterCallback(jsb_register_global_variables);
  93. se->addRegisterCallback(JSB_register_opengl);
  94. se->addRegisterCallback(register_all_engine);
  95. se->addRegisterCallback(register_all_cocos2dx_manual);
  96. se->addRegisterCallback(register_platform_bindings);
  97. se->addRegisterCallback(register_all_network);
  98. se->addRegisterCallback(register_all_cocos2dx_network_manual);
  99. se->addRegisterCallback(register_all_xmlhttprequest);
  100. // extension depend on network
  101. se->addRegisterCallback(register_all_extension);
  102. #if USE_GFX_RENDERER
  103. se->addRegisterCallback(register_all_gfx);
  104. se->addRegisterCallback(jsb_register_gfx_manual);
  105. se->addRegisterCallback(register_all_renderer);
  106. se->addRegisterCallback(jsb_register_renderer_manual);
  107. #endif
  108. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
  109. se->addRegisterCallback(register_javascript_objc_bridge);
  110. #endif
  111. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  112. se->addRegisterCallback(register_javascript_java_bridge);
  113. #endif
  114. #if USE_AUDIO
  115. se->addRegisterCallback(register_all_audioengine);
  116. #endif
  117. #if USE_SOCKET
  118. se->addRegisterCallback(register_all_websocket);
  119. se->addRegisterCallback(register_all_socketio);
  120. #if USE_WEBSOCKET_SERVER
  121. se->addRegisterCallback(register_all_websocket_server);
  122. #endif
  123. #endif
  124. #if USE_GFX_RENDERER && USE_MIDDLEWARE
  125. se->addRegisterCallback(register_all_cocos2dx_editor_support);
  126. #if USE_SPINE
  127. se->addRegisterCallback(register_all_cocos2dx_spine);
  128. se->addRegisterCallback(register_all_spine_manual);
  129. #endif
  130. #if USE_DRAGONBONES
  131. se->addRegisterCallback(register_all_cocos2dx_dragonbones);
  132. se->addRegisterCallback(register_all_dragonbones_manual);
  133. #endif
  134. #if USE_PARTICLE
  135. se->addRegisterCallback(register_all_cocos2dx_particle);
  136. #endif
  137. #endif // USE_MIDDLEWARE
  138. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  139. #if USE_VIDEO
  140. se->addRegisterCallback(register_all_video);
  141. #endif
  142. #if USE_WEB_VIEW
  143. se->addRegisterCallback(register_all_webview);
  144. #endif
  145. #endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  146. se->addAfterCleanupHook([](){
  147. PoolManager::getInstance()->getCurrentPool()->clear();
  148. JSBClassType::destroy();
  149. });
  150. return true;
  151. }