diff options
48 files changed, 1383 insertions, 196 deletions
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 2a3c298633..dbfb2bdeab 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,4 +1,9 @@ -**Operating system or device, Godot version, GPU Model and driver (if graphics related):** +**Godot version:** +<!-- If thirdparty of self-compiled, specify the build date or commit hash. --> + + +**OS/device including version:** +<!-- If graphics related, specify also GPU model and drivers. --> **Issue description:** @@ -8,5 +13,5 @@ **Steps to reproduce:** -**Link to minimal example project:** -<!-- Optional but very welcome. You can drag and drop a zip archive to upload it. --> +**Minimal reproduction project:** +<!-- Optional but greatly speeds up debugging. You can drag and drop a zip archive to upload it. --> diff --git a/SConstruct b/SConstruct index ad6b6ee445..88cd1494f1 100644 --- a/SConstruct +++ b/SConstruct @@ -557,9 +557,9 @@ class cache_progress: # decay since the ctime, and return a list with the entries # (filename, size, weight). current_time = time.time() - file_stat = [(x[0], x[1][0], x[1][0] * math.exp(self.exponent_scale * (x[1][1] - current_time))) for x in file_stat] - # Sort by highest weight (most sensible to keep) first - file_stat.sort(key=lambda x: x[2], reverse=True) + file_stat = [(x[0], x[1][0], (current_time - x[1][1])) for x in file_stat] + # Sort by the most resently accessed files (most sensible to keep) first + file_stat.sort(key=lambda x: x[2]) # Search for the first entry where the storage limit is # reached sum, mark = 0, None diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index d2aad1d63a..dea9f38634 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -35,6 +35,7 @@ #include "print_string.h" #include "project_settings.h" #include "translation.h" +#include "variant_parser.h" ResourceFormatLoader *ResourceLoader::loader[MAX_LOADERS]; int ResourceLoader::loader_count = 0; @@ -454,6 +455,49 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem if (path_remaps.has(new_path)) { new_path = path_remaps[new_path]; } + + if (new_path == p_path) { //did not remap + //try file remap + Error err; + FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err); + + if (f) { + + VariantParser::StreamFile stream; + stream.f = f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines = 0; + String error_text; + while (true) { + + assign = Variant(); + next_tag.fields.clear(); + next_tag.name = String(); + + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + if (err == ERR_FILE_EOF) { + break; + } else if (err != OK) { + ERR_PRINTS("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text); + break; + } + + if (assign == "path") { + new_path = value; + break; + } else if (next_tag.name != "remap") { + break; + } + } + + memdelete(f); + } + } + return new_path; } diff --git a/doc/classes/BakedLightmap.xml b/doc/classes/BakedLightmap.xml index 8084af3817..b351aeac05 100644 --- a/doc/classes/BakedLightmap.xml +++ b/doc/classes/BakedLightmap.xml @@ -57,11 +57,7 @@ </constant> <constant name="SUBDIV_1024" value="3" enum="Subdiv"> </constant> - <constant name="SUBDIV_2048" value="4" enum="Subdiv"> - </constant> - <constant name="SUBDIV_4096" value="5" enum="Subdiv"> - </constant> - <constant name="SUBDIV_MAX" value="6" enum="Subdiv"> + <constant name="SUBDIV_MAX" value="4" enum="Subdiv"> </constant> <constant name="BAKE_QUALITY_LOW" value="0" enum="BakeQuality"> </constant> @@ -73,5 +69,15 @@ </constant> <constant name="BAKE_MODE_RAY_TRACE" value="1" enum="BakeMode"> </constant> + <constant name="BAKE_ERROR_OK" value="0" enum="BakeError"> + </constant> + <constant name="BAKE_ERROR_NO_SAVE_PATH" value="1" enum="BakeError"> + </constant> + <constant name="BAKE_ERROR_NO_MESHES" value="2" enum="BakeError"> + </constant> + <constant name="BAKE_ERROR_CANT_CREATE_IMAGE" value="3" enum="BakeError"> + </constant> + <constant name="BAKE_ERROR_USER_ABORTED" value="4" enum="BakeError"> + </constant> </constants> </class> diff --git a/doc/classes/BakedLightmapData.xml b/doc/classes/BakedLightmapData.xml index 6997dcb0b2..2b95cff136 100644 --- a/doc/classes/BakedLightmapData.xml +++ b/doc/classes/BakedLightmapData.xml @@ -16,6 +16,8 @@ </argument> <argument index="1" name="lightmap" type="Texture"> </argument> + <argument index="2" name="instance" type="int"> + </argument> <description> </description> </method> diff --git a/doc/classes/Dictionary.xml b/doc/classes/Dictionary.xml index 40b60f00cf..08c01c1d85 100644 --- a/doc/classes/Dictionary.xml +++ b/doc/classes/Dictionary.xml @@ -16,6 +16,12 @@ Clear the dictionary, removing all key/value pairs. </description> </method> + <method name="duplicate"> + <return type="Dictionary"> + </return> + <description> + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 5d93c6a982..a4daa77b50 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -1784,6 +1784,8 @@ void RasterizerCanvasGLES3::initialize() { state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows); state.canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows); + + state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_PIXEL_SNAP, GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false)); } void RasterizerCanvasGLES3::finalize() { diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index ee6c738a05..8ee9e3fdb8 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -6048,6 +6048,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { glDeleteTextures(1, &rt->effects.mip_maps[i].color); rt->effects.mip_maps[i].sizes.clear(); rt->effects.mip_maps[i].levels = 0; + rt->effects.mip_maps[i].color = 0; } } diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp index 20b2bc0a28..56b1cfdf0f 100644 --- a/drivers/gles3/shader_gles3.cpp +++ b/drivers/gles3/shader_gles3.cpp @@ -465,7 +465,6 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() { if (feedbacks[i].conditional == -1 || (1 << feedbacks[i].conditional) & conditional_version.version) { //conditional for this feedback is enabled - print_line("tf varying: " + itos(feedback.size()) + " " + String(feedbacks[i].name)); feedback.push_back(feedbacks[i].name); } } diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 4bbb18ce42..0b8230234b 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -171,7 +171,7 @@ VERTEX_SHADER_CODE #ifdef USE_PIXEL_SNAP - outvec.xy=floor(outvec+0.5); + outvec.xy=floor(outvec+0.5).xy; #endif diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 3585417d13..1b88a56b75 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -740,7 +740,24 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & ProjectSettings::CustomMap custom_map; if (path_remaps.size()) { - custom_map["path_remap/remapped_paths"] = path_remaps; + if (1) { //new remap mode, use always as it's friendlier with multiple .pck exports + for (int i = 0; i < path_remaps.size(); i += 2) { + String from = path_remaps[i]; + String to = path_remaps[i + 1]; + String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n"; + CharString utf8 = remap_file.utf8(); + Vector<uint8_t> new_file; + new_file.resize(utf8.length()); + for (int j = 0; j < utf8.length(); j++) { + new_file[j] = utf8[j]; + } + + p_func(p_udata, from + ".remap", new_file, idx, total); + } + } else { + //old remap mode, will still work, but it's unused because it's not multiple pck export friendly + custom_map["path_remap/remapped_paths"] = path_remaps; + } } // Store icon and splash images directly, they need to bypass the import system and be loaded as images diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index eaa57fa46b..deba16a524 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -107,8 +107,8 @@ void EditorFileDialog::_notification(int p_what) { fav_up->set_icon(get_icon("MoveUp", "EditorIcons")); fav_down->set_icon(get_icon("MoveDown", "EditorIcons")); fav_rm->set_icon(get_icon("Remove", "EditorIcons")); - - update_file_list(); + // DO NOT CALL UPDATE FILE LIST HERE, ALL HUNDREDS OF HIDDEN DIALOGS WILL RESPOND, CALL INVALIDATE INSTEAD + invalidate(); } } @@ -637,6 +637,7 @@ bool EditorFileDialog::_is_open_should_be_disabled() { return false; } +// DO NOT USE THIS FUNCTION UNLESS NEEDED, CALL INVALIDATE() INSTEAD. void EditorFileDialog::update_file_list() { int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index d20b55e268..46badc8c86 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1016,6 +1016,10 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { class_desc->pop(); //cell } + if (m[i].description != "") { + method_descr = true; + } + _add_method(m[i], true); } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 0eb8ea6e46..f8e350bee3 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5033,7 +5033,7 @@ EditorNode::EditorNode() { scene_root_parent->set_v_size_flags(Control::SIZE_EXPAND_FILL); scene_root = memnew(Viewport); - scene_root->set_usage(Viewport::USAGE_2D); + //scene_root->set_usage(Viewport::USAGE_2D); canvas BG mode prevents usage of this as 2D scene_root->set_disable_3d(true); VisualServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport_rid(), true); diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index 3eaa6e44fd..a72769b222 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -273,7 +273,7 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ char fname[16384]; unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); - String file = fname; + String file = String(fname).get_file(); Vector<uint8_t> data; data.resize(info.uncompressed_size); @@ -283,21 +283,18 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ unzReadCurrentFile(pkg, data.ptrw(), data.size()); unzCloseCurrentFile(pkg); - print_line(fname); - /* - for(int i=0;i<512;i++) { - print_line(itos(data[i])); - } - */ - - file = file.get_file(); if (p) { p->step(TTR("Importing:") + " " + file, fc); } FileAccess *f = FileAccess::open(template_path.plus_file(file), FileAccess::WRITE); - ERR_CONTINUE(!f); + if (!f) { + ret = unzGoToNextFile(pkg); + fc++; + ERR_CONTINUE(!f); + } + f->store_buffer(data.ptr(), data.size()); memdelete(f); @@ -555,7 +552,7 @@ ExportTemplateManager::ExportTemplateManager() { template_open->add_filter("*.tpz ; Godot Export Templates"); template_open->set_access(FileDialog::ACCESS_FILESYSTEM); template_open->set_mode(FileDialog::MODE_OPEN_FILE); - template_open->connect("file_selected", this, "_install_from_file"); + template_open->connect("file_selected", this, "_install_from_file", varray(true)); add_child(template_open); set_title(TTR("Export Template Manager")); diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index 2c2e5a7c9b..e02925e377 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -188,6 +188,9 @@ void ProgressDialog::add_task(const String &p_task, const String &p_label, int p cancel_hb->raise(); cancelled = false; _popup(); + if (p_can_cancel) { + cancel->grab_focus(); + } } bool ProgressDialog::task_step(const String &p_task, const String &p_state, int p_step, bool p_force_redraw) { diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp index cc70a48f6f..2bdc824248 100644 --- a/editor/settings_config_dialog.cpp +++ b/editor/settings_config_dialog.cpp @@ -352,7 +352,7 @@ void EditorSettingsDialog::_tabs_tab_changed(int p_tab) { void EditorSettingsDialog::_focus_current_search_box() { Control *tab = tabs->get_current_tab_control(); - LineEdit* current_search_box; + LineEdit *current_search_box; if (tab == tab_general) current_search_box = search_box; else if (tab == tab_shortcuts) diff --git a/main/main.cpp b/main/main.cpp index ab520c5e7f..5648676c4c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1448,6 +1448,9 @@ bool Main::start() { bool snap_controls = GLOBAL_DEF("gui/common/snap_controls_to_pixels", true); sml->get_root()->set_snap_controls_to_pixels(snap_controls); + bool font_oversampling = GLOBAL_DEF("rendering/quality/dynamic_fonts/use_oversampling", false); + sml->set_use_font_oversampling(font_oversampling); + } else { GLOBAL_DEF("display/window/stretch/mode", "disabled"); ProjectSettings::get_singleton()->set_custom_property_info("display/window/stretch/mode", PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,2d,viewport")); @@ -1458,6 +1461,7 @@ bool Main::start() { sml->set_auto_accept_quit(GLOBAL_DEF("application/config/auto_accept_quit", true)); sml->set_quit_on_go_back(GLOBAL_DEF("application/config/quit_on_go_back", true)); GLOBAL_DEF("gui/common/snap_controls_to_pixels", true); + GLOBAL_DEF("rendering/quality/dynamic_fonts/use_oversampling", false); } String local_game_path; @@ -1867,6 +1871,7 @@ void Main::cleanup() { if (engine) memdelete(engine); + message_queue->flush(); memdelete(message_queue); unregister_core_driver_types(); diff --git a/methods.py b/methods.py index e861303e63..f9da6c8dd5 100644 --- a/methods.py +++ b/methods.py @@ -1755,16 +1755,16 @@ def precious_program(env, program, sources, **args): return program def add_shared_library(env, name, sources, **args): - library = env.SharedLibrary(name, sources, **args) - env.NoCache(library) - return library + library = env.SharedLibrary(name, sources, **args) + env.NoCache(library) + return library def add_library(env, name, sources, **args): - library = env.Library(name, sources, **args) - env.NoCache(library) - return library + library = env.Library(name, sources, **args) + env.NoCache(library) + return library def add_program(env, name, sources, **args): - program = env.Program(name, sources, **args) - env.NoCache(program) - return program + program = env.Program(name, sources, **args) + env.NoCache(program) + return program diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index fd11c8d094..4e73ebfb9d 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -3,12 +3,12 @@ Import('env') gdn_env = env.Clone() - -gdn_env.add_source_files(env.modules_sources, "gd_native_library_editor.cpp") gdn_env.add_source_files(env.modules_sources, "gdnative.cpp") gdn_env.add_source_files(env.modules_sources, "register_types.cpp") gdn_env.add_source_files(env.modules_sources, "gdnative/*.cpp") gdn_env.add_source_files(env.modules_sources, "nativescript/*.cpp") +gdn_env.add_source_files(env.modules_sources, "gdnative_library_singleton_editor.cpp") +gdn_env.add_source_files(env.modules_sources, "gdnative_library_editor_plugin.cpp") gdn_env.Append(CPPPATH=['#modules/gdnative/include/']) diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp new file mode 100644 index 0000000000..1e638ab702 --- /dev/null +++ b/modules/gdnative/gdnative_library_editor_plugin.cpp @@ -0,0 +1,423 @@ +/*************************************************************************/ +/* gdnative_library_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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. */ +/*************************************************************************/ + +#ifdef TOOLS_ENABLED +#include "gdnative_library_editor_plugin.h" +#include "gdnative.h" + +void GDNativeLibraryEditor::edit(Ref<GDNativeLibrary> p_library) { + library = p_library; + Ref<ConfigFile> config = p_library->get_config_file(); + + for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { + for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) { + + String target = E->key() + "." + it->get(); + TargetConfig ecfg; + ecfg.library = config->get_value("entry", target, ""); + ecfg.dependencies = config->get_value("dependencies", target, Array()); + entry_configs[target] = ecfg; + } + } + + _update_tree(); +} + +void GDNativeLibraryEditor::_bind_methods() { + + ClassDB::bind_method("_on_item_button", &GDNativeLibraryEditor::_on_item_button); + ClassDB::bind_method("_on_library_selected", &GDNativeLibraryEditor::_on_library_selected); + ClassDB::bind_method("_on_dependencies_selected", &GDNativeLibraryEditor::_on_dependencies_selected); + ClassDB::bind_method("_on_filter_selected", &GDNativeLibraryEditor::_on_filter_selected); + ClassDB::bind_method("_on_item_collapsed", &GDNativeLibraryEditor::_on_item_collapsed); + ClassDB::bind_method("_on_item_activated", &GDNativeLibraryEditor::_on_item_activated); + ClassDB::bind_method("_on_create_new_entry", &GDNativeLibraryEditor::_on_create_new_entry); +} + +void GDNativeLibraryEditor::_update_tree() { + + tree->clear(); + TreeItem *root = tree->create_item(); + + for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { + + if (showing_platform != E->key() && showing_platform != "All") + continue; + + TreeItem *platform = tree->create_item(root); + platform->set_text(0, E->get().name); + platform->set_metadata(0, E->get().library_extension); + + platform->set_custom_bg_color(0, get_color("prop_category", "Editor")); + platform->set_custom_bg_color(1, get_color("prop_category", "Editor")); + platform->set_custom_bg_color(2, get_color("prop_category", "Editor")); + platform->set_selectable(0, false); + platform->set_expand_right(0, true); + + for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) { + + String target = E->key() + "." + it->get(); + TreeItem *bit = tree->create_item(platform); + + bit->set_text(0, it->get()); + bit->set_metadata(0, target); + bit->set_selectable(0, false); + bit->set_custom_bg_color(0, get_color("prop_subsection", "Editor")); + + bit->add_button(1, get_icon("Folder", "EditorIcons"), BUTTON_SELECT_LIBRARY, false, TTR("Select the dynamic library for this entry")); + String file = entry_configs[target].library; + if (!file.empty()) { + bit->add_button(1, get_icon("Clear", "EditorIcons"), BUTTON_CLEAR_LIBRARY, false, TTR("Clear")); + } + bit->set_text(1, file); + + bit->add_button(2, get_icon("Folder", "EditorIcons"), BUTTON_SELECT_DEPENDENCES, false, TTR("Select dependencies of the library for this entry")); + Array files = entry_configs[target].dependencies; + if (files.size()) { + bit->add_button(2, get_icon("Clear", "EditorIcons"), BUTTON_CLEAR_DEPENDENCES, false, TTR("Clear")); + } + bit->set_text(2, Variant(files)); + + bit->add_button(3, get_icon("MoveUp", "EditorIcons"), BUTTON_MOVE_UP, false, TTR("Move Up")); + bit->add_button(3, get_icon("MoveDown", "EditorIcons"), BUTTON_MOVE_DOWN, false, TTR("Move Down")); + bit->add_button(3, get_icon("Remove", "EditorIcons"), BUTTON_ERASE_ENTRY, false, TTR("Remove current entry")); + } + + TreeItem *new_arch = tree->create_item(platform); + new_arch->set_text(0, TTR("Double click to create a new entry")); + new_arch->set_text_align(0, TreeItem::ALIGN_CENTER); + new_arch->set_custom_color(0, get_color("accent_color", "Editor")); + new_arch->set_expand_right(0, true); + new_arch->set_metadata(1, E->key()); + + platform->set_collapsed(collapsed_items.find(E->get().name) != NULL); + } +} + +void GDNativeLibraryEditor::_on_item_button(Object *item, int column, int id) { + + String target = Object::cast_to<TreeItem>(item)->get_metadata(0); + String platform = target.substr(0, target.find(".")); + String entry = target.substr(platform.length() + 1, target.length()); + String section = (id == BUTTON_SELECT_DEPENDENCES || id == BUTTON_CLEAR_DEPENDENCES) ? "dependencies" : "entry"; + + if (id == BUTTON_SELECT_LIBRARY || id == BUTTON_SELECT_DEPENDENCES) { + + EditorFileDialog::Mode mode = EditorFileDialog::MODE_OPEN_FILE; + if (id == BUTTON_SELECT_DEPENDENCES) + mode = EditorFileDialog::MODE_OPEN_FILES; + + file_dialog->set_meta("target", target); + file_dialog->set_meta("section", section); + file_dialog->clear_filters(); + file_dialog->add_filter(Object::cast_to<TreeItem>(item)->get_parent()->get_metadata(0)); + file_dialog->set_mode(mode); + file_dialog->popup_centered_ratio(); + + } else if (id == BUTTON_CLEAR_LIBRARY) { + _set_target_value(section, target, ""); + } else if (id == BUTTON_CLEAR_DEPENDENCES) { + _set_target_value(section, target, Array()); + } else if (id == BUTTON_ERASE_ENTRY) { + _erase_entry(platform, entry); + } else if (id == BUTTON_MOVE_UP || id == BUTTON_MOVE_DOWN) { + _move_entry(platform, entry, id); + } +} + +void GDNativeLibraryEditor::_on_library_selected(const String &file) { + + _set_target_value(file_dialog->get_meta("section"), file_dialog->get_meta("target"), file); +} + +void GDNativeLibraryEditor::_on_dependencies_selected(const PoolStringArray &files) { + + _set_target_value(file_dialog->get_meta("section"), file_dialog->get_meta("target"), files); +} + +void GDNativeLibraryEditor::_on_filter_selected(int id) { + + showing_platform = filter->get_item_metadata(id); + _update_tree(); +} + +void GDNativeLibraryEditor::_on_item_collapsed(Object *p_item) { + + TreeItem *item = Object::cast_to<TreeItem>(p_item); + String name = item->get_text(0); + + if (item->is_collapsed()) { + collapsed_items.insert(name); + } else if (Set<String>::Element *e = collapsed_items.find(name)) { + collapsed_items.erase(e); + } +} + +void GDNativeLibraryEditor::_on_item_activated() { + + TreeItem *item = tree->get_selected(); + if (item && tree->get_selected_column() == 0 && item->get_metadata(0).get_type() == Variant::NIL) { + new_architecture_dialog->set_meta("platform", item->get_metadata(1)); + new_architecture_dialog->popup_centered(); + } +} + +void GDNativeLibraryEditor::_on_create_new_entry() { + + String platform = new_architecture_dialog->get_meta("platform"); + String entry = new_architecture_input->get_text().strip_edges(); + if (!entry.empty()) { + platforms[platform].entries.push_back(entry); + _update_tree(); + } +} + +void GDNativeLibraryEditor::_set_target_value(const String §ion, const String &target, Variant file) { + if (section == "entry") + entry_configs[target].library = file; + else if (section == "dependencies") + entry_configs[target].dependencies = file; + _translate_to_config_file(); + _update_tree(); +} + +void GDNativeLibraryEditor::_erase_entry(const String &platform, const String &entry) { + + if (platforms.has(platform)) { + if (List<String>::Element *E = platforms[platform].entries.find(entry)) { + + String target = platform + "." + entry; + Ref<ConfigFile> config = library->get_config_file(); + + platforms[platform].entries.erase(E); + _set_target_value("entry", target, ""); + _set_target_value("dependencies", target, Array()); + _translate_to_config_file(); + _update_tree(); + } + } +} + +void GDNativeLibraryEditor::_move_entry(const String &platform, const String &entry, int dir) { + if (List<String>::Element *E = platforms[platform].entries.find(entry)) { + if (E->prev() && dir == BUTTON_MOVE_UP) { + platforms[platform].entries.insert_before(E->prev(), E->get()); + platforms[platform].entries.erase(E); + } else if (E->next() && dir == BUTTON_MOVE_DOWN) { + platforms[platform].entries.insert_after(E->next(), E->get()); + platforms[platform].entries.erase(E); + } + _translate_to_config_file(); + _update_tree(); + } +} + +void GDNativeLibraryEditor::_translate_to_config_file() { + + if (!library.is_null()) { + + Ref<ConfigFile> config = library->get_config_file(); + config->erase_section("entry"); + config->erase_section("dependencies"); + + for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { + for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) { + + String target = E->key() + "." + it->get(); + if (entry_configs[target].library.empty() && entry_configs[target].dependencies.empty()) + continue; + + config->set_value("entry", target, entry_configs[target].library); + config->set_value("dependencies", target, entry_configs[target].dependencies); + } + } + + library->_change_notify(); + } +} + +GDNativeLibraryEditor::GDNativeLibraryEditor() { + + showing_platform = "All"; + + { // Define platforms + NativePlatformConfig platform_windows; + platform_windows.name = "Windows"; + platform_windows.entries.push_back("64"); + platform_windows.entries.push_back("32"); + platform_windows.library_extension = "*.dll"; + platforms["Windows"] = platform_windows; + + NativePlatformConfig platform_linux; + platform_linux.name = "Linux/X11"; + platform_linux.entries.push_back("64"); + platform_linux.entries.push_back("32"); + platform_linux.library_extension = "*.so"; + platforms["X11"] = platform_linux; + + NativePlatformConfig platform_osx; + platform_osx.name = "Mac OSX"; + platform_osx.entries.push_back("64"); + platform_osx.entries.push_back("32"); + platform_osx.library_extension = "*.dylib"; + platforms["OSX"] = platform_osx; + + NativePlatformConfig platform_haiku; + platform_haiku.name = "Haiku"; + platform_haiku.entries.push_back("64"); + platform_haiku.entries.push_back("32"); + platform_haiku.library_extension = "*.so"; + platforms["Haiku"] = platform_haiku; + + NativePlatformConfig platform_uwp; + platform_uwp.name = "Windows Universal"; + platform_uwp.entries.push_back("arm"); + platform_uwp.entries.push_back("x86"); + platform_uwp.entries.push_back("x64"); + platform_uwp.library_extension = "*.dll"; + platforms["UWP"] = platform_uwp; + + NativePlatformConfig platform_android; + platform_android.name = "Android"; + platform_android.entries.push_back("armeabi-v7a"); + platform_android.entries.push_back("arm64-v8a"); + platform_android.entries.push_back("x86"); + platform_android.entries.push_back("x86_64"); + platform_android.library_extension = "*.so"; + platforms["Android"] = platform_android; + + // TODO: Javascript platform is not supported yet + // NativePlatformConfig platform_html5; + // platform_html5.name = "HTML5"; + // platform_html5.library_extension = "*.wasm"; + // platforms["Javascript"] = platform_html5; + + NativePlatformConfig platform_ios; + platform_ios.name = "iOS"; + platform_ios.entries.push_back("armv7"); + platform_ios.entries.push_back("arm64"); + platform_ios.library_extension = "*.dylib"; + platforms["iOS"] = platform_ios; + } + + VBoxContainer *container = memnew(VBoxContainer); + add_child(container); + container->set_anchors_and_margins_preset(PRESET_WIDE); + + HBoxContainer *hbox = memnew(HBoxContainer); + container->add_child(hbox); + Label *label = memnew(Label); + label->set_text(TTR("Platform:")); + hbox->add_child(label); + filter = memnew(OptionButton); + hbox->add_child(filter); + filter->set_h_size_flags(SIZE_EXPAND_FILL); + + int idx = 0; + filter->add_item(TTR("All"), idx); + filter->set_item_metadata(idx, "All"); + idx += 1; + for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { + filter->add_item(E->get().name, idx); + filter->set_item_metadata(idx, E->key()); + idx += 1; + } + filter->connect("item_selected", this, "_on_filter_selected"); + + tree = memnew(Tree); + container->add_child(tree); + tree->set_v_size_flags(SIZE_EXPAND_FILL); + tree->set_hide_root(true); + tree->set_column_titles_visible(true); + tree->set_columns(4); + tree->set_column_expand(0, false); + tree->set_column_min_width(0, int(200 * EDSCALE)); + tree->set_column_title(0, TTR("Platform")); + tree->set_column_title(1, TTR("Dynamic Library")); + tree->set_column_title(2, TTR("Dependencies")); + tree->set_column_expand(3, false); + tree->set_column_min_width(3, int(110 * EDSCALE)); + tree->connect("button_pressed", this, "_on_item_button"); + tree->connect("item_collapsed", this, "_on_item_collapsed"); + tree->connect("item_activated", this, "_on_item_activated"); + + file_dialog = memnew(EditorFileDialog); + file_dialog->set_access(EditorFileDialog::ACCESS_RESOURCES); + file_dialog->set_resizable(true); + add_child(file_dialog); + file_dialog->connect("file_selected", this, "_on_library_selected"); + file_dialog->connect("files_selected", this, "_on_dependencies_selected"); + + new_architecture_dialog = memnew(ConfirmationDialog); + add_child(new_architecture_dialog); + new_architecture_dialog->set_title(TTR("Add an architecture entry")); + new_architecture_input = memnew(LineEdit); + new_architecture_dialog->add_child(new_architecture_input); + new_architecture_dialog->set_custom_minimum_size(Vector2(300, 80) * EDSCALE); + new_architecture_input->set_anchors_and_margins_preset(PRESET_HCENTER_WIDE, PRESET_MODE_MINSIZE, 5 * EDSCALE); + new_architecture_dialog->get_ok()->connect("pressed", this, "_on_create_new_entry"); +} + +void GDNativeLibraryEditorPlugin::edit(Object *p_node) { + + if (Object::cast_to<GDNativeLibrary>(p_node)) { + library_editor->edit(Object::cast_to<GDNativeLibrary>(p_node)); + library_editor->show(); + } else + library_editor->hide(); +} + +bool GDNativeLibraryEditorPlugin::handles(Object *p_node) const { + + return p_node->is_class("GDNativeLibrary"); +} + +void GDNativeLibraryEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + button->show(); + EditorNode::get_singleton()->make_bottom_panel_item_visible(library_editor); + + } else { + if (library_editor->is_visible_in_tree()) + EditorNode::get_singleton()->hide_bottom_panel(); + button->hide(); + } +} + +GDNativeLibraryEditorPlugin::GDNativeLibraryEditorPlugin(EditorNode *p_node) { + + library_editor = memnew(GDNativeLibraryEditor); + library_editor->set_custom_minimum_size(Size2(0, 250 * EDSCALE)); + button = p_node->add_bottom_panel_item(TTR("GDNativeLibrary"), library_editor); + button->hide(); +} + +#endif diff --git a/modules/gdnative/gdnative_library_editor_plugin.h b/modules/gdnative/gdnative_library_editor_plugin.h new file mode 100644 index 0000000000..1fa6a0c945 --- /dev/null +++ b/modules/gdnative/gdnative_library_editor_plugin.h @@ -0,0 +1,113 @@ +/*************************************************************************/ +/* gdnative_library_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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. */ +/*************************************************************************/ +#ifndef GDNATIVE_LIBRARY_EDITOR_PLUGIN_H +#define GDNATIVE_LIBRARY_EDITOR_PLUGIN_H + +#ifdef TOOLS_ENABLED +#include "editor/editor_node.h" +#include "gdnative.h" + +class GDNativeLibraryEditor : public Control { + + GDCLASS(GDNativeLibraryEditor, Control); + + struct NativePlatformConfig { + String name; + String library_extension; + List<String> entries; + }; + + struct TargetConfig { + String library; + Array dependencies; + }; + + enum ItemButton { + BUTTON_SELECT_LIBRARY, + BUTTON_CLEAR_LIBRARY, + BUTTON_SELECT_DEPENDENCES, + BUTTON_CLEAR_DEPENDENCES, + BUTTON_ERASE_ENTRY, + BUTTON_MOVE_UP, + BUTTON_MOVE_DOWN, + }; + + Tree *tree; + OptionButton *filter; + EditorFileDialog *file_dialog; + ConfirmationDialog *new_architecture_dialog; + LineEdit *new_architecture_input; + Set<String> collapsed_items; + + String showing_platform; + Ref<GDNativeLibrary> library; + Map<String, NativePlatformConfig> platforms; + Map<String, TargetConfig> entry_configs; + +protected: + static void _bind_methods(); + void _update_tree(); + void _on_item_button(Object *item, int column, int id); + void _on_library_selected(const String &file); + void _on_dependencies_selected(const PoolStringArray &files); + void _on_filter_selected(int id); + void _on_item_collapsed(Object *item); + void _on_item_activated(); + void _on_create_new_entry(); + void _set_target_value(const String §ion, const String &target, Variant file); + void _erase_entry(const String &platform, const String &entry); + void _move_entry(const String &platform, const String &entry, int dir); + void _translate_to_config_file(); + +public: + void edit(Ref<GDNativeLibrary> p_library); + + GDNativeLibraryEditor(); +}; + +class GDNativeLibraryEditorPlugin : public EditorPlugin { + + GDCLASS(GDNativeLibraryEditorPlugin, EditorPlugin); + + GDNativeLibraryEditor *library_editor; + EditorNode *editor; + Button *button; + +public: + virtual String get_name() const { return "GDNativeLibrary"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); + + GDNativeLibraryEditorPlugin(EditorNode *p_node); +}; +#endif +#endif // GDNATIVE_LIBRARY_EDITOR_PLUGIN_H diff --git a/modules/gdnative/gd_native_library_editor.cpp b/modules/gdnative/gdnative_library_singleton_editor.cpp index fda5dcdcad..2ad497fcad 100644 --- a/modules/gdnative/gd_native_library_editor.cpp +++ b/modules/gdnative/gdnative_library_singleton_editor.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_native_library_editor.cpp */ +/* gdnative_library_singleton_editor.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #ifdef TOOLS_ENABLED -#include "gd_native_library_editor.h" - +#include "gdnative_library_singleton_editor.h" #include "gdnative.h" -void GDNativeLibraryEditor::_find_gdnative_singletons(EditorFileSystemDirectory *p_dir, const Set<String> &enabled_list) { +void GDNativeLibrarySingletonEditor::_find_gdnative_singletons(EditorFileSystemDirectory *p_dir, const Set<String> &enabled_list) { // check children @@ -65,7 +64,7 @@ void GDNativeLibraryEditor::_find_gdnative_singletons(EditorFileSystemDirectory } } -void GDNativeLibraryEditor::_update_libraries() { +void GDNativeLibrarySingletonEditor::_update_libraries() { updating = true; libraries->clear(); @@ -88,7 +87,7 @@ void GDNativeLibraryEditor::_update_libraries() { updating = false; } -void GDNativeLibraryEditor::_item_edited() { +void GDNativeLibrarySingletonEditor::_item_edited() { if (updating) return; @@ -119,7 +118,7 @@ void GDNativeLibraryEditor::_item_edited() { } } -void GDNativeLibraryEditor::_notification(int p_what) { +void GDNativeLibrarySingletonEditor::_notification(int p_what) { if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { if (is_visible_in_tree()) { @@ -128,12 +127,12 @@ void GDNativeLibraryEditor::_notification(int p_what) { } } -void GDNativeLibraryEditor::_bind_methods() { +void GDNativeLibrarySingletonEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_item_edited"), &GDNativeLibraryEditor::_item_edited); + ClassDB::bind_method(D_METHOD("_item_edited"), &GDNativeLibrarySingletonEditor::_item_edited); } -GDNativeLibraryEditor::GDNativeLibraryEditor() { +GDNativeLibrarySingletonEditor::GDNativeLibrarySingletonEditor() { libraries = memnew(Tree); libraries->set_columns(2); libraries->set_column_titles_visible(true); diff --git a/modules/gdnative/gd_native_library_editor.h b/modules/gdnative/gdnative_library_singleton_editor.h index a11c4620dd..ee1a32c5a5 100644 --- a/modules/gdnative/gd_native_library_editor.h +++ b/modules/gdnative/gdnative_library_singleton_editor.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_native_library_editor.h */ +/* gdnative_library_singleton_editor.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -34,7 +34,7 @@ #include "editor/editor_file_system.h" #include "editor/project_settings_editor.h" -class GDNativeLibraryEditor : public VBoxContainer { +class GDNativeLibrarySingletonEditor : public VBoxContainer { Tree *libraries; bool updating; @@ -48,7 +48,7 @@ protected: static void _bind_methods(); public: - GDNativeLibraryEditor(); + GDNativeLibrarySingletonEditor(); }; #endif diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 1cb35ec006..bd9bae5294 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -45,7 +45,8 @@ #ifdef TOOLS_ENABLED #include "editor/editor_node.h" -#include "gd_native_library_editor.h" +#include "gdnative_library_editor_plugin.h" +#include "gdnative_library_singleton_editor.h" // Class used to discover singleton gdnative files static void actual_discoverer_handler(); @@ -267,7 +268,7 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty static void editor_init_callback() { - GDNativeLibraryEditor *library_editor = memnew(GDNativeLibraryEditor); + GDNativeLibrarySingletonEditor *library_editor = memnew(GDNativeLibrarySingletonEditor); library_editor->set_name(TTR("GDNative")); ProjectSettingsEditor::get_singleton()->get_tabs()->add_child(library_editor); @@ -278,6 +279,8 @@ static void editor_init_callback() { export_plugin.instance(); EditorExport::get_singleton()->add_export_plugin(export_plugin); + + EditorNode::get_singleton()->add_editor_plugin(memnew(GDNativeLibraryEditorPlugin(EditorNode::get_singleton()))); } #endif diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml index 8c862b52e8..e9bb90631d 100644 --- a/modules/gridmap/doc_classes/GridMap.xml +++ b/modules/gridmap/doc_classes/GridMap.xml @@ -21,6 +21,26 @@ Clear all cells. </description> </method> + <method name="clear_baked_meshes"> + <return type="void"> + </return> + <description> + </description> + </method> + <method name="get_bake_mesh_instance"> + <return type="RID"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + </description> + </method> + <method name="get_bake_meshes"> + <return type="Array"> + </return> + <description> + </description> + </method> <method name="get_cell_item" qualifiers="const"> <return type="int"> </return> @@ -103,6 +123,16 @@ Array of [Vector3] with the non empty cell coordinates in the grid map. </description> </method> + <method name="make_baked_meshes"> + <return type="void"> + </return> + <argument index="0" name="gen_lightmap_uv" type="bool" default="false"> + </argument> + <argument index="1" name="lightmap_uv_texel_size" type="float" default="0.1"> + </argument> + <description> + </description> + </method> <method name="map_to_world" qualifiers="const"> <return type="Vector3"> </return> diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index bebf8bcf8f..0b73cbfc6d 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -101,6 +101,27 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { } } _recreate_octant_data(); + } else if (name == "baked_meshes") { + + clear_baked_meshes(); + + Array meshes = p_value; + + for (int i = 0; i < meshes.size(); i++) { + BakedMesh bm; + bm.mesh = meshes[i]; + ERR_CONTINUE(!bm.mesh.is_valid()); + bm.instance = VS::get_singleton()->instance_create(); + VS::get_singleton()->get_singleton()->instance_set_base(bm.instance, bm.mesh->get_rid()); + VS::get_singleton()->instance_attach_object_instance_id(bm.instance, get_instance_id()); + if (is_inside_tree()) { + VS::get_singleton()->instance_set_scenario(bm.instance, get_world()->get_scenario()); + VS::get_singleton()->instance_set_transform(bm.instance, get_global_transform()); + } + baked_meshes.push_back(bm); + } + + _recreate_octant_data(); } else return false; @@ -145,6 +166,15 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { d["cells"] = cells; r_ret = d; + } else if (name == "baked_meshes") { + + Array ret; + ret.resize(baked_meshes.size()); + for (int i = 0; i < baked_meshes.size(); i++) { + ret.push_back(baked_meshes[i].mesh); + } + r_ret = ret; + } else return false; @@ -161,6 +191,9 @@ void GridMap::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_y")); p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_z")); p_list->push_back(PropertyInfo(Variant::REAL, "cell_scale")); + if (baked_meshes.size()) { + p_list->push_back(PropertyInfo(Variant::ARRAY, "baked_meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); + } p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); } @@ -235,6 +268,12 @@ bool GridMap::get_center_z() const { void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { + if (baked_meshes.size() && !recreating_octants) { + //if you set a cell item, baked meshes go good bye + clear_baked_meshes(); + _recreate_octant_data(); + } + ERR_FAIL_INDEX(ABS(p_x), 1 << 20); ERR_FAIL_INDEX(ABS(p_y), 1 << 20); ERR_FAIL_INDEX(ABS(p_z), 1 << 20); @@ -436,16 +475,17 @@ bool GridMap::_octant_update(const OctantKey &p_key) { xform.basis.set_orthogonal_index(c.rot); xform.set_origin(cellpos * cell_size + ofs); xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); + if (baked_meshes.size() == 0) { + if (theme->get_item_mesh(c.item).is_valid()) { + if (!multimesh_items.has(c.item)) { + multimesh_items[c.item] = List<Pair<Transform, IndexKey> >(); + } - if (theme->get_item_mesh(c.item).is_valid()) { - if (!multimesh_items.has(c.item)) { - multimesh_items[c.item] = List<Pair<Transform, IndexKey> >(); + Pair<Transform, IndexKey> p; + p.first = xform; + p.second = E->get(); + multimesh_items[c.item].push_back(p); } - - Pair<Transform, IndexKey> p; - p.first = xform; - p.second = E->get(); - multimesh_items[c.item].push_back(p); } Vector<MeshLibrary::ShapeData> shapes = theme->get_item_shapes(c.item); @@ -477,41 +517,44 @@ bool GridMap::_octant_update(const OctantKey &p_key) { } } - //update multimeshes - for (Map<int, List<Pair<Transform, IndexKey> > >::Element *E = multimesh_items.front(); E; E = E->next()) { - Octant::MultimeshInstance mmi; + //update multimeshes, only if not baked + if (baked_meshes.size() == 0) { + + for (Map<int, List<Pair<Transform, IndexKey> > >::Element *E = multimesh_items.front(); E; E = E->next()) { + Octant::MultimeshInstance mmi; - RID mm = VS::get_singleton()->multimesh_create(); - VS::get_singleton()->multimesh_allocate(mm, E->get().size(), VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_NONE); - VS::get_singleton()->multimesh_set_mesh(mm, theme->get_item_mesh(E->key())->get_rid()); + RID mm = VS::get_singleton()->multimesh_create(); + VS::get_singleton()->multimesh_allocate(mm, E->get().size(), VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_NONE); + VS::get_singleton()->multimesh_set_mesh(mm, theme->get_item_mesh(E->key())->get_rid()); - int idx = 0; - for (List<Pair<Transform, IndexKey> >::Element *F = E->get().front(); F; F = F->next()) { - VS::get_singleton()->multimesh_instance_set_transform(mm, idx, F->get().first); + int idx = 0; + for (List<Pair<Transform, IndexKey> >::Element *F = E->get().front(); F; F = F->next()) { + VS::get_singleton()->multimesh_instance_set_transform(mm, idx, F->get().first); #ifdef TOOLS_ENABLED - Octant::MultimeshInstance::Item it; - it.index = idx; - it.transform = F->get().first; - it.key = F->get().second; - mmi.items.push_back(it); + Octant::MultimeshInstance::Item it; + it.index = idx; + it.transform = F->get().first; + it.key = F->get().second; + mmi.items.push_back(it); #endif - idx++; - } + idx++; + } - RID instance = VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_base(instance, mm); + RID instance = VS::get_singleton()->instance_create(); + VS::get_singleton()->instance_set_base(instance, mm); - if (is_inside_tree()) { - VS::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); - VS::get_singleton()->instance_set_transform(instance, get_global_transform()); - } + if (is_inside_tree()) { + VS::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); + VS::get_singleton()->instance_set_transform(instance, get_global_transform()); + } - mmi.multimesh = mm; - mmi.instance = instance; + mmi.multimesh = mm; + mmi.instance = instance; - g.multimesh_instances.push_back(mmi); + g.multimesh_instances.push_back(mmi); + } } if (col_debug.size()) { @@ -642,6 +685,11 @@ void GridMap::_notification(int p_what) { _octant_enter_world(E->key()); } + for (int i = 0; i < baked_meshes.size(); i++) { + VS::get_singleton()->instance_set_scenario(baked_meshes[i].instance, get_world()->get_scenario()); + VS::get_singleton()->instance_set_transform(baked_meshes[i].instance, get_global_transform()); + } + } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -655,6 +703,10 @@ void GridMap::_notification(int p_what) { last_transform = new_xform; + for (int i = 0; i < baked_meshes.size(); i++) { + VS::get_singleton()->instance_set_transform(baked_meshes[i].instance, get_global_transform()); + } + } break; case NOTIFICATION_EXIT_WORLD: { @@ -667,6 +719,9 @@ void GridMap::_notification(int p_what) { //_queue_octants_dirty(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS); //_update_octants_callback(); //_update_area_instances(); + for (int i = 0; i < baked_meshes.size(); i++) { + VS::get_singleton()->instance_set_scenario(baked_meshes[i].instance, RID()); + } } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -701,12 +756,14 @@ void GridMap::_queue_octants_dirty() { void GridMap::_recreate_octant_data() { + recreating_octants = true; Map<IndexKey, Cell> cell_copy = cell_map; _clear_internal(); for (Map<IndexKey, Cell>::Element *E = cell_copy.front(); E; E = E->next()) { set_cell_item(E->key().x, E->key().y, E->key().z, E->get().item, E->get().rot); } + recreating_octants = false; } void GridMap::_clear_internal() { @@ -726,6 +783,7 @@ void GridMap::_clear_internal() { void GridMap::clear() { _clear_internal(); + clear_baked_meshes(); } void GridMap::resource_changed(const RES &p_res) { @@ -791,6 +849,11 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("get_used_cells"), &GridMap::get_used_cells); ClassDB::bind_method(D_METHOD("get_meshes"), &GridMap::get_meshes); + ClassDB::bind_method(D_METHOD("get_bake_meshes"), &GridMap::get_bake_meshes); + ClassDB::bind_method(D_METHOD("get_bake_mesh_instance", "idx"), &GridMap::get_bake_mesh_instance); + + ClassDB::bind_method(D_METHOD("clear_baked_meshes"), &GridMap::clear_baked_meshes); + ClassDB::bind_method(D_METHOD("make_baked_meshes", "gen_lightmap_uv", "lightmap_uv_texel_size"), &GridMap::make_baked_meshes, DEFVAL(false), DEFVAL(0.1)); BIND_CONSTANT(INVALID_CELL_ITEM); } @@ -883,10 +946,129 @@ Vector3 GridMap::_get_offset() const { cell_size.z * 0.5 * int(center_z)); } +void GridMap::clear_baked_meshes() { + + for (int i = 0; i < baked_meshes.size(); i++) { + VS::get_singleton()->free(baked_meshes[i].instance); + } + baked_meshes.clear(); + + _recreate_octant_data(); +} + +void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel_size) { + + if (!theme.is_valid()) + return; + + //generate + Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool> > > surface_map; + + for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { + + IndexKey key = E->key(); + + int item = E->get().item; + if (!theme->has_item(item)) + continue; + + Ref<Mesh> mesh = theme->get_item_mesh(item); + if (!mesh.is_valid()) + continue; + + Vector3 cellpos = Vector3(key.x, key.y, key.z); + Vector3 ofs = _get_offset(); + + Transform xform; + + xform.basis.set_orthogonal_index(E->get().rot); + xform.set_origin(cellpos * cell_size + ofs); + xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); + + OctantKey ok; + ok.x = key.x / octant_size; + ok.y = key.y / octant_size; + ok.z = key.z / octant_size; + + if (!surface_map.has(ok)) { + surface_map[ok] = Map<Ref<Material>, Ref<SurfaceTool> >(); + } + + Map<Ref<Material>, Ref<SurfaceTool> > &mat_map = surface_map[ok]; + + for (int i = 0; i < mesh->get_surface_count(); i++) { + + if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) + continue; + + Ref<Material> surf_mat = mesh->surface_get_material(i); + if (!mat_map.has(surf_mat)) { + Ref<SurfaceTool> st; + st.instance(); + st->begin(Mesh::PRIMITIVE_TRIANGLES); + st->set_material(surf_mat); + mat_map[surf_mat] = st; + } + + mat_map[surf_mat]->append_from(mesh, i, xform); + } + } + + int ofs = 0; + + for (Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool> > >::Element *E = surface_map.front(); E; E = E->next()) { + + print_line("generating mesh " + itos(ofs++) + "/" + itos(surface_map.size())); + Ref<ArrayMesh> mesh; + mesh.instance(); + for (Map<Ref<Material>, Ref<SurfaceTool> >::Element *F = E->get().front(); F; F = F->next()) { + F->get()->commit(mesh); + } + + BakedMesh bm; + bm.mesh = mesh; + bm.instance = VS::get_singleton()->instance_create(); + VS::get_singleton()->get_singleton()->instance_set_base(bm.instance, bm.mesh->get_rid()); + VS::get_singleton()->instance_attach_object_instance_id(bm.instance, get_instance_id()); + if (is_inside_tree()) { + VS::get_singleton()->instance_set_scenario(bm.instance, get_world()->get_scenario()); + VS::get_singleton()->instance_set_transform(bm.instance, get_global_transform()); + } + + if (p_gen_lightmap_uv) { + mesh->lightmap_unwrap(get_global_transform(), p_lightmap_uv_texel_size); + } + baked_meshes.push_back(bm); + } + + _recreate_octant_data(); +} + +Array GridMap::get_bake_meshes() { + + if (!baked_meshes.size()) { + make_baked_meshes(true); + } + + Array arr; + for (int i = 0; i < baked_meshes.size(); i++) { + arr.push_back(baked_meshes[i].mesh); + arr.push_back(Transform()); + } + + return arr; +} + +RID GridMap::get_bake_mesh_instance(int p_idx) { + + ERR_FAIL_INDEX_V(p_idx, baked_meshes.size(), RID()); + return baked_meshes[p_idx].instance; +} + GridMap::GridMap() { cell_size = Vector3(2, 2, 2); - octant_size = 4; + octant_size = 8; awaiting_update = false; _in_tree = false; center_x = true; @@ -901,6 +1083,7 @@ GridMap::GridMap() { navigation = NULL; set_notify_transform(true); + recreating_octants = false; } GridMap::~GridMap() { diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index ab66bf123e..241ac7a434 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -148,6 +148,9 @@ class GridMap : public Spatial { bool clip; bool clip_above; int clip_floor; + + bool recreating_octants; + Vector3::Axis clip_axis; Ref<MeshLibrary> theme; @@ -188,9 +191,11 @@ class GridMap : public Spatial { struct BakedMesh { Ref<Mesh> mesh; - Transform transform; + RID instance; }; + Vector<BakedMesh> baked_meshes; + protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -237,8 +242,14 @@ public: Array get_meshes(); + void clear_baked_meshes(); + void make_baked_meshes(bool p_gen_lightmap_uv = false, float p_lightmap_uv_texel_size = 0.1); + void clear(); + Array get_bake_meshes(); + RID get_bake_mesh_instance(int p_idx); + GridMap(); ~GridMap(); }; diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp index e473348897..e8aea8624d 100644 --- a/modules/mono/mono_gd/gd_mono_log.cpp +++ b/modules/mono/mono_gd/gd_mono_log.cpp @@ -70,7 +70,9 @@ void gdmono_MonoLogCallback(const char *log_domain, const char *log_level, const } if (fatal) { - ERR_PRINTS("Mono: FALTAL ERROR, ABORTING! Logfile: " + GDMonoLog::get_singleton()->get_log_file_path() + "\n"); + ERR_PRINTS("Mono: FATAL ERROR, ABORTING! Logfile: " + GDMonoLog::get_singleton()->get_log_file_path() + "\n"); + // If we were to abort without flushing, the log wouldn't get written. + f->flush(); abort(); } } diff --git a/modules/thekla_unwrap/register_types.cpp b/modules/thekla_unwrap/register_types.cpp index ab3203068f..da6c1bab2a 100644 --- a/modules/thekla_unwrap/register_types.cpp +++ b/modules/thekla_unwrap/register_types.cpp @@ -65,7 +65,7 @@ bool thekla_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver Thekla::atlas_set_default_options(&options); options.packer_options.witness.packing_quality = 1; options.packer_options.witness.texel_area = 1.0 / p_texel_size; - options.packer_options.witness.conservative = true; + options.packer_options.witness.conservative = false; //generate Thekla::Atlas_Error err; diff --git a/platform/android/godot_android.cpp b/platform/android/godot_android.cpp index f9bcbadc24..8c4a4726ae 100644 --- a/platform/android/godot_android.cpp +++ b/platform/android/godot_android.cpp @@ -927,7 +927,6 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerMethod(JNIEnv *e int stringCount = env->GetArrayLength(args); - print_line("Singl: " + singname + " Method: " + mname + " RetVal: " + retval); for (int i = 0; i < stringCount; i++) { jstring string = (jstring)env->GetObjectArrayElement(args, i); @@ -939,7 +938,6 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerMethod(JNIEnv *e cs += ")"; cs += get_jni_sig(retval); jclass cls = env->GetObjectClass(s->get_instance()); - print_line("METHOD: " + mname + " sig: " + cs); jmethodID mid = env->GetMethodID(cls, mname.ascii().get_data(), cs.ascii().get_data()); if (!mid) { diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp index c4d0cf5181..1e28ef4c6a 100644 --- a/platform/android/java_glue.cpp +++ b/platform/android/java_glue.cpp @@ -241,7 +241,6 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { String name = _get_class_name(env, c, &array); //print_line("name is " + name + ", array "+Variant(array)); - print_line("ARGNAME: " + name); if (name == "java.lang.String") { return String::utf8(env->GetStringUTFChars((jstring)obj, NULL)); @@ -1513,7 +1512,6 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_method(JNIEnv *env, j int stringCount = env->GetArrayLength(args); - print_line("Singl: " + singname + " Method: " + mname + " RetVal: " + retval); for (int i = 0; i < stringCount; i++) { jstring string = (jstring)env->GetObjectArrayElement(args, i); @@ -1525,7 +1523,6 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_method(JNIEnv *env, j cs += ")"; cs += get_jni_sig(retval); jclass cls = env->GetObjectClass(s->get_instance()); - print_line("METHOD: " + mname + " sig: " + cs); jmethodID mid = env->GetMethodID(cls, mname.ascii().get_data(), cs.ascii().get_data()); if (!mid) { diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index 7afac94e71..754dcd9a6c 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -55,12 +55,13 @@ float BakedLightmapData::get_energy() const { return energy; } -void BakedLightmapData::add_user(const NodePath &p_path, const Ref<Texture> &p_lightmap) { +void BakedLightmapData::add_user(const NodePath &p_path, const Ref<Texture> &p_lightmap, int p_instance) { ERR_FAIL_COND(p_lightmap.is_null()); User user; user.path = p_path; user.lightmap = p_lightmap; + user.instance_index = p_instance; users.push_back(user); } @@ -79,16 +80,22 @@ Ref<Texture> BakedLightmapData::get_user_lightmap(int p_user) const { return users[p_user].lightmap; } +int BakedLightmapData::get_user_instance(int p_user) const { + + ERR_FAIL_INDEX_V(p_user, users.size(), -1); + return users[p_user].instance_index; +} + void BakedLightmapData::clear_users() { users.clear(); } void BakedLightmapData::_set_user_data(const Array &p_data) { - ERR_FAIL_COND(p_data.size() & 1); + ERR_FAIL_COND((p_data.size() % 3) != 0); - for (int i = 0; i < p_data.size(); i += 2) { - add_user(p_data[i], p_data[i + 1]); + for (int i = 0; i < p_data.size(); i += 3) { + add_user(p_data[i], p_data[i + 1], p_data[i + 2]); } } @@ -98,6 +105,7 @@ Array BakedLightmapData::_get_user_data() const { for (int i = 0; i < users.size(); i++) { ret.push_back(users[i].path); ret.push_back(users[i].lightmap); + ret.push_back(users[i].instance_index); } return ret; } @@ -125,7 +133,7 @@ void BakedLightmapData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_energy", "energy"), &BakedLightmapData::set_energy); ClassDB::bind_method(D_METHOD("get_energy"), &BakedLightmapData::get_energy); - ClassDB::bind_method(D_METHOD("add_user", "path", "lightmap"), &BakedLightmapData::add_user); + ClassDB::bind_method(D_METHOD("add_user", "path", "lightmap", "instance"), &BakedLightmapData::add_user); ClassDB::bind_method(D_METHOD("get_user_count"), &BakedLightmapData::get_user_count); ClassDB::bind_method(D_METHOD("get_user_path", "user_idx"), &BakedLightmapData::get_user_path); ClassDB::bind_method(D_METHOD("get_user_lightmap", "user_idx"), &BakedLightmapData::get_user_lightmap); @@ -209,6 +217,7 @@ void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, List<PlotMesh> &plo pm.local_xform = xf; pm.mesh = mesh; pm.path = get_path_to(mi); + pm.instance_idx = -1; for (int i = 0; i < mesh->get_surface_count(); i++) { pm.instance_materials.push_back(mi->get_surface_material(i)); } @@ -219,6 +228,26 @@ void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, List<PlotMesh> &plo } } + Spatial *s = Object::cast_to<Spatial>(p_at_node); + + if (!mi && s) { + Array meshes = p_at_node->call("get_bake_meshes"); + if (meshes.size() && (meshes.size() & 1) == 0) { + Transform xf = get_global_transform().affine_inverse() * s->get_global_transform(); + for (int i = 0; i < meshes.size(); i += 2) { + PlotMesh pm; + Transform mesh_xf = meshes[i + 1]; + pm.local_xform = xf * mesh_xf; + pm.mesh = meshes[i]; + pm.instance_idx = i / 2; + if (!pm.mesh.is_valid()) + continue; + pm.path = get_path_to(s); + plot_meshes.push_back(pm); + } + } + } + Light *light = Object::cast_to<Light>(p_at_node); if (light && light->get_bake_mode() != Light::BAKE_DISABLED) { @@ -477,7 +506,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_vi if (set_path) { tex->set_path(image_path); } - new_light_data->add_user(E->get().path, tex); + new_light_data->add_user(E->get().path, tex, E->get().instance_idx); } } @@ -547,12 +576,21 @@ void BakedLightmap::_assign_lightmaps() { ERR_FAIL_COND(!light_data.is_valid()); for (int i = 0; i < light_data->get_user_count(); i++) { - Node *node = get_node(light_data->get_user_path(i)); - VisualInstance *vi = Object::cast_to<VisualInstance>(node); - ERR_CONTINUE(!vi); Ref<Texture> lightmap = light_data->get_user_lightmap(i); ERR_CONTINUE(!lightmap.is_valid()); - VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid()); + + Node *node = get_node(light_data->get_user_path(i)); + int instance_idx = light_data->get_user_instance(i); + if (instance_idx >= 0) { + RID instance = node->call("get_bake_mesh_instance", instance_idx); + if (instance.is_valid()) { + VS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), lightmap->get_rid()); + } + } else { + VisualInstance *vi = Object::cast_to<VisualInstance>(node); + ERR_CONTINUE(!vi); + VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid()); + } } } @@ -560,9 +598,17 @@ void BakedLightmap::_clear_lightmaps() { ERR_FAIL_COND(!light_data.is_valid()); for (int i = 0; i < light_data->get_user_count(); i++) { Node *node = get_node(light_data->get_user_path(i)); - VisualInstance *vi = Object::cast_to<VisualInstance>(node); - ERR_CONTINUE(!vi); - VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), RID(), RID()); + int instance_idx = light_data->get_user_instance(i); + if (instance_idx >= 0) { + RID instance = node->call("get_bake_mesh_instance", instance_idx); + if (instance.is_valid()) { + VS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), RID()); + } + } else { + VisualInstance *vi = Object::cast_to<VisualInstance>(node); + ERR_CONTINUE(!vi); + VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), RID()); + } } } diff --git a/scene/3d/baked_lightmap.h b/scene/3d/baked_lightmap.h index f63749a0b4..9e15f1bb10 100644 --- a/scene/3d/baked_lightmap.h +++ b/scene/3d/baked_lightmap.h @@ -18,6 +18,7 @@ class BakedLightmapData : public Resource { NodePath path; Ref<Texture> lightmap; + int instance_index; }; Vector<User> users; @@ -44,10 +45,11 @@ public: void set_energy(float p_energy); float get_energy() const; - void add_user(const NodePath &p_path, const Ref<Texture> &p_lightmap); + void add_user(const NodePath &p_path, const Ref<Texture> &p_lightmap, int p_instance = -1); int get_user_count() const; NodePath get_user_path(int p_user) const; Ref<Texture> get_user_lightmap(int p_user) const; + int get_user_instance(int p_user) const; void clear_users(); virtual RID get_rid() const; @@ -111,6 +113,7 @@ private: Ref<Mesh> mesh; Transform local_xform; NodePath path; + int instance_idx; }; struct PlotLight { diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp index 39ff6fa35e..4c52d0bb1b 100644 --- a/scene/3d/voxel_light_baker.cpp +++ b/scene/3d/voxel_light_baker.cpp @@ -1,5 +1,41 @@ +/*************************************************************************/ +/* voxel_light_baker.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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. */ +/*************************************************************************/ + #include "voxel_light_baker.h" #include "os/os.h" + +#include <stdlib.h> +#ifdef _OPENMP +#include <omp.h> +#endif + #define FINDMINMAX(x0, x1, x2, min, max) \ min = max = x0; \ if (x1 < min) min = x1; \ @@ -183,14 +219,23 @@ static bool fast_tri_box_overlap(const Vector3 &boxcenter, const Vector3 boxhalf return true; /* box and triangle overlaps */ } -static _FORCE_INLINE_ Vector2 get_uv(const Vector3 &p_pos, const Vector3 *p_vtx, const Vector2 *p_uv) { +static _FORCE_INLINE_ void get_uv_and_normal(const Vector3 &p_pos, const Vector3 *p_vtx, const Vector2 *p_uv, const Vector3 *p_normal, Vector2 &r_uv, Vector3 &r_normal) { - if (p_pos.distance_squared_to(p_vtx[0]) < CMP_EPSILON2) - return p_uv[0]; - if (p_pos.distance_squared_to(p_vtx[1]) < CMP_EPSILON2) - return p_uv[1]; - if (p_pos.distance_squared_to(p_vtx[2]) < CMP_EPSILON2) - return p_uv[2]; + if (p_pos.distance_squared_to(p_vtx[0]) < CMP_EPSILON2) { + r_uv = p_uv[0]; + r_normal = p_normal[0]; + return; + } + if (p_pos.distance_squared_to(p_vtx[1]) < CMP_EPSILON2) { + r_uv = p_uv[1]; + r_normal = p_normal[1]; + return; + } + if (p_pos.distance_squared_to(p_vtx[2]) < CMP_EPSILON2) { + r_uv = p_uv[2]; + r_normal = p_normal[2]; + return; + } Vector3 v0 = p_vtx[1] - p_vtx[0]; Vector3 v1 = p_vtx[2] - p_vtx[0]; @@ -202,16 +247,20 @@ static _FORCE_INLINE_ Vector2 get_uv(const Vector3 &p_pos, const Vector3 *p_vtx, float d20 = v2.dot(v0); float d21 = v2.dot(v1); float denom = (d00 * d11 - d01 * d01); - if (denom == 0) - return p_uv[0]; + if (denom == 0) { + r_uv = p_uv[0]; + r_normal = p_normal[0]; + return; + } float v = (d11 * d20 - d01 * d21) / denom; float w = (d00 * d21 - d01 * d20) / denom; float u = 1.0f - v - w; - return p_uv[0] * u + p_uv[1] * v + p_uv[2] * w; + r_uv = p_uv[0] * u + p_uv[1] * v + p_uv[2] * w; + r_normal = (p_normal[0] * u + p_normal[1] * v + p_normal[2] * w).normalized(); } -void VoxelLightBaker::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector2 *p_uv, const MaterialCache &p_material, const AABB &p_aabb) { +void VoxelLightBaker::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector3 *p_normal, const Vector2 *p_uv, const MaterialCache &p_material, const AABB &p_aabb) { if (p_level == cell_subdiv - 1) { //plot the face by guessing it's albedo and emission value @@ -289,7 +338,11 @@ void VoxelLightBaker::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p intersection = Face3(p_vtx[0], p_vtx[1], p_vtx[2]).get_closest_point_to(intersection); - Vector2 uv = get_uv(intersection, p_vtx, p_uv); + Vector2 uv; + Vector3 lnormal; + get_uv_and_normal(intersection, p_vtx, p_uv, p_normal, uv, lnormal); + if (lnormal == Vector3()) //just in case normal as nor provided + lnormal = normal; int uv_x = CLAMP(Math::fposmod(uv.x, 1.0f) * bake_texture_size, 0, bake_texture_size - 1); int uv_y = CLAMP(Math::fposmod(uv.y, 1.0f) * bake_texture_size, 0, bake_texture_size - 1); @@ -304,7 +357,7 @@ void VoxelLightBaker::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p emission_accum.g += p_material.emission[ofs].g; emission_accum.b += p_material.emission[ofs].b; - normal_accum += normal; + normal_accum += lnormal; alpha += 1.0; } @@ -316,7 +369,11 @@ void VoxelLightBaker::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p Face3 f(p_vtx[0], p_vtx[1], p_vtx[2]); Vector3 inters = f.get_closest_point_to(p_aabb.position + p_aabb.size * 0.5); - Vector2 uv = get_uv(inters, p_vtx, p_uv); + Vector3 lnormal; + Vector2 uv; + get_uv_and_normal(inters, p_vtx, p_uv, p_normal, uv, normal); + if (lnormal == Vector3()) //just in case normal as nor provided + lnormal = normal; int uv_x = CLAMP(Math::fposmod(uv.x, 1.0f) * bake_texture_size, 0, bake_texture_size - 1); int uv_y = CLAMP(Math::fposmod(uv.y, 1.0f) * bake_texture_size, 0, bake_texture_size - 1); @@ -334,7 +391,7 @@ void VoxelLightBaker::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p emission_accum.g = p_material.emission[ofs].g * alpha; emission_accum.b = p_material.emission[ofs].b * alpha; - normal_accum *= alpha; + normal_accum = lnormal * alpha; } else { @@ -415,7 +472,7 @@ void VoxelLightBaker::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p bake_cells[child_idx].level = p_level + 1; } - _plot_face(bake_cells[p_idx].childs[i], p_level + 1, nx, ny, nz, p_vtx, p_uv, p_material, aabb); + _plot_face(bake_cells[p_idx].childs[i], p_level + 1, nx, ny, nz, p_vtx, p_normal, p_uv, p_material, aabb); } } } @@ -539,9 +596,12 @@ void VoxelLightBaker::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, con PoolVector<Vector3>::Read vr = vertices.read(); PoolVector<Vector2> uv = a[Mesh::ARRAY_TEX_UV]; PoolVector<Vector2>::Read uvr; + PoolVector<Vector3> normals = a[Mesh::ARRAY_NORMAL]; + PoolVector<Vector3>::Read nr; PoolVector<int> index = a[Mesh::ARRAY_INDEX]; bool read_uv = false; + bool read_normals = false; if (uv.size()) { @@ -549,6 +609,11 @@ void VoxelLightBaker::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, con read_uv = true; } + if (normals.size()) { + read_normals = true; + nr = normals.read(); + } + if (index.size()) { int facecount = index.size() / 3; @@ -558,6 +623,7 @@ void VoxelLightBaker::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, con Vector3 vtxs[3]; Vector2 uvs[3]; + Vector3 normal[3]; for (int k = 0; k < 3; k++) { vtxs[k] = p_xform.xform(vr[ir[j * 3 + k]]); @@ -569,11 +635,17 @@ void VoxelLightBaker::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, con } } + if (read_normals) { + for (int k = 0; k < 3; k++) { + normal[k] = nr[ir[j * 3 + k]]; + } + } + //test against original bounds if (!fast_tri_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs)) continue; //plot - _plot_face(0, 0, 0, 0, 0, vtxs, uvs, material, po2_bounds); + _plot_face(0, 0, 0, 0, 0, vtxs, normal, uvs, material, po2_bounds); } } else { @@ -584,6 +656,7 @@ void VoxelLightBaker::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, con Vector3 vtxs[3]; Vector2 uvs[3]; + Vector3 normal[3]; for (int k = 0; k < 3; k++) { vtxs[k] = p_xform.xform(vr[j * 3 + k]); @@ -595,11 +668,17 @@ void VoxelLightBaker::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, con } } + if (read_normals) { + for (int k = 0; k < 3; k++) { + normal[k] = nr[j * 3 + k]; + } + } + //test against original bounds if (!fast_tri_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs)) continue; //plot face - _plot_face(0, 0, 0, 0, 0, vtxs, uvs, material, po2_bounds); + _plot_face(0, 0, 0, 0, 0, vtxs, normal, uvs, material, po2_bounds); } } } @@ -833,11 +912,13 @@ void VoxelLightBaker::plot_light_directional(const Vector3 &p_direction, const C } } - for (int i = 0; i < 6; i++) { - float s = MAX(0.0, aniso_normal[i].dot(-light_axis)); //light depending on normal for direct - light->direct_accum[i][0] += light_energy.x * s; - light->direct_accum[i][1] += light_energy.y * s; - light->direct_accum[i][2] += light_energy.z * s; + if (p_direct) { + for (int i = 0; i < 6; i++) { + float s = MAX(0.0, aniso_normal[i].dot(-light_axis)); //light depending on normal for direct + light->direct_accum[i][0] += light_energy.x * s; + light->direct_accum[i][1] += light_energy.y * s; + light->direct_accum[i][2] += light_energy.z * s; + } } success_count++; } @@ -962,11 +1043,13 @@ void VoxelLightBaker::plot_light_omni(const Vector3 &p_pos, const Color &p_color } } - for (int i = 0; i < 6; i++) { - float s = MAX(0.0, aniso_normal[i].dot(-light_axis)); //light depending on normal for direct - light->direct_accum[i][0] += light_energy.x * s * att; - light->direct_accum[i][1] += light_energy.y * s * att; - light->direct_accum[i][2] += light_energy.z * s * att; + if (p_direct) { + for (int i = 0; i < 6; i++) { + float s = MAX(0.0, aniso_normal[i].dot(-light_axis)); //light depending on normal for direct + light->direct_accum[i][0] += light_energy.x * s * att; + light->direct_accum[i][1] += light_energy.y * s * att; + light->direct_accum[i][2] += light_energy.z * s * att; + } } } @@ -1095,11 +1178,13 @@ void VoxelLightBaker::plot_light_spot(const Vector3 &p_pos, const Vector3 &p_axi } } - for (int i = 0; i < 6; i++) { - float s = MAX(0.0, aniso_normal[i].dot(-light_axis)); //light depending on normal for direct - light->direct_accum[i][0] += light_energy.x * s * att; - light->direct_accum[i][1] += light_energy.y * s * att; - light->direct_accum[i][2] += light_energy.z * s * att; + if (p_direct) { + for (int i = 0; i < 6; i++) { + float s = MAX(0.0, aniso_normal[i].dot(-light_axis)); //light depending on normal for direct + light->direct_accum[i][0] += light_energy.x * s * att; + light->direct_accum[i][1] += light_energy.y * s * att; + light->direct_accum[i][2] += light_energy.z * s * att; + } } } @@ -1594,19 +1679,17 @@ Vector3 VoxelLightBaker::_compute_pixel_light_at_pos(const Vector3 &p_pos, const return accum; } -uint32_t xorshiftstate[] = { 123 }; // anything non-zero will do here - -_ALWAYS_INLINE_ uint32_t xorshift32() { +_ALWAYS_INLINE_ uint32_t xorshift32(uint32_t *state) { /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */ - uint32_t x = xorshiftstate[0]; + uint32_t x = *state; x ^= x << 13; x ^= x >> 17; x ^= x << 5; - xorshiftstate[0] = x; + *state = x; return x; } -Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal) { +Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal, uint32_t *rng_state) { int samples_per_quality[3] = { 48, 128, 512 }; @@ -1630,18 +1713,18 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V for (int i = 0; i < samples; i++) { - float random_angle1 = (((xorshift32() % 65535) / 65535.0) * 2.0 - 1.0) * spread; + float random_angle1 = (((xorshift32(rng_state) % 65535) / 65535.0) * 2.0 - 1.0) * spread; Vector3 axis(0, sin(random_angle1), cos(random_angle1)); - float random_angle2 = ((xorshift32() % 65535) / 65535.0) * Math_PI * 2.0; + float random_angle2 = ((xorshift32(rng_state) % 65535) / 65535.0) * Math_PI * 2.0; Basis rot(Vector3(0, 0, 1), random_angle2); axis = rot.xform(axis); Vector3 direction = normal_xform.xform(axis).normalized(); - Vector3 pos = p_pos + Vector3(0.5, 0.5, 0.5) + direction * bias; - Vector3 advance = direction * _get_normal_advance(direction); + Vector3 pos = p_pos /*+ Vector3(0.5, 0.5, 0.5)*/ + advance * bias; + uint32_t cell = CHILD_EMPTY; while (cell == CHILD_EMPTY) { @@ -1703,6 +1786,9 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V accum.y += light[cell].accum[i][1] * amount; accum.z += light[cell].accum[i][2] * amount; } + accum.x += cells[cell].emission[0]; + accum.y += cells[cell].emission[1]; + accum.z += cells[cell].emission[2]; } } @@ -1752,6 +1838,7 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh Vector3 vertex[3]; Vector3 normal[3]; Vector2 uv[3]; + for (int j = 0; j < 3; j++) { int idx = ic ? ir[i * 3 + j] : i * 3 + j; vertex[j] = xform.xform(vr[idx]); @@ -1762,21 +1849,43 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh _plot_triangle(uv, vertex, normal, lightmap.ptrw(), width, height); } } - //step 3 perform voxel cone trace on lightmap pixels + //step 3 perform voxel cone trace on lightmap pixels { LightMap *lightmap_ptr = lightmap.ptrw(); uint64_t begin_time = OS::get_singleton()->get_ticks_usec(); volatile int lines = 0; + // make sure our OS-level rng is seeded + srand(OS::get_singleton()->get_ticks_usec()); + + // setup an RNG state for each OpenMP thread + uint32_t threadcount = 1; + uint32_t threadnum = 0; +#ifdef _OPENMP + threadcount = omp_get_max_threads(); +#endif + Vector<uint32_t> rng_states; + rng_states.resize(threadcount); + for (uint32_t i = 0; i < threadcount; i++) { + do { + rng_states[i] = rand(); + } while (rng_states[i] == 0); + } + uint32_t *rng_states_p = rng_states.ptrw(); + for (int i = 0; i < height; i++) { //print_line("bake line " + itos(i) + " / " + itos(height)); #ifdef _OPENMP -#pragma omp parallel for schedule(dynamic, 1) +#pragma omp parallel for schedule(dynamic, 1) private(threadnum) #endif for (int j = 0; j < width; j++) { +#ifdef _OPENMP + threadnum = omp_get_thread_num(); +#endif + //if (i == 125 && j == 280) { LightMap *pixel = &lightmap_ptr[i * width + j]; @@ -1789,7 +1898,7 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh pixel->light = _compute_pixel_light_at_pos(pixel->pos, pixel->normal) * energy; } break; case BAKE_MODE_RAY_TRACE: { - pixel->light = _compute_ray_trace_at_pos(pixel->pos, pixel->normal) * energy; + pixel->light = _compute_ray_trace_at_pos(pixel->pos, pixel->normal, &rng_states_p[threadnum]) * energy; } break; // pixel->light = Vector3(1, 1, 1); //} diff --git a/scene/3d/voxel_light_baker.h b/scene/3d/voxel_light_baker.h index 6dee2ee69b..7db31f8a67 100644 --- a/scene/3d/voxel_light_baker.h +++ b/scene/3d/voxel_light_baker.h @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* voxel_light_baker.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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. */ +/*************************************************************************/ + #ifndef VOXEL_LIGHT_BAKER_H #define VOXEL_LIGHT_BAKER_H @@ -99,7 +129,8 @@ private: Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color_mul, const Color &p_color_add); MaterialCache _get_material_cache(Ref<Material> p_material); - void _plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector2 *p_uv, const MaterialCache &p_material, const AABB &p_aabb); + + void _plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector3 *p_normal, const Vector2 *p_uv, const MaterialCache &p_material, const AABB &p_aabb); void _fixup_plot(int p_idx, int p_level); void _debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<MultiMesh> &p_multimesh, int &idx, DebugMode p_mode); void _check_init_light(); @@ -117,7 +148,7 @@ private: _FORCE_INLINE_ void _sample_baked_octree_filtered_and_anisotropic(const Vector3 &p_posf, const Vector3 &p_direction, float p_level, Vector3 &r_color, float &r_alpha); _FORCE_INLINE_ Vector3 _voxel_cone_trace(const Vector3 &p_pos, const Vector3 &p_normal, float p_aperture); _FORCE_INLINE_ Vector3 _compute_pixel_light_at_pos(const Vector3 &p_pos, const Vector3 &p_normal); - _FORCE_INLINE_ Vector3 _compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal); + _FORCE_INLINE_ Vector3 _compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal, uint32_t *rng_state); public: void begin_bake(int p_subdiv, const AABB &p_bounds); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index e1f77594da..51a25c60a1 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -207,7 +207,7 @@ void Label::_notification(int p_what) { } break; } - int y_ofs = style->get_offset().y; + float y_ofs = style->get_offset().y; y_ofs += (line - lines_skipped) * font_h + font->get_ascent(); y_ofs += vbegin + line * vsep; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index deb40800bc..400c7f5b6e 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -38,6 +38,7 @@ #include "os/os.h" #include "print_string.h" #include "project_settings.h" +#include "scene/resources/dynamic_font.h" #include "scene/resources/material.h" #include "scene/resources/mesh.h" #include "scene/resources/packed_scene.h" @@ -495,6 +496,11 @@ bool SceneTree::idle(float p_time) { Size2 win_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); if (win_size != last_screen_size) { + if (use_font_oversampling) { + DynamicFontAtSize::font_oversampling = OS::get_singleton()->get_window_size().width / root->get_visible_rect().size.width; + DynamicFont::update_oversampling(); + } + last_screen_size = win_size; _update_root_rect(); @@ -2195,6 +2201,9 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("_connection_failed"), &SceneTree::_connection_failed); ClassDB::bind_method(D_METHOD("_server_disconnected"), &SceneTree::_server_disconnected); + ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &SceneTree::set_use_font_oversampling); + ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &SceneTree::is_using_font_oversampling); + ADD_SIGNAL(MethodInfo("tree_changed")); ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::OBJECT, "node"))); ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::OBJECT, "node"))); @@ -2244,6 +2253,20 @@ void SceneTree::add_idle_callback(IdleCallback p_callback) { idle_callbacks[idle_callback_count++] = p_callback; } +void SceneTree::set_use_font_oversampling(bool p_oversampling) { + + use_font_oversampling = p_oversampling; + if (use_font_oversampling) { + DynamicFontAtSize::font_oversampling = OS::get_singleton()->get_window_size().width / root->get_visible_rect().size.width; + } else { + DynamicFontAtSize::font_oversampling = 1.0; + } +} + +bool SceneTree::is_using_font_oversampling() const { + return use_font_oversampling; +} + SceneTree::SceneTree() { singleton = this; @@ -2380,6 +2403,8 @@ SceneTree::SceneTree() { last_send_cache_id = 1; #endif + + use_font_oversampling = false; } SceneTree::~SceneTree() { diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 244fc8da62..9c5b0f69cb 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -122,11 +122,13 @@ private: bool _quit; bool initialized; bool input_handled; + Size2 last_screen_size; StringName tree_changed_name; StringName node_added_name; StringName node_removed_name; + bool use_font_oversampling; int64_t current_frame; int node_count; @@ -420,6 +422,9 @@ public: void set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize, real_t p_shrink = 1); + void set_use_font_oversampling(bool p_oversampling); + bool is_using_font_oversampling() const; + //void change_scene(const String& p_path); //Node *get_loaded_scene(); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index f5d7043a40..ae855e803c 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1659,6 +1659,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { //cancel event, sorry, modal exclusive EATS UP ALL //alternative, you can't pop out a window the same frame it was made modal (fixes many issues) get_tree()->set_input_as_handled(); + return; // no one gets the event if exclusive NO ONE } @@ -2348,7 +2349,6 @@ void Viewport::_gui_control_grab_focus(Control *p_control) { //no need for change if (gui.key_focus && gui.key_focus == p_control) return; - get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus"); gui.key_focus = p_control; p_control->notification(Control::NOTIFICATION_FOCUS_ENTER); @@ -2370,6 +2370,11 @@ List<Control *>::Element *Viewport::_gui_show_modal(Control *p_control) { else p_control->_modal_set_prev_focus_owner(0); + if (gui.mouse_focus && !p_control->is_a_parent_of(gui.mouse_focus)) { + gui.mouse_focus->notification(Control::NOTIFICATION_MOUSE_EXIT); + gui.mouse_focus = NULL; + } + return gui.modal_stack.back(); } diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 246283edcc..39e6698725 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -542,6 +542,8 @@ void register_scene_types() { ClassDB::register_class<DynamicFontData>(); ClassDB::register_class<DynamicFont>(); + DynamicFont::initialize_dynamic_fonts(); + ClassDB::register_virtual_class<StyleBox>(); ClassDB::register_class<StyleBoxEmpty>(); ClassDB::register_class<StyleBoxTexture>(); @@ -621,6 +623,8 @@ void unregister_scene_types() { memdelete(resource_loader_stream_texture); memdelete(resource_loader_theme); + DynamicFont::finish_dynamic_fonts(); + if (resource_saver_text) { memdelete(resource_saver_text); } diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index a40417f24d..66b1e49d13 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -191,10 +191,10 @@ Error DynamicFontAtSize::_load() { ERR_FAIL_COND_V( error, ERR_INVALID_PARAMETER ); }*/ - error = FT_Set_Pixel_Sizes(face, 0, id.size); + error = FT_Set_Pixel_Sizes(face, 0, id.size * oversampling); - ascent = face->size->metrics.ascender >> 6; - descent = -face->size->metrics.descender >> 6; + ascent = (face->size->metrics.ascender >> 6) / oversampling; + descent = (-face->size->metrics.descender >> 6) / oversampling; linegap = 0; texture_flags = 0; if (id.mipmaps) @@ -208,6 +208,8 @@ Error DynamicFontAtSize::_load() { return OK; } +float DynamicFontAtSize::font_oversampling = 1.0; + float DynamicFontAtSize::get_height() const { return ascent + descent; @@ -282,11 +284,11 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const V if (delta.x == 0) continue; - ret.x += delta.x >> 6; + ret.x += (delta.x >> 6) / oversampling; break; } } else { - ret.x += delta.x >> 6; + ret.x += (delta.x >> 6) / oversampling; } } @@ -338,7 +340,7 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT cpos.y += ch->v_align; ERR_FAIL_COND_V(ch->texture_idx < -1 || ch->texture_idx >= fb->textures.size(), 0); if (ch->texture_idx != -1) - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size), fb->textures[ch->texture_idx].texture->get_rid(), ch->rect, p_modulate, false, RID(), false); + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size), fb->textures[ch->texture_idx].texture->get_rid(), ch->rect_uv, p_modulate, false, RID(), false); advance = ch->advance; used_fallback = true; break; @@ -360,7 +362,7 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT cpos.y += c->v_align; ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); if (c->texture_idx != -1) - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx].texture->get_rid(), c->rect, p_modulate, false, RID(), false); + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx].texture->get_rid(), c->rect_uv, p_modulate, false, RID(), false); advance = c->advance; //textures[c->texture_idx].texture->draw(p_canvas_item,Vector2()); } @@ -382,11 +384,11 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT if (delta.x == 0) continue; - advance += delta.x >> 6; + advance += (delta.x >> 6) / oversampling; break; } } else { - advance += delta.x >> 6; + advance += (delta.x >> 6) / oversampling; } } @@ -602,19 +604,37 @@ void DynamicFontAtSize::_update_char(CharType p_char) { } Character chr; - chr.h_align = xofs; - chr.v_align = ascent - yofs; // + ascent - descent; - chr.advance = advance; + chr.h_align = xofs / oversampling; + chr.v_align = ascent - (yofs / oversampling); // + ascent - descent; + chr.advance = advance / oversampling; chr.texture_idx = tex_index; chr.found = true; - chr.rect = Rect2(tex_x + rect_margin, tex_y + rect_margin, w, h); + chr.rect_uv = Rect2(tex_x + rect_margin, tex_y + rect_margin, w, h); + chr.rect = chr.rect_uv; + chr.rect.position /= oversampling; + chr.rect.size /= oversampling; //print_line("CHAR: "+String::chr(p_char)+" TEX INDEX: "+itos(tex_index)+" RECT: "+chr.rect+" X OFS: "+itos(xofs)+" Y OFS: "+itos(yofs)); char_map[p_char] = chr; } +bool DynamicFontAtSize::update_oversampling() { + if (oversampling == font_oversampling) + return false; + if (!valid) + return false; + + FT_Done_FreeType(library); + textures.clear(); + char_map.clear(); + oversampling = font_oversampling; + _load(); + + return true; +} + DynamicFontAtSize::DynamicFontAtSize() { valid = false; @@ -623,6 +643,7 @@ DynamicFontAtSize::DynamicFontAtSize() { descent = 1; linegap = 1; texture_flags = 0; + oversampling = font_oversampling; } DynamicFontAtSize::~DynamicFontAtSize() { @@ -913,15 +934,52 @@ void DynamicFont::_bind_methods() { BIND_ENUM_CONSTANT(SPACING_SPACE); } -DynamicFont::DynamicFont() { +Mutex *DynamicFont::dynamic_font_mutex = NULL; + +SelfList<DynamicFont>::List DynamicFont::dynamic_fonts; + +DynamicFont::DynamicFont() : + font_list(this) { spacing_top = 0; spacing_bottom = 0; spacing_char = 0; spacing_space = 0; + if (dynamic_font_mutex) + dynamic_font_mutex->lock(); + dynamic_fonts.add(&font_list); + if (dynamic_font_mutex) + dynamic_font_mutex->unlock(); } DynamicFont::~DynamicFont() { + + if (dynamic_font_mutex) + dynamic_font_mutex->lock(); + dynamic_fonts.remove(&font_list); + if (dynamic_font_mutex) + dynamic_font_mutex->unlock(); +} + +void DynamicFont::initialize_dynamic_fonts() { + dynamic_font_mutex = Mutex::create(); +} + +void DynamicFont::finish_dynamic_fonts() { + memdelete(dynamic_font_mutex); + dynamic_font_mutex = NULL; +} + +void DynamicFont::update_oversampling() { + + SelfList<DynamicFont> *E = dynamic_fonts.first(); + while (E) { + + if (E->self()->data_at_size.is_valid() && E->self()->data_at_size->update_oversampling()) { + E->self()->emit_changed(); + } + E = E->next(); + } } ///////////////////////// diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index 52c3f30590..b2452a6a0a 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -32,6 +32,7 @@ #ifdef FREETYPE_ENABLED #include "io/resource_loader.h" +#include "os/mutex.h" #include "os/thread_safe.h" #include "scene/resources/font.h" @@ -97,10 +98,11 @@ class DynamicFontAtSize : public Reference { FT_Face face; /* handle to face object */ FT_StreamRec stream; - int ascent; - int descent; - int linegap; - int rect_margin; + float ascent; + float descent; + float linegap; + float rect_margin; + float oversampling; uint32_t texture_flags; @@ -121,6 +123,7 @@ class DynamicFontAtSize : public Reference { bool found; int texture_idx; Rect2 rect; + Rect2 rect_uv; float v_align; float h_align; float advance; @@ -145,8 +148,9 @@ class DynamicFontAtSize : public Reference { static HashMap<String, Vector<uint8_t> > _fontdata; Error _load(); -protected: public: + static float font_oversampling; + float get_height() const; float get_ascent() const; @@ -157,6 +161,7 @@ public: float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const; void set_texture_flags(uint32_t p_flags); + bool update_oversampling(); DynamicFontAtSize(); ~DynamicFontAtSize(); @@ -232,6 +237,15 @@ public: virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) const; + SelfList<DynamicFont> font_list; + + static Mutex *dynamic_font_mutex; + static SelfList<DynamicFont>::List dynamic_fonts; + + static void initialize_dynamic_fonts(); + static void finish_dynamic_fonts(); + static void update_oversampling(); + DynamicFont(); ~DynamicFont(); }; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 2b44ea4554..8510669d6c 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -257,8 +257,8 @@ Error BitmapFont::create_from_fnt(const String &p_file) { if (keys.has("file")) { - String file = keys["file"]; - file = p_file.get_base_dir() + "/" + file; + String base_dir = p_file.get_base_dir(); + String file = base_dir.plus_file(keys["file"]); Ref<Texture> tex = ResourceLoader::load(file); if (tex.is_null()) { ERR_PRINT("Can't load font texture!"); diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index d7b2c2c5e0..15d4a11223 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -76,6 +76,13 @@ void AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale, internal_buffer[1] = internal_buffer[INTERNAL_BUFFER_LEN + 1]; internal_buffer[2] = internal_buffer[INTERNAL_BUFFER_LEN + 2]; internal_buffer[3] = internal_buffer[INTERNAL_BUFFER_LEN + 3]; + if (!is_playing()) { + for (int i = 4; i < INTERNAL_BUFFER_LEN; ++i) { + internal_buffer[i] = AudioFrame(0, 0); + } + + return; + } _mix_internal(internal_buffer + 4, INTERNAL_BUFFER_LEN); mix_offset -= (INTERNAL_BUFFER_LEN << FP_BITS); } diff --git a/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp b/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp index 5ce452cb9e..fd37b8c59c 100644 --- a/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp +++ b/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.cpp @@ -142,9 +142,11 @@ AtlasPacker::AtlasPacker(Atlas * atlas) : m_atlas(atlas), m_bitmap(256, 256) { m_width = 0; m_height = 0; - - m_debug_bitmap.allocate(256, 256); - m_debug_bitmap.fill(Color32(0,0,0,0)); + + // -- GODOT start -- + //m_debug_bitmap.allocate(256, 256); + //m_debug_bitmap.fill(Color32(0,0,0,0)); + // -- GODOT end -- } AtlasPacker::~AtlasPacker() @@ -597,8 +599,10 @@ void AtlasPacker::packCharts(int quality, float texelsPerUnit, bool blockAligned m_bitmap.clearAll(); if (approximateExtent > m_bitmap.width()) { m_bitmap.resize(approximateExtent, approximateExtent, false); - m_debug_bitmap.resize(approximateExtent, approximateExtent); - m_debug_bitmap.fill(Color32(0,0,0,0)); + // -- GODOT start -- + //m_debug_bitmap.resize(approximateExtent, approximateExtent); + //m_debug_bitmap.fill(Color32(0,0,0,0)); + // -- GODOT end -- } @@ -680,20 +684,24 @@ void AtlasPacker::packCharts(int quality, float texelsPerUnit, bool blockAligned { //nvDebug("Resize bitmap (%d, %d).\n", nextPowerOfTwo(w), nextPowerOfTwo(h)); m_bitmap.resize(nextPowerOfTwo(U32(w)), nextPowerOfTwo(U32(h)), false); - m_debug_bitmap.resize(nextPowerOfTwo(U32(w)), nextPowerOfTwo(U32(h))); + // -- GODOT start -- + //m_debug_bitmap.resize(nextPowerOfTwo(U32(w)), nextPowerOfTwo(U32(h))); + // -- GODOT end -- } //nvDebug("Add chart at (%d, %d).\n", best_x, best_y); addChart(&chart_bitmap, w, h, best_x, best_y, best_r, /*debugOutput=*/NULL); + // -- GODOT start -- // IC: Output chart again to debug bitmap. - if (chart->isVertexMapped()) { + /*if (chart->isVertexMapped()) { addChart(&chart_bitmap, w, h, best_x, best_y, best_r, &m_debug_bitmap); } else { addChart(chart, w, h, best_x, best_y, best_r, &m_debug_bitmap); - } + }*/ + // -- GODOT end -- //float best_angle = 2 * PI * best_r; @@ -842,8 +850,10 @@ void AtlasPacker::packCharts(int quality, float texelsPerUnit, bool blockAligned nvCheck(isAligned(m_width, 4)); nvCheck(isAligned(m_height, 4)); - m_debug_bitmap.resize(m_width, m_height); - m_debug_bitmap.setFormat(Image::Format_ARGB); + // -- GODOT start -- + //m_debug_bitmap.resize(m_width, m_height); + //m_debug_bitmap.setFormat(Image::Format_ARGB); + // -- GODOT end -- #if DEBUG_OUTPUT //outputDebugBitmap("debug_packer_final.tga", m_bitmap, w, h); diff --git a/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.h b/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.h index 2d305f38cd..845dbfb6f3 100644 --- a/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.h +++ b/thirdparty/thekla_atlas/nvmesh/param/AtlasPacker.h @@ -48,7 +48,9 @@ namespace nv Atlas * m_atlas; BitMap m_bitmap; - Image m_debug_bitmap; + // -- GODOT start -- + //Image m_debug_bitmap; + // -- GODOT end -- RadixSort m_radix; uint m_width; diff --git a/thirdparty/thekla_atlas/thekla/thekla_atlas.cpp b/thirdparty/thekla_atlas/thekla/thekla_atlas.cpp index d6f0accf54..de1953db8a 100644 --- a/thirdparty/thekla_atlas/thekla/thekla_atlas.cpp +++ b/thirdparty/thekla_atlas/thekla/thekla_atlas.cpp @@ -2,6 +2,9 @@ #include "thekla_atlas.h" #include <cfloat> +// -- GODOT start -- +#include <stdio.h> +// -- GODOT end -- #include "nvmesh/halfedge/Edge.h" #include "nvmesh/halfedge/Mesh.h" @@ -112,6 +115,8 @@ static Atlas_Output_Mesh * mesh_atlas_to_output(const HalfEdge::Mesh * mesh, con output->index_count = face_count * 3; output->index_array = new int[face_count * 3]; + // -- GODOT start -- + int face_ofs = 0; // Set face indices. for (int f = 0; f < face_count; f++) { uint c = charts->faceChartAt(f); @@ -121,14 +126,26 @@ static Atlas_Output_Mesh * mesh_atlas_to_output(const HalfEdge::Mesh * mesh, con const Chart * chart = charts->chartAt(c); nvDebugCheck(chart->faceAt(i) == f); + if (i >= chart->chartMesh()->faceCount()) { + printf("WARNING: Faces may be missing in the final vertex, which could not be packed\n"); + continue; + } + const HalfEdge::Face * face = chart->chartMesh()->faceAt(i); const HalfEdge::Edge * edge = face->edge; - output->index_array[3*f+0] = vertexOffset + edge->vertex->id; - output->index_array[3*f+1] = vertexOffset + edge->next->vertex->id; - output->index_array[3*f+2] = vertexOffset + edge->next->next->vertex->id; + //output->index_array[3*f+0] = vertexOffset + edge->vertex->id; + //output->index_array[3*f+1] = vertexOffset + edge->next->vertex->id; + //output->index_array[3*f+2] = vertexOffset + edge->next->next->vertex->id; + output->index_array[3 * face_ofs + 0] = vertexOffset + edge->vertex->id; + output->index_array[3 * face_ofs + 1] = vertexOffset + edge->next->vertex->id; + output->index_array[3 * face_ofs + 2] = vertexOffset + edge->next->next->vertex->id; + face_ofs++; } + output->index_count = face_ofs * 3; + // -- GODOT end -- + *error = Atlas_Error_Success; output->atlas_width = w; output->atlas_height = h; |