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 3D into a module; add dummy 3D physics server #95252

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

rburing
Copy link
Member

@rburing rburing commented Aug 7, 2024

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

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

To try it, compile with the SCons option module_godot_physics_3d_enabled=no.

This is useful for games that want to use a different 3D 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 3D): 70.516 MiB (73941216 bytes)
  • After (with only dummy 3D physics server): 69.603 MiB (72983072 bytes), nice.

So the binary size of the Godot Physics 3D module is 935.688 KiB (958144 bytes).

@Calinou
Copy link
Member

Calinou commented Aug 7, 2024

Is this module already automatically disabled with the disable_3d=yes SCons option?

@rburing rburing force-pushed the 3d_physics_module branch 2 times, most recently from 4a992f6 to 3821d80 Compare August 7, 2024 16:58
@rburing
Copy link
Member Author

rburing commented Aug 7, 2024

@Calinou Thanks for the suggestion, the disable_3d option is taken into account now, and some #ifndefs that were made redundant were removed.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected.

When compiling the editor with module_godot_physics_3d_enabled=no, the project settings dialog is correctly updated to remove the mention of the GodotPhysics server:

image

All 3D demo projects run when no physics server is enabled (with correct visuals), although you can't move, which is expected.

Some remarks (which also apply to the 2D counterpart of this PR, I assume):

  • A warning is also printed on startup of an empty project with just a Node, both in the editor stdout (not visible in the Output panel as it's too early) and in the running project:
WARNING: No PhysicsServer3D implementation was found; 3D physics functionality will be disabled.
     at: initialize_physics (main/main.cpp:326)
  • There should probably be a Dummy option you can select in the project settings for two reasons:
    • Silence the warning when you don't compile any physics engines. This is useful when compiling a binary with no physics engines to reduce the binary size of non-game applications, or games that write their own physics without using PhysicsServer.
    • Simulate what happens when physics are disabled at build-time, without needing to compile a separate binary.

@rburing rburing force-pushed the 3d_physics_module branch from 0979158 to 561a199 Compare August 8, 2024 09:13
@rburing rburing requested a review from a team as a code owner August 8, 2024 09:13
@rburing
Copy link
Member Author

rburing commented Aug 8, 2024

Great idea @Calinou. I added the option, and now a warning only appears when the dummy server is used as a fallback:

WARNING: Falling back to dummy PhysicsServer3D; 3D physics functionality will be disabled. If this is intended, set the physics/3d/physics_engine project setting to Dummy.

When the Dummy setting is chosen explicitly, there is no warning.

The fallback warning is still not printed in the editor Output panel when the editor starts, but I guess that's fine.

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Sep 17, 2024
@akien-mga
Copy link
Member

akien-mga commented Sep 17, 2024

Tested a build of a web template_release template, with the module:

-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

Without:

-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

So a 1.47% size reduction on the wasm (487 KiB), and 1.88% on the zip (148 KiB).

Tested with scons p=web target=template_release module_godot_physics_3d_enabled=yes|no

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

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

The dummy 3D physics server can also be selected explicitly, in which
case no warning is printed.
@akien-mga akien-mga merged commit dd71bc2 into godotengine:master Sep 23, 2024
19 checks passed
@akien-mga
Copy link
Member

Thanks!

@rburing rburing deleted the 3d_physics_module branch September 23, 2024 11:15
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.

4 participants