diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/main.cpp | 103 | ||||
-rw-r--r-- | main/tests/test_physics.cpp | 2 | ||||
-rw-r--r-- | main/tests/test_physics_2d.cpp | 20 | ||||
-rw-r--r-- | main/tests/test_render.cpp | 4 |
4 files changed, 85 insertions, 44 deletions
diff --git a/main/main.cpp b/main/main.cpp index deffb3a632..aa4dce93a6 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -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", " "); @@ -288,8 +321,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph I = args.front(); - video_mode = OS::get_singleton()->get_default_video_mode(); - String video_driver = ""; String audio_driver = ""; String game_path = "."; @@ -746,38 +777,41 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph //if (video_driver == "") // useless for now, so removing // video_driver = GLOBAL_DEF("display/driver/name", Variant((const char *)OS::get_singleton()->get_video_driver_name(0))); - if (!force_res && use_custom_res && globals->has_setting("display/window/size/width")) - video_mode.width = globals->get("display/window/size/width"); - if (!force_res && use_custom_res && globals->has_setting("display/window/size/height")) - video_mode.height = globals->get("display/window/size/height"); - if (!editor && ((globals->has_setting("display/window/dpi/allow_hidpi") && !globals->get("display/window/dpi/allow_hidpi")) || force_lowdpi)) { - OS::get_singleton()->_allow_hidpi = false; - } - if (use_custom_res && globals->has_setting("display/window/size/fullscreen")) - video_mode.fullscreen = globals->get("display/window/size/fullscreen"); - if (use_custom_res && globals->has_setting("display/window/size/resizable")) - video_mode.resizable = globals->get("display/window/size/resizable"); - if (use_custom_res && globals->has_setting("display/window/size/borderless")) - video_mode.borderless_window = globals->get("display/window/size/borderless"); - - if (!force_res && use_custom_res && globals->has_setting("display/window/size/test_width") && globals->has_setting("display/window/size/test_height")) { - int tw = globals->get("display/window/size/test_width"); - int th = globals->get("display/window/size/test_height"); - if (tw > 0 && th > 0) { - video_mode.width = tw; - video_mode.height = th; + GLOBAL_DEF("display/window/size/width", 1024); + GLOBAL_DEF("display/window/size/height", 600); + GLOBAL_DEF("display/window/size/resizable", true); + GLOBAL_DEF("display/window/size/borderless", false); + GLOBAL_DEF("display/window/size/fullscreen", false); + GLOBAL_DEF("display/window/size/test_width", 0); + GLOBAL_DEF("display/window/size/test_height", 0); + + if (use_custom_res) { + + if (!force_res) { + video_mode.width = GLOBAL_GET("display/window/size/width"); + video_mode.height = GLOBAL_GET("display/window/size/height"); + + if (globals->has_setting("display/window/size/test_width") && globals->has_setting("display/window/size/test_height")) { + int tw = globals->get("display/window/size/test_width"); + int th = globals->get("display/window/size/test_height"); + if (tw > 0 && th > 0) { + video_mode.width = tw; + video_mode.height = th; + } + } } + + video_mode.resizable = GLOBAL_GET("display/window/size/resizable"); + video_mode.borderless_window = GLOBAL_GET("display/window/size/borderless"); + video_mode.fullscreen = GLOBAL_GET("display/window/size/fullscreen"); } - GLOBAL_DEF("display/window/size/width", video_mode.width); - GLOBAL_DEF("display/window/size/height", video_mode.height); - GLOBAL_DEF("display/window/dpi/allow_hidpi", false); - GLOBAL_DEF("display/window/size/fullscreen", video_mode.fullscreen); - GLOBAL_DEF("display/window/size/resizable", video_mode.resizable); - GLOBAL_DEF("display/window/size/borderless", video_mode.borderless_window); - use_vsync = GLOBAL_DEF("display/window/vsync/use_vsync", use_vsync); - GLOBAL_DEF("display/window/size/test_width", 0); - GLOBAL_DEF("display/window/size/test_height", 0); + if (!force_lowdpi) { + OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", false); + } + + use_vsync = GLOBAL_DEF("display/window/vsync/use_vsync", true); + GLOBAL_DEF("rendering/quality/intended_usage/framebuffer_allocation", 2); GLOBAL_DEF("rendering/quality/intended_usage/framebuffer_allocation.mobile", 3); @@ -1072,9 +1106,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 +1829,7 @@ void Main::cleanup() { unregister_server_types(); OS::get_singleton()->finalize(); + finalize_physics(); if (packed_data) memdelete(packed_data); diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp index f149821928..1c50470544 100644 --- a/main/tests/test_physics.cpp +++ b/main/tests/test_physics.cpp @@ -299,7 +299,7 @@ public: VisualServer *vs = VisualServer::get_singleton(); /* LIGHT */ - RID lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL); + RID lightaux = vs->directional_light_create(); scenario = vs->scenario_create(); vs->light_set_shadow(lightaux, true); light = vs->instance_create2(lightaux, scenario); diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp index a746973799..7d596fbda3 100644 --- a/main/tests/test_physics_2d.cpp +++ b/main/tests/test_physics_2d.cpp @@ -86,7 +86,7 @@ class TestPhysics2DMainLoop : public MainLoop { body_shape_data[Physics2DServer::SHAPE_SEGMENT].image = vs->texture_create_from_image(image); - RID segment_shape = ps->shape_create(Physics2DServer::SHAPE_SEGMENT); + RID segment_shape = ps->segment_shape_create(); Rect2 sg(Point2(-16, 0), Point2(16, 0)); ps->shape_set_data(segment_shape, sg); @@ -113,7 +113,7 @@ class TestPhysics2DMainLoop : public MainLoop { body_shape_data[Physics2DServer::SHAPE_CIRCLE].image = vs->texture_create_from_image(image); - RID circle_shape = ps->shape_create(Physics2DServer::SHAPE_CIRCLE); + RID circle_shape = ps->circle_shape_create(); ps->shape_set_data(circle_shape, 16); body_shape_data[Physics2DServer::SHAPE_CIRCLE].shape = circle_shape; @@ -140,7 +140,7 @@ class TestPhysics2DMainLoop : public MainLoop { body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image = vs->texture_create_from_image(image); - RID rectangle_shape = ps->shape_create(Physics2DServer::SHAPE_RECTANGLE); + RID rectangle_shape = ps->rectangle_shape_create(); ps->shape_set_data(rectangle_shape, Vector2(16, 16)); body_shape_data[Physics2DServer::SHAPE_RECTANGLE].shape = rectangle_shape; @@ -168,7 +168,7 @@ class TestPhysics2DMainLoop : public MainLoop { body_shape_data[Physics2DServer::SHAPE_CAPSULE].image = vs->texture_create_from_image(image); - RID capsule_shape = ps->shape_create(Physics2DServer::SHAPE_CAPSULE); + RID capsule_shape = ps->capsule_shape_create(); ps->shape_set_data(capsule_shape, Vector2(16, 32)); body_shape_data[Physics2DServer::SHAPE_CAPSULE].shape = capsule_shape; @@ -182,7 +182,7 @@ class TestPhysics2DMainLoop : public MainLoop { body_shape_data[Physics2DServer::SHAPE_CONVEX_POLYGON].image = vs->texture_create_from_image(image); - RID convex_polygon_shape = ps->shape_create(Physics2DServer::SHAPE_CONVEX_POLYGON); + RID convex_polygon_shape = ps->convex_polygon_shape_create(); PoolVector<Vector2> arr; Point2 sb(32, 32); @@ -277,10 +277,11 @@ protected: arr.push_back(p_normal); arr.push_back(p_d); - RID plane = ps->shape_create(Physics2DServer::SHAPE_LINE); + RID plane = ps->line_shape_create(); ps->shape_set_data(plane, arr); - RID plane_body = ps->body_create(Physics2DServer::BODY_MODE_STATIC); + RID plane_body = ps->body_create(); + ps->body_set_mode(plane_body, Physics2DServer::BODY_MODE_STATIC); ps->body_set_space(plane_body, space); ps->body_add_shape(plane_body, plane); } @@ -290,9 +291,10 @@ protected: Physics2DServer *ps = Physics2DServer::get_singleton(); VisualServer *vs = VisualServer::get_singleton(); - RID concave = ps->shape_create(Physics2DServer::SHAPE_CONCAVE_POLYGON); + RID concave = ps->concave_polygon_shape_create(); ps->shape_set_data(concave, p_points); - RID body = ps->body_create(Physics2DServer::BODY_MODE_STATIC); + RID body = ps->body_create(); + ps->body_set_mode(body, Physics2DServer::BODY_MODE_STATIC); ps->body_set_space(body, space); ps->body_add_shape(body, concave); ps->body_set_state(body, Physics2DServer::BODY_STATE_TRANSFORM, p_xform); diff --git a/main/tests/test_render.cpp b/main/tests/test_render.cpp index 1f6217928d..cbf1a57855 100644 --- a/main/tests/test_render.cpp +++ b/main/tests/test_render.cpp @@ -180,7 +180,7 @@ public: */ RID lightaux; - lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL); + lightaux = vs->directional_light_create(); //vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) ); vs->light_set_color(lightaux, Color(1.0, 1.0, 1.0)); //vs->light_set_shadow( lightaux, true ); @@ -191,7 +191,7 @@ public: vs->instance_set_transform(light, lla); - lightaux = vs->light_create(VisualServer::LIGHT_OMNI); + lightaux = vs->omni_light_create(); //vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,1.0) ); vs->light_set_color(lightaux, Color(1.0, 1.0, 0.0)); vs->light_set_param(lightaux, VisualServer::LIGHT_PARAM_RANGE, 4); |