mirror of
https://github.com/Relintai/regression-test-project.git
synced 2024-11-14 10:27:53 +01:00
Add debug prints (#48)
This commit is contained in:
parent
4a4a1543d9
commit
7177d6034a
@ -1,39 +1,67 @@
|
||||
extends Node
|
||||
|
||||
var TIME_TO_DELETE : float = 1.0
|
||||
var time_to_delete : float = TIME_TO_DELETE
|
||||
# This script adds nodes to scene tree and removes them after certain amount
|
||||
# of time
|
||||
|
||||
var disabled_classes : Array = []
|
||||
# Counters which are used to delete and adds nodes in loop
|
||||
var TIME_TO_DELETE: float = 3.0
|
||||
var time_to_delete: float = TIME_TO_DELETE
|
||||
|
||||
func _populate() -> void:
|
||||
for _i in range(2): # Number of created
|
||||
# List of disabled classes
|
||||
var disabled_classes: Array = []
|
||||
# List of all collected nodes which
|
||||
var classes: Array = []
|
||||
|
||||
var debug_enabled: bool = false
|
||||
|
||||
|
||||
# Collects all classes which will be used
|
||||
func collect() -> void:
|
||||
for name_of_class in ClassDB.get_class_list():
|
||||
if name_of_class in disabled_classes:
|
||||
continue
|
||||
if !ClassDB.can_instance(name_of_class):
|
||||
continue
|
||||
|
||||
|
||||
if ClassDB.is_parent_class(name_of_class,"Control"):
|
||||
add_child(ClassDB.instance(name_of_class))
|
||||
if ClassDB.is_parent_class(name_of_class, "Control"):
|
||||
classes.append(name_of_class)
|
||||
continue
|
||||
if ClassDB.is_parent_class(name_of_class,"Spatial"):
|
||||
add_child(ClassDB.instance(name_of_class))
|
||||
if ClassDB.is_parent_class(name_of_class, "Spatial"):
|
||||
classes.append(name_of_class)
|
||||
continue
|
||||
if ClassDB.is_parent_class(name_of_class,"Node2D"):
|
||||
add_child(ClassDB.instance(name_of_class))
|
||||
if ClassDB.is_parent_class(name_of_class, "Node2D"):
|
||||
classes.append(name_of_class)
|
||||
continue
|
||||
if ClassDB.is_parent_class(name_of_class,"Node"):
|
||||
add_child(ClassDB.instance(name_of_class))
|
||||
if ClassDB.get_parent_class(name_of_class) == "Node":
|
||||
classes.append(name_of_class)
|
||||
continue
|
||||
|
||||
classes.sort()
|
||||
if debug_enabled:
|
||||
var to_print: String = "DEBUG: List of classes used in Nodes scene:\n"
|
||||
to_print += "DEBUG: ["
|
||||
for index in range(classes.size()):
|
||||
to_print += "\"" + classes[index] + "\""
|
||||
if index != classes.size() - 1:
|
||||
to_print += ", "
|
||||
print(to_print)
|
||||
|
||||
# Populate at start
|
||||
|
||||
# Adds nodes to scenes
|
||||
func populate() -> void:
|
||||
for _i in range(2): # Number of created instances of object
|
||||
for name_of_class in classes:
|
||||
add_child(ClassDB.instance(name_of_class))
|
||||
|
||||
|
||||
# Populate nodes at start
|
||||
func _ready() -> void:
|
||||
_populate()
|
||||
collect()
|
||||
populate()
|
||||
|
||||
|
||||
# Move nodes a little and delete and readd them later
|
||||
func _process(delta: float) -> void:
|
||||
# Moves nodes a little
|
||||
for i in get_children():
|
||||
if i is Control:
|
||||
i._set_size(Vector2(200 * randf() - 100, 200 * randf() - 100))
|
||||
@ -45,10 +73,15 @@ func _process(delta: float) -> void:
|
||||
i.set_translation(Vector3(10 * randf(), 10 * randf(), 10 * randf()))
|
||||
|
||||
time_to_delete -= delta
|
||||
# Delete and adds later nodes
|
||||
if time_to_delete < 0:
|
||||
if debug_enabled:
|
||||
print("DEBUG: Deleting nodes")
|
||||
time_to_delete += TIME_TO_DELETE
|
||||
|
||||
for i in get_children():
|
||||
i.queue_free()
|
||||
|
||||
_populate()
|
||||
if debug_enabled:
|
||||
print("DEBUG: Adding nodes")
|
||||
populate()
|
||||
|
@ -1,44 +1,15 @@
|
||||
extends Node
|
||||
|
||||
var number_of_nodes : int = 0
|
||||
# Script first adds nodes to scene, then choose some random nodes and reparents
|
||||
# them or delete and replace with new ones
|
||||
|
||||
var collected_nodes : Array = []
|
||||
var disabled_classes : Array = [
|
||||
"ReflectionProbe", # Cause errors, not sure about it
|
||||
] # Just add name of any class if cause problems
|
||||
|
||||
func collect() -> void:
|
||||
var classes : Array = ClassDB.get_class_list()
|
||||
classes.sort()
|
||||
for name_of_class in classes:
|
||||
if ClassDB.is_parent_class(name_of_class,"Node"):
|
||||
if name_of_class.find("Editor") != -1: # We don't want to test editor nodes
|
||||
continue
|
||||
if disabled_classes.has(name_of_class): # Class is disabled
|
||||
continue
|
||||
if ClassDB.can_instance(name_of_class): # Only instantable nodes can be used
|
||||
collected_nodes.append(name_of_class)
|
||||
|
||||
func _ready() -> void:
|
||||
seed(405)
|
||||
collect()
|
||||
number_of_nodes = max(collected_nodes.size(),200) # Use at least all nodes, or more if you want(168 is probably number nodes)
|
||||
for i in range(number_of_nodes):
|
||||
var index = i
|
||||
if i >= collected_nodes.size(): # Wrap values
|
||||
index = i % collected_nodes.size()
|
||||
|
||||
var child : Node = ClassDB.instance(collected_nodes[index])
|
||||
child.set_name("Special Node " + str(i))
|
||||
add_child(child)
|
||||
|
||||
## It is quite easy algorithm to reparent and delete items
|
||||
## Algorithm
|
||||
# - Add multiple nodes to scene
|
||||
# - Set name to each
|
||||
# - In process
|
||||
# - In _process
|
||||
# - Get random node
|
||||
# - Remove its parent
|
||||
# - Play with a russian roulette
|
||||
# - Detach it from its parent
|
||||
# - Play with a russian roulette:
|
||||
# - If node will be deleted, be sure to get list of its all children and then
|
||||
# replace all with new nodes(change also name) and old remove with queue_free()
|
||||
# - Get another random node
|
||||
@ -46,30 +17,77 @@ func _ready() -> void:
|
||||
# - If second node is child of first, add first node to root one(prevents from memory leaks due invalid reparenting)
|
||||
# - At the end add first random node as child of second
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# assert(Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT) == 0) # Don't work good with running more than 1 this scene
|
||||
var number_of_nodes: int = 0
|
||||
|
||||
var choosen_node : Node
|
||||
var parent_of_node : Node
|
||||
# Collected nodes
|
||||
var collected_nodes: Array = []
|
||||
# Disabled nodes which won't be used
|
||||
var disabled_classes: Array = [
|
||||
"ReflectionProbe", #GH 45460
|
||||
]
|
||||
|
||||
var debug_enabled: bool = false
|
||||
|
||||
|
||||
func collect() -> void:
|
||||
var classes: Array = ClassDB.get_class_list()
|
||||
classes.sort()
|
||||
for name_of_class in classes:
|
||||
if ClassDB.is_parent_class(name_of_class, "Node"):
|
||||
if name_of_class.find("Editor") != -1: # We don't want to test editor nodes
|
||||
continue
|
||||
if disabled_classes.has(name_of_class): # Class is disabled
|
||||
continue
|
||||
if ClassDB.can_instance(name_of_class): # Only instantable nodes can be used
|
||||
collected_nodes.append(name_of_class)
|
||||
|
||||
if debug_enabled:
|
||||
var to_print: String = "DEBUG: List of classes used in ReparentingDeleting scene:\n"
|
||||
to_print += "DEBUG: ["
|
||||
for index in range(classes.size()):
|
||||
to_print += "\"" + classes[index] + "\""
|
||||
if index != classes.size() - 1:
|
||||
to_print += ", "
|
||||
print(to_print)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
seed(405)
|
||||
collect()
|
||||
number_of_nodes = max(collected_nodes.size(), 200) # Use at least all nodes, or more if you want(168 is probably number of all nodes)
|
||||
for i in range(number_of_nodes):
|
||||
var index = i
|
||||
if i >= collected_nodes.size(): # Wrap values
|
||||
index = i % collected_nodes.size()
|
||||
|
||||
var child: Node = ClassDB.instance(collected_nodes[index])
|
||||
child.set_name("Special Node " + str(i))
|
||||
add_child(child)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# assert(Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT) == 0) # Don't work good when instancing more than 1 scene, because node queued for deleting
|
||||
|
||||
var choosen_node: Node
|
||||
var parent_of_node: Node
|
||||
for i in range(5):
|
||||
var number : String = "Special Node " + str(randi() % number_of_nodes)
|
||||
choosen_node = find_node(number,true,false)
|
||||
var number: String = "Special Node " + str(randi() % number_of_nodes)
|
||||
choosen_node = find_node(number, true, false)
|
||||
parent_of_node = choosen_node.get_parent()
|
||||
|
||||
var random_node = find_node("Special Node " + str(randi() % number_of_nodes),true,false)
|
||||
var random_node = find_node("Special Node " + str(randi() % number_of_nodes), true, false)
|
||||
parent_of_node.remove_child(choosen_node)
|
||||
|
||||
if randi() % 6 == 0: # 16% chance to remove node with children
|
||||
var names_to_remove : Array = find_all_special_children_names(choosen_node)
|
||||
var names_to_remove: Array = find_all_special_children_names(choosen_node)
|
||||
for name_to_remove in names_to_remove:
|
||||
var node : Node = ClassDB.instance(collected_nodes[randi() % collected_nodes.size()])
|
||||
var node: Node = ClassDB.instance(collected_nodes[randi() % collected_nodes.size()])
|
||||
node.set_name(name_to_remove)
|
||||
add_child(node)
|
||||
choosen_node.queue_free()
|
||||
continue
|
||||
|
||||
|
||||
if choosen_node.find_node(random_node.get_name(),true,false) != null: # Cannot set as node parent one of its child
|
||||
if choosen_node.find_node(random_node.get_name(), true, false) != null: # Cannot set as node parent one of its child
|
||||
add_child(choosen_node)
|
||||
continue
|
||||
if choosen_node == random_node: # Do not reparent node to self
|
||||
@ -77,9 +95,11 @@ func _process(delta: float) -> void:
|
||||
continue
|
||||
random_node.add_child(choosen_node)
|
||||
|
||||
# Finds recusivelly all child nodes which are not internal
|
||||
func find_all_special_children_names(node : Node) -> Array:
|
||||
var array : Array = []
|
||||
|
||||
# Finds recusivelly all child nodes which will be also removed to be able to add
|
||||
# exactly same number of nodes in replacement.
|
||||
func find_all_special_children_names(node: Node) -> Array:
|
||||
var array: Array = []
|
||||
array.append(node.get_name())
|
||||
for child in node.get_children():
|
||||
if child.get_name().begins_with("Special Node"):
|
||||
|
Loading…
Reference in New Issue
Block a user