You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-06 17:25:19 +00:00
GDScript: Reintroduce binary tokenization on export
This adds back a function available in 3.x: exporting the GDScript files in a binary form by converting the tokens recognized by the tokenizer into a data format. It is enabled by default on export but can be manually disabled. The format helps with loading times since, the tokens are easily reconstructed, and with hiding the source code, since recovering it would require a specialized tool. Code comments are not stored in this format. The `--test` command can also include a `--use-binary-tokens` flag which will run the GDScript tests with the binary format instead of the regular source code by converting them in-memory before the test runs.
This commit is contained in:
@@ -85,6 +85,7 @@ void EditorExport::_save() {
|
||||
config->set_value(section, "encryption_exclude_filters", preset->get_enc_ex_filter());
|
||||
config->set_value(section, "encrypt_pck", preset->get_enc_pck());
|
||||
config->set_value(section, "encrypt_directory", preset->get_enc_directory());
|
||||
config->set_value(section, "script_export_mode", preset->get_script_export_mode());
|
||||
credentials->set_value(section, "script_encryption_key", preset->get_script_encryption_key());
|
||||
|
||||
String option_section = "preset." + itos(i) + ".options";
|
||||
@@ -269,6 +270,7 @@ void EditorExport::load_config() {
|
||||
preset->set_include_filter(config->get_value(section, "include_filter"));
|
||||
preset->set_exclude_filter(config->get_value(section, "exclude_filter"));
|
||||
preset->set_export_path(config->get_value(section, "export_path", ""));
|
||||
preset->set_script_export_mode(config->get_value(section, "script_export_mode", EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS));
|
||||
|
||||
if (config->has_section_key(section, "encrypt_pck")) {
|
||||
preset->set_enc_pck(config->get_value(section, "encrypt_pck"));
|
||||
|
||||
@@ -323,6 +323,15 @@ String EditorExportPreset::get_script_encryption_key() const {
|
||||
return script_key;
|
||||
}
|
||||
|
||||
void EditorExportPreset::set_script_export_mode(int p_mode) {
|
||||
script_mode = p_mode;
|
||||
EditorExport::singleton->save_presets();
|
||||
}
|
||||
|
||||
int EditorExportPreset::get_script_export_mode() const {
|
||||
return script_mode;
|
||||
}
|
||||
|
||||
Variant EditorExportPreset::get_or_env(const StringName &p_name, const String &p_env_var, bool *r_valid) const {
|
||||
const String from_env = OS::get_singleton()->get_environment(p_env_var);
|
||||
if (!from_env.is_empty()) {
|
||||
|
||||
@@ -54,6 +54,11 @@ public:
|
||||
MODE_FILE_REMOVE,
|
||||
};
|
||||
|
||||
enum ScriptExportMode {
|
||||
MODE_SCRIPT_TEXT,
|
||||
MODE_SCRIPT_BINARY_TOKENS,
|
||||
};
|
||||
|
||||
private:
|
||||
Ref<EditorExportPlatform> platform;
|
||||
ExportFilter export_filter = EXPORT_ALL_RESOURCES;
|
||||
@@ -84,6 +89,7 @@ private:
|
||||
bool enc_directory = false;
|
||||
|
||||
String script_key;
|
||||
int script_mode = MODE_SCRIPT_BINARY_TOKENS;
|
||||
|
||||
protected:
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
@@ -152,6 +158,9 @@ public:
|
||||
void set_script_encryption_key(const String &p_key);
|
||||
String get_script_encryption_key() const;
|
||||
|
||||
void set_script_export_mode(int p_mode);
|
||||
int get_script_export_mode() const;
|
||||
|
||||
Variant get_or_env(const StringName &p_name, const String &p_env_var, bool *r_valid = nullptr) const;
|
||||
|
||||
// Return the preset's version number, or fall back to the
|
||||
|
||||
@@ -383,6 +383,9 @@ void ProjectExportDialog::_edit_preset(int p_index) {
|
||||
script_key_error->hide();
|
||||
}
|
||||
|
||||
int script_export_mode = current->get_script_export_mode();
|
||||
script_mode->select(script_export_mode);
|
||||
|
||||
updating = false;
|
||||
}
|
||||
|
||||
@@ -582,6 +585,19 @@ bool ProjectExportDialog::_validate_script_encryption_key(const String &p_key) {
|
||||
return is_valid;
|
||||
}
|
||||
|
||||
void ProjectExportDialog::_script_export_mode_changed(int p_mode) {
|
||||
if (updating) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<EditorExportPreset> current = get_current_preset();
|
||||
ERR_FAIL_COND(current.is_null());
|
||||
|
||||
current->set_script_export_mode(p_mode);
|
||||
|
||||
_update_current_preset();
|
||||
}
|
||||
|
||||
void ProjectExportDialog::_duplicate_preset() {
|
||||
Ref<EditorExportPreset> current = get_current_preset();
|
||||
if (current.is_null()) {
|
||||
@@ -1328,7 +1344,7 @@ ProjectExportDialog::ProjectExportDialog() {
|
||||
feature_vb->add_margin_child(TTR("Feature List:"), custom_feature_display, true);
|
||||
sections->add_child(feature_vb);
|
||||
|
||||
// Script export parameters.
|
||||
// Encryption export parameters.
|
||||
|
||||
VBoxContainer *sec_vb = memnew(VBoxContainer);
|
||||
sec_vb->set_name(TTR("Encryption"));
|
||||
@@ -1373,6 +1389,18 @@ ProjectExportDialog::ProjectExportDialog() {
|
||||
sec_more_info->connect("pressed", callable_mp(this, &ProjectExportDialog::_open_key_help_link));
|
||||
sec_vb->add_child(sec_more_info);
|
||||
|
||||
// Script export parameters.
|
||||
|
||||
VBoxContainer *script_vb = memnew(VBoxContainer);
|
||||
script_vb->set_name(TTR("Scripts"));
|
||||
|
||||
script_mode = memnew(OptionButton);
|
||||
script_vb->add_margin_child(TTR("GDScript Export Mode:"), script_mode);
|
||||
script_mode->add_item(TTR("Text (easier debugging)"), (int)EditorExportPreset::MODE_SCRIPT_TEXT);
|
||||
script_mode->add_item(TTR("Binary tokens (faster loading)"), (int)EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS);
|
||||
script_mode->connect("item_selected", callable_mp(this, &ProjectExportDialog::_script_export_mode_changed));
|
||||
sections->add_child(script_vb);
|
||||
|
||||
sections->connect("tab_changed", callable_mp(this, &ProjectExportDialog::_tab_changed));
|
||||
|
||||
// Disable by default.
|
||||
|
||||
@@ -160,6 +160,8 @@ class ProjectExportDialog : public ConfirmationDialog {
|
||||
LineEdit *enc_in_filters = nullptr;
|
||||
LineEdit *enc_ex_filters = nullptr;
|
||||
|
||||
OptionButton *script_mode = nullptr;
|
||||
|
||||
void _open_export_template_manager();
|
||||
|
||||
void _export_pck_zip();
|
||||
@@ -183,6 +185,8 @@ class ProjectExportDialog : public ConfirmationDialog {
|
||||
void _script_encryption_key_changed(const String &p_key);
|
||||
bool _validate_script_encryption_key(const String &p_key);
|
||||
|
||||
void _script_export_mode_changed(int p_mode);
|
||||
|
||||
void _open_key_help_link();
|
||||
|
||||
void _tab_changed(int);
|
||||
|
||||
Reference in New Issue
Block a user