project_settings.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  1. /**************************************************************************/
  2. /* project_settings.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "project_settings.h"
  31. #include "core/core_bind.h" // For Compression enum.
  32. #include "core/input/input_map.h"
  33. #include "core/io/config_file.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/io/file_access.h"
  36. #include "core/io/file_access_pack.h"
  37. #include "core/io/marshalls.h"
  38. #include "core/io/resource_uid.h"
  39. #include "core/object/script_language.h"
  40. #include "core/templates/rb_set.h"
  41. #include "core/variant/typed_array.h"
  42. #include "core/variant/variant_parser.h"
  43. #include "core/version.h"
  44. #ifdef TOOLS_ENABLED
  45. #include "modules/modules_enabled.gen.h" // For mono.
  46. #endif // TOOLS_ENABLED
  47. const String ProjectSettings::PROJECT_DATA_DIR_NAME_SUFFIX = "godot";
  48. ProjectSettings *ProjectSettings::singleton = nullptr;
  49. ProjectSettings *ProjectSettings::get_singleton() {
  50. return singleton;
  51. }
  52. String ProjectSettings::get_project_data_dir_name() const {
  53. return project_data_dir_name;
  54. }
  55. String ProjectSettings::get_project_data_path() const {
  56. return "res://" + get_project_data_dir_name();
  57. }
  58. String ProjectSettings::get_resource_path() const {
  59. return resource_path;
  60. }
  61. String ProjectSettings::get_imported_files_path() const {
  62. return get_project_data_path().path_join("imported");
  63. }
  64. #ifdef TOOLS_ENABLED
  65. // Returns the features that a project must have when opened with this build of Godot.
  66. // This is used by the project manager to provide the initial_settings for config/features.
  67. const PackedStringArray ProjectSettings::get_required_features() {
  68. PackedStringArray features;
  69. features.append(VERSION_BRANCH);
  70. #ifdef REAL_T_IS_DOUBLE
  71. features.append("Double Precision");
  72. #endif
  73. return features;
  74. }
  75. // Returns the features supported by this build of Godot. Includes all required features.
  76. const PackedStringArray ProjectSettings::_get_supported_features() {
  77. PackedStringArray features = get_required_features();
  78. #ifdef MODULE_MONO_ENABLED
  79. features.append("C#");
  80. #endif
  81. // Allow pinning to a specific patch number or build type by marking
  82. // them as supported. They're only used if the user adds them manually.
  83. features.append(VERSION_BRANCH "." _MKSTR(VERSION_PATCH));
  84. features.append(VERSION_FULL_CONFIG);
  85. features.append(VERSION_FULL_BUILD);
  86. #ifdef RD_ENABLED
  87. features.append("Forward Plus");
  88. features.append("Mobile");
  89. #endif
  90. #ifdef GLES3_ENABLED
  91. features.append("GL Compatibility");
  92. #endif
  93. return features;
  94. }
  95. // Returns the features that this project needs but this build of Godot lacks.
  96. const PackedStringArray ProjectSettings::get_unsupported_features(const PackedStringArray &p_project_features) {
  97. PackedStringArray unsupported_features;
  98. PackedStringArray supported_features = singleton->_get_supported_features();
  99. for (int i = 0; i < p_project_features.size(); i++) {
  100. if (!supported_features.has(p_project_features[i])) {
  101. // Temporary compatibility code to ease upgrade to 4.0 beta 2+.
  102. if (p_project_features[i].begins_with("Vulkan")) {
  103. continue;
  104. }
  105. unsupported_features.append(p_project_features[i]);
  106. }
  107. }
  108. unsupported_features.sort();
  109. return unsupported_features;
  110. }
  111. // Returns the features that both this project has and this build of Godot has, ensuring required features exist.
  112. const PackedStringArray ProjectSettings::_trim_to_supported_features(const PackedStringArray &p_project_features) {
  113. // Remove unsupported features if present.
  114. PackedStringArray features = PackedStringArray(p_project_features);
  115. PackedStringArray supported_features = _get_supported_features();
  116. for (int i = p_project_features.size() - 1; i > -1; i--) {
  117. if (!supported_features.has(p_project_features[i])) {
  118. features.remove_at(i);
  119. }
  120. }
  121. // Add required features if not present.
  122. PackedStringArray required_features = get_required_features();
  123. for (int i = 0; i < required_features.size(); i++) {
  124. if (!features.has(required_features[i])) {
  125. features.append(required_features[i]);
  126. }
  127. }
  128. features.sort();
  129. return features;
  130. }
  131. #endif // TOOLS_ENABLED
  132. String ProjectSettings::localize_path(const String &p_path) const {
  133. String path = p_path.simplify_path();
  134. if (resource_path.is_empty() || (path.is_absolute_path() && !path.begins_with(resource_path))) {
  135. return path;
  136. }
  137. // Check if we have a special path (like res://) or a protocol identifier.
  138. int p = path.find("://");
  139. bool found = false;
  140. if (p > 0) {
  141. found = true;
  142. for (int i = 0; i < p; i++) {
  143. if (!is_ascii_alphanumeric_char(path[i])) {
  144. found = false;
  145. break;
  146. }
  147. }
  148. }
  149. if (found) {
  150. return path;
  151. }
  152. Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  153. if (dir->change_dir(path) == OK) {
  154. String cwd = dir->get_current_dir();
  155. cwd = cwd.replace("\\", "/");
  156. // Ensure that we end with a '/'.
  157. // This is important to ensure that we do not wrongly localize the resource path
  158. // in an absolute path that just happens to contain this string but points to a
  159. // different folder (e.g. "/my/project" as resource_path would be contained in
  160. // "/my/project_data", even though the latter is not part of res://.
  161. // `path_join("")` is an easy way to ensure we have a trailing '/'.
  162. const String res_path = resource_path.path_join("");
  163. // DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
  164. // so we must make sure we have it as well in order to compare with 'res_path'.
  165. cwd = cwd.path_join("");
  166. if (!cwd.begins_with(res_path)) {
  167. return path;
  168. }
  169. return cwd.replace_first(res_path, "res://");
  170. } else {
  171. int sep = path.rfind_char('/');
  172. if (sep == -1) {
  173. return "res://" + path;
  174. }
  175. String parent = path.substr(0, sep);
  176. String plocal = localize_path(parent);
  177. if (plocal.is_empty()) {
  178. return "";
  179. }
  180. // Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/'
  181. if (plocal[plocal.length() - 1] == '/') {
  182. sep += 1;
  183. }
  184. return plocal + path.substr(sep, path.size() - sep);
  185. }
  186. }
  187. void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) {
  188. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  189. // Duplicate so that if value is array or dictionary, changing the setting will not change the stored initial value.
  190. props[p_name].initial = p_value.duplicate();
  191. }
  192. void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
  193. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  194. props[p_name].restart_if_changed = p_restart;
  195. }
  196. void ProjectSettings::set_as_basic(const String &p_name, bool p_basic) {
  197. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  198. props[p_name].basic = p_basic;
  199. }
  200. void ProjectSettings::set_as_internal(const String &p_name, bool p_internal) {
  201. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  202. props[p_name].internal = p_internal;
  203. }
  204. void ProjectSettings::set_ignore_value_in_docs(const String &p_name, bool p_ignore) {
  205. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  206. #ifdef DEBUG_METHODS_ENABLED
  207. props[p_name].ignore_value_in_docs = p_ignore;
  208. #endif
  209. }
  210. bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
  211. ERR_FAIL_COND_V_MSG(!props.has(p_name), false, vformat("Request for nonexistent project setting: '%s'.", p_name));
  212. #ifdef DEBUG_METHODS_ENABLED
  213. return props[p_name].ignore_value_in_docs;
  214. #else
  215. return false;
  216. #endif
  217. }
  218. void ProjectSettings::add_hidden_prefix(const String &p_prefix) {
  219. ERR_FAIL_COND_MSG(hidden_prefixes.has(p_prefix), vformat("Hidden prefix '%s' already exists.", p_prefix));
  220. hidden_prefixes.push_back(p_prefix);
  221. }
  222. String ProjectSettings::globalize_path(const String &p_path) const {
  223. if (p_path.begins_with("res://")) {
  224. if (!resource_path.is_empty()) {
  225. return p_path.replace("res:/", resource_path);
  226. }
  227. return p_path.replace("res://", "");
  228. } else if (p_path.begins_with("uid://")) {
  229. const String path = ResourceUID::uid_to_path(p_path);
  230. if (!resource_path.is_empty()) {
  231. return path.replace("res:/", resource_path);
  232. }
  233. return path.replace("res://", "");
  234. } else if (p_path.begins_with("user://")) {
  235. String data_dir = OS::get_singleton()->get_user_data_dir();
  236. if (!data_dir.is_empty()) {
  237. return p_path.replace("user:/", data_dir);
  238. }
  239. return p_path.replace("user://", "");
  240. }
  241. return p_path;
  242. }
  243. bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
  244. _THREAD_SAFE_METHOD_
  245. if (p_value.get_type() == Variant::NIL) {
  246. props.erase(p_name);
  247. if (p_name.operator String().begins_with("autoload/")) {
  248. String node_name = p_name.operator String().split("/")[1];
  249. if (autoloads.has(node_name)) {
  250. remove_autoload(node_name);
  251. }
  252. } else if (p_name.operator String().begins_with("global_group/")) {
  253. String group_name = p_name.operator String().get_slice("/", 1);
  254. if (global_groups.has(group_name)) {
  255. remove_global_group(group_name);
  256. }
  257. }
  258. } else {
  259. if (p_name == CoreStringName(_custom_features)) {
  260. Vector<String> custom_feature_array = String(p_value).split(",");
  261. for (int i = 0; i < custom_feature_array.size(); i++) {
  262. custom_features.insert(custom_feature_array[i]);
  263. }
  264. _queue_changed();
  265. return true;
  266. }
  267. { // Feature overrides.
  268. int dot = p_name.operator String().find_char('.');
  269. if (dot != -1) {
  270. Vector<String> s = p_name.operator String().split(".");
  271. for (int i = 1; i < s.size(); i++) {
  272. String feature = s[i].strip_edges();
  273. Pair<StringName, StringName> feature_override(feature, p_name);
  274. if (!feature_overrides.has(s[0])) {
  275. feature_overrides[s[0]] = LocalVector<Pair<StringName, StringName>>();
  276. }
  277. feature_overrides[s[0]].push_back(feature_override);
  278. }
  279. }
  280. }
  281. if (props.has(p_name)) {
  282. props[p_name].variant = p_value;
  283. } else {
  284. props[p_name] = VariantContainer(p_value, last_order++);
  285. }
  286. if (p_name.operator String().begins_with("autoload/")) {
  287. String node_name = p_name.operator String().split("/")[1];
  288. AutoloadInfo autoload;
  289. autoload.name = node_name;
  290. String path = p_value;
  291. if (path.begins_with("*")) {
  292. autoload.is_singleton = true;
  293. autoload.path = path.substr(1).simplify_path();
  294. } else {
  295. autoload.path = path.simplify_path();
  296. }
  297. add_autoload(autoload);
  298. } else if (p_name.operator String().begins_with("global_group/")) {
  299. String group_name = p_name.operator String().get_slice("/", 1);
  300. add_global_group(group_name, p_value);
  301. }
  302. }
  303. _queue_changed();
  304. return true;
  305. }
  306. bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
  307. _THREAD_SAFE_METHOD_
  308. if (!props.has(p_name)) {
  309. return false;
  310. }
  311. r_ret = props[p_name].variant;
  312. return true;
  313. }
  314. Variant ProjectSettings::get_setting_with_override(const StringName &p_name) const {
  315. _THREAD_SAFE_METHOD_
  316. StringName name = p_name;
  317. if (feature_overrides.has(name)) {
  318. const LocalVector<Pair<StringName, StringName>> &overrides = feature_overrides[name];
  319. for (uint32_t i = 0; i < overrides.size(); i++) {
  320. if (OS::get_singleton()->has_feature(overrides[i].first)) { // Custom features are checked in OS.has_feature() already. No need to check twice.
  321. if (props.has(overrides[i].second)) {
  322. name = overrides[i].second;
  323. break;
  324. }
  325. }
  326. }
  327. }
  328. if (!props.has(name)) {
  329. WARN_PRINT(vformat("Property not found: '%s'.", String(name)));
  330. return Variant();
  331. }
  332. return props[name].variant;
  333. }
  334. struct _VCSort {
  335. String name;
  336. Variant::Type type = Variant::VARIANT_MAX;
  337. int order = 0;
  338. uint32_t flags = 0;
  339. bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
  340. };
  341. void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  342. _THREAD_SAFE_METHOD_
  343. RBSet<_VCSort> vclist;
  344. for (const KeyValue<StringName, VariantContainer> &E : props) {
  345. const VariantContainer *v = &E.value;
  346. if (v->hide_from_editor) {
  347. continue;
  348. }
  349. _VCSort vc;
  350. vc.name = E.key;
  351. vc.order = v->order;
  352. vc.type = v->variant.get_type();
  353. bool internal = v->internal;
  354. if (!internal) {
  355. for (const String &F : hidden_prefixes) {
  356. if (vc.name.begins_with(F)) {
  357. internal = true;
  358. break;
  359. }
  360. }
  361. }
  362. if (internal) {
  363. vc.flags = PROPERTY_USAGE_STORAGE;
  364. } else {
  365. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  366. }
  367. if (v->internal) {
  368. vc.flags |= PROPERTY_USAGE_INTERNAL;
  369. }
  370. if (v->basic) {
  371. vc.flags |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  372. }
  373. if (v->restart_if_changed) {
  374. vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  375. }
  376. vclist.insert(vc);
  377. }
  378. for (const _VCSort &E : vclist) {
  379. String prop_info_name = E.name;
  380. int dot = prop_info_name.find_char('.');
  381. if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
  382. prop_info_name = prop_info_name.substr(0, dot);
  383. }
  384. if (custom_prop_info.has(prop_info_name)) {
  385. PropertyInfo pi = custom_prop_info[prop_info_name];
  386. pi.name = E.name;
  387. pi.usage = E.flags;
  388. p_list->push_back(pi);
  389. } else {
  390. p_list->push_back(PropertyInfo(E.type, E.name, PROPERTY_HINT_NONE, "", E.flags));
  391. }
  392. }
  393. }
  394. void ProjectSettings::_queue_changed() {
  395. if (is_changed || !MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) {
  396. return;
  397. }
  398. is_changed = true;
  399. callable_mp(this, &ProjectSettings::_emit_changed).call_deferred();
  400. }
  401. void ProjectSettings::_emit_changed() {
  402. if (!is_changed) {
  403. return;
  404. }
  405. is_changed = false;
  406. emit_signal("settings_changed");
  407. }
  408. bool ProjectSettings::load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) {
  409. return ProjectSettings::_load_resource_pack(p_pack, p_replace_files, p_offset, false);
  410. }
  411. bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset, bool p_main_pack) {
  412. if (PackedData::get_singleton()->is_disabled()) {
  413. return false;
  414. }
  415. if (p_pack == "res://") {
  416. // Loading the resource directory as a pack source is reserved for internal use only.
  417. return false;
  418. }
  419. if (!p_main_pack && !using_datapack && !OS::get_singleton()->get_resource_dir().is_empty()) {
  420. // Add the project's resource file system to PackedData so directory access keeps working when
  421. // the game is running without a main pack, like in the editor or on Android.
  422. PackedData::get_singleton()->add_pack_source(memnew(PackedSourceDirectory));
  423. PackedData::get_singleton()->add_pack("res://", false, 0);
  424. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  425. using_datapack = true;
  426. }
  427. bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files, p_offset) == OK;
  428. if (!ok) {
  429. return false;
  430. }
  431. if (project_loaded) {
  432. // This pack may have declared new global classes (make sure they are picked up).
  433. refresh_global_class_list();
  434. // This pack may have defined new UIDs, make sure they are cached.
  435. ResourceUID::get_singleton()->load_from_cache(false);
  436. }
  437. // If the data pack was found, all directory access will be from here.
  438. if (!using_datapack) {
  439. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  440. using_datapack = true;
  441. }
  442. return true;
  443. }
  444. void ProjectSettings::_convert_to_last_version(int p_from_version) {
  445. #ifndef DISABLE_DEPRECATED
  446. if (p_from_version <= 3) {
  447. // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
  448. for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) {
  449. Variant value = E.value.variant;
  450. if (String(E.key).begins_with("input/") && value.get_type() == Variant::ARRAY) {
  451. Array array = value;
  452. Dictionary action;
  453. action["deadzone"] = Variant(0.5f);
  454. action["events"] = array;
  455. E.value.variant = action;
  456. }
  457. }
  458. }
  459. if (p_from_version == 5) {
  460. // Converts the device in events from -3 to -1.
  461. // -3 was introduced in GH-97707 as a way to prevent a clash in device IDs, but as reported in GH-99243, this leads to problems.
  462. // -3 was used during dev-releases, so this conversion helps to revert such affected projects.
  463. // This conversion doesn't affect any other projects, since -3 is not used otherwise.
  464. for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) {
  465. if (String(E.key).begins_with("input/")) {
  466. Dictionary action = E.value.variant;
  467. Array events = action["events"];
  468. for (int i = 0; i < events.size(); i++) {
  469. Ref<InputEvent> ev = events[i];
  470. if (ev.is_valid() && ev->get_device() == -3) {
  471. ev->set_device(-1);
  472. }
  473. }
  474. }
  475. }
  476. }
  477. #endif // DISABLE_DEPRECATED
  478. }
  479. /*
  480. * This method is responsible for loading a project.godot file and/or data file
  481. * using the following merit order:
  482. * - If using NetworkClient, try to lookup project file or fail.
  483. * - If --main-pack was passed by the user (`p_main_pack`), load it or fail.
  484. * - Search for project PCKs automatically. For each step we try loading a potential
  485. * PCK, and if it doesn't work, we proceed to the next step. If any step succeeds,
  486. * we try loading the project settings, and abort if it fails. Steps:
  487. * o Bundled PCK in the executable.
  488. * o [macOS only] PCK with same basename as the binary in the .app resource dir.
  489. * o PCK with same basename as the binary in the binary's directory. We handle both
  490. * changing the extension to '.pck' (e.g. 'win_game.exe' -> 'win_game.pck') and
  491. * appending '.pck' to the binary name (e.g. 'linux_game' -> 'linux_game.pck').
  492. * o PCK with the same basename as the binary in the current working directory.
  493. * Same as above for the two possible PCK file names.
  494. * - On relevant platforms (Android/iOS), lookup project file in OS resource path.
  495. * If found, load it or fail.
  496. * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we
  497. * are running from source code.
  498. * If not found and `p_upwards` is true (--upwards passed by the user), look for
  499. * project files in parent folders up to the system root (used to run a game
  500. * from command line while in a subfolder).
  501. * If a project file is found, load it or fail.
  502. * If nothing was found, error out.
  503. */
  504. Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  505. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  506. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  507. // If the OS would rather use a specific location, then it will not be empty.
  508. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  509. if (!resource_path.is_empty() && resource_path[resource_path.length() - 1] == '/') {
  510. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  511. }
  512. }
  513. // Attempt with a user-defined main pack first
  514. if (!p_main_pack.is_empty()) {
  515. bool ok = _load_resource_pack(p_main_pack, false, 0, true);
  516. ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, vformat("Cannot open resource pack '%s'.", p_main_pack));
  517. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  518. if (err == OK && !p_ignore_override) {
  519. // Load override from location of the main pack
  520. // Optional, we don't mind if it fails
  521. _load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
  522. }
  523. return err;
  524. }
  525. String exec_path = OS::get_singleton()->get_executable_path();
  526. if (!exec_path.is_empty()) {
  527. // We do several tests sequentially until one succeeds to find a PCK,
  528. // and if so, we attempt loading it at the end.
  529. // Attempt with PCK bundled into executable.
  530. bool found = _load_resource_pack(exec_path, false, 0, true);
  531. // Attempt with exec_name.pck.
  532. // (This is the usual case when distributing a Godot game.)
  533. String exec_dir = exec_path.get_base_dir();
  534. String exec_filename = exec_path.get_file();
  535. String exec_basename = exec_filename.get_basename();
  536. // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
  537. // or the exec path's basename + '.pck' (Windows).
  538. // We need to test both possibilities as extensions for Linux binaries are optional
  539. // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
  540. #ifdef MACOS_ENABLED
  541. if (!found) {
  542. // Attempt to load PCK from macOS .app bundle resources.
  543. found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_basename + ".pck"), false, 0, true) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"), false, 0, true);
  544. }
  545. #endif
  546. if (!found) {
  547. // Try to load data pack at the location of the executable.
  548. // As mentioned above, we have two potential names to attempt.
  549. found = _load_resource_pack(exec_dir.path_join(exec_basename + ".pck"), false, 0, true) || _load_resource_pack(exec_dir.path_join(exec_filename + ".pck"), false, 0, true);
  550. }
  551. if (!found) {
  552. // If we couldn't find them next to the executable, we attempt
  553. // the current working directory. Same story, two tests.
  554. found = _load_resource_pack(exec_basename + ".pck", false, 0, true) || _load_resource_pack(exec_filename + ".pck", false, 0, true);
  555. }
  556. // If we opened our package, try and load our project.
  557. if (found) {
  558. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  559. if (err == OK && !p_ignore_override) {
  560. // Load overrides from the PCK and the executable location.
  561. // Optional, we don't mind if either fails.
  562. _load_settings_text("res://override.cfg");
  563. _load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
  564. }
  565. return err;
  566. }
  567. }
  568. // Try to use the filesystem for files, according to OS.
  569. // (Only Android -when reading from pck- and iOS use this.)
  570. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  571. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  572. if (err == OK && !p_ignore_override) {
  573. // Optional, we don't mind if it fails.
  574. _load_settings_text("res://override.cfg");
  575. }
  576. return err;
  577. }
  578. #ifdef MACOS_ENABLED
  579. // Attempt to load project file from macOS .app bundle resources.
  580. resource_path = OS::get_singleton()->get_bundle_resource_dir();
  581. if (!resource_path.is_empty()) {
  582. if (resource_path[resource_path.length() - 1] == '/') {
  583. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  584. }
  585. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  586. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", resource_path));
  587. d->change_dir(resource_path);
  588. Error err;
  589. err = _load_settings_text_or_binary(resource_path.path_join("project.godot"), resource_path.path_join("project.binary"));
  590. if (err == OK && !p_ignore_override) {
  591. // Optional, we don't mind if it fails.
  592. _load_settings_text(resource_path.path_join("override.cfg"));
  593. return err;
  594. }
  595. }
  596. #endif
  597. // Nothing was found, try to find a project file in provided path (`p_path`)
  598. // or, if requested (`p_upwards`) in parent directories.
  599. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  600. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", p_path));
  601. d->change_dir(p_path);
  602. String current_dir = d->get_current_dir();
  603. bool found = false;
  604. Error err;
  605. while (true) {
  606. // Set the resource path early so things can be resolved when loading.
  607. resource_path = current_dir;
  608. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  609. err = _load_settings_text_or_binary(current_dir.path_join("project.godot"), current_dir.path_join("project.binary"));
  610. if (err == OK && !p_ignore_override) {
  611. // Optional, we don't mind if it fails.
  612. _load_settings_text(current_dir.path_join("override.cfg"));
  613. found = true;
  614. break;
  615. }
  616. if (p_upwards) {
  617. // Try to load settings ascending through parent directories
  618. d->change_dir("..");
  619. if (d->get_current_dir() == current_dir) {
  620. break; // not doing anything useful
  621. }
  622. current_dir = d->get_current_dir();
  623. } else {
  624. break;
  625. }
  626. }
  627. if (!found) {
  628. return err;
  629. }
  630. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  631. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  632. }
  633. return OK;
  634. }
  635. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  636. Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override);
  637. if (err == OK && !p_ignore_override) {
  638. String custom_settings = GLOBAL_GET("application/config/project_settings_override");
  639. if (!custom_settings.is_empty()) {
  640. _load_settings_text(custom_settings);
  641. }
  642. }
  643. // Updating the default value after the project settings have loaded.
  644. bool use_hidden_directory = GLOBAL_GET("application/config/use_hidden_project_data_directory");
  645. project_data_dir_name = (use_hidden_directory ? "." : "") + PROJECT_DATA_DIR_NAME_SUFFIX;
  646. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  647. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  648. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  649. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  650. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  651. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  652. load_scene_groups_cache();
  653. project_loaded = err == OK;
  654. return err;
  655. }
  656. bool ProjectSettings::has_setting(const String &p_var) const {
  657. _THREAD_SAFE_METHOD_
  658. return props.has(p_var);
  659. }
  660. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  661. Error err;
  662. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  663. if (err != OK) {
  664. return err;
  665. }
  666. uint8_t hdr[4];
  667. f->get_buffer(hdr, 4);
  668. ERR_FAIL_COND_V_MSG((hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G'), ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
  669. uint32_t count = f->get_32();
  670. for (uint32_t i = 0; i < count; i++) {
  671. uint32_t slen = f->get_32();
  672. CharString cs;
  673. cs.resize(slen + 1);
  674. cs[slen] = 0;
  675. f->get_buffer((uint8_t *)cs.ptr(), slen);
  676. String key;
  677. key.parse_utf8(cs.ptr(), slen);
  678. uint32_t vlen = f->get_32();
  679. Vector<uint8_t> d;
  680. d.resize(vlen);
  681. f->get_buffer(d.ptrw(), vlen);
  682. Variant value;
  683. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  684. ERR_CONTINUE_MSG(err != OK, vformat("Error decoding property: '%s'.", key));
  685. set(key, value);
  686. }
  687. return OK;
  688. }
  689. Error ProjectSettings::_load_settings_text(const String &p_path) {
  690. Error err;
  691. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  692. if (f.is_null()) {
  693. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  694. // This needs to be streamlined if we want decent error reporting
  695. return ERR_FILE_NOT_FOUND;
  696. }
  697. VariantParser::StreamFile stream;
  698. stream.f = f;
  699. String assign;
  700. Variant value;
  701. VariantParser::Tag next_tag;
  702. int lines = 0;
  703. String error_text;
  704. String section;
  705. int config_version = 0;
  706. while (true) {
  707. assign = Variant();
  708. next_tag.fields.clear();
  709. next_tag.name = String();
  710. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  711. if (err == ERR_FILE_EOF) {
  712. // If we're loading a project.godot from source code, we can operate some
  713. // ProjectSettings conversions if need be.
  714. _convert_to_last_version(config_version);
  715. last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
  716. return OK;
  717. }
  718. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Error parsing '%s' at line %d: %s File might be corrupted.", p_path, lines, error_text));
  719. if (!assign.is_empty()) {
  720. if (section.is_empty() && assign == "config_version") {
  721. config_version = value;
  722. ERR_FAIL_COND_V_MSG(config_version > CONFIG_VERSION, 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));
  723. } else {
  724. if (section.is_empty()) {
  725. set(assign, value);
  726. } else {
  727. set(section + "/" + assign, value);
  728. }
  729. }
  730. } else if (!next_tag.name.is_empty()) {
  731. section = next_tag.name;
  732. }
  733. }
  734. }
  735. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  736. // Attempt first to load the binary project.godot file.
  737. Error err = _load_settings_binary(p_bin_path);
  738. if (err == OK) {
  739. return OK;
  740. } else if (err != ERR_FILE_NOT_FOUND) {
  741. // If the file exists but can't be loaded, we want to know it.
  742. ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_bin_path, err));
  743. }
  744. // Fallback to text-based project.godot file if binary was not found.
  745. err = _load_settings_text(p_text_path);
  746. if (err == OK) {
  747. return OK;
  748. } else if (err != ERR_FILE_NOT_FOUND) {
  749. ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_text_path, err));
  750. }
  751. return err;
  752. }
  753. Error ProjectSettings::load_custom(const String &p_path) {
  754. if (p_path.ends_with(".binary")) {
  755. return _load_settings_binary(p_path);
  756. }
  757. return _load_settings_text(p_path);
  758. }
  759. int ProjectSettings::get_order(const String &p_name) const {
  760. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, vformat("Request for nonexistent project setting: '%s'.", p_name));
  761. return props[p_name].order;
  762. }
  763. void ProjectSettings::set_order(const String &p_name, int p_order) {
  764. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  765. props[p_name].order = p_order;
  766. }
  767. void ProjectSettings::set_builtin_order(const String &p_name) {
  768. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  769. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  770. props[p_name].order = last_builtin_order++;
  771. }
  772. }
  773. bool ProjectSettings::is_builtin_setting(const String &p_name) const {
  774. // Return true because a false negative is worse than a false positive.
  775. ERR_FAIL_COND_V_MSG(!props.has(p_name), true, vformat("Request for nonexistent project setting: '%s'.", p_name));
  776. return props[p_name].order < NO_BUILTIN_ORDER_BASE;
  777. }
  778. void ProjectSettings::clear(const String &p_name) {
  779. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  780. props.erase(p_name);
  781. }
  782. Error ProjectSettings::save() {
  783. Error error = save_custom(get_resource_path().path_join("project.godot"));
  784. if (error == OK) {
  785. last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
  786. }
  787. return error;
  788. }
  789. Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) {
  790. Error err;
  791. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  792. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.binary at '%s'.", p_file));
  793. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  794. file->store_buffer(hdr, 4);
  795. int count = 0;
  796. for (const KeyValue<String, List<String>> &E : p_props) {
  797. count += E.value.size();
  798. }
  799. if (!p_custom_features.is_empty()) {
  800. // Store how many properties are saved, add one for custom features, which must always go first.
  801. file->store_32(uint32_t(count + 1));
  802. String key = CoreStringName(_custom_features);
  803. file->store_pascal_string(key);
  804. int len;
  805. err = encode_variant(p_custom_features, nullptr, len, false);
  806. ERR_FAIL_COND_V(err != OK, err);
  807. Vector<uint8_t> buff;
  808. buff.resize(len);
  809. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  810. ERR_FAIL_COND_V(err != OK, err);
  811. file->store_32(uint32_t(len));
  812. file->store_buffer(buff.ptr(), buff.size());
  813. } else {
  814. // Store how many properties are saved.
  815. file->store_32(uint32_t(count));
  816. }
  817. for (const KeyValue<String, List<String>> &E : p_props) {
  818. for (const String &key : E.value) {
  819. String k = key;
  820. if (!E.key.is_empty()) {
  821. k = E.key + "/" + k;
  822. }
  823. Variant value;
  824. if (p_custom.has(k)) {
  825. value = p_custom[k];
  826. } else {
  827. value = get(k);
  828. }
  829. file->store_pascal_string(k);
  830. int len;
  831. err = encode_variant(value, nullptr, len, true);
  832. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  833. Vector<uint8_t> buff;
  834. buff.resize(len);
  835. err = encode_variant(value, buff.ptrw(), len, true);
  836. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  837. file->store_32(uint32_t(len));
  838. file->store_buffer(buff.ptr(), buff.size());
  839. }
  840. }
  841. return OK;
  842. }
  843. Error ProjectSettings::_save_settings_text(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) {
  844. Error err;
  845. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  846. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.godot - %s.", p_file));
  847. file->store_line("; Engine configuration file.");
  848. file->store_line("; It's best edited using the editor UI and not directly,");
  849. file->store_line("; since the parameters that go here are not all obvious.");
  850. file->store_line(";");
  851. file->store_line("; Format:");
  852. file->store_line("; [section] ; section goes between []");
  853. file->store_line("; param=value ; assign values to parameters");
  854. file->store_line("");
  855. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  856. if (!p_custom_features.is_empty()) {
  857. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  858. }
  859. file->store_string("\n");
  860. for (const KeyValue<String, List<String>> &E : p_props) {
  861. if (E.key != p_props.begin()->key) {
  862. file->store_string("\n");
  863. }
  864. if (!E.key.is_empty()) {
  865. file->store_string("[" + E.key + "]\n\n");
  866. }
  867. for (const String &F : E.value) {
  868. String key = F;
  869. if (!E.key.is_empty()) {
  870. key = E.key + "/" + key;
  871. }
  872. Variant value;
  873. if (p_custom.has(key)) {
  874. value = p_custom[key];
  875. } else {
  876. value = get(key);
  877. }
  878. String vstr;
  879. VariantWriter::write_to_string(value, vstr);
  880. file->store_string(F.property_name_encode() + "=" + vstr + "\n");
  881. }
  882. }
  883. return OK;
  884. }
  885. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  886. return save_custom(p_file);
  887. }
  888. #ifdef TOOLS_ENABLED
  889. bool _csproj_exists(const String &p_root_dir) {
  890. Ref<DirAccess> dir = DirAccess::open(p_root_dir);
  891. ERR_FAIL_COND_V(dir.is_null(), false);
  892. dir->list_dir_begin();
  893. String file_name = dir->_get_next();
  894. while (file_name != "") {
  895. if (!dir->current_is_dir() && file_name.get_extension() == "csproj") {
  896. return true;
  897. }
  898. file_name = dir->_get_next();
  899. }
  900. return false;
  901. }
  902. #endif // TOOLS_ENABLED
  903. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  904. ERR_FAIL_COND_V_MSG(p_path.is_empty(), ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  905. #ifdef TOOLS_ENABLED
  906. PackedStringArray project_features = get_setting("application/config/features");
  907. // If there is no feature list currently present, force one to generate.
  908. if (project_features.is_empty()) {
  909. project_features = ProjectSettings::get_required_features();
  910. }
  911. // Check the rendering API.
  912. const String rendering_api = has_setting("rendering/renderer/rendering_method") ? (String)get_setting("rendering/renderer/rendering_method") : String();
  913. if (!rendering_api.is_empty()) {
  914. // Add the rendering API as a project feature if it doesn't already exist.
  915. if (!project_features.has(rendering_api)) {
  916. project_features.append(rendering_api);
  917. }
  918. }
  919. // Check for the existence of a csproj file.
  920. if (_csproj_exists(get_resource_path())) {
  921. // If there is a csproj file, add the C# feature if it doesn't already exist.
  922. if (!project_features.has("C#")) {
  923. project_features.append("C#");
  924. }
  925. } else {
  926. // If there isn't a csproj file, remove the C# feature if it exists.
  927. if (project_features.has("C#")) {
  928. project_features.remove_at(project_features.find("C#"));
  929. }
  930. }
  931. project_features = _trim_to_supported_features(project_features);
  932. set_setting("application/config/features", project_features);
  933. #endif // TOOLS_ENABLED
  934. RBSet<_VCSort> vclist;
  935. if (p_merge_with_current) {
  936. for (const KeyValue<StringName, VariantContainer> &G : props) {
  937. const VariantContainer *v = &G.value;
  938. if (v->hide_from_editor) {
  939. continue;
  940. }
  941. if (p_custom.has(G.key)) {
  942. continue;
  943. }
  944. _VCSort vc;
  945. vc.name = G.key; //*k;
  946. vc.order = v->order;
  947. vc.type = v->variant.get_type();
  948. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  949. if (v->variant == v->initial) {
  950. continue;
  951. }
  952. vclist.insert(vc);
  953. }
  954. }
  955. for (const KeyValue<String, Variant> &E : p_custom) {
  956. // Lookup global prop to store in the same order
  957. RBMap<StringName, VariantContainer>::Iterator global_prop = props.find(E.key);
  958. _VCSort vc;
  959. vc.name = E.key;
  960. vc.order = global_prop ? global_prop->value.order : 0xFFFFFFF;
  961. vc.type = E.value.get_type();
  962. vc.flags = PROPERTY_USAGE_STORAGE;
  963. vclist.insert(vc);
  964. }
  965. RBMap<String, List<String>> save_props;
  966. for (const _VCSort &E : vclist) {
  967. String category = E.name;
  968. String name = E.name;
  969. int div = category.find_char('/');
  970. if (div < 0) {
  971. category = "";
  972. } else {
  973. category = category.substr(0, div);
  974. name = name.substr(div + 1, name.size());
  975. }
  976. save_props[category].push_back(name);
  977. }
  978. String save_features;
  979. for (int i = 0; i < p_custom_features.size(); i++) {
  980. if (i > 0) {
  981. save_features += ",";
  982. }
  983. String f = p_custom_features[i].strip_edges().replace("\"", "");
  984. save_features += f;
  985. }
  986. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  987. return _save_settings_text(p_path, save_props, p_custom, save_features);
  988. } else if (p_path.ends_with(".binary")) {
  989. return _save_settings_binary(p_path, save_props, p_custom, save_features);
  990. } else {
  991. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, vformat("Unknown config file format: '%s'.", p_path));
  992. }
  993. }
  994. Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
  995. Variant ret;
  996. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  997. ProjectSettings::get_singleton()->set(p_var, p_default);
  998. }
  999. ret = GLOBAL_GET(p_var);
  1000. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  1001. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  1002. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  1003. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  1004. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  1005. ProjectSettings::get_singleton()->set_as_internal(p_var, p_internal);
  1006. return ret;
  1007. }
  1008. Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
  1009. Variant ret = _GLOBAL_DEF(p_info.name, p_default, p_restart_if_changed, p_ignore_value_in_docs, p_basic, p_internal);
  1010. ProjectSettings::get_singleton()->set_custom_property_info(p_info);
  1011. return ret;
  1012. }
  1013. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  1014. ERR_FAIL_COND(!p_info.has("name"));
  1015. ERR_FAIL_COND(!p_info.has("type"));
  1016. PropertyInfo pinfo;
  1017. pinfo.name = p_info["name"];
  1018. ERR_FAIL_COND(!props.has(pinfo.name));
  1019. pinfo.type = Variant::Type(p_info["type"].operator int());
  1020. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  1021. if (p_info.has("hint")) {
  1022. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  1023. }
  1024. if (p_info.has("hint_string")) {
  1025. pinfo.hint_string = p_info["hint_string"];
  1026. }
  1027. set_custom_property_info(pinfo);
  1028. }
  1029. void ProjectSettings::set_custom_property_info(const PropertyInfo &p_info) {
  1030. const String &prop_name = p_info.name;
  1031. ERR_FAIL_COND(!props.has(prop_name));
  1032. custom_prop_info[prop_name] = p_info;
  1033. }
  1034. const HashMap<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  1035. return custom_prop_info;
  1036. }
  1037. bool ProjectSettings::is_using_datapack() const {
  1038. return using_datapack;
  1039. }
  1040. bool ProjectSettings::is_project_loaded() const {
  1041. return project_loaded;
  1042. }
  1043. bool ProjectSettings::_property_can_revert(const StringName &p_name) const {
  1044. return props.has(p_name);
  1045. }
  1046. bool ProjectSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  1047. const RBMap<StringName, ProjectSettings::VariantContainer>::Element *value = props.find(p_name);
  1048. if (value) {
  1049. r_property = value->value().initial.duplicate();
  1050. return true;
  1051. }
  1052. return false;
  1053. }
  1054. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  1055. set(p_setting, p_value);
  1056. }
  1057. Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_default_value) const {
  1058. if (has_setting(p_setting)) {
  1059. return get(p_setting);
  1060. } else {
  1061. return p_default_value;
  1062. }
  1063. }
  1064. void ProjectSettings::refresh_global_class_list() {
  1065. // This is called after mounting a new PCK file to pick up class changes.
  1066. is_global_class_list_loaded = false; // Make sure we read from the freshly mounted PCK.
  1067. Array script_classes = get_global_class_list();
  1068. for (int i = 0; i < script_classes.size(); i++) {
  1069. Dictionary c = script_classes[i];
  1070. if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
  1071. continue;
  1072. }
  1073. ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"]);
  1074. }
  1075. }
  1076. TypedArray<Dictionary> ProjectSettings::get_global_class_list() {
  1077. if (is_global_class_list_loaded) {
  1078. return global_class_list;
  1079. }
  1080. Ref<ConfigFile> cf;
  1081. cf.instantiate();
  1082. if (cf->load(get_global_class_list_path()) == OK) {
  1083. global_class_list = cf->get_value("", "list", Array());
  1084. } else {
  1085. #ifndef TOOLS_ENABLED
  1086. // Script classes can't be recreated in exported project, so print an error.
  1087. ERR_PRINT("Could not load global script cache.");
  1088. #endif
  1089. }
  1090. // File read succeeded or failed. If it failed, assume everything is still okay.
  1091. // We will later receive updated class data in store_global_class_list().
  1092. is_global_class_list_loaded = true;
  1093. return global_class_list;
  1094. }
  1095. String ProjectSettings::get_global_class_list_path() const {
  1096. return get_project_data_path().path_join("global_script_class_cache.cfg");
  1097. }
  1098. void ProjectSettings::store_global_class_list(const Array &p_classes) {
  1099. Ref<ConfigFile> cf;
  1100. cf.instantiate();
  1101. cf->set_value("", "list", p_classes);
  1102. cf->save(get_global_class_list_path());
  1103. global_class_list = p_classes;
  1104. }
  1105. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  1106. return custom_features.has(p_feature);
  1107. }
  1108. const HashMap<StringName, ProjectSettings::AutoloadInfo> &ProjectSettings::get_autoload_list() const {
  1109. return autoloads;
  1110. }
  1111. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  1112. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  1113. autoloads[p_autoload.name] = p_autoload;
  1114. }
  1115. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  1116. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  1117. autoloads.erase(p_autoload);
  1118. }
  1119. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  1120. return autoloads.has(p_autoload);
  1121. }
  1122. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  1123. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  1124. return autoloads[p_name];
  1125. }
  1126. const HashMap<StringName, String> &ProjectSettings::get_global_groups_list() const {
  1127. return global_groups;
  1128. }
  1129. void ProjectSettings::add_global_group(const StringName &p_name, const String &p_description) {
  1130. ERR_FAIL_COND_MSG(p_name == StringName(), "Trying to add global group with no name.");
  1131. global_groups[p_name] = p_description;
  1132. }
  1133. void ProjectSettings::remove_global_group(const StringName &p_name) {
  1134. ERR_FAIL_COND_MSG(!global_groups.has(p_name), "Trying to remove non-existent global group.");
  1135. global_groups.erase(p_name);
  1136. }
  1137. bool ProjectSettings::has_global_group(const StringName &p_name) const {
  1138. return global_groups.has(p_name);
  1139. }
  1140. void ProjectSettings::remove_scene_groups_cache(const StringName &p_path) {
  1141. scene_groups_cache.erase(p_path);
  1142. }
  1143. void ProjectSettings::add_scene_groups_cache(const StringName &p_path, const HashSet<StringName> &p_cache) {
  1144. scene_groups_cache[p_path] = p_cache;
  1145. }
  1146. void ProjectSettings::save_scene_groups_cache() {
  1147. Ref<ConfigFile> cf;
  1148. cf.instantiate();
  1149. for (const KeyValue<StringName, HashSet<StringName>> &E : scene_groups_cache) {
  1150. if (E.value.is_empty()) {
  1151. continue;
  1152. }
  1153. Array list;
  1154. for (const StringName &group : E.value) {
  1155. list.push_back(group);
  1156. }
  1157. cf->set_value(E.key, "groups", list);
  1158. }
  1159. cf->save(get_scene_groups_cache_path());
  1160. }
  1161. String ProjectSettings::get_scene_groups_cache_path() const {
  1162. return get_project_data_path().path_join("scene_groups_cache.cfg");
  1163. }
  1164. void ProjectSettings::load_scene_groups_cache() {
  1165. Ref<ConfigFile> cf;
  1166. cf.instantiate();
  1167. if (cf->load(get_scene_groups_cache_path()) == OK) {
  1168. List<String> scene_paths;
  1169. cf->get_sections(&scene_paths);
  1170. for (const String &E : scene_paths) {
  1171. Array scene_groups = cf->get_value(E, "groups", Array());
  1172. HashSet<StringName> cache;
  1173. for (const Variant &scene_group : scene_groups) {
  1174. cache.insert(scene_group);
  1175. }
  1176. add_scene_groups_cache(E, cache);
  1177. }
  1178. }
  1179. }
  1180. const HashMap<StringName, HashSet<StringName>> &ProjectSettings::get_scene_groups_cache() const {
  1181. return scene_groups_cache;
  1182. }
  1183. #ifdef TOOLS_ENABLED
  1184. void ProjectSettings::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1185. const String pf = p_function;
  1186. if (p_idx == 0) {
  1187. if (pf == "has_setting" || pf == "set_setting" || pf == "get_setting" || pf == "get_setting_with_override" ||
  1188. pf == "set_order" || pf == "get_order" || pf == "set_initial_value" || pf == "set_as_basic" ||
  1189. pf == "set_as_internal" || pf == "set_restart_if_changed" || pf == "clear") {
  1190. for (const KeyValue<StringName, VariantContainer> &E : props) {
  1191. if (E.value.hide_from_editor) {
  1192. continue;
  1193. }
  1194. r_options->push_back(String(E.key).quote());
  1195. }
  1196. }
  1197. }
  1198. Object::get_argument_options(p_function, p_idx, r_options);
  1199. }
  1200. #endif
  1201. void ProjectSettings::_bind_methods() {
  1202. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  1203. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  1204. ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant()));
  1205. ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override);
  1206. ClassDB::bind_method(D_METHOD("get_global_class_list"), &ProjectSettings::get_global_class_list);
  1207. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  1208. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  1209. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  1210. ClassDB::bind_method(D_METHOD("set_as_basic", "name", "basic"), &ProjectSettings::set_as_basic);
  1211. ClassDB::bind_method(D_METHOD("set_as_internal", "name", "internal"), &ProjectSettings::set_as_internal);
  1212. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  1213. ClassDB::bind_method(D_METHOD("set_restart_if_changed", "name", "restart"), &ProjectSettings::set_restart_if_changed);
  1214. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  1215. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  1216. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  1217. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  1218. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::load_resource_pack, DEFVAL(true), DEFVAL(0));
  1219. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  1220. ADD_SIGNAL(MethodInfo("settings_changed"));
  1221. }
  1222. void ProjectSettings::_add_builtin_input_map() {
  1223. if (InputMap::get_singleton()) {
  1224. HashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  1225. for (KeyValue<String, List<Ref<InputEvent>>> &E : builtins) {
  1226. Array events;
  1227. // Convert list of input events into array
  1228. for (List<Ref<InputEvent>>::Element *I = E.value.front(); I; I = I->next()) {
  1229. events.push_back(I->get());
  1230. }
  1231. Dictionary action;
  1232. action["deadzone"] = Variant(InputMap::DEFAULT_DEADZONE);
  1233. action["events"] = events;
  1234. String action_name = "input/" + E.key;
  1235. GLOBAL_DEF(action_name, action);
  1236. input_presets.push_back(action_name);
  1237. }
  1238. }
  1239. }
  1240. ProjectSettings::ProjectSettings() {
  1241. // Initialization of engine variables should be done in the setup() method,
  1242. // so that the values can be overridden from project.godot or project.binary.
  1243. CRASH_COND_MSG(singleton != nullptr, "Instantiating a new ProjectSettings singleton is not supported.");
  1244. singleton = this;
  1245. #ifdef TOOLS_ENABLED
  1246. // Available only at runtime in editor builds. Needs to be processed before anything else to work properly.
  1247. if (!Engine::get_singleton()->is_editor_hint()) {
  1248. String editor_features = OS::get_singleton()->get_environment("GODOT_EDITOR_CUSTOM_FEATURES");
  1249. if (!editor_features.is_empty()) {
  1250. PackedStringArray feature_list = editor_features.split(",");
  1251. for (const String &s : feature_list) {
  1252. custom_features.insert(s);
  1253. }
  1254. }
  1255. }
  1256. #endif
  1257. GLOBAL_DEF_BASIC("application/config/name", "");
  1258. GLOBAL_DEF_BASIC(PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary());
  1259. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT), "");
  1260. GLOBAL_DEF_BASIC("application/config/version", "");
  1261. GLOBAL_DEF_INTERNAL(PropertyInfo(Variant::STRING, "application/config/tags"), PackedStringArray());
  1262. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"), "");
  1263. GLOBAL_DEF("application/run/disable_stdout", false);
  1264. GLOBAL_DEF("application/run/disable_stderr", false);
  1265. GLOBAL_DEF("application/run/print_header", true);
  1266. GLOBAL_DEF("application/run/enable_alt_space_menu", false);
  1267. GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true);
  1268. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  1269. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  1270. GLOBAL_DEF("application/config/project_settings_override", "");
  1271. GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
  1272. GLOBAL_DEF("application/config/auto_accept_quit", true);
  1273. GLOBAL_DEF("application/config/quit_on_go_back", true);
  1274. // The default window size is tuned to:
  1275. // - Have a 16:9 aspect ratio,
  1276. // - Have both dimensions divisible by 8 to better play along with video recording,
  1277. // - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings).
  1278. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "1,7680,1,or_greater"), 1152); // 8K resolution
  1279. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "1,4320,1,or_greater"), 648); // 8K resolution
  1280. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"), 0);
  1281. // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
  1282. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_position_type", PROPERTY_HINT_ENUM, "Absolute,Center of Primary Screen,Center of Other Screen,Center of Screen With Mouse Pointer,Center of Screen With Keyboard Focus"), 1);
  1283. GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR2I, "display/window/size/initial_position"), Vector2i());
  1284. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), 0);
  1285. GLOBAL_DEF_BASIC("display/window/size/resizable", true);
  1286. GLOBAL_DEF_BASIC("display/window/size/borderless", false);
  1287. GLOBAL_DEF("display/window/size/always_on_top", false);
  1288. GLOBAL_DEF("display/window/size/transparent", false);
  1289. GLOBAL_DEF("display/window/size/extend_to_title", false);
  1290. GLOBAL_DEF("display/window/size/no_focus", false);
  1291. GLOBAL_DEF("display/window/size/sharp_corners", false);
  1292. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution
  1293. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution
  1294. GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
  1295. GLOBAL_DEF("animation/warnings/check_invalid_track_paths", true);
  1296. GLOBAL_DEF("animation/warnings/check_angle_interpolation_type_conflicting", true);
  1297. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"), "res://default_bus_layout.tres");
  1298. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type", PROPERTY_HINT_ENUM, "Stream,Sample"), 0);
  1299. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type.web", PROPERTY_HINT_ENUM, "Stream,Sample"), 1);
  1300. GLOBAL_DEF_RST("audio/general/text_to_speech", false);
  1301. GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
  1302. GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
  1303. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/ios/session_category", PROPERTY_HINT_ENUM, "Ambient,Multi Route,Play and Record,Playback,Record,Solo Ambient"), 0);
  1304. GLOBAL_DEF("audio/general/ios/mix_with_others", false);
  1305. _add_builtin_input_map();
  1306. // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
  1307. custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::INT, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor");
  1308. GLOBAL_DEF("display/window/subwindows/embed_subwindows", true);
  1309. // Keep the enum values in sync with the `DisplayServer::VSyncMode` enum.
  1310. custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox");
  1311. GLOBAL_DEF("display/window/frame_pacing/android/enable_frame_pacing", true);
  1312. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/frame_pacing/android/swappy_mode", PROPERTY_HINT_ENUM, "pipeline_forced_on,auto_fps_pipeline_forced_on,auto_fps_auto_pipeline"), 2);
  1313. #ifdef DISABLE_DEPRECATED
  1314. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Safe:1,Separate");
  1315. #else
  1316. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Unsafe (deprecated),Safe,Separate");
  1317. #endif
  1318. GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
  1319. GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
  1320. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,canvas_items,viewport"), "disabled");
  1321. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand"), "keep");
  1322. GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "display/window/stretch/scale", PROPERTY_HINT_RANGE, "0.5,8.0,0.01"), 1.0);
  1323. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/scale_mode", PROPERTY_HINT_ENUM, "fractional,integer"), "fractional");
  1324. GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1"), 16384);
  1325. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "debug/settings/profiler/max_timestamp_query_elements", PROPERTY_HINT_RANGE, "256,65535,1"), 256);
  1326. GLOBAL_DEF(PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching"), Compression::zstd_long_distance_matching);
  1327. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"), Compression::zstd_level);
  1328. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1"), Compression::zstd_window_log_size);
  1329. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::zlib_level);
  1330. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::gzip_level);
  1331. GLOBAL_DEF("debug/settings/crash_handler/message",
  1332. String("Please include this when reporting the bug to the project developer."));
  1333. GLOBAL_DEF("debug/settings/crash_handler/message.editor",
  1334. String("Please include this when reporting the bug on: https://github.com/godotengine/godot/issues"));
  1335. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/occlusion_culling/bvh_build_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), 2);
  1336. GLOBAL_DEF_RST("rendering/occlusion_culling/jitter_projection", true);
  1337. GLOBAL_DEF_RST("internationalization/rendering/force_right_to_left_layout_direction", false);
  1338. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "internationalization/rendering/root_node_layout_direction", PROPERTY_HINT_ENUM, "Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale"), 0);
  1339. GLOBAL_DEF_BASIC("internationalization/rendering/root_node_auto_translate", true);
  1340. GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/timers/incremental_search_max_interval_msec", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"), 2000);
  1341. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "gui/timers/tooltip_delay_sec", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5);
  1342. #ifdef TOOLS_ENABLED
  1343. GLOBAL_DEF("gui/timers/tooltip_delay_sec.editor_hint", 0.5);
  1344. #endif
  1345. GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true);
  1346. GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true);
  1347. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/frame_queue_size", PROPERTY_HINT_RANGE, "2,3,1"), 2);
  1348. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/swapchain_image_count", PROPERTY_HINT_RANGE, "2,4,1"), 3);
  1349. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/block_size_kb", PROPERTY_HINT_RANGE, "4,2048,1,or_greater"), 256);
  1350. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/max_size_mb", PROPERTY_HINT_RANGE, "1,1024,1,or_greater"), 128);
  1351. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_upload_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1352. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_download_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1353. GLOBAL_DEF_RST(PropertyInfo(Variant::BOOL, "rendering/rendering_device/pipeline_cache/enable"), true);
  1354. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/rendering_device/pipeline_cache/save_chunk_size_mb", PROPERTY_HINT_RANGE, "0.000001,64.0,0.001,or_greater"), 3.0);
  1355. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/vulkan/max_descriptors_per_pool", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1356. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", 16384);
  1357. custom_prop_info["rendering/rendering_device/d3d12/max_resource_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", PROPERTY_HINT_RANGE, "512,262144");
  1358. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", 1024);
  1359. custom_prop_info["rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", PROPERTY_HINT_RANGE, "256,2048");
  1360. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_misc_descriptors_per_frame", 512);
  1361. custom_prop_info["rendering/rendering_device/d3d12/max_misc_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_misc_descriptors_per_frame", PROPERTY_HINT_RANGE, "32,4096");
  1362. // The default value must match the minor part of the Agility SDK version
  1363. // installed by the scripts provided in the repository
  1364. // (check `misc/scripts/install_d3d12_sdk_windows.py`).
  1365. // For example, if the script installs 1.613.3, the default value must be 613.
  1366. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/agility_sdk_version", PROPERTY_HINT_RANGE, "0,10000,1,or_greater,hide_slider"), 613);
  1367. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Linear Mipmap,Nearest Mipmap"), 1);
  1368. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_repeat", PROPERTY_HINT_ENUM, "Disable,Enable,Mirror"), 0);
  1369. GLOBAL_DEF("collada/use_ambient", false);
  1370. // Input settings
  1371. GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_long_press_as_right_click", false);
  1372. GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_pan_and_scale_gestures", false);
  1373. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "input_devices/pointing/android/rotary_input_scroll_axis", PROPERTY_HINT_ENUM, "Horizontal,Vertical"), 1);
  1374. // These properties will not show up in the dialog. If you want to exclude whole groups, use add_hidden_prefix().
  1375. GLOBAL_DEF_INTERNAL("application/config/features", PackedStringArray());
  1376. GLOBAL_DEF_INTERNAL("internationalization/locale/translation_remaps", PackedStringArray());
  1377. GLOBAL_DEF_INTERNAL("internationalization/locale/translations", PackedStringArray());
  1378. GLOBAL_DEF_INTERNAL("internationalization/locale/translations_pot_files", PackedStringArray());
  1379. GLOBAL_DEF_INTERNAL("internationalization/locale/translation_add_builtin_strings_to_pot", false);
  1380. ProjectSettings::get_singleton()->add_hidden_prefix("input/");
  1381. }
  1382. ProjectSettings::ProjectSettings(const String &p_path) {
  1383. if (load_custom(p_path) == OK) {
  1384. resource_path = p_path.get_base_dir();
  1385. project_loaded = true;
  1386. }
  1387. }
  1388. ProjectSettings::~ProjectSettings() {
  1389. if (singleton == this) {
  1390. singleton = nullptr;
  1391. }
  1392. }