summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp4
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp16
-rw-r--r--drivers/gles3/shader_compiler_gles3.cpp16
-rw-r--r--drivers/png/resource_saver_png.cpp2
-rw-r--r--editor/editor_node.cpp262
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp78
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h2
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp11
-rw-r--r--editor/plugins/spatial_editor_plugin.h2
-rw-r--r--modules/bmp/image_loader_bmp.cpp2
-rw-r--r--modules/gdscript/gdscript_editor.cpp4
-rw-r--r--platform/server/os_server.cpp4
-rw-r--r--platform/server/os_server.h1
-rw-r--r--scene/3d/audio_stream_player_3d.cpp2
-rw-r--r--scene/gui/line_edit.cpp8
-rw-r--r--scene/resources/audio_stream_sample.cpp3
-rw-r--r--servers/audio/effects/audio_effect_chorus.cpp8
-rw-r--r--servers/audio/effects/audio_effect_distortion.cpp2
-rw-r--r--servers/audio/effects/audio_effect_filter.cpp2
-rw-r--r--servers/visual/shader_language.cpp193
-rw-r--r--servers/visual/shader_language.h2
-rw-r--r--thirdparty/README.md2
-rw-r--r--thirdparty/xatlas/xatlas.cpp698
23 files changed, 868 insertions, 456 deletions
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index ea29af7d9e..c8ceca8d97 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -1133,8 +1133,8 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G
LightInstance *li = light_instance_owner.getornull(e->instance->light_instances[i]);
- if (li->light_index >= render_light_instance_count) {
- continue; // too many
+ if (li->light_index >= render_light_instance_count || render_light_instances[li->light_index] != li) {
+ continue; // too many or light_index did not correspond to the light instances to be rendered
}
if (copy) {
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index af88d0172a..df7eee2301 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -531,6 +531,22 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener
declaration += "[";
declaration += itos(var_dec_node->declarations[i].size);
declaration += "]";
+ int sz = var_dec_node->declarations[i].initializer.size();
+ if (sz > 0) {
+ declaration += "=";
+ declaration += _typestr(var_dec_node->datatype);
+ declaration += "[";
+ declaration += itos(sz);
+ declaration += "]";
+ declaration += "(";
+ for (int j = 0; j < sz; j++) {
+ declaration += _dump_node_code(var_dec_node->declarations[i].initializer[j], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
+ if (j != sz - 1) {
+ declaration += ", ";
+ }
+ }
+ declaration += ")";
+ }
}
code += declaration.as_string();
diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp
index ae68f0a06d..f826bdf5a2 100644
--- a/drivers/gles3/shader_compiler_gles3.cpp
+++ b/drivers/gles3/shader_compiler_gles3.cpp
@@ -622,6 +622,22 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
declaration += "[";
declaration += itos(vdnode->declarations[i].size);
declaration += "]";
+ int sz = vdnode->declarations[i].initializer.size();
+ if (sz > 0) {
+ declaration += "=";
+ declaration += _typestr(vdnode->datatype);
+ declaration += "[";
+ declaration += itos(sz);
+ declaration += "]";
+ declaration += "(";
+ for (int j = 0; j < sz; j++) {
+ declaration += _dump_node_code(vdnode->declarations[i].initializer[j], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
+ if (j != sz - 1) {
+ declaration += ", ";
+ }
+ }
+ declaration += ")";
+ }
}
code += declaration;
diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp
index 89e8ee32cc..43a30f055b 100644
--- a/drivers/png/resource_saver_png.cpp
+++ b/drivers/png/resource_saver_png.cpp
@@ -79,7 +79,7 @@ bool ResourceSaverPNG::recognize(const RES &p_resource) const {
void ResourceSaverPNG::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
- if (Object::cast_to<Texture>(*p_resource)) {
+ if (Object::cast_to<ImageTexture>(*p_resource)) {
p_extensions->push_back("png");
}
}
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 3431930b8b..3183f1ae97 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -238,185 +238,183 @@ void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) {
void EditorNode::_notification(int p_what) {
- if (p_what == NOTIFICATION_EXIT_TREE) {
-
- editor_data.save_editor_external_data();
- FileAccess::set_file_close_fail_notify_callback(NULL);
- log->deinit(); // do not get messages anymore
- }
- if (p_what == NOTIFICATION_PROCESS) {
-
- if (opening_prev && !confirmation->is_visible())
- opening_prev = false;
+ switch (p_what) {
+ case NOTIFICATION_PROCESS: {
+ if (opening_prev && !confirmation->is_visible())
+ opening_prev = false;
- if (unsaved_cache != (saved_version != editor_data.get_undo_redo().get_version())) {
+ if (unsaved_cache != (saved_version != editor_data.get_undo_redo().get_version())) {
- unsaved_cache = (saved_version != editor_data.get_undo_redo().get_version());
- _update_title();
- }
+ unsaved_cache = (saved_version != editor_data.get_undo_redo().get_version());
+ _update_title();
+ }
- if (last_checked_version != editor_data.get_undo_redo().get_version()) {
- _update_scene_tabs();
- last_checked_version = editor_data.get_undo_redo().get_version();
- }
+ if (last_checked_version != editor_data.get_undo_redo().get_version()) {
+ _update_scene_tabs();
+ last_checked_version = editor_data.get_undo_redo().get_version();
+ }
- // update the animation frame of the update spinner
- uint64_t frame = Engine::get_singleton()->get_frames_drawn();
- uint32_t tick = OS::get_singleton()->get_ticks_msec();
+ // update the animation frame of the update spinner
+ uint64_t frame = Engine::get_singleton()->get_frames_drawn();
+ uint32_t tick = OS::get_singleton()->get_ticks_msec();
- if (frame != update_spinner_step_frame && (tick - update_spinner_step_msec) > (1000 / 8)) {
+ if (frame != update_spinner_step_frame && (tick - update_spinner_step_msec) > (1000 / 8)) {
- update_spinner_step++;
- if (update_spinner_step >= 8)
- update_spinner_step = 0;
+ update_spinner_step++;
+ if (update_spinner_step >= 8)
+ update_spinner_step = 0;
- update_spinner_step_msec = tick;
- update_spinner_step_frame = frame + 1;
+ update_spinner_step_msec = tick;
+ update_spinner_step_frame = frame + 1;
- // update the icon itself only when the spinner is visible
- if (EditorSettings::get_singleton()->get("interface/editor/show_update_spinner")) {
- update_spinner->set_icon(gui_base->get_icon("Progress" + itos(update_spinner_step + 1), "EditorIcons"));
+ // update the icon itself only when the spinner is visible
+ if (EditorSettings::get_singleton()->get("interface/editor/show_update_spinner")) {
+ update_spinner->set_icon(gui_base->get_icon("Progress" + itos(update_spinner_step + 1), "EditorIcons"));
+ }
}
- }
- editor_selection->update();
+ editor_selection->update();
- scene_root->set_size_override(true, Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")));
+ scene_root->set_size_override(true, Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")));
- ResourceImporterTexture::get_singleton()->update_imports();
- }
- if (p_what == NOTIFICATION_ENTER_TREE) {
+ ResourceImporterTexture::get_singleton()->update_imports();
+ } break;
- Engine::get_singleton()->set_editor_hint(true);
+ case NOTIFICATION_ENTER_TREE: {
+ Engine::get_singleton()->set_editor_hint(true);
- OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
- get_tree()->get_root()->set_usage(Viewport::USAGE_2D_NO_SAMPLING); //reduce memory usage
- get_tree()->get_root()->set_disable_3d(true);
- get_tree()->get_root()->set_as_audio_listener(false);
- get_tree()->get_root()->set_as_audio_listener_2d(false);
- get_tree()->set_auto_accept_quit(false);
- get_tree()->connect("files_dropped", this, "_dropped_files");
+ OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
+ get_tree()->get_root()->set_usage(Viewport::USAGE_2D_NO_SAMPLING); //reduce memory usage
+ get_tree()->get_root()->set_disable_3d(true);
+ get_tree()->get_root()->set_as_audio_listener(false);
+ get_tree()->get_root()->set_as_audio_listener_2d(false);
+ get_tree()->set_auto_accept_quit(false);
+ get_tree()->connect("files_dropped", this, "_dropped_files");
- /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
- }
+ /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
+ case NOTIFICATION_EXIT_TREE: {
+ editor_data.save_editor_external_data();
+ FileAccess::set_file_close_fail_notify_callback(NULL);
+ log->deinit(); // do not get messages anymore
+ editor_data.clear_edited_scenes();
+ } break;
- editor_data.clear_edited_scenes();
- }
- if (p_what == NOTIFICATION_READY) {
+ case NOTIFICATION_READY: {
- VisualServer::get_singleton()->viewport_set_hide_scenario(get_scene_root()->get_viewport_rid(), true);
- VisualServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport_rid(), true);
- VisualServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(), true);
+ VisualServer::get_singleton()->viewport_set_hide_scenario(get_scene_root()->get_viewport_rid(), true);
+ VisualServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport_rid(), true);
+ VisualServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(), true);
- feature_profile_manager->notify_changed();
+ feature_profile_manager->notify_changed();
- if (!main_editor_buttons[EDITOR_3D]->is_visible()) { //may be hidden due to feature profile
- _editor_select(EDITOR_2D);
- } else {
- _editor_select(EDITOR_3D);
- }
+ if (!main_editor_buttons[EDITOR_3D]->is_visible()) { //may be hidden due to feature profile
+ _editor_select(EDITOR_2D);
+ } else {
+ _editor_select(EDITOR_3D);
+ }
- _update_debug_options();
+ _update_debug_options();
- /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
- }
+ /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
+ } break;
- if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) {
+ case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
- // Restore the original FPS cap after focusing back on the editor
- OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
+ // Restore the original FPS cap after focusing back on the editor
+ OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
- EditorFileSystem::get_singleton()->scan_changes();
- }
+ EditorFileSystem::get_singleton()->scan_changes();
+ } break;
- if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT) {
+ case MainLoop::NOTIFICATION_WM_FOCUS_OUT: {
- // Set a low FPS cap to decrease CPU/GPU usage while the editor is unfocused
- OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec")));
- }
+ // Set a low FPS cap to decrease CPU/GPU usage while the editor is unfocused
+ OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec")));
+ } break;
- if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) {
+ case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: {
- _menu_option_confirm(FILE_QUIT, false);
- }
+ _menu_option_confirm(FILE_QUIT, false);
+ } break;
- if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
- scene_tabs->set_tab_close_display_policy((bool(EDITOR_GET("interface/scene_tabs/always_show_close_button")) ? Tabs::CLOSE_BUTTON_SHOW_ALWAYS : Tabs::CLOSE_BUTTON_SHOW_ACTIVE_ONLY));
- Ref<Theme> theme = create_editor_theme(theme_base->get_theme());
+ case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
+ scene_tabs->set_tab_close_display_policy((bool(EDITOR_GET("interface/scene_tabs/always_show_close_button")) ? Tabs::CLOSE_BUTTON_SHOW_ALWAYS : Tabs::CLOSE_BUTTON_SHOW_ACTIVE_ONLY));
+ Ref<Theme> theme = create_editor_theme(theme_base->get_theme());
- theme_base->set_theme(theme);
- gui_base->set_theme(theme);
+ theme_base->set_theme(theme);
+ gui_base->set_theme(theme);
- gui_base->add_style_override("panel", gui_base->get_stylebox("Background", "EditorStyles"));
- scene_root_parent->add_style_override("panel", gui_base->get_stylebox("Content", "EditorStyles"));
- bottom_panel->add_style_override("panel", gui_base->get_stylebox("panel", "TabContainer"));
- scene_tabs->add_style_override("tab_fg", gui_base->get_stylebox("SceneTabFG", "EditorStyles"));
- scene_tabs->add_style_override("tab_bg", gui_base->get_stylebox("SceneTabBG", "EditorStyles"));
+ gui_base->add_style_override("panel", gui_base->get_stylebox("Background", "EditorStyles"));
+ scene_root_parent->add_style_override("panel", gui_base->get_stylebox("Content", "EditorStyles"));
+ bottom_panel->add_style_override("panel", gui_base->get_stylebox("panel", "TabContainer"));
+ scene_tabs->add_style_override("tab_fg", gui_base->get_stylebox("SceneTabFG", "EditorStyles"));
+ scene_tabs->add_style_override("tab_bg", gui_base->get_stylebox("SceneTabBG", "EditorStyles"));
- file_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
- project_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
- debug_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
- settings_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
- help_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
+ file_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
+ project_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
+ debug_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
+ settings_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
+ help_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
- if (EDITOR_GET("interface/scene_tabs/resize_if_many_tabs")) {
- scene_tabs->set_min_width(int(EDITOR_GET("interface/scene_tabs/minimum_width")) * EDSCALE);
- } else {
- scene_tabs->set_min_width(0);
- }
- _update_scene_tabs();
+ if (EDITOR_GET("interface/scene_tabs/resize_if_many_tabs")) {
+ scene_tabs->set_min_width(int(EDITOR_GET("interface/scene_tabs/minimum_width")) * EDSCALE);
+ } else {
+ scene_tabs->set_min_width(0);
+ }
+ _update_scene_tabs();
- recent_scenes->set_as_minsize();
+ recent_scenes->set_as_minsize();
- // debugger area
- if (ScriptEditor::get_singleton()->get_debugger()->is_visible())
- bottom_panel->add_style_override("panel", gui_base->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles"));
+ // debugger area
+ if (ScriptEditor::get_singleton()->get_debugger()->is_visible())
+ bottom_panel->add_style_override("panel", gui_base->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles"));
- // update_icons
- for (int i = 0; i < singleton->main_editor_buttons.size(); i++) {
+ // update_icons
+ for (int i = 0; i < singleton->main_editor_buttons.size(); i++) {
- ToolButton *tb = singleton->main_editor_buttons[i];
- EditorPlugin *p_editor = singleton->editor_table[i];
- Ref<Texture> icon = p_editor->get_icon();
+ ToolButton *tb = singleton->main_editor_buttons[i];
+ EditorPlugin *p_editor = singleton->editor_table[i];
+ Ref<Texture> icon = p_editor->get_icon();
- if (icon.is_valid()) {
- tb->set_icon(icon);
- } else if (singleton->gui_base->has_icon(p_editor->get_name(), "EditorIcons")) {
- tb->set_icon(singleton->gui_base->get_icon(p_editor->get_name(), "EditorIcons"));
+ if (icon.is_valid()) {
+ tb->set_icon(icon);
+ } else if (singleton->gui_base->has_icon(p_editor->get_name(), "EditorIcons")) {
+ tb->set_icon(singleton->gui_base->get_icon(p_editor->get_name(), "EditorIcons"));
+ }
}
- }
- _build_icon_type_cache();
+ _build_icon_type_cache();
- play_button->set_icon(gui_base->get_icon("MainPlay", "EditorIcons"));
- play_scene_button->set_icon(gui_base->get_icon("PlayScene", "EditorIcons"));
- play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom", "EditorIcons"));
- pause_button->set_icon(gui_base->get_icon("Pause", "EditorIcons"));
- stop_button->set_icon(gui_base->get_icon("Stop", "EditorIcons"));
+ play_button->set_icon(gui_base->get_icon("MainPlay", "EditorIcons"));
+ play_scene_button->set_icon(gui_base->get_icon("PlayScene", "EditorIcons"));
+ play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom", "EditorIcons"));
+ pause_button->set_icon(gui_base->get_icon("Pause", "EditorIcons"));
+ stop_button->set_icon(gui_base->get_icon("Stop", "EditorIcons"));
- prev_scene->set_icon(gui_base->get_icon("PrevScene", "EditorIcons"));
- distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons"));
- scene_tab_add->set_icon(gui_base->get_icon("Add", "EditorIcons"));
+ prev_scene->set_icon(gui_base->get_icon("PrevScene", "EditorIcons"));
+ distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons"));
+ scene_tab_add->set_icon(gui_base->get_icon("Add", "EditorIcons"));
- // clear_button->set_icon(gui_base->get_icon("Close", "EditorIcons")); don't have access to that node. needs to become a class property
- dock_tab_move_left->set_icon(theme->get_icon("Back", "EditorIcons"));
- dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons"));
+ // clear_button->set_icon(gui_base->get_icon("Close", "EditorIcons")); don't have access to that node. needs to become a class property
+ dock_tab_move_left->set_icon(theme->get_icon("Back", "EditorIcons"));
+ dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons"));
- PopupMenu *p = help_menu->get_popup();
- p->set_item_icon(p->get_item_index(HELP_SEARCH), gui_base->get_icon("HelpSearch", "EditorIcons"));
- p->set_item_icon(p->get_item_index(HELP_DOCS), gui_base->get_icon("Instance", "EditorIcons"));
- p->set_item_icon(p->get_item_index(HELP_QA), gui_base->get_icon("Instance", "EditorIcons"));
- p->set_item_icon(p->get_item_index(HELP_ISSUES), gui_base->get_icon("Instance", "EditorIcons"));
- p->set_item_icon(p->get_item_index(HELP_COMMUNITY), gui_base->get_icon("Instance", "EditorIcons"));
- p->set_item_icon(p->get_item_index(HELP_ABOUT), gui_base->get_icon("Godot", "EditorIcons"));
+ PopupMenu *p = help_menu->get_popup();
+ p->set_item_icon(p->get_item_index(HELP_SEARCH), gui_base->get_icon("HelpSearch", "EditorIcons"));
+ p->set_item_icon(p->get_item_index(HELP_DOCS), gui_base->get_icon("Instance", "EditorIcons"));
+ p->set_item_icon(p->get_item_index(HELP_QA), gui_base->get_icon("Instance", "EditorIcons"));
+ p->set_item_icon(p->get_item_index(HELP_ISSUES), gui_base->get_icon("Instance", "EditorIcons"));
+ p->set_item_icon(p->get_item_index(HELP_COMMUNITY), gui_base->get_icon("Instance", "EditorIcons"));
+ p->set_item_icon(p->get_item_index(HELP_ABOUT), gui_base->get_icon("Godot", "EditorIcons"));
- _update_update_spinner();
- }
+ _update_update_spinner();
+ } break;
- if (p_what == Control::NOTIFICATION_RESIZED) {
- _update_scene_tabs();
+ case Control::NOTIFICATION_RESIZED: {
+ _update_scene_tabs();
+ } break;
}
}
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 1f601e64fa..d4eab888cc 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -860,20 +860,47 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
Ref<InputEventMouseButton> b = p_event;
Ref<InputEventMouseMotion> m = p_event;
- // Start dragging a guide
if (drag_type == DRAG_NONE) {
- if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
- if (show_guides && show_rulers && EditorNode::get_singleton()->get_edited_scene()) {
- Transform2D xform = viewport_scrollable->get_transform() * transform;
- // Retrieve the guide lists
- Array vguides;
- if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
- vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_");
+ if (show_guides && show_rulers && EditorNode::get_singleton()->get_edited_scene()) {
+ Transform2D xform = viewport_scrollable->get_transform() * transform;
+ // Retrieve the guide lists
+ Array vguides;
+ if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
+ vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_");
+ }
+ Array hguides;
+ if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) {
+ hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_");
+ }
+
+ // Hover over guides
+ float minimum = 1e20;
+ is_hovering_h_guide = false;
+ is_hovering_v_guide = false;
+
+ if (m.is_valid() && m->get_position().x < RULER_WIDTH) {
+ // Check if we are hovering an existing horizontal guide
+ for (int i = 0; i < hguides.size(); i++) {
+ if (ABS(xform.xform(Point2(0, hguides[i])).y - m->get_position().y) < MIN(minimum, 8)) {
+ is_hovering_h_guide = true;
+ is_hovering_v_guide = false;
+ break;
+ }
}
- Array hguides;
- if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) {
- hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_");
+
+ } else if (m.is_valid() && m->get_position().y < RULER_WIDTH) {
+ // Check if we are hovering an existing vertical guide
+ for (int i = 0; i < vguides.size(); i++) {
+ if (ABS(xform.xform(Point2(vguides[i], 0)).x - m->get_position().x) < MIN(minimum, 8)) {
+ is_hovering_v_guide = true;
+ is_hovering_h_guide = false;
+ break;
+ }
}
+ }
+
+ // Start dragging a guide
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
// Press button
if (b->get_position().x < RULER_WIDTH && b->get_position().y < RULER_WIDTH) {
@@ -883,7 +910,6 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
return true;
} else if (b->get_position().x < RULER_WIDTH) {
// Check if we drag an existing horizontal guide
- float minimum = 1e20;
dragged_guide_index = -1;
for (int i = 0; i < hguides.size(); i++) {
if (ABS(xform.xform(Point2(0, hguides[i])).y - b->get_position().y) < MIN(minimum, 8)) {
@@ -901,7 +927,6 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
return true;
} else if (b->get_position().y < RULER_WIDTH) {
// Check if we drag an existing vertical guide
- float minimum = 1e20;
dragged_guide_index = -1;
for (int i = 0; i < vguides.size(); i++) {
if (ABS(xform.xform(Point2(vguides[i], 0)).x - b->get_position().x) < MIN(minimum, 8)) {
@@ -956,14 +981,14 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
// Adds a new vertical guide
if (dragged_guide_index >= 0) {
vguides[dragged_guide_index] = edited.x;
- undo_redo->create_action(TTR("Move vertical guide"));
+ undo_redo->create_action(TTR("Move Vertical Guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
} else {
vguides.push_back(edited.x);
- undo_redo->create_action(TTR("Create new vertical guide"));
+ undo_redo->create_action(TTR("Create Vertical Guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
undo_redo->add_undo_method(viewport, "update");
@@ -972,7 +997,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
} else {
if (dragged_guide_index >= 0) {
vguides.remove(dragged_guide_index);
- undo_redo->create_action(TTR("Remove vertical guide"));
+ undo_redo->create_action(TTR("Remove Vertical Guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
undo_redo->add_undo_method(viewport, "update");
@@ -985,14 +1010,14 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
// Adds a new horizontal guide
if (dragged_guide_index >= 0) {
hguides[dragged_guide_index] = edited.y;
- undo_redo->create_action(TTR("Move horizontal guide"));
+ undo_redo->create_action(TTR("Move Horizontal Guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
} else {
hguides.push_back(edited.y);
- undo_redo->create_action(TTR("Create new horizontal guide"));
+ undo_redo->create_action(TTR("Create Horizontal Guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
undo_redo->add_undo_method(viewport, "update");
@@ -1001,7 +1026,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
} else {
if (dragged_guide_index >= 0) {
hguides.remove(dragged_guide_index);
- undo_redo->create_action(TTR("Remove horizontal guide"));
+ undo_redo->create_action(TTR("Remove Horizontal Guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
undo_redo->add_undo_method(viewport, "update");
@@ -1015,7 +1040,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
// Adds a new horizontal guide a new vertical guide
vguides.push_back(edited.x);
hguides.push_back(edited.y);
- undo_redo->create_action(TTR("Create new horizontal and vertical guides"));
+ undo_redo->create_action(TTR("Create Horizontal and Vertical Guides"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
@@ -2221,8 +2246,6 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
//printf("Plugin\n");
} else if ((accepted = _gui_input_open_scene_on_double_click(p_event))) {
//printf("Open scene on double click\n");
- } else if ((accepted = _gui_input_anchors(p_event))) {
- //printf("Anchors\n");
} else if ((accepted = _gui_input_scale(p_event))) {
//printf("Set scale\n");
} else if ((accepted = _gui_input_pivot(p_event))) {
@@ -2233,6 +2256,8 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
//printf("Rotate\n");
} else if ((accepted = _gui_input_move(p_event))) {
//printf("Move\n");
+ } else if ((accepted = _gui_input_anchors(p_event))) {
+ //printf("Anchors\n");
} else if ((accepted = _gui_input_select(p_event))) {
//printf("Selection\n");
} else {
@@ -2268,14 +2293,17 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
break;
case DRAG_LEFT:
case DRAG_RIGHT:
+ case DRAG_V_GUIDE:
c = CURSOR_HSIZE;
break;
case DRAG_TOP:
case DRAG_BOTTOM:
+ case DRAG_H_GUIDE:
c = CURSOR_VSIZE;
break;
case DRAG_TOP_LEFT:
case DRAG_BOTTOM_RIGHT:
+ case DRAG_DOUBLE_GUIDE:
c = CURSOR_FDIAGSIZE;
break;
case DRAG_TOP_RIGHT:
@@ -2288,6 +2316,12 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
default:
break;
}
+
+ if (is_hovering_h_guide)
+ c = CURSOR_VSIZE;
+ else if (is_hovering_v_guide)
+ c = CURSOR_HSIZE;
+
viewport->set_default_cursor_shape(c);
// Grab focus
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index a46682d494..2a85b20424 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -371,6 +371,8 @@ private:
List<CanvasItem *> drag_selection;
int dragged_guide_index;
Point2 dragged_guide_pos;
+ bool is_hovering_h_guide;
+ bool is_hovering_v_guide;
bool updating_value_dialog;
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 9fd694ee0d..a593a92b97 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -283,7 +283,8 @@ void SpatialEditorViewport::_select_clicked(bool p_append, bool p_single) {
node = node->get_parent();
}
- _select(selected, clicked_wants_append, true);
+ if (!_is_node_locked(selected))
+ _select(selected, clicked_wants_append, true);
}
void SpatialEditorViewport::_select(Node *p_node, bool p_append, bool p_single) {
@@ -513,7 +514,7 @@ void SpatialEditorViewport::_select_region() {
for (int i = 0; i < instances.size(); i++) {
Spatial *sp = Object::cast_to<Spatial>(ObjectDB::get_instance(instances[i]));
- if (!sp)
+ if (!sp && _is_node_locked(sp))
continue;
Node *item = Object::cast_to<Node>(sp);
@@ -536,6 +537,8 @@ void SpatialEditorViewport::_select_region() {
if (selected.find(item) != -1) continue;
+ if (_is_node_locked(Object::cast_to<Spatial>(item))) continue;
+
Ref<EditorSpatialGizmo> seg = sp->get_gizmo();
if (!seg.is_valid())
@@ -833,7 +836,9 @@ void SpatialEditorViewport::_surface_focus_exit() {
view_menu->set_disable_shortcuts(true);
}
-
+bool SpatialEditorViewport ::_is_node_locked(const Node *p_node) {
+ return p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_");
+}
void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) {
_find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift());
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index b4e2f028d2..1a32d6e047 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -364,7 +364,7 @@ private:
Camera *preview;
bool previewing_cinema;
-
+ bool _is_node_locked(const Node *p_node);
void _preview_exited_scene();
void _toggle_camera_preview(bool);
void _toggle_cinema_preview(bool);
diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp
index a7e8dec11e..bd7aeeebeb 100644
--- a/modules/bmp/image_loader_bmp.cpp
+++ b/modules/bmp/image_loader_bmp.cpp
@@ -257,8 +257,8 @@ Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f,
if (bmp_header.bmp_info_header.bmp_bit_count <= 8) {
// Support 256 colors max
color_table_size = 1 << bmp_header.bmp_info_header.bmp_bit_count;
+ ERR_FAIL_COND_V(color_table_size == 0, ERR_BUG);
}
- ERR_FAIL_COND_V(color_table_size == 0, ERR_BUG);
PoolVector<uint8_t> bmp_color_table;
// Color table is usually 4 bytes per color -> [B][G][R][0]
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index 78a1bfc99b..c4937f023b 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -161,6 +161,10 @@ bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &
funcs[cl->subclasses[i]->functions[j]->line] = String(cl->subclasses[i]->name) + "." + String(cl->subclasses[i]->functions[j]->name);
}
+ for (int j = 0; j < cl->subclasses[i]->static_functions.size(); j++) {
+
+ funcs[cl->subclasses[i]->static_functions[j]->line] = String(cl->subclasses[i]->name) + "." + String(cl->subclasses[i]->static_functions[j]->name);
+ }
}
for (Map<int, String>::Element *E = funcs.front(); E; E = E->next()) {
diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp
index 12e53054bc..87dc6421ac 100644
--- a/platform/server/os_server.cpp
+++ b/platform/server/os_server.cpp
@@ -88,6 +88,8 @@ Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int
visual_server = memnew(VisualServerRaster);
visual_server->init();
+ camera_server = memnew(CameraServer);
+
AudioDriverManager::initialize(p_audio_driver);
input = memnew(InputDefault);
@@ -117,6 +119,8 @@ void OS_Server::finalize() {
memdelete(input);
+ memdelete(camera_server);
+
memdelete(power_manager);
ResourceLoader::remove_resource_format_loader(resource_loader_dummy);
diff --git a/platform/server/os_server.h b/platform/server/os_server.h
index e3488a693d..dbdae6afb1 100644
--- a/platform/server/os_server.h
+++ b/platform/server/os_server.h
@@ -74,6 +74,7 @@ class OS_Server : public OS_Unix {
#endif
CrashHandler crash_handler;
+ CameraServer *camera_server;
int video_driver_index;
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index ff28f60d4f..054c211d23 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -974,7 +974,7 @@ void AudioStreamPlayer3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "emission_angle_degrees", PROPERTY_HINT_RANGE, "0.1,90,0.1"), "set_emission_angle", "get_emission_angle");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "emission_angle_filter_attenuation_db", PROPERTY_HINT_RANGE, "-80,0,0.1"), "set_emission_angle_filter_attenuation_db", "get_emission_angle_filter_attenuation_db");
ADD_GROUP("Attenuation Filter", "attenuation_filter_");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation_filter_cutoff_hz", PROPERTY_HINT_RANGE, "50,50000,1"), "set_attenuation_filter_cutoff_hz", "get_attenuation_filter_cutoff_hz");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation_filter_cutoff_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_attenuation_filter_cutoff_hz", "get_attenuation_filter_cutoff_hz");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation_filter_db", PROPERTY_HINT_RANGE, "-80,0,0.1"), "set_attenuation_filter_db", "get_attenuation_filter_db");
ADD_GROUP("Doppler", "doppler_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics"), "set_doppler_tracking", "get_doppler_tracking");
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 3dcbf64e7c..d5347edb87 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -999,6 +999,8 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
Ref<StyleBox> style = get_stylebox("normal");
int pixel_ofs = 0;
Size2 size = get_size();
+ bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled;
+ int r_icon_width = Control::get_icon("clear")->get_width();
switch (align) {
@@ -1013,10 +1015,16 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
pixel_ofs = int(style->get_offset().x);
else
pixel_ofs = int(size.width - (cached_width)) / 2;
+
+ if (display_clear_icon)
+ pixel_ofs -= int(r_icon_width / 2 + style->get_margin(MARGIN_RIGHT));
} break;
case ALIGN_RIGHT: {
pixel_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_width));
+
+ if (display_clear_icon)
+ pixel_ofs -= int(r_icon_width + style->get_margin(MARGIN_RIGHT));
} break;
}
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp
index 4b3e392013..5b61654c5d 100644
--- a/scene/resources/audio_stream_sample.cpp
+++ b/scene/resources/audio_stream_sample.cpp
@@ -564,7 +564,8 @@ Error AudioStreamSample::save_to_wav(const String &p_path) {
file->store_32(sub_chunk_2_size); //Subchunk2Size
// Add data
- PoolVector<uint8_t>::Read read_data = get_data().read();
+ PoolVector<uint8_t> data = get_data();
+ PoolVector<uint8_t>::Read read_data = data.read();
switch (format) {
case AudioStreamSample::FORMAT_8_BITS:
for (unsigned int i = 0; i < data_bytes; i++) {
diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp
index c2f8b97c1a..216a0a4aa6 100644
--- a/servers/audio/effects/audio_effect_chorus.cpp
+++ b/servers/audio/effects/audio_effect_chorus.cpp
@@ -333,28 +333,28 @@ void AudioEffectChorus::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/rate_hz", PROPERTY_HINT_RANGE, "0.1,20,0.1"), "set_voice_rate_hz", "get_voice_rate_hz", 0);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/depth_ms", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_voice_depth_ms", "get_voice_depth_ms", 0);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/level_db", PROPERTY_HINT_RANGE, "-60,24,0.1"), "set_voice_level_db", "get_voice_level_db", 0);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/cutoff_hz", PROPERTY_HINT_RANGE, "1,16000,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 0);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/cutoff_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 0);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/1/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_voice_pan", "get_voice_pan", 0);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/delay_ms", PROPERTY_HINT_RANGE, "0,50,0.01"), "set_voice_delay_ms", "get_voice_delay_ms", 1);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/rate_hz", PROPERTY_HINT_RANGE, "0.1,20,0.1"), "set_voice_rate_hz", "get_voice_rate_hz", 1);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/depth_ms", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_voice_depth_ms", "get_voice_depth_ms", 1);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/level_db", PROPERTY_HINT_RANGE, "-60,24,0.1"), "set_voice_level_db", "get_voice_level_db", 1);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/cutoff_hz", PROPERTY_HINT_RANGE, "1,16000,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 1);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/cutoff_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 1);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/2/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_voice_pan", "get_voice_pan", 1);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/delay_ms", PROPERTY_HINT_RANGE, "0,50,0.01"), "set_voice_delay_ms", "get_voice_delay_ms", 2);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/rate_hz", PROPERTY_HINT_RANGE, "0.1,20,0.1"), "set_voice_rate_hz", "get_voice_rate_hz", 2);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/depth_ms", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_voice_depth_ms", "get_voice_depth_ms", 2);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/level_db", PROPERTY_HINT_RANGE, "-60,24,0.1"), "set_voice_level_db", "get_voice_level_db", 2);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/cutoff_hz", PROPERTY_HINT_RANGE, "1,16000,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 2);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/cutoff_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 2);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/3/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_voice_pan", "get_voice_pan", 2);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/delay_ms", PROPERTY_HINT_RANGE, "0,50,0.01"), "set_voice_delay_ms", "get_voice_delay_ms", 3);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/rate_hz", PROPERTY_HINT_RANGE, "0.1,20,0.1"), "set_voice_rate_hz", "get_voice_rate_hz", 3);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/depth_ms", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_voice_depth_ms", "get_voice_depth_ms", 3);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/level_db", PROPERTY_HINT_RANGE, "-60,24,0.1"), "set_voice_level_db", "get_voice_level_db", 3);
- ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/cutoff_hz", PROPERTY_HINT_RANGE, "1,16000,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 3);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/cutoff_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_voice_cutoff_hz", "get_voice_cutoff_hz", 3);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "voice/4/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_voice_pan", "get_voice_pan", 3);
}
diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp
index 37305bd7f4..278647c304 100644
--- a/servers/audio/effects/audio_effect_distortion.cpp
+++ b/servers/audio/effects/audio_effect_distortion.cpp
@@ -173,7 +173,7 @@ void AudioEffectDistortion::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Clip,ATan,LoFi,Overdrive,WaveShape"), "set_mode", "get_mode");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "pre_gain", PROPERTY_HINT_RANGE, "-60,60,0.01"), "set_pre_gain", "get_pre_gain");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "keep_hf_hz", PROPERTY_HINT_RANGE, "1,20000,1"), "set_keep_hf_hz", "get_keep_hf_hz");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "keep_hf_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_keep_hf_hz", "get_keep_hf_hz");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "drive", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drive", "get_drive");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "post_gain", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_post_gain", "get_post_gain");
diff --git a/servers/audio/effects/audio_effect_filter.cpp b/servers/audio/effects/audio_effect_filter.cpp
index dc86d6ffbb..3841f2b5a0 100644
--- a/servers/audio/effects/audio_effect_filter.cpp
+++ b/servers/audio/effects/audio_effect_filter.cpp
@@ -156,7 +156,7 @@ void AudioEffectFilter::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_db", "amount"), &AudioEffectFilter::set_db);
ClassDB::bind_method(D_METHOD("get_db"), &AudioEffectFilter::get_db);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "cutoff_hz", PROPERTY_HINT_RANGE, "1,40000,0.1"), "set_cutoff", "get_cutoff");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "cutoff_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_cutoff", "get_cutoff");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "resonance", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_resonance", "get_resonance");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "gain", PROPERTY_HINT_RANGE, "0,4,0.01"), "set_gain", "get_gain");
ADD_PROPERTY(PropertyInfo(Variant::INT, "db", PROPERTY_HINT_ENUM, "6 dB,12 dB,18 dB,24 dB"), "set_db", "get_db");
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 58028962b1..14fefbf195 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -785,6 +785,17 @@ ShaderLanguage::DataPrecision ShaderLanguage::get_token_precision(TokenType p_ty
return PRECISION_MEDIUMP;
}
+String ShaderLanguage::get_precision_name(DataPrecision p_type) {
+ switch (p_type) {
+ case PRECISION_LOWP: return "lowp";
+ case PRECISION_MEDIUMP: return "mediump";
+ case PRECISION_HIGHP: return "highp";
+ default:
+ break;
+ }
+ return "";
+}
+
String ShaderLanguage::get_datatype_name(DataType p_type) {
switch (p_type) {
@@ -3803,6 +3814,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
tk = _get_token();
if (tk.type == TK_BRACKET_OPEN) {
+ bool unknown_size = false;
ArrayDeclarationNode *node = alloc_node<ArrayDeclarationNode>();
node->datatype = type;
@@ -3815,22 +3827,177 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
tk = _get_token();
- if (tk.type != TK_INT_CONSTANT || ((int)tk.constant) <= 0) {
- _set_error("Expected integer constant > 0");
- return ERR_PARSE_ERROR;
- }
+ if (tk.type == TK_BRACKET_CLOSE) {
+ unknown_size = true;
+ } else {
- tk = _get_token();
+ if (tk.type != TK_INT_CONSTANT || ((int)tk.constant) <= 0) {
+ _set_error("Expected integer constant > 0 or ']'");
+ return ERR_PARSE_ERROR;
+ }
- if (tk.type != TK_BRACKET_CLOSE) {
- _set_error("Expected ']'");
- return ERR_PARSE_ERROR;
+ tk = _get_token();
+
+ if (tk.type != TK_BRACKET_CLOSE) {
+ _set_error("Expected ']'");
+ return ERR_PARSE_ERROR;
+ }
+
+ decl.size = ((uint32_t)tk.constant);
+ var.array_size = decl.size;
}
- decl.size = ((uint32_t)tk.constant);
- var.array_size = decl.size;
+ bool full_def = false;
tk = _get_token();
+ if (tk.type == TK_OP_ASSIGN) {
+ tk = _get_token();
+
+ if (tk.type != TK_CURLY_BRACKET_OPEN) {
+
+ if (unknown_size) {
+ _set_error("Expected '{'");
+ return ERR_PARSE_ERROR;
+ }
+
+ full_def = true;
+
+ DataPrecision precision2 = PRECISION_DEFAULT;
+ if (is_token_precision(tk.type)) {
+ precision2 = get_token_precision(tk.type);
+ tk = _get_token();
+ if (!is_token_nonvoid_datatype(tk.type)) {
+ _set_error("Expected datatype after precision");
+ return ERR_PARSE_ERROR;
+ }
+ }
+ if (!is_token_variable_datatype(tk.type)) {
+ _set_error("Invalid data type for array");
+ return ERR_PARSE_ERROR;
+ }
+ DataType type2 = get_token_datatype(tk.type);
+
+ int array_size2 = 0;
+
+ tk = _get_token();
+ if (tk.type == TK_BRACKET_OPEN) {
+ Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
+ if (!n || n->type != Node::TYPE_CONSTANT || n->get_datatype() != TYPE_INT) {
+ _set_error("Expected single integer constant > 0");
+ return ERR_PARSE_ERROR;
+ }
+
+ ConstantNode *cnode = (ConstantNode *)n;
+ if (cnode->values.size() == 1) {
+ array_size2 = cnode->values[0].sint;
+ if (array_size2 <= 0) {
+ _set_error("Expected single integer constant > 0");
+ return ERR_PARSE_ERROR;
+ }
+ } else {
+ _set_error("Expected single integer constant > 0");
+ return ERR_PARSE_ERROR;
+ }
+
+ tk = _get_token();
+ if (tk.type != TK_BRACKET_CLOSE) {
+ _set_error("Expected ']");
+ return ERR_PARSE_ERROR;
+ } else {
+ tk = _get_token();
+ }
+ } else {
+ _set_error("Expected '[");
+ return ERR_PARSE_ERROR;
+ }
+
+ if (precision != precision2 || type != type2 || var.array_size != array_size2) {
+ String error_str = "Cannot convert from '";
+ if (precision2 != PRECISION_DEFAULT) {
+ error_str += get_precision_name(precision2);
+ error_str += " ";
+ }
+ error_str += get_datatype_name(type2);
+ error_str += "[";
+ error_str += itos(array_size2);
+ error_str += "]'";
+ error_str += " to '";
+ if (precision != PRECISION_DEFAULT) {
+ error_str += get_precision_name(precision);
+ error_str += " ";
+ }
+ error_str += get_datatype_name(type);
+ error_str += "[";
+ error_str += itos(var.array_size);
+ error_str += "]'";
+ _set_error(error_str);
+ return ERR_PARSE_ERROR;
+ }
+ }
+
+ bool curly = tk.type == TK_CURLY_BRACKET_OPEN;
+
+ if (unknown_size) {
+ if (!curly) {
+ _set_error("Expected '{'");
+ return ERR_PARSE_ERROR;
+ }
+ } else {
+ if (full_def) {
+ if (curly) {
+ _set_error("Expected '('");
+ return ERR_PARSE_ERROR;
+ }
+ }
+ }
+
+ if (tk.type == TK_PARENTHESIS_OPEN || curly) { // initialization
+ while (true) {
+
+ Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
+ if (!n) {
+ return ERR_PARSE_ERROR;
+ }
+
+ if (var.type != n->get_datatype()) {
+ _set_error("Invalid assignment of '" + get_datatype_name(n->get_datatype()) + "' to '" + get_datatype_name(var.type) + "'");
+ return ERR_PARSE_ERROR;
+ }
+
+ tk = _get_token();
+ if (tk.type == TK_COMMA) {
+ decl.initializer.push_back(n);
+ continue;
+ } else if (!curly && tk.type == TK_PARENTHESIS_CLOSE) {
+ decl.initializer.push_back(n);
+ break;
+ } else if (curly && tk.type == TK_CURLY_BRACKET_CLOSE) {
+ decl.initializer.push_back(n);
+ break;
+ } else {
+ if (curly)
+ _set_error("Expected '}' or ','");
+ else
+ _set_error("Expected ')' or ','");
+ return ERR_PARSE_ERROR;
+ }
+ }
+ if (unknown_size) {
+ decl.size = decl.initializer.size();
+ var.array_size = decl.initializer.size();
+ } else if (decl.initializer.size() != var.array_size) {
+ _set_error("Array size mismatch");
+ return ERR_PARSE_ERROR;
+ }
+ tk = _get_token();
+ }
+ } else {
+ if (unknown_size) {
+ _set_error("Expected array initialization");
+ return ERR_PARSE_ERROR;
+ }
+ }
+
node->declarations.push_back(decl);
} else if (tk.type == TK_OP_ASSIGN) {
@@ -3878,11 +4045,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
} else if (tk.type == TK_SEMICOLON) {
break;
} else {
- if (var.array_size != 0U) {
- _set_error("Expected ',' or ';' or '[' after variable");
- } else {
- _set_error("Expected ',' or ';' after variable");
- }
+ _set_error("Expected ',' or ';' after variable");
return ERR_PARSE_ERROR;
}
}
diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h
index 33c862d4bf..8253bce468 100644
--- a/servers/visual/shader_language.h
+++ b/servers/visual/shader_language.h
@@ -376,6 +376,7 @@ public:
struct Declaration {
StringName name;
uint32_t size;
+ Vector<Node *> initializer;
};
Vector<Declaration> declarations;
@@ -588,6 +589,7 @@ public:
static DataInterpolation get_token_interpolation(TokenType p_type);
static bool is_token_precision(TokenType p_type);
static DataPrecision get_token_precision(TokenType p_type);
+ static String get_precision_name(DataPrecision p_type);
static String get_datatype_name(DataType p_type);
static bool is_token_nonvoid_datatype(TokenType p_type);
static bool is_token_operator(TokenType p_type);
diff --git a/thirdparty/README.md b/thirdparty/README.md
index cb29eadeca..c6817e2389 100644
--- a/thirdparty/README.md
+++ b/thirdparty/README.md
@@ -511,7 +511,7 @@ folder.
## xatlas
- Upstream: https://github.com/jpcy/xatlas
-- Version: git (b7d7bb, 2019)
+- Version: git (f65a664, 2019)
- License: MIT
Files extracted from upstream source:
diff --git a/thirdparty/xatlas/xatlas.cpp b/thirdparty/xatlas/xatlas.cpp
index c62be4e73a..1b30305cd4 100644
--- a/thirdparty/xatlas/xatlas.cpp
+++ b/thirdparty/xatlas/xatlas.cpp
@@ -299,29 +299,30 @@ static void *Realloc(void *ptr, size_t size, int /*tag*/, const char * /*file*/,
#if XA_PROFILE
#define XA_PROFILE_START(var) const clock_t var##Start = clock();
#define XA_PROFILE_END(var) internal::s_profile.var += clock() - var##Start;
-#define XA_PROFILE_PRINT(label, var) XA_PRINT("%s%.2f seconds (%g ms)\n", label, internal::clockToSeconds(internal::s_profile.var), internal::clockToMs(internal::s_profile.var));
+#define XA_PROFILE_PRINT_AND_RESET(label, var) XA_PRINT("%s%.2f seconds (%g ms)\n", label, internal::clockToSeconds(internal::s_profile.var), internal::clockToMs(internal::s_profile.var)); internal::s_profile.var = 0;
struct ProfileData
{
- clock_t addMeshConcurrent;
- std::atomic<clock_t> addMesh;
+ clock_t addMeshReal;
+ std::atomic<clock_t> addMeshThread;
std::atomic<clock_t> addMeshCreateColocals;
std::atomic<clock_t> addMeshCreateFaceGroups;
std::atomic<clock_t> addMeshCreateBoundaries;
- std::atomic<clock_t> addMeshCreateChartGroupsConcurrent;
- std::atomic<clock_t> addMeshCreateChartGroups;
- clock_t computeChartsConcurrent;
- std::atomic<clock_t> computeCharts;
+ std::atomic<clock_t> addMeshCreateChartGroupsReal;
+ std::atomic<clock_t> addMeshCreateChartGroupsThread;
+ clock_t computeChartsReal;
+ std::atomic<clock_t> computeChartsThread;
std::atomic<clock_t> atlasBuilder;
std::atomic<clock_t> atlasBuilderInit;
std::atomic<clock_t> atlasBuilderCreateInitialCharts;
std::atomic<clock_t> atlasBuilderGrowCharts;
std::atomic<clock_t> atlasBuilderMergeCharts;
- std::atomic<clock_t> createChartMeshes;
+ std::atomic<clock_t> createChartMeshesReal;
+ std::atomic<clock_t> createChartMeshesThread;
std::atomic<clock_t> fixChartMeshTJunctions;
std::atomic<clock_t> closeChartMeshHoles;
- clock_t parameterizeChartsConcurrent;
- std::atomic<clock_t> parameterizeCharts;
+ clock_t parameterizeChartsReal;
+ std::atomic<clock_t> parameterizeChartsThread;
std::atomic<clock_t> parameterizeChartsOrthogonal;
std::atomic<clock_t> parameterizeChartsLSCM;
std::atomic<clock_t> parameterizeChartsEvaluateQuality;
@@ -329,6 +330,7 @@ struct ProfileData
clock_t packChartsRasterize;
clock_t packChartsDilate;
clock_t packChartsFindLocation;
+ std::atomic<clock_t> packChartsFindLocationThread;
clock_t packChartsBlit;
};
@@ -346,7 +348,7 @@ static double clockToSeconds(clock_t c)
#else
#define XA_PROFILE_START(var)
#define XA_PROFILE_END(var)
-#define XA_PROFILE_PRINT(label, var)
+#define XA_PROFILE_PRINT_AND_RESET(label, var)
#endif
static constexpr float kPi = 3.14159265358979323846f;
@@ -641,6 +643,7 @@ static bool linesIntersect(const Vector2 &a1, const Vector2 &a2, const Vector2 &
struct Vector2i
{
+ Vector2i() {}
Vector2i(int32_t x, int32_t y) : x(x), y(y) {}
int32_t x, y;
@@ -3528,6 +3531,15 @@ private:
std::mutex m_mutex;
};
+struct Spinlock
+{
+ void lock() { while(m_lock.test_and_set(std::memory_order_acquire)) {} }
+ void unlock() { m_lock.clear(std::memory_order_release); }
+
+private:
+ std::atomic_flag m_lock = ATOMIC_FLAG_INIT;
+};
+
struct TaskGroupHandle
{
uint32_t value = UINT32_MAX;
@@ -3545,6 +3557,14 @@ class TaskScheduler
public:
TaskScheduler() : m_shutdown(false)
{
+ // Max with current task scheduler usage is 1 per thread + 1 deep nesting, but allow for some slop.
+ m_maxGroups = std::thread::hardware_concurrency() * 4;
+ m_groups = XA_ALLOC_ARRAY(MemTag::Default, TaskGroup, m_maxGroups);
+ for (uint32_t i = 0; i < m_maxGroups; i++) {
+ new (&m_groups[i]) TaskGroup();
+ m_groups[i].free = true;
+ m_groups[i].ref = 0;
+ }
m_workers.resize(std::thread::hardware_concurrency() <= 1 ? 1 : std::thread::hardware_concurrency() - 1);
for (uint32_t i = 0; i < m_workers.size(); i++) {
m_workers[i].wakeup = false;
@@ -3565,36 +3585,42 @@ public:
worker.thread->~thread();
XA_FREE(worker.thread);
}
- for (uint32_t i = 0; i < m_groups.size(); i++)
- destroyGroup(i);
+ for (uint32_t i = 0; i < m_maxGroups; i++)
+ m_groups[i].~TaskGroup();
+ XA_FREE(m_groups);
}
- void run(TaskGroupHandle *handle, Task task)
+ TaskGroupHandle createTaskGroup(uint32_t reserveSize = 0)
{
- // Allocate a task group if this is the first time using this handle.
- TaskGroup *group;
- if (handle->value == UINT32_MAX) {
- group = XA_NEW(MemTag::Default, TaskGroup);
- group->ref = 0;
- std::lock_guard<std::mutex> lock(m_groupsMutex);
- for (uint32_t i = 0; i < m_groups.size(); i++) {
- if (!m_groups[i]) {
- m_groups[i] = group;
- handle->value = i;
- break;
- }
- }
- if (handle->value == UINT32_MAX) {
- m_groups.push_back(group);
- handle->value = m_groups.size() - 1;
- }
- }
- group = m_groups[handle->value];
- {
- std::lock_guard<std::mutex> lock(group->queueMutex);
- group->queue.push_back(task);
- }
- group->ref++;
+ // Claim the first free group.
+ for (uint32_t i = 0; i < m_maxGroups; i++) {
+ TaskGroup &group = m_groups[i];
+ bool expected = true;
+ if (!group.free.compare_exchange_strong(expected, false))
+ continue;
+ group.queueLock.lock();
+ group.queueHead = 0;
+ group.queue.clear();
+ group.queue.reserve(reserveSize);
+ group.queueLock.unlock();
+ TaskGroupHandle handle;
+ handle.value = i;
+ return handle;
+ }
+ XA_DEBUG_ASSERT(false);
+ TaskGroupHandle handle;
+ handle.value = UINT32_MAX;
+ return handle;
+ }
+
+ void run(TaskGroupHandle handle, Task task)
+ {
+ XA_DEBUG_ASSERT(handle.value != UINT32_MAX);
+ TaskGroup &group = m_groups[handle.value];
+ group.queueLock.lock();
+ group.queue.push_back(task);
+ group.queueLock.unlock();
+ group.ref++;
// Wake up a worker to run this task.
for (uint32_t i = 0; i < m_workers.size(); i++) {
m_workers[i].wakeup = true;
@@ -3609,33 +3635,32 @@ public:
return;
}
// Run tasks from the group queue until empty.
- TaskGroup *group = m_groups[handle->value];
+ TaskGroup &group = m_groups[handle->value];
for (;;) {
Task *task = nullptr;
- {
- std::lock_guard<std::mutex> lock(group->queueMutex);
- if (group->queueHead < group->queue.size())
- task = &group->queue[group->queueHead++];
- }
+ group.queueLock.lock();
+ if (group.queueHead < group.queue.size())
+ task = &group.queue[group.queueHead++];
+ group.queueLock.unlock();
if (!task)
break;
task->func(task->userData);
- group->ref--;
+ group.ref--;
}
// Even though the task queue is empty, workers can still be running tasks.
- while (group->ref > 0)
+ while (group.ref > 0)
std::this_thread::yield();
- std::lock_guard<std::mutex> lock(m_groupsMutex);
- destroyGroup(handle->value);
+ group.free = true;
handle->value = UINT32_MAX;
}
private:
struct TaskGroup
{
+ std::atomic<bool> free;
Array<Task> queue; // Items are never removed. queueHead is incremented to pop items.
uint32_t queueHead = 0;
- std::mutex queueMutex;
+ Spinlock queueLock;
std::atomic<uint32_t> ref; // Increment when a task is enqueued, decrement when a task finishes.
};
@@ -3647,21 +3672,11 @@ private:
std::atomic<bool> wakeup;
};
- Array<TaskGroup *> m_groups;
- std::mutex m_groupsMutex;
+ TaskGroup *m_groups;
+ uint32_t m_maxGroups;
Array<Worker> m_workers;
std::atomic<bool> m_shutdown;
- void destroyGroup(uint32_t index)
- {
- TaskGroup *group = m_groups[index];
- m_groups[index] = nullptr;
- if (group) {
- group->~TaskGroup();
- XA_FREE(group);
- }
- }
-
static void workerThread(TaskScheduler *scheduler, Worker *worker)
{
std::unique_lock<std::mutex> lock(worker->mutex);
@@ -3674,18 +3689,17 @@ private:
// Look for a task in any of the groups and run it.
TaskGroup *group = nullptr;
Task *task = nullptr;
- {
- std::lock_guard<std::mutex> groupsLock(scheduler->m_groupsMutex);
- for (uint32_t i = 0; i < scheduler->m_groups.size(); i++) {
- group = scheduler->m_groups[i];
- if (!group)
- continue;
- std::lock_guard<std::mutex> queueLock(group->queueMutex);
- if (group->queueHead < group->queue.size()) {
- task = &group->queue[group->queueHead++];
- break;
- }
+ for (uint32_t i = 0; i < scheduler->m_maxGroups; i++) {
+ group = &scheduler->m_groups[i];
+ if (group->free || group->ref == 0)
+ continue;
+ group->queueLock.lock();
+ if (group->queueHead < group->queue.size()) {
+ task = &group->queue[group->queueHead++];
+ group->queueLock.unlock();
+ break;
}
+ group->queueLock.unlock();
}
if (!task)
break;
@@ -3705,23 +3719,19 @@ public:
destroyGroup({ i });
}
- void run(TaskGroupHandle *handle, Task task)
+ TaskGroupHandle createTaskGroup(uint32_t reserveSize = 0)
{
- if (handle->value == UINT32_MAX) {
- TaskGroup *group = XA_NEW(MemTag::Default, TaskGroup);
- for (uint32_t i = 0; i < m_groups.size(); i++) {
- if (!m_groups[i]) {
- m_groups[i] = group;
- handle->value = i;
- break;
- }
- }
- if (handle->value == UINT32_MAX) {
- m_groups.push_back(group);
- handle->value = m_groups.size() - 1;
- }
- }
- m_groups[handle->value]->queue.push_back(task);
+ TaskGroup *group = XA_NEW(MemTag::Default, TaskGroup);
+ group->queue.reserve(reserveSize);
+ m_groups.push_back(group);
+ TaskGroupHandle handle;
+ handle.value = m_groups.size() - 1;
+ return handle;
+ }
+
+ void run(TaskGroupHandle handle, Task task)
+ {
+ m_groups[handle.value]->queue.push_back(task);
}
void wait(TaskGroupHandle *handle)
@@ -5967,6 +5977,58 @@ private:
#endif
};
+struct CreateChartTaskArgs
+{
+ const Mesh *mesh;
+ const Array<uint32_t> *faceArray;
+ const Basis *basis;
+ uint32_t meshId;
+ uint32_t chartGroupId;
+ uint32_t chartId;
+ Chart **chart;
+};
+
+static void runCreateChartTask(void *userData)
+{
+ XA_PROFILE_START(createChartMeshesThread)
+ auto args = (CreateChartTaskArgs *)userData;
+ *(args->chart) = XA_NEW(MemTag::Default, Chart, args->mesh, *(args->faceArray), *(args->basis), args->meshId, args->chartGroupId, args->chartId);
+ XA_PROFILE_END(createChartMeshesThread)
+}
+
+struct ParameterizeChartTaskArgs
+{
+ Chart *chart;
+ ParameterizeFunc func;
+};
+
+static void runParameterizeChartTask(void *userData)
+{
+ auto args = (ParameterizeChartTaskArgs *)userData;
+ Mesh *mesh = args->chart->unifiedMesh();
+ XA_PROFILE_START(parameterizeChartsOrthogonal)
+#if 1
+ computeOrthogonalProjectionMap(mesh);
+#else
+ for (uint32_t i = 0; i < vertexCount; i++)
+ mesh->texcoord(i) = Vector2(dot(args->chart->basis().tangent, mesh->position(i)), dot(args->chart->basis().bitangent, mesh->position(i)));
+#endif
+ XA_PROFILE_END(parameterizeChartsOrthogonal)
+ args->chart->evaluateOrthoParameterizationQuality();
+ if (!args->chart->isOrtho() && !args->chart->isPlanar()) {
+ XA_PROFILE_START(parameterizeChartsLSCM)
+ if (args->func)
+ args->func(&mesh->position(0).x, &mesh->texcoord(0).x, mesh->vertexCount(), mesh->indices(), mesh->indexCount());
+ else if (args->chart->isDisk())
+ computeLeastSquaresConformalMap(mesh);
+ XA_PROFILE_END(parameterizeChartsLSCM)
+ args->chart->evaluateParameterizationQuality();
+ }
+ // @@ Check that parameterization quality is above a certain threshold.
+ // Transfer parameterization from unified mesh to chart mesh.
+ args->chart->transferParameterization();
+}
+
// Set of charts corresponding to mesh faces in the same face group.
class ChartGroup
{
@@ -6107,7 +6169,7 @@ public:
- emphasize roundness metrics to prevent those cases.
- If interior self-overlaps: preserve boundary parameterization and use mean-value map.
*/
- void computeCharts(const ChartOptions &options)
+ void computeCharts(TaskScheduler *taskScheduler, const ChartOptions &options)
{
m_chartOptions = options;
// This function may be called multiple times, so destroy existing charts.
@@ -6128,13 +6190,30 @@ public:
AtlasBuilder builder(m_mesh, nullptr, options);
runAtlasBuilder(builder, options);
XA_PROFILE_END(atlasBuilder)
- XA_PROFILE_START(createChartMeshes)
const uint32_t chartCount = builder.chartCount();
+ m_chartArray.resize(chartCount);
+ Array<CreateChartTaskArgs> taskArgs;
+ taskArgs.resize(chartCount);
+ for (uint32_t i = 0; i < chartCount; i++) {
+ CreateChartTaskArgs &args = taskArgs[i];
+ args.mesh = m_mesh;
+ args.faceArray = &builder.chartFaces(i);
+ args.basis = &builder.chartBasis(i);
+ args.meshId = m_sourceId;
+ args.chartGroupId = m_id;
+ args.chartId = i;
+ args.chart = &m_chartArray[i];
+ }
+ XA_PROFILE_START(createChartMeshesReal)
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartCount);
for (uint32_t i = 0; i < chartCount; i++) {
- Chart *chart = XA_NEW(MemTag::Default, Chart, m_mesh, builder.chartFaces(i), builder.chartBasis(i), m_sourceId, m_id, i);
- m_chartArray.push_back(chart);
+ Task task;
+ task.userData = &taskArgs[i];
+ task.func = runCreateChartTask;
+ taskScheduler->run(taskGroup, task);
}
- XA_PROFILE_END(createChartMeshes)
+ taskScheduler->wait(&taskGroup);
+ XA_PROFILE_END(createChartMeshesReal)
#endif
#if XA_DEBUG_EXPORT_OBJ_CHARTS
char filename[256];
@@ -6157,18 +6236,33 @@ public:
#endif
}
- void parameterizeCharts(ParameterizeFunc func)
+ void parameterizeCharts(TaskScheduler *taskScheduler, ParameterizeFunc func)
{
+ const uint32_t chartCount = m_chartArray.size();
+ Array<ParameterizeChartTaskArgs> taskArgs;
+ taskArgs.resize(chartCount);
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartCount);
+ for (uint32_t i = 0; i < chartCount; i++) {
+ ParameterizeChartTaskArgs &args = taskArgs[i];
+ args.chart = m_chartArray[i];
+ args.func = func;
+ Task task;
+ task.userData = &args;
+ task.func = runParameterizeChartTask;
+ taskScheduler->run(taskGroup, task);
+ }
+ taskScheduler->wait(&taskGroup);
#if XA_RECOMPUTE_CHARTS
+ // Find charts with invalid parameterizations.
Array<Chart *> invalidCharts;
- const uint32_t chartCount = m_chartArray.size();
for (uint32_t i = 0; i < chartCount; i++) {
Chart *chart = m_chartArray[i];
- parameterizeChart(chart, func);
const ParameterizationQuality &quality = chart->paramQuality();
if (quality.boundaryIntersection || quality.flippedTriangleCount > 0)
invalidCharts.push_back(chart);
}
+ if (invalidCharts.isEmpty())
+ return;
// Recompute charts with invalid parameterizations.
Array<uint32_t> meshFaces;
for (uint32_t i = 0; i < invalidCharts.size(); i++) {
@@ -6211,8 +6305,18 @@ public:
#endif
}
// Parameterize the new charts.
- for (uint32_t i = chartCount; i < m_chartArray.size(); i++)
- parameterizeChart(m_chartArray[i], func);
+ taskGroup = taskScheduler->createTaskGroup(m_chartArray.size() - chartCount);
+ taskArgs.resize(m_chartArray.size() - chartCount);
+ for (uint32_t i = chartCount; i < m_chartArray.size(); i++) {
+ ParameterizeChartTaskArgs &args = taskArgs[i - chartCount];
+ args.chart = m_chartArray[i];
+ args.func = func;
+ Task task;
+ task.userData = &args;
+ task.func = runParameterizeChartTask;
+ taskScheduler->run(taskGroup, task);
+ }
+ taskScheduler->wait(&taskGroup);
// Remove and delete the invalid charts.
for (uint32_t i = 0; i < invalidCharts.size(); i++) {
Chart *chart = invalidCharts[i];
@@ -6221,12 +6325,6 @@ public:
XA_FREE(chart);
m_paramDeletedChartsCount++;
}
-#else
- const uint32_t chartCount = m_chartArray.size();
- for (uint32_t i = 0; i < chartCount; i++) {
- Chart *chart = m_chartArray[i];
- parameterizeChart(chart, func);
- }
#endif
}
@@ -6269,32 +6367,6 @@ private:
XA_DEBUG_ASSERT(builder.facesLeft() == 0);
}
- void parameterizeChart(Chart *chart, ParameterizeFunc func)
- {
- Mesh *mesh = chart->unifiedMesh();
- XA_PROFILE_START(parameterizeChartsOrthogonal)
-#if 1
- computeOrthogonalProjectionMap(mesh);
-#else
- for (uint32_t i = 0; i < vertexCount; i++)
- mesh->texcoord(i) = Vector2(dot(chart->basis().tangent, mesh->position(i)), dot(chart->basis().bitangent, mesh->position(i)));
-#endif
- XA_PROFILE_END(parameterizeChartsOrthogonal)
- chart->evaluateOrthoParameterizationQuality();
- if (!chart->isOrtho() && !chart->isPlanar()) {
- XA_PROFILE_START(parameterizeChartsLSCM)
- if (func)
- func(&mesh->position(0).x, &mesh->texcoord(0).x, mesh->vertexCount(), mesh->indices(), mesh->indexCount());
- else if (chart->isDisk())
- computeLeastSquaresConformalMap(mesh);
- XA_PROFILE_END(parameterizeChartsLSCM)
- chart->evaluateParameterizationQuality();
- }
- // @@ Check that parameterization quality is above a certain threshold.
- // Transfer parameterization from unified mesh to chart mesh.
- chart->transferParameterization();
- }
-
void removeChart(const Chart *chart)
{
for (uint32_t i = 0; i < m_chartArray.size(); i++) {
@@ -6326,14 +6398,15 @@ struct CreateChartGroupTaskArgs
static void runCreateChartGroupTask(void *userData)
{
- XA_PROFILE_START(addMeshCreateChartGroups)
+ XA_PROFILE_START(addMeshCreateChartGroupsThread)
auto args = (CreateChartGroupTaskArgs *)userData;
*(args->chartGroup) = XA_NEW(MemTag::Default, ChartGroup, args->groupId, args->mesh, args->faceGroup);
- XA_PROFILE_END(addMeshCreateChartGroups)
+ XA_PROFILE_END(addMeshCreateChartGroupsThread)
}
struct ComputeChartsTaskArgs
{
+ TaskScheduler *taskScheduler;
ChartGroup *chartGroup;
const ChartOptions *options;
Progress *progress;
@@ -6341,18 +6414,19 @@ struct ComputeChartsTaskArgs
static void runComputeChartsJob(void *userData)
{
- ComputeChartsTaskArgs *args = (ComputeChartsTaskArgs *)userData;
+ auto args = (ComputeChartsTaskArgs *)userData;
if (args->progress->cancel)
return;
- XA_PROFILE_START(computeCharts)
- args->chartGroup->computeCharts(*args->options);
- XA_PROFILE_END(computeCharts)
+ XA_PROFILE_START(computeChartsThread)
+ args->chartGroup->computeCharts(args->taskScheduler, *args->options);
+ XA_PROFILE_END(computeChartsThread)
args->progress->value++;
args->progress->update();
}
struct ParameterizeChartsTaskArgs
{
+ TaskScheduler *taskScheduler;
ChartGroup *chartGroup;
ParameterizeFunc func;
Progress *progress;
@@ -6360,12 +6434,12 @@ struct ParameterizeChartsTaskArgs
static void runParameterizeChartsJob(void *userData)
{
- ParameterizeChartsTaskArgs *args = (ParameterizeChartsTaskArgs *)userData;
+ auto args = (ParameterizeChartsTaskArgs *)userData;
if (args->progress->cancel)
return;
- XA_PROFILE_START(parameterizeCharts)
- args->chartGroup->parameterizeCharts(args->func);
- XA_PROFILE_END(parameterizeCharts)
+ XA_PROFILE_START(parameterizeChartsThread)
+ args->chartGroup->parameterizeCharts(args->taskScheduler, args->func);
+ XA_PROFILE_END(parameterizeChartsThread)
args->progress->value++;
args->progress->update();
}
@@ -6460,12 +6534,12 @@ public:
args.groupId = g;
args.mesh = mesh;
}
- TaskGroupHandle taskGroup;
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartGroups.size());
for (uint32_t g = 0; g < chartGroups.size(); g++) {
Task task;
task.userData = &taskArgs[g];
task.func = runCreateChartGroupTask;
- taskScheduler->run(&taskGroup, task);
+ taskScheduler->run(taskGroup, task);
}
taskScheduler->wait(&taskGroup);
// Thread-safe append.
@@ -6481,29 +6555,39 @@ public:
{
m_chartsComputed = false;
m_chartsParameterized = false;
- uint32_t taskCount = 0;
+ // Ignore vertex maps.
+ uint32_t chartGroupCount = 0;
for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
if (!m_chartGroups[i]->isVertexMap())
- taskCount++;
+ chartGroupCount++;
}
- Progress progress(ProgressCategory::ComputeCharts, progressFunc, progressUserData, taskCount);
+ Progress progress(ProgressCategory::ComputeCharts, progressFunc, progressUserData, chartGroupCount);
Array<ComputeChartsTaskArgs> taskArgs;
- taskArgs.reserve(taskCount);
+ taskArgs.reserve(chartGroupCount);
for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
if (!m_chartGroups[i]->isVertexMap()) {
ComputeChartsTaskArgs args;
+ args.taskScheduler = taskScheduler;
args.chartGroup = m_chartGroups[i];
args.options = &options;
args.progress = &progress;
taskArgs.push_back(args);
}
}
- TaskGroupHandle taskGroup;
- for (uint32_t i = 0; i < taskCount; i++) {
+ // Sort chart groups by mesh indexCount.
+ m_chartGroupsRadix = RadixSort();
+ Array<float> chartGroupSortData;
+ chartGroupSortData.resize(chartGroupCount);
+ for (uint32_t i = 0; i < chartGroupCount; i++)
+ chartGroupSortData[i] = (float)taskArgs[i].chartGroup->mesh()->indexCount();
+ m_chartGroupsRadix.sort(chartGroupSortData);
+ // Larger chart group meshes are added first to reduce the chance of thread starvation.
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartGroupCount);
+ for (uint32_t i = 0; i < chartGroupCount; i++) {
Task task;
- task.userData = &taskArgs[i];
+ task.userData = &taskArgs[m_chartGroupsRadix.ranks()[chartGroupCount - i - 1]];
task.func = runComputeChartsJob;
- taskScheduler->run(&taskGroup, task);
+ taskScheduler->run(taskGroup, task);
}
taskScheduler->wait(&taskGroup);
if (progress.cancel)
@@ -6515,29 +6599,32 @@ public:
bool parameterizeCharts(TaskScheduler *taskScheduler, ParameterizeFunc func, ProgressFunc progressFunc, void *progressUserData)
{
m_chartsParameterized = false;
- uint32_t taskCount = 0;
+ // Ignore vertex maps.
+ uint32_t chartGroupCount = 0;
for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
if (!m_chartGroups[i]->isVertexMap())
- taskCount++;
+ chartGroupCount++;
}
- Progress progress(ProgressCategory::ParameterizeCharts, progressFunc, progressUserData, taskCount);
+ Progress progress(ProgressCategory::ParameterizeCharts, progressFunc, progressUserData, chartGroupCount);
Array<ParameterizeChartsTaskArgs> taskArgs;
- taskArgs.reserve(taskCount);
+ taskArgs.reserve(chartGroupCount);
for (uint32_t i = 0; i < m_chartGroups.size(); i++) {
if (!m_chartGroups[i]->isVertexMap()) {
ParameterizeChartsTaskArgs args;
+ args.taskScheduler = taskScheduler;
args.chartGroup = m_chartGroups[i];
args.func = func;
args.progress = &progress;
taskArgs.push_back(args);
}
}
- TaskGroupHandle taskGroup;
- for (uint32_t i = 0; i < taskCount; i++) {
+ // Larger chart group meshes are added first to reduce the chance of thread starvation.
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(chartGroupCount);
+ for (uint32_t i = 0; i < chartGroupCount; i++) {
Task task;
- task.userData = &taskArgs[i];
+ task.userData = &taskArgs[m_chartGroupsRadix.ranks()[chartGroupCount - i - 1]];
task.func = runParameterizeChartsJob;
- taskScheduler->run(&taskGroup, task);
+ taskScheduler->run(taskGroup, task);
}
taskScheduler->wait(&taskGroup);
if (progress.cancel)
@@ -6570,6 +6657,7 @@ private:
bool m_chartsComputed;
bool m_chartsParameterized;
Array<ChartGroup *> m_chartGroups;
+ RadixSort m_chartGroupsRadix; // By mesh indexCount.
Array<uint32_t> m_chartGroupSourceMeshes;
Array<Array<Vector2> > m_originalChartTexcoords;
};
@@ -6734,6 +6822,71 @@ struct Chart
uint32_t uniqueVertexCount() const { return uniqueVertices.isEmpty() ? vertexCount : uniqueVertices.size(); }
};
+struct FindChartLocationBruteForceTaskArgs
+{
+ std::atomic<bool> *finished; // One of the tasks found a location that doesn't expand the atlas.
+ Vector2i startPosition;
+ const BitImage *atlasBitImage;
+ const BitImage *chartBitImage;
+ const BitImage *chartBitImageRotated;
+ int w, h;
+ bool blockAligned, resizableAtlas, allowRotate;
+ // out
+ bool best_insideAtlas;
+ int best_metric, best_x, best_y, best_w, best_h, best_r;
+};
+
+static void runFindChartLocationBruteForceTask(void *userData)
+{
+ XA_PROFILE_START(packChartsFindLocationThread)
+ auto args = (FindChartLocationBruteForceTaskArgs *)userData;
+ args->best_metric = INT_MAX;
+ if (args->finished->load())
+ return;
+ // Try two different orientations.
+ for (int r = 0; r < 2; r++) {
+ int cw = args->chartBitImage->width();
+ int ch = args->chartBitImage->height();
+ if (r == 1) {
+ if (args->allowRotate)
+ swap(cw, ch);
+ else
+ break;
+ }
+ const int y = args->startPosition.y;
+ const int stepSize = args->blockAligned ? 4 : 1;
+ for (int x = args->startPosition.x; x <= args->w + stepSize; x += stepSize) { // + 1 not really necessary here.
+ if (!args->resizableAtlas && (x > (int)args->atlasBitImage->width() - cw || y > (int)args->atlasBitImage->height() - ch))
+ continue;
+ if (args->finished->load())
+ break;
+ // Early out if metric not better.
+ const int area = max(args->w, x + cw) * max(args->h, y + ch);
+ const int extents = max(max(args->w, x + cw), max(args->h, y + ch));
+ const int metric = extents * extents + area;
+ if (metric > args->best_metric)
+ continue;
+ // If metric is the same, pick the one closest to the origin.
+ if (metric == args->best_metric && max(x, y) >= max(args->best_x, args->best_y))
+ continue;
+ if (!args->atlasBitImage->canBlit(r == 1 ? *(args->chartBitImageRotated) : *(args->chartBitImage), x, y))
+ continue;
+ args->best_metric = metric;
+ args->best_insideAtlas = area == args->w * args->h;
+ args->best_x = x;
+ args->best_y = y;
+ args->best_w = cw;
+ args->best_h = ch;
+ args->best_r = r;
+ if (args->best_insideAtlas) {
+ args->finished->store(true);
+ break;
+ }
+ }
+ }
+ XA_PROFILE_END(packChartsFindLocationThread)
+}
+
struct Atlas
{
~Atlas()
@@ -6854,7 +7007,7 @@ struct Atlas
}
// Pack charts in the smallest possible rectangle.
- bool packCharts(const PackOptions &options, ProgressFunc progressFunc, void *progressUserData)
+ bool packCharts(TaskScheduler *taskScheduler, const PackOptions &options, ProgressFunc progressFunc, void *progressUserData)
{
if (progressFunc) {
if (!progressFunc(ProgressCategory::PackCharts, 0, progressUserData))
@@ -7069,7 +7222,7 @@ struct Atlas
chartStartPositions.push_back(Vector2i(0, 0));
}
XA_PROFILE_START(packChartsFindLocation)
- const bool foundLocation = findChartLocation(chartStartPositions[currentAtlas], options.bruteForce, m_bitImages[currentAtlas], &chartBitImage, &chartBitImageRotated, atlasWidth, atlasHeight, &best_x, &best_y, &best_cw, &best_ch, &best_r, options.blockAlign, resizableAtlas, chart->allowRotate);
+ const bool foundLocation = findChartLocation(taskScheduler, chartStartPositions[currentAtlas], options.bruteForce, m_bitImages[currentAtlas], &chartBitImage, &chartBitImageRotated, atlasWidth, atlasHeight, &best_x, &best_y, &best_cw, &best_ch, &best_r, options.blockAlign, resizableAtlas, chart->allowRotate);
XA_PROFILE_END(packChartsFindLocation)
if (firstChartInBitImage && !foundLocation) {
// Chart doesn't fit in an empty, newly allocated bitImage. texelsPerUnit must be too large for the resolution.
@@ -7181,65 +7334,66 @@ private:
// is occupied at this point. At the end we have many small charts and a large atlas with sparse holes. Finding those holes randomly is slow. A better approach would be to
// start stacking large charts as if they were tetris pieces. Once charts get small try to place them randomly. It may be interesting to try a intermediate strategy, first try
// along one axis and then try exhaustively along that axis.
- bool findChartLocation(const Vector2i &startPosition, bool bruteForce, const BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, bool blockAligned, bool resizableAtlas, bool allowRotate)
+ bool findChartLocation(TaskScheduler *taskScheduler, const Vector2i &startPosition, bool bruteForce, const BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, bool blockAligned, bool resizableAtlas, bool allowRotate)
{
const int attempts = 4096;
if (bruteForce || attempts >= w * h)
- return findChartLocation_bruteForce(startPosition, atlasBitImage, chartBitImage, chartBitImageRotated, w, h, best_x, best_y, best_w, best_h, best_r, blockAligned, resizableAtlas, allowRotate);
+ return findChartLocation_bruteForce(taskScheduler, startPosition, atlasBitImage, chartBitImage, chartBitImageRotated, w, h, best_x, best_y, best_w, best_h, best_r, blockAligned, resizableAtlas, allowRotate);
return findChartLocation_random(atlasBitImage, chartBitImage, chartBitImageRotated, w, h, best_x, best_y, best_w, best_h, best_r, attempts, blockAligned, resizableAtlas, allowRotate);
}
- bool findChartLocation_bruteForce(const Vector2i &startPosition, const BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, bool blockAligned, bool resizableAtlas, bool allowRotate)
+ bool findChartLocation_bruteForce(TaskScheduler *taskScheduler, const Vector2i &startPosition, const BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, bool blockAligned, bool resizableAtlas, bool allowRotate)
{
- bool result = false;
- const int BLOCK_SIZE = 4;
+ const int stepSize = blockAligned ? 4 : 1;
+ uint32_t taskCount = 0;
+ for (int y = startPosition.y; y <= h + stepSize; y += stepSize)
+ taskCount++;
+ Array<FindChartLocationBruteForceTaskArgs> taskArgs;
+ taskArgs.resize(taskCount);
+ TaskGroupHandle taskGroup = taskScheduler->createTaskGroup(taskCount);
+ std::atomic<bool> finished(false); // One of the tasks found a location that doesn't expand the atlas.
+ uint32_t i = 0;
+ for (int y = startPosition.y; y <= h + stepSize; y += stepSize) {
+ FindChartLocationBruteForceTaskArgs &args = taskArgs[i];
+ args.finished = &finished;
+ args.startPosition = Vector2i(y == startPosition.y ? startPosition.x : 0, y);
+ args.atlasBitImage = atlasBitImage;
+ args.chartBitImage = chartBitImage;
+ args.chartBitImageRotated = chartBitImageRotated;
+ args.w = w;
+ args.h = h;
+ args.blockAligned = blockAligned;
+ args.resizableAtlas = resizableAtlas;
+ args.allowRotate = allowRotate;
+ Task task;
+ task.userData = &taskArgs[i];
+ task.func = runFindChartLocationBruteForceTask;
+ taskScheduler->run(taskGroup, task);
+ i++;
+ }
+ taskScheduler->wait(&taskGroup);
+ // Find the task result with the best metric.
int best_metric = INT_MAX;
- int step_size = blockAligned ? BLOCK_SIZE : 1;
- // Try two different orientations.
- for (int r = 0; r < 2; r++) {
- int cw = chartBitImage->width();
- int ch = chartBitImage->height();
- if (r == 1) {
- if (allowRotate)
- swap(cw, ch);
- else
- break;
- }
- for (int y = startPosition.y; y <= h + step_size; y += step_size) { // + 1 to extend atlas in case atlas full.
- for (int x = (y == startPosition.y ? startPosition.x : 0); x <= w + step_size; x += step_size) { // + 1 not really necessary here.
- if (!resizableAtlas && (x > (int)atlasBitImage->width() - cw || y > (int)atlasBitImage->height() - ch))
- continue;
- // Early out.
- int area = max(w, x + cw) * max(h, y + ch);
- //int perimeter = max(w, x+cw) + max(h, y+ch);
- int extents = max(max(w, x + cw), max(h, y + ch));
- int metric = extents * extents + area;
- if (metric > best_metric) {
- continue;
- }
- if (metric == best_metric && max(x, y) >= max(*best_x, *best_y)) {
- // If metric is the same, pick the one closest to the origin.
- continue;
- }
- if (atlasBitImage->canBlit(r == 1 ? *chartBitImageRotated : *chartBitImage, x, y)) {
- result = true;
- best_metric = metric;
- *best_x = x;
- *best_y = y;
- *best_w = cw;
- *best_h = ch;
- *best_r = r;
- if (area == w * h) {
- // Chart is completely inside, do not look at any other location.
- goto done;
- }
- }
- }
- }
+ bool best_insideAtlas = false;
+ for (i = 0; i < taskCount; i++) {
+ FindChartLocationBruteForceTaskArgs &args = taskArgs[i];
+ if (args.best_metric > best_metric)
+ continue;
+ // A location that doesn't expand the atlas is always preferred.
+ if (!args.best_insideAtlas && best_insideAtlas)
+ continue;
+ // If metric is the same, pick the one closest to the origin.
+ if (args.best_insideAtlas == best_insideAtlas && args.best_metric == best_metric && max(args.best_x, args.best_y) >= max(*best_x, *best_y))
+ continue;
+ best_metric = args.best_metric;
+ best_insideAtlas = args.best_insideAtlas;
+ *best_x = args.best_x;
+ *best_y = args.best_y;
+ *best_w = args.best_w;
+ *best_h = args.best_h;
+ *best_r = args.best_r;
}
- done:
- XA_DEBUG_ASSERT (best_metric != INT_MAX);
- return result;
+ return best_metric != INT_MAX;
}
bool findChartLocation_random(const BitImage *atlasBitImage, const BitImage *chartBitImage, const BitImage *chartBitImageRotated, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, int minTrialCount, bool blockAligned, bool resizableAtlas, bool allowRotate)
@@ -7439,25 +7593,31 @@ struct AddMeshTaskArgs
static void runAddMeshTask(void *userData)
{
- XA_PROFILE_START(addMesh)
+ XA_PROFILE_START(addMeshThread)
auto args = (AddMeshTaskArgs *)userData; // Responsible for freeing this.
internal::Mesh *mesh = args->mesh;
internal::Progress *progress = args->ctx->addMeshProgress;
if (progress->cancel)
goto cleanup;
- XA_PROFILE_START(addMeshCreateColocals)
- mesh->createColocals();
- XA_PROFILE_END(addMeshCreateColocals)
+ {
+ XA_PROFILE_START(addMeshCreateColocals)
+ mesh->createColocals();
+ XA_PROFILE_END(addMeshCreateColocals)
+ }
if (progress->cancel)
goto cleanup;
- XA_PROFILE_START(addMeshCreateFaceGroups)
- mesh->createFaceGroups();
- XA_PROFILE_END(addMeshCreateFaceGroups)
+ {
+ XA_PROFILE_START(addMeshCreateFaceGroups)
+ mesh->createFaceGroups();
+ XA_PROFILE_END(addMeshCreateFaceGroups)
+ }
if (progress->cancel)
goto cleanup;
- XA_PROFILE_START(addMeshCreateBoundaries)
- mesh->createBoundaries();
- XA_PROFILE_END(addMeshCreateBoundaries)
+ {
+ XA_PROFILE_START(addMeshCreateBoundaries)
+ mesh->createBoundaries();
+ XA_PROFILE_END(addMeshCreateBoundaries)
+ }
if (progress->cancel)
goto cleanup;
#if XA_DEBUG_EXPORT_OBJ_SOURCE_MESHES
@@ -7491,9 +7651,11 @@ static void runAddMeshTask(void *userData)
fclose(file);
}
#endif
- XA_PROFILE_START(addMeshCreateChartGroupsConcurrent)
- args->ctx->paramAtlas.addMesh(args->ctx->taskScheduler, mesh); // addMesh is thread safe
- XA_PROFILE_END(addMeshCreateChartGroupsConcurrent)
+ {
+ XA_PROFILE_START(addMeshCreateChartGroupsReal)
+ args->ctx->paramAtlas.addMesh(args->ctx->taskScheduler, mesh); // addMesh is thread safe
+ XA_PROFILE_END(addMeshCreateChartGroupsReal)
+ }
if (progress->cancel)
goto cleanup;
progress->value++;
@@ -7503,7 +7665,7 @@ cleanup:
XA_FREE(mesh);
args->~AddMeshTaskArgs();
XA_FREE(args);
- XA_PROFILE_END(addMesh)
+ XA_PROFILE_END(addMeshThread)
}
static internal::Vector3 DecodePosition(const MeshDecl &meshDecl, uint32_t index)
@@ -7547,12 +7709,13 @@ AddMeshError::Enum AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t mesh
XA_PRINT_WARNING("AddMesh: Meshes and UV meshes cannot be added to the same atlas.\n");
return AddMeshError::Error;
}
+#if XA_PROFILE
+ if (ctx->meshCount == 0)
+ internal::s_profile.addMeshReal = clock();
+#endif
// Don't know how many times AddMesh will be called, so progress needs to adjusted each time.
if (!ctx->addMeshProgress) {
ctx->addMeshProgress = XA_NEW(internal::MemTag::Default, internal::Progress, ProgressCategory::AddMesh, ctx->progressFunc, ctx->progressUserData, 1);
-#if XA_PROFILE
- internal::s_profile.addMeshConcurrent = clock();
-#endif
}
else {
ctx->addMeshProgress->setMaxValue(internal::max(ctx->meshCount + 1, meshCountHint));
@@ -7560,7 +7723,6 @@ AddMeshError::Enum AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t mesh
bool decoded = (meshDecl.indexCount <= 0);
uint32_t indexCount = decoded ? meshDecl.vertexCount : meshDecl.indexCount;
XA_PRINT("Adding mesh %d: %u vertices, %u triangles\n", ctx->meshCount, meshDecl.vertexCount, indexCount / 3);
- XA_PROFILE_START(addMesh)
// Expecting triangle faces.
if ((indexCount % 3) != 0)
return AddMeshError::InvalidIndexCount;
@@ -7629,15 +7791,16 @@ AddMeshError::Enum AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t mesh
ignore = true;
mesh->addFace(tri[0], tri[1], tri[2], ignore);
}
+ if (ctx->addMeshTaskGroup.value == UINT32_MAX)
+ ctx->addMeshTaskGroup = ctx->taskScheduler->createTaskGroup();
AddMeshTaskArgs *taskArgs = XA_NEW(internal::MemTag::Default, AddMeshTaskArgs); // The task frees this.
taskArgs->ctx = ctx;
taskArgs->mesh = mesh;
internal::Task task;
task.userData = taskArgs;
task.func = runAddMeshTask;
- ctx->taskScheduler->run(&ctx->addMeshTaskGroup, task);
+ ctx->taskScheduler->run(ctx->addMeshTaskGroup, task);
ctx->meshCount++;
- XA_PROFILE_END(addMesh)
return AddMeshError::Success;
}
@@ -7657,15 +7820,15 @@ void AddMeshJoin(Atlas *atlas)
ctx->addMeshProgress = nullptr;
#if XA_PROFILE
XA_PRINT("Added %u meshes\n", ctx->meshCount);
- internal::s_profile.addMeshConcurrent = clock() - internal::s_profile.addMeshConcurrent;
+ internal::s_profile.addMeshReal = clock() - internal::s_profile.addMeshReal;
#endif
- XA_PROFILE_PRINT(" Total (concurrent): ", addMeshConcurrent)
- XA_PROFILE_PRINT(" Total: ", addMesh)
- XA_PROFILE_PRINT(" Create colocals: ", addMeshCreateColocals)
- XA_PROFILE_PRINT(" Create face groups: ", addMeshCreateFaceGroups)
- XA_PROFILE_PRINT(" Create boundaries: ", addMeshCreateBoundaries)
- XA_PROFILE_PRINT(" Create chart groups (concurrent): ", addMeshCreateChartGroupsConcurrent)
- XA_PROFILE_PRINT(" Create chart groups: ", addMeshCreateChartGroups)
+ XA_PROFILE_PRINT_AND_RESET(" Total (real): ", addMeshReal)
+ XA_PROFILE_PRINT_AND_RESET(" Total (thread): ", addMeshThread)
+ XA_PROFILE_PRINT_AND_RESET(" Create colocals: ", addMeshCreateColocals)
+ XA_PROFILE_PRINT_AND_RESET(" Create face groups: ", addMeshCreateFaceGroups)
+ XA_PROFILE_PRINT_AND_RESET(" Create boundaries: ", addMeshCreateBoundaries)
+ XA_PROFILE_PRINT_AND_RESET(" Create chart groups (real): ", addMeshCreateChartGroupsReal)
+ XA_PROFILE_PRINT_AND_RESET(" Create chart groups (thread): ", addMeshCreateChartGroupsThread)
XA_PRINT_MEM_USAGE
}
@@ -7815,12 +7978,12 @@ void ComputeCharts(Atlas *atlas, ChartOptions chartOptions)
}
XA_PRINT("Computing charts\n");
uint32_t chartCount = 0, chartsWithHolesCount = 0, holesCount = 0, chartsWithTJunctionsCount = 0, tJunctionsCount = 0;
- XA_PROFILE_START(computeChartsConcurrent)
+ XA_PROFILE_START(computeChartsReal)
if (!ctx->paramAtlas.computeCharts(ctx->taskScheduler, chartOptions, ctx->progressFunc, ctx->progressUserData)) {
XA_PRINT(" Cancelled by user\n");
return;
}
- XA_PROFILE_END(computeChartsConcurrent)
+ XA_PROFILE_END(computeChartsReal)
// Count charts and print warnings.
for (uint32_t i = 0; i < ctx->meshCount; i++) {
for (uint32_t j = 0; j < ctx->paramAtlas.chartGroupCount(i); j++) {
@@ -7854,16 +8017,17 @@ void ComputeCharts(Atlas *atlas, ChartOptions chartOptions)
if (tJunctionsCount > 0)
XA_PRINT(" Fixed %u t-junctions in %u charts\n", tJunctionsCount, chartsWithTJunctionsCount);
XA_PRINT(" %u charts\n", chartCount);
- XA_PROFILE_PRINT(" Total (concurrent): ", computeChartsConcurrent)
- XA_PROFILE_PRINT(" Total: ", computeCharts)
- XA_PROFILE_PRINT(" Atlas builder: ", atlasBuilder)
- XA_PROFILE_PRINT(" Init: ", atlasBuilderInit)
- XA_PROFILE_PRINT(" Create initial charts: ", atlasBuilderCreateInitialCharts)
- XA_PROFILE_PRINT(" Grow charts: ", atlasBuilderGrowCharts)
- XA_PROFILE_PRINT(" Merge charts: ", atlasBuilderMergeCharts)
- XA_PROFILE_PRINT(" Create chart meshes: ", createChartMeshes)
- XA_PROFILE_PRINT(" Fix t-junctions: ", fixChartMeshTJunctions);
- XA_PROFILE_PRINT(" Close holes: ", closeChartMeshHoles)
+ XA_PROFILE_PRINT_AND_RESET(" Total (real): ", computeChartsReal)
+ XA_PROFILE_PRINT_AND_RESET(" Total (thread): ", computeChartsThread)
+ XA_PROFILE_PRINT_AND_RESET(" Atlas builder: ", atlasBuilder)
+ XA_PROFILE_PRINT_AND_RESET(" Init: ", atlasBuilderInit)
+ XA_PROFILE_PRINT_AND_RESET(" Create initial charts: ", atlasBuilderCreateInitialCharts)
+ XA_PROFILE_PRINT_AND_RESET(" Grow charts: ", atlasBuilderGrowCharts)
+ XA_PROFILE_PRINT_AND_RESET(" Merge charts: ", atlasBuilderMergeCharts)
+ XA_PROFILE_PRINT_AND_RESET(" Create chart meshes (real): ", createChartMeshesReal)
+ XA_PROFILE_PRINT_AND_RESET(" Create chart meshes (thread): ", createChartMeshesThread)
+ XA_PROFILE_PRINT_AND_RESET(" Fix t-junctions: ", fixChartMeshTJunctions)
+ XA_PROFILE_PRINT_AND_RESET(" Close holes: ", closeChartMeshHoles)
XA_PRINT_MEM_USAGE
}
@@ -7896,12 +8060,12 @@ void ParameterizeCharts(Atlas *atlas, ParameterizeFunc func)
}
DestroyOutputMeshes(ctx);
XA_PRINT("Parameterizing charts\n");
- XA_PROFILE_START(parameterizeChartsConcurrent)
+ XA_PROFILE_START(parameterizeChartsReal)
if (!ctx->paramAtlas.parameterizeCharts(ctx->taskScheduler, func, ctx->progressFunc, ctx->progressUserData)) {
XA_PRINT(" Cancelled by user\n");
return;
}
- XA_PROFILE_END(parameterizeChartsConcurrent)
+ XA_PROFILE_END(parameterizeChartsReal)
uint32_t chartCount = 0, orthoChartsCount = 0, planarChartsCount = 0, chartsAddedCount = 0, chartsDeletedCount = 0;
for (uint32_t i = 0; i < ctx->meshCount; i++) {
for (uint32_t j = 0; j < ctx->paramAtlas.chartGroupCount(i); j++) {
@@ -7982,11 +8146,11 @@ void ParameterizeCharts(Atlas *atlas, ParameterizeFunc func)
}
if (invalidParamCount > 0)
XA_PRINT_WARNING(" %u charts with invalid parameterizations\n", invalidParamCount);
- XA_PROFILE_PRINT(" Total (concurrent): ", parameterizeChartsConcurrent)
- XA_PROFILE_PRINT(" Total: ", parameterizeCharts)
- XA_PROFILE_PRINT(" Orthogonal: ", parameterizeChartsOrthogonal)
- XA_PROFILE_PRINT(" LSCM: ", parameterizeChartsLSCM)
- XA_PROFILE_PRINT(" Evaluate quality: ", parameterizeChartsEvaluateQuality)
+ XA_PROFILE_PRINT_AND_RESET(" Total (real): ", parameterizeChartsReal)
+ XA_PROFILE_PRINT_AND_RESET(" Total (thread): ", parameterizeChartsThread)
+ XA_PROFILE_PRINT_AND_RESET(" Orthogonal: ", parameterizeChartsOrthogonal)
+ XA_PROFILE_PRINT_AND_RESET(" LSCM: ", parameterizeChartsLSCM)
+ XA_PROFILE_PRINT_AND_RESET(" Evaluate quality: ", parameterizeChartsEvaluateQuality)
XA_PRINT_MEM_USAGE
}
@@ -8039,7 +8203,7 @@ void PackCharts(Atlas *atlas, PackOptions packOptions)
packAtlas.addChart(ctx->paramAtlas.chartAt(i));
}
XA_PROFILE_START(packCharts)
- if (!packAtlas.packCharts(packOptions, ctx->progressFunc, ctx->progressUserData))
+ if (!packAtlas.packCharts(ctx->taskScheduler, packOptions, ctx->progressFunc, ctx->progressUserData))
return;
XA_PROFILE_END(packCharts)
// Populate atlas object with pack results.
@@ -8058,19 +8222,13 @@ void PackCharts(Atlas *atlas, PackOptions packOptions)
for (uint32_t i = 0; i < atlas->atlasCount; i++)
packAtlas.getImages()[i]->copyTo(&atlas->image[atlas->width * atlas->height * i], atlas->width, atlas->height);
}
- XA_PROFILE_PRINT(" Total: ", packCharts)
- XA_PROFILE_PRINT(" Rasterize: ", packChartsRasterize)
- XA_PROFILE_PRINT(" Dilate (padding): ", packChartsDilate)
- XA_PROFILE_PRINT(" Find location: ", packChartsFindLocation)
- XA_PROFILE_PRINT(" Blit: ", packChartsBlit)
+ XA_PROFILE_PRINT_AND_RESET(" Total: ", packCharts)
+ XA_PROFILE_PRINT_AND_RESET(" Rasterize: ", packChartsRasterize)
+ XA_PROFILE_PRINT_AND_RESET(" Dilate (padding): ", packChartsDilate)
+ XA_PROFILE_PRINT_AND_RESET(" Find location (real): ", packChartsFindLocation)
+ XA_PROFILE_PRINT_AND_RESET(" Find location (thread): ", packChartsFindLocationThread)
+ XA_PROFILE_PRINT_AND_RESET(" Blit: ", packChartsBlit)
XA_PRINT_MEM_USAGE
-#if XA_PROFILE
- internal::s_profile.packCharts = 0;
- internal::s_profile.packChartsRasterize = 0;
- internal::s_profile.packChartsDilate = 0;
- internal::s_profile.packChartsFindLocation = 0;
- internal::s_profile.packChartsBlit = 0;
-#endif
XA_PRINT("Building output meshes\n");
int progress = 0;
if (ctx->progressFunc) {