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