project_settings.cpp 40 KB

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