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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ Copyright: 2011, Ole Kniemeyer, MAXON, www.maxon.net
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib

Files: ./modules/godot_physics_3d/gjk_epa.cpp
./modules/godot_physics_3d/joints/godot_generic_6dof_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_generic_6dof_joint_3d.h
./modules/godot_physics_3d/joints/godot_hinge_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_hinge_joint_3d_sw.h
./modules/godot_physics_3d/joints/godot_jacobian_entry_3d_sw.h
./modules/godot_physics_3d/joints/godot_pin_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_pin_joint_3d.h
./modules/godot_physics_3d/joints/godot_slider_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_slider_joint_3d.h
./modules/godot_physics_3d/godot_soft_body_3d.cpp
./modules/godot_physics_3d/godot_soft_body_3d.h
./modules/godot_physics_3d/godot_shape_3d.cpp
./modules/godot_physics_3d/godot_shape_3d.h
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2003-2008, Erwin Coumans
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib

Files: ./modules/godot_physics_3d/godot_collision_solver_3d_sat.cpp
Comment: Open Dynamics Engine
Copyright: 2001-2003, Russell L. Smith, Alen Ladavac, Nguyen Binh
License: BSD-3-clause

Files: ./modules/godot_physics_3d/joints/godot_cone_twist_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_cone_twist_joint_3d.h
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2007, Starbreeze Studios
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib

Files: ./modules/lightmapper_rd/lm_compute.glsl
Comment: Joint Non-Local Means (JNLM) denoiser
Copyright: 2020, Manuel Prandini
Expand Down Expand Up @@ -98,39 +131,6 @@ Comment: Chipmunk2D Joint Constraints
Copyright: 2007, Scott Lembcke
License: Expat

Files: ./servers/physics_3d/collision_solver_3d_sat.cpp
Comment: Open Dynamics Engine
Copyright: 2001-2003, Russell L. Smith, Alen Ladavac, Nguyen Binh
License: BSD-3-clause

Files: ./servers/physics_3d/gjk_epa.cpp
./servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp
./servers/physics_3d/joints/generic_6dof_joint_3d_sw.h
./servers/physics_3d/joints/hinge_joint_3d_sw.cpp
./servers/physics_3d/joints/hinge_joint_3d_sw.h
./servers/physics_3d/joints/jacobian_entry_3d_sw.h
./servers/physics_3d/joints/pin_joint_3d_sw.cpp
./servers/physics_3d/joints/pin_joint_3d_sw.h
./servers/physics_3d/joints/slider_joint_3d_sw.cpp
./servers/physics_3d/joints/slider_joint_3d_sw.h
./servers/physics_3d/soft_body_3d_sw.cpp
./servers/physics_3d/soft_body_3d_sw.h
./servers/physics_3d/shape_3d_sw.cpp
./servers/physics_3d/shape_3d_sw.h
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2003-2008, Erwin Coumans
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib

Files: ./servers/physics_3d/joints/cone_twist_joint_3d_sw.cpp
./servers/physics_3d/joints/cone_twist_joint_3d_sw.h
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2007, Starbreeze Studios
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib

Files: ./servers/rendering/renderer_rd/shaders/ss_effects_downsample.glsl
./servers/rendering/renderer_rd/shaders/ssao_blur.glsl
./servers/rendering/renderer_rd/shaders/ssao_importance_map.glsl
Expand Down
1 change: 1 addition & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,7 @@
<member name="physics/3d/physics_engine" type="String" setter="" getter="" default="&quot;DEFAULT&quot;">
Sets which physics engine to use for 3D physics.
"DEFAULT" and "GodotPhysics3D" are the same, as there is currently no alternative 3D physics server implemented.
"Dummy" is a 3D physics server that does nothing and returns only dummy values, effectively disabling all 3D physics functionality.
</member>
<member name="physics/3d/run_on_separate_thread" type="bool" setter="" getter="" default="false">
If [code]true[/code], the 3D physics server runs on a separate thread, making better use of multi-core CPUs. If [code]false[/code], the 3D physics server runs on the main thread. Running the physics server on a separate thread can increase performance, but restricts API access to only physics process.
Expand Down
11 changes: 10 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#include "servers/physics_server_3d_dummy.h"
#include "servers/xr_server.h"
#endif // _3D_DISABLED

Expand Down Expand Up @@ -320,7 +321,15 @@ void initialize_physics() {
// Physics server not found, Use the default physics
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();
}
ERR_FAIL_NULL(physics_server_3d);

// Fall back to dummy if no default server has been registered.
if (!physics_server_3d) {
WARN_PRINT(vformat("Falling back to dummy PhysicsServer3D; 3D physics functionality will be disabled. If this is intended, set the %s project setting to Dummy.", PhysicsServer3DManager::setting_property_name));
physics_server_3d = memnew(PhysicsServer3DDummy);
}

// Should be impossible, but make sure it's not null.
ERR_FAIL_NULL_MSG(physics_server_3d, "Failed to initialize PhysicsServer3D.");
physics_server_3d->init();
#endif // _3D_DISABLED

Expand Down
7 changes: 7 additions & 0 deletions modules/godot_physics_3d/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python

Import('env')

env.add_source_files(env.modules_sources, "*.cpp")

SConscript("joints/SCsub")
6 changes: 6 additions & 0 deletions modules/godot_physics_3d/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def can_build(env, platform):
return not env["disable_3d"]


def configure(env):
pass
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1629,8 +1629,6 @@ void GodotPhysicsServer3D::init() {
}

void GodotPhysicsServer3D::step(real_t p_step) {
#ifndef _3D_DISABLED

if (!active) {
return;
}
Expand All @@ -1646,16 +1644,13 @@ void GodotPhysicsServer3D::step(real_t p_step) {
active_objects += E->get_active_objects();
collision_pairs += E->get_collision_pairs();
}
#endif
}

void GodotPhysicsServer3D::sync() {
doing_sync = true;
}

void GodotPhysicsServer3D::flush_queries() {
#ifndef _3D_DISABLED

if (!active) {
return;
}
Expand Down Expand Up @@ -1703,7 +1698,6 @@ void GodotPhysicsServer3D::flush_queries() {
values.push_front("physics_3d");
EngineDebugger::profiler_add_frame_data("servers", values);
}
#endif
}

void GodotPhysicsServer3D::end_sync() {
Expand Down
5 changes: 5 additions & 0 deletions modules/godot_physics_3d/joints/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python

Import('env')

env.add_source_files(env.modules_sources, "*.cpp")
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ subject to the following restrictions:
Written by: Marcus Hennix
*/

#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"

// GodotConeTwistJoint3D can be used to simulate ragdoll joints (upper arm, leg etc).
class GodotConeTwistJoint3D : public GodotJoint3D {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
Adapted to Godot from the Bullet library.
*/

#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"

/*
Bullet Continuous Collision Detection and Physics Library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
Adapted to Godot from the Bullet library.
*/

#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"

/*
Bullet Continuous Collision Detection and Physics Library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
Adapted to Godot from the Bullet library.
*/

#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"

/*
Bullet Continuous Collision Detection and Physics Library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
Adapted to Godot from the Bullet library.
*/

#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"

/*
Bullet Continuous Collision Detection and Physics Library
Expand Down
61 changes: 61 additions & 0 deletions modules/godot_physics_3d/register_types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**************************************************************************/
/* register_types.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#include "register_types.h"

#include "godot_physics_server_3d.h"
#include "servers/physics_server_3d.h"
#include "servers/physics_server_3d_wrap_mt.h"

static PhysicsServer3D *_createGodotPhysics3DCallback() {
#ifdef THREADS_ENABLED
bool using_threads = GLOBAL_GET("physics/3d/run_on_separate_thread");
#else
bool using_threads = false;
#endif

PhysicsServer3D *physics_server_3d = memnew(GodotPhysicsServer3D(using_threads));

return memnew(PhysicsServer3DWrapMT(physics_server_3d, using_threads));
}

void initialize_godot_physics_3d_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) {
return;
}
PhysicsServer3DManager::get_singleton()->register_server("GodotPhysics3D", callable_mp_static(_createGodotPhysics3DCallback));
PhysicsServer3DManager::get_singleton()->set_default_server("GodotPhysics3D");
}

void uninitialize_godot_physics_3d_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) {
return;
}
}
39 changes: 39 additions & 0 deletions modules/godot_physics_3d/register_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**************************************************************************/
/* register_types.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_PHYSICS_3D_REGISTER_TYPES_H
#define GODOT_PHYSICS_3D_REGISTER_TYPES_H

#include "modules/register_module_types.h"

void initialize_godot_physics_3d_module(ModuleInitializationLevel p_level);
void uninitialize_godot_physics_3d_module(ModuleInitializationLevel p_level);

#endif // GODOT_PHYSICS_3D_REGISTER_TYPES_H
4 changes: 2 additions & 2 deletions scu_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ def generate_scu_files(max_includes_per_scu):
process_folder(["modules/openxr"], ["register_types"])
process_folder(["modules/openxr/action_map"])
process_folder(["modules/openxr/editor"])
process_folder(["modules/godot_physics_3d"])
process_folder(["modules/godot_physics_3d/joints"])

process_folder(["modules/csg"])
process_folder(["modules/gdscript"])
Expand Down Expand Up @@ -349,8 +351,6 @@ def generate_scu_files(max_includes_per_scu):
process_folder(["servers/rendering/renderer_rd/environment"])
process_folder(["servers/rendering/renderer_rd/storage_rd"])
process_folder(["servers/physics_2d"])
process_folder(["servers/physics_3d"])
process_folder(["servers/physics_3d/joints"])
process_folder(["servers/audio"])
process_folder(["servers/audio/effects"])

Expand Down
1 change: 0 additions & 1 deletion servers/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ SConscript("text/SCsub")
SConscript("physics_2d/SCsub")

if not env["disable_3d"]:
SConscript("physics_3d/SCsub")
env.add_source_files(env.servers_sources, "physics_server_3d.cpp")
env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp")
SConscript("xr/SCsub")
Expand Down
7 changes: 0 additions & 7 deletions servers/physics_3d/SCsub

This file was deleted.

5 changes: 0 additions & 5 deletions servers/physics_3d/joints/SCsub

This file was deleted.

4 changes: 3 additions & 1 deletion servers/physics_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,9 @@ String PhysicsServer3DManager::get_server_name(int p_id) {
}

PhysicsServer3D *PhysicsServer3DManager::new_default_server() {
ERR_FAIL_COND_V(default_server_id == -1, nullptr);
if (default_server_id == -1) {
return nullptr;
}
Variant ret;
Callable::CallError ce;
physics_servers[default_server_id].create_callback.callp(nullptr, 0, ret, ce);
Expand Down
Loading
Loading