summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/classes/PhysicsServer2D.xml3
-rw-r--r--doc/classes/PhysicsServer3D.xml2
-rw-r--r--editor/plugins/mesh_instance_3d_editor_plugin.cpp45
-rw-r--r--tests/scene/test_timer.h217
-rw-r--r--tests/test_main.cpp1
5 files changed, 263 insertions, 5 deletions
diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml
index def0c2bd91..c0672cc503 100644
--- a/doc/classes/PhysicsServer2D.xml
+++ b/doc/classes/PhysicsServer2D.xml
@@ -370,7 +370,8 @@
<method name="body_create">
<return type="RID" />
<description>
- Creates a 2D body object in the physics server, and returns the [RID] that identifies it. Use [method body_add_shape] to add shapes to it, use [method body_set_state] to set its transform, and use [method body_set_space] to add the body to a space.
+ Creates a 2D body object in the physics server, and returns the [RID] that identifies it. The default settings for the created area include a collision layer and mask set to [code]1[/code], and body mode set to [constant BODY_MODE_RIGID].
+ Use [method body_add_shape] to add shapes to it, use [method body_set_state] to set its transform, and use [method body_set_space] to add the body to a space.
</description>
</method>
<method name="body_get_canvas_instance_id" qualifiers="const">
diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml
index 28ef03614a..e835724e36 100644
--- a/doc/classes/PhysicsServer3D.xml
+++ b/doc/classes/PhysicsServer3D.xml
@@ -352,6 +352,8 @@
<method name="body_create">
<return type="RID" />
<description>
+ Creates a 3D body object in the physics server, and returns the [RID] that identifies it. The default settings for the created area include a collision layer and mask set to [code]1[/code], and body mode set to [constant BODY_MODE_RIGID].
+ Use [method body_add_shape] to add shapes to it, use [method body_set_state] to set its transform, and use [method body_set_space] to add the body to a space.
</description>
</method>
<method name="body_get_collision_layer" qualifiers="const">
diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
index 0c922ea070..92c9572a02 100644
--- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp
+++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
@@ -33,6 +33,7 @@
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
+#include "editor/multi_node_edit.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "editor/themes/editor_scale.h"
#include "scene/3d/navigation_region_3d.h"
@@ -188,8 +189,7 @@ void MeshInstance3DEditor::_create_collision_shape() {
cshape->set_shape(shape);
cshape->set_name("CollisionShape3D");
cshape->set_transform(node->get_transform());
- ur->add_do_method(E->get_parent(), "add_child", cshape);
- ur->add_do_method(E->get_parent(), "move_child", cshape, E->get_index() + 1);
+ ur->add_do_method(E, "add_sibling", cshape, true);
ur->add_do_method(cshape, "set_owner", owner);
ur->add_do_method(Node3DEditor::get_singleton(), SceneStringNames::get_singleton()->_request_gizmo, cshape);
ur->add_do_reference(cshape);
@@ -612,11 +612,48 @@ MeshInstance3DEditor::MeshInstance3DEditor() {
}
void MeshInstance3DEditorPlugin::edit(Object *p_object) {
- mesh_editor->edit(Object::cast_to<MeshInstance3D>(p_object));
+ {
+ MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_object);
+ if (mi) {
+ mesh_editor->edit(mi);
+ return;
+ }
+ }
+
+ Ref<MultiNodeEdit> mne = Ref<MultiNodeEdit>(p_object);
+ Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
+ if (mne.is_valid() && edited_scene) {
+ for (int i = 0; i < mne->get_node_count(); i++) {
+ MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(edited_scene->get_node(mne->get_node(i)));
+ if (mi) {
+ mesh_editor->edit(mi);
+ return;
+ }
+ }
+ }
+ mesh_editor->edit(nullptr);
}
bool MeshInstance3DEditorPlugin::handles(Object *p_object) const {
- return p_object->is_class("MeshInstance3D");
+ if (Object::cast_to<MeshInstance3D>(p_object)) {
+ return true;
+ }
+
+ Ref<MultiNodeEdit> mne = Ref<MultiNodeEdit>(p_object);
+ Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
+ if (mne.is_valid() && edited_scene) {
+ bool has_mesh = false;
+ for (int i = 0; i < mne->get_node_count(); i++) {
+ if (Object::cast_to<MeshInstance3D>(edited_scene->get_node(mne->get_node(i)))) {
+ if (has_mesh) {
+ return true;
+ } else {
+ has_mesh = true;
+ }
+ }
+ }
+ }
+ return false;
}
void MeshInstance3DEditorPlugin::make_visible(bool p_visible) {
diff --git a/tests/scene/test_timer.h b/tests/scene/test_timer.h
new file mode 100644
index 0000000000..913ed92de5
--- /dev/null
+++ b/tests/scene/test_timer.h
@@ -0,0 +1,217 @@
+/**************************************************************************/
+/* test_timer.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#ifndef TEST_TIMER_H
+#define TEST_TIMER_H
+
+#include "scene/main/timer.h"
+
+#include "tests/test_macros.h"
+
+namespace TestTimer {
+
+TEST_CASE("[SceneTree][Timer] Check Timer Setters and Getters") {
+ Timer *test_timer = memnew(Timer);
+
+ SUBCASE("[Timer] Timer set and get wait time") {
+ // check default
+ CHECK(Math::is_equal_approx(test_timer->get_wait_time(), 1.0));
+
+ test_timer->set_wait_time(50.0);
+ CHECK(Math::is_equal_approx(test_timer->get_wait_time(), 50.0));
+
+ test_timer->set_wait_time(42.0);
+ CHECK(Math::is_equal_approx(test_timer->get_wait_time(), 42.0));
+
+ // wait time remains unchanged if we attempt to set it negative or zero
+ ERR_PRINT_OFF;
+ test_timer->set_wait_time(-22.0);
+ ERR_PRINT_ON;
+ CHECK(Math::is_equal_approx(test_timer->get_wait_time(), 42.0));
+
+ ERR_PRINT_OFF;
+ test_timer->set_wait_time(0.0);
+ ERR_PRINT_ON;
+ CHECK(Math::is_equal_approx(test_timer->get_wait_time(), 42.0));
+ }
+
+ SUBCASE("[Timer] Timer set and get one shot") {
+ // check default
+ CHECK(test_timer->is_one_shot() == false);
+
+ test_timer->set_one_shot(true);
+ CHECK(test_timer->is_one_shot() == true);
+
+ test_timer->set_one_shot(false);
+ CHECK(test_timer->is_one_shot() == false);
+ }
+
+ SUBCASE("[Timer] Timer set and get autostart") {
+ // check default
+ CHECK(test_timer->has_autostart() == false);
+
+ test_timer->set_autostart(true);
+ CHECK(test_timer->has_autostart() == true);
+
+ test_timer->set_autostart(false);
+ CHECK(test_timer->has_autostart() == false);
+ }
+
+ SUBCASE("[Timer] Timer start and stop") {
+ test_timer->set_autostart(false);
+ }
+
+ SUBCASE("[Timer] Timer set and get paused") {
+ // check default
+ CHECK(test_timer->is_paused() == false);
+
+ test_timer->set_paused(true);
+ CHECK(test_timer->is_paused() == true);
+
+ test_timer->set_paused(false);
+ CHECK(test_timer->is_paused() == false);
+ }
+
+ memdelete(test_timer);
+}
+
+TEST_CASE("[SceneTree][Timer] Check Timer Start and Stop") {
+ Timer *test_timer = memnew(Timer);
+
+ SUBCASE("[Timer] Timer start and stop") {
+ SceneTree::get_singleton()->get_root()->add_child(test_timer);
+
+ test_timer->start(5.0);
+
+ CHECK(Math::is_equal_approx(test_timer->get_wait_time(), 5.0));
+ CHECK(Math::is_equal_approx(test_timer->get_time_left(), 5.0));
+
+ test_timer->start(-2.0);
+
+ // the wait time and time left remains unchanged when started with a negative start time
+ CHECK(Math::is_equal_approx(test_timer->get_wait_time(), 5.0));
+ CHECK(Math::is_equal_approx(test_timer->get_time_left(), 5.0));
+
+ test_timer->stop();
+ CHECK(test_timer->is_processing() == false);
+ CHECK(test_timer->has_autostart() == false);
+ }
+
+ memdelete(test_timer);
+}
+
+TEST_CASE("[SceneTree][Timer] Check Timer process callback") {
+ Timer *test_timer = memnew(Timer);
+
+ SUBCASE("[Timer] Timer process callback") {
+ // check default
+ CHECK(test_timer->get_timer_process_callback() == Timer::TimerProcessCallback::TIMER_PROCESS_IDLE);
+
+ test_timer->set_timer_process_callback(Timer::TimerProcessCallback::TIMER_PROCESS_PHYSICS);
+ CHECK(test_timer->get_timer_process_callback() == Timer::TimerProcessCallback::TIMER_PROCESS_PHYSICS);
+
+ test_timer->set_timer_process_callback(Timer::TimerProcessCallback::TIMER_PROCESS_IDLE);
+ CHECK(test_timer->get_timer_process_callback() == Timer::TimerProcessCallback::TIMER_PROCESS_IDLE);
+ }
+
+ memdelete(test_timer);
+}
+
+TEST_CASE("[SceneTree][Timer] Check Timer timeout signal") {
+ Timer *test_timer = memnew(Timer);
+ SceneTree::get_singleton()->get_root()->add_child(test_timer);
+
+ test_timer->set_process(true);
+ test_timer->set_physics_process(true);
+
+ SUBCASE("[Timer] Timer process timeout signal must be emitted") {
+ SIGNAL_WATCH(test_timer, SNAME("timeout"));
+ test_timer->start(0.1);
+
+ SceneTree::get_singleton()->process(0.2);
+
+ Array signal_args;
+ signal_args.push_back(Array());
+
+ SIGNAL_CHECK(SNAME("timeout"), signal_args);
+
+ SIGNAL_UNWATCH(test_timer, SNAME("timeout"));
+ }
+
+ SUBCASE("[Timer] Timer process timeout signal must not be emitted") {
+ SIGNAL_WATCH(test_timer, SNAME("timeout"));
+ test_timer->start(0.1);
+
+ SceneTree::get_singleton()->process(0.05);
+
+ Array signal_args;
+ signal_args.push_back(Array());
+
+ SIGNAL_CHECK_FALSE(SNAME("timeout"));
+
+ SIGNAL_UNWATCH(test_timer, SNAME("timeout"));
+ }
+
+ test_timer->set_timer_process_callback(Timer::TimerProcessCallback::TIMER_PROCESS_PHYSICS);
+
+ SUBCASE("[Timer] Timer physics process timeout signal must be emitted") {
+ SIGNAL_WATCH(test_timer, SNAME("timeout"));
+ test_timer->start(0.1);
+
+ SceneTree::get_singleton()->physics_process(0.2);
+
+ Array signal_args;
+ signal_args.push_back(Array());
+
+ SIGNAL_CHECK(SNAME("timeout"), signal_args);
+
+ SIGNAL_UNWATCH(test_timer, SNAME("timeout"));
+ }
+
+ SUBCASE("[Timer] Timer physics process timeout signal must not be emitted") {
+ SIGNAL_WATCH(test_timer, SNAME("timeout"));
+ test_timer->start(0.1);
+
+ SceneTree::get_singleton()->physics_process(0.05);
+
+ Array signal_args;
+ signal_args.push_back(Array());
+
+ SIGNAL_CHECK_FALSE(SNAME("timeout"));
+
+ SIGNAL_UNWATCH(test_timer, SNAME("timeout"));
+ }
+
+ memdelete(test_timer);
+}
+
+} // namespace TestTimer
+
+#endif // TEST_TIMER_H
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 56bd8739c6..3a4ae3369d 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -118,6 +118,7 @@
#include "tests/scene/test_sprite_frames.h"
#include "tests/scene/test_text_edit.h"
#include "tests/scene/test_theme.h"
+#include "tests/scene/test_timer.h"
#include "tests/scene/test_viewport.h"
#include "tests/scene/test_visual_shader.h"
#include "tests/scene/test_window.h"