register_server_types.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /**************************************************************************/
  2. /* register_server_types.cpp */
  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. #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_hard_limiter.h"
  44. #include "audio/effects/audio_effect_limiter.h"
  45. #include "audio/effects/audio_effect_panner.h"
  46. #include "audio/effects/audio_effect_phaser.h"
  47. #include "audio/effects/audio_effect_pitch_shift.h"
  48. #include "audio/effects/audio_effect_record.h"
  49. #include "audio/effects/audio_effect_reverb.h"
  50. #include "audio/effects/audio_effect_spectrum_analyzer.h"
  51. #include "audio/effects/audio_effect_stereo_enhance.h"
  52. #include "audio/effects/audio_stream_generator.h"
  53. #include "audio_server.h"
  54. #include "camera/camera_feed.h"
  55. #include "camera_server.h"
  56. #include "debugger/servers_debugger.h"
  57. #include "display/native_menu.h"
  58. #include "display_server.h"
  59. #include "movie_writer/movie_writer.h"
  60. #include "movie_writer/movie_writer_mjpeg.h"
  61. #include "movie_writer/movie_writer_pngwav.h"
  62. #include "rendering/renderer_compositor.h"
  63. #include "rendering/renderer_rd/framebuffer_cache_rd.h"
  64. #include "rendering/renderer_rd/storage_rd/render_data_rd.h"
  65. #include "rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h"
  66. #include "rendering/renderer_rd/storage_rd/render_scene_data_rd.h"
  67. #include "rendering/renderer_rd/uniform_set_cache_rd.h"
  68. #include "rendering/rendering_device.h"
  69. #include "rendering/rendering_device_binds.h"
  70. #include "rendering/shader_include_db.h"
  71. #include "rendering/storage/render_data.h"
  72. #include "rendering/storage/render_scene_buffers.h"
  73. #include "rendering/storage/render_scene_data.h"
  74. #include "rendering_server.h"
  75. #include "servers/rendering/shader_types.h"
  76. #include "text/text_server_dummy.h"
  77. #include "text/text_server_extension.h"
  78. #include "text_server.h"
  79. // 2D physics and navigation.
  80. #include "navigation_server_2d.h"
  81. #include "physics_server_2d.h"
  82. #include "physics_server_2d_dummy.h"
  83. #include "physics_server_2d_wrap_mt.h"
  84. #include "servers/extensions/physics_server_2d_extension.h"
  85. // 3D physics and navigation (3D navigation is needed for 2D).
  86. #include "navigation_server_3d.h"
  87. #ifndef _3D_DISABLED
  88. #include "physics_server_3d.h"
  89. #include "physics_server_3d_dummy.h"
  90. #include "physics_server_3d_wrap_mt.h"
  91. #include "servers/extensions/physics_server_3d_extension.h"
  92. #include "xr/xr_body_tracker.h"
  93. #include "xr/xr_controller_tracker.h"
  94. #include "xr/xr_face_tracker.h"
  95. #include "xr/xr_hand_tracker.h"
  96. #include "xr/xr_interface.h"
  97. #include "xr/xr_interface_extension.h"
  98. #include "xr/xr_positional_tracker.h"
  99. #include "xr_server.h"
  100. #endif // _3D_DISABLED
  101. ShaderTypes *shader_types = nullptr;
  102. #ifndef _3D_DISABLED
  103. static PhysicsServer3D *_create_dummy_physics_server_3d() {
  104. return memnew(PhysicsServer3DDummy);
  105. }
  106. #endif // _3D_DISABLED
  107. static PhysicsServer2D *_create_dummy_physics_server_2d() {
  108. return memnew(PhysicsServer2DDummy);
  109. }
  110. static bool has_server_feature_callback(const String &p_feature) {
  111. if (RenderingServer::get_singleton()) {
  112. if (RenderingServer::get_singleton()->has_os_feature(p_feature)) {
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118. static MovieWriterMJPEG *writer_mjpeg = nullptr;
  119. static MovieWriterPNGWAV *writer_pngwav = nullptr;
  120. void register_server_types() {
  121. OS::get_singleton()->benchmark_begin_measure("Servers", "Register Extensions");
  122. shader_types = memnew(ShaderTypes);
  123. GDREGISTER_CLASS(TextServerManager);
  124. GDREGISTER_ABSTRACT_CLASS(TextServer);
  125. GDREGISTER_CLASS(TextServerExtension);
  126. GDREGISTER_CLASS(TextServerDummy);
  127. GDREGISTER_NATIVE_STRUCT(Glyph, "int start = -1;int end = -1;uint8_t count = 0;uint8_t repeat = 1;uint16_t flags = 0;float x_off = 0.f;float y_off = 0.f;float advance = 0.f;RID font_rid;int font_size = 0;int32_t index = 0");
  128. GDREGISTER_NATIVE_STRUCT(CaretInfo, "Rect2 leading_caret;Rect2 trailing_caret;TextServer::Direction leading_direction;TextServer::Direction trailing_direction");
  129. Engine::get_singleton()->add_singleton(Engine::Singleton("TextServerManager", TextServerManager::get_singleton(), "TextServerManager"));
  130. OS::get_singleton()->set_has_server_feature_callback(has_server_feature_callback);
  131. GDREGISTER_ABSTRACT_CLASS(DisplayServer);
  132. GDREGISTER_ABSTRACT_CLASS(RenderingServer);
  133. GDREGISTER_CLASS(AudioServer);
  134. GDREGISTER_CLASS(NativeMenu);
  135. GDREGISTER_CLASS(CameraServer);
  136. GDREGISTER_ABSTRACT_CLASS(RenderingDevice);
  137. GDREGISTER_CLASS(AudioStream);
  138. GDREGISTER_CLASS(AudioStreamPlayback);
  139. GDREGISTER_VIRTUAL_CLASS(AudioStreamPlaybackResampled);
  140. GDREGISTER_CLASS(AudioStreamMicrophone);
  141. GDREGISTER_CLASS(AudioStreamRandomizer);
  142. GDREGISTER_CLASS(AudioSample);
  143. GDREGISTER_CLASS(AudioSamplePlayback);
  144. GDREGISTER_VIRTUAL_CLASS(AudioEffect);
  145. GDREGISTER_VIRTUAL_CLASS(AudioEffectInstance);
  146. GDREGISTER_CLASS(AudioEffectEQ);
  147. GDREGISTER_CLASS(AudioEffectFilter);
  148. GDREGISTER_CLASS(AudioBusLayout);
  149. GDREGISTER_CLASS(AudioStreamGenerator);
  150. GDREGISTER_ABSTRACT_CLASS(AudioStreamGeneratorPlayback);
  151. {
  152. //audio effects
  153. GDREGISTER_CLASS(AudioEffectAmplify);
  154. GDREGISTER_CLASS(AudioEffectReverb);
  155. GDREGISTER_CLASS(AudioEffectLowPassFilter);
  156. GDREGISTER_CLASS(AudioEffectHighPassFilter);
  157. GDREGISTER_CLASS(AudioEffectBandPassFilter);
  158. GDREGISTER_CLASS(AudioEffectNotchFilter);
  159. GDREGISTER_CLASS(AudioEffectBandLimitFilter);
  160. GDREGISTER_CLASS(AudioEffectLowShelfFilter);
  161. GDREGISTER_CLASS(AudioEffectHighShelfFilter);
  162. GDREGISTER_CLASS(AudioEffectEQ6);
  163. GDREGISTER_CLASS(AudioEffectEQ10);
  164. GDREGISTER_CLASS(AudioEffectEQ21);
  165. GDREGISTER_CLASS(AudioEffectDistortion);
  166. GDREGISTER_CLASS(AudioEffectStereoEnhance);
  167. GDREGISTER_CLASS(AudioEffectPanner);
  168. GDREGISTER_CLASS(AudioEffectChorus);
  169. GDREGISTER_CLASS(AudioEffectDelay);
  170. GDREGISTER_CLASS(AudioEffectCompressor);
  171. GDREGISTER_CLASS(AudioEffectLimiter);
  172. GDREGISTER_CLASS(AudioEffectHardLimiter);
  173. GDREGISTER_CLASS(AudioEffectPitchShift);
  174. GDREGISTER_CLASS(AudioEffectPhaser);
  175. GDREGISTER_CLASS(AudioEffectRecord);
  176. GDREGISTER_CLASS(AudioEffectSpectrumAnalyzer);
  177. GDREGISTER_ABSTRACT_CLASS(AudioEffectSpectrumAnalyzerInstance);
  178. GDREGISTER_CLASS(AudioEffectCapture);
  179. }
  180. GDREGISTER_ABSTRACT_CLASS(RenderingDevice);
  181. GDREGISTER_CLASS(ShaderIncludeDB);
  182. GDREGISTER_CLASS(RDTextureFormat);
  183. GDREGISTER_CLASS(RDTextureView);
  184. GDREGISTER_CLASS(RDAttachmentFormat);
  185. GDREGISTER_CLASS(RDFramebufferPass);
  186. GDREGISTER_CLASS(RDSamplerState);
  187. GDREGISTER_CLASS(RDVertexAttribute);
  188. GDREGISTER_CLASS(RDUniform);
  189. GDREGISTER_CLASS(RDPipelineRasterizationState);
  190. GDREGISTER_CLASS(RDPipelineMultisampleState);
  191. GDREGISTER_CLASS(RDPipelineDepthStencilState);
  192. GDREGISTER_CLASS(RDPipelineColorBlendStateAttachment);
  193. GDREGISTER_CLASS(RDPipelineColorBlendState);
  194. GDREGISTER_CLASS(RDShaderSource);
  195. GDREGISTER_CLASS(RDShaderSPIRV);
  196. GDREGISTER_CLASS(RDShaderFile);
  197. GDREGISTER_CLASS(RDPipelineSpecializationConstant);
  198. GDREGISTER_ABSTRACT_CLASS(RenderData);
  199. GDREGISTER_CLASS(RenderDataExtension);
  200. GDREGISTER_CLASS(RenderDataRD);
  201. GDREGISTER_ABSTRACT_CLASS(RenderSceneData);
  202. GDREGISTER_CLASS(RenderSceneDataExtension);
  203. GDREGISTER_CLASS(RenderSceneDataRD);
  204. GDREGISTER_CLASS(RenderSceneBuffersConfiguration);
  205. GDREGISTER_ABSTRACT_CLASS(RenderSceneBuffers);
  206. GDREGISTER_CLASS(RenderSceneBuffersExtension);
  207. GDREGISTER_CLASS(RenderSceneBuffersRD);
  208. GDREGISTER_CLASS(FramebufferCacheRD);
  209. GDREGISTER_CLASS(UniformSetCacheRD);
  210. GDREGISTER_CLASS(CameraFeed);
  211. GDREGISTER_VIRTUAL_CLASS(MovieWriter);
  212. ServersDebugger::initialize();
  213. // Physics 2D
  214. GDREGISTER_CLASS(PhysicsServer2DManager);
  215. Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2DManager", PhysicsServer2DManager::get_singleton(), "PhysicsServer2DManager"));
  216. GDREGISTER_ABSTRACT_CLASS(PhysicsServer2D);
  217. GDREGISTER_VIRTUAL_CLASS(PhysicsServer2DExtension);
  218. GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState2DExtension);
  219. GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState2DExtension);
  220. GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionRayResult, "Vector2 position;Vector2 normal;RID rid;ObjectID collider_id;Object *collider;int shape");
  221. GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape");
  222. GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeRestInfo, "Vector2 point;Vector2 normal;RID rid;ObjectID collider_id;int shape;Vector2 linear_velocity");
  223. GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionMotionResult, "Vector2 travel;Vector2 remainder;Vector2 collision_point;Vector2 collision_normal;Vector2 collider_velocity;real_t collision_depth;real_t collision_safe_fraction;real_t collision_unsafe_fraction;int collision_local_shape;ObjectID collider_id;RID collider;int collider_shape");
  224. GDREGISTER_ABSTRACT_CLASS(PhysicsDirectBodyState2D);
  225. GDREGISTER_ABSTRACT_CLASS(PhysicsDirectSpaceState2D);
  226. GDREGISTER_CLASS(PhysicsRayQueryParameters2D);
  227. GDREGISTER_CLASS(PhysicsPointQueryParameters2D);
  228. GDREGISTER_CLASS(PhysicsShapeQueryParameters2D);
  229. GDREGISTER_CLASS(PhysicsTestMotionParameters2D);
  230. GDREGISTER_CLASS(PhysicsTestMotionResult2D);
  231. GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer2DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT");
  232. PhysicsServer2DManager::get_singleton()->register_server("Dummy", callable_mp_static(_create_dummy_physics_server_2d));
  233. GDREGISTER_ABSTRACT_CLASS(NavigationServer2D);
  234. GDREGISTER_CLASS(NavigationPathQueryParameters2D);
  235. GDREGISTER_CLASS(NavigationPathQueryResult2D);
  236. #ifndef _3D_DISABLED
  237. // Physics 3D
  238. GDREGISTER_CLASS(PhysicsServer3DManager);
  239. Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3DManager", PhysicsServer3DManager::get_singleton(), "PhysicsServer3DManager"));
  240. GDREGISTER_ABSTRACT_CLASS(PhysicsServer3D);
  241. GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DExtension);
  242. GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState3DExtension);
  243. GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState3DExtension)
  244. GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DRenderingServerHandler)
  245. GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionRayResult, "Vector3 position;Vector3 normal;RID rid;ObjectID collider_id;Object *collider;int shape;int face_index");
  246. GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape");
  247. GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionShapeRestInfo, "Vector3 point;Vector3 normal;RID rid;ObjectID collider_id;int shape;Vector3 linear_velocity");
  248. GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionMotionCollision, "Vector3 position;Vector3 normal;Vector3 collider_velocity;Vector3 collider_angular_velocity;real_t depth;int local_shape;ObjectID collider_id;RID collider;int collider_shape");
  249. GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionMotionResult, "Vector3 travel;Vector3 remainder;real_t collision_depth;real_t collision_safe_fraction;real_t collision_unsafe_fraction;PhysicsServer3DExtensionMotionCollision collisions[32];int collision_count");
  250. GDREGISTER_ABSTRACT_CLASS(PhysicsDirectBodyState3D);
  251. GDREGISTER_ABSTRACT_CLASS(PhysicsDirectSpaceState3D);
  252. GDREGISTER_CLASS(PhysicsRayQueryParameters3D);
  253. GDREGISTER_CLASS(PhysicsPointQueryParameters3D);
  254. GDREGISTER_CLASS(PhysicsShapeQueryParameters3D);
  255. GDREGISTER_CLASS(PhysicsTestMotionParameters3D);
  256. GDREGISTER_CLASS(PhysicsTestMotionResult3D);
  257. GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer3DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT");
  258. PhysicsServer3DManager::get_singleton()->register_server("Dummy", callable_mp_static(_create_dummy_physics_server_3d));
  259. GDREGISTER_ABSTRACT_CLASS(XRInterface);
  260. GDREGISTER_CLASS(XRVRS);
  261. GDREGISTER_CLASS(XRBodyTracker);
  262. GDREGISTER_CLASS(XRControllerTracker);
  263. GDREGISTER_CLASS(XRFaceTracker);
  264. GDREGISTER_CLASS(XRHandTracker);
  265. GDREGISTER_CLASS(XRInterfaceExtension); // can't register this as virtual because we need a creation function for our extensions.
  266. GDREGISTER_CLASS(XRPose);
  267. GDREGISTER_CLASS(XRPositionalTracker);
  268. GDREGISTER_CLASS(XRServer);
  269. GDREGISTER_ABSTRACT_CLASS(XRTracker);
  270. #endif // _3D_DISABLED
  271. GDREGISTER_ABSTRACT_CLASS(NavigationServer3D);
  272. GDREGISTER_CLASS(NavigationPathQueryParameters3D);
  273. GDREGISTER_CLASS(NavigationPathQueryResult3D);
  274. writer_mjpeg = memnew(MovieWriterMJPEG);
  275. MovieWriter::add_writer(writer_mjpeg);
  276. writer_pngwav = memnew(MovieWriterPNGWAV);
  277. MovieWriter::add_writer(writer_pngwav);
  278. OS::get_singleton()->benchmark_end_measure("Servers", "Register Extensions");
  279. }
  280. void unregister_server_types() {
  281. OS::get_singleton()->benchmark_begin_measure("Servers", "Unregister Extensions");
  282. ServersDebugger::deinitialize();
  283. memdelete(shader_types);
  284. memdelete(writer_mjpeg);
  285. memdelete(writer_pngwav);
  286. OS::get_singleton()->benchmark_end_measure("Servers", "Unregister Extensions");
  287. }
  288. void register_server_singletons() {
  289. OS::get_singleton()->benchmark_begin_measure("Servers", "Register Singletons");
  290. Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton(), "AudioServer"));
  291. Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer"));
  292. Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton(), "DisplayServer"));
  293. Engine::get_singleton()->add_singleton(Engine::Singleton("NativeMenu", NativeMenu::get_singleton(), "NativeMenu"));
  294. Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton(), "NavigationServer2D"));
  295. Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D"));
  296. Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer"));
  297. Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D", PhysicsServer2D::get_singleton(), "PhysicsServer2D"));
  298. #ifndef _3D_DISABLED
  299. Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton(), "PhysicsServer3D"));
  300. Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer"));
  301. #endif // _3D_DISABLED
  302. OS::get_singleton()->benchmark_end_measure("Servers", "Register Singletons");
  303. }