From eb019e243f5048b1218d1b6cb5161fd8fb16a69c Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 7 Jul 2023 23:08:03 -0500 Subject: [PATCH] Disable registering 3D physics types when 3D is disabled --- servers/register_server_types.cpp | 108 ++++++++++++++++-------------- 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index 150c155f1ab..66843aaad87 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -60,14 +60,6 @@ #include "movie_writer/movie_writer.h" #include "movie_writer/movie_writer_mjpeg.h" #include "movie_writer/movie_writer_pngwav.h" -#include "navigation_server_2d.h" -#include "navigation_server_3d.h" -#include "physics_2d/godot_physics_server_2d.h" -#include "physics_3d/godot_physics_server_3d.h" -#include "physics_server_2d.h" -#include "physics_server_2d_wrap_mt.h" -#include "physics_server_3d.h" -#include "physics_server_3d_wrap_mt.h" #include "rendering/renderer_compositor.h" #include "rendering/renderer_rd/framebuffer_cache_rd.h" #include "rendering/renderer_rd/storage_rd/render_data_rd.h" @@ -80,8 +72,6 @@ #include "rendering/storage/render_scene_buffers.h" #include "rendering/storage/render_scene_data.h" #include "rendering_server.h" -#include "servers/extensions/physics_server_2d_extension.h" -#include "servers/extensions/physics_server_3d_extension.h" #include "servers/rendering/shader_types.h" #include "text/text_server_dummy.h" #include "text/text_server_extension.h" @@ -92,8 +82,25 @@ #include "xr/xr_positional_tracker.h" #include "xr_server.h" +// 2D physics and navigation. +#include "navigation_server_2d.h" +#include "physics_2d/godot_physics_server_2d.h" +#include "physics_server_2d.h" +#include "physics_server_2d_wrap_mt.h" +#include "servers/extensions/physics_server_2d_extension.h" + +// 3D physics and navigation (3D navigation is needed for 2D). +#include "navigation_server_3d.h" +#ifndef _3D_DISABLED +#include "physics_3d/godot_physics_server_3d.h" +#include "physics_server_3d.h" +#include "physics_server_3d_wrap_mt.h" +#include "servers/extensions/physics_server_3d_extension.h" +#endif // _3D_DISABLED + ShaderTypes *shader_types = nullptr; +#ifndef _3D_DISABLED static PhysicsServer3D *_createGodotPhysics3DCallback() { #ifdef THREADS_ENABLED bool using_threads = GLOBAL_GET("physics/3d/run_on_separate_thread"); @@ -105,6 +112,7 @@ static PhysicsServer3D *_createGodotPhysics3DCallback() { return memnew(PhysicsServer3DWrapMT(physics_server_3d, using_threads)); } +#endif // _3D_DISABLED static PhysicsServer2D *_createGodotPhysics2DCallback() { #ifdef THREADS_ENABLED @@ -152,34 +160,6 @@ void register_server_types() { GDREGISTER_ABSTRACT_CLASS(RenderingServer); GDREGISTER_CLASS(AudioServer); - GDREGISTER_CLASS(PhysicsServer2DManager); - Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2DManager", PhysicsServer2DManager::get_singleton(), "PhysicsServer2DManager")); - - GDREGISTER_ABSTRACT_CLASS(PhysicsServer2D); - GDREGISTER_VIRTUAL_CLASS(PhysicsServer2DExtension); - GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState2DExtension); - GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState2DExtension); - - GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionRayResult, "Vector2 position;Vector2 normal;RID rid;ObjectID collider_id;Object *collider;int shape"); - GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape"); - GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeRestInfo, "Vector2 point;Vector2 normal;RID rid;ObjectID collider_id;int shape;Vector2 linear_velocity"); - 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"); - - GDREGISTER_CLASS(PhysicsServer3DManager); - Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3DManager", PhysicsServer3DManager::get_singleton(), "PhysicsServer3DManager")); - - GDREGISTER_ABSTRACT_CLASS(PhysicsServer3D); - GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DExtension); - GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState3DExtension); - GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState3DExtension) - GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DRenderingServerHandler) - - GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionRayResult, "Vector3 position;Vector3 normal;RID rid;ObjectID collider_id;Object *collider;int shape;int face_index"); - GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape"); - GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionShapeRestInfo, "Vector3 point;Vector3 normal;RID rid;ObjectID collider_id;int shape;Vector3 linear_velocity"); - 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"); - 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"); - GDREGISTER_ABSTRACT_CLASS(NavigationServer2D); GDREGISTER_ABSTRACT_CLASS(NavigationServer3D); GDREGISTER_CLASS(NavigationPathQueryParameters2D); @@ -285,6 +265,24 @@ void register_server_types() { GDREGISTER_CLASS(CameraFeed); + GDREGISTER_VIRTUAL_CLASS(MovieWriter); + + ServersDebugger::initialize(); + + // Physics 2D + GDREGISTER_CLASS(PhysicsServer2DManager); + Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2DManager", PhysicsServer2DManager::get_singleton(), "PhysicsServer2DManager")); + + GDREGISTER_ABSTRACT_CLASS(PhysicsServer2D); + GDREGISTER_VIRTUAL_CLASS(PhysicsServer2DExtension); + GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState2DExtension); + GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState2DExtension); + + GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionRayResult, "Vector2 position;Vector2 normal;RID rid;ObjectID collider_id;Object *collider;int shape"); + GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape"); + GDREGISTER_NATIVE_STRUCT(PhysicsServer2DExtensionShapeRestInfo, "Vector2 point;Vector2 normal;RID rid;ObjectID collider_id;int shape;Vector2 linear_velocity"); + 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"); + GDREGISTER_ABSTRACT_CLASS(PhysicsDirectBodyState2D); GDREGISTER_ABSTRACT_CLASS(PhysicsDirectSpaceState2D); GDREGISTER_CLASS(PhysicsRayQueryParameters2D); @@ -293,6 +291,28 @@ void register_server_types() { GDREGISTER_CLASS(PhysicsTestMotionParameters2D); GDREGISTER_CLASS(PhysicsTestMotionResult2D); + GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer2DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT"); + + PhysicsServer2DManager::get_singleton()->register_server("GodotPhysics2D", callable_mp_static(_createGodotPhysics2DCallback)); + PhysicsServer2DManager::get_singleton()->set_default_server("GodotPhysics2D"); + +#ifndef _3D_DISABLED + // Physics 3D + GDREGISTER_CLASS(PhysicsServer3DManager); + Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3DManager", PhysicsServer3DManager::get_singleton(), "PhysicsServer3DManager")); + + GDREGISTER_ABSTRACT_CLASS(PhysicsServer3D); + GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DExtension); + GDREGISTER_VIRTUAL_CLASS(PhysicsDirectBodyState3DExtension); + GDREGISTER_VIRTUAL_CLASS(PhysicsDirectSpaceState3DExtension) + GDREGISTER_VIRTUAL_CLASS(PhysicsServer3DRenderingServerHandler) + + GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionRayResult, "Vector3 position;Vector3 normal;RID rid;ObjectID collider_id;Object *collider;int shape;int face_index"); + GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionShapeResult, "RID rid;ObjectID collider_id;Object *collider;int shape"); + GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionShapeRestInfo, "Vector3 point;Vector3 normal;RID rid;ObjectID collider_id;int shape;Vector3 linear_velocity"); + 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"); + 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"); + GDREGISTER_ABSTRACT_CLASS(PhysicsDirectBodyState3D); GDREGISTER_ABSTRACT_CLASS(PhysicsDirectSpaceState3D); GDREGISTER_CLASS(PhysicsRayQueryParameters3D); @@ -301,21 +321,11 @@ void register_server_types() { GDREGISTER_CLASS(PhysicsTestMotionParameters3D); GDREGISTER_CLASS(PhysicsTestMotionResult3D); - GDREGISTER_VIRTUAL_CLASS(MovieWriter); - - ServersDebugger::initialize(); - - // Physics 2D - GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer2DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT"); - - PhysicsServer2DManager::get_singleton()->register_server("GodotPhysics2D", callable_mp_static(_createGodotPhysics2DCallback)); - PhysicsServer2DManager::get_singleton()->set_default_server("GodotPhysics2D"); - - // Physics 3D GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer3DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT"); PhysicsServer3DManager::get_singleton()->register_server("GodotPhysics3D", callable_mp_static(_createGodotPhysics3DCallback)); PhysicsServer3DManager::get_singleton()->set_default_server("GodotPhysics3D"); +#endif // _3D_DISABLED writer_mjpeg = memnew(MovieWriterMJPEG); MovieWriter::add_writer(writer_mjpeg);