godot
godot copied to clipboard
Move Godot Physics 2D into a module; add dummy 2D physics server
- Production edit: 2D counterpart of https://github.com/godotengine/godot/pull/95252.
If the module is enabled (default), 2D physics works as it did before this PR.
If the module is disabled and no other 2D physics server is registered (via a module or GDExtension), then Godot falls back to a dummy implementation which effectively disables 2D physics functionality (and a warning is printed).
To try it, compile with the SCons option module_godot_physics_2d_enabled=no.
This is useful for games that want to use a different 2D physics server, especially in web builds where binary size matters.
Linux binary size comparison (scons target=template_release production=yes use_llvm=yes linker=lld):
- Before (with Godot Physics 2D): 70.512 MiB (73936320 bytes)
- After (with only dummy 2D physics server): 68.821 MiB (72163512 bytes).
So the binary size of the Godot Physics 2D module is 1.691 MiB (1772680 bytes), nice.
What's the best way to disable 2D physics tests when the physics server is the dummy physics server?
What's the best way to disable 2D physics tests when the physics server is the dummy physics server?
I guess you could test something from PhysicsServer2DManager to check if the active/only registered server is the Dummy one?
Or register a bool somewhere in the initialize_physics code that falls back to Dummy to check directly.
What's the best way to disable 2D physics tests when the physics server is the dummy physics server?
E.g. navigation checks in test_main.cpp if the navigation module is enabled and if not the entire navigation tests are excluded from the build.
@smix8 I think we shouldn't rely on a define like MODULE_GODOT_PHYSICS_2D_ENABLED, because another module may provide a non-dummy physics server. This is maybe not so relevant right now, but it will be relevant in 3D.
For now I hacked around it with an early return from the test. Ideally I would skip the test instead, but I didn't find a way to do it properly within the doctest framework (which I am not really familiar with).
What's the best way to disable 2D physics tests when the physics server is the dummy physics server?
TextServer tests are checking server feature flags to skip tests (dummy ts have none set), it's also running tests on all available implementations (usually only one is active, but there's *ServerManager to register them):
https://github.com/godotengine/godot/blob/03afb92efa18874da19f7fc185a32c005d20aa1d/tests/servers/test_text_server.h#L45-L51
Continuing my test on top of https://github.com/godotengine/godot/pull/95252#issuecomment-2356272247 (merged both PRs locally) on a web template_release template:
Default config (both 2D and 3D physics enabled):
-rwxr-xr-x. 1 akien akien 33838516 Sep 17 17:35 godot.web.template_release.wasm32.wasm
-rw-r--r--. 1 akien akien 8040612 Sep 17 17:35 godot.web.template_release.wasm32.zip
With the 3D physics module disabled:
-rwxr-xr-x. 1 akien akien 33339961 Sep 17 17:31 godot.web.template_release.wasm32.wasm
-rw-r--r--. 1 akien akien 7889273 Sep 17 17:31 godot.web.template_release.wasm32.zip
With both the 3D and 2D physics modules disabled:
-rwxr-xr-x. 1 akien akien 31870984 Sep 17 19:10 godot.web.template_release.wasm32.wasm
-rw-r--r--. 1 akien akien 7675088 Sep 17 19:10 godot.web.template_release.wasm32.zip
So removing the 2D physics reduces the wasm size by 4.4% (1.4 MiB) and the zip size by 2.7% (209 KiB).
Also for the lulz, my minimal template with all engine functionality disabled (at least all functionality that can be disabled currently):
-rwxr-xr-x. 1 akien akien 11374999 Sep 17 19:43 godot.web.template_release.wasm32.wasm
-rw-r--r--. 1 akien akien 2583545 Sep 17 19:43 godot.web.template_release.wasm32.zip
Now to find what I would need to re-enable to be able to export an actual small game :D
Thanks!