Add reparenting test (#18)

This commit is contained in:
Rafał Mikrut 2021-01-12 09:06:16 +01:00 committed by GitHub
parent 0a8289a3d6
commit 16938eb80c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 219 additions and 7 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
.DS_Store
*~
.import/
#.import/
logs/
.~lock.*#
.mono/

View File

@ -0,0 +1,3 @@
source_md5="d98fe5b307b619f42f0bd920ee4f170d"
dest_md5="d07f6dc66eca2ede4e35cb8bd212f64f"

View File

@ -23,6 +23,7 @@ const alone_steps : Array = [
"res://Rendering/Lights2D/Lights2D.tscn",
"res://Rendering/Lights3D/Lights3D.tscn",
"res://Text/Text.tscn",
"res://Reparenting/Reparenting.tscn",
]
# All scenes run in one step
@ -39,12 +40,11 @@ func _init():
time_for_each_step = time_to_show / (alone_steps.size() + 1)
for argument in OS.get_cmdline_args():
var rr: String = argument
if rr.ends_with("tscn"): # Ignore all tscn scenes/names
continue
time_to_show = int(argument.to_float() * 1000)
time_for_each_step = time_to_show / (alone_steps.size() + 1)
print("Time set to: " + str(time_to_show / 1000.0) + " seconds with "+ str(alone_steps.size() + 1) + " steps, each step will take " + str(time_for_each_step / 1000.0) + " seconds.")
if argument.is_valid_float(): # Ignore all non numeric arguments
time_to_show = int(argument.to_float() * 1000)
time_for_each_step = time_to_show / (alone_steps.size() + 1)
print("Time set to: " + str(time_to_show / 1000.0) + " seconds with "+ str(alone_steps.size() + 1) + " steps, each step will take " + str(time_for_each_step / 1000.0) + " seconds.")
break # We only need to take first argument
func _process(delta: float) -> void:

203
Reparenting/Reparenting.gd Normal file
View File

@ -0,0 +1,203 @@
extends Node
var number_of_nodes : int = -1
func _ready() -> void:
seed(45)
for _i in range(3):
add_child(Control.new())
add_child(Popup.new())
add_child(WindowDialog.new())
add_child(AcceptDialog.new())
add_child(ConfirmationDialog.new())
add_child(FileDialog.new())
add_child(PopupDialog.new())
add_child(PopupMenu.new())
add_child(PopupPanel.new())
add_child(Button.new())
add_child(CheckBox.new())
add_child(CheckButton.new())
add_child(ColorPickerButton.new())
add_child(MenuButton.new())
add_child(OptionButton.new())
add_child(ToolButton.new())
add_child(LinkButton.new())
add_child(TextureButton.new())
add_child(Container.new())
add_child(ColorPicker.new())
add_child(VBoxContainer.new())
add_child(HBoxContainer.new())
add_child(CenterContainer.new())
add_child(ScrollContainer.new())
add_child(GraphNode.new())
add_child(GridContainer.new())
add_child(HSplitContainer.new())
add_child(VSplitContainer.new())
add_child(MarginContainer.new())
add_child(PanelContainer.new())
add_child(TabContainer.new())
add_child(ViewportContainer.new())
add_child(ColorRect.new())
add_child(HScrollBar.new())
add_child(VScrollBar.new())
add_child(HSlider.new())
add_child(VSlider.new())
add_child(ProgressBar.new())
add_child(SpinBox.new())
add_child(TextureProgress.new())
add_child(GraphEdit.new())
add_child(HSeparator.new())
add_child(VSeparator.new())
add_child(ItemList.new())
add_child(Label.new())
add_child(LineEdit.new())
add_child(NinePatchRect.new())
add_child(Panel.new())
add_child(ReferenceRect.new())
add_child(RichTextLabel.new())
add_child(Tabs.new())
add_child(TextEdit.new())
add_child(TextureRect.new())
add_child(Tree.new())
add_child(VideoPlayer.new())
add_child(Node2D.new())
add_child(AnimatedSprite.new())
add_child(Area2D.new())
add_child(KinematicBody2D.new())
add_child(RigidBody2D.new())
add_child(StaticBody2D.new())
add_child(AudioStreamPlayer2D.new())
add_child(BackBufferCopy.new())
add_child(Bone2D.new())
add_child(CPUParticles2D.new())
add_child(Camera2D.new())
add_child(CanvasModulate.new())
add_child(CollisionPolygon2D.new()) # Errors
add_child(CollisionShape2D.new())
add_child(DampedSpringJoint2D.new())
add_child(GrooveJoint2D.new())
add_child(PinJoint2D.new())
add_child(Light2D.new())
add_child(LightOccluder2D.new())
add_child(Line2D.new())
add_child(MeshInstance2D.new())
add_child(MultiMeshInstance2D.new())
add_child(Navigation2D.new())
add_child(NavigationPolygonInstance.new())
add_child(ParallaxLayer.new())
add_child(Particles2D.new())
add_child(Path2D.new())
add_child(PathFollow2D.new())
add_child(Polygon2D.new())
add_child(Position2D.new())
add_child(RayCast2D.new())
add_child(RemoteTransform2D.new())
add_child(Skeleton2D.new())
add_child(Sprite.new())
add_child(TileMap.new())
add_child(TouchScreenButton.new())
add_child(VisibilityNotifier2D.new())
add_child(VisibilityEnabler2D.new())
add_child(YSort.new())
add_child(AnimationPlayer.new())
add_child(AnimationTree.new())
add_child(AnimationTreePlayer.new())
add_child(AudioStreamPlayer.new())
add_child(CanvasLayer.new())
add_child(ParallaxBackground.new())
add_child(HTTPRequest.new())
add_child(ResourcePreloader.new())
add_child(Skeleton2D.new())
add_child(Timer.new())
add_child(Tween.new())
add_child(Viewport.new())
add_child(WorldEnvironment.new())
add_child(Spatial.new())
add_child(ARVRAnchor.new())
add_child(Camera.new())
add_child(ARVRCamera.new())
add_child(ClippedCamera.new())
add_child(InterpolatedCamera.new())
add_child(ARVRController.new())
add_child(ARVROrigin.new())
add_child(AnimatedSprite3D.new())
add_child(Sprite3D.new())
add_child(CPUParticles.new())
add_child(CSGBox.new())
add_child(CSGCylinder.new())
add_child(CSGMesh.new())
add_child(CSGPolygon.new())
add_child(CSGSphere.new())
add_child(CSGTorus.new())
add_child(CSGCombiner.new())
add_child(ImmediateGeometry.new())
add_child(MeshInstance.new())
add_child(SoftBody.new())
add_child(MultiMeshInstance.new())
add_child(Particles.new())
add_child(BakedLightmap.new())
add_child(DirectionalLight.new())
add_child(OmniLight.new())
add_child(SpotLight.new())
add_child(GIProbe.new())
add_child(ReflectionProbe.new())
add_child(Area.new())
add_child(KinematicBody.new())
add_child(PhysicalBone.new())
add_child(RigidBody.new())
add_child(VehicleBody.new())
add_child(StaticBody.new())
add_child(AudioStreamPlayer3D.new())
add_child(BoneAttachment.new())
add_child(CollisionPolygon.new())
add_child(CollisionShape.new())
add_child(ConeTwistJoint.new())
add_child(Generic6DOFJoint.new())
add_child(HingeJoint.new())
add_child(PinJoint.new())
add_child(SliderJoint.new())
add_child(GridMap.new())
add_child(Listener.new())
add_child(Navigation.new())
add_child(NavigationMeshInstance.new())
add_child(Path.new())
add_child(PathFollow.new())
add_child(Position3D.new())
add_child(ProximityGroup.new())
add_child(RayCast.new())
add_child(RemoteTransform.new())
add_child(Skeleton.new())
add_child(SpringArm.new())
add_child(VehicleWheel.new())
add_child(VisibilityNotifier.new())
add_child(VisibilityEnabler.new())
for i in range(get_child_count()):
get_child(i).set_name("Node " + str(i))
number_of_nodes = get_child_count()
func _process(delta: float) -> void:
assert(Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT) == 0)
var choosen_node : Node
var parent_of_node : Node
for i in range(20):
var number = "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("Node " + str(randi() % number_of_nodes),true,false)
if choosen_node.find_node(random_node.get_name(),true,false) != null: # Cannot set as node parent one of its child
continue
if choosen_node == random_node: # Do not reparent node to self
continue
parent_of_node.remove_child(choosen_node)
random_node.add_child(choosen_node)
if !choosen_node.is_inside_tree() || choosen_node.get_parent() == null: # Failed to add node, due e.g. requsrive problem or similar
add_child(choosen_node)

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Reparenting/Reparenting.gd" type="Script" id=1]
[node name="Reparenting" type="Node"]
script = ExtResource( 1 )