project_settings.cpp 61 KB

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