diff options
-rw-r--r-- | doc/classes/String.xml | 2 | ||||
-rw-r--r-- | doc/classes/StringName.xml | 2 | ||||
-rw-r--r-- | editor/animation_track_editor_plugins.cpp | 88 | ||||
-rw-r--r-- | editor/import/dynamic_font_import_settings.cpp | 11 | ||||
-rw-r--r-- | editor/plugins/animation_blend_space_1d_editor.cpp | 34 | ||||
-rw-r--r-- | editor/plugins/animation_blend_space_2d_editor.cpp | 35 | ||||
-rw-r--r-- | editor/plugins/animation_blend_tree_editor_plugin.cpp | 59 | ||||
-rw-r--r-- | editor/plugins/animation_state_machine_editor.cpp | 51 | ||||
-rw-r--r-- | editor/plugins/animation_tree_editor_plugin.cpp | 13 | ||||
-rw-r--r-- | editor/plugins/animation_tree_editor_plugin.h | 1 | ||||
-rw-r--r-- | editor/plugins/tiles/tile_map_editor.cpp | 9 | ||||
-rw-r--r-- | editor/plugins/tiles/tile_map_editor.h | 2 | ||||
-rw-r--r-- | scene/2d/gpu_particles_2d.cpp | 6 | ||||
-rw-r--r-- | scene/animation/animation_tree.cpp | 2 | ||||
-rw-r--r-- | tests/scene/test_arraymesh.h | 4 | ||||
-rw-r--r-- | tests/scene/test_bit_map.h | 35 | ||||
-rw-r--r-- | tests/scene/test_curve.h | 3 |
17 files changed, 264 insertions, 93 deletions
diff --git a/doc/classes/String.xml b/doc/classes/String.xml index d5624aeaa2..653d53607e 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -237,7 +237,7 @@ <description> If the string is a valid file path, returns the base directory name. [codeblock] - var dir_path = "/path/to/file.txt".get_basename() # dir_path is "/path/to" + var dir_path = "/path/to/file.txt".get_base_dir() # dir_path is "/path/to" [/codeblock] </description> </method> diff --git a/doc/classes/StringName.xml b/doc/classes/StringName.xml index e3cb6517f3..44d78a46fb 100644 --- a/doc/classes/StringName.xml +++ b/doc/classes/StringName.xml @@ -220,7 +220,7 @@ <description> If the string is a valid file path, returns the base directory name. [codeblock] - var dir_path = "/path/to/file.txt".get_basename() # dir_path is "/path/to" + var dir_path = "/path/to/file.txt".get_base_dir() # dir_path is "/path/to" [/codeblock] </description> </method> diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index a5f6f449a6..704935e163 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -857,18 +857,14 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int float start_ofs = get_animation()->audio_track_get_key_start_offset(get_track(), p_index); float end_ofs = get_animation()->audio_track_get_key_end_offset(get_track(), p_index); + int px_offset = 0; if (len_resizing && p_index == len_resizing_index) { - float ofs_local = -len_resizing_rel / get_timeline()->get_zoom_scale(); + float ofs_local = len_resizing_rel / get_timeline()->get_zoom_scale(); if (len_resizing_start) { start_ofs += ofs_local; - if (start_ofs < 0) { - start_ofs = 0; - } + px_offset = ofs_local * p_pixels_sec; } else { - end_ofs += ofs_local; - if (end_ofs < 0) { - end_ofs = 0; - } + end_ofs -= ofs_local; } } @@ -897,8 +893,8 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int int pixel_len = len * p_pixels_sec; - int pixel_begin = p_x; - int pixel_end = p_x + pixel_len; + int pixel_begin = px_offset + p_x; + int pixel_end = px_offset + p_x + pixel_len; if (pixel_end < p_clip_left) { return; @@ -1061,9 +1057,6 @@ void AnimationTrackEditTypeAudio::gui_input(const Ref<InputEvent> &p_event) { len -= end_ofs; len -= start_ofs; - if (len <= 0.001) { - len = 0.001; - } if (get_animation()->track_get_key_count(get_track()) > i + 1) { len = MIN(len, get_animation()->track_get_key_time(get_track(), i + 1) - get_animation()->track_get_key_time(get_track(), i)); @@ -1078,6 +1071,13 @@ void AnimationTrackEditTypeAudio::gui_input(const Ref<InputEvent> &p_event) { int end = ofs + len * get_timeline()->get_zoom_scale(); if (end >= get_timeline()->get_name_limit() && end <= get_size().width - get_timeline()->get_buttons_width() && ABS(mm->get_position().x - end) < 5 * EDSCALE) { + len_resizing_start = false; + use_hsize_cursor = true; + len_resizing_index = i; + } + + if (ofs >= get_timeline()->get_name_limit() && ofs <= get_size().width - get_timeline()->get_buttons_width() && ABS(mm->get_position().x - ofs) < 5 * EDSCALE) { + len_resizing_start = true; use_hsize_cursor = true; len_resizing_index = i; } @@ -1086,8 +1086,25 @@ void AnimationTrackEditTypeAudio::gui_input(const Ref<InputEvent> &p_event) { } if (len_resizing && mm.is_valid()) { + // Rezising index is some. len_resizing_rel += mm->get_relative().x; - len_resizing_start = mm->is_shift_pressed(); + float ofs_local = len_resizing_rel / get_timeline()->get_zoom_scale(); + float prev_ofs_start = get_animation()->audio_track_get_key_start_offset(get_track(), len_resizing_index); + float prev_ofs_end = get_animation()->audio_track_get_key_end_offset(get_track(), len_resizing_index); + Ref<AudioStream> stream = get_animation()->audio_track_get_key_stream(get_track(), len_resizing_index); + float len = stream->get_length(); + if (len == 0) { + Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); + float preview_len = preview->get_length(); + len = preview_len; + } + + if (len_resizing_start) { + len_resizing_rel = CLAMP(ofs_local, -prev_ofs_start, len - prev_ofs_end - prev_ofs_start) * get_timeline()->get_zoom_scale(); + } else { + len_resizing_rel = CLAMP(ofs_local, -(len - prev_ofs_end - prev_ofs_start), prev_ofs_end) * get_timeline()->get_zoom_scale(); + } + queue_redraw(); accept_event(); return; @@ -1096,7 +1113,11 @@ void AnimationTrackEditTypeAudio::gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT && over_drag_position) { len_resizing = true; - len_resizing_start = mb->is_shift_pressed(); + // In case if resizing index is not set yet reset the flag. + if (len_resizing_index < 0) { + len_resizing = false; + return; + } len_resizing_from_px = mb->get_position().x; len_resizing_rel = 0; queue_redraw(); @@ -1106,23 +1127,42 @@ void AnimationTrackEditTypeAudio::gui_input(const Ref<InputEvent> &p_event) { Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); if (len_resizing && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { - float ofs_local = -len_resizing_rel / get_timeline()->get_zoom_scale(); + if (len_resizing_rel == 0 || len_resizing_index < 0) { + len_resizing = false; + return; + } + if (len_resizing_start) { + float ofs_local = len_resizing_rel / get_timeline()->get_zoom_scale(); float prev_ofs = get_animation()->audio_track_get_key_start_offset(get_track(), len_resizing_index); - undo_redo->create_action(TTR("Change Audio Track Clip Start Offset")); - undo_redo->add_do_method(get_animation().ptr(), "audio_track_set_key_start_offset", get_track(), len_resizing_index, prev_ofs + ofs_local); - undo_redo->add_undo_method(get_animation().ptr(), "audio_track_set_key_start_offset", get_track(), len_resizing_index, prev_ofs); - undo_redo->commit_action(); + float prev_time = get_animation()->track_get_key_time(get_track(), len_resizing_index); + float new_ofs = prev_ofs + ofs_local; + float new_time = prev_time + ofs_local; + if (prev_time != new_time) { + undo_redo->create_action(TTR("Change Audio Track Clip Start Offset")); + + undo_redo->add_do_method(get_animation().ptr(), "track_set_key_time", get_track(), len_resizing_index, new_time); + undo_redo->add_undo_method(get_animation().ptr(), "track_set_key_time", get_track(), len_resizing_index, prev_time); + + undo_redo->add_do_method(get_animation().ptr(), "audio_track_set_key_start_offset", get_track(), len_resizing_index, new_ofs); + undo_redo->add_undo_method(get_animation().ptr(), "audio_track_set_key_start_offset", get_track(), len_resizing_index, prev_ofs); + undo_redo->commit_action(); + } } else { + float ofs_local = -len_resizing_rel / get_timeline()->get_zoom_scale(); float prev_ofs = get_animation()->audio_track_get_key_end_offset(get_track(), len_resizing_index); - undo_redo->create_action(TTR("Change Audio Track Clip End Offset")); - undo_redo->add_do_method(get_animation().ptr(), "audio_track_set_key_end_offset", get_track(), len_resizing_index, prev_ofs + ofs_local); - undo_redo->add_undo_method(get_animation().ptr(), "audio_track_set_key_end_offset", get_track(), len_resizing_index, prev_ofs); - undo_redo->commit_action(); + float new_ofs = prev_ofs + ofs_local; + if (prev_ofs != new_ofs) { + undo_redo->create_action(TTR("Change Audio Track Clip End Offset")); + undo_redo->add_do_method(get_animation().ptr(), "audio_track_set_key_end_offset", get_track(), len_resizing_index, new_ofs); + undo_redo->add_undo_method(get_animation().ptr(), "audio_track_set_key_end_offset", get_track(), len_resizing_index, prev_ofs); + undo_redo->commit_action(); + } } len_resizing_index = -1; + len_resizing = false; queue_redraw(); accept_event(); return; diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp index 75d0abbb0c..afcfacdf75 100644 --- a/editor/import/dynamic_font_import_settings.cpp +++ b/editor/import/dynamic_font_import_settings.cpp @@ -954,9 +954,18 @@ void DynamicFontImportSettings::_re_import() { Dictionary preload_config; preload_config["name"] = vars_item->get_text(0); + Size2i conf_size = Vector2i(16, 0); for (const KeyValue<StringName, Variant> &E : import_variation_data->settings) { - preload_config[E.key] = E.value; + if (E.key == "size") { + conf_size.x = E.value; + } + if (E.key == "outline_size") { + conf_size.y = E.value; + } else { + preload_config[E.key] = E.value; + } } + preload_config["size"] = conf_size; Array chars; for (const char32_t &E : import_variation_data->selected_chars) { diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index e64b80abbd..7d64055cc3 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -46,6 +46,11 @@ StringName AnimationNodeBlendSpace1DEditor::get_blend_position_path() const { } void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + Ref<InputEventKey> k = p_event; if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == Key::KEY_DELETE && !k->is_echo()) { @@ -71,11 +76,8 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven menu->add_submenu_item(TTR("Add Animation"), "animations"); - AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_animation_tree(); - ERR_FAIL_COND(!gp); - - if (gp->has_node(gp->get_animation_player())) { - AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player())); + if (tree->has_node(tree->get_animation_player())) { + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player())); if (ap) { List<StringName> names; @@ -180,7 +182,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven blend_pos *= blend_space->get_max_space() - blend_space->get_min_space(); blend_pos += blend_space->get_min_space(); - AnimationTreeEditor::get_singleton()->get_animation_tree()->set(get_blend_position_path(), blend_pos); + tree->set(get_blend_position_path(), blend_pos); blend_space_draw->queue_redraw(); } @@ -203,13 +205,18 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven blend_pos *= blend_space->get_max_space() - blend_space->get_min_space(); blend_pos += blend_space->get_min_space(); - AnimationTreeEditor::get_singleton()->get_animation_tree()->set(get_blend_position_path(), blend_pos); + tree->set(get_blend_position_path(), blend_pos); blend_space_draw->queue_redraw(); } } void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + Color linecolor = get_theme_color(SNAME("font_color"), SNAME("Label")); Color linecolor_soft = linecolor; linecolor_soft.a *= 0.5; @@ -301,7 +308,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { color.a *= 0.5; } - float point = AnimationTreeEditor::get_singleton()->get_animation_tree()->get(get_blend_position_path()); + float point = tree->get(get_blend_position_path()); point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space()); point *= s.width; @@ -575,12 +582,17 @@ void AnimationNodeBlendSpace1DEditor::_notification(int p_what) { } break; case NOTIFICATION_PROCESS: { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + String error; - if (!AnimationTreeEditor::get_singleton()->get_animation_tree()->is_active()) { + if (!tree->is_active()) { error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (AnimationTreeEditor::get_singleton()->get_animation_tree()->is_state_invalid()) { - error = AnimationTreeEditor::get_singleton()->get_animation_tree()->get_invalid_state_reason(); + } else if (tree->is_state_invalid()) { + error = tree->get_invalid_state_reason(); } if (error != error_label->get_text()) { diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 4d8e972883..526f69732b 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -95,6 +95,11 @@ StringName AnimationNodeBlendSpace2DEditor::get_blend_position_path() const { } void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + Ref<InputEventKey> k = p_event; if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == Key::KEY_DELETE && !k->is_echo()) { if (selected_point != -1 || selected_triangle != -1) { @@ -118,10 +123,8 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven ClassDB::get_inheriters_from_class("AnimationRootNode", &classes); menu->add_submenu_item(TTR("Add Animation"), "animations"); - AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_animation_tree(); - ERR_FAIL_COND(!gp); - if (gp && gp->has_node(gp->get_animation_player())) { - AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player())); + if (tree->has_node(tree->get_animation_player())) { + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player())); if (ap) { List<StringName> names; ap->get_animation_list(&names); @@ -275,7 +278,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space()); blend_pos += blend_space->get_min_space(); - AnimationTreeEditor::get_singleton()->get_animation_tree()->set(get_blend_position_path(), blend_pos); + tree->set(get_blend_position_path(), blend_pos); blend_space_draw->queue_redraw(); } @@ -311,7 +314,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space()); blend_pos += blend_space->get_min_space(); - AnimationTreeEditor::get_singleton()->get_animation_tree()->set(get_blend_position_path(), blend_pos); + tree->set(get_blend_position_path(), blend_pos); blend_space_draw->queue_redraw(); } @@ -438,6 +441,11 @@ void AnimationNodeBlendSpace2DEditor::_tool_switch(int p_tool) { } void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + Color linecolor = get_theme_color(SNAME("font_color"), SNAME("Label")); Color linecolor_soft = linecolor; linecolor_soft.a *= 0.5; @@ -596,7 +604,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { color.a *= 0.5; } - Vector2 blend_pos = AnimationTreeEditor::get_singleton()->get_animation_tree()->get(get_blend_position_path()); + Vector2 blend_pos = tree->get(get_blend_position_path()); Vector2 point = blend_pos; point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space()); @@ -806,14 +814,19 @@ void AnimationNodeBlendSpace2DEditor::_notification(int p_what) { } break; case NOTIFICATION_PROCESS: { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + String error; - if (!AnimationTreeEditor::get_singleton()->get_animation_tree()) { + if (!tree) { error = TTR("BlendSpace2D does not belong to an AnimationTree node."); - } else if (!AnimationTreeEditor::get_singleton()->get_animation_tree()->is_active()) { + } else if (!tree->is_active()) { error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (AnimationTreeEditor::get_singleton()->get_animation_tree()->is_state_invalid()) { - error = AnimationTreeEditor::get_singleton()->get_animation_tree()->get_invalid_state_reason(); + } else if (tree->is_state_invalid()) { + error = tree->get_invalid_state_reason(); } else if (blend_space->get_triangle_count() == 0) { error = TTR("No triangles exist, so no blending can take place."); } diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index dbd1b12a94..509caa78ef 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -99,6 +99,9 @@ Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const { void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } updating = true; Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); undo_redo->create_action(TTR("Parameter Changed:") + " " + String(p_property), UndoRedo::MERGE_ENDS); @@ -115,6 +118,11 @@ void AnimationNodeBlendTreeEditor::update_graph() { return; } + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + visible_properties.clear(); graph->set_scroll_ofs(blend_tree->get_graph_offset() * EDSCALE); @@ -177,10 +185,10 @@ void AnimationNodeBlendTreeEditor::update_graph() { continue; } String base_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E) + "/" + F.name; - EditorProperty *prop = EditorInspector::instantiate_property_editor(AnimationTreeEditor::get_singleton()->get_animation_tree(), F.type, base_path, F.hint, F.hint_string, F.usage); + EditorProperty *prop = EditorInspector::instantiate_property_editor(tree, F.type, base_path, F.hint, F.hint_string, F.usage); if (prop) { prop->set_read_only(read_only); - prop->set_object_and_property(AnimationTreeEditor::get_singleton()->get_animation_tree(), base_path); + prop->set_object_and_property(tree, base_path); prop->update_property(); prop->set_name_split_ratio(0); prop->connect("property_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_property_changed)); @@ -228,9 +236,8 @@ void AnimationNodeBlendTreeEditor::update_graph() { ProgressBar *pb = memnew(ProgressBar); - AnimationTree *player = AnimationTreeEditor::get_singleton()->get_animation_tree(); - if (player->has_node(player->get_animation_player())) { - AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(player->get_node(player->get_animation_player())); + if (tree->has_node(tree->get_animation_player())) { + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player())); if (ap) { List<StringName> anims; ap->get_animation_list(&anims); @@ -601,14 +608,19 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano return false; } - NodePath player_path = AnimationTreeEditor::get_singleton()->get_animation_tree()->get_animation_player(); + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return false; + } + + NodePath player_path = tree->get_animation_player(); - if (!AnimationTreeEditor::get_singleton()->get_animation_tree()->has_node(player_path)) { + if (!tree->has_node(player_path)) { EditorNode::get_singleton()->show_warning(TTR("No animation player set, so unable to retrieve track names.")); return false; } - AnimationPlayer *player = Object::cast_to<AnimationPlayer>(AnimationTreeEditor::get_singleton()->get_animation_tree()->get_node(player_path)); + AnimationPlayer *player = Object::cast_to<AnimationPlayer>(tree->get_node(player_path)); if (!player) { EditorNode::get_singleton()->show_warning(TTR("Player path set is invalid, so unable to retrieve track names.")); return false; @@ -839,12 +851,17 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { } break; case NOTIFICATION_PROCESS: { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; // Node has been changed. + } + String error; - if (!AnimationTreeEditor::get_singleton()->get_animation_tree()->is_active()) { + if (!tree->is_active()) { error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (AnimationTreeEditor::get_singleton()->get_animation_tree()->is_state_invalid()) { - error = AnimationTreeEditor::get_singleton()->get_animation_tree()->get_invalid_state_reason(); + } else if (tree->is_state_invalid()) { + error = tree->get_invalid_state_reason(); } if (error != error_label->get_text()) { @@ -861,16 +878,15 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { for (const AnimationNodeBlendTree::NodeConnection &E : conns) { float activity = 0; StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node; - if (AnimationTreeEditor::get_singleton()->get_animation_tree() && !AnimationTreeEditor::get_singleton()->get_animation_tree()->is_state_invalid()) { - activity = AnimationTreeEditor::get_singleton()->get_animation_tree()->get_connection_activity(path, E.input_index); + if (!tree->is_state_invalid()) { + activity = tree->get_connection_activity(path, E.input_index); } graph->set_connection_activity(E.output_node, 0, E.input_node, E.input_index, activity); } - AnimationTree *graph_player = AnimationTreeEditor::get_singleton()->get_animation_tree(); AnimationPlayer *player = nullptr; - if (graph_player->has_node(graph_player->get_animation_player())) { - player = Object::cast_to<AnimationPlayer>(graph_player->get_node(graph_player->get_animation_player())); + if (tree->has_node(tree->get_animation_player())) { + player = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player())); } if (player) { @@ -883,7 +899,7 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { E.value->set_max(anim->get_length()); //StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node; StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E.key) + "/time"; - E.value->set_value(AnimationTreeEditor::get_singleton()->get_animation_tree()->get(time_path)); + E.value->set_value(tree->get(time_path)); } } } @@ -937,6 +953,11 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima return; } + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + String prev_name = blend_tree->get_node_name(p_node); ERR_FAIL_COND(prev_name.is_empty()); GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(prev_name)); @@ -965,8 +986,8 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima undo_redo->create_action(TTR("Node Renamed")); undo_redo->add_do_method(blend_tree.ptr(), "rename_node", prev_name, name); undo_redo->add_undo_method(blend_tree.ptr(), "rename_node", name, prev_name); - undo_redo->add_do_method(AnimationTreeEditor::get_singleton()->get_animation_tree(), "rename_parameter", base_path + prev_name, base_path + name); - undo_redo->add_undo_method(AnimationTreeEditor::get_singleton()->get_animation_tree(), "rename_parameter", base_path + name, base_path + prev_name); + undo_redo->add_do_method(tree, "rename_parameter", base_path + prev_name, base_path + name); + undo_redo->add_undo_method(tree, "rename_parameter", base_path + name, base_path + prev_name); undo_redo->add_do_method(this, "update_graph"); undo_redo->add_undo_method(this, "update_graph"); undo_redo->commit_action(); diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index ef9477abea..66a0c746d9 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -79,7 +79,12 @@ void AnimationNodeStateMachineEditor::edit(const Ref<AnimationNode> &p_node) { } void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEvent> &p_event) { - Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_animation_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + + Ref<AnimationNodeStateMachinePlayback> playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); if (playback.is_null()) { return; } @@ -736,6 +741,11 @@ void AnimationNodeStateMachineEditor::_ungroup_selected_nodes() { } void AnimationNodeStateMachineEditor::_open_menu(const Vector2 &p_position) { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + menu->clear(); animations_menu->clear(); animations_to_add.clear(); @@ -745,10 +755,8 @@ void AnimationNodeStateMachineEditor::_open_menu(const Vector2 &p_position) { ClassDB::get_inheriters_from_class("AnimationRootNode", &classes); menu->add_submenu_item(TTR("Add Animation"), "animations"); - AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_animation_tree(); - ERR_FAIL_COND(!gp); - if (gp && gp->has_node(gp->get_animation_player())) { - AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player())); + if (tree->has_node(tree->get_animation_player())) { + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player())); if (ap) { List<StringName> names; ap->get_animation_list(&names); @@ -1192,7 +1200,12 @@ void AnimationNodeStateMachineEditor::_clip_dst_line_to_rect(const Vector2 &p_fr } void AnimationNodeStateMachineEditor::_state_machine_draw() { - Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_animation_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + + Ref<AnimationNodeStateMachinePlayback> playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); Ref<StyleBoxFlat> style = get_theme_stylebox(SNAME("state_machine_frame"), SNAME("GraphNode")); Ref<StyleBoxFlat> style_selected = get_theme_stylebox(SNAME("state_machine_selected_frame"), SNAME("GraphNode")); @@ -1380,7 +1393,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } StringName fullpath = AnimationTreeEditor::get_singleton()->get_base_path() + String(tl.advance_condition_name); - if (tl.advance_condition_name != StringName() && bool(AnimationTreeEditor::get_singleton()->get_animation_tree()->get(fullpath))) { + if (tl.advance_condition_name != StringName() && bool(tree->get(fullpath))) { tl.advance_condition_state = true; tl.auto_advance = true; } @@ -1495,7 +1508,12 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { - Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_animation_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + + Ref<AnimationNodeStateMachinePlayback> playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); if (!playback.is_valid() || !playback->is_playing()) { return; @@ -1587,17 +1605,22 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { } break; case NOTIFICATION_PROCESS: { + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree(); + if (!tree) { + return; + } + String error; - Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_animation_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + Ref<AnimationNodeStateMachinePlayback> playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); if (error_time > 0) { error = error_text; error_time -= get_process_delta_time(); - } else if (!AnimationTreeEditor::get_singleton()->get_animation_tree()->is_active()) { + } else if (!tree->is_active()) { error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (AnimationTreeEditor::get_singleton()->get_animation_tree()->is_state_invalid()) { - error = AnimationTreeEditor::get_singleton()->get_animation_tree()->get_invalid_state_reason(); + } else if (tree->is_state_invalid()) { + error = tree->get_invalid_state_reason(); /*} else if (state_machine->get_parent().is_valid() && state_machine->get_parent()->is_class("AnimationNodeStateMachine")) { if (state_machine->get_start_node() == StringName() || state_machine->get_end_node() == StringName()) { error = TTR("Start and end nodes are needed for a sub-transition."); @@ -1649,7 +1672,7 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { break; } - bool acstate = transition_lines[i].advance_condition_name != StringName() && bool(AnimationTreeEditor::get_singleton()->get_animation_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + String(transition_lines[i].advance_condition_name))); + bool acstate = transition_lines[i].advance_condition_name != StringName() && bool(tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + String(transition_lines[i].advance_condition_name))); if (transition_lines[i].advance_condition_state != acstate) { state_machine_draw->queue_redraw(); @@ -1704,7 +1727,7 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { Ref<AnimationNodeStateMachinePlayback> current_node_playback; while (anodesm.is_valid()) { - current_node_playback = AnimationTreeEditor::get_singleton()->get_animation_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + next + "/playback"); + current_node_playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + next + "/playback"); next += "/" + current_node_playback->get_current_node(); anodesm = anodesm->get_node(current_node_playback->get_current_node()); } diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index 61aa861a3f..c31a2689ec 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -77,6 +77,7 @@ void AnimationTreeEditor::edit(AnimationTree *p_tree) { void AnimationTreeEditor::_node_removed(Node *p_node) { if (p_node == tree) { tree = nullptr; + _clear_editors(); } } @@ -151,7 +152,6 @@ void AnimationTreeEditor::edit_path(const Vector<String> &p_path) { } else { current_root = ObjectID(); edited_path = button_path; - for (int i = 0; i < editors.size(); i++) { editors[i]->edit(Ref<AnimationNode>()); editors[i]->hide(); @@ -161,6 +161,17 @@ void AnimationTreeEditor::edit_path(const Vector<String> &p_path) { _update_path(); } +void AnimationTreeEditor::_clear_editors() { + button_path.clear(); + current_root = ObjectID(); + edited_path = button_path; + for (int i = 0; i < editors.size(); i++) { + editors[i]->edit(Ref<AnimationNode>()); + editors[i]->hide(); + } + _update_path(); +} + Vector<String> AnimationTreeEditor::get_edited_path() const { return button_path; } diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h index e1d9536f03..b933523057 100644 --- a/editor/plugins/animation_tree_editor_plugin.h +++ b/editor/plugins/animation_tree_editor_plugin.h @@ -60,6 +60,7 @@ class AnimationTreeEditor : public VBoxContainer { Vector<AnimationTreeNodeEditorPlugin *> editors; void _update_path(); + void _clear_editors(); ObjectID current_root; void _path_button_pressed(int p_path); diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index 0331e3f69e..4131c06745 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -55,7 +55,7 @@ void TileMapEditorTilesPlugin::tile_set_changed() { } void TileMapEditorTilesPlugin::_on_random_tile_checkbox_toggled(bool p_pressed) { - scatter_spinbox->set_editable(p_pressed); + scatter_controls_container->set_visible(p_pressed); } void TileMapEditorTilesPlugin::_on_scattering_spinbox_changed(double p_value) { @@ -2124,10 +2124,12 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { tools_settings->add_child(random_tile_toggle); // Random tile scattering. + scatter_controls_container = memnew(HBoxContainer); + scatter_label = memnew(Label); scatter_label->set_tooltip_text(TTR("Defines the probability of painting nothing instead of a randomly selected tile.")); scatter_label->set_text(TTR("Scattering:")); - tools_settings->add_child(scatter_label); + scatter_controls_container->add_child(scatter_label); scatter_spinbox = memnew(SpinBox); scatter_spinbox->set_min(0.0); @@ -2136,7 +2138,8 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { scatter_spinbox->set_tooltip_text(TTR("Defines the probability of painting nothing instead of a randomly selected tile.")); scatter_spinbox->get_line_edit()->add_theme_constant_override("minimum_character_width", 4); scatter_spinbox->connect("value_changed", callable_mp(this, &TileMapEditorTilesPlugin::_on_scattering_spinbox_changed)); - tools_settings->add_child(scatter_spinbox); + scatter_controls_container->add_child(scatter_spinbox); + tools_settings->add_child(scatter_controls_container); _on_random_tile_checkbox_toggled(false); diff --git a/editor/plugins/tiles/tile_map_editor.h b/editor/plugins/tiles/tile_map_editor.h index ad27795437..9700e26e01 100644 --- a/editor/plugins/tiles/tile_map_editor.h +++ b/editor/plugins/tiles/tile_map_editor.h @@ -91,6 +91,8 @@ private: VSeparator *tools_settings_vsep_2 = nullptr; CheckBox *bucket_contiguous_checkbox = nullptr; Button *random_tile_toggle = nullptr; + + HBoxContainer *scatter_controls_container = nullptr; float scattering = 0.0; Label *scatter_label = nullptr; SpinBox *scatter_spinbox = nullptr; diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index c8f5d7f5a6..ccbc080768 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -625,6 +625,8 @@ void GPUParticles2D::_bind_methods() { ADD_PROPERTY_DEFAULT("emitting", true); // Workaround for doctool in headless mode, as dummy rasterizer always returns false. ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "sub_emitter", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GPUParticles2D"), "set_sub_emitter", "get_sub_emitter"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "process_material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,ParticleProcessMaterial"), "set_process_material", "get_process_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); ADD_GROUP("Time", ""); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,suffix:s"), "set_lifetime", "get_lifetime"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot"); @@ -646,10 +648,6 @@ void GPUParticles2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "trail_lifetime", PROPERTY_HINT_RANGE, "0.01,10,0.01,or_greater,suffix:s"), "set_trail_lifetime", "get_trail_lifetime"); ADD_PROPERTY(PropertyInfo(Variant::INT, "trail_sections", PROPERTY_HINT_RANGE, "2,128,1"), "set_trail_sections", "get_trail_sections"); ADD_PROPERTY(PropertyInfo(Variant::INT, "trail_section_subdivisions", PROPERTY_HINT_RANGE, "1,1024,1"), "set_trail_section_subdivisions", "get_trail_section_subdivisions"); - ADD_GROUP("Process Material", "process_"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "process_material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,ParticleProcessMaterial"), "set_process_material", "get_process_material"); - ADD_GROUP("Textures", ""); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX); BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME); diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index fbc85bd5e1..b06a21dea9 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -1759,7 +1759,7 @@ void AnimationTree::_setup_animation_player() { AnimationPlayer *new_player = nullptr; if (!animation_player.is_empty()) { - new_player = Object::cast_to<AnimationPlayer>(get_node(animation_player)); + new_player = Object::cast_to<AnimationPlayer>(get_node_or_null(animation_player)); if (new_player && !new_player->is_connected("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed))) { new_player->connect("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed)); } diff --git a/tests/scene/test_arraymesh.h b/tests/scene/test_arraymesh.h index fc23adcd06..a11916fbd0 100644 --- a/tests/scene/test_arraymesh.h +++ b/tests/scene/test_arraymesh.h @@ -82,7 +82,9 @@ TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") { cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f); mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array); + ERR_PRINT_OFF mesh->add_blend_shape(name_a); + ERR_PRINT_ON CHECK(mesh->get_blend_shape_count() == 0); } @@ -121,7 +123,9 @@ TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") { cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f); mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array); + ERR_PRINT_OFF mesh->clear_blend_shapes(); + ERR_PRINT_ON CHECK(mesh->get_blend_shape_count() == 2); } diff --git a/tests/scene/test_bit_map.h b/tests/scene/test_bit_map.h index dc47bd7863..a8ee7505ec 100644 --- a/tests/scene/test_bit_map.h +++ b/tests/scene/test_bit_map.h @@ -49,6 +49,8 @@ TEST_CASE("[BitMap] Create bit map") { CHECK(bit_map.get_size() == Size2i(256, 512)); CHECK_MESSAGE(bit_map.get_true_bit_count() == 0, "This will go through the entire bitmask inside of bitmap, thus hopefully checking if the bitmask was correctly set up."); + ERR_PRINT_OFF + dim = Size2i(0, 256); bit_map.create(dim); CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 512), "We should still have the same dimensions as before, because the new dimension is invalid."); @@ -60,6 +62,8 @@ TEST_CASE("[BitMap] Create bit map") { dim = Size2i(46341, 46341); bit_map.create(dim); CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 512), "We should still have the same dimensions as before, because the new dimension is too large (46341*46341=2147488281)."); + + ERR_PRINT_ON } TEST_CASE("[BitMap] Create bit map from image alpha") { @@ -67,6 +71,8 @@ TEST_CASE("[BitMap] Create bit map from image alpha") { BitMap bit_map{}; bit_map.create(dim); + ERR_PRINT_OFF + const Ref<Image> null_img = nullptr; bit_map.create_from_image_alpha(null_img); CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Bitmap should have its old values because bitmap creation from a nullptr should fail."); @@ -80,6 +86,8 @@ TEST_CASE("[BitMap] Create bit map from image alpha") { bit_map.create_from_image_alpha(wrong_format_img); CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Bitmap should have its old values because converting from a compressed image should fail."); + ERR_PRINT_ON + Ref<Image> img = Image::create_empty(3, 3, false, Image::Format::FORMAT_RGBA8); img->set_pixel(0, 0, Color(0, 0, 0, 0)); img->set_pixel(0, 1, Color(0, 0, 0, 0.09f)); @@ -105,6 +113,8 @@ TEST_CASE("[BitMap] Set bit") { BitMap bit_map{}; // Setting a point before a bit map is created should not crash, because there are checks to see if we are out of bounds. + ERR_PRINT_OFF + bit_map.set_bitv(Point2i(128, 128), true); bit_map.create(dim); @@ -120,12 +130,16 @@ TEST_CASE("[BitMap] Set bit") { bit_map.create(dim); bit_map.set_bitv(Point2i(512, 512), true); CHECK_MESSAGE(bit_map.get_true_bit_count() == 0, "Nothing should change as we were trying to edit a bit outside of the correct range."); + + ERR_PRINT_ON } TEST_CASE("[BitMap] Get bit") { const Size2i dim{ 256, 256 }; BitMap bit_map{}; + ERR_PRINT_OFF + CHECK_MESSAGE(bit_map.get_bitv(Point2i(128, 128)) == false, "Trying to access a bit outside of the BitMap's range should always return false"); bit_map.create(dim); @@ -140,6 +154,8 @@ TEST_CASE("[BitMap] Get bit") { CHECK(bit_map.get_bitv(Point2i(255, 255)) == true); CHECK(bit_map.get_bitv(Point2i(256, 256)) == false); CHECK(bit_map.get_bitv(Point2i(257, 257)) == false); + + ERR_PRINT_ON } TEST_CASE("[BitMap] Set bit rect") { @@ -158,6 +174,9 @@ TEST_CASE("[BitMap] Set bit rect") { reset_bit_map(bit_map); // Checking out of bounds handling. + + ERR_PRINT_OFF + bit_map.set_bit_rect(Rect2i{ 128, 128, 256, 256 }, true); CHECK(bit_map.get_true_bit_count() == 16384); @@ -170,6 +189,8 @@ TEST_CASE("[BitMap] Set bit rect") { bit_map.set_bit_rect(Rect2i{ -128, -128, 512, 512 }, true); CHECK(bit_map.get_true_bit_count() == 65536); + + ERR_PRINT_ON } TEST_CASE("[BitMap] Get true bit count") { @@ -197,7 +218,9 @@ TEST_CASE("[BitMap] Get size") { bit_map.create(dim); CHECK(bit_map.get_size() == Size2i(256, 256)); + ERR_PRINT_OFF bit_map.create(Size2i(-1, 0)); + ERR_PRINT_ON CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Invalid size should not be accepted by create"); bit_map.create(Size2i(256, 128)); @@ -219,7 +242,9 @@ TEST_CASE("[BitMap] Resize") { CHECK_MESSAGE(bit_map.get_true_bit_count() == 50, "There should be 25 bits in the top left corner, and 25 bits in the bottom right corner"); bit_map.create(dim); + ERR_PRINT_OFF bit_map.resize(Size2i(-1, 128)); + ERR_PRINT_ON CHECK_MESSAGE(bit_map.get_size() == Size2i(128, 128), "When an invalid size is given the bit map will keep its size"); bit_map.create(dim); @@ -234,7 +259,9 @@ TEST_CASE("[BitMap] Resize") { TEST_CASE("[BitMap] Grow and shrink mask") { const Size2i dim{ 256, 256 }; BitMap bit_map{}; + ERR_PRINT_OFF bit_map.grow_mask(100, Rect2i(0, 0, 128, 128)); // Check if method does not crash when working with an uninitialized bit map. + ERR_PRINT_ON CHECK_MESSAGE(bit_map.get_size() == Size2i(0, 0), "Size should still be equal to 0x0"); bit_map.create(dim); @@ -331,7 +358,9 @@ TEST_CASE("[BitMap] Blit") { Ref<BitMap> blit_bit_map{}; // Testing null reference to blit bit map. + ERR_PRINT_OFF bit_map.blit(blit_pos, blit_bit_map); + ERR_PRINT_ON blit_bit_map.instantiate(); @@ -378,7 +407,9 @@ TEST_CASE("[BitMap] Convert to image") { BitMap bit_map{}; Ref<Image> img; + ERR_PRINT_OFF img = bit_map.convert_to_image(); + ERR_PRINT_ON CHECK_MESSAGE(img.is_valid(), "We should receive a valid Image Object even if BitMap is not created yet"); CHECK_MESSAGE(img->get_format() == Image::FORMAT_L8, "We should receive a valid Image Object even if BitMap is not created yet"); CHECK_MESSAGE(img->get_size() == (Size2i(0, 0)), "Image should have no width or height, because BitMap has not yet been created"); @@ -392,7 +423,7 @@ TEST_CASE("[BitMap] Convert to image") { bit_map.set_bit_rect(Rect2i(0, 0, 128, 128), true); img = bit_map.convert_to_image(); CHECK_MESSAGE(img->get_pixel(0, 0).is_equal_approx(Color(1, 1, 1)), "BitMap's top-left quadrant is all 1's, so Image should be white"); - CHECK_MESSAGE(img->get_pixel(256, 256).is_equal_approx(Color(0, 0, 0)), "All other quadrants were 0's, so these should be black"); + CHECK_MESSAGE(img->get_pixel(255, 255).is_equal_approx(Color(0, 0, 0)), "All other quadrants were 0's, so these should be black"); } TEST_CASE("[BitMap] Clip to polygon") { @@ -400,7 +431,9 @@ TEST_CASE("[BitMap] Clip to polygon") { BitMap bit_map{}; Vector<Vector<Vector2>> polygons; + ERR_PRINT_OFF polygons = bit_map.clip_opaque_to_polygons(Rect2i(0, 0, 128, 128)); + ERR_PRINT_ON CHECK_MESSAGE(polygons.size() == 0, "We should have no polygons, because the BitMap was not initialized"); bit_map.create(dim); diff --git a/tests/scene/test_curve.h b/tests/scene/test_curve.h index 4afd5b293f..4f95568b4a 100644 --- a/tests/scene/test_curve.h +++ b/tests/scene/test_curve.h @@ -240,8 +240,9 @@ TEST_CASE("[Curve3D] Linear sampling should return exact value") { curve->add_point(Vector3(0, 0, 0)); curve->add_point(Vector3(len, 0, 0)); - + ERR_PRINT_OFF real_t baked_length = curve->get_baked_length(); + ERR_PRINT_ON CHECK(len == baked_length); for (int i = 0; i < len; i++) { |