1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Move Godot Physics 2D into a module; add dummy 2D physics server

If the module is enabled (default), 2D physics works as it did before.

If the module is disabled and no other 2D physics server is registered
(via a module or GDExtension), then we fall back to a dummy
implementation which effectively disables 2D physics functionality (and
a warning is printed).

The dummy 2D physics server can also be selected explicitly, in which
case no warning is printed.
This commit is contained in:
Ricardo Buring
2024-08-07 21:15:17 +02:00
parent 4254946de9
commit 7c4c4b9987
47 changed files with 497 additions and 29 deletions

View File

@@ -80,6 +80,7 @@
#include "servers/navigation_server_2d.h"
#include "servers/navigation_server_2d_dummy.h"
#include "servers/physics_server_2d.h"
#include "servers/physics_server_2d_dummy.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
@@ -340,7 +341,15 @@ void initialize_physics() {
// Physics server not found, Use the default physics
physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server();
}
ERR_FAIL_NULL(physics_server_2d);
// Fall back to dummy if no default server has been registered.
if (!physics_server_2d) {
WARN_PRINT(vformat("Falling back to dummy PhysicsServer2D; 2D physics functionality will be disabled. If this is intended, set the %s project setting to Dummy.", PhysicsServer2DManager::setting_property_name));
physics_server_2d = memnew(PhysicsServer2DDummy);
}
// Should be impossible, but make sure it's not null.
ERR_FAIL_NULL_MSG(physics_server_2d, "Failed to initialize PhysicsServer2D.");
physics_server_2d->init();
}