Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

rburing
Copy link
Member

@rburing rburing commented Aug 7, 2024

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.

@rburing
Copy link
Member Author

rburing commented Aug 7, 2024

What's the best way to disable 2D physics tests when the physics server is the dummy physics server?

COPYRIGHT.txt Outdated Show resolved Hide resolved
main/main.cpp Outdated Show resolved Hide resolved
modules/godot_physics_2d/register_types.h Outdated Show resolved Hide resolved
@akien-mga
Copy link
Member

akien-mga commented Aug 7, 2024

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.

@rburing rburing force-pushed the 2d_physics_module branch from 1842267 to 34c250e Compare August 7, 2024 21:22
@smix8
Copy link
Contributor

smix8 commented Aug 7, 2024

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.

@rburing rburing force-pushed the 2d_physics_module branch from 34c250e to 28298cd Compare August 7, 2024 21:35
@rburing
Copy link
Member Author

rburing commented Aug 7, 2024

@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).

@rburing rburing force-pushed the 2d_physics_module branch from 28298cd to 29851a7 Compare August 8, 2024 09:29
@rburing rburing requested a review from a team as a code owner August 8, 2024 09:29
@bruvzg
Copy link
Member

bruvzg commented Aug 8, 2024

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):

for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i);
CHECK_FALSE_MESSAGE(ts.is_null(), "Invalid TS interface.");
if (!ts->has_feature(TextServer::FEATURE_FONT_DYNAMIC)) {
continue;
}

@akien-mga
Copy link
Member

akien-mga commented Sep 17, 2024

Continuing my test on top of #95252 (comment) (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

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Sep 17, 2024
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.
@akien-mga akien-mga merged commit 39115be into godotengine:master Sep 24, 2024
19 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants