2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2017-09-01 14:07:55 +00:00
|
|
|
/* project_settings.h */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2022-01-13 08:45:09 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2022-07-25 10:33:41 +00:00
|
|
|
#ifndef PROJECT_SETTINGS_H
|
|
|
|
#define PROJECT_SETTINGS_H
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/object.h"
|
|
|
|
#include "core/os/thread_safe.h"
|
|
|
|
#include "core/set.h"
|
|
|
|
|
2021-10-01 10:47:28 +00:00
|
|
|
// Querying ProjectSettings is usually done at startup.
|
|
|
|
// Additionally, in order to keep track of changes to ProjectSettings,
|
|
|
|
// instead of Querying all the strings every frame just in case of changes,
|
|
|
|
// there is a signal "project_settings_changed" which objects can subscribe to.
|
|
|
|
|
|
|
|
// E.g. (from another Godot object)
|
|
|
|
// // Call your user written object function to Query the project settings once at creation,
|
|
|
|
// perhaps in an ENTER_TREE notification:
|
|
|
|
// _project_settings_changed()
|
|
|
|
// // Then connect your function to the signal so it is called every time something changes in future:
|
|
|
|
// ProjectSettings::get_singleton()->connect("project_settings_changed", this, "_project_settings_changed");
|
|
|
|
|
|
|
|
// Where for example your function may take the form:
|
|
|
|
// void _project_settings_changed() {
|
|
|
|
// _shadowmap_size = GLOBAL_GET("rendering/quality/shadow_atlas/size");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// You may want to also disconnect from the signal in EXIT_TREE notification, if your object may be deleted
|
|
|
|
// before ProjectSettings:
|
|
|
|
// ProjectSettings::get_singleton()->disconnect("project_settings_changed", this, "_project_settings_changed");
|
|
|
|
|
|
|
|
// Additionally, for objects that are not regular Godot objects capable of subscribing to signals (e.g. Rasterizers),
|
|
|
|
// you can also query the function "has_changes()" each frame,
|
|
|
|
// and update your local settings whenever this is set.
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
class ProjectSettings : public Object {
|
|
|
|
GDCLASS(ProjectSettings, Object);
|
2014-02-10 01:10:30 +00:00
|
|
|
_THREAD_SAFE_CLASS_
|
|
|
|
|
2021-10-01 10:47:28 +00:00
|
|
|
int _dirty_this_frame = 2;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2017-03-05 15:44:50 +00:00
|
|
|
typedef Map<String, Variant> CustomMap;
|
2021-10-13 20:16:52 +00:00
|
|
|
static const String PROJECT_DATA_DIR_NAME_SUFFIX;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-12-16 02:39:36 +00:00
|
|
|
enum {
|
2017-07-18 00:05:38 +00:00
|
|
|
//properties that are not for built in values begin from this value, so builtin ones are displayed first
|
|
|
|
NO_BUILTIN_ORDER_BASE = 1 << 16
|
2015-12-16 02:39:36 +00:00
|
|
|
};
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
protected:
|
2014-02-10 01:10:30 +00:00
|
|
|
struct VariantContainer {
|
|
|
|
int order;
|
|
|
|
bool persist;
|
|
|
|
Variant variant;
|
2017-01-05 12:16:00 +00:00
|
|
|
Variant initial;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool hide_from_editor;
|
2018-01-18 20:37:17 +00:00
|
|
|
bool overridden;
|
2018-07-19 21:58:15 +00:00
|
|
|
bool restart_if_changed;
|
2021-10-10 20:40:32 +00:00
|
|
|
#ifdef DEBUG_METHODS_ENABLED
|
|
|
|
bool ignore_value_in_docs = false;
|
|
|
|
#endif
|
|
|
|
|
2017-12-06 20:36:34 +00:00
|
|
|
VariantContainer() :
|
|
|
|
order(0),
|
|
|
|
persist(false),
|
|
|
|
hide_from_editor(false),
|
2018-07-20 06:37:10 +00:00
|
|
|
overridden(false),
|
|
|
|
restart_if_changed(false) {
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2017-12-06 20:36:34 +00:00
|
|
|
VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) :
|
|
|
|
order(p_order),
|
|
|
|
persist(p_persist),
|
|
|
|
variant(p_variant),
|
|
|
|
hide_from_editor(false),
|
2018-07-20 06:37:10 +00:00
|
|
|
overridden(false),
|
|
|
|
restart_if_changed(false) {
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2015-12-16 02:39:36 +00:00
|
|
|
bool registering_order;
|
2014-02-10 01:10:30 +00:00
|
|
|
int last_order;
|
2017-07-18 00:05:38 +00:00
|
|
|
int last_builtin_order;
|
2021-02-11 00:08:49 +00:00
|
|
|
uint64_t last_save_time = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<StringName, VariantContainer> props;
|
2014-02-10 01:10:30 +00:00
|
|
|
String resource_path;
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<StringName, PropertyInfo> custom_prop_info;
|
2017-07-19 20:00:46 +00:00
|
|
|
bool disable_feature_overrides;
|
2014-02-19 14:57:14 +00:00
|
|
|
bool using_datapack;
|
2015-12-14 21:36:53 +00:00
|
|
|
List<String> input_presets;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
Set<String> custom_features;
|
|
|
|
Map<StringName, StringName> feature_overrides;
|
|
|
|
|
2021-09-10 17:52:41 +00:00
|
|
|
String project_data_dir_name;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
static ProjectSettings *singleton;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2019-07-10 09:54:12 +00:00
|
|
|
Error _load_settings_text(const String &p_path);
|
|
|
|
Error _load_settings_binary(const String &p_path);
|
|
|
|
Error _load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-05-04 12:20:36 +00:00
|
|
|
Error _save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
|
|
|
|
Error _save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error _save_custom_bnd(const String &p_file);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-12-21 11:20:48 +00:00
|
|
|
void _convert_to_last_version(int p_from_version);
|
2018-02-21 21:06:34 +00:00
|
|
|
|
2020-07-13 16:22:06 +00:00
|
|
|
bool _load_resource_pack(const String &p_pack, bool p_replace_files = true, int p_offset = 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _add_property_info_bind(const Dictionary &p_info);
|
2016-08-16 20:10:53 +00:00
|
|
|
|
2021-11-22 15:10:31 +00:00
|
|
|
Error _setup(const String &p_path, const String &p_main_pack, bool p_upwards = false, bool p_ignore_override = false);
|
2018-11-18 13:56:21 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
static void _bind_methods();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2018-12-21 11:20:48 +00:00
|
|
|
static const int CONFIG_VERSION = 4;
|
|
|
|
|
2017-10-05 18:34:34 +00:00
|
|
|
void set_setting(const String &p_setting, const Variant &p_value);
|
|
|
|
Variant get_setting(const String &p_setting) const;
|
|
|
|
|
|
|
|
bool has_setting(String p_var) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
String localize_path(const String &p_path) const;
|
|
|
|
String globalize_path(const String &p_path) const;
|
2017-01-05 12:16:00 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_initial_value(const String &p_name, const Variant &p_value);
|
2018-07-19 21:58:15 +00:00
|
|
|
void set_restart_if_changed(const String &p_name, bool p_restart);
|
2021-10-05 20:10:12 +00:00
|
|
|
void set_hide_from_editor(const String &p_name, bool p_hide_from_editor);
|
2021-10-10 20:40:32 +00:00
|
|
|
void set_ignore_value_in_docs(const String &p_name, bool p_ignore);
|
|
|
|
bool get_ignore_value_in_docs(const String &p_name) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
bool property_can_revert(const String &p_name);
|
|
|
|
Variant property_get_revert(const String &p_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-09-10 17:52:41 +00:00
|
|
|
String get_project_data_dir_name() const;
|
|
|
|
String get_project_data_path() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
String get_resource_path() const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
static ProjectSettings *get_singleton();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void clear(const String &p_name);
|
|
|
|
int get_order(const String &p_name) const;
|
|
|
|
void set_order(const String &p_name, int p_order);
|
2017-07-18 00:05:38 +00:00
|
|
|
void set_builtin_order(const String &p_name);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2021-11-22 15:10:31 +00:00
|
|
|
Error setup(const String &p_path, const String &p_main_pack, bool p_upwards = false, bool p_ignore_override = false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-07-26 13:28:54 +00:00
|
|
|
Error save_custom(const String &p_path = "", const CustomMap &p_custom = CustomMap(), const Vector<String> &p_custom_features = Vector<String>(), bool p_merge_with_current = true);
|
2014-02-10 01:10:30 +00:00
|
|
|
Error save();
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info);
|
2018-05-26 18:19:38 +00:00
|
|
|
const Map<StringName, PropertyInfo> &get_custom_property_info() const;
|
2021-02-11 00:08:49 +00:00
|
|
|
uint64_t get_last_saved_time() { return last_save_time; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector<String> get_optimizer_presets() const;
|
|
|
|
|
2015-12-14 21:36:53 +00:00
|
|
|
List<String> get_input_presets() const { return input_presets; }
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
void set_disable_feature_overrides(bool p_disable);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-02-19 14:57:14 +00:00
|
|
|
bool is_using_datapack() const;
|
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
void set_registering_order(bool p_enable);
|
2015-12-16 02:39:36 +00:00
|
|
|
|
2018-07-18 08:22:59 +00:00
|
|
|
bool has_custom_feature(const String &p_feature) const;
|
|
|
|
|
2021-10-01 10:47:28 +00:00
|
|
|
// Either use the signal `project_settings_changed` or query this function.
|
|
|
|
// N.B. _dirty_this_frame is set initially to 2.
|
|
|
|
// This is to cope with the situation where a project setting is changed in the iteration AFTER it is read.
|
|
|
|
// There is therefore the potential for a change to be missed. Persisting the counter
|
|
|
|
// for two frames avoids this, at the cost of a frame delay.
|
|
|
|
bool has_changes() const { return _dirty_this_frame == 1; }
|
|
|
|
void update();
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
ProjectSettings();
|
|
|
|
~ProjectSettings();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//not a macro any longer
|
2021-10-10 20:40:32 +00:00
|
|
|
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed = false, bool p_ignore_value_in_docs = false);
|
2021-03-09 15:16:24 +00:00
|
|
|
Variant _GLOBAL_DEF_ALIAS(const String &p_var, const String &p_old_name, const Variant &p_default, bool p_restart_if_changed = false);
|
2017-03-05 15:44:50 +00:00
|
|
|
#define GLOBAL_DEF(m_var, m_value) _GLOBAL_DEF(m_var, m_value)
|
2018-07-19 21:58:15 +00:00
|
|
|
#define GLOBAL_DEF_RST(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true)
|
2021-10-10 20:40:32 +00:00
|
|
|
#define GLOBAL_DEF_NOVAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, true)
|
|
|
|
#define GLOBAL_DEF_RST_NOVAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, true)
|
2021-03-09 15:16:24 +00:00
|
|
|
#define GLOBAL_DEF_ALIAS(m_var, m_old_name, m_value) _GLOBAL_DEF_ALIAS(m_var, m_old_name, m_value)
|
|
|
|
#define GLOBAL_DEF_ALIAS_RST(m_var, m_old_name, m_value) _GLOBAL_DEF(m_var, m_old_name, m_value, true)
|
2017-07-19 20:00:46 +00:00
|
|
|
#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get(m_var)
|
2017-01-05 12:16:00 +00:00
|
|
|
|
2022-07-25 10:33:41 +00:00
|
|
|
#endif // PROJECT_SETTINGS_H
|