From 25678b1876816b9ccb14b2c92aef62f3b009f88f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 19 Jul 2017 17:00:46 -0300 Subject: -Renamed GlobalConfig to ProjectSettings, makes more sense. -Added system for feature overrides, it's pretty cool :) --- core/SCsub | 6 +- core/bind/core_bind.cpp | 4 +- core/core_string_names.cpp | 1 + core/core_string_names.h | 1 + core/global_config.cpp | 970 ----------- core/global_config.h | 170 -- core/input_map.cpp | 6 +- core/io/compression.cpp | 2 +- core/io/file_access_memory.cpp | 6 +- core/io/file_access_network.cpp | 2 +- core/io/packet_peer.cpp | 2 +- core/io/resource_format_binary.cpp | 16 +- core/io/resource_import.cpp | 7 +- core/io/resource_loader.cpp | 14 +- core/io/resource_saver.cpp | 4 +- core/message_queue.cpp | 2 +- core/os/dir_access.cpp | 8 +- core/os/file_access.cpp | 6 +- core/os/input.cpp | 4 +- core/os/input_event.cpp | 2 +- core/os/os.cpp | 24 +- core/os/os.h | 3 +- core/project_settings.cpp | 1038 ++++++++++++ core/project_settings.h | 172 ++ core/register_core_types.cpp | 26 +- core/script_debugger_remote.cpp | 8 +- core/translation.cpp | 8 +- doc/base/classes.xml | 4 +- drivers/alsa/audio_driver_alsa.cpp | 2 +- drivers/gles2/rasterizer_gles2.cpp | 8 +- drivers/gles3/rasterizer_canvas_gles3.cpp | 2 +- drivers/gles3/rasterizer_gles3.cpp | 2 +- drivers/gles3/rasterizer_scene_gles3.cpp | 18 +- drivers/gles3/rasterizer_storage_gles3.cpp | 8 +- drivers/png/resource_saver_png.cpp | 2 +- drivers/pulseaudio/audio_driver_pulseaudio.cpp | 2 +- drivers/rtaudio/audio_driver_rtaudio.cpp | 2 +- drivers/unix/os_unix.cpp | 11 +- drivers/unix/os_unix.h | 2 - drivers/xaudio2/audio_driver_xaudio2.cpp | 2 +- editor/asset_library_editor_plugin.cpp | 4 +- editor/collada/collada.cpp | 8 +- editor/collada/collada.h | 2 +- editor/doc/doc_data.cpp | 10 +- editor/editor_autoload_settings.cpp | 76 +- editor/editor_data.cpp | 2 +- editor/editor_export.cpp | 83 +- editor/editor_export.h | 18 +- editor/editor_file_system.cpp | 10 +- editor/editor_node.cpp | 50 +- editor/editor_node.h | 4 +- editor/editor_plugin_settings.cpp | 4 +- editor/editor_resource_preview.cpp | 4 +- editor/editor_run.cpp | 12 +- editor/editor_settings.cpp | 4 +- editor/file_type_cache.cpp | 6 +- editor/filesystem_dock.cpp | 6 +- editor/import/resource_importer_texture.cpp | 18 +- editor/io_plugins/editor_export_scene.cpp | 4 +- editor/io_plugins/editor_scene_import_plugin.cpp | 12 +- editor/io_plugins/editor_texture_import_plugin.cpp | 4 +- editor/plugins/animation_player_editor_plugin.cpp | 4 +- editor/plugins/animation_tree_editor_plugin.cpp | 4 +- editor/plugins/canvas_item_editor_plugin.cpp | 8 +- editor/plugins/editor_preview_plugins.cpp | 2 +- .../plugins/resource_preloader_editor_plugin.cpp | 2 +- editor/plugins/sample_editor_plugin.cpp | 2 +- editor/plugins/sample_library_editor_plugin.cpp | 2 +- editor/plugins/script_editor_plugin.cpp | 6 +- editor/plugins/spatial_editor_plugin.cpp | 18 +- editor/plugins/sprite_frames_editor_plugin.cpp | 2 +- editor/plugins/texture_editor_plugin.cpp | 2 +- editor/project_export.cpp | 77 +- editor/project_export.h | 9 + editor/project_settings.cpp | 1683 ------------------- editor/project_settings.h | 167 -- editor/project_settings_editor.cpp | 1751 ++++++++++++++++++++ editor/project_settings_editor.h | 169 ++ editor/property_editor.cpp | 44 +- editor/property_editor.h | 2 + editor/resources_dock.cpp | 4 +- editor/scene_tree_dock.cpp | 4 +- editor/script_create_dialog.cpp | 8 +- editor/script_editor_debugger.cpp | 2 +- editor/settings_config_dialog.cpp | 2 +- main/main.cpp | 57 +- main/tests/test_io.cpp | 10 +- modules/gdnative/api_generator.cpp | 4 +- modules/gdnative/gdnative.cpp | 6 +- modules/gdnative/godot.cpp | 4 +- modules/gdscript/gd_editor.cpp | 20 +- modules/gdscript/gd_script.cpp | 8 +- modules/openssl/stream_peer_openssl.cpp | 4 +- modules/openssl/stream_peer_openssl.h | 2 +- modules/theora/video_stream_theora.cpp | 4 +- modules/visual_script/visual_script.cpp | 2 +- .../visual_script/visual_script_flow_control.cpp | 10 +- modules/visual_script/visual_script_func_nodes.cpp | 16 +- modules/visual_script/visual_script_nodes.cpp | 14 +- modules/webm/video_stream_webm.cpp | 4 +- platform/android/audio_driver_jandroid.cpp | 2 +- platform/android/export/export.cpp | 40 +- platform/android/globals/global_defaults.cpp | 4 +- platform/android/godot_android.cpp | 8 +- platform/android/java_glue.cpp | 16 +- platform/android/os_android.cpp | 8 +- platform/android/os_android.h | 1 + platform/haiku/audio_driver_media_kit.cpp | 2 +- platform/haiku/os_haiku.cpp | 5 + platform/haiku/os_haiku.h | 2 + platform/iphone/app_delegate.mm | 10 +- platform/iphone/export/export.cpp | 13 +- platform/iphone/gl_view.mm | 4 +- platform/iphone/globals/global_defaults.cpp | 4 +- platform/iphone/os_iphone.cpp | 19 +- platform/iphone/os_iphone.h | 1 + platform/javascript/export/export.cpp | 12 + platform/javascript/os_javascript.cpp | 11 +- platform/javascript/os_javascript.h | 2 + platform/osx/export/export.cpp | 22 +- platform/osx/os_osx.h | 2 + platform/osx/os_osx.mm | 4 + platform/uwp/export/export.cpp | 14 +- platform/uwp/os_uwp.cpp | 7 +- platform/uwp/os_uwp.h | 2 +- platform/windows/export/export.cpp | 1 + platform/windows/os_windows.cpp | 10 +- platform/windows/os_windows.h | 2 +- platform/x11/export/export.cpp | 1 + platform/x11/os_x11.cpp | 5 + platform/x11/os_x11.h | 2 + scene/3d/light.cpp | 2 +- scene/3d/portal.cpp | 2 +- scene/3d/room_instance.cpp | 2 +- scene/3d/skeleton.cpp | 2 +- scene/gui/control.cpp | 2 +- scene/gui/item_list.cpp | 6 +- scene/gui/label.cpp | 2 +- scene/gui/text_edit.cpp | 2 +- scene/gui/tree.cpp | 44 +- scene/gui/tree.h | 9 +- scene/io/resource_format_image.cpp | 4 +- scene/main/node.cpp | 8 +- scene/main/node.h | 2 +- scene/main/scene_tree.cpp | 16 +- scene/main/viewport.cpp | 2 +- scene/register_scene_types.cpp | 8 +- scene/resources/audio_stream_resampled.cpp | 2 +- scene/resources/environment.cpp | 2 +- scene/resources/packed_scene.cpp | 2 +- scene/resources/scene_format_text.cpp | 26 +- scene/resources/world_2d.cpp | 2 +- scene/resources/world_2d.h | 2 +- servers/audio/audio_driver_dummy.cpp | 2 +- servers/audio_server.cpp | 2 +- servers/physics/space_sw.cpp | 2 +- servers/physics/space_sw.h | 2 +- servers/physics_2d/broad_phase_2d_hash_grid.cpp | 2 +- servers/physics_2d/physics_2d_server_sw.cpp | 4 +- servers/physics_2d/physics_2d_server_wrap_mt.h | 2 +- servers/physics_2d/space_2d_sw.h | 2 +- servers/register_server_types.cpp | 10 +- servers/visual/visual_server_raster.cpp | 2 +- servers/visual/visual_server_viewport.cpp | 2 +- servers/visual/visual_server_wrap_mt.cpp | 2 +- servers/visual_server.cpp | 21 +- 166 files changed, 3981 insertions(+), 3516 deletions(-) delete mode 100644 core/global_config.cpp delete mode 100644 core/global_config.h create mode 100644 core/project_settings.cpp create mode 100644 core/project_settings.h delete mode 100644 editor/project_settings.cpp delete mode 100644 editor/project_settings.h create mode 100644 editor/project_settings_editor.cpp create mode 100644 editor/project_settings_editor.h diff --git a/core/SCsub b/core/SCsub index 02abaa2bb6..4c541d7269 100644 --- a/core/SCsub +++ b/core/SCsub @@ -14,9 +14,9 @@ for x in env.global_defaults: gd_inc += '#include "platform/' + x + '/globals/global_defaults.h"\n' gd_call += "\tregister_" + x + "_global_defaults();\n" -gd_cpp = '#include "global_config.h"\n' +gd_cpp = '#include "project_settings.h"\n' gd_cpp += gd_inc -gd_cpp += "void GlobalConfig::register_global_defaults() {\n" + gd_call + "\n}\n" +gd_cpp += "void ProjectSettings::register_global_defaults() {\n" + gd_call + "\n}\n" f = open("global_defaults.gen.cpp", "wb") f.write(gd_cpp) @@ -48,7 +48,7 @@ if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ): print("Invalid AES256 encryption key, not 64 bits hex: " + e) f = open("script_encryption_key.gen.cpp", "wb") -f.write("#include \"global_config.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n") +f.write("#include \"project_settings.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n") f.close() diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 694e077f48..69d0ba7851 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "core_bind.h" -#include "core/global_config.h" +#include "core/project_settings.h" #include "geometry.h" #include "io/file_access_compressed.h" #include "io/file_access_encrypted.h" @@ -106,7 +106,7 @@ PoolStringArray _ResourceLoader::get_dependencies(const String &p_path) { bool _ResourceLoader::has(const String &p_path) { - String local_path = GlobalConfig::get_singleton()->localize_path(p_path); + String local_path = ProjectSettings::get_singleton()->localize_path(p_path); return ResourceCache::has(local_path); }; diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp index 0ed44b0cb7..2adc15447a 100644 --- a/core/core_string_names.cpp +++ b/core/core_string_names.cpp @@ -44,6 +44,7 @@ CoreStringNames::CoreStringNames() { _iter_next = StaticCString::create("_iter_next"); _iter_get = StaticCString::create("_iter_get"); get_rid = StaticCString::create("get_rid"); + _custom_features = StaticCString::create("_custom_features"); #ifdef TOOLS_ENABLED _sections_unfolded = StaticCString::create("_sections_unfolded"); #endif diff --git a/core/core_string_names.h b/core/core_string_names.h index 4b4f87a8f0..501185f5b7 100644 --- a/core/core_string_names.h +++ b/core/core_string_names.h @@ -61,6 +61,7 @@ public: StringName _iter_next; StringName _iter_get; StringName get_rid; + StringName _custom_features; #ifdef TOOLS_ENABLED StringName _sections_unfolded; #endif diff --git a/core/global_config.cpp b/core/global_config.cpp deleted file mode 100644 index 76572df2a7..0000000000 --- a/core/global_config.cpp +++ /dev/null @@ -1,970 +0,0 @@ -/*************************************************************************/ -/* globals.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "global_config.h" - -#include "bind/core_bind.h" -#include "io/file_access_network.h" -#include "io/file_access_pack.h" -#include "io/marshalls.h" -#include "os/dir_access.h" -#include "os/file_access.h" -#include "os/keyboard.h" -#include "os/os.h" -#include "variant_parser.h" - -#include - -#define FORMAT_VERSION 3 - -GlobalConfig *GlobalConfig::singleton = NULL; - -GlobalConfig *GlobalConfig::get_singleton() { - - return singleton; -} - -String GlobalConfig::get_resource_path() const { - - return resource_path; -}; - -String GlobalConfig::localize_path(const String &p_path) const { - - if (resource_path == "") - return p_path; //not initialied yet - - if (p_path.begins_with("res://") || p_path.begins_with("user://") || - (p_path.is_abs_path() && !p_path.begins_with(resource_path))) - return p_path.simplify_path(); - - DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - - String path = p_path.replace("\\", "/").simplify_path(); - - if (dir->change_dir(path) == OK) { - - String cwd = dir->get_current_dir(); - cwd = cwd.replace("\\", "/"); - - memdelete(dir); - - if (!cwd.begins_with(resource_path)) { - return p_path; - }; - - return cwd.replace_first(resource_path, "res:/"); - } else { - - memdelete(dir); - - int sep = path.find_last("/"); - if (sep == -1) { - return "res://" + path; - }; - - String parent = path.substr(0, sep); - - String plocal = localize_path(parent); - if (plocal == "") { - return ""; - }; - return plocal + path.substr(sep, path.size() - sep); - }; -} - -void GlobalConfig::set_initial_value(const String &p_name, const Variant &p_value) { - - ERR_FAIL_COND(!props.has(p_name)); - props[p_name].initial = p_value; -} - -String GlobalConfig::globalize_path(const String &p_path) const { - - if (p_path.begins_with("res://")) { - - if (resource_path != "") { - - return p_path.replace("res:/", resource_path); - }; - return p_path.replace("res://", ""); - }; - - return p_path; -} - -bool GlobalConfig::_set(const StringName &p_name, const Variant &p_value) { - - _THREAD_SAFE_METHOD_ - - if (p_value.get_type() == Variant::NIL) - props.erase(p_name); - else { - if (props.has(p_name)) { - if (!props[p_name].overrided) - props[p_name].variant = p_value; - - } else { - props[p_name] = VariantContainer(p_value, last_order++); - } - } - - return true; -} -bool GlobalConfig::_get(const StringName &p_name, Variant &r_ret) const { - - _THREAD_SAFE_METHOD_ - - if (!props.has(p_name)) { - print_line("WARNING: not found: " + String(p_name)); - return false; - } - r_ret = props[p_name].variant; - return true; -} - -struct _VCSort { - - String name; - Variant::Type type; - int order; - int flags; - - bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; } -}; - -void GlobalConfig::_get_property_list(List *p_list) const { - - _THREAD_SAFE_METHOD_ - - Set<_VCSort> vclist; - - for (Map::Element *E = props.front(); E; E = E->next()) { - - const VariantContainer *v = &E->get(); - - if (v->hide_from_editor) - continue; - - _VCSort vc; - vc.name = E->key(); - vc.order = v->order; - vc.type = v->variant.get_type(); - if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) - vc.flags = PROPERTY_USAGE_STORAGE; - else - vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE; - - vclist.insert(vc); - } - - for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { - - if (custom_prop_info.has(E->get().name)) { - PropertyInfo pi = custom_prop_info[E->get().name]; - pi.name = E->get().name; - pi.usage = E->get().flags; - p_list->push_back(pi); - } else - p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags)); - } -} - -bool GlobalConfig::_load_resource_pack(const String &p_pack) { - - if (PackedData::get_singleton()->is_disabled()) - return false; - - bool ok = PackedData::get_singleton()->add_pack(p_pack) == OK; - - if (!ok) - return false; - - //if data.pck is found, all directory access will be from here - DirAccess::make_default(DirAccess::ACCESS_RESOURCES); - using_datapack = true; - - return true; -} - -Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { - - //If looking for files in network, just use network! - - if (FileAccessNetworkClient::get_singleton()) { - - if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://godot.cfb") == OK) { - - _load_settings("res://override.cfg"); - } - - return OK; - } - - String exec_path = OS::get_singleton()->get_executable_path(); - - //Attempt with a passed main pack first - - if (p_main_pack != "") { - - bool ok = _load_resource_pack(p_main_pack); - ERR_FAIL_COND_V(!ok, ERR_CANT_OPEN); - - if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://godot.cfb") == OK) { - //load override from location of the main pack - _load_settings(p_main_pack.get_base_dir().plus_file("override.cfg")); - } - - return OK; - } - - //Attempt with execname.pck - if (exec_path != "") { - - if (_load_resource_pack(exec_path.get_basename() + ".pck")) { - - if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://godot.cfb") == OK) { - //load override from location of executable - _load_settings(exec_path.get_base_dir().plus_file("override.cfg")); - } - - return OK; - } - } - - //Try to use the filesystem for files, according to OS. (only Android -when reading from pck- and iOS use this) - if (OS::get_singleton()->get_resource_dir() != "") { - //OS will call Globals->get_resource_path which will be empty if not overridden! - //if the OS would rather use somewhere else, then it will not be empty. - - resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/"); - if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') - resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end - - // data.pck and data.zip are deprecated and no longer supported, apologies. - // make sure this is loaded from the resource path - - if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://godot.cfb") == OK) { - _load_settings("res://override.cfg"); - } - - return OK; - } - - //Nothing was found, try to find a project.godot somewhere! - - DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - ERR_FAIL_COND_V(!d, ERR_CANT_CREATE); - - d->change_dir(p_path); - - String candidate = d->get_current_dir(); - String current_dir = d->get_current_dir(); - bool found = false; - - while (true) { - //try to load settings in ascending through dirs shape! - - if (_load_settings(current_dir + "/project.godot") == OK || _load_settings_binary(current_dir + "/godot.cfb") == OK) { - - _load_settings(current_dir + "/override.cfg"); - candidate = current_dir; - found = true; - break; - } - - d->change_dir(".."); - if (d->get_current_dir() == current_dir) - break; //not doing anything useful - current_dir = d->get_current_dir(); - } - - resource_path = candidate; - resource_path = resource_path.replace("\\", "/"); // windows path to unix path just in case - memdelete(d); - - if (!found) - return ERR_FILE_NOT_FOUND; - - if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') - resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end - - return OK; -} - -bool GlobalConfig::has(String p_var) const { - - _THREAD_SAFE_METHOD_ - - return props.has(p_var); -} - -void GlobalConfig::set_registering_order(bool p_enable) { - - registering_order = p_enable; -} - -Error GlobalConfig::_load_settings_binary(const String p_path) { - - Error err; - FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err != OK) { - return err; - } - - uint8_t hdr[4]; - f->get_buffer(hdr, 4); - if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') { - - memdelete(f); - ERR_EXPLAIN("Corrupted header in binary godot.cfb (not ECFG)"); - ERR_FAIL_V(ERR_FILE_CORRUPT;) - } - - uint32_t count = f->get_32(); - - for (uint32_t i = 0; i < count; i++) { - - uint32_t slen = f->get_32(); - CharString cs; - cs.resize(slen + 1); - cs[slen] = 0; - f->get_buffer((uint8_t *)cs.ptr(), slen); - String key; - key.parse_utf8(cs.ptr()); - - uint32_t vlen = f->get_32(); - Vector d; - d.resize(vlen); - f->get_buffer(d.ptr(), vlen); - Variant value; - Error err = decode_variant(value, d.ptr(), d.size()); - ERR_EXPLAIN("Error decoding property: " + key); - ERR_CONTINUE(err != OK); - set(key, value); - } - - return OK; -} -Error GlobalConfig::_load_settings(const String p_path) { - - Error err; - FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - - if (!f) - return ERR_CANT_OPEN; - - VariantParser::StreamFile stream; - stream.f = f; - - String assign; - Variant value; - VariantParser::Tag next_tag; - - int lines = 0; - String error_text; - - String section; - - while (true) { - - assign = Variant(); - next_tag.fields.clear(); - next_tag.name = String(); - - err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); - if (err == ERR_FILE_EOF) { - memdelete(f); - return OK; - } else if (err != OK) { - ERR_PRINTS("GlobalConfig::load - " + p_path + ":" + itos(lines) + " error: " + error_text); - memdelete(f); - return err; - } - - if (assign != String()) { - if (section == String() && assign == "config_version") { - int config_version = value; - if (config_version > FORMAT_VERSION) { - memdelete(f); - ERR_FAIL_COND_V(config_version > FORMAT_VERSION, ERR_FILE_CANT_OPEN); - } - } - set(section + "/" + assign, value); - } else if (next_tag.name != String()) { - section = next_tag.name; - } - } - - memdelete(f); - - return OK; -} - -int GlobalConfig::get_order(const String &p_name) const { - - ERR_FAIL_COND_V(!props.has(p_name), -1); - return props[p_name].order; -} - -void GlobalConfig::set_order(const String &p_name, int p_order) { - - ERR_FAIL_COND(!props.has(p_name)); - props[p_name].order = p_order; -} - -void GlobalConfig::set_builtin_order(const String &p_name) { - - ERR_FAIL_COND(!props.has(p_name)); - if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) { - props[p_name].order = last_builtin_order++; - } -} - -void GlobalConfig::clear(const String &p_name) { - - ERR_FAIL_COND(!props.has(p_name)); - props.erase(p_name); -} - -Error GlobalConfig::save() { - - return save_custom(get_resource_path() + "/project.godot"); -} - -Error GlobalConfig::_save_settings_binary(const String &p_file, const Map > &props, const CustomMap &p_custom) { - - Error err; - FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); - if (err != OK) { - - ERR_EXPLAIN("Couldn't save godot.cfb at " + p_file); - ERR_FAIL_COND_V(err, err) - } - - uint8_t hdr[4] = { 'E', 'C', 'F', 'G' }; - file->store_buffer(hdr, 4); - - int count = 0; - - for (Map >::Element *E = props.front(); E; E = E->next()) { - - for (List::Element *F = E->get().front(); F; F = F->next()) { - - count++; - } - } - - file->store_32(count); //store how many properties are saved - - for (Map >::Element *E = props.front(); E; E = E->next()) { - - for (List::Element *F = E->get().front(); F; F = F->next()) { - - String key = F->get(); - if (E->key() != "") - key = E->key() + "/" + key; - Variant value; - if (p_custom.has(key)) - value = p_custom[key]; - else - value = get(key); - - file->store_32(key.length()); - file->store_string(key); - - int len; - Error err = encode_variant(value, NULL, len); - if (err != OK) - memdelete(file); - ERR_FAIL_COND_V(err != OK, ERR_INVALID_DATA); - - Vector buff; - buff.resize(len); - - err = encode_variant(value, &buff[0], len); - if (err != OK) - memdelete(file); - ERR_FAIL_COND_V(err != OK, ERR_INVALID_DATA); - file->store_32(len); - file->store_buffer(buff.ptr(), buff.size()); - } - } - - file->close(); - memdelete(file); - - return OK; -} - -Error GlobalConfig::_save_settings_text(const String &p_file, const Map > &props, const CustomMap &p_custom) { - - Error err; - FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); - - if (err) { - ERR_EXPLAIN("Couldn't save project.godot - " + p_file); - ERR_FAIL_COND_V(err, err) - } - - file->store_string("config_version=" + itos(FORMAT_VERSION) + "\n"); - - for (Map >::Element *E = props.front(); E; E = E->next()) { - - if (E != props.front()) - file->store_string("\n"); - - if (E->key() != "") - file->store_string("[" + E->key() + "]\n\n"); - for (List::Element *F = E->get().front(); F; F = F->next()) { - - String key = F->get(); - if (E->key() != "") - key = E->key() + "/" + key; - Variant value; - if (p_custom.has(key)) - value = p_custom[key]; - else - value = get(key); - - String vstr; - VariantWriter::write_to_string(value, vstr); - file->store_string(F->get() + "=" + vstr + "\n"); - } - } - - file->close(); - memdelete(file); - - return OK; -} - -Error GlobalConfig::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array? - - return save_custom(p_file); -}; - -Error GlobalConfig::save_custom(const String &p_path, const CustomMap &p_custom, const Set &p_ignore_masks) { - - ERR_FAIL_COND_V(p_path == "", ERR_INVALID_PARAMETER); - - Set<_VCSort> vclist; - - for (Map::Element *G = props.front(); G; G = G->next()) { - - const VariantContainer *v = &G->get(); - - if (v->hide_from_editor) - continue; - - if (p_custom.has(G->key())) - continue; - - bool discard = false; - - for (const Set::Element *E = p_ignore_masks.front(); E; E = E->next()) { - - if (String(G->key()).match(E->get())) { - discard = true; - break; - } - } - - if (discard) - continue; - - _VCSort vc; - vc.name = G->key(); //*k; - vc.order = v->order; - vc.type = v->variant.get_type(); - vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE; - if (v->variant == v->initial) - continue; - - vclist.insert(vc); - } - - for (const Map::Element *E = p_custom.front(); E; E = E->next()) { - - _VCSort vc; - vc.name = E->key(); - vc.order = 0xFFFFFFF; - vc.type = E->get().get_type(); - vc.flags = PROPERTY_USAGE_STORAGE; - vclist.insert(vc); - } - - Map > props; - - for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { - - String category = E->get().name; - String name = E->get().name; - - int div = category.find("/"); - - if (div < 0) - category = ""; - else { - - category = category.substr(0, div); - name = name.substr(div + 1, name.size()); - } - props[category].push_back(name); - } - - if (p_path.ends_with(".godot")) - return _save_settings_text(p_path, props, p_custom); - else if (p_path.ends_with(".cfb")) - return _save_settings_binary(p_path, props, p_custom); - else { - - ERR_EXPLAIN("Unknown config file format: " + p_path); - ERR_FAIL_V(ERR_FILE_UNRECOGNIZED); - } - - return OK; - -#if 0 - Error err = file->open(dst_file,FileAccess::WRITE); - if (err) { - memdelete(file); - ERR_EXPLAIN("Couldn't save project.godot"); - ERR_FAIL_COND_V(err,err) - } - - - for(Map >::Element *E=props.front();E;E=E->next()) { - - if (E!=props.front()) - file->store_string("\n"); - - if (E->key()!="") - file->store_string("["+E->key()+"]\n\n"); - for(List::Element *F=E->get().front();F;F=F->next()) { - - String key = F->get(); - if (E->key()!="") - key=E->key()+"/"+key; - Variant value; - - if (p_custom.has(key)) - value=p_custom[key]; - else - value = get(key); - - file->store_string(F->get()+"="+_encode_variant(value)+"\n"); - - } - } - - file->close(); - memdelete(file); - - - return OK; -#endif -} - -Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default) { - - Variant ret; - if (GlobalConfig::get_singleton()->has(p_var)) { - ret = GlobalConfig::get_singleton()->get(p_var); - } else { - GlobalConfig::get_singleton()->set(p_var, p_default); - ret = p_default; - } - GlobalConfig::get_singleton()->set_initial_value(p_var, p_default); - GlobalConfig::get_singleton()->set_builtin_order(p_var); - return ret; -} - -void GlobalConfig::add_singleton(const Singleton &p_singleton) { - - singletons.push_back(p_singleton); - singleton_ptrs[p_singleton.name] = p_singleton.ptr; -} - -Object *GlobalConfig::get_singleton_object(const String &p_name) const { - - const Map::Element *E = singleton_ptrs.find(p_name); - if (!E) - return NULL; - else - return E->get(); -}; - -bool GlobalConfig::has_singleton(const String &p_name) const { - - return get_singleton_object(p_name) != NULL; -}; - -void GlobalConfig::get_singletons(List *p_singletons) { - - for (List::Element *E = singletons.front(); E; E = E->next()) - p_singletons->push_back(E->get()); -} - -Vector GlobalConfig::get_optimizer_presets() const { - - List pi; - GlobalConfig::get_singleton()->get_property_list(&pi); - Vector names; - - for (List::Element *E = pi.front(); E; E = E->next()) { - - if (!E->get().name.begins_with("optimizer_presets/")) - continue; - names.push_back(E->get().name.get_slicec('/', 1)); - } - - names.sort(); - - return names; -} - -void GlobalConfig::_add_property_info_bind(const Dictionary &p_info) { - - ERR_FAIL_COND(!p_info.has("name")); - ERR_FAIL_COND(!p_info.has("type")); - - PropertyInfo pinfo; - pinfo.name = p_info["name"]; - ERR_FAIL_COND(!props.has(pinfo.name)); - pinfo.type = Variant::Type(p_info["type"].operator int()); - ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX); - - if (p_info.has("hint")) - pinfo.hint = PropertyHint(p_info["hint"].operator int()); - if (p_info.has("hint_string")) - pinfo.hint_string = p_info["hint_string"]; - - set_custom_property_info(pinfo.name, pinfo); -} - -void GlobalConfig::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) { - - ERR_FAIL_COND(!props.has(p_prop)); - custom_prop_info[p_prop] = p_info; - custom_prop_info[p_prop].name = p_prop; -} - -void GlobalConfig::set_disable_platform_override(bool p_disable) { - - disable_platform_override = p_disable; -} - -bool GlobalConfig::is_using_datapack() const { - - return using_datapack; -} - -bool GlobalConfig::property_can_revert(const String &p_name) { - - if (!props.has(p_name)) - return false; - - return props[p_name].initial != props[p_name].variant; -} - -Variant GlobalConfig::property_get_revert(const String &p_name) { - - if (!props.has(p_name)) - return Variant(); - - return props[p_name].initial; -} - -void GlobalConfig::_bind_methods() { - - ClassDB::bind_method(D_METHOD("has", "name"), &GlobalConfig::has); - ClassDB::bind_method(D_METHOD("set_order", "name", "pos"), &GlobalConfig::set_order); - ClassDB::bind_method(D_METHOD("get_order", "name"), &GlobalConfig::get_order); - ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &GlobalConfig::set_initial_value); - ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &GlobalConfig::_add_property_info_bind); - ClassDB::bind_method(D_METHOD("clear", "name"), &GlobalConfig::clear); - ClassDB::bind_method(D_METHOD("localize_path", "path"), &GlobalConfig::localize_path); - ClassDB::bind_method(D_METHOD("globalize_path", "path"), &GlobalConfig::globalize_path); - ClassDB::bind_method(D_METHOD("save"), &GlobalConfig::save); - ClassDB::bind_method(D_METHOD("has_singleton", "name"), &GlobalConfig::has_singleton); - ClassDB::bind_method(D_METHOD("get_singleton", "name"), &GlobalConfig::get_singleton_object); - ClassDB::bind_method(D_METHOD("load_resource_pack", "pack"), &GlobalConfig::_load_resource_pack); - ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &GlobalConfig::property_can_revert); - ClassDB::bind_method(D_METHOD("property_get_revert:Variant", "name"), &GlobalConfig::property_get_revert); - - ClassDB::bind_method(D_METHOD("save_custom", "file"), &GlobalConfig::_save_custom_bnd); -} - -GlobalConfig::GlobalConfig() { - - singleton = this; - last_order = NO_BUILTIN_ORDER_BASE; - last_builtin_order = 0; - disable_platform_override = false; - registering_order = true; - - Array va; - Ref key; - Ref joyb; - - GLOBAL_DEF("application/config/name", ""); - GLOBAL_DEF("application/run/main_scene", ""); - custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "tscn,scn,res"); - GLOBAL_DEF("application/run/disable_stdout", false); - GLOBAL_DEF("application/run/disable_stderr", false); - GLOBAL_DEF("application/config/use_shared_user_dir", true); - - key.instance(); - key->set_scancode(KEY_RETURN); - va.push_back(key); - key.instance(); - key->set_scancode(KEY_ENTER); - va.push_back(key); - key.instance(); - key->set_scancode(KEY_SPACE); - va.push_back(key); - joyb.instance(); - joyb->set_button_index(JOY_BUTTON_0); - va.push_back(joyb); - GLOBAL_DEF("input/ui_accept", va); - input_presets.push_back("input/ui_accept"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_SPACE); - va.push_back(key); - joyb.instance(); - joyb->set_button_index(JOY_BUTTON_3); - va.push_back(joyb); - GLOBAL_DEF("input/ui_select", va); - input_presets.push_back("input/ui_select"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_ESCAPE); - va.push_back(key); - joyb.instance(); - joyb->set_button_index(JOY_BUTTON_1); - va.push_back(joyb); - GLOBAL_DEF("input/ui_cancel", va); - input_presets.push_back("input/ui_cancel"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_TAB); - va.push_back(key); - GLOBAL_DEF("input/ui_focus_next", va); - input_presets.push_back("input/ui_focus_next"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_TAB); - key->set_shift(true); - va.push_back(key); - GLOBAL_DEF("input/ui_focus_prev", va); - input_presets.push_back("input/ui_focus_prev"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_LEFT); - va.push_back(key); - joyb.instance(); - joyb->set_button_index(JOY_DPAD_LEFT); - va.push_back(joyb); - GLOBAL_DEF("input/ui_left", va); - input_presets.push_back("input/ui_left"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_RIGHT); - va.push_back(key); - joyb.instance(); - joyb->set_button_index(JOY_DPAD_RIGHT); - va.push_back(joyb); - GLOBAL_DEF("input/ui_right", va); - input_presets.push_back("input/ui_right"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_UP); - va.push_back(key); - joyb.instance(); - joyb->set_button_index(JOY_DPAD_UP); - va.push_back(joyb); - GLOBAL_DEF("input/ui_up", va); - input_presets.push_back("input/ui_up"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_DOWN); - va.push_back(key); - joyb.instance(); - joyb->set_button_index(JOY_DPAD_DOWN); - va.push_back(joyb); - GLOBAL_DEF("input/ui_down", va); - input_presets.push_back("input/ui_down"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_PAGEUP); - va.push_back(key); - GLOBAL_DEF("input/ui_page_up", va); - input_presets.push_back("input/ui_page_up"); - - va = Array(); - key.instance(); - key->set_scancode(KEY_PAGEDOWN); - va.push_back(key); - GLOBAL_DEF("input/ui_page_down", va); - input_presets.push_back("input/ui_page_down"); - - //GLOBAL_DEF("display/window/handheld/orientation", "landscape"); - - custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor"); - custom_prop_info["rendering/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded"); - custom_prop_info["physics/2d/thread_model"] = PropertyInfo(Variant::INT, "physics/2d/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded"); - - GLOBAL_DEF("debug/settings/profiler/max_functions", 16384); - - //assigning here, because using GLOBAL_GET on every block for compressing can be slow - Compression::zstd_level = GLOBAL_DEF("compression/formats/zstd/compression_level", 3); - custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"); - Compression::zlib_level = GLOBAL_DEF("compression/formats/zlib/compression_level", Z_DEFAULT_COMPRESSION); - custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); - Compression::gzip_level = GLOBAL_DEF("compression/formats/gzip/compression_level", Z_DEFAULT_COMPRESSION); - custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); - - using_datapack = false; -} - -GlobalConfig::~GlobalConfig() { - - singleton = NULL; -} diff --git a/core/global_config.h b/core/global_config.h deleted file mode 100644 index 30c77bbc27..0000000000 --- a/core/global_config.h +++ /dev/null @@ -1,170 +0,0 @@ -/*************************************************************************/ -/* globals.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef GLOBAL_CONFIG_H -#define GLOBAL_CONFIG_H - -#include "object.h" -#include "os/thread_safe.h" -#include "set.h" -/** - @author Juan Linietsky -*/ - -class GlobalConfig : public Object { - - GDCLASS(GlobalConfig, Object); - _THREAD_SAFE_CLASS_ - -public: - typedef Map CustomMap; - - struct Singleton { - StringName name; - Object *ptr; - Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) { - name = p_name; - ptr = p_ptr; - } - }; - -protected: - enum { - //properties that are not for built in values begin from this value, so builtin ones are displayed first - NO_BUILTIN_ORDER_BASE = 1 << 16 - }; - - struct VariantContainer { - int order; - bool persist; - Variant variant; - Variant initial; - bool hide_from_editor; - bool overrided; - VariantContainer() { - order = 0; - hide_from_editor = false; - persist = false; - overrided = false; - } - VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) { - variant = p_variant; - order = p_order; - hide_from_editor = false; - persist = p_persist; - overrided = false; - } - }; - - bool registering_order; - int last_order; - int last_builtin_order; - Map props; - String resource_path; - Map custom_prop_info; - bool disable_platform_override; - bool using_datapack; - List input_presets; - - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; - - static GlobalConfig *singleton; - - Error _load_settings(const String p_path); - Error _load_settings_binary(const String p_path); - - Error _save_settings_text(const String &p_file, const Map > &props, const CustomMap &p_custom = CustomMap()); - Error _save_settings_binary(const String &p_file, const Map > &props, const CustomMap &p_custom = CustomMap()); - - List singletons; - Map singleton_ptrs; - - Error _save_custom_bnd(const String &p_file); - - bool _load_resource_pack(const String &p_pack); - - void _add_property_info_bind(const Dictionary &p_info); - -protected: - static void _bind_methods(); - -public: - bool has(String p_var) const; - String localize_path(const String &p_path) const; - String globalize_path(const String &p_path) const; - - void set_initial_value(const String &p_name, const Variant &p_value); - bool property_can_revert(const String &p_name); - Variant property_get_revert(const String &p_name); - - String get_resource_path() const; - - static GlobalConfig *get_singleton(); - - void clear(const String &p_name); - int get_order(const String &p_name) const; - void set_order(const String &p_name, int p_order); - void set_builtin_order(const String &p_name); - - Error setup(const String &p_path, const String &p_main_pack); - - Error save_custom(const String &p_path = "", const CustomMap &p_custom = CustomMap(), const Set &p_ignore_masks = Set()); - Error save(); - void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info); - - void add_singleton(const Singleton &p_singleton); - void get_singletons(List *p_singletons); - - bool has_singleton(const String &p_name) const; - - Vector get_optimizer_presets() const; - - List get_input_presets() const { return input_presets; } - - void set_disable_platform_override(bool p_disable); - Object *get_singleton_object(const String &p_name) const; - - void register_global_defaults(); - - bool is_using_datapack() const; - - void set_registering_order(bool p_registering); - - GlobalConfig(); - ~GlobalConfig(); -}; - -//not a macro any longer -Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default); -#define GLOBAL_DEF(m_var, m_value) _GLOBAL_DEF(m_var, m_value) -#define GLOBAL_GET(m_var) GlobalConfig::get_singleton()->get(m_var) - -#endif diff --git a/core/input_map.cpp b/core/input_map.cpp index 422ebd2956..1abe019167 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "input_map.h" -#include "global_config.h" +#include "project_settings.h" #include "os/keyboard.h" InputMap *InputMap::singleton = NULL; @@ -189,7 +189,7 @@ void InputMap::load_from_globals() { input_map.clear(); List pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); + ProjectSettings::get_singleton()->get_property_list(&pinfo); for (List::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); @@ -201,7 +201,7 @@ void InputMap::load_from_globals() { add_action(name); - Array va = GlobalConfig::get_singleton()->get(pi.name); + Array va = ProjectSettings::get_singleton()->get(pi.name); for (int i = 0; i < va.size(); i++) { diff --git a/core/io/compression.cpp b/core/io/compression.cpp index b0f5448b6c..ca35ece8f5 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "compression.h" -#include "global_config.h" +#include "project_settings.h" #include "os/copymem.h" #include "zip_io.h" diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 32ea4ce096..2197b187eb 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "file_access_memory.h" -#include "global_config.h" +#include "project_settings.h" #include "map.h" #include "os/copymem.h" #include "os/dir_access.h" @@ -43,8 +43,8 @@ void FileAccessMemory::register_file(String p_name, Vector p_data) { } String name; - if (GlobalConfig::get_singleton()) - name = GlobalConfig::get_singleton()->globalize_path(p_name); + if (ProjectSettings::get_singleton()) + name = ProjectSettings::get_singleton()->globalize_path(p_name); else name = p_name; //name = DirAccess::normalize_path(name); diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 50e78899fb..46457d1425 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "file_access_network.h" -#include "global_config.h" +#include "project_settings.h" #include "io/ip.h" #include "marshalls.h" #include "os/os.h" diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 93682e6b8a..81446a3886 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "packet_peer.h" -#include "global_config.h" +#include "project_settings.h" #include "io/marshalls.h" /* helpers / binders */ diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 728cd5d4ff..602cbe6f30 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "resource_format_binary.h" -#include "global_config.h" +#include "project_settings.h" #include "image.h" #include "io/file_access_compressed.h" #include "io/marshalls.h" @@ -317,7 +317,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { if (path.find("://") == -1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path = GlobalConfig::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); + path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); } if (remaps.find(path)) { @@ -346,7 +346,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { if (path.find("://") == -1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path = GlobalConfig::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); + path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); } RES res = ResourceLoader::load(path, type); @@ -1017,7 +1017,7 @@ Ref ResourceFormatLoaderBinary::load_interactive(cons } Ref ria = memnew(ResourceInteractiveLoaderBinary); - ria->local_path = GlobalConfig::get_singleton()->localize_path(p_path); + ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path); ria->res_path = ria->local_path; //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); ria->open(f); @@ -1065,7 +1065,7 @@ void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List ria = memnew(ResourceInteractiveLoaderBinary); - ria->local_path = GlobalConfig::get_singleton()->localize_path(p_path); + ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path); ria->res_path = ria->local_path; //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); ria->get_dependencies(f, p_dependencies, p_add_types); @@ -1152,7 +1152,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons } Ref ria = memnew(ResourceInteractiveLoaderBinary); - ria->local_path = GlobalConfig::get_singleton()->localize_path(p_path); + ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path); ria->res_path = ria->local_path; ria->remaps = p_map; //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); @@ -1281,7 +1281,7 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const } Ref ria = memnew(ResourceInteractiveLoaderBinary); - ria->local_path = GlobalConfig::get_singleton()->localize_path(p_path); + ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path); ria->res_path = ria->local_path; //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); String r = ria->recognize(f); @@ -1984,7 +1984,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p Error ResourceFormatSaverBinary::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - String local_path = GlobalConfig::get_singleton()->localize_path(p_path); + String local_path = ProjectSettings::get_singleton()->localize_path(p_path); ResourceFormatSaverBinaryInstance saver; return saver.save(local_path, p_resource, p_flags); } diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp index ffb27bc26a..61da4f3350 100644 --- a/core/io/resource_import.cpp +++ b/core/io/resource_import.cpp @@ -49,6 +49,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy int lines = 0; String error_text; + bool path_found = false; //first match must have priority while (true) { assign = Variant(); @@ -66,14 +67,16 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy } if (assign != String()) { - if (assign.begins_with("path.") && r_path_and_type.path == String()) { + if (!path_found && assign.begins_with("path.") && r_path_and_type.path == String()) { String feature = assign.get_slicec('.', 1); if (OS::get_singleton()->check_feature_support(feature)) { r_path_and_type.path = value; + path_found = true; //first match must have priority } - } else if (assign == "path") { + } else if (!path_found && assign == "path") { r_path_and_type.path = value; + path_found = true; //first match must have priority } else if (assign == "type") { r_path_and_type.type = value; } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index bb7be38413..57acb6c754 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "resource_loader.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_import.h" #include "os/file_access.h" #include "os/os.h" @@ -166,7 +166,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p if (p_path.is_rel_path()) local_path = "res://" + p_path; else - local_path = GlobalConfig::get_singleton()->localize_path(p_path); + local_path = ProjectSettings::get_singleton()->localize_path(p_path); bool xl_remapped = false; String path = _path_remap(local_path, &xl_remapped); @@ -233,7 +233,7 @@ Ref ResourceLoader::load_interactive(const String &p_ if (p_path.is_rel_path()) local_path = "res://" + p_path; else - local_path = GlobalConfig::get_singleton()->localize_path(p_path); + local_path = ProjectSettings::get_singleton()->localize_path(p_path); bool xl_remapped = false; String path = _path_remap(local_path, &xl_remapped); @@ -304,7 +304,7 @@ void ResourceLoader::get_dependencies(const String &p_path, List *p_depe if (path.is_rel_path()) local_path = "res://" + path; else - local_path = GlobalConfig::get_singleton()->localize_path(path); + local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { @@ -327,7 +327,7 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Maplocalize_path(path); + local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { @@ -350,7 +350,7 @@ String ResourceLoader::get_resource_type(const String &p_path) { if (p_path.is_rel_path()) local_path = "res://" + p_path; else - local_path = GlobalConfig::get_singleton()->localize_path(p_path); + local_path = ProjectSettings::get_singleton()->localize_path(p_path); for (int i = 0; i < loader_count; i++) { @@ -430,7 +430,7 @@ void ResourceLoader::reload_translation_remaps() { void ResourceLoader::load_translation_remaps() { - Dictionary remaps = GlobalConfig::get_singleton()->get("locale/translation_remaps"); + Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); List keys; remaps.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 8592346a72..58913b80cc 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "resource_saver.h" -#include "global_config.h" +#include "project_settings.h" #include "os/file_access.h" #include "resource_loader.h" #include "script_language.h" @@ -64,7 +64,7 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t String old_path = p_resource->get_path(); - String local_path = GlobalConfig::get_singleton()->localize_path(p_path); + String local_path = ProjectSettings::get_singleton()->localize_path(p_path); RES rwcopy = p_resource; if (p_flags & FLAG_CHANGE_PATH) diff --git a/core/message_queue.cpp b/core/message_queue.cpp index 1c980a56e3..93d0b0730a 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "message_queue.h" -#include "global_config.h" +#include "project_settings.h" #include "script_language.h" MessageQueue *MessageQueue::singleton = NULL; diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index aa03b764ef..484942bad5 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "dir_access.h" -#include "global_config.h" +#include "project_settings.h" #include "os/file_access.h" #include "os/memory.h" #include "os/os.h" @@ -37,7 +37,7 @@ String DirAccess::_get_root_path() const { switch (_access_type) { - case ACCESS_RESOURCES: return GlobalConfig::get_singleton()->get_resource_path(); + case ACCESS_RESOURCES: return ProjectSettings::get_singleton()->get_resource_path(); case ACCESS_USERDATA: return OS::get_singleton()->get_data_dir(); default: return ""; } @@ -200,10 +200,10 @@ String DirAccess::fix_path(String p_path) const { case ACCESS_RESOURCES: { - if (GlobalConfig::get_singleton()) { + if (ProjectSettings::get_singleton()) { if (p_path.begins_with("res://")) { - String resource_path = GlobalConfig::get_singleton()->get_resource_path(); + String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { return p_path.replace_first("res:/", resource_path); diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 805b66b983..2bb676381f 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -31,7 +31,7 @@ #include "core/io/file_access_pack.h" #include "core/io/marshalls.h" -#include "global_config.h" +#include "project_settings.h" #include "os/os.h" #include "thirdparty/misc/md5.h" @@ -135,10 +135,10 @@ String FileAccess::fix_path(const String &p_path) const { case ACCESS_RESOURCES: { - if (GlobalConfig::get_singleton()) { + if (ProjectSettings::get_singleton()) { if (r_path.begins_with("res://")) { - String resource_path = GlobalConfig::get_singleton()->get_resource_path(); + String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { return r_path.replace("res:/", resource_path); diff --git a/core/os/input.cpp b/core/os/input.cpp index 587340fe91..18d644668c 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "input.h" -#include "global_config.h" +#include "project_settings.h" #include "input_map.h" #include "os/os.h" Input *Input::singleton = NULL; @@ -101,7 +101,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); + ProjectSettings::get_singleton()->get_property_list(&pinfo); for (List::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 1c575aa970..0a07b6b2b7 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -103,7 +103,7 @@ bool InputEvent::is_action_type() const { if (String(p_method) == "is_action" && p_argidx == 0) { List pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); + ProjectSettings::get_singleton()->get_property_list(&pinfo); for (List::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); diff --git a/core/os/os.cpp b/core/os/os.cpp index 48463722cf..5a9766891d 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -30,9 +30,9 @@ #include "os.h" #include "dir_access.h" -#include "global_config.h" #include "input.h" #include "os/file_access.h" +#include "project_settings.h" #include @@ -260,7 +260,7 @@ String OS::get_locale() const { String OS::get_resource_dir() const { - return GlobalConfig::get_singleton()->get_resource_path(); + return ProjectSettings::get_singleton()->get_resource_path(); } String OS::get_system_dir(SystemDir p_dir) const { @@ -269,7 +269,7 @@ String OS::get_system_dir(SystemDir p_dir) const { } String OS::get_safe_application_name() const { - String an = GlobalConfig::get_singleton()->get("application/config/name"); + String an = ProjectSettings::get_singleton()->get("application/config/name"); Vector invalid_char = String("\\ / : * ? \" < > |").split(" "); for (int i = 0; i < invalid_char.size(); i++) { an = an.replace(invalid_char[i], "-"); @@ -494,6 +494,24 @@ int OS::get_power_percent_left() { return -1; } +bool OS::check_feature_support(const String &p_feature) { + + if (p_feature == get_name()) + return true; +#ifdef DEBUG_ENABLED + if (p_feature == "debug") + return true; +#else + if (p_feature == "release") + return true; +#endif + + if (_check_internal_feature_support(p_feature)) + return true; + + return false; +} + OS::OS() { last_error = NULL; singleton = this; diff --git a/core/os/os.h b/core/os/os.h index cafd1f4e14..362fec8a9e 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -109,6 +109,7 @@ protected: virtual void set_cmdline(const char *p_execpath, const List &p_args); void _ensure_data_dir(); + virtual bool _check_internal_feature_support(const String &p_feature) = 0; public: typedef int64_t ProcessID; @@ -408,7 +409,7 @@ public: virtual int get_power_seconds_left(); virtual int get_power_percent_left(); - virtual bool check_feature_support(const String &p_feature) = 0; + bool check_feature_support(const String &p_feature); bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); diff --git a/core/project_settings.cpp b/core/project_settings.cpp new file mode 100644 index 0000000000..1a0a50a10f --- /dev/null +++ b/core/project_settings.cpp @@ -0,0 +1,1038 @@ +/*************************************************************************/ +/* globals.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "project_settings.h" + +#include "bind/core_bind.h" +#include "core_string_names.h" +#include "io/file_access_network.h" +#include "io/file_access_pack.h" +#include "io/marshalls.h" +#include "os/dir_access.h" +#include "os/file_access.h" +#include "os/keyboard.h" +#include "os/os.h" +#include "variant_parser.h" +#include + +#define FORMAT_VERSION 3 + +ProjectSettings *ProjectSettings::singleton = NULL; + +ProjectSettings *ProjectSettings::get_singleton() { + + return singleton; +} + +String ProjectSettings::get_resource_path() const { + + return resource_path; +}; + +String ProjectSettings::localize_path(const String &p_path) const { + + if (resource_path == "") + return p_path; //not initialied yet + + if (p_path.begins_with("res://") || p_path.begins_with("user://") || + (p_path.is_abs_path() && !p_path.begins_with(resource_path))) + return p_path.simplify_path(); + + DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + + String path = p_path.replace("\\", "/").simplify_path(); + + if (dir->change_dir(path) == OK) { + + String cwd = dir->get_current_dir(); + cwd = cwd.replace("\\", "/"); + + memdelete(dir); + + if (!cwd.begins_with(resource_path)) { + return p_path; + }; + + return cwd.replace_first(resource_path, "res:/"); + } else { + + memdelete(dir); + + int sep = path.find_last("/"); + if (sep == -1) { + return "res://" + path; + }; + + String parent = path.substr(0, sep); + + String plocal = localize_path(parent); + if (plocal == "") { + return ""; + }; + return plocal + path.substr(sep, path.size() - sep); + }; +} + +void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) { + + ERR_FAIL_COND(!props.has(p_name)); + props[p_name].initial = p_value; +} + +String ProjectSettings::globalize_path(const String &p_path) const { + + if (p_path.begins_with("res://")) { + + if (resource_path != "") { + + return p_path.replace("res:/", resource_path); + }; + return p_path.replace("res://", ""); + }; + + return p_path; +} + +bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { + + _THREAD_SAFE_METHOD_ + + if (p_value.get_type() == Variant::NIL) + props.erase(p_name); + else { + + if (p_name == CoreStringNames::get_singleton()->_custom_features) { + Vector custom_feature_array = p_value; + for (int i = 0; i < custom_feature_array.size(); i++) { + + custom_features.insert(custom_feature_array[i]); + } + return true; + } + + if (!disable_feature_overrides) { + int dot = p_name.operator String().find("."); + if (dot != -1) { + Vector s = p_name.operator String().split("."); + + bool override_valid = false; + for (int i = 1; i < s.size(); i++) { + String feature = s[i].strip_edges(); + if (OS::get_singleton()->check_feature_support(feature) || custom_features.has(feature)) { + override_valid = true; + break; + } + } + + if (override_valid) { + + feature_overrides[s[0]] = p_name; + } + } + } + + if (props.has(p_name)) { + if (!props[p_name].overrided) + props[p_name].variant = p_value; + + } else { + props[p_name] = VariantContainer(p_value, last_order++); + } + } + + return true; +} +bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const { + + _THREAD_SAFE_METHOD_ + + StringName name = p_name; + if (!disable_feature_overrides && feature_overrides.has(name)) { + name = feature_overrides[name]; + } + if (!props.has(name)) { + print_line("WARNING: not found: " + String(name)); + return false; + } + r_ret = props[name].variant; + return true; +} + +struct _VCSort { + + String name; + Variant::Type type; + int order; + int flags; + + bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; } +}; + +void ProjectSettings::_get_property_list(List *p_list) const { + + _THREAD_SAFE_METHOD_ + + Set<_VCSort> vclist; + + for (Map::Element *E = props.front(); E; E = E->next()) { + + const VariantContainer *v = &E->get(); + + if (v->hide_from_editor) + continue; + + _VCSort vc; + vc.name = E->key(); + vc.order = v->order; + vc.type = v->variant.get_type(); + if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) + vc.flags = PROPERTY_USAGE_STORAGE; + else + vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE; + + vclist.insert(vc); + } + + for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { + + String prop_info_name = E->get().name; + int dot = prop_info_name.find("."); + if (dot != -1) + prop_info_name = prop_info_name.substr(0, dot); + + if (custom_prop_info.has(prop_info_name)) { + PropertyInfo pi = custom_prop_info[prop_info_name]; + pi.name = E->get().name; + pi.usage = E->get().flags; + p_list->push_back(pi); + } else + p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags)); + } +} + +bool ProjectSettings::_load_resource_pack(const String &p_pack) { + + if (PackedData::get_singleton()->is_disabled()) + return false; + + bool ok = PackedData::get_singleton()->add_pack(p_pack) == OK; + + if (!ok) + return false; + + //if data.pck is found, all directory access will be from here + DirAccess::make_default(DirAccess::ACCESS_RESOURCES); + using_datapack = true; + + return true; +} + +Error ProjectSettings::setup(const String &p_path, const String &p_main_pack) { + + //If looking for files in network, just use network! + + if (FileAccessNetworkClient::get_singleton()) { + + if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) { + + _load_settings("res://override.cfg"); + } + + return OK; + } + + String exec_path = OS::get_singleton()->get_executable_path(); + + //Attempt with a passed main pack first + + if (p_main_pack != "") { + + bool ok = _load_resource_pack(p_main_pack); + ERR_FAIL_COND_V(!ok, ERR_CANT_OPEN); + + if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) { + //load override from location of the main pack + _load_settings(p_main_pack.get_base_dir().plus_file("override.cfg")); + } + + return OK; + } + + //Attempt with execname.pck + if (exec_path != "") { + + if (_load_resource_pack(exec_path.get_basename() + ".pck")) { + + if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) { + //load override from location of executable + _load_settings(exec_path.get_base_dir().plus_file("override.cfg")); + } + + return OK; + } + } + + //Try to use the filesystem for files, according to OS. (only Android -when reading from pck- and iOS use this) + if (OS::get_singleton()->get_resource_dir() != "") { + //OS will call Globals->get_resource_path which will be empty if not overridden! + //if the OS would rather use somewhere else, then it will not be empty. + + resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/"); + if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') + resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end + + // data.pck and data.zip are deprecated and no longer supported, apologies. + // make sure this is loaded from the resource path + + if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) { + _load_settings("res://override.cfg"); + } + + return OK; + } + + //Nothing was found, try to find a project.godot somewhere! + + DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + ERR_FAIL_COND_V(!d, ERR_CANT_CREATE); + + d->change_dir(p_path); + + String candidate = d->get_current_dir(); + String current_dir = d->get_current_dir(); + bool found = false; + + while (true) { + //try to load settings in ascending through dirs shape! + + if (_load_settings(current_dir + "/project.godot") == OK || _load_settings_binary(current_dir + "/project.binary") == OK) { + + _load_settings(current_dir + "/override.cfg"); + candidate = current_dir; + found = true; + break; + } + + d->change_dir(".."); + if (d->get_current_dir() == current_dir) + break; //not doing anything useful + current_dir = d->get_current_dir(); + } + + resource_path = candidate; + resource_path = resource_path.replace("\\", "/"); // windows path to unix path just in case + memdelete(d); + + if (!found) + return ERR_FILE_NOT_FOUND; + + if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') + resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end + + return OK; +} + +bool ProjectSettings::has(String p_var) const { + + _THREAD_SAFE_METHOD_ + + return props.has(p_var); +} + +void ProjectSettings::set_registering_order(bool p_enable) { + + registering_order = p_enable; +} + +Error ProjectSettings::_load_settings_binary(const String p_path) { + + Error err; + FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); + if (err != OK) { + return err; + } + + uint8_t hdr[4]; + f->get_buffer(hdr, 4); + if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') { + + memdelete(f); + ERR_EXPLAIN("Corrupted header in binary project.binary (not ECFG)"); + ERR_FAIL_V(ERR_FILE_CORRUPT;) + } + + uint32_t count = f->get_32(); + + for (uint32_t i = 0; i < count; i++) { + + uint32_t slen = f->get_32(); + CharString cs; + cs.resize(slen + 1); + cs[slen] = 0; + f->get_buffer((uint8_t *)cs.ptr(), slen); + String key; + key.parse_utf8(cs.ptr()); + + uint32_t vlen = f->get_32(); + Vector d; + d.resize(vlen); + f->get_buffer(d.ptr(), vlen); + Variant value; + Error err = decode_variant(value, d.ptr(), d.size()); + ERR_EXPLAIN("Error decoding property: " + key); + ERR_CONTINUE(err != OK); + set(key, value); + } + + return OK; +} +Error ProjectSettings::_load_settings(const String p_path) { + + Error err; + FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); + + if (!f) + return ERR_CANT_OPEN; + + VariantParser::StreamFile stream; + stream.f = f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines = 0; + String error_text; + + String section; + + while (true) { + + assign = Variant(); + next_tag.fields.clear(); + next_tag.name = String(); + + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + if (err == ERR_FILE_EOF) { + memdelete(f); + return OK; + } else if (err != OK) { + ERR_PRINTS("ProjectSettings::load - " + p_path + ":" + itos(lines) + " error: " + error_text); + memdelete(f); + return err; + } + + if (assign != String()) { + if (section == String() && assign == "config_version") { + int config_version = value; + if (config_version > FORMAT_VERSION) { + memdelete(f); + ERR_FAIL_COND_V(config_version > FORMAT_VERSION, ERR_FILE_CANT_OPEN); + } + } + set(section + "/" + assign, value); + } else if (next_tag.name != String()) { + section = next_tag.name; + } + } + + memdelete(f); + + return OK; +} + +int ProjectSettings::get_order(const String &p_name) const { + + ERR_FAIL_COND_V(!props.has(p_name), -1); + return props[p_name].order; +} + +void ProjectSettings::set_order(const String &p_name, int p_order) { + + ERR_FAIL_COND(!props.has(p_name)); + props[p_name].order = p_order; +} + +void ProjectSettings::set_builtin_order(const String &p_name) { + + ERR_FAIL_COND(!props.has(p_name)); + if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) { + props[p_name].order = last_builtin_order++; + } +} + +void ProjectSettings::clear(const String &p_name) { + + ERR_FAIL_COND(!props.has(p_name)); + props.erase(p_name); +} + +Error ProjectSettings::save() { + + return save_custom(get_resource_path() + "/project.godot"); +} + +Error ProjectSettings::_save_settings_binary(const String &p_file, const Map > &props, const CustomMap &p_custom, const String &p_custom_features) { + + Error err; + FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); + if (err != OK) { + + ERR_EXPLAIN("Couldn't save project.binary at " + p_file); + ERR_FAIL_COND_V(err, err) + } + + uint8_t hdr[4] = { 'E', 'C', 'F', 'G' }; + file->store_buffer(hdr, 4); + + int count = 0; + + for (Map >::Element *E = props.front(); E; E = E->next()) { + + for (List::Element *F = E->get().front(); F; F = F->next()) { + + count++; + } + } + + if (p_custom_features != String()) { + file->store_32(count + 1); + //store how many properties are saved, add one for custom featuers, which must always go first + String key = CoreStringNames::get_singleton()->_custom_features; + file->store_32(key.length()); + file->store_string(key); + + int len; + Error err = encode_variant(p_custom_features, NULL, len); + if (err != OK) { + memdelete(file); + ERR_FAIL_V(err); + } + + Vector buff; + buff.resize(len); + + err = encode_variant(p_custom_features, &buff[0], len); + if (err != OK) { + memdelete(file); + ERR_FAIL_V(err); + } + file->store_32(len); + file->store_buffer(buff.ptr(), buff.size()); + + } else { + file->store_32(count); //store how many properties are saved + } + + for (Map >::Element *E = props.front(); E; E = E->next()) { + + for (List::Element *F = E->get().front(); F; F = F->next()) { + + String key = F->get(); + if (E->key() != "") + key = E->key() + "/" + key; + Variant value; + if (p_custom.has(key)) + value = p_custom[key]; + else + value = get(key); + + file->store_32(key.length()); + file->store_string(key); + + int len; + Error err = encode_variant(value, NULL, len); + if (err != OK) + memdelete(file); + ERR_FAIL_COND_V(err != OK, ERR_INVALID_DATA); + + Vector buff; + buff.resize(len); + + err = encode_variant(value, &buff[0], len); + if (err != OK) + memdelete(file); + ERR_FAIL_COND_V(err != OK, ERR_INVALID_DATA); + file->store_32(len); + file->store_buffer(buff.ptr(), buff.size()); + } + } + + file->close(); + memdelete(file); + + return OK; +} + +Error ProjectSettings::_save_settings_text(const String &p_file, const Map > &props, const CustomMap &p_custom, const String &p_custom_features) { + + Error err; + FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); + + if (err) { + ERR_EXPLAIN("Couldn't save project.godot - " + p_file); + ERR_FAIL_COND_V(err, err) + } + + file->store_string("config_version=" + itos(FORMAT_VERSION) + "\n"); + if (p_custom_features != String()) + file->store_string("_custom_featores=\"" + p_custom_features + "\"\n"); + + for (Map >::Element *E = props.front(); E; E = E->next()) { + + if (E != props.front()) + file->store_string("\n"); + + if (E->key() != "") + file->store_string("[" + E->key() + "]\n\n"); + for (List::Element *F = E->get().front(); F; F = F->next()) { + + String key = F->get(); + if (E->key() != "") + key = E->key() + "/" + key; + Variant value; + if (p_custom.has(key)) + value = p_custom[key]; + else + value = get(key); + + String vstr; + VariantWriter::write_to_string(value, vstr); + file->store_string(F->get() + "=" + vstr + "\n"); + } + } + + file->close(); + memdelete(file); + + return OK; +} + +Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array? + + return save_custom(p_file); +}; + +Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector &p_custom_features) { + + ERR_FAIL_COND_V(p_path == "", ERR_INVALID_PARAMETER); + + Set<_VCSort> vclist; + + for (Map::Element *G = props.front(); G; G = G->next()) { + + const VariantContainer *v = &G->get(); + + if (v->hide_from_editor) + continue; + + if (p_custom.has(G->key())) + continue; + + _VCSort vc; + vc.name = G->key(); //*k; + vc.order = v->order; + vc.type = v->variant.get_type(); + vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE; + if (v->variant == v->initial) + continue; + + vclist.insert(vc); + } + + for (const Map::Element *E = p_custom.front(); E; E = E->next()) { + + _VCSort vc; + vc.name = E->key(); + vc.order = 0xFFFFFFF; + vc.type = E->get().get_type(); + vc.flags = PROPERTY_USAGE_STORAGE; + vclist.insert(vc); + } + + Map > props; + + for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { + + String category = E->get().name; + String name = E->get().name; + + int div = category.find("/"); + + if (div < 0) + category = ""; + else { + + category = category.substr(0, div); + name = name.substr(div + 1, name.size()); + } + props[category].push_back(name); + } + + String custom_features; + + for (int i = 0; i < p_custom_features.size(); i++) { + if (i > 0) + custom_features += ","; + + String f = p_custom_features[i].strip_edges().replace("\"", ""); + custom_features += f; + } + + if (p_path.ends_with(".godot")) + return _save_settings_text(p_path, props, p_custom, custom_features); + else if (p_path.ends_with(".binary")) + return _save_settings_binary(p_path, props, p_custom, custom_features); + else { + + ERR_EXPLAIN("Unknown config file format: " + p_path); + ERR_FAIL_V(ERR_FILE_UNRECOGNIZED); + } + + return OK; + +#if 0 + Error err = file->open(dst_file,FileAccess::WRITE); + if (err) { + memdelete(file); + ERR_EXPLAIN("Couldn't save project.godot"); + ERR_FAIL_COND_V(err,err) + } + + + for(Map >::Element *E=props.front();E;E=E->next()) { + + if (E!=props.front()) + file->store_string("\n"); + + if (E->key()!="") + file->store_string("["+E->key()+"]\n\n"); + for(List::Element *F=E->get().front();F;F=F->next()) { + + String key = F->get(); + if (E->key()!="") + key=E->key()+"/"+key; + Variant value; + + if (p_custom.has(key)) + value=p_custom[key]; + else + value = get(key); + + file->store_string(F->get()+"="+_encode_variant(value)+"\n"); + + } + } + + file->close(); + memdelete(file); + + + return OK; +#endif +} + +Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default) { + + Variant ret; + if (ProjectSettings::get_singleton()->has(p_var)) { + ret = ProjectSettings::get_singleton()->get(p_var); + } else { + ProjectSettings::get_singleton()->set(p_var, p_default); + ret = p_default; + } + ProjectSettings::get_singleton()->set_initial_value(p_var, p_default); + ProjectSettings::get_singleton()->set_builtin_order(p_var); + return ret; +} + +void ProjectSettings::add_singleton(const Singleton &p_singleton) { + + singletons.push_back(p_singleton); + singleton_ptrs[p_singleton.name] = p_singleton.ptr; +} + +Object *ProjectSettings::get_singleton_object(const String &p_name) const { + + const Map::Element *E = singleton_ptrs.find(p_name); + if (!E) + return NULL; + else + return E->get(); +}; + +bool ProjectSettings::has_singleton(const String &p_name) const { + + return get_singleton_object(p_name) != NULL; +}; + +void ProjectSettings::get_singletons(List *p_singletons) { + + for (List::Element *E = singletons.front(); E; E = E->next()) + p_singletons->push_back(E->get()); +} + +Vector ProjectSettings::get_optimizer_presets() const { + + List pi; + ProjectSettings::get_singleton()->get_property_list(&pi); + Vector names; + + for (List::Element *E = pi.front(); E; E = E->next()) { + + if (!E->get().name.begins_with("optimizer_presets/")) + continue; + names.push_back(E->get().name.get_slicec('/', 1)); + } + + names.sort(); + + return names; +} + +void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) { + + ERR_FAIL_COND(!p_info.has("name")); + ERR_FAIL_COND(!p_info.has("type")); + + PropertyInfo pinfo; + pinfo.name = p_info["name"]; + ERR_FAIL_COND(!props.has(pinfo.name)); + pinfo.type = Variant::Type(p_info["type"].operator int()); + ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX); + + if (p_info.has("hint")) + pinfo.hint = PropertyHint(p_info["hint"].operator int()); + if (p_info.has("hint_string")) + pinfo.hint_string = p_info["hint_string"]; + + set_custom_property_info(pinfo.name, pinfo); +} + +void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) { + + ERR_FAIL_COND(!props.has(p_prop)); + custom_prop_info[p_prop] = p_info; + custom_prop_info[p_prop].name = p_prop; +} + +void ProjectSettings::set_disable_feature_overrides(bool p_disable) { + + disable_feature_overrides = p_disable; +} + +bool ProjectSettings::is_using_datapack() const { + + return using_datapack; +} + +bool ProjectSettings::property_can_revert(const String &p_name) { + + if (!props.has(p_name)) + return false; + + return props[p_name].initial != props[p_name].variant; +} + +Variant ProjectSettings::property_get_revert(const String &p_name) { + + if (!props.has(p_name)) + return Variant(); + + return props[p_name].initial; +} + +void ProjectSettings::_bind_methods() { + + ClassDB::bind_method(D_METHOD("has", "name"), &ProjectSettings::has); + ClassDB::bind_method(D_METHOD("set_order", "name", "pos"), &ProjectSettings::set_order); + ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order); + ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value); + ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind); + ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear); + ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path); + ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path); + ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save); + ClassDB::bind_method(D_METHOD("has_singleton", "name"), &ProjectSettings::has_singleton); + ClassDB::bind_method(D_METHOD("get_singleton", "name"), &ProjectSettings::get_singleton_object); + ClassDB::bind_method(D_METHOD("load_resource_pack", "pack"), &ProjectSettings::_load_resource_pack); + ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert); + ClassDB::bind_method(D_METHOD("property_get_revert:Variant", "name"), &ProjectSettings::property_get_revert); + + ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd); +} + +ProjectSettings::ProjectSettings() { + + singleton = this; + last_order = NO_BUILTIN_ORDER_BASE; + last_builtin_order = 0; + disable_feature_overrides = false; + registering_order = true; + + Array va; + Ref key; + Ref joyb; + + GLOBAL_DEF("application/config/name", ""); + GLOBAL_DEF("application/run/main_scene", ""); + custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "tscn,scn,res"); + GLOBAL_DEF("application/run/disable_stdout", false); + GLOBAL_DEF("application/run/disable_stderr", false); + GLOBAL_DEF("application/config/use_shared_user_dir", true); + + key.instance(); + key->set_scancode(KEY_RETURN); + va.push_back(key); + key.instance(); + key->set_scancode(KEY_ENTER); + va.push_back(key); + key.instance(); + key->set_scancode(KEY_SPACE); + va.push_back(key); + joyb.instance(); + joyb->set_button_index(JOY_BUTTON_0); + va.push_back(joyb); + GLOBAL_DEF("input/ui_accept", va); + input_presets.push_back("input/ui_accept"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_SPACE); + va.push_back(key); + joyb.instance(); + joyb->set_button_index(JOY_BUTTON_3); + va.push_back(joyb); + GLOBAL_DEF("input/ui_select", va); + input_presets.push_back("input/ui_select"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_ESCAPE); + va.push_back(key); + joyb.instance(); + joyb->set_button_index(JOY_BUTTON_1); + va.push_back(joyb); + GLOBAL_DEF("input/ui_cancel", va); + input_presets.push_back("input/ui_cancel"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_TAB); + va.push_back(key); + GLOBAL_DEF("input/ui_focus_next", va); + input_presets.push_back("input/ui_focus_next"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_TAB); + key->set_shift(true); + va.push_back(key); + GLOBAL_DEF("input/ui_focus_prev", va); + input_presets.push_back("input/ui_focus_prev"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_LEFT); + va.push_back(key); + joyb.instance(); + joyb->set_button_index(JOY_DPAD_LEFT); + va.push_back(joyb); + GLOBAL_DEF("input/ui_left", va); + input_presets.push_back("input/ui_left"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_RIGHT); + va.push_back(key); + joyb.instance(); + joyb->set_button_index(JOY_DPAD_RIGHT); + va.push_back(joyb); + GLOBAL_DEF("input/ui_right", va); + input_presets.push_back("input/ui_right"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_UP); + va.push_back(key); + joyb.instance(); + joyb->set_button_index(JOY_DPAD_UP); + va.push_back(joyb); + GLOBAL_DEF("input/ui_up", va); + input_presets.push_back("input/ui_up"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_DOWN); + va.push_back(key); + joyb.instance(); + joyb->set_button_index(JOY_DPAD_DOWN); + va.push_back(joyb); + GLOBAL_DEF("input/ui_down", va); + input_presets.push_back("input/ui_down"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_PAGEUP); + va.push_back(key); + GLOBAL_DEF("input/ui_page_up", va); + input_presets.push_back("input/ui_page_up"); + + va = Array(); + key.instance(); + key->set_scancode(KEY_PAGEDOWN); + va.push_back(key); + GLOBAL_DEF("input/ui_page_down", va); + input_presets.push_back("input/ui_page_down"); + + //GLOBAL_DEF("display/window/handheld/orientation", "landscape"); + + custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor"); + custom_prop_info["rendering/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded"); + custom_prop_info["physics/2d/thread_model"] = PropertyInfo(Variant::INT, "physics/2d/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded"); + custom_prop_info["rendering/quality/intended_usage/framebuffer_allocation"] = PropertyInfo(Variant::INT, "rendering/quality/intended_usage/framebuffer_allocation", PROPERTY_HINT_ENUM, "2D,2D Without Sampling,3D,3D Without Effects"); + GLOBAL_DEF("rendering/quality/intended_usage/framebuffer_mode", 2); + + GLOBAL_DEF("debug/settings/profiler/max_functions", 16384); + + //assigning here, because using GLOBAL_GET on every block for compressing can be slow + Compression::zstd_level = GLOBAL_DEF("compression/formats/zstd/compression_level", 3); + custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"); + Compression::zlib_level = GLOBAL_DEF("compression/formats/zlib/compression_level", Z_DEFAULT_COMPRESSION); + custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); + Compression::gzip_level = GLOBAL_DEF("compression/formats/gzip/compression_level", Z_DEFAULT_COMPRESSION); + custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); + + using_datapack = false; +} + +ProjectSettings::~ProjectSettings() { + + singleton = NULL; +} diff --git a/core/project_settings.h b/core/project_settings.h new file mode 100644 index 0000000000..278d4b8132 --- /dev/null +++ b/core/project_settings.h @@ -0,0 +1,172 @@ +/*************************************************************************/ +/* globals.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GLOBAL_CONFIG_H +#define GLOBAL_CONFIG_H + +#include "object.h" +#include "os/thread_safe.h" +#include "set.h" +/** + @author Juan Linietsky +*/ + +class ProjectSettings : public Object { + + GDCLASS(ProjectSettings, Object); + _THREAD_SAFE_CLASS_ + +public: + typedef Map CustomMap; + + struct Singleton { + StringName name; + Object *ptr; + Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) { + name = p_name; + ptr = p_ptr; + } + }; + enum { + //properties that are not for built in values begin from this value, so builtin ones are displayed first + NO_BUILTIN_ORDER_BASE = 1 << 16 + }; + +protected: + struct VariantContainer { + int order; + bool persist; + Variant variant; + Variant initial; + bool hide_from_editor; + bool overrided; + VariantContainer() { + order = 0; + hide_from_editor = false; + persist = false; + overrided = false; + } + VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) { + variant = p_variant; + order = p_order; + hide_from_editor = false; + persist = p_persist; + overrided = false; + } + }; + + bool registering_order; + int last_order; + int last_builtin_order; + Map props; + String resource_path; + Map custom_prop_info; + bool disable_feature_overrides; + bool using_datapack; + List input_presets; + + Set custom_features; + Map feature_overrides; + + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; + + static ProjectSettings *singleton; + + Error _load_settings(const String p_path); + Error _load_settings_binary(const String p_path); + + Error _save_settings_text(const String &p_file, const Map > &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String()); + Error _save_settings_binary(const String &p_file, const Map > &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String()); + + List singletons; + Map singleton_ptrs; + + Error _save_custom_bnd(const String &p_file); + + bool _load_resource_pack(const String &p_pack); + + void _add_property_info_bind(const Dictionary &p_info); + +protected: + static void _bind_methods(); + +public: + bool has(String p_var) const; + String localize_path(const String &p_path) const; + String globalize_path(const String &p_path) const; + + void set_initial_value(const String &p_name, const Variant &p_value); + bool property_can_revert(const String &p_name); + Variant property_get_revert(const String &p_name); + + String get_resource_path() const; + + static ProjectSettings *get_singleton(); + + void clear(const String &p_name); + int get_order(const String &p_name) const; + void set_order(const String &p_name, int p_order); + void set_builtin_order(const String &p_name); + + Error setup(const String &p_path, const String &p_main_pack); + + Error save_custom(const String &p_path = "", const CustomMap &p_custom = CustomMap(), const Vector &p_custom_features = Vector()); + Error save(); + void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info); + + void add_singleton(const Singleton &p_singleton); + void get_singletons(List *p_singletons); + + bool has_singleton(const String &p_name) const; + + Vector get_optimizer_presets() const; + + List get_input_presets() const { return input_presets; } + + void set_disable_feature_overrides(bool p_disable); + Object *get_singleton_object(const String &p_name) const; + + void register_global_defaults(); + + bool is_using_datapack() const; + + void set_registering_order(bool p_registering); + + ProjectSettings(); + ~ProjectSettings(); +}; + +//not a macro any longer +Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default); +#define GLOBAL_DEF(m_var, m_value) _GLOBAL_DEF(m_var, m_value) +#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get(m_var) + +#endif diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index d6a521a86f..07715f9718 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -36,7 +36,7 @@ #include "core_string_names.h" #include "func_ref.h" #include "geometry.h" -#include "global_config.h" +#include "project_settings.h" #include "input_map.h" #include "io/config_file.h" #include "io/http_client.h" @@ -177,18 +177,18 @@ void register_core_settings() { void register_core_singletons() { - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("GlobalConfig", GlobalConfig::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("IP", IP::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("Geometry", _Geometry::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("ResourceLoader", _ResourceLoader::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("ResourceSaver", _ResourceSaver::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("OS", _OS::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("Engine", _Engine::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("ClassDB", _classdb)); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("Marshalls", _Marshalls::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("TranslationServer", TranslationServer::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("Input", Input::get_singleton())); - GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("InputMap", InputMap::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("ProjectSettings", ProjectSettings::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("IP", IP::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("Geometry", _Geometry::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("ResourceLoader", _ResourceLoader::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("ResourceSaver", _ResourceSaver::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("OS", _OS::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("Engine", _Engine::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("ClassDB", _classdb)); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("Marshalls", _Marshalls::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("TranslationServer", TranslationServer::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("Input", Input::get_singleton())); + ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("InputMap", InputMap::get_singleton())); } void unregister_core_types() { diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index 7fc151d83f..a7b6f25590 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "script_debugger_remote.h" -#include "global_config.h" +#include "project_settings.h" #include "io/ip.h" #include "os/input.h" #include "os/os.h" @@ -130,7 +130,7 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) ERR_FAIL(); } - OS::get_singleton()->enable_for_stealing_focus(GlobalConfig::get_singleton()->get("editor_pid")); + OS::get_singleton()->enable_for_stealing_focus(ProjectSettings::get_singleton()->get("editor_pid")); packet_peer_stream->put_var("debug_enter"); packet_peer_stream->put_var(2); @@ -952,7 +952,7 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() { phl.userdata = this; add_print_handler(&phl); requested_quit = false; - performance = GlobalConfig::get_singleton()->get_singleton_object("Performance"); + performance = ProjectSettings::get_singleton()->get_singleton_object("Performance"); last_perf_time = 0; poll_every = 0; request_scene_tree = NULL; @@ -967,7 +967,7 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() { eh.userdata = this; add_error_handler(&eh); - profile_info.resize(CLAMP(int(GlobalConfig::get_singleton()->get("debug/settings/profiler/max_functions")), 128, 65535)); + profile_info.resize(CLAMP(int(ProjectSettings::get_singleton()->get("debug/settings/profiler/max_functions")), 128, 65535)); profile_info_ptrs.resize(profile_info.size()); profiling = false; max_frame_functions = 16; diff --git a/core/translation.cpp b/core/translation.cpp index 72231ef295..d782006ddc 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "translation.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" #include "os/os.h" @@ -1053,8 +1053,8 @@ TranslationServer *TranslationServer::singleton = NULL; bool TranslationServer::_load_translations(const String &p_from) { - if (GlobalConfig::get_singleton()->has(p_from)) { - PoolVector translations = GlobalConfig::get_singleton()->get(p_from); + if (ProjectSettings::get_singleton()->has(p_from)) { + PoolVector translations = ProjectSettings::get_singleton()->get(p_from); int tcount = translations.size(); @@ -1095,7 +1095,7 @@ void TranslationServer::setup() { options += locale_list[idx]; idx++; } - GlobalConfig::get_singleton()->set_custom_property_info("locale/fallback", PropertyInfo(Variant::STRING, "locale/fallback", PROPERTY_HINT_ENUM, options)); + ProjectSettings::get_singleton()->set_custom_property_info("locale/fallback", PropertyInfo(Variant::STRING, "locale/fallback", PROPERTY_HINT_ENUM, options)); } #endif //load translations diff --git a/doc/base/classes.xml b/doc/base/classes.xml index a137f9be7d..fa93d7ece7 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -741,7 +741,7 @@ [Geometry] singleton - + [IP] singleton @@ -17682,7 +17682,7 @@ - + Contains global variables accessible from everywhere. diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp index b32d540380..4e6739e8c0 100644 --- a/drivers/alsa/audio_driver_alsa.cpp +++ b/drivers/alsa/audio_driver_alsa.cpp @@ -31,7 +31,7 @@ #ifdef ALSA_ENABLED -#include "global_config.h" +#include "project_settings.h" #include diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index e854abb6a1..0cb7aa8745 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -31,7 +31,7 @@ #include "rasterizer_gles2.h" #include "gl_context/context_gl.h" -#include "global_config.h" +#include "project_settings.h" #include "os/os.h" #include "servers/visual/particle_system_sw.h" #include "servers/visual/shader_language.h" @@ -3942,7 +3942,7 @@ void RasterizerGLES2::begin_frame() { //fragment_lighting=Globals::get_singleton()->get("rasterizer/use_fragment_lighting"); #ifdef TOOLS_ENABLED canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP, GLOBAL_DEF("rendering/use_2d_pixel_snap", false)); - shadow_filter = ShadowFilterTechnique(int(GlobalConfig::get_singleton()->get("rasterizer/shadow_filter"))); + shadow_filter = ShadowFilterTechnique(int(ProjectSettings::get_singleton()->get("rasterizer/shadow_filter"))); #endif canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_PCF5, shadow_filter == SHADOW_FILTER_PCF5); @@ -6819,7 +6819,7 @@ void RasterizerGLES2::end_scene() { if (current_env->bg_mode == VS::ENV_BG_COLOR) bgcolor = current_env->bg_param[VS::ENV_BG_PARAM_COLOR]; else - bgcolor = GlobalConfig::get_singleton()->get("render/default_clear_color"); + bgcolor = ProjectSettings::get_singleton()->get("render/default_clear_color"); bgcolor = _convert_color(bgcolor); float a = use_fb ? float(current_env->bg_param[VS::ENV_BG_PARAM_GLOW]) : 1.0; glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, a); @@ -10718,7 +10718,7 @@ RasterizerGLES2::RasterizerGLES2(bool p_compress_arrays, bool p_keep_ram_copy, b fragment_lighting = GLOBAL_DEF("rasterizer/use_fragment_lighting", true); read_depth_supported = true; //todo check for extension shadow_filter = ShadowFilterTechnique((int)(GLOBAL_DEF("rasterizer/shadow_filter", SHADOW_FILTER_PCF5))); - GlobalConfig::get_singleton()->set_custom_property_info("rasterizer/shadow_filter", PropertyInfo(Variant::INT, "rasterizer/shadow_filter", PROPERTY_HINT_ENUM, "None,PCF5,PCF13,ESM")); + ProjectSettings::get_singleton()->set_custom_property_info("rasterizer/shadow_filter", PropertyInfo(Variant::INT, "rasterizer/shadow_filter", PROPERTY_HINT_ENUM, "None,PCF5,PCF13,ESM")); use_fp16_fb = bool(GLOBAL_DEF("rasterizer/fp16_framebuffer", true)); use_shadow_mapping = true; use_fast_texture_filter = !bool(GLOBAL_DEF("rasterizer/trilinear_mipmap_filter", true)); diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 98e55c5a53..42d4572b7f 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "rasterizer_canvas_gles3.h" -#include "global_config.h" +#include "project_settings.h" #include "os/os.h" #include "rasterizer_scene_gles3.h" #include "servers/visual/visual_server_raster.h" diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index 233095dec2..4f0d9a03c4 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -30,7 +30,7 @@ #include "rasterizer_gles3.h" #include "gl_context/context_gl.h" -#include "global_config.h" +#include "project_settings.h" #include "os/os.h" #include RasterizerStorage *RasterizerGLES3::get_storage() { diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index b7547f53a8..5d884fff11 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -29,8 +29,8 @@ /*************************************************************************/ #include "rasterizer_scene_gles3.h" -#include "global_config.h" #include "os/os.h" +#include "project_settings.h" #include "rasterizer_canvas_gles3.h" #ifndef GLES_OVER_GL @@ -4779,8 +4779,6 @@ void RasterizerSceneGLES3::initialize() { state.scene_shader.add_custom_define("#define MAX_SKELETON_BONES " + itos(state.max_skeleton_bones) + "\n"); } - GLOBAL_DEF("rendering/quality/shadows/filter_mode", 1); - GlobalConfig::get_singleton()->set_custom_property_info("rendering/quality/shadows/filter_mode", PropertyInfo(Variant::INT, "rendering/quality/shadows/filter_mode", PROPERTY_HINT_ENUM, "Disabled,PCF5,PCF13")); shadow_filter_mode = SHADOW_FILTER_NEAREST; { //reflection cubemaps @@ -4872,9 +4870,9 @@ void RasterizerSceneGLES3::initialize() { { GLOBAL_DEF("rendering/quality/subsurface_scattering/quality", 1); - GlobalConfig::get_singleton()->set_custom_property_info("rendering/quality/subsurface_scattering/quality", PropertyInfo(Variant::INT, "rendering/quality/subsurface_scattering/quality", PROPERTY_HINT_ENUM, "Low,Medium,High")); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/subsurface_scattering/quality", PropertyInfo(Variant::INT, "rendering/quality/subsurface_scattering/quality", PROPERTY_HINT_ENUM, "Low,Medium,High")); GLOBAL_DEF("rendering/quality/subsurface_scattering/scale", 1.0); - GlobalConfig::get_singleton()->set_custom_property_info("rendering/quality/subsurface_scattering/scale", PropertyInfo(Variant::INT, "rendering/quality/subsurface_scattering/scale", PROPERTY_HINT_RANGE, "0.01,8,0.01")); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/subsurface_scattering/scale", PropertyInfo(Variant::INT, "rendering/quality/subsurface_scattering/scale", PROPERTY_HINT_RANGE, "0.01,8,0.01")); GLOBAL_DEF("rendering/quality/subsurface_scattering/follow_surface", false); GLOBAL_DEF("rendering/quality/voxel_cone_tracing/high_quality", true); @@ -4916,12 +4914,12 @@ void RasterizerSceneGLES3::initialize() { void RasterizerSceneGLES3::iteration() { - shadow_filter_mode = ShadowFilterMode(int(GlobalConfig::get_singleton()->get("rendering/quality/shadows/filter_mode"))); - subsurface_scatter_follow_surface = GlobalConfig::get_singleton()->get("rendering/quality/subsurface_scattering/follow_surface"); - subsurface_scatter_quality = SubSurfaceScatterQuality(int(GlobalConfig::get_singleton()->get("rendering/quality/subsurface_scattering/quality"))); - subsurface_scatter_size = GlobalConfig::get_singleton()->get("rendering/quality/subsurface_scattering/scale"); + shadow_filter_mode = ShadowFilterMode(int(ProjectSettings::get_singleton()->get("rendering/quality/shadows/filter_mode"))); + subsurface_scatter_follow_surface = ProjectSettings::get_singleton()->get("rendering/quality/subsurface_scattering/follow_surface"); + subsurface_scatter_quality = SubSurfaceScatterQuality(int(ProjectSettings::get_singleton()->get("rendering/quality/subsurface_scattering/quality"))); + subsurface_scatter_size = ProjectSettings::get_singleton()->get("rendering/quality/subsurface_scattering/scale"); - state.scene_shader.set_conditional(SceneShaderGLES3::VCT_QUALITY_HIGH, GlobalConfig::get_singleton()->get("rendering/quality/voxel_cone_tracing/high_quality")); + state.scene_shader.set_conditional(SceneShaderGLES3::VCT_QUALITY_HIGH, ProjectSettings::get_singleton()->get("rendering/quality/voxel_cone_tracing/high_quality")); } void RasterizerSceneGLES3::finalize() { diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 981426f4dc..17e77aed89 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "rasterizer_storage_gles3.h" -#include "global_config.h" +#include "project_settings.h" #include "rasterizer_canvas_gles3.h" #include "rasterizer_scene_gles3.h" @@ -6848,7 +6848,7 @@ void RasterizerStorageGLES3::initialize() { } config.shrink_textures_x2 = false; - config.use_fast_texture_filter = int(GlobalConfig::get_singleton()->get("rendering/quality/filters/use_nearest_mipmap_filter")); + config.use_fast_texture_filter = int(ProjectSettings::get_singleton()->get("rendering/quality/filters/use_nearest_mipmap_filter")); config.use_anisotropic_filter = config.extensions.has("rendering/quality/filters/anisotropic_filter_level"); config.s3tc_supported = config.extensions.has("GL_EXT_texture_compression_dxt1") || config.extensions.has("GL_EXT_texture_compression_s3tc") || config.extensions.has("WEBGL_compressed_texture_s3tc"); @@ -6872,7 +6872,7 @@ void RasterizerStorageGLES3::initialize() { config.use_anisotropic_filter = config.extensions.has("GL_EXT_texture_filter_anisotropic"); if (config.use_anisotropic_filter) { glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &config.anisotropic_level); - config.anisotropic_level = MIN(int(GlobalConfig::get_singleton()->get("rendering/quality/anisotropic_filter_level")), config.anisotropic_level); + config.anisotropic_level = MIN(int(ProjectSettings::get_singleton()->get("rendering/quality/anisotropic_filter_level")), config.anisotropic_level); } frame.clear_request = false; @@ -7009,7 +7009,7 @@ void RasterizerStorageGLES3::initialize() { frame.current_rt = NULL; config.keep_original_textures = false; config.generate_wireframes = false; - config.use_texture_array_environment = GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections", true); + config.use_texture_array_environment = GLOBAL_GET("rendering/quality/reflections/texture_array_reflections"); } void RasterizerStorageGLES3::finalize() { diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index 0d7e1d9d72..ff3128d476 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -30,7 +30,7 @@ #include "resource_saver_png.h" #include "core/image.h" -#include "global_config.h" +#include "project_settings.h" #include "os/file_access.h" #include "scene/resources/texture.h" diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index 45827ee4f7..fb04ef0088 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -33,7 +33,7 @@ #include -#include "global_config.h" +#include "project_settings.h" Error AudioDriverPulseAudio::init() { diff --git a/drivers/rtaudio/audio_driver_rtaudio.cpp b/drivers/rtaudio/audio_driver_rtaudio.cpp index 0cbe145b41..4dee796060 100644 --- a/drivers/rtaudio/audio_driver_rtaudio.cpp +++ b/drivers/rtaudio/audio_driver_rtaudio.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "audio_driver_rtaudio.h" -#include "global_config.h" +#include "project_settings.h" #include "os/os.h" #ifdef RTAUDIO_ENABLED diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 2f88296ea4..d05529ef9a 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -53,7 +53,7 @@ #if defined(__FreeBSD__) || defined(__OpenBSD__) #include #endif -#include "global_config.h" +#include "project_settings.h" #include #include #include @@ -494,7 +494,7 @@ String OS_Unix::get_data_dir() const { if (has_environment("HOME")) { - bool use_godot = GlobalConfig::get_singleton()->get("application/config/use_shared_user_dir"); + bool use_godot = ProjectSettings::get_singleton()->get("application/config/use_shared_user_dir"); if (use_godot) return get_environment("HOME") + "/.godot/app_userdata/" + an; else @@ -502,12 +502,7 @@ String OS_Unix::get_data_dir() const { } } - return GlobalConfig::get_singleton()->get_resource_path(); -} - -bool OS_Unix::check_feature_support(const String &p_feature) { - - return VisualServer::get_singleton()->has_os_feature(p_feature); + return ProjectSettings::get_singleton()->get_resource_path(); } String OS_Unix::get_installed_templates_path() const { diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 67eb5cefdf..953b0f0431 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -117,8 +117,6 @@ public: virtual String get_executable_path() const; virtual String get_data_dir() const; - virtual bool check_feature_support(const String &p_feature); - //virtual void run( MainLoop * p_main_loop ); }; diff --git a/drivers/xaudio2/audio_driver_xaudio2.cpp b/drivers/xaudio2/audio_driver_xaudio2.cpp index 23ba177824..da6de79592 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.cpp +++ b/drivers/xaudio2/audio_driver_xaudio2.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "audio_driver_xaudio2.h" -#include "global_config.h" +#include "project_settings.h" #include "os/os.h" const char *AudioDriverXAudio2::get_name() const { diff --git a/editor/asset_library_editor_plugin.cpp b/editor/asset_library_editor_plugin.cpp index 27d468bc25..74e21b31ea 100644 --- a/editor/asset_library_editor_plugin.cpp +++ b/editor/asset_library_editor_plugin.cpp @@ -1228,8 +1228,8 @@ void EditorAssetLibrary::_asset_open() { void EditorAssetLibrary::_manage_plugins() { - ProjectSettings::get_singleton()->popup_project_settings(); - ProjectSettings::get_singleton()->set_plugins_page(); + ProjectSettingsEditor::get_singleton()->popup_project_settings(); + ProjectSettingsEditor::get_singleton()->set_plugins_page(); } void EditorAssetLibrary::_install_external_asset(String p_zip_path, String p_title) { diff --git a/editor/collada/collada.cpp b/editor/collada/collada.cpp index 2f234c441a..ab1e397ccc 100644 --- a/editor/collada/collada.cpp +++ b/editor/collada/collada.cpp @@ -306,7 +306,7 @@ void Collada::_parse_image(XMLParser &parser) { String path = parser.get_attribute_value("source").strip_edges(); if (path.find("://") == -1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - image.path = GlobalConfig::get_singleton()->localize_path(state.local_path.get_base_dir() + "/" + path.percent_decode()); + image.path = ProjectSettings::get_singleton()->localize_path(state.local_path.get_base_dir() + "/" + path.percent_decode()); } } else { @@ -323,11 +323,11 @@ void Collada::_parse_image(XMLParser &parser) { if (path.find("://") == -1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path = GlobalConfig::get_singleton()->localize_path(state.local_path.get_base_dir() + "/" + path); + path = ProjectSettings::get_singleton()->localize_path(state.local_path.get_base_dir() + "/" + path); } else if (path.find("file:///") == 0) { path = path.replace_first("file:///", ""); - path = GlobalConfig::get_singleton()->localize_path(path); + path = ProjectSettings::get_singleton()->localize_path(path); } image.path = path; @@ -2556,7 +2556,7 @@ Error Collada::load(const String &p_path, int p_flags) { Error err = parser.open(p_path); ERR_FAIL_COND_V(err, err); - state.local_path = GlobalConfig::get_singleton()->localize_path(p_path); + state.local_path = ProjectSettings::get_singleton()->localize_path(p_path); state.import_flags = p_flags; /* Skip headers */ err = OK; diff --git a/editor/collada/collada.h b/editor/collada/collada.h index ca60c392dd..38e66a7e45 100644 --- a/editor/collada/collada.h +++ b/editor/collada/collada.h @@ -32,7 +32,7 @@ #ifndef COLLADA_H #define COLLADA_H -#include "global_config.h" +#include "project_settings.h" #include "io/xml_parser.h" #include "map.h" #include "scene/resources/material.h" diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index 6a79f99354..fa90cd36b3 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "doc_data.h" -#include "global_config.h" +#include "project_settings.h" #include "global_constants.h" #include "io/compression.h" #include "io/marshalls.h" @@ -568,14 +568,14 @@ void DocData::generate(bool p_basic_types) { c.constants.push_back(cd); } - List singletons; - GlobalConfig::get_singleton()->get_singletons(&singletons); + List singletons; + ProjectSettings::get_singleton()->get_singletons(&singletons); //servers (this is kind of hackish) - for (List::Element *E = singletons.front(); E; E = E->next()) { + for (List::Element *E = singletons.front(); E; E = E->next()) { PropertyDoc pd; - GlobalConfig::Singleton &s = E->get(); + ProjectSettings::Singleton &s = E->get(); pd.name = s.name; pd.type = s.ptr->get_class(); while (String(ClassDB::get_parent_class(pd.type)) != "Object") diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index b83ac69141..399c22bf2c 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -30,7 +30,7 @@ #include "editor_autoload_settings.h" #include "editor_node.h" -#include "global_config.h" +#include "project_settings.h" #include "global_constants.h" #define PREVIEW_LIST_MAX_SIZE 10 @@ -115,12 +115,12 @@ void EditorAutoloadSettings::_autoload_add() { UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); undo_redo->create_action(TTR("Add AutoLoad")); - undo_redo->add_do_property(GlobalConfig::get_singleton(), name, "*" + path); + undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path); - if (GlobalConfig::get_singleton()->has(name)) { - undo_redo->add_undo_property(GlobalConfig::get_singleton(), name, GlobalConfig::get_singleton()->get(name)); + if (ProjectSettings::get_singleton()->has(name)) { + undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name)); } else { - undo_redo->add_undo_property(GlobalConfig::get_singleton(), name, Variant()); + undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant()); } undo_redo->add_do_method(this, "update_autoload"); @@ -169,7 +169,7 @@ void EditorAutoloadSettings::_autoload_edited() { return; } - if (GlobalConfig::get_singleton()->has("autoload/" + name)) { + if (ProjectSettings::get_singleton()->has("autoload/" + name)) { ti->set_text(0, old_name); EditorNode::get_singleton()->show_warning(vformat(TTR("Autoload '%s' already exists!"), name)); return; @@ -179,18 +179,18 @@ void EditorAutoloadSettings::_autoload_edited() { name = "autoload/" + name; - int order = GlobalConfig::get_singleton()->get_order(selected_autoload); - String path = GlobalConfig::get_singleton()->get(selected_autoload); + int order = ProjectSettings::get_singleton()->get_order(selected_autoload); + String path = ProjectSettings::get_singleton()->get(selected_autoload); undo_redo->create_action(TTR("Rename Autoload")); - undo_redo->add_do_property(GlobalConfig::get_singleton(), name, path); - undo_redo->add_do_method(GlobalConfig::get_singleton(), "set_order", name, order); - undo_redo->add_do_method(GlobalConfig::get_singleton(), "clear", selected_autoload); + undo_redo->add_do_property(ProjectSettings::get_singleton(), name, path); + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", name, order); + undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", selected_autoload); - undo_redo->add_undo_property(GlobalConfig::get_singleton(), selected_autoload, path); - undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_order", selected_autoload, order); - undo_redo->add_undo_method(GlobalConfig::get_singleton(), "clear", name); + undo_redo->add_undo_property(ProjectSettings::get_singleton(), selected_autoload, path); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", selected_autoload, order); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", name); undo_redo->add_do_method(this, "update_autoload"); undo_redo->add_undo_method(this, "update_autoload"); @@ -207,8 +207,8 @@ void EditorAutoloadSettings::_autoload_edited() { bool checked = ti->is_checked(2); String base = "autoload/" + ti->get_text(0); - int order = GlobalConfig::get_singleton()->get_order(base); - String path = GlobalConfig::get_singleton()->get(base); + int order = ProjectSettings::get_singleton()->get_order(base); + String path = ProjectSettings::get_singleton()->get(base); if (path.begins_with("*")) path = path.substr(1, path.length()); @@ -218,11 +218,11 @@ void EditorAutoloadSettings::_autoload_edited() { undo_redo->create_action(TTR("Toggle AutoLoad Globals")); - undo_redo->add_do_property(GlobalConfig::get_singleton(), base, path); - undo_redo->add_undo_property(GlobalConfig::get_singleton(), base, GlobalConfig::get_singleton()->get(base)); + undo_redo->add_do_property(ProjectSettings::get_singleton(), base, path); + undo_redo->add_undo_property(ProjectSettings::get_singleton(), base, ProjectSettings::get_singleton()->get(base)); - undo_redo->add_do_method(GlobalConfig::get_singleton(), "set_order", base, order); - undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_order", base, order); + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", base, order); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", base, order); undo_redo->add_do_method(this, "update_autoload"); undo_redo->add_undo_method(this, "update_autoload"); @@ -262,16 +262,16 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu String swap_name = "autoload/" + swap->get_text(0); - int order = GlobalConfig::get_singleton()->get_order(name); - int swap_order = GlobalConfig::get_singleton()->get_order(swap_name); + int order = ProjectSettings::get_singleton()->get_order(name); + int swap_order = ProjectSettings::get_singleton()->get_order(swap_name); undo_redo->create_action(TTR("Move Autoload")); - undo_redo->add_do_method(GlobalConfig::get_singleton(), "set_order", name, swap_order); - undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_order", name, order); + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", name, swap_order); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", name, order); - undo_redo->add_do_method(GlobalConfig::get_singleton(), "set_order", swap_name, order); - undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_order", swap_name, swap_order); + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", swap_name, order); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", swap_name, swap_order); undo_redo->add_do_method(this, "update_autoload"); undo_redo->add_undo_method(this, "update_autoload"); @@ -283,15 +283,15 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu } break; case BUTTON_DELETE: { - int order = GlobalConfig::get_singleton()->get_order(name); + int order = ProjectSettings::get_singleton()->get_order(name); undo_redo->create_action(TTR("Remove Autoload")); - undo_redo->add_do_property(GlobalConfig::get_singleton(), name, Variant()); + undo_redo->add_do_property(ProjectSettings::get_singleton(), name, Variant()); - undo_redo->add_undo_property(GlobalConfig::get_singleton(), name, GlobalConfig::get_singleton()->get(name)); - undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_persisting", name, true); - undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_order", order); + undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name)); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_persisting", name, true); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", order); undo_redo->add_do_method(this, "update_autoload"); undo_redo->add_undo_method(this, "update_autoload"); @@ -322,7 +322,7 @@ void EditorAutoloadSettings::update_autoload() { TreeItem *root = tree->create_item(); List props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List::Element *E = props.front(); E; E = E->next()) { @@ -332,14 +332,14 @@ void EditorAutoloadSettings::update_autoload() { continue; String name = pi.name.get_slice("/", 1); - String path = GlobalConfig::get_singleton()->get(pi.name); + String path = ProjectSettings::get_singleton()->get(pi.name); if (name.empty()) continue; AutoLoadInfo info; info.name = pi.name; - info.order = GlobalConfig::get_singleton()->get_order(pi.name); + info.order = ProjectSettings::get_singleton()->get_order(pi.name); autoload_cache.push_back(info); @@ -459,7 +459,7 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant & move_to_back = true; } - int order = GlobalConfig::get_singleton()->get_order("autoload/" + name); + int order = ProjectSettings::get_singleton()->get_order("autoload/" + name); AutoLoadInfo aux; List::Element *E = NULL; @@ -476,7 +476,7 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant & orders.resize(autoload_cache.size()); for (int i = 0; i < autoloads.size(); i++) { - aux.order = GlobalConfig::get_singleton()->get_order("autoload/" + autoloads[i]); + aux.order = ProjectSettings::get_singleton()->get_order("autoload/" + autoloads[i]); List::Element *I = autoload_cache.find(aux); @@ -506,8 +506,8 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant & i = 0; for (List::Element *E = autoload_cache.front(); E; E = E->next()) { - undo_redo->add_do_method(GlobalConfig::get_singleton(), "set_order", E->get().name, orders[i++]); - undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_order", E->get().name, E->get().order); + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", E->get().name, orders[i++]); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", E->get().name, E->get().order); } orders.clear(); diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 11b900f45c..f8dbd9abe5 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -31,7 +31,7 @@ #include "editor_node.h" #include "editor_settings.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" #include "os/dir_access.h" #include "os/file_access.h" diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 5cd00738a2..abbce0199a 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -33,13 +33,13 @@ #include "editor/plugins/script_editor_plugin.h" #include "editor_node.h" #include "editor_settings.h" -#include "global_config.h" #include "io/config_file.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "io/zip_io.h" #include "os/dir_access.h" #include "os/file_access.h" +#include "project_settings.h" #include "script_language.h" #include "version.h" @@ -200,6 +200,17 @@ Vector EditorExportPreset::get_patches() const { return patches; } +void EditorExportPreset::set_custom_features(const String &p_custom_features) { + + custom_features = p_custom_features; + EditorExport::singleton->save_presets(); +} + +String EditorExportPreset::get_custom_features() const { + + return custom_features; +} + EditorExportPreset::EditorExportPreset() { export_filter = EXPORT_ALL_RESOURCES; @@ -491,9 +502,23 @@ Error EditorExportPlatform::export_project_files(const Ref & //save config! - String config_file = "godot.cfb"; + Vector custom_list; + + if (p_preset->get_custom_features() != String()) { + + Vector tmp_custom_list = p_preset->get_custom_features().split(","); + + for (int i = 0; i < tmp_custom_list.size(); i++) { + String f = tmp_custom_list[i].strip_edges(); + if (f != String()) { + custom_list.push_back(f); + } + } + } + + String config_file = "project.binary"; String engine_cfb = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmp" + config_file; - GlobalConfig::get_singleton()->save_custom(engine_cfb); + ProjectSettings::get_singleton()->save_custom(engine_cfb, ProjectSettings::CustomMap(), custom_list); Vector data = FileAccess::get_file_as_array(engine_cfb); p_func(p_udata, "res://" + config_file, data, idx, total); @@ -691,6 +716,7 @@ void EditorExport::_save() { config->set_value(section, "name", preset->get_name()); config->set_value(section, "platform", preset->get_platform()->get_name()); config->set_value(section, "runnable", preset->is_runnable()); + config->set_value(section, "custom_feaures", preset->get_custom_features()); bool save_files = false; switch (preset->get_export_filter()) { case EditorExportPreset::EXPORT_ALL_RESOURCES: { @@ -823,6 +849,10 @@ void EditorExport::load_config() { preset->set_name(config->get_value(section, "name")); preset->set_runnable(config->get_value(section, "runnable")); + if (config->has_section_key(section, "custom_features")) { + preset->set_custom_features(config->get_value(section, "custom_features")); + } + String export_filter = config->get_value(section, "export_filter"); bool get_files = false; @@ -931,6 +961,11 @@ String EditorExportPlatformPC::get_name() const { return name; } + +String EditorExportPlatformPC::get_os_name() const { + + return os_name; +} Ref EditorExportPlatformPC::get_logo() const { return logo; @@ -1033,6 +1068,10 @@ void EditorExportPlatformPC::set_name(const String &p_name) { name = p_name; } +void EditorExportPlatformPC::set_os_name(const String &p_name) { + os_name = p_name; +} + void EditorExportPlatformPC::set_logo(const Ref &p_logo) { logo = p_logo; } @@ -1055,6 +1094,20 @@ void EditorExportPlatformPC::set_debug_32(const String &p_file) { debug_file_32 = p_file; } +void EditorExportPlatformPC::add_platform_feature(const String &p_feature) { + + extra_features.insert(p_feature); +} + +void EditorExportPlatformPC::get_platform_features(List *r_features) { + r_features->push_back("pc"); //all pcs support "pc" + r_features->push_back("s3tc"); //all pcs support "s3tc" compression + r_features->push_back(get_os_name()); //OS name is a feature + for (Set::Element *E = extra_features.front(); E; E = E->next()) { + r_features->push_back(E->get()); + } +} + EditorExportPlatformPC::EditorExportPlatformPC() { } @@ -1065,7 +1118,6 @@ EditorExportPlatformPC::EditorExportPlatformPC() { #include "editor/plugins/script_editor_plugin.h" #include "editor_node.h" #include "editor_settings.h" -#include "global_config.h" #include "io/config_file.h" #include "io/md5.h" #include "io/resource_loader.h" @@ -1074,14 +1126,15 @@ EditorExportPlatformPC::EditorExportPlatformPC() { #include "io_plugins/editor_texture_import_plugin.h" #include "os/dir_access.h" #include "os/file_access.h" +#include "project_settings.h" #include "script_language.h" #include "version.h" String EditorImportPlugin::validate_source_path(const String& p_path) { - String gp = GlobalConfig::get_singleton()->globalize_path(p_path); - String rp = GlobalConfig::get_singleton()->get_resource_path(); + String gp = ProjectSettings::get_singleton()->globalize_path(p_path); + String rp = ProjectSettings::get_singleton()->get_resource_path(); if (!rp.ends_with("/")) rp+="/"; @@ -1091,7 +1144,7 @@ String EditorImportPlugin::validate_source_path(const String& p_path) { String EditorImportPlugin::expand_source_path(const String& p_path) { if (p_path.is_rel_path()) { - return GlobalConfig::get_singleton()->get_resource_path().plus_file(p_path).simplify_path(); + return ProjectSettings::get_singleton()->get_resource_path().plus_file(p_path).simplify_path(); } else { return p_path; } @@ -1766,7 +1819,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func { MD5_CTX ctx; MD5Init(&ctx); - String path = GlobalConfig::get_singleton()->get_resource_path()+"::"+String(E->get())+"::"+get_name(); + String path = ProjectSettings::get_singleton()->get_resource_path()+"::"+String(E->get())+"::"+get_name(); MD5Update(&ctx,(unsigned char*)path.utf8().get_data(),path.utf8().length()); MD5Final(&ctx); md5 = String::md5(ctx.digest); @@ -1875,11 +1928,11 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func int flags=0; - if (GlobalConfig::get_singleton()->get("image_loader/filter")) + if (ProjectSettings::get_singleton()->get("image_loader/filter")) flags|=EditorTextureImportPlugin::IMAGE_FLAG_FILTER; - if (!GlobalConfig::get_singleton()->get("image_loader/gen_mipmaps")) + if (!ProjectSettings::get_singleton()->get("image_loader/gen_mipmaps")) flags|=EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS; - if (!GlobalConfig::get_singleton()->get("image_loader/repeat")) + if (!ProjectSettings::get_singleton()->get("image_loader/repeat")) flags|=EditorTextureImportPlugin::IMAGE_FLAG_REPEAT; flags|=EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA; @@ -1988,7 +2041,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func StringName engine_cfg="res://project.godot"; StringName boot_splash; { - String splash=GlobalConfig::get_singleton()->get("application/boot_splash"); //avoid splash from being converted + String splash=ProjectSettings::get_singleton()->get("application/boot_splash"); //avoid splash from being converted splash=splash.strip_edges(); if (splash!=String()) { if (!splash.begins_with("res://")) @@ -1999,7 +2052,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func } StringName custom_cursor; { - String splash=GlobalConfig::get_singleton()->get("display/custom_mouse_cursor"); //avoid splash from being converted + String splash=ProjectSettings::get_singleton()->get("display/custom_mouse_cursor"); //avoid splash from being converted splash=splash.strip_edges(); if (splash!=String()) { if (!splash.begins_with("res://")) @@ -2083,9 +2136,9 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func } - String remap_file="godot.cfb"; + String remap_file="project.binary"; String engine_cfb =EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmp"+remap_file; - GlobalConfig::get_singleton()->save_custom(engine_cfb,custom); + ProjectSettings::get_singleton()->save_custom(engine_cfb,custom); Vector data = FileAccess::get_file_as_array(engine_cfb); Error err = p_func(p_udata,"res://"+remap_file,data,counter,files.size()); diff --git a/editor/editor_export.h b/editor/editor_export.h index 64381fbb35..dc4b198575 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -70,6 +70,8 @@ private: String name; + String custom_features; + protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -107,6 +109,9 @@ public: void remove_patch(int p_idx); Vector get_patches() const; + void set_custom_features(const String &p_custom_features); + String get_custom_features() const; + const List &get_properties() const { return properties; } EditorExportPreset(); @@ -153,12 +158,13 @@ private: static Error _save_zip_file(void *p_userdata, const String &p_path, const Vector &p_data, int p_file, int p_total); protected: - virtual void get_preset_features(const Ref &p_preset, List *r_features) = 0; bool exists_export_template(String template_file_name, String *err) const; String find_export_template(String template_file_name, String *err = NULL) const; void gen_export_flags(Vector &r_flags, int p_flags); public: + virtual void get_preset_features(const Ref &p_preset, List *r_features) = 0; + struct ExportOption { PropertyInfo option; Variant default_value; @@ -175,6 +181,7 @@ public: virtual void get_export_options(List *r_options) = 0; virtual bool get_option_visibility(const String &p_option, const Map &p_options) const { return true; } + virtual String get_os_name() const = 0; virtual String get_name() const = 0; virtual Ref get_logo() const = 0; @@ -203,6 +210,7 @@ public: virtual String get_binary_extension() const = 0; virtual Error export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0; + virtual void get_platform_features(List *r_features) = 0; EditorExportPlatform(); }; @@ -253,6 +261,7 @@ class EditorExportPlatformPC : public EditorExportPlatform { Ref logo; String name; + String os_name; String extension; String release_file_32; @@ -260,6 +269,8 @@ class EditorExportPlatformPC : public EditorExportPlatform { String debug_file_32; String debug_file_64; + Set extra_features; + bool use64; public: @@ -268,6 +279,7 @@ public: virtual void get_export_options(List *r_options); virtual String get_name() const; + virtual String get_os_name() const; virtual Ref get_logo() const; virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; @@ -276,6 +288,7 @@ public: void set_extension(const String &p_extension); void set_name(const String &p_name); + void set_os_name(const String &p_name); void set_logo(const Ref &p_loco); @@ -284,6 +297,9 @@ public: void set_debug_64(const String &p_file); void set_debug_32(const String &p_file); + void add_platform_feature(const String &p_feature); + virtual void get_platform_features(List *r_features); + EditorExportPlatformPC(); }; diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index c8fa86ed73..f0f84416bf 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -32,12 +32,12 @@ #include "editor_node.h" #include "editor_resource_preview.h" #include "editor_settings.h" -#include "global_config.h" #include "io/resource_import.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/file_access.h" #include "os/os.h" +#include "project_settings.h" #include "variant_parser.h" EditorFileSystem *EditorFileSystem::singleton = NULL; @@ -179,7 +179,7 @@ void EditorFileSystem::_scan_filesystem() { sources_changed.clear(); file_cache.clear(); - String project = GlobalConfig::get_singleton()->get_resource_path(); + String project = ProjectSettings::get_singleton()->get_resource_path(); String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache2"); FileAccess *f = FileAccess::open(fscache, FileAccess::READ); @@ -1008,7 +1008,7 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector if (!filesystem || scanning) return false; - String f = GlobalConfig::get_singleton()->localize_path(p_file); + String f = ProjectSettings::get_singleton()->localize_path(p_file); if (!f.begins_with("res://")) return false; @@ -1121,7 +1121,7 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p if (!filesystem || scanning) return NULL; - String f = GlobalConfig::get_singleton()->localize_path(p_path); + String f = ProjectSettings::get_singleton()->localize_path(p_path); if (!f.begins_with("res://")) return NULL; @@ -1335,7 +1335,7 @@ void EditorFileSystem::_reimport_file(const String &p_file) { f->store_line("[params]"); f->store_line(""); - //store options in provided order, to avoid file changing + //store options in provided order, to avoid file changing. Order is also important because first match is accepted first. for (List::Element *E = opts.front(); E; E = E->next()) { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 79c7aa044c..ea4cbd4853 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -39,7 +39,6 @@ #include "editor_help.h" #include "editor_settings.h" #include "editor_themes.h" -#include "global_config.h" #include "io/config_file.h" #include "io/stream_peer_ssl.h" #include "io/zip_io.h" @@ -52,6 +51,7 @@ #include "os/os.h" #include "path_remap.h" #include "print_string.h" +#include "project_settings.h" #include "pvrtc_compress.h" #include "register_exporters.h" #include "scene/resources/packed_scene.h" @@ -163,7 +163,7 @@ void EditorNode::_update_scene_tabs() { void EditorNode::_update_title() { - String appname = GlobalConfig::get_singleton()->get("application/config/name"); + String appname = ProjectSettings::get_singleton()->get("application/config/name"); String title = appname.empty() ? String(VERSION_FULL_NAME) : String(_MKSTR(VERSION_NAME) + String(" - ") + appname); String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String(); if (!edited.empty()) @@ -272,7 +272,7 @@ void EditorNode::_notification(int p_what) { } editor_selection->update(); - scene_root->set_size_override(true, Size2(GlobalConfig::get_singleton()->get("display/window/size/width"), GlobalConfig::get_singleton()->get("display/window/size/height"))); + scene_root->set_size_override(true, Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"))); ResourceImporterTexture::get_singleton()->update_imports(); } @@ -519,7 +519,7 @@ void EditorNode::save_resource_in_path(const Ref &p_resource, const St flg|=ResourceSaver::FLAG_RELATIVE_PATHS; */ - String path = GlobalConfig::get_singleton()->localize_path(p_path); + String path = ProjectSettings::get_singleton()->localize_path(p_path); Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); if (err != OK) { @@ -870,7 +870,7 @@ void EditorNode::_save_scene_with_preview(String p_file) { //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); - String cache_base = GlobalConfig::get_singleton()->globalize_path(p_file).md5_text(); + String cache_base = ProjectSettings::get_singleton()->globalize_path(p_file).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); //does not have it, try to load a cached thumbnail @@ -950,7 +950,7 @@ void EditorNode::_save_scene(String p_file, int idx) { _save_edited_subresources(scene, processed, flg); editor_data.save_editor_external_data(); if (err == OK) { - scene->set_filename(GlobalConfig::get_singleton()->localize_path(p_file)); + scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_file)); //EditorFileSystem::get_singleton()->update_file(p_file,sdata->get_type()); if (idx < 0 || idx == editor_data.get_edited_scene()) set_current_version(editor_data.get_undo_redo().get_version()); @@ -1029,7 +1029,7 @@ void EditorNode::_import_action(const String &p_action) { EditorImport::generate_version_hashes(src); - Node *dst = SceneLoader::load(editor_data.get_imported_scene(GlobalConfig::get_singleton()->localize_path(_tmp_import_path))); + Node *dst = SceneLoader::load(editor_data.get_imported_scene(ProjectSettings::get_singleton()->localize_path(_tmp_import_path))); if (!dst) { @@ -1132,8 +1132,8 @@ void EditorNode::_dialog_action(String p_file) { } break; case SETTINGS_PICK_MAIN_SCENE: { - GlobalConfig::get_singleton()->set("application/run/main_scene", p_file); - GlobalConfig::get_singleton()->save(); + ProjectSettings::get_singleton()->set("application/run/main_scene", p_file); + ProjectSettings::get_singleton()->save(); //would be nice to show the project manager opened with the highlighted field.. _run(false, ""); // automatically run the project } break; @@ -1802,7 +1802,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { List breakpoints; editor_data.get_editor_breakpoints(&breakpoints); - args = GlobalConfig::get_singleton()->get("editor/main_run_args"); + args = ProjectSettings::get_singleton()->get("editor/main_run_args"); Error error = editor_run.run(run_filename, args, breakpoints); @@ -2269,7 +2269,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } instanced_scene->generate_instance_state(); - instanced_scene->set_filename( GlobalConfig::get_singleton()->localize_path(external_file) ); + instanced_scene->set_filename( ProjectSettings::get_singleton()->localize_path(external_file) ); editor_data.get_undo_redo().create_action("Instance Scene"); editor_data.get_undo_redo().add_do_method(parent,"add_child",instanced_scene); @@ -2944,9 +2944,9 @@ void EditorNode::_update_addon_config() { } if (enabled_addons.size() == 0) { - GlobalConfig::get_singleton()->set("editor_plugins/enabled", Variant()); + ProjectSettings::get_singleton()->set("editor_plugins/enabled", Variant()); } else { - GlobalConfig::get_singleton()->set("editor_plugins/enabled", enabled_addons); + ProjectSettings::get_singleton()->set("editor_plugins/enabled", enabled_addons); } project_settings->queue_save(); @@ -3287,7 +3287,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b if (p_clear_errors) load_errors->clear(); - String lpath = GlobalConfig::get_singleton()->localize_path(p_scene); + String lpath = ProjectSettings::get_singleton()->localize_path(p_scene); if (!lpath.begins_with("res://")) { @@ -3575,7 +3575,7 @@ void EditorNode::animation_editor_make_visible(bool p_visible) { #endif void EditorNode::_add_to_recent_scenes(const String &p_scene) { - String base = "_" + GlobalConfig::get_singleton()->get_resource_path().replace("\\", "::").replace("/", "::"); + String base = "_" + ProjectSettings::get_singleton()->get_resource_path().replace("\\", "::").replace("/", "::"); Vector rc = EDITOR_DEF(base + "/_recent_scenes", Array()); String name = p_scene; name = name.replace("res://", ""); @@ -3592,7 +3592,7 @@ void EditorNode::_add_to_recent_scenes(const String &p_scene) { void EditorNode::_open_recent_scene(int p_idx) { - String base = "_" + GlobalConfig::get_singleton()->get_resource_path().replace("\\", "::").replace("/", "::"); + String base = "_" + ProjectSettings::get_singleton()->get_resource_path().replace("\\", "::").replace("/", "::"); Vector rc = EDITOR_DEF(base + "/_recent_scenes", Array()); ERR_FAIL_INDEX(p_idx, rc.size()); @@ -3635,13 +3635,13 @@ void EditorNode::_save_optimized() { } - project_settings->add_remapped_path(GlobalConfig::get_singleton()->localize_path(get_edited_scene()->get_filename()),GlobalConfig::get_singleton()->localize_path(path),platform); + project_settings->add_remapped_path(ProjectSettings::get_singleton()->localize_path(get_edited_scene()->get_filename()),ProjectSettings::get_singleton()->localize_path(path),platform); #endif } void EditorNode::_update_recent_scenes() { - String base = "_" + GlobalConfig::get_singleton()->get_resource_path().replace("\\", "::").replace("/", "::"); + String base = "_" + ProjectSettings::get_singleton()->get_resource_path().replace("\\", "::").replace("/", "::"); Vector rc = EDITOR_DEF(base + "/_recent_scenes", Array()); recent_scenes->clear(); for (int i = 0; i < rc.size(); i++) { @@ -5419,7 +5419,7 @@ EditorNode::EditorNode() { VisualServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport_rid(), true); scene_root->set_disable_input(true); scene_root->set_as_audio_listener_2d(true); - //scene_root->set_size_override(true,Size2(GlobalConfig::get_singleton()->get("display/width"),GlobalConfig::get_singleton()->get("display/height"))); + //scene_root->set_size_override(true,Size2(ProjectSettings::get_singleton()->get("display/width"),ProjectSettings::get_singleton()->get("display/height"))); //scene_root->set_world_2d( Ref( memnew( World2D )) ); @@ -5948,7 +5948,7 @@ EditorNode::EditorNode() { settings_config_dialog = memnew(EditorSettingsDialog); gui_base->add_child(settings_config_dialog); - project_settings = memnew(ProjectSettings(&editor_data)); + project_settings = memnew(ProjectSettingsEditor(&editor_data)); gui_base->add_child(project_settings); import_confirmation = memnew(ConfirmationDialog); @@ -6275,7 +6275,7 @@ EditorNode::EditorNode() { Physics2DServer::get_singleton()->set_active(false); // no physics by default if editor ScriptServer::set_scripting_enabled(false); // no scripting by default if editor - //GlobalConfig::get_singleton()->set("render/room_cull_enabled",false); + //ProjectSettings::get_singleton()->set("render/room_cull_enabled",false); reference_resource_mem = true; save_external_resources_mem = true; @@ -6288,7 +6288,7 @@ EditorNode::EditorNode() { //store project name in ssettings String project_name; //figure it out from path - project_name = GlobalConfig::get_singleton()->get_resource_path().replace("\\", "/"); + project_name = ProjectSettings::get_singleton()->get_resource_path().replace("\\", "/"); print_line("path: " + project_name); if (project_name.length() && project_name[project_name.length() - 1] == '/') project_name = project_name.substr(0, project_name.length() - 1); @@ -6296,7 +6296,7 @@ EditorNode::EditorNode() { project_name = project_name.replace("/", "::"); if (project_name != "") { - EditorSettings::get_singleton()->set("projects/" + project_name, GlobalConfig::get_singleton()->get_resource_path()); + EditorSettings::get_singleton()->set("projects/" + project_name, ProjectSettings::get_singleton()->get_resource_path()); EditorSettings::get_singleton()->raise_order("projects/" + project_name); EditorSettings::get_singleton()->save(); } @@ -6377,8 +6377,8 @@ EditorNode::EditorNode() { _initializing_addons = true; Vector addons; - if (GlobalConfig::get_singleton()->has("editor_plugins/enabled")) { - addons = GlobalConfig::get_singleton()->get("editor_plugins/enabled"); + if (ProjectSettings::get_singleton()->has("editor_plugins/enabled")) { + addons = ProjectSettings::get_singleton()->get("editor_plugins/enabled"); } for (int i = 0; i < addons.size(); i++) { diff --git a/editor/editor_node.h b/editor/editor_node.h index 228fbe7196..e5a4cf654a 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -64,7 +64,7 @@ #include "editor/editor_log.h" #include "editor/editor_run_script.h" #include "editor/project_export.h" -#include "editor/project_settings.h" +#include "editor/project_settings_editor.h" #include "editor/resources_dock.h" #include "editor/run_settings_dialog.h" #include "editor/scene_tree_dock.h" @@ -310,7 +310,7 @@ private: //OptimizedPresetsDialog *optimized_presets; EditorSettingsDialog *settings_config_dialog; RunSettingsDialog *run_settings_dialog; - ProjectSettings *project_settings; + ProjectSettingsEditor *project_settings; EditorFileDialog *file; ExportTemplateManager *export_template_manager; FileDialog *file_templates; diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index c6b9d4bb41..6ab1468b1d 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -30,7 +30,7 @@ #include "editor_plugin_settings.h" #include "editor_node.h" -#include "global_config.h" +#include "project_settings.h" #include "io/config_file.h" #include "os/file_access.h" #include "os/main_loop.h" @@ -82,7 +82,7 @@ void EditorPluginSettings::update_plugins() { plugins.sort(); - Vector active_plugins = GlobalConfig::get_singleton()->get("editor_plugins/enabled"); + Vector active_plugins = ProjectSettings::get_singleton()->get("editor_plugins/enabled"); for (int i = 0; i < plugins.size(); i++) { diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 5d68de3bb6..3a6b34b7b4 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -31,7 +31,7 @@ #include "editor_scale.h" #include "editor_settings.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "message_queue.h" @@ -206,7 +206,7 @@ void EditorResourcePreview::_thread() { } else { String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); - String cache_base = GlobalConfig::get_singleton()->globalize_path(item.path).md5_text(); + String cache_base = ProjectSettings::get_singleton()->globalize_path(item.path).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); //does not have it, try to load a cached thumbnail diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index 8d01484b34..aa97dd237b 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -30,7 +30,7 @@ #include "editor_run.h" #include "editor_settings.h" -#include "global_config.h" +#include "project_settings.h" EditorRun::Status EditorRun::get_status() const { @@ -40,7 +40,7 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li List args; - String resource_path = GlobalConfig::get_singleton()->get_resource_path(); + String resource_path = ProjectSettings::get_singleton()->get_resource_path(); String remote_host = EditorSettings::get_singleton()->get("network/debug/remote_host"); int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); @@ -79,12 +79,12 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li Size2 desired_size; - desired_size.x = GlobalConfig::get_singleton()->get("display/window/size/width"); - desired_size.y = GlobalConfig::get_singleton()->get("display/window/size/height"); + desired_size.x = ProjectSettings::get_singleton()->get("display/window/size/width"); + desired_size.y = ProjectSettings::get_singleton()->get("display/window/size/height"); Size2 test_size; - test_size.x = GlobalConfig::get_singleton()->get("display/window/size/test_width"); - test_size.y = GlobalConfig::get_singleton()->get("display/window/size/test_height"); + test_size.x = ProjectSettings::get_singleton()->get("display/window/size/test_width"); + test_size.y = ProjectSettings::get_singleton()->get("display/window/size/test_height"); if (test_size.x > 0 && test_size.y > 0) { desired_size = test_size; diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 4ab1a435f8..e653502c0e 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -30,7 +30,7 @@ #include "editor_settings.h" #include "editor_node.h" -#include "global_config.h" +#include "project_settings.h" #include "io/compression.h" #include "io/config_file.h" #include "io/file_access_memory.h" @@ -329,7 +329,7 @@ void EditorSettings::create() { dir->change_dir("config"); - String pcp = GlobalConfig::get_singleton()->get_resource_path(); + String pcp = ProjectSettings::get_singleton()->get_resource_path(); if (pcp.ends_with("/")) pcp = config_path.substr(0, pcp.size() - 1); pcp = pcp.get_file() + "-" + pcp.md5_text(); diff --git a/editor/file_type_cache.cpp b/editor/file_type_cache.cpp index de6ee171ae..100ebe21cd 100644 --- a/editor/file_type_cache.cpp +++ b/editor/file_type_cache.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "file_type_cache.h" -#include "global_config.h" +#include "project_settings.h" #include "os/file_access.h" FileTypeCache *FileTypeCache::singleton = NULL; @@ -55,7 +55,7 @@ void FileTypeCache::set_file_type(const String &p_path, const String &p_type) { void FileTypeCache::load() { GLOBAL_LOCK_FUNCTION - String project = GlobalConfig::get_singleton()->get_resource_path(); + String project = ProjectSettings::get_singleton()->get_resource_path(); FileAccess *f = FileAccess::open(project + "/file_type_cache.cch", FileAccess::READ); if (!f) { @@ -80,7 +80,7 @@ void FileTypeCache::load() { void FileTypeCache::save() { GLOBAL_LOCK_FUNCTION - String project = GlobalConfig::get_singleton()->get_resource_path(); + String project = ProjectSettings::get_singleton()->get_resource_path(); FileAccess *f = FileAccess::open(project + "/file_type_cache.cch", FileAccess::WRITE); if (!f) { diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index fe66cd7009..ae3fdede73 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -31,7 +31,7 @@ #include "editor_node.h" #include "editor_settings.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" #include "os/dir_access.h" #include "os/file_access.h" @@ -879,7 +879,7 @@ void FileSystemDock::_file_option(int p_option) { String path = files->get_item_metadata(idx); if (p_option == FILE_SHOW_IN_EXPLORER) { - String dir = GlobalConfig::get_singleton()->globalize_path(path); + String dir = ProjectSettings::get_singleton()->globalize_path(path); dir = dir.substr(0, dir.find_last("/")); OS::get_singleton()->shell_open(String("file://") + dir); return; @@ -1067,7 +1067,7 @@ void FileSystemDock::_folder_option(int p_option) { break; case FOLDER_SHOW_IN_EXPLORER: String path = item->get_metadata(tree->get_selected_column()); - String dir = GlobalConfig::get_singleton()->globalize_path(path); + String dir = ProjectSettings::get_singleton()->globalize_path(path); OS::get_singleton()->shell_open(String("file://") + dir); return; } diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 7e23a422f7..98020ed9b8 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -416,26 +416,26 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String bool force_normal = normal == 1; if (compress_mode == COMPRESS_VIDEO_RAM) { - //must import in all formats + //must import in all formats, in order of priority (so platform choses the best supported one. IE, etc2 over etc). //Android, GLES 2.x - if (GlobalConfig::get_singleton()->get("rendering/vram_compression/import_s3tc")) { + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc")) { _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, Image::COMPRESS_S3TC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); r_platform_variants->push_back("s3tc"); } - if (GlobalConfig::get_singleton()->get("rendering/vram_compression/import_etc")) { - _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); - r_platform_variants->push_back("etc"); - } - - if (GlobalConfig::get_singleton()->get("rendering/vram_compression/import_etc2")) { + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); r_platform_variants->push_back("etc2"); } - if (GlobalConfig::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) { + _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + r_platform_variants->push_back("etc"); + } + + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { _save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); r_platform_variants->push_back("pvrtc"); diff --git a/editor/io_plugins/editor_export_scene.cpp b/editor/io_plugins/editor_export_scene.cpp index bdf9dc6844..390217053a 100644 --- a/editor/io_plugins/editor_export_scene.cpp +++ b/editor/io_plugins/editor_export_scene.cpp @@ -30,7 +30,7 @@ #include "editor_export_scene.h" #if 0 #include "editor/editor_settings.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/dir_access.h" @@ -63,7 +63,7 @@ Vector EditorSceneExportPlugin::custom_export(String& p_path,const Ref< uint64_t sd=0; String smd5; - String gp = GlobalConfig::get_singleton()->globalize_path(p_path); + String gp = ProjectSettings::get_singleton()->globalize_path(p_path); String md5=gp.md5_text(); String tmp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/"); diff --git a/editor/io_plugins/editor_scene_import_plugin.cpp b/editor/io_plugins/editor_scene_import_plugin.cpp index fed02b0e72..5f0e928844 100644 --- a/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/editor/io_plugins/editor_scene_import_plugin.cpp @@ -31,7 +31,7 @@ #if 0 #include "editor/create_dialog.h" #include "editor/editor_node.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_saver.h" #include "os/file_access.h" #include "os/os.h" @@ -672,9 +672,9 @@ void EditorSceneImportDialog::_choose_save_file(const String& p_path) { void EditorSceneImportDialog::_choose_script(const String& p_path) { - String p = GlobalConfig::get_singleton()->localize_path(p_path); + String p = ProjectSettings::get_singleton()->localize_path(p_path); if (!p.is_resource_file()) - p=GlobalConfig::get_singleton()->get_resource_path().path_to(p_path.get_base_dir())+p_path.get_file(); + p=ProjectSettings::get_singleton()->get_resource_path().path_to(p_path.get_base_dir())+p_path.get_file(); script_path->set_text(p); } @@ -727,7 +727,7 @@ void EditorSceneImportDialog::_import(bool p_and_open) { if (texture_action->get_selected()==0) dst_path=save_path->get_text();//.get_base_dir(); else - dst_path=GlobalConfig::get_singleton()->get("import/shared_textures"); + dst_path=ProjectSettings::get_singleton()->get("import/shared_textures"); uint32_t flags=0; @@ -1277,7 +1277,7 @@ EditorSceneImportDialog::EditorSceneImportDialog(EditorNode *p_editor, EditorSce set_hide_on_ok(false); GLOBAL_DEF("import/shared_textures","res://"); - GlobalConfig::get_singleton()->set_custom_property_info("import/shared_textures",PropertyInfo(Variant::STRING,"import/shared_textures",PROPERTY_HINT_DIR)); + ProjectSettings::get_singleton()->set_custom_property_info("import/shared_textures",PropertyInfo(Variant::STRING,"import/shared_textures",PROPERTY_HINT_DIR)); import_hb->add_constant_override("separation",30); @@ -2812,7 +2812,7 @@ Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, c String path = texture->get_path(); String fname= path.get_file(); - String target_path = GlobalConfig::get_singleton()->localize_path(target_res_path.plus_file(fname)); + String target_path = ProjectSettings::get_singleton()->localize_path(target_res_path.plus_file(fname)); progress.step(TTR("Import Image:")+" "+fname,3+(idx)*100/imagemap.size()); idx++; diff --git a/editor/io_plugins/editor_texture_import_plugin.cpp b/editor/io_plugins/editor_texture_import_plugin.cpp index d48675fa30..842c43f4de 100644 --- a/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/editor/io_plugins/editor_texture_import_plugin.cpp @@ -33,7 +33,7 @@ #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "editor_atlas.h" -#include "global_config.h" +#include "project_settings.h" #include "io/image_loader.h" #include "io/marshalls.h" #include "io/resource_saver.h" @@ -1653,7 +1653,7 @@ Vector EditorTextureImportPlugin::custom_export(const String& p_path, c uint8_t f4[4]; encode_uint32(flags,&f4[0]); MD5Init(&ctx); - String gp = GlobalConfig::get_singleton()->globalize_path(p_path); + String gp = ProjectSettings::get_singleton()->globalize_path(p_path); CharString cs = gp.utf8(); MD5Update(&ctx,(unsigned char*)cs.get_data(),cs.length()); MD5Update(&ctx,f4,4); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index c3e1f60ccc..82b03d3a19 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -31,7 +31,7 @@ #include "editor/animation_editor.h" #include "editor/editor_settings.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/keyboard.h" @@ -372,7 +372,7 @@ void AnimationPlayerEditor::_animation_save_in_path(const Ref &p_resou flg |= ResourceSaver::FLAG_RELATIVE_PATHS; */ - String path = GlobalConfig::get_singleton()->localize_path(p_path); + String path = ProjectSettings::get_singleton()->localize_path(p_path); Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); if (err != OK) { diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index d67832e10b..58948071fd 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "animation_tree_editor_plugin.h" -#include "core/global_config.h" +#include "core/project_settings.h" #include "core/io/resource_loader.h" #include "os/input.h" #include "os/keyboard.h" @@ -1408,7 +1408,7 @@ AnimationTreeEditor::AnimationTreeEditor() { file_dialog = memnew(EditorFileDialog); file_dialog->set_enable_multiple_selection(true); - file_dialog->set_current_dir(GlobalConfig::get_singleton()->get_resource_path()); + file_dialog->set_current_dir(ProjectSettings::get_singleton()->get_resource_path()); add_child(file_dialog); file_dialog->connect("file_selected", this, "_file_dialog_selected"); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index c8936c8c35..4f07fdba2b 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -35,7 +35,7 @@ #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h" #include "editor/script_editor_debugger.h" -#include "global_config.h" +#include "project_settings.h" #include "os/input.h" #include "os/keyboard.h" #include "print_string.h" @@ -2007,7 +2007,7 @@ void CanvasItemEditor::_viewport_draw() { VisualServer::get_singleton()->canvas_item_add_line(ci, transform.xform(display_rotate_from), transform.xform(display_rotate_to), rotate_color); } - Size2 screen_size = Size2(GlobalConfig::get_singleton()->get("display/window/size/width"), GlobalConfig::get_singleton()->get("display/window/size/height")); + Size2 screen_size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")); Vector2 screen_endpoints[4] = { transform.xform(Vector2(0, 0)), @@ -2323,7 +2323,7 @@ void CanvasItemEditor::_update_scrollbars() { h_scroll->set_begin(Point2(0, size.height - hmin.height)); h_scroll->set_end(Point2(size.width - vmin.width, size.height)); - Size2 screen_rect = Size2(GlobalConfig::get_singleton()->get("display/window/size/width"), GlobalConfig::get_singleton()->get("display/window/size/height")); + Size2 screen_rect = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")); Rect2 local_rect = Rect2(Point2(), viewport->get_size() - Size2(vmin.width, hmin.height)); @@ -3697,7 +3697,7 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons } } - instanced_scene->set_filename(GlobalConfig::get_singleton()->localize_path(path)); + instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path)); editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene); editor_data->get_undo_redo().add_do_method(instanced_scene, "set_owner", editor->get_edited_scene()); diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 7f8581535c..ce6eefd694 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -186,7 +186,7 @@ Ref EditorPackedScenePreviewPlugin::generate(const RES &p_from) { Ref EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path) { String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); - String cache_base = GlobalConfig::get_singleton()->globalize_path(p_path).md5_text(); + String cache_base = ProjectSettings::get_singleton()->globalize_path(p_path).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); //does not have it, try to load a cached thumbnail diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index ea7a84d2f4..463b6360ad 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "resource_preloader_editor_plugin.h" #include "editor/editor_settings.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" void ResourcePreloaderEditor::_gui_input(Ref p_event) { diff --git a/editor/plugins/sample_editor_plugin.cpp b/editor/plugins/sample_editor_plugin.cpp index a9af5823e3..0b99ab5460 100644 --- a/editor/plugins/sample_editor_plugin.cpp +++ b/editor/plugins/sample_editor_plugin.cpp @@ -31,7 +31,7 @@ #if 0 #include "editor/editor_settings.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" diff --git a/editor/plugins/sample_library_editor_plugin.cpp b/editor/plugins/sample_library_editor_plugin.cpp index 9eb1af70d1..04c805165f 100644 --- a/editor/plugins/sample_library_editor_plugin.cpp +++ b/editor/plugins/sample_library_editor_plugin.cpp @@ -32,7 +32,7 @@ #include "sample_library_editor_plugin.h" #include "editor/editor_settings.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" #include "sample_editor_plugin.h" #include "scene/main/viewport.h" diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index f7952e77f2..aeb16f13ee 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -32,7 +32,7 @@ #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "editor/script_editor_debugger.h" -#include "global_config.h" +#include "project_settings.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/file_access.h" @@ -1603,8 +1603,8 @@ bool ScriptEditor::edit(const Ref