Tests for node (physics) processing and process priority

This commit is contained in:
Marius Hanl 2023-06-12 22:57:56 +02:00
parent 46321379ba
commit 60a17ba78d

View File

@ -37,6 +37,47 @@
namespace TestNode {
class TestNode : public Node {
GDCLASS(TestNode, Node);
protected:
void _notification(int p_what) {
switch (p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
internal_process_counter++;
push_self();
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
internal_physics_process_counter++;
push_self();
} break;
case NOTIFICATION_PROCESS: {
process_counter++;
push_self();
} break;
case NOTIFICATION_PHYSICS_PROCESS: {
physics_process_counter++;
push_self();
} break;
}
}
private:
void push_self() {
if (callback_list) {
callback_list->push_back(this);
}
}
public:
int internal_process_counter = 0;
int internal_physics_process_counter = 0;
int process_counter = 0;
int physics_process_counter = 0;
List<Node *> *callback_list = nullptr;
};
TEST_CASE("[SceneTree][Node] Testing node operations with a very simple scene tree") {
Node *node = memnew(Node);
@ -420,7 +461,7 @@ TEST_CASE("[SceneTree][Node] Testing node operations with a more complex simple
memdelete(node2);
}
TEST_CASE("[Node] Processing") {
TEST_CASE("[Node] Processing checks") {
Node *node = memnew(Node);
SUBCASE("Processing") {
@ -507,9 +548,203 @@ TEST_CASE("[Node] Processing") {
CHECK_FALSE(node->is_processing_internal());
}
SUBCASE("Process priority") {
CHECK_EQ(0, node->get_process_priority());
node->set_process_priority(1);
CHECK_EQ(1, node->get_process_priority());
}
SUBCASE("Physics process priority") {
CHECK_EQ(0, node->get_physics_process_priority());
node->set_physics_process_priority(1);
CHECK_EQ(1, node->get_physics_process_priority());
}
memdelete(node);
}
TEST_CASE("[SceneTree][Node] Test the processing") {
TestNode *node = memnew(TestNode);
SceneTree::get_singleton()->get_root()->add_child(node);
SUBCASE("No process") {
CHECK_EQ(0, node->process_counter);
CHECK_EQ(0, node->physics_process_counter);
}
SUBCASE("Process") {
node->set_process(true);
SceneTree::get_singleton()->process(0);
CHECK_EQ(1, node->process_counter);
CHECK_EQ(0, node->physics_process_counter);
CHECK_EQ(0, node->internal_process_counter);
CHECK_EQ(0, node->internal_physics_process_counter);
}
SUBCASE("Physics process") {
node->set_physics_process(true);
SceneTree::get_singleton()->physics_process(0);
CHECK_EQ(0, node->process_counter);
CHECK_EQ(1, node->physics_process_counter);
CHECK_EQ(0, node->internal_process_counter);
CHECK_EQ(0, node->internal_physics_process_counter);
}
SUBCASE("Normal and physics process") {
node->set_process(true);
node->set_physics_process(true);
SceneTree::get_singleton()->process(0);
SceneTree::get_singleton()->physics_process(0);
CHECK_EQ(1, node->process_counter);
CHECK_EQ(1, node->physics_process_counter);
CHECK_EQ(0, node->internal_process_counter);
CHECK_EQ(0, node->internal_physics_process_counter);
}
SUBCASE("Internal, normal and physics process") {
node->set_process_internal(true);
node->set_physics_process_internal(true);
SceneTree::get_singleton()->process(0);
SceneTree::get_singleton()->physics_process(0);
CHECK_EQ(0, node->process_counter);
CHECK_EQ(0, node->physics_process_counter);
CHECK_EQ(1, node->internal_process_counter);
CHECK_EQ(1, node->internal_physics_process_counter);
}
SUBCASE("All processing") {
node->set_process(true);
node->set_physics_process(true);
node->set_process_internal(true);
node->set_physics_process_internal(true);
SceneTree::get_singleton()->process(0);
SceneTree::get_singleton()->physics_process(0);
CHECK_EQ(1, node->process_counter);
CHECK_EQ(1, node->physics_process_counter);
CHECK_EQ(1, node->internal_process_counter);
CHECK_EQ(1, node->internal_physics_process_counter);
}
SUBCASE("All processing twice") {
node->set_process(true);
node->set_physics_process(true);
node->set_process_internal(true);
node->set_physics_process_internal(true);
SceneTree::get_singleton()->process(0);
SceneTree::get_singleton()->physics_process(0);
SceneTree::get_singleton()->process(0);
SceneTree::get_singleton()->physics_process(0);
CHECK_EQ(2, node->process_counter);
CHECK_EQ(2, node->physics_process_counter);
CHECK_EQ(2, node->internal_process_counter);
CHECK_EQ(2, node->internal_physics_process_counter);
}
SUBCASE("Enable and disable processing") {
node->set_process(true);
node->set_physics_process(true);
node->set_process_internal(true);
node->set_physics_process_internal(true);
SceneTree::get_singleton()->process(0);
SceneTree::get_singleton()->physics_process(0);
node->set_process(false);
node->set_physics_process(false);
node->set_process_internal(false);
node->set_physics_process_internal(false);
SceneTree::get_singleton()->process(0);
SceneTree::get_singleton()->physics_process(0);
CHECK_EQ(1, node->process_counter);
CHECK_EQ(1, node->physics_process_counter);
CHECK_EQ(1, node->internal_process_counter);
CHECK_EQ(1, node->internal_physics_process_counter);
}
memdelete(node);
}
TEST_CASE("[SceneTree][Node] Test the process priority") {
List<Node *> process_order;
TestNode *node = memnew(TestNode);
node->callback_list = &process_order;
SceneTree::get_singleton()->get_root()->add_child(node);
TestNode *node2 = memnew(TestNode);
node2->callback_list = &process_order;
SceneTree::get_singleton()->get_root()->add_child(node2);
TestNode *node3 = memnew(TestNode);
node3->callback_list = &process_order;
SceneTree::get_singleton()->get_root()->add_child(node3);
TestNode *node4 = memnew(TestNode);
node4->callback_list = &process_order;
SceneTree::get_singleton()->get_root()->add_child(node4);
SUBCASE("Process priority") {
node->set_process(true);
node->set_process_priority(20);
node2->set_process(true);
node2->set_process_priority(10);
node3->set_process(true);
node3->set_process_priority(40);
node4->set_process(true);
node4->set_process_priority(30);
SceneTree::get_singleton()->process(0);
CHECK_EQ(4, process_order.size());
List<Node *>::Element *E = process_order.front();
CHECK_EQ(E->get(), node2);
E = E->next();
CHECK_EQ(E->get(), node);
E = E->next();
CHECK_EQ(E->get(), node4);
E = E->next();
CHECK_EQ(E->get(), node3);
}
SUBCASE("Physics process priority") {
node->set_physics_process(true);
node->set_physics_process_priority(20);
node2->set_physics_process(true);
node2->set_physics_process_priority(10);
node3->set_physics_process(true);
node3->set_physics_process_priority(40);
node4->set_physics_process(true);
node4->set_physics_process_priority(30);
SceneTree::get_singleton()->physics_process(0);
CHECK_EQ(4, process_order.size());
List<Node *>::Element *E = process_order.front();
CHECK_EQ(E->get(), node2);
E = E->next();
CHECK_EQ(E->get(), node);
E = E->next();
CHECK_EQ(E->get(), node4);
E = E->next();
CHECK_EQ(E->get(), node3);
}
memdelete(node);
memdelete(node2);
memdelete(node3);
memdelete(node4);
}
} // namespace TestNode
#endif // TEST_NODE_H