project_settings.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. /*************************************************************************/
  2. /* project_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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/core_string_names.h"
  33. #include "core/input/input_map.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/io/file_access.h"
  36. #include "core/io/file_access_network.h"
  37. #include "core/io/file_access_pack.h"
  38. #include "core/io/marshalls.h"
  39. #include "core/os/keyboard.h"
  40. #include "core/os/os.h"
  41. #include "core/variant/variant_parser.h"
  42. ProjectSettings *ProjectSettings::singleton = nullptr;
  43. ProjectSettings *ProjectSettings::get_singleton() {
  44. return singleton;
  45. }
  46. String ProjectSettings::get_resource_path() const {
  47. return resource_path;
  48. }
  49. const String ProjectSettings::IMPORTED_FILES_PATH("res://.godot/imported");
  50. String ProjectSettings::localize_path(const String &p_path) const {
  51. if (resource_path == "") {
  52. return p_path; //not initialized yet
  53. }
  54. if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
  55. (p_path.is_absolute_path() && !p_path.begins_with(resource_path))) {
  56. return p_path.simplify_path();
  57. }
  58. DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  59. String path = p_path.replace("\\", "/").simplify_path();
  60. if (dir->change_dir(path) == OK) {
  61. String cwd = dir->get_current_dir();
  62. cwd = cwd.replace("\\", "/");
  63. memdelete(dir);
  64. // Ensure that we end with a '/'.
  65. // This is important to ensure that we do not wrongly localize the resource path
  66. // in an absolute path that just happens to contain this string but points to a
  67. // different folder (e.g. "/my/project" as resource_path would be contained in
  68. // "/my/project_data", even though the latter is not part of res://.
  69. // `plus_file("")` is an easy way to ensure we have a trailing '/'.
  70. const String res_path = resource_path.plus_file("");
  71. // DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
  72. // so we must make sure we have it as well in order to compare with 'res_path'.
  73. cwd = cwd.plus_file("");
  74. if (!cwd.begins_with(res_path)) {
  75. return p_path;
  76. }
  77. return cwd.replace_first(res_path, "res://");
  78. } else {
  79. memdelete(dir);
  80. int sep = path.rfind("/");
  81. if (sep == -1) {
  82. return "res://" + path;
  83. }
  84. String parent = path.substr(0, sep);
  85. String plocal = localize_path(parent);
  86. if (plocal == "") {
  87. return "";
  88. }
  89. // Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/'
  90. if (plocal[plocal.length() - 1] == '/') {
  91. sep += 1;
  92. }
  93. return plocal + path.substr(sep, path.size() - sep);
  94. }
  95. }
  96. void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) {
  97. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  98. props[p_name].initial = p_value;
  99. }
  100. void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
  101. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  102. props[p_name].restart_if_changed = p_restart;
  103. }
  104. void ProjectSettings::set_as_basic(const String &p_name, bool p_basic) {
  105. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  106. props[p_name].basic = p_basic;
  107. }
  108. void ProjectSettings::set_ignore_value_in_docs(const String &p_name, bool p_ignore) {
  109. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  110. #ifdef DEBUG_METHODS_ENABLED
  111. props[p_name].ignore_value_in_docs = p_ignore;
  112. #endif
  113. }
  114. bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
  115. ERR_FAIL_COND_V_MSG(!props.has(p_name), false, "Request for nonexistent project setting: " + p_name + ".");
  116. #ifdef DEBUG_METHODS_ENABLED
  117. return props[p_name].ignore_value_in_docs;
  118. #else
  119. return false;
  120. #endif
  121. }
  122. String ProjectSettings::globalize_path(const String &p_path) const {
  123. if (p_path.begins_with("res://")) {
  124. if (resource_path != "") {
  125. return p_path.replace("res:/", resource_path);
  126. }
  127. return p_path.replace("res://", "");
  128. } else if (p_path.begins_with("user://")) {
  129. String data_dir = OS::get_singleton()->get_user_data_dir();
  130. if (data_dir != "") {
  131. return p_path.replace("user:/", data_dir);
  132. }
  133. return p_path.replace("user://", "");
  134. }
  135. return p_path;
  136. }
  137. bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
  138. _THREAD_SAFE_METHOD_
  139. if (p_value.get_type() == Variant::NIL) {
  140. props.erase(p_name);
  141. if (p_name.operator String().begins_with("autoload/")) {
  142. String node_name = p_name.operator String().split("/")[1];
  143. if (autoloads.has(node_name)) {
  144. remove_autoload(node_name);
  145. }
  146. }
  147. } else {
  148. if (p_name == CoreStringNames::get_singleton()->_custom_features) {
  149. Vector<String> custom_feature_array = String(p_value).split(",");
  150. for (int i = 0; i < custom_feature_array.size(); i++) {
  151. custom_features.insert(custom_feature_array[i]);
  152. }
  153. return true;
  154. }
  155. if (!disable_feature_overrides) {
  156. int dot = p_name.operator String().find(".");
  157. if (dot != -1) {
  158. Vector<String> s = p_name.operator String().split(".");
  159. bool override_valid = false;
  160. for (int i = 1; i < s.size(); i++) {
  161. String feature = s[i].strip_edges();
  162. if (OS::get_singleton()->has_feature(feature) || custom_features.has(feature)) {
  163. override_valid = true;
  164. break;
  165. }
  166. }
  167. if (override_valid) {
  168. feature_overrides[s[0]] = p_name;
  169. }
  170. }
  171. }
  172. if (props.has(p_name)) {
  173. if (!props[p_name].overridden) {
  174. props[p_name].variant = p_value;
  175. }
  176. } else {
  177. props[p_name] = VariantContainer(p_value, last_order++);
  178. }
  179. if (p_name.operator String().begins_with("autoload/")) {
  180. String node_name = p_name.operator String().split("/")[1];
  181. AutoloadInfo autoload;
  182. autoload.name = node_name;
  183. String path = p_value;
  184. if (path.begins_with("*")) {
  185. autoload.is_singleton = true;
  186. autoload.path = path.substr(1);
  187. } else {
  188. autoload.path = path;
  189. }
  190. add_autoload(autoload);
  191. }
  192. }
  193. return true;
  194. }
  195. bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
  196. _THREAD_SAFE_METHOD_
  197. StringName name = p_name;
  198. if (!disable_feature_overrides && feature_overrides.has(name)) {
  199. name = feature_overrides[name];
  200. }
  201. if (!props.has(name)) {
  202. WARN_PRINT("Property not found: " + String(name));
  203. return false;
  204. }
  205. r_ret = props[name].variant;
  206. return true;
  207. }
  208. struct _VCSort {
  209. String name;
  210. Variant::Type type;
  211. int order;
  212. uint32_t flags;
  213. bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
  214. };
  215. void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  216. _THREAD_SAFE_METHOD_
  217. Set<_VCSort> vclist;
  218. for (Map<StringName, VariantContainer>::Element *E = props.front(); E; E = E->next()) {
  219. const VariantContainer *v = &E->get();
  220. if (v->hide_from_editor) {
  221. continue;
  222. }
  223. _VCSort vc;
  224. vc.name = E->key();
  225. vc.order = v->order;
  226. vc.type = v->variant.get_type();
  227. if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) {
  228. vc.flags = PROPERTY_USAGE_STORAGE;
  229. } else {
  230. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  231. }
  232. if (v->basic) {
  233. vc.flags |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  234. }
  235. if (v->restart_if_changed) {
  236. vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  237. }
  238. vclist.insert(vc);
  239. }
  240. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  241. String prop_info_name = E->get().name;
  242. int dot = prop_info_name.find(".");
  243. if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
  244. prop_info_name = prop_info_name.substr(0, dot);
  245. }
  246. if (custom_prop_info.has(prop_info_name)) {
  247. PropertyInfo pi = custom_prop_info[prop_info_name];
  248. pi.name = E->get().name;
  249. pi.usage = E->get().flags;
  250. p_list->push_back(pi);
  251. } else {
  252. p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags));
  253. }
  254. }
  255. }
  256. bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) {
  257. if (PackedData::get_singleton()->is_disabled()) {
  258. return false;
  259. }
  260. bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files, p_offset) == OK;
  261. if (!ok) {
  262. return false;
  263. }
  264. //if data.pck is found, all directory access will be from here
  265. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  266. using_datapack = true;
  267. return true;
  268. }
  269. void ProjectSettings::_convert_to_last_version(int p_from_version) {
  270. if (p_from_version <= 3) {
  271. // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
  272. for (Map<StringName, ProjectSettings::VariantContainer>::Element *E = props.front(); E; E = E->next()) {
  273. Variant value = E->get().variant;
  274. if (String(E->key()).begins_with("input/") && value.get_type() == Variant::ARRAY) {
  275. Array array = value;
  276. Dictionary action;
  277. action["deadzone"] = Variant(0.5f);
  278. action["events"] = array;
  279. E->get().variant = action;
  280. }
  281. }
  282. }
  283. }
  284. /*
  285. * This method is responsible for loading a project.godot file and/or data file
  286. * using the following merit order:
  287. * - If using NetworkClient, try to lookup project file or fail.
  288. * - If --main-pack was passed by the user (`p_main_pack`), load it or fail.
  289. * - Search for project PCKs automatically. For each step we try loading a potential
  290. * PCK, and if it doesn't work, we proceed to the next step. If any step succeeds,
  291. * we try loading the project settings, and abort if it fails. Steps:
  292. * o Bundled PCK in the executable.
  293. * o [macOS only] PCK with same basename as the binary in the .app resource dir.
  294. * o PCK with same basename as the binary in the binary's directory. We handle both
  295. * changing the extension to '.pck' (e.g. 'win_game.exe' -> 'win_game.pck') and
  296. * appending '.pck' to the binary name (e.g. 'linux_game' -> 'linux_game.pck').
  297. * o PCK with the same basename as the binary in the current working directory.
  298. * Same as above for the two possible PCK file names.
  299. * - On relevant platforms (Android/iOS), lookup project file in OS resource path.
  300. * If found, load it or fail.
  301. * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we
  302. * are running from source code.
  303. * If not found and `p_upwards` is true (--upwards passed by the user), look for
  304. * project files in parent folders up to the system root (used to run a game
  305. * from command line while in a subfolder).
  306. * If a project file is found, load it or fail.
  307. * If nothing was found, error out.
  308. */
  309. Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards) {
  310. // If looking for files in a network client, use it directly
  311. if (FileAccessNetworkClient::get_singleton()) {
  312. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  313. if (err == OK) {
  314. // Optional, we don't mind if it fails
  315. _load_settings_text("res://override.cfg");
  316. }
  317. return err;
  318. }
  319. // Attempt with a user-defined main pack first
  320. if (p_main_pack != "") {
  321. bool ok = _load_resource_pack(p_main_pack);
  322. ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, "Cannot open resource pack '" + p_main_pack + "'.");
  323. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  324. if (err == OK) {
  325. // Load override from location of the main pack
  326. // Optional, we don't mind if it fails
  327. _load_settings_text(p_main_pack.get_base_dir().plus_file("override.cfg"));
  328. }
  329. return err;
  330. }
  331. String exec_path = OS::get_singleton()->get_executable_path();
  332. if (exec_path != "") {
  333. // We do several tests sequentially until one succeeds to find a PCK,
  334. // and if so, we attempt loading it at the end.
  335. // Attempt with PCK bundled into executable.
  336. bool found = _load_resource_pack(exec_path);
  337. // Attempt with exec_name.pck.
  338. // (This is the usual case when distributing a Godot game.)
  339. String exec_dir = exec_path.get_base_dir();
  340. String exec_filename = exec_path.get_file();
  341. String exec_basename = exec_filename.get_basename();
  342. // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
  343. // or the exec path's basename + '.pck' (Windows).
  344. // We need to test both possibilities as extensions for Linux binaries are optional
  345. // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
  346. #ifdef OSX_ENABLED
  347. if (!found) {
  348. // Attempt to load PCK from macOS .app bundle resources.
  349. found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_basename + ".pck")) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_filename + ".pck"));
  350. }
  351. #endif
  352. if (!found) {
  353. // Try to load data pack at the location of the executable.
  354. // As mentioned above, we have two potential names to attempt.
  355. found = _load_resource_pack(exec_dir.plus_file(exec_basename + ".pck")) || _load_resource_pack(exec_dir.plus_file(exec_filename + ".pck"));
  356. }
  357. if (!found) {
  358. // If we couldn't find them next to the executable, we attempt
  359. // the current working directory. Same story, two tests.
  360. found = _load_resource_pack(exec_basename + ".pck") || _load_resource_pack(exec_filename + ".pck");
  361. }
  362. // If we opened our package, try and load our project.
  363. if (found) {
  364. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  365. if (err == OK) {
  366. // Load override from location of the executable.
  367. // Optional, we don't mind if it fails.
  368. _load_settings_text(exec_path.get_base_dir().plus_file("override.cfg"));
  369. }
  370. return err;
  371. }
  372. }
  373. // Try to use the filesystem for files, according to OS.
  374. // (Only Android -when reading from pck- and iOS use this.)
  375. if (OS::get_singleton()->get_resource_dir() != "") {
  376. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  377. // If the OS would rather use a specific location, then it will not be empty.
  378. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  379. if (resource_path != "" && resource_path[resource_path.length() - 1] == '/') {
  380. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  381. }
  382. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  383. if (err == OK) {
  384. // Optional, we don't mind if it fails.
  385. _load_settings_text("res://override.cfg");
  386. }
  387. return err;
  388. }
  389. // Nothing was found, try to find a project file in provided path (`p_path`)
  390. // or, if requested (`p_upwards`) in parent directories.
  391. DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  392. ERR_FAIL_COND_V_MSG(!d, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'.");
  393. d->change_dir(p_path);
  394. String current_dir = d->get_current_dir();
  395. bool found = false;
  396. Error err;
  397. while (true) {
  398. // Set the resource path early so things can be resolved when loading.
  399. resource_path = current_dir;
  400. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  401. err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
  402. if (err == OK) {
  403. // Optional, we don't mind if it fails.
  404. _load_settings_text(current_dir.plus_file("override.cfg"));
  405. found = true;
  406. break;
  407. }
  408. if (p_upwards) {
  409. // Try to load settings ascending through parent directories
  410. d->change_dir("..");
  411. if (d->get_current_dir() == current_dir) {
  412. break; // not doing anything useful
  413. }
  414. current_dir = d->get_current_dir();
  415. } else {
  416. break;
  417. }
  418. }
  419. memdelete(d);
  420. if (!found) {
  421. return err;
  422. }
  423. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  424. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  425. }
  426. return OK;
  427. }
  428. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards) {
  429. Error err = _setup(p_path, p_main_pack, p_upwards);
  430. if (err == OK) {
  431. String custom_settings = GLOBAL_DEF("application/config/project_settings_override", "");
  432. if (custom_settings != "") {
  433. _load_settings_text(custom_settings);
  434. }
  435. }
  436. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  437. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  438. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  439. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  440. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  441. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  442. return err;
  443. }
  444. bool ProjectSettings::has_setting(String p_var) const {
  445. _THREAD_SAFE_METHOD_
  446. return props.has(p_var);
  447. }
  448. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  449. Error err;
  450. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  451. if (err != OK) {
  452. return err;
  453. }
  454. uint8_t hdr[4];
  455. f->get_buffer(hdr, 4);
  456. if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
  457. memdelete(f);
  458. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
  459. }
  460. uint32_t count = f->get_32();
  461. for (uint32_t i = 0; i < count; i++) {
  462. uint32_t slen = f->get_32();
  463. CharString cs;
  464. cs.resize(slen + 1);
  465. cs[slen] = 0;
  466. f->get_buffer((uint8_t *)cs.ptr(), slen);
  467. String key;
  468. key.parse_utf8(cs.ptr());
  469. uint32_t vlen = f->get_32();
  470. Vector<uint8_t> d;
  471. d.resize(vlen);
  472. f->get_buffer(d.ptrw(), vlen);
  473. Variant value;
  474. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  475. ERR_CONTINUE_MSG(err != OK, "Error decoding property: " + key + ".");
  476. set(key, value);
  477. }
  478. f->close();
  479. memdelete(f);
  480. return OK;
  481. }
  482. Error ProjectSettings::_load_settings_text(const String &p_path) {
  483. Error err;
  484. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  485. if (!f) {
  486. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  487. // This needs to be streamlined if we want decent error reporting
  488. return ERR_FILE_NOT_FOUND;
  489. }
  490. VariantParser::StreamFile stream;
  491. stream.f = f;
  492. String assign;
  493. Variant value;
  494. VariantParser::Tag next_tag;
  495. int lines = 0;
  496. String error_text;
  497. String section;
  498. int config_version = 0;
  499. while (true) {
  500. assign = Variant();
  501. next_tag.fields.clear();
  502. next_tag.name = String();
  503. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  504. if (err == ERR_FILE_EOF) {
  505. memdelete(f);
  506. // If we're loading a project.godot from source code, we can operate some
  507. // ProjectSettings conversions if need be.
  508. _convert_to_last_version(config_version);
  509. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  510. return OK;
  511. } else if (err != OK) {
  512. ERR_PRINT("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
  513. memdelete(f);
  514. return err;
  515. }
  516. if (assign != String()) {
  517. if (section == String() && assign == "config_version") {
  518. config_version = value;
  519. if (config_version > CONFIG_VERSION) {
  520. memdelete(f);
  521. ERR_FAIL_V_MSG(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));
  522. }
  523. } else {
  524. if (section == String()) {
  525. set(assign, value);
  526. } else {
  527. set(section + "/" + assign, value);
  528. }
  529. }
  530. } else if (next_tag.name != String()) {
  531. section = next_tag.name;
  532. }
  533. }
  534. }
  535. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  536. // Attempt first to load the binary project.godot file.
  537. Error err = _load_settings_binary(p_bin_path);
  538. if (err == OK) {
  539. return OK;
  540. } else if (err != ERR_FILE_NOT_FOUND) {
  541. // If the file exists but can't be loaded, we want to know it.
  542. ERR_PRINT("Couldn't load file '" + p_bin_path + "', error code " + itos(err) + ".");
  543. }
  544. // Fallback to text-based project.godot file if binary was not found.
  545. err = _load_settings_text(p_text_path);
  546. if (err == OK) {
  547. return OK;
  548. } else if (err != ERR_FILE_NOT_FOUND) {
  549. ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err) + ".");
  550. }
  551. return err;
  552. }
  553. int ProjectSettings::get_order(const String &p_name) const {
  554. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + ".");
  555. return props[p_name].order;
  556. }
  557. void ProjectSettings::set_order(const String &p_name, int p_order) {
  558. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  559. props[p_name].order = p_order;
  560. }
  561. void ProjectSettings::set_builtin_order(const String &p_name) {
  562. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  563. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  564. props[p_name].order = last_builtin_order++;
  565. }
  566. }
  567. bool ProjectSettings::is_builtin_setting(const String &p_name) const {
  568. // Return true because a false negative is worse than a false positive.
  569. ERR_FAIL_COND_V_MSG(!props.has(p_name), true, "Request for nonexistent project setting: " + p_name + ".");
  570. return props[p_name].order < NO_BUILTIN_ORDER_BASE;
  571. }
  572. void ProjectSettings::clear(const String &p_name) {
  573. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  574. props.erase(p_name);
  575. }
  576. Error ProjectSettings::save() {
  577. Error error = save_custom(get_resource_path().plus_file("project.godot"));
  578. if (error == OK) {
  579. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  580. }
  581. return error;
  582. }
  583. Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  584. Error err;
  585. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  586. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
  587. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  588. file->store_buffer(hdr, 4);
  589. int count = 0;
  590. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  591. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  592. count++;
  593. }
  594. }
  595. if (p_custom_features != String()) {
  596. file->store_32(count + 1);
  597. //store how many properties are saved, add one for custom featuers, which must always go first
  598. String key = CoreStringNames::get_singleton()->_custom_features;
  599. file->store_pascal_string(key);
  600. int len;
  601. err = encode_variant(p_custom_features, nullptr, len, false);
  602. if (err != OK) {
  603. memdelete(file);
  604. ERR_FAIL_V(err);
  605. }
  606. Vector<uint8_t> buff;
  607. buff.resize(len);
  608. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  609. if (err != OK) {
  610. memdelete(file);
  611. ERR_FAIL_V(err);
  612. }
  613. file->store_32(len);
  614. file->store_buffer(buff.ptr(), buff.size());
  615. } else {
  616. file->store_32(count); //store how many properties are saved
  617. }
  618. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  619. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  620. String key = F->get();
  621. if (E->key() != "") {
  622. key = E->key() + "/" + key;
  623. }
  624. Variant value;
  625. if (p_custom.has(key)) {
  626. value = p_custom[key];
  627. } else {
  628. value = get(key);
  629. }
  630. file->store_pascal_string(key);
  631. int len;
  632. err = encode_variant(value, nullptr, len, true);
  633. if (err != OK) {
  634. memdelete(file);
  635. }
  636. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  637. Vector<uint8_t> buff;
  638. buff.resize(len);
  639. err = encode_variant(value, buff.ptrw(), len, true);
  640. if (err != OK) {
  641. memdelete(file);
  642. }
  643. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  644. file->store_32(len);
  645. file->store_buffer(buff.ptr(), buff.size());
  646. }
  647. }
  648. file->close();
  649. memdelete(file);
  650. return OK;
  651. }
  652. Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  653. Error err;
  654. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  655. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.godot - " + p_file + ".");
  656. file->store_line("; Engine configuration file.");
  657. file->store_line("; It's best edited using the editor UI and not directly,");
  658. file->store_line("; since the parameters that go here are not all obvious.");
  659. file->store_line(";");
  660. file->store_line("; Format:");
  661. file->store_line("; [section] ; section goes between []");
  662. file->store_line("; param=value ; assign values to parameters");
  663. file->store_line("");
  664. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  665. if (p_custom_features != String()) {
  666. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  667. }
  668. file->store_string("\n");
  669. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  670. if (E != props.front()) {
  671. file->store_string("\n");
  672. }
  673. if (E->key() != "") {
  674. file->store_string("[" + E->key() + "]\n\n");
  675. }
  676. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  677. String key = F->get();
  678. if (E->key() != "") {
  679. key = E->key() + "/" + key;
  680. }
  681. Variant value;
  682. if (p_custom.has(key)) {
  683. value = p_custom[key];
  684. } else {
  685. value = get(key);
  686. }
  687. String vstr;
  688. VariantWriter::write_to_string(value, vstr);
  689. file->store_string(F->get().property_name_encode() + "=" + vstr + "\n");
  690. }
  691. }
  692. file->close();
  693. memdelete(file);
  694. return OK;
  695. }
  696. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  697. return save_custom(p_file);
  698. }
  699. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  700. ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  701. Set<_VCSort> vclist;
  702. if (p_merge_with_current) {
  703. for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
  704. const VariantContainer *v = &G->get();
  705. if (v->hide_from_editor) {
  706. continue;
  707. }
  708. if (p_custom.has(G->key())) {
  709. continue;
  710. }
  711. _VCSort vc;
  712. vc.name = G->key(); //*k;
  713. vc.order = v->order;
  714. vc.type = v->variant.get_type();
  715. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  716. if (v->variant == v->initial) {
  717. continue;
  718. }
  719. vclist.insert(vc);
  720. }
  721. }
  722. for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
  723. // Lookup global prop to store in the same order
  724. Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key());
  725. _VCSort vc;
  726. vc.name = E->key();
  727. vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
  728. vc.type = E->get().get_type();
  729. vc.flags = PROPERTY_USAGE_STORAGE;
  730. vclist.insert(vc);
  731. }
  732. Map<String, List<String>> props;
  733. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  734. String category = E->get().name;
  735. String name = E->get().name;
  736. int div = category.find("/");
  737. if (div < 0) {
  738. category = "";
  739. } else {
  740. category = category.substr(0, div);
  741. name = name.substr(div + 1, name.size());
  742. }
  743. props[category].push_back(name);
  744. }
  745. String custom_features;
  746. for (int i = 0; i < p_custom_features.size(); i++) {
  747. if (i > 0) {
  748. custom_features += ",";
  749. }
  750. String f = p_custom_features[i].strip_edges().replace("\"", "");
  751. custom_features += f;
  752. }
  753. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  754. return _save_settings_text(p_path, props, p_custom, custom_features);
  755. } else if (p_path.ends_with(".binary")) {
  756. return _save_settings_binary(p_path, props, p_custom, custom_features);
  757. } else {
  758. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
  759. }
  760. }
  761. 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) {
  762. Variant ret;
  763. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  764. ProjectSettings::get_singleton()->set(p_var, p_default);
  765. }
  766. ret = ProjectSettings::get_singleton()->get(p_var);
  767. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  768. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  769. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  770. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  771. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  772. return ret;
  773. }
  774. Vector<String> ProjectSettings::get_optimizer_presets() const {
  775. List<PropertyInfo> pi;
  776. ProjectSettings::get_singleton()->get_property_list(&pi);
  777. Vector<String> names;
  778. for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
  779. if (!E->get().name.begins_with("optimizer_presets/")) {
  780. continue;
  781. }
  782. names.push_back(E->get().name.get_slicec('/', 1));
  783. }
  784. names.sort();
  785. return names;
  786. }
  787. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  788. ERR_FAIL_COND(!p_info.has("name"));
  789. ERR_FAIL_COND(!p_info.has("type"));
  790. PropertyInfo pinfo;
  791. pinfo.name = p_info["name"];
  792. ERR_FAIL_COND(!props.has(pinfo.name));
  793. pinfo.type = Variant::Type(p_info["type"].operator int());
  794. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  795. if (p_info.has("hint")) {
  796. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  797. }
  798. if (p_info.has("hint_string")) {
  799. pinfo.hint_string = p_info["hint_string"];
  800. }
  801. set_custom_property_info(pinfo.name, pinfo);
  802. }
  803. void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
  804. ERR_FAIL_COND(!props.has(p_prop));
  805. custom_prop_info[p_prop] = p_info;
  806. custom_prop_info[p_prop].name = p_prop;
  807. }
  808. const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  809. return custom_prop_info;
  810. }
  811. void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
  812. disable_feature_overrides = p_disable;
  813. }
  814. bool ProjectSettings::is_using_datapack() const {
  815. return using_datapack;
  816. }
  817. bool ProjectSettings::property_can_revert(const String &p_name) {
  818. if (!props.has(p_name)) {
  819. return false;
  820. }
  821. return props[p_name].initial != props[p_name].variant;
  822. }
  823. Variant ProjectSettings::property_get_revert(const String &p_name) {
  824. if (!props.has(p_name)) {
  825. return Variant();
  826. }
  827. return props[p_name].initial;
  828. }
  829. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  830. set(p_setting, p_value);
  831. }
  832. Variant ProjectSettings::get_setting(const String &p_setting) const {
  833. return get(p_setting);
  834. }
  835. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  836. return custom_features.has(p_feature);
  837. }
  838. Map<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
  839. return autoloads;
  840. }
  841. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  842. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  843. autoloads[p_autoload.name] = p_autoload;
  844. }
  845. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  846. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  847. autoloads.erase(p_autoload);
  848. }
  849. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  850. return autoloads.has(p_autoload);
  851. }
  852. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  853. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  854. return autoloads[p_name];
  855. }
  856. void ProjectSettings::_bind_methods() {
  857. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  858. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  859. ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
  860. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  861. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  862. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  863. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  864. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  865. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  866. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  867. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  868. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));
  869. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert);
  870. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert);
  871. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  872. }
  873. void ProjectSettings::_add_builtin_input_map() {
  874. if (InputMap::get_singleton()) {
  875. OrderedHashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  876. for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
  877. Array events;
  878. // Convert list of input events into array
  879. for (List<Ref<InputEvent>>::Element *I = E.get().front(); I; I = I->next()) {
  880. events.push_back(I->get());
  881. }
  882. Dictionary action;
  883. action["deadzone"] = Variant(0.5f);
  884. action["events"] = events;
  885. String action_name = "input/" + E.key();
  886. GLOBAL_DEF(action_name, action);
  887. input_presets.push_back(action_name);
  888. }
  889. }
  890. }
  891. ProjectSettings::ProjectSettings() {
  892. // Initialization of engine variables should be done in the setup() method,
  893. // so that the values can be overridden from project.godot or project.binary.
  894. singleton = this;
  895. GLOBAL_DEF_BASIC("application/config/name", "");
  896. GLOBAL_DEF_BASIC("application/config/description", "");
  897. custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
  898. GLOBAL_DEF_BASIC("application/run/main_scene", "");
  899. custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res");
  900. GLOBAL_DEF("application/run/disable_stdout", false);
  901. GLOBAL_DEF("application/run/disable_stderr", false);
  902. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  903. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  904. GLOBAL_DEF("application/config/project_settings_override", "");
  905. GLOBAL_DEF_BASIC("audio/buses/default_bus_layout", "res://default_bus_layout.tres");
  906. custom_prop_info["audio/buses/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
  907. PackedStringArray extensions = PackedStringArray();
  908. extensions.push_back("gd");
  909. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  910. extensions.push_back("cs");
  911. }
  912. extensions.push_back("gdshader");
  913. GLOBAL_DEF("editor/run/main_run_args", "");
  914. GLOBAL_DEF("editor/script/search_in_file_extensions", extensions);
  915. custom_prop_info["editor/script/search_in_file_extensions"] = PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions");
  916. GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates");
  917. custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR);
  918. _add_builtin_input_map();
  919. // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
  920. 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");
  921. // Keep the enum values in sync with the `DisplayServer::VSyncMode` enum.
  922. custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox");
  923. 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");
  924. GLOBAL_DEF("physics/2d/run_on_thread", false);
  925. GLOBAL_DEF("physics/3d/run_on_thread", false);
  926. GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
  927. custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
  928. GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching);
  929. custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
  930. GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level);
  931. custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
  932. GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size);
  933. custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
  934. GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level);
  935. custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  936. GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level);
  937. custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  938. }
  939. ProjectSettings::~ProjectSettings() {
  940. singleton = nullptr;
  941. }