project_settings.cpp 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  1. /**************************************************************************/
  2. /* project_settings.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "project_settings.h"
  31. #include "core/core_bind.h" // For Compression enum.
  32. #include "core/input/input_map.h"
  33. #include "core/io/config_file.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/io/file_access.h"
  36. #include "core/io/file_access_pack.h"
  37. #include "core/io/marshalls.h"
  38. #include "core/io/resource_uid.h"
  39. #include "core/object/script_language.h"
  40. #include "core/os/keyboard.h"
  41. #include "core/templates/rb_set.h"
  42. #include "core/variant/typed_array.h"
  43. #include "core/variant/variant_parser.h"
  44. #include "core/version.h"
  45. #ifdef TOOLS_ENABLED
  46. #include "modules/modules_enabled.gen.h" // For mono.
  47. #endif // TOOLS_ENABLED
  48. const String ProjectSettings::PROJECT_DATA_DIR_NAME_SUFFIX = "godot";
  49. ProjectSettings *ProjectSettings::singleton = nullptr;
  50. ProjectSettings *ProjectSettings::get_singleton() {
  51. return singleton;
  52. }
  53. String ProjectSettings::get_project_data_dir_name() const {
  54. return project_data_dir_name;
  55. }
  56. String ProjectSettings::get_project_data_path() const {
  57. return "res://" + get_project_data_dir_name();
  58. }
  59. String ProjectSettings::get_resource_path() const {
  60. return resource_path;
  61. }
  62. String ProjectSettings::get_imported_files_path() const {
  63. return get_project_data_path().path_join("imported");
  64. }
  65. #ifdef TOOLS_ENABLED
  66. // Returns the features that a project must have when opened with this build of Godot.
  67. // This is used by the project manager to provide the initial_settings for config/features.
  68. const PackedStringArray ProjectSettings::get_required_features() {
  69. PackedStringArray features;
  70. features.append(VERSION_BRANCH);
  71. #ifdef REAL_T_IS_DOUBLE
  72. features.append("Double Precision");
  73. #endif
  74. return features;
  75. }
  76. // Returns the features supported by this build of Godot. Includes all required features.
  77. const PackedStringArray ProjectSettings::_get_supported_features() {
  78. PackedStringArray features = get_required_features();
  79. #ifdef MODULE_MONO_ENABLED
  80. features.append("C#");
  81. #endif
  82. // Allow pinning to a specific patch number or build type by marking
  83. // them as supported. They're only used if the user adds them manually.
  84. features.append(VERSION_BRANCH "." _MKSTR(VERSION_PATCH));
  85. features.append(VERSION_FULL_CONFIG);
  86. features.append(VERSION_FULL_BUILD);
  87. #ifdef RD_ENABLED
  88. features.append("Forward Plus");
  89. features.append("Mobile");
  90. #endif
  91. #ifdef GLES3_ENABLED
  92. features.append("GL Compatibility");
  93. #endif
  94. return features;
  95. }
  96. // Returns the features that this project needs but this build of Godot lacks.
  97. const PackedStringArray ProjectSettings::get_unsupported_features(const PackedStringArray &p_project_features) {
  98. PackedStringArray unsupported_features;
  99. PackedStringArray supported_features = singleton->_get_supported_features();
  100. for (int i = 0; i < p_project_features.size(); i++) {
  101. if (!supported_features.has(p_project_features[i])) {
  102. // Temporary compatibility code to ease upgrade to 4.0 beta 2+.
  103. if (p_project_features[i].begins_with("Vulkan")) {
  104. continue;
  105. }
  106. unsupported_features.append(p_project_features[i]);
  107. }
  108. }
  109. unsupported_features.sort();
  110. return unsupported_features;
  111. }
  112. // Returns the features that both this project has and this build of Godot has, ensuring required features exist.
  113. const PackedStringArray ProjectSettings::_trim_to_supported_features(const PackedStringArray &p_project_features) {
  114. // Remove unsupported features if present.
  115. PackedStringArray features = PackedStringArray(p_project_features);
  116. PackedStringArray supported_features = _get_supported_features();
  117. for (int i = p_project_features.size() - 1; i > -1; i--) {
  118. if (!supported_features.has(p_project_features[i])) {
  119. features.remove_at(i);
  120. }
  121. }
  122. // Add required features if not present.
  123. PackedStringArray required_features = get_required_features();
  124. for (int i = 0; i < required_features.size(); i++) {
  125. if (!features.has(required_features[i])) {
  126. features.append(required_features[i]);
  127. }
  128. }
  129. features.sort();
  130. return features;
  131. }
  132. #endif // TOOLS_ENABLED
  133. String ProjectSettings::localize_path(const String &p_path) const {
  134. String path = p_path.simplify_path();
  135. if (resource_path.is_empty() || (path.is_absolute_path() && !path.begins_with(resource_path))) {
  136. return path;
  137. }
  138. // Check if we have a special path (like res://) or a protocol identifier.
  139. int p = path.find("://");
  140. bool found = false;
  141. if (p > 0) {
  142. found = true;
  143. for (int i = 0; i < p; i++) {
  144. if (!is_ascii_alphanumeric_char(path[i])) {
  145. found = false;
  146. break;
  147. }
  148. }
  149. }
  150. if (found) {
  151. return path;
  152. }
  153. Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  154. if (dir->change_dir(path) == OK) {
  155. String cwd = dir->get_current_dir();
  156. cwd = cwd.replace("\\", "/");
  157. // Ensure that we end with a '/'.
  158. // This is important to ensure that we do not wrongly localize the resource path
  159. // in an absolute path that just happens to contain this string but points to a
  160. // different folder (e.g. "/my/project" as resource_path would be contained in
  161. // "/my/project_data", even though the latter is not part of res://.
  162. // `path_join("")` is an easy way to ensure we have a trailing '/'.
  163. const String res_path = resource_path.path_join("");
  164. // DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
  165. // so we must make sure we have it as well in order to compare with 'res_path'.
  166. cwd = cwd.path_join("");
  167. if (!cwd.begins_with(res_path)) {
  168. return path;
  169. }
  170. return cwd.replace_first(res_path, "res://");
  171. } else {
  172. int sep = path.rfind_char('/');
  173. if (sep == -1) {
  174. return "res://" + path;
  175. }
  176. String parent = path.substr(0, sep);
  177. String plocal = localize_path(parent);
  178. if (plocal.is_empty()) {
  179. return "";
  180. }
  181. // Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/'
  182. if (plocal[plocal.length() - 1] == '/') {
  183. sep += 1;
  184. }
  185. return plocal + path.substr(sep, path.size() - sep);
  186. }
  187. }
  188. void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) {
  189. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  190. // Duplicate so that if value is array or dictionary, changing the setting will not change the stored initial value.
  191. props[p_name].initial = p_value.duplicate();
  192. }
  193. void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
  194. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  195. props[p_name].restart_if_changed = p_restart;
  196. }
  197. void ProjectSettings::set_as_basic(const String &p_name, bool p_basic) {
  198. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  199. props[p_name].basic = p_basic;
  200. }
  201. void ProjectSettings::set_as_internal(const String &p_name, bool p_internal) {
  202. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  203. props[p_name].internal = p_internal;
  204. }
  205. void ProjectSettings::set_ignore_value_in_docs(const String &p_name, bool p_ignore) {
  206. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  207. #ifdef DEBUG_METHODS_ENABLED
  208. props[p_name].ignore_value_in_docs = p_ignore;
  209. #endif
  210. }
  211. bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
  212. ERR_FAIL_COND_V_MSG(!props.has(p_name), false, vformat("Request for nonexistent project setting: '%s'.", p_name));
  213. #ifdef DEBUG_METHODS_ENABLED
  214. return props[p_name].ignore_value_in_docs;
  215. #else
  216. return false;
  217. #endif
  218. }
  219. void ProjectSettings::add_hidden_prefix(const String &p_prefix) {
  220. ERR_FAIL_COND_MSG(hidden_prefixes.has(p_prefix), vformat("Hidden prefix '%s' already exists.", p_prefix));
  221. hidden_prefixes.push_back(p_prefix);
  222. }
  223. String ProjectSettings::globalize_path(const String &p_path) const {
  224. if (p_path.begins_with("res://")) {
  225. if (!resource_path.is_empty()) {
  226. return p_path.replace("res:/", resource_path);
  227. }
  228. return p_path.replace("res://", "");
  229. } else if (p_path.begins_with("uid://")) {
  230. const String path = ResourceUID::uid_to_path(p_path);
  231. if (!resource_path.is_empty()) {
  232. return path.replace("res:/", resource_path);
  233. }
  234. return path.replace("res://", "");
  235. } else if (p_path.begins_with("user://")) {
  236. String data_dir = OS::get_singleton()->get_user_data_dir();
  237. if (!data_dir.is_empty()) {
  238. return p_path.replace("user:/", data_dir);
  239. }
  240. return p_path.replace("user://", "");
  241. }
  242. return p_path;
  243. }
  244. bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
  245. _THREAD_SAFE_METHOD_
  246. if (p_value.get_type() == Variant::NIL) {
  247. props.erase(p_name);
  248. if (p_name.operator String().begins_with("autoload/")) {
  249. String node_name = p_name.operator String().split("/")[1];
  250. if (autoloads.has(node_name)) {
  251. remove_autoload(node_name);
  252. }
  253. } else if (p_name.operator String().begins_with("global_group/")) {
  254. String group_name = p_name.operator String().get_slice("/", 1);
  255. if (global_groups.has(group_name)) {
  256. remove_global_group(group_name);
  257. }
  258. }
  259. } else {
  260. if (p_name == CoreStringName(_custom_features)) {
  261. Vector<String> custom_feature_array = String(p_value).split(",");
  262. for (int i = 0; i < custom_feature_array.size(); i++) {
  263. custom_features.insert(custom_feature_array[i]);
  264. }
  265. _queue_changed();
  266. return true;
  267. }
  268. { // Feature overrides.
  269. int dot = p_name.operator String().find_char('.');
  270. if (dot != -1) {
  271. Vector<String> s = p_name.operator String().split(".");
  272. for (int i = 1; i < s.size(); i++) {
  273. String feature = s[i].strip_edges();
  274. Pair<StringName, StringName> feature_override(feature, p_name);
  275. if (!feature_overrides.has(s[0])) {
  276. feature_overrides[s[0]] = LocalVector<Pair<StringName, StringName>>();
  277. }
  278. feature_overrides[s[0]].push_back(feature_override);
  279. }
  280. }
  281. }
  282. if (props.has(p_name)) {
  283. props[p_name].variant = p_value;
  284. } else {
  285. props[p_name] = VariantContainer(p_value, last_order++);
  286. }
  287. if (p_name.operator String().begins_with("autoload/")) {
  288. String node_name = p_name.operator String().split("/")[1];
  289. AutoloadInfo autoload;
  290. autoload.name = node_name;
  291. String path = p_value;
  292. if (path.begins_with("*")) {
  293. autoload.is_singleton = true;
  294. autoload.path = path.substr(1).simplify_path();
  295. } else {
  296. autoload.path = path.simplify_path();
  297. }
  298. add_autoload(autoload);
  299. } else if (p_name.operator String().begins_with("global_group/")) {
  300. String group_name = p_name.operator String().get_slice("/", 1);
  301. add_global_group(group_name, p_value);
  302. }
  303. }
  304. _queue_changed();
  305. return true;
  306. }
  307. bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
  308. _THREAD_SAFE_METHOD_
  309. if (!props.has(p_name)) {
  310. return false;
  311. }
  312. r_ret = props[p_name].variant;
  313. return true;
  314. }
  315. Variant ProjectSettings::get_setting_with_override(const StringName &p_name) const {
  316. _THREAD_SAFE_METHOD_
  317. StringName name = p_name;
  318. if (feature_overrides.has(name)) {
  319. const LocalVector<Pair<StringName, StringName>> &overrides = feature_overrides[name];
  320. for (uint32_t i = 0; i < overrides.size(); i++) {
  321. if (OS::get_singleton()->has_feature(overrides[i].first)) { // Custom features are checked in OS.has_feature() already. No need to check twice.
  322. if (props.has(overrides[i].second)) {
  323. name = overrides[i].second;
  324. break;
  325. }
  326. }
  327. }
  328. }
  329. if (!props.has(name)) {
  330. WARN_PRINT(vformat("Property not found: '%s'.", String(name)));
  331. return Variant();
  332. }
  333. return props[name].variant;
  334. }
  335. struct _VCSort {
  336. String name;
  337. Variant::Type type = Variant::VARIANT_MAX;
  338. int order = 0;
  339. uint32_t flags = 0;
  340. bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
  341. };
  342. void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  343. _THREAD_SAFE_METHOD_
  344. RBSet<_VCSort> vclist;
  345. for (const KeyValue<StringName, VariantContainer> &E : props) {
  346. const VariantContainer *v = &E.value;
  347. if (v->hide_from_editor) {
  348. continue;
  349. }
  350. _VCSort vc;
  351. vc.name = E.key;
  352. vc.order = v->order;
  353. vc.type = v->variant.get_type();
  354. bool internal = v->internal;
  355. if (!internal) {
  356. for (const String &F : hidden_prefixes) {
  357. if (vc.name.begins_with(F)) {
  358. internal = true;
  359. break;
  360. }
  361. }
  362. }
  363. if (internal) {
  364. vc.flags = PROPERTY_USAGE_STORAGE;
  365. } else {
  366. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  367. }
  368. if (v->internal) {
  369. vc.flags |= PROPERTY_USAGE_INTERNAL;
  370. }
  371. if (v->basic) {
  372. vc.flags |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  373. }
  374. if (v->restart_if_changed) {
  375. vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  376. }
  377. vclist.insert(vc);
  378. }
  379. for (const _VCSort &E : vclist) {
  380. String prop_info_name = E.name;
  381. int dot = prop_info_name.find_char('.');
  382. if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
  383. prop_info_name = prop_info_name.substr(0, dot);
  384. }
  385. if (custom_prop_info.has(prop_info_name)) {
  386. PropertyInfo pi = custom_prop_info[prop_info_name];
  387. pi.name = E.name;
  388. pi.usage = E.flags;
  389. p_list->push_back(pi);
  390. } else {
  391. p_list->push_back(PropertyInfo(E.type, E.name, PROPERTY_HINT_NONE, "", E.flags));
  392. }
  393. }
  394. }
  395. void ProjectSettings::_queue_changed() {
  396. if (is_changed || !MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) {
  397. return;
  398. }
  399. is_changed = true;
  400. callable_mp(this, &ProjectSettings::_emit_changed).call_deferred();
  401. }
  402. void ProjectSettings::_emit_changed() {
  403. if (!is_changed) {
  404. return;
  405. }
  406. is_changed = false;
  407. emit_signal("settings_changed");
  408. }
  409. bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) {
  410. if (PackedData::get_singleton()->is_disabled()) {
  411. return false;
  412. }
  413. bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files, p_offset) == OK;
  414. if (!ok) {
  415. return false;
  416. }
  417. if (project_loaded) {
  418. // This pack may have declared new global classes (make sure they are picked up).
  419. refresh_global_class_list();
  420. // This pack may have defined new UIDs, make sure they are cached.
  421. ResourceUID::get_singleton()->load_from_cache(false);
  422. }
  423. //if data.pck is found, all directory access will be from here
  424. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  425. using_datapack = true;
  426. return true;
  427. }
  428. void ProjectSettings::_convert_to_last_version(int p_from_version) {
  429. #ifndef DISABLE_DEPRECATED
  430. if (p_from_version <= 3) {
  431. // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
  432. for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) {
  433. Variant value = E.value.variant;
  434. if (String(E.key).begins_with("input/") && value.get_type() == Variant::ARRAY) {
  435. Array array = value;
  436. Dictionary action;
  437. action["deadzone"] = Variant(0.5f);
  438. action["events"] = array;
  439. E.value.variant = action;
  440. }
  441. }
  442. }
  443. #endif // DISABLE_DEPRECATED
  444. }
  445. /*
  446. * This method is responsible for loading a project.godot file and/or data file
  447. * using the following merit order:
  448. * - If using NetworkClient, try to lookup project file or fail.
  449. * - If --main-pack was passed by the user (`p_main_pack`), load it or fail.
  450. * - Search for project PCKs automatically. For each step we try loading a potential
  451. * PCK, and if it doesn't work, we proceed to the next step. If any step succeeds,
  452. * we try loading the project settings, and abort if it fails. Steps:
  453. * o Bundled PCK in the executable.
  454. * o [macOS only] PCK with same basename as the binary in the .app resource dir.
  455. * o PCK with same basename as the binary in the binary's directory. We handle both
  456. * changing the extension to '.pck' (e.g. 'win_game.exe' -> 'win_game.pck') and
  457. * appending '.pck' to the binary name (e.g. 'linux_game' -> 'linux_game.pck').
  458. * o PCK with the same basename as the binary in the current working directory.
  459. * Same as above for the two possible PCK file names.
  460. * - On relevant platforms (Android/iOS), lookup project file in OS resource path.
  461. * If found, load it or fail.
  462. * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we
  463. * are running from source code.
  464. * If not found and `p_upwards` is true (--upwards passed by the user), look for
  465. * project files in parent folders up to the system root (used to run a game
  466. * from command line while in a subfolder).
  467. * If a project file is found, load it or fail.
  468. * If nothing was found, error out.
  469. */
  470. Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  471. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  472. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  473. // If the OS would rather use a specific location, then it will not be empty.
  474. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  475. if (!resource_path.is_empty() && resource_path[resource_path.length() - 1] == '/') {
  476. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  477. }
  478. }
  479. // Attempt with a user-defined main pack first
  480. if (!p_main_pack.is_empty()) {
  481. bool ok = _load_resource_pack(p_main_pack);
  482. ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, vformat("Cannot open resource pack '%s'.", p_main_pack));
  483. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  484. if (err == OK && !p_ignore_override) {
  485. // Load override from location of the main pack
  486. // Optional, we don't mind if it fails
  487. _load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
  488. }
  489. return err;
  490. }
  491. String exec_path = OS::get_singleton()->get_executable_path();
  492. if (!exec_path.is_empty()) {
  493. // We do several tests sequentially until one succeeds to find a PCK,
  494. // and if so, we attempt loading it at the end.
  495. // Attempt with PCK bundled into executable.
  496. bool found = _load_resource_pack(exec_path);
  497. // Attempt with exec_name.pck.
  498. // (This is the usual case when distributing a Godot game.)
  499. String exec_dir = exec_path.get_base_dir();
  500. String exec_filename = exec_path.get_file();
  501. String exec_basename = exec_filename.get_basename();
  502. // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
  503. // or the exec path's basename + '.pck' (Windows).
  504. // We need to test both possibilities as extensions for Linux binaries are optional
  505. // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
  506. #ifdef MACOS_ENABLED
  507. if (!found) {
  508. // Attempt to load PCK from macOS .app bundle resources.
  509. found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_basename + ".pck")) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"));
  510. }
  511. #endif
  512. if (!found) {
  513. // Try to load data pack at the location of the executable.
  514. // As mentioned above, we have two potential names to attempt.
  515. found = _load_resource_pack(exec_dir.path_join(exec_basename + ".pck")) || _load_resource_pack(exec_dir.path_join(exec_filename + ".pck"));
  516. }
  517. if (!found) {
  518. // If we couldn't find them next to the executable, we attempt
  519. // the current working directory. Same story, two tests.
  520. found = _load_resource_pack(exec_basename + ".pck") || _load_resource_pack(exec_filename + ".pck");
  521. }
  522. // If we opened our package, try and load our project.
  523. if (found) {
  524. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  525. if (err == OK && !p_ignore_override) {
  526. // Load overrides from the PCK and the executable location.
  527. // Optional, we don't mind if either fails.
  528. _load_settings_text("res://override.cfg");
  529. _load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
  530. }
  531. return err;
  532. }
  533. }
  534. // Try to use the filesystem for files, according to OS.
  535. // (Only Android -when reading from pck- and iOS use this.)
  536. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  537. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  538. if (err == OK && !p_ignore_override) {
  539. // Optional, we don't mind if it fails.
  540. _load_settings_text("res://override.cfg");
  541. }
  542. return err;
  543. }
  544. // Nothing was found, try to find a project file in provided path (`p_path`)
  545. // or, if requested (`p_upwards`) in parent directories.
  546. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  547. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", p_path));
  548. d->change_dir(p_path);
  549. String current_dir = d->get_current_dir();
  550. bool found = false;
  551. Error err;
  552. while (true) {
  553. // Set the resource path early so things can be resolved when loading.
  554. resource_path = current_dir;
  555. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  556. err = _load_settings_text_or_binary(current_dir.path_join("project.godot"), current_dir.path_join("project.binary"));
  557. if (err == OK && !p_ignore_override) {
  558. // Optional, we don't mind if it fails.
  559. _load_settings_text(current_dir.path_join("override.cfg"));
  560. found = true;
  561. break;
  562. }
  563. if (p_upwards) {
  564. // Try to load settings ascending through parent directories
  565. d->change_dir("..");
  566. if (d->get_current_dir() == current_dir) {
  567. break; // not doing anything useful
  568. }
  569. current_dir = d->get_current_dir();
  570. } else {
  571. break;
  572. }
  573. }
  574. if (!found) {
  575. return err;
  576. }
  577. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  578. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  579. }
  580. return OK;
  581. }
  582. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  583. Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override);
  584. if (err == OK && !p_ignore_override) {
  585. String custom_settings = GLOBAL_GET("application/config/project_settings_override");
  586. if (!custom_settings.is_empty()) {
  587. _load_settings_text(custom_settings);
  588. }
  589. }
  590. // Updating the default value after the project settings have loaded.
  591. bool use_hidden_directory = GLOBAL_GET("application/config/use_hidden_project_data_directory");
  592. project_data_dir_name = (use_hidden_directory ? "." : "") + PROJECT_DATA_DIR_NAME_SUFFIX;
  593. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  594. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  595. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  596. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  597. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  598. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  599. load_scene_groups_cache();
  600. project_loaded = err == OK;
  601. return err;
  602. }
  603. bool ProjectSettings::has_setting(const String &p_var) const {
  604. _THREAD_SAFE_METHOD_
  605. return props.has(p_var);
  606. }
  607. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  608. Error err;
  609. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  610. if (err != OK) {
  611. return err;
  612. }
  613. uint8_t hdr[4];
  614. f->get_buffer(hdr, 4);
  615. ERR_FAIL_COND_V_MSG((hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G'), ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
  616. uint32_t count = f->get_32();
  617. for (uint32_t i = 0; i < count; i++) {
  618. uint32_t slen = f->get_32();
  619. CharString cs;
  620. cs.resize(slen + 1);
  621. cs[slen] = 0;
  622. f->get_buffer((uint8_t *)cs.ptr(), slen);
  623. String key;
  624. key.parse_utf8(cs.ptr(), slen);
  625. uint32_t vlen = f->get_32();
  626. Vector<uint8_t> d;
  627. d.resize(vlen);
  628. f->get_buffer(d.ptrw(), vlen);
  629. Variant value;
  630. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  631. ERR_CONTINUE_MSG(err != OK, vformat("Error decoding property: '%s'.", key));
  632. set(key, value);
  633. }
  634. return OK;
  635. }
  636. Error ProjectSettings::_load_settings_text(const String &p_path) {
  637. Error err;
  638. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  639. if (f.is_null()) {
  640. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  641. // This needs to be streamlined if we want decent error reporting
  642. return ERR_FILE_NOT_FOUND;
  643. }
  644. VariantParser::StreamFile stream;
  645. stream.f = f;
  646. String assign;
  647. Variant value;
  648. VariantParser::Tag next_tag;
  649. int lines = 0;
  650. String error_text;
  651. String section;
  652. int config_version = 0;
  653. while (true) {
  654. assign = Variant();
  655. next_tag.fields.clear();
  656. next_tag.name = String();
  657. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  658. if (err == ERR_FILE_EOF) {
  659. // If we're loading a project.godot from source code, we can operate some
  660. // ProjectSettings conversions if need be.
  661. _convert_to_last_version(config_version);
  662. last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
  663. return OK;
  664. }
  665. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Error parsing '%s' at line %d: %s File might be corrupted.", p_path, lines, error_text));
  666. if (!assign.is_empty()) {
  667. if (section.is_empty() && assign == "config_version") {
  668. config_version = value;
  669. ERR_FAIL_COND_V_MSG(config_version > CONFIG_VERSION, ERR_FILE_CANT_OPEN, vformat("Can't open project at '%s', its `config_version` (%d) is from a more recent and incompatible version of the engine. Expected config version: %d.", p_path, config_version, CONFIG_VERSION));
  670. } else {
  671. if (section.is_empty()) {
  672. set(assign, value);
  673. } else {
  674. set(section + "/" + assign, value);
  675. }
  676. }
  677. } else if (!next_tag.name.is_empty()) {
  678. section = next_tag.name;
  679. }
  680. }
  681. }
  682. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  683. // Attempt first to load the binary project.godot file.
  684. Error err = _load_settings_binary(p_bin_path);
  685. if (err == OK) {
  686. return OK;
  687. } else if (err != ERR_FILE_NOT_FOUND) {
  688. // If the file exists but can't be loaded, we want to know it.
  689. ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_bin_path, err));
  690. }
  691. // Fallback to text-based project.godot file if binary was not found.
  692. err = _load_settings_text(p_text_path);
  693. if (err == OK) {
  694. return OK;
  695. } else if (err != ERR_FILE_NOT_FOUND) {
  696. ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_text_path, err));
  697. }
  698. return err;
  699. }
  700. Error ProjectSettings::load_custom(const String &p_path) {
  701. if (p_path.ends_with(".binary")) {
  702. return _load_settings_binary(p_path);
  703. }
  704. return _load_settings_text(p_path);
  705. }
  706. int ProjectSettings::get_order(const String &p_name) const {
  707. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, vformat("Request for nonexistent project setting: '%s'.", p_name));
  708. return props[p_name].order;
  709. }
  710. void ProjectSettings::set_order(const String &p_name, int p_order) {
  711. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  712. props[p_name].order = p_order;
  713. }
  714. void ProjectSettings::set_builtin_order(const String &p_name) {
  715. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  716. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  717. props[p_name].order = last_builtin_order++;
  718. }
  719. }
  720. bool ProjectSettings::is_builtin_setting(const String &p_name) const {
  721. // Return true because a false negative is worse than a false positive.
  722. ERR_FAIL_COND_V_MSG(!props.has(p_name), true, vformat("Request for nonexistent project setting: '%s'.", p_name));
  723. return props[p_name].order < NO_BUILTIN_ORDER_BASE;
  724. }
  725. void ProjectSettings::clear(const String &p_name) {
  726. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  727. props.erase(p_name);
  728. }
  729. Error ProjectSettings::save() {
  730. Error error = save_custom(get_resource_path().path_join("project.godot"));
  731. if (error == OK) {
  732. last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
  733. }
  734. return error;
  735. }
  736. Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) {
  737. Error err;
  738. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  739. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.binary at '%s'.", p_file));
  740. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  741. file->store_buffer(hdr, 4);
  742. int count = 0;
  743. for (const KeyValue<String, List<String>> &E : p_props) {
  744. count += E.value.size();
  745. }
  746. if (!p_custom_features.is_empty()) {
  747. // Store how many properties are saved, add one for custom features, which must always go first.
  748. file->store_32(count + 1);
  749. String key = CoreStringName(_custom_features);
  750. file->store_pascal_string(key);
  751. int len;
  752. err = encode_variant(p_custom_features, nullptr, len, false);
  753. ERR_FAIL_COND_V(err != OK, err);
  754. Vector<uint8_t> buff;
  755. buff.resize(len);
  756. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  757. ERR_FAIL_COND_V(err != OK, err);
  758. file->store_32(len);
  759. file->store_buffer(buff.ptr(), buff.size());
  760. } else {
  761. // Store how many properties are saved.
  762. file->store_32(count);
  763. }
  764. for (const KeyValue<String, List<String>> &E : p_props) {
  765. for (const String &key : E.value) {
  766. String k = key;
  767. if (!E.key.is_empty()) {
  768. k = E.key + "/" + k;
  769. }
  770. Variant value;
  771. if (p_custom.has(k)) {
  772. value = p_custom[k];
  773. } else {
  774. value = get(k);
  775. }
  776. file->store_pascal_string(k);
  777. int len;
  778. err = encode_variant(value, nullptr, len, true);
  779. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  780. Vector<uint8_t> buff;
  781. buff.resize(len);
  782. err = encode_variant(value, buff.ptrw(), len, true);
  783. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  784. file->store_32(len);
  785. file->store_buffer(buff.ptr(), buff.size());
  786. }
  787. }
  788. return OK;
  789. }
  790. Error ProjectSettings::_save_settings_text(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) {
  791. Error err;
  792. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  793. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.godot - %s.", p_file));
  794. file->store_line("; Engine configuration file.");
  795. file->store_line("; It's best edited using the editor UI and not directly,");
  796. file->store_line("; since the parameters that go here are not all obvious.");
  797. file->store_line(";");
  798. file->store_line("; Format:");
  799. file->store_line("; [section] ; section goes between []");
  800. file->store_line("; param=value ; assign values to parameters");
  801. file->store_line("");
  802. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  803. if (!p_custom_features.is_empty()) {
  804. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  805. }
  806. file->store_string("\n");
  807. for (const KeyValue<String, List<String>> &E : p_props) {
  808. if (E.key != p_props.begin()->key) {
  809. file->store_string("\n");
  810. }
  811. if (!E.key.is_empty()) {
  812. file->store_string("[" + E.key + "]\n\n");
  813. }
  814. for (const String &F : E.value) {
  815. String key = F;
  816. if (!E.key.is_empty()) {
  817. key = E.key + "/" + key;
  818. }
  819. Variant value;
  820. if (p_custom.has(key)) {
  821. value = p_custom[key];
  822. } else {
  823. value = get(key);
  824. }
  825. String vstr;
  826. VariantWriter::write_to_string(value, vstr);
  827. file->store_string(F.property_name_encode() + "=" + vstr + "\n");
  828. }
  829. }
  830. return OK;
  831. }
  832. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  833. return save_custom(p_file);
  834. }
  835. #ifdef TOOLS_ENABLED
  836. bool _csproj_exists(const String &p_root_dir) {
  837. Ref<DirAccess> dir = DirAccess::open(p_root_dir);
  838. ERR_FAIL_COND_V(dir.is_null(), false);
  839. dir->list_dir_begin();
  840. String file_name = dir->_get_next();
  841. while (file_name != "") {
  842. if (!dir->current_is_dir() && file_name.get_extension() == "csproj") {
  843. return true;
  844. }
  845. file_name = dir->_get_next();
  846. }
  847. return false;
  848. }
  849. #endif // TOOLS_ENABLED
  850. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  851. ERR_FAIL_COND_V_MSG(p_path.is_empty(), ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  852. #ifdef TOOLS_ENABLED
  853. PackedStringArray project_features = get_setting("application/config/features");
  854. // If there is no feature list currently present, force one to generate.
  855. if (project_features.is_empty()) {
  856. project_features = ProjectSettings::get_required_features();
  857. }
  858. // Check the rendering API.
  859. const String rendering_api = has_setting("rendering/renderer/rendering_method") ? (String)get_setting("rendering/renderer/rendering_method") : String();
  860. if (!rendering_api.is_empty()) {
  861. // Add the rendering API as a project feature if it doesn't already exist.
  862. if (!project_features.has(rendering_api)) {
  863. project_features.append(rendering_api);
  864. }
  865. }
  866. // Check for the existence of a csproj file.
  867. if (_csproj_exists(get_resource_path())) {
  868. // If there is a csproj file, add the C# feature if it doesn't already exist.
  869. if (!project_features.has("C#")) {
  870. project_features.append("C#");
  871. }
  872. } else {
  873. // If there isn't a csproj file, remove the C# feature if it exists.
  874. if (project_features.has("C#")) {
  875. project_features.remove_at(project_features.find("C#"));
  876. }
  877. }
  878. project_features = _trim_to_supported_features(project_features);
  879. set_setting("application/config/features", project_features);
  880. #endif // TOOLS_ENABLED
  881. RBSet<_VCSort> vclist;
  882. if (p_merge_with_current) {
  883. for (const KeyValue<StringName, VariantContainer> &G : props) {
  884. const VariantContainer *v = &G.value;
  885. if (v->hide_from_editor) {
  886. continue;
  887. }
  888. if (p_custom.has(G.key)) {
  889. continue;
  890. }
  891. _VCSort vc;
  892. vc.name = G.key; //*k;
  893. vc.order = v->order;
  894. vc.type = v->variant.get_type();
  895. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  896. if (v->variant == v->initial) {
  897. continue;
  898. }
  899. vclist.insert(vc);
  900. }
  901. }
  902. for (const KeyValue<String, Variant> &E : p_custom) {
  903. // Lookup global prop to store in the same order
  904. RBMap<StringName, VariantContainer>::Iterator global_prop = props.find(E.key);
  905. _VCSort vc;
  906. vc.name = E.key;
  907. vc.order = global_prop ? global_prop->value.order : 0xFFFFFFF;
  908. vc.type = E.value.get_type();
  909. vc.flags = PROPERTY_USAGE_STORAGE;
  910. vclist.insert(vc);
  911. }
  912. RBMap<String, List<String>> save_props;
  913. for (const _VCSort &E : vclist) {
  914. String category = E.name;
  915. String name = E.name;
  916. int div = category.find_char('/');
  917. if (div < 0) {
  918. category = "";
  919. } else {
  920. category = category.substr(0, div);
  921. name = name.substr(div + 1, name.size());
  922. }
  923. save_props[category].push_back(name);
  924. }
  925. String save_features;
  926. for (int i = 0; i < p_custom_features.size(); i++) {
  927. if (i > 0) {
  928. save_features += ",";
  929. }
  930. String f = p_custom_features[i].strip_edges().replace("\"", "");
  931. save_features += f;
  932. }
  933. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  934. return _save_settings_text(p_path, save_props, p_custom, save_features);
  935. } else if (p_path.ends_with(".binary")) {
  936. return _save_settings_binary(p_path, save_props, p_custom, save_features);
  937. } else {
  938. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, vformat("Unknown config file format: '%s'.", p_path));
  939. }
  940. }
  941. Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
  942. Variant ret;
  943. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  944. ProjectSettings::get_singleton()->set(p_var, p_default);
  945. }
  946. ret = GLOBAL_GET(p_var);
  947. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  948. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  949. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  950. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  951. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  952. ProjectSettings::get_singleton()->set_as_internal(p_var, p_internal);
  953. return ret;
  954. }
  955. Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
  956. Variant ret = _GLOBAL_DEF(p_info.name, p_default, p_restart_if_changed, p_ignore_value_in_docs, p_basic, p_internal);
  957. ProjectSettings::get_singleton()->set_custom_property_info(p_info);
  958. return ret;
  959. }
  960. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  961. ERR_FAIL_COND(!p_info.has("name"));
  962. ERR_FAIL_COND(!p_info.has("type"));
  963. PropertyInfo pinfo;
  964. pinfo.name = p_info["name"];
  965. ERR_FAIL_COND(!props.has(pinfo.name));
  966. pinfo.type = Variant::Type(p_info["type"].operator int());
  967. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  968. if (p_info.has("hint")) {
  969. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  970. }
  971. if (p_info.has("hint_string")) {
  972. pinfo.hint_string = p_info["hint_string"];
  973. }
  974. set_custom_property_info(pinfo);
  975. }
  976. void ProjectSettings::set_custom_property_info(const PropertyInfo &p_info) {
  977. const String &prop_name = p_info.name;
  978. ERR_FAIL_COND(!props.has(prop_name));
  979. custom_prop_info[prop_name] = p_info;
  980. }
  981. const HashMap<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  982. return custom_prop_info;
  983. }
  984. bool ProjectSettings::is_using_datapack() const {
  985. return using_datapack;
  986. }
  987. bool ProjectSettings::is_project_loaded() const {
  988. return project_loaded;
  989. }
  990. bool ProjectSettings::_property_can_revert(const StringName &p_name) const {
  991. return props.has(p_name);
  992. }
  993. bool ProjectSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  994. const RBMap<StringName, ProjectSettings::VariantContainer>::Element *value = props.find(p_name);
  995. if (value) {
  996. r_property = value->value().initial.duplicate();
  997. return true;
  998. }
  999. return false;
  1000. }
  1001. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  1002. set(p_setting, p_value);
  1003. }
  1004. Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_default_value) const {
  1005. if (has_setting(p_setting)) {
  1006. return get(p_setting);
  1007. } else {
  1008. return p_default_value;
  1009. }
  1010. }
  1011. void ProjectSettings::refresh_global_class_list() {
  1012. // This is called after mounting a new PCK file to pick up class changes.
  1013. is_global_class_list_loaded = false; // Make sure we read from the freshly mounted PCK.
  1014. Array script_classes = get_global_class_list();
  1015. for (int i = 0; i < script_classes.size(); i++) {
  1016. Dictionary c = script_classes[i];
  1017. if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
  1018. continue;
  1019. }
  1020. ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"]);
  1021. }
  1022. }
  1023. TypedArray<Dictionary> ProjectSettings::get_global_class_list() {
  1024. if (is_global_class_list_loaded) {
  1025. return global_class_list;
  1026. }
  1027. Ref<ConfigFile> cf;
  1028. cf.instantiate();
  1029. if (cf->load(get_global_class_list_path()) == OK) {
  1030. global_class_list = cf->get_value("", "list", Array());
  1031. } else {
  1032. #ifndef TOOLS_ENABLED
  1033. // Script classes can't be recreated in exported project, so print an error.
  1034. ERR_PRINT("Could not load global script cache.");
  1035. #endif
  1036. }
  1037. // File read succeeded or failed. If it failed, assume everything is still okay.
  1038. // We will later receive updated class data in store_global_class_list().
  1039. is_global_class_list_loaded = true;
  1040. return global_class_list;
  1041. }
  1042. String ProjectSettings::get_global_class_list_path() const {
  1043. return get_project_data_path().path_join("global_script_class_cache.cfg");
  1044. }
  1045. void ProjectSettings::store_global_class_list(const Array &p_classes) {
  1046. Ref<ConfigFile> cf;
  1047. cf.instantiate();
  1048. cf->set_value("", "list", p_classes);
  1049. cf->save(get_global_class_list_path());
  1050. global_class_list = p_classes;
  1051. }
  1052. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  1053. return custom_features.has(p_feature);
  1054. }
  1055. const HashMap<StringName, ProjectSettings::AutoloadInfo> &ProjectSettings::get_autoload_list() const {
  1056. return autoloads;
  1057. }
  1058. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  1059. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  1060. autoloads[p_autoload.name] = p_autoload;
  1061. }
  1062. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  1063. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  1064. autoloads.erase(p_autoload);
  1065. }
  1066. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  1067. return autoloads.has(p_autoload);
  1068. }
  1069. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  1070. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  1071. return autoloads[p_name];
  1072. }
  1073. const HashMap<StringName, String> &ProjectSettings::get_global_groups_list() const {
  1074. return global_groups;
  1075. }
  1076. void ProjectSettings::add_global_group(const StringName &p_name, const String &p_description) {
  1077. ERR_FAIL_COND_MSG(p_name == StringName(), "Trying to add global group with no name.");
  1078. global_groups[p_name] = p_description;
  1079. }
  1080. void ProjectSettings::remove_global_group(const StringName &p_name) {
  1081. ERR_FAIL_COND_MSG(!global_groups.has(p_name), "Trying to remove non-existent global group.");
  1082. global_groups.erase(p_name);
  1083. }
  1084. bool ProjectSettings::has_global_group(const StringName &p_name) const {
  1085. return global_groups.has(p_name);
  1086. }
  1087. void ProjectSettings::remove_scene_groups_cache(const StringName &p_path) {
  1088. scene_groups_cache.erase(p_path);
  1089. }
  1090. void ProjectSettings::add_scene_groups_cache(const StringName &p_path, const HashSet<StringName> &p_cache) {
  1091. scene_groups_cache[p_path] = p_cache;
  1092. }
  1093. void ProjectSettings::save_scene_groups_cache() {
  1094. Ref<ConfigFile> cf;
  1095. cf.instantiate();
  1096. for (const KeyValue<StringName, HashSet<StringName>> &E : scene_groups_cache) {
  1097. if (E.value.is_empty()) {
  1098. continue;
  1099. }
  1100. Array list;
  1101. for (const StringName &group : E.value) {
  1102. list.push_back(group);
  1103. }
  1104. cf->set_value(E.key, "groups", list);
  1105. }
  1106. cf->save(get_scene_groups_cache_path());
  1107. }
  1108. String ProjectSettings::get_scene_groups_cache_path() const {
  1109. return get_project_data_path().path_join("scene_groups_cache.cfg");
  1110. }
  1111. void ProjectSettings::load_scene_groups_cache() {
  1112. Ref<ConfigFile> cf;
  1113. cf.instantiate();
  1114. if (cf->load(get_scene_groups_cache_path()) == OK) {
  1115. List<String> scene_paths;
  1116. cf->get_sections(&scene_paths);
  1117. for (const String &E : scene_paths) {
  1118. Array scene_groups = cf->get_value(E, "groups", Array());
  1119. HashSet<StringName> cache;
  1120. for (const Variant &scene_group : scene_groups) {
  1121. cache.insert(scene_group);
  1122. }
  1123. add_scene_groups_cache(E, cache);
  1124. }
  1125. }
  1126. }
  1127. const HashMap<StringName, HashSet<StringName>> &ProjectSettings::get_scene_groups_cache() const {
  1128. return scene_groups_cache;
  1129. }
  1130. #ifdef TOOLS_ENABLED
  1131. void ProjectSettings::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1132. const String pf = p_function;
  1133. if (p_idx == 0) {
  1134. if (pf == "has_setting" || pf == "set_setting" || pf == "get_setting" || pf == "get_setting_with_override" ||
  1135. pf == "set_order" || pf == "get_order" || pf == "set_initial_value" || pf == "set_as_basic" ||
  1136. pf == "set_as_internal" || pf == "set_restart_if_changed" || pf == "clear") {
  1137. for (const KeyValue<StringName, VariantContainer> &E : props) {
  1138. if (E.value.hide_from_editor) {
  1139. continue;
  1140. }
  1141. r_options->push_back(String(E.key).quote());
  1142. }
  1143. }
  1144. }
  1145. Object::get_argument_options(p_function, p_idx, r_options);
  1146. }
  1147. #endif
  1148. void ProjectSettings::_bind_methods() {
  1149. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  1150. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  1151. ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant()));
  1152. ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override);
  1153. ClassDB::bind_method(D_METHOD("get_global_class_list"), &ProjectSettings::get_global_class_list);
  1154. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  1155. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  1156. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  1157. ClassDB::bind_method(D_METHOD("set_as_basic", "name", "basic"), &ProjectSettings::set_as_basic);
  1158. ClassDB::bind_method(D_METHOD("set_as_internal", "name", "internal"), &ProjectSettings::set_as_internal);
  1159. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  1160. ClassDB::bind_method(D_METHOD("set_restart_if_changed", "name", "restart"), &ProjectSettings::set_restart_if_changed);
  1161. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  1162. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  1163. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  1164. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  1165. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));
  1166. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  1167. ADD_SIGNAL(MethodInfo("settings_changed"));
  1168. }
  1169. void ProjectSettings::_add_builtin_input_map() {
  1170. if (InputMap::get_singleton()) {
  1171. HashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  1172. for (KeyValue<String, List<Ref<InputEvent>>> &E : builtins) {
  1173. Array events;
  1174. // Convert list of input events into array
  1175. for (List<Ref<InputEvent>>::Element *I = E.value.front(); I; I = I->next()) {
  1176. events.push_back(I->get());
  1177. }
  1178. Dictionary action;
  1179. action["deadzone"] = Variant(InputMap::DEFAULT_DEADZONE);
  1180. action["events"] = events;
  1181. String action_name = "input/" + E.key;
  1182. GLOBAL_DEF(action_name, action);
  1183. input_presets.push_back(action_name);
  1184. }
  1185. }
  1186. }
  1187. ProjectSettings::ProjectSettings() {
  1188. // Initialization of engine variables should be done in the setup() method,
  1189. // so that the values can be overridden from project.godot or project.binary.
  1190. CRASH_COND_MSG(singleton != nullptr, "Instantiating a new ProjectSettings singleton is not supported.");
  1191. singleton = this;
  1192. #ifdef TOOLS_ENABLED
  1193. // Available only at runtime in editor builds. Needs to be processed before anything else to work properly.
  1194. if (!Engine::get_singleton()->is_editor_hint()) {
  1195. String editor_features = OS::get_singleton()->get_environment("GODOT_EDITOR_CUSTOM_FEATURES");
  1196. if (!editor_features.is_empty()) {
  1197. PackedStringArray feature_list = editor_features.split(",");
  1198. for (const String &s : feature_list) {
  1199. custom_features.insert(s);
  1200. }
  1201. }
  1202. }
  1203. #endif
  1204. GLOBAL_DEF_BASIC("application/config/name", "");
  1205. GLOBAL_DEF_BASIC(PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary());
  1206. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT), "");
  1207. GLOBAL_DEF_BASIC("application/config/version", "");
  1208. GLOBAL_DEF_INTERNAL(PropertyInfo(Variant::STRING, "application/config/tags"), PackedStringArray());
  1209. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"), "");
  1210. GLOBAL_DEF("application/run/disable_stdout", false);
  1211. GLOBAL_DEF("application/run/disable_stderr", false);
  1212. GLOBAL_DEF("application/run/print_header", true);
  1213. GLOBAL_DEF("application/run/enable_alt_space_menu", false);
  1214. GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true);
  1215. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  1216. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  1217. GLOBAL_DEF("application/config/project_settings_override", "");
  1218. GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
  1219. GLOBAL_DEF("application/config/auto_accept_quit", true);
  1220. GLOBAL_DEF("application/config/quit_on_go_back", true);
  1221. // The default window size is tuned to:
  1222. // - Have a 16:9 aspect ratio,
  1223. // - Have both dimensions divisible by 8 to better play along with video recording,
  1224. // - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings).
  1225. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "1,7680,1,or_greater"), 1152); // 8K resolution
  1226. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "1,4320,1,or_greater"), 648); // 8K resolution
  1227. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"), 0);
  1228. // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
  1229. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_position_type", PROPERTY_HINT_ENUM, "Absolute,Center of Primary Screen,Center of Other Screen,Center of Screen With Mouse Pointer,Center of Screen With Keyboard Focus"), 1);
  1230. GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR2I, "display/window/size/initial_position"), Vector2i());
  1231. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), 0);
  1232. GLOBAL_DEF_BASIC("display/window/size/resizable", true);
  1233. GLOBAL_DEF_BASIC("display/window/size/borderless", false);
  1234. GLOBAL_DEF("display/window/size/always_on_top", false);
  1235. GLOBAL_DEF("display/window/size/transparent", false);
  1236. GLOBAL_DEF("display/window/size/extend_to_title", false);
  1237. GLOBAL_DEF("display/window/size/no_focus", false);
  1238. GLOBAL_DEF("display/window/size/sharp_corners", false);
  1239. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution
  1240. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution
  1241. GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
  1242. GLOBAL_DEF("animation/warnings/check_invalid_track_paths", true);
  1243. GLOBAL_DEF("animation/warnings/check_angle_interpolation_type_conflicting", true);
  1244. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"), "res://default_bus_layout.tres");
  1245. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type", PROPERTY_HINT_ENUM, "Stream,Sample"), 0);
  1246. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type.web", PROPERTY_HINT_ENUM, "Stream,Sample"), 1);
  1247. GLOBAL_DEF_RST("audio/general/text_to_speech", false);
  1248. GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
  1249. GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
  1250. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/ios/session_category", PROPERTY_HINT_ENUM, "Ambient,Multi Route,Play and Record,Playback,Record,Solo Ambient"), 0);
  1251. GLOBAL_DEF("audio/general/ios/mix_with_others", false);
  1252. _add_builtin_input_map();
  1253. // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
  1254. custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::INT, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor");
  1255. GLOBAL_DEF("display/window/subwindows/embed_subwindows", true);
  1256. // Keep the enum values in sync with the `DisplayServer::VSyncMode` enum.
  1257. custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox");
  1258. GLOBAL_DEF("display/window/frame_pacing/android/enable_frame_pacing", true);
  1259. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/frame_pacing/android/swappy_mode", PROPERTY_HINT_ENUM, "pipeline_forced_on,auto_fps_pipeline_forced_on,auto_fps_auto_pipeline"), 2);
  1260. #ifdef DISABLE_DEPRECATED
  1261. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Safe:1,Separate");
  1262. #else
  1263. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Unsafe (deprecated),Safe,Separate");
  1264. #endif
  1265. GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
  1266. GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
  1267. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,canvas_items,viewport"), "disabled");
  1268. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand"), "keep");
  1269. GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "display/window/stretch/scale", PROPERTY_HINT_RANGE, "0.5,8.0,0.01"), 1.0);
  1270. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/scale_mode", PROPERTY_HINT_ENUM, "fractional,integer"), "fractional");
  1271. GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1"), 16384);
  1272. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "debug/settings/profiler/max_timestamp_query_elements", PROPERTY_HINT_RANGE, "256,65535,1"), 256);
  1273. GLOBAL_DEF(PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching"), Compression::zstd_long_distance_matching);
  1274. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"), Compression::zstd_level);
  1275. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1"), Compression::zstd_window_log_size);
  1276. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::zlib_level);
  1277. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::gzip_level);
  1278. GLOBAL_DEF("debug/settings/crash_handler/message",
  1279. String("Please include this when reporting the bug to the project developer."));
  1280. GLOBAL_DEF("debug/settings/crash_handler/message.editor",
  1281. String("Please include this when reporting the bug on: https://github.com/godotengine/godot/issues"));
  1282. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/occlusion_culling/bvh_build_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), 2);
  1283. GLOBAL_DEF_RST("rendering/occlusion_culling/jitter_projection", true);
  1284. GLOBAL_DEF_RST("internationalization/rendering/force_right_to_left_layout_direction", false);
  1285. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "internationalization/rendering/root_node_layout_direction", PROPERTY_HINT_ENUM, "Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale"), 0);
  1286. GLOBAL_DEF_BASIC("internationalization/rendering/root_node_auto_translate", true);
  1287. GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/timers/incremental_search_max_interval_msec", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"), 2000);
  1288. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "gui/timers/tooltip_delay_sec", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5);
  1289. #ifdef TOOLS_ENABLED
  1290. GLOBAL_DEF("gui/timers/tooltip_delay_sec.editor_hint", 0.5);
  1291. #endif
  1292. GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true);
  1293. GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true);
  1294. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/frame_queue_size", PROPERTY_HINT_RANGE, "2,3,1"), 2);
  1295. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/swapchain_image_count", PROPERTY_HINT_RANGE, "2,4,1"), 3);
  1296. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/block_size_kb", PROPERTY_HINT_RANGE, "4,2048,1,or_greater"), 256);
  1297. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/max_size_mb", PROPERTY_HINT_RANGE, "1,1024,1,or_greater"), 128);
  1298. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_upload_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1299. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_download_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1300. GLOBAL_DEF_RST(PropertyInfo(Variant::BOOL, "rendering/rendering_device/pipeline_cache/enable"), true);
  1301. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/rendering_device/pipeline_cache/save_chunk_size_mb", PROPERTY_HINT_RANGE, "0.000001,64.0,0.001,or_greater"), 3.0);
  1302. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/vulkan/max_descriptors_per_pool", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1303. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", 16384);
  1304. custom_prop_info["rendering/rendering_device/d3d12/max_resource_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", PROPERTY_HINT_RANGE, "512,262144");
  1305. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", 1024);
  1306. custom_prop_info["rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", PROPERTY_HINT_RANGE, "256,2048");
  1307. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_misc_descriptors_per_frame", 512);
  1308. custom_prop_info["rendering/rendering_device/d3d12/max_misc_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_misc_descriptors_per_frame", PROPERTY_HINT_RANGE, "32,4096");
  1309. // The default value must match the minor part of the Agility SDK version
  1310. // installed by the scripts provided in the repository
  1311. // (check `misc/scripts/install_d3d12_sdk_windows.py`).
  1312. // For example, if the script installs 1.613.3, the default value must be 613.
  1313. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/agility_sdk_version"), 613);
  1314. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Linear Mipmap,Nearest Mipmap"), 1);
  1315. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_repeat", PROPERTY_HINT_ENUM, "Disable,Enable,Mirror"), 0);
  1316. GLOBAL_DEF("collada/use_ambient", false);
  1317. // Input settings
  1318. GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_long_press_as_right_click", false);
  1319. GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_pan_and_scale_gestures", false);
  1320. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "input_devices/pointing/android/rotary_input_scroll_axis", PROPERTY_HINT_ENUM, "Horizontal,Vertical"), 1);
  1321. // These properties will not show up in the dialog. If you want to exclude whole groups, use add_hidden_prefix().
  1322. GLOBAL_DEF_INTERNAL("application/config/features", PackedStringArray());
  1323. GLOBAL_DEF_INTERNAL("internationalization/locale/translation_remaps", PackedStringArray());
  1324. GLOBAL_DEF_INTERNAL("internationalization/locale/translations", PackedStringArray());
  1325. GLOBAL_DEF_INTERNAL("internationalization/locale/translations_pot_files", PackedStringArray());
  1326. GLOBAL_DEF_INTERNAL("internationalization/locale/translation_add_builtin_strings_to_pot", false);
  1327. ProjectSettings::get_singleton()->add_hidden_prefix("input/");
  1328. }
  1329. ProjectSettings::ProjectSettings(const String &p_path) {
  1330. if (load_custom(p_path) == OK) {
  1331. resource_path = p_path.get_base_dir();
  1332. project_loaded = true;
  1333. }
  1334. }
  1335. ProjectSettings::~ProjectSettings() {
  1336. if (singleton == this) {
  1337. singleton = nullptr;
  1338. }
  1339. }