Implemented physics plug
Moved init_physics Implemented physics 2D plug Fix clang Fix clang Fix static check Fix clang Fix static check Moved physics server initialization Moved physics server settings initialization
This commit is contained in:
parent
f52ab8d864
commit
7a9ca08f16
|
@ -47,6 +47,8 @@
|
|||
#include "scene/main/scene_tree.h"
|
||||
#include "servers/arvr_server.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics_2d_server.h"
|
||||
#include "servers/physics_server.h"
|
||||
|
||||
#include "io/resource_loader.h"
|
||||
#include "script_language.h"
|
||||
|
@ -84,6 +86,8 @@ static bool _start_success = false;
|
|||
static ScriptDebugger *script_debugger = NULL;
|
||||
AudioServer *audio_server = NULL;
|
||||
ARVRServer *arvr_server = NULL;
|
||||
PhysicsServer *physics_server = NULL;
|
||||
Physics2DServer *physics_2d_server = NULL;
|
||||
|
||||
static MessageQueue *message_queue = NULL;
|
||||
static Performance *performance = NULL;
|
||||
|
@ -120,6 +124,35 @@ static int fixed_fps = -1;
|
|||
|
||||
static OS::ProcessID allow_focus_steal_pid = 0;
|
||||
|
||||
void initialize_physics() {
|
||||
|
||||
/// 3D Physics Server
|
||||
physics_server = PhysicsServerManager::new_server(ProjectSettings::get_singleton()->get(PhysicsServerManager::setting_property_name));
|
||||
if (!physics_server) {
|
||||
// Physics server not found, Use the default physics
|
||||
physics_server = PhysicsServerManager::new_default_server();
|
||||
}
|
||||
ERR_FAIL_COND(!physics_server);
|
||||
physics_server->init();
|
||||
|
||||
/// 2D Physics server
|
||||
physics_2d_server = Physics2DServerManager::new_server(ProjectSettings::get_singleton()->get(Physics2DServerManager::setting_property_name));
|
||||
if (!physics_2d_server) {
|
||||
// Physics server not found, Use the default physics
|
||||
physics_2d_server = Physics2DServerManager::new_default_server();
|
||||
}
|
||||
ERR_FAIL_COND(!physics_2d_server);
|
||||
physics_2d_server->init();
|
||||
}
|
||||
|
||||
void finalize_physics() {
|
||||
physics_server->finish();
|
||||
memdelete(physics_server);
|
||||
|
||||
physics_2d_server->finish();
|
||||
memdelete(physics_2d_server);
|
||||
}
|
||||
|
||||
static String unescape_cmdline(const String &p_str) {
|
||||
|
||||
return p_str.replace("%20", " ");
|
||||
|
@ -1072,9 +1105,13 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
|
|||
OS::get_singleton()->enable_for_stealing_focus(allow_focus_steal_pid);
|
||||
}
|
||||
|
||||
MAIN_PRINT("Main: Load Scripts, Modules, Drivers");
|
||||
MAIN_PRINT("Main: Load Modules, Physics, Drivers, Scripts");
|
||||
|
||||
register_module_types();
|
||||
|
||||
initialize_physics();
|
||||
register_server_singletons();
|
||||
|
||||
register_driver_types();
|
||||
|
||||
ScriptServer::init_languages();
|
||||
|
@ -1791,6 +1828,7 @@ void Main::cleanup() {
|
|||
unregister_server_types();
|
||||
|
||||
OS::get_singleton()->finalize();
|
||||
finalize_physics();
|
||||
|
||||
if (packed_data)
|
||||
memdelete(packed_data);
|
||||
|
|
|
@ -155,11 +155,6 @@ void OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
|
|||
|
||||
AudioDriverManager::initialize(p_audio_driver);
|
||||
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
||||
physics_2d_server->init();
|
||||
|
||||
input = memnew(InputDefault);
|
||||
input->set_fallback_mapping("Default Android Gamepad");
|
||||
|
||||
|
|
|
@ -38,9 +38,6 @@
|
|||
#include "os/main_loop.h"
|
||||
//#include "power_android.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
|
||||
#ifdef ANDROID_NATIVE_ACTIVITY
|
||||
|
@ -106,8 +103,6 @@ private:
|
|||
bool use_16bits_fbo;
|
||||
|
||||
VisualServer *visual_server;
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
|
||||
mutable String data_dir_cache;
|
||||
|
||||
|
|
|
@ -130,13 +130,6 @@ void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_
|
|||
window->Show();
|
||||
visual_server->init();
|
||||
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
physics_2d_server = memnew(Physics2DServerSW);
|
||||
// TODO: enable multithreaded PS
|
||||
//physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
||||
physics_2d_server->init();
|
||||
|
||||
AudioDriverManager::initialize(p_audio_driver);
|
||||
|
||||
power_manager = memnew(PowerHaiku);
|
||||
|
@ -153,12 +146,6 @@ void OS_Haiku::finalize() {
|
|||
memdelete(visual_server);
|
||||
memdelete(rasterizer);
|
||||
|
||||
physics_server->finish();
|
||||
memdelete(physics_server);
|
||||
|
||||
physics_2d_server->finish();
|
||||
memdelete(physics_2d_server);
|
||||
|
||||
memdelete(input);
|
||||
|
||||
#if defined(OPENGL_ENABLED)
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
#include "main/input_default.h"
|
||||
#include "power_haiku.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/physics_server.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
|
@ -52,8 +50,6 @@ private:
|
|||
Rasterizer *rasterizer;
|
||||
VisualServer *visual_server;
|
||||
VideoMode current_video_mode;
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
PowerHaiku *power_manager;
|
||||
|
||||
#ifdef MEDIA_KIT_ENABLED
|
||||
|
|
|
@ -136,13 +136,6 @@ void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_
|
|||
AudioDriverManager::add_driver(&audio_driver);
|
||||
AudioDriverManager::initialize(p_audio_driver);
|
||||
|
||||
// init physics servers
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
//physics_2d_server = memnew( Physics2DServerSW );
|
||||
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
||||
physics_2d_server->init();
|
||||
|
||||
input = memnew(InputDefault);
|
||||
|
||||
/*
|
||||
|
@ -382,12 +375,6 @@ void OSIPhone::finalize() {
|
|||
memdelete(visual_server);
|
||||
// memdelete(rasterizer);
|
||||
|
||||
physics_server->finish();
|
||||
memdelete(physics_server);
|
||||
|
||||
physics_2d_server->finish();
|
||||
memdelete(physics_2d_server);
|
||||
|
||||
memdelete(input);
|
||||
};
|
||||
|
||||
|
|
|
@ -41,9 +41,6 @@
|
|||
#include "in_app_store.h"
|
||||
#include "main/input_default.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
|
@ -66,8 +63,6 @@ private:
|
|||
uint8_t supported_orientations;
|
||||
|
||||
VisualServer *visual_server;
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
|
||||
AudioDriverCoreAudio audio_driver;
|
||||
|
||||
|
|
|
@ -480,11 +480,6 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i
|
|||
|
||||
print_line("Init Physicsserver");
|
||||
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
physics_2d_server = memnew(Physics2DServerSW);
|
||||
physics_2d_server->init();
|
||||
|
||||
input = memnew(InputDefault);
|
||||
_input = input;
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
#include "os/main_loop.h"
|
||||
#include "power_javascript.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
|
@ -54,8 +52,6 @@ class OS_JavaScript : public OS_Unix {
|
|||
int64_t last_sync_time;
|
||||
|
||||
VisualServer *visual_server;
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
AudioDriverJavaScript audio_driver_javascript;
|
||||
const char *gl_extensions;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
/*************************************************************************/
|
||||
#include "main/main.h"
|
||||
#include "os_osx.h"
|
||||
#include "project_settings.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
|
|
@ -38,9 +38,6 @@
|
|||
#include "os/input.h"
|
||||
#include "power_osx.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
|
||||
#include "servers/physics_server.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
#include "servers/visual/visual_server_wrap_mt.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
@ -62,9 +59,6 @@ public:
|
|||
List<String> args;
|
||||
MainLoop *main_loop;
|
||||
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
|
||||
IP_Unix *ip_unix;
|
||||
|
||||
AudioDriverCoreAudio audio_driver;
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "os/keyboard.h"
|
||||
#include "print_string.h"
|
||||
#include "sem_osx.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
|
||||
#include <Carbon/Carbon.h>
|
||||
|
@ -1092,13 +1091,6 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
|
|||
|
||||
AudioDriverManager::initialize(p_audio_driver);
|
||||
|
||||
//
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
//physics_2d_server = memnew( Physics2DServerSW );
|
||||
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
||||
physics_2d_server->init();
|
||||
|
||||
input = memnew(InputDefault);
|
||||
joypad_osx = memnew(JoypadOSX);
|
||||
|
||||
|
@ -1120,12 +1112,6 @@ void OS_OSX::finalize() {
|
|||
visual_server->finish();
|
||||
memdelete(visual_server);
|
||||
//memdelete(rasterizer);
|
||||
|
||||
physics_server->finish();
|
||||
memdelete(physics_server);
|
||||
|
||||
physics_2d_server->finish();
|
||||
memdelete(physics_2d_server);
|
||||
}
|
||||
|
||||
void OS_OSX::set_main_loop(MainLoop *p_main_loop) {
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
//#include "servers/visual/rasterizer_dummy.h"
|
||||
#include "os_server.h"
|
||||
#include "print_string.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -75,11 +74,6 @@ void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p
|
|||
ERR_FAIL_COND(!visual_server);
|
||||
|
||||
visual_server->init();
|
||||
//
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
physics_2d_server = memnew(Physics2DServerSW);
|
||||
physics_2d_server->init();
|
||||
|
||||
input = memnew(InputDefault);
|
||||
|
||||
|
@ -111,12 +105,6 @@ void OS_Server::finalize() {
|
|||
memdelete(visual_server);
|
||||
//memdelete(rasterizer);
|
||||
|
||||
physics_server->finish();
|
||||
memdelete(physics_server);
|
||||
|
||||
physics_2d_server->finish();
|
||||
memdelete(physics_2d_server);
|
||||
|
||||
memdelete(input);
|
||||
|
||||
args.clear();
|
||||
|
|
|
@ -35,8 +35,6 @@
|
|||
#include "drivers/unix/os_unix.h"
|
||||
#include "main/input_default.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/physics_server.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
|
@ -56,9 +54,6 @@ class OS_Server : public OS_Unix {
|
|||
|
||||
bool grab;
|
||||
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
|
||||
virtual void delete_main_loop();
|
||||
IP_Unix *ip_unix;
|
||||
|
||||
|
|
|
@ -262,13 +262,6 @@ void OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_aud
|
|||
}
|
||||
*/
|
||||
|
||||
//
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
|
||||
physics_2d_server = memnew(Physics2DServerSW);
|
||||
physics_2d_server->init();
|
||||
|
||||
visual_server->init();
|
||||
|
||||
input = memnew(InputDefault);
|
||||
|
@ -367,12 +360,6 @@ void OSUWP::finalize() {
|
|||
|
||||
memdelete(input);
|
||||
|
||||
physics_server->finish();
|
||||
memdelete(physics_server);
|
||||
|
||||
physics_2d_server->finish();
|
||||
memdelete(physics_2d_server);
|
||||
|
||||
joypad = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,8 +40,6 @@
|
|||
#include "os/os.h"
|
||||
#include "power_uwp.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
|
@ -94,8 +92,6 @@ private:
|
|||
int old_x, old_y;
|
||||
Point2i center;
|
||||
VisualServer *visual_server;
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
int pressrc;
|
||||
|
||||
ContextEGL *gl_context;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
/*************************************************************************/
|
||||
#include "main/main.h"
|
||||
#include "os_windows.h"
|
||||
#include "project_settings.h"
|
||||
|
||||
#ifdef CRASH_HANDLER_EXCEPTION
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#include "lang_table.h"
|
||||
#include "main/main.h"
|
||||
#include "packet_peer_udp_winsock.h"
|
||||
#include "project_settings.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
#include "servers/visual/visual_server_wrap_mt.h"
|
||||
|
@ -1056,12 +1055,6 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
|
|||
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
|
||||
}
|
||||
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
|
||||
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
||||
physics_2d_server->init();
|
||||
|
||||
if (!is_no_window_mode_enabled()) {
|
||||
ShowWindow(hWnd, SW_SHOW); // Show The Window
|
||||
SetForegroundWindow(hWnd); // Slightly Higher Priority
|
||||
|
@ -1223,12 +1216,6 @@ void OS_Windows::finalize() {
|
|||
memdelete(debugger_connection_console);
|
||||
}
|
||||
*/
|
||||
|
||||
physics_server->finish();
|
||||
memdelete(physics_server);
|
||||
|
||||
physics_2d_server->finish();
|
||||
memdelete(physics_2d_server);
|
||||
}
|
||||
|
||||
void OS_Windows::finalize_core() {
|
||||
|
|
|
@ -29,8 +29,8 @@
|
|||
/*************************************************************************/
|
||||
#ifndef OS_WINDOWS_H
|
||||
#define OS_WINDOWS_H
|
||||
|
||||
#include "context_gl_win.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "crash_handler_win.h"
|
||||
#include "drivers/rtaudio/audio_driver_rtaudio.h"
|
||||
#include "drivers/wasapi/audio_driver_wasapi.h"
|
||||
|
@ -38,7 +38,6 @@
|
|||
#include "os/os.h"
|
||||
#include "power_windows.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
#include "servers/visual_server.h"
|
||||
#ifdef XAUDIO2_ENABLED
|
||||
|
@ -47,8 +46,6 @@
|
|||
#include "drivers/unix/ip_unix.h"
|
||||
#include "key_mapping_win.h"
|
||||
#include "main/input_default.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
|
@ -90,8 +87,6 @@ class OS_Windows : public OS {
|
|||
ContextGL_Win *gl_context;
|
||||
#endif
|
||||
VisualServer *visual_server;
|
||||
PhysicsServer *physics_server;
|
||||
Physics2DServer *physics_2d_server;
|
||||
int pressrc;
|
||||
HDC hDC; // Private GDI Device Context
|
||||
HINSTANCE hInstance; // Holds The Instance Of The Application
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "main/main.h"
|
||||
#include "os_x11.h"
|
||||
#include "project_settings.h"
|
||||
|
||||
#ifdef CRASH_HANDLER_ENABLED
|
||||
#include <cxxabi.h>
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include "errno.h"
|
||||
#include "key_mapping_x11.h"
|
||||
#include "print_string.h"
|
||||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
#include "servers/visual/visual_server_wrap_mt.h"
|
||||
#include <mntent.h>
|
||||
|
@ -458,12 +457,6 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
|
|||
requested = None;
|
||||
|
||||
visual_server->init();
|
||||
//
|
||||
physics_server = memnew(PhysicsServerSW);
|
||||
physics_server->init();
|
||||
//physics_2d_server = memnew( Physics2DServerSW );
|
||||
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
||||
physics_2d_server->init();
|
||||
|
||||
input = memnew(InputDefault);
|
||||
|
||||
|
@ -519,12 +512,6 @@ void OS_X11::finalize() {
|
|||
memdelete(visual_server);
|
||||
//memdelete(rasterizer);
|
||||
|
||||
physics_server->finish();
|
||||
memdelete(physics_server);
|
||||
|
||||
physics_2d_server->finish();
|
||||
memdelete(physics_2d_server);
|
||||
|
||||
memdelete(power_manager);
|
||||
|
||||
if (xrandr_handle)
|
||||
|
|
|
@ -42,9 +42,6 @@
|
|||
#include "main/input_default.h"
|
||||
#include "power_x11.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
|
||||
#include "servers/physics_server.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
|
@ -121,10 +118,8 @@ class OS_X11 : public OS_Unix {
|
|||
uint64_t last_click_ms;
|
||||
uint32_t last_button_state;
|
||||
|
||||
PhysicsServer *physics_server;
|
||||
unsigned int get_mouse_button_state(unsigned int p_x11_state);
|
||||
void get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state);
|
||||
Physics2DServer *physics_2d_server;
|
||||
|
||||
MouseMode mouse_mode;
|
||||
Point2i center;
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "physics_2d_server.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "print_string.h"
|
||||
|
||||
Physics2DServer *Physics2DServer::singleton = NULL;
|
||||
|
||||
void Physics2DDirectBodyState::integrate_forces() {
|
||||
|
@ -691,3 +693,68 @@ Physics2DServer::~Physics2DServer() {
|
|||
|
||||
singleton = NULL;
|
||||
}
|
||||
|
||||
Vector<Physics2DServerManager::ClassInfo> Physics2DServerManager::physics_2d_servers;
|
||||
int Physics2DServerManager::default_server_id = -1;
|
||||
int Physics2DServerManager::default_server_priority = -1;
|
||||
const String Physics2DServerManager::setting_property_name("physics/2d/physics_engine");
|
||||
|
||||
void Physics2DServerManager::on_servers_changed() {
|
||||
|
||||
String physics_servers("DEFAULT");
|
||||
for (int i = get_servers_count() - 1; 0 <= i; --i) {
|
||||
physics_servers += "," + get_server_name(i);
|
||||
}
|
||||
ProjectSettings::get_singleton()->set_custom_property_info(setting_property_name, PropertyInfo(Variant::STRING, setting_property_name, PROPERTY_HINT_ENUM, physics_servers));
|
||||
}
|
||||
|
||||
void Physics2DServerManager::register_server(const String &p_name, CreatePhysics2DServerCallback p_creat_callback) {
|
||||
|
||||
ERR_FAIL_COND(!p_creat_callback);
|
||||
ERR_FAIL_COND(find_server_id(p_name) != -1);
|
||||
physics_2d_servers.push_back(ClassInfo(p_name, p_creat_callback));
|
||||
on_servers_changed();
|
||||
}
|
||||
|
||||
void Physics2DServerManager::set_default_server(const String &p_name, int p_priority) {
|
||||
|
||||
const int id = find_server_id(p_name);
|
||||
ERR_FAIL_COND(id == -1); // Not found
|
||||
if (default_server_priority < p_priority) {
|
||||
default_server_id = id;
|
||||
default_server_priority = p_priority;
|
||||
}
|
||||
}
|
||||
|
||||
int Physics2DServerManager::find_server_id(const String &p_name) {
|
||||
|
||||
for (int i = physics_2d_servers.size() - 1; 0 <= i; --i) {
|
||||
if (p_name == physics_2d_servers[i].name) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Physics2DServerManager::get_servers_count() {
|
||||
return physics_2d_servers.size();
|
||||
}
|
||||
|
||||
String Physics2DServerManager::get_server_name(int p_id) {
|
||||
ERR_FAIL_INDEX_V(p_id, get_servers_count(), "");
|
||||
return physics_2d_servers[p_id].name;
|
||||
}
|
||||
|
||||
Physics2DServer *Physics2DServerManager::new_default_server() {
|
||||
ERR_FAIL_COND_V(default_server_id == -1, NULL);
|
||||
return physics_2d_servers[default_server_id].create_callback();
|
||||
}
|
||||
|
||||
Physics2DServer *Physics2DServerManager::new_server(const String &p_name) {
|
||||
int id = find_server_id(p_name);
|
||||
if (id == -1) {
|
||||
return NULL;
|
||||
} else {
|
||||
return physics_2d_servers[id].create_callback();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -590,6 +590,43 @@ public:
|
|||
Physics2DTestMotionResult();
|
||||
};
|
||||
|
||||
typedef Physics2DServer *(*CreatePhysics2DServerCallback)();
|
||||
|
||||
class Physics2DServerManager {
|
||||
struct ClassInfo {
|
||||
String name;
|
||||
CreatePhysics2DServerCallback create_callback;
|
||||
|
||||
ClassInfo()
|
||||
: name(""), create_callback(NULL) {}
|
||||
|
||||
ClassInfo(String p_name, CreatePhysics2DServerCallback p_create_callback)
|
||||
: name(p_name), create_callback(p_create_callback) {}
|
||||
|
||||
ClassInfo(const ClassInfo &p_ci)
|
||||
: name(p_ci.name), create_callback(p_ci.create_callback) {}
|
||||
};
|
||||
|
||||
static Vector<ClassInfo> physics_2d_servers;
|
||||
static int default_server_id;
|
||||
static int default_server_priority;
|
||||
|
||||
public:
|
||||
static const String setting_property_name;
|
||||
|
||||
private:
|
||||
static void on_servers_changed();
|
||||
|
||||
public:
|
||||
static void register_server(const String &p_name, CreatePhysics2DServerCallback p_creat_callback);
|
||||
static void set_default_server(const String &p_name, int p_priority = 0);
|
||||
static int find_server_id(const String &p_name);
|
||||
static int get_servers_count();
|
||||
static String get_server_name(int p_id);
|
||||
static Physics2DServer *new_default_server();
|
||||
static Physics2DServer *new_server(const String &p_name);
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(Physics2DServer::ShapeType);
|
||||
VARIANT_ENUM_CAST(Physics2DServer::SpaceParameter);
|
||||
VARIANT_ENUM_CAST(Physics2DServer::AreaParameter);
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "physics_server.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "print_string.h"
|
||||
|
||||
PhysicsServer *PhysicsServer::singleton = NULL;
|
||||
|
||||
void PhysicsDirectBodyState::integrate_forces() {
|
||||
|
@ -732,3 +734,68 @@ PhysicsServer::~PhysicsServer() {
|
|||
|
||||
singleton = NULL;
|
||||
}
|
||||
|
||||
Vector<PhysicsServerManager::ClassInfo> PhysicsServerManager::physics_servers;
|
||||
int PhysicsServerManager::default_server_id = -1;
|
||||
int PhysicsServerManager::default_server_priority = -1;
|
||||
const String PhysicsServerManager::setting_property_name("physics/3d/physics_engine");
|
||||
|
||||
void PhysicsServerManager::on_servers_changed() {
|
||||
|
||||
String physics_servers("DEFAULT");
|
||||
for (int i = get_servers_count() - 1; 0 <= i; --i) {
|
||||
physics_servers += "," + get_server_name(i);
|
||||
}
|
||||
ProjectSettings::get_singleton()->set_custom_property_info(setting_property_name, PropertyInfo(Variant::STRING, setting_property_name, PROPERTY_HINT_ENUM, physics_servers));
|
||||
}
|
||||
|
||||
void PhysicsServerManager::register_server(const String &p_name, CreatePhysicsServerCallback p_creat_callback) {
|
||||
|
||||
ERR_FAIL_COND(!p_creat_callback);
|
||||
ERR_FAIL_COND(find_server_id(p_name) != -1);
|
||||
physics_servers.push_back(ClassInfo(p_name, p_creat_callback));
|
||||
on_servers_changed();
|
||||
}
|
||||
|
||||
void PhysicsServerManager::set_default_server(const String &p_name, int p_priority) {
|
||||
|
||||
const int id = find_server_id(p_name);
|
||||
ERR_FAIL_COND(id == -1); // Not found
|
||||
if (default_server_priority < p_priority) {
|
||||
default_server_id = id;
|
||||
default_server_priority = p_priority;
|
||||
}
|
||||
}
|
||||
|
||||
int PhysicsServerManager::find_server_id(const String &p_name) {
|
||||
|
||||
for (int i = physics_servers.size() - 1; 0 <= i; --i) {
|
||||
if (p_name == physics_servers[i].name) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int PhysicsServerManager::get_servers_count() {
|
||||
return physics_servers.size();
|
||||
}
|
||||
|
||||
String PhysicsServerManager::get_server_name(int p_id) {
|
||||
ERR_FAIL_INDEX_V(p_id, get_servers_count(), "");
|
||||
return physics_servers[p_id].name;
|
||||
}
|
||||
|
||||
PhysicsServer *PhysicsServerManager::new_default_server() {
|
||||
ERR_FAIL_COND_V(default_server_id == -1, NULL);
|
||||
return physics_servers[default_server_id].create_callback();
|
||||
}
|
||||
|
||||
PhysicsServer *PhysicsServerManager::new_server(const String &p_name) {
|
||||
int id = find_server_id(p_name);
|
||||
if (id == -1) {
|
||||
return NULL;
|
||||
} else {
|
||||
return physics_servers[id].create_callback();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -658,6 +658,43 @@ public:
|
|||
~PhysicsServer();
|
||||
};
|
||||
|
||||
typedef PhysicsServer *(*CreatePhysicsServerCallback)();
|
||||
|
||||
class PhysicsServerManager {
|
||||
struct ClassInfo {
|
||||
String name;
|
||||
CreatePhysicsServerCallback create_callback;
|
||||
|
||||
ClassInfo()
|
||||
: name(""), create_callback(NULL) {}
|
||||
|
||||
ClassInfo(String p_name, CreatePhysicsServerCallback p_create_callback)
|
||||
: name(p_name), create_callback(p_create_callback) {}
|
||||
|
||||
ClassInfo(const ClassInfo &p_ci)
|
||||
: name(p_ci.name), create_callback(p_ci.create_callback) {}
|
||||
};
|
||||
|
||||
static Vector<ClassInfo> physics_servers;
|
||||
static int default_server_id;
|
||||
static int default_server_priority;
|
||||
|
||||
public:
|
||||
static const String setting_property_name;
|
||||
|
||||
private:
|
||||
static void on_servers_changed();
|
||||
|
||||
public:
|
||||
static void register_server(const String &p_name, CreatePhysicsServerCallback p_creat_callback);
|
||||
static void set_default_server(const String &p_name, int p_priority = 0);
|
||||
static int find_server_id(const String &p_name);
|
||||
static int get_servers_count();
|
||||
static String get_server_name(int p_id);
|
||||
static PhysicsServer *new_default_server();
|
||||
static PhysicsServer *new_server(const String &p_name);
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(PhysicsServer::ShapeType);
|
||||
VARIANT_ENUM_CAST(PhysicsServer::SpaceParameter);
|
||||
VARIANT_ENUM_CAST(PhysicsServer::AreaParameter);
|
||||
|
|
|
@ -49,6 +49,9 @@
|
|||
#include "audio/effects/audio_effect_reverb.h"
|
||||
#include "audio/effects/audio_effect_stereo_enhance.h"
|
||||
#include "audio_server.h"
|
||||
#include "physics/physics_server_sw.h"
|
||||
#include "physics_2d/physics_2d_server_sw.h"
|
||||
#include "physics_2d/physics_2d_server_wrap_mt.h"
|
||||
#include "physics_2d_server.h"
|
||||
#include "physics_server.h"
|
||||
#include "script_debugger_remote.h"
|
||||
|
@ -74,6 +77,14 @@ static void _debugger_get_resource_usage(List<ScriptDebuggerRemote::ResourceUsag
|
|||
|
||||
ShaderTypes *shader_types = NULL;
|
||||
|
||||
PhysicsServer *_createGodotPhysicsCallback() {
|
||||
return memnew(PhysicsServerSW);
|
||||
}
|
||||
|
||||
Physics2DServer *_createGodotPhysics2DCallback() {
|
||||
return Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
||||
}
|
||||
|
||||
void register_server_types() {
|
||||
|
||||
ClassDB::register_virtual_class<VisualServer>();
|
||||
|
@ -82,12 +93,6 @@ void register_server_types() {
|
|||
ClassDB::register_virtual_class<Physics2DServer>();
|
||||
ClassDB::register_class<ARVRServer>();
|
||||
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("VisualServer", VisualServer::get_singleton()));
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("AudioServer", AudioServer::get_singleton()));
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("PhysicsServer", PhysicsServer::get_singleton()));
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("Physics2DServer", Physics2DServer::get_singleton()));
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("ARVRServer", ARVRServer::get_singleton()));
|
||||
|
||||
shader_types = memnew(ShaderTypes);
|
||||
|
||||
ClassDB::register_virtual_class<ARVRInterface>();
|
||||
|
@ -144,9 +149,31 @@ void register_server_types() {
|
|||
ClassDB::register_virtual_class<PhysicsShapeQueryResult>();
|
||||
|
||||
ScriptDebuggerRemote::resource_usage_func = _debugger_get_resource_usage;
|
||||
|
||||
// Physics 2D
|
||||
GLOBAL_DEF(Physics2DServerManager::setting_property_name, "DEFAULT");
|
||||
ProjectSettings::get_singleton()->set_custom_property_info(Physics2DServerManager::setting_property_name, PropertyInfo(Variant::STRING, Physics2DServerManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"));
|
||||
|
||||
Physics2DServerManager::register_server("GodotPhysics", &_createGodotPhysics2DCallback);
|
||||
Physics2DServerManager::set_default_server("GodotPhysics");
|
||||
|
||||
// Physics 3D
|
||||
GLOBAL_DEF(PhysicsServerManager::setting_property_name, "DEFAULT");
|
||||
ProjectSettings::get_singleton()->set_custom_property_info(PhysicsServerManager::setting_property_name, PropertyInfo(Variant::STRING, PhysicsServerManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"));
|
||||
|
||||
PhysicsServerManager::register_server("GodotPhysics", &_createGodotPhysicsCallback);
|
||||
PhysicsServerManager::set_default_server("GodotPhysics");
|
||||
}
|
||||
|
||||
void unregister_server_types() {
|
||||
|
||||
memdelete(shader_types);
|
||||
}
|
||||
|
||||
void register_server_singletons() {
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("VisualServer", VisualServer::get_singleton()));
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("AudioServer", AudioServer::get_singleton()));
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("PhysicsServer", PhysicsServer::get_singleton()));
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("Physics2DServer", Physics2DServer::get_singleton()));
|
||||
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("ARVRServer", ARVRServer::get_singleton()));
|
||||
}
|
||||
|
|
|
@ -33,4 +33,6 @@
|
|||
void register_server_types();
|
||||
void unregister_server_types();
|
||||
|
||||
void register_server_singletons();
|
||||
|
||||
#endif // REGISTER_SERVER_TYPES_H
|
||||
|
|
Loading…
Reference in New Issue