register_server_types.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*************************************************************************/
  2. /* register_server_types.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. #include "register_server_types.h"
  31. #include "core/config/engine.h"
  32. #include "core/config/project_settings.h"
  33. #include "audio/audio_effect.h"
  34. #include "audio/audio_stream.h"
  35. #include "audio/effects/audio_effect_amplify.h"
  36. #include "audio/effects/audio_effect_capture.h"
  37. #include "audio/effects/audio_effect_chorus.h"
  38. #include "audio/effects/audio_effect_compressor.h"
  39. #include "audio/effects/audio_effect_delay.h"
  40. #include "audio/effects/audio_effect_distortion.h"
  41. #include "audio/effects/audio_effect_eq.h"
  42. #include "audio/effects/audio_effect_filter.h"
  43. #include "audio/effects/audio_effect_limiter.h"
  44. #include "audio/effects/audio_effect_panner.h"
  45. #include "audio/effects/audio_effect_phaser.h"
  46. #include "audio/effects/audio_effect_pitch_shift.h"
  47. #include "audio/effects/audio_effect_record.h"
  48. #include "audio/effects/audio_effect_reverb.h"
  49. #include "audio/effects/audio_effect_spectrum_analyzer.h"
  50. #include "audio/effects/audio_effect_stereo_enhance.h"
  51. #include "audio/effects/audio_stream_generator.h"
  52. #include "audio_server.h"
  53. #include "camera/camera_feed.h"
  54. #include "camera_server.h"
  55. #include "core/extension/native_extension_manager.h"
  56. #include "display_server.h"
  57. #include "navigation_server_2d.h"
  58. #include "navigation_server_3d.h"
  59. #include "physics_2d/godot_physics_server_2d.h"
  60. #include "physics_3d/godot_physics_server_3d.h"
  61. #include "physics_server_2d.h"
  62. #include "physics_server_2d_wrap_mt.h"
  63. #include "physics_server_3d.h"
  64. #include "physics_server_3d_wrap_mt.h"
  65. #include "rendering/renderer_compositor.h"
  66. #include "rendering/rendering_device.h"
  67. #include "rendering/rendering_device_binds.h"
  68. #include "rendering_server.h"
  69. #include "servers/rendering/shader_types.h"
  70. #include "text/text_server_extension.h"
  71. #include "text_server.h"
  72. #include "xr/xr_interface.h"
  73. #include "xr/xr_interface_extension.h"
  74. #include "xr/xr_positional_tracker.h"
  75. #include "xr_server.h"
  76. ShaderTypes *shader_types = nullptr;
  77. PhysicsServer3D *_createGodotPhysics3DCallback() {
  78. bool using_threads = GLOBAL_GET("physics/3d/run_on_separate_thread");
  79. PhysicsServer3D *physics_server = memnew(GodotPhysicsServer3D(using_threads));
  80. return memnew(PhysicsServer3DWrapMT(physics_server, using_threads));
  81. }
  82. PhysicsServer2D *_createGodotPhysics2DCallback() {
  83. bool using_threads = GLOBAL_GET("physics/2d/run_on_separate_thread");
  84. PhysicsServer2D *physics_server = memnew(GodotPhysicsServer2D(using_threads));
  85. return memnew(PhysicsServer2DWrapMT(physics_server, using_threads));
  86. }
  87. static bool has_server_feature_callback(const String &p_feature) {
  88. if (RenderingServer::get_singleton()) {
  89. if (RenderingServer::get_singleton()->has_os_feature(p_feature)) {
  90. return true;
  91. }
  92. }
  93. return false;
  94. }
  95. void preregister_server_types() {
  96. shader_types = memnew(ShaderTypes);
  97. GDREGISTER_CLASS(TextServerManager);
  98. GDREGISTER_VIRTUAL_CLASS(TextServer);
  99. GDREGISTER_CLASS(TextServerExtension);
  100. Engine::get_singleton()->add_singleton(Engine::Singleton("TextServerManager", TextServerManager::get_singleton(), "TextServerManager"));
  101. }
  102. void register_server_types() {
  103. OS::get_singleton()->set_has_server_feature_callback(has_server_feature_callback);
  104. GDREGISTER_VIRTUAL_CLASS(DisplayServer);
  105. GDREGISTER_VIRTUAL_CLASS(RenderingServer);
  106. GDREGISTER_CLASS(AudioServer);
  107. GDREGISTER_VIRTUAL_CLASS(PhysicsServer2D);
  108. GDREGISTER_VIRTUAL_CLASS(PhysicsServer3D);
  109. GDREGISTER_VIRTUAL_CLASS(NavigationServer2D);
  110. GDREGISTER_VIRTUAL_CLASS(NavigationServer3D);
  111. GDREGISTER_CLASS(XRServer);
  112. GDREGISTER_CLASS(CameraServer);
  113. GDREGISTER_VIRTUAL_CLASS(RenderingDevice);
  114. GDREGISTER_VIRTUAL_CLASS(XRInterface);
  115. GDREGISTER_CLASS(XRInterfaceExtension); // can't register this as virtual because we need a creation function for our extensions.
  116. GDREGISTER_CLASS(XRPose);
  117. GDREGISTER_CLASS(XRPositionalTracker);
  118. GDREGISTER_CLASS(AudioStream);
  119. GDREGISTER_CLASS(AudioStreamPlayback);
  120. GDREGISTER_VIRTUAL_CLASS(AudioStreamPlaybackResampled);
  121. GDREGISTER_CLASS(AudioStreamMicrophone);
  122. GDREGISTER_CLASS(AudioStreamRandomPitch);
  123. GDREGISTER_VIRTUAL_CLASS(AudioEffect);
  124. GDREGISTER_VIRTUAL_CLASS(AudioEffectInstance);
  125. GDREGISTER_CLASS(AudioEffectEQ);
  126. GDREGISTER_CLASS(AudioEffectFilter);
  127. GDREGISTER_CLASS(AudioBusLayout);
  128. GDREGISTER_CLASS(AudioStreamGenerator);
  129. GDREGISTER_VIRTUAL_CLASS(AudioStreamGeneratorPlayback);
  130. {
  131. //audio effects
  132. GDREGISTER_CLASS(AudioEffectAmplify);
  133. GDREGISTER_CLASS(AudioEffectReverb);
  134. GDREGISTER_CLASS(AudioEffectLowPassFilter);
  135. GDREGISTER_CLASS(AudioEffectHighPassFilter);
  136. GDREGISTER_CLASS(AudioEffectBandPassFilter);
  137. GDREGISTER_CLASS(AudioEffectNotchFilter);
  138. GDREGISTER_CLASS(AudioEffectBandLimitFilter);
  139. GDREGISTER_CLASS(AudioEffectLowShelfFilter);
  140. GDREGISTER_CLASS(AudioEffectHighShelfFilter);
  141. GDREGISTER_CLASS(AudioEffectEQ6);
  142. GDREGISTER_CLASS(AudioEffectEQ10);
  143. GDREGISTER_CLASS(AudioEffectEQ21);
  144. GDREGISTER_CLASS(AudioEffectDistortion);
  145. GDREGISTER_CLASS(AudioEffectStereoEnhance);
  146. GDREGISTER_CLASS(AudioEffectPanner);
  147. GDREGISTER_CLASS(AudioEffectChorus);
  148. GDREGISTER_CLASS(AudioEffectDelay);
  149. GDREGISTER_CLASS(AudioEffectCompressor);
  150. GDREGISTER_CLASS(AudioEffectLimiter);
  151. GDREGISTER_CLASS(AudioEffectPitchShift);
  152. GDREGISTER_CLASS(AudioEffectPhaser);
  153. GDREGISTER_CLASS(AudioEffectRecord);
  154. GDREGISTER_CLASS(AudioEffectSpectrumAnalyzer);
  155. GDREGISTER_VIRTUAL_CLASS(AudioEffectSpectrumAnalyzerInstance);
  156. GDREGISTER_CLASS(AudioEffectCapture);
  157. }
  158. GDREGISTER_VIRTUAL_CLASS(RenderingDevice);
  159. GDREGISTER_CLASS(RDTextureFormat);
  160. GDREGISTER_CLASS(RDTextureView);
  161. GDREGISTER_CLASS(RDAttachmentFormat);
  162. GDREGISTER_CLASS(RDFramebufferPass);
  163. GDREGISTER_CLASS(RDSamplerState);
  164. GDREGISTER_CLASS(RDVertexAttribute);
  165. GDREGISTER_CLASS(RDUniform);
  166. GDREGISTER_CLASS(RDPipelineRasterizationState);
  167. GDREGISTER_CLASS(RDPipelineMultisampleState);
  168. GDREGISTER_CLASS(RDPipelineDepthStencilState);
  169. GDREGISTER_CLASS(RDPipelineColorBlendStateAttachment);
  170. GDREGISTER_CLASS(RDPipelineColorBlendState);
  171. GDREGISTER_CLASS(RDShaderSource);
  172. GDREGISTER_CLASS(RDShaderSPIRV);
  173. GDREGISTER_CLASS(RDShaderFile);
  174. GDREGISTER_CLASS(RDPipelineSpecializationConstant);
  175. GDREGISTER_CLASS(CameraFeed);
  176. GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState2D);
  177. GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState2D);
  178. GDREGISTER_CLASS(PhysicsRayQueryParameters2D);
  179. GDREGISTER_CLASS(PhysicsPointQueryParameters2D);
  180. GDREGISTER_CLASS(PhysicsShapeQueryParameters2D);
  181. GDREGISTER_CLASS(PhysicsTestMotionParameters2D);
  182. GDREGISTER_CLASS(PhysicsTestMotionResult2D);
  183. GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState3D);
  184. GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState3D);
  185. GDREGISTER_CLASS(PhysicsRayQueryParameters3D);
  186. GDREGISTER_CLASS(PhysicsPointQueryParameters3D);
  187. GDREGISTER_CLASS(PhysicsShapeQueryParameters3D);
  188. GDREGISTER_CLASS(PhysicsTestMotionParameters3D);
  189. GDREGISTER_CLASS(PhysicsTestMotionResult3D);
  190. // Physics 2D
  191. GLOBAL_DEF(PhysicsServer2DManager::setting_property_name, "DEFAULT");
  192. ProjectSettings::get_singleton()->set_custom_property_info(PhysicsServer2DManager::setting_property_name, PropertyInfo(Variant::STRING, PhysicsServer2DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"));
  193. PhysicsServer2DManager::register_server("GodotPhysics2D", &_createGodotPhysics2DCallback);
  194. PhysicsServer2DManager::set_default_server("GodotPhysics2D");
  195. // Physics 3D
  196. GLOBAL_DEF(PhysicsServer3DManager::setting_property_name, "DEFAULT");
  197. ProjectSettings::get_singleton()->set_custom_property_info(PhysicsServer3DManager::setting_property_name, PropertyInfo(Variant::STRING, PhysicsServer3DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"));
  198. PhysicsServer3DManager::register_server("GodotPhysics3D", &_createGodotPhysics3DCallback);
  199. PhysicsServer3DManager::set_default_server("GodotPhysics3D");
  200. NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS);
  201. }
  202. void unregister_server_types() {
  203. NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS);
  204. memdelete(shader_types);
  205. }
  206. void register_server_singletons() {
  207. Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton(), "DisplayServer"));
  208. Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer"));
  209. Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton(), "AudioServer"));
  210. Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D", PhysicsServer2D::get_singleton(), "PhysicsServer2D"));
  211. Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton(), "PhysicsServer3D"));
  212. Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton_mut(), "NavigationServer2D"));
  213. Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton_mut(), "NavigationServer3D"));
  214. Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer"));
  215. Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer"));
  216. }