project_settings.cpp 40 KB

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