| 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 | |
| 31 | #include "register_server_types.h" |
| 32 | |
| 33 | #include "core/config/engine.h" |
| 34 | #include "core/config/project_settings.h" |
| 35 | |
| 36 | #include "audio/audio_effect.h" |
| 37 | #include "audio/audio_stream.h" |
| 38 | #include "audio/effects/audio_effect_amplify.h" |
| 39 | #include "audio/effects/audio_effect_capture.h" |
| 40 | #include "audio/effects/audio_effect_chorus.h" |
| 41 | #include "audio/effects/audio_effect_compressor.h" |
| 42 | #include "audio/effects/audio_effect_delay.h" |
| 43 | #include "audio/effects/audio_effect_distortion.h" |
| 44 | #include "audio/effects/audio_effect_eq.h" |
| 45 | #include "audio/effects/audio_effect_filter.h" |
| 46 | #include "audio/effects/audio_effect_limiter.h" |
| 47 | #include "audio/effects/audio_effect_panner.h" |
| 48 | #include "audio/effects/audio_effect_phaser.h" |
| 49 | #include "audio/effects/audio_effect_pitch_shift.h" |
| 50 | #include "audio/effects/audio_effect_record.h" |
| 51 | #include "audio/effects/audio_effect_reverb.h" |
| 52 | #include "audio/effects/audio_effect_spectrum_analyzer.h" |
| 53 | #include "audio/effects/audio_effect_stereo_enhance.h" |
| 54 | #include "audio/effects/audio_stream_generator.h" |
| 55 | #include "audio_server.h" |
| 56 | #include "camera/camera_feed.h" |
| 57 | #include "camera_server.h" |
| 58 | #include "debugger/servers_debugger.h" |
| 59 | #include "display_server.h" |
| 60 | #include "movie_writer/movie_writer.h" |
| 61 | #include "movie_writer/movie_writer_mjpeg.h" |
| 62 | #include "movie_writer/movie_writer_pngwav.h" |
| 63 | #include "navigation_server_2d.h" |
| 64 | #include "navigation_server_3d.h" |
| 65 | #include "physics_2d/godot_physics_server_2d.h" |
| 66 | #include "physics_3d/godot_physics_server_3d.h" |
| 67 | #include "physics_server_2d.h" |
| 68 | #include "physics_server_2d_wrap_mt.h" |
| 69 | #include "physics_server_3d.h" |
| 70 | #include "physics_server_3d_wrap_mt.h" |
| 71 | #include "rendering/renderer_compositor.h" |
| 72 | #include "rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h" |
| 73 | #include "rendering/rendering_device.h" |
| 74 | #include "rendering/rendering_device_binds.h" |
| 75 | #include "rendering/storage/render_scene_buffers.h" |
| 76 | #include "rendering_server.h" |
| 77 | #include "servers/extensions/physics_server_2d_extension.h" |
| 78 | #include "servers/extensions/physics_server_3d_extension.h" |
| 79 | #include "servers/rendering/shader_types.h" |
| 80 | #include "text/text_server_dummy.h" |
| 81 | #include "text/text_server_extension.h" |
| 82 | #include "text_server.h" |
| 83 | #include "xr/xr_interface.h" |
| 84 | #include "xr/xr_interface_extension.h" |
| 85 | #include "xr/xr_positional_tracker.h" |
| 86 | #include "xr_server.h" |
| 87 | |
| 88 | ShaderTypes *shader_types = nullptr; |
| 89 | |
| 90 | static PhysicsServer3D *_createGodotPhysics3DCallback() { |
| 91 | bool using_threads = GLOBAL_GET("physics/3d/run_on_separate_thread" ); |
| 92 | |
| 93 | PhysicsServer3D *physics_server_3d = memnew(GodotPhysicsServer3D(using_threads)); |
| 94 | |
| 95 | return memnew(PhysicsServer3DWrapMT(physics_server_3d, using_threads)); |
| 96 | } |
| 97 | |
| 98 | static PhysicsServer2D *_createGodotPhysics2DCallback() { |
| 99 | bool using_threads = GLOBAL_GET("physics/2d/run_on_separate_thread" ); |
| 100 | |
| 101 | PhysicsServer2D *physics_server_2d = memnew(GodotPhysicsServer2D(using_threads)); |
| 102 | |
| 103 | return memnew(PhysicsServer2DWrapMT(physics_server_2d, using_threads)); |
| 104 | } |
| 105 | |
| 106 | static bool has_server_feature_callback(const String &p_feature) { |
| 107 | if (RenderingServer::get_singleton()) { |
| 108 | if (RenderingServer::get_singleton()->has_os_feature(p_feature)) { |
| 109 | return true; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | static MovieWriterMJPEG *writer_mjpeg = nullptr; |
| 117 | static MovieWriterPNGWAV *writer_pngwav = nullptr; |
| 118 | |
| 119 | void register_server_types() { |
| 120 | shader_types = memnew(ShaderTypes); |
| 121 | |
| 122 | GDREGISTER_CLASS(TextServerManager); |
| 123 | GDREGISTER_ABSTRACT_CLASS(TextServer); |
| 124 | GDREGISTER_CLASS(TextServerExtension); |
| 125 | GDREGISTER_CLASS(TextServerDummy); |
| 126 | |
| 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 | |
| 130 | Engine::get_singleton()->add_singleton(Engine::Singleton("TextServerManager" , TextServerManager::get_singleton(), "TextServerManager" )); |
| 131 | |
| 132 | OS::get_singleton()->set_has_server_feature_callback(has_server_feature_callback); |
| 133 | |
| 134 | GDREGISTER_ABSTRACT_CLASS(DisplayServer); |
| 135 | GDREGISTER_ABSTRACT_CLASS(RenderingServer); |
| 136 | GDREGISTER_CLASS(AudioServer); |
| 137 | |
| 138 | GDREGISTER_CLASS(PhysicsServer2DManager); |
| 139 | Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2DManager" , PhysicsServer2DManager::get_singleton(), "PhysicsServer2DManager" )); |
| 140 | |
| 141 | GDREGISTER_ABSTRACT_CLASS(PhysicsServer2D); |
| 142 | GDREGISTER_VIRTUAL_CLASS(PhysicsServer2DExtension); |
| 143 | GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState2DExtension); |
| 144 | GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState2DExtension); |
| 145 | |
| 146 | GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionRayResult, "Vector2 position;Vector2 normal;RID rid;ObjectID collider_id;Object *collider;int shape" ); |
| 147 | GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape" ); |
| 148 | GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeRestInfo, "Vector2 point;Vector2 normal;RID rid;ObjectID collider_id;int shape;Vector2 linear_velocity" ); |
| 149 | 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" ); |
| 150 | |
| 151 | GDREGISTER_CLASS(PhysicsServer3DManager); |
| 152 | Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3DManager" , PhysicsServer3DManager::get_singleton(), "PhysicsServer3DManager" )); |
| 153 | |
| 154 | GDREGISTER_ABSTRACT_CLASS(PhysicsServer3D); |
| 155 | GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DExtension); |
| 156 | GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState3DExtension); |
| 157 | GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState3DExtension) |
| 158 | GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DRenderingServerHandler) |
| 159 | |
| 160 | GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionRayResult, "Vector3 position;Vector3 normal;RID rid;ObjectID collider_id;Object *collider;int shape" ); |
| 161 | GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape" ); |
| 162 | GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionShapeRestInfo, "Vector3 point;Vector3 normal;RID rid;ObjectID collider_id;int shape;Vector3 linear_velocity" ); |
| 163 | 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" ); |
| 164 | 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" ); |
| 165 | |
| 166 | GDREGISTER_ABSTRACT_CLASS(NavigationServer2D); |
| 167 | GDREGISTER_ABSTRACT_CLASS(NavigationServer3D); |
| 168 | GDREGISTER_CLASS(NavigationPathQueryParameters2D); |
| 169 | GDREGISTER_CLASS(NavigationPathQueryParameters3D); |
| 170 | GDREGISTER_CLASS(NavigationPathQueryResult2D); |
| 171 | GDREGISTER_CLASS(NavigationPathQueryResult3D); |
| 172 | |
| 173 | GDREGISTER_CLASS(XRServer); |
| 174 | GDREGISTER_CLASS(CameraServer); |
| 175 | |
| 176 | GDREGISTER_ABSTRACT_CLASS(RenderingDevice); |
| 177 | |
| 178 | GDREGISTER_ABSTRACT_CLASS(XRInterface); |
| 179 | GDREGISTER_CLASS(XRInterfaceExtension); // can't register this as virtual because we need a creation function for our extensions. |
| 180 | GDREGISTER_CLASS(XRPose); |
| 181 | GDREGISTER_CLASS(XRPositionalTracker); |
| 182 | |
| 183 | GDREGISTER_CLASS(AudioStream); |
| 184 | GDREGISTER_CLASS(AudioStreamPlayback); |
| 185 | GDREGISTER_VIRTUAL_CLASS(AudioStreamPlaybackResampled); |
| 186 | GDREGISTER_CLASS(AudioStreamMicrophone); |
| 187 | GDREGISTER_CLASS(AudioStreamRandomizer); |
| 188 | GDREGISTER_VIRTUAL_CLASS(AudioEffect); |
| 189 | GDREGISTER_VIRTUAL_CLASS(AudioEffectInstance); |
| 190 | GDREGISTER_CLASS(AudioEffectEQ); |
| 191 | GDREGISTER_CLASS(AudioEffectFilter); |
| 192 | GDREGISTER_CLASS(AudioBusLayout); |
| 193 | |
| 194 | GDREGISTER_CLASS(AudioStreamGenerator); |
| 195 | GDREGISTER_ABSTRACT_CLASS(AudioStreamGeneratorPlayback); |
| 196 | |
| 197 | { |
| 198 | //audio effects |
| 199 | GDREGISTER_CLASS(AudioEffectAmplify); |
| 200 | |
| 201 | GDREGISTER_CLASS(AudioEffectReverb); |
| 202 | |
| 203 | GDREGISTER_CLASS(AudioEffectLowPassFilter); |
| 204 | GDREGISTER_CLASS(AudioEffectHighPassFilter); |
| 205 | GDREGISTER_CLASS(AudioEffectBandPassFilter); |
| 206 | GDREGISTER_CLASS(AudioEffectNotchFilter); |
| 207 | GDREGISTER_CLASS(AudioEffectBandLimitFilter); |
| 208 | GDREGISTER_CLASS(AudioEffectLowShelfFilter); |
| 209 | GDREGISTER_CLASS(AudioEffectHighShelfFilter); |
| 210 | |
| 211 | GDREGISTER_CLASS(AudioEffectEQ6); |
| 212 | GDREGISTER_CLASS(AudioEffectEQ10); |
| 213 | GDREGISTER_CLASS(AudioEffectEQ21); |
| 214 | |
| 215 | GDREGISTER_CLASS(AudioEffectDistortion); |
| 216 | |
| 217 | GDREGISTER_CLASS(AudioEffectStereoEnhance); |
| 218 | |
| 219 | GDREGISTER_CLASS(AudioEffectPanner); |
| 220 | GDREGISTER_CLASS(AudioEffectChorus); |
| 221 | GDREGISTER_CLASS(AudioEffectDelay); |
| 222 | GDREGISTER_CLASS(AudioEffectCompressor); |
| 223 | GDREGISTER_CLASS(AudioEffectLimiter); |
| 224 | GDREGISTER_CLASS(AudioEffectPitchShift); |
| 225 | GDREGISTER_CLASS(AudioEffectPhaser); |
| 226 | |
| 227 | GDREGISTER_CLASS(AudioEffectRecord); |
| 228 | GDREGISTER_CLASS(AudioEffectSpectrumAnalyzer); |
| 229 | GDREGISTER_ABSTRACT_CLASS(AudioEffectSpectrumAnalyzerInstance); |
| 230 | |
| 231 | GDREGISTER_CLASS(AudioEffectCapture); |
| 232 | } |
| 233 | |
| 234 | GDREGISTER_ABSTRACT_CLASS(RenderingDevice); |
| 235 | GDREGISTER_CLASS(RDTextureFormat); |
| 236 | GDREGISTER_CLASS(RDTextureView); |
| 237 | GDREGISTER_CLASS(RDAttachmentFormat); |
| 238 | GDREGISTER_CLASS(RDFramebufferPass); |
| 239 | GDREGISTER_CLASS(RDSamplerState); |
| 240 | GDREGISTER_CLASS(RDVertexAttribute); |
| 241 | GDREGISTER_CLASS(RDUniform); |
| 242 | GDREGISTER_CLASS(RDPipelineRasterizationState); |
| 243 | GDREGISTER_CLASS(RDPipelineMultisampleState); |
| 244 | GDREGISTER_CLASS(RDPipelineDepthStencilState); |
| 245 | GDREGISTER_CLASS(RDPipelineColorBlendStateAttachment); |
| 246 | GDREGISTER_CLASS(RDPipelineColorBlendState); |
| 247 | GDREGISTER_CLASS(RDShaderSource); |
| 248 | GDREGISTER_CLASS(RDShaderSPIRV); |
| 249 | GDREGISTER_CLASS(RDShaderFile); |
| 250 | GDREGISTER_CLASS(RDPipelineSpecializationConstant); |
| 251 | |
| 252 | GDREGISTER_CLASS(RenderSceneBuffersConfiguration); |
| 253 | GDREGISTER_ABSTRACT_CLASS(RenderSceneBuffers); |
| 254 | GDREGISTER_CLASS(RenderSceneBuffersExtension); |
| 255 | GDREGISTER_ABSTRACT_CLASS(RenderSceneBuffersRD); |
| 256 | |
| 257 | GDREGISTER_CLASS(CameraFeed); |
| 258 | |
| 259 | GDREGISTER_ABSTRACT_CLASS(PhysicsDirectBodyState2D); |
| 260 | GDREGISTER_ABSTRACT_CLASS(PhysicsDirectSpaceState2D); |
| 261 | GDREGISTER_CLASS(PhysicsRayQueryParameters2D); |
| 262 | GDREGISTER_CLASS(PhysicsPointQueryParameters2D); |
| 263 | GDREGISTER_CLASS(PhysicsShapeQueryParameters2D); |
| 264 | GDREGISTER_CLASS(PhysicsTestMotionParameters2D); |
| 265 | GDREGISTER_CLASS(PhysicsTestMotionResult2D); |
| 266 | |
| 267 | GDREGISTER_ABSTRACT_CLASS(PhysicsDirectBodyState3D); |
| 268 | GDREGISTER_ABSTRACT_CLASS(PhysicsDirectSpaceState3D); |
| 269 | GDREGISTER_CLASS(PhysicsRayQueryParameters3D); |
| 270 | GDREGISTER_CLASS(PhysicsPointQueryParameters3D); |
| 271 | GDREGISTER_CLASS(PhysicsShapeQueryParameters3D); |
| 272 | GDREGISTER_CLASS(PhysicsTestMotionParameters3D); |
| 273 | GDREGISTER_CLASS(PhysicsTestMotionResult3D); |
| 274 | |
| 275 | GDREGISTER_VIRTUAL_CLASS(MovieWriter); |
| 276 | |
| 277 | ServersDebugger::initialize(); |
| 278 | |
| 279 | // Physics 2D |
| 280 | GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer2DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT" ), "DEFAULT" ); |
| 281 | |
| 282 | PhysicsServer2DManager::get_singleton()->register_server("GodotPhysics2D" , callable_mp_static(_createGodotPhysics2DCallback)); |
| 283 | PhysicsServer2DManager::get_singleton()->set_default_server("GodotPhysics2D" ); |
| 284 | |
| 285 | // Physics 3D |
| 286 | GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer3DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT" ), "DEFAULT" ); |
| 287 | |
| 288 | PhysicsServer3DManager::get_singleton()->register_server("GodotPhysics3D" , callable_mp_static(_createGodotPhysics3DCallback)); |
| 289 | PhysicsServer3DManager::get_singleton()->set_default_server("GodotPhysics3D" ); |
| 290 | |
| 291 | writer_mjpeg = memnew(MovieWriterMJPEG); |
| 292 | MovieWriter::add_writer(writer_mjpeg); |
| 293 | |
| 294 | writer_pngwav = memnew(MovieWriterPNGWAV); |
| 295 | MovieWriter::add_writer(writer_pngwav); |
| 296 | } |
| 297 | |
| 298 | void unregister_server_types() { |
| 299 | ServersDebugger::deinitialize(); |
| 300 | memdelete(shader_types); |
| 301 | memdelete(writer_mjpeg); |
| 302 | memdelete(writer_pngwav); |
| 303 | } |
| 304 | |
| 305 | void register_server_singletons() { |
| 306 | Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer" , DisplayServer::get_singleton(), "DisplayServer" )); |
| 307 | Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer" , RenderingServer::get_singleton(), "RenderingServer" )); |
| 308 | Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer" , AudioServer::get_singleton(), "AudioServer" )); |
| 309 | Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D" , PhysicsServer2D::get_singleton(), "PhysicsServer2D" )); |
| 310 | Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D" , PhysicsServer3D::get_singleton(), "PhysicsServer3D" )); |
| 311 | Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D" , NavigationServer2D::get_singleton(), "NavigationServer2D" )); |
| 312 | Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D" , NavigationServer3D::get_singleton(), "NavigationServer3D" )); |
| 313 | Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer" , XRServer::get_singleton(), "XRServer" )); |
| 314 | Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer" , CameraServer::get_singleton(), "CameraServer" )); |
| 315 | } |
| 316 | |