project_settings.cpp 39 KB

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