[Physics] Fix export with 3D disabled

This commit is contained in:
A Thousand Ships 2024-02-22 15:14:29 +01:00
parent 9c626b6236
commit f06222e487
No known key found for this signature in database
GPG Key ID: 2033189A662F8BD7
4 changed files with 44 additions and 0 deletions

View File

@ -74,7 +74,9 @@
#include "servers/navigation_server_3d.h" #include "servers/navigation_server_3d.h"
#include "servers/navigation_server_3d_dummy.h" #include "servers/navigation_server_3d_dummy.h"
#include "servers/physics_server_2d.h" #include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h" #include "servers/physics_server_3d.h"
#endif // _3D_DISABLED
#include "servers/register_server_types.h" #include "servers/register_server_types.h"
#include "servers/rendering/rendering_server_default.h" #include "servers/rendering/rendering_server_default.h"
#include "servers/text/text_server_dummy.h" #include "servers/text/text_server_dummy.h"
@ -144,8 +146,10 @@ static RenderingServer *rendering_server = nullptr;
static CameraServer *camera_server = nullptr; static CameraServer *camera_server = nullptr;
static XRServer *xr_server = nullptr; static XRServer *xr_server = nullptr;
static TextServerManager *tsman = nullptr; static TextServerManager *tsman = nullptr;
#ifndef _3D_DISABLED
static PhysicsServer3DManager *physics_server_3d_manager = nullptr; static PhysicsServer3DManager *physics_server_3d_manager = nullptr;
static PhysicsServer3D *physics_server_3d = nullptr; static PhysicsServer3D *physics_server_3d = nullptr;
#endif // _3D_DISABLED
static PhysicsServer2DManager *physics_server_2d_manager = nullptr; static PhysicsServer2DManager *physics_server_2d_manager = nullptr;
static PhysicsServer2D *physics_server_2d = nullptr; static PhysicsServer2D *physics_server_2d = nullptr;
static NavigationServer3D *navigation_server_3d = nullptr; static NavigationServer3D *navigation_server_3d = nullptr;
@ -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. // FIXME: Could maybe be moved to have less code in main.cpp.
void initialize_physics() { void initialize_physics() {
#ifndef _3D_DISABLED
/// 3D Physics Server /// 3D Physics Server
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_server( physics_server_3d = PhysicsServer3DManager::get_singleton()->new_server(
GLOBAL_GET(PhysicsServer3DManager::setting_property_name)); GLOBAL_GET(PhysicsServer3DManager::setting_property_name));
@ -302,6 +307,7 @@ void initialize_physics() {
} }
ERR_FAIL_NULL(physics_server_3d); ERR_FAIL_NULL(physics_server_3d);
physics_server_3d->init(); physics_server_3d->init();
#endif // _3D_DISABLED
// 2D Physics server // 2D Physics server
physics_server_2d = PhysicsServer2DManager::get_singleton()->new_server( physics_server_2d = PhysicsServer2DManager::get_singleton()->new_server(
@ -315,8 +321,10 @@ void initialize_physics() {
} }
void finalize_physics() { void finalize_physics() {
#ifndef _3D_DISABLED
physics_server_3d->finish(); physics_server_3d->finish();
memdelete(physics_server_3d); memdelete(physics_server_3d);
#endif // _3D_DISABLED
physics_server_2d->finish(); physics_server_2d->finish();
memdelete(physics_server_2d); memdelete(physics_server_2d);
@ -655,7 +663,9 @@ Error Main::test_setup() {
tsman->add_interface(ts); tsman->add_interface(ts);
} }
#ifndef _3D_DISABLED
physics_server_3d_manager = memnew(PhysicsServer3DManager); physics_server_3d_manager = memnew(PhysicsServer3DManager);
#endif // _3D_DISABLED
physics_server_2d_manager = memnew(PhysicsServer2DManager); physics_server_2d_manager = memnew(PhysicsServer2DManager);
// From `Main::setup2()`. // From `Main::setup2()`.
@ -783,9 +793,11 @@ void Main::test_cleanup() {
if (tsman) { if (tsman) {
memdelete(tsman); memdelete(tsman);
} }
#ifndef _3D_DISABLED
if (physics_server_3d_manager) { if (physics_server_3d_manager) {
memdelete(physics_server_3d_manager); memdelete(physics_server_3d_manager);
} }
#endif // _3D_DISABLED
if (physics_server_2d_manager) { if (physics_server_2d_manager) {
memdelete(physics_server_2d_manager); memdelete(physics_server_2d_manager);
} }
@ -2561,7 +2573,9 @@ Error Main::setup2() {
tsman->add_interface(ts); tsman->add_interface(ts);
} }
#ifndef _3D_DISABLED
physics_server_3d_manager = memnew(PhysicsServer3DManager); physics_server_3d_manager = memnew(PhysicsServer3DManager);
#endif // _3D_DISABLED
physics_server_2d_manager = memnew(PhysicsServer2DManager); physics_server_2d_manager = memnew(PhysicsServer2DManager);
register_server_types(); register_server_types();
@ -3925,14 +3939,18 @@ bool Main::iteration() {
uint64_t physics_begin = OS::get_singleton()->get_ticks_usec(); uint64_t physics_begin = OS::get_singleton()->get_ticks_usec();
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->sync(); PhysicsServer3D::get_singleton()->sync();
PhysicsServer3D::get_singleton()->flush_queries(); PhysicsServer3D::get_singleton()->flush_queries();
#endif // _3D_DISABLED
PhysicsServer2D::get_singleton()->sync(); PhysicsServer2D::get_singleton()->sync();
PhysicsServer2D::get_singleton()->flush_queries(); PhysicsServer2D::get_singleton()->flush_queries();
if (OS::get_singleton()->get_main_loop()->physics_process(physics_step * time_scale)) { if (OS::get_singleton()->get_main_loop()->physics_process(physics_step * time_scale)) {
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->end_sync(); PhysicsServer3D::get_singleton()->end_sync();
#endif // _3D_DISABLED
PhysicsServer2D::get_singleton()->end_sync(); PhysicsServer2D::get_singleton()->end_sync();
exit = true; exit = true;
@ -3948,8 +3966,10 @@ bool Main::iteration() {
message_queue->flush(); message_queue->flush();
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->end_sync(); PhysicsServer3D::get_singleton()->end_sync();
PhysicsServer3D::get_singleton()->step(physics_step * time_scale); PhysicsServer3D::get_singleton()->step(physics_step * time_scale);
#endif // _3D_DISABLED
PhysicsServer2D::get_singleton()->end_sync(); PhysicsServer2D::get_singleton()->end_sync();
PhysicsServer2D::get_singleton()->step(physics_step * time_scale); PhysicsServer2D::get_singleton()->step(physics_step * time_scale);
@ -4194,9 +4214,11 @@ void Main::cleanup(bool p_force) {
if (tsman) { if (tsman) {
memdelete(tsman); memdelete(tsman);
} }
#ifndef _3D_DISABLED
if (physics_server_3d_manager) { if (physics_server_3d_manager) {
memdelete(physics_server_3d_manager); memdelete(physics_server_3d_manager);
} }
#endif // _3D_DISABLED
if (physics_server_2d_manager) { if (physics_server_2d_manager) {
memdelete(physics_server_2d_manager); memdelete(physics_server_2d_manager);
} }

View File

@ -180,12 +180,22 @@ double Performance::get_monitor(Monitor p_monitor) const {
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS); return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS);
case PHYSICS_2D_ISLAND_COUNT: case PHYSICS_2D_ISLAND_COUNT:
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_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: case PHYSICS_3D_ACTIVE_OBJECTS:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS); return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS);
case PHYSICS_3D_COLLISION_PAIRS: case PHYSICS_3D_COLLISION_PAIRS:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS); return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS);
case PHYSICS_3D_ISLAND_COUNT: case PHYSICS_3D_ISLAND_COUNT:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ISLAND_COUNT); return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ISLAND_COUNT);
#endif // _3D_DISABLED
case AUDIO_OUTPUT_LATENCY: case AUDIO_OUTPUT_LATENCY:
return AudioServer::get_singleton()->get_output_latency(); return AudioServer::get_singleton()->get_output_latency();
case NAVIGATION_ACTIVE_MAPS: case NAVIGATION_ACTIVE_MAPS:

View File

@ -60,7 +60,9 @@
#include "servers/display_server.h" #include "servers/display_server.h"
#include "servers/navigation_server_3d.h" #include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h" #include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h" #include "servers/physics_server_3d.h"
#endif // _3D_DISABLED
#include "window.h" #include "window.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -884,7 +886,9 @@ void SceneTree::set_pause(bool p_enabled) {
return; return;
} }
paused = p_enabled; paused = p_enabled;
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->set_active(!p_enabled); PhysicsServer3D::get_singleton()->set_active(!p_enabled);
#endif // _3D_DISABLED
PhysicsServer2D::get_singleton()->set_active(!p_enabled); PhysicsServer2D::get_singleton()->set_active(!p_enabled);
if (get_root()) { if (get_root()) {
get_root()->_propagate_pause_notification(p_enabled); get_root()->_propagate_pause_notification(p_enabled);

View File

@ -144,7 +144,9 @@
#include "servers/navigation_server_2d.h" #include "servers/navigation_server_2d.h"
#include "servers/navigation_server_3d.h" #include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h" #include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h" #include "servers/physics_server_3d.h"
#endif // _3D_DISABLED
#include "servers/rendering/rendering_server_default.h" #include "servers/rendering/rendering_server_default.h"
int test_main(int argc, char *argv[]) { int test_main(int argc, char *argv[]) {
@ -219,7 +221,9 @@ struct GodotTestCaseListener : public doctest::IReporter {
SignalWatcher *signal_watcher = nullptr; SignalWatcher *signal_watcher = nullptr;
#ifndef _3D_DISABLED
PhysicsServer3D *physics_server_3d = nullptr; PhysicsServer3D *physics_server_3d = nullptr;
#endif // _3D_DISABLED
PhysicsServer2D *physics_server_2d = nullptr; PhysicsServer2D *physics_server_2d = nullptr;
NavigationServer3D *navigation_server_3d = nullptr; NavigationServer3D *navigation_server_3d = nullptr;
NavigationServer2D *navigation_server_2d = nullptr; NavigationServer2D *navigation_server_2d = nullptr;
@ -254,8 +258,10 @@ struct GodotTestCaseListener : public doctest::IReporter {
ThemeDB::get_singleton()->finalize_theme(); ThemeDB::get_singleton()->finalize_theme();
ThemeDB::get_singleton()->initialize_theme_noproject(); ThemeDB::get_singleton()->initialize_theme_noproject();
#ifndef _3D_DISABLED
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server(); physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();
physics_server_3d->init(); physics_server_3d->init();
#endif // _3D_DISABLED
physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server(); physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server();
physics_server_2d->init(); physics_server_2d->init();
@ -334,11 +340,13 @@ struct GodotTestCaseListener : public doctest::IReporter {
navigation_server_2d = nullptr; navigation_server_2d = nullptr;
} }
#ifndef _3D_DISABLED
if (physics_server_3d) { if (physics_server_3d) {
physics_server_3d->finish(); physics_server_3d->finish();
memdelete(physics_server_3d); memdelete(physics_server_3d);
physics_server_3d = nullptr; physics_server_3d = nullptr;
} }
#endif // _3D_DISABLED
if (physics_server_2d) { if (physics_server_2d) {
physics_server_2d->finish(); physics_server_2d->finish();