project_settings.cpp 40 KB

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