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

Refactor main.cpp setup #49362

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions core/core_string_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
#include "core/string/string_name.h"

class CoreStringNames {
friend void register_core_types();
friend void unregister_core_types();

friend void register_core();
static void create() { singleton = memnew(CoreStringNames); }

friend void unregister_core();
static void free() {
memdelete(singleton);
singleton = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,13 @@ class ObjectDB {
static uint64_t validator_counter;

friend class Object;
friend void unregister_core_types();
friend void unregister_core();
static void cleanup();

static ObjectID add_instance(Object *p_object);
static void remove_instance(Object *p_object);

friend void register_core_types();
friend void register_core();
static void setup();

public:
Expand Down
2 changes: 1 addition & 1 deletion core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ String OS::get_model_name() const {
return "GenericDevice";
}

void OS::set_cmdline(const char *p_execpath, const List<String> &p_args) {
void OS::set_cmdline(const String p_execpath, const List<String> &p_args) {
_execpath = p_execpath;
_cmdline = p_args;
}
Expand Down
2 changes: 1 addition & 1 deletion core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class OS {
virtual void finalize() = 0;
virtual void finalize_core() = 0;

virtual void set_cmdline(const char *p_execpath, const List<String> &p_args);
virtual void set_cmdline(const String p_execpath, const List<String> &p_args);

virtual bool _check_internal_feature_support(const String &p_feature) = 0;

Expand Down
55 changes: 27 additions & 28 deletions core/register_core_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include "core/os/main_loop.h"
#include "core/string/optimized_translation.h"
#include "core/string/translation.h"
#include <main/performance.h>

static Ref<ResourceFormatSaverBinary> resource_saver_binary;
static Ref<ResourceFormatLoaderBinary> resource_loader_binary;
Expand Down Expand Up @@ -98,26 +99,28 @@ extern Mutex _global_mutex;
extern void register_global_constants();
extern void unregister_global_constants();

void register_core_types() {
void register_core() {
//consistency check
static_assert(sizeof(Callable) <= 16);

ObjectDB::setup();

StringName::setup();
ResourceLoader::initialize();

register_global_constants();

Variant::register_types();

CoreStringNames::create();

ResourceLoader::initialize();

resource_format_po.instance();
ResourceLoader::add_resource_format_loader(resource_format_po);

resource_saver_binary.instance();
ResourceSaver::add_resource_format_saver(resource_saver_binary);

resource_loader_binary.instance();
ResourceLoader::add_resource_format_loader(resource_loader_binary);

Expand All @@ -127,6 +130,16 @@ void register_core_types() {
resource_format_image.instance();
ResourceLoader::add_resource_format_loader(resource_format_image);

resource_format_loader_crypto.instance();
ResourceLoader::add_resource_format_loader(resource_format_loader_crypto);

resource_format_saver_crypto.instance();
ResourceSaver::add_resource_format_saver(resource_format_saver_crypto);

ip = IP::create();
}

void register_core_types() {
ClassDB::register_class<Object>();

ClassDB::register_virtual_class<Script>();
Expand Down Expand Up @@ -171,11 +184,6 @@ void register_core_types() {
ClassDB::register_custom_instance_class<Crypto>();
ClassDB::register_custom_instance_class<StreamPeerSSL>();

resource_format_saver_crypto.instance();
ResourceSaver::add_resource_format_saver(resource_format_saver_crypto);
resource_format_loader_crypto.instance();
ResourceLoader::add_resource_format_loader(resource_format_loader_crypto);

ClassDB::register_virtual_class<IP>();
ClassDB::register_virtual_class<PacketPeer>();
ClassDB::register_class<PacketPeerStream>();
Expand Down Expand Up @@ -215,8 +223,6 @@ void register_core_types() {

ClassDB::register_virtual_class<ResourceImporter>();

ip = IP::create();

_geometry_2d = memnew(_Geometry2D);
_geometry_3d = memnew(_Geometry3D);

Expand All @@ -230,17 +236,6 @@ void register_core_types() {
_engine_debugger = memnew(_EngineDebugger);
}

void register_core_settings() {
// Since in register core types, globals may not be present.
GLOBAL_DEF("network/limits/tcp/connect_timeout_seconds", (30));
ProjectSettings::get_singleton()->set_custom_property_info("network/limits/tcp/connect_timeout_seconds", PropertyInfo(Variant::INT, "network/limits/tcp/connect_timeout_seconds", PROPERTY_HINT_RANGE, "1,1800,1"));
GLOBAL_DEF_RST("network/limits/packet_peer_stream/max_buffer_po2", (16));
ProjectSettings::get_singleton()->set_custom_property_info("network/limits/packet_peer_stream/max_buffer_po2", PropertyInfo(Variant::INT, "network/limits/packet_peer_stream/max_buffer_po2", PROPERTY_HINT_RANGE, "0,64,1,or_greater"));

GLOBAL_DEF("network/ssl/certificate_bundle_override", "");
ProjectSettings::get_singleton()->set_custom_property_info("network/ssl/certificate_bundle_override", PropertyInfo(Variant::STRING, "network/ssl/certificate_bundle_override", PROPERTY_HINT_FILE, "*.crt"));
}

void register_core_singletons() {
ClassDB::register_class<ProjectSettings>();
ClassDB::register_virtual_class<IP>();
Expand All @@ -258,8 +253,10 @@ void register_core_singletons() {
ClassDB::register_class<_JSON>();
ClassDB::register_class<Expression>();
ClassDB::register_class<_EngineDebugger>();
ClassDB::register_class<Performance>();

Engine::get_singleton()->add_singleton(Engine::Singleton("ProjectSettings", ProjectSettings::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Performance", Performance::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("IP", IP::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry2D", _Geometry2D::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry3D", _Geometry3D::get_singleton()));
Expand Down Expand Up @@ -289,6 +286,15 @@ void unregister_core_types() {
memdelete(_geometry_2d);
memdelete(_geometry_3d);

ClassDB::cleanup_defaults();

unregister_global_constants();

ClassDB::cleanup();
ResourceCache::clear();
}

void unregister_core() {
ResourceLoader::remove_resource_format_loader(resource_format_image);
resource_format_image.unref();

Expand All @@ -309,21 +315,14 @@ void unregister_core_types() {
ResourceLoader::remove_resource_format_loader(resource_format_loader_crypto);
resource_format_loader_crypto.unref();

ResourceLoader::finalize();
if (ip) {
memdelete(ip);
}

ResourceLoader::finalize();

ClassDB::cleanup_defaults();
ObjectDB::cleanup();

Variant::unregister_types();

unregister_global_constants();

ClassDB::cleanup();
ResourceCache::clear();
CoreStringNames::free();
StringName::cleanup();
}
4 changes: 3 additions & 1 deletion core/register_core_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
#ifndef REGISTER_CORE_TYPES_H
#define REGISTER_CORE_TYPES_H

void register_core();
void register_core_types();
void register_core_settings();
void register_core_singletons();

void unregister_core_types();
void unregister_core();

#endif // REGISTER_CORE_TYPES_H
4 changes: 2 additions & 2 deletions core/string/string_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class StringName {
};

void unref();
friend void register_core_types();
friend void unregister_core_types();
friend void register_core();
friend void unregister_core();
friend class Main;
static Mutex mutex;
static void setup();
Expand Down
27 changes: 26 additions & 1 deletion doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@
<member name="application/boot_splash/use_filter" type="bool" setter="" getter="" default="true">
If [code]true[/code], applies linear filtering when scaling the image (recommended for high resolution artwork). If [code]false[/code], uses nearest-neighbor interpolation (recommended for pixel art).
</member>
<member name="application/config/auto_accept_quit" type="bool" setter="" getter="" default="true">
</member>
<member name="application/config/custom_user_dir_name" type="String" setter="" getter="" default="&quot;&quot;">
This user directory is used for storing persistent data ([code]user://[/code] filesystem). If left empty, [code]user://[/code] resolves to a project-specific folder in Godot's own configuration folder (see [method OS.get_user_data_dir]). If a custom directory name is defined, this name will be used instead and appended to the system-specific user data directory (same parent folder as the Godot configuration folder documented in [method OS.get_user_data_dir]).
The [member application/config/use_custom_user_dir] setting must be enabled for this to take effect.
Expand All @@ -249,7 +251,6 @@
Icon used for the project, set when project loads. Exporters will also use this icon when possible.
</member>
<member name="application/config/macos_native_icon" type="String" setter="" getter="" default="&quot;&quot;">
Icon set in [code].icns[/code] format used on macOS to set the game's icon. This is done automatically on start by calling [method DisplayServer.set_native_icon].
</member>
<member name="application/config/name" type="String" setter="" getter="" default="&quot;&quot;">
The project's name. It is used both by the Project Manager and by exporters. The project name can be translated by translating its value in localization files. The window title will be set to match the project name automatically on startup.
Expand All @@ -259,6 +260,8 @@
Specifies a file to override project settings. For example: [code]user://custom_settings.cfg[/code]. See "Overriding" in the [ProjectSettings] class description at the top for more information.
[b]Note:[/b] Regardless of this setting's value, [code]res://override.cfg[/code] will still be read to override the project settings.
</member>
<member name="application/config/quit_on_go_back" type="bool" setter="" getter="" default="true">
</member>
<member name="application/config/use_custom_user_dir" type="bool" setter="" getter="" default="false">
If [code]true[/code], the project will save user data to its own user directory (see [member application/config/custom_user_dir_name]). This setting is only effective on desktop platforms. A name must be set in the [member application/config/custom_user_dir_name] setting for this to take effect. If [code]false[/code], the project will save user data to [code](OS user data directory)/Godot/app_userdata/(project name)[/code].
</member>
Expand Down Expand Up @@ -290,6 +293,8 @@
<member name="application/run/low_processor_mode_sleep_usec" type="int" setter="" getter="" default="6900">
Amount of sleeping between frames when the low-processor usage mode is enabled (in microseconds). Higher values will result in lower CPU usage.
</member>
<member name="application/run/main_loop_type" type="String" setter="" getter="" default="&quot;SceneTree&quot;">
</member>
<member name="application/run/main_scene" type="String" setter="" getter="" default="&quot;&quot;">
Path to the main scene file that will be loaded when the project runs.
</member>
Expand Down Expand Up @@ -501,6 +506,10 @@
<member name="display/window/ios/hide_home_indicator" type="bool" setter="" getter="" default="true">
If [code]true[/code], the home indicator is hidden automatically. This only affects iOS devices without a physical home button.
</member>
<member name="display/window/per_pixel_transparency/allowed" type="bool" setter="" getter="" default="false">
</member>
<member name="display/window/per_pixel_transparency/enabled" type="bool" setter="" getter="" default="false">
</member>
<member name="display/window/size/always_on_top" type="bool" setter="" getter="" default="false">
Forces the main window to be always on top.
[b]Note:[/b] This setting is ignored on iOS, Android, and HTML5.
Expand Down Expand Up @@ -530,6 +539,14 @@
<member name="display/window/size/width" type="int" setter="" getter="" default="1024">
Sets the game's main viewport width. On desktop platforms, this is the default window size. Stretch mode settings also use this as a reference when enabled.
</member>
<member name="display/window/stretch/aspect" type="String" setter="" getter="" default="&quot;ignore&quot;">
</member>
<member name="display/window/stretch/mode" type="String" setter="" getter="" default="&quot;disabled&quot;">
</member>
<member name="display/window/stretch/shrink" type="float" setter="" getter="" default="1.0">
</member>
<member name="display/window/subwindows/embed_subwindows" type="bool" setter="" getter="" default="false">
</member>
<member name="display/window/vsync/use_vsync" type="bool" setter="" getter="" default="true">
If [code]true[/code], enables vertical synchronization. This eliminates tearing that may appear in moving scenes, at the cost of higher input latency and stuttering at lower framerates. If [code]false[/code], vertical synchronization will be disabled, however, many platforms will enforce it regardless (such as mobile platforms and HTML5).
</member>
Expand Down Expand Up @@ -560,11 +577,15 @@
<member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0">
Default value for [member ScrollContainer.scroll_deadzone], which will be used for all [ScrollContainer]s unless overridden.
</member>
<member name="gui/common/snap_controls_to_pixels" type="bool" setter="" getter="" default="true">
</member>
<member name="gui/common/swap_cancel_ok" type="bool" setter="" getter="">
If [code]true[/code], swaps Cancel and OK buttons in dialogs on Windows and UWP to follow interface conventions.
</member>
<member name="gui/common/text_edit_undo_stack_max_size" type="int" setter="" getter="" default="1024">
</member>
<member name="gui/fonts/dynamic_fonts/use_oversampling" type="bool" setter="" getter="" default="true">
</member>
<member name="gui/theme/custom" type="String" setter="" getter="" default="&quot;&quot;">
Path to a custom [Theme] resource file to use for the project ([code]theme[/code] or generic [code]tres[/code]/[code]res[/code] extension).
</member>
Expand Down Expand Up @@ -1572,6 +1593,10 @@
<member name="rendering/shadows/shadows/soft_shadow_quality.mobile" type="int" setter="" getter="" default="0">
Lower-end override for [member rendering/shadows/shadows/soft_shadow_quality] on mobile devices, due to performance concerns or driver support.
</member>
<member name="rendering/textures/canvas_textures/default_texture_filter" type="int" setter="" getter="" default="1">
</member>
<member name="rendering/textures/canvas_textures/default_texture_repeat" type="int" setter="" getter="" default="0">
</member>
<member name="rendering/textures/default_filters/anisotropic_filtering_level" type="int" setter="" getter="" default="2">
Sets the maximum number of samples to take when using anisotropic filtering on textures (as a power of two). A higher sample count will result in sharper textures at oblique angles, but is more expensive to compute. A value of [code]0[/code] forcibly disables anisotropic filtering, even on materials where it is enabled.
</member>
Expand Down
6 changes: 0 additions & 6 deletions drivers/register_driver_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,3 @@ void unregister_core_driver_types() {
ResourceSaver::remove_resource_format_saver(resource_saver_png);
resource_saver_png.unref();
}

void register_driver_types() {
}

void unregister_driver_types() {
}
3 changes: 0 additions & 3 deletions drivers/register_driver_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,4 @@
void register_core_driver_types();
void unregister_core_driver_types();

void register_driver_types();
void unregister_driver_types();

#endif
4 changes: 0 additions & 4 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5687,10 +5687,6 @@ EditorNode::EditorNode() {
script_distraction = false;

TranslationServer::get_singleton()->set_enabled(false);
// load settings
if (!EditorSettings::get_singleton()) {
EditorSettings::create();
}

FileAccess::set_backup_save(EDITOR_GET("filesystem/on_save/safe_save_on_backup_then_rename"));

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ EditorPaths::EditorPaths(bool p_for_project_mamanger) {

// Validate/create cache dir

if (dir->change_dir(EditorPaths::get_singleton()->get_cache_dir()) != OK) {
if (dir->change_dir(cache_dir) != OK) {
dir->make_dir_recursive(cache_dir);
if (dir->change_dir(cache_dir) != OK) {
ERR_PRINT("Cannot create cache directory!");
Expand Down
9 changes: 4 additions & 5 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "editor_scale.h"
#include "editor_settings.h"
#include "editor_themes.h"
#include "progress_dialog.h"
#include "scene/gui/center_container.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/margin_container.h"
Expand Down Expand Up @@ -2389,11 +2390,6 @@ void ProjectManager::_version_button_pressed() {
}

ProjectManager::ProjectManager() {
// load settings
if (!EditorSettings::get_singleton()) {
EditorSettings::create();
}

EditorSettings::get_singleton()->set_optimize_save(false); //just write settings as they came

{
Expand Down Expand Up @@ -2470,6 +2466,9 @@ ProjectManager::ProjectManager() {

set_anchors_and_offsets_preset(Control::PRESET_WIDE);

ProgressDialog *progress_dialog = memnew(ProgressDialog);
add_child(progress_dialog);

Panel *panel = memnew(Panel);
add_child(panel);
panel->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
Expand Down
Loading