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

[Physics] Fix exporting with 3D disabled #88668

Merged
merged 1 commit into from
Feb 22, 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
22 changes: 22 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
#include "servers/navigation_server_3d.h"
#include "servers/navigation_server_3d_dummy.h"
#include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#endif // _3D_DISABLED
#include "servers/register_server_types.h"
#include "servers/rendering/rendering_server_default.h"
#include "servers/text/text_server_dummy.h"
Expand Down Expand Up @@ -144,8 +146,10 @@ static RenderingServer *rendering_server = nullptr;
static CameraServer *camera_server = nullptr;
static XRServer *xr_server = nullptr;
static TextServerManager *tsman = nullptr;
#ifndef _3D_DISABLED
static PhysicsServer3DManager *physics_server_3d_manager = nullptr;
static PhysicsServer3D *physics_server_3d = nullptr;
#endif // _3D_DISABLED
static PhysicsServer2DManager *physics_server_2d_manager = nullptr;
static PhysicsServer2D *physics_server_2d = nullptr;
static NavigationServer3D *navigation_server_3d = nullptr;
Expand Down Expand Up @@ -293,6 +297,7 @@ static Vector<String> get_files_with_extension(const String &p_root, const Strin

// FIXME: Could maybe be moved to have less code in main.cpp.
void initialize_physics() {
#ifndef _3D_DISABLED
/// 3D Physics Server
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_server(
GLOBAL_GET(PhysicsServer3DManager::setting_property_name));
Expand All @@ -302,6 +307,7 @@ void initialize_physics() {
}
ERR_FAIL_NULL(physics_server_3d);
physics_server_3d->init();
#endif // _3D_DISABLED

// 2D Physics server
physics_server_2d = PhysicsServer2DManager::get_singleton()->new_server(
Expand All @@ -315,8 +321,10 @@ void initialize_physics() {
}

void finalize_physics() {
#ifndef _3D_DISABLED
physics_server_3d->finish();
memdelete(physics_server_3d);
#endif // _3D_DISABLED

physics_server_2d->finish();
memdelete(physics_server_2d);
Expand Down Expand Up @@ -655,7 +663,9 @@ Error Main::test_setup() {
tsman->add_interface(ts);
}

#ifndef _3D_DISABLED
physics_server_3d_manager = memnew(PhysicsServer3DManager);
#endif // _3D_DISABLED
physics_server_2d_manager = memnew(PhysicsServer2DManager);

// From `Main::setup2()`.
Expand Down Expand Up @@ -783,9 +793,11 @@ void Main::test_cleanup() {
if (tsman) {
memdelete(tsman);
}
#ifndef _3D_DISABLED
if (physics_server_3d_manager) {
memdelete(physics_server_3d_manager);
}
#endif // _3D_DISABLED
if (physics_server_2d_manager) {
memdelete(physics_server_2d_manager);
}
Expand Down Expand Up @@ -2561,7 +2573,9 @@ Error Main::setup2() {
tsman->add_interface(ts);
}

#ifndef _3D_DISABLED
physics_server_3d_manager = memnew(PhysicsServer3DManager);
#endif // _3D_DISABLED
physics_server_2d_manager = memnew(PhysicsServer2DManager);

register_server_types();
Expand Down Expand Up @@ -3925,14 +3939,18 @@ bool Main::iteration() {

uint64_t physics_begin = OS::get_singleton()->get_ticks_usec();

#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->sync();
PhysicsServer3D::get_singleton()->flush_queries();
#endif // _3D_DISABLED

PhysicsServer2D::get_singleton()->sync();
PhysicsServer2D::get_singleton()->flush_queries();

if (OS::get_singleton()->get_main_loop()->physics_process(physics_step * time_scale)) {
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->end_sync();
#endif // _3D_DISABLED
PhysicsServer2D::get_singleton()->end_sync();

exit = true;
Expand All @@ -3948,8 +3966,10 @@ bool Main::iteration() {

message_queue->flush();

#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->end_sync();
PhysicsServer3D::get_singleton()->step(physics_step * time_scale);
#endif // _3D_DISABLED

PhysicsServer2D::get_singleton()->end_sync();
PhysicsServer2D::get_singleton()->step(physics_step * time_scale);
Expand Down Expand Up @@ -4194,9 +4214,11 @@ void Main::cleanup(bool p_force) {
if (tsman) {
memdelete(tsman);
}
#ifndef _3D_DISABLED
if (physics_server_3d_manager) {
memdelete(physics_server_3d_manager);
}
#endif // _3D_DISABLED
if (physics_server_2d_manager) {
memdelete(physics_server_2d_manager);
}
Expand Down
10 changes: 10 additions & 0 deletions main/performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,22 @@ double Performance::get_monitor(Monitor p_monitor) const {
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS);
case PHYSICS_2D_ISLAND_COUNT:
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ISLAND_COUNT);
#ifdef _3D_DISABLED
case PHYSICS_3D_ACTIVE_OBJECTS:
return 0;
case PHYSICS_3D_COLLISION_PAIRS:
return 0;
case PHYSICS_3D_ISLAND_COUNT:
return 0;
#else
case PHYSICS_3D_ACTIVE_OBJECTS:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS);
case PHYSICS_3D_COLLISION_PAIRS:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS);
case PHYSICS_3D_ISLAND_COUNT:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ISLAND_COUNT);
#endif // _3D_DISABLED

case AUDIO_OUTPUT_LATENCY:
return AudioServer::get_singleton()->get_output_latency();
case NAVIGATION_ACTIVE_MAPS:
Expand Down
4 changes: 4 additions & 0 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
#include "servers/display_server.h"
#include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#endif // _3D_DISABLED
#include "window.h"
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -884,7 +886,9 @@ void SceneTree::set_pause(bool p_enabled) {
return;
}
paused = p_enabled;
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->set_active(!p_enabled);
#endif // _3D_DISABLED
PhysicsServer2D::get_singleton()->set_active(!p_enabled);
if (get_root()) {
get_root()->_propagate_pause_notification(p_enabled);
Expand Down
8 changes: 8 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@
#include "servers/navigation_server_2d.h"
#include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#endif // _3D_DISABLED
#include "servers/rendering/rendering_server_default.h"

int test_main(int argc, char *argv[]) {
Expand Down Expand Up @@ -219,7 +221,9 @@ struct GodotTestCaseListener : public doctest::IReporter {

SignalWatcher *signal_watcher = nullptr;

#ifndef _3D_DISABLED
PhysicsServer3D *physics_server_3d = nullptr;
#endif // _3D_DISABLED
PhysicsServer2D *physics_server_2d = nullptr;
NavigationServer3D *navigation_server_3d = nullptr;
NavigationServer2D *navigation_server_2d = nullptr;
Expand Down Expand Up @@ -254,8 +258,10 @@ struct GodotTestCaseListener : public doctest::IReporter {
ThemeDB::get_singleton()->finalize_theme();
ThemeDB::get_singleton()->initialize_theme_noproject();

#ifndef _3D_DISABLED
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();
physics_server_3d->init();
#endif // _3D_DISABLED

physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server();
physics_server_2d->init();
Expand Down Expand Up @@ -334,11 +340,13 @@ struct GodotTestCaseListener : public doctest::IReporter {
navigation_server_2d = nullptr;
}

#ifndef _3D_DISABLED
if (physics_server_3d) {
physics_server_3d->finish();
memdelete(physics_server_3d);
physics_server_3d = nullptr;
}
#endif // _3D_DISABLED

if (physics_server_2d) {
physics_server_2d->finish();
Expand Down
Loading