Skip to content

Commit

Permalink
Merge pull request #70377 from dsnopek/server-export-mk2
Browse files Browse the repository at this point in the history
Add "dedicated server" export mode which can strip unneeded visual resources
  • Loading branch information
akien-mga committed Jan 23, 2023
2 parents f963202 + 74458b6 commit 1dfd236
Show file tree
Hide file tree
Showing 26 changed files with 670 additions and 41 deletions.
8 changes: 8 additions & 0 deletions doc/classes/Cubemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@
</description>
<tutorials>
</tutorials>
<methods>
<method name="create_placeholder" qualifiers="const">
<return type="Resource" />
<description>
Creates a placeholder version of this resource ([PlaceholderCubemap]).
</description>
</method>
</methods>
</class>
8 changes: 8 additions & 0 deletions doc/classes/CubemapArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@
</description>
<tutorials>
</tutorials>
<methods>
<method name="create_placeholder" qualifiers="const">
<return type="Resource" />
<description>
Creates a placeholder version of this resource ([PlaceholderCubemapArray]).
</description>
</method>
</methods>
</class>
6 changes: 6 additions & 0 deletions doc/classes/Material.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<description>
</description>
</method>
<method name="create_placeholder" qualifiers="const">
<return type="Resource" />
<description>
Creates a placeholder version of this resource ([PlaceholderMaterial]).
</description>
</method>
<method name="inspect_native_shader_code">
<return type="void" />
<description>
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/Mesh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
[b]Note:[/b] This method typically returns the vertices in reverse order (e.g. clockwise to counterclockwise).
</description>
</method>
<method name="create_placeholder" qualifiers="const">
<return type="Resource" />
<description>
Creates a placeholder version of this resource ([PlaceholderMesh]).
</description>
</method>
<method name="create_trimesh_shape" qualifiers="const">
<return type="ConcavePolygonShape3D" />
<description>
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/Texture2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
Called when a pixel's opaque state in the [Texture2D] is queried at the specified [code](x, y)[/code] position.
</description>
</method>
<method name="create_placeholder" qualifiers="const">
<return type="Resource" />
<description>
Creates a placeholder version of this resource ([PlaceholderTexture2D]).
</description>
</method>
<method name="draw" qualifiers="const">
<return type="void" />
<param index="0" name="canvas_item" type="RID" />
Expand Down
8 changes: 8 additions & 0 deletions doc/classes/Texture2DArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@
</description>
<tutorials>
</tutorials>
<methods>
<method name="create_placeholder" qualifiers="const">
<return type="Resource" />
<description>
Creates a placeholder version of this resource ([PlaceholderTexture2DArray]).
</description>
</method>
</methods>
</class>
6 changes: 6 additions & 0 deletions doc/classes/Texture3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
Called when the presence of mipmaps in the [Texture3D] is queried.
</description>
</method>
<method name="create_placeholder" qualifiers="const">
<return type="Resource" />
<description>
Creates a placeholder version of this resource ([PlaceholderTexture3D]).
</description>
</method>
<method name="get_data" qualifiers="const">
<return type="Image[]" />
<description>
Expand Down
6 changes: 6 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
#include "editor/plugins/asset_library_editor_plugin.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/plugins/debugger_editor_plugin.h"
#include "editor/plugins/dedicated_server_export_plugin.h"
#include "editor/plugins/editor_preview_plugins.h"
#include "editor/plugins/editor_resource_conversion_plugin.h"
#include "editor/plugins/gdextension_export_plugin.h"
Expand Down Expand Up @@ -7878,6 +7879,11 @@ EditorNode::EditorNode() {

EditorExport::get_singleton()->add_export_plugin(gdextension_export_plugin);

Ref<DedicatedServerExportPlugin> dedicated_server_export_plugin;
dedicated_server_export_plugin.instantiate();

EditorExport::get_singleton()->add_export_plugin(dedicated_server_export_plugin);

Ref<PackedSceneEditorTranslationParserPlugin> packed_scene_translation_parser_plugin;
packed_scene_translation_parser_plugin.instantiate();
EditorTranslationParser::get_singleton()->add_parser(packed_scene_translation_parser_plugin, EditorTranslationParser::STANDARD);
Expand Down
11 changes: 11 additions & 0 deletions editor/export/editor_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void EditorExport::_save() {
config->set_value(section, "name", preset->get_name());
config->set_value(section, "platform", preset->get_platform()->get_name());
config->set_value(section, "runnable", preset->is_runnable());
config->set_value(section, "dedicated_server", preset->is_dedicated_server());
config->set_value(section, "custom_features", preset->get_custom_features());

bool save_files = false;
Expand All @@ -64,6 +65,11 @@ void EditorExport::_save() {
config->set_value(section, "export_filter", "exclude");
save_files = true;
} break;
case EditorExportPreset::EXPORT_CUSTOMIZED: {
config->set_value(section, "export_filter", "customized");
config->set_value(section, "customized_files", preset->get_customized_files());
save_files = false;
};
}

if (save_files) {
Expand Down Expand Up @@ -213,6 +219,7 @@ void EditorExport::load_config() {

preset->set_name(config->get_value(section, "name"));
preset->set_runnable(config->get_value(section, "runnable"));
preset->set_dedicated_server(config->get_value(section, "dedicated_server", false));

if (config->has_section_key(section, "custom_features")) {
preset->set_custom_features(config->get_value(section, "custom_features"));
Expand All @@ -233,6 +240,10 @@ void EditorExport::load_config() {
} else if (export_filter == "exclude") {
preset->set_export_filter(EditorExportPreset::EXCLUDE_SELECTED_RESOURCES);
get_files = true;
} else if (export_filter == "customized") {
preset->set_export_filter(EditorExportPreset::EXPORT_CUSTOMIZED);
preset->set_customized_files(config->get_value(section, "customized_files", Dictionary()));
get_files = false;
}

if (get_files) {
Expand Down
45 changes: 39 additions & 6 deletions editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,24 @@ void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_d
}
}

void EditorExportPlatform::_export_find_customized_resources(const Ref<EditorExportPreset> &p_preset, EditorFileSystemDirectory *p_dir, EditorExportPreset::FileExportMode p_mode, HashSet<String> &p_paths) {
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
EditorFileSystemDirectory *subdir = p_dir->get_subdir(i);
_export_find_customized_resources(p_preset, subdir, p_preset->get_file_export_mode(subdir->get_path(), p_mode), p_paths);
}

for (int i = 0; i < p_dir->get_file_count(); i++) {
if (p_dir->get_file_type(i) == "TextFile") {
continue;
}
String path = p_dir->get_file_path(i);
EditorExportPreset::FileExportMode file_mode = p_preset->get_file_export_mode(path, p_mode);
if (file_mode != EditorExportPreset::MODE_FILE_REMOVE) {
p_paths.insert(path);
}
}
}

void EditorExportPlatform::_export_find_dependencies(const String &p_path, HashSet<String> &p_paths) {
if (p_paths.has(p_path)) {
return;
Expand Down Expand Up @@ -639,10 +657,20 @@ bool EditorExportPlatform::_export_customize_object(Object *p_object, LocalVecto
return changed;
}

bool EditorExportPlatform::_is_editable_ancestor(Node *p_root, Node *p_node) {
while (p_node != nullptr && p_node != p_root) {
if (p_root->is_editable_instance(p_node)) {
return true;
}
p_node = p_node->get_owner();
}
return false;
}

bool EditorExportPlatform::_export_customize_scene_resources(Node *p_root, Node *p_node, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins) {
bool changed = false;

if (p_node == p_root || p_node->get_owner() == p_root) {
if (p_root == p_node || p_node->get_owner() == p_root || _is_editable_ancestor(p_root, p_node)) {
if (_export_customize_object(p_node, customize_resources_plugins)) {
changed = true;
}
Expand Down Expand Up @@ -757,10 +785,10 @@ String EditorExportPlatform::_export_customize(const String &p_path, LocalVector
break;
}
}
}

if (_export_customize_object(res.ptr(), customize_resources_plugins)) {
modified = true;
}
if (_export_customize_object(res.ptr(), customize_resources_plugins)) {
modified = true;
}

if (modified || p_force_save) {
Expand Down Expand Up @@ -796,6 +824,8 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
for (int i = 0; i < files.size(); i++) {
paths.erase(files[i]);
}
} else if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED) {
_export_find_customized_resources(p_preset, EditorFileSystem::get_singleton()->get_filesystem(), p_preset->get_file_export_mode("res://"), paths);
} else {
bool scenes_only = p_preset->get_export_filter() == EditorExportPreset::EXPORT_SELECTED_SCENES;

Expand Down Expand Up @@ -939,14 +969,14 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
LocalVector<Ref<EditorExportPlugin>> customize_scenes_plugins;

for (int i = 0; i < export_plugins.size(); i++) {
if (export_plugins[i]->_begin_customize_resources(Ref<EditorExportPlatform>(this), features_psa)) {
if (export_plugins.write[i]->_begin_customize_resources(Ref<EditorExportPlatform>(this), features_psa)) {
customize_resources_plugins.push_back(export_plugins[i]);

custom_resources_hash = hash_murmur3_one_64(export_plugins[i]->_get_name().hash64(), custom_resources_hash);
uint64_t hash = export_plugins[i]->_get_customization_configuration_hash();
custom_resources_hash = hash_murmur3_one_64(hash, custom_resources_hash);
}
if (export_plugins[i]->_begin_customize_scenes(Ref<EditorExportPlatform>(this), features_psa)) {
if (export_plugins.write[i]->_begin_customize_scenes(Ref<EditorExportPlatform>(this), features_psa)) {
customize_scenes_plugins.push_back(export_plugins[i]);

custom_resources_hash = hash_murmur3_one_64(export_plugins[i]->_get_name().hash64(), custom_resources_hash);
Expand Down Expand Up @@ -1218,6 +1248,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
}
}
}
for (int i = 0; i < export_plugins.size(); i++) {
custom_list.append_array(export_plugins[i]->_get_export_features(Ref<EditorExportPlatform>(this), p_debug));
}

ProjectSettings::CustomMap custom_map;
if (path_remaps.size()) {
Expand Down
2 changes: 2 additions & 0 deletions editor/export/editor_export_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class EditorExportPlatform : public RefCounted {
Vector<ExportMessage> messages;

void _export_find_resources(EditorFileSystemDirectory *p_dir, HashSet<String> &p_paths);
void _export_find_customized_resources(const Ref<EditorExportPreset> &p_preset, EditorFileSystemDirectory *p_dir, EditorExportPreset::FileExportMode p_mode, HashSet<String> &p_paths);
void _export_find_dependencies(const String &p_path, HashSet<String> &p_paths);

static Error _save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
Expand All @@ -112,6 +113,7 @@ class EditorExportPlatform : public RefCounted {
bool _export_customize_array(Array &array, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
bool _export_customize_object(Object *p_object, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
bool _export_customize_scene_resources(Node *p_root, Node *p_node, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins);
bool _is_editable_ancestor(Node *p_root, Node *p_node);

String _export_customize(const String &p_path, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins, LocalVector<Ref<EditorExportPlugin>> &customize_scenes_plugins, HashMap<String, FileExportCache> &export_cache, const String &export_base_path, bool p_force_save);

Expand Down
10 changes: 8 additions & 2 deletions editor/export/editor_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void EditorExportPlugin::_export_end_script() {

// Customization

bool EditorExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) const {
bool EditorExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
bool ret = false;
GDVIRTUAL_CALL(_begin_customize_resources, p_platform, p_features, ret);
return ret;
Expand All @@ -153,7 +153,7 @@ Ref<Resource> EditorExportPlugin::_customize_resource(const Ref<Resource> &p_res
return ret;
}

bool EditorExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) const {
bool EditorExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
bool ret = false;
GDVIRTUAL_CALL(_begin_customize_scenes, p_platform, p_features, ret);
return ret;
Expand Down Expand Up @@ -185,6 +185,12 @@ String EditorExportPlugin::_get_name() const {
return ret;
}

PackedStringArray EditorExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {
PackedStringArray ret;
GDVIRTUAL_CALL(_get_export_features, p_platform, p_debug, ret);
return ret;
}

void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) {
}

Expand Down
18 changes: 11 additions & 7 deletions editor/export/editor_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,22 @@ class EditorExportPlugin : public RefCounted {
GDVIRTUAL0(_end_customize_scenes)
GDVIRTUAL0(_end_customize_resources)

GDVIRTUAL2RC(PackedStringArray, _get_export_features, const Ref<EditorExportPlatform> &, bool);

GDVIRTUAL0RC(String, _get_name)

bool _begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) const; // Return true if this plugin does property export customization
Ref<Resource> _customize_resource(const Ref<Resource> &p_resource, const String &p_path); // If nothing is returned, it means do not touch (nothing changed). If something is returned (either the same or a different resource) it means changes are made.
virtual bool _begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features); // Return true if this plugin does property export customization
virtual Ref<Resource> _customize_resource(const Ref<Resource> &p_resource, const String &p_path); // If nothing is returned, it means do not touch (nothing changed). If something is returned (either the same or a different resource) it means changes are made.

virtual bool _begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features); // Return true if this plugin does property export customization
virtual Node *_customize_scene(Node *p_root, const String &p_path); // Return true if a change was made

bool _begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) const; // Return true if this plugin does property export customization
Node *_customize_scene(Node *p_root, const String &p_path); // Return true if a change was made
virtual uint64_t _get_customization_configuration_hash() const; // Hash used for caching customized resources and scenes.

uint64_t _get_customization_configuration_hash() const; // Hash used for caching customized resources and scenes.
virtual void _end_customize_scenes();
virtual void _end_customize_resources();

void _end_customize_scenes();
void _end_customize_resources();
virtual PackedStringArray _get_export_features(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const;

virtual String _get_name() const;

Expand Down
Loading

0 comments on commit 1dfd236

Please sign in to comment.