summaryrefslogtreecommitdiff
path: root/main/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/main.cpp')
-rw-r--r--main/main.cpp115
1 files changed, 71 insertions, 44 deletions
diff --git a/main/main.cpp b/main/main.cpp
index a99654542a..5ddce818ca 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -35,6 +35,7 @@
#include "core/crypto/crypto.h"
#include "core/debugger/engine_debugger.h"
#include "core/extension/extension_api_dump.h"
+#include "core/extension/native_extension_manager.h"
#include "core/input/input.h"
#include "core/input/input_map.h"
#include "core/io/dir_access.h"
@@ -120,10 +121,10 @@ static RenderingServer *rendering_server = nullptr;
static CameraServer *camera_server = nullptr;
static XRServer *xr_server = nullptr;
static TextServerManager *tsman = nullptr;
-static PhysicsServer3D *physics_server = nullptr;
-static PhysicsServer2D *physics_2d_server = nullptr;
-static NavigationServer3D *navigation_server = nullptr;
-static NavigationServer2D *navigation_2d_server = nullptr;
+static PhysicsServer3D *physics_server_3d = nullptr;
+static PhysicsServer2D *physics_server_2d = nullptr;
+static NavigationServer3D *navigation_server_3d = nullptr;
+static NavigationServer2D *navigation_server_2d = nullptr;
// We error out if setup2() doesn't turn this true
static bool _start_success = false;
@@ -204,32 +205,32 @@ static String get_full_version_string() {
// to have less code in main.cpp.
void initialize_physics() {
/// 3D Physics Server
- physics_server = PhysicsServer3DManager::new_server(
+ physics_server_3d = PhysicsServer3DManager::new_server(
ProjectSettings::get_singleton()->get(PhysicsServer3DManager::setting_property_name));
- if (!physics_server) {
+ if (!physics_server_3d) {
// Physics server not found, Use the default physics
- physics_server = PhysicsServer3DManager::new_default_server();
+ physics_server_3d = PhysicsServer3DManager::new_default_server();
}
- ERR_FAIL_COND(!physics_server);
- physics_server->init();
+ ERR_FAIL_COND(!physics_server_3d);
+ physics_server_3d->init();
/// 2D Physics server
- physics_2d_server = PhysicsServer2DManager::new_server(
+ physics_server_2d = PhysicsServer2DManager::new_server(
ProjectSettings::get_singleton()->get(PhysicsServer2DManager::setting_property_name));
- if (!physics_2d_server) {
+ if (!physics_server_2d) {
// Physics server not found, Use the default physics
- physics_2d_server = PhysicsServer2DManager::new_default_server();
+ physics_server_2d = PhysicsServer2DManager::new_default_server();
}
- ERR_FAIL_COND(!physics_2d_server);
- physics_2d_server->init();
+ ERR_FAIL_COND(!physics_server_2d);
+ physics_server_2d->init();
}
void finalize_physics() {
- physics_server->finish();
- memdelete(physics_server);
+ physics_server_3d->finish();
+ memdelete(physics_server_3d);
- physics_2d_server->finish();
- memdelete(physics_2d_server);
+ physics_server_2d->finish();
+ memdelete(physics_server_2d);
}
void finalize_display() {
@@ -240,18 +241,18 @@ void finalize_display() {
}
void initialize_navigation_server() {
- ERR_FAIL_COND(navigation_server != nullptr);
+ ERR_FAIL_COND(navigation_server_3d != nullptr);
- navigation_server = NavigationServer3DManager::new_default_server();
- navigation_2d_server = memnew(NavigationServer2D);
+ navigation_server_3d = NavigationServer3DManager::new_default_server();
+ navigation_server_2d = memnew(NavigationServer2D);
}
void finalize_navigation_server() {
- memdelete(navigation_server);
- navigation_server = nullptr;
+ memdelete(navigation_server_3d);
+ navigation_server_3d = nullptr;
- memdelete(navigation_2d_server);
- navigation_2d_server = nullptr;
+ memdelete(navigation_server_2d);
+ navigation_server_2d = nullptr;
}
//#define DEBUG_INIT
@@ -406,15 +407,18 @@ Error Main::test_setup() {
tsman->add_interface(ts);
}
+ // From `Main::setup2()`.
+ initialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
register_core_extensions();
- // From `Main::setup2()`.
- preregister_module_types();
preregister_server_types();
register_core_singletons();
+ /** INITIALIZE SERVERS **/
register_server_types();
+ initialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
+ NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS);
translation_server->setup(); //register translations, load them, etc.
if (!locale.is_empty()) {
@@ -428,16 +432,20 @@ Error Main::test_setup() {
register_scene_types();
register_driver_types();
+ initialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
+ NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SCENE);
+
#ifdef TOOLS_ENABLED
ClassDB::set_current_api(ClassDB::API_EDITOR);
EditorNode::register_editor_types();
+ initialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
+ NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR);
+
ClassDB::set_current_api(ClassDB::API_CORE);
#endif
register_platform_apis();
- register_module_types();
-
// Theme needs modules to be initialized so that sub-resources can be loaded.
initialize_theme();
@@ -479,13 +487,19 @@ void Main::test_cleanup() {
ResourceSaver::remove_custom_savers();
#ifdef TOOLS_ENABLED
+ NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR);
+ uninitialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
EditorNode::unregister_editor_types();
#endif
- unregister_module_types();
+ NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SCENE);
+ uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
unregister_platform_apis();
unregister_driver_types();
unregister_scene_types();
+
+ NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS);
+ uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
unregister_server_types();
OS::get_singleton()->finalize();
@@ -507,6 +521,7 @@ void Main::test_cleanup() {
}
unregister_core_driver_types();
+ uninitialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
unregister_core_extensions();
unregister_core_types();
@@ -1166,6 +1181,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
// Initialize user data dir.
OS::get_singleton()->ensure_user_data_dir();
+ initialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
register_core_extensions(); // core extensions must be registered after globals setup and before display
ResourceUID::get_singleton()->load_from_cache(); // load UUIDs from cache.
@@ -1584,7 +1600,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
tsman->add_interface(ts);
}
- preregister_module_types();
preregister_server_types();
// Print engine name and version
@@ -1751,6 +1766,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
}
register_server_types();
+ initialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
+ NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS);
MAIN_PRINT("Main: Load Boot Image");
@@ -1925,14 +1942,16 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
MAIN_PRINT("Main: Load Scene Types");
register_scene_types();
-
- MAIN_PRINT("Main: Load Driver Types");
-
register_driver_types();
+ initialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
+ NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SCENE);
+
#ifdef TOOLS_ENABLED
ClassDB::set_current_api(ClassDB::API_EDITOR);
EditorNode::register_editor_types();
+ initialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
+ NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR);
ClassDB::set_current_api(ClassDB::API_CORE);
@@ -1941,7 +1960,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
MAIN_PRINT("Main: Load Modules");
register_platform_apis();
- register_module_types();
// Theme needs modules to be initialized so that sub-resources can be loaded.
initialize_theme();
@@ -2112,8 +2130,8 @@ bool Main::start() {
}
{
- DirAccessRef da = DirAccess::open(doc_tool_path);
- ERR_FAIL_COND_V_MSG(!da, false, "Argument supplied to --doctool must be a valid directory path.");
+ Ref<DirAccess> da = DirAccess::open(doc_tool_path);
+ ERR_FAIL_COND_V_MSG(da.is_null(), false, "Argument supplied to --doctool must be a valid directory path.");
}
#ifndef MODULE_MONO_ENABLED
@@ -2149,7 +2167,7 @@ bool Main::start() {
checked_paths.insert(path);
// Create the module documentation directory if it doesn't exist
- DirAccessRef da = DirAccess::create_for_path(path);
+ Ref<DirAccess> da = DirAccess::create_for_path(path);
err = da->make_dir_recursive(path);
ERR_FAIL_COND_V_MSG(err != OK, false, "Error: Can't create directory: " + path + ": " + itos(err));
@@ -2161,7 +2179,7 @@ bool Main::start() {
String index_path = doc_tool_path.plus_file("doc/classes");
// Create the main documentation directory if it doesn't exist
- DirAccessRef da = DirAccess::create_for_path(index_path);
+ Ref<DirAccess> da = DirAccess::create_for_path(index_path);
err = da->make_dir_recursive(index_path);
ERR_FAIL_COND_V_MSG(err != OK, false, "Error: Can't create index directory: " + index_path + ": " + itos(err));
@@ -2324,7 +2342,7 @@ bool Main::start() {
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
const ProjectSettings::AutoloadInfo &info = E.get();
- RES res = ResourceLoader::load(info.path);
+ Ref<Resource> res = ResourceLoader::load(info.path);
ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + info.path);
Node *n = nullptr;
Ref<PackedScene> scn = res;
@@ -2501,11 +2519,11 @@ bool Main::start() {
int sep = local_game_path.rfind("/");
if (sep == -1) {
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
local_game_path = da->get_current_dir().plus_file(local_game_path);
} else {
- DirAccessRef da = DirAccess::open(local_game_path.substr(0, sep));
- if (da) {
+ Ref<DirAccess> da = DirAccess::open(local_game_path.substr(0, sep));
+ if (da.is_valid()) {
local_game_path = da->get_current_dir().plus_file(
local_game_path.substr(sep + 1, local_game_path.length()));
}
@@ -2852,15 +2870,23 @@ void Main::cleanup(bool p_force) {
}
#ifdef TOOLS_ENABLED
+ NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR);
+ uninitialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
EditorNode::unregister_editor_types();
+
#endif
ImageLoader::cleanup();
- unregister_module_types();
+ NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SCENE);
+ uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
+
unregister_platform_apis();
unregister_driver_types();
unregister_scene_types();
+
+ NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS);
+ uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
unregister_server_types();
EngineDebugger::deinitialize();
@@ -2929,6 +2955,7 @@ void Main::cleanup(bool p_force) {
unregister_core_driver_types();
unregister_core_extensions();
+ uninitialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
unregister_core_types();
OS::get_singleton()->finalize_core();